Skip to content

Commit

Permalink
fix: Prevent infinite purchase from shopkeeper (#56)
Browse files Browse the repository at this point in the history
* Switch order of origin and target storage so that selling stores the item correctly
* Switch to playerResourceStore instead of storage building
  • Loading branch information
askneller committed Apr 12, 2020
1 parent 97c8395 commit 074ea0f
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private MarketItem buy(MarketItem item) {
if (!walletSystem.isValidTransaction(-1 * item.cost)) {
logger.warn("Insufficient funds");
return item;
} else {
} else if (item.quantity > 0) {

if (!createItemOrBlock(item.name)) {
logger.warn("Failed to create entity");
Expand All @@ -206,10 +206,10 @@ private MarketItem buy(MarketItem item) {
handler.availableResourceAmount(component, item.name));

item.quantity--;
localPlayer.getCharacterEntity().send(new UpdateWalletEvent(-1 * item.cost));
break;
}

localPlayer.getCharacterEntity().send(new UpdateWalletEvent(-1 * item.cost));
}

return item;
Expand All @@ -228,12 +228,12 @@ private MarketItem sell(MarketItem item) {
}

SettlementRefComponent settlementRefComponent = bldg.getComponent(SettlementRefComponent.class);
bldg.send(new ResourceStoreEvent(item.name, 1, settlementRefComponent.settlement.getComponent(MarketComponent.class).market));
playerResourceStore.send(new ResourceStoreEvent(item.name, 1, settlementRefComponent.settlement.getComponent(MarketComponent.class).market));
item.quantity--;
localPlayer.getCharacterEntity().send(new UpdateWalletEvent(item.cost));
break;
}

localPlayer.getCharacterEntity().send(new UpdateWalletEvent(item.cost));
return item;
}

Expand Down

0 comments on commit 074ea0f

Please sign in to comment.