Esempio n. 1
0
        protected override ISpawnable Construct(SpawnEntry entry, Point3D loc, Map map)
        {
            Item item = CreateItem();

            item.OnBeforeSpawn(loc, map);
            item.MoveToWorld(loc, map);
            item.OnAfterSpawn();

            return(item);
        }
Esempio n. 2
0
        public override ISpawnable Spawn(SpawnEntry entry)
        {
            BaseRegion region = entry.Region;
            Map        map    = region.Map;

            Point3D loc = entry.RandomSpawnLocation(this.Height, this.Land, this.Water);

            if (loc == Point3D.Zero)
            {
                return(null);
            }

            return(Construct(entry, loc, map));
        }
Esempio n. 3
0
        public override ISpawnable Spawn(SpawnEntry entry)
        {
            int index = Utility.Random(m_TotalWeight);

            for (int i = 0; i < m_Elements.Length; i++)
            {
                SpawnGroupElement element = m_Elements[i];

                if (index < element.Weight)
                {
                    return(element.SpawnDefinition.Spawn(entry));
                }

                index -= element.Weight;
            }

            return(null);
        }
Esempio n. 4
0
        protected override ISpawnable Construct(SpawnEntry entry, Point3D loc, Map map)
        {
            Mobile mobile = CreateMobile();

            BaseCreature creature = mobile as BaseCreature;

            if (creature != null)
            {
                creature.Home      = entry.HomeLocation;
                creature.RangeHome = entry.HomeRange;
            }

            if (entry.Direction != SpawnEntry.InvalidDirection)
            {
                mobile.Direction = entry.Direction;
            }

            mobile.OnBeforeSpawn(loc, map);
            mobile.MoveToWorld(loc, map);
            mobile.OnAfterSpawn();

            return(mobile);
        }
Esempio n. 5
0
        public static bool CanSpawn(Region region, params Type[] types)
        {
            while (region != null)
            {
                if (!region.AllowSpawn())
                {
                    return(false);
                }

                BaseRegion br = region as BaseRegion;

                if (br != null)
                {
                    if (br.Spawns != null)
                    {
                        for (int i = 0; i < br.Spawns.Length; i++)
                        {
                            SpawnEntry entry = br.Spawns[i];

                            if (entry.Definition.CanSpawn(types))
                            {
                                return(true);
                            }
                        }
                    }

                    if (br.ExcludeFromParentSpawns)
                    {
                        return(false);
                    }
                }

                region = region.Parent;
            }

            return(false);
        }
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadEncodedInt();

            int count = reader.ReadInt();

            for (int i = 0; i < count; i++)
            {
                int id = reader.ReadInt();

                SpawnEntry entry = (SpawnEntry)SpawnEntry.Table[id];

                if (entry != null)
                {
                    entry.Deserialize(reader, version);
                }
                else
                {
                    SpawnEntry.Remove(reader, version);
                }
            }
        }
Esempio n. 7
0
 public abstract ISpawnable Spawn(SpawnEntry entry);
Esempio n. 8
0
 protected abstract ISpawnable Construct(SpawnEntry entry, Point3D loc, Map map);
Esempio n. 9
0
        public BaseRegion(XmlElement xml, Map map, Region parent) : base(xml, map, parent)
        {
            ReadString(xml["rune"], "name", ref m_RuneName, false);

            bool logoutDelayActive = true;

            ReadBoolean(xml["logoutDelay"], "active", ref logoutDelayActive, false);
            m_NoLogoutDelay = !logoutDelayActive;


            XmlElement spawning = xml["spawning"];

            if (spawning != null)
            {
                ReadBoolean(spawning, "excludeFromParent", ref m_ExcludeFromParentSpawns, false);

                SpawnZLevel zLevel = SpawnZLevel.Lowest;
                ReadEnum(spawning, "zLevel", ref zLevel, false);
                m_SpawnZLevel = zLevel;


                List <SpawnEntry> list = new List <SpawnEntry>();

                foreach (XmlNode node in spawning.ChildNodes)
                {
                    XmlElement el = node as XmlElement;

                    if (el != null)
                    {
                        SpawnDefinition def = SpawnDefinition.GetSpawnDefinition(el);
                        if (def == null)
                        {
                            continue;
                        }

                        int id = 0;
                        if (!ReadInt32(el, "id", ref id, true))
                        {
                            continue;
                        }

                        int amount = 0;
                        if (!ReadInt32(el, "amount", ref amount, true))
                        {
                            continue;
                        }

                        TimeSpan minSpawnTime = SpawnEntry.DefaultMinSpawnTime;
                        ReadTimeSpan(el, "minSpawnTime", ref minSpawnTime, false);

                        TimeSpan maxSpawnTime = SpawnEntry.DefaultMaxSpawnTime;
                        ReadTimeSpan(el, "maxSpawnTime", ref maxSpawnTime, false);

                        Point3D home  = Point3D.Zero;
                        int     range = 0;

                        XmlElement homeEl = el["home"];
                        if (ReadPoint3D(homeEl, map, ref home, false))
                        {
                            ReadInt32(homeEl, "range", ref range, false);
                        }

                        Direction dir = SpawnEntry.InvalidDirection;
                        ReadEnum(el["direction"], "value", ref dir, false);

                        SpawnEntry entry = new SpawnEntry(id, this, home, range, dir, def, amount, minSpawnTime, maxSpawnTime);
                        list.Add(entry);
                    }
                }

                if (list.Count > 0)
                {
                    m_Spawns = list.ToArray();
                }
            }
        }