Beispiel #1
0
        static void ExcutePassiveSkill(this PassiveSkillComponent self, string skillId)
        {
            Unit source = self.GetParent <Unit>();

            if (!self.bufferDatas.ContainsKey(skillId))
            {
                self.bufferDatas[skillId] = new PassiveSkillBufferData();
            }
            SkillHelper.ExecuteSkillParams excuteSkillParams = new SkillHelper.ExecuteSkillParams();
            excuteSkillParams.skillId    = skillId;
            excuteSkillParams.source     = self.GetParent <Unit>();
            excuteSkillParams.skillLevel = 1;

            self.cancelToken = new CancellationTokenSource();
            excuteSkillParams.cancelToken = self.cancelToken;

            PassiveSkillData passiveSkillData = Game.Scene.GetComponent <SkillConfigComponent>().GetPassiveSkill(skillId);

            if (passiveSkillData.listenToEvent)
            {
                if (!self.bufferDatas[skillId].apply)
                {
                    self.bufferDatas[skillId].apply  = true;
                    self.bufferDatas[skillId].aEvent = new ListenPassiveSkillEvent(
                        (unitId) =>
                    {
                        if (unitId == source.Id)
                        {
                            if (SkillHelper.CheckIfSkillCanUse(skillId, source))
                            {
                                self.tokenSource = new ETCancellationTokenSource();

                                SkillHelper.ExecutePassiveSkill(excuteSkillParams);
                            }
                        }
                    }
                        );
                    Game.EventSystem.RegisterEvent(passiveSkillData.eventIdType, self.bufferDatas[skillId].aEvent);
                }
                return;
            }
            else
            {
                if (self.bufferDatas[skillId].apply)
                {
                    return;
                }
            }
            if (SkillHelper.CheckIfSkillCanUse(skillId, source))
            {
                self.tokenSource = new ETCancellationTokenSource();
                SkillHelper.ExecutePassiveSkill(excuteSkillParams);
                self.bufferDatas[skillId].apply = true;
            }
        }
Beispiel #2
0
        public static void RemoveSkill(this PassiveSkillComponent self, string skillId)
        {
            if (self.skillList.ContainsKey(skillId))
            {
                PassiveSkillData data = Game.Scene.GetComponent <SkillConfigComponent>().GetPassiveSkill(skillId);

                if (data.listenToEvent)
                {
                    if (self.bufferDatas.ContainsKey(data.skillId))
                    {
                        if (self.bufferDatas[data.skillId].apply)
                        {
                            self.bufferDatas[data.skillId].apply = false;
                            Game.EventSystem.RemoveEvent(data.eventIdType, self.bufferDatas[data.skillId].aEvent);
                        }
                    }
                }
                SkillHelper.OnPassiveSkillRemove(self.GetParent <Unit>(), skillId);
                self.skillList.Remove(skillId);
            }
        }