BossHomeSceneRankItem = BossHomeSceneRankItem or BaseClass(BaseItem)
|
|
local BossHomeSceneRankItem = BossHomeSceneRankItem
|
|
|
|
function BossHomeSceneRankItem:__init(parent_wnd,prefab_asset,layer_name,tag)
|
|
self.base_file = "boss"
|
|
self.layout_file = "BossHomeSceneRankItem"
|
|
self.tag = tag
|
|
self.model = BossHomeModel:getInstance()
|
|
self.enemy_list = {}
|
|
self.show_data = false
|
|
self.show_time = 0--显示的时间
|
|
|
|
self:Load()
|
|
end
|
|
|
|
function BossHomeSceneRankItem:Load_callback()
|
|
self.nodes = {
|
|
"img_rank:img:obj","lb_rank:tmp","lb_name:tmp","lb_att:tmp",
|
|
|
|
"con:obj","btn_team:img:obj","btn_att:img:obj","con/con_tip:obj",
|
|
}
|
|
self:GetChildren(self.nodes)
|
|
|
|
self:AddEvents()
|
|
if self.need_refreshData then
|
|
self:UpdateView()
|
|
end
|
|
|
|
if self.tag == "boss_home" then
|
|
lua_resM:setImageSprite(self, self.btn_att_img,'boss_asset',"boss_btn_29",true)
|
|
lua_resM:setImageSprite(self, self.btn_team_img,'boss_asset',"boss_btn_30",true)
|
|
end
|
|
end
|
|
|
|
function BossHomeSceneRankItem:AddEvents( )
|
|
local function call_back( target )
|
|
if target == self.btn_team_obj then
|
|
if not self.data then return end
|
|
local my_team_id = RoleManager.Instance.mainRoleInfo.team_id
|
|
local other_team_id = 0
|
|
if self.data.type == 0 then
|
|
--无组队玩家
|
|
else
|
|
other_team_id = self.data.role_id
|
|
end
|
|
-------------------------
|
|
if my_team_id == 0 and other_team_id ~= 0 then
|
|
GlobalEventSystem:Fire(TeamModel.APPLY_JOIN_TEAM,other_team_id)
|
|
elseif my_team_id == 0 and other_team_id == 0 then
|
|
GlobalEventSystem:Fire(TeamModel.INVITE_PLAYER,{self.data.role_id})
|
|
elseif my_team_id ~= 0 and other_team_id == 0 then
|
|
GlobalEventSystem:Fire(TeamModel.INVITE_PLAYER,{self.data.role_id})
|
|
elseif my_team_id ~= 0 and other_team_id ~= 0 then
|
|
Message.show("双方均有队伍! 请退出队伍再操作!")
|
|
end
|
|
elseif target == self.btn_att_obj then
|
|
if not self.data then return end
|
|
local support_data = GuildModel:getInstance():GetCurSupportPlayerInfo()
|
|
if self.data.type == 1 then
|
|
--队伍的时候,先找到活着的队长,然后找到活着的队员,最后找死的队长
|
|
local lead_info = false--队长
|
|
local team_info = {}--队员信息
|
|
local all_other_vo = SceneManager.Instance:GetAllRoleVos( )
|
|
for a,vo in pairs(all_other_vo) do
|
|
local temp = Scene:getInstance():GetRole(vo.role_id)
|
|
if vo.team_id == self.data.role_id then
|
|
if vo.team_job == 1 then
|
|
lead_info = vo
|
|
else
|
|
table.insert( team_info, vo )
|
|
end
|
|
end
|
|
end
|
|
-------------------------
|
|
local role_target = false
|
|
if lead_info and lead_info.hp > 0 then
|
|
--先找到活着的队长
|
|
role_target = Scene.Instance:GetRole(lead_info.role_id)
|
|
elseif team_info[1] then
|
|
for k,v in pairs(team_info) do
|
|
if v.hp > 0 then
|
|
--然后找到活着的队员
|
|
role_target = Scene.Instance:GetRole(v.role_id)
|
|
break
|
|
end
|
|
end
|
|
end
|
|
if not role_target then
|
|
--如果没有活的就找死的
|
|
if lead_info then
|
|
role_target = Scene.Instance:GetRole(lead_info.role_id)
|
|
elseif team_info[1] then
|
|
role_target = Scene.Instance:GetRole(team_info[1].role_id)
|
|
end
|
|
end
|
|
-------------------------
|
|
--对协助目标的判断
|
|
local is_support = false
|
|
if support_data then
|
|
if lead_info and lead_info.role_id == support_data.role_id then
|
|
is_support = true
|
|
end
|
|
if not is_support then
|
|
for k,v in pairs(team_info) do
|
|
if v.role_id == support_data.role_id then
|
|
is_support = true
|
|
break
|
|
end
|
|
end
|
|
end
|
|
end
|
|
if is_support then
|
|
--点到了协助目标
|
|
Message.show("对方正在接收您的协助")
|
|
return
|
|
end
|
|
-------------------------
|
|
if role_target then
|
|
Scene.Instance:SetClickTarget(role_target)
|
|
GlobalEventSystem:Fire(EventName.STARTAUTOFIGHT)
|
|
end
|
|
else
|
|
if support_data and support_data.role_id == self.data.role_id then
|
|
--点到了协助目标
|
|
Message.show("对方正在接收您的协助")
|
|
return
|
|
end
|
|
local role = Scene.Instance:GetRole(self.data.role_id)
|
|
if role then
|
|
Scene.Instance:SetClickTarget(role)
|
|
GlobalEventSystem:Fire(EventName.STARTAUTOFIGHT)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
AddClickEvent(self.btn_team_obj,call_back,false)
|
|
AddClickEvent(self.btn_att_obj,call_back,false)
|
|
|
|
local function REFRESH_ENEMY_LIST( data )
|
|
if not data then return end
|
|
if not self.data then return end
|
|
-------------------------
|
|
local curTime = TimeUtil:getServerTime()
|
|
if self.show_data and (curTime - self.show_data.time <= 5) then
|
|
--强制闪烁5s,中间跳过过滤
|
|
return
|
|
end
|
|
self.enemy_list = data
|
|
self.show_data = false
|
|
for k,v in pairs(self.enemy_list) do
|
|
if self.data.type == 1 then
|
|
--队伍的时候
|
|
local all_other_vo = SceneManager.Instance:GetAllRoleVos( )
|
|
for a,vo in pairs(all_other_vo) do
|
|
local temp = Scene:getInstance():GetRole(vo.role_id)
|
|
if vo.role_id == v.role_id and vo.team_id == self.data.role_id then
|
|
self.show_data = v
|
|
break
|
|
end
|
|
end
|
|
elseif v.role_id == self.data.role_id then
|
|
self.show_data = v
|
|
break
|
|
end
|
|
end
|
|
if not self.show_data then
|
|
self:CleanAction()
|
|
else
|
|
self:ShowAction()
|
|
end
|
|
end
|
|
self:BindEvent(self.model, BossHomeConst.REFRESH_ENEMY_LIST, REFRESH_ENEMY_LIST)
|
|
end
|
|
|
|
function BossHomeSceneRankItem:UpdateView( )
|
|
if not self.data then return end
|
|
self.data.server_num = 0
|
|
if self.data.server_num ~= 0 then
|
|
self.data.name = GetCSLongName(self.data.name, self.data.server_num)
|
|
end
|
|
if self.data.type == 1 then
|
|
self.lb_name_tmp.text = self.model:GetShortNameStr(string.format( "%s队", self.data.name ))
|
|
else
|
|
self.lb_name_tmp.text = self.model:GetShortNameStr(self.data.name)
|
|
end
|
|
-------------------------
|
|
local boss_id = self.model:GetCurFightBossId()
|
|
if not boss_id then return end
|
|
local boss_type = self.model:GetBossTypeByBossId( boss_id )
|
|
-------------------------
|
|
local boss_max_hp = boss_type and self.model:GetSceneBossHp(boss_type) or 0
|
|
if boss_max_hp == 0 and boss_type ~= Config.ConfigBoss.ModuleId.BossHome and boss_type ~= Config.ConfigBoss.ModuleId.GuildBossHome then
|
|
self.lb_att_tmp.text = "获取中"
|
|
else
|
|
self.lb_att_tmp.text = self.model:GetHurtNumStr(self.data.hurt)--string.format("%0.2f%%",self.data.hurt / boss_max_hp * 100)
|
|
end
|
|
|
|
self.img_rank_obj:SetActive(self.index <= 3)
|
|
if self.index <= 3 then
|
|
self.lb_rank_tmp.text = ""
|
|
lua_resM:setImageSprite(self, self.img_rank_img, "common_asset", "com_rank_3_" .. self.index,true)
|
|
else
|
|
self.lb_rank_tmp.text = self.index
|
|
end
|
|
|
|
local is_me = false
|
|
if self.data.type == 1 then
|
|
is_me = RoleManager.Instance.mainRoleInfo.team_id == self.data.role_id
|
|
else
|
|
is_me = self.data.role_id == RoleManager.Instance.mainRoleInfo.role_id
|
|
end
|
|
self.btn_team_obj:SetActive((self.tag_str == "boss_home") and (not is_me))
|
|
self.btn_att_obj:SetActive((self.tag_str == "boss_home") and (not is_me))
|
|
end
|
|
|
|
function BossHomeSceneRankItem:ShowAction( )
|
|
--5s的闪现
|
|
if (not self.is_loaded) or (not self.show_data) then return end
|
|
self.show_time = 5
|
|
local function clockFun()
|
|
if self.show_time <= 0 then
|
|
self:CleanAction()
|
|
elseif self.show_time <= 2 then
|
|
self.con_obj:SetActive(false)
|
|
else
|
|
self.con_obj:SetActive(true)
|
|
self.con_tip.transform:GetComponent("CanvasGroup").alpha = 0
|
|
local function right_action_move( percent )
|
|
if percent <= 0.5 then
|
|
self.con_tip.transform:GetComponent("CanvasGroup").alpha = percent * 2
|
|
else
|
|
self.con_tip.transform:GetComponent("CanvasGroup").alpha = 1 - ((percent-0.5) * 2)
|
|
end
|
|
end
|
|
local action = cc.CustomUpdate.New(1,right_action_move)
|
|
self:AddAction(action, self.con_tip.transform)
|
|
self.show_time = self.show_time - 1
|
|
end
|
|
end
|
|
if not self.close_time_id then
|
|
clockFun()
|
|
end
|
|
self.close_time_id = self.close_time_id or GlobalTimerQuest:AddPeriodQuest(clockFun, 1, -1)
|
|
end
|
|
|
|
function BossHomeSceneRankItem:CleanAction( )
|
|
self.show_time = 0
|
|
self.con_obj:SetActive(false)
|
|
self.show_data = false
|
|
if self.close_time_id then
|
|
GlobalTimerQuest:CancelQuest(self.close_time_id)
|
|
self.close_time_id = nil
|
|
end
|
|
if self.con.transform then
|
|
cc.ActionManager:getInstance():removeAllActionsFromTarget( self.con.transform )
|
|
end
|
|
end
|
|
|
|
function BossHomeSceneRankItem:SetData( index, data, tag_str )
|
|
self.index = index
|
|
self.data = data
|
|
self.tag_str = tag_str
|
|
if self.is_loaded then
|
|
self.need_refreshData = false
|
|
self:UpdateView()
|
|
else
|
|
self.need_refreshData = true
|
|
end
|
|
end
|
|
|
|
function BossHomeSceneRankItem:__delete( )
|
|
self:CleanAction()
|
|
end
|