VPet/VPet-Simulator.Core/Handle/GameSave.cs

356 lines
11 KiB
C#
Raw Normal View History

2022-12-13 07:10:18 +00:00
using LinePutScript;
2023-05-09 23:16:58 +00:00
using LinePutScript.Converter;
2022-12-13 07:10:18 +00:00
using System;
2023-11-24 04:16:29 +00:00
using static VPet_Simulator.Core.IGameSave;
2022-12-13 07:10:18 +00:00
namespace VPet_Simulator.Core
{
/// <summary>
/// 游戏存档
/// </summary>
2023-11-24 04:16:29 +00:00
public class GameSave : IGameSave
2022-12-13 07:10:18 +00:00
{
2023-01-11 13:10:18 +00:00
/// <summary>
/// 宠物名字
/// </summary>
2023-05-10 03:13:34 +00:00
[Line(name: "name")]
2023-12-12 08:06:49 +00:00
public string Name { get; set; }
2023-01-20 12:42:00 +00:00
2022-12-13 07:10:18 +00:00
/// <summary>
/// 金钱
/// </summary>
2023-07-16 23:58:09 +00:00
[Line(Type = LPSConvert.ConvertType.ToFloat, Name = "money")]
2023-12-12 08:06:49 +00:00
public double Money { get; set; }
2022-12-13 07:10:18 +00:00
/// <summary>
/// 经验值
/// </summary>
2023-12-12 08:06:49 +00:00
[Line(type: LPSConvert.ConvertType.ToFloat, name: "exp")] public double Exp { get; set; }
2022-12-13 07:10:18 +00:00
/// <summary>
/// 等级
/// </summary>
2023-12-12 08:06:49 +00:00
public int Level => Exp < 0 ? 1 : (int)(Math.Sqrt(Exp) / 10) + 1;
2022-12-13 07:10:18 +00:00
/// <summary>
/// 升级所需经验值
/// </summary>
/// <returns></returns>
2023-12-12 08:06:49 +00:00
public int LevelUpNeed() => (int)(Math.Pow((Level) * 10, 2));
2022-12-13 07:10:18 +00:00
/// <summary>
/// 体力 0-100
/// </summary>
2023-12-12 08:06:49 +00:00
public double Strength { get => strength; set => strength = Math.Min(StrengthMax, Math.Max(0, value)); }
public double StrengthMax { get; } = 100;
2023-12-12 08:06:49 +00:00
2023-07-23 20:46:21 +00:00
[Line(Type = LPSConvert.ConvertType.ToFloat, IgnoreCase = true)]
protected double strength { get; set; }
2022-12-13 07:10:18 +00:00
/// <summary>
2023-06-03 21:51:58 +00:00
/// 待补充的体力,随着时间缓慢加给桌宠
/// </summary>//让游戏更有游戏性
2023-07-23 20:46:21 +00:00
[Line(Type = LPSConvert.ConvertType.ToFloat, IgnoreCase = true)]
2023-06-18 18:11:40 +00:00
public double StoreStrength { get; set; }
2023-06-03 21:51:58 +00:00
/// <summary>
2023-01-20 12:42:00 +00:00
/// 变化 体力
/// </summary>
2023-12-12 08:06:49 +00:00
public double ChangeStrength { get; set; } = 0;
public void StrengthChange(double value)
2023-01-20 12:42:00 +00:00
{
ChangeStrength += value;
Strength += value;
}
/// <summary>
2022-12-13 07:10:18 +00:00
/// 饱腹度
/// </summary>
2023-12-12 08:06:49 +00:00
public double StrengthFood
2023-06-08 11:44:41 +00:00
{
get => strengthFood; set
{
value = Math.Min(100, value);
if (value <= 0)
{
Health += value;
strengthFood = 0;
}
else
strengthFood = value;
}
}
2023-05-09 23:16:58 +00:00
[Line(Type = LPSConvert.ConvertType.ToFloat)]
2023-07-23 20:46:21 +00:00
protected double strengthFood { get; set; }
2023-06-03 21:51:58 +00:00
/// <summary>
/// 待补充的饱腹度,随着时间缓慢加给桌宠
/// </summary>//让游戏更有游戏性
[Line(Type = LPSConvert.ConvertType.ToFloat)]
2023-12-12 08:06:49 +00:00
public double StoreStrengthFood { get; set; }
public void StrengthChangeFood(double value)
2023-01-20 12:42:00 +00:00
{
ChangeStrengthFood += value;
StrengthFood += value;
}
/// <summary>
/// 变化 食物
/// </summary>
2023-12-12 08:06:49 +00:00
public double ChangeStrengthFood { get; set; } = 0;
2022-12-13 07:10:18 +00:00
/// <summary>
/// 口渴度
/// </summary>
2023-12-12 08:06:49 +00:00
public double StrengthDrink
2023-06-08 11:44:41 +00:00
{
get => strengthDrink; set
{
value = Math.Min(100, value);
if (value <= 0)
{
Health += value;
strengthDrink = 0;
}
else
strengthDrink = value;
}
}
2022-12-13 07:10:18 +00:00
2023-05-09 23:16:58 +00:00
[Line(Type = LPSConvert.ConvertType.ToFloat)]
2023-07-23 20:46:21 +00:00
protected double strengthDrink { get; set; }
2022-12-13 07:10:18 +00:00
/// <summary>
2023-06-03 21:51:58 +00:00
/// 待补充的口渴度,随着时间缓慢加给桌宠
/// </summary>//让游戏更有游戏性
[Line(Type = LPSConvert.ConvertType.ToFloat)]
2023-12-12 08:06:49 +00:00
public double StoreStrengthDrink { get; set; }
2023-06-03 21:51:58 +00:00
/// <summary>
2023-01-20 12:42:00 +00:00
/// 变化 口渴度
/// </summary>
2023-12-12 08:06:49 +00:00
public double ChangeStrengthDrink { get; set; } = 0;
2023-01-20 12:42:00 +00:00
public void StrengthChangeDrink(double value)
{
ChangeStrengthDrink += value;
StrengthDrink += value;
}
/// <summary>
2022-12-13 07:10:18 +00:00
/// 心情
/// </summary>
2023-12-12 08:06:49 +00:00
public double Feeling
2023-07-16 23:58:09 +00:00
{
get => feeling; set
{
value = Math.Min(100, value);
if (value <= 0)
{
Health += value / 2;
Likability += value / 2;
feeling = 0;
}
else
feeling = value;
}
}
2022-12-13 07:10:18 +00:00
2023-05-09 23:16:58 +00:00
[Line(Type = LPSConvert.ConvertType.ToFloat)]
2023-07-23 20:46:21 +00:00
protected double feeling { get; set; }
2022-12-13 07:10:18 +00:00
/// <summary>
2023-06-03 21:51:58 +00:00
/// 待补充的心情,随着时间缓慢加给桌宠
/// </summary>//让游戏更有游戏性
[Line(Type = LPSConvert.ConvertType.ToFloat)]
2023-06-18 18:11:40 +00:00
public double StoreFeeling { get; set; }
2023-06-03 21:51:58 +00:00
/// <summary>
2023-01-20 12:42:00 +00:00
/// 变化 心情
/// </summary>
2024-02-22 18:46:09 +00:00
public double ChangeFeeling { get; set; } = 0;
2023-12-12 08:06:49 +00:00
public void FeelingChange(double value)
2023-01-20 12:42:00 +00:00
{
ChangeFeeling += value;
Feeling += value;
}
/// <summary>
2022-12-13 07:10:18 +00:00
/// 健康(生病)(隐藏)
/// </summary>
public double Health { get => health; set => health = Math.Min(100, Math.Max(0, value)); }
2023-05-09 23:16:58 +00:00
[Line(Type = LPSConvert.ConvertType.ToFloat)]
2023-07-23 20:46:21 +00:00
protected double health { get; set; }
2022-12-13 07:10:18 +00:00
/// <summary>
/// 好感度(隐藏)(累加值)
/// </summary>
2023-06-08 11:44:41 +00:00
public double Likability
{
get => likability; set
{
2024-02-22 18:46:09 +00:00
var max = LikabilityMax;
2023-06-08 11:44:41 +00:00
value = Math.Max(0, value);
if (value > max)
{
likability = max;
Health += value - max;
}
else
likability = value;
}
}
2022-12-13 07:10:18 +00:00
2023-05-09 23:16:58 +00:00
[Line(Type = LPSConvert.ConvertType.ToFloat)]
2023-07-23 20:46:21 +00:00
protected double likability { get; set; }
2023-01-20 12:42:00 +00:00
/// <summary>
/// 清除变化
/// </summary>
2023-06-08 11:44:41 +00:00
public void CleanChange()
2023-01-20 12:42:00 +00:00
{
2023-06-08 11:44:41 +00:00
ChangeStrength /= 2;
ChangeFeeling /= 2;
ChangeStrengthDrink /= 2;
ChangeStrengthFood /= 2;
2023-01-20 12:42:00 +00:00
}
2023-06-03 21:51:58 +00:00
/// <summary>
/// 取回被储存的体力
/// </summary>
public void StoreTake()
{
2023-06-08 11:44:41 +00:00
const int t = 10;
var s = StoreFeeling / t;
StoreFeeling -= s;
2023-06-03 21:51:58 +00:00
if (Math.Abs(StoreFeeling) < 1)
StoreFeeling = 0;
else
2023-06-08 11:44:41 +00:00
FeelingChange(s);
2023-06-03 21:51:58 +00:00
2023-06-08 11:44:41 +00:00
s = StoreStrength / t;
StoreStrength -= s;
2023-06-03 21:51:58 +00:00
if (Math.Abs(StoreStrength) < 1)
StoreStrength = 0;
else
2023-06-08 11:44:41 +00:00
StrengthChange(s);
2023-06-03 21:51:58 +00:00
2023-06-08 11:44:41 +00:00
s = StoreStrengthDrink / t;
StoreStrengthDrink -= s;
2023-06-03 21:51:58 +00:00
if (Math.Abs(StoreStrengthDrink) < 1)
StoreStrengthDrink = 0;
else
2023-06-08 11:44:41 +00:00
StrengthChangeDrink(s);
2023-01-20 12:42:00 +00:00
2023-06-08 11:44:41 +00:00
s = StoreStrengthFood / t;
StoreStrengthFood -= s;
2023-06-03 21:51:58 +00:00
if (Math.Abs(StoreStrengthFood) < 1)
StoreStrengthFood = 0;
else
2023-06-08 11:44:41 +00:00
StrengthChangeFood(s);
2023-06-03 21:51:58 +00:00
}
2023-06-08 08:46:53 +00:00
/// <summary>
/// 吃食物
/// </summary>
/// <param name="food">食物类</param>
2023-06-03 21:51:58 +00:00
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;
}
2022-12-13 07:10:18 +00:00
/// <summary>
2023-11-24 04:16:29 +00:00
/// 宠物当前状态
2022-12-13 07:10:18 +00:00
/// </summary>
2023-05-10 03:13:34 +00:00
[Line(name: "mode")]
2023-06-18 18:11:40 +00:00
public ModeType Mode { get; set; } = ModeType.Nomal;
2024-02-22 18:46:09 +00:00
public double LikabilityMax => 90 + Level * 10;
public double FeelingMax => 100;
public double ExpBonus => 1;
2022-12-13 07:10:18 +00:00
/// <summary>
/// 计算宠物当前状态
/// </summary>
2023-01-08 16:57:10 +00:00
public ModeType CalMode()
2022-12-13 07:10:18 +00:00
{
2023-07-24 01:53:55 +00:00
int realhel = 60 - (Feeling >= 80 ? 12 : 0) - (Likability >= 80 ? 12 : (Likability >= 40 ? 6 : 0));
2022-12-13 07:10:18 +00:00
//先从最次的开始
if (Health <= realhel)
{
//可以确认从状态不佳和生病二选一
if (Health <= realhel / 2)
{//生病
2023-01-08 16:57:10 +00:00
return ModeType.Ill;
2022-12-13 07:10:18 +00:00
}
else
{
2023-01-08 16:57:10 +00:00
return ModeType.PoorCondition;
2022-12-13 07:10:18 +00:00
}
}
//然后判断是高兴还是普通
double realfel = .90 - (Likability >= 80 ? .20 : (Likability >= 40 ? .10 : 0));
double felps = Feeling / FeelingMax;
if (felps >= realfel)
2022-12-13 07:10:18 +00:00
{
2023-01-08 16:57:10 +00:00
return ModeType.Happy;
2022-12-13 07:10:18 +00:00
}
else if (felps <= realfel / 2)
2022-12-13 07:10:18 +00:00
{
2023-06-14 11:13:52 +00:00
return ModeType.PoorCondition;
2022-12-13 07:10:18 +00:00
}
2023-06-14 11:13:52 +00:00
return ModeType.Nomal;
2022-12-13 07:10:18 +00:00
}
/// <summary>
/// 新游戏
/// </summary>
2023-05-09 23:16:58 +00:00
public GameSave(string name)
2022-12-13 07:10:18 +00:00
{
2023-01-11 13:10:18 +00:00
Name = name;
2022-12-13 07:10:18 +00:00
Money = 100;
Exp = 0;
Strength = 100;
StrengthFood = 100;
StrengthDrink = 100;
Feeling = 60;
Health = 100;
Likability = 0;
2023-01-08 16:57:10 +00:00
Mode = CalMode();
2022-12-13 07:10:18 +00:00
}
/// <summary>
/// 读档
/// </summary>
2023-05-09 23:16:58 +00:00
public GameSave()
2022-12-13 07:10:18 +00:00
{
2023-05-09 23:16:58 +00:00
//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();
2022-12-13 07:10:18 +00:00
}
/// <summary>
2023-05-09 23:16:58 +00:00
/// 读档
/// </summary>
public static GameSave Load(ILine data) => LPSConvert.DeserializeObject<GameSave>(data);
/// <summary>
2022-12-13 07:10:18 +00:00
/// 存档
/// </summary>
/// <returns>存档行</returns>
public Line ToLine()
{
2023-05-09 23:16:58 +00:00
//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);
2023-05-10 03:13:34 +00:00
return LPSConvert.SerializeObject(this, "vpet");
2022-12-13 07:10:18 +00:00
}
}
2023-11-24 04:16:29 +00:00
}