VPet/VPet-Simulator.Core/Display/MainLogic.cs

239 lines
7.7 KiB
C#
Raw Normal View History

2022-12-13 07:10:18 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
2022-12-14 18:17:13 +00:00
using System.Windows;
2022-12-13 07:10:18 +00:00
namespace VPet_Simulator.Core
{
public partial class Main
{
2023-01-24 15:47:16 +00:00
public const int DistanceMax = 100;
public const int DistanceMid = 100;
public const int DistanceMin = 50;
2023-01-25 04:49:18 +00:00
public const int LoopProMax = 20;
2023-01-24 15:47:16 +00:00
public const int LoopMax = 10;
public const int LoopMid = 7;
public const int LoopMin = 5;
2023-01-26 15:15:37 +00:00
public const int TreeRND = 5;
2022-12-14 18:17:13 +00:00
2023-04-01 19:31:28 +00:00
/// <summary>
/// 处理说话内容
/// </summary>
public event Action<string> OnSay;
2023-04-04 16:21:46 +00:00
/// <summary>
/// 事件Timer
/// </summary>
2022-12-13 07:10:18 +00:00
public Timer EventTimer = new Timer(15000)
{
AutoReset = true,
Enabled = true
};
2023-01-27 17:44:57 +00:00
/// <summary>
/// 说话
/// </summary>
/// <param name="text">说话内容</param>
2023-04-01 15:15:50 +00:00
public void Say(string text, GraphCore.Helper.SayType type = GraphCore.Helper.SayType.Shining)
2023-01-26 15:15:37 +00:00
{
2023-04-03 18:11:12 +00:00
OnSay?.Invoke(text);
2023-03-28 13:18:14 +00:00
if (type != GraphCore.Helper.SayType.None && DisplayType == GraphCore.GraphType.Default)
Display(GraphCore.Helper.Convert(type, GraphCore.Helper.AnimatType.A_Start), () =>
2023-01-27 17:44:57 +00:00
{
2023-03-28 13:18:14 +00:00
Dispatcher.Invoke(() => MsgBar.Show(Core.Save.Name, text, type));
Saying(type);
2023-01-27 17:44:57 +00:00
});
else
2023-01-26 15:15:37 +00:00
{
2023-03-28 13:18:14 +00:00
Dispatcher.Invoke(() => MsgBar.Show(Core.Save.Name, text, type));
2023-01-27 17:44:57 +00:00
}
2023-01-26 15:15:37 +00:00
}
2023-04-01 19:31:28 +00:00
2023-03-28 13:18:14 +00:00
public void Saying(GraphCore.Helper.SayType type)
2023-01-26 15:15:37 +00:00
{
2023-03-28 13:18:14 +00:00
Display(GraphCore.Helper.Convert(type, GraphCore.Helper.AnimatType.B_Loop), () => Saying(type));
2023-01-26 15:15:37 +00:00
}
2022-12-14 18:17:13 +00:00
2022-12-13 07:10:18 +00:00
private void EventTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
2023-01-22 17:33:13 +00:00
Core.Save.CleanChange();
2023-01-08 16:57:10 +00:00
//所有Handle
TimeHandle?.Invoke(this);
2023-01-21 14:16:13 +00:00
if (Core.Controller.EnableFunction)
2023-01-20 12:42:00 +00:00
{
2023-01-21 14:16:13 +00:00
//饮食等乱七八糟的消耗
if (Core.Save.StrengthFood >= 50)
2023-01-20 12:42:00 +00:00
{
2023-01-21 14:16:13 +00:00
Core.Save.StrengthChange(1);
2023-01-22 17:33:13 +00:00
if (Core.Save.StrengthFood >= 75)
Core.Save.Health += Function.Rnd.Next(0, 1);
2023-01-21 14:16:13 +00:00
}
else if (Core.Save.StrengthFood <= 25)
{
Core.Save.Health -= Function.Rnd.Next(0, 1);
}
2023-01-22 17:33:13 +00:00
//if (Core.Save.Strength <= 40)
//{
// Core.Save.Health -= Function.Rnd.Next(0, 1);
//}
2023-01-21 14:16:13 +00:00
Core.Save.StrengthChangeFood(-1);
if (Core.Save.Feeling >= 75)
{
if (Core.Save.Feeling >= 90)
{
Core.Save.Likability++;
}
Core.Save.Exp++;
Core.Save.Health++;
}
else if (Core.Save.Feeling <= 25)
{
Core.Save.Likability--;
}
if (Core.Save.StrengthDrink <= 25)
{
Core.Save.Health -= Function.Rnd.Next(0, 1);
}
2023-01-24 06:56:16 +00:00
else if (Core.Save.StrengthDrink >= 75)
Core.Save.Health += Function.Rnd.Next(0, 1);
2023-01-21 14:16:13 +00:00
var newmod = Core.Save.CalMode();
2023-01-22 17:33:13 +00:00
if (Core.Save.Mode != newmod)
2023-01-21 14:16:13 +00:00
{
//TODO:切换逻辑
2023-01-22 17:33:13 +00:00
Core.Save.Mode = newmod;
2023-01-20 12:42:00 +00:00
}
}
2023-01-21 14:16:13 +00:00
else
2023-01-20 12:42:00 +00:00
{
2023-01-21 14:16:13 +00:00
Core.Save.Mode = Save.ModeType.Happy;
2023-03-01 22:51:07 +00:00
//Core.Save.Mode = Save.ModeType.Ill;
2023-01-20 12:42:00 +00:00
}
2023-01-19 15:26:58 +00:00
2023-01-08 16:57:10 +00:00
//UIHandle
Dispatcher.Invoke(() => TimeUIHandle.Invoke(this));
2023-01-20 12:42:00 +00:00
if (DisplayType == GraphCore.GraphType.Default && !isPress)
2023-01-25 16:23:09 +00:00
switch (Function.Rnd.Next(Math.Max(20, Core.Controller.InteractionCycle - CountNomal)))
2022-12-14 18:17:13 +00:00
{
case 0:
2023-01-20 12:42:00 +00:00
//随机向右
2022-12-14 18:17:13 +00:00
DisplayWalk_Left();
break;
case 1:
DisplayClimb_Left_UP();
2023-01-08 16:57:10 +00:00
break;
2022-12-14 18:17:13 +00:00
case 2:
DisplayClimb_Left_DOWN();
break;
case 3:
DisplayClimb_Right_UP();
break;
case 4:
DisplayClimb_Right_DOWN();
break;
2023-01-19 15:26:58 +00:00
case 5:
DisplayWalk_Right();
break;
2023-01-24 15:47:16 +00:00
case 6:
2023-01-21 14:16:13 +00:00
DisplayFall_Left();
break;
2023-01-24 15:47:16 +00:00
case 7:
2023-01-21 14:16:13 +00:00
DisplayFall_Right();
break;
2023-01-24 15:47:16 +00:00
case 8:
2023-01-08 16:57:10 +00:00
DisplayClimb_Top_Right();
2022-12-14 18:17:13 +00:00
break;
2023-01-24 15:47:16 +00:00
case 9:
2023-01-19 15:26:58 +00:00
DisplayClimb_Top_Left();
break;
2023-01-24 15:47:16 +00:00
case 10:
DisplayCrawl_Left();
break;
case 11:
DisplayCrawl_Right();
break;
2023-01-25 04:49:18 +00:00
case 13:
case 14:
DisplaySleep();
break;
2023-01-20 07:08:28 +00:00
case 15:
2023-01-20 12:42:00 +00:00
case 16:
2023-01-19 15:26:58 +00:00
DisplayBoring();
break;
2023-01-20 12:42:00 +00:00
case 18:
case 17:
2023-01-19 15:26:58 +00:00
DisplaySquat();
2023-01-25 04:49:18 +00:00
break;
2023-01-28 06:12:01 +00:00
case 12:
case 19:
case 20:
DisplayIdel_StateONE();
2023-03-28 13:18:14 +00:00
break;
2022-12-14 18:17:13 +00:00
default:
break;
}
2023-01-19 15:26:58 +00:00
2022-12-13 07:10:18 +00:00
}
2022-12-14 18:17:13 +00:00
/// <summary>
/// 定点移动位置向量
/// </summary>
private Point MoveTimerPoint = new Point(0, 0);
/// <summary>
/// 定点移动定时器
/// </summary>
private Timer MoveTimer = new Timer(125)
{
AutoReset = true,
};
2023-01-24 06:56:16 +00:00
/// <summary>
/// 设置计算间隔
/// </summary>
/// <param name="Interval">计算间隔</param>
public void SetLogicInterval(int Interval)
{
EventTimer.Interval = Interval;
}
private Timer SmartMoveTimer = new Timer(20 * 60)
{
AutoReset = true,
};
/// <summary>
/// 是否启用智能移动
/// </summary>
private bool SmartMove;
/// <summary>
/// 设置移动模式
/// </summary>
/// <param name="AllowMove">允许移动</param>
2023-04-04 16:21:46 +00:00
/// <param name="smartMove">启用智能移动</param>
2023-01-24 06:56:16 +00:00
/// <param name="SmartMoveInterval">智能移动周期</param>
public void SetMoveMode(bool AllowMove, bool smartMove, int SmartMoveInterval)
{
2023-04-03 18:11:12 +00:00
MoveTimer.Enabled = false;
2023-01-24 06:56:16 +00:00
if (AllowMove)
{
MoveTimer.AutoReset = true;
if (smartMove)
{
SmartMoveTimer.Interval = SmartMoveInterval;
SmartMoveTimer.Start();
SmartMove = true;
}
else
{
2023-04-04 09:32:53 +00:00
SmartMoveTimer.Enabled = false;
2023-01-24 06:56:16 +00:00
SmartMove = false;
}
}
else
{
MoveTimer.AutoReset = false;
}
}
2022-12-13 07:10:18 +00:00
}
}