Пример #1
0
        public static void UpdateNearbyClients(Mobile m, Direction d)
        {
            if (m == null)
            {
                return;
            }

            IPooledEnumerable eable = m.Map.GetClientsInRange(m.Location);

            foreach (NetState state in eable.OfType <NetState>().Where(ns => ns != m.NetState))
            {
                Mobile beholder = state.Mobile;

                if (state.StygianAbyss)
                {
                    int noto = Notoriety.Compute(beholder, m);

                    Packet p = Packet.Acquire(new MobileDirectionToOthersOnly(m, noto, d));

                    state.Send(p);
                }
                else
                {
                    int noto = Notoriety.Compute(beholder, m);

                    Packet p = Packet.Acquire(new MobileDirectionToOthersOnly(m, noto, d));

                    state.Send(p);
                }
            }

            eable.Free();
        }
Пример #2
0
        public static T FindNearest <T>(IEntity e, Func <T, bool> predicate = null) where T : IEntity
        {
            IPooledEnumerable eable = null;
            var loc = e.Location;
            var map = e.Map;

            for (int i = 0; i < 50; i++)
            {
                eable = map.GetObjectsInRange(loc, i);

                var toFind = eable.OfType <T>().FirstOrDefault(entity => predicate == null || predicate(entity));

                if (toFind != null)
                {
                    eable.Free();
                    return(toFind);
                }
            }

            if (eable != null)
            {
                eable.Free();
            }

            return(default(T));
        }
Пример #3
0
        public List <IDamageable> FindDamageables(Mobile shooter, Point3D pnt, Map map, bool player, bool pet, bool monsters, bool seacreature, bool items)
        {
            List <IDamageable> list = new List <IDamageable>();

            if (map == null || map == Map.Internal || Galleon == null)
            {
                return(list);
            }

            IPooledEnumerable eable = map.GetObjectsInRange(pnt, 0);

            foreach (IDamageable dam in eable.OfType <IDamageable>())
            {
                Mobile mob = dam as Mobile;

                if (mob != null && (!shooter.CanBeHarmful(mob, false) || Galleon.Contains(mob)))
                {
                    continue;
                }

                if (!items && dam is DamageableItem)
                {
                    continue;
                }

                if (items && dam is DamageableItem && ((DamageableItem)dam).CanDamage && !Galleon.Contains(dam))
                {
                    list.Add(dam);
                }

                if (player && mob is PlayerMobile)
                {
                    list.Add(mob);
                }

                if (monsters && mob is BaseCreature && !((BaseCreature)mob).Controlled && !((BaseCreature)mob).Summoned)
                {
                    list.Add(mob);
                }

                if (pet && mob is BaseCreature && (((BaseCreature)mob).Controlled || ((BaseCreature)mob).Summoned))
                {
                    list.Add(mob);
                }

                if (seacreature && mob is BaseSeaChampion)
                {
                    list.Add(mob);
                }
            }

            eable.Free();
            return(list);
        }
Пример #4
0
        public static IEnumerable <TEntity> FindEntities <TEntity>(this Rectangle3D r, Map m) where TEntity : IEntity
        {
            IPooledEnumerable i = m.GetObjectsInBounds(r.ToRectangle2D());

            foreach (TEntity e in i.OfType <TEntity>().Where(o => r.Contains(o)))
            {
                yield return(e);
            }

            i.Free();
        }
Пример #5
0
        private static bool FindObject <T>(Map map, Point3D p, int range, Func <T, bool> predicate, out T value)
            where T : IEntity
        {
            value = default(T);

            bool any = false;

            IPooledEnumerable <IEntity> e = map.GetObjectsInRange(p, range);

            foreach (T o in (predicate != null ? e.OfType <T>().Where(predicate) : e.OfType <T>()).Where(o => o != null))
            {
                value = o;
                any   = true;
                break;
            }

            e.Free();

            return(any);
        }
Пример #6
0
        public static IEnumerable <Mobile> FindValidTargets(BaseCreature creature, int range)
        {
            IPooledEnumerable eable = creature.GetMobilesInRange(range);

            foreach (Mobile m in eable.OfType <Mobile>())
            {
                if (ValidTarget(creature, m))
                {
                    yield return(m);
                }
            }

            eable.Free();
        }
Пример #7
0
        public static IEnumerable <TEntity> FindEntities <TEntity>(this Rectangle2D r, Map m) where TEntity : IEntity
        {
            if (m == null || m == Map.Internal)
            {
                yield break;
            }

            IPooledEnumerable i = m.GetObjectsInBounds(r);

            foreach (TEntity e in i.OfType <TEntity>().Where(o => o != null && o.Map == m && r.Contains(o)))
            {
                yield return(e);
            }

            i.Free();
        }
Пример #8
0
        private void CheckGuard(Mobile m, bool pass)
        {
            IPooledEnumerable eable = Map.GetMobilesInRange(m.Location, 10);

            foreach (var g in eable.OfType <KhaldunCampGuard>())
            {
                if (pass)
                {
                    g.PrivateOverheadMessage(MessageType.Regular, 0x47E, 1158716, m.NetState); // *nods* Please proceed, Detective
                }
                else
                {
                    g.PrivateOverheadMessage(MessageType.Regular, 0x47E, 1158715, m.NetState); // Halt! Who goes there! Official RBG Detective personnel only!
                }

                break;
            }
        }
Пример #9
0
        public override void OnThink()
        {
            if (EraSE && Summoned)
            {
                IPooledEnumerable list = GetMobilesInRange(5);

                List <BaseCreature> spirtsOrVortexes =
                    list.OfType <BaseCreature>().Where(m => m.Summoned && (m is EnergyVortex || m is BladeSpirits)).ToList();

                list.Free();

                while (spirtsOrVortexes.Count > 6)
                {
                    int index = Utility.Random(spirtsOrVortexes.Count);

                    Dispel(spirtsOrVortexes[index]);
                    spirtsOrVortexes.RemoveAt(index);
                }
            }

            base.OnThink();
        }
Пример #10
0
        public void AreaPeace()
        {
            if (Combatant == null || Deleted || !Alive || m_NextPeace > DateTime.UtcNow || 0.1 < Utility.RandomDouble())
            {
                return;
            }

            IPooledEnumerable eable = GetMobilesInRange(RangePerception);

            foreach (var p in eable.OfType <PlayerMobile>())
            {
                if (IsValidTarget(p))
                {
                    AddPeaceEffects(p);
                }
            }

            eable.Free();

            m_NextPeace = DateTime.UtcNow + TimeSpan.FromSeconds(10);
            PlaySound(0x1D3);
        }
Пример #11
0
        public static void ZombieDeathAnim(Mobile mob, Corpse c)
        {
            if (mob == null || mob.Map == null)
            {
                return;
            }

            Packet animPacket = null; //new DeathAnimation( this, c );
            Packet remPacket  = null; //this.RemovePacket;

            IPooledEnumerable eable = mob.Map.GetClientsInRange(mob.Location);

            foreach (NetState state in eable.OfType <NetState>().Where(state => state != mob.NetState))
            {
                if (animPacket == null)
                {
                    animPacket = Packet.Acquire(new DeathAnimation(mob, c));
                }

                state.Send(animPacket);

                if (state.Mobile.CanSee(mob))
                {
                    continue;
                }

                if (remPacket == null)
                {
                    remPacket = mob.RemovePacket;
                }

                state.Send(remPacket);
            }

            Packet.Release(animPacket);

            eable.Free();
        }
Пример #12
0
        public void Start()
        {
            if (Deleted || !Active || Map == null || Map == Map.Internal || Parent != null)
            {
                Stop();
                return;
            }

            if (_Effects == null || _Center != GetWorldLocation())
            {
                ClearEffects();

                _Effects = new List <EffectInfo>(GetEffects());
            }

            if (_Timer == null)
            {
                _Timer = PollTimer.CreateInstance(
                    Interval,
                    () =>
                {
                    if (!Active)
                    {
                        Stop();
                        return;
                    }

                    SendEffects();
                },
                    () => !Deleted && Active && Map != null && Map != Map.Internal && Parent == null);
            }
            else
            {
                _Timer.Running = true;
            }

            if (!PlayerRangeSensitive)
            {
                if (_ActivityTimer != null)
                {
                    _ActivityTimer.Running = false;
                    _ActivityTimer         = null;
                }

                return;
            }

            if (_ActivityTimer != null)
            {
                _ActivityTimer.Running = true;
                return;
            }

            _ActivityTimer = PollTimer.CreateInstance(
                ActivityInterval,
                () =>
            {
                if (DateTime.UtcNow - _LastActivity < ActivityInterval)
                {
                    return;
                }

                IPooledEnumerable clients = GetClientsInRange(GetMaxUpdateRange());

                if (clients.OfType <NetState>().Any())
                {
                    clients.Free();
                    return;
                }

                clients.Free();

                Stop();
            },
                () => !Deleted && Map != null && Map != Map.Internal && Parent == null);
        }
Пример #13
0
        private void SetupClaimPeriod()
        {
            var     map = Siege.SiegeShard ? Map.Felucca : Map.Trammel;
            Point3D p   = TownTree.Location;

            RewardBag = new SantasGiftBag();
            RewardBag.MoveToWorld(new Point3D(p.X, p.Y + 2, p.Z), map);

            if (PointTable.Count > 0)
            {
                Winners = new Dictionary <PlayerMobile, bool>();

                if (TownTree.Stage == TreeStage.Five)
                {
                    foreach (var pm in PointTable.Keys)
                    {
                        Winners[pm] = false;
                    }
                }
                else
                {
                    double perc;

                    switch (TownTree.Stage)
                    {
                    default: perc = 0.1; break;

                    case TreeStage.Three: perc = .25; break;

                    case TreeStage.Four: perc = .5; break;
                    }

                    int count = (int)Math.Max(1, (double)PointTable.Count * perc);

                    for (int i = 0; i < count; i++)
                    {
                        DoRaffle();
                    }
                }
            }

            PointTable.Clear();

            var tree = TownTree;

            if (tree != null)
            {
                for (int i = 0; i < 30; i++)
                {
                    Point3D spawnPoint;

                    var temp = new Point3D(Utility.RandomMinMax(tree.X - 5, tree.X + 5), Utility.RandomMinMax(tree.Y - 5, tree.Y + 5), tree.Z);

                    IPooledEnumerable eable = map.GetItemsInRange(temp, 0);
                    var spawnZ = temp.Z;

                    foreach (var comp in eable.OfType <AddonComponent>().Where(c => c.ItemID >= 0x46A2 && c.ItemID < 0x46A7))
                    {
                        spawnZ = Math.Max(spawnZ, comp.Z + 5);
                    }

                    eable.Free();

                    if (spawnZ != TownTree.Z)
                    {
                        spawnPoint   = temp;
                        spawnPoint.Z = spawnZ;
                    }
                    else
                    {
                        Spells.SpellHelper.AdjustField(ref temp, map, 20, false);

                        spawnPoint = temp;
                    }

                    var component = new AddonComponent(Utility.Random(0x46A2, 6))
                    {
                        Hue = Utility.RandomMinMax(1, 500)
                    };

                    tree.AddComponent(component, tree.X - spawnPoint.X, tree.Y - spawnPoint.Y, tree.Z - spawnPoint.Z);
                }
            }
        }