自动战斗逻辑

This commit is contained in:
fatiao 2026-02-12 20:57:07 +08:00
parent 39097339a9
commit 517ee6981a
2 changed files with 243 additions and 34 deletions

View File

@ -9314,6 +9314,7 @@ BtnSecondeDay,第二天
BtnThirdDay,第三天
LabelWating,待领取
BtnNextTower,挑战下一层
CannotAutoBattle,当前关卡不能自动战斗
stopautobattle,已退出自动挑战
OnlineRewards,你确定使用{0}金币进行加速,立即获得奖励吗?
BtnTomorrow,明日可领

Can't render this file because it is too large.

View File

@ -63,8 +63,206 @@ function UIBattleSuccessView:Init()
end
)
]]
local canEnterAutoMode = self:CanCurrLevelEnterAutoMode()
self.flag = 3
if canEnterAutoMode then
self.currAutoMode = ManagerContainer.LuaBattleMgr:GetAutoChallengeState()
self:AutoBatlle(self.currAutoMode)
else
ManagerContainer.LuaBattleMgr:StopAutoChallenge()
self.currAutoMode = false
self:AutoBatlle(self.currAutoMode)
end
self:AutoBatlle()
self.uiBase:AddButtonUniqueEventListener(self.btn_autofight.button, self, function()
if self.timerId ~= nil then
self.flag = 3
ManagerContainer.LuaTimerMgr:RemoveTimer(self.timerId)
self.timerId = nil
end
if self.currAutoMode then
ManagerContainer.LuaBattleMgr:StopAutoChallenge()
ManagerContainer.LuaBattleMgr:SetAutoChallengeState(false)
self.currAutoMode = false
self:AutoBatlle(false)
else
if not ManagerContainer.DataMgr.RuneShopDataMgr:CheckSuperMonth() then
ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("nomonthcard")
ManagerContainer.LuaBattleMgr:StopAutoChallenge()
return
end
if canEnterAutoMode == false then
ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("CannotAutoBattle")
return
end
if ManagerContainer.LuaBattleMgr:GetAutoChallengeState() then
ManagerContainer.LuaBattleMgr:StopAutoChallenge()
else
ManagerContainer.LuaBattleMgr:SetAutoChallengeState(true)
self.currAutoMode = true
self:AutoBatlle(true)
end
end
end)
end
function UIBattleSuccessView:CanCurrLevelEnterAutoMode()
local curMapId, curLevelId = ManagerContainer.LuaBattleMgr:GetCurMapAndLevel()
local mapLevel = curMapId * 10000 + curLevelId
local storyCfgV2 = ManagerContainer.CfgMgr:GetStoryCfgV2()
local storyTaskCfgV2 = ManagerContainer.CfgMgr:GetStoryTaskCfgV2()
local currStoryId = 10
local levelDiff = 100000
local levelData = ManagerContainer.CfgMgr:GetLevelDataById(mapLevel)
if levelData.DlgId > 0 or levelData.ForceGuideGroup > 0 then
return false
end
local keys = {}
for k in pairs(storyCfgV2) do
if type(k) == "number" then
table.insert(keys, k)
end
end
table.sort(keys)
--此处设置currStoryId和tmpMapLevel
--选择MapLevel最接近但不大于当前mapLevel的故事
for _, k in ipairs(keys) do
local v = storyCfgV2[k]
if v.MapLevel - mapLevel > 0 and v.MapLevel - mapLevel < levelDiff then
currStoryId = v.StoryId
levelDiff = v.MapLevel - mapLevel
end
end
--LogError("[RefreshStoryTaskInfo] currStoryId="..currStoryId..", levelDiff="..levelDiff)
--此处设置currTaskId基于currStoryId从storyTaskCfgV2中查找相同的StoryId返回id
local currTaskId = 0
for k, v in pairs(storyTaskCfgV2) do
if v.StoryId == currStoryId then
currTaskId = v.Id
end
end
if currTaskId == 0 then
LogError("[Err] RefreshStoryTaskInfo currStoryId=" .. currStoryId)
return
end
--获取后两个的StoryId和TaskId
local next1TaskId = currTaskId + 1
local next2TaskId = currTaskId + 2
local next1StoryId = storyTaskCfgV2[next1TaskId].StoryId
local next2StoryId = storyTaskCfgV2[next2TaskId].StoryId
--LogError(string.format("mapLevel=%s currTaskId=%s currStoryId=%s next1StoryId=%s next2StoryId=%s", mapLevel, currTaskId, currStoryId, next1StoryId, next2StoryId))
local subTasksFinishInfo = {}
local subLevelId = 0
for k, v in pairs(storyTaskCfgV2[currTaskId].SubTasks) do
local t = v[1]
local val = v[2]
local isFinish = false
local txt = ""
-- 子任务列表(1:关卡;2:炼之塔层数;3:StoryNpcId;4:StoryId;5:玩家等级)
if t == 1 then
if mapLevel > val then
isFinish = true
end
local levelData = ManagerContainer.CfgMgr:GetLevelDataById(val)
local bossId = levelData.BossId
local npcId = math.floor(bossId / 1000)
local npcData = ManagerContainer.CfgMgr:GetNpcCfgById(npcId)
subLevelId = subLevelId + 1
txt = string.format("关卡%s-%s: 击败BOSS【%s】", math.floor(currStoryId / 10), subLevelId, npcData["Name"])
elseif t == 2 then
local climbingTowerLv = ManagerContainer.DataMgr.TowerDataMgr:GetCurChallengeLevel()
if climbingTowerLv > val then
isFinish = true
end
elseif t == 3 then
local storyNpcId = val
local storyNpcCfg = ManagerContainer.CfgMgr:GetStoryNpcCfgByChatNpcId(tonumber(storyNpcId))
local storyId = storyNpcCfg.StoryId
txt = string.format("去MOMO撩一下女神【%s】", I18N.T(storyNpcCfg.NameKey))
if ManagerContainer.DataMgr.StoryData:IsStoryPlay(storyId) then
isFinish = true
end
elseif t == 4 then
local storyNpcId = val
local storyNpcCfg = ManagerContainer.CfgMgr:GetStoryNpcCfgByChatNpcId(tonumber(storyNpcId))
txt = string.format("回复【%s】发来的消息", I18N.T(storyNpcCfg.NameKey))
local currLevelData = ManagerContainer.CfgMgr:GetLevelDataById(mapLevel)
local storyId = currLevelData.DlgId
LogError("[RefreshStoryTaskInfo] mapLevel="..mapLevel..", storyId="..storyId)
if ManagerContainer.DataMgr.StoryData:IsStoryPlay(storyId) or storyId==0 then
isFinish = true
end
elseif t == 5 then
local curLv = ManagerContainer.DataMgr.UserData:GetRoleLv()
if curLv > val then
isFinish = true
end
end
table.insert(subTasksFinishInfo, { type = t, txt = txt, isFinish = isFinish })
end
local currTaskShowData = {
title = storyCfgV2[currStoryId].StoryTitle,
subTasksFinishInfo = subTasksFinishInfo
}
local next1TaskShowData = {
title = storyCfgV2[next1StoryId].StoryTitle,
subTasksFinishInfo = {}
}
local next2TaskShowData = {
title = storyCfgV2[next2StoryId].StoryTitle,
subTasksFinishInfo = {}
}
local firstUnfinishId = 0
for i = 1, #currTaskShowData.subTasksFinishInfo do
if currTaskShowData.subTasksFinishInfo[i].isFinish == false then
firstUnfinishId = i
break
end
end
local showDatas = {}
if firstUnfinishId > 0 then
table.insert(showDatas, currTaskShowData.subTasksFinishInfo[firstUnfinishId])
end
local step = 1
local loops = 0
while true do
local preId = firstUnfinishId - step
local postId = firstUnfinishId + step
if preId >= 1 then
table.insert(showDatas, 1, currTaskShowData.subTasksFinishInfo[preId])
end
if postId <= #currTaskShowData.subTasksFinishInfo then
table.insert(showDatas, currTaskShowData.subTasksFinishInfo[postId])
end
if preId < 1 and postId > #currTaskShowData.subTasksFinishInfo then
break
end
step = step + 1
loops = loops + 1
if loops > 10000 then break end
end
if loops > 10000 then
LogError("ERR: UIBattle RefreshStoryTaskInfo loops > 10000")
end
local maxRow = #showDatas
if maxRow > 5 then maxRow = 5 end
if currTaskShowData.subTasksFinishInfo[firstUnfinishId] then
local taskType = currTaskShowData.subTasksFinishInfo[firstUnfinishId].type
if taskType == 1 then
return true
end
end
return false
end
function UIBattleSuccessView:AddEventListener()
@ -144,6 +342,14 @@ function UIBattleSuccessView:ShowItemTips(button, params)
end
function UIBattleSuccessView:OnBackBtn()
if self.timerId ~= nil then
ManagerContainer.LuaTimerMgr:RemoveTimer(self.timerId)
self.timerId = nil
end
if ManagerContainer.LuaBattleMgr:GetAutoChallengeState() then
ManagerContainer.LuaBattleMgr:StopAutoChallenge()
end
ManagerContainer.LuaUIMgr:ClosePage(self.uiBase.PageId)
if ManagerContainer.UIFuncUnlockMgr:NeedOpenFuncCurLevelStart(ManagerContainer.LuaBattleMgr:GetCurLevelUniqueId()) then
ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_FUNCLOCK_OPEN_NTF)
@ -152,38 +358,40 @@ function UIBattleSuccessView:OnBackBtn()
--ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_FORCE_GUIDE_TRIGGER, Enum.ForceGuideTriggerEnum.BattleWin)
end
function UIBattleSuccessView:AutoBatlle()
local isauto= ManagerContainer.LuaBattleMgr:GetAutoChallengeState()
function UIBattleSuccessView:AutoBatlle(isauto)
if self.timerId ~= nil then
ManagerContainer.LuaTimerMgr:RemoveTimer(self.timerId)
LogError("remove self.timerId: ".. tostring(self.timerId))
self.timerId = nil
end
LogError("00000 isAuto3 "..tostring(isauto))
self.text_autofight:SetActive(false)
self.text_autofight_time:SetActive(false)
if isauto==true then
local flag=4
if isauto then
--按钮
self.btn_autofight.button.interactable=false
--self.btn_autofight.button.interactable=false
self.btn_autofight.image.sprite=self.btn_autofight.switchSprite:GetSprite("img_result_btn_auto_fighting")
--文字
self.text_autofight_time.text.text = ""..flag.."S"
self.text_autofight_time.text.text = ""..self.flag.."S"
self.text_autofight_time:SetActive(true)
self.flag = 3
self.timerId = ManagerContainer.LuaTimerMgr:AddTimer(1000, self.flag, self, self.TimerTick, nil)
LogError("start self.timerId: ".. tostring(self.timerId))
ManagerContainer.LuaTimerMgr:AddLuaTimer(1000, 4, function()
flag=flag-1
self.text_autofight_time.text.text = "" .. flag .. "S"
if flag==0 then
self:UIClose()
ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_CHALLENGE_AUTO)
end
end)
-- self.timerId = ManagerContainer.LuaTimerMgr:AddLuaTimer(1000, 4, function()
-- flag=flag-1
-- if self.text_autofight_time then
-- self.text_autofight_time.text.text = "" .. flag .. "S"
-- end
-- if flag==0 then
-- self:UIClose()
-- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_CHALLENGE_AUTO)
-- end
-- end)
else
--文字
@ -191,21 +399,21 @@ function UIBattleSuccessView:AutoBatlle()
--按钮
self.btn_autofight.image.sprite = self.btn_autofight.switchSprite:GetSprite("img_result_btn_auto_fight")
self.uiBase:AddButtonUniqueEventListener(self.btn_autofight.button, self, function()
ManagerContainer.LuaBattleMgr:SetAutoChallengeState(true)
ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_CHALLENGE_AUTO)
self:UIClose()
end)
end
end
function UIBattleSuccessView:TimerTick()
self.flag = self.flag or 10
self.flag=self.flag-1
if self.text_autofight_time then
self.text_autofight_time.text.text = "" .. self.flag .. "S"
end
if self.flag==0 then
self:UIClose()
LogError("333333333333333333333")
ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_CHALLENGE_AUTO)
end
end
return UIBattleSuccessView