-- --- 定时释放本技能(且添加倒计时显示) --- local Base = require("Battle/Logic/Entity/SkillDecorator/SkillDecorator") local SkillDecoratorTimingUseSkill = class("SkillDecoratorTimingUseSkill", Base) local EventSystem = require 'Event/EventSystem' local FP_Greater = FP.Greater local FP_LessEquals = FP.LessEquals -- 注意:这个 skillID 必须是belongTo技能id function SkillDecoratorTimingUseSkill:initialize(entity, skillID, maxTimer) Base.initialize(self, entity, skillID) self.type = LuaConst.SkillDecoratorType.TimingUseSkill self.UIType = LuaConst.UISkillBtnResetType.TimingUseSkill self.maxTimer = FP.newV1(0):Reset(maxTimer) -- 倒计时总时长 单位:毫秒 self.leftTime = FP.newV1(0):Reset(maxTimer) -- 剩余时长 单位:毫秒 end function SkillDecoratorTimingUseSkill:OnLogicUpdate() if not self.enable then return end if FP_Greater(self.leftTime,0) then self.leftTime:Sub(LuaConst.TimeSpanMs) if FP_LessEquals(self.leftTime,0) then -- 可使用技能了 if self.entity:IsAlive() then self.entity.components.record.BtnSkillId = self.skillID -- 设置是通过按钮触发的技能(防止事件ENTITY_SKILL_START不派发) SystemManager.SetNextState(LuaConst.StateType.Attack,self.entity,self.skillID,"",{}) end -- 删除此Decorator self.enable = false -- 告知UI EventSystem.Dispatch(EventID.UI_BattleAttack_ResetBtn, self.entity, self.skillID, self.UIType, nil) end end end -- ui上面渲染的方法 function SkillDecoratorTimingUseSkill:OnUIBtn() EventSystem.Dispatch(EventID.UI_BattleAttack_ResetBtn, self.entity, self.skillID, self.UIType, self.leftTime, self.maxTimer) end function SkillDecoratorTimingUseSkill:SetEnable(value) self.leftTime:Reset(self.maxTimer) self.enable = value end function SkillDecoratorTimingUseSkill.StringParamToFormat(str) return tonumber(str) end --AI 需要执行的特殊处理 function SkillDecoratorTimingUseSkill:OnAICantRunToNextPos(command) if self.enable and FP_Greater(self.leftTime,0) then command.SkillIndex = self.entity.components.skillBase:GetSkillIndexBySkillID(self.skillID) end end return SkillDecoratorTimingUseSkill