Skip to content

Commit

Permalink
Make creatures drop extra gold they cant handle
Browse files Browse the repository at this point in the history
  • Loading branch information
tonihele committed Jul 8, 2024
1 parent b2a0609 commit e106880
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,21 @@ public void resetReEvaluationTimer() {
@Override
public void addGold(int amount) {
Gold gold = entityData.getComponent(entityId, Gold.class);
entityData.setComponent(entityId, new Gold(gold.gold + amount, gold.maxGold));

// Drop excess gold, we can only carry so much
boolean hasMaxGold = gold.maxGold > 0;
int maxGoldCanAdd = hasMaxGold ? gold.maxGold - gold.gold : Integer.MAX_VALUE;
int goldToAdd = Math.min(amount, maxGoldCanAdd);
int looseGold = amount - goldToAdd;

if (goldToAdd > 0) {
entityData.setComponent(entityId, new Gold(gold.gold + goldToAdd, gold.maxGold));
}

if (looseGold > 0) {
Point coordinates = getCreatureCoordinates();
objectsController.addLooseGold(getOwnerId(), coordinates.x, coordinates.y, looseGold, (int) gameSettings.get(Variable.MiscVariable.MiscType.MAX_GOLD_PILE_OUTSIDE_TREASURY).getValue());
}
}

@Override
Expand Down

0 comments on commit e106880

Please sign in to comment.