Exemple #1
0
        public bool ReadPlayer(string playerName, out Player player)
        {
            player = null;

            string fileName = GetSaveFileName(playerName);
            if (!System.IO.File.Exists(fileName)) return false;

            using (StreamReader sr = new StreamReader(fileName))
            {
                string strLine = "";

                while (!sr.EndOfStream)
                {
                    strLine = sr.ReadLine();

                    // uid,name,level,exp,a,d,p,k
                    string[] datas = null;
                    Hero hero = null;
                    {
                        datas = strLine.Split(new char[] { ',' });

                        player = new Player();
                        player._id = System.Convert.ToInt32(datas[0]);
                        player._name = datas[1];

                        hero = new Hero();
                        hero._id = player._id;
                        hero._name = player._name;
                        hero._level = System.Convert.ToInt32(datas[2]);
                        hero._experience = System.Convert.ToInt32(datas[3]);
                        hero._attack = System.Convert.ToInt32(datas[4]);
                        hero._defense = System.Convert.ToInt32(datas[5]);
                        hero._power = System.Convert.ToInt32(datas[6]);
                        hero._knowledge = System.Convert.ToInt32(datas[7]);
                    }

                    // skillId,skillLevel,...
                    {
                        datas = strLine.Split(new char[] { ',' });

                        for (int i = 0; i < datas.Length; i += 2)
                        {
                            int skillId = System.Convert.ToInt32(datas[i]);
                            int skillLevel = System.Convert.ToInt32(datas[i + 1]);

                            Skill skill = new Skill();
                            skill.CopyFrom((Skill)Heroes.Core.Setting._skills[skillId]);
                            skill._level = skillLevel;

                            hero._skills.Add(skill._id, skill);
                        }
                    }

                    // spells
                    {
                        datas = strLine.Split(new char[] { ',' });

                        for (int i = 0; i < datas.Length; i++)
                        {
                            int spellId = System.Convert.ToInt32(datas[i]);

                            Spell spell = new Spell();
                            spell.CopyFrom((Spell)Heroes.Core.Setting._spells[spellId]);

                            hero._spells.Add(spell._id, spell);
                        }
                    }

                    // artifacts
                }
            }

            return true;
        }