Beispiel #1
0
		private void _buySellItem(ShopItem item)
		{
			if (m_state != ShopState.Buying && m_state != ShopState.Selling)
				return;
			bool isBuying = m_state == ShopState.Buying;

			InventoryItem ii = World.Instance.MainPlayer.ActiveCharacter.Inventory.Find(x => (isBuying ? x.id == 1 : x.id == item.ID));
			ItemRecord rec = World.Instance.EIF.GetItemRecordByID(item.ID);
			if (isBuying)
			{
				if (!EOGame.Instance.Hud.InventoryFits((short)item.ID))
				{
					EOMessageBox.Show(World.GetString(DATCONST2.DIALOG_TRANSFER_NOT_ENOUGH_SPACE),
						World.GetString(DATCONST2.STATUS_LABEL_TYPE_WARNING),
						XNADialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader);
					return;
				}

				if (rec.Weight + World.Instance.MainPlayer.ActiveCharacter.Weight >
					World.Instance.MainPlayer.ActiveCharacter.MaxWeight)
				{
					EOMessageBox.Show(World.GetString(DATCONST2.DIALOG_TRANSFER_NOT_ENOUGH_WEIGHT),
						World.GetString(DATCONST2.STATUS_LABEL_TYPE_WARNING),
						XNADialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader);
					return;
				}

				if (ii.amount < item.Buy)
				{
					EOMessageBox.Show(DATCONST1.WARNING_YOU_HAVE_NOT_ENOUGH, " gold.", XNADialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader);
					return;
				}
			}
			else if (ii.amount == 0)
				return; //can't sell if amount of item is 0

			//special case: no need for prompting if selling an item with count == 1 in inventory
			if (!isBuying && ii.amount == 1)
			{
				string _message = string.Format("{0} 1 {1} {2} {3} gold?",
					World.GetString(DATCONST2.DIALOG_WORD_SELL),
					rec.Name,
					World.GetString(DATCONST2.DIALOG_WORD_FOR),
					item.Sell);
				EOMessageBox.Show(_message, World.GetString(DATCONST2.DIALOG_SHOP_SELL_ITEMS), XNADialogButtons.OkCancel,
					EOMessageBoxStyle.SmallDialogSmallHeader, (oo, ee) =>
					{
						if (ee.Result == XNADialogResult.OK && !m_api.SellItem((short)item.ID, 1))
						{
							EOGame.Instance.DoShowLostConnectionDialogAndReturnToMainMenu();
						}
					});
			}
			else
			{
				ItemTransferDialog dlg = new ItemTransferDialog(rec.Name, ItemTransferDialog.TransferType.ShopTransfer,
					isBuying ? item.MaxBuy : ii.amount, isBuying ? DATCONST2.DIALOG_TRANSFER_BUY : DATCONST2.DIALOG_TRANSFER_SELL);
				dlg.DialogClosing += (o, e) =>
				{
					if (e.Result == XNADialogResult.OK)
					{
						string _message = string.Format("{0} {1} {2} {3} {4} gold?",
							World.GetString(isBuying ? DATCONST2.DIALOG_WORD_BUY : DATCONST2.DIALOG_WORD_SELL),
							dlg.SelectedAmount, rec.Name,
							World.GetString(DATCONST2.DIALOG_WORD_FOR),
							(isBuying ? item.Buy : item.Sell) * dlg.SelectedAmount);

						EOMessageBox.Show(_message,
							World.GetString(isBuying ? DATCONST2.DIALOG_SHOP_BUY_ITEMS : DATCONST2.DIALOG_SHOP_SELL_ITEMS),
							XNADialogButtons.OkCancel, EOMessageBoxStyle.SmallDialogSmallHeader, (oo, ee) =>
							{
								if (ee.Result == XNADialogResult.OK)
								{
									//only actually do the buy/sell if the user then clicks "OK" in the second prompt
									if (isBuying && !m_api.BuyItem((short)item.ID, dlg.SelectedAmount) ||
										!isBuying && !m_api.SellItem((short)item.ID, dlg.SelectedAmount))
									{
										EOGame.Instance.DoShowLostConnectionDialogAndReturnToMainMenu();
									}
								}
							});
					}
				};
			}
		}
Beispiel #2
0
        /// <summary>
        /// Handles SHOP_OPEN from server, contains shop data for a shop dialog
        /// </summary>
        private void _handleShopOpen(Packet pkt)
        {
            if (OnShopOpen == null) return;

            int shopKeeperID = pkt.GetShort();
            string shopName = pkt.GetBreakString();

            List<ShopItem> tradeItems = new List<ShopItem>();
            while (pkt.PeekByte() != 255)
            {
                ShopItem nextItem = new ShopItem(pkt.GetShort(), pkt.GetThree(), pkt.GetThree(), pkt.GetChar());
                tradeItems.Add(nextItem);
            }
            pkt.GetByte();

            List<CraftItem> craftItems = new List<CraftItem>();
            while (pkt.PeekByte() != 255)
            {
                int ID = pkt.GetShort();
                List<Tuple<int, int>> ingreds = new List<Tuple<int, int>>();

                for (int i = 0; i < 4; ++i)
                {
                    ingreds.Add(new Tuple<int, int>(pkt.GetShort(), pkt.GetChar()));
                }
                craftItems.Add(new CraftItem(ID, ingreds));
            }
            pkt.GetByte();

            OnShopOpen(shopKeeperID, shopName, tradeItems, craftItems);
        }