using LinePutScript; using LinePutScript.Converter; using System; namespace VPet_Simulator.Core { /// /// 游戏存档 /// public class GameSave { /// /// 宠物名字 /// [Line(name: "name")] public string Name; /// /// 金钱 /// [Line(Type = LPSConvert.ConvertType.ToFloat, Name = "money")] public double Money; /// /// 经验值 /// [Line(type: LPSConvert.ConvertType.ToFloat, name: "exp")] public double Exp; /// /// 等级 /// public int Level => (int)(Math.Sqrt(Exp) / 5) + 1; /// /// 升级所需经验值 /// /// public int LevelUpNeed() => (int)(Math.Pow((Level) * 5, 2)); /// /// 体力 0-100 /// public double Strength { get => strength; set => strength = Math.Min(100, Math.Max(0, value)); } [Line(Type = LPSConvert.ConvertType.ToFloat)] private double strength; /// /// 待补充的体力,随着时间缓慢加给桌宠 /// //让游戏更有游戏性 [Line(Type = LPSConvert.ConvertType.ToFloat)] public double StoreStrength; /// /// 变化 体力 /// public double ChangeStrength = 0; public void StrengthChange(double value) { ChangeStrength += value; Strength += value; } /// /// 饱腹度 /// public double StrengthFood { get => strengthFood; set => strengthFood = Math.Min(100, Math.Max(0, value)); } [Line(Type = LPSConvert.ConvertType.ToFloat)] private double strengthFood; /// /// 待补充的饱腹度,随着时间缓慢加给桌宠 /// //让游戏更有游戏性 [Line(Type = LPSConvert.ConvertType.ToFloat)] public double StoreStrengthFood; public void StrengthChangeFood(double value) { ChangeStrengthFood += value; StrengthFood += value; } /// /// 变化 食物 /// public double ChangeStrengthFood = 0; /// /// 口渴度 /// public double StrengthDrink { get => strengthDrink; set => strengthDrink = Math.Min(100, Math.Max(0, value)); } [Line(Type = LPSConvert.ConvertType.ToFloat)] private double strengthDrink; /// /// 待补充的口渴度,随着时间缓慢加给桌宠 /// //让游戏更有游戏性 [Line(Type = LPSConvert.ConvertType.ToFloat)] public double StoreStrengthDrink; /// /// 变化 口渴度 /// public double ChangeStrengthDrink = 0; public void StrengthChangeDrink(double value) { ChangeStrengthDrink += value; StrengthDrink += value; } /// /// 心情 /// public double Feeling { get => feeling; set => feeling = Math.Min(100, Math.Max(0, value)); } [Line(Type = LPSConvert.ConvertType.ToFloat)] private double feeling; /// /// 待补充的心情,随着时间缓慢加给桌宠 /// //让游戏更有游戏性 [Line(Type = LPSConvert.ConvertType.ToFloat)] public double StoreFeeling; /// /// 变化 心情 /// public double ChangeFeeling = 0; public void FeelingChange(double value) { ChangeFeeling += value; Feeling += value; } /// /// 健康(生病)(隐藏) /// public double Health { get => health; set => health = Math.Min(100, Math.Max(0, value)); } [Line(Type = LPSConvert.ConvertType.ToFloat)] private double health; /// /// 好感度(隐藏)(累加值) /// public double Likability { get => likability; set => likability = Math.Min(90 + Level * 10, Math.Max(0, value)); } [Line(Type = LPSConvert.ConvertType.ToFloat)] private double likability; private int cleantick = 10; /// /// 清除变化 /// public void CleanChange(bool force = false) { if (--cleantick <= 0 || force) { ChangeStrength /= 2; ChangeFeeling /= 2; ChangeStrengthDrink /= 2; ChangeStrengthFood /= 2; cleantick = 10; } } /// /// 取回被储存的体力 /// public void StoreTake() { StoreFeeling /= 2; if (Math.Abs(StoreFeeling) < 1) StoreFeeling = 0; else FeelingChange(StoreFeeling); StoreStrength /= 2; if (Math.Abs(StoreStrength) < 1) StoreStrength = 0; else StrengthChange(StoreStrength); StoreStrengthDrink /= 2; if (Math.Abs(StoreStrengthDrink) < 1) StoreStrengthDrink = 0; else StrengthChange(StoreStrengthDrink); StoreStrengthFood /= 2; if (Math.Abs(StoreStrengthFood) < 1) StoreStrengthFood = 0; else StrengthChange(StoreStrengthFood); } public void EatFood(IFood food) { Exp += food.Exp; var tmp = food.Strength / 2; StrengthChange(tmp); StoreStrength += tmp; tmp = food.StrengthFood / 2; StrengthChangeFood(tmp); StoreStrengthFood += tmp; tmp = food.StrengthDrink / 2; StrengthChangeDrink(tmp); StoreStrengthDrink += tmp; tmp = food.Feeling / 2; FeelingChange(tmp); StoreFeeling += tmp; Health += food.Health; Likability += food.Likability; } /// /// 宠物状态模式 /// public enum ModeType { /// /// 高兴 /// Happy, /// /// 普通 /// Nomal, /// /// 状态不佳 /// PoorCondition, /// /// 生病(躺床) /// Ill } [Line(name: "mode")] public ModeType Mode = ModeType.Nomal; /// /// 计算宠物当前状态 /// public ModeType CalMode() { int realhel = 60 - (Feeling >= 80 ? 20 : 0) - (Likability >= 80 ? 20 : (Likability >= 40 ? 10 : 0)); //先从最次的开始 if (Health <= realhel) { //可以确认从状态不佳和生病二选一 if (Health <= realhel / 2) {//生病 return ModeType.Ill; } else { return ModeType.PoorCondition; } } //然后判断是高兴还是普通 else if (Feeling >= 80 - (Likability >= 80 ? 20 : (Likability >= 40 ? 10 : 0))) { return ModeType.Happy; } else { return ModeType.Nomal; } } /// /// 新游戏 /// public GameSave(string name) { Name = name; Money = 100; Exp = 0; Strength = 100; StrengthFood = 100; StrengthDrink = 100; Feeling = 60; Health = 100; Likability = 0; Mode = CalMode(); } /// /// 读档 /// public GameSave() { //Money = line.GetFloat("money"); //Name = line.Info; //Exp = line.GetInt("exp"); //Strength = line.GetFloat("strength"); //StrengthDrink = line.GetFloat("strengthdrink"); //StrengthFood = line.GetFloat("strengthfood"); //Feeling = line.GetFloat("feeling"); //Health = line.GetFloat("health"); //Likability = line.GetFloat("likability"); //Mode = CalMode(); } /// /// 读档 /// public static GameSave Load(ILine data) => LPSConvert.DeserializeObject(data); /// /// 存档 /// /// 存档行 public Line ToLine() { //Line save = new Line("vpet", Name); //save.SetFloat("money", Money); //save.SetInt("exp", Exp); //save.SetFloat("strength", Strength); //save.SetFloat("strengthdrink", StrengthDrink); //save.SetFloat("strengthfood", StrengthFood); //save.SetFloat("feeling", Feeling); //save.SetFloat("health", Health); //save.SetFloat("Likability", Likability); return LPSConvert.SerializeObject(this, "vpet"); } } }