public ArrayList CreateArray(RelayInfo info, Mobile from)
        {
            ArrayList subSpawnerE = new ArrayList();

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

                if (te != null)
                {
                    string str = te.Text;

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

                        Type type = SpawnerType.GetType(str);

                        if (type != null)
                        {
                            subSpawnerE.Add(str);
                        }
                        else
                        {
                            from.SendMessage("{0} is not a valid type name.", str);
                        }
                    }
                }
            }

            return(subSpawnerE);
        }
Beispiel #2
0
        private ArrayList Search(object target, out string status_str)
        {
            status_str = null;
            ArrayList newarray   = new ArrayList();
            Type      targetType = null;

            // if the type is specified then get the search type
            if (Dosearchtype && Searchtype != null)
            {
                targetType = SpawnerType.GetType(Searchtype);
                if (targetType == null)
                {
                    status_str = "Invalid type: " + Searchtype;
                    return(newarray);
                }
            }

            ArrayList attachments = XmlAttach.FindAttachments(target as IEntity);

            // do the search through attachments
            if (attachments != null)
            {
                foreach (XmlAttachment i in attachments)
                {
                    bool hastype = false;
                    bool hasname = false;

                    if (i == null || i.Deleted)
                    {
                        continue;
                    }

                    // check for type
                    if (Dosearchtype && (i.GetType().IsSubclassOf(targetType) || i.GetType().Equals(targetType)))
                    {
                        hastype = true;
                    }
                    if (Dosearchtype && !hastype)
                    {
                        continue;
                    }

                    // check for name
                    if (Dosearchname && (i.Name != null) && (Searchname != null) &&
                        (i.Name.ToLower().IndexOf(Searchname.ToLower()) >= 0))
                    {
                        hasname = true;
                    }
                    if (Dosearchname && !hasname)
                    {
                        continue;
                    }

                    // satisfied all conditions so add it
                    newarray.Add(i);
                }
            }

            return(newarray);
        }
Beispiel #3
0
        public List <string> CreateArray(RelayInfo info, Mobile from)
        {
            List <string> creaturesName = new List <string>();

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

                if (te != null)
                {
                    string str = te.Text;

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

                        Type type = SpawnerType.GetType(str);

                        if (type != null)
                        {
                            creaturesName.Add(str);
                        }
                        else
                        {
                            from.SendMessage("{0} is not a valid type name.", str);
                        }
                    }
                }
            }

            return(creaturesName);
        }
        protected virtual IEntity CreateSpawnedObject(int index)
        {
            if (index >= m_CreaturesName.Count)
            {
                return(null);
            }


            Type type = SpawnerType.GetType(m_CreaturesName[index]);

            if (type != null)
            {
                try
                {
                    object o = Activator.CreateInstance(type);

                    return(o as IEntity);
                }
                catch
                {
                }
            }

            return(null);
        }
        public ArrayList CreateArray(RelayInfo info, Mobile from)
        {
            ArrayList creaturesName = new ArrayList();

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

                if (te != null)
                {
                    string str = te.Text;

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

                        Type type = SpawnerType.GetType(str);

                        if (type == null)
                        {
                            from.SendMessage("{0} is not a valid type name.", str);
                        }
                        else
                        {
                            if (type == typeofBaseCreature || type.IsSubclassOf(typeofBaseCreature))
                            {
                                if (type.IsSubclassOf(typeofBaseVendor) || type.IsSubclassOf(typeofBaseMount))
                                {
                                    from.SendMessage("a {0} may not carry a Guard's Key.", str);
                                }
                                else
                                {
                                    creaturesName.Add(str);
                                }
                            }
                            else
                            {
                                from.SendMessage("{0} is not a type of Creature.", str);
                            }
                        }
                    }
                }
            }

            return(creaturesName);
        }
Beispiel #6
0
        public void CreateArray(RelayInfo info, Mobile from, Spawner spawner)
        {
            int ocount = spawner.Entries.Count;

            List <SpawnerEntry> rementries = new List <SpawnerEntry>();

            for (int i = 0; i < 13; i++)
            {
                int index      = i * 5;
                int entryindex = (m_Page * 13) + i;

                TextRelay cte    = info.GetTextEntry(index);
                TextRelay mte    = info.GetTextEntry(index + 1);
                TextRelay poste  = info.GetTextEntry(index + 2);
                TextRelay parmte = info.GetTextEntry(index + 3);
                TextRelay propte = info.GetTextEntry(index + 4);

                if (cte != null)
                {
                    string str = cte.Text.Trim().ToLower();

                    if (str.Length > 0)
                    {
                        Type type = SpawnerType.GetType(str);

                        if (type != null)
                        {
                            SpawnerEntry entry = null;

                            if (entryindex < ocount)
                            {
                                entry             = spawner.Entries[entryindex];
                                entry.SpawnedName = str;

                                if (mte != null)
                                {
                                    entry.SpawnedMaxCount = Utility.ToInt32(mte.Text.Trim());
                                }

                                if (poste != null)
                                {
                                    entry.SpawnedProbability = Utility.ToInt32(poste.Text.Trim());
                                }
                            }
                            else
                            {
                                int maxcount  = 1;
                                int probcount = 100;

                                if (mte != null)
                                {
                                    maxcount = Utility.ToInt32(mte.Text.Trim());
                                }

                                if (poste != null)
                                {
                                    probcount = Utility.ToInt32(poste.Text.Trim());
                                }

                                entry = spawner.AddEntry(str, probcount, maxcount);
                            }

                            if (parmte != null)
                            {
                                entry.Parameters = parmte.Text.Trim();
                            }

                            if (propte != null)
                            {
                                entry.Properties = propte.Text.Trim();
                            }
                        }
                        else
                        {
                            from.SendMessage("{0} is not a valid type name for entry #{1}.", str, i);
                        }
                    }
                    else if (entryindex < ocount && spawner.Entries[entryindex] != null)
                    {
                        rementries.Add(spawner.Entries[entryindex]);
                    }
                }
            }

            if (rementries.Count > 0)
            {
                for (int i = 0; i < rementries.Count; i++)
                {
                    spawner.RemoveEntry(rementries[i]);
                }
            }

            if (ocount == 0 && spawner.Entries.Count > 0)
            {
                spawner.Start();
            }
        }
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();

            switch (version)
            {
            case 1:
            {
                key_KeyVal      = reader.ReadUInt();
                key_Description = reader.ReadString();
                key_Max         = reader.ReadInt();
                key_Delay       = TimeSpan.Parse(reader.ReadString());
                i_Door          = reader.ReadItem();

                goto case 0;
            }

            case 0:
            {
                m_SpawnRange = reader.ReadInt();
                m_WayPoint   = reader.ReadItem() as WayPoint;
                m_MinDelay   = reader.ReadTimeSpan();
                m_MaxDelay   = reader.ReadTimeSpan();
                m_Count      = 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.Now;
                }

                int size = reader.ReadInt();

                m_CreaturesName = new ArrayList(size);

                for (int i = 0; i < size; ++i)
                {
                    string typeName = reader.ReadString();

                    m_CreaturesName.Add(typeName);

                    if (SpawnerType.GetType(typeName) == null)
                    {
                        if (m_WarnTimer == null)
                        {
                            m_WarnTimer = new gWarnTimer();
                        }

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

                int count = reader.ReadInt();

                m_Creatures = new ArrayList(count);

                for (int i = 0; i < count; ++i)
                {
                    IEntity e = World.FindEntity(reader.ReadInt());

                    if (e != null)
                    {
                        m_Creatures.Add(e);
                    }
                }

                if (m_Running)
                {
                    DoTimer(ts);
                }

                break;
            }
            }
        }
        public void Spawn(int index)
        {
            Map map = Map;

            if (map == null || map == Map.Internal || m_CreaturesName.Count == 0 || index >= m_CreaturesName.Count)
            {
                return;
            }

            Defrag();

            if (m_Creatures.Count >= m_Count)
            {
                return;
            }

            Type type = SpawnerType.GetType((string)m_CreaturesName[index]);

            if (type != null)
            {
                try
                {
                    object o = Activator.CreateInstance(type);

                    if (o is Mobile)
                    {
                        Mobile m = (Mobile)o;

                        m_Creatures.Add(m);
                        InvalidateProperties();

                        m.Map = map;

                        m.Location = GetSpawnPosition();

                        GuardKey key = new GuardKey(key_KeyVal, key_Description, key_Max, key_Delay);
                        // m.AddToBackpack( key );

                        if (m is BaseCreature)
                        {
                            BaseCreature c = (BaseCreature)m;

                            c.PackItem(key);

                            c.RangeHome = m_HomeRange;

                            c.CurrentWayPoint = m_WayPoint;

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

                            c.Home = this.Location;
                        }
                    }
                }
                catch
                {
                }
            }
        }
Beispiel #9
0
		public static Spawner GetRandomSpawner(SpawnerType type)
		{
			// if still empty, fail
			if (m_Spawners.Count == 0)
				return null;

			Spawner spawner = null;
			Utility.TimeCheck tc = new Utility.TimeCheck();
			tc.Start();
			//try to find an appropriate spawner
			for (int count = 0; count < m_Spawners.Count * 2; ++count)
			{
				// pick one at random..
				Spawner random = m_Spawners[Utility.Random(m_Spawners.Count)] as Spawner;
				Region region = Server.Region.Find(random.Location, Map.Felucca);

				// test if this spawner satisfies type required
				switch (type)
				{
					case SpawnerType.Overland:
						{
							// Must be running
							if (!random.Running)
								continue;

							if (region != null)
							{	// No Towns
								if (IsTown(region.Name))
									continue;

								// no green acres, inside houses, etc..
								if (IsValidRegion(random.Location, region) == false)
									continue;
							}

							break;
						}

					default:
						{
							if (region != null)
							{
								// no green acres, inside houses, etc..
								if (IsValidRegion(random.Location, region) == false)
									continue;
							}

							break;
						}
				}

				//this is a good candidate!
				spawner = random;
				break;
			}
			tc.End();
			if (tc.Elapsed() > 30)
			{
				LogHelper logger = new LogHelper("SpawnerCache");
				logger.Log("Warning:  Spawner overland search took " + tc.Elapsed().ToString() + "ms");
			}

			return spawner;

		}
Beispiel #10
0
        /// <summary>
        /// Spawns the mobile or item with the index given
        /// </summary>
        /// <param name="index">number representing the mobile or item</param>
        public void Spawn(int index)
        {
            Map map = Map;

            if (map == null || map == Map.Internal || m_CreaturesName.Count == 0 || index >= m_CreaturesName.Count || Parent != null)
            {
                return;
            }

            Defrag();

            if (m_Creatures.Count >= m_Count)
            {
                return;
            }

            Type type = SpawnerType.GetType(m_CreaturesName[index]);

            if (type != null)
            {
                try
                {
                    object o = Activator.CreateInstance(type);

                    if (o is Mobile)
                    {
                        Mobile m = (Mobile)o;

                        m_Creatures.Add(m);


                        Point3D loc = (m is BaseVendor ? this.Location : GetSpawnPosition());

                        m.OnBeforeSpawn(loc, map);
                        InvalidateProperties();


                        m.MoveToWorld(loc, map);

                        if (m is BaseCreature)
                        {
                            BaseCreature c = (BaseCreature)m;

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

                            c.CurrentWayPoint = m_WayPoint;

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

                            c.Home = this.Location;
                        }

                        m.OnAfterSpawn();
                    }
                    else if (o is Item)
                    {
                        Item item = (Item)o;

                        m_Creatures.Add(item);

                        Point3D loc = GetSpawnPosition();

                        item.OnBeforeSpawn(loc, map);
                        InvalidateProperties();

                        item.MoveToWorld(loc, map);

                        item.OnAfterSpawn();
                    }
                }
                catch
                {
                }
            }

            m_WaveStarted = false;
        }
Beispiel #11
0
        public virtual void Spawn(int index)
        {
            Map map = Map;

            if (map == null || map == Map.Internal || m_CreaturesName.Count == 0 || index >= m_CreaturesName.Count)
            {
                return;
            }

            if (m_Creatures.Count >= m_Count)
            {
                return;
            }

            Type type = SpawnerType.GetType((string)m_CreaturesName[index]);

            if (type != null)
            {
                try
                {
                    object o = Activator.CreateInstance(type);

                    if (o is Mobile)
                    {
                        Mobile m = (Mobile)o;

                        m_Creatures.Add(m);
                        InvalidateProperties();

                        m.Map = map;

                        if (m is BaseVendor)
                        {
                            m.Location = this.Location;
                        }
                        else
                        {
                            m.Location = GetSpawnPosition();
                        }

                        if (m is BaseCreature)
                        {
                            BaseCreature c = (BaseCreature)m;

                            c.RangeHome       = m_HomeRange;
                            c.CurrentWayPoint = m_WayPoint;

                            if (m_Team > 0)
                            {
                                c.Team = m_Team;
                            }
                            if (m_RelHomeRange)
                            {
                                c.Home = c.Location;
                            }
                            else
                            {
                                c.Home = this.Location;
                            }
                        }
                    }
                    else if (o is Item)
                    {
                        Item item = (Item)o;

                        m_Creatures.Add(item);
                        InvalidateProperties();

                        object parent = Parent;
                        if (parent != null && parent is Container)
                        {
                            ((Container)parent).DropItem(item);
                            if (parent is TrapableContainer)
                            {
                                TrapableContainer tc = (TrapableContainer)parent;
                                if (tc.TrapType != TrapType.None && !tc.Trapped)
                                {
                                    tc.Trapped = true;
                                }
                            }

                            if (parent is LockableContainer)
                            {
                                LockableContainer lc = (LockableContainer)parent;

                                if (lc.LockLevel > 0)
                                {
                                    lc.Locked = true;
                                }
                            }
                        }
                        else
                        {
                            item.MoveToWorld(GetSpawnPosition(), map);
                            item.LastMoved = DateTime.Now + TimeSpan.FromDays(30);
                        }
                    }
                }
                catch
                {
                }
            }
        }
        public void Spawn(int index)
        {
            Map map = Map;

            if (map == null || map == Map.Internal || m_CreaturesName.Count == 0 || index >= m_CreaturesName.Count)
            {
                return;
            }

            Defrag();

            if (m_Creatures.Count >= m_Count)
            {
                return;
            }

            Type type = SpawnerType.GetType((string)m_CreaturesName[index]);

            if (type != null)
            {
                try
                {
                    object o = Activator.CreateInstance(type);

                    if (o is Mobile)
                    {
                        Mobile m = (Mobile)o;

                        m_Creatures.Add(m);
                        InvalidateProperties();
// Base Vendors now spawn at any position (maps set SpawnRange to 0)
// this will spawn WanderingHealer at any point too (spawnrange = homerange)
                        Point3D loc = (/*m is BaseVendor ? this.Location :*/ GetSpawnPosition());

                        m.MoveToWorld(loc, map);

                        if (m is BaseCreature)
                        {
                            BaseCreature c = (BaseCreature)m;

                            c.RangeHome = m_HomeRange;

                            c.CurrentWayPoint = m_WayPoint;

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

                            c.Home = this.Location;
                        }
                    }
                    else if (o is Item)
                    {
                        Item item = (Item)o;

                        m_Creatures.Add(item);
                        InvalidateProperties();

                        item.MoveToWorld(GetSpawnPosition(), map);
                    }
                }
                catch
                {
                }
            }
        }
Beispiel #13
0
        public bool Spawn(SpawnerEntry entry, out EntryFlags flags)
        {
            Map map = GetSpawnMap();

            flags = EntryFlags.None;

            if (map == null || map == Map.Internal || Parent != null)
            {
                return(false);
            }

            //Defrag taken care of in Spawn(), beforehand
            //Count check taken care of in Spawn(), beforehand

            Type type = SpawnerType.GetType(entry.SpawnedName);

            if (type != null)
            {
                try
                {
                    object   o = null;
                    string[] paramargs;
                    string[] propargs;

                    if (String.IsNullOrEmpty(entry.Properties))
                    {
                        propargs = new string[0];
                    }
                    else
                    {
                        propargs = CommandSystem.Split(entry.Properties.Trim());
                    }

                    string[,] props = FormatProperties(propargs);

                    PropertyInfo[] realProps = GetTypeProperties(type, props);

                    if (realProps == null)
                    {
                        flags = EntryFlags.InvalidProps;
                        return(false);
                    }

                    if (String.IsNullOrEmpty(entry.Parameters))
                    {
                        paramargs = new string[0];
                    }
                    else
                    {
                        paramargs = entry.Parameters.Trim().Split(' ');
                    }

                    ConstructorInfo[] ctors = type.GetConstructors();

                    for (int i = 0; i < ctors.Length; ++i)
                    {
                        ConstructorInfo ctor = ctors[i];

                        if (Add.IsConstructable(ctor, AccessLevel.GameMaster))
                        {
                            ParameterInfo[] paramList = ctor.GetParameters();

                            if (paramargs.Length == paramList.Length)
                            {
                                object[] paramValues = Add.ParseValues(paramList, paramargs);

                                if (paramValues != null)
                                {
                                    o = ctor.Invoke(paramValues);
                                    for (int j = 0; j < realProps.Length; j++)
                                    {
                                        if (realProps[j] != null)
                                        {
                                            object toSet  = null;
                                            string result = Properties.ConstructFromString(realProps[j].PropertyType, o, props[j, 1], ref toSet);
                                            if (result == null)
                                            {
                                                realProps[j].SetValue(o, toSet, null);
                                            }
                                            else
                                            {
                                                flags = EntryFlags.InvalidProps;

                                                if (o is ISpawnable)
                                                {
                                                    ((ISpawnable)o).Delete();
                                                }

                                                return(false);
                                            }
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }

                    if (o is Mobile)
                    {
                        Mobile m = (Mobile)o;

                        m_Spawned.Add(m, entry);
                        entry.Spawned.Add(m);

                        Point3D loc = (m is BaseVendor ? this.Location : GetSpawnPosition(m, map));

                        m.OnBeforeSpawn(loc, map);
                        InvalidateProperties();

                        m.MoveToWorld(loc, map);

                        if (m is BaseCreature)
                        {
                            BaseCreature c = (BaseCreature)m;

                            int walkrange = GetWalkingRange();

                            if (walkrange >= 0)
                            {
                                c.RangeHome = walkrange;
                            }
                            else
                            {
                                c.RangeHome = m_HomeRange;
                            }

                            c.CurrentWayPoint = GetWayPoint();

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

                            c.Home    = this.Location;
                            c.HomeMap = this.Map;
                        }

                        m.Spawner = this;
                        m.OnAfterSpawn();
                    }
                    else if (o is Item)
                    {
                        Item item = (Item)o;

                        m_Spawned.Add(item, entry);
                        entry.Spawned.Add(item);

                        Point3D loc = GetSpawnPosition(item, map);

                        item.OnBeforeSpawn(loc, map);

                        item.MoveToWorld(loc, map);

                        item.Spawner = this;
                        item.OnAfterSpawn();
                    }
                    else
                    {
                        flags = EntryFlags.InvalidType | EntryFlags.InvalidParams;
                        return(false);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("EXCEPTION CAUGHT: {0:X}", Serial);
                    Console.WriteLine(e);
                    return(false);
                }

                InvalidateProperties();
                return(true);
            }

            flags = EntryFlags.InvalidType;
            return(false);
        }
Beispiel #14
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();

            m_Spawned = new Dictionary <ISpawnable, SpawnerEntry>();

            if (version < 7)
            {
                m_Entries = new List <SpawnerEntry>();
            }

            switch (version)
            {
            case 7:
            {
                int size = reader.ReadInt();

                m_Entries = new List <SpawnerEntry>(size);

                for (int i = 0; i < size; ++i)
                {
                    m_Entries.Add(new SpawnerEntry(this, reader));
                }

                goto case 4;                         //Skip the other crap
            }

            case 6:
            {
                int size = reader.ReadInt();

                bool addentries = m_Entries.Count == 0;

                for (int i = 0; i < size; ++i)
                {
                    if (addentries)
                    {
                        m_Entries.Add(new SpawnerEntry(String.Empty, 100, reader.ReadInt()));
                    }
                    else
                    {
                        m_Entries[i].SpawnedMaxCount = reader.ReadInt();
                    }
                }

                goto case 5;
            }

            case 5:
            {
                int size = reader.ReadInt();

                bool addentries = m_Entries.Count == 0;

                for (int i = 0; i < size; ++i)
                {
                    if (addentries)
                    {
                        m_Entries.Add(new SpawnerEntry(String.Empty, reader.ReadInt(), 1));
                    }
                    else
                    {
                        m_Entries[i].SpawnedProbability = reader.ReadInt();
                    }
                }

                goto case 4;
            }

            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_Count     = 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;
                }

                if (version < 7)
                {
                    int size = reader.ReadInt();

                    bool addentries = m_Entries.Count == 0;

                    for (int i = 0; i < size; ++i)
                    {
                        string typeName = reader.ReadString();

                        if (addentries)
                        {
                            m_Entries.Add(new SpawnerEntry(typeName, 100, 1));
                        }
                        else
                        {
                            m_Entries[i].SpawnedName = typeName;
                        }

                        if (SpawnerType.GetType(typeName) == null)
                        {
                            if (m_WarnTimer == null)
                            {
                                m_WarnTimer = new WarnTimer();
                            }

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

                    int count = reader.ReadInt();

                    for (int i = 0; i < count; ++i)
                    {
                        ISpawnable e = reader.ReadEntity() as ISpawnable;

                        if (e != null)
                        {
                            if (e is BaseCreature)
                            {
                                ((BaseCreature)e).RemoveIfUntamed = true;
                            }

                            e.Spawner = this;

                            for (int j = 0; j < m_Entries.Count; j++)
                            {
                                if (SpawnerType.GetType(m_Entries[j].SpawnedName) == e.GetType())
                                {
                                    m_Entries[j].Spawned.Add(e);
                                    m_Spawned.Add(e, m_Entries[j]);
                                    break;
                                }
                            }
                        }
                    }
                }

                DoTimer(ts);

                break;
            }
            }

            if (version < 4)
            {
                m_WalkingRange = m_HomeRange;
            }
        }
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();

            switch (version)
            {
            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_Count     = 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.Now;
                }

                int size = reader.ReadInt();

                m_CreaturesName = new ArrayList(size);

                for (int i = 0; i < size; ++i)
                {
                    string typeName = reader.ReadString();

                    m_CreaturesName.Add(typeName);

                    if (SpawnerType.GetType(typeName) == null)
                    {
                        if (m_WarnTimer == null)
                        {
                            m_WarnTimer = new WarnTimer();
                        }

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

                int count = reader.ReadInt();

                m_Creatures = new ArrayList(count);

                for (int i = 0; i < count; ++i)
                {
                    IEntity e = World.FindEntity(reader.ReadInt());

                    if (e != null)
                    {
                        m_Creatures.Add(e);
                    }
                }

                if (m_Running)
                {
                    DoTimer(ts);
                }

                break;
            }
            }

            for (int i = 0; i < m_CreaturesName.Count; i++)
            {
                Type type = SpawnerType.GetType((string)m_CreaturesName[i]);

                Item item = Activator.CreateInstance(type) as Item;

                if (item is StealableArtifact || item is StealableContainerArtifact || item is StealableLightArtifact || item is StealableLongswordArtifact || item is StealablePlateGlovesArtifact || item is StealableWarHammerArtifact || item is StealableExecutionersAxeArtifact || item is StealableFoodArtifact)
                {
                    item.Delete();

                    this.Delete();
                }
            }
        }
Beispiel #16
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();

            switch (version)
            {
            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_Count     = 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.Now;
                }

                int size = reader.ReadInt();

                m_CreaturesName = new List <string>(size);

                for (int i = 0; i < size; ++i)
                {
                    string typeName = reader.ReadString();

                    m_CreaturesName.Add(typeName);

                    if (SpawnerType.GetType(typeName) == null)
                    {
                        if (m_WarnTimer == null)
                        {
                            m_WarnTimer = new WarnTimer();
                        }

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

                int count = reader.ReadInt();

                m_Creatures = new List <IEntity>(count);

                for (int i = 0; i < count; ++i)
                {
                    IEntity e = World.FindEntity(reader.ReadInt());

                    if (e != null)
                    {
                        m_Creatures.Add(e);
                    }
                }

                if (m_Running)
                {
                    DoTimer(ts);
                }

                break;
            }
            }

            if (version < 3 && Weight == 0)
            {
                Weight = -1;
            }
        }
        public static Spawner GetRandomSpawner(SpawnerType type)
        {
            // if still empty, fail
            if (m_Spawners.Count == 0)
            {
                return(null);
            }

            Spawner spawner = null;

            Utility.TimeCheck tc = new Utility.TimeCheck();
            tc.Start();
            //try to find an appropriate spawner
            for (int count = 0; count < m_Spawners.Count * 2; ++count)
            {
                // pick one at random..
                Spawner random = m_Spawners[Utility.Random(m_Spawners.Count)] as Spawner;
                Region  region = Server.Region.Find(random.Location, Map.Felucca);

                // test if this spawner satisfies type required
                switch (type)
                {
                case SpawnerType.Overland:
                {
                    // Must be running
                    if (!random.Running)
                    {
                        continue;
                    }

                    if (region != null)
                    {                                           // No Towns
                        if (IsTown(region.Name))
                        {
                            continue;
                        }

                        // no green acres, inside houses, etc..
                        if (IsValidRegion(random.Location, region) == false)
                        {
                            continue;
                        }
                    }

                    break;
                }

                default:
                {
                    if (region != null)
                    {
                        // no green acres, inside houses, etc..
                        if (IsValidRegion(random.Location, region) == false)
                        {
                            continue;
                        }
                    }

                    break;
                }
                }

                //this is a good candidate!
                spawner = random;
                break;
            }
            tc.End();
            if (tc.Elapsed() > 30)
            {
                LogHelper logger = new LogHelper("SpawnerCache");
                logger.Log("Warning:  Spawner overland search took " + tc.Elapsed().ToString() + "ms");
            }

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

            int version = reader.ReadInt();

            switch (version)
            {
            case 3:
            {
                m_SpawnRange = reader.ReadInt();
// ----------------------------------------
                m_SpawnID = reader.ReadInt();
// ----------------------------------------

                goto case 2;
            }

            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_Count     = 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.Now;
                }

                int size = reader.ReadInt();

                m_CreaturesName = new ArrayList(size);

                for (int i = 0; i < size; ++i)
                {
                    string typeName = reader.ReadString();

                    m_CreaturesName.Add(typeName);

                    if (SpawnerType.GetType(typeName) == null)
                    {
                        if (m_WarnTimer == null)
                        {
                            m_WarnTimer = new WarnTimer();
                        }

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

                int count = reader.ReadInt();

                m_Creatures = new ArrayList(count);

                for (int i = 0; i < count; ++i)
                {
                    IEntity e = World.FindEntity(reader.ReadInt());

                    if (e != null)
                    {
                        m_Creatures.Add(e);
                    }
                }

                if (m_Running)
                {
                    DoTimer(ts);
                }

                break;
            }
            }

            m_SpawnRange = (version <= 2 ? m_HomeRange : m_SpawnRange);               //fix SpawnRange until first Deserialize of ver 3
        }
Beispiel #19
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();

            switch (version)
            {
            case 3:
            {
                m_SpawnRange   = reader.ReadInt();
                m_RelHomeRange = reader.ReadBool();

                goto case 2;
            }

            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_Count     = 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.Now;
                }

                int size = reader.ReadInt();

                m_CreaturesName = new ArrayList(size);

                for (int i = 0; i < size; ++i)
                {
                    string typeName = reader.ReadString();

                    /*
                     * if ( typeName == "JackRabit" )
                     *      typeName = "JackRabbit";
                     * else if ( typeName == "Rabit" )
                     *      typeName = "Rabbit";
                     * else if ( typeName.ToLower() == "barkeeper" )
                     *      typeName = "Tavernkeeper";
                     */

                    m_CreaturesName.Add(typeName);

                    if (SpawnerType.GetType(typeName) == null)
                    {
                        if (m_WarnTimer == null)
                        {
                            m_WarnTimer = new WarnTimer();
                        }

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

                int count = reader.ReadInt();

                m_Creatures = new ArrayList(count);

                for (int i = 0; i < count; ++i)
                {
                    IEntity e = World.FindEntity(reader.ReadInt());

                    if (e != null)
                    {
                        m_Creatures.Add(e);
                    }
                }

                if (m_Running)
                {
                    DoTimer(ts);
                }

                break;
            }
            }
        }