local UIGuildWarMiniMapMain = UIViewClass() local EventSystem = require('Event/EventSystem') local MAP_PATH = ConstAssetPathConfig.MAP_PATH local EntityHeadUIModule = require("View/Battle/BattleEntityUI/EntityUIModule/EntityHeadUIModule") local MiniMapWidth = 450 local MiniMapHeight = 450 local UpdatePlayerGap = 0.2 local SecondBossBornEftGap = 2 local ThirdBossBornEftGap = 4 local PerFrameRefreshFieldMaxCount = 4 local BatteringRam_Visible_Range = FP.tonumberV1(DataSheetManager.ConstData:GetDataByID("MiniMapFOVRangeSiege").FloatValue) local Player_Visible_Range = FP.tonumberV1(DataSheetManager.ConstData:GetDataByID("MiniMapFOVRangePlayer").FloatValue) local Camp_Visible_Range = FP.tonumberV1(DataSheetManager.ConstData:GetDataByID("MiniMapFOVRangeCamp").FloatValue) local BatteringRam_Visible_Range_Sqr = BatteringRam_Visible_Range*BatteringRam_Visible_Range local Player_Visible_Range_Sqr = Player_Visible_Range*Player_Visible_Range local Camp_Visible_Range_Sqr = Camp_Visible_Range*Camp_Visible_Range local PosStr = "(%d,%d)" local Const_Boss_FeatureID = 2002 local Const_Quartermaster_FeatureID = 46 local Const_Mangonel_FeatureID = 47 local Const_Ballista_FeatureID = 48 local Const_LittleMangonel_FeatureID = 49 local Const_BatteringRam_FeatureID = 2010 --冲车 --超级冲车ID1 local Const_Super_ChongCheID1 = 35502160 --超级冲车ID2 local Const_Super_ChongCheID2 = 35502161 --炸弹 local Const_Bomb_FeatureID = 35502162 local OccupyStage = { Staying = 0, -- 僵持中阶段(或无人占领阶段) Snatching = 1, -- 抢夺中阶段 Occupying = 2, -- 占领中阶段 Occupied = 3, -- 已占领阶段 } local StaticPointType = { MotherBase = 1, MangonelCamp = 2, BatteringRamCamp = 3, BossRespawn = 4, } -- 地图配置 local StaticPointItemIDs = {} -- 左地图 StaticPointItemIDs[355011] = { [StaticPointType.MotherBase] = {2001, 2002}, [StaticPointType.MangonelCamp] = {[10001] = {2041, 2042}}, [StaticPointType.BossRespawn] = {{2011, 2012, 2013}} } -- 中地图 StaticPointItemIDs[355021] = { [StaticPointType.MotherBase] = {2001, 2002}, [StaticPointType.BatteringRamCamp] = {[10001] = {2031, 2032}}, [StaticPointType.MangonelCamp] = {[10002] = {2041, 2042}, [10003] = {2051, 2052}}, } -- 右地图 StaticPointItemIDs[355031] = { [StaticPointType.MotherBase] = {2001, 2002}, [StaticPointType.MangonelCamp] = {[10001] = {2041, 2042}}, [StaticPointType.BossRespawn] = {{2011, 2012, 2013}} } local MapItemIndexToID = { [MDL.GuildWar.MapItemIndex.MiddleLeftTouShi] = 10002, [MDL.GuildWar.MapItemIndex.MiddleRightTouShi] = 10003, [MDL.GuildWar.MapItemIndex.MiddleChongChe] = 10001, [MDL.GuildWar.MapItemIndex.LeftTouShi] = 10001, [MDL.GuildWar.MapItemIndex.RightTouShi] = 10001, [MDL.GuildWar.MapItemIndex.LeftBoss] = {2011, 2012}, [MDL.GuildWar.MapItemIndex.RightBoss] = {2011, 2012} } ---------------------------------- 系统函数 ---------------------------------- function UIGuildWarMiniMapMain:OnCreated() self.isInitEnd = false --地图一打开就显示的几个特效 self.BeginEffectTime = 2 -- 剩余次时间 self.LeftBeginEffectTimes = 2 --剩余次数 -- 地图相关 self.mapTex = nil -- 加载的地图纹理 self.mapTexLoadPath = nil -- 加载的地图纹理加载路径 self.OffsetX = 0 self.OffsetY = 0 self.SizeRateX = 1 self.SizeRateY = 1 self.mapWidth = 0 self.mapHeight = 0 self.mapCenterPosX = 0 self.mapCenterPosY = 0 self.isMirrorMap = false -- 静态地图点 self.motherBasePoints = {} self.batteringRamBasePoints = {} self.mangonelBasePoints = {} self.bossRespawnPoints = {} -- 动态地图点 self.ownerPoint = nil self.teammatePoints = {} self.enemyPoints = {} self.bossPoints = {} self.drivablePoints = {} self.batteringRamPoints = {} self.dynamicPointPool = {} -- 视野参数 self.maxGridCount = 0 self.mapGrids = nil self.mapGridsUpdateTime = 0 self.fieldEntityIDs = {} self.curRefreshFieldIndex = 1 -- 标识位 self.myBaseIsHurt = false self.enemyBaseIsHurt = false self.curPinpointEft = nil self.lastPlayEffectDict = {} end function UIGuildWarMiniMapMain:OnOpened() self:RegistSystemEvent(EventID.UI_MiniMapMain_Monster_Create, self.NotifyMonsterCreate) self:RegistSystemEvent(EventID.UI_MiniMapMain_Monster_Dead, self.NotifyMonsterDead) self:RegistSystemEvent(EventID.Level_HPChange, self.NotifyMonsterChangeHP) self:RegistSystemEvent(EventID.UI_MiniMapMain_StrongHold_Occupation, self.NotifyStrongHoldOccupation) self:RegistSystemEvent(EventID.UI_MiniMapMain_Player_Create, self.NotifyPlayerCreate) self:RegistSystemEvent(EventID.UI_MiniMapMain_Player_Change, self.NotifyPlayerChange) self:RegistSystemEvent(EventID.UI_MiniMapMain_Player_Dead, self.NotifyPlayerDead) self:RegistSystemEvent(EventID.UI_GuildWarHpUpdate, self.NotifyMotherBaseChangeHP) self:RegistSystemEvent(EventID.Player_DriveEntity, self.NotifyPlayerOnDrive) self:RegistSystemEvent(EventID.Player_OffDriveEntity, self.NotifyPlayerOffDrive) self:RegistSystemEvent(EventID.UI_MiniMapMain_ShowEffect, self.NotifyPlayEffect) self:RegistSystemEvent(EventID.UI_GuildWarCommandTeam, self.NotifyPlayPinpointEffect) self:RegistSystemEvent(EventID.UI_GuildWarBigMapUpdate, self.OnMapUpdate) self:RegistSystemEvent(EventID.UI_GuildWarGroupInfosUpdate, self.GetGroupInfos) self:RegistSystemEvent(EventID.UI_ShowCommonCommandTips, self.NotifyCommandEffect) self:RegistSystemEvent(EventID.GuildWar_Catapult_Cause_Damage, self.OnToushicheAttack) self:RegistSystemEvent(EventID.GuildWar_Boss_Got_Damage, self.OnBossAttack) self:RegistSystemEvent(EventID.UIBattle_Element_SetHeadUI, self.RefreshDynamicPointIcon) --有玩家拾起炸弹时,刷新pointIcon self:RegistSystemEvent(EventID.UIBattle_Element_RemoveHeadUI, self.RefreshDynamicPointIcon) --炸弹爆炸销毁时,刷新pointIcon MDL.GuildWar.C2GGetGuildWarMapInfo() -- 节点控制 UIUtils.SetActive(self.bg_MiniMap, true) UIUtils.SetActive(self.panel_MiniMap, true) UIUtils.SetActive(self.bg_Town, false) UIUtils.SetActive(self.mask_Town, false) UIUtils.SetActive(self.group_MapItem, false) UIUtils.SetActive(self.group_GuildwarInfo, true) UIUtils.SetActive(self.img_MapFrameGuildWar, true) UIUtils.SetActive(self.Img_Bg, false) UIUtils.SetActive(self.img_MapFrame, false) self:InitGuildWarMap() self.isInitEnd = true if not BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.GuildWarWaitingArea) then -- 等待区不谈tips CTL.GuildWar.BeginTips() end UIUtils.SetActive(self.event_Quit, false); end function UIGuildWarMiniMapMain:OnButtonClicked(comp) if comp == self.panel_Main then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGuildWarMapInfo) end end function UIGuildWarMiniMapMain:OnUpdateFun(deltaTime, timeSinceUpdate) if self.isInitEnd then self:RefreshBatteringRamPos() self:RefreshBossPosAndPlayBornEft(deltaTime) self:RefreshOwnerPosAndDir() self:RefreshPlayerPos() if self.LeftBeginEffectTimes > 0 then self.BeginEffectTime = self.BeginEffectTime - deltaTime if self.BeginEffectTime < 0 then CTL.GuildWar.BeginTips(true) self.BeginEffectTime = 2 self.LeftBeginEffectTimes = self.LeftBeginEffectTimes - 1 end end end end function UIGuildWarMiniMapMain:OnClosed() if self.mapTex and self.mapTexLoadPath then TK2API.ReturnAsset(self.mapTexLoadPath, self.mapTex) end end ------------------------------------------------------------------------------- ---------------------------- 初始化函数 ---------------------------------------- -- 检查己方出生位置 function UIGuildWarMiniMapMain:CheckMapNeedMirror(sceneMapID) local stateItemDict = StaticPointItemIDs[sceneMapID] -- 确定己方基地在小地图的显示位置 if stateItemDict and stateItemDict[StaticPointType.MotherBase] then local myBasePosY = 0 local enemyBasePosY = 0 for _, levelItemID in pairs (stateItemDict[StaticPointType.MotherBase]) do local baseEntity = LevelItemManager.GetMonsterByItemID(levelItemID) if baseEntity then local posX, posY = self:ChangePosToMapPos(baseEntity:GetLogicPos()) if baseEntity:GetCampID() == BattleDataGetter.GetMyCampID() then myBasePosY = posY else enemyBasePosY = posY end end end self.isMirrorMap = myBasePosY > enemyBasePosY MDL.GuildWar.SetIsMirrorMap(self.isMirrorMap) end end -- 初始化小地图显示 function UIGuildWarMiniMapMain:InitGuildWarMap() -- 加载对应小地图纹理资源 local levelInfoData = BattleDataGetter.GetLevelInfoData() local miniMapData = DataSheetManager.MiniMapData:GetDataByID(levelInfoData.SceneMapID) UIUtils.SetLabelText(self.lab_GuildwarName, Const_IDS[levelInfoData.LevelNameIDS]) self:CheckMapNeedMirror(levelInfoData.SceneMapID) if miniMapData and not string.isNilOrEmpty(miniMapData.SceneMap) then self.mapTexLoadPath = string.format(MAP_PATH, miniMapData.SceneMap) self.mapTex = TK2API.GetTextureAsset(self.mapTexLoadPath) if self.mapTex then -- 设置地图纹理 self.texture_MiniMap.texture = self.mapTex self.texture_MiniMap.rectTransform:SetParent(self.img_MapMaskGuildWar.transform) self.texture_MiniMap.rectTransform:SetLocalPosition(0, 0, 0) self.texture_MiniMap.rectTransform:SetAsFirstSibling() self.texture_MiniMap.transform:SetLocalScale(self.isMirrorMap and -1 or 1, self.isMirrorMap and -1 or 1, 1) UIUtils.SetGraphicSize(self.texture_MiniMap, MiniMapWidth, MiniMapHeight) self.group_MapItem:SetParent(self.panel_Main.transform) self.group_MapItem:SetLocalPosition(0, 0, 0) -- UIUtils.SetRectPosition(self.panel_MiniMap.gameObject, 0, 0) UIUtils.SetRectTransformSize(self.panel_MiniMap, MiniMapWidth, MiniMapHeight) --self.panel_MiniMap:SetAnchoredPosition(74, 13) -- 计算地图缩放参数 self:InitMapParams(miniMapData) -- 初始化地图点 self:InitStaticPoints(levelInfoData.SceneMapID) self:InitMonsterPoints() self:InitPlayerPoints() self:StartRepeatFunc(self.OnUpdateFun, UpdatePlayerGap) self:StartRepeatFunc(self.NewCheckFriendlyField, UpdatePlayerGap/2) else logging.error(LTAG.ERROR, "无法加载出小地图纹理资源 加载路径 : ", tostring(self.mapTexLoadPath)) end else logging.error(LTAG.ERROR, "无法从MiniMapData中查询到数据 SceneMapID : ", levelInfoData.SceneMapID) end end function UIGuildWarMiniMapMain:InitMapParams(miniMapData) local texSize = self.mapTex.width local mapSize = miniMapData.UIMapSize > 0 and miniMapData.UIMapSize or texSize --缩放比例 self.SizeRateX = MiniMapWidth / texSize self.SizeRateY = MiniMapHeight / texSize local uiMapRate = (miniMapData.OriMapSize > 0 and miniMapData.UIMapSize > 0) and (miniMapData.UIMapSize / miniMapData.OriMapSize) or 1 local xMax, zMax, offsetX, offsetZ = BattleExt.GetCurMapInfo() if miniMapData.IsCombine == 1 then self.OffsetX = (mapSize / uiMapRate) / 2 + miniMapData.MapOffsetX self.OffsetY = (mapSize / uiMapRate) / 2 + miniMapData.MapOffsetY else self.OffsetX = xMax / 2 + offsetX self.OffsetY = zMax / 2 + offsetZ end self.mapWidth = xMax self.mapHeight = zMax self.maxGridCount = self.mapWidth * self.mapHeight self.mapCenterPosX = math.floor(self.mapWidth / 2) self.mapCenterPosY = math.floor(self.mapHeight / 2) self.SizeRateX = self.SizeRateX * uiMapRate self.SizeRateY = self.SizeRateY * uiMapRate -- 地图区域格子 end -- 初始化静态点 function UIGuildWarMiniMapMain:InitStaticPoints(sceneMapID) local stateItemDict = StaticPointItemIDs[sceneMapID] if stateItemDict then for k, v in pairs (stateItemDict) do if k == StaticPointType.MotherBase then self:CreateMotherBasePoint(k, v) elseif k == StaticPointType.MangonelCamp or k == StaticPointType.BatteringRamCamp then self:CreateCampPoint(k, v) elseif k == StaticPointType.BossRespawn then self:CreateBossRespawnPoint(k, v) end end end end function UIGuildWarMiniMapMain:InitMonsterPoints() for _, entity in ipairs (BattleDataGetter.GetEntityList_Normal()) do if entity:IsValid() then if entity:GetFeatureID() == Const_BatteringRam_FeatureID then self:CreateBatteringRamPoint(entity) elseif entity:GetFeatureID() == Const_Boss_FeatureID or entity:GetFeatureID() == Const_Quartermaster_FeatureID then self:CreateBossPoint(entity) elseif entity:GetFeatureID() == Const_Mangonel_FeatureID then self:RefreshMangonelPointState(entity._logicInitData.BornItemID, entity) elseif entity:GetFeatureID() == Const_LittleMangonel_FeatureID or entity:GetFeatureID() == Const_Ballista_FeatureID then self:CreateDrivablePoint(entity) elseif entity:GetFeatureID() == Const_Bomb_FeatureID and entity:GetCampID() == BattleDataGetter.GetMyCampID() then if self.bombPoint == nil then local point = self:CreateDynamicPoint(entity) UIUtils.SetActive(point.img_Bomb, true) UTL.Item.SetAtlasSprite(point.img_Bomb, "UI_Battle", "zd_icon_zd_bomb") self.bombPoint = point self:SetDynamicPointPos(point) end end end end self:RefreshMotherBaseBatteringRamTipShow() end -- 初始化玩家点 function UIGuildWarMiniMapMain:InitPlayerPoints() self:CreateOwnerPoint() -- 创建其他玩家 local entities = BattleDataGetter.GetEntityList_Sync() if entities and #entities then for _, entity in ipairs (entities) do self:CreatePlayerPoint(entity) end end end ------------------------------------------------------------------------------- --------------------------------- 地图点处理 ----------------------------------- function UIGuildWarMiniMapMain:CreateStaticPoint() self:InstantiateCollection(self.staticPoints, self.template_StaticPoint.gameObject) local addPoint = self.staticPoints[#self.staticPoints] UIUtils.SetActive(addPoint.gameObject, true) return addPoint end function UIGuildWarMiniMapMain:SetStaticPointPos(point, levelItemID) if point and levelItemID then local itemData = LevelItemManager.GetItemDataByID(levelItemID) if itemData then local posX, posY = self:ChangePosToMapPos(itemData.ItemPos) point.gameObject.transform:SetLocalPosition(self.isMirrorMap and -posX or posX, self.isMirrorMap and -posY or posY, 0) end end end function UIGuildWarMiniMapMain:CreateDynamicPoint(entity) if not entity then return nil end local parentRoot = entity:IsHero() and self.playerPoints or self.dynamicPoints local addPoint = nil local entityID = entity.EntityID if entity:IsHero() then if self.teammatePoints[entityID] then addPoint = self.teammatePoints[entityID] addPoint.entity = entity elseif self.enemyPoints[entityID] then addPoint = self.enemyPoints[entityID] addPoint.entity = entity end else local count = #self.dynamicPointPool if count > 0 then addPoint = table.remove(self.dynamicPointPool, count) addPoint.entity = entity end end if not addPoint then self:InstantiateCollection(parentRoot, self.template_DynamicPoint.gameObject) addPoint = setmetatable({entity = entity, posX = nil, posY = nil, centerIndex = -1, isInField = false, carEntity = nil}, {__index = parentRoot[#parentRoot]}) end if entity:IsHero() then addPoint.gameObject.transform:SetLocalScale(self.isMirrorMap and -1 or 1, self.isMirrorMap and -1 or 1, 1) end UIUtils.SetActive(addPoint.gameObject, true) addPoint.fieldDict = {} return addPoint end function UIGuildWarMiniMapMain:RecycleDynamicPoint(point) if point and point.entity then local entityID = point.entity.EntityID if not point.entity:IsHero() then if self.bossPoints[entityID] then self.bossPoints[entityID] = nil end if self.batteringRamPoints[entityID] then self.batteringRamPoints[entityID] = nil end table.insert(self.dynamicPointPool, point) end self:InitDynamicPoint(point) end end function UIGuildWarMiniMapMain:SetDynamicPointPos(point, isNeedAngle) if point and point.entity then local posX, posY = self:ChangePosToMapPos(point.entity:GetLogicPos()) if not point.posX or not point.posY or point.posX ~= posX or point.posY ~= posY then point.gameObject.transform:SetLocalPosition(self.isMirrorMap and -posX or posX, self.isMirrorMap and -posY or posY, 0) end if isNeedAngle then point.gameObject.transform:SetLocalEulerAngles(0, 0, -point.entity.ExpEntity:GetEulerAngleY()) end -- 上车强制 if point.carEntity then point.gameObject.transform:SetLocalEulerAngles(0, 0, -point.carEntity.ExpEntity:GetEulerAngleY()) end end end function UIGuildWarMiniMapMain:RefreshDynamicPointIcon(renderEntity, headUIType, ...) if headUIType == EntityHeadUIModule.HeadUIType.GuildWarBomb then self:StopRepeatFunc(self.OnUpdateBombFun) --与战斗沟通发现:炸弹事件派发会先于entity的炸弹数据刷新,需延迟0.2s刷新小地图的炸弹icon self:StartRepeatFunc(self.OnUpdateBombFun, 0.2, 1) end end function UIGuildWarMiniMapMain:OnUpdateBombFun(deltaTime, timeSinceUpdate) for _, point in pairs (self.teammatePoints) do self:SetDynamicPointIcon(point) end for _, point in pairs (self.enemyPoints) do self:SetDynamicPointIcon(point) end end function UIGuildWarMiniMapMain:SetDynamicPointIcon(point) if not point.entity then return end local iconName, widthAndHeight = MDL.GuildWar.GetPlayerImageResource(point.entity) UTL.Item.SetAtlasSprite(point.img_PlayerSelf, "UI_MiniMap", iconName) if widthAndHeight then point.img_PlayerSelf.transform:SetSizeDelta(widthAndHeight.Width, widthAndHeight.Height) else point.img_PlayerSelf:SetNativeSize() end local bombPropId = 30 --势力战炸弹的道具id为30 if point.entity.components.battleProp:GetBattlePropNum(bombPropId) ~= 0 then --是携带炸弹的point,则恢复scale point.gameObject.transform:SetLocalScale(1, 1, 1) else point.gameObject.transform:SetLocalScale(self.isMirrorMap and -1 or 1, self.isMirrorMap and -1 or 1, 1) end end function UIGuildWarMiniMapMain:InitDynamicPoint(point) if point then point.entity = nil point.posX = nil point.posY = nil point.centerIndex = -1 point.isInField = false point.carEntity = nil UIUtils.SetActive(point.img_Owener, false) UIUtils.SetActive(point.img_Player, false) UIUtils.SetActive(point.img_Boss, false) UIUtils.SetActive(point.img_BatteringRam, false) UIUtils.SetActive(point.img_Car, false) UIUtils.SetActive(point.gameObject, false) point.gameObject.transform:SetLocalEulerAngles(0, 0, 0) point.img_BatteringRamBar.fillAmount = 0 point.fieldDict = {} end end function UIGuildWarMiniMapMain:ChangePosToMapPos(posData) if not posData then return 0, 0 end local posX, posY = FP.tonumberV2(posData) return self:ChangePosToMapPosByPosXY(posX, posY) end function UIGuildWarMiniMapMain:ChangePosToMapPosByPosXY(posX, posY) if not posX or not posY then return 0, 0 end posX = (posX - self.OffsetX) * self.SizeRateX posY = (posY - self.OffsetY) * self.SizeRateY return posX, posY end -- -------------- 基地处理 function UIGuildWarMiniMapMain:CreateMotherBasePoint(staticPointType, levelItemIDs) if levelItemIDs and #levelItemIDs > 0 then for _, levelItemID in ipairs (levelItemIDs) do local point = self:CreateStaticPoint() self.motherBasePoints[levelItemID] = setmetatable({ID = levelItemID, centerIndex = -1, isInField = false, remainHP = MDL.GuildWar.MaxGuildWarBaseHp}, {__index = point}) local baseMonter = LevelItemManager.GetMonsterByItemID(levelItemID) local isMy = BattleDataGetter.GetMyCampID() == (baseMonter and baseMonter:GetCampID() or -1) -- 基地添加视野 self:SetLevelItemField(self.motherBasePoints[levelItemID]) -- 设置显示 UIUtils.SetActive(point.img_MyBase, isMy) UIUtils.SetActive(point.img_EnemyBase, not isMy) UIUtils.SetActive(point.img_MyAttackTip, false) UIUtils.SetActive(point.img_EnemyAttackTip, false) -- 设置位置 self:SetStaticPointPos(point, levelItemID) end end end function UIGuildWarMiniMapMain:RefreshMotherBaseBatteringRamTipShow() if self.motherBasePoints then for levelItemID, point in pairs (self.motherBasePoints) do local isShowTip = false local baseMonter = LevelItemManager.GetMonsterByItemID(levelItemID) local isMy = false if baseMonter then isMy = BattleDataGetter.GetMyCampID() == baseMonter:GetCampID() if self.batteringRamPoints then for _, point in pairs (self.batteringRamPoints) do if point and point.entity and point.entity:GetCampID() ~= baseMonter:GetCampID() then isShowTip = true break end end end end if isMy then UIUtils.SetActive(point.img_MyAttackTip, isShowTip) else UIUtils.SetActive(point.img_EnemyAttackTip, isShowTip) end end end end ---------------------- -- 创建营地 投石车、冲车共用 function UIGuildWarMiniMapMain:CreateCampPoint(staticPointType, levelItemIDToMonsterIDs) if levelItemIDToMonsterIDs then for levelItemID, monsterIDs in pairs (levelItemIDToMonsterIDs) do local monsterDict = nil if monsterIDs and #monsterIDs > 0 then monsterDict = {} for _, v in ipairs (monsterIDs) do monsterDict[v] = true end end local data = {ID = levelItemID, monsterDict = monsterDict, campID = nil, centerIndex = -1, isInField = false} local point = self:CreateStaticPoint() -- 设置显示 UIUtils.SetActive(point.img_Camp, true) if staticPointType == StaticPointType.BatteringRamCamp then self.batteringRamBasePoints[levelItemID] = setmetatable(data, {__index = point}) self:SetLevelItemField(self.batteringRamBasePoints[levelItemID]) UTL.Item.SetAtlasSprite(point.img_CampIcon, "UI_GuildWar", MDL.GuildWar.GetBatteringRamCampImageResource()) self:RefreshBatteringRamOccupation(levelItemID) elseif staticPointType == StaticPointType.MangonelCamp then self.mangonelBasePoints[levelItemID] = setmetatable(data, {__index = point}) self:SetLevelItemField(self.mangonelBasePoints[levelItemID]) UTL.Item.SetAtlasSprite(point.img_CampIcon, "UI_MiniMap", MDL.GuildWar.GetMangonelCampImageResource()) self:RefreshMangonelOccupation(levelItemID) end -- 设置位置 self:SetStaticPointPos(point, levelItemID) end end end -------------- 投石车处理 function UIGuildWarMiniMapMain:RefreshMangonelPointState(levelItemID, entity) if self.mangonelBasePoints then for _, point in pairs (self.mangonelBasePoints) do if point and point.monsterDict and point.monsterDict[levelItemID] then if entity then -- 投石车据点转化为投石车实体 UIUtils.SetActive(point.img_Camp, false) UIUtils.SetActive(point.img_Mangonel, true) self:RefreshMangonelHP(levelItemID, FP.tonumberV1(entity:GetHp() / entity:GetMaxHp())) -- 设置阵营显示 local imageCfg = MDL.GuildWar.GetMangonelImageResource(BattleDataGetter.GetMyCampID() == entity:GetCampID()) UTL.Item.SetAtlasSprite(point.img_Mangonel, "UI_MiniMap", imageCfg.Main) UTL.Item.SetAtlasSprite(point.img_MangonelHP, "UI_MiniMap", imageCfg.Progress) else -- 投石车实体转化为投石车据点 UIUtils.SetActive(point.img_Camp, true) UIUtils.SetActive(point.img_Mangonel, false) -- 据点强制变为中立 point.campID = nil point.img_OccupiedBar.fillAmount = 0 end end end end end function UIGuildWarMiniMapMain:RefreshMangonelOccupation(levelItemID) if self.mangonelBasePoints then local levelItem = LevelItemManager.GetItemByID(levelItemID) if not levelItem then return false end local curState, campID, occupationPercent = levelItem:GetStrongHoldInfo() local point = self.mangonelBasePoints[levelItemID] if point then -- 处理视野 if (not point.isInField and BattleDataGetter.GetMyCampID() == campID and occupationPercent == 1) or (point.isInField and BattleDataGetter.GetMyCampID() ~= campID) then self:UpdateLevelItemField(point) end if not point.campID or point.campID ~= campID then -- 阵营切换 point.campID = campID UTL.Item.SetAtlasSprite(point.img_OccupiedBar, "UI_MiniMap", MDL.GuildWar.GetOccupationBarImageResource(BattleDataGetter.GetMyCampID() == campID)) end if occupationPercent == 1 then if BattleDataGetter.GetMyCampID() == campID then CTL.Sound.PlayGameSound("UI_strongpoint") point.eft_MyCamp:PlayUIEffect() else CTL.Sound.PlayGameSound("UI_enemypoint") point.eft_EnemyCamp:PlayUIEffect() end end point.img_OccupiedBar.fillAmount = occupationPercent return true end end return false end function UIGuildWarMiniMapMain:RefreshMangonelHP(levelItemID, hpPercent) if self.mangonelBasePoints then for _, point in pairs (self.mangonelBasePoints) do if point.monsterDict and point.monsterDict[levelItemID] then point.img_MangonelHP.fillAmount = hpPercent end end end end ----------------------- -------------- 冲车处理 function UIGuildWarMiniMapMain:CreateBatteringRamPoint(entity) local point = self:CreateDynamicPoint(entity) if point then self.batteringRamPoints[entity.EntityID] = point local isSuper = entity:GetCharacterID() == Const_Super_ChongCheID1 or entity:GetCharacterID() == Const_Super_ChongCheID2 local imageCfg = MDL.GuildWar.GetBatteringRamImageResource(BattleDataGetter.GetMyCampID() == entity:GetCampID(), isSuper) UTL.Item.SetAtlasSprite(point.img_BatteringRam, "UI_MiniMap", imageCfg.Main) UTL.Item.SetAtlasSprite(point.img_BatteringRamBar, "UI_MiniMap", imageCfg.Progress) self:RefreshBatteringRamHP(entity, FP.tonumberV1(entity:GetHp() / entity:GetMaxHp())) self:SetDynamicPointPos(point) UIUtils.SetActive(point.img_BatteringRam, true) self:SetEntityField(point) table.insert(self.fieldEntityIDs, entity.EntityID) end end function UIGuildWarMiniMapMain:RefreshBatteringRamOccupation(levelItemID) if self.batteringRamBasePoints then local levelItem = LevelItemManager.GetItemByID(levelItemID) if not levelItem then return end local curState, campID, occupationPercent = levelItem:GetStrongHoldInfo() local point = self.batteringRamBasePoints[levelItemID] if point then -- 处理视野 if (not point.isInField and BattleDataGetter.GetMyCampID() == campID and occupationPercent == 1) or (point.isInField and BattleDataGetter.GetMyCampID() ~= campID) then self:UpdateLevelItemField(point) end if not point.campID or point.campID ~= campID then -- 阵营切换 point.campID = campID UTL.Item.SetAtlasSprite(point.img_OccupiedBar, "UI_MiniMap", MDL.GuildWar.GetOccupationBarImageResource(BattleDataGetter.GetMyCampID() == campID)) end if occupationPercent == 1 then if BattleDataGetter.GetMyCampID() == campID then CTL.Sound.PlayGameSound("UI_strongpoint") point.eft_MyCamp:PlayUIEffect() else CTL.Sound.PlayGameSound("UI_enemypoint") point.eft_EnemyCamp:PlayUIEffect() end end point.img_OccupiedBar.fillAmount = occupationPercent end end end function UIGuildWarMiniMapMain:RefreshBatteringRamHP(entity, hpPercent) if not entity then return false end if self.batteringRamPoints and self.batteringRamPoints[entity.EntityID] then local point = self.batteringRamPoints[entity.EntityID] point.img_BatteringRamBar.fillAmount = hpPercent return true end return false end function UIGuildWarMiniMapMain:RefreshBatteringRamPos() if self.batteringRamPoints then for _, point in pairs (self.batteringRamPoints) do self:SetDynamicPointPos(point) end end end ----------------------- -------------- BOSS处理 function UIGuildWarMiniMapMain:CreateBossRespawnPoint(staticPointType, levelItemIDParam) if levelItemIDParam and #levelItemIDParam > 0 then for _, itemIDs in ipairs (levelItemIDParam) do local IDDict = nil if itemIDs and #itemIDs > 0 then IDDict = {} for _, itemID in ipairs (itemIDs) do IDDict[itemID] = true end end local point = setmetatable({IDDict = IDDict, bossPoints = {}}, {__index = self:CreateStaticPoint()}) table.insert(self.bossRespawnPoints, point) -- 设置显示 self:RefreshBossRespawnPointState(point) -- 设置位置 self:SetStaticPointPos(point, itemIDs[1]) end end end function UIGuildWarMiniMapMain:CreateBossPoint(entity, isPlayEft) local respwanPoint = self:GetBossRespwanPointByBossEntity(entity) if respwanPoint then local point = self:CreateDynamicPoint(entity) respwanPoint.bossPoints[entity.EntityID] = true UIUtils.SetActive(point.img_Boss, true) if isPlayEft then self.bossPoints[entity.EntityID] = setmetatable({bornDuration = 0, remainPlayEftTime = 2}, {__index = point}) point.eft_Boss:PlayUIEffect() else self.bossPoints[entity.EntityID] = point end self:SetDynamicPointPos(point) self:RefreshBossRespawnPointState(respwanPoint) elseif entity:GetFeatureID() == Const_Quartermaster_FeatureID then local point = self:CreateDynamicPoint(entity) UIUtils.SetActive(point.img_Quartermaster, true) UTL.Item.SetAtlasSprite(point.img_Quartermaster, "UI_MiniMap", MDL.GuildWar.GetQuartermasterImageResource(entity)) self.bossPoints[entity.EntityID] = point self:SetDynamicPointPos(point) end end function UIGuildWarMiniMapMain:RefreshBossRespawnPointState(bossRespawnPoint) if bossRespawnPoint and bossRespawnPoint.bossPoints then for _, v in pairs (bossRespawnPoint.bossPoints) do if v then UIUtils.SetActive(bossRespawnPoint.img_Boss, false) return end end UIUtils.SetActive(bossRespawnPoint.img_Boss, true) end end function UIGuildWarMiniMapMain:RefreshBossPosAndPlayBornEft(deltaTime) if self.bossPoints then for _, point in pairs (self.bossPoints) do if point.remainPlayEftTime and point.remainPlayEftTime > 0 then point.bornDuration = point.bornDuration + deltaTime if point.remainPlayEftTime == 2 and point.bornDuration >= SecondBossBornEftGap then point.eft_Boss:PlayUIEffect() point.remainPlayEftTime = point.remainPlayEftTime - 1 elseif point.remainPlayEftTime == 1 and point.bornDuration >= ThirdBossBornEftGap then point.eft_Boss:PlayUIEffect() point.remainPlayEftTime = point.remainPlayEftTime - 1 end end self:SetDynamicPointPos(point) end end end function UIGuildWarMiniMapMain:GetBossRespwanPointByBossEntity(entity) if not entity then return nil end local levelItemID = entity._logicInitData.OriginBornItemID if self.bossRespawnPoints and #self.bossRespawnPoints > 0 then for _, point in ipairs (self.bossRespawnPoints) do if point.IDDict and point.IDDict[levelItemID] then return point end end end return nil end ----------------------- -------------- 玩家处理 -- 动态点处理 function UIGuildWarMiniMapMain:CreateOwnerPoint() self.ownerPoint = self:CreateDynamicPoint(BattleDataGetter.GetCurEntity()) if self.ownerPoint then UIUtils.SetActive(self.ownerPoint.img_Owener, true) self:RefreshOwnerPosAndDir() self:RefreshPlayerDrivableState(self.ownerPoint) self:SetEntityField(self.ownerPoint) end end function UIGuildWarMiniMapMain:RefreshOwnerPosAndDir() self:SetDynamicPointPos(self.ownerPoint, true) local posData = self.ownerPoint.entity:GetLogicPos() local posX, posY = FP.tonumberV2(posData) UIUtils.SetLabel(self.lab_GuildwarPos, string.format(PosStr, posX, posY)) end function UIGuildWarMiniMapMain:CreatePlayerPoint(entity) if not entity or not entity:IsActive() or entity.EntityID == BattleDataGetter.GetCurEntity().EntityID then return end local point = self:CreateDynamicPoint(entity) if point then UIUtils.SetActive(point.img_Player, true) self:SetDynamicPointIcon(point) self:SetDynamicPointPos(point) if BattleDataGetter.GetMyCampID() == point.entity:GetCampID() then self.teammatePoints[point.entity.EntityID] = point self:SetEntityField(point) else UIUtils.SetActive(point.gameObject, false) self.enemyPoints[point.entity.EntityID] = point end self:RefreshPlayerDrivableState(point) table.insert(self.fieldEntityIDs, entity.EntityID) end end function UIGuildWarMiniMapMain:RefreshPlayerPos() for _, point in pairs (self.teammatePoints) do self:SetDynamicPointPos(point) end for _, point in pairs (self.enemyPoints) do self:SetDynamicPointPos(point) end end function UIGuildWarMiniMapMain:RefreshPlayerDrivableState(point) if not point or not point.entity then return end local isSelf = BattleDataGetter.GetCurEntity().EntityID == point.entity.EntityID local isOnDrive, carEntity = self:PlayerIsOnDrive(point.entity) if isSelf then UIUtils.SetActive(point.img_OwenerSelf, not isOnDrive) UIUtils.SetActive(point.img_OwenerInCar, isOnDrive) else UIUtils.SetActive(point.img_PlayerSelf, not isOnDrive) UIUtils.SetActive(point.img_PlayerInCar, isOnDrive) end if isOnDrive then local carImage = carEntity:GetFeatureID() == Const_Ballista_FeatureID and MDL.GuildWar.GetDrivableBallistaImageResource(point.entity) or MDL.GuildWar.GetDrivableMangonelImageResource(point.entity) if isSelf then UTL.Item.SetAtlasSprite(point.img_OwenerInCar, "UI_MiniMap", carImage) else UTL.Item.SetAtlasSprite(point.img_PlayerInCar, "UI_MiniMap", carImage) end self:RefreshDrivablePoint(carEntity.EntityID, isOnDrive) point.carEntity = carEntity else point.carEntity = nil end end function UIGuildWarMiniMapMain:RefreshPlayerDrivableStateByEntityID(entityID, carEntityID, isOnDrive) local point = nil if self.ownerPoint and self.ownerPoint.entity.EntityID == entityID then point = self.ownerPoint elseif self.teammatePoints[entityID] then point = self.teammatePoints[entityID] elseif self.enemyPoints[entityID] then point = self.enemyPoints[entityID] end self:RefreshPlayerDrivableState(point) self:RefreshDrivablePoint(carEntityID, isOnDrive) end function UIGuildWarMiniMapMain:PlayerIsOnDrive(entity) if not entity then return false end local carEntity = entity.components.drive:GetDrivedEntity() if not carEntity then return false end return carEntity:GetFeatureID() == Const_Ballista_FeatureID or carEntity:GetFeatureID() == Const_LittleMangonel_FeatureID, carEntity end ----------------------- -------------- 可驾驶处理 function UIGuildWarMiniMapMain:CreateDrivablePoint(entity) local point = self:CreateDynamicPoint(entity) if point then UIUtils.SetActive(point.gameObject, entity:GetCampID() == BattleDataGetter.GetMyCampID()) UIUtils.SetActive(point.img_Car, true) self.drivablePoints[entity.EntityID] = point UTL.Item.SetAtlasSprite(point.img_Car, "UI_MiniMap", entity:GetFeatureID() == Const_Ballista_FeatureID and MDL.GuildWar.GetDrivableBallistaImageResource(entity) or MDL.GuildWar.GetDrivableMangonelImageResource(entity)) self:SetDynamicPointPos(point, true) end end function UIGuildWarMiniMapMain:RefreshDrivablePoint(carEntityID, isOnDrive) if self.drivablePoints and self.drivablePoints[carEntityID] then local point = self.drivablePoints[carEntityID] UIUtils.SetActive(point.img_Car, not isOnDrive) if not isOnDrive then self:SetDynamicPointPos(point, true) end end end ----------------------- ------------------------------------------------------------------------------- ---------------------------------- 事件处理 ----------------------------------- -- 怪物出生事件 function UIGuildWarMiniMapMain:NotifyMonsterCreate(entity) if not entity then return end local levelItemID = entity._logicInitData.OriginBornItemID -- 投石车营地 if entity:GetFeatureID() == Const_Mangonel_FeatureID then self:RefreshMangonelPointState(levelItemID, entity) elseif entity:GetFeatureID() == Const_BatteringRam_FeatureID then -- 冲车 self:CreateBatteringRamPoint(entity) CTL.Sound.PlayGameSound("UI_strongpoint_light") self:RefreshMotherBaseBatteringRamTipShow() -- 播放营地路线特效 for _, point in pairs (self.batteringRamBasePoints) do if entity:GetCampID() == BattleDataGetter.GetMyCampID() then point.eft_MyRoute:PlayUIEffect() else point.eft_EnemyRoute:PlayUIEffect() end end elseif entity:GetFeatureID() == Const_Boss_FeatureID then -- BOSS self:CreateBossPoint(entity, true) CTL.Sound.PlayGameSound("UI_strongpoint_light") elseif entity:GetFeatureID() == Const_Ballista_FeatureID or entity:GetFeatureID() == Const_LittleMangonel_FeatureID then self:CreateDrivablePoint(entity) elseif entity:GetFeatureID() == Const_Bomb_FeatureID and entity:GetCampID() == BattleDataGetter.GetMyCampID() then local point = self:CreateDynamicPoint(entity) UIUtils.SetActive(point.img_Bomb, true) UTL.Item.SetAtlasSprite(point.img_Bomb, "UI_Battle", "zd_icon_zd_bomb") self.bombPoint = point self:SetDynamicPointPos(point) end end -- 怪物死亡事件 function UIGuildWarMiniMapMain:NotifyMonsterDead(entity) if not entity then return end local levelItemID = entity._logicInitData.OriginBornItemID local entityID = entity.EntityID -- 投石车营地 if entity:GetFeatureID() == Const_Mangonel_FeatureID then self:RefreshMangonelPointState(levelItemID) return elseif self.batteringRamPoints and self.batteringRamPoints[entityID] then -- 冲车 self:SetEntityField(self.batteringRamPoints[entityID]) self:RecycleDynamicPoint(self.batteringRamPoints[entityID]) self.batteringRamPoints[entityID] = nil self:RefreshMotherBaseBatteringRamTipShow() elseif self.bossPoints and self.bossPoints[entityID] then -- BOSS local respwanPoint = self:GetBossRespwanPointByBossEntity(entity) if respwanPoint then -- BOSS出生点 respwanPoint.bossPoints[entityID] = nil self:RefreshBossRespawnPointState(respwanPoint) end self:RecycleDynamicPoint(self.bossPoints[entityID]) self.bossPoints[entityID] = nil elseif self.drivablePoints and self.drivablePoints[entityID] then self:RecycleDynamicPoint(self.drivablePoints[entityID]) self.drivablePoints[entityID] = nil elseif entity:GetFeatureID() == Const_Bomb_FeatureID then if self.bombPoint then UIUtils.SetActive(self.bombPoint.img_Bomb, false) self:RecycleDynamicPoint(self.bombPoint) self.bombPoint = nil end end end -- 基地血量变化 function UIGuildWarMiniMapMain:NotifyMotherBaseChangeHP(motherBaseInfo) if self.motherBasePoints and motherBaseInfo then local totalHP = MDL.GuildWar.MaxGuildWarBaseHp for _, point in pairs (self.motherBasePoints) do local entity = LevelItemManager.GetMonsterByItemID(point.ID) if entity then if entity:GetCampID() == BattleDataGetter.GetMyCampID() then if not self.myBaseIsHurt and point.remainHP ~= motherBaseInfo.selfCamp.hpValue then point.eft_MyHurt:PlayUIEffect() self.myBaseIsHurt = true elseif self.myBaseIsHurt and point.remainHP == motherBaseInfo.selfCamp.hpValue then point.eft_MyHurt:StopUIEffect() self.myBaseIsHurt = false end point.remainHP = motherBaseInfo.selfCamp.hpValue point.img_MyBaseBar.fillAmount = point.remainHP / totalHP else if not self.enemyBaseIsHurt and point.remainHP ~= motherBaseInfo.enemyCamp.hpValue then point.eft_EnemyHurt:PlayUIEffect() self.enemyBaseIsHurt = true elseif self.enemyBaseIsHurt and point.remainHP == motherBaseInfo.enemyCamp.hpValue then point.eft_EnemyHurt:StopUIEffect() self.enemyBaseIsHurt = false end point.remainHP = motherBaseInfo.enemyCamp.hpValue point.img_EnemyBaseBar.fillAmount = point.remainHP / totalHP end end end end end -- 怪物血量变化 function UIGuildWarMiniMapMain:NotifyMonsterChangeHP(entity) if not entity or entity:IsHero() then return end local levelItemID = entity._logicInitData.OriginBornItemID local hpPercent = FP.tonumberV1(entity:GetHp() / entity:GetMaxHp()) if entity:GetFeatureID() == Const_Mangonel_FeatureID then -- 投石车 self:RefreshMangonelHP(levelItemID, hpPercent) elseif entity:GetFeatureID() == Const_BatteringRam_FeatureID then -- 冲车 self:RefreshBatteringRamHP(entity, hpPercent) end end -- 据点占领变化 function UIGuildWarMiniMapMain:NotifyStrongHoldOccupation(levelItemID) -- 投石车据点 if not self:RefreshMangonelOccupation(levelItemID) then -- 冲车据点 self:RefreshBatteringRamOccupation(levelItemID) end end -- 玩家出生 function UIGuildWarMiniMapMain:NotifyPlayerCreate(entity) local entityID = entity.EntityID if BattleDataGetter.GetMyCampID() == entity:GetCampID() then if self.teammatePoints and not self.teammatePoints[entityID] then self:CreatePlayerPoint(entity) end else if self.enemyPoints and not self.enemyPoints[entityID] then self:CreatePlayerPoint(entity) end end end -- 玩家死亡 function UIGuildWarMiniMapMain:NotifyPlayerDead(entity) local entityID = entity.EntityID if self.ownerPoint and self.ownerPoint.entity.EntityID == entityID then self:SetEntityField(self.ownerPoint) UIUtils.SetActive(self.ownerPoint.gameObject, false) return end if BattleDataGetter.GetMyCampID() == entity:GetCampID() then if self.teammatePoints and self.teammatePoints[entityID] then self:SetEntityField(self.teammatePoints[entityID]) self:RecycleDynamicPoint(self.teammatePoints[entityID]) end else if self.enemyPoints and self.enemyPoints[entityID] then self:RecycleDynamicPoint(self.enemyPoints[entityID]) end end end -- 玩家更换(玩家复活) function UIGuildWarMiniMapMain:NotifyPlayerChange(oldEntity) local oldEntityID = oldEntity.EntityID local newEntity = BattleDataGetter.GetPlayerActiveEntity(oldEntity:GetPlayerID()) local newEntityID = newEntity and newEntity.EntityID or -1 if self.ownerPoint and self.ownerPoint.entity.EntityID == oldEntityID then self.ownerPoint.entity = newEntity UIUtils.SetActive(self.ownerPoint.gameObject, true) UIUtils.SetActive(self.ownerPoint.img_Owener, true) self:RefreshOwnerPosAndDir() self:SetEntityField(self.ownerPoint) return end local point = nil if BattleDataGetter.GetMyCampID() == oldEntity:GetCampID() then if self.teammatePoints and self.teammatePoints[oldEntityID] then point = self.teammatePoints[oldEntityID] self.teammatePoints[oldEntityID] = nil self.teammatePoints[newEntityID] = point end else if self.enemyPoints and self.enemyPoints[oldEntityID] then point = self.enemyPoints[oldEntityID] self.enemyPoints[oldEntityID] = nil self.enemyPoints[newEntityID] = point end end if point then point.entity = newEntity UIUtils.SetActive(point.gameObject, point.entity:GetCampID() == BattleDataGetter.GetMyCampID()) UIUtils.SetActive(point.img_Player, true) self:SetDynamicPointIcon(point) self:SetDynamicPointPos(point) self:RefreshPlayerDrivableState(point) self:SetEntityField(point) table.insert(self.fieldEntityIDs, newEntityID) end end -- 玩家上弩车 function UIGuildWarMiniMapMain:NotifyPlayerOnDrive(carEntity, entity) if carEntity:GetFeatureID() == Const_Ballista_FeatureID or carEntity:GetFeatureID() == Const_LittleMangonel_FeatureID then self:RefreshPlayerDrivableStateByEntityID(entity.EntityID, carEntity.EntityID, true) end end -- 玩家下弩车 function UIGuildWarMiniMapMain:NotifyPlayerOffDrive(entity, carEntity) if carEntity:GetFeatureID() == Const_Ballista_FeatureID or carEntity:GetFeatureID() == Const_LittleMangonel_FeatureID then self:RefreshPlayerDrivableStateByEntityID(entity.EntityID, carEntity.EntityID, false) end end -- 大地图拖动特效 GuildWar_Model.MapItemIndex function UIGuildWarMiniMapMain:NotifyPlayPinpointEffect(mapItemIndex) if self.curPinpointEft then self.curPinpointEft:StopUIEffect() self.curPinpointEft = nil end if mapItemIndex and mapItemIndex ~= -1 then local MapItemIndex = MDL.GuildWar.MapItemIndex if mapItemIndex == MapItemIndex.LeftEnemyCity or mapItemIndex == MapItemIndex.MiddleEnemyCity or mapItemIndex == MapItemIndex.RightEnemyCity then for levelItemID, point in pairs (self.motherBasePoints) do local baseMonter = LevelItemManager.GetMonsterByItemID(levelItemID) if BattleDataGetter.GetMyCampID() ~= baseMonter:GetCampID() then self.curPinpointEft = point.eft_Pinpoint break end end elseif mapItemIndex == MapItemIndex.LeftMyCity or mapItemIndex == MapItemIndex.MiddleMyCity or mapItemIndex == MapItemIndex.RightMyCity then for levelItemID, point in pairs (self.motherBasePoints) do local baseMonter = LevelItemManager.GetMonsterByItemID(levelItemID) if BattleDataGetter.GetMyCampID() == baseMonter:GetCampID() then self.curPinpointEft = point.eft_Pinpoint break end end elseif MapItemIndexToID[mapItemIndex] then local idParams = MapItemIndexToID[mapItemIndex] if mapItemIndex == MapItemIndex.MiddleLeftTouShi or mapItemIndex == MapItemIndex.MiddleRightTouShi or mapItemIndex == MapItemIndex.LeftTouShi or mapItemIndex == MapItemIndex.RightTouShi then local point = self.mangonelBasePoints[idParams] if point then self.curPinpointEft = point.eft_Pinpoint end elseif mapItemIndex == MapItemIndex.MiddleChongChe then local point = self.batteringRamBasePoints[idParams] if point then self.curPinpointEft = point.eft_Pinpoint end elseif mapItemIndex == MapItemIndex.LeftBoss or mapItemIndex == MapItemIndex.RightBoss then for _, levelItemID in ipairs (idParams) do for _, point in ipairs (self.bossRespawnPoints) do if point.IDDict and point.IDDict[levelItemID] then self.curPinpointEft = point.eft_Pinpoint break end end if self.curPinpointEft then break end end end end if self.curPinpointEft then self.curPinpointEft:PlayUIEffect() end end end -- 特定位置播放特效(战斗客户端发过来的事件提示) function UIGuildWarMiniMapMain:NotifyPlayEffect(posX, posY, levelItemID, entity) if not self.isInitEnd then return end local eftPoint = nil local eftPath = nil if type(levelItemID) == "number" and LevelItemManager.GetItemByID(levelItemID) then if self.mangonelBasePoints and self.mangonelBasePoints[levelItemID] then eftPoint = self.mangonelBasePoints[levelItemID].eftPoint elseif self.batteringRamBasePoints and self.batteringRamBasePoints[levelItemID] then eftPoint = self.batteringRamBasePoints[levelItemID].eftPoint elseif self.motherBasePoints and self.motherBasePoints[levelItemID] then local baseMonter = LevelItemManager.GetMonsterByItemID(levelItemID) local isMy = BattleDataGetter.GetMyCampID() == baseMonter:GetCampID() eftPoint = isMy and self.motherBasePoints[levelItemID].eft_MyInfo or self.motherBasePoints[levelItemID].eft_EnemyInfo end end if not eftPoint and type(entity) == "table" and entity.EntityID then if entity:GetFeatureID() == Const_Mangonel_FeatureID then local bornItemID = entity._logicInitData.OriginBornItemID for _, point in pairs (self.mangonelBasePoints) do if point.monsterDict and point.monsterDict[bornItemID] then eftPoint = point.eftPoint break end end else local entityID = entity.EntityID local points = nil if entity:GetFeatureID() == Const_BatteringRam_FeatureID and self.batteringRamPoints[entityID] then eftPoint = self.batteringRamPoints[entityID].eftPoint elseif entity:IsHero() then if self.teammatePoints[entityID] then eftPoint = self.teammatePoints[entityID].eftPoint elseif self.enemyPoints[entityID] then eftPoint = self.enemyPoints[entityID].eftPoint end elseif entity:GetFeatureID() == Const_Boss_FeatureID and self.bossPoints[entityID] then eftPoint = self.bossPoints[entityID].eftPoint end end end if not eftPoint and type(posX) == "number" and type(posY) == "number" then eftPoint = self.eftPoint local posX, posY = self:ChangePosToMapPosByPosXY(posX, posY) eftPoint.gameObject.transform:SetLocalPosition(posX, posY, 0) end if eftPoint then eftPoint:PlayUIEffect() else logging.error(LTAG.ERROR, "军团战小地图播放特效失败,检查参数", posX, posY, levelItemID, entity) end end function UIGuildWarMiniMapMain:PlayCommandEffect(index) local eftPoint = nil local eftPath = nil local levelItemID = self.indexToLevelItemID[index] if levelItemID and LevelItemManager.GetItemByID(levelItemID) then if self.mangonelBasePoints and self.mangonelBasePoints[levelItemID] then eftPoint = self.mangonelBasePoints[levelItemID].eftPoint elseif self.batteringRamBasePoints and self.batteringRamBasePoints[levelItemID] then eftPoint = self.batteringRamBasePoints[levelItemID].eftPoint elseif self.motherBasePoints and self.motherBasePoints[levelItemID] then local baseMonter = LevelItemManager.GetMonsterByItemID(levelItemID) local isMy = BattleDataGetter.GetMyCampID() == baseMonter:GetCampID() eftPoint = isMy and self.motherBasePoints[levelItemID].eft_MyInfo or self.motherBasePoints[levelItemID].eft_EnemyInfo end end if eftPoint then eftPoint:PlayUIEffect() end end function UIGuildWarMiniMapMain:GetGroupInfos() self:OnMapUpdate() end function UIGuildWarMiniMapMain:OnMapUpdate(commands) local roomType = MDL.GuildWar.GetRoomTypeByLevelType() local groupInfos = MDL.GuildWar.GetGroupInfos() if groupInfos == nil then self.commands = commands return groupInfos end if commands == nil then commands = self.commands end if groupInfos[roomType] and groupInfos[roomType].players then local players = groupInfos[roomType].players local teamIndex = nil for i=1,#players do if players[i].isHasPlayer and players[i].headInfo.acid == BattleDataGetter.GetAcID() then teamIndex = math.ceil(i/3) end end if teamIndex and commands then for i,v in ipairs(commands) do if v.roomType == MDL.GuildWar.GetRoomTypeByLevelType() then if v.targetId > 0 and v.teamId == teamIndex then self:NotifyPlayPinpointEffect(v.targetId) end end end end end EventSystem.UnRegist(EventID.UI_GuildWarBigMapUpdate, self.OnMapUpdate, self) end ------------------------------------------------------------------------------- -------------------------- 视野相关 -------------------------------------------- function UIGuildWarMiniMapMain:UpdateEntityField(myCampPoint) local entity = myCampPoint.entity if myCampPoint.isInField and entity and entity:GetLogicPos() and BattleDataGetter.GetMyCampID() == entity:GetCampID() then if self.enemyPoints then for _, point in pairs (self.enemyPoints) do if point and point.entity then self:CalEntityDistance(entity, point) end end end if self.drivablePoints then for _, point in pairs (self.drivablePoints) do if point.entity:GetCampID() ~= BattleDataGetter.GetMyCampID() then self:CalEntityDistance(entity, point) end end end end end function UIGuildWarMiniMapMain:CalEntityDistance(entity, point) local range = entity:IsHero() and Player_Visible_Range_Sqr or BatteringRam_Visible_Range_Sqr local bombPropId = 30 --势力战炸弹的道具id为30 if point.entity.components.battleProp:GetBattlePropNum(bombPropId) ~= 0 or not FP.V2.IsDistanceSqrGreater(point.entity:GetLogicPos(), entity:GetLogicPos(), range) then point.fieldDict[entity] = true else point.fieldDict[entity] = nil end end function UIGuildWarMiniMapMain:UpdateFriendEntity() if #self.fieldEntityIDs > 0 then local refreshCount = 0 local remainRefreshCount = PerFrameRefreshFieldMaxCount while (remainRefreshCount > 0) do local entityID = self.fieldEntityIDs[self.curRefreshFieldIndex] if not entityID then break end local point = nil if self.teammatePoints[entityID] then point = self.teammatePoints[entityID] elseif self.batteringRamPoints[entityID] then point = self.batteringRamPoints[entityID] end if point then self:UpdateEntityField(point) remainRefreshCount = remainRefreshCount - 1 self.curRefreshFieldIndex = self.curRefreshFieldIndex < #self.fieldEntityIDs and self.curRefreshFieldIndex + 1 or 1 else -- 无效entityID table.remove(self.fieldEntityIDs, self.curRefreshFieldIndex) self.curRefreshFieldIndex = self.curRefreshFieldIndex <= #self.fieldEntityIDs and self.curRefreshFieldIndex or 1 end refreshCount = refreshCount + 1 if #self.fieldEntityIDs == 0 or refreshCount >= #self.fieldEntityIDs then if #self.fieldEntityIDs == 0 then self.curRefreshFieldIndex = 1 end break end end end end --每0.1秒刷新一次 每次都刷新自己 如果当前刷新静态item 就不刷新友方entity 反之亦然 function UIGuildWarMiniMapMain:NewCheckFriendlyField() --UnityProfiler.BeginSample("UIGuildWarMiniMapMain:NewCheckFriendlyField") if self.ownerPoint then self:UpdateEntityField(self.ownerPoint) end if self.curUpdateItem then self:UpdateAllItemPoints() else self:UpdateFriendEntity() end if self.enemyPoints then for _, point in pairs (self.enemyPoints) do if point and point.entity then local isShow = next(point.fieldDict) and true or false UIUtils.SetActive(point.gameObject, isShow) end end end if self.drivablePoints then for _, point in pairs (self.drivablePoints) do if point.entity:GetCampID() ~= BattleDataGetter.GetMyCampID() then local isShow = next(point.fieldDict) and true or false UIUtils.SetActive(point.gameObject, isShow) end end end self.curUpdateItem = not self.curUpdateItem --UnityProfiler.EndSample() end --投石车 据点 工程车 都在这list里 最坏情况刷新5次 function UIGuildWarMiniMapMain:UpdateAllItemPoints() for i, v in pairs(self.motherBasePoints) do self:SetLevelItemField(v) end for i, v in pairs(self.batteringRamBasePoints) do self:SetLevelItemField(v) end for i, v in pairs(self.mangonelBasePoints) do self:SetLevelItemField(v) end end function UIGuildWarMiniMapMain:SetEntityField(entityPoint) if not entityPoint then return end local entity = entityPoint.entity if entity and entity:GetLogicPos() and BattleDataGetter.GetMyCampID() == entityPoint.entity:GetCampID() then --死亡 不在视野了 if entityPoint.isInField then entityPoint.isInField = false --移除视野 self:RemoveFriendField(entity) else entityPoint.isInField = true end end end function UIGuildWarMiniMapMain:RemoveFriendField(entity) if self.enemyPoints then for _, point in pairs(self.enemyPoints) do if point and point.entity then point.fieldDict[entity] = nil end end end if self.drivablePoints then for _, point in pairs(self.drivablePoints) do if point.entity:GetCampID() ~= BattleDataGetter.GetMyCampID() then point.fieldDict[entity] = nil end end end end function UIGuildWarMiniMapMain:SetLevelItemField(levelItemPoint) if not levelItemPoint then return end self:UpdateLevelItemField(levelItemPoint) end function UIGuildWarMiniMapMain:CalLevelItemField(itemPoint, itemPos) if not itemPoint or not itemPos then return end if self.enemyPoints then for _, point in pairs (self.enemyPoints) do if point and point.entity then self:CalIemDistance(point, itemPoint, itemPos) end end end if self.drivablePoints then for _, point in pairs (self.drivablePoints) do if point.entity:GetCampID() ~= BattleDataGetter.GetMyCampID() then self:CalIemDistance(point, itemPoint, itemPos) end end end end function UIGuildWarMiniMapMain:ClearLevelItemField(itemPoint) if self.enemyPoints then for _, point in pairs(self.enemyPoints) do if point and point.entity then point.fieldDict[itemPoint] = nil end end end if self.drivablePoints then for _, point in pairs(self.drivablePoints) do point.fieldDict[itemPoint] = nil end end end function UIGuildWarMiniMapMain:CalIemDistance(point, itemPoint, pos) local range = Camp_Visible_Range_Sqr local distance = FP.V2.DistanceSqr(point.entity:GetLogicPos(), pos) if not FP.V2.IsDistanceSqrGreater(point.entity:GetLogicPos(), pos, range) then point.fieldDict[itemPoint] = true else point.fieldDict[itemPoint] = nil end end function UIGuildWarMiniMapMain:UpdateLevelItemField(levelItemPoint) if not levelItemPoint then return end local levelItem = LevelItemManager.GetItemByID(levelItemPoint.ID) if levelItem then if levelItem.LevelItemType == LuaConst.LevelItemType.BornPoint then local baseMonter = LevelItemManager.GetMonsterByItemID(levelItemID) local isMy = BattleDataGetter.GetMyCampID() == baseMonter:GetCampID() if isMy and not levelItemPoint.isInField then self:CalLevelItemField(levelItemPoint, levelItem.ItemData.ItemPos) levelItemPoint.isInField = true end elseif levelItem.LevelItemType == LuaConst.LevelItemType.StrongHold then if levelItem:GetCurOccupierID() == BattleDataGetter.GetMyCampID() then if not levelItemPoint.isInField then levelItemPoint.isInField = true end self:CalLevelItemField(levelItemPoint, levelItem.ItemData.ItemPos) else if levelItemPoint.isInField then levelItemPoint.fieldDict = {} levelItemPoint.isInField = false self:ClearLevelItemField(levelItemPoint) end end end end end function UIGuildWarMiniMapMain:OnBossAttack(entity) local point = self.bossPoints[entity.EntityID] local effectPoint = point and point.eft_BossAttack if effectPoint and self:CanPlayEffect(effectPoint) then effectPoint:PlayUIEffect(ConstAssetPathConfig.AssetPath136, 1) end end function UIGuildWarMiniMapMain:OnToushicheAttack(entity) local levelItemID = entity._logicInitData.BornItemID local effectPoint = nil if self.mangonelBasePoints then for _, point in pairs(self.mangonelBasePoints) do if point and point.monsterDict and point.monsterDict[levelItemID] then effectPoint = point.eft_Pinpoint end end end if effectPoint and self:CanPlayEffect(effectPoint) then if entity:GetCampID() == BattleDataGetter.GetMyCampID() then effectPoint:PlayUIEffect(ConstAssetPathConfig.AssetPath100, 1) else effectPoint:PlayUIEffect(ConstAssetPathConfig.AssetPath101, 1) end end end function UIGuildWarMiniMapMain:CanPlayEffect(effectPoint) local lastPlayTime = self.lastPlayEffectDict[effectPoint] if lastPlayTime and Time.realtimeSinceStartup - lastPlayTime < 1 then return false else self.lastPlayEffectDict[effectPoint] = Time.realtimeSinceStartup return true end end function UIGuildWarMiniMapMain:NotifyCommandEffect(commandData) local commandItemType = commandData.type local effectPoint = nil local CommandMapItemType = MDL.GuildWar.CommandMapItemType if commandItemType == CommandMapItemType.MiddleChongChe then effectPoint = self.batteringRamBasePoints[MapItemIndexToID[MDL.GuildWar.MapItemIndex.MiddleChongChe]].eft_Pinpoint elseif commandItemType == CommandMapItemType.LeftTouShi then effectPoint = self.mangonelBasePoints[MapItemIndexToID[MDL.GuildWar.MapItemIndex.LeftTouShi]].eft_Pinpoint elseif commandItemType == CommandMapItemType.MiddleLeftTouShi then if not self.isMirrorMap then effectPoint = self.mangonelBasePoints[MapItemIndexToID[MDL.GuildWar.MapItemIndex.MiddleRightTouShi]].eft_Pinpoint else effectPoint = self.mangonelBasePoints[MapItemIndexToID[MDL.GuildWar.MapItemIndex.MiddleLeftTouShi]].eft_Pinpoint end elseif commandItemType == CommandMapItemType.MiddleRightTouShi then if self.isMirrorMap then effectPoint = self.mangonelBasePoints[MapItemIndexToID[MDL.GuildWar.MapItemIndex.MiddleRightTouShi]].eft_Pinpoint else effectPoint = self.mangonelBasePoints[MapItemIndexToID[MDL.GuildWar.MapItemIndex.MiddleLeftTouShi]].eft_Pinpoint end elseif commandItemType == CommandMapItemType.LeftBoss then local idParams = MapItemIndexToID[MDL.GuildWar.MapItemIndex.LeftBoss] for _, levelItemID in ipairs (idParams) do for _, point in ipairs (self.bossRespawnPoints) do if point.IDDict and point.IDDict[levelItemID] then effectPoint = point.eft_Pinpoint break end end end elseif commandItemType == CommandMapItemType.EnemyCity then local cityEntity1 = LevelItemManager.GetItemByID(2001):GetMonsterEntity() local cityEntity2 = LevelItemManager.GetItemByID(2002):GetMonsterEntity() if cityEntity1:GetCampID() == BattleDataGetter.GetMyCampID() then effectPoint = self.motherBasePoints[2002].eft_Pinpoint else effectPoint = self.motherBasePoints[2001].eft_Pinpoint end elseif commandItemType == CommandMapItemType.MyCity then local cityEntity1 = LevelItemManager.GetItemByID(2001):GetMonsterEntity() local cityEntity2 = LevelItemManager.GetItemByID(2002):GetMonsterEntity() if cityEntity1:GetCampID() == BattleDataGetter.GetMyCampID() then effectPoint = self.motherBasePoints[2001].eft_Pinpoint else effectPoint = self.motherBasePoints[2002].eft_Pinpoint end end if effectPoint then effectPoint:PlayUIEffect(ConstAssetPathConfig.AssetPath99, 3) end end return UIGuildWarMiniMapMain