Example #1
0
        public static DUnit Get(this DUnitComponent self, long id)
        {
            DUnit unit;

            self.idUnits.TryGetValue(id, out unit);
            return(unit);
        }
Example #2
0
        public static void Remove(this DUnitComponent self, long id)
        {
            DUnit unit;

            self.idUnits.TryGetValue(id, out unit);
            self.idUnits.Remove(id);
            unit?.Dispose();
        }
Example #3
0
        public static void UpdateTriggers(this Skill self)
        {
            ListComponent <long> deleteList = ListComponent <long> .Create();

            DUnitComponent dUnitComponent = self.Domain.GetComponent <DUnitComponent>();

            // 刷新MonitorList
            for (int i = 0; i < self.MonitorList.List.Count; i++)
            {
                DUnit unit = dUnitComponent.Get(self.MonitorList.List[i]);
                if (unit == null)
                {
                    deleteList.List.Add(unit.Id);
                    continue;
                }

                if (unit.GetComponent <UnitStateComponent>().UnitState == (int)UnitState.Death)
                {
                    deleteList.List.Add(unit.Id);
                }
            }
            for (int i = 0; i < deleteList.List.Count; i++)
            {
                self.MonitorList.List.Remove(deleteList.List[i]);
            }
            deleteList.List.Clear();


            // 刷新MonitorList
            for (int i = 0; i < self.DamageList.List.Count; i++)
            {
                DUnit unit = dUnitComponent.Get(self.DamageList.List[i]);
                if (unit == null)
                {
                    deleteList.List.Add(unit.Id);
                    continue;
                }

                if (unit.GetComponent <UnitStateComponent>().UnitState == (int)UnitState.Death)
                {
                    deleteList.List.Add(unit.Id);
                }
            }
            for (int i = 0; i < deleteList.List.Count; i++)
            {
                self.DamageList.List.Remove(deleteList.List[i]);
            }
            deleteList.List.Clear();
        }
Example #4
0
        public static void UpdateTarget(this Skill self)
        {
            if (self.TargetId == 0)
            {
                return;
            }

            DUnitComponent dUnitComponent = self.Domain.GetComponent <DUnitComponent>();
            DUnit          unit           = dUnitComponent.Get(self.TargetId);

            if (unit == null)
            {
                self.SetSkillTarget(0);
                return;
            }
        }
Example #5
0
        public static DUnit GetMonitorTarget(this Skill self, SkillTargetCondition condition)
        {
            self.UpdateTriggers();

            DUnitComponent dUnitComponent = self.Domain.GetComponent <DUnitComponent>();

            if (condition == SkillTargetCondition.MaxDistance)
            {
                Vector3 srcpos  = self.Self.Position;
                float   sqrdis  = 0;
                DUnit   selunit = null;
                for (int i = 0; i < self.MonitorList.List.Count; i++)
                {
                    DUnit u      = dUnitComponent.Get(self.MonitorList.List[i]);
                    float tmpdis = (u.Position - srcpos).sqrMagnitude;
                    if (tmpdis > sqrdis)
                    {
                        selunit = u;
                    }
                }
                return(selunit);
            }
            else
            {
                Vector3 srcpos  = self.Self.Position;
                float   sqrdis  = float.MaxValue;
                DUnit   selunit = null;
                for (int i = 0; i < self.MonitorList.List.Count; i++)
                {
                    DUnit u      = dUnitComponent.Get(self.MonitorList.List[i]);
                    float tmpdis = (u.Position - srcpos).sqrMagnitude;
                    if (tmpdis < sqrdis)
                    {
                        selunit = u;
                    }
                }
                return(selunit);
            }
        }
Example #6
0
 public static DUnit[] GetAll(this DUnitComponent self)
 {
     return(self.idUnits.Values.ToArray());
 }
Example #7
0
 public static void RemoveNoDispose(this DUnitComponent self, long id)
 {
     self.idUnits.Remove(id);
 }
Example #8
0
 public static void Add(this DUnitComponent self, DUnit unit)
 {
     self.idUnits.Add(unit.Id, unit);
     unit.Parent = self;
 }