ludic/packages/ludic.gear/buy.ludic

25 lines
906 B
Text

# buy.ludic - a tier bought with money once the standing is there; the kind's item follows
export function gear_can_buy(k: int) -> bool {
if not gear_ok(k) or gear_best(k) or GearWorld.hidden(k) { return false }
return GearPurse.rep() >= gear_next_rep(k) and GearPurse.money() >= gear_next_cost(k)
}
export function gear_buy(k: int) -> bool {
if not gear_can_buy(k) { return false }
let cost = gear_next_cost(k)
if not GearPurse.spend(cost) { return false }
gear__lv[k] += 1
let it = GearKinds[k].item
if it >= 0 and GearPack.count(it) == 0 { GearPack.add(it, 1) }
gear__fact(GEAR_BOUGHT, k, -1, cost)
return true
}
# a kind whose item is already carried counts as its first tier
export function gear_sync() -> void {
gear__ensure()
for k in 0 .. GEAR_COUNT {
let it = GearKinds[k].item
if it >= 0 and gear__lv[k] == 0 and GearPack.count(it) > 0 { gear__lv[k] = 1 }
}
}