public override void OnResponse(Mobile from, string text)
            {
                bool invalid = false;

                // Pattern match for invalid characters
                Regex InvalidPatt = new Regex("[^0-9]");

                if (InvalidPatt.IsMatch(text))
                {
                    invalid = true;
                }
                else
                if (text.Length > 3)
                {
                    invalid = true;
                }
                else
                if (Convert.ToInt16(text) > 255 || Convert.ToInt16(text) < 1)
                {
                    invalid = true;
                }

                if (invalid == true)
                {
                    // Invalid chars
                    from.SendMessage("You may only use numbers (1-255) to define indexes.");
                    from.SendMessage("Please enter a number instead :");
                    from.Prompt = new IndexPrompt(state, from, RareFactory.ViewingDOD);
                }
                else
                {
                    // The property we set + whether we send an additional prompt
                    // is dependent on our entry state
                    switch (state)
                    {
                    case 0:
                    {
                        m_DODInst.StartIndex = Convert.ToInt16(text);
                        from.SendMessage("Please enter the 'Last Index' of the rare : ");
                        from.Prompt = new IndexPrompt(((short)(state + 1)), from, m_DODInst);
                        break;
                    }

                    case 1:
                    {
                        m_DODInst.LastIndex = Convert.ToInt16(text);
                        from.SendMessage("Please enter the 'Start Date' of the rare : ");
                        from.Prompt = new DatePrompt(((short)0), from, m_DODInst);
                        break;
                    }
                    }

                    // Update their display
                    RareFactory.ReloadViews(from);
                }
            }
            public override void OnResponse(Mobile from, string text)
            {
                // Pattern match for invalid characters
                Regex InvalidPatt = new Regex("[^-a-zA-Z0-9' ]");

                DateTime resDateTime = new DateTime();

                try
                {
                    resDateTime = Convert.ToDateTime(text);
                }
                catch (Exception e)
                {
                    from.SendMessage("You must use a valid date/time format.");
                    from.SendMessage("Please re-enter in the format <DD/MM/YYYY HH:MM:SS> :");
                    from.Prompt = new DatePrompt(state, from, RareFactory.ViewingDOD);
                    LogHelper.LogException(e);
                    return;
                }

                try
                {
                    // The property we set + whether we send an additional prompt
                    // is dependent on our entry state
                    switch (state)
                    {
                    case 0:
                    {
                        m_DODInst.StartDate = Convert.ToDateTime(text);
                        from.SendMessage("Please enter the 'End Date' of the rare : ");
                        from.Prompt = new DatePrompt(((short)(state + 1)), from, m_DODInst);
                        break;
                    }

                    case 1:
                    {
                        m_DODInst.EndDate = Convert.ToDateTime(text);
                        from.SendMessage("Sucessfully defined new rare '" + m_DODInst.Name + "'!");
                        break;
                    }
                    }
                }
                catch (Exception e)
                {
                    // Console.WriteLine("RFControlGump() : Caught exception trying to set date properties : {0}", e);
                    LogHelper.LogException(e);
                }


                // Update their display
                RareFactory.ReloadViews(from);
            }
            protected override void OnTarget(Mobile from, object targ)
            {
                if (!(targ is Item))
                {
                    from.SendMessage("You can only create rares from items.");
                    return;
                }

                // Create the rare from the item
                RareFactory.AddRare((Item)targ);

                // Give it a name! Viewing DOD will be the one we're after now
                from.SendMessage("Enter the name you wish to use to represent the rare :");
                from.Prompt = new RareNamePrompt(from, RareFactory.ViewingDOD);
            }
            public override void OnResponse(Mobile from, string text)
            {
                if (text.ToLower() == "y")
                {
                    RareFactory.ViewingDOD.Expire();

                    if (RareFactory.ViewingDODIndex > 0)
                    {
                        RareFactory.ViewingDODIndex -= 1;
                    }
                }
                else
                {
                    from.SendMessage("Rare deletion cancelled.");
                }

                RareFactory.ReloadViews(from);
            }
            public override void OnResponse(Mobile from, string text)
            {
                if (text.ToLower() == "y")
                {
                    // Delete all the DOD instances first
                    DODGroup dg = (DODGroup)RareFactory.DODGroup[m_idg];

                    for (int i = 0; i < dg.DODInst.Count; i++)
                    {
                        string sName = "";

                        if (dg.DODInst[i] is DODInstance)
                        {
                            sName = ((DODInstance)dg.DODInst[i]).Name;
                        }

                        from.SendMessage("Deleting rare '{0}'...", sName);

                        for (int inst = 0; inst < RareFactory.DODInst.Count; inst++)
                        {
                            if (((DODInstance)RareFactory.DODInst[inst]) == dg.DODInst[i])
                            {                               // There should never be more than one of these right?
                                RareFactory.DODInst.RemoveAt(inst);
                                break;
                            }
                        }
                    }

                    from.SendMessage("Deleting group '{0}'", dg.Name);
                    RareFactory.DODGroup.RemoveAt(m_idg);

                    from.SendMessage("Rare group deletion complete.");
                    if (RareFactory.ViewingDODGroupIndex > 0)
                    {
                        RareFactory.ViewingDODGroupIndex -= 1;
                    }
                }
                else
                {
                    from.SendMessage("Rare group deletion cancelled.");
                }

                RareFactory.ReloadViews(from);
            }
Beispiel #6
0
        public static void AcquireRare_OnCommand(CommandEventArgs e)
        {
            try
            {
                if (e.Length != 1 && e.Length != 2)
                {
                    e.Mobile.SendMessage("Incorrect number of arguments. Format : [acquirerare (<rare level>) <rare group name>");
                    return;
                }

                Regex ValidRarityPatt = new Regex("^[0-9]$");

                if (!ValidRarityPatt.IsMatch(e.GetString(0)))
                {
                    // Invalid
                    e.Mobile.SendMessage("You may only enter an number to represent a rarity level. Format : [acquirerare (<rare level>) <rare group name>");
                    return;
                }

                int iRarity = e.GetInt32(0);

                // Check rarity level is ok
                if (iRarity < 0 || iRarity > 10)
                {
                    // Invalid
                    e.Mobile.SendMessage("Item rarity is scaled from 0 (most common) to 10 (most rare).");
                    return;
                }

                e.Mobile.Backpack.AddItem(
                    (e.Length == 1
                        ?
                     RareFactory.AcquireRare((short)iRarity)                    // only have rarity
                        :
                     RareFactory.AcquireRare((short)iRarity, e.GetString(1))    // rarity + group
                    ));
            }
            catch (Exception ex)
            {
                LogHelper.LogException(ex);
                e.Mobile.SendMessage(ex.Message);
            }
        }
            public override void OnResponse(Mobile from, string text)
            {
                // Pattern match for invalid characters
                Regex InvalidPatt = new Regex("[^-a-zA-Z0-9' ]");

                if (InvalidPatt.IsMatch(text) || text.Length < 1 || text.Length > 15)
                {
                    // Invalid chars
                    from.SendMessage("You may only use numbers, letters, apostrophes, hyphens and spaces (1-15 characters).");
                    from.SendMessage("Please re-enter an allowed name :");
                    from.Prompt = new RareNamePrompt(from, RareFactory.ViewingDOD);
                }
                else
                {
                    m_DODInst.Name = text;

                    from.SendMessage("Please enter the 'Start Index' of the rare :");
                    from.Prompt = new IndexPrompt(0, from, m_DODInst);

                    // Update their display
                    RareFactory.ReloadViews(from);
                }
            }
        public override void OnResponse(NetState state, RelayInfo info)
        {
            Mobile from = state.Mobile;

            switch ((RFButtons)info.ButtonID)
            {
            case RFButtons.AddRareButton:
            {
                // Make sure a group has been defined (if one has, one will be
                // selected by default - group 0)
                if (RareFactory.DODGroup.Count == 0)
                {
                    from.SendMessage("You must define a Dynamic Object Definition Group before adding rares.");
                    break;
                }

                from.SendMessage("Select the item you wish to use as a template for this rare...");
                from.Target = new RareTarget();
                break;
            }

            case RFButtons.DelRareButton:
            {
                if (RareFactory.ViewingDODGroup.DODInst.Count == 0)
                {
                    from.SendMessage("There are no rares to delete!");
                    break;
                }

                from.SendMessage("Are you sure you wish to delete this rare? (y/n)");
                from.Prompt = new DelConfirmPrompt(from);
                break;
            }


            case RFButtons.NextRareButton:
            {
                if (RareFactory.DODGroup.Count == 0)
                {
                    from.SendMessage("No rares defined!");
                    break;
                }

                // The .ViewingDODIndex references the relative index
                // within this particular DODGroup

                DODGroup dg = (DODGroup)RareFactory.DODGroup[RareFactory.ViewingDODGroupIndex];

                if ((RareFactory.ViewingDODIndex + 1) >= dg.DODInst.Count)
                {
                    from.SendMessage("Last rare in group!");
                    break;
                }
                else
                {
                    RareFactory.ViewingDODIndex++;
                    break;
                }
            }

            case RFButtons.PrevRareButton:
            {
                if (RareFactory.DODGroup.Count == 0)
                {
                    from.SendMessage("No rares defined!");
                    break;
                }

                // The .ViewingDODIndex references the relative index
                // within this particular DODGroup

                if (RareFactory.ViewingDODIndex == 0)
                {
                    from.SendMessage("First rare in group!");
                    break;
                }
                else
                {
                    RareFactory.ViewingDODIndex--;
                    break;
                }
            }

            case RFButtons.TestButton:
            {
                if (RareFactory.DODGroup.Count == 0)
                {
                    from.SendMessage("Define Dynamic Object Definition Groups and objects (rares) before attempting to generate test batches.");
                    break;
                }

                if (((DODGroup)RareFactory.DODGroup[RareFactory.ViewingDODGroupIndex]).DODInst.Count == 0)
                {
                    from.SendMessage("You must add rares to the group before attempting to generate test batches.");
                    break;
                }

                int prevCur = RareFactory.ViewingDOD.CurIndex;

                // Generates a complete set of rares as a test
                from.SendMessage("Generating example rare set...");

                for (int i = RareFactory.ViewingDOD.StartIndex; i <= RareFactory.ViewingDOD.LastIndex; i++)
                {
                    // Create a new item
                    DODInstance dodi    = RareFactory.ViewingDOD;
                    Item        newitem = RareFactory.DupeItem(dodi.RareTemplate);

                    newitem.Movable = true;
                    dodi.CurIndex   = (short)i;
                    dodi.DynamicFill(newitem);
                    from.AddToBackpack(newitem);
                }

                RareFactory.ViewingDOD.CurIndex = (short)prevCur;

                from.SendMessage("Completed. {0} rares generated and added to your backpack.",
                                 (RareFactory.ViewingDOD.LastIndex -
                                  RareFactory.ViewingDOD.StartIndex) + 1);

                break;
            }

            default:
            {
                return;
            }
            }

            RareFactory.ReloadViews(from);
        }
Beispiel #9
0
            public override void Execute(CommandEventArgs e, object obj)
            {
                try
                {
                    Item item = obj as Item;

                    if (!RareFactory.InUse)
                    {
                        if (e.Arguments.Length == 4)
                        {
                            int iRarity = 0;
                            if (int.TryParse(e.Arguments[1], out iRarity) == true && iRarity >= 0 && iRarity <= 10)
                            {
                                DODGroup match;
                                if ((match = FindGroup(e.Arguments[0], iRarity)) != null)
                                {
                                    int iStartIndex = 0;
                                    if (int.TryParse(e.Arguments[2], out iStartIndex) == true && iStartIndex > 0 && iStartIndex <= 255)
                                    {
                                        int iLastIndex = 0;
                                        if (int.TryParse(e.Arguments[3], out iLastIndex) == true && iLastIndex > 0 && iLastIndex <= 255)
                                        {
                                            if (item != null)
                                            {
                                                LogHelper Logger = null;
                                                try
                                                {
                                                    DODInstance di = RareFactory.AddRare(match, item);    // rarity is defined by the group
                                                    di.LastIndex  = (short)iLastIndex;
                                                    di.StartIndex = (short)iStartIndex;
                                                    di.StartDate  = DateTime.MinValue;  // valid now
                                                    di.EndDate    = DateTime.MaxValue;  // valid forever

                                                    // default the name to the name of the item
                                                    if (item.Name != null && item.Name != "")
                                                    {
                                                        di.Name = item.Name;
                                                    }
                                                    else
                                                    {
                                                        di.Name = item.GetType().Name;
                                                    }

                                                    AddResponse("Sucessfully defined new rare '" + di.Name + "'!");
                                                }
                                                catch (Exception ex)
                                                {
                                                    LogHelper.LogException(ex);
                                                    e.Mobile.SendMessage(ex.Message);
                                                }
                                                finally
                                                {
                                                    if (Logger != null)
                                                    {
                                                        Logger.Finish();
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                LogFailure("Only an item may be converted into a rare.");
                                            }
                                        }
                                        else
                                        {
                                            LogFailure("The LastIndex must be a numeric value between 1 and 255 inclusive.");
                                        }
                                    }
                                    else
                                    {
                                        LogFailure("The StartIndex must be a numeric value between 1 and 255 inclusive.");
                                    }
                                }
                                else
                                {
                                    LogFailure(String.Format("Could not find the group \"{0}\" with a rarity of {1}", e.Arguments[0], iRarity));
                                }
                            }
                            else
                            {
                                LogFailure("The rarity must be a numeric value between 0 and 10 inclusive.");
                            }
                        }
                        else
                        {
                            LogFailure("AddRare sGroup iRarity iStartIndex iLastIndex");
                        }
                    }
                    else
                    {
                        LogFailure("Rare Factory is currently being configured by another administrator! Please wait. ");
                    }
                }
                catch (Exception exe)
                {
                    LogHelper.LogException(exe);
                    e.Mobile.SendMessage(exe.Message);
                }
            }
        public override void OnResponse(NetState state, RelayInfo info)
        {
            Mobile from = state.Mobile;

            // Console.WriteLine("Group button {0} pressed", info.ButtonID);

            switch (info.ButtonID)
            {
            case 0:
            {
                return;
            }

            case 1:
            {
                RareFactory.ReloadViews(from);
                from.SendGump(new RFNewGroupGump("", 0));

                /*
                 * from.SendMessage("Enter name for new rare group :");
                 * from.Prompt = new GroupNamePrompt(from);
                 */

                return;
            }

            case 2:
            {
                // Next Page
                if (curPage == numPages)
                {
                    from.SendMessage("You are already viewing the last page of DOD groups.");
                    break;
                }

                curPage++;

                break;
            }

            case 3:
            {
                // Prev Page
                if (curPage == 0)
                {
                    from.SendMessage("You are already viewing the first page of DOD groups.");
                    break;
                }

                curPage--;

                break;
            }

            default:
            {
                // Work out whether we're deleting or selecting and
                // act accordingly

                // 1 - view, 2 - delete etc. (odd = view, even = delete)

                if (info.ButtonID % 2 > 0)
                {
                    // odd, so we're deleting
                    int grpNum = (((info.ButtonID + 1) / 2) - 3);
                    from.SendMessage(string.Format("Are you sure you wish to delete rare group '{0}' and all associated rares? (y/n)", ((DODGroup)RareFactory.DODGroup[grpNum]).Name));
                    from.Prompt = new GrpDelConfirmPrompt(from, (short)grpNum);
                    break;
                }
                else
                {
                    // even, so we're viewing
                    int grpNum = ((info.ButtonID / 2) - 2);
                    RareFactory.ViewingDODGroupIndex = grpNum;
                }

                break;
            }
            }
            RareFactory.ViewingDODGroupPage = curPage;
            RareFactory.ReloadViews(from);
        }
Beispiel #11
0
        public override void OnResponse(NetState state, RelayInfo info)
        {
            Mobile from = state.Mobile;

            switch (info.ButtonID)
            {
            case 0:
            {
                // Close this gump
                return;
            }

            case 1:
            {
                // Raise rarity

                if (m_RarityLevel >= 10)
                {
                    from.SendMessage("Maximum rarity level is 10 (most unique)");
                    break;
                }

                m_RarityLevel++;

                break;
            }

            case 2:
            {
                // Lower rarity

                if (m_RarityLevel == 0)
                {
                    from.SendMessage("Minimum rarity level is 0 (most common)");
                    break;
                }

                m_RarityLevel--;

                break;
            }

            case 3:
            {
                // Make sure they've specified a name :P
                if (m_GroupName == "")
                {
                    from.SendMessage("You must specify a group name to identify this group by!");
                    break;
                }

                // Now make sure that the name doesn't already exist :)
                if (RareFactory.DODGroup.Count > 0)
                {
                    for (int i = 0; i < RareFactory.DODGroup.Count; i++)
                    {
                        DODGroup dg = (DODGroup)RareFactory.DODGroup[i];
                        if (dg.Name == m_GroupName)
                        {
                            // Don't bother with the rest of this code - they messed up!
                            from.SendMessage("DOD Group names must be unique - the name you have chosen already exists! Please try again.");
                            break;
                        }
                    }
                }

                // Accept + create
                RareFactory.DODGroup.Add(new DODGroup(m_GroupName, m_RarityLevel));

                // Update their display
                RareFactory.ReloadViews(from);

                return;
            }

            case 4:
            {
                // Cancel the whole thing
                return;
            }

            case 5:
            {
                // Set the group name
                from.SendMessage("Enter the name you wish to use to represent this group of rares :");
                from.Prompt = new GroupNamePrompt(from, this);
                return;
            }

            default:
            {
                break;
            }
            }

            Refresh(from);
        }
        // spawners can now spawn special lootpacks with per item drop rates.
        public ArrayList CreateItem(Item lootPack)
        {
            LogHelper Logger = null;
            ArrayList items  = new ArrayList();

            try
            {
                if (lootPack == null || lootPack.Deleted == true)
                {
                    return(null);
                }

                Logger = new LogHelper("LootPack.log", false, true);

                if (lootPack is Container)
                {
                    if ((lootPack as Container).Factory)
                    {                           // only one item from factory has a chance at a drop
                        if ((lootPack as Container).DropRate >= Utility.RandomDouble())
                        {
                            if ((lootPack as Container).Items.Count > 0)
                            {
                                Item item = (lootPack as Container).Items[Utility.Random((lootPack as Container).Items.Count)] as Item;
                                Item temp = RareFactory.DupeItem(item);
                                if (temp != null)
                                {
                                    Logger.Log(LogType.Item, this, string.Format("Dropped lootpack item {0}", temp));
                                    temp.DropRate = 1.0;                                        // should not be set, but lets be safe
                                    items.Add(temp);
                                    return(items);
                                }
                            }
                        }
                    }
                    else
                    {
                        // each item from a container has a chance at a drop
                        foreach (Item item in lootPack.Items)
                        {                               // drop chance
                            if (item.DropRate >= Utility.RandomDouble())
                            {
                                Item temp = RareFactory.DupeItem(item);
                                if (temp != null)
                                {
                                    Logger.Log(LogType.Item, this, string.Format("Dropped lootpack item {0}", temp));
                                    temp.DropRate = 1.0;                                        // all this does is save the sizeof(double) for each item generated
                                    items.Add(temp);
                                }
                            }
                        }

                        return(items);
                    }
                }
                else
                {
                    // drop chance
                    if (lootPack.DropRate >= Utility.RandomDouble())
                    {
                        Item temp = RareFactory.DupeItem(RareFactory.DupeItem(lootPack));
                        if (temp != null)
                        {
                            Logger.Log(LogType.Item, this, string.Format("Dropped lootpack item {0}", temp));
                            temp.DropRate = 1.0;                                // all this does is save the sizeof(double) for each item generated
                            items.Add(temp);
                            return(items);
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                LogHelper.LogException(exc);
            }
            finally
            {
                if (Logger != null)
                {
                    Logger.Finish();
                }
            }

            return(items);
        }