Exemplo n.º 1
0
        public ArrayList CreateArray(RelayInfo info, Mobile from)
        {
            ArrayList itemsName = 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 = ChestItemSpawnerType.GetType(str);


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

            return(itemsName);
        }
Exemplo n.º 2
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();

            m_Container = reader.ReadItem() as Container;
            m_MinDelay  = reader.ReadTimeSpan();
            m_MaxDelay  = reader.ReadTimeSpan();
            m_Count     = reader.ReadInt();
            m_Running   = reader.ReadBool();

            if (m_Running)
            {
                TimeSpan delay = reader.ReadTimeSpan();
                DoTimer(delay);
            }

            int size = reader.ReadInt();

            m_ItemsName = new ArrayList(size);

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

                m_ItemsName.Add(typeName);

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

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

            int count = reader.ReadInt();

            m_Items = new ArrayList(count);

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

                if (e != null)
                {
                    m_Items.Add(e);
                }
            }
        }
        public void Spawn(int index)
        {
            if (m_ItemsName.Count == 0 || index >= m_ItemsName.Count || m_Container == null)
            {
                return;
            }

            Defrag();

            // random means spawn N random items from the list
            // Note RandomItem is ignored when the spawner type is ChestLootPackSpawner
            if (m_RandomItem == false && this is ChestLootPackSpawner == false)
            {                   // See if we have reached the limit at for this type of item
                if (CountItems((string)m_ItemsName[index]) >= m_Count)
                {
                    return;
                }
            }
            // otherwise spawn N of everything in the list
            else
            {                   // See if we have reached the limit at for this type of item
                if (m_Items.Count >= m_Count)
                {
                    return;
                }
            }

            if (m_ChanceToSpawn >= Utility.RandomDouble())
            {
                Type type = SpawnerType.GetType((string)m_ItemsName[index]);

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

                        if (o is Item)
                        {
                            if (m_Container != null)
                            {
                                Item item = (Item)o;
                                m_Items.Add(item);                                              //add it to the list
                                InvalidateProperties();
                                Container cont = m_Container;                                   //spawn it in the container
                                cont.DropItem(item);
                            }
                        }
                    }
                    catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); }
                }

                Item lootPack = ChestItemSpawnerType.GetLootPack((string)m_ItemsName[index]);

                if (lootPack != null)
                {
                    try
                    {
                        ArrayList o = CreateItem(lootPack);

                        if (o != null && o.Count > 0)
                        {
                            if (m_Container != null)
                            {
                                for (int ix = 0; ix < o.Count; ix++)
                                {
                                    Item item = o[ix] as Item;
                                    m_Items.Add(item);                                                  //add it to the list
                                    InvalidateProperties();
                                    Container cont = m_Container;                                       //spawn it in the container
                                    cont.DropItem(item);
                                }
                            }
                        }
                    }
                    catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); }
                }
            }
        }