Exemplo n.º 1
0
        //Mass constructor =]
        public Hero(string Name, HeroPrimaryAttr PrimaryAttr, int InitialStr, int InitialAgi, int InitialInt,
                    int InitialHP, float InitialHPRegen, int InitialMana, float InitialManaRegen,
                    int MovementSpeed, float StrPerLevel, float AgiPerLevel, float IntPerLevel,
                    float Armor, float MagicArmor, HeroAttackType AttackType, int MinDamage, int MaxDamage,
                    int AttackRange, float BAT, Skill FirstSkill, Skill SecondSkill, Skill ThirdSkill, Skill UltimateSkill)
        {
            m_Name = Name;

            m_PrimaryAttr = PrimaryAttr;
            m_InitialHP = InitialHP;
            m_InitialHPRegen = InitialHPRegen;
            m_InitialMana = InitialMana;
            m_InitialManaRegen = InitialManaRegen;

            m_InitialStr = InitialStr;
            m_InitialAgi = InitialAgi;
            m_InitialInt = InitialInt;

            m_MovementSpeed = MovementSpeed;
            m_StrPerLevel = StrPerLevel;
            m_AgiPerLevel = AgiPerLevel;
            m_IntPerLevel = IntPerLevel;

            m_Armor = Armor;
            m_MagicArmor = MagicArmor;

            m_AttackType = AttackType;
            m_MinDamage = MinDamage;
            m_MaxDamage = MaxDamage;
            m_AttackRange = AttackRange;
            m_BAT = BAT;

            m_Skills[0] = FirstSkill;
            m_Skills[1] = SecondSkill;
            m_Skills[2] = ThirdSkill;
            m_Skills[3] = UltimateSkill;
        }
Exemplo n.º 2
0
        public static void loadHeroesFromFile()
        {
            ArrayList xml_list = new ArrayList();
            Heroes = new Hashtable();
            Hero newHero;
            Skill[] heroSkills;

            string temp;
            string temp2;

            //Hero attributes:
            string heroName;
            string heroPortrait;

            HeroPrimaryAttr heroPrim;
            int heroInitialHP;
            int heroInitialMana;
            float heroInitialHPRegen;
            float heroInitialManaRegen;

            int heroIStr;
            int heroIAgi;
            int heroIInt;

            int heroMovS;
            float heroStrPerLevel;
            float heroAgiPerLevel;
            float heroIntPerLevel;

            float heroArmor;
            float heroMagicArmor;

            HeroAttackType heroAttackType;
            int heroMinDamage;
            int heroMaxDamage;
            int heroAttackRange;
            float heroBAT;

            //Loading xml list file
            try
            {
                XmlReader reader = XmlReader.Create("./data/heroes.xml");

                reader.ReadStartElement("HoNBuildPlanner");
                reader.ReadStartElement("HeroList");

                while (reader.IsStartElement("File"))
                {
                    xml_list.Add(reader.ReadElementString("File"));
                }

                reader.ReadEndElement();
                reader.ReadEndElement();
                reader.Close();
            }
            catch (Exception ex)
            {
                exceptionWindow ew = new exceptionWindow(ex.ToString());
                ew.ShowDialog();
            }

            //Parsing heroes xml files

            while (xml_list.Count > 0)
            {
                try
                {
                    XmlReader reader = XmlReader.Create("./data/" + xml_list[0].ToString());

                    reader.ReadStartElement("HoNBuildPlanner");

                    while (reader.IsStartElement("Hero"))
                    {
                        heroSkills = new Skill[4];

                        reader.ReadStartElement("Hero");

                        reader.ReadStartElement("Name");
                        heroName = reader.ReadString();
                        reader.ReadEndElement();

                        reader.ReadStartElement("PrimaryAttribute");
                        temp = reader.ReadString();
                        reader.ReadEndElement();

                        switch (temp)
                        {
                            case "Strength":
                                heroPrim = HeroPrimaryAttr.Strength;
                                break;
                            case "Agility":
                                heroPrim = HeroPrimaryAttr.Agility;
                                break;
                            case "Intelligence":
                                heroPrim = HeroPrimaryAttr.Intelligence;
                                break;
                            default:
                                heroPrim = HeroPrimaryAttr.Strength;
                                break;
                        }

                        reader.ReadStartElement("InitialHP");
                        heroInitialHP = int.Parse(reader.ReadString());
                        reader.ReadEndElement();

                        reader.ReadStartElement("InitialHPRegen");
                        heroInitialHPRegen = float.Parse(reader.ReadString());
                        reader.ReadEndElement();

                        reader.ReadStartElement("InitialMana");
                        heroInitialMana = int.Parse(reader.ReadString());
                        reader.ReadEndElement();

                        reader.ReadStartElement("InitialManaRegen");
                        heroInitialManaRegen = float.Parse(reader.ReadString());
                        reader.ReadEndElement();

                        reader.ReadStartElement("InitialAttirbutes");

                        reader.ReadStartElement("Strength");
                        heroIStr = int.Parse(reader.ReadString());
                        reader.ReadEndElement();

                        reader.ReadStartElement("Agility");
                        heroIAgi = int.Parse(reader.ReadString());
                        reader.ReadEndElement();

                        reader.ReadStartElement("Intelligence");
                        heroIInt = int.Parse(reader.ReadString());
                        reader.ReadEndElement();

                        reader.ReadEndElement();

                        reader.ReadStartElement("MovementSpeed");
                        heroMovS = int.Parse(reader.ReadString());
                        reader.ReadEndElement();

                        reader.ReadStartElement("PerLevel");

                        reader.ReadStartElement("Strength");
                        heroStrPerLevel = float.Parse(reader.ReadString());
                        reader.ReadEndElement();

                        reader.ReadStartElement("Agility");
                        heroAgiPerLevel = float.Parse(reader.ReadString());
                        reader.ReadEndElement();

                        reader.ReadStartElement("Intelligence");
                        heroIntPerLevel = float.Parse(reader.ReadString());
                        reader.ReadEndElement();

                        reader.ReadEndElement();

                        reader.ReadStartElement("Armor");
                        heroArmor = float.Parse(reader.ReadString());
                        reader.ReadEndElement();

                        reader.ReadStartElement("MagicArmor");
                        heroMagicArmor = float.Parse(reader.ReadString());
                        reader.ReadEndElement();

                        reader.ReadStartElement("AttackType");
                        temp = reader.ReadString();
                        reader.ReadEndElement();

                        switch (temp)
                        {
                            case "Melee":
                                heroAttackType = HeroAttackType.Melee;
                                break;
                            case "Ranged":
                                heroAttackType = HeroAttackType.Ranged;
                                break;
                            default:
                                heroAttackType = HeroAttackType.Melee;
                                break;
                        }

                        reader.ReadStartElement("MinDamage");
                        heroMinDamage = int.Parse(reader.ReadString());
                        reader.ReadEndElement();

                        reader.ReadStartElement("MaxDamage");
                        heroMaxDamage = int.Parse(reader.ReadString());
                        reader.ReadEndElement();

                        reader.ReadStartElement("Range");
                        heroAttackRange = int.Parse(reader.ReadString());
                        reader.ReadEndElement();

                        reader.ReadStartElement("BAT");
                        heroBAT = float.Parse(reader.ReadString());
                        reader.ReadEndElement();

                        reader.ReadStartElement("Skills");

                        for (int i = 0; i < 4; i++)
                        {
                            reader.ReadStartElement("Skill");

                            reader.ReadStartElement("Name");
                            temp = reader.ReadString();
                            reader.ReadEndElement();

                            reader.ReadStartElement("Lore");
                            temp2 = reader.ReadString();
                            reader.ReadEndElement();
                            heroSkills[i] = new Skill(temp, temp2);

                            reader.ReadStartElement("image");
                            temp = reader.ReadString();
                            reader.ReadEndElement();

                            heroSkills[i].setImage(temp);

                            reader.ReadEndElement();
                        }

                        reader.ReadEndElement();

                        reader.ReadStartElement("portrait");
                        heroPortrait = reader.ReadString();
                        reader.ReadEndElement();

                        reader.ReadEndElement();

                        newHero = new Hero(heroName, heroPrim, heroIStr, heroIAgi, heroIInt, heroInitialHP, heroInitialHPRegen,
                                            heroInitialMana, heroInitialManaRegen, heroMovS, heroStrPerLevel, heroAgiPerLevel,
                                            heroIntPerLevel, heroArmor, heroMagicArmor, heroAttackType,
                                            heroMinDamage, heroMaxDamage, heroAttackRange, heroBAT,
                                            heroSkills[0], heroSkills[1], heroSkills[2], heroSkills[3]);

                        newHero.Portrait(heroPortrait);

                        Heroes.Add(heroName, newHero);
                    }

                    reader.ReadEndElement();
                    reader.Close();
                }
                catch (Exception ex)
                {
                    exceptionWindow ew = new exceptionWindow(ex.ToString());
                    ew.ShowDialog();
                }

                xml_list.RemoveAt(0);
            }

            return;
        }