local ChangAnSiege_Controller = {} --Modules\ChangAnSiege\ChangAnSiege_Controller.lua local EventSystem = require('Event/EventSystem') local private = {} local SiegeCityGoodsID = DataSheetManager.ConstData:GetDataByID("SiegeCityGoodsID").IntValue local EntityHeadUIModule = require("View/Battle/BattleEntityUI/EntityUIModule/EntityHeadUIModule") ChangAnSiege_Controller.commandRedPoint = true -- 指挥按钮红点(仅登录显示一次) function ChangAnSiege_Controller.OnStartup() EventSystem.Regist(EventID.VoiceRoom_OnServerRoomInitStateResp, private.OnServerRoomInitStateResp) EventSystem.Regist(EventID.ChangAnSiege_StageChanged, private.OpenChangAnSiegeRemind) EventSystem.Regist(EventID.FunctionUnlockUpdate, private.OnFunctionUnlockUpdate) EventSystem.Regist(EventID.UI_MainShowDialogue, private.OnShowMainDialogue) EventSystem.Regist(EventID.Level_InitLevel, private.OnInitLevel) EventSystem.Regist(EventID.UI_ChangAnSiege_RefreshCurrency, private.OnSiegeCityGoodsRefresh) EventSystem.Regist(EventID.Country_OnGetFoundCountry, private.OpenChangAnSiegeBattleGround) EventSystem.Regist(EventID.ChangAnSiege_TowerAttackSelf, private.OnTowerAttackSelf) EventSystem.Regist(EventID.AfterTownLevelBegin, private.UpdateActivityEntryRed) EventSystem.Regist(EventID.TimerWheelStartTimeOver, private.UpdateActivityEntryRed) EventSystem.Regist(EventID.TimerWheelEndTimeOver, private.UpdateActivityEntryRed) private.playTowerEffectDict = {} end function private.OnShowMainDialogue(dialogueID, callback, context, entity) if dialogueID == "Tip_ChangAnSiege_622001_02" then EventSystem.Dispatch(EventID.BI_LevelMiddle, BIManager.BIType.ChangAnSiegeChongceArrive, BattleDataGetter.GetCurFrameIndex()) end end function private.OnFunctionUnlockUpdate(fucId, isUnlock) if fucId == MDL.Unlock.FunctionType.ChangAnSiege and not isUnlock then if not isUnlock then ChangAnSiege_Controller.CloseChangAnSiegeView() else private.OpenChangAnSiegeRemind() end end end function private.OnServerRoomInitStateResp(roomType) if roomType == MDL.VoiceRoom.VoiceRoomType.ChangAnSiege then local listenerState, microState = MDL.VoiceRoom.GetVoiceRoomInitState(roomType) local roomId = MDL.ChangAnSiege.GetChatChannel() CTL.VoiceRoom.EnterVoiceRoom(MDL.VoiceRoom.VoiceRoomType.ChangAnSiege, roomId, listenerState, microState and MDL.ChangAnSiege.IsBattleLeader()) MDL.VoiceRoom.VoiceCallSetStateReq(roomType, microState and MDL.ChangAnSiege.IsBattleLeader(), listenerState) end end function ChangAnSiege_Controller.OpenMainView() if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.ChangAnSiege) then CTL.Tips.AddTipsMsg(Const_IDS.IDS_BossChallenge_NotOpen) elseif MDL.ChangAnSiege.GetCurStage() == nil or MDL.ChangAnSiege.GetCurStage() == MDL.ChangAnSiege.SiegeCitySeasonStage.None then CTL.Tips.AddTipsMsg(Const_IDS.IDS_7DayActivity_Hint_6) else UIManager.OpenView(Const_UI_Lua.UIEnum.UIChangAnSiegeMain) end end ---是否开启 且不是展示阶段 function ChangAnSiege_Controller.IsOpen() if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.ChangAnSiege) then return MDL.ChangAnSiege.GetCurStage() ~= nil and MDL.ChangAnSiege.GetCurStage() ~= MDL.ChangAnSiege.SiegeCitySeasonStage.None and not MDL.ChangAnSiege.IsLastBattle() end return false end function ChangAnSiege_Controller.CloseChangAnSiegeView() UIManager.CloseView(Const_UI_Lua.UIEnum.UIChangAnSiegeMain) UIManager.CloseView(Const_UI_Lua.UIEnum.UIChangAnSiegeBattleArray) UIManager.CloseView(Const_UI_Lua.UIEnum.UIChangAnSiegeSelectOfficer) UIManager.CloseView(Const_UI_Lua.UIEnum.UIChangAnSiegeReward) UIManager.CloseView(Const_UI_Lua.UIEnum.UIChangAnSiegeTaxation) end function ChangAnSiege_Controller.IsDefendCamp() return BattleDataGetter.GetMyCampID() == BattleDataGetter.GetCityWarDefendCampID() end --region 布阵相关 function ChangAnSiege_Controller.SetCurSelectKingdom() private.curSelectKingdomId = ChangAnSiege_Controller.GetCurLimitKingdom() end function ChangAnSiege_Controller.IsKindDomChanged() return private.curSelectKingdomId ~= ChangAnSiege_Controller.GetCurLimitKingdom() end --组合国别 -- 比如魏国1、蜀国2 ==> curKingdom为12; 魏国1、蜀国2、吴国3 ==> curKingdom为123 function ChangAnSiege_Controller.GetCurLimitKingdom() local lineUpCountryLimits = MDL.ChangAnSiege.GetLineUpCountryLimits() return MDL.FreeLineUp.GetMultiCountryId(lineUpCountryLimits) end --endregion function ChangAnSiege_Controller.GetSiegeCityBuildCfgByMonsterID(id) for _, v in DataSheetManager.SiegeCityBuild:GetEnumerator() do if v.SiegeCityNpcID == id then return v end end return nil end function private.OpenChangAnSiegeRemind() if private.isShowRemind == nil and MDL.Country.IsHasCountry() then if MDL.ChangAnSiege.GetCurStage() == MDL.ChangAnSiege.SiegeCitySeasonStage.Preparation or MDL.ChangAnSiege.GetCurStage() == MDL.ChangAnSiege.SiegeCitySeasonStage.Fight then if CTL.Activities.IsInActivitySpecificLevel() then UIManager.OpenView(Const_UI_Lua.UIEnum.UIActivitiesRemind, {LuaConst.ActivityType.SyncCityWar}) else CTL.HomeMain.AddTownHomeDelayView(Const_UI_Lua.UIEnum.UIActivitiesRemind,{LuaConst.ActivityType.SyncCityWar}) end end private.isShowRemind = true end private.UpdateActivityEntryRed() end function private.SetActivityRedPoint(timeId, activityId, timeIndex) if activityId == LuaConst.ActivityType.SyncCityWar then private.UpdateActivityEntryRed() end end function private.UpdateActivityEntryRed() if CTL.Activities.IsOpeningTime(LuaConst.ActivityType.SyncCityWar) then local time = MDL.RedPoint.GetRedPointTimeByType(MDL.RedPoint.RedPointType.SyncCityWar) if time and time > 0 and UTL.Time.IsTimestampSameDay(time) then EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, LuaConst.ActivityType.SyncCityWar, false) else EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, LuaConst.ActivityType.SyncCityWar, true) end else EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, LuaConst.ActivityType.SyncCityWar, false) end end function private.GetTowerState(index) return BattleDataGetter.GetCityWarTowerStage(index - 2) end function private.IsCrushCarAttackGate(commandItemEnum) if commandItemEnum == MDL.ChangAnSiege.CommandItemEnum.LeftCrushCar then return BattleDataGetter.GetCityWarIsCrushCarArrivedGate(MDL.ChangAnSiege.LeftCrushCarMonsterId) else return BattleDataGetter.GetCityWarIsCrushCarArrivedGate(MDL.ChangAnSiege.RightCrushCarMonsterId) end end function ChangAnSiege_Controller.GetCommandStrByIndex(index) local CommandItemEnum = MDL.ChangAnSiege.CommandItemEnum local str = "" if index == CommandItemEnum.DriverCrushCar then local list = BattleDataGetter.GetCityWarVehicleEntityList() if list and #list > 0 then str = UIUtils.GetLocalizedTxt(Const_IDS.IDS_SiegeCity_CommandTips11) else str = nil end elseif index == CommandItemEnum.LeftCrushCar then if BattleDataGetter.GetCityWarIsCrushCarBorn() then if MDL.ChangAnSiege.IsDefendCountry() then if private.IsCrushCarAttackGate(index) then str = string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandTips2, UIUtils.GetLocalizedTxt(Const_IDS.IDS_SiegeCity_WestCar)) else str = string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandTips1, UIUtils.GetLocalizedTxt(Const_IDS.IDS_SiegeCity_WestCar)) end else if private.IsCrushCarAttackGate(index) then str = string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandTips8, UIUtils.GetLocalizedTxt(Const_IDS.IDS_SiegeCity_WestCar)) else str = string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandTips7, UIUtils.GetLocalizedTxt(Const_IDS.IDS_SiegeCity_WestCar)) end end else return false end elseif index == CommandItemEnum.RightCrushCar then if BattleDataGetter.GetCityWarIsCrushCarBorn() then if MDL.ChangAnSiege.IsDefendCountry() then if private.IsCrushCarAttackGate(index) then str = string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandTips2, UIUtils.GetLocalizedTxt(Const_IDS.IDS_SiegeCity_EastCar)) else str = string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandTips1, UIUtils.GetLocalizedTxt(Const_IDS.IDS_SiegeCity_EastCar)) end else if private.IsCrushCarAttackGate(index) then str = string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandTips8, UIUtils.GetLocalizedTxt(Const_IDS.IDS_SiegeCity_EastCar)) else str = string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandTips7, UIUtils.GetLocalizedTxt(Const_IDS.IDS_SiegeCity_EastCar)) end end else return false end elseif index == CommandItemEnum.LeftTower1 then str = private.GetLeftTowerStrByIndex(1, index) elseif index == CommandItemEnum.LeftTower2 then str = private.GetLeftTowerStrByIndex(2, index) elseif index == CommandItemEnum.LeftTower3 then str = private.GetLeftTowerStrByIndex(3, index) elseif index == CommandItemEnum.RightTower1 then str = private.GetRightTowerStrByIndex(1, index) elseif index == CommandItemEnum.RightTower2 then str = private.GetRightTowerStrByIndex(2, index) elseif index == CommandItemEnum.RightTower3 then str = private.GetRightTowerStrByIndex(3, index) elseif index == CommandItemEnum.GuardElite then if not BattleDataGetter.GetCityWarDefendBossIsDead() and BattleDataGetter.IsCityWarFirstStage() then str = UIUtils.GetLocalizedTxt(Const_IDS.IDS_ChangAnSiege_LevelMissionTips_11) else str = nil end end if str then return str else return false end end function private.GetLeftTowerStrByIndex(index, commandItemEnum) if private.GetTowerState(commandItemEnum) == MDL.ChangAnSiege.TowerState.None then return false end if MDL.ChangAnSiege.IsDefendCountry() then if private.GetTowerState(commandItemEnum) == MDL.ChangAnSiege.TowerState.Drive then return string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandTips5, index) else return string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandTips3, index) end else return string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandTips9, index) end end function private.GetRightTowerStrByIndex(index, commandItemEnum) if private.GetTowerState(commandItemEnum) == MDL.ChangAnSiege.TowerState.None then return false end if MDL.ChangAnSiege.IsDefendCountry() then if private.GetTowerState(commandItemEnum) == MDL.ChangAnSiege.TowerState.Drive then return string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandTips6, index) else return string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandTips4, index) end else return string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandTips10, index) end end function ChangAnSiege_Controller.GetCommandBtnTextByIndex(index) local CommandItemEnum = MDL.ChangAnSiege.CommandItemEnum if index == CommandItemEnum.DriverCrushCar then return UIUtils.GetLocalizedTxt(Const_IDS.IDS_SiegeCity_CommandButton9) elseif index == CommandItemEnum.LeftCrushCar then if MDL.ChangAnSiege.IsDefendCountry() then return string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandButton1, UIUtils.GetLocalizedTxt(Const_IDS.IDS_SiegeCity_WestCar)) else return string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandButton6, UIUtils.GetLocalizedTxt(Const_IDS.IDS_SiegeCity_WestCar)) end elseif index == CommandItemEnum.RightCrushCar then if MDL.ChangAnSiege.IsDefendCountry() then return string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandButton1, UIUtils.GetLocalizedTxt(Const_IDS.IDS_SiegeCity_EastCar)) else return string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandButton6, UIUtils.GetLocalizedTxt(Const_IDS.IDS_SiegeCity_EastCar)) end elseif index == CommandItemEnum.LeftTower1 then return private.GetLeftTowerBtnTextByIndex(1, index) elseif index == CommandItemEnum.LeftTower2 then return private.GetLeftTowerBtnTextByIndex(2, index) elseif index == CommandItemEnum.LeftTower3 then return private.GetLeftTowerBtnTextByIndex(3, index) elseif index == CommandItemEnum.RightTower1 then return private.GetRightTowerBtnTextByIndex(1, index) elseif index == CommandItemEnum.RightTower2 then return private.GetRightTowerBtnTextByIndex(2, index) elseif index == CommandItemEnum.RightTower3 then return private.GetRightTowerBtnTextByIndex(3, index) elseif index == CommandItemEnum.GuardElite then return UIUtils.GetLocalizedTxt(Const_IDS.IDS_ChangAnSiege_LevelMissionName_9) end end function private.GetLeftTowerBtnTextByIndex(index, commandItemEnum) if MDL.ChangAnSiege.IsDefendCountry() then if private.GetTowerState(commandItemEnum) == MDL.ChangAnSiege.TowerState.Drive then return string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandButton4, index) else return string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandButton2, index) end else return string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandButton7, index) end end function private.GetRightTowerBtnTextByIndex(index, commandItemEnum) if MDL.ChangAnSiege.IsDefendCountry() then if private.GetTowerState(commandItemEnum) == MDL.ChangAnSiege.TowerState.Drive then return string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandButton5, index) else return string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandButton3, index) end else return string.FormatByIdsId(Const_IDS.IDS_SiegeCity_CommandButton8, index) end end function private.OnInitLevel() if BattleDataGetter.IsSyncCityWarMainWaitingArea() or BattleDataGetter.IsSyncCityWarSideWaitingArea() then private.isShowChangAnSiegeBattleGround = true if MDL.Country.GetMyCountryId() ~= nil then private.OpenChangAnSiegeBattleGround() end else private.isShowChangAnSiegeBattleGround = false end end function private.OpenChangAnSiegeBattleGround() if private.isShowChangAnSiegeBattleGround then if BattleDataGetter.IsSyncCityWarMainWaitingArea() then --选中冲车 local slotIndex = MDL.ChangAnSiege.IsDefendCountry() and 26 or 24 UIManager.OpenView(Const_UI_Lua.UIEnum.UIChangAnSiegeBattleGround,{tableIndex = 0, slotIndex = slotIndex}) elseif BattleDataGetter.IsSyncCityWarSideWaitingArea() then --boss UIManager.OpenView(Const_UI_Lua.UIEnum.UIChangAnSiegeBattleGround,{tableIndex = 2, slotIndex = 8}) end private.isShowChangAnSiegeBattleGround = false end end function private.IsCanUpdateAttackBuild() if BattleDataGetter.IsSyncCityWarMainWaitingArea() or BattleDataGetter.IsSyncCityWarSideWaitingArea() then return false end local list = BattleDataGetter.GetCityWarVehicleEntityList() if list and #list< 3 then if private.TankDataList == nil then private.TankDataList = {} for _, v in DataSheetManager.SiegeCityBuild:GetEnumerator() do if v.SiegeCityBuildingType == 2 then table.insert(private.TankDataList, v) end end end local WarVehicleCharacterIDs = {} for i, v in ipairs(list) do WarVehicleCharacterIDs[v:GetCharacterID()] = true end for i, v in ipairs(private.TankDataList) do if not WarVehicleCharacterIDs[v.SiegeCityNpcID] then if private.IsSiegeCityGoodsEnough(v.SiegeCityBuildingCost) then return true end end end end end function private.OnSiegeCityGoodsRefresh() if BattleDataGetter.GetMyPlayerInfo() and BattleDataGetter.GetMyPlayerInfo().siegeCityCanBuild then if MDL.ChangAnSiege.IsDefendCountry() then EventSystem.Dispatch(EventID.UI_ChangAnSiege_BuildRedPoint, private.IsCanUpdateDefendBuild()) else EventSystem.Dispatch(EventID.UI_ChangAnSiege_BuildRedPoint, private.IsCanUpdateAttackBuild()) end end end function private.IsCanUpdateDefendBuild() if BattleDataGetter.IsCityWarFirstStage() then local TowerFoundationFeatureId = 622021 --炮塔地基FeatureId local towerEntityData = BattleDataGetter.GetCityWarTowerEntityList() --长度为6的数组,元素是对应地块的炮塔entity for i, entity in ipairs(towerEntityData) do if entity.featureID ~= TowerFoundationFeatureId then local cfg = CTL.ChangAnSiege.GetSiegeCityBuildCfgByMonsterID(entity:GetCharacterID()) if #cfg.SiegeCityBuildingNext > 0 then for i = 1, 2 do local nextBuildingCfg = DataSheetManager.SiegeCityBuild:GetDataBySiegeCityBuildingID(cfg.SiegeCityBuildingNext[i]) if private.IsSiegeCityGoodsEnough(nextBuildingCfg.SiegeCityBuildingCost) then return true end end end else local nextBuildingCfg = DataSheetManager.SiegeCityBuild:GetDataBySiegeCityBuildingID(1) if private.IsSiegeCityGoodsEnough(nextBuildingCfg.SiegeCityBuildingCost) then return true end end end end return false end function private.IsSiegeCityGoodsEnough(needNum) local bagSiegeCityGoodsCount = UTL.Item.GetItemStockCount(SiegeCityGoodsID) return bagSiegeCityGoodsCount >= needNum end function private.OnTowerAttackSelf(index, towerEntity) if private.playTowerEffectDict[index] == nil or private.playTowerEffectDict[index] - Time.realtimeSinceStartup <= 0 then private.playTowerEffectDict[index] = Time.realtimeSinceStartup + 3 EventSystem.Dispatch(EventID.UIBattle_Element_SetHeadUI, towerEntity.ExpEntity.RenderEntity, EntityHeadUIModule.HeadUIType.ChangAnSiegeAttackTowerState, 3, true) EventSystem.Dispatch(EventID.UI_ChangAnSiege_MiniMapTowerAttackSelf, index) end end function ChangAnSiege_Controller.IsLeaderByJobId(countryJobId) if countryJobIdMDL.Country.CountryJob.CountryCommander4 then return false end return true end return ChangAnSiege_Controller