local Base = require("Battle/Logic/Level/LevelFunction/LevelFunction") local DigTreasureLevelFunction = class("DigTreasureLevelFunction",Base) local EventSystem = require('Event/EventSystem') local REWARD_BOX_FEATURE_ID_MIN = 91 local REWARD_BOX_FEATURE_ID_MAX = 93 function DigTreasureLevelFunction:InitLevel() Base.InitLevel(self) --切换到自动开宝箱所需静止时长 self.advancedDigNormalChangeToAutoCountdownStaticFrameNeed = DataSheetManager.ConstData:GetDataByID("DigForTreasureStatic").IntValue * LuaConst.LogicFrameRate self.advancedDigNormalAutoCountdownFrameNeed = DataSheetManager.ConstData:GetDataByID("DigForTreasureCountDown").IntValue * LuaConst.LogicFrameRate self.isAutoOpenedRewardBox = false self.lastMainEntityPos = FP.newV2(0, 0) self.lastMainEntityID = nil self.lastMoveFrame = 0 self.autoOpenRewardBoxFrameCountdownStart = nil end function DigTreasureLevelFunction:OnCreatePlayer() Base.OnCreatePlayer(self) local selectIndex = 1 for i=LuaConst.BattleSettingEnum.AutoOpenRewardBoxWater, LuaConst.BattleSettingEnum.AutoOpenRewardBoxWood do if LevelPlayerManager.GetPlayerSetting(LuaConst.STANDALONE_PLAYER_PlayID, i) then --主视角safe,单机玩法 selectIndex = i - LuaConst.BattleSettingEnum.AutoOpenRewardBoxWater + 1 break end end self.autoOpenRewardBoxIndex = selectIndex end function DigTreasureLevelFunction:OnPlayerAllHeroDead(entity) local heroEntitys = LevelPlayerManager.GetPlayerEntitysByPlayerIDInRoom(entity._logicInitData.PlayerIDInRoom) if heroEntitys then for i,heroEntity in ipairs(heroEntitys) do SystemManager.OnRevive(heroEntity,true) if i == 1 then local ctrlParam = RuntimeDataManager.New_BuffCtrl() ctrlParam.ForceDuration:Reset(1) heroEntity.components.skillBase.NeedReleaseGetInSkill = true SystemManager.AddBuff(heroEntity,500000, entity, nil, ctrlParam) --ugly 复活后强行加一个无敌buff,防止被眩晕打断入场技 --临时代码,之后会改掉 end end end end function DigTreasureLevelFunction:GetLevelAutoFightInitRule() --单机挖宝副本默认开启自动战斗 return LuaConst.ELevelAutoFightInitRule.LOAD_DEFAULT_OPEN end function DigTreasureLevelFunction:CheckIsRewardBoxShowedAndNotOpened() local treasureBoxCount = 0 for i,v in ipairs(LogicUpdateManager.EntityList_Normal) do if v:GetFeatureID() >= REWARD_BOX_FEATURE_ID_MIN and v:GetFeatureID() <= REWARD_BOX_FEATURE_ID_MAX then treasureBoxCount = treasureBoxCount + 1 end end return treasureBoxCount == 3 end function DigTreasureLevelFunction:OnUpdate() Base.OnUpdate(self) if LogicUpdateManager._curEntity then --主视角safe, 因为是单机玩法 if self.lastMainEntityPos ~= LogicUpdateManager._curEntity:GetLogicPos() or self.lastMainEntityID ~= LogicUpdateManager._curEntity.EntityID then self.lastMoveFrame = LogicUpdateManager._clientHandleFrame self.autoOpenRewardBoxFrameCountdownStart = nil end self.lastMainEntityPos:Reset(LogicUpdateManager._curEntity:GetLogicPos()) self.lastMainEntityID = LogicUpdateManager._curEntity.EntityID if not self.triedAutoOpenRewardBoxCurFrame then self:ClearAutoOpenRewardBox() end self.triedAutoOpenRewardBoxCurFrame = false end end function DigTreasureLevelFunction:TryAutoOpenRewardBox(entity, decisionRecordDic) self.triedAutoOpenRewardBoxCurFrame = true if not self.isAutoOpenedRewardBox then if self:CheckIsRewardBoxShowedAndNotOpened() then if LogicUpdateManager._clientHandleFrame - self.lastMoveFrame >= self.advancedDigNormalChangeToAutoCountdownStaticFrameNeed then if self.autoOpenRewardBoxFrameCountdownStart then self:OpenRewardBoxCountdown() else self.autoOpenRewardBoxFrameCountdownStart = LogicUpdateManager._clientHandleFrame end else self.autoOpenRewardBoxFrameCountdownStart = nil end end end end function DigTreasureLevelFunction:OpenRewardBoxCountdown() local countDownframeEla = LogicUpdateManager._clientHandleFrame - self.autoOpenRewardBoxFrameCountdownStart if countDownframeEla >= self.advancedDigNormalAutoCountdownFrameNeed then self.isAutoOpenedRewardBox = true self:AutoOpenRewardBoxBySetting(entity) elseif countDownframeEla % 20 == 0 and countDownframeEla > 0 then EventSystem.Dispatch(EventID.DigTreasure_AutoOpenBoxCountdownSecond, self.advancedDigNormalAutoCountdownFrameNeed - countDownframeEla, self.autoOpenRewardBoxIndex) end end function DigTreasureLevelFunction:AutoOpenRewardBoxBySetting() EventSystem.Dispatch(EventID.DigTreasure_AutoOpenBox, self.autoOpenRewardBoxIndex) for i,v in ipairs(LogicUpdateManager.EntityList_Normal) do if v:GetFeatureID() == REWARD_BOX_FEATURE_ID_MIN + self.autoOpenRewardBoxIndex - 1 then SystemManager.DeadQuit(v) break end end LevelItemManager.Global:HandleEndLevel(true, false, nil, true) end function DigTreasureLevelFunction:ClearAutoOpenRewardBox() self.autoOpenRewardBoxFrameCountdownStart = nil self.lastMoveFrame = LogicUpdateManager._clientHandleFrame end return DigTreasureLevelFunction