private void dgvVendorItems_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 3) { var itemID = dgvVendorItems.Rows[e.RowIndex].Cells[0].Value; Item itemBeingBought = World.ItemByID(Convert.ToInt32(itemID)); //checks is player has enough gold to buy the item if (_currentPlayer.Gold >= itemBeingBought.Price) { //removes gold = to item price _currentPlayer.Gold -= itemBeingBought.Price; _currentPlayer.AddItemToInventory(itemBeingBought); } else { MessageBox.Show("You do not have enough gold to buy the " + itemBeingBought.Name); } } }
private void dgvVendorItems_CellClick(object sender, DataGridViewCellEventArgs e) { //4th column has Buy 1 button if (e.ColumnIndex == 3) { //Get ID value of item from hidden 1st column var itemID = dgvVendorItems.Rows[e.RowIndex].Cells[0].Value; //Get Item object for selected row Item itemBeingBought = World.ItemByID(Convert.ToInt32(itemID)); if (itemBeingBought.Price <= _currentPlayer.Gold) { _currentPlayer.AddItemToInventory(itemBeingBought); _currentPlayer.Gold -= itemBeingBought.Price; } else { MessageBox.Show("You do not have enough gold to buy the " + itemBeingBought.Name); } } }
private void MoveTo(Location newLocation) { //Does the location have any required items if (!player.HasRequiredItemToEnterThisLocation(newLocation)) { rtbMessages.Text += "Musíš mít " + newLocation.ItemRequiredToEnter.Name + " aby si mohl vstoupit do této lokace." + Environment.NewLine; ScrollToBottomOfMessages(); return; } if ((player.CurrentLocation != null) && (player.CurrentLocation.MonsterLivingHere != null) && (!player.KilledMobRequiredToEnter(newLocation, player.y[player.CurrentLocation.MonsterLivingHere.ID]))) { rtbMessages.Text += "Musíš zabít " + player.CurrentLocation.MonsterLivingHere.Name + " aby si mohl vstoupit do této lokace." + Environment.NewLine; ScrollToBottomOfMessages(); return; } // Update the player's current location player.CurrentLocation = newLocation; // Show/hide available movement buttons btnNorth.Visible = (newLocation.LocationToNorth != null); btnEast.Visible = (newLocation.LocationToEast != null); btnSouth.Visible = (newLocation.LocationToSouth != null); btnWest.Visible = (newLocation.LocationToWest != null); // Display current location name and description rtbLocation.Text = newLocation.Name + Environment.NewLine; rtbLocation.Text += newLocation.Description + Environment.NewLine; ScrollToBottomOfMessages(); // Completely heal the player player.CurrentHP = player.MaxHP; // Does the location have a quest? if (newLocation.QuestAvailableHere != null) { // See if the player already has the quest, and if they've completed it bool playerAlreadyHasQuest = player.HasThisQuest(newLocation.QuestAvailableHere); bool playerAlreadyCompletedQuest = player.CompletedThisQuest(newLocation.QuestAvailableHere); // See if the player already has the quest if (playerAlreadyHasQuest) { // If the player has not completed the quest yet if (!playerAlreadyCompletedQuest) { // See if the player has all the items needed to complete the quest bool playerHasAllItemsToCompleteQuest = player.HasAllQuestCompletionItems(newLocation.QuestAvailableHere); // The player has all items required to complete the quest if (playerHasAllItemsToCompleteQuest) { // Display message rtbMessages.Text += Environment.NewLine; rtbMessages.Text += "Dokončil si úkol'" + newLocation.QuestAvailableHere.Name + "'." + Environment.NewLine; ScrollToBottomOfMessages(); // Remove quest items from inventory player.RemoveQuestCompletionItems(newLocation.QuestAvailableHere); // Give quest rewards rtbMessages.Text += "Dostal si: " + Environment.NewLine; rtbMessages.Text += newLocation.QuestAvailableHere.XPReward.ToString() + " XP" + Environment.NewLine; rtbMessages.Text += newLocation.QuestAvailableHere.GoldReward.ToString() + " zlatých" + Environment.NewLine; if (newLocation.QuestAvailableHere.RewardItem != null) { rtbMessages.Text += newLocation.QuestAvailableHere.RewardItem.Name + Environment.NewLine; // Add the reward item to the player's inventory player.AddItemToInventory(newLocation.QuestAvailableHere.RewardItem); } rtbMessages.Text += Environment.NewLine; ScrollToBottomOfMessages(); player.XP += newLocation.QuestAvailableHere.XPReward; player.Gold += newLocation.QuestAvailableHere.GoldReward; int lastlevel = player.Level; player.Level = player.LevelUp(player.XP, player.Level); levelUp(lastlevel); // Mark the quest as completed // Find the quest in the player's quest list player.MarkQuestCompleted(newLocation.QuestAvailableHere); } } } else { // The player does not already have the quest // Display the messages rtbMessages.Text += "Dostal si úkol '" + newLocation.QuestAvailableHere.Name + "'." + Environment.NewLine; rtbMessages.Text += newLocation.QuestAvailableHere.Description + Environment.NewLine; rtbMessages.Text += "Aby si ho splnil, vrať se s:" + Environment.NewLine; ScrollToBottomOfMessages(); foreach (QuestCompletionItem qci in newLocation.QuestAvailableHere.QuestCompletionItems) { if (qci.Quantity == 1) { rtbMessages.Text += qci.Quantity.ToString() + " " + qci.Details.Name + Environment.NewLine; ScrollToBottomOfMessages(); } else { rtbMessages.Text += qci.Quantity.ToString() + " " + qci.Details.NamePlural + Environment.NewLine; ScrollToBottomOfMessages(); } } rtbMessages.Text += Environment.NewLine; ScrollToBottomOfMessages(); // Add the quest to the player's quest list player.Quests.Add(new PlayerQuest(newLocation.QuestAvailableHere)); } } // Does the location have a monster? if (newLocation.MonsterLivingHere != null) { if (newLocation.MonsterLivingHere.Boss == true) { if (player.y[newLocation.MonsterLivingHere.ID] != 0) { Nomob(); } else { Ismob(); } } else { Ismob(); } } else { Nomob(); } // Refresh player's inventory list UpdateInventoryListInUI(); // Refresh player's quest list UpdateQuestListInUI(); // Refresh player's weapons combobox UpdateWeaponListInUI(); // Refresh player's potions combobox UpdatePotionListInUI(); //function for "summoning" mob void Ismob() { rtbMessages.Text += "Před tebou se vynořil divoký " + newLocation.MonsterLivingHere.Name + Environment.NewLine; ScrollToBottomOfMessages(); // Make a new monster, using the values from the standard monster in the World.Monster list Mob standardMob = World.MobByID(newLocation.MonsterLivingHere.ID); currentMob = new Mob(standardMob.ID, standardMob.Name, standardMob.MaxDmg, standardMob.XPReward, standardMob.GoldReward, standardMob.CurrentHP, standardMob.MaxHP, standardMob.Boss); foreach (LootItem lootItem in standardMob.LootTable) { currentMob.LootTable.Add(lootItem); } cboWeapons.Visible = true; cboPotions.Visible = true; btnUseWeapon.Visible = true; btnUsePotion.Visible = true; } }
private void MoveTo(Location newLocation) { //Does the location have any required items if (!_player.HasRequiredItemToEnterThisLocation(newLocation)) { rtbMessages.Text += "You must have a " + newLocation.ItemRequiredToEnter.Name + " to enter this location." + Environment.NewLine; return; } // Update the player's current location _player.CurrentLocation = newLocation; // Show/hide available movement buttons btnNorth.Visible = (newLocation.LocationToNorth != null); btnEast.Visible = (newLocation.LocationToEast != null); btnSouth.Visible = (newLocation.LocationToSouth != null); btnWest.Visible = (newLocation.LocationToWest != null); // Display current location name and description rtbLocation.Text = newLocation.Name + Environment.NewLine; rtbLocation.Text += newLocation.Description + Environment.NewLine; // Completely heal the player _player.CurrentHitPoints = _player.MaximumHitPoints; // Update Hit Points in UI lblHitPoints.Text = _player.CurrentHitPoints.ToString(); // Does the location have a quest? if (newLocation.QuestAvailableHere != null) { // See if the player already has the quest, and if they've completed it bool playerAlreadyHasQuest = _player.HasThisQuest(newLocation.QuestAvailableHere); bool playerAlreadyCompletedQuest = _player.CompletedThisQuest(newLocation.QuestAvailableHere); // See if the player already has the quest if (playerAlreadyHasQuest) { // If the player has not completed the quest yet if (!playerAlreadyCompletedQuest) { // See if the player has all the items needed to complete the quest bool playerHasAllItemsToCompleteQuest = _player.HasAllQuestCompletionItems(newLocation.QuestAvailableHere); // The player has all items required to complete the quest if (playerHasAllItemsToCompleteQuest) { // Display message rtbMessages.Text += Environment.NewLine; rtbMessages.Text += "You complete the '" + newLocation.QuestAvailableHere.Name + "' quest." + Environment.NewLine; // Remove quest items from inventory _player.RemoveQuestCompletionItems(newLocation.QuestAvailableHere); // Give quest rewards rtbMessages.Text += "You receive: " + Environment.NewLine; rtbMessages.Text += newLocation.QuestAvailableHere.RewardExperiencePoints.ToString() + " experience points" + Environment.NewLine; rtbMessages.Text += newLocation.QuestAvailableHere.RewardGold.ToString() + " gold" + Environment.NewLine; rtbMessages.Text += newLocation.QuestAvailableHere.RewardItem.Name + Environment.NewLine; rtbMessages.Text += Environment.NewLine; _player.ExperiencePoints += newLocation.QuestAvailableHere.RewardExperiencePoints; _player.Gold += newLocation.QuestAvailableHere.RewardGold; // Add the reward item to the player's inventory _player.AddItemToInventory(newLocation.QuestAvailableHere.RewardItem); // Mark the quest as completed _player.MarkQuestCompleted(newLocation.QuestAvailableHere); } } } else { // The player does not already have the quest // Display the messages rtbMessages.Text += "You receive the " + newLocation.QuestAvailableHere.Name + " quest." + Environment.NewLine; rtbMessages.Text += newLocation.QuestAvailableHere.Description + Environment.NewLine; rtbMessages.Text += "To complete it, return with:" + Environment.NewLine; foreach (QuestCompletionItem qci in newLocation.QuestAvailableHere.QuestCompletionItems) { if (qci.Quantity == 1) { rtbMessages.Text += qci.Quantity.ToString() + " " + qci.Details.Name + Environment.NewLine; } else { rtbMessages.Text += qci.Quantity.ToString() + " " + qci.Details.NamePlural + Environment.NewLine; } } rtbMessages.Text += Environment.NewLine; // Add the quest to the player's quest list _player.Quests.Add(new PlayerQuest(newLocation.QuestAvailableHere)); } } // Does the location have a monster? if (newLocation.MonsterLivingHere != null) { rtbMessages.Text += "You see a " + newLocation.MonsterLivingHere.Name + Environment.NewLine; // Make a new monster, using the values from the standard monster in the World.Monster list Monster standardMonster = World.MonsterByID(newLocation.MonsterLivingHere.ID); _currentMonster = new Monster(standardMonster.ID, standardMonster.Name, standardMonster.MaximumDamage, standardMonster.RewardExperiencePoints, standardMonster.RewardGold, standardMonster.CurrentHitPoints, standardMonster.MaximumHitPoints); foreach (LootItem lootItem in standardMonster.LootTable) { _currentMonster.LootTable.Add(lootItem); } cboWeapons.Visible = true; cboPotions.Visible = true; btnUseWeapon.Visible = true; btnUsePotion.Visible = true; } else { _currentMonster = null; cboWeapons.Visible = false; cboPotions.Visible = false; btnUseWeapon.Visible = false; btnUsePotion.Visible = false; } // Refresh player's inventory list UpdateInventoryListInUI(); // Refresh player's quest list UpdateQuestListInUI(); // Refresh player's weapons combobox UpdateWeaponListInUI(); // Refresh player's potions combobox UpdatePotionListInUI(); }
private void btnUseWeapon_Click(object sender, EventArgs e) { // Get currently selected weapon from the cboWeapons Combobox Weapon currentWeapon = (Weapon)cboWeapons.SelectedItem; // Determine amount of daamge to do to monster int damageToMonster = RNG.NumberBetween(currentWeapon.MinimumDamage, currentWeapon.MaximumDamage); //Apply damage to monsters currentHP _currentMonster.CurrentHitPoints -= damageToMonster; //display msg rtbMessages.Text += "You've dealt " + damageToMonster.ToString() + "damage to " + _currentMonster.Name + "." + Environment.NewLine; ScrollToBottomOfMessages(); //Check if monster is dead if (_currentMonster.CurrentHitPoints <= 0) { //monster is dead rtbMessages.Text += Environment.NewLine; rtbMessages.Text += _currentMonster.Name + " has been defeated!" + Environment.NewLine; //Give player xp for killing monster _player.ExperiencePoints += _currentMonster.RewardExperiencePoints; rtbMessages.Text += _currentMonster.RewardExperiencePoints.ToString() + " experience points received." + Environment.NewLine; //Give player gold for killing monster _player.Gold += _currentMonster.RewardGold; rtbMessages.Text += _currentMonster.RewardGold.ToString() + " gold found!" + Environment.NewLine; ScrollToBottomOfMessages(); //Get random loot items from monster List <InventoryItem> lootedItems = new List <InventoryItem>(); //Add items to the lootedItems list, comapring random number to the drop % foreach (LootItem lootItem in _currentMonster.LootTable) { if (RNG.NumberBetween(1, 100) <= lootItem.DropPercentage) { lootedItems.Add(new InventoryItem(lootItem.Details, 1)); } } //if no items were randomly selected, add the default loot item(s). if (lootedItems.Count == 0) { foreach (LootItem lootItem in _currentMonster.LootTable) { if (lootItem.IsDefaultItem) { lootedItems.Add(new InventoryItem(lootItem.Details, 1)); } } } //Add the looted items to the player's inventory foreach (InventoryItem inventoryItem in lootedItems) { _player.AddItemToInventory(inventoryItem.Details); if (inventoryItem.Quantity == 1) { rtbMessages.Text += "You found " + inventoryItem.Quantity.ToString() + " " + inventoryItem.Details.Name + Environment.NewLine; } else { rtbMessages.Text += "You found " + inventoryItem.Quantity.ToString() + " " + inventoryItem.Details.NamePlural + Environment.NewLine; } } ScrollToBottomOfMessages(); UpdatePlayerStats(); UpdateInventoryListInUI(); UpdateWeaponListinUI(); UpdatePotionListInUI(); //Add blank line to msg box for appearance rtbMessages.Text += Environment.NewLine; //Move player to current location (heal player and create a new monster to fight) MoveTo(_player.CurrentLocation); } else { MonsterAttack(); } }