diff --git a/Server/src/main/core/game/ge/GrandExchangeOffer.kt b/Server/src/main/core/game/ge/GrandExchangeOffer.kt index d27f7f431..3a7522919 100644 --- a/Server/src/main/core/game/ge/GrandExchangeOffer.kt +++ b/Server/src/main/core/game/ge/GrandExchangeOffer.kt @@ -237,4 +237,22 @@ class GrandExchangeOffer() { return o } } + + fun cacheValue(): Int { + var value = 0 + if(sell) { + // count the cache value of the unsold items + value += ItemDefinition.forId(itemID).getValue() * amountLeft + } else { + // count the number of coins that haven't yet been spent + value += offeredValue * amountLeft + } + // for both the buyer and seller, the already completed portion is present in withdraw + for(item in withdraw) { + if(item != null) { + value += item.definition.value * item.amount + } + } + return value + } } diff --git a/Server/src/main/core/game/ge/GrandExchangeRecords.kt b/Server/src/main/core/game/ge/GrandExchangeRecords.kt index cf31406b0..49fe56a73 100644 --- a/Server/src/main/core/game/ge/GrandExchangeRecords.kt +++ b/Server/src/main/core/game/ge/GrandExchangeRecords.kt @@ -251,4 +251,4 @@ class GrandExchangeRecords(private val player: Player? = null) : PersistPlayer, return player?.getAttribute("ge-records", GrandExchangeRecords()) ?: GrandExchangeRecords() } } -} \ No newline at end of file +} diff --git a/Server/src/main/core/game/node/entity/player/Player.java b/Server/src/main/core/game/node/entity/player/Player.java index 824b13c9b..cf16dde2c 100644 --- a/Server/src/main/core/game/node/entity/player/Player.java +++ b/Server/src/main/core/game/node/entity/player/Player.java @@ -77,6 +77,9 @@ import core.game.world.update.MapChunkRenderer; import core.game.world.update.NPCRenderer; import core.game.world.update.PlayerRenderer; import core.game.world.update.UpdateSequence; +import core.game.ge.GrandExchangeRecords; +import core.game.ge.GrandExchangeOffer; +import core.cache.def.impl.ItemDefinition; import core.worker.ManagementEvents; import java.util.*; @@ -494,6 +497,21 @@ public class Player extends Entity { if (i == null) break; totalWealth += (long) i.getDefinition().getValue() * i.getAmount(); } + GrandExchangeRecords ge = GrandExchangeRecords.getInstance(this); + for (int i=0; i<6; i++) { + GrandExchangeOffer offer = ge.getOffer(i); + if (offer != null) { + totalWealth += offer.cacheValue(); + } + } + + // This can lead to a false positive of up to 3 * 187.5k, but only for 3 ticks while a cannon is being constructed + if (this.getAttribute("dmc", null) != null) { + totalWealth += ItemDefinition.forId(Items.CANNON_BASE_6).getValue(); + totalWealth += ItemDefinition.forId(Items.CANNON_STAND_8).getValue(); + totalWealth += ItemDefinition.forId(Items.CANNON_BARRELS_10).getValue(); + totalWealth += ItemDefinition.forId(Items.CANNON_FURNACE_12).getValue(); + } long diff = previousWealth == -1 ? 0L : totalWealth - previousWealth; setAttribute("/save:last-wealth", totalWealth);