예제 #1
0
        public override void OnResponse(NetState sender, RelayInfo info)
        {
            if (info.ButtonID == 2)
            {
                PlayerVendor pv = m_Book.RootParent as PlayerVendor;

                if (pv != null)
                {
                    int price = 0;

                    VendorItem vi = pv.GetVendorItem(m_Book);

                    if (vi != null && !vi.IsForSale)
                    {
                        price = m_Recipe.Price;
                    }

                    if (price != m_Price)
                    {
                        pv.SayTo(m_From, 1150158); // The price of the selected item has been changed from the value you confirmed. You must select and confirm the purchase again at the new price in order to buy it.
                        m_Book.Using = false;
                    }
                    else if (m_Recipe.Amount == 0 || price == 0)
                    {
                        pv.SayTo(m_From, 1158821); // The recipe selected is not available.
                        m_Book.Using = false;
                    }
                    else
                    {
                        Item item = new RecipeScroll(m_Recipe.RecipeID);

                        pv.Say(m_From.Name);

                        Container pack = m_From.Backpack;

                        if ((pack != null && pack.ConsumeTotal(typeof(Gold), price)) || Banker.Withdraw(m_From, price))
                        {
                            m_Book.Recipes.ForEach(x =>
                            {
                                if (x.RecipeID == m_Recipe.RecipeID)
                                {
                                    x.Amount = x.Amount - 1;
                                }
                            });

                            m_Book.InvalidateProperties();

                            pv.HoldGold += price;

                            if (m_From.AddToBackpack(item))
                            {
                                m_From.SendLocalizedMessage(1158820); // The recipe has been placed in your backpack.
                            }
                            else
                            {
                                pv.SayTo(m_From, 503204); // You do not have room in your backpack for this.
                            }
                            m_From.SendGump(new RecipeBookGump(m_From, m_Book));
                        }
                        else
                        {
                            pv.SayTo(m_From, 503205); // You cannot afford this item.
                            item.Delete();
                            m_Book.Using = false;
                        }
                    }
                }
                else
                {
                    m_Book.Using = false;

                    if (pv == null)
                    {
                        m_From.SendLocalizedMessage(1158821); // The recipe selected is not available.
                    }
                    else
                    {
                        pv.SayTo(m_From, 1158821); // The recipe selected is not available.
                    }
                }
            }
            else
            {
                m_Book.Using = false;
                m_From.SendLocalizedMessage(503207); // Cancelled purchase.
            }
        }
예제 #2
0
        public override void OnResponse(NetState sender, RelayInfo info)
        {
            Mobile from = sender.Mobile;

            int index = info.ButtonID;

            switch (index)
            {
            case 0: { m_Book.Using = false; break; }

            case 1:
            {
                from.SendGump(new RecipeScrollFilterGump(from, m_Book));
                break;
            }

            case 2:
            {
                if (m_Page > 0)
                {
                    from.SendGump(new RecipeBookGump(from, m_Book, m_Page - 1, m_List));
                }

                return;
            }

            case 3:
            {
                if (GetIndexForPage(m_Page + 1) < m_List.Count)
                {
                    from.SendGump(new RecipeBookGump(from, m_Book, m_Page + 1, m_List));
                }

                break;
            }

            default:
            {
                bool canDrop  = m_Book.IsChildOf(from.Backpack);
                bool canPrice = canDrop || (m_Book.RootParent is PlayerVendor);

                index -= 4;

                int type = index % 2;
                index /= 2;

                if (index < 0 || index >= m_List.Count)
                {
                    break;
                }

                var recipe = m_List[index];

                if (type == 0)
                {
                    if (!m_Book.CheckAccessible(from, m_Book))
                    {
                        m_Book.SendLocalizedMessageTo(from, 1061637);         // You are not allowed to access this.
                        m_Book.Using = false;
                        break;
                    }

                    if (m_Book.IsChildOf(from.Backpack) || m_Book.IsLockedDown)
                    {
                        if (recipe.Amount == 0)
                        {
                            from.SendLocalizedMessage(1158821);         // The recipe selected is not available.
                            m_Book.Using = false;
                            break;
                        }

                        Item item = new RecipeScroll(recipe.RecipeID);

                        if (from.AddToBackpack(item))
                        {
                            m_Book.Recipes.ForEach(x =>
                                {
                                    if (x.RecipeID == recipe.RecipeID)
                                    {
                                        x.Amount = x.Amount - 1;
                                    }
                                });

                            m_Book.InvalidateProperties();

                            from.SendLocalizedMessage(1158820);         // The recipe has been placed in your backpack.

                            from.SendGump(new RecipeBookGump(from, m_Book, m_Page, null));
                        }
                        else
                        {
                            m_Book.Using = false;
                            item.Delete();
                            from.SendLocalizedMessage(1158819);         // There is not enough room in your backpack for the recipe.
                        }
                    }
                    else
                    {
                        m_Book.Using = false;
                    }
                }
                else
                {
                    if (m_Book.IsChildOf(from.Backpack))
                    {
                        from.Prompt = new SetPricePrompt(m_Book, recipe, m_Page, m_List);
                        from.SendLocalizedMessage(1062383);         // Type in a price for the deed:
                        m_Book.Using = false;
                    }
                    else if (m_Book.RootParent is PlayerVendor)
                    {
                        if (recipe.Amount > 0)
                        {
                            from.SendGump(new RecipeScrollBuyGump(from, m_Book, recipe, recipe.Price));
                        }
                        else
                        {
                            m_Book.Using = false;
                        }
                    }
                }

                break;
            }
            }
        }
예제 #3
0
        public override void OnResponse(NetState sender, RelayInfo info)
        {
            int index = info.ButtonID;

            switch (index)
            {
            case 0: { break; }

            case 1:
            {
                m_From.SendGump(new RecipeScrollFilterGump(m_From, m_Book));
                break;
            }

            case 2:
            {
                if (m_Page > 0)
                {
                    m_From.SendGump(new RecipeBookGump(m_From, m_Book, m_Page - 1, m_List));
                }

                return;
            }

            case 3:
            {
                if (GetIndexForPage(m_Page + 1) < m_List.Count)
                {
                    m_From.SendGump(new RecipeBookGump(m_From, m_Book, m_Page + 1, m_List));
                }

                break;
            }

            default:
            {
                bool canDrop  = m_Book.IsChildOf(m_From.Backpack);
                bool canPrice = canDrop || (m_Book.RootParent is PlayerVendor);

                index -= 4;

                int type = index % 2;
                index /= 2;

                if (index < 0 || index >= m_List.Count)
                {
                    break;
                }

                var recipe = m_List[index];

                if (type == 0)
                {
                    if (m_Book.IsChildOf(m_From.Backpack))
                    {
                        if (recipe.Amount == 0)
                        {
                            m_From.SendLocalizedMessage(1158821);         // The recipe selected is not available.
                            break;
                        }

                        Item item = new RecipeScroll(recipe.RecipeID);

                        if (m_From.AddToBackpack(item))
                        {
                            m_Book.Recipes.ForEach(x =>
                                {
                                    if (x.RecipeID == recipe.RecipeID)
                                    {
                                        x.Amount = x.Amount - 1;
                                    }
                                });

                            m_Book.InvalidateProperties();

                            m_From.SendLocalizedMessage(1158820);         // The recipe has been placed in your backpack.

                            m_From.SendGump(new RecipeBookGump(m_From, m_Book, m_Page, null));
                        }
                        else
                        {
                            item.Delete();
                            m_From.SendLocalizedMessage(1158819);         // There is not enough room in your backpack for the recipe.
                        }
                    }
                }
                else
                {
                    if (m_Book.IsChildOf(m_From.Backpack))
                    {
                        m_From.Prompt = new SetPricePrompt(m_Book, recipe, m_Page, m_List);
                        m_From.SendLocalizedMessage(1062383);         // Type in a price for the deed:
                    }
                    else if (m_Book.RootParent is PlayerVendor)
                    {
                        PlayerVendor pv = (PlayerVendor)m_Book.RootParent;

                        VendorItem vi = pv.GetVendorItem(m_Book);

                        int price = 0;

                        if (vi != null && !vi.IsForSale)
                        {
                            price = recipe.Price;
                        }

                        if (price == 0)
                        {
                            m_From.SendLocalizedMessage(1062382);
                        }
                        else
                        {
                            m_From.SendGump(new RecipeScrollBuyGump(m_From, m_Book, recipe, price));
                        }
                    }
                }

                break;
            }
            }
        }