源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

171 lines
5.9 KiB

GuildSceneCollectView = GuildSceneCollectView or BaseClass(BaseItem)
local GuildSceneCollectView = GuildSceneCollectView
function GuildSceneCollectView:__init(parent_wnd,prefab_asset,layer_name)
self.base_file = "mainui"
self.layout_file = "CollectBarView"
self.parent_wnd = parent_wnd
self.layer_name = layer_name
self.curr_progress = 0 --采集当前进度
self.total_step = 40
self.is_collecting = false
self.collect_time = 3 --采集装备时间
self.main_role = Scene:getInstance():GetMainRole()
self.model = GuildModel:getInstance()
self:Load()
end
function GuildSceneCollectView:Load_callback()
self.transform.anchoredPosition = Vector2(0, 155)
self.collectText = self:GetChild("Image/collectText"):GetComponent("Text")
self.effect = self:GetChild("effect")
self.effect2 = self:GetChild("effect2")
self.fg_img
= GetChildImages(self.transform, {
"barCon/progressImg/fgImg"
})
self.fg_img.enabled = false
self:SetProgress(0, 100)
-- 修改节点名称
self.transform.name = "GuildSceneCollectView"
self:AddEvents()
end
function GuildSceneCollectView:AddEvents( )
--开始采集
local function startCollect(vo)
self:StartCollectAction(vo)
end
self:BindEvent(self.model, GuildModel.START_TO_COLLECT_ITEM, startCollect)
--取消采集
local function cancelCollect()
if self.is_collecting then
local role = Scene.Instance.main_role
if role and not role:IsInState(PoseState.COLLECT) then
self:CancelCollectAction()
end
end
end
self:BindEvent(self.model, GuildModel.STOP_COLLECT_ITEM, cancelCollect)
self.attack_id = GlobalEventSystem:Bind(FightEvent.RELEASE_MAIN_SKILL, cancelCollect)
self.game_start_id = GlobalEventSystem:Bind(SceneEventType.SCENE_CHANGED,cancelCollect)
self.mainrole_move_id = GlobalEventSystem:Bind(ObjectEventType.MAINROLE_MOVE_EVENT_IMME,cancelCollect)
end
function GuildSceneCollectView:StartCollectAction(vo)
self.vo = vo
self:SetVisible(true)
self.curr_progress = 0
self.is_collecting = true
self.main_role:SetIsCollecting(true)
SceneManager:getInstance():SetCollectFlag(true)
self:SwitchCollectState(true)
self:SetProgress(0, 100)
local function call_back( )
cs_particleM:SetSpeed(self.effect.gameObject, 1 / self.collect_time) --特效播放1.5秒
end
self.effect.gameObject:SetActive(true)
self:AddUIEffect("ui_caijinew_01", self.effect, self.layer_name, nil, 1, false, self.collect_time + 2, nil, nil, call_back)
if self.collecting_time_id == nil then
local function collectingFunc( ... )
self:Collecting()
end
self.collecting_time_id = GlobalTimerQuest:AddPeriodQuest(collectingFunc, self.collect_time / self.total_step, 100)
end
end
function GuildSceneCollectView:CancelCollectAction(auto_end)
self:SetVisible(false)
self.curr_progress = 0
self.is_collecting = false
SceneManager:getInstance():SetCollectFlag(false)
self:SwitchCollectState(false)
self.main_role:SetIsCollecting(false)
if auto_end then
self.model:Fire(GuildModel.PICK_UP_BOSS_DROP_ITEM, GuildModel.GBossPickOpty.Succeed, self.vo.drop_id)
else
-- GlobalEventSystem:Fire(SceneEventType.GBOSS_PICK_CANCEL, self.model:GetCurGuildBossCollectDropId())
self.model:Fire(GuildModel.PICK_UP_BOSS_DROP_ITEM, GuildModel.GBossPickOpty.Cancel, self.vo.drop_id)
end
end
--采集进行器
function GuildSceneCollectView:Collecting( )
if self.is_collecting == false then
if self.collecting_time_id ~= nil then
GlobalTimerQuest:CancelQuest(self.collecting_time_id)
self.collecting_time_id = nil
end
return
end
self.curr_progress = self.curr_progress + 1
self:SetProgress(self.curr_progress, self.total_step)
if self.curr_progress >= self.total_step then --少许延时关闭
if self.collecting_time_id ~= nil then
GlobalTimerQuest:CancelQuest(self.collecting_time_id)
self.collecting_time_id = nil
end
local function DelayClose()
self:CancelCollectAction(true)
end
if self.delay_close_id then
GlobalTimerQuest:CancelQuest(self.delay_close_id)
self.delay_close_id = false
end
self:AddUIEffect("ui_caijinew_02", self.effect2, self.layer_name, nil, 1, false, false, nil, nil, nil)
self.delay_close_id = GlobalTimerQuest:AddDelayQuest(DelayClose, 0.7)
end
end
function GuildSceneCollectView:SwitchCollectState( flag )
local main_role = Scene.Instance.main_role
if not main_role then
return
end
if flag then
main_role:DoCollect()
else
if main_role:IsInState(PoseState.COLLECT) then
main_role:DoStand(nil, 0.1)
end
end
end
-- 采集进度
function GuildSceneCollectView:SetProgress(curr_value, max_value)
local progress_value = math.floor(curr_value / max_value * 100)
progress_value = progress_value >= 100 and 100 or progress_value
self.collectText.text = progress_value .. "%"
end
function GuildSceneCollectView:__delete( )
if self.attack_id then
GlobalEventSystem:UnBind(self.attack_id)
self.attack_id = nil
end
if self.game_start_id then
GlobalEventSystem:UnBind(self.game_start_id)
self.game_start_id = nil
end
if self.mainrole_move_id then
GlobalEventSystem:UnBind(self.mainrole_move_id)
self.mainrole_move_id = nil
end
if self.collecting_time_id ~= nil then
GlobalTimerQuest:CancelQuest(self.collecting_time_id)
self.collecting_time_id = nil
end
if self.delay_close_id then
GlobalTimerQuest:CancelQuest(self.delay_close_id)
self.delay_close_id = false
end
self:ClearUIEffect(self.effect)
self:ClearUIEffect(self.effect2)
end