public static HeroSerialize GetHeroSerialize(string heroID) { BinaryFormatter formatter = new BinaryFormatter(); FileStream myFile = new FileStream(ThereIsConstants.Path.Datas_Path + ThereIsConstants.Path.DoubleSlash + FirstNameOfFile + heroID + EndNameOfFile, FileMode.Open, FileAccess.Read); HeroSerialize heroSerialize = (HeroSerialize)formatter.Deserialize(myFile); return(heroSerialize); }
/// <summary> /// Loading the ordinary Information of this hero from /// the file. /// loading <see cref="Name"/>, /// <see cref="HeroSkill"/> (by: <see cref="HeroSkill.GetHeroSkill(string, uint)"/> /// which string is <see cref="HeroSerialize.HeroSkillsString"/> and /// uint is <see cref="HeroSerialize.HeroSkillsCount"/>), /// <see cref="HeroType"/>. /// </summary> /// <param name="heroID"></param> protected virtual void LoadMe(StrongString heroID) { if (this.MyRes is null) { this.MyRes = new WotoRes(typeof(Hero)); } //--------------------------------------------- this.HeroSerialize = HeroSerialize.GetHeroSerialize(heroID.GetValue()); this.Name = this.HeroSerialize.HeroName; this.HeroSkill = HeroSkill.GetHeroSkill(this.HeroSerialize.HeroSkillsString, this.HeroSerialize.HeroSkillsCount, this); this.HeroType = this.HeroSerialize.HeroType; this.HeroElement = this.HeroSerialize.HeroElement; //--------------------------------------------- }
/// <summary> /// Create a new HeroSerialize. /// Use this method if and only if you wanna create a new hero /// in the game. /// </summary> /// <param name="heroID"> /// the HeroID, we will save and load this hero's inforamation /// with this ID to the specified File name in the /// Data files. /// check here for more information: <see cref="Serialize()"/> /// </param> /// <param name="heroName"></param> /// <param name="heroSkillsString"> /// HeroSkillsString, you should get is from /// <see cref="HeroSkill.GetForSerialize()"/>. /// </param> /// <param name="heroSkillsCount"></param> /// <param name="type"></param> /// <param name="heroElement"></param> /// <param name="hP_rate"></param> /// <param name="aTK_rate"></param> /// <param name="iNT_rate"></param> /// <param name="dEF_rate"></param> /// <param name="rES_rate"></param> /// <param name="sPD_rate"></param> /// <param name="pEN_rate"></param> /// <param name="bLock_rate"></param> /// <param name="imagePath"> /// The path of the Image of this hero. /// </param> /// <returns></returns> public static HeroSerialize GenerateHeroSerialize( string heroID, string heroName, string heroSkillsString, uint heroSkillsCount, HeroType type, PlayerElement heroElement, Unit hP_rate, Unit aTK_rate, Unit iNT_rate, Unit dEF_rate, Unit rES_rate, Unit sPD_rate, Unit pEN_rate, Unit bLock_rate, string imagePath ) { HeroSerialize heroSerialize = new HeroSerialize() { heroID = heroID, heroName = heroName, heroSkillsString = heroSkillsString, heroSkillsCount = heroSkillsCount, heroType = type, heroElement = heroElement, //-------------------------- HP_Rate = hP_rate, ATK_Rate = aTK_rate, INT_Rate = iNT_rate, DEF_Rate = dEF_rate, RES_Rate = rES_rate, SPD_Rate = sPD_rate, PEN_Rate = pEN_rate, Block_Rate = bLock_rate, }; File.Copy(imagePath, ThereIsConstants.Path.Datas_Path + ThereIsConstants.Path.DoubleSlash + FirstNameOfImage_580_500_File + heroID + EndNameOfFile, true); return(heroSerialize); }
/// <summary> /// Create a new hero in the Game. /// This method will create a new hero just in the /// game data. /// </summary> public static void CreateHero(HeroSerialize heroSerialize) { heroSerialize.Serialize(); }
//------------------------------------------------- public static void Serialize(HeroSerialize heroSerialize) { heroSerialize.Serialize(); }