Commit 3eb7777532c6afb4f7eba05595481ebf76f3e59d

Authored by wangyujie
1 parent 7f1e84e6

完成友情界面功能

Showing 1 changed file with 44 additions and 12 deletions   Show diff stats
src/actions/HeroAction.lua
@@ -362,23 +362,55 @@ end @@ -362,23 +362,55 @@ end
362 function _M.loveItemRpc(agent, data) 362 function _M.loveItemRpc(agent, data)
363 local role = agent.role 363 local role = agent.role
364 local msg = MsgPack.unpack(data) 364 local msg = MsgPack.unpack(data)
365 - local hero = role.heros[msg.id]  
366 - if not hero then return end  
367 - local result = {} 365 + local hero = role.heros[msg.heroId]
  366 + if not hero then
  367 + return
  368 + end
368 local curL = hero:getProperty("loveL") 369 local curL = hero:getProperty("loveL")
369 local curExp = hero:getProperty("loveExp") 370 local curExp = hero:getProperty("loveExp")
370 local curPlus = csvdb["unit_love_plusCsv"][hero:getProperty("type")] 371 local curPlus = csvdb["unit_love_plusCsv"][hero:getProperty("type")]
371 - if not curPlus or curL >= curPlus.limit then return end  
372 - 372 + if not curPlus then
  373 + return
  374 + end
  375 + if curL >= curPlus.limit then
  376 + SendPacket(actionCodes.Hero_loveItemRpc, MsgPack.pack({errMsg = 1})) --已满级
  377 + return true
  378 + end
373 local curEffect = csvdb["unit_love_effectCsv"][curL] 379 local curEffect = csvdb["unit_love_effectCsv"][curL]
374 - if not curEffect or curExp >= curEffect.loveValue then return end  
375 - local delta = 100 -- todo  
376 - local newExp = curExp + delta  
377 - hero:updateProperty({field = "loveExp", value = newExp})  
378 - if newExp >= curEffect.loveValue then  
379 - -- todo 发任务 380 + if not curEffect then
  381 + return
  382 + end
  383 + if curExp >= curEffect.loveValue and not msg.bBreak then
  384 + SendPacket(actionCodes.Hero_loveItemRpc, MsgPack.pack({errMsg = 2})) --当前等级经验已满
  385 + return true
  386 + end
  387 +
  388 + if msg.bBreak then
  389 + local cost = curEffect.cost:toArray(true, "=")
  390 + if not role:checkItemEnough({[cost[1]] = cost[2]}) then
  391 + SendPacket(actionCodes.Hero_loveItemRpc, MsgPack.pack({errMsg = 3, itemId = cost[1]})) --物品不足
  392 + return true
  393 + end
  394 + role:costItems({[cost[1]] = cost[2]})
  395 + hero:updateProperty({field = "loveL", value = curL + 1})
  396 + hero:updateProperty({field = "loveExp", value = 0})
  397 + else
  398 + local delta = globalCsv.unit_love_presentValue[msg.itemId]
  399 + if not delta then
  400 + return
  401 + end
  402 + if not role:checkItemEnough({[msg.itemId] = 1}) then
  403 + SendPacket(actionCodes.Hero_loveItemRpc, MsgPack.pack({errMsg = 3, itemId = msg.itemId}))
  404 + return true
  405 + end
  406 + local newExp = curExp + delta
  407 + if newExp > curEffect.loveValue then
  408 + newExp = curEffect.loveValue
  409 + end
  410 + role:costItems({[msg.itemId] = 1})
  411 + hero:updateProperty({field = "loveExp", value = newExp})
380 end 412 end
381 - SendPacket(actionCodes.Hero_loveItemRpc, MsgPack.pack({delta = delta})) 413 + SendPacket(actionCodes.Hero_loveItemRpc, "")
382 return true 414 return true
383 end 415 end
384 416