VPet/VPet-Simulator.Windows.Interface/ExtensionFunction.cs

247 lines
9.4 KiB
C#
Raw Permalink Normal View History

using LinePutScript.Localization.WPF;
using System;
2023-08-25 21:23:30 +00:00
using System.Collections.Generic;
2024-04-17 21:13:51 +00:00
using System.Diagnostics;
using System.IO;
2023-08-25 21:23:30 +00:00
using System.Linq;
2023-09-27 07:13:48 +00:00
using VPet_Simulator.Core;
2023-08-25 21:23:30 +00:00
using static VPet_Simulator.Core.GraphHelper;
namespace VPet_Simulator.Windows.Interface
{
public static class ExtensionFunction
{
/// <summary>
2023-11-13 14:34:57 +00:00
/// 工作获取效率
2023-08-25 21:23:30 +00:00
/// </summary>
/// <param name="work">工作</param>
2023-11-13 14:34:57 +00:00
/// <returns>工作获取效率</returns>
public static double Get(this Work work)
{
2024-03-14 07:36:13 +00:00
if (work.Type == Work.WorkType.Work)
return MathPow(Math.Abs(work.MoneyBase) * (1 + work.FinishBonus / 2) + 1, 1.25);
else
return MathPow((Math.Abs(work.MoneyBase) * (1 + work.FinishBonus / 2) + 1) / 10, 1.25);
}
/// <summary>
/// 求幂(带符号)
/// </summary>
public static double MathPow(double value, double pow)
{
return Math.Pow(Math.Abs(value), pow) * Math.Sign(value);
2023-11-13 14:34:57 +00:00
}
/// <summary>
/// 工作花费效率
/// </summary>
/// <param name="work">工作</param>
/// <returns>工作花费效率</returns>
2023-11-13 14:34:57 +00:00
public static double Spend(this Work work)
{
return (MathPow(work.StrengthFood, 1.5) / 3 + MathPow(work.StrengthDrink, 1.5) / 4 + MathPow(work.Feeling, 1.5) / 4 +
2024-03-14 11:31:34 +00:00
work.LevelLimit / 10.0 + MathPow(work.StrengthFood + work.StrengthDrink + work.Feeling, 1.5) / 10) * 3;
2023-11-13 14:34:57 +00:00
}
/// <summary>
/// 判断这个工作是否超模
/// </summary>
/// <param name="work">工作</param>
/// <returns>是否超模</returns>
public static bool IsOverLoad(this Work work)
{//判断这个工作是否超模
if (work.LevelLimit < 0)
work.LevelLimit = 0;
2023-11-13 14:34:57 +00:00
if (work.FinishBonus < 0)
2024-03-14 07:36:13 +00:00
work.FinishBonus = 0;
if (work.Type == Work.WorkType.Play && work.Feeling > 0)
work.Feeling *= -1;//旧版本代码兼容
2024-03-14 11:31:34 +00:00
if (work.Time < 10)
work.Time = 10;
2024-03-26 13:10:56 +00:00
if (work.FinishBonus > 2)
work.FinishBonus = 2;
2024-03-14 07:36:13 +00:00
2023-11-13 14:34:57 +00:00
var spend = work.Spend();
var get = work.Get();
2023-08-25 21:23:30 +00:00
var rel = get / spend;
2023-09-12 05:15:22 +00:00
if (rel < 0)
return true;
2024-03-14 11:31:34 +00:00
var lvlimit = 1.1 * work.LevelLimit + 10;
if (work.Type != Work.WorkType.Work)
lvlimit *= 10;
if (Math.Abs(work.MoneyBase) > lvlimit) //等级获取速率限制
2023-09-13 09:29:45 +00:00
return true;
return rel > 1.4; // 推荐rel为1左右 超过1.3就是超模
}
/// <summary>
2024-05-17 09:09:05 +00:00
/// 为所有工作进行1.2倍效率修正
/// </summary>
/// <param name="work"></param>
public static void FixOverLoad(this Work work)
{
2024-03-25 05:33:58 +00:00
if (work.LevelLimit < 0)
work.LevelLimit = 0;
if (work.FinishBonus < 0)
work.FinishBonus = 0;
if (work.Type == Work.WorkType.Play && work.Feeling > 0)
work.Feeling *= -1;//旧版本代码兼容
if (work.Time < 10)
work.Time = 10;
2024-03-26 13:10:56 +00:00
if (work.FinishBonus > 2)
work.FinishBonus = 2;
2024-03-25 05:33:58 +00:00
2024-05-17 09:09:05 +00:00
var spend = work.Spend();
if (spend > 0)
{
2024-05-17 09:09:05 +00:00
work.MoneyBase = 2 * (1.15 * Math.Pow(spend, 0.8) - 1) / (2 + work.FinishBonus);
var lvlimit = 1.1 * work.LevelLimit + 10;
if (work.Type != Work.WorkType.Work)
lvlimit *= 10;
if (work.Type == Work.WorkType.Work)
{
2024-05-17 09:58:40 +00:00
work.MoneyBase = Math.Round(work.MoneyBase, 1);
}
2024-05-17 09:09:05 +00:00
else
{
2024-05-17 09:58:40 +00:00
work.MoneyBase = Math.Round(work.MoneyBase * 10, 1);
}
2024-05-17 09:09:05 +00:00
work.MoneyBase = Math.Min(work.MoneyBase, lvlimit);
}
// 如果仍然不合理,设定一个默认值
if (work.IsOverLoad())
2024-03-14 07:36:13 +00:00
{
switch (work.Type)
{
case Work.WorkType.Play:
work.FinishBonus = 0.2;
2024-03-14 07:36:13 +00:00
work.MoneyBase = 18;
work.StrengthFood = 1;
work.StrengthDrink = 1.5;
work.Feeling = -1;
work.LevelLimit = 0;
break;
case Work.WorkType.Work:
work.FinishBonus = 0.1;
2024-03-14 07:36:13 +00:00
work.MoneyBase = 8;
work.StrengthFood = 3.5;
work.StrengthDrink = 2.5;
work.Feeling = 1;
work.LevelLimit = 0;
break;
case Work.WorkType.Study:
work.FinishBonus = 0.2;
2024-03-14 07:36:13 +00:00
work.MoneyBase = 80;
work.StrengthFood = 2;
work.StrengthDrink = 2;
work.Feeling = 3;
work.LevelLimit = 0;
break;
}
}
2023-08-25 21:23:30 +00:00
}
2024-03-14 11:31:34 +00:00
/// <summary>
/// 将工作的属性值翻倍
/// </summary>
public static Work Double(this Work work, int value)
{
if (value == 1) return work;
2024-03-14 11:31:34 +00:00
Work w = (Work)work.Clone();
2024-05-17 09:58:40 +00:00
w.StrengthFood *= 0.5 + 0.4 * value;
w.StrengthDrink *= 0.5 + 0.4 * value;
w.Feeling *= 0.5 + 0.4 * value;
2024-03-14 11:31:34 +00:00
w.LevelLimit = (work.LevelLimit + 10) * value;
2024-05-17 09:09:05 +00:00
FixOverLoad(w);
2024-03-14 11:31:34 +00:00
return w;
}
2023-09-27 07:13:48 +00:00
public static string FoodToDescription(this IFood food)
{
var dic = new List<Tuple<string, double, string>>()
{
new Tuple<string, double, string>(LocalizeCore.Translate("经验值"), food.Exp, ValueToPlusPlus(food.Exp, 1 / 4, 5)),
new Tuple<string, double, string>(LocalizeCore.Translate("饱腹度"),food.StrengthFood, ValueToPlusPlus(food.StrengthFood, 1 / 2, 5)) ,
new Tuple<string, double, string>(LocalizeCore.Translate("口渴度"), food.StrengthDrink, ValueToPlusPlus(food.StrengthDrink, 1 / 2.5, 5)),
new Tuple<string, double, string>(LocalizeCore.Translate("体力"),food.Strength, ValueToPlusPlus(food.Strength, 1 / 4, 5)),
new Tuple<string, double, string>(LocalizeCore.Translate("心情"), food.Feeling, ValueToPlusPlus(food.Feeling, 1 / 3, 5)),
new Tuple<string, double, string>(LocalizeCore.Translate("健康"),food.Health, ValueToPlusPlus(food.Health, 1, 5)) ,
new Tuple<string, double, string>(LocalizeCore.Translate("好感度"),food.Likability, ValueToPlusPlus(food.Likability, 1.5, 5))
};
var dic2 = dic.Where(kv => kv.Item2 != 0)
.Select(x => x.Item1 + x.Item3);
return string.Join("\n", dic2);
}
/// <summary>
/// 把值变成++
/// </summary>
/// <param name="value">值</param>
/// <param name="magnification">倍率</param>
/// <returns></returns>
public static string ValueToPlusPlus(double value, double magnification, int max = 10)
{
int v = (int)Math.Abs(value);
v = (int)(Math.Pow(v, magnification));
v = Math.Min(Math.Max(v, 0), max);
if (value < 0)
return new string('-', v);
else
return new string('+', v);
}
2024-04-17 21:13:51 +00:00
/// <summary>
/// 启动URL
/// </summary>
public static void StartURL(string url)
{
try
{
var psi = new ProcessStartInfo
{
FileName = url,
UseShellExecute = true
};
Process.Start(psi);
}
catch
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "explorer.exe";
startInfo.UseShellExecute = false;
startInfo.Arguments = url;
Process.Start(startInfo);
}
}
/// <summary>
/// 吃食物 附带倍率
/// </summary>
/// <param name="save">存档</param>
/// <param name="food">食物</param>
/// <param name="buff">默认1倍</param>
public static void EatFood(this IGameSave save, IFood food, double buff)
{
save.Exp += food.Exp * buff;
var tmp = food.Strength / 2 * buff;
save.StrengthChange(tmp);
save.StoreStrength += tmp;
tmp = food.StrengthFood / 2 * buff;
save.StrengthChangeFood(tmp);
save.StoreStrengthFood += tmp;
tmp = food.StrengthDrink / 2 * buff;
save.StrengthChangeDrink(tmp);
save.StoreStrengthDrink += tmp;
save.FeelingChange(food.Feeling * buff);
2024-04-17 21:13:51 +00:00
save.Health += food.Health * buff;
save.Likability += food.Likability * buff;
}
2023-08-25 21:23:30 +00:00
}
2023-12-29 19:37:41 +00:00
public static partial class ExtensionValue
{
/// <summary>
/// 当前运行目录
/// </summary>
public static string BaseDirectory = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName;
}
2023-09-27 07:13:48 +00:00
2023-08-25 21:23:30 +00:00
}