VPet/VPet-Simulator.Windows.Interface/Mod/Food.cs

227 lines
7.3 KiB
C#
Raw Normal View History

2023-06-03 21:51:58 +00:00
using LinePutScript.Converter;
2023-07-01 07:46:08 +00:00
using LinePutScript.Localization.WPF;
2023-06-08 08:46:53 +00:00
using Panuon.WPF;
2023-06-03 21:51:58 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2023-06-08 08:46:53 +00:00
using System.Windows.Media;
2023-08-18 06:51:33 +00:00
using System.Windows.Media.Imaging;
2023-06-03 21:51:58 +00:00
using VPet_Simulator.Core;
2023-06-08 08:46:53 +00:00
using static LinePutScript.Converter.LPSConvert;
2023-06-03 21:51:58 +00:00
namespace VPet_Simulator.Windows.Interface
{
2023-06-08 08:46:53 +00:00
public class Food : NotifyPropertyChangedBase, IFood
2023-06-03 21:51:58 +00:00
{
2023-06-08 08:46:53 +00:00
/// <summary>
/// 食物类型
/// </summary>
public enum FoodType
{
/// <summary>
/// 食物 (默认)
/// </summary>
Food,
/// <summary>
/// 收藏 (自定义)
/// </summary>
Star,
/// <summary>
/// 正餐
/// </summary>
Meal,
/// <summary>
/// 零食
/// </summary>
Snack,
/// <summary>
/// 饮料
/// </summary>
Drink,
/// <summary>
/// 功能性
/// </summary>
Functional,
/// <summary>
/// 药品
/// </summary>
Drug,
2023-07-16 23:58:09 +00:00
/// <summary>
2024-01-02 19:39:36 +00:00
/// 礼品
2023-07-16 23:58:09 +00:00
/// </summary>
Gift,
2023-06-08 08:46:53 +00:00
}
/// <summary>
/// 食物类型
/// </summary>
[Line(type: ConvertType.ToEnum, ignoreCase: true)]
public FoodType Type { get; set; } = FoodType.Food;
/// <summary>
/// 食物名字
/// </summary>
[Line(name: "name")]
public string Name { get; set; }
2023-07-01 07:46:08 +00:00
private string transname = null;
2023-07-03 11:41:02 +00:00
/// <summary>
/// 食物名字 (翻译)
/// </summary>
2023-07-01 07:46:08 +00:00
public string TranslateName
{
get
{
if (transname == null)
{
transname = LocalizeCore.Translate(Name);
}
return transname;
}
}
2023-06-08 08:46:53 +00:00
[Line(ignoreCase: true)]
2023-06-03 21:51:58 +00:00
public int Exp { get; set; }
2023-06-08 08:46:53 +00:00
[Line(ignoreCase: true)]
2023-06-03 21:51:58 +00:00
public double Strength { get; set; }
2023-06-08 08:46:53 +00:00
[Line(ignoreCase: true)]
2023-06-03 21:51:58 +00:00
public double StrengthFood { get; set; }
2023-06-08 08:46:53 +00:00
[Line(ignoreCase: true)]
2023-06-03 21:51:58 +00:00
public double StrengthDrink { get; set; }
2023-06-08 08:46:53 +00:00
[Line(ignoreCase: true)]
2023-06-03 21:51:58 +00:00
public double Feeling { get; set; }
2023-06-08 08:46:53 +00:00
[Line(ignoreCase: true)]
2023-06-03 21:51:58 +00:00
public double Health { get; set; }
2023-06-08 08:46:53 +00:00
[Line(ignoreCase: true)]
2023-06-03 21:51:58 +00:00
public double Likability { get; set; }
/// <summary>
/// 食物价格
/// </summary>
2023-06-08 08:46:53 +00:00
[Line(ignoreCase: true)]
2023-06-03 21:51:58 +00:00
public double Price { get; set; }
2023-06-08 08:46:53 +00:00
/// <summary>
/// 描述
/// </summary>
[Line(ignoreCase: true)]
public string Desc { get; set; }
2023-08-11 02:48:04 +00:00
private string descs = null;
2023-06-08 08:46:53 +00:00
/// <summary>
/// 描述(ToBetterBuy)
/// </summary>
2023-09-14 10:18:35 +00:00
2023-06-08 08:46:53 +00:00
public string Description
{
get
{
2023-09-14 10:18:35 +00:00
return descs + '\n' + Desc.Translate();
}
}
2023-08-23 19:49:16 +00:00
2023-09-14 10:18:35 +00:00
public IDictionary<string, string> DescriptionValues
{
get
{
var dic = new Dictionary<string, double>()
{
{ LocalizeCore.Translate("经验值"), (double)Exp },
{ LocalizeCore.Translate("饱腹度"), StrengthFood },
{ LocalizeCore.Translate("口渴度"), StrengthDrink },
{ LocalizeCore.Translate("体力"), Strength },
{ LocalizeCore.Translate("心情"), Feeling },
{ LocalizeCore.Translate("健康"), Health },
{ LocalizeCore.Translate("好感度"), Likability },
};
return dic.Where(kv => kv.Value != 0)
.ToDictionary(kv => kv.Key, kv => $"{(kv.Value > 0 ? "+" : "")}{kv.Value.ToString("f2")}");
2023-06-08 08:46:53 +00:00
}
}
2023-09-14 10:18:35 +00:00
2023-06-08 08:46:53 +00:00
/// <summary>
/// 显示的图片
/// </summary>
2023-08-18 06:51:33 +00:00
public BitmapImage ImageSource { get; set; }
2023-06-08 08:46:53 +00:00
/// <summary>
/// 是否已收藏
/// </summary>
public bool Star { get; set; }
/// <summary>
/// 物品图片
/// </summary>
[Line(ignoreCase: true)]
public string Image;
public bool? isoverload = null;
2023-08-23 19:49:16 +00:00
/// <summary>
2023-08-24 20:22:09 +00:00
/// 当前物品推荐价格
/// </summary>
2023-09-05 11:26:27 +00:00
public double RealPrice => ((Exp / 3 + Strength / 5 + StrengthDrink / 3 + StrengthFood / 2 + Feeling / 5) / 3 + Health + Likability * 10);
2023-08-24 20:22:09 +00:00
/// <summary>
2023-08-23 19:49:16 +00:00
/// 该食物是否超模
/// </summary>
public bool IsOverLoad()
{
if (isoverload == null)
{
2023-08-24 20:22:09 +00:00
double relp = RealPrice;
2023-08-25 22:08:13 +00:00
isoverload = Price < (relp - 10) * 0.7;// Price > (relp + 10) * 1.3;// || Price < (relp - 10) * 0.7;//30%容错
2023-08-23 19:49:16 +00:00
}
return isoverload.Value;
}
2023-06-08 08:46:53 +00:00
/// <summary>
/// 加载物品图片
/// </summary>
public void LoadImageSource(IMainWindow imw)
{
ImageSource = imw.ImageSources.FindImage(Image ?? Name, "food");
Star = imw.Set["betterbuy"]["star"].GetInfos().Contains(Name);
2023-08-11 02:48:04 +00:00
LoadEatTimeSource(imw);
}
public void LoadEatTimeSource(IMainWindow imw)
{
DateTime now = DateTime.Now;
2023-09-22 16:18:24 +00:00
DateTime eattime = imw.GameSavesData["buytime"].GetDateTime(Name, now);
2023-08-11 02:48:04 +00:00
if (eattime <= now)
{
2023-09-28 16:44:25 +00:00
if (Type == FoodType.Meal || Type == FoodType.Snack || Type == FoodType.Drink || Type == FoodType.Gift)// || Type == FoodType.Limit)
2023-08-11 02:48:04 +00:00
descs = "喜好度".Translate();
else
descs = "有效度".Translate();
descs += ":\t100%";
}
else
{
2023-09-28 16:44:25 +00:00
if (Type == FoodType.Meal || Type == FoodType.Snack || Type == FoodType.Drink || Type == FoodType.Gift)// || Type == FoodType.Limit)
2023-08-11 02:48:04 +00:00
descs = "喜好度".Translate();
else
descs = "有效度".Translate();
2023-09-05 11:26:27 +00:00
if (Type == FoodType.Gift)
descs += ":\t" + Math.Max(0.4, 1 - Math.Pow((eattime - now).TotalHours, 2) * 0.01).ToString("p0");
else
descs += ":\t" + Math.Max(0.2, 1 - Math.Pow((eattime - now).TotalHours, 2) * 0.02).ToString("p0");
2023-08-11 02:48:04 +00:00
descs += "\t\t" + "恢复".Translate() + ":\t" + (eattime).ToString("MM/dd HH");
}
2023-06-08 08:46:53 +00:00
}
2023-08-30 15:14:41 +00:00
/// <summary>
/// 食用时显示的动画
/// </summary>
[Line(ignoreCase: true)]
public string Graph { get; set; } = null;
/// <summary>
/// 获取食用时显示的动画
/// </summary>
public string GetGraph()
{
if (string.IsNullOrEmpty(Graph))
switch (Type)
{
default:
return "eat";
case Food.FoodType.Drink:
return "drink";
case Food.FoodType.Gift:
return "gift";
}
else
return Graph;
}
2023-06-03 21:51:58 +00:00
}
}