local ChangAnSiege_Model = {} local siege_city_op_pb = require "Proto.siege_city_op_pb" local siege_city_pb = require('Proto/siege_city_pb') local EventSystem = require('Event/EventSystem') local private = {} ChangAnSiege_Model.RevenueStatus = { Has_Received = siege_city_pb.Has_Received, -- 已领取 Can_Receive = siege_city_pb.Can_Receive, -- 待领取 CanNot_receive = siege_city_pb.CanNot_receive, -- 不可领取 } ChangAnSiege_Model.SiegeCitySeasonStage = { None = 0, -- 空置阶段(展示阶段结束,但是下一个国家赛季还未到第9阶段,这个时间内是没有阶段的) Register = 1, -- 报名阶段 Preparation = 2, -- 准备阶段 Fight = 3, -- 战斗阶段 Show = 4, -- 展示阶段 } ChangAnSiege_Model.SiegeCityBuildingType = { Turret = siege_city_pb.Turret, -- 炮台 WarCar = siege_city_pb.WarCar, -- 战车 } ChangAnSiege_Model.CommandItemEnum = { LeftCrushCar = 1, --西方冲车 RightCrushCar = 2, --东方冲车 LeftTower1 = 3, --西1塔 LeftTower2 = 4, --西2塔 LeftTower3 = 5, --西3塔 RightTower1 = 6, --东1塔 RightTower2 = 7, --东2塔 RightTower3 = 8, --东3塔 DriverCrushCar = 9, --驾驶冲车 GuardElite = 10, --镇守大将 } ChangAnSiege_Model.TowerState = { None = 1, --未建造 Free = 2, --建造但没人驾驶 Drive = 3 --有人驾驶 } ChangAnSiege_Model.LeftCrushCarMonsterId = 62200121 ChangAnSiege_Model.RightCrushCarMonsterId = 62200122 function ChangAnSiege_Model.OnStartup() NetManager.RegisterMsgCB(MessageEnums.MessageSighUpSiegeCity, private.RefreshSighUpSiegeCity) NetManager.RegisterMsgCB(MessageEnums.MessageChangePlayerSeat, private.RefreshChangePlayerSeat) NetManager.RegisterMsgCB(MessageEnums.MessageSiegeCityEnterMainPanel, private.RefreshSiegeCityEnterMainPanel) NetManager.RegisterMsgCB(MessageEnums.MessageReceiveRevenueReward, nil) NetManager.RegisterMsgCB(MessageEnums.MessageSiegeCityBuildingUpgrade, private.RefreshSiegeCityBuildingUpgrade) NetManager.RegisterMsgCB(MessageEnums.MessageEnterSiegeCity, nil) NetManager.RegisterMsgCB(MessageEnums.MessageG2CPushSiegeResult, private.OnG2CPushSiegeResult) NetManager.RegisterMsgCB(MessageEnums.MessageG2CPushSiegeCityInfo, private.OnG2CPushSiegeCityInfo) NetManager.RegisterMsgCB(MessageEnums.MessageG2CPushSiegeMainRoomResult, private.OnG2CPushSiegeMainRoomResult) NetManager.RegisterMsgCB(MessageEnums.MessageRefreshSighUpPlayers, private.RefreshSighUpPlayers) NetManager.RegisterMsgCB(MessageEnums.MessageGetRoomChatInfo, private.JoinChatChannel) NetManager.RegisterMsgCB(MessageEnums.MessageG2CSiegeCommandTips, private.OnG2CSiegeCommandTips) EventSystem.Regist(EventID.Country_OnGetFoundCountry, private.UpdateEntryRed) EventSystem.Regist(EventID.CityWar_SendResult , private.SendCityWarResult) end function ChangAnSiege_Model.InitSiegeCityBaseInfo(info) logging.log(LTAG.LOG," ChangAnSiege_Model.InitSiegeCityBaseInfo ", info) local preStage = ChangAnSiege_Model.GetCurStage() local preRevenueStatus = ChangAnSiege_Model.GetRevenueStatus() private.siegeCityBaseInfo = info if preStage ~= ChangAnSiege_Model.GetCurStage() then EventSystem.Dispatch(EventID.ChangAnSiege_StageChanged) end if preRevenueStatus ~= ChangAnSiege_Model.GetRevenueStatus() then EventSystem.Dispatch(EventID.UI_ChangAnSiege_RefreshRevenueStatus) end if ChangAnSiege_Model.GetCurStage() ~= ChangAnSiege_Model.SiegeCitySeasonStage.Fight then private.defendGoods = 0 private.attackGoods = 0 end private.UpdateEntryRed() end function ChangAnSiege_Model.InitMainCityMemberCount() --主战场进攻人数上限 local SiegeCityMBFAttackerLimit = DataSheetManager.ConstData:GetDataByID("SiegeCityMBFAttackerLimit").IntValue --主战场防守人数上限 local SiegeCityMBFDefenderLimit = DataSheetManager.ConstData:GetDataByID("SiegeCityMBFDefenderLimit").IntValue if ChangAnSiege_Model.IsDefendCountry() then private.numberMax = SiegeCityMBFDefenderLimit else private.numberMax = SiegeCityMBFAttackerLimit end end function ChangAnSiege_Model.GetMainCityMemberCount() return private.numberMax end --设置红点,国战部分显示红点 function private.UpdateEntryRed() --税收可领取 if MDL.ChangAnSiege.GetRevenueStatus() == MDL.ChangAnSiege.RevenueStatus.Can_Receive then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Country_SyncCityWar) return end --可报名 if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.ChangAnSiege) and MDL.ChangAnSiege.GetCurStage() == MDL.ChangAnSiege.SiegeCitySeasonStage.Register then if not private.siegeCityBaseInfo.isSignUp then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Country_SyncCityWar) return end end CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Country_SyncCityWar) end function ChangAnSiege_Model.GetStageTime(stage) for i, v in ipairs(private.siegeCityBaseInfo.stageAndTimes) do if v.stage == stage then return v end end end function ChangAnSiege_Model.GetCurStage() return private.siegeCityBaseInfo and private.siegeCityBaseInfo.stage end function ChangAnSiege_Model.GetDefendCountryId() return private.siegeCityBaseInfo and private.siegeCityBaseInfo.defendCountryId end function ChangAnSiege_Model.GetLineUpCountryLimits() return private.siegeCityBaseInfo.LineUpCountryLimits end function ChangAnSiege_Model.GetRevenueStatus() return private.siegeCityBaseInfo and private.siegeCityBaseInfo.revenueStatus end function ChangAnSiege_Model.GetGoods() if ChangAnSiege_Model.IsDefendCountry() then return private.defendGoods or 0 else return private.attackGoods or 0 end end function ChangAnSiege_Model.IsDefendCountry() return MDL.Country.GetMyCountryId() == ChangAnSiege_Model.GetDefendCountryId() end function ChangAnSiege_Model.CanEditMembers() return MDL.Country.JobHasPermission(MDL.Country.GetMyJobId(), MDL.Country.AuthorityEnum.EditChanganSiegeMembers) end function ChangAnSiege_Model.CanBattleCommand() return MDL.Country.JobHasPermission(MDL.Country.GetMyJobId(), MDL.Country.AuthorityEnum.ChanganSiegeBattleOrder) end function ChangAnSiege_Model.IsBattleLeader() return private.siegeCityBaseInfo and private.siegeCityBaseInfo.isLeader end --赛季最后一场已经打完 function ChangAnSiege_Model.IsLastBattle() local endTime = MDL.ChangAnSiege.GetStageTime(MDL.ChangAnSiege.SiegeCitySeasonStage.Show).endTime return private.siegeCityBaseInfo.countrySeasonEndTime == endTime end function ChangAnSiege_Model.SiegeCityEnterMainPanelReq(pages) local msg = siege_city_op_pb.SiegeCityEnterMainPanelReq() msg.pages = pages or 0 NetManager.SendMessage(MessageEnums.MessageSiegeCityEnterMainPanel, msg) end function ChangAnSiege_Model.SighUpSiegeCityReq(countryId) local msg = siege_city_op_pb.SighUpSiegeCityReq() msg.countryId = countryId logging.log(LTAG.LOG, "SighUpSiegeCityReq", countryId) NetManager.SendMessage(MessageEnums.MessageSighUpSiegeCity, msg) end function ChangAnSiege_Model.ChangePlayerSeatReq(playerId1, countryId1, playerId2, countryId2) logging.log(LTAG.LOG, "ChangePlayerSeatReq", playerId1, countryId1, playerId2, countryId2) local msg = siege_city_op_pb.ChangePlayerSeatReq() msg.info1.playerId = playerId1 or "" msg.info1.countryId = countryId1 msg.info2.playerId = playerId2 or "" msg.info2.countryId = countryId2 NetManager.SendMessage(MessageEnums.MessageChangePlayerSeat, msg) end function ChangAnSiege_Model.ReceiveRevenueRewardReq() local msg = siege_city_op_pb.ReceiveRevenueRewardReq() NetManager.SendMessage(MessageEnums.MessageReceiveRevenueReward, msg) end function ChangAnSiege_Model.SiegeCityBuildingUpgradeReq(buildingId, pos) local msg = siege_city_op_pb.SiegeCityBuildingUpgradeReq() msg.buildingId = buildingId msg.pos = pos NetManager.SendMessage(MessageEnums.MessageSiegeCityBuildingUpgrade, msg) end function ChangAnSiege_Model.RefreshSighUpPlayersReq() local msg = siege_city_op_pb.RefreshSighUpPlayersReq() NetManager.SendMessage(MessageEnums.MessageRefreshSighUpPlayers, msg) end function ChangAnSiege_Model.EnterSiegeCityReq() local msg = siege_city_op_pb.EnterSiegeCityReq() NetManager.SendMessage(MessageEnums.MessageEnterSiegeCity, msg) end function ChangAnSiege_Model.GetRoomChatInfoReq() local msg = siege_city_op_pb.GetRoomChatInfoReq() NetManager.SendMessage(MessageEnums.MessageGetRoomChatInfo, msg) end function ChangAnSiege_Model.SiegeCommandTipsReq(content, index) local msg = siege_city_op_pb.C2GSiegeCommandTipsReq() msg.content = content msg.index = index NetManager.SendMessage(MessageEnums.MessageC2GSiegeCommandTips, msg) end function private.RefreshSighUpSiegeCity(msgResp) logging.log(LTAG.LOG," RefreshSighUpSiegeCity ", msgResp) EventSystem.Dispatch(EventID.UI_ChangeSighUpSiegeCity, msgResp.members) end function private.RefreshChangePlayerSeat(msgResp) logging.log(LTAG.LOG," RefreshChangePlayerSeat ", msgResp) EventSystem.Dispatch(EventID.UI_ChangePlayerSeat, msgResp.members) if msgResp.Resp.Code == 0 then CTL.Tips.AddTipsMsg(Const_IDS.IDS_SiegeCity_BattleField_AdjustTips_4) end end local DefenceIDS = { Const_IDS.IDS_SiegeCity_MBFTab_1, Const_IDS.IDS_SiegeCity_MBFTab_2, Const_IDS.IDS_SiegeCity_MBFTab_3, Const_IDS.IDS_SiegeCity_MBFTab_4 } local OffenceIDS = { Const_IDS.IDS_SiegeCity_MBFTab_5, Const_IDS.IDS_SiegeCity_MBFTab_6, Const_IDS.IDS_SiegeCity_MBFTab_7, Const_IDS.IDS_SiegeCity_MBFTab_8 } function ChangAnSiege_Model.GetCountryTabDesc(countryId, isDefence) if countryId == MDL.Country.CountryType.Han then return UIUtils.GetLocalizedTxt(Const_IDS.IDS_SiegeCity_ABFTab) end if isDefence then return UIUtils.GetLocalizedTxt(DefenceIDS[countryId]) else return UIUtils.GetLocalizedTxt(OffenceIDS[ChangAnSiege_Model.GetDefendCountryId()]) end end function ChangAnSiege_Model.GetMembersFormatStr(num, maxNum) if maxNum then if maxNum == num then return string.format("(%s/%s)", UTL.Color.FormatGreenColor(maxNum), maxNum) else return string.format("(%s/%s)", UTL.Color.FormatYellowColor(num), maxNum) end else return string.format("(%s)", UTL.Color.FormatTextByColor("e8d588", num)) end end --是否是副战场 function ChangAnSiege_Model.IsSecondBattlefield(countryId) return countryId == MDL.Country.CountryType.Han end function ChangAnSiege_Model.GetChatChannel() if not private.siegeCityBaseInfo or private.siegeCityBaseInfo.battleGroundId == 0 then return nil else local chatCfgData = DataSheetManager.Chat:GetDataByID(MDL.ChannelChat.ChannelCfgId.MyCamp) local roomStr = chatCfgData.ChannelPrefix .. private.siegeCityBaseInfo.groupId .. private.siegeCityBaseInfo.battleGroundId return roomStr end end function private.JoinChatChannel(msgResp) logging.log(LTAG.LOG," JoinChatChannel ", msgResp) if msgResp.Resp.Code == 0 then private.siegeCityBaseInfo.battleGroundId = msgResp.battleGroundId if not CTL.VoiceRoom.IsInVoiceRoom(MDL.VoiceRoom.VoiceRoomType.ChangAnSiege) then MDL.VoiceRoom.VoiceCallStateReq(MDL.VoiceRoom.VoiceRoomType.ChangAnSiege) end if not MDL.ChannelChat.IsJoinChannel(MDL.ChannelChat.ChannelCfgId.MyCamp) then CTL.ChannelChat.TryCreateDynamicChannel(MDL.ChannelChat.ChannelCfgId.MyCamp) end end end function private.RefreshSiegeCityEnterMainPanel(msgResp) logging.log(LTAG.LOG," RefreshSiegeCityEnterMainPanel ", msgResp) if msgResp.Resp.Code == 0 then EventSystem.Dispatch(EventID.UI_ChangAnSiege_MainPanel, msgResp) end end function private.RefreshSiegeCityBuildingUpgrade(msgResp) logging.log(LTAG.LOG," RefreshSiegeCityBuilding ", msgResp) EventSystem.Dispatch(EventID.UI_ChangAnSiege_RefreshBuilding, msgResp) end function private.OnG2CPushSiegeResult(msgResp) private.defendGoods = 0 private.attackGoods = 0 private.siegeResult = msgResp if BattleDataGetter.IsCityWarSideLevel() then UIManager.OpenView(Const_UI_Lua.UIEnum.UIChangAnSiegeSummaryPanel, private.siegeResult) end end function private.OnG2CPushSiegeCityInfo(msgResp) private.defendGoods = msgResp.defendGoods private.attackGoods = msgResp.attackGoods EventSystem.Dispatch(EventID.UI_ChangAnSiege_RefreshCurrency) EventSystem.Dispatch(EventID.UI_ChangAnSiege_PushSiegeCityInfo, msgResp) end function private.OnG2CPushSiegeMainRoomResult(msgResp) CameraController.Instance:SetGray(false) if BattleDataGetter.IsCityWarFirstStage() then if msgResp.winCampId == 1 then AuxUtil.StartTimeline(DataSheetManager.ConstData:GetDataByID("SiegeCityFirstStageAttackerTimeLine").StringValue, false, -1, false, nil) else AuxUtil.StartTimeline(DataSheetManager.ConstData:GetDataByID("SiegeCityFirstStageDefenderTimeLine").StringValue, false, -1, false, function() UIManager.OpenView(Const_UI_Lua.UIEnum.UIChangAnSiegeSummaryPanel, private.siegeResult) end) end elseif BattleDataGetter.IsCityWarSecondStage() then if msgResp.winCampId == 1 then AuxUtil.StartTimeline(DataSheetManager.ConstData:GetDataByID("SiegeCitySecondStageAttackerTimeLine").StringValue, false, -1, false, function() UIManager.OpenView(Const_UI_Lua.UIEnum.UIChangAnSiegeSummaryPanel, private.siegeResult) end) else AuxUtil.StartTimeline(DataSheetManager.ConstData:GetDataByID("SiegeCitySecondStageDefenderTimeLine").StringValue, false, -1, false, function() UIManager.OpenView(Const_UI_Lua.UIEnum.UIChangAnSiegeSummaryPanel, private.siegeResult) end) end end end function private.SendCityWarResult(msg) NetManager.SendMessage(MessageEnums.MessageC2GUploadSiegeCityResult, msg) end function private.RefreshSighUpPlayers(msgResp) logging.log(LTAG.LOG," RefreshSighUpPlayers ", msgResp) if msgResp.Resp.Code == 0 then EventSystem.Dispatch(EventID.UI_ChangePlayerSeat, msgResp.members) end end function private.OnG2CSiegeCommandTips(msgResp) logging.log(LTAG.LOG," OnG2CSiegeCommandTips ", msgResp) EventSystem.Dispatch(EventID.SiegeCityCommand, msgResp.index) local title = UIUtils.GetLocalizedTxt(Const_IDS[MDL.Country.GetJobName(msgResp.OfficialJob)]) local name = msgResp.playerName local tipsData = { heroId = msgResp.hero, heroAwaken = msgResp.heroAwaken, commandStr = msgResp.content, titile = title, name = name } EventSystem.Dispatch(EventID.UI_ShowCommonCommandTips, tipsData) end return ChangAnSiege_Model