Exemple #1
0
        public static Player CreatePlayerFromDatabase(int currentHitPoints, int maximumHitPoints, int gold, int experiencePoints, int currentLocationID)
        {
            Player player = new Player(currentHitPoints, maximumHitPoints, gold, experiencePoints);

            player.MoveTo(World.LocationByID(currentLocationID));
            return(player);
        }
Exemple #2
0
        /// <summary>
        /// creates player using SQL database
        /// </summary>
        /// <param name="chp">current hit points</param>
        /// <param name="mhp">max hit points</param>
        /// <param name="gold">gold</param>
        /// <param name="exp">experience</param>
        /// <param name="clID">current location ID</param>
        /// <returns>a player from a database</returns>
        public static Player CreatePlayerFromDatabase(int chp, int mhp, int gold, int exp, int clID)
        {
            Player player = new Player(chp, mhp, gold, exp);

            player.MoveTo(World.LocationByID(clID));
            return(player);
        }
        public static Player CreatePlayerfromDatabase(int hp, int maxhp, int gold, int exp, int currentlocation)
        {
            Player player = new Player(hp, (maxhp + 10), 100, gold, exp, 10, 10, 10, 10, 10, 5);

            player.MoveTo(World.LocationByID(currentlocation));
            return(player);
        }
        //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
        public static Player CreateDefaultPlayer()
        {
            Player player = new Player(100, 100, 100, 10, 0, 10, 10, 10, 10, 10, 5);

            player.Inventory.Add(new Inventory(World.ItemByID(World.Item_ID_Bow), 1));
            player.Inventory.Add(new Inventory(World.ItemByID(World.Item_ID_GODSWORD), 1));
            player.CurrentLocation = World.LocationByID(World.Location_ID_Camp);
            return(player);

            /*if(clas == "I")
             * {
             *  Player playerI = new Player(120,120,100,20,0,13,10,12,11,10,7);
             *  player.Inventory.Add(new Inventory(World.ItemByID(World.Item_ID_Dagger), 1));
             *  player.CurrentLocation = World.LocationByID(World.Location_ID_Camp);
             *  return playerI;
             *
             * }
             * else if(clas == "M")
             * {
             *  Player playerM = new Player(100, 100, 140, 5, 0, 10, 10, 13, 12, 16, 4);
             *  player.Inventory.Add(new Inventory(World.ItemByID(World.Item_ID_Staff), 1));
             *  player.Inventory.Add(new Inventory(World.ItemByID(World.Item_ID_Dagger), 1));
             *  player.CurrentLocation = World.LocationByID(World.Location_ID_Camp);
             *  return playerM;
             * }
             * else if(clas == "C")
             * {
             *  Player playerC = new Player(110, 110, 110, 10, 0, 10, 10, 14, 13, 11, 6);
             *  player.Inventory.Add(new Inventory(World.ItemByID(World.Item_ID_Bow), 1));
             *  player.Inventory.Add(new Inventory(World.ItemByID(World.Item_ID_Dagger), 1));
             *  player.CurrentLocation = World.LocationByID(World.Location_ID_Camp);
             *  return playerC;
             * }*/
        }
        public static Player CreatePlayerFromXmlString(string xmlPlayerData)
        {
            try
            {
                XmlDocument playerData = new XmlDocument();

                playerData.LoadXml(xmlPlayerData);

                int currentHitPoints          = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentHitPoints").InnerText);
                int maximumHitPoints          = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/MaximumHitPoints").InnerText);
                int level                     = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Level").InnerText);
                int currentStrength           = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentStrength").InnerText);
                int currentDexterity          = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentDexterity").InnerText);
                int gold                      = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Gold").InnerText);
                int experiencePoints          = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/ExperiencePoints").InnerText);
                int experienceRequiredToLevel = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/ExperienceRequiredToLevel").InnerText);

                Player player = new Player(currentHitPoints, maximumHitPoints, level, currentStrength, currentDexterity, gold, experiencePoints, experienceRequiredToLevel);

                int currentLocationID = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentLocation").InnerText);
                player.CurrentLocation = World.LocationByID(currentLocationID);
                if (playerData.SelectSingleNode("/Player/Stats/CurrentWeapon") != null)
                {
                    int currentWeaponID = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentWeapon").InnerText);
                    player.CurrentWeapon = (Weapon)World.ItemByID(currentWeaponID);
                }



                foreach (XmlNode node in playerData.SelectNodes("/Player/InventoryItems/InventoryItem"))
                {
                    int id       = Convert.ToInt32(node.Attributes["ID"].Value);
                    int quantity = Convert.ToInt32(node.Attributes["Quantity"].Value);

                    for (int i = 0; i < quantity; i++)
                    {
                        player.AddItemToInventory(World.ItemByID(id));
                    }
                }

                foreach (XmlNode node in playerData.SelectNodes("/Player/PlayerQuests/PlayerQuest"))
                {
                    int  id          = Convert.ToInt32(node.Attributes["ID"].Value);
                    bool isCompleted = Convert.ToBoolean(node.Attributes["IsCompleted"].Value);

                    PlayerQuest playerQuest = new PlayerQuest(World.QuestByID(id));
                    playerQuest.IsCompleted = isCompleted;

                    player.Quests.Add(playerQuest);
                }

                return(player);
            }
            catch
            {
                // If there was an error with the XML data, return a default player object
                return(Player.CreateDefaultPlayer());
            }
        }
Exemple #6
0
        public static Player CreateDefaultPlayer()
        {
            Player player = new Player(10, 10, 20, 0, false);

            player.CurrentLocation = World.LocationByID(World.LOCATION_ID_HOME);

            return(player);
        }
Exemple #7
0
        public static Player CreateDefaultPlayer()
        {
            Player player = new Player(10, 10, 20, 0);
            player.Inventory.Add(new InventoryItem(World.ItemByID(World.ITEM_ID_RUSTY_SWORD), 1));
            player.CurrentLocation = World.LocationByID(World.LOCATION_ID_HOME);

            return player;
        }
Exemple #8
0
        public static Player CreateDefaultPlayer()
        {
            Player player = new Player(10, 10, 20, 0);

            player.Inventory.Add(new InventoryItem(World.ItemByID((int)ItemId.RustySword), 1));
            player.CurrentLocation = World.LocationByID(World.LOCATION_ID_HOME);

            return(player);
        }
Exemple #9
0
        public static Player CreatePlayerFromXmlString(string xmlPlayerData)
        {
            try {
                XmlDocument playerData = new XmlDocument();

                playerData.LoadXml(xmlPlayerData);

                int currentHitPoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentHitPoints").InnerText);
                int maximumHitPoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/MaximumHitPoints").InnerText);
                int gold             = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Gold").InnerText);
                int experiencePoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/ExperiencePoints").InnerText);

                Player player = new Player(currentHitPoints, maximumHitPoints, gold, experiencePoints);

                int currentLocationID = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentLocation").InnerText);
                player.CurrentLocation = World.LocationByID(currentLocationID);


                if (playerData.SelectSingleNode("/Player/Stats/CurrentWeapon") != null)
                {
                    int currentWeaponID = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentWeapon").InnerText);
                    player.CurrentWeapon = (Weapon)World.ItemByID(currentWeaponID);
                }

                if (playerData.SelectSingleNode("/Player/Stats/CurrentArmor") != null)
                {
                    int currentArmorID = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentArmor").InnerText);
                    player.CurrentArmor = (Armor)World.ItemByID(currentArmorID);
                }

                foreach (XmlNode node in playerData.SelectNodes("/Player/InventoryItems/InventoryItem"))
                {
                    int id       = Convert.ToInt32(node.Attributes["ID"].Value);
                    int quantity = Convert.ToInt32(node.Attributes["Quantity"].Value);

                    for (int i = 0; i < quantity; i++)
                    {
                        player.AddItemToInventory(World.ItemByID(id));
                    }
                }

                foreach (XmlNode node in playerData.SelectNodes("/Player/PlayerQuests/PlayerQuest"))
                {
                    int  id          = Convert.ToInt32(node.Attributes["ID"].Value);
                    bool isCompleted = Convert.ToBoolean(node.Attributes["IsCompleted"].Value);

                    PlayerQuest playerQuest = new PlayerQuest(World.QuestByID(id));
                    playerQuest.IsCompleted = isCompleted;

                    player.Quests.Add(playerQuest);
                }
                player.MoveTo(World.LocationByID(player.CurrentLocation.ID));
                return(player);
            } catch {
                return(Player.CreateDefaultPlayer());
            }
        }
Exemple #10
0
        public static Player CreateDefaultPlayer()
        {
            Player player = new Player(10, 10, 10, 0);

            player.Inventory.Add(new InventoryItem(World.ItemByID(World.ITEM_ID_POINTY_STICK), 1));
            player.CurrentLocation = World.LocationByID(World.LOCATION_ID_CAMPSITE);

            return(player);
        }
Exemple #11
0
        public static Player CreateDefaultPlayer()
        {
            Player player = new Player(10, 10, 20, 0, 10, 10);

            player.Inventory.Add(new InventoryItem(World.ItemByID(World.ITEM_ID_RUSTY_SWORD), 1));
            player.Spells.Add(World.SpellByID(World.SPELL_ID_FIREBALL));
            player.CurrentLocation = World.LocationByID(World.LOCATION_ID_HOME);

            return(player);
        }
Exemple #12
0
        public static Player CreatePlayerFromXmlString(string xmlPlayerData)
        {
            try
            {
                XmlDocument playerData = new XmlDocument();

                playerData.LoadXml(xmlPlayerData);

                int currentHitPoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentHitPoints").InnerText);
                int maximumHitPoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/MaximumHitPoints").InnerText);
                int gold             = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Gold").InnerText);
                int experiencePoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/ExperiencePoints").InnerText);
                int level            = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Level").InnerText);

                Player player = new Player(currentHitPoints, maximumHitPoints, gold, experiencePoints, level);

                int currentLocationID = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentLocation").InnerText);
                player.CurrentLocation = World.LocationByID(currentLocationID);

                if (playerData.SelectSingleNode("/Player/Stats/CurrentWeapon") != null)
                {
                    int currentWeaponID = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentWeapon").InnerText);
                    player.CurrentWeapon = (Weapon)World.ItemByID(currentWeaponID);
                }

                foreach (XmlNode node in playerData.SelectNodes("/Player/InventoryItems/InventoryItem"))
                {
                    int id       = Convert.ToInt32(node.Attributes["ID"].Value);
                    int quantity = Convert.ToInt32(node.Attributes["Quantity"].Value);

                    player.Inventory.Add(new InventoryItem(World.ItemByID(id), quantity));
                }

                foreach (XmlNode node in playerData.SelectNodes("/Player/PlayerQuests/PlayerQuest"))
                {
                    int  id          = Convert.ToInt32(node.Attributes["ID"].Value);
                    bool isCompleted = Convert.ToBoolean(node.Attributes["IsCompleted"].Value);

                    PlayerQuest playerQuest = new PlayerQuest(World.QuestByID(id));
                    playerQuest.IsCompleted = isCompleted;

                    player.Quests.Add(playerQuest);
                }

                return(player);
            }
            catch
            {
                // if there's an error loading xml file, create default player
                return(CreateDefaultPlayer());
            }
        }
        public void Rest()
        {
            if (World.LocationByID(World.Location_ID_Camp) == CurrentLocation)
            {
                HP = MaxHP;
                if (Stamina <= 100 + ((int)Speed / 4))
                {
                    Stamina = 100 + ((int)Speed / 5);
                }
            }
            else
            {
                if (MaxHP <= (HP + (int)(MaxHP * .12)))
                {
                    HP = MaxHP;
                }
                else
                {
                    HP = HP + (int)(MaxHP * .12);
                }
                if ((Stamina + 40) >= 100)
                {
                    Stamina = 100;
                }
                else
                {
                    Stamina += 40;
                }
            }


            RaiseMessage("You had a rest and regain health and replenshed stamina");
            if (CurrentMonster != null)
            {
                if (CurrentMonster.HP >= 0)
                {
                    double crit           = CurrentMonster.MaxDmg * 1.5;
                    int    damageToPlayer = RandomNumberGen.NumberBetween(10, (int)crit);
                    RaiseMessage("The " + CurrentMonster.Name + " did " + damageToPlayer + " points of damage.");
                    HP -= damageToPlayer;
                    if (HP <= 0)
                    {
                        RaiseMessage("The " + CurrentMonster.Name + " killed you.");
                        Gold = Gold - (int)(0.05 * Gold);
                        MoveHome();
                    }
                }
            }
        }
Exemple #14
0
        /* Function for monster attack */
        public void MonsterAttack()
        {
            // monster attacks
            int damageToPlayer = Engine.RandomNumberGenerator.NumberBetween(0, _currentMonster.MaximumDamage);

            RaiseMessage(_currentMonster.Name + " attacks and deals " + damageToPlayer.ToString() + " damage!" + Environment.NewLine);
            CurrentHitPoints -= damageToPlayer;
            // updatePlayerStats();
            if (CurrentHitPoints <= 0)
            {
                // player defeated
                RaiseMessage("You've been defeated!" + Environment.NewLine);
                MoveTo(World.LocationByID(World.LOCATION_ID_HOME));
            }
        }
Exemple #15
0
        public static Player CreatePlayerFromXmlString(string xmlPlayerData)
        {
            try
            {
                XmlDocument playerData = new XmlDocument();

                playerData.LoadXml(xmlPlayerData);

                int currentHP = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentHP").InnerText);
                int maximumHP = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/MaximumHP").InnerText);
                int gold      = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Gold").InnerText);
                int xp        = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/XP").InnerText);

                Player player = new Player(currentHP, maximumHP, gold, xp);

                int currentLocationID = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentLocation").InnerText);
                player.CurrentLocation = World.LocationByID(currentLocationID);

                foreach (XmlNode node in playerData.SelectNodes("/Player/InventoryItems/InventoryItem"))
                {
                    int id       = Convert.ToInt32(node.Attributes["ID"].Value);
                    int quantity = Convert.ToInt32(node.Attributes["Quantity"].Value);

                    for (int i = 0; i < quantity; i++)
                    {
                        player.AddItemToInventory(World.ItemByID(id));
                    }
                }

                foreach (XmlNode node in playerData.SelectNodes("/Player/PlayerQuests/PlayerQuest"))
                {
                    int  id          = Convert.ToInt32(node.Attributes["ID"].Value);
                    bool isCompleted = Convert.ToBoolean(node.Attributes["IsCompleted"].Value);

                    PlayerQuest playerQuest = new PlayerQuest(World.QuestByID(id));
                    playerQuest.IsCompleted = isCompleted;

                    player.Quests.Add(playerQuest);
                }

                return(player);
            }
            catch (Exception)
            {
                //If there was an error with the XML Data, return a default player object
                return(Player.CreateDefaultPlayer());
            }
        }
        public static Player createplayerformxmlString(string xmlPlayerData)
        {
            try
            {
                XmlDocument playerdata = new XmlDocument();

                playerdata.LoadXml(xmlPlayerData);

                int HP    = Convert.ToInt32(playerdata.SelectSingleNode("/Player/Stats/HP").InnerText);
                int MaxHP = Convert.ToInt32(playerdata.SelectSingleNode("/Player/Stats/MaxHP").InnerText);
                int gold  = Convert.ToInt32(playerdata.SelectSingleNode("/Player/Stats/Gold").InnerText);
                int exp   = Convert.ToInt32(playerdata.SelectSingleNode("/Player/Stats/EXP").InnerText);

                Player player = new Player(HP, MaxHP, 100, gold, exp, 10, 10, 10, 10, 10, 5);

                int currentLocationID = Convert.ToInt32(playerdata.SelectSingleNode("/Player/Stats/CurrentLocation").InnerText);
                player.CurrentLocation = World.LocationByID(currentLocationID);
                if (playerdata.SelectSingleNode(".Player/Stats/CurrentWeapon") != null)
                {
                    int currentWeaponID = Convert.ToInt32(playerdata.SelectSingleNode("/Player/Stats/CurrentWeapon").InnerText);
                    player.CurrentWeapon = (Weapon)World.ItemByID(currentWeaponID);
                }
                foreach (XmlNode node in playerdata.SelectNodes("/Player/Inventory/Inventory"))
                {
                    int id       = Convert.ToInt32(node.Attributes["ID"].Value);
                    int quantity = Convert.ToInt32(node.Attributes["Quantity"].Value);
                    for (int i = 0; i < quantity; i++)
                    {
                        player.additemtoinventor(World.ItemByID(id));
                    }
                }
                foreach (XmlNode node in playerdata.SelectNodes("/Player/PlayerQuest/PlayerQuest"))
                {
                    int  id          = Convert.ToInt32(node.Attributes["ID"].Value);
                    bool iscompleted = Convert.ToBoolean(node.Attributes["IsCompleted"].Value);

                    PlayerQuest playerQuest = new PlayerQuest(World.QuestByID(id));
                    playerQuest.IsCompleted = iscompleted;
                    player.Quest.Add(playerQuest);
                }
                return(player);
            }
            catch
            {
                return(CreateDefaultPlayer());
            }
        }
        /// <summary>
        /// Creates a Default Player at the Default Location
        /// </summary>
        /// <returns></returns>
        public static Player CreateDefaultPlayer()
        {
            int DEFAULT_HIT_POINTS        = 10;
            int DEFAULT_GOLD              = 20;
            int DEFAULT_EXPERIENCE_POINTS = 0;

            Player player = new Player(
                DEFAULT_HIT_POINTS,
                DEFAULT_HIT_POINTS,
                DEFAULT_GOLD,
                DEFAULT_EXPERIENCE_POINTS);

            player.Inventory.Add(new InventoryItem(World.ItemByID(World.ITEM_ID_RUSTY_SWORD), 1));

            // add a club as well to test out the weapon combobox logic
            player.Inventory.Add(new InventoryItem(World.ItemByID(World.ITEM_ID_CLUB), 1));

            player.CurrentLocation = World.LocationByID(World.LOCATION_ID_HOME);

            return(player);
        }
        public void EnemyAttack(Player player)
        {
            //Determine the amount of damage the monster does to the player
            int damageToPlayer = RandomNumberGenerator.NumberBetween(0, MaximumDamage);

            //Display message
            RaiseMessage($"The {Name} deals {damageToPlayer} points of damage." + Environment.NewLine);

            //Subtract damage from player
            player.CurrentHitPoints -= damageToPlayer;

            if (player.CurrentHitPoints <= 0)
            {
                RaiseMessage($"The f*****g {Name} killed your weak ass." + Environment.NewLine);

                //Move player back to 'Home'
                player.MoveTo(World.LocationByID(World.LOCATION_ID_HOME));

                MessageBox.Show("YOU DIED", "DEAD");
            }
        }
Exemple #19
0
        public static Player LoadPlayerInformationFromXml(string xmlPlayerData)
        {
            Player player;

            try
            {
                XmlDocument playerData = new XmlDocument();
                playerData.LoadXml(xmlPlayerData);

                int    currentHitPoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentHitPoints").InnerText);
                int    maximumHitPoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/MaximumHitPoints").InnerText);
                int    gold             = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Gold").InnerText);
                int    experiencePoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/ExperiencePoints").InnerText);
                int    level            = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Level").InnerText);
                int    strength         = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Strength").InnerText);
                int    dexterity        = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Dexterity").InnerText);
                int    intelligent      = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Intelligent").InnerText);
                int    currentMana      = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentMana").InnerText);
                int    maximumMana      = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/MaximumMana").InnerText);
                Race   race             = World.RaceByID(Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Race").InnerText));
                Armour armourUsed       = null;
                if (Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/ArmourUsed").InnerText) != 0)
                {
                    armourUsed = (Armour)World.ItemByID(Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/ArmourUsed").InnerText));
                }
                player = new Player(currentHitPoints, maximumHitPoints, gold, experiencePoints, level, strength, dexterity, intelligent, currentMana, maximumMana, race, armourUsed);
                player.CurrentLocation = World.LocationByID(Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentLocation").InnerText));
                if (Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentWeapon").InnerText) != 0)
                {
                    player.CurrentWeapon = (Weapon)World.ItemByID(Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentWeapon").InnerText));
                }
                else
                {
                    player.CurrentWeapon = null;
                }

                if (Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentPotion").InnerText) != 0)
                {
                    player.CurrentPotion = (HealingPotion)World.ItemByID(Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentPotion").InnerText));
                }
                else
                {
                    player.CurrentPotion = null;
                }
                foreach (XmlNode node in playerData.SelectNodes("/Player/InventoryItems/InventoryItem"))
                {
                    player.AddItem(World.ItemByID(Convert.ToInt32(node.Attributes["ID"].Value)), Convert.ToInt32(node.Attributes["Quantity"].Value));
                }

                foreach (XmlNode node in playerData.SelectNodes("/Player/PlayerQuests/PlayerQuest"))
                {
                    PlayerQuest playerQuest = new PlayerQuest(World.QuestByID(Convert.ToInt32(node.Attributes["ID"].Value)));
                    playerQuest.IsCompleted = Convert.ToBoolean(node.Attributes["IsCompleted"].Value);
                    player.Quests.Add(playerQuest);
                }
            }
            catch
            {
                player = new Player(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, World.RaceByID(World.RACE_ID_HUNMAN));
            }
            return(player);
        }
Exemple #20
0
 private void MoveHome()
 {
     MoveTo(World.LocationByID(World.LOCATION_ID_HOME));
 }
 public void MoveHome()
 {
     MoveTo(World.LocationByID(World.Location_ID_Camp));
     HP      = MaxHP;
     Stamina = 100;
 }
Exemple #22
0
        public static Player CreateFromDatabase()
        {
            try
            {
                // This is our connection to the database
                using (SqlConnection connection = new SqlConnection(_connectionString))
                {
                    // Open the connection, so we can perform SQL commands
                    connection.Open();

                    Player player;
                    int    currentLocationID;

                    // Create a SQL command object, that uses the connection to our database
                    // The SqlCommand object is where we create our SQL statement
                    using (SqlCommand savedGameCommand = connection.CreateCommand())
                    {
                        savedGameCommand.CommandType = CommandType.Text;
                        // This SQL statement reads the first rows in teh SavedGame table.
                        // For this program, we should only ever have one row,
                        // but this will ensure we only get one record in our SQL query results.
                        savedGameCommand.CommandText = "SELECT TOP 1 * FROM SavedGame";

                        // Use ExecuteReader when you expect the query to return a row, or rows
                        SqlDataReader reader = savedGameCommand.ExecuteReader();

                        // Check if the query did not return a row/record of data
                        if (!reader.HasRows)
                        {
                            // There is no data in the SavedGame table,
                            // so return null (no saved player data)
                            return(null);
                        }

                        // Get the row/record from the data reader
                        reader.Read();

                        // Get the column values for the row/record
                        int currentHitPoints = (int)reader["CurrentHitPoints"];
                        int maximumHitPoints = (int)reader["MaximumHitPoints"];
                        int gold             = (int)reader["Gold"];
                        int experiencePoints = (int)reader["ExperiencePoints"];
                        int currentWeaponID  = (int)reader["CurrentWeaponID"];
                        currentLocationID = (int)reader["CurrentLocationID"];

                        reader.Close();

                        // Create the Player object, with the saved game values
                        player = Player.CreatePlayerFromDatabase(currentHitPoints, maximumHitPoints, gold,
                                                                 experiencePoints, currentLocationID, currentWeaponID);
                    }

                    // Read the rows/records from the Quest table, and add them to the player
                    using (SqlCommand questCommand = connection.CreateCommand())
                    {
                        questCommand.CommandType = CommandType.Text;
                        questCommand.CommandText = "SELECT * FROM Quest";

                        SqlDataReader reader = questCommand.ExecuteReader();

                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                int  questID     = (int)reader["QuestID"];
                                bool isCompleted = (bool)reader["IsCompleted"];

                                // Build the PlayerQuest item, for this row
                                PlayerQuest playerQuest = new PlayerQuest(World.QuestByID(questID));
                                playerQuest.IsCompleted = isCompleted;

                                // Add the PlayerQuest to the player's property
                                player.Quests.Add(playerQuest);
                            }
                        }

                        reader.Close();
                    }

                    // Read the rows/records from the Inventory table, and add them to the player
                    using (SqlCommand inventoryCommand = connection.CreateCommand())
                    {
                        inventoryCommand.CommandType = CommandType.Text;
                        inventoryCommand.CommandText = "SELECT * FROM Inventory";

                        SqlDataReader reader = inventoryCommand.ExecuteReader();

                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                int inventoryItemID = (int)reader["InventoryItemID"];
                                int quantity        = (int)reader["Quantity"];

                                // Add the item to the player's inventory
                                player.AddItemToInventory(World.ItemByID(inventoryItemID), quantity);
                            }
                        }

                        reader.Close();
                    }

                    // Read the rows/records from the LocationVisited table, and add them to the player
                    using (SqlCommand locationVisitedCommand = connection.CreateCommand())
                    {
                        locationVisitedCommand.CommandType = CommandType.Text;
                        locationVisitedCommand.CommandText = "SELECT * FROM LocationVisited";

                        SqlDataReader reader = locationVisitedCommand.ExecuteReader();

                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                int id = (int)reader["ID"];

                                // Add the item to the player's LocationsVisited property
                                player.LocationsVisited.Add(id);
                            }
                        }

                        reader.Close();
                    }

                    player.CurrentLocation = World.LocationByID(currentLocationID);

                    // Now that the player has been built from the database, return it.
                    return(player);
                }
            }
            catch (Exception ex)
            {
                // Ignore errors. If there is an error, this function will return a "null" player.
            }

            return(null);
        }
Exemple #23
0
        public void UseWeapon(Weapon weapon)
        {
            int damageToMonster = RandomNumberGenerator.NumberBetween(weapon.MinimumDamage, weapon.MaximumDamage);

            _currentMonster.CurrentHitPoints -= damageToMonster;

            RaiseMessage("You hit the " + _currentMonster.Name + " for " + damageToMonster.ToString() + " points.");

            // is monster dead?
            if (_currentMonster.CurrentHitPoints <= 0)
            {
                RaiseMessage("");
                RaiseMessage("You defeated the " + _currentMonster.Name);

                // gain experience
                AddExperiencePoints(_currentMonster.RewardExperiencePoints);
                RaiseMessage("You receive " + _currentMonster.RewardExperiencePoints.ToString() +
                             " experience points");

                // gain gold
                Gold += _currentMonster.RewardGold;
                RaiseMessage("You receive " + _currentMonster.RewardGold.ToString() +
                             " gold");

                // gain loot
                List <InventoryItem> lootedItems = new List <InventoryItem>();
                foreach (LootItem li in _currentMonster.LootTable)
                {
                    if (RandomNumberGenerator.NumberBetween(1, 100) <= li.DropPercentage)
                    {
                        lootedItems.Add(new InventoryItem(li.Details, 1));
                    }
                }

                // default loot
                if (lootedItems.Count == 0)
                {
                    foreach (LootItem li in _currentMonster.LootTable)
                    {
                        if (li.IsDefaultItem)
                        {
                            lootedItems.Add(new InventoryItem(li.Details, 1));
                        }
                    }
                }

                // add loot to inventory
                foreach (InventoryItem ii in lootedItems)
                {
                    AddItemToInventory(ii.Details);

                    if (ii.Quantity == 1)
                    {
                        RaiseMessage("You loot " + ii.Quantity.ToString() + " " + ii.Details.Name);
                    }
                    else
                    {
                        RaiseMessage("You loot " + ii.Quantity.ToString() + " " + ii.Details.NamePlural);
                    }
                }

                RaiseMessage("");

                // move to current location for healing
                MoveTo(CurrentLocation);
            }

            else
            {
                // Monster is alive and does damage
                int damageToPlayer = RandomNumberGenerator.NumberBetween(0, _currentMonster.MaximumDamage);
                RaiseMessage("The " + _currentMonster.Name + " did " + damageToPlayer.ToString() +
                             " points of damage.");
                CurrentHitPoints -= damageToPlayer;

                if (CurrentHitPoints <= 0)
                {
                    // Is player dead?
                    RaiseMessage("The " + _currentMonster.Name + " killed you!!");
                    MoveTo(World.LocationByID(World.LOCATION_ID_HOME));
                }
            }
        }
Exemple #24
0
 private void MoveHome(TTS tts)
 {
     MoveTo(World.LocationByID(World.LOCATION_ID_HOME), tts);
 }
        public static Player CreatePlayerFromXmlString(string xmlPlayerData)
        {
            try
            {
                XmlDocument playerData = new XmlDocument();

                //  playerData.PreserveWhitespace = true;
                playerData.LoadXml(xmlPlayerData);

                int currentHitPoints = Convert.ToInt32(
                    playerData.SelectSingleNode("/Player/Stats/CurrentHitPoints").InnerText);
                int maximumHitPoints = Convert.ToInt32(
                    playerData.SelectSingleNode("/Player/Stats/MaximumHitPoints").InnerText);
                int gold = Convert.ToInt32(
                    playerData.SelectSingleNode("/Player/Stats/Gold").InnerText);
                int experiencePoints = Convert.ToInt32(
                    playerData.SelectSingleNode("/Player/Stats/ExperiencePoints").InnerText);

                Player player = new Player(
                    currentHitPoints, maximumHitPoints, gold, experiencePoints);

                int currentLocationID = Convert.ToInt32(
                    playerData.SelectSingleNode("/Player/Stats/CurrentLocation").InnerText);
                player.CurrentLocation = World.LocationByID(currentLocationID);

                if (playerData.SelectSingleNode("/Player/Stats/CurrentWeaponID") != null)
                {
                    int currentWeaponID = Convert.ToInt32(playerData.SelectSingleNode(
                                                              "/Player/Stats/CurrentWeaponID").InnerText);
                    player.CurrentWeapon = (Weapon)World.ItemByID(currentWeaponID);
                }

                if (playerData.SelectSingleNode("/Player/Stats/CurrentPotionID") != null)
                {
                    int currentPotionID = Convert.ToInt32(playerData.SelectSingleNode(
                                                              "/Player/Stats/CurrentPotionID").InnerText);
                    player.CurrentPotion = (HealingPotion)World.ItemByID(currentPotionID);
                }

                foreach (XmlNode node in playerData.SelectNodes(
                             "/Player/InventoryItems/InventoryItem"))
                {
                    int itemID       = Convert.ToInt32(node.Attributes["ID"].Value);
                    int itemQuantity = Convert.ToInt32(node.Attributes["Quantity"].Value);

                    // refactored from tutorial due to overloading AddItemToInventory with quantity
                    player.AddItemToInventory(World.ItemByID(itemID), itemQuantity);
                }

                foreach (XmlNode node in playerData.SelectNodes(
                             "/Player/PlayerQuests/PlayerQuest"))
                {
                    int  questID          = Convert.ToInt32(node.Attributes["ID"].Value);
                    bool questIsCompleted = Convert.ToBoolean(node.Attributes["IsCompleted"].Value);

                    PlayerQuest playerQuest = new PlayerQuest(World.QuestByID(questID));
                    playerQuest.IsCompleted = questIsCompleted;

                    player.Quests.Add(playerQuest);
                }

                return(player);
            }
            catch
            {
                // If there was an error with the XML data, return a default player object
                return(Player.CreateDefaultPlayer());
            }
        }
Exemple #26
0
        public static Player CreatePlayerFromXmlString(string PLAYER_DATA_FILE_NAME)
        {
            try
            {
                XmlDocument playerData = new XmlDocument();

                playerData.LoadXml(PLAYER_DATA_FILE_NAME);
                string playerName = playerData.SelectSingleNode("/Player/Stats/Name").InnerText;
                // Console.WriteLine("Got name: " + playerName);
                string PC = playerData.SelectSingleNode("/Player/Stats/Class").InnerText;
                // Console.WriteLine("Got class: " + PC);
                string PR = playerData.SelectSingleNode("/Player/Stats/Race").InnerText;
                //Console.WriteLine("Got race: " + PR);
                int currentHitPoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentHitPoints").InnerText);
                // Console.WriteLine("Got current hit points: " + currentHitPoints.ToString());
                int maximumHitPoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/MaximumHitPoints").InnerText);
                // Console.WriteLine("Got max hit points: " + maximumHitPoints.ToString());
                int gold = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Gold").InnerText);
                // Console.WriteLine("Got gold: " + gold.ToString());
                int experiencePoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/ExperiencePoints").InnerText);
                //Console.WriteLine("Got experience: " + experiencePoints.ToString());
                Factions factionString = (Factions)Enum.Parse(typeof(Factions), (playerData.SelectSingleNode("/Player/Stats/Faction").InnerText), true);
                //Console.WriteLine("Got Faction: " + factionString.ToString());
                int alignment = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Alignment").InnerText);
                //Console.WriteLine("Got Alignment: " + alignment.ToString());
                int     equiptString = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentWeapon").InnerText);
                IWeapon equipt       = World.WeaponByID(equiptString);
                // Console.WriteLine("Got equipt weapon: " + equipt.Name.ToString());

                Player player = new Player(playerName, PC, PR, gold, currentHitPoints, maximumHitPoints, (Weapon)equipt, false, true, factionString, alignment);

                int currentLocationID = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentLocation").InnerText);
                Player.CurrentLocation = World.LocationByID(currentLocationID);

                if (playerData.SelectSingleNode("/Player/Stats/CurrentWeapon") != null)
                {
                    int currentWeaponID = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentWeapon").InnerText);
                    player.Equipt = (Weapon)World.WeaponByID(currentWeaponID);
                }

                foreach (XmlNode node in playerData.SelectNodes("/Player/InventoryItems/InventoryItem"))
                {
                    int id       = Convert.ToInt32(node.Attributes["ID"].Value);
                    int quantity = Convert.ToInt32(node.Attributes["Quantity"].Value);

                    if (id > 100 && id <= 200)
                    {
                        for (int i = 0; i < quantity; i++)
                        {
                            player.AddItemToInventory((Weapon)World.WeaponByID(id));
                        }
                    }
                    else
                    {
                        for (int i = 0; i < quantity; i++)
                        {
                            player.AddItemToInventory(World.ItemByID(id));
                        }
                    }
                }

                return(player);
            }
            catch (Exception ex)
            {
                // If there was an error with the XML data, return a default player object
                Console.WriteLine(ex.ToString());
                //return CreateDefaultPlayer();
                return(null);
            }
        }
Exemple #27
0
        //////
        private void PlayerOnPropertyChanged(object sender, PropertyChangedEventArgs protertyChangedEventArgs)
        {
            if (protertyChangedEventArgs.PropertyName == "Weapon")
            {
                cobweapons.DataSource = _player.Weapons;
                if (!_player.Weapons.Any())
                {
                    cobweapons.Visible = false;
                }
            }
            if (_player.CurrentLocation == World.LocationByID(World.Location_ID_Camp))
            {
                Restandsleep.Text = "sleep";
            }
            else
            {
                Restandsleep.Text = "rest";
            }
            if (protertyChangedEventArgs.PropertyName == "Potions")
            {
                cobpotion.DataSource = _player.Potions;
                if (!_player.Potions.Any())
                {
                    Inventor.Enabled  = false;
                    cobpotion.Visible = false;
                }
            }
            if (protertyChangedEventArgs.PropertyName == "CurrentLocation")
            {
                North.Enabled = (_player.CurrentLocation.LocationToNorth != null);
                East.Enabled  = (_player.CurrentLocation.LocationToEast != null);
                South.Enabled = (_player.CurrentLocation.LocationToSouth != null);
                West.Enabled  = (_player.CurrentLocation.LocationToWest != null);
                if ((_player.CurrentLocation.LocationToNorth != null))
                {
                    North.Text = _player.CurrentLocation.LocationToNorth.Name;
                }
                else
                {
                    North.Text = " ";
                }
                if ((_player.CurrentLocation.LocationToEast != null))
                {
                    East.Text = _player.CurrentLocation.LocationToEast.Name;
                }
                else
                {
                    East.Text = " ";
                }
                if ((_player.CurrentLocation.LocationToSouth != null))
                {
                    South.Text = _player.CurrentLocation.LocationToSouth.Name;
                }
                else
                {
                    South.Text = " ";
                }
                if ((_player.CurrentLocation.LocationToWest != null))
                {
                    West.Text = _player.CurrentLocation.LocationToWest.Name;
                }
                else
                {
                    West.Text = " ";
                }
                textBox1.Text += _player.CurrentLocation.Description + Environment.NewLine;

                btnTrade.Enabled = (_player.CurrentLocation.Vending != null);
                if (btnTrade.Enabled = (_player.CurrentLocation.Vending != null))
                {
                    btnTrade.Text = "Shop";
                }
                else
                {
                    btnTrade.Text = " ";
                }
                clock(15);
            }
            if (protertyChangedEventArgs.PropertyName == "CurrentMonster")
            {
                if (_player.CurrentMonster == null)
                {
                    Attack.Enabled = false;
                }
                else if (_player.CurrentMonster != null)
                {
                    Attack.Enabled = _player.Weapons.Any();
                    Attack.Text    = "Attack";
                }
            }
            if (protertyChangedEventArgs.PropertyName == "Stats")
            {
                if (_player.Strength != Convert.ToInt32(Strength.Text))
                {
                    Strength.Text     = Convert.ToString(_player.Strength);
                    StrengthBar.Value = Convert.ToInt32(Strength.Text);
                }
                if (_player.Speed != Convert.ToInt32(Speed.Text))
                {
                    Speed.Text         = Convert.ToString(_player.Speed);
                    SpeedBar.Value     = Convert.ToInt32(Speed.Text);
                    StaminaBar.Maximum = 100 + ((int)_player.Speed / 5);
                }
                if (_player.Endurance != Convert.ToInt32(Endurance.Text))
                {
                    Endurance.Text     = Convert.ToString(_player.Endurance);
                    EnduranceBar.Value = Convert.ToInt32(Endurance.Text);
                    _player.MaxHP      = 100 + _player.Endurance;
                }
                if (_player.Sight != Convert.ToInt32(Sight.Text))
                {
                    Sight.Text     = Convert.ToString(_player.Sight);
                    SightBar.Value = Convert.ToInt32(Sight.Text);
                }
                if (_player.Intelligence != Convert.ToInt32(Intelligence.Text))
                {
                    Intelligence.Text     = Convert.ToString(_player.Intelligence);
                    IntelligenceBar.Value = Convert.ToInt32(Intelligence.Text);
                }
            }

            if (_player.Stamina > StaminaBar.Maximum)
            {
                _player.Stamina = StaminaBar.Maximum;
            }
            HealthBar.Maximum = _player.MaxHP;
            if (_player.HP > _player.MaxHP)
            {
                _player.HP = _player.MaxHP;
            }
            HealthBar.Value = Convert.ToInt32(_player.HP);
            Health.Text     = Convert.ToString(_player.HP);
        }