예제 #1
0
        public XmlSocketable(int maxsockets, string skillname, double minskilllevel, string skillname2, double minskilllevel2, string resource, int quantity)
        {
            this.MaxSockets = maxsockets;

            try
            {
                this.RequiredResource = SpawnerType.GetType(resource);
            }
            catch
            {
            }

            try
            {
                this.RequiredSkill = (SkillName)Enum.Parse(typeof(SkillName), skillname);
            }
            catch
            {
            }

            this.MinSkillLevel = minskilllevel;

            try
            {
                this.RequiredSkill2 = (SkillName)Enum.Parse(typeof(SkillName), skillname2);
            }
            catch
            {
            }

            this.MinSkillLevel2 = minskilllevel2;

            this.ResourceQuantity = quantity;
            this.InvalidateParentProperties();
        }
예제 #2
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
                        {
                            AddLabel(70, 230, 39, "Invalid Search String");
                        }
                    }
                }
            }

            return(creaturesName);
        }
예제 #3
0
        private static void ExecuteDeathAction(Item corpse, Mobile killer, string action)
        {
            if (action == null || action.Length <= 0 || corpse == null)
            {
                return;
            }

            string status_str = null;

            XmlSpawner.SpawnObject TheSpawn = new XmlSpawner.SpawnObject(null, 0);

            TheSpawn.TypeName = action;
            string substitutedtypeName = BaseXmlSpawner.ApplySubstitution(null, corpse, killer, action);
            string typeName            = BaseXmlSpawner.ParseObjectType(substitutedtypeName);

            Point3D loc = corpse.Location;
            Map     map = corpse.Map;

            if (BaseXmlSpawner.IsTypeOrItemKeyword(typeName))
            {
                BaseXmlSpawner.SpawnTypeKeyword(corpse, TheSpawn, typeName, substitutedtypeName, true, killer, loc, map, out status_str);
            }
            else
            {
                // its a regular type descriptor so find out what it is
                Type type = SpawnerType.GetType(typeName);
                try
                {
                    string[] arglist = BaseXmlSpawner.ParseString(substitutedtypeName, 3, "/");
                    object   o       = XmlSpawner.CreateObject(type, arglist[0]);

                    if (o == null)
                    {
                        status_str = "invalid type specification: " + arglist[0];
                    }
                    else
                    if (o is Mobile)
                    {
                        Mobile m = (Mobile)o;
                        if (m is BaseCreature)
                        {
                            BaseCreature c = (BaseCreature)m;
                            c.Home = loc;                                     // Spawners location is the home point
                        }

                        m.Location = loc;
                        m.Map      = map;

                        BaseXmlSpawner.ApplyObjectStringProperties(null, substitutedtypeName, m, killer, corpse, out status_str);
                    }
                    else
                    if (o is Item)
                    {
                        Item item = (Item)o;
                        BaseXmlSpawner.AddSpawnItem(null, corpse, TheSpawn, item, loc, map, killer, false, substitutedtypeName, out status_str);
                    }
                }
                catch { }
            }
        }
예제 #4
0
 public void DoSpawn()
 {
     if (this.m_Entity != null)
     {
         this.m_Entity.MoveToWorld(this.Location, this.Map);
     }
     if (this.NestSpawnType != null && this.m_Spawn != null && this.Count() < this.m_MaxCount)
     {
         try
         {
             Type   type = SpawnerType.GetType(this.NestSpawnType);
             object o    = Activator.CreateInstance(type);
             if (o != null && o is Mobile)
             {
                 Mobile c = o as Mobile;
                 if (c is BaseCreature)
                 {
                     BaseCreature m = o as BaseCreature;
                     this.m_Spawn.Add(m);
                     m.OnBeforeSpawn(this.Location, this.Map);
                     m.MoveToWorld(this.Location, this.Map);
                     m.Home      = this.Location;
                     m.RangeHome = this.m_RangeHome;
                 }
             }
         }
         catch
         {
             this.NestSpawnType = null;
         }
     }
 }
예제 #5
0
        /// <summary>
        /// Returns list of guard types a kin is eligible to hire
        /// </summary>
        /// <param name="alignment"></param>
        /// <returns></returns>
        public static List <KinFactionGuardTypes> GetEligibleGuardTypes(IOBAlignment alignment)
        {
            List <KinFactionGuardTypes> results = new List <KinFactionGuardTypes>();

            foreach (KinFactionGuardTypes guardType in Enum.GetValues(typeof(KinFactionGuardTypes)))
            {
                try
                {
                    //See if this type exists and has a KinFactionGuardTypeAttribute
                    Type t = SpawnerType.GetType(guardType.ToString().ToLower());
                    if (t != null)
                    {
                        bool addToList = true;
                        KinFactionGuardTypeAttribute[] att = (KinFactionGuardTypeAttribute[])t.GetCustomAttributes(typeof(KinFactionGuardTypeAttribute), true);

                        //Note here that if there isn't an attribute, all kins get added
                        if (att != null && att.Length > 0 && att[0].EligibleKin != null && att[0].EligibleKin.Count > 0)
                        {
                            if (att[0].EligibleKin != null && !att[0].EligibleKin.Contains(alignment))
                            {
                                addToList = false;
                            }
                        }
                        if (addToList)
                        {
                            results.Add(guardType);
                        }
                    }
                }
                catch
                {
                }
            }
            return(results);
        }
예제 #6
0
        /// <summary>
        /// Returns cost type of the guard using reflection, or defaults to Medium. This is the amount of slots required for the guard.
        /// </summary>
        /// <returns></returns>
        public static int GetGuardCostType(KinFactionGuardTypes guardType)
        {
            //Default to medium cost
            int  cost = (int)KinFactionGuardCostTypes.MediumCost;
            Type t    = SpawnerType.GetType(guardType.ToString());

            if (t == null)
            {
                return(cost);
            }
            //Although foreach is used here, there will only be one of these attributes.
            foreach (KinFactionGuardTypeAttribute att in t.GetCustomAttributes(typeof(KinFactionGuardTypeAttribute), true))
            {
                //Use the custom value if it was provided
                if (att.CustomSlotCost > 0)
                {
                    cost = att.CustomSlotCost;
                }
                else
                {
                    cost = (int)att.GuardCostType;
                }
            }
            return(cost);
        }
예제 #7
0
        /// <summary>
        /// Returns silver guard hire cost based on guard type using reflection
        /// </summary>
        /// <returns></returns>
        public static int GetGuardHireCost(KinFactionGuardTypes guardType)
        {
            //Default to medium cost
            int  cost = KinSystemSettings.GuardTypeMediumSilverCost;
            Type t    = SpawnerType.GetType(guardType.ToString());

            if (t == null)
            {
                return(cost);
            }
            foreach (KinFactionGuardTypeAttribute att in t.GetCustomAttributes(typeof(KinFactionGuardTypeAttribute), true))
            {                    //Although foreach is used here, there will only be one of these attributes.
                //Use the custom value if it was provided
                if (att.CustomHireCost > 0)
                {
                    cost = att.CustomHireCost;
                }
                else
                {
                    switch (att.GuardCostType)
                    {
                    case KinFactionGuardCostTypes.LowCost: cost = KinSystemSettings.GuardTypeLowSilverCost; break;

                    case KinFactionGuardCostTypes.MediumCost: cost = KinSystemSettings.GuardTypeMediumSilverCost; break;

                    case KinFactionGuardCostTypes.HighCost: cost = KinSystemSettings.GuardTypeHighSilverCost; break;
                    }
                }
            }
            return(cost);
        }
예제 #8
0
        // note that this method will be called when attached to either a mobile or a weapon
        // when attached to a weapon, only that weapon will do additional damage
        // when attached to a mobile, any weapon the mobile wields will do additional damage
        public override void OnWeaponHit(Mobile attacker, Mobile defender, BaseWeapon weapon, int damageGiven)
        {
            // if it is still refractory then return
            if (DateTime.UtcNow < this.m_EndTime)
            {
                return;
            }

            if (this.m_Chance <= 0 || Utility.Random(100) > this.m_Chance)
            {
                return;
            }

            if (defender != null && attacker != null)
            {
                // spawn a minion
                object o = null;
                try
                {
                    o = Activator.CreateInstance(SpawnerType.GetType(this.m_Minion));
                }
                catch
                {
                }

                if (o is BaseCreature)
                {
                    BaseCreature b = o as BaseCreature;
                    b.MoveToWorld(attacker.Location, attacker.Map);

                    if (attacker is PlayerMobile)
                    {
                        b.Controlled    = true;
                        b.ControlMaster = attacker;
                    }

                    b.Combatant = defender;

                    // add it to the list of controlled mobs
                    this.MinionList.Add(b);
                }
                else
                {
                    if (o is Item)
                    {
                        ((Item)o).Delete();
                    }
                    if (o is Mobile)
                    {
                        ((Mobile)o).Delete();
                    }
                    // bad minion specification so delete the attachment
                    this.Delete();
                }

                this.m_EndTime = DateTime.UtcNow + this.Refractory;
            }
        }
예제 #9
0
        /// <summary>
        /// Loads info
        /// </summary>
        /// <param name="reader"></param>
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();

            m_RitualItem   = SpawnerType.GetType(reader.ReadString());
            m_RitualAmount = reader.ReadInt();

            Serial serial = reader.ReadInt();

            PSpawner = World.FindItem(serial);
        }
예제 #10
0
        public void Spawn(int index)
        {
            if (m_ItemsName.Count == 0 || index >= m_ItemsName.Count)
            {
                return;
            }

            Defrag();

            //limit already at
            if (m_Items.Count >= m_Count)
            {
                return;
            }

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

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

                    if (o is Item)
                    {
                        //parent must be container to spawn
                        if (this.Parent is Container)
                        {
                            Item item = (Item)o;

                            //add it to the list
                            m_Items.Add(item);
                            InvalidateProperties();
                            //spawn it in the container
                            Container cont = (Container)this.Parent;
                            cont.DropItem(item);
                        }
                    }
                }
                catch
                {
                }
            }
        }
예제 #11
0
        public void Spawn(int index)
        {
            if (m_ItemsName.Count == 0 ||
                index >= m_ItemsName.Count ||
                m_Container == null)
            {
                return;
            }

            Defrag();

            //limit already at for this type of item
            // (changed from m_Items.Count so that m_Count items of each type will spawn)
            if (CountItems((string)m_ItemsName[index]) >= m_Count)
            {
                return;
            }

            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;

                            //add it to the list
                            m_Items.Add(item);
                            InvalidateProperties();
                            //spawn it in the container
                            Container cont = m_Container;
                            cont.DropItem(item);
                        }
                    }
                }
                catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); }
            }
        }
예제 #12
0
        public override void OnResponse(NetState sender, RelayInfo info)
        {
            Mobile from = sender.Mobile;

            if (from == null)
            {
                return;
            }

            int val = info.ButtonID - 1;

            if (val < 0)
            {
                return;
            }

            int version = val % 15;
            int index   = val / 15;

            switch (version)
            {
            case 0:
            {
                DeleteByTypeGumpPage page;

                switch (index)
                {
                case 0: page = DeleteByTypeGumpPage.start; break;

                case 1: page = DeleteByTypeGumpPage.targeting; break;

                case 2: page = DeleteByTypeGumpPage.textentry; break;

                default: return;
                }
                from.SendGump(new DeleteByTypeGump(m_staff, m_todelete, m_count, m_item, m_typename, page, m_count));
                break;
            }

            case 1:
            {
                switch (index)
                {
                case 0:                                 // close the gump
                {
                    from.SendMessage("DeleteByType Gump Closing");
                    return;
                }

                case 1:                                 // Targeting
                {
                    from.Target = new DeleteByTypeTarget();
                    break;
                }

                case 2:                                 // TextEntry
                {
                    Mobile staff = from;

                    TextRelay entry    = info.GetTextEntry(0);
                    string    typename = (entry == null ? "" : entry.Text.Trim());

                    int       count    = 0;
                    int       precount = 0;
                    ArrayList ToDelete = new ArrayList();
                    Type      type     = SpawnerType.GetType(typename);

                    if (type == null || typename.Length == 0)
                    {
                        staff.SendMessage(0x35, "You must enter a Valid TypeName.");
                        staff.SendGump(new DeleteByTypeGump(m_staff, m_todelete, m_count, m_item, m_typename, DeleteByTypeGumpPage.start, precount));
                        return;
                    }

                    if (type == typeofItem || type.IsSubclassOf(typeofItem))
                    {
                        foreach (Item item in World.Items.Values)
                        {
                            if (item.GetType().Name == type.Name)
                            {
                                if (item != null && !item.Deleted)
                                {
                                    ToDelete.Add(item);
                                    precount++;
                                }
                            }
                        }
                        staff.SendGump(new DeleteByTypeGump(staff, ToDelete, count, null, typename, DeleteByTypeGumpPage.textentry, precount));
                    }
                    break;
                }

                case 3:                                // Last Chance Targeting Delete
                {
                    DeleteByTypeTarget.mToDelete(m_staff, m_todelete, m_count, m_item, null);
                    break;
                }

                case 4:                                // Last Chance TextEntry Delete
                {
                    DeleteByTypeTarget.mToDelete(m_staff, m_todelete, m_count, null, m_typename);
                    break;
                }
                }
                break;
            }
            }
        }
        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)); }
                }
            }
        }
예제 #14
0
        public void Spawn()
        {
            Map map = Map;

            if (map == null || map == Map.Internal || m_Location == Point3D.Zero || m_Creature == null || m_Creature == "-invalid-")
            {
                return;
            }

            Type type = SpawnerType.GetType((string)m_Creature);

            if (type != null)
            {
                m_NextSpawn = DateTime.Now + m_Delay;

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

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

                        m_Creatures.Add(m);
                        InvalidateProperties();

                        m.Map      = map;
                        m.Location = m_Location;

                        if (m_Message != null)
                        {
                            m.PublicOverheadMessage(MessageType.Regular, 0x76C, false, m_Message);
                        }

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

                            c.RangeHome = m_HomeRange;

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

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

                        m_Creatures.Add(item);
                        InvalidateProperties();

                        item.MoveToWorld(m_Location, map);

                        if (m_Message != null)
                        {
                            item.PublicOverheadMessage(MessageType.Regular, 0x76C, false, m_Message);
                        }
                    }
                }
                catch
                {
                    PublicOverheadMessage(MessageType.Regular, 0x3BD, false, string.Format("Exception Caught"));                         // debugging
                }
            }
        }
예제 #15
0
        // adds components from a multi.txt file to an existing addon
        public static int LoadAddonFromMulti(XmlSpawnerAddon newaddon, string filename, out string status_str)
        {
            status_str = null;

            if (filename == null)
            {
                status_str = "Invalid filename";
                return(0);
            }

            if (newaddon == null)
            {
                status_str = "Invalid addon";
                return(0);
            }

            bool badformat   = false;
            int  ncomponents = 0;

            if (System.IO.File.Exists(filename))
            {
                using (StreamReader sr = new StreamReader(filename))
                {
                    string line;
                    int    linenumber = 0;

                    // Read and process lines from the file until the end of the file is reached.
                    // Individual lines have the format of
                    // itemid x y z visible [hue] ; attachment[,args]
                    // where visible is a 0/1 and hue can be optionally specified for individual itemid entries.
                    while ((line = sr.ReadLine()) != null)
                    {
                        linenumber++;

                        // process the line
                        if (line.Length == 0)
                        {
                            continue;
                        }

                        // first parse out the component specification from any optional attachment specifications

                        string[] specs = line.Split(';');

                        // the component spec will always be first

                        if (specs == null || specs.Length < 1)
                        {
                            continue;
                        }

                        string[] args = specs[0].Trim().Split(' ');

                        AddonComponent newcomponent = null;

                        if (args != null && args.Length >= 5)
                        {
                            int itemid  = -1;
                            int x       = 0;
                            int y       = 0;
                            int z       = 0;
                            int visible = 0;
                            int hue     = -1;

                            try
                            {
                                itemid  = int.Parse(args[0]);
                                x       = int.Parse(args[1]);
                                y       = int.Parse(args[2]);
                                z       = int.Parse(args[3]);
                                visible = int.Parse(args[4]);

                                // handle the optional fields that are not part of the original multi.txt specification
                                if (args.Length > 5)
                                {
                                    hue = int.Parse(args[5]);
                                }
                            }
                            catch { badformat = true; }

                            if (itemid < 0 || badformat)
                            {
                                status_str = String.Format("Error line {0}", linenumber);
                                break;
                            }

                            // create the new component
                            newcomponent = new AddonComponent(itemid);

                            // set the properties according to the specification
                            newcomponent.Visible = (visible == 1);

                            if (hue >= 0)
                            {
                                newcomponent.Hue = hue;
                            }

                            // add it to the addon
                            newaddon.AddComponent(newcomponent, x, y, z);

                            ncomponents++;
                        }

                        // if a valid component was added, then check to see if any additional attachment specifications need to be processed
                        if (newcomponent != null && specs.Length > 1)
                        {
                            for (int j = 1; j < specs.Length; j++)
                            {
                                if (specs[j] == null)
                                {
                                    continue;
                                }

                                string attachstring = specs[j].Trim();

                                Type type = null;
                                try
                                {
                                    type = SpawnerType.GetType(BaseXmlSpawner.ParseObjectType(attachstring));
                                }
                                catch { }

                                // if so then create it
                                if (type != null && type.IsSubclassOf(typeof(XmlAttachment)))
                                {
                                    object newo = XmlSpawner.CreateObject(type, attachstring, false, true);
                                    if (newo is XmlAttachment)
                                    {
                                        // add the attachment to the target
                                        XmlAttach.AttachTo(newcomponent, (XmlAttachment)newo);
                                    }
                                }
                            }
                        }
                    }

                    sr.Close();
                }
            }
            else
            {
                status_str = "No such file : " + filename;
            }

            if (badformat)
            {
                return(0);
            }
            else
            {
                return(ncomponents);
            }
        }
예제 #16
0
        public override void OnDoubleClick(Mobile from)
        {
            Type type = SpawnerType.GetType(m_ItemType);

            if (type != null && typeof(Item).IsAssignableFrom(type))
            {
                object o = null;

                try
                {
                    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 (m_ParamList.Length == paramList.Length)
                            {
                                object[] paramValues = Add.ParseValues(paramList, m_ParamList);

                                if (paramValues != null)
                                {
                                    o = ctor.Invoke(paramValues);
                                    break;
                                }
                            }
                        }
                    }
                }
                catch
                {
                    Console.WriteLine("VendStone: Invalid constructor or parameters for {0}: {1} {2}", Serial, m_ItemType, m_Parameters);
                }

                Item item = o as Item;

                if (m_Value < 0)
                {
                    m_Value = 0;
                }

                int amt = from.AccessLevel >= AccessLevel.GameMaster ? 0 : Currency.Consume(from, m_Value, true, CurrencyType.Both);

                if (amt > 0)
                {
                    from.SendMessage(1153, "You lack {0}gp for this", amt);
                    item.Delete();
                }
                else if (from.AddToBackpack(item))
                {
                    from.SendMessage("You place the {0} into your backpack.", FullName);
                    from.PlaySound(from.Backpack.GetDroppedSound(item));
                }
                else
                {
                    from.SendMessage("You do not have room for this item in your backpack and it has been dropped to the ground.");
                    int sound = item.GetDropSound();
                    from.PlaySound(sound == -1 ? 0x42 : sound);
                }
            }
            else
            {
                from.SendMessage("There is nothing being sold on this stone.");
            }
        }
예제 #17
0
        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((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);


                        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;

                            c.RangeHome = m_HomeRange;

                            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
                {
                }
            }
        }
예제 #18
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();

            m_MinDelay  = reader.ReadTimeSpan();
            m_MaxDelay  = reader.ReadTimeSpan();
            m_Count     = 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);
                }
            }

            m_Farmer = reader.ReadMobile();

            if (m_Running)
            {
                DoTimer(ts);
            }
        }
예제 #19
0
        public override TransferMessage ProcessMessage()
        {
            ArrayList tmparray = new ArrayList();
            Type      type     = null;

            // is there a object type restriction?
            if (ObjectType != null && ObjectType.Length > 0)
            {
                //type = Type.GetType(ObjectType);
                type = SpawnerType.GetType(ObjectType);
            }

            if (type != null)
            {
                if (type == typeof(Mobile) || type.IsSubclassOf(typeof(Mobile)))
                {
                    // because this is going to run in a separate thread, need to worry about the world lists
                    // being modified while loooping, so make a copy
                    ArrayList mobilearray = null;

                    mobilearray = new ArrayList(World.Mobiles.Values);

                    if (mobilearray != null)
                    {
                        foreach (Mobile m in mobilearray)
                        {
                            if (m.Map == null || m.Map == Map.Internal)
                            {
                                continue;
                            }

                            bool passed = true;

                            // match map
                            if (m.Map.MapID != SelectedMap && SelectedMap != -1)
                            {
                                passed = false;
                            }

                            // match type
                            if (passed && type != m.GetType() && !m.GetType().IsSubclassOf(type))
                            {
                                passed = false;
                            }

                            // check filters

                            // apply playermobile filters
                            if (m is PlayerMobile)
                            {
                                PlayerMobile b = (PlayerMobile)m;

                                // AccessLevel restricted?  1=playeronly 2=staffonly 3=counseloronly 4=gmonly 5=seeronly 6=adminonly
                                if (passed && Access > 0)
                                {
                                    if (Access == 1 && b.AccessLevel != AccessLevel.Player)
                                    {
                                        passed = false;
                                    }
                                    else
                                    if (Access == 2 && b.AccessLevel == AccessLevel.Player)
                                    {
                                        passed = false;
                                    }
                                    else
                                    if (Access == 3 && b.AccessLevel != AccessLevel.Counselor)
                                    {
                                        passed = false;
                                    }
                                    else
                                    if (Access == 4 && b.AccessLevel != AccessLevel.GameMaster)
                                    {
                                        passed = false;
                                    }
                                    else
                                    if (Access == 5 && b.AccessLevel != AccessLevel.Seer)
                                    {
                                        passed = false;
                                    }
                                    else
                                    if (Access == 6 && b.AccessLevel != AccessLevel.Administrator)
                                    {
                                        passed = false;
                                    }
                                }

                                // criminal restricted?  1=innocentonly 2=criminalonly 3=murdereronly
                                if (passed && Criminal > 0)
                                {
                                    int noto = NotorietyHandlers.MobileNotoriety(b, b);

                                    if (Criminal == 1 && noto != Notoriety.Innocent)
                                    {
                                        passed = false;
                                    }
                                    else
                                    if (Criminal == 2 && noto != Notoriety.Criminal && noto != Notoriety.Murderer)
                                    {
                                        passed = false;
                                    }
                                    else
                                    if (Criminal == 3 && noto != Notoriety.Murderer)
                                    {
                                        passed = false;
                                    }
                                }
                            }

                            // apply basecreature filters
                            if (m is BaseCreature)
                            {
                                BaseCreature b = (BaseCreature)m;

                                // controlled restricted?  1=controlledonly 2=notcontrolled
                                if (passed && Controlled > 0)
                                {
                                    if (Controlled == 1 && !b.Controled)
                                    {
                                        passed = false;
                                    }
                                    else
                                    if (Controlled == 2 && b.Controled)
                                    {
                                        passed = false;
                                    }
                                }

                                // innocent restricted?  1=innocentonly 2=invulnerable 3=attackable
                                if (passed && Innocent > 0)
                                {
                                    int noto = NotorietyHandlers.MobileNotoriety(b, b);

                                    if (Innocent == 1 && noto != Notoriety.Innocent)
                                    {
                                        passed = false;
                                    }
                                    else
                                    if (Innocent == 2 && noto != Notoriety.Invulnerable)
                                    {
                                        passed = false;
                                    }
                                    else
                                    if (Innocent == 3 && noto != Notoriety.CanBeAttacked)
                                    {
                                        passed = false;
                                    }
                                }
                            }

                            // add it to the array if it passed all the tests
                            if (passed)
                            {
                                tmparray.Add(m);
                            }
                        }
                    }
                }
                else
                if (type == typeof(Item) || type.IsSubclassOf(typeof(Item)))
                {
                    ArrayList itemarray = null;

                    itemarray = new ArrayList(World.Items.Values);

                    if (itemarray != null)
                    {
                        foreach (Item m in itemarray)
                        {
                            if (m.Map == null || m.Map == Map.Internal)
                            {
                                continue;
                            }

                            bool passed = true;

                            if (m.Map.MapID != SelectedMap && SelectedMap != -1)
                            {
                                passed = false;
                            }

                            if (passed && type != m.GetType() && !m.GetType().IsSubclassOf(type))
                            {
                                passed = false;
                            }

                            // movable restricted?  1=movableonly 2=not movable only
                            if (passed && Movable > 0)
                            {
                                if (Movable == 1 && !m.Movable)
                                {
                                    passed = false;
                                }
                                else
                                if (Movable == 2 && m.Movable)
                                {
                                    passed = false;
                                }
                            }

                            // visible restricted?  1=visibleonly 2=not visible only
                            if (passed && Visible > 0)
                            {
                                if (Visible == 1 && !m.Visible)
                                {
                                    passed = false;
                                }
                                else
                                if (Visible == 2 && m.Visible)
                                {
                                    passed = false;
                                }
                            }

                            // blessed restricted?  1=blessedonly 2=notblessed
                            if (passed && Blessed > 0)
                            {
                                if (Blessed == 1 && m.LootType != LootType.Blessed)
                                {
                                    passed = false;
                                }
                                else
                                if (Blessed == 2 && m.LootType == LootType.Blessed)
                                {
                                    passed = false;
                                }
                            }

                            // static restricted?  1=staticsonly 2=no statics
                            if (passed && Statics > 0)
                            {
                                if (Statics == 1 && !(m is Static))
                                {
                                    passed = false;
                                }
                                else
                                if (Statics == 2 && m is Static)
                                {
                                    passed = false;
                                }
                            }

                            // container restricted?  1=incontaineronly 2=not in containers
                            if (passed && InContainers > 0)
                            {
                                if (InContainers == 1 && !(m.Parent is Container))
                                {
                                    passed = false;
                                }
                                else
                                if (InContainers == 2 && m.Parent is Container)
                                {
                                    passed = false;
                                }
                            }

                            // carried by mobiles restricted?  1=carriedonly 2=not carried
                            if (passed && Carried > 0)
                            {
                                if (Carried == 1 && !(m.RootParent is Mobile))
                                {
                                    passed = false;
                                }
                                else
                                if (Carried == 2 && m.RootParent is Mobile)
                                {
                                    passed = false;
                                }
                            }

                            // itemid restricted?
                            if (passed && ItemID >= 0 && ItemID != m.ItemID)
                            {
                                passed = false;
                            }

                            if (passed)
                            {
                                tmparray.Add(m);
                            }
                        }
                    }
                }
            }

            ObjectData [] objectlist = new ObjectData[tmparray.Count];

            for (int i = 0; i < tmparray.Count; i++)
            {
                if (tmparray[i] is Mobile)
                {
                    Mobile m = tmparray[i] as Mobile;

                    string name = m.Name;
                    if (name == null)
                    {
                        name = m.GetType().Name;
                    }

                    // append a title if they have one
                    if (m.Title != null)
                    {
                        name += " " + m.Title;
                    }

                    // fill the return data array
                    objectlist[i] = new ObjectData((short)m.Location.X, (short)m.Location.Y, (byte)m.Map.MapID, name);
                }
                else
                if (tmparray[i] is Item)
                {
                    Item m = tmparray[i] as Item;

                    // fill the return data array
                    string name = m.Name;
                    if (name == null)
                    {
                        name = m.GetType().Name;
                    }

                    short x = (short)m.Location.X;
                    short y = (short)m.Location.Y;
                    if (m.RootParent is Mobile)
                    {
                        x = (short)((Mobile)m.RootParent).Location.X;
                        y = (short)((Mobile)m.RootParent).Location.Y;
                    }
                    else
                    if (m.RootParent is Container)
                    {
                        x = (short)((Container)m.RootParent).Location.X;
                        y = (short)((Container)m.RootParent).Location.Y;
                    }


                    objectlist[i] = new ObjectData(x, y, (byte)m.Map.MapID, name);
                }
            }

            return(new ReturnObjectData(objectlist));
        }
예제 #20
0
        private static int SaveSpawnersWorker(CommandEventArgs e)
        {
            List <Spawner> list = new List <Spawner>();

            foreach (Item ix in World.Items.Values)
            {
                Spawner sx = ix as Spawner;

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

                // now filter for type, that is spawners that contain this object.
                //	for instance "cottonplant"
                if (e.Arguments.Length > 0)
                {
                    //if (sx.ObjectNames != null && sx.ObjectNames.Contains(e.Arguments[0]) == false)
                    if (sx.ObjectTypes.Contains(SpawnerType.GetType(e.Arguments[0])) == false)
                    {
                        continue;
                    }
                }

                list.Add(sx);
            }

            int write_count = 0;

            if (write_count++ % 100 == 0)
            {
                Console.WriteLine("Saving spawner {0} of {1}", write_count, list.Count);
            }

            if (!Directory.Exists("Saves/Capture"))
            {
                Directory.CreateDirectory("Saves/Capture");
            }

            string filePath = Path.Combine("Saves/Capture", "spawners.xml");

            using (StreamWriter op = new StreamWriter(filePath))
            {
                XmlTextWriter xml = new XmlTextWriter(op);

                xml.Formatting  = Formatting.Indented;
                xml.IndentChar  = '\t';
                xml.Indentation = 1;

                xml.WriteStartDocument(true);
                xml.WriteStartElement("SPAWNERS");

                // just to be complete..
                xml.WriteAttributeString("Count", list.Count.ToString());

                // Now write each entry
                foreach (Spawner spawner in list)
                {
                    Save(spawner, xml);
                }

                //and end doc
                xml.WriteEndElement();
                xml.Close();
            }

            return(list.Count);
        }
예제 #21
0
        // Searches for spawners and returns struct list containing
        // relevant detail

        public static ArrayList FindMobSpawners(string searchtext, int x, int y, int tilerange)
        {
            ArrayList SpawnerList   = new ArrayList();
            Regex     SearchPattern = new Regex(searchtext.ToLower());

            // Loop through mobiles and check for Spawners

            foreach (Item item in World.Items.Values)
            {
                if (item is Server.Mobiles.Spawner)
                {
                    Spawner sp = (Spawner)item;

                    // Now check range / ignore range accordingly

                    int spX = sp.Location.X - x;
                    int spY = sp.Location.Y - y;

                    if ((tilerange == 0) || (
                            (sqr(sp.Location.X - x) <= sqr(tilerange) &&
                             sqr(sp.Location.Y - y) <= sqr(tilerange))
                            ))
                    {
                        // Loop through spawners' creature list and match
                        // against search text

                        foreach (string CreatureName in sp.CreaturesName)
                        {
                            if (SearchPattern.IsMatch(CreatureName.ToLower()))
                            {
                                SpawnerMatch ms = new SpawnerMatch();

                                ms.Item = false;
                                ms.Sp   = sp;

                                // Check if item type

                                Type   TestType = SpawnerType.GetType(CreatureName);
                                string strTest  = TestType.ToString();

                                Regex InvalidPatt = new Regex("^Server.Item");

                                if (InvalidPatt.IsMatch(strTest))
                                {
                                    ms.Item = true;
                                }
                                // We have a match! Create new match struct
                                // and add to return reference list

                                if (sp.Running == true)
                                {
                                    ms.Status = "on";
                                }
                                else
                                {
                                    ms.Status = "off";
                                }

                                ms.Matched  = CreatureName;
                                ms.Distance = (int)Math.Sqrt(sqr(spX) + sqr(spY));

                                SpawnerList.Add(ms);
                            }
                        }
                    }
                }

                if (item is Server.Items.ChestItemSpawner)
                {
                    ChestItemSpawner sp = (ChestItemSpawner)item;

                    // Now check range / ignore range accordingly

                    int spX = sp.Location.X - x;
                    int spY = sp.Location.Y - y;

                    if ((tilerange == 0) || (
                            (sqr(sp.Location.X - x) <= sqr(tilerange) &&
                             sqr(sp.Location.Y - y) <= sqr(tilerange))
                            ))
                    {
                        // Loop through spawners' creature list and match
                        // against search text

                        foreach (string ItemName in sp.ItemsName)
                        {
                            if (SearchPattern.IsMatch(ItemName.ToLower()))
                            {
                                SpawnerMatch ms = new SpawnerMatch();

                                ms.Item = false;
                                ms.Sp   = sp;

                                // Check if item type

                                Type   TestType = SpawnerType.GetType(ItemName);
                                string strTest  = TestType.ToString();

                                Regex InvalidPatt = new Regex("^Server.Item");

                                if (InvalidPatt.IsMatch(strTest))
                                {
                                    ms.Item = true;
                                }
                                // We have a match! Create new match struct
                                // and add to return reference list

                                if (sp.Running == true)
                                {
                                    ms.Status = "on";
                                }
                                else
                                {
                                    ms.Status = "off";
                                }

                                ms.Matched  = ItemName;
                                ms.Distance = (int)Math.Sqrt(sqr(spX) + sqr(spY));

                                SpawnerList.Add(ms);
                            }
                        }
                    }
                }
            }

            return(SpawnerList);
        }
예제 #22
0
        public override void OnDoubleClick(Mobile from)
        {
            Type type = SpawnerType.GetType(ItemType);

            if (type != null && type.IsEqualOrChildOf <Item>())
            {
                if (m_Price < 0)
                {
                    m_Price = 0;
                }

                if (from.AccessLevel < AccessLevel.GameMaster && m_Price > 0)
                {
                    int totalGold = 0;

                    if (from.Backpack != null)
                    {
                        totalGold += from.Backpack.GetAmount(TypeOfCurrency, true);
                    }

                    totalGold += Banker.GetBalance(from, TypeOfCurrency);

                    if (totalGold < m_Price)
                    {
                        from.SendMessage(1153, "You lack the funds to purchase this.");
                        return;
                    }
                }

                object o = null;

                try
                {
                    ConstructorInfo[] ctors = type.GetConstructors();

                    foreach (ConstructorInfo ctor in ctors)
                    {
                        if (!Add.IsConstructable(ctor, AccessLevel.GameMaster))
                        {
                            continue;
                        }

                        ParameterInfo[] paramList = ctor.GetParameters();

                        if (m_ParamList.Length != paramList.Length)
                        {
                            continue;
                        }

                        object[] paramValues = Add.ParseValues(paramList, m_ParamList);

                        if (paramValues == null)
                        {
                            continue;
                        }

                        o = ctor.Invoke(paramValues);
                        break;
                    }
                }
                catch
                {
                    Console.WriteLine(
                        "VendStone: Invalid constructor or parameters for {0}: {1} {2}", Serial, ItemType, m_Parameters);
                }

                var item = o as Item;

                if (item != null && from.Backpack != null)
                {
                    if (from.AddToBackpack(item))
                    {
                        from.SendMessage("You place the {0} into your backpack.", FullName);
                        from.PlaySound(from.Backpack.GetDroppedSound(item));

                        int leftPrice = m_Price;

                        if (from.Backpack != null)
                        {
                            leftPrice -= from.Backpack.ConsumeUpTo(TypeOfCurrency, leftPrice, true);
                        }

                        if (leftPrice > 0)
                        {
                            Banker.Withdraw(from, TypeOfCurrency, leftPrice);
                        }
                    }
                    else
                    {
                        from.SendMessage("You do not have room for this item in your backpack.");
                        int sound = item.GetDropSound();
                        from.PlaySound(sound == -1 ? 0x42 : sound);
                    }
                }
            }
            else
            {
                from.SendMessage("The magic from this stone has faded.");
            }
        }
예제 #23
0
파일: XmlUse.cs 프로젝트: Pumpk1ns/outlands
        private void ExecuteAction(Mobile mob, object target, string action)
        {
            if (action == null || action.Length <= 0)
            {
                return;
            }

            string status_str = null;

            Server.Mobiles.XmlSpawner.SpawnObject TheSpawn = new Server.Mobiles.XmlSpawner.SpawnObject(null, 0);

            TheSpawn.TypeName = action;
            string substitutedtypeName = BaseXmlSpawner.ApplySubstitution(null, target, mob, action);
            string typeName            = BaseXmlSpawner.ParseObjectType(substitutedtypeName);

            Point3D loc = new Point3D(0, 0, 0);
            Map     map = null;


            if (target is Item)
            {
                Item ti = target as Item;
                if (ti.Parent == null)
                {
                    loc = ti.Location;
                    map = ti.Map;
                }
                else if (ti.RootParent is Item)
                {
                    loc = ((Item)ti.RootParent).Location;
                    map = ((Item)ti.RootParent).Map;
                }
                else if (ti.RootParent is Mobile)
                {
                    loc = ((Mobile)ti.RootParent).Location;
                    map = ((Mobile)ti.RootParent).Map;
                }
            }
            else if (target is Mobile)
            {
                Mobile ti = target as Mobile;

                loc = ti.Location;
                map = ti.Map;
            }

            if (BaseXmlSpawner.IsTypeOrItemKeyword(typeName))
            {
                BaseXmlSpawner.SpawnTypeKeyword(target, TheSpawn, typeName, substitutedtypeName, true, mob, loc, map, out status_str);
            }
            else
            {
                // its a regular type descriptor so find out what it is
                Type type = SpawnerType.GetType(typeName);
                try
                {
                    string[] arglist = BaseXmlSpawner.ParseString(substitutedtypeName, 3, "/");
                    object   o       = Server.Mobiles.XmlSpawner.CreateObject(type, arglist[0]);

                    if (o == null)
                    {
                        status_str = "invalid type specification: " + arglist[0];
                    }
                    else
                    if (o is Mobile)
                    {
                        Mobile m = (Mobile)o;
                        if (m is BaseCreature)
                        {
                            BaseCreature c = (BaseCreature)m;
                            c.Home = loc;     // Spawners location is the home point
                        }

                        m.Location = loc;
                        m.Map      = map;

                        BaseXmlSpawner.ApplyObjectStringProperties(null, substitutedtypeName, m, mob, target, out status_str);
                    }
                    else
                    if (o is Item)
                    {
                        Item item = (Item)o;
                        BaseXmlSpawner.AddSpawnItem(null, target, TheSpawn, item, loc, map, mob, false, substitutedtypeName, out status_str);
                    }
                }
                catch { }
            }

            ReportError(mob, status_str);
        }
예제 #24
0
파일: Import.cs 프로젝트: zerodowned/annox
        public static void ProcessSpawnSet(
            string spawnSet,
            int x,
            int y,
            int z,
            int hRange,
            int sRange,
            int n,
            string mapName
            )
        {
            Point3D location = new Point3D(x, y, z);

            Map mapInstance = null;

            Map[] maps = Map.Maps;

            foreach (Map map in maps)
            {
                if (map.Name == mapName)
                {
                    mapInstance = map;
                    break;
                }
            }

            if (mapInstance == null)
            {
                Console.WriteLine("#### RE: no map for map nammed \"{0}\".", mapName);
            }

            Dictionary <string, List <ImportRecord> > regionEncounters;

            if (facetEncounters.ContainsKey(mapName))
            {
                regionEncounters = facetEncounters[mapName];
            }
            else
            {
                regionEncounters = new Dictionary <string, List <ImportRecord> >();

                facetEncounters.Add(mapName, regionEncounters);
            }

            Region region = Region.Find(location, mapInstance);

            if (
                region != null
                &&
                region.Name != null
                &&
                region.Name != "")
            {
                string[] spawns = spawnSet.Split(':');

                List <ImportRecord> encounterSet;

                if (regionEncounters.ContainsKey(region.Name))
                {
                    encounterSet = regionEncounters[region.Name];
                }
                else
                {
                    /*
                     *  public class ProbabilityComparer : IComparer
                     *  {
                     *      public int Compare( object o1, object o2 )
                     *      {
                     *          ImportRecord r1 = (ImportRecord) o1;
                     *          ImportRecord r2 = (ImportRecord) o2;
                     *
                     *          if ( r1.P > r2.P ) return -1;
                     *          if ( r1.P < r2.P ) return 1;
                     *
                     *          else return 0;
                     *      }
                     *  }
                     */
                    encounterSet = new List <ImportRecord>( );

                    regionEncounters.Add(region.Name, encounterSet);
                }

                foreach (string spawn in spawns)
                {
                    Type   typeObject = SpawnerType.GetType(spawn);
                    object created    = null;
                    double level      = 0.0;
                    double p          = 0.0;

                    if (typeObject == null)
                    {
                        continue;
                    }
                    try
                    {
                        created = Activator.CreateInstance(typeObject);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        continue;
                    }

                    if (created is TownCrier)
                    {
                        continue;
                    }
                    if (created is BaseVendor)
                    {
                        continue;
                    }
                    if (created is Mobile)
                    {
                        Mobile m = (Mobile)created;

                        bool hostile = (m is BaseEscortable) ? false : true;

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

                            switch (c.AI)
                            {
                            case AIType.AI_Healer: { hostile = false; break; }

                            case AIType.AI_Vendor: { hostile = false; break; }

                            case AIType.AI_Animal: { if (c.Fame < 400)
                                                     {
                                                         hostile = false;
                                                     }
                                                     break; }
                            }
                        }

                        level = Helpers.CalculateLevelForMobile(m, LevelType.Overall);

                        p = 1.0 / Math.Pow(1 + level, 1.4);

                        ImportRecord ir = new ImportRecord(
                            (Mobile)created,
                            spawn,
                            x,
                            y,
                            z,
                            hRange,
                            sRange,
                            n,
                            mapName,
                            region.Name,
                            level,
                            hostile,
                            p
                            );

                        //Console.WriteLine("        "+ir);

                        encounterSet.Add(ir);
                    }
                }
            }
        }