diff --git a/src/actions/HeroAction.lua b/src/actions/HeroAction.lua index 0cbe33c..d5168e7 100644 --- a/src/actions/HeroAction.lua +++ b/src/actions/HeroAction.lua @@ -362,23 +362,55 @@ end function _M.loveItemRpc(agent, data) local role = agent.role local msg = MsgPack.unpack(data) - local hero = role.heros[msg.id] - if not hero then return end - local result = {} + local hero = role.heros[msg.heroId] + if not hero then + return + end local curL = hero:getProperty("loveL") local curExp = hero:getProperty("loveExp") local curPlus = csvdb["unit_love_plusCsv"][hero:getProperty("type")] - if not curPlus or curL >= curPlus.limit then return end - + if not curPlus then + return + end + if curL >= curPlus.limit then + SendPacket(actionCodes.Hero_loveItemRpc, MsgPack.pack({errMsg = 1})) --已满级 + return true + end local curEffect = csvdb["unit_love_effectCsv"][curL] - if not curEffect or curExp >= curEffect.loveValue then return end - local delta = 100 -- todo - local newExp = curExp + delta - hero:updateProperty({field = "loveExp", value = newExp}) - if newExp >= curEffect.loveValue then - -- todo 发任务 + if not curEffect then + return + end + if curExp >= curEffect.loveValue and not msg.bBreak then + SendPacket(actionCodes.Hero_loveItemRpc, MsgPack.pack({errMsg = 2})) --当前等级经验已满 + return true + end + + if msg.bBreak then + local cost = curEffect.cost:toArray(true, "=") + if not role:checkItemEnough({[cost[1]] = cost[2]}) then + SendPacket(actionCodes.Hero_loveItemRpc, MsgPack.pack({errMsg = 3, itemId = cost[1]})) --物品不足 + return true + end + role:costItems({[cost[1]] = cost[2]}) + hero:updateProperty({field = "loveL", value = curL + 1}) + hero:updateProperty({field = "loveExp", value = 0}) + else + local delta = globalCsv.unit_love_presentValue[msg.itemId] + if not delta then + return + end + if not role:checkItemEnough({[msg.itemId] = 1}) then + SendPacket(actionCodes.Hero_loveItemRpc, MsgPack.pack({errMsg = 3, itemId = msg.itemId})) + return true + end + local newExp = curExp + delta + if newExp > curEffect.loveValue then + newExp = curEffect.loveValue + end + role:costItems({[msg.itemId] = 1}) + hero:updateProperty({field = "loveExp", value = newExp}) end - SendPacket(actionCodes.Hero_loveItemRpc, MsgPack.pack({delta = delta})) + SendPacket(actionCodes.Hero_loveItemRpc, "") return true end -- libgit2 0.21.2