示例#1
0
        //可以选择单个目标,也可以是多个目标
        //提供给SkillSelecotr使用
        public static IEnumerable <ServerNPC> GetNPCInRange(ServerNPC caster, float range, WarServerNpcMgr NpcSource, KindOfNPC kind,
                                                            TargetClass target, NpcStatus TarStatusInCfg, LifeNPCType type = LifeNPCType.SkTarAll)
        {
            List <ServerNPC> found = new List <ServerNPC>();
            ///
            ///  枚举器,其实不用返回特定类型,返回枚举器就可以了。(在不需要Copy容器里面的数据时,就是用枚举器)
            ///
            IEnumerable <ServerNPC> Itor = found.AsEnumerable();
            // 临时枚举器
            IEnumerable <ServerNPC> Itor1 = null;

            Vector3   anchor = caster.transform.position;
            Transform trans  = caster.transform;

            ServerNPC nearest = null;

            CAMP camp = CAMP.None;

            if (target.AnySame(TargetClass.Friendly))
            {
                camp = caster.Camp;
            }
            else if (target.AnySame(TargetClass.Hostile))
            {
                camp = caster.Camp.Hostile();
            }

            Itor1 = NpcSource.getCampBnpc(camp);

            if (kind == KindOfNPC.Life)
            {
                Itor1 = Itor1.Where(n => (n.WhatKindOf() == kind) &&
                                    (type.check(((ServerLifeNpc)n).WhatTypeOf)));
            }
            else if (kind == KindOfNPC.NonLife)
            {
                Itor1 = Itor1.Where(n => n.WhatKindOf() == kind);
            }

            bool any = Itor1 != null?Itor1.Any() : false;

            if (any)
            {
                ///
                /// --- 筛选出有效状态的NPC ----
                ///
                Itor1 = Itor1.Where(n => {
                    ServerLifeNpc lifeTar = n as ServerLifeNpc;
                    if (lifeTar != null)
                    {
                        return(!lifeTar.curStatus.AnySame(TarStatusInCfg));
                    }
                    else
                    {
                        return(true);
                    }
                });

                ///
                /// --- 再次根据距离条件筛选出NPC ----
                ///
                float radius = caster.data.configData.radius;
                Itor1 = Itor1.Where(n => IsInRange(anchor, n.data.configData.radius + radius + range, n.transform));

                if (target.AnySame(TargetClass.FarAwary))
                {
                    nearest = Itor1.OrderByDescending(n => GetVirtualDistance(trans, n.transform)).FirstOrDefault();
                    if (nearest != null)
                    {
                        found.Add(nearest);
                    }
                }
                else if (target.AnySame(TargetClass.Nearest))
                {
                    nearest = Itor1.OrderBy(n => GetVirtualDistance(trans, n.transform)).FirstOrDefault();
                    if (nearest != null)
                    {
                        found.Add(nearest);
                    }
                }
                else
                {
                    Itor = Itor1;
                }


                ///
                /// --- 判定最大,最小生命值的NPC -----
                ///

                if (target.AnySame(TargetClass.HpLowest))
                {
                    ServerNPC lowest = Itor1.OrderBy(n => n.data.rtData.CurHpNested).FirstOrDefault();
                    if (lowest != null)
                    {
                        found.Add(lowest);
                    }
                }
                else if (target.AnySame(TargetClass.HpHighest))
                {
                    ServerNPC highest = Itor1.OrderByDescending(n => n.data.rtData.CurHpNested).FirstOrDefault();
                    if (highest != null)
                    {
                        found.Add(highest);
                    }
                }
            }

            return(Itor);
        }
示例#2
0
        /// <summary>
        /// Gets the npc with in range.
        /// </summary>
        /// <returns>The npc with in range.</returns>
        /// <param name="anchor">起点</param>
        /// <param name="range">范围</param>
        /// <param name="NpcSource">NPC 容器</param>
        /// <param name="capm">阵营</param>
        /// <param name="kind">是否是lifeNpc</param>
        /// <param name="type">如果是LifeNpc的时候,又是什么子类型</param>
        public static List <ServerNPC> GetNpcWithInRange(ServerNPC caster, float range, WarServerNpcMgr NpcSource, CAMP camp, KindOfNPC kind, LifeNPCType type = LifeNPCType.SkTarAll)
        {
            IEnumerable <ServerNPC> filter = NpcSource.getCampBnpc(camp);

            if (kind == KindOfNPC.Life)
            {
                filter = filter.Where(n => (n.WhatKindOf() == kind) &&
                                      (type.check(((ServerLifeNpc)n).WhatTypeOf)));
            }
            else if (kind == KindOfNPC.NonLife)
            {
                filter = filter.Where(n => n.WhatKindOf() == kind);
            }

            int count = filter.Count();

            if (count > 0)
            {
                Vector3 anchor = caster.transform.position;
                float   radius = caster.data.configData.radius;
                filter = filter.Where(n => IsInRange(anchor, n.data.configData.radius + range + radius, n.transform));
            }

            return(filter.ToList());
        }
示例#3
0
        /// <summary>
        /// 获取特定的KindOfNPC,敌友方,有效状态的, 是建筑物还是什么的  活着的NPC
        /// </summary>
        /// <returns>ServerNPC 列表</returns>
        /// <param name="caster">Caster.</param>
        /// <param name="NpcSource">Npc source.</param>
        /// <param name="kind">KindOfNPC</param>
        /// <param name="target">TargetClass</param>
        /// <param name="TarStatusInCfg">NpcStatus</param>
        /// <param name="type">LifeNPCType.</param>
        public static IEnumerable <ServerNPC> GetNPCValideStatus(ServerNPC caster, WarServerNpcMgr NpcSource, KindOfNPC kind, TargetClass target,
                                                                 NpcStatus TarStatusInCfg, LifeNPCType type = LifeNPCType.SkTarAll)
        {
            // 临时枚举器
            IEnumerable <ServerNPC> Itor1 = null;

            CAMP camp = CAMP.None;

            if (target.AnySame(TargetClass.Friendly))
            {
                camp = caster.Camp;
            }
            else if (target.AnySame(TargetClass.Hostile))
            {
                camp = caster.Camp.Hostile();
            }
            else
            {
                //全阵营
                camp = CAMP.All;
            }

            Itor1 = NpcSource.getCampBnpc(camp);

            if (kind == KindOfNPC.Life)
            {
                Itor1 = Itor1.Where(n => (n.WhatKindOf() == kind) &&
                                    (type.check(((ServerLifeNpc)n).WhatTypeOf)));
            }
            else if (kind == KindOfNPC.NonLife)
            {
                Itor1 = Itor1.Where(n => n.WhatKindOf() == kind);
            }

            ///
            /// --- 筛选出有效状态的NPC ----
            ///
            Itor1 = Itor1.Where(n => {
                ServerLifeNpc lifeTar = n as ServerLifeNpc;
                if (lifeTar != null)
                {
                    return(!lifeTar.curStatus.AnySame(TarStatusInCfg));
                }
                else
                {
                    return(true);
                }
            });

            return(Itor1);
        }