diff options
Diffstat (limited to 'internal/game/cmd_shop.go')
| -rw-r--r-- | internal/game/cmd_shop.go | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/internal/game/cmd_shop.go b/internal/game/cmd_shop.go index f3211e0..e2209fc 100644 --- a/internal/game/cmd_shop.go +++ b/internal/game/cmd_shop.go @@ -345,10 +345,25 @@ func (g *Game) doShopSell(sess *net.Session, mob *world.MobInstance, input strin } stock := g.MobStore.ShopStockOf(mob.InstanceID, match.ID) + // Only sell as many as the balance headroom can pay for: grantCredits + // clamps at the economy cap, so selling past it would consume the items + // and destroy the excess credits (the pickup paths take only the headroom). + headroom := creditHeadroom(p) total := 0 + sellQty := 0 for k := 0; k < actualQty; k++ { - total += mob.Shop.SellPrice(value, stock+k) + price := mob.Shop.SellPrice(value, stock+k) + if total+price > headroom { + break + } + total += price + sellQty++ + } + if sellQty <= 0 { + sess.WriteLine("You can't carry any more credits.") + return } + actualQty = sellQty p.RemoveItem(match.ID, actualQty) g.grantCredits(p, total) |
