More GE work

This commit is contained in:
ceikry 2022-03-10 22:46:19 -06:00
parent f36faa0f09
commit 41ae35a0f0
6 changed files with 102 additions and 68 deletions

View file

@ -8,10 +8,8 @@ import core.game.component.ComponentDefinition;
import core.game.component.ComponentPlugin; import core.game.component.ComponentPlugin;
import core.game.ge.GEGuidePrice; import core.game.ge.GEGuidePrice;
import core.game.ge.GEItemSet; import core.game.ge.GEItemSet;
import core.game.ge.GrandExchangeDatabase;
import core.game.ge.OfferState; import core.game.ge.OfferState;
import core.game.node.entity.player.Player; import core.game.node.entity.player.Player;
import core.game.node.entity.player.link.RunScript;
import core.game.node.entity.player.link.audio.Audio; import core.game.node.entity.player.link.audio.Audio;
import core.game.node.item.Item; import core.game.node.item.Item;
import core.game.system.task.Pulse; import core.game.system.task.Pulse;
@ -181,7 +179,7 @@ public class GrandExchangeInterface extends ComponentPlugin {
break; break;
} }
GrandExchangeOffer offer; GrandExchangeOffer offer;
if (index > -1 && (offer = player.getPlayerGrandExchange().getOffers()[index]) != null) { if (index > -1 && (offer = player.getPlayerGrandExchange().getOffer(player.getPlayerGrandExchange().getOfferRecords()[index])) != null) {
player.getPlayerGrandExchange().withdraw(offer, slot >> 1); player.getPlayerGrandExchange().withdraw(offer, slot >> 1);
} }
return true; return true;

View file

@ -2,7 +2,6 @@ package core.game.interaction.object;
import static api.ContentAPIKt.*; import static api.ContentAPIKt.*;
import api.Container;
import core.cache.def.impl.NPCDefinition; import core.cache.def.impl.NPCDefinition;
import core.cache.def.impl.SceneryDefinition; import core.cache.def.impl.SceneryDefinition;
import core.game.component.CloseEvent; import core.game.component.CloseEvent;
@ -32,7 +31,6 @@ import core.game.world.update.flag.context.Animation;
import core.plugin.Initializable; import core.plugin.Initializable;
import core.plugin.Plugin; import core.plugin.Plugin;
import kotlin.Unit; import kotlin.Unit;
import org.rs09.consts.Items;
import rs09.game.content.dialogue.DumpContainer; import rs09.game.content.dialogue.DumpContainer;
import rs09.game.ge.GrandExchangeOffer; import rs09.game.ge.GrandExchangeOffer;
import rs09.game.world.GameWorld; import rs09.game.world.GameWorld;
@ -174,7 +172,7 @@ public final class BankingPlugin extends OptionHandler {
return true; return true;
} }
interpreter.sendDialogues(id, FacialExpression.HALF_GUILTY, "Good day, How may I help you?"); interpreter.sendDialogues(id, FacialExpression.HALF_GUILTY, "Good day, How may I help you?");
for (GrandExchangeOffer o : player.getPlayerGrandExchange().getOffers()) { for (GrandExchangeOffer o : player.getPlayerGrandExchange().getOfferRecords()) {
if (o != null && (o.getWithdraw()[0] != null || o.getWithdraw()[1] != null)) { if (o != null && (o.getWithdraw()[0] != null || o.getWithdraw()[1] != null)) {
stage = -1; stage = -1;
break; break;

View file

@ -142,7 +142,7 @@ public class GrandExchangeTab extends ConsoleTab {
JOptionPane.showMessageDialog(null, "Error! No player found."); JOptionPane.showMessageDialog(null, "Error! No player found.");
return; return;
} }
for (GrandExchangeOffer o : player.getPlayerGrandExchange().getOffers()) { for (GrandExchangeOffer o : player.getPlayerGrandExchange().getOfferRecords()) {
if (o == null) { if (o == null) {
continue; continue;
} }

View file

@ -80,8 +80,9 @@ class GrandExchangeOffer() {
PacketRepository.send(ContainerPacket::class.java, ContainerContext(player, -1, -1757, 523 + index, withdraw, false)) PacketRepository.send(ContainerPacket::class.java, ContainerContext(player, -1, -1757, 523 + index, withdraw, false))
} }
fun visualize(player: Player) fun visualize(player: Player?)
{ {
player ?: return
PacketRepository.send( PacketRepository.send(
GrandExchangePacket::class.java, GrandExchangePacket::class.java,
GrandExchangeContext(player, index.toByte(), offerState.ordinal.toByte(), itemID.toShort(), GrandExchangeContext(player, index.toByte(), offerState.ordinal.toByte(), itemID.toShort(),
@ -109,6 +110,7 @@ class GrandExchangeOffer() {
stmt.setString(3, encodeWithdraw()) stmt.setString(3, encodeWithdraw())
stmt.setLong(4, uid) stmt.setLong(4, uid)
stmt.executeUpdate() stmt.executeUpdate()
visualize(player)
} }
} }
@ -142,6 +144,7 @@ class GrandExchangeOffer() {
stmt.setInt(5, offerState.ordinal) stmt.setInt(5, offerState.ordinal)
stmt.setInt(6, if(sell) 1 else 0) stmt.setInt(6, if(sell) 1 else 0)
stmt.executeUpdate() stmt.executeUpdate()
visualize(player)
} }
} }

View file

@ -21,13 +21,12 @@ import core.game.system.monitor.PlayerMonitor
import core.net.packet.PacketRepository import core.net.packet.PacketRepository
import core.net.packet.context.ConfigContext import core.net.packet.context.ConfigContext
import core.net.packet.context.ContainerContext import core.net.packet.context.ContainerContext
import core.net.packet.context.GrandExchangeContext
import core.net.packet.out.Config import core.net.packet.out.Config
import core.net.packet.out.ContainerPacket import core.net.packet.out.ContainerPacket
import core.net.packet.out.GrandExchangePacket
import org.json.simple.JSONArray import org.json.simple.JSONArray
import org.json.simple.JSONObject import org.json.simple.JSONObject
import org.rs09.consts.Components import org.rs09.consts.Components
import org.rs09.consts.Items
import rs09.game.system.SystemLogger import rs09.game.system.SystemLogger
import java.text.DecimalFormat import java.text.DecimalFormat
import java.text.NumberFormat import java.text.NumberFormat
@ -45,7 +44,7 @@ class PlayerGrandExchange(private val player: Player) {
var history = arrayOfNulls<GrandExchangeOffer>(5) var history = arrayOfNulls<GrandExchangeOffer>(5)
public val offers = arrayOfNulls<GrandExchangeOffer>(6) public val offerRecords = arrayOfNulls<OfferRecord>(6)
private var openedIndex = -1 private var openedIndex = -1
@ -93,15 +92,40 @@ class PlayerGrandExchange(private val player: Player) {
player.packetDispatch.sendAccessMask(6, 36, 109, 0, 2) player.packetDispatch.sendAccessMask(6, 36, 109, 0, 2)
player.packetDispatch.sendAccessMask(6, 44, 109, 0, 2) player.packetDispatch.sendAccessMask(6, 44, 109, 0, 2)
player.packetDispatch.sendAccessMask(6, 52, 109, 0, 2) player.packetDispatch.sendAccessMask(6, 52, 109, 0, 2)
for (offer in offers) {
if (offer != null) { visualizeRecords()
PacketRepository.send( }
ContainerPacket::class.java,
ContainerContext(player, -1, -1757, 523 + offer.index, offer.withdraw, false) fun visualizeRecords()
) {
val conn = GEDB.connect()
val stmt = conn.createStatement()
for (record in offerRecords) {
if (record != null) {
val offer_raw = stmt.executeQuery("select * from player_offers where uid = ${record.uid}")
if(offer_raw.next())
{
val offer = GrandExchangeOffer.fromQuery(offer_raw)
offer.index = record.slot
offer.visualize(player)
} }
} }
} }
}
fun getOffer(record: OfferRecord) : GrandExchangeOffer?
{
val conn = GEDB.connect()
val stmt = conn.createStatement()
val offer_raw = stmt.executeQuery("select * from player_offers where uid = ${record.uid}")
if(offer_raw.next())
{
val offer = GrandExchangeOffer.fromQuery(offer_raw)
return offer
}
return null
}
/** /**
* Opens the history log. * Opens the history log.
@ -228,24 +252,36 @@ class PlayerGrandExchange(private val player: Player) {
} }
fun parse(geData: JSONObject) { fun parse(geData: JSONObject) {
val offersRaw = geData["offers"] val recordsRaw = geData["records"]
if (offersRaw != null) { if(recordsRaw != null)
val offersJSON = offersRaw as JSONArray {
for (i in offersJSON.indices) { val recordsJSON = recordsRaw as JSONArray
val offer = offersJSON[i] as JSONObject
val index = offer["offerIndex"].toString().toInt() for((index,recordRaw) in recordsJSON.withIndex())
if (index > offers.size - 1) { {
SystemLogger.logAlert("Grand Exchange: INVALID OFFER INDEX FOR " + player.name + " INDEX: " + index + ", SKIPPING!") val record = recordRaw as JSONObject
SystemLogger.logAlert("IF YOU SEE THIS MESSAGE, THE GRAND EXCHANGE NEEDS TO BE FIXED.") val recordIndex = record["index"].toString().toInt()
SystemLogger.logAlert("Check your logs, AVENGING ANGLE might have fucked up HARD and now " + player.name + "'s trade with index " + index + "is gone :(") val recordUid = record["uid"].toString().toLong()
continue offerRecords[index] = OfferRecord(recordUid,recordIndex)
}
OfferManager.setIndex(offer["offerUID"].toString().toLong(), index)
offers[index] = OfferManager.OFFER_MAPPING[offer["offerUID"].toString().toLong()]
update(offers[index])
} }
} }
else //offer records null, as a safety fallback just get all offers belonging to this player and reindex
{
val conn = GEDB.connect()
val stmt = conn.createStatement()
val offer_records = stmt.executeQuery("SELECT * from player_offers where player_uid = ${player.details.uid}")
var index = 0
while(offer_records.next())
{
val offer = GrandExchangeOffer.fromQuery(offer_records)
offerRecords[index] = OfferRecord(offer.uid, index++)
}
}
visualizeRecords()
val historyRaw = geData["history"] val historyRaw = geData["history"]
if(historyRaw != null){ if(historyRaw != null){
val history = historyRaw as JSONArray val history = historyRaw as JSONArray
@ -267,17 +303,17 @@ class PlayerGrandExchange(private val player: Player) {
fun init() { fun init() {
// Were trades made while gone? // Were trades made while gone?
var updated = false var updated = false
for (offer in offers) { for (record in offerRecords) {
if (offer != null) { if (record != null) {
offer.player = player val offer = getOffer(record) ?: continue
if (!updated && (offer.withdraw[0] != null || offer.withdraw[1] != null)) { if (!updated && (offer.withdraw[0] != null || offer.withdraw[1] != null)) {
updated = true updated = true
} }
update(offer) offer.visualize(player)
} }
} }
if (updated) { if (updated) {
player.packetDispatch.sendMessage("You have items from the Grand Exchange waiting in your collection box.") sendMessage(player, "You have items from the Grand Exchange waiting in your collection box.")
} }
} }
@ -285,9 +321,7 @@ class PlayerGrandExchange(private val player: Player) {
* Updates the client with the grand exchange data. * Updates the client with the grand exchange data.
*/ */
fun update() { fun update() {
for (offer in offers) { visualizeRecords()
update(offer)
}
} }
/** /**
@ -331,7 +365,7 @@ class PlayerGrandExchange(private val player: Player) {
* @param item The item to sell. * @param item The item to sell.
*/ */
fun constructSale(item: Item) { fun constructSale(item: Item) {
if (openedIndex < 0 || offers[openedIndex] != null) { if (openedIndex < 0 || offerRecords[openedIndex] != null) {
return return
} }
if (item.id == 995) { if (item.id == 995) {
@ -419,19 +453,17 @@ class PlayerGrandExchange(private val player: Player) {
} }
} }
if (OfferManager.dispatch(player, temporaryOffer!!)) { if (OfferManager.dispatch(player, temporaryOffer!!)) {
offers[openedIndex] = temporaryOffer offerRecords[openedIndex] = OfferRecord(temporaryOffer!!.uid, openedIndex)
OfferManager.updateOffer(temporaryOffer!!)
} }
} else { } else {
val total: Int = temporaryOffer!!.amount * temporaryOffer!!.offeredValue val total: Int = temporaryOffer!!.amount * temporaryOffer!!.offeredValue
if (total > player.inventory.getAmount(Item(995))) { if (total > amountInInventory(player, Items.COINS_995)) {
player.audioManager.send(Audio(4039, 1, 1)) playAudio(player, Audio(4039, 1, 1))
player.packetDispatch.sendMessage("You do not have enough coins to cover the offer.") sendMessage(player, "You do not have enough coins to cover the offer.")
return return
} }
if (OfferManager.dispatch(player, temporaryOffer!!) && player.inventory.remove(Item(995, total))) { if (OfferManager.dispatch(player, temporaryOffer!!) && player.inventory.remove(Item(995, total))) {
offers[openedIndex] = temporaryOffer offerRecords[openedIndex] = OfferRecord(temporaryOffer!!.uid, openedIndex)
OfferManager.updateOffer(temporaryOffer!!)
} }
} }
player.monitor.log( player.monitor.log(
@ -443,6 +475,7 @@ class PlayerGrandExchange(private val player: Player) {
toMainInterface() toMainInterface()
player.audioManager.send(Audio(4043, 1, 1)) player.audioManager.send(Audio(4043, 1, 1))
temporaryOffer = null temporaryOffer = null
visualizeRecords()
} }
/** /**
@ -451,7 +484,7 @@ class PlayerGrandExchange(private val player: Player) {
* @param index The offer index. * @param index The offer index.
*/ */
fun abort(index: Int) { fun abort(index: Int) {
val offer: GrandExchangeOffer? = offers[index] val offer: GrandExchangeOffer? = getOffer(offerRecords[index] ?: return)
player.packetDispatch.sendMessage("Abort request acknowledged. Please be aware that your offer may") player.packetDispatch.sendMessage("Abort request acknowledged. Please be aware that your offer may")
player.packetDispatch.sendMessage("have already been completed.") player.packetDispatch.sendMessage("have already been completed.")
if (offer == null || !offer.isActive) { if (offer == null || !offer.isActive) {
@ -459,10 +492,11 @@ class PlayerGrandExchange(private val player: Player) {
} }
offer.offerState = OfferState.ABORTED offer.offerState = OfferState.ABORTED
if (offer.sell) { if (offer.sell) {
OfferManager.addWithdraw(offer, offer.itemID, offer.amountLeft, true) offer.addWithdrawItem(offer.itemID, offer.amountLeft)
} else { } else {
OfferManager.addWithdraw(offer, 995, offer.amountLeft * offer.offeredValue, true) offer.addWithdrawItem(995, offer.amountLeft * offer.offeredValue)
} }
offer.update()
update(offer) update(offer)
player.monitor.log( player.monitor.log(
"aborted offer => item => " + ItemDefinition.forId(offer.itemID).name + " => amount => " + offer.amount + "", "aborted offer => item => " + ItemDefinition.forId(offer.itemID).name + " => amount => " + offer.amount + "",
@ -477,10 +511,10 @@ class PlayerGrandExchange(private val player: Player) {
* @param index The offer index. * @param index The offer index.
*/ */
fun remove(index: Int): Boolean { fun remove(index: Int): Boolean {
if (offers[index] == null) { if (offerRecords[index] == null) {
return false return false
} }
var offer: GrandExchangeOffer = offers[index]!! val offer: GrandExchangeOffer = getOffer(offerRecords[index] ?: return false)!!
if (offer.completedAmount > 0) { if (offer.completedAmount > 0) {
val newHistory = arrayOfNulls<GrandExchangeOffer>(5) val newHistory = arrayOfNulls<GrandExchangeOffer>(5)
newHistory[0] = offer newHistory[0] = offer
@ -492,17 +526,16 @@ class PlayerGrandExchange(private val player: Player) {
) )
} }
offer.withdraw = arrayOfNulls(2) offer.withdraw = arrayOfNulls(2)
var didExist = OfferManager.removeEntry(offer)
offer.uid = 0 offer.uid = 0
offer.offerState = OfferState.REMOVED offer.offerState = OfferState.REMOVED
offers[index] = null offerRecords[index] = null
update(offer) update(offer)
toMainInterface() toMainInterface()
return didExist return true
} }
fun hasActiveOffer(): Boolean { fun hasActiveOffer(): Boolean {
for (i in offers) { for (i in offerRecords) {
if (i != null) if (i != null)
return true return true
} }
@ -520,7 +553,7 @@ class PlayerGrandExchange(private val player: Player) {
var entry: GrandExchangeEntry? = GrandExchangeDatabase.getDatabase()[offer?.itemID] var entry: GrandExchangeEntry? = GrandExchangeDatabase.getDatabase()[offer?.itemID]
var examine: String? = "" var examine: String? = ""
val formatter = DecimalFormat("###,###,###,###") val formatter = DecimalFormat("###,###,###,###")
val text = StringBuilder() /* val text = StringBuilder()
var lowestOfferValue = 0 var lowestOfferValue = 0
var totalAmounts = 0 var totalAmounts = 0
val foundOffers: MutableList<Int> = ArrayList() val foundOffers: MutableList<Int> = ArrayList()
@ -554,7 +587,7 @@ class PlayerGrandExchange(private val player: Player) {
.append(formatter.format(count.toLong())) .append(formatter.format(count.toLong()))
} }
} }
player.packetDispatch.sendString(if (offer != null && !offer.sell) text.toString() else examine, 105, 142) player.packetDispatch.sendString(if (offer != null && !offer.sell) text.toString() else examine, 105, 142)*/
var lowPrice = 0 var lowPrice = 0
var highPrice = 0 var highPrice = 0
val recommendedPrice = OfferManager.getRecommendedPrice(entry?.itemId ?: 0) val recommendedPrice = OfferManager.getRecommendedPrice(entry?.itemId ?: 0)
@ -599,7 +632,7 @@ class PlayerGrandExchange(private val player: Player) {
*/ */
fun openBuy(index: Int) { fun openBuy(index: Int) {
openedIndex = index openedIndex = index
sendConfiguration(offers[index], false) sendConfiguration(getOffer(offerRecords[index] ?: return), false)
openSearch() openSearch()
} }
@ -608,7 +641,7 @@ class PlayerGrandExchange(private val player: Player) {
*/ */
fun openSell(index: Int) { fun openSell(index: Int) {
openedIndex = index openedIndex = index
sendConfiguration(offers[index], true) sendConfiguration(getOffer(offerRecords[index] ?: return), true)
player.interfaceManager.openSingleTab(Component(Components.STOCKSIDE_107)).open(player) player.interfaceManager.openSingleTab(Component(Components.STOCKSIDE_107)).open(player)
player.packetDispatch.sendRunScript( player.packetDispatch.sendRunScript(
149, "IviiiIsssss", "", "", "", "Examine", "Offer", 149, "IviiiIsssss", "", "", "", "Examine", "Offer",
@ -645,7 +678,7 @@ class PlayerGrandExchange(private val player: Player) {
ContainerPacket::class.java, ContainerPacket::class.java,
ContainerContext(player, -1, -1757, 523 + offer.index, offer.withdraw, false) ContainerContext(player, -1, -1757, 523 + offer.index, offer.withdraw, false)
) )
OfferManager.dumpDatabase = true offer.update()
} }
/** /**
@ -656,7 +689,7 @@ class PlayerGrandExchange(private val player: Player) {
fun getOpenedOffer(): GrandExchangeOffer? { fun getOpenedOffer(): GrandExchangeOffer? {
return if (openedIndex < 0) { return if (openedIndex < 0) {
null null
} else offers[openedIndex] } else getOffer(offerRecords[openedIndex] ?: return null)
} }
/** /**
@ -665,11 +698,11 @@ class PlayerGrandExchange(private val player: Player) {
* @param index The index. * @param index The index.
*/ */
fun view(index: Int) { fun view(index: Int) {
if (offers[index] == null) { if (offerRecords[index] == null) {
return return
} }
openedIndex = index openedIndex = index
sendConfiguration(offers[index], false) sendConfiguration(getOffer(offerRecords[index] ?: return), false)
} }
/** /**
@ -679,8 +712,9 @@ class PlayerGrandExchange(private val player: Player) {
*/ */
fun format(): String? { fun format(): String? {
var log = "" var log = ""
for (offer in offers) { for (record in offerRecords) {
if (offer != null) { if (record != null) {
val offer = getOffer(record) ?: continue
log += offer.itemID.toString() + "," + offer.amount + "," + offer.sell + "|" log += offer.itemID.toString() + "," + offer.amount + "," + offer.sell + "|"
} }
} }
@ -691,4 +725,5 @@ class PlayerGrandExchange(private val player: Player) {
} }
data class OfferRecord(val uid: Long, val slot: Int)
} }

View file

@ -636,7 +636,7 @@ class PlayerSaver (val player: Player){
val grandExchange = JSONObject() val grandExchange = JSONObject()
if(player.playerGrandExchange.hasActiveOffer()){ if(player.playerGrandExchange.hasActiveOffer()){
val offers = JSONArray() val offers = JSONArray()
player.playerGrandExchange.offers.map { player.playerGrandExchange.offerRecords.map {
if(it != null){ if(it != null){
val offer = JSONObject() val offer = JSONObject()
offer["offerIndex"] = it.index.toString() offer["offerIndex"] = it.index.toString()