Example #1
0
        private void InitSpawner(int amount, TimeSpan minDelay, TimeSpan maxDelay, int team, int spawnRange,
                                 List <SpawnObject> spawnObjects)
        {
            Visible        = false;
            Movable        = false;
            m_Running      = true;
            m_Group        = false;
            m_MinDelay     = minDelay;
            m_MaxDelay     = maxDelay;
            m_MaxCount     = amount;
            m_Team         = team;
            m_SpawnRange   = spawnRange;
            m_WalkingRange = -1;
            m_SpawnObjects = spawnObjects;
            DoTimer(TimeSpan.FromSeconds(1));

            m_HomeRange = 5;

            int max = 1;

            if (spawnObjects != null)
            {
                for (var index = 0; index < spawnObjects.Count; index++)
                {
                    SpawnObject obj = spawnObjects[index];

                    max += obj.MaxCount;
                }
            }
        }
Example #2
0
        public void RemoveSpawn(ISpawnable e)
        {
            SpawnObject so = m_SpawnObjects.FirstOrDefault(s => s.SpawnedObjects.Contains(e));

            if (so != null)
            {
                so.SpawnedObjects.Remove(e);
            }
        }
Example #3
0
        public void Spawn(SpawnObject so)
        {
            Map map = Map;

            if (map == null || map == Map.Internal || SpawnObjectCount == 0 || so == null || Parent != null || GetSpawnCount(so) >= so.MaxCount)
            {
                return;
            }

            Defrag();

            if (CheckSpawnerFull())
            {
                return;
            }

            ISpawnable spawned = CreateSpawnedObject(so);

            if (spawned == null)
            {
                return;
            }

            spawned.Spawner = this;
            so.SpawnedObjects.Add(spawned);

            Point3D loc = (spawned is BaseVendor ? Location : GetSpawnPosition(spawned));

            spawned.OnBeforeSpawn(loc, map);

            InvalidateProperties();

            spawned.MoveToWorld(loc, map);

            if (spawned is BaseCreature)
            {
                BaseCreature bc = (BaseCreature)spawned;

                if (m_WalkingRange >= 0)
                {
                    bc.RangeHome = m_WalkingRange;
                }
                else
                {
                    bc.RangeHome = m_HomeRange;
                }

                bc.CurrentWayPoint = m_WayPoint;

                if (m_Team > 0)
                {
                    bc.Team = m_Team;
                }

                bc.Home = HomeLocation;
            }
        }
Example #4
0
        public void RemoveSpawned(SpawnObject so)
        {
            Defrag();

            if (so.CurrentCount > 0)
            {
                so.SpawnedObjects[0].Delete();
            }

            InvalidateProperties();
        }
Example #5
0
        public bool AddSpawnObject(SpawnObject so)
        {
            if (m_SpawnObjects.FirstOrDefault(s => ParseType(s.SpawnName.ToLower()) == ParseType(so.SpawnName.ToLower())) == null &&
                m_SpawnObjects.Count < SpawnerGump.MaxEntries)
            {
                SpawnObjects.Add(so);
                return(true);
            }

            return(false);
        }
Example #6
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            reader.ReadInt();

            GuardImmune    = reader.ReadBool();
            m_SpawnRange   = reader.ReadInt();
            m_WalkingRange = reader.ReadInt();
            WayPoint       = reader.ReadItem() as WayPoint;
            m_Group        = reader.ReadBool();

            m_MinDelay  = reader.ReadTimeSpan();
            m_MaxDelay  = reader.ReadTimeSpan();
            m_MaxCount  = reader.ReadInt();
            m_Team      = reader.ReadInt();
            m_HomeRange = reader.ReadInt();
            m_Running   = reader.ReadBool();

            TimeSpan ts = TimeSpan.Zero;

            if (m_Running)
            {
                ts = reader.ReadDeltaTime() - DateTime.UtcNow;
            }

            int size = reader.ReadInt();

            m_SpawnObjects = new List <SpawnObject>(size);

            for (int i = 0; i < size; ++i)
            {
                SpawnObject so = new SpawnObject(reader);

                if (AddSpawnObject(so))
                {
                    string typeName = ParseType(so.SpawnName);

                    if (ScriptCompiler.FindTypeByName(typeName) == null)
                    {
                        if (m_WarnTimer == null)
                        {
                            m_WarnTimer = new WarnTimer();
                        }

                        m_WarnTimer.Add(Location, Map, typeName);
                    }
                }
            }

            if (m_Running)
            {
                DoTimer(ts);
            }
        }
Example #7
0
        public void RemoveSpawned(int index)
        {
            if (index >= 0 && index < m_SpawnObjects.Count)
            {
                SpawnObject so = m_SpawnObjects[index];

                if (m_Group)
                {
                    int count = GetSpawnCount(so);

                    for (int i = 0; i < count; i++)
                    {
                        RemoveSpawned(so);
                    }
                }
                else
                {
                    RemoveSpawned(so);
                }
            }
        }
Example #8
0
        public void Spawn(int index)
        {
            if (index >= 0 && index < m_SpawnObjects.Count)
            {
                SpawnObject so = m_SpawnObjects[index];

                if (m_Group)
                {
                    int toSpawn = so.MaxCount - GetSpawnCount(so);

                    for (int i = 0; i < toSpawn; i++)
                    {
                        Spawn(so);
                    }
                }
                else
                {
                    Spawn(so);
                }
            }
        }
Example #9
0
        protected virtual ISpawnable CreateSpawnedObject(SpawnObject obj)
        {
            if (!m_SpawnObjects.Contains(obj))
            {
                return(null);
            }

            Type type = ScriptCompiler.FindTypeByName(ParseType(obj.SpawnName));

            if (type != null)
            {
                try
                {
                    return(Build(type, CommandSystem.Split(obj.SpawnName)));
                }
                catch
                {
                }
            }

            return(null);
        }
Example #10
0
        protected virtual ISpawnable CreateSpawnedObject(SpawnObject obj)
        {
            if (!m_SpawnObjects.Contains(obj))
            {
                return(null);
            }

            Type type = ScriptCompiler.FindTypeByName(ParseType(obj.SpawnName));

            if (type != null)
            {
                try
                {
                    return(Build(type, CommandSystem.Split(obj.SpawnName)));
                }
                catch (Exception e)
                {
                    Server.Diagnostics.ExceptionLogging.LogException(e);
                }
            }

            return(null);
        }
Example #11
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();

            switch (version)
            {
            case 7:
            {
                GuardImmune = reader.ReadBool();

                goto case 6;
            }

            case 6:
            {
                m_SpawnRange = reader.ReadInt();

                goto case 5;
            }

            case 5:
            case 4:
            {
                m_WalkingRange = reader.ReadInt();

                goto case 3;
            }

            case 3:
            case 2:
            {
                m_WayPoint = reader.ReadItem() as WayPoint;

                goto case 1;
            }

            case 1:
            {
                m_Group = reader.ReadBool();

                goto case 0;
            }

            case 0:
            {
                m_MinDelay  = reader.ReadTimeSpan();
                m_MaxDelay  = reader.ReadTimeSpan();
                m_MaxCount  = reader.ReadInt();
                m_Team      = reader.ReadInt();
                m_HomeRange = reader.ReadInt();
                m_Running   = reader.ReadBool();

                TimeSpan ts = TimeSpan.Zero;

                if (m_Running)
                {
                    ts = reader.ReadDeltaTime() - DateTime.UtcNow;
                }

                int size = reader.ReadInt();

                m_SpawnObjects = new List <SpawnObject>(size);

                for (int i = 0; i < size; ++i)
                {
                    if (version > 4)
                    {
                        SpawnObject so = new SpawnObject(reader);

                        if (AddSpawnObject(so))
                        {
                            string typeName = ParseType(so.SpawnName);

                            if (ScriptCompiler.FindTypeByName(typeName) == null)
                            {
                                if (m_WarnTimer == null)
                                {
                                    m_WarnTimer = new WarnTimer();
                                }

                                m_WarnTimer.Add(Location, Map, typeName);
                            }
                        }
                    }
                    else
                    {
                        string creatureString = reader.ReadString();

                        AddSpawnObject(new SpawnObject(creatureString));
                        string typeName = ParseType(creatureString);

                        if (ScriptCompiler.FindTypeByName(typeName) == null)
                        {
                            if (m_WarnTimer == null)
                            {
                                m_WarnTimer = new WarnTimer();
                            }

                            m_WarnTimer.Add(Location, Map, typeName);
                        }
                    }
                }

                if (version < 5)
                {
                    int count = reader.ReadInt();
                    for (int i = 0; i < count; ++i)
                    {
                        ISpawnable e = World.FindEntity(reader.ReadInt()) as ISpawnable;

                        if (e != null)
                        {
                            e.Delete();         // lets make this easy
                        }
                    }
                }

                if (m_Running)
                {
                    DoTimer(ts);
                }

                break;
            }
            }

            if (version < 3 && Weight == 0)
            {
                Weight = -1;
            }
        }
Example #12
0
        public int CountCreatures(SpawnObject so)
        {
            Defrag();

            return(so.CurrentCount);
        }
Example #13
0
 public int GetSpawnCount(SpawnObject so)
 {
     return(so != null ? so.CurrentCount : 0);
 }
Example #14
0
        public void UpdateSpawnObjects(RelayInfo info, Mobile from)
        {
            TextRelay tr = info.GetTextEntry(500);

            if (tr != null && tr.Text.Length > 0)
            {
                Spawner.MaxCount = Math.Max(0, Utility.ToInt32(tr.Text));
            }

            for (int i = 0; i < MaxEntries; i++)
            {
                TextRelay te  = info.GetTextEntry(i);
                TextRelay te2 = info.GetTextEntry(i + 20);

                SpawnObject so = i < Spawner.SpawnObjects.Count ? Spawner.SpawnObjects[i] : null;

                if (te != null)
                {
                    string name     = te.Text;
                    string maxCount = te2 != null ? te2.Text : null;
                    int    max      = 0;

                    if (name.Length > 0)
                    {
                        name = name.Trim();

                        if (!string.IsNullOrEmpty(maxCount))
                        {
                            max = Utility.ToInt32(maxCount);
                        }

                        max = Math.Max(0, max);

                        string t    = Spawner.ParseType(name);
                        Type   type = ScriptCompiler.FindTypeByName(t);

                        if (type == null)
                        {
                            from.SendMessage("{0} is not a valid type name.", t);
                            continue;
                        }

                        if (so != null)
                        {
                            if (so.SpawnName != name)
                            {
                                so.SpawnName = name;
                            }

                            if (so.MaxCount != max)
                            {
                                so.MaxCount = max;
                            }
                        }
                        else
                        {
                            Spawner.AddSpawnObject(new SpawnObject(name, max));
                        }
                    }
                }
            }
        }
Example #15
0
        public override void AddGumpLayout()
        {
            AddPage(0);

            AddBackground(0, 0, 410, 381, 5054);

            AddLabel(75, 1, 0, "Spawn List");
            AddLabel(335, 1, 0, "Max");
            AddLabel(378, 1, 0, "Total");

            AddButton(5, 310, 0xFB7, 0xFB9, 1, GumpButtonType.Reply, 0);
            AddLabel(38, 310, LabelHue, "Apply");

            AddButton(5, 333, 0xFA8, 0xFAB, 1025, GumpButtonType.Reply, 0);
            AddLabel(38, 333, LabelHue, "Props");

            AddButton(5, 356, 0xFB1, 0xFB3, 0, GumpButtonType.Reply, 0);
            AddLabel(38, 356, LabelHue, "Cancel");

            AddButton(110, 310, 0xFA5, 0xFA7, 1500, GumpButtonType.Reply, 0);
            AddLabel(143, 310, LabelHue, string.Format("Running: {0}", Spawner.Running ? "Yes" : "No"));

            AddButton(110, 333, 0xFA5, 0xFA7, 1000, GumpButtonType.Reply, 0);
            AddLabel(143, 333, LabelHue, string.Format("Group: {0}", Spawner.Group ? "Yes" : "No"));

            AddButton(110, 356, 0xFB4, 0xFB6, 2, GumpButtonType.Reply, 0);
            AddLabel(143, 356, LabelHue, "Bring to Home");

            AddButton(270, 333, 0xFA8, 0xFAA, 3, GumpButtonType.Reply, 0);
            AddLabel(303, 333, LabelHue, "Total Respawn");

            AddButton(270, 356, 0xFA8, 0xFAA, 1750, GumpButtonType.Reply, 0);
            AddLabel(303, 356, LabelHue, "Total Reset");

            AddImageTiled(350, 306, 30, 23, 0xA40);
            AddImageTiled(351, 307, 28, 21, 0xBBC);

            AddLabel(270, 306, LabelHue, "Max Spawn:");
            AddTextEntry(353, 307, 28, 21, 0, 500, Spawner.MaxCount.ToString());

            AddLabel(382, 307, 0, Spawner.SpawnCount.ToString());

            for (int i = 0; i < MaxEntries; i++)
            {
                AddButton(5, (22 * i) + 20, 0xFA5, 0xFA7, 4 + (i * 2), GumpButtonType.Reply, 0);
                AddButton(38, (22 * i) + 20, 0xFA2, 0xFA4, 5 + (i * 2), GumpButtonType.Reply, 0);

                AddImageTiled(71, (22 * i) + 20, 279, 23, 0xA40);
                AddImageTiled(72, (22 * i) + 21, 277, 21, 0xBBC);

                AddImageTiled(330, (22 * i) + 20, 50, 23, 0xA40);
                AddImageTiled(331, (22 * i) + 21, 48, 21, 0xBBC);

                string str = "";
                int    max = 0;

                if (i < Spawner.SpawnObjects.Count)
                {
                    SpawnObject so = Spawner.SpawnObjects[i];

                    str = so.SpawnName;
                    max = so.MaxCount;

                    int count = Spawner.CountCreatures(so);
                    AddLabel(382, (22 * i) + 20, 0, count.ToString());
                }

                AddTextEntry(75, (22 * i) + 21, 304, 21, 0, i, str);
                AddTextEntry(332, (22 * i) + 21, 28, 21, 0, i + 20, max.ToString());
            }
        }
Example #16
0
 public int GetSpawnCount(SpawnObject so)
 {
     return(so?.CurrentCount ?? 0);
 }