public override void OnResponse(NetState state, RelayInfo info) { Mobile from = state.Mobile; switch (info.ButtonID) { case 0: return; case 999: from.SendGump(new CommodityInventoryGump(m_Broker, m_Index, m_Buy, m_Page, 0)); return; case 1: from.SendGump(new CommodityInventoryGump(m_Broker, m_Index, m_Buy, m_Page, 1150654)); return; case 400: from.SendGump(new CommodityInventoryGump(m_Broker, -1, m_Buy, m_Page - 1, 0)); return; case 401: from.SendGump(new CommodityInventoryGump(m_Broker, -1, m_Buy, m_Page + 1, 0)); return; case 500: // TRADE { for (int i = 0; i < m_Entries.Count; i++) { int buyid = 2 + i; int sellid = 102 + i; if (info.IsSwitched(buyid)) { if (m_Broker.CommodityEntries.Contains(m_Entries[i])) { m_Buy = true; m_Index = i; } } else if (info.IsSwitched(sellid)) { if (m_Broker.CommodityEntries.Contains(m_Entries[i])) { m_Buy = false; m_Index = i; } } } if (m_Index >= 0 && m_Index < m_Entries.Count) { CommodityBrokerEntry entry = m_Entries[m_Index]; if (!m_Broker.CommodityEntries.Contains(entry)) { from.SendGump(new CommodityInventoryGump(m_Broker, m_Index, m_Buy, m_Page, 1150244)); // Transaction no longer available return; } int amount = 0; TextRelay relay = info.TextEntries[0]; try { amount = Convert.ToInt32(relay.Text); } catch (Exception e) { Server.Diagnostics.ExceptionLogging.LogException(e); } if (amount > 0) { if (m_Buy && Banker.GetBalance(from) < entry.SellPricePer * amount) { /* You do not have the funds needed to make this trade available in your bank box. Brokers are only able to transfer funds from your bank box. * Please deposit the necessary funds into your bank box and try again. */ from.SendGump(new CommodityInventoryGump(m_Broker, m_Index, m_Buy, m_Page, 1150252)); return; } else if (!m_Buy && !m_Broker.SellCommodityControl(from, entry, amount)) { /* You do not have the requested amount of that commodity (either in item or deed form) in your backpack to trade. * Note that commodities cannot be traded from your bank box. */ from.SendGump(new CommodityInventoryGump(m_Broker, m_Index, m_Buy, m_Page, 1150667)); return; } else if (m_Buy && entry.PlayerCanBuy(amount)) { from.SendGump(new ConfirmBuyCommodityGump(m_Broker, amount, entry, true, new CommodityInventoryGump(m_Broker, m_Index, m_Buy, m_Page, 0))); return; } else if (!m_Buy && entry.PlayerCanSell(amount)) { from.SendGump(new ConfirmBuyCommodityGump(m_Broker, amount, entry, false, new CommodityInventoryGump(m_Broker, m_Index, m_Buy, m_Page, 0))); return; } else { from.SendGump(new CommodityInventoryGump(m_Broker, m_Index, m_Buy, m_Page, 1150215)); // You have entered an invalid value, or a non-numeric value. Please try again. return; } } else { from.SendGump(new CommodityInventoryGump(m_Broker, m_Index, m_Buy, m_Page, 1150215)); // You have entered an invalid value, or a non-numeric value. Please try again. return; } } else { from.SendGump(new CommodityInventoryGump(m_Broker, m_Index, m_Buy, m_Page, 1150642)); // You did not select a commodity. return; } } } }
public override void OnResponse(NetState state, RelayInfo info) { Mobile from = state.Mobile; switch (info.ButtonID) { case 0: return; case 1: from.SendGump(new CommodityInventoryGump(m_Broker, m_Index, m_Buy, m_Page)); from.SendGump(new BazaarInformationGump(1150655, 1150654)); return; case 400: from.SendGump(new CommodityInventoryGump(m_Broker, -1, m_Buy, m_Page - 1)); return; case 401: from.SendGump(new CommodityInventoryGump(m_Broker, -1, m_Buy, m_Page + 1)); return; case 500: // TRADE { if (m_Index >= 0 && m_Index < m_Entries.Count) { CommodityBrokerEntry entry = m_Entries[m_Index]; if (!m_Broker.CommodityEntries.Contains(entry)) { from.SendLocalizedMessage(1150244); // Transaction no longer available break; } int amount = 0; TextRelay relay = info.TextEntries[0]; try { amount = Convert.ToInt32(relay.Text); } catch {} if (amount > 0) { if (m_Buy && entry.PlayerCanBuy(amount)) { from.SendGump(new ConfirmBuyCommodityGump(m_Broker, amount, entry, true)); } else if (!m_Buy && entry.PlayerCanSell(amount)) { from.SendGump(new ConfirmBuyCommodityGump(m_Broker, amount, entry, false)); } else { from.SendLocalizedMessage(1150215); // You have entered an invalid value, or a non-numeric value. Please try again. } return; } else { from.SendLocalizedMessage(1150215); // You have entered an invalid value, or a non-numeric value. Please try again. } } else { from.SendLocalizedMessage(1150642); // You did not select a commodity. } } break; default: { if (info.ButtonID < 102) { int id = info.ButtonID - 2; if (id >= 0 && id < m_Entries.Count && m_Broker.CommodityEntries.Contains(m_Entries[id])) { m_Buy = true; m_Index = id; } else { from.SendLocalizedMessage(1150244); // Transaction no longer available } } else { int id = info.ButtonID - 102; if (id >= 0 && id < m_Entries.Count && m_Broker.CommodityEntries.Contains(m_Entries[id])) { m_Buy = false; m_Index = id; } else { from.SendLocalizedMessage(1150244); // Transaction no longer available } } } break; } from.SendGump(new CommodityInventoryGump(m_Broker, m_Index, m_Buy, 0)); }
public CommodityInventoryGump(CommodityBroker broker, int index, bool buy, int page, int cliloc) : base(655, 520) { m_Broker = broker; m_Entries = broker.CommodityEntries; m_Buy = buy; m_Page = page; m_Index = index; AddHtmlLocalized(10, 10, 640, 18, 1114513, "#1150636", RedColor16, false, false); // Commodity Broker if (m_Broker.Plot.ShopName != null && m_Broker.Plot.ShopName.Length > 0) { AddHtml(10, 37, 640, 18, Color(FormatStallName(m_Broker.Plot.ShopName), BlueColor), false, false); } else { AddHtmlLocalized(10, 37, 640, 18, 1114513, "#1150314", BlueColor16, false, false); // This Shop Has No Name } AddHtmlLocalized(10, 55, 310, 18, 1114514, "#1150313", BlueColor16, false, false); // Proprietor: AddHtml(330, 55, 320, 18, Color(String.Format("{0}", broker.Name), BlueColor), false, false); if (cliloc != 0) { if (cliloc == 1150654) { /* This broker trades in commodities. Commodity brokers can buy and sell most commodities, either in item or deed form. * The menu shows all commodities this broker will deal in.<BR><BR>The center column lists the commodities by name. * The columns on the left indicate how much of the commodity the broker has available for purchase, and the price per unit. * The right-hand columns indicate how much of the commodity the broker is willing to buy from you and the price it will pay per unit. * <BR><BR>If you wish to buy that commodity, click the button to the left of it to select it, then enter the quantity you wish to buy in the QUANTITY field below. * If you wish to sell a commodity to the broker, click the button to the right of it and enter the quantity you wish to sell below. Finally, click the "TRADE" button. * You will be presented with a confirmation window that will show the item being traded, the quantity, and how much gold will change hands.<BR><BR>If a broker lists a price but shows 0 quantity available, * the broker may be out of stock (unable to sell to you) or may have reached its purchasing limit (unable to buy from you). All gold transactions are between your bank box and the commodity broker. * Gold or bank checks in your backpack cannot be used for these trades. Commodities are traded between your backpack and the broker, and commodity items/deeds in your bank box cannot be used for these trades. */ AddHtmlLocalized(10, 127, 640, 354, 1150654, OrangeColor16, true, true); } else { AddHtmlLocalized(10, 127, 640, 354, 1114513, String.Format("#{0}", cliloc), OrangeColor16, false, false); } AddButton(10, 490, 0xFAE, 0xFAF, 999, GumpButtonType.Reply, 0); AddHtmlLocalized(50, 490, 210, 20, 1149777, BlueColor16, false, false); // MAIN MENU } else { AddButton(190, 91, 4005, 4007, 1, GumpButtonType.Reply, 0); AddHtmlLocalized(230, 91, 420, 22, 1150392, OrangeColor16, false, false); // INFORMATION AddHtmlLocalized(10, 124, 54, 20, 1150656, OrangeColor16, false, false); // BUY AddHtmlLocalized(70, 124, 54, 20, 1150659, OrangeColor16, false, false); // PRICE AddHtmlLocalized(130, 124, 109, 20, 1150658, OrangeColor16, false, false); // LIMIT AddHtmlLocalized(245, 124, 164, 20, 1114513, "#1150655", OrangeColor16, false, false); // COMMODITY AddHtmlLocalized(415, 124, 54, 20, 1114514, "#1150659", OrangeColor16, false, false); // PRICE AddHtmlLocalized(475, 124, 109, 20, 1114514, "#1150658", OrangeColor16, false, false); // LIMIT AddHtmlLocalized(590, 124, 54, 20, 1114514, "#1150657", OrangeColor16, false, false); // SELL if (m_Entries.Count != 0) { int y = 153; int perPage = 10; if (index > -1) { m_Page = index <= 0 ? 0 : index / perPage; } int start = page * perPage; int count = 0; for (int i = start; i < m_Entries.Count && /*index < perPage*/ count <= perPage; i++) { CommodityBrokerEntry entry = m_Entries[i]; int stock = entry.Stock; int buyLimit = entry.ActualSellLimit; int sellLimit = entry.ActualBuyLimit; // Sell to player if (entry.SellPricePer > 0) { AddHtml(70, y, 54, 20, Color(FormatAmt(entry.SellPricePer), OrangeColor), false, false); } else { AddHtmlLocalized(70, y, 54, 20, 1150397, OrangeColor16, false, false); // N/A } if (entry.SellPricePer > 0 && entry.SellLimit > 0) { AddHtml(130, y, 109, 20, Color(FormatAmt(buyLimit), OrangeColor), false, false); } // what we're selling/buying AddHtmlLocalized(200, y, 164, 20, 1114514, String.Format("#{0}", entry.Label), OrangeColor16, false, false); // <DIV ALIGN=RIGHT>~1_TOKEN~</DIV> AddTooltip(entry.Label); // buy from player if (entry.BuyPricePer > 0) { AddHtml(415, y, 54, 20, Color(AlignRight(FormatAmt(entry.BuyPricePer)), OrangeColor), false, false); } else { AddHtmlLocalized(415, y, 54, 20, 1150397, OrangeColor16, false, false); // N/A } if (entry.BuyPricePer > 0 && entry.BuyLimit > 0) { AddHtml(475, y, 109, 20, (Color(AlignRight(FormatAmt(sellLimit)), OrangeColor)), false, false); } //Buttons if (entry.PlayerCanBuy(0)) { AddRadio(10, y, 0xFA5, 0xFA6, false, 2 + i); } if (entry.PlayerCanSell(0)) { AddRadio(590, y, 0xFAE, 0xFAF, false, 102 + i); } y += 20; count++; } if (m_Page > 0) // back { AddButton(60, 362, 0xFAE, 0xFAF, 400, GumpButtonType.Reply, 0); AddHtmlLocalized(100, 362, 230, 40, 1044044, OrangeColor16, false, false); // PREV PAGE } if (m_Entries.Count - start > perPage) // forward { AddButton(570, 362, 0xFA5, 0xFA6, 401, GumpButtonType.Reply, 0); AddHtmlLocalized(330, 362, 230, 40, 1114514, "#1044045", OrangeColor16, false, false); // NEXT PAGE } AddHtmlLocalized(10, 421, 210, 22, 1114514, "#1150662", BlueColor16, false, false); // QUANTITY AddBackground(230, 421, 420, 22, 0x2486); AddTextEntry(232, 423, 416, 18, LabelHueBlue, 0, ""); AddButton(190, 445, 4005, 4007, 500, GumpButtonType.Reply, 0); AddHtmlLocalized(230, 445, 420, 22, 1077761, OrangeColor16, false, false); // TRADE } else { AddHtmlLocalized(10, 153, 640, 20, 1114513, "#1150638", OrangeColor16, false, false); // There are no commodities in this broker's inventory. } } }
public CommodityInventoryGump(CommodityBroker broker, int index, bool buy, int page) : base(655, 520) { m_Broker = broker; m_Entries = broker.CommodityEntries; m_Buy = buy; m_Page = page; m_Index = index; AddHtmlLocalized(205, 10, 200, 18, 1150636, RedColor16, false, false); // Commodity Broker if (m_Broker.Plot.ShopName != null && m_Broker.Plot.ShopName.Length > 0) { AddHtml(173, 40, 173, 18, Color(FormatStallName(m_Broker.Plot.ShopName), BlueColor), false, false); // "~1_NAME~" } else { AddHtmlLocalized(180, 40, 200, 18, 1150314, BlueColor16, false, false); // This Shop Has No Name } AddHtml(173, 65, 173, 18, Color(FormatBrokerName(String.Format("Proprietor: {0}", broker.Name)), BlueColor), false, false); AddButton(150, 100, 4005, 4007, 1, GumpButtonType.Reply, 0); AddHtmlLocalized(190, 100, 150, 18, 1150392, OrangeColor16, false, false); // INFORMATION AddHtmlLocalized(10, 125, 75, 18, 1150656, OrangeColor16, false, false); // BUY AddHtmlLocalized(60, 125, 75, 18, 1150659, OrangeColor16, false, false); // PRICE AddHtmlLocalized(120, 125, 75, 18, 1150658, OrangeColor16, false, false); // LIMIT AddHtmlLocalized(330, 125, 75, 18, 1150655, OrangeColor16, false, false); // COMMODITY AddHtmlLocalized(490, 125, 75, 18, 1150659, OrangeColor16, false, false); // PRICE AddHtmlLocalized(550, 125, 75, 18, 1150658, OrangeColor16, false, false); // LIMIT AddHtmlLocalized(610, 125, 75, 18, 1150657, OrangeColor16, false, false); // SELL int y = 150; int perPage = 10; if (index > -1) { m_Page = index <= 0 ? 0 : index / perPage; } int start = page * perPage; int count = 0; for (int i = start; i < m_Entries.Count && /*index < perPage*/ count <= perPage; i++) { CommodityBrokerEntry entry = m_Entries[i]; int buyCol = index == i && buy ? YellowColor : OrangeColor; int sellCol = index == i && !buy ? YellowColor : OrangeColor; int stock = entry.Stock; int buyLimit = entry.ActualSellLimit; int sellLimit = entry.ActualBuyLimit; string buyAmount = entry.SellPricePer > 0 ? FormatAmt(entry.SellPricePer) : "N/A"; string sellAmount = entry.BuyPricePer > 0 ? FormatAmt(entry.BuyPricePer) : "N/A"; // Sell to player AddHtml(60, y, 60, 18, Color(buyAmount, buyCol), false, false); if (entry.SellPricePer > 0 && entry.SellLimit > 0) { AddHtml(120, y, 150, 18, Color(FormatAmt(buyLimit), buyCol), false, false); } // what we're selling/buying AddHtmlLocalized(200, y, 215, 18, 1114514, String.Format("#{0}", entry.Label), OrangeColor16, false, false); // <DIV ALIGN=RIGHT>~1_TOKEN~</DIV> // buy from player AddHtml(490, y, 75, 18, AlignRight(Color(sellAmount, sellCol)), false, false); if (entry.BuyPricePer > 0 && entry.BuyLimit > 0) { AddHtml(550, y, 150, 18, AlignRight(Color(FormatAmt(sellLimit), sellCol)), false, false); } //Buttons if (entry.PlayerCanBuy(0)) { AddButton(10, y, 4005, 4007, 2 + i, GumpButtonType.Reply, 0); } if (entry.PlayerCanSell(0)) { AddButton(610, y, 4014, 4016, 102 + i, GumpButtonType.Reply, 0); } y += 22; count++; } if (m_Page > 0) // back { AddHtmlLocalized(100, 410, 150, 18, 1044044, OrangeColor16, false, false); AddButton(60, 410, 4014, 4016, 400, GumpButtonType.Reply, 0); } if (m_Entries.Count - start > perPage) // forward { AddHtmlLocalized(340, 410, 150, 18, 1044045, OrangeColor16, false, false); AddButton(425, 410, 4005, 4007, 401, GumpButtonType.Reply, 0); } AddHtmlLocalized(240, 445, 150, 18, 1150662, BlueColor16, false, false); // QUANTITY AddBackground(315, 445, 325, 22, 9350); AddTextEntry(316, 445, 300, 20, 0, 0, ""); AddButton(275, 470, 4005, 4007, 500, GumpButtonType.Reply, 0); AddHtmlLocalized(315, 470, 100, 18, 1077761, OrangeColor16, false, false); // TRADE }