|
@@ -29,7 +29,7 @@ function State.new()
|
|
|
level = 1,
|
|
level = 1,
|
|
|
exp = 0,
|
|
exp = 0,
|
|
|
talents = {},
|
|
talents = {},
|
|
|
- _pendingTalent = false,
|
|
|
|
|
|
|
+ _pendingTalent = 0, -- 待选天赋点数(连续升级累加)
|
|
|
race = nil, -- 种族 id
|
|
race = nil, -- 种族 id
|
|
|
class = nil, -- 职业 id
|
|
class = nil, -- 职业 id
|
|
|
stamina = 50, -- 当前精力
|
|
stamina = 50, -- 当前精力
|
|
@@ -134,9 +134,12 @@ function State.buyItem(state, itemId)
|
|
|
local stats = TalentStats.fromState(state)
|
|
local stats = TalentStats.fromState(state)
|
|
|
local price = math.ceil(item.price * (stats.shopBuyDiscount or 1))
|
|
local price = math.ceil(item.price * (stats.shopBuyDiscount or 1))
|
|
|
if state.money < price then return false, "金币不足" end
|
|
if state.money < price then return false, "金币不足" end
|
|
|
|
|
+ -- 先确认背包能容纳(同类可堆叠或存在空位),避免扣款后放不下
|
|
|
|
|
+ local inv = state.inventory
|
|
|
|
|
+ local canAdd = inv:findSlot("item", itemId) ~= nil or inv:findEmpty() ~= nil
|
|
|
|
|
+ if not canAdd then return false, "背包已满" end
|
|
|
state.money = state.money - price
|
|
state.money = state.money - price
|
|
|
- local idx = state.inventory:addItem(itemId, 1)
|
|
|
|
|
- if not idx then return false, "背包已满" end
|
|
|
|
|
|
|
+ inv:addItem(itemId, 1)
|
|
|
Bus.emit("item_bought", { itemId=itemId })
|
|
Bus.emit("item_bought", { itemId=itemId })
|
|
|
return true
|
|
return true
|
|
|
end
|
|
end
|
|
@@ -230,7 +233,7 @@ function State.addExp(state, amount)
|
|
|
if state.exp >= nextExp then
|
|
if state.exp >= nextExp then
|
|
|
state.exp = state.exp - nextExp
|
|
state.exp = state.exp - nextExp
|
|
|
state.level = lv + 1
|
|
state.level = lv + 1
|
|
|
- state._pendingTalent = true
|
|
|
|
|
|
|
+ state._pendingTalent = (state._pendingTalent or 0) + 1
|
|
|
leveled = true
|
|
leveled = true
|
|
|
Bus.emit("player_levelup", { level = state.level })
|
|
Bus.emit("player_levelup", { level = state.level })
|
|
|
else
|
|
else
|
|
@@ -276,7 +279,8 @@ function State.pickTalent(state, talentId)
|
|
|
local maxS = def.maxStack or 99
|
|
local maxS = def.maxStack or 99
|
|
|
if stack >= maxS then return false end
|
|
if stack >= maxS then return false end
|
|
|
state.talents[talentId] = stack + 1
|
|
state.talents[talentId] = stack + 1
|
|
|
- state._pendingTalent = false
|
|
|
|
|
|
|
+ -- 消耗一个待选点数;剩余点数由 game.lua 继续弹面板
|
|
|
|
|
+ state._pendingTalent = math.max(0, (state._pendingTalent or 0) - 1)
|
|
|
Bus.emit("talent_picked", { talentId = talentId })
|
|
Bus.emit("talent_picked", { talentId = talentId })
|
|
|
return true
|
|
return true
|
|
|
end
|
|
end
|