| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950 |
- local MainAssistLayout = class("MainAssistLayout", function()
- return cc.Node:create()
- end)
- local utf8 = require("util/utf8")
- local proxyUtils = requireProxy("proxyUtils")
- function MainAssistLayout:ctor()
- self._path = global.MMO.PATH_RES_PRIVATE .. "main/"
- -- 提高进出视野效率
- self._updateActorAble = false
- self._updateHeroAble = false
- self._checkHero = false
- end
- function MainAssistLayout.create()
- local layout = MainAssistLayout.new()
- if layout:Init() then
- return layout
- end
- return nil
- end
- function MainAssistLayout:Init()
- self._ui = ui_delegate(self)
- return true
- end
- function MainAssistLayout:InitGUI( ... )
- SL:RequireFile(SLDefine.LUAFile.LUA_FILE_MAIN_ASSIST)
- MainAssist.main()
- self:InitAssist()
- self:InitEnemy()
- self:InitHero()
- self:InitEditMode()
- return true
- end
- function MainAssistLayout:InitEditMode()
- local items =
- {
- "Panel_assist",
- "Panel_hide",
- "Image_24",
- "Button_hide",
- }
- for _, widgetName in ipairs(items) do
- if self._ui[widgetName] then
- self._ui[widgetName].editMode = 1
- end
- end
- end
- function MainAssistLayout:ChangeHideStatus(data)
- MainAssist.ChangeHideStatus(data)
- end
- function MainAssistLayout:ReloadCUISetWidget( ... )
- if self._layoutAssist then
- MainAssist._assistPos = GUI:getPosition(self._layoutAssist)
- end
- if self._ui["Panel_hide"] then
- MainAssist._hidePos = GUI:getPosition(self._ui["Panel_hide"])
- end
- end
- function MainAssistLayout:InitAssist()
- self._assistGroup = 0 -- 活动 2任务组队 1附近列表 3英雄
- self._contentIndex = 0 -- 任务组队显示索引 1任务 2组队
- self._enemyIndex = 0 -- 人物怪物显示索引 1玩家 2怪物
- self._layoutAssist = self._ui.Panel_assist
- -- group
- self._layoutGroup = self._layoutAssist:getChildByName("Panel_group")
- self._ui_group = ui_delegate(self._layoutGroup)
- if not self._ui_group then
- return
- end
- self._ui_group.Button_change:addClickEventListener(function()
- local maxGroup = 2
- local group = self._assistGroup == 1 and maxGroup or self._assistGroup - 1
- if tonumber(SL:GetMetaValue("GAME_DATA","syshero") or 0) == 1 then
- maxGroup = 3
- if self._assistGroup == 1 then
- group = maxGroup
- elseif self._assistGroup == 2 then
- group = maxGroup - self._assistGroup
- elseif self._assistGroup == 3 then
- group = 2
- end
- end
- self:ChangeAssistGroup(group)
- self:CalcAssistShow()
- global.Facade:sendNotification(global.NoticeTable.GuideEventEnded, {name = "GUIDE_ASSIST_MISSION_END"})
- end)
- -- 任务/组队
- self._ui_group.Button_mission:addClickEventListener(function()
- self:ChangeContentIndex(1)
- self:CalcAssistShow()
- end)
- self._ui_group.Button_team:addClickEventListener(function()
- self:ChangeContentIndex(2)
- self:CalcAssistShow()
- end)
- -- 人物/怪物
- self._ui_group.Button_player:addClickEventListener(function()
- self:ChangeEnemyIndex(1)
- self:CalcAssistShow()
- end)
- self._ui_group.Button_monster:addClickEventListener(function()
- self:ChangeEnemyIndex(2)
- self:CalcAssistShow()
- end)
- -- content
- self._layoutContent = self._layoutAssist:getChildByName("Panel_content")
- self._ui_content = ui_delegate(self._layoutContent)
- self._listviewCells = self._ui_content.ListView_mission
- -- enemy
- self._layoutEnemy = self._layoutAssist:getChildByName("Panel_enemy")
- self._ui_enemy = ui_delegate(self._layoutEnemy)
- -- hero
- self._layoutHero = self._layoutAssist:getChildByName("Panel_hero")
- self._ui_hero = ui_delegate(self._layoutHero)
- self:ChangeAssistGroup(2)
- self:ChangeContentIndex(1)
- self:ChangeEnemyIndex(1)
- self:CalcAssistShow()
- end
- function MainAssistLayout:OnSwitchBackToMission()
- self:ChangeAssistGroup(2)
- self:ChangeContentIndex(1)
- self:ChangeEnemyIndex(1)
- self:CalcAssistShow()
- end
- function MainAssistLayout:ChangeAssistGroup(g)
- self._assistGroup = g
- self._ui_group.BtnG_content:setVisible(self._assistGroup == 2)
- self._ui_group.BtnG_enemy:setVisible(self._assistGroup == 1)
- self._ui_group.BtnG_hero:setVisible(self._assistGroup == 3)
- end
- function MainAssistLayout:ChangeContentIndex(index)
- self._contentIndex = index
- self._ui_group.Button_mission:setTouchEnabled(self._contentIndex == 2)
- self._ui_group.Button_mission:setBright(self._contentIndex == 1)
- self._ui_group.Button_team:setTouchEnabled(self._contentIndex == 1)
- self._ui_group.Button_team:setBright(self._contentIndex == 2)
-
- if not (self._contentIndex == 1) then
- global.Facade:sendNotification(global.NoticeTable.GuideEventEnded, {name = "GUIDE_ASSIST_MISSION_END"})
- end
- end
- function MainAssistLayout:ChangeEnemyIndex(index)
- self._enemyIndex = index
- self._ui_group.Button_player:setTouchEnabled(self._enemyIndex == 2)
- self._ui_group.Button_player:setBright(self._enemyIndex == 1)
- self._ui_group.Button_monster:setTouchEnabled(self._enemyIndex == 1)
- self._ui_group.Button_monster:setBright(self._enemyIndex == 2)
- self:UpdateAllEnemy()
- end
- function MainAssistLayout:CalcAssistShow()
- self._ui_content.nativeUI:setVisible(self._assistGroup == 2)
- self._ui_enemy.nativeUI:setVisible(self._assistGroup == 1)
- self._ui_hero.nativeUI:setVisible(self._assistGroup == 3)
- -- 任务组队
- self._ui_content.Panel_mission:setVisible(self._contentIndex == 1)
- self._ui_content.Panel_team:setVisible(self._contentIndex == 2)
-
- -- 附近列表
- self._ui_enemy.Panel_player:setVisible(self._enemyIndex == 1)
- self._ui_enemy.Panel_monster:setVisible(self._enemyIndex == 2)
- end
- ---------------------------------Enemy begin------------------------------------
- function MainAssistLayout:InitEnemy()
- self._enemyCells = {}
- self._playerCells = {}
- self._monsterCells = {}
- self._ui_enemy.ListView_player:removeAllItems()
- self._ui_enemy.ListView_monster:removeAllItems()
- -- 1s检测一次
- schedule(self._layoutEnemy, function()
- self:CheckAllEnemy()
- end, 1)
- end
- function MainAssistLayout:CheckAllEnemy()
- if not self._updateActorAble then
- return nil
- end
- self._updateActorAble = false
- if self._enemyIndex == 1 then
- self:AutoAddPlayer()
- elseif self._enemyIndex == 2 then
- self:AutoAddMonster()
- end
- end
- function MainAssistLayout:CreateEnemyCell(data)
- local root = cc.Node:create()
- local tData = {
- actorID = data.actorID
- }
- if MainAssist and MainAssist.CreateEnemyCell then
- return MainAssist.CreateEnemyCell(root, tData)
- end
- end
- function MainAssistLayout:UpdateAllEnemy()
- self._enemyCells = {}
- self._ui_enemy.ListView_player:removeAllItems()
- self._ui_enemy.ListView_monster:removeAllItems()
- if self._enemyIndex == 1 then
- self:AutoAddPlayer()
-
- elseif self._enemyIndex == 2 then
- self:AutoAddMonster()
- end
- end
- function MainAssistLayout:OnMainNearRefresh(data)
- local actor = data.actor
- local actorID = data.actorID
- if actorID == global.playerManager:GetMainPlayerID() then
- return
- end
-
- if actor:IsPlayer() then
- if actor:IsHero() then
- self:RmvHero(data)
- else
- self:RmvPlayer(data)
- end
- if self._enemyIndex == 1 then
- self:AutoAddPlayer()
- end
- elseif actor:IsMonster() then
- self:RmvMonster(data)
- if self._enemyIndex == 2 then
- self:AutoAddMonster()
- end
- end
- end
- function MainAssistLayout:OnActorRevive(data)
- local actor = data.actor
- local actorID = data.actorID
- if actorID == global.playerManager:GetMainPlayerID() then
- return
- end
- self._updateActorAble = true
- self._updateHeroAble = true
- end
- function MainAssistLayout:OnActorInOfView(data)
- local actor = data.actor
- local actorID = data.actorID
- if actorID == global.playerManager:GetMainPlayerID() then
- return
- end
-
- self._updateActorAble = true
- self._updateHeroAble = true
- end
- function MainAssistLayout:OnActorOutOfView(data)
- local actor = data.actor
- local actorID = data.actorID
- if actorID == global.playerManager:GetMainPlayerID() then
- return
- end
- self._updateActorAble = true
- self._updateHeroAble = true
-
- if actor:IsPlayer() then
- if actor:IsHero() then
- self:RmvHero(data)
- elseif actor:IsHumanoid() then
- self:RmvMonster(data)
- else
- self:RmvPlayer(data)
- end
- elseif actor:IsMonster() then
- self:RmvMonster(data)
- end
- end
- function MainAssistLayout:OnActorDie(data)
- local actor = data.actor
- local actorID = data.actorID
- if actorID == global.playerManager:GetMainPlayerID() then
- return
- end
- self._updateActorAble = true
- self._updateHeroAble = true
-
- if actor:IsPlayer() then
- if actor:IsHero() then
- self:RmvHero(data)
- elseif actor:IsHumanoid() then
- self:RmvMonster(data)
- else
- self:RmvPlayer(data)
- end
- elseif actor:IsMonster() then
- self:RmvMonster(data)
- end
- end
- function MainAssistLayout:OnRefreshActorHP(data)
- self:UpdateEnemy(data)
- self:UpdateHero(data)
- end
- function MainAssistLayout:OnTargetChange(data)
- local targetID = data.targetID
- for k, v in pairs(self._enemyCells) do
- v.imageTarget:setVisible(k == targetID)
- end
- end
- function MainAssistLayout:OnPlayerPKStateChange()
- -- 切模式,刷新附近列表
- if self._enemyIndex ~= 1 then
- return nil
- end
- self._enemyCells = {}
- self._ui_enemy.ListView_player:removeAllItems()
- self:AutoAddPlayer()
- end
- local function checkPeaceModeEnemyTag(actor)
- if not actor then
- return global.MMO.RS_NO
- end
- -- 1. oneself
- local mainPlayer = global.gamePlayerController:GetMainPlayer()
- if not mainPlayer or ( actor:IsPlayer() and actor:IsMainPlayer() ) then
- return global.MMO.RS_NO
- end
- return global.MMO.RS_ENEMY
- end
- local function checkPeaceLaunchTarget(targetActor)
- -- player & monster, only!!!!
- if false == targetActor:IsPlayer() and false == targetActor:IsMonster() then
- return false
- end
- local mainPlayer = global.gamePlayerController:GetMainPlayer()
- if not mainPlayer then
- return false
- end
- local autoProxy = global.Facade:retrieveProxy(global.ProxyTable.Auto)
- if autoProxy:IsAutoFightState() then --所有模式 可以攻击自己的宝宝
- ---- hero player / matser is main hero
- local HeroPropertyProxy = global.Facade:retrieveProxy( global.ProxyTable.HeroPropertyProxy )
- local heroID = HeroPropertyProxy:GetRoleUID()
- if heroID and (targetActor:GetID() == heroID or targetActor:GetMasterID() == heroID) then
- return false
- end
- -- main player / matser is main player
- if (targetActor:IsPlayer() and targetActor:IsMainPlayer()) or targetActor:GetMasterID() == mainPlayer:GetID() then
- return false
- end
- end
- -- dead & born
- if targetActor:IsDie() or targetActor:IsDeath() or targetActor:IsBorn() or targetActor:IsCave() then
- return false
- end
-
- -- hp 0
- if targetActor:GetHP() <= 0 then
- return false
- end
- -- humanoid
- if targetActor:IsPlayer() and targetActor:IsHumanoid() then
- if targetActor:GetMasterID() and checkPeaceModeEnemyTag(targetActor) ~= 1 then --人性怪如果有MasterID, 要判断Master是否是敌友
- return false
- end
- return true
- end
- -- player, check is enmey
- if targetActor:IsPlayer() and checkPeaceModeEnemyTag(targetActor) ~= 1 then
- return false
- end
- if targetActor:IsHero() and checkPeaceModeEnemyTag(targetActor) ~= 1 then
- return false
- end
- -- 采集物
- if targetActor:IsCollection() then
- return false
- end
- -- buff的石化怪
- if targetActor:IsMonster() and targetActor:GetStoneMode() and not targetActor:IsBorn() then
- return false
- end
- return true
- end
- function MainAssistLayout:CheckPlayerEnemyTag(actor)
- local playerPropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
- local pkMode = playerPropertyProxy:GetPKMode()
- if pkMode ~= global.MMO.HAM_PEACE then
- return proxyUtils.checkEnemyTag(actor)
- else
- return checkPeaceModeEnemyTag(actor)
- end
- end
- function MainAssistLayout:CheckPlayerLaunchTarget(actor)
- local playerPropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
- local pkMode = playerPropertyProxy:GetPKMode()
- if pkMode ~= global.MMO.HAM_PEACE then
- return proxyUtils.checkLaunchTarget(actor)
- else
- return checkPeaceLaunchTarget(actor)
- end
- end
- function MainAssistLayout:AddPlayer(data)
- local actor = data.actor
- local actorID = data.actorID
- if self._enemyIndex ~= 1 then
- return
- end
- if self._enemyCells[actorID] then
- return
- end
- if false == self:CheckPlayerLaunchTarget(actor) then
- -- enemy only
- return
- end
- local listview = self._ui_enemy.ListView_player
- local items = listview:getItems()
- if #items >= MainAssist.PLAYER_COUNT then
- return
- end
- -- 找到插入位置
- local insertIndex = #items
- for enemyID, enemyCell in pairs(self._enemyCells) do
- local enemy = global.actorManager:GetActor(enemyID)
- -- 我日,出错了,啥错啊,难搞
- if nil == enemy then
- print("ERRORRRRRRRRRRRRRRRRRRR AddPlayer")
- return
- end
- if self:CheckPlayerEnemyTag(enemy) == 1 and self:CheckPlayerEnemyTag(actor) == 1 then
- -- 都可以攻击,判断等级
- if actor:GetLevel() > enemy:GetLevel() then
- insertIndex = math.min(insertIndex, listview:getIndex(enemyCell.layout))
- end
- elseif self:CheckPlayerEnemyTag(enemy) ~= 1 and self:CheckPlayerEnemyTag(actor) == 1 then
- -- 一个可攻击,一个不可以攻击,取可以攻击的
- insertIndex = math.min(insertIndex, listview:getIndex(enemyCell.layout))
-
- elseif self:CheckPlayerEnemyTag(enemy) ~= 1 and self:CheckPlayerEnemyTag(actor) ~= 1 then
- -- 都不可以攻击,判断等级
- if actor:GetLevel() > enemy:GetLevel() then
- insertIndex = math.min(insertIndex, listview:getIndex(enemyCell.layout))
- end
- end
- end
- local cell = self:CreateEnemyCell(data)
- if cell and next(cell) then
- listview:insertCustomItem(cell.layout, insertIndex)
- self._enemyCells[actorID] = cell
- end
- end
- function MainAssistLayout:RmvPlayer(data)
- local actor = data.actor
- local actorID = data.actorID
- if self._enemyIndex ~= 1 then
- return
- end
- if not self._enemyCells[actorID] then
- return
- end
- local listview = self._ui_enemy.ListView_player
- local cell = self._enemyCells[actorID]
- listview:removeItem(listview:getIndex(cell.layout))
- self._enemyCells[actorID] = nil
- end
- function MainAssistLayout:AutoAddPlayer()
- if self._enemyIndex ~= 1 then
- return
- end
- local listview = self._ui_enemy.ListView_player
- local items = listview:getItems()
- if #items >= MainAssist.PLAYER_COUNT then
- return
- end
- local actors, nActor = global.playerManager:GetPlayersInCurrViewField()
- for i = 1, nActor do
- local actor = actors[i]
- if actor and not actor:IsMainPlayer() and not actor:IsHero() and not actor:IsHumanoid() and not actor:GetValueByKey(global.MMO.HUD_SNEAK) then
- self:AddPlayer({actor = actor, actorID = actor:GetID()})
- self:AutoRmvPlayer()
- end
- end
- end
- function MainAssistLayout:AutoRmvPlayer()
- if self._enemyIndex ~= 1 then
- return
- end
- local listview = self._ui_enemy.ListView_player
- local items = listview:getItems()
- if #items <= MainAssist.PLAYER_COUNT then
- return
- end
- local rmved = nil
- for enemyID, enemyCell in pairs(self._enemyCells) do
- local enemy = global.actorManager:GetActor(enemyID)
- -- 出错了吧
- if nil == enemy then
- print("ERRORRRRRRRRRRRRRRRRRRR AutoRmvPlayer")
- break
- end
-
- if nil == rmved then
- rmved = enemy
- elseif proxyUtils.checkEnemyTag(enemy) == 1 and proxyUtils.checkEnemyTag(rmved) == 1 then
- -- 都可以攻击,判断等级
- if rmved:GetLevel() > enemy:GetLevel() then
- rmved = enemy
- end
- elseif proxyUtils.checkEnemyTag(enemy) == 1 and proxyUtils.checkEnemyTag(rmved) ~= 1 then
- -- 一个可攻击,一个不可以攻击,取可以攻击的
- rmved = enemy
-
- elseif proxyUtils.checkEnemyTag(enemy) ~= 1 and proxyUtils.checkEnemyTag(rmved) ~= 1 then
- -- 都不可以攻击,判断等级
- if rmved:GetLevel() > enemy:GetLevel() then
- rmved = enemy
- end
- end
- end
- if rmved then
- self:RmvPlayer({actorID = rmved:GetID(), actor = rmved})
- end
- end
- local function getWeight(actor)
- local weight = 0
- if actor:IsEscort() then
- weight = 4
- elseif actor:IsBoss() then
- weight = 3
-
- elseif actor:IsElite() then
- weight = 2
-
- elseif actor:IsMonster() and false == actor:IsHaveMaster() then
- weight = 1
- end
- return weight
- end
- function MainAssistLayout:AddMonster(data)
- local actor = data.actor
- local actorID = data.actorID
- if self._enemyIndex ~= 2 then
- return
- end
- if self._enemyCells[actorID] then
- return
- end
- if false == proxyUtils.checkLaunchTarget(actor) then
- -- enemy only
- return
- end
- local listview = self._ui_enemy.ListView_monster
- local items = listview:getItems()
- if #items >= MainAssist.MONSTER_COUNT and getWeight(actor) == 0 then
- return
- end
- -- 根据怪物权值找到插入位置
- local insertIndex = #items
- for enemyID, enemyCell in pairs(self._enemyCells) do
- local enemy = global.actorManager:GetActor(enemyID)
- if enemy and getWeight(actor) > getWeight(enemy) then
- insertIndex = math.min(listview:getIndex(enemyCell.layout), insertIndex)
- end
- end
- local cell = self:CreateEnemyCell(data)
- if cell and next(cell) then
- listview:insertCustomItem(cell.layout, insertIndex)
- self._enemyCells[actorID] = cell
- end
- end
- function MainAssistLayout:RmvMonster(data)
- local actor = data.actor
- local actorID = data.actorID
- if self._enemyIndex ~= 2 then
- return
- end
- if not self._enemyCells[actorID] then
- return
- end
- local listview = self._ui_enemy.ListView_monster
- local cell = self._enemyCells[actorID]
- listview:removeItem(listview:getIndex(cell.layout))
- self._enemyCells[actorID] = nil
- end
- function MainAssistLayout:AutoAddMonster()
- if self._enemyIndex ~= 2 then
- return
- end
- local listview = self._ui_enemy.ListView_monster
- local items = listview:getItems()
- if #items >= MainAssist.MONSTER_COUNT then
- return
- end
- local actors, nActor = global.monsterManager:FindMonsterInCurrViewField(true)
-
- local playerVec, nPlayer = global.playerManager:FindPlayerInCurrViewField()
- for i = 1, nPlayer do
- local player = playerVec[i]
- if player:IsHumanoid() then
- nActor = nActor + 1
- actors[nActor] = player
- end
- end
- for i = 1, nActor do
- local actor = actors[i]
- if actor then
- self:AddMonster({actor = actor, actorID = actor:GetID()})
- self:AutoRmvMonster()
- end
- end
- end
- function MainAssistLayout:AutoRmvMonster()
- if self._enemyIndex ~= 2 then
- return
- end
- local listview = self._ui_enemy.ListView_monster
- local items = listview:getItems()
- if #items <= MainAssist.MONSTER_COUNT then
- return
- end
- local rmved = nil
- for enemyID, enemyCell in pairs(self._enemyCells) do
- local enemy = global.actorManager:GetActor(enemyID)
- -- 出错了吧
- if nil == enemy then
- print("ERRORRRRRRRRRRRRRRRRRRR AutoRmvMonster")
- break
- end
- -- 根据权重,移除
- if getWeight(enemy) == 0 then
- rmved = enemy
- break
- end
- if nil == rmved or getWeight(enemy) < getWeight(rmved) then
- rmved = enemy
- end
- end
- if rmved then
- self:RmvMonster({actorID = rmved:GetID(), actor = rmved})
- end
- end
- function MainAssistLayout:OnActorMonsterBirth(data)
- local actor = data.actor
- local actorID = data.actorID
- self._updateActorAble = true
- end
- function MainAssistLayout:OnActorMonsterCave(data)
- local actor = data.actor
- local actorID = data.actorID
- self._updateActorAble = true
- end
- function MainAssistLayout:UpdateEnemy(data)
- local actorID = data.actorID
- local actor = global.actorManager:GetActor(actorID)
- if not actor then
- return
- end
- if not ((self._enemyIndex == 1 and actor:IsPlayer()) or (self._enemyIndex == 2 and actor:IsMonster())) then
- return
- end
- if not self._enemyCells[actorID] then
- return
- end
- local cell = self._enemyCells[actorID]
- local curHP = actor:GetHP()
- local maxHP = actor:GetMaxHP()
- local percent = math.floor((curHP / maxHP * 100))
- cell.loadingBarHp:setPercent(percent)
- end
- ----------------------------------Enemy end-------------------------------------
- function MainAssistLayout:InitHero()
- self._checkHero = tonumber(SL:GetMetaValue("GAME_DATA","syshero")) == 1
- if self._checkHero then
- self._heroCells = {}
- self._ui_hero.ListView_hero:removeAllItems()
- schedule(self._layoutHero, function()
- self:CheckAllHero()
- end, 1)
- end
- end
- function MainAssistLayout:CheckAllHero( ... )
- if not self._updateHeroAble then
- return nil
- end
- self._updateHeroAble = false
- if self._assistGroup == 3 and self._checkHero then
- local items = self._ui_hero.ListView_hero:getItems()
- if #items >= MainAssist.HERO_COUNT then
- return
- end
-
- local actors, nActor = global.playerManager:FindHeroInCurrViewField()
- for i = 1, nActor do
- local actor = actors[i]
- self:AddHero({actor = actor, actorID = actor:GetID()})
- self:AutoRmvHero()
- end
- end
- end
- function MainAssistLayout:AddHero(data)
- local actor = data.actor
- local actorID = data.actorID
- if not (self._assistGroup == 3 and self._checkHero) then
- return
- end
- if self._heroCells[actorID] then
- return
- end
- if false == proxyUtils.checkLaunchTarget(actor) then
- -- enemy only
- return
- end
- local listview = self._ui_hero.ListView_hero
- local items = listview:getItems()
- if #items >= MainAssist.HERO_COUNT then
- return
- end
- -- 找到插入位置
- local insertIndex = #items
- for heroID, heroCell in pairs(self._heroCells) do
- local hero = global.actorManager:GetActor(heroID)
- if nil == hero then
- print("ERRORRRRRRRRRRRRRRRRRRR AddHERO BY ASSIST")
- break
- end
- if proxyUtils.checkEnemyTag(hero) == 1 and proxyUtils.checkEnemyTag(actor) == 1 then
- -- 都可以攻击,判断等级
- if actor:GetLevel() > hero:GetLevel() then
- insertIndex = math.min(insertIndex, listview:getIndex(heroCell.layout))
- end
- elseif proxyUtils.checkEnemyTag(hero) ~= 1 and proxyUtils.checkEnemyTag(actor) == 1 then
- -- 一个可攻击,一个不可以攻击,取可以攻击的
- insertIndex = math.min(insertIndex, listview:getIndex(heroCell.layout))
-
- elseif proxyUtils.checkEnemyTag(hero) ~= 1 and proxyUtils.checkEnemyTag(actor) ~= 1 then
- -- 都不可以攻击,判断等级
- if actor:GetLevel() > hero:GetLevel() then
- insertIndex = math.min(insertIndex, listview:getIndex(heroCell.layout))
- end
- end
- end
- local cell = self:CreateEnemyCell(data)
- if cell and next(cell) then
- listview:insertCustomItem(cell.layout, insertIndex)
- self._heroCells[actorID] = cell
- end
- end
- function MainAssistLayout:AutoRmvHero()
- if not (self._assistGroup == 3 and self._checkHero) then
- return
- end
- local listview = self._ui_hero.ListView_hero
- local items = listview:getItems()
- if #items <= MainAssist.HERO_COUNT then
- return
- end
- local rmved = nil
- for heroID, heroCell in pairs(self._heroCells) do
- local hero = global.actorManager:GetActor(heroID)
- if nil == hero then
- print("ERRORRRRRRRRRRRRRRRRRRR AutoRmvHERO ")
- break
- end
-
- if nil == rmved then
- rmved = hero
- elseif proxyUtils.checkEnemyTag(hero) == 1 and proxyUtils.checkEnemyTag(rmved) == 1 then
- -- 都可以攻击,判断等级
- if rmved:GetLevel() > hero:GetLevel() then
- rmved = hero
- end
- elseif proxyUtils.checkEnemyTag(hero) == 1 and proxyUtils.checkEnemyTag(rmved) ~= 1 then
- -- 一个可攻击,一个不可以攻击,取可以攻击的
- rmved = hero
-
- elseif proxyUtils.checkEnemyTag(hero) ~= 1 and proxyUtils.checkEnemyTag(rmved) ~= 1 then
- -- 都不可以攻击,判断等级
- if rmved:GetLevel() > hero:GetLevel() then
- rmved = hero
- end
- end
- end
- if rmved then
- self:RmvHero({actorID = rmved:GetID(), actor = rmved})
- end
- end
- function MainAssistLayout:RmvHero(data)
- local actor = data.actor
- local actorID = data.actorID
- if not (self._assistGroup == 3 and self._checkHero) then
- return
- end
- if not self._heroCells[actorID] then
- return
- end
- local listview = self._ui_hero.ListView_hero
- local cell = self._heroCells[actorID]
- listview:removeItem(listview:getIndex(cell.layout))
- self._heroCells[actorID] = nil
- end
- function MainAssistLayout:UpdateHero(data)
- local actorID = data.actorID
- local actor = global.actorManager:GetActor(actorID)
- if not actor then
- return
- end
- if not (self._assistGroup == 3 and self._checkHero) then
- return
- end
- if not self._heroCells[actorID] then
- return
- end
- local cell = self._heroCells[actorID]
- local curHP = actor:GetHP()
- local maxHP = actor:GetMaxHP()
- local percent = math.floor((curHP / maxHP * 100))
- cell.loadingBarHp:setPercent(percent)
- end
- return MainAssistLayout
|