private void OnClick_BuyAll(object sender, RoutedEventArgs e) { GroupedInventoryItem groupedInventoryItem = ((FrameworkElement)sender).DataContext as GroupedInventoryItem; if (groupedInventoryItem != null) { if (Session.CurrentPlayer.Gold >= (groupedInventoryItem.Item.Price * groupedInventoryItem.Quantity)) { Session.CurrentPlayer.SpendGold(groupedInventoryItem.Item.Price * groupedInventoryItem.Quantity); int quantita = groupedInventoryItem.Quantity; while (1 < groupedInventoryItem.Quantity) { Session.CurrentTrader.RemoveItemFromInventory(groupedInventoryItem.Item); } Session.CurrentTrader.RemoveItemFromInventory(groupedInventoryItem.Item); if (groupedInventoryItem.Item.Category == GameItem.ItemCategory.Spell) { Session.CurrentPlayer.AddItemToInventory(SpellFactory.CreateSpell(groupedInventoryItem.Item.ItemTypeID)); } else { for (int i = 0; i < quantita; i++) { Session.CurrentPlayer.AddItemToInventory(groupedInventoryItem.Item); } } } else { MessageBox.Show("Nemáš dost zlatých."); } } }
private void OnClick_Sell(object sender, RoutedEventArgs e) { GroupedInventoryItem groupedInventoryItem = ((FrameworkElement)sender).DataContext as GroupedInventoryItem; if (groupedInventoryItem != null) { Sell(groupedInventoryItem); } }
private void OnClick_Sell(object sender, RoutedEventArgs e) { GroupedInventoryItem groupedInventoryItem = ((FrameworkElement)sender).DataContext as GroupedInventoryItem; if (groupedInventoryItem != null) { Session.CurrentPlayer.ReceiveGold(groupedInventoryItem.Item.Price); Session.CurrentTrader.AddItemToInventory(groupedInventoryItem.Item); Session.CurrentPlayer.RemoveItemFromInventory(groupedInventoryItem.Item); } }
private void OnClick_Sell(object sender, RoutedEventArgs e) { GroupedInventoryItem groupedInventoryItem = ((FrameworkElement)sender).DataContext as GroupedInventoryItem; //gets the item that sent the click event.. in this case the row in the datagrid click by the player if (groupedInventoryItem != null) { Session.CurrentPlayer.ReceiveGold(groupedInventoryItem.Item.Price); Session.CurrentTrader.AddItemToInventory(groupedInventoryItem.Item); Session.CurrentPlayer.RemoveItemFromInventory(groupedInventoryItem.Item); } }
public void OnClick_Sell(object sender, RoutedEventArgs e) { // 获取当前需要出售的物品 // get the item that sent the click event // (the row in the datagrid where the user clicked the buy or sell button) // and cast it as a GameItem object. GroupedInventoryItem groupInventoryItem = ((FrameworkElement)sender).DataContext as GroupedInventoryItem; if (groupInventoryItem != null) { session.CurrentPlayer.ReceiveGold(groupInventoryItem.Item.Price); session.CurrentTrader.AddItemToInventory(groupInventoryItem.Item); session.CurrentPlayer.RemoveItemFromInventory(groupInventoryItem.Item); } }
public void OnClick_Buy(object sender, RoutedEventArgs e) { GroupedInventoryItem groupedItem = ((FrameworkElement)sender).DataContext as GroupedInventoryItem; if (Session.CurrentPlayer.Gold < groupedItem.Item.Price) { MessageBox.Show("You do not have enough gold!"); return; } if (groupedItem != null) { Session.CurrentPlayer.AddItemToInventory(groupedItem.Item); Session.CurrentPlayer.Gold -= groupedItem.Item.Price; Session.CurrentTrader.RemoveItemFromInventory(groupedItem.Item); } }
private void OnClick_Sell(object sender, RoutedEventArgs e) { //Figure out what row the button was on. //sender=what sent the event (the button). The button is part of a row so get its data context //and convert it to a GameItem (as each row should be a GameItem). GroupedInventoryItem groupedInventoryItem = ((FrameworkElement)sender).DataContext as GroupedInventoryItem; //If we were able to convert the raiser of the event into a GameItem if (groupedInventoryItem != null) { Session.CurrentPlayer.ReceiveGold(groupedInventoryItem.Item.Price); Session.CurrentTrader.AddItemToInventory(groupedInventoryItem.Item); Session.CurrentPlayer.RemoveItemFromInventory(groupedInventoryItem.Item); } }
// private void OnClick_Sell(object sender, RoutedEventArgs e) { //Gets the row (item) from trade screen that sent the click to sell, which is determined by the framework element sender.data context //converts it to game item GroupedInventoryItem groupedInventoryItem = ((FrameworkElement)sender).DataContext as GroupedInventoryItem; //make sure its not null to prevent problems if (groupedInventoryItem != null) { //our gold property has an event handler that will notify of changes already so need to need to worry //methods set up already to handle the addition and removal from inventory in trader and player classes Session.CurrentPlayer.ReceiveGold(groupedInventoryItem.Item.Price); Session.CurrentTrader.AddItemToInventory(groupedInventoryItem.Item); Session.CurrentPlayer.RemoveItemFromInventory(groupedInventoryItem.Item); } }
private void OnClick_Buy(object sender, RoutedEventArgs e) { GroupedInventoryItem groupedInventoryItem = ((FrameworkElement)sender).DataContext as GroupedInventoryItem; if (groupedInventoryItem != null) { if (Session.CurrentPlayer.Gold >= groupedInventoryItem.Item.Price) { Session.CurrentPlayer.SpendGold(groupedInventoryItem.Item.Price); Session.CurrentTrader.RemoveItemFromInventory(groupedInventoryItem.Item); Session.CurrentPlayer.AddItemToInventory(groupedInventoryItem.Item); } else { MessageBox.Show("You do not have enough gold."); } } }
private void OnClick_Buy(object sender, RoutedEventArgs e) { GroupedInventoryItem groupedInventoryItem = ((FrameworkElement)sender).DataContext as GroupedInventoryItem; if (groupedInventoryItem != null) { if (Session.CurrentPlayer.Money >= groupedInventoryItem.Item.Price) { Session.CurrentPlayer.RecieveMoney(groupedInventoryItem.Item.Price); Session.CurrentTrader.RemoveItemFromInventory(groupedInventoryItem.Item); Session.CurrentPlayer.AddItemToInventory(groupedInventoryItem.Item); } else { MessageBox.Show("Man I'm Broke!"); } } }
//function to buy items private void OnClick_Buy(object sender, RoutedEventArgs e) { GroupedInventoryItem groupedInventoryItem = ((FrameworkElement)sender).DataContext as GroupedInventoryItem; if (groupedInventoryItem != null) { if (Session.currentPlayer.gold >= groupedInventoryItem.item.price) { Session.currentPlayer.spendGold(groupedInventoryItem.item.price); Session.currentTrader.RemoveItemFromInventory(groupedInventoryItem.item); Session.currentPlayer.AddItemToInventory(groupedInventoryItem.item); } else { MessageBox.Show("Insufficient Macca."); } } }
private void OnClick_Sell(object sender, RoutedEventArgs e) { GroupedInventoryItem inventoryItem = ((FrameworkElement)sender).DataContext as GroupedInventoryItem; int amounttoSell = inventoryItem.QuantityForTrade; GameItem item = inventoryItem.Item; int fullPrice = item.Price * amounttoSell; if (item != null) { if (Session.CurrentPlayer.Gold >= fullPrice) { Session.CurrentPlayer.ReceiveGold(fullPrice); Session.CurrentTrader.AddItemToInventory(item, amounttoSell); Session.CurrentPlayer.RemoveItemFromInventory(item, amounttoSell); } } }
private void OnClick_Buy(object sender, RoutedEventArgs e) { GroupedInventoryItem groupedInventoryItem = ((FrameworkElement)sender).DataContext as GroupedInventoryItem; if (groupedInventoryItem != null) { //Extra check here to make sure player has enough gold to buy item if (Session.CurrentPlayer.Gold >= groupedInventoryItem.Item.Price) { Session.CurrentPlayer.ReceiveGold(groupedInventoryItem.Item.Price); Session.CurrentTrader.RemoveItemFromInventory(groupedInventoryItem.Item); Session.CurrentPlayer.AddItemToInventory(groupedInventoryItem.Item); } else { MessageBox.Show("You do not have enough gold"); } } }
private void OnClick_Buy(object sender, RoutedEventArgs e) { // GameItem item = ((FrameworkElement)sender).DataContext as GameItem; GroupedInventoryItem inventoryItem = ((FrameworkElement)sender).DataContext as GroupedInventoryItem; GameItem item = inventoryItem.Item; int amounttoBuy = inventoryItem.QuantityForTrade; int fullPrice = item.Price * amounttoBuy; if (item != null) { if (Session.CurrentPlayer.Gold >= fullPrice) { Session.CurrentPlayer.SpendGold(fullPrice); Session.CurrentTrader.RemoveItemFromInventory(item, amounttoBuy); Session.CurrentPlayer.AddItemToInventory(item, amounttoBuy); } else { System.Windows.MessageBox.Show("You do not have enough gold"); } } }
private void Sell(GroupedInventoryItem groupedInventoryItem) { Session.CurrentPlayer.ReceiveGold(groupedInventoryItem.Item.Price); Session.CurrentTrader.AddItemToInventory(groupedInventoryItem.Item); Session.CurrentPlayer.RemoveItemFromInventory(groupedInventoryItem.Item); }