|
|
@@ -0,0 +1,220 @@
|
|
|
+------------------------------------------------------
|
|
|
+-- 战意逻辑
|
|
|
+------------------------------------------------------
|
|
|
+
|
|
|
+local Lang = require("common.Lang")
|
|
|
+local Util = require("common.Util")
|
|
|
+local Msg = require("core.Msg")
|
|
|
+local ObjHuman = require("core.ObjHuman")
|
|
|
+local Broadcast = require("broadcast.Broadcast")
|
|
|
+local Grid = require("bag.Grid")
|
|
|
+local BagLogic = require("bag.BagLogic")
|
|
|
+local ItemDefine = require("bag.ItemDefine")
|
|
|
+local HeroLogic = require("hero.HeroLogic")
|
|
|
+local Log = require("common.Log")
|
|
|
+
|
|
|
+-- 战意回退配置
|
|
|
+local BATTLE_WILL_ROLLBACK_CONFIG = {
|
|
|
+ [1] = { -- 初级
|
|
|
+ needItemID = 1050, -- 消耗道具ID
|
|
|
+ needItemCnt = 1, -- 消耗数量:1个
|
|
|
+ returnBattleWillID = 0, -- 返还战意道具ID(需要确认实际ID)
|
|
|
+ returnBattleWillCnt = 1, -- 返还战意:1个
|
|
|
+ returnFragmentID = 0, -- 返还战意碎片道具ID(需要确认实际ID)
|
|
|
+ returnFragmentCnt = 0, -- 返还战意碎片:0
|
|
|
+ returnAncientSpiritID = 0, -- 返还远古之灵道具ID(需要确认实际ID)
|
|
|
+ returnAncientSpiritCnt = 0 -- 返还远古之灵:0
|
|
|
+ },
|
|
|
+ [2] = { -- 中级
|
|
|
+ needItemID = 1050,
|
|
|
+ needItemCnt = 5, -- 消耗数量:5个
|
|
|
+ returnBattleWillID = 0,
|
|
|
+ returnBattleWillCnt = 4, -- 返还战意:4个
|
|
|
+ returnFragmentID = 0,
|
|
|
+ returnFragmentCnt = 10000, -- 返还战意碎片:10,000
|
|
|
+ returnAncientSpiritID = 0,
|
|
|
+ returnAncientSpiritCnt = 0
|
|
|
+ },
|
|
|
+ [3] = { -- 高级
|
|
|
+ needItemID = 1050,
|
|
|
+ needItemCnt = 12, -- 消耗数量:12个
|
|
|
+ returnBattleWillID = 0,
|
|
|
+ returnBattleWillCnt = 9, -- 返还战意:9个
|
|
|
+ returnFragmentID = 0,
|
|
|
+ returnFragmentCnt = 40000, -- 返还战意碎片:40,000
|
|
|
+ returnAncientSpiritID = 0,
|
|
|
+ returnAncientSpiritCnt = 0
|
|
|
+ },
|
|
|
+ [4] = { -- 超级
|
|
|
+ needItemID = 1050,
|
|
|
+ needItemCnt = 50, -- 消耗数量:50个
|
|
|
+ returnBattleWillID = 0,
|
|
|
+ returnBattleWillCnt = 19, -- 返还战意:19个
|
|
|
+ returnFragmentID = 0,
|
|
|
+ returnFragmentCnt = 90000, -- 返还战意碎片:90,000
|
|
|
+ returnAncientSpiritID = 0,
|
|
|
+ returnAncientSpiritCnt = 100 -- 返还远古之灵:100
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+-- 获取战意格子数据
|
|
|
+-- 假设战意数据存储在 heroGrid.battleWill[index] 中,包含 level 字段
|
|
|
+function getBattleWillGrid(heroGrid, index)
|
|
|
+ if not heroGrid then return end
|
|
|
+ if not heroGrid.battleWill then return end
|
|
|
+ return index and heroGrid.battleWill[index]
|
|
|
+end
|
|
|
+
|
|
|
+-- 获取战意等级
|
|
|
+function getBattleWillLevel(heroGrid, index)
|
|
|
+ local grid = getBattleWillGrid(heroGrid, index)
|
|
|
+ if not grid then return 0 end
|
|
|
+ return grid.level or 0
|
|
|
+end
|
|
|
+
|
|
|
+-- 查询回退信息
|
|
|
+function sendRollbackQuery(human, heroID, heroIndex, index)
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[sendRollbackQuery] 收到查询请求: heroID="..(heroID or "nil")..", heroIndex="..(heroIndex or "nil")..", index="..(index or "nil"))
|
|
|
+
|
|
|
+ local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
|
|
|
+ if not heroGrid then
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[sendRollbackQuery] 英雄不存在")
|
|
|
+ return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
|
|
|
+ end
|
|
|
+
|
|
|
+ local currentLevel = getBattleWillLevel(heroGrid, index)
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[sendRollbackQuery] 当前战意等级: "..currentLevel)
|
|
|
+
|
|
|
+ -- 检查等级是否可回退(等级0为空,不可回退)
|
|
|
+ if currentLevel == 0 or currentLevel < 1 or currentLevel > 4 then
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[sendRollbackQuery] 当前等级不可回退: level="..currentLevel)
|
|
|
+ return Broadcast.sendErr(human, "当前战意格子为空,无法回退")
|
|
|
+ end
|
|
|
+
|
|
|
+ local config = BATTLE_WILL_ROLLBACK_CONFIG[currentLevel]
|
|
|
+ if not config then
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[sendRollbackQuery] 配置不存在: level="..currentLevel)
|
|
|
+ return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
|
|
|
+ end
|
|
|
+
|
|
|
+ local msgRet = Msg.gc.GC_BATTLE_WILL_ROLLBACK_QUERY
|
|
|
+ msgRet.heroID = heroID
|
|
|
+ msgRet.heroIndex = heroIndex
|
|
|
+ msgRet.index = index
|
|
|
+ msgRet.currentLevel = currentLevel
|
|
|
+ msgRet.targetLevel = 0 -- 回退后等级固定为0(空)
|
|
|
+
|
|
|
+ -- 消耗道具
|
|
|
+ Grid.makeItem(msgRet.needItem, config.needItemID, config.needItemCnt)
|
|
|
+
|
|
|
+ -- 返还物品列表
|
|
|
+ msgRet.returnItems[0] = 0
|
|
|
+ local itemCnt = 0
|
|
|
+
|
|
|
+ -- 返还战意
|
|
|
+ if config.returnBattleWillCnt > 0 and config.returnBattleWillID > 0 then
|
|
|
+ itemCnt = itemCnt + 1
|
|
|
+ if itemCnt <= #msgRet.returnItems then
|
|
|
+ Grid.makeItem(msgRet.returnItems[itemCnt], config.returnBattleWillID, config.returnBattleWillCnt)
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 返还战意碎片
|
|
|
+ if config.returnFragmentCnt > 0 and config.returnFragmentID > 0 then
|
|
|
+ itemCnt = itemCnt + 1
|
|
|
+ if itemCnt <= #msgRet.returnItems then
|
|
|
+ Grid.makeItem(msgRet.returnItems[itemCnt], config.returnFragmentID, config.returnFragmentCnt)
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 返还远古之灵
|
|
|
+ if config.returnAncientSpiritCnt > 0 and config.returnAncientSpiritID > 0 then
|
|
|
+ itemCnt = itemCnt + 1
|
|
|
+ if itemCnt <= #msgRet.returnItems then
|
|
|
+ Grid.makeItem(msgRet.returnItems[itemCnt], config.returnAncientSpiritID, config.returnAncientSpiritCnt)
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ msgRet.returnItems[0] = itemCnt
|
|
|
+
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[sendRollbackQuery] 发送查询结果: currentLevel="..currentLevel..", needItemCnt="..config.needItemCnt..", returnItemsCount="..itemCnt)
|
|
|
+ Msg.send(msgRet, human.fd)
|
|
|
+end
|
|
|
+
|
|
|
+-- 执行回退
|
|
|
+function rollback(human, heroID, heroIndex, index)
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[rollback] 收到回退请求: heroID="..(heroID or "nil")..", heroIndex="..(heroIndex or "nil")..", index="..(index or "nil"))
|
|
|
+
|
|
|
+ local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
|
|
|
+ if not heroGrid then
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[rollback] 英雄不存在")
|
|
|
+ return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
|
|
|
+ end
|
|
|
+
|
|
|
+ local currentLevel = getBattleWillLevel(heroGrid, index)
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[rollback] 当前战意等级: "..currentLevel)
|
|
|
+
|
|
|
+ -- 检查等级是否可回退
|
|
|
+ if currentLevel == 0 or currentLevel < 1 or currentLevel > 4 then
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[rollback] 当前等级不可回退: level="..currentLevel)
|
|
|
+ return Broadcast.sendErr(human, "当前战意格子为空,无法回退")
|
|
|
+ end
|
|
|
+
|
|
|
+ local config = BATTLE_WILL_ROLLBACK_CONFIG[currentLevel]
|
|
|
+ if not config then
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[rollback] 配置不存在: level="..currentLevel)
|
|
|
+ return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 检查消耗道具
|
|
|
+ if not BagLogic.checkItemCnt(human, config.needItemID, config.needItemCnt) then
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[rollback] 消耗道具不足: needItemID="..config.needItemID..", needItemCnt="..config.needItemCnt)
|
|
|
+ return Broadcast.sendErr(human, Lang.COMMON_NO_ITEM)
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 扣除消耗道具
|
|
|
+ BagLogic.delItem(human, config.needItemID, config.needItemCnt, "battleWill_rollback")
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[rollback] 扣除消耗道具: needItemID="..config.needItemID..", needItemCnt="..config.needItemCnt)
|
|
|
+
|
|
|
+ -- 收集返还物品
|
|
|
+ local returnItemList = {}
|
|
|
+
|
|
|
+ -- 返还战意
|
|
|
+ if config.returnBattleWillCnt > 0 and config.returnBattleWillID > 0 then
|
|
|
+ returnItemList[config.returnBattleWillID] = config.returnBattleWillCnt
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 返还战意碎片
|
|
|
+ if config.returnFragmentCnt > 0 and config.returnFragmentID > 0 then
|
|
|
+ returnItemList[config.returnFragmentID] = config.returnFragmentCnt
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 返还远古之灵
|
|
|
+ if config.returnAncientSpiritCnt > 0 and config.returnAncientSpiritID > 0 then
|
|
|
+ returnItemList[config.returnAncientSpiritID] = config.returnAncientSpiritCnt
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 发放返还物品(使用通用道具发放逻辑)
|
|
|
+ if next(returnItemList) then
|
|
|
+ BagLogic.addItemList(human, returnItemList, "battleWill_rollback")
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[rollback] 发放返还物品")
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 更新战意等级为0(清空)
|
|
|
+ if not heroGrid.battleWill then
|
|
|
+ heroGrid.battleWill = {}
|
|
|
+ end
|
|
|
+ if not heroGrid.battleWill[index] then
|
|
|
+ heroGrid.battleWill[index] = {}
|
|
|
+ end
|
|
|
+ heroGrid.battleWill[index].level = 0
|
|
|
+
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[rollback] 回退完成: 等级从 "..currentLevel.." 变为 0")
|
|
|
+
|
|
|
+ -- 重新计算英雄属性
|
|
|
+ ObjHuman.doCalcHero(human, heroIndex)
|
|
|
+
|
|
|
+ -- 发送英雄数据更新(如果需要)
|
|
|
+ HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
|
|
|
+end
|
|
|
+
|