Ejemplo n.º 1
0
        public Combat(Player player, Monster monster)
        {
            _player = player;
            _monster = monster;

            playerInit = RollInitiative(_player);
            monsterInit = RollInitiative(_monster);
        }
Ejemplo n.º 2
0
        public static Player CreatePlayerFromXmlString(string xmlPlayerData)
        {
            try
            {
                XmlDocument playerData = new XmlDocument();

                playerData.LoadXml(xmlPlayerData);

                string name = playerData.SelectSingleNode("/Player/Stats/Name").InnerText;

                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 str = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Strength").InnerText);
                int dex = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Dexterity").InnerText);
                int con = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Constitution").InnerText);
                int intel = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Intelligence").InnerText);
                int wis = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Wisdom").InnerText);
                int charisma = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Charisma").InnerText);

                Player player = new Player(currentHitPoints, maximumHitPoints, str, dex, con, intel, wis, charisma, name);

                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 CreateDefaultPlayer();
            }
        }
Ejemplo n.º 3
0
        public static Player CreateDefaultPlayer()
        {
            Player player = new Player(10, 10, 8, 8, 8, 8, 8, 8, "Bob");
            player.inventory.Add(new InventoryItem(World.ItemByID(World.WEAPON_ID_SHORT_SWORD), 1));
            player.currentLocation = World.LocationByID(World.LOCATION_ID_HOME);

            return player;
        }