mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-10 10:20:41 -07:00
Improved accuracy of player wealth calculation
This commit is contained in:
parent
f1e2083506
commit
eeedafe637
3 changed files with 37 additions and 1 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -251,4 +251,4 @@ class GrandExchangeRecords(private val player: Player? = null) : PersistPlayer,
|
|||
return player?.getAttribute("ge-records", GrandExchangeRecords()) ?: GrandExchangeRecords()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue