Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        private static void SpawnLocations()
        {
            // Create locations with NPCs only
            Location center = new Location(LocCenter, "Home, sweet home...", NPCByID(NPC_ID_Captain));

            Location north = new Location(LocNorth, "Cold North Pole", NPCByID(NPC_ID_Mage));

            // Create locations with Monsters only
            Location west = new Location(LocWest, "Yeeeeehhaa West Coast", null, MonsterByID(MONSTER_ID_SNAKE));

            Location east = new Location(LocEast, "Alchemist's garden", null, MonsterByID(MONSTER_ID_RAT));

            Location south = new Location(LocSouth, "Farmhouse", null, MonsterByID(MONSTER_ID_GIANT_SPIDER));

            // Create empty locations
            Location northWest = new Location(LocNorthWest, "North West");
            Location northEast = new Location(LocNorthEast, "North East");
            Location southWest = new Location(LocSouthWest, "South West");
            Location southEast = new Location(LocSouthEast, "South East");

            // Link the locations together
            north.LocationToSouth = center;
            north.LocationToWest = northWest;
            north.LocationToEast = northEast;

            center.LocationToNorth = north;
            center.LocationToSouth = south;
            center.LocationToEast = east;
            center.LocationToWest = west;

            west.LocationToEast = center;
            west.LocationToNorth = northWest;
            west.LocationToSouth = southWest;

            south.LocationToNorth = center;
            south.LocationToWest = southWest;
            south.LocationToEast = southEast;

            east.LocationToWest = center;
            east.LocationToNorth = northEast;
            east.LocationToSouth = southEast;

            northEast.LocationToWest = north;
            northEast.LocationToSouth = east;

            northWest.LocationToEast = north;
            northWest.LocationToSouth = west;

            southEast.LocationToWest = south;
            southEast.LocationToNorth = east;

            southWest.LocationToEast = south;
            southWest.LocationToNorth = west;

            // Add the locations to the list
            Locations.Add(north);
            Locations.Add(center);
            Locations.Add(west);
            Locations.Add(south);
            Locations.Add(east);
            Locations.Add(northEast);
            Locations.Add(northWest);
            Locations.Add(southEast);
            Locations.Add(southWest);
        }