public Location(int id, string name, NPC npcHere = null, Monster monsterHere = null, Uri imgUri = null) { ID = id; Name = name; NPCHere = npcHere; MonsterHere = monsterHere; if (imgUri == null) { Image = new BitmapImage(GroundURI); } else { Image = new BitmapImage(imgUri); } }
private void MoveTo(Location newLocation) { // Update the player's current location _player.CurrentLocation = newLocation; // Update the player's current location in UI UpdatePlayerPositionUI(); // Show/hide available movement buttons #region Directions Block if (newLocation.LocationToNorth != null) { btnNorth.Visibility = Visibility.Visible; } else { btnNorth.Visibility = Visibility.Hidden; } if (newLocation.LocationToEast != null) { btnEast.Visibility = Visibility.Visible; } else { btnEast.Visibility = Visibility.Hidden; } if (newLocation.LocationToSouth != null) { btnSouth.Visibility = Visibility.Visible; } else { btnSouth.Visibility = Visibility.Hidden; } if (newLocation.LocationToWest != null) { btnWest.Visibility = Visibility.Visible; } else { btnWest.Visibility = Visibility.Hidden; } #endregion // Display current location name tblckLocation.Text = newLocation.Name + Environment.NewLine; // Does the location have a quest? if (newLocation.NPCHere != null) { // Display current Target properties tblckTargetName.Text = "NPC \"" + newLocation.NPCHere.Name + "\""; // See if the player already has the quest, and if they've completed it bool playerAlreadyHasQuest = _player.HasThisQuest(newLocation.NPCHere.Quest); bool playerAlreadyCompletedQuest = _player.CompletedThisQuest(newLocation.NPCHere.Quest); // 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.NPCHere.Quest); // The player has all items required to complete the quest if (playerHasAllItemsToCompleteQuest) { // Display message tblckLocation.Text += Environment.NewLine; tblckLocation.Text += "You complete the '" + newLocation.NPCHere.Quest.Name + "' quest." + Environment.NewLine; // Remove quest items from inventory _player.RemoveQuestCompletionItems(newLocation.NPCHere.Quest); // Give quest rewards tblckLocation.Text += "You receive: " + Environment.NewLine; tblckLocation.Text += newLocation.NPCHere.Quest.ExpReward.ToString() + " experience points" + Environment.NewLine; tblckLocation.Text += newLocation.NPCHere.Quest.GoldReward.ToString() + " gold" + Environment.NewLine; tblckLocation.Text += newLocation.NPCHere.Quest.ItemReward.Name + Environment.NewLine; tblckLocation.Text += Environment.NewLine; _player.AddExperience(newLocation.NPCHere.Quest.ExpReward); _player.Gold += newLocation.NPCHere.Quest.GoldReward; // Add the reward item to the player's inventory _player.AddItemToInventory(newLocation.NPCHere.Quest.ItemReward); // Mark the quest as completed _player.MarkQuestCompleted(newLocation.NPCHere.Quest); } } } else { // The player does not already have the quest // Ask Player whether he wants to take a quest var dialogResult = MessageBox.Show( newLocation.NPCHere.Quest.Description + Environment.NewLine + Environment.NewLine + "Do you want to complete this quest?", newLocation.NPCHere.Name, MessageBoxButton.YesNo); if (dialogResult == MessageBoxResult.Yes) { // Display the messages tblckLocation.Text += "You receive the " + newLocation.NPCHere.Quest.Name + " quest." + Environment.NewLine; tblckLocation.Text += newLocation.NPCHere.Quest.Description + Environment.NewLine; tblckLocation.Text += "To complete it, return with:" + Environment.NewLine; foreach (QuestCompletionItem qci in newLocation.NPCHere.Quest.QuestCompletionItems) { tblckLocation.Text += qci.Quantity.ToString() + " " + qci.Details.Name + Environment.NewLine; } tblckLocation.Text += Environment.NewLine; // Add the quest to the player's quest list _player.Quests.Add(new PlayerQuest(newLocation.NPCHere.Quest)); } else if (dialogResult == MessageBoxResult.No) { MessageBox.Show( "See you next time", newLocation.NPCHere.Name); } } } // Does the location have a monster? if (newLocation.MonsterHere != null) { // Display current Target properties tblckTargetName.Text = "Monster \"" + newLocation.MonsterHere.Name + "\" "; tblckTargetHP.Text = newLocation.MonsterHere.CurrentHP.ToString() + " / " + newLocation.MonsterHere.MaxHP.ToString(); tblckLocation.Text += "You see a " + newLocation.MonsterHere.Name + Environment.NewLine; // Make a new monster, using the values from the standard monster in the World.Monster list Monster standardMonster = World.MonsterByID(newLocation.MonsterHere.ID); _currentMonster = new Monster(standardMonster.ID, standardMonster.Name, standardMonster.CurrentHP, standardMonster.MaxHP, standardMonster.Damage, standardMonster.ExpReward, standardMonster.GoldReward, Monster.MonsterUri); foreach (LootItem lootItem in standardMonster.ItemsReward) { _currentMonster.ItemsReward.Add(lootItem); } } else { _currentMonster = null; } // Refresh player's stats UpdatePlayerStats(); // Refresh player's inventory list UpdateInventoryItems(); // Refresh player's quest list UpdatePlayerQuests(); // Refresh player's weapons combobox UpdateWeaponList(); }
private static void SpawnMonsters() { Monster rat = new Monster(MONSTER_ID_RAT, "Rat", 50, 50, 3, 10, 20, _ratImgUri); rat.ItemsReward.Add(new LootItem(ItemByID(ITEM_ID_RAT_TAIL), 75)); rat.ItemsReward.Add(new LootItem(ItemByID(ITEM_ID_PIECE_OF_FUR), 75)); Monster snake = new Monster(MONSTER_ID_SNAKE, "Snake", 55, 55, 3, 10, 30, _snakeImgUri); snake.ItemsReward.Add(new LootItem(ItemByID(ITEM_ID_SNAKE_FANG), 75)); snake.ItemsReward.Add(new LootItem(ItemByID(ITEM_ID_SNAKESKIN), 75)); Monster giantSpider = new Monster(MONSTER_ID_GIANT_SPIDER, "Giant spider", 60, 60, 3, 10, 40, _spiderImgUri); giantSpider.ItemsReward.Add(new LootItem(ItemByID(ITEM_ID_SPIDER_FANG), 75)); giantSpider.ItemsReward.Add(new LootItem(ItemByID(ITEM_ID_SPIDER_SILK), 25)); Monsters.Add(rat); Monsters.Add(snake); Monsters.Add(giantSpider); }