新增状态等数值运算

This commit is contained in:
ZouJin 2023-01-20 20:42:00 +08:00
parent ee8bb69942
commit 5aea3e0d74
6 changed files with 129 additions and 23 deletions

View File

@ -22,17 +22,48 @@ namespace VPet_Simulator.Core
//所有Handle //所有Handle
TimeHandle?.Invoke(this); TimeHandle?.Invoke(this);
//TODO:饮食等乱七八糟的消耗 //饮食等乱七八糟的消耗
if (Core.Save.StrengthFood >= 50)
{
Core.Save.StrengthChange(1);
}
else if (Core.Save.StrengthFood <= 25)
{
Core.Save.Health -= Function.Rnd.Next(0, 1);
}
if (Core.Save.Strength <= 40)
{
Core.Save.Health -= Function.Rnd.Next(0, 1);
}
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);
}
//UIHandle //UIHandle
Dispatcher.Invoke(() => TimeUIHandle.Invoke(this)); Dispatcher.Invoke(() => TimeUIHandle.Invoke(this));
if (DisplayType == GraphCore.GraphType.Default) if (DisplayType == GraphCore.GraphType.Default && !isPress)
switch (-1)//Function.Rnd.Next(10)) switch (Function.Rnd.Next(Math.Max(20, 200 - CountNomal)))
{ {
case 0: case 0:
//随机向右 case 7:
//随机向右
DisplayWalk_Left(); DisplayWalk_Left();
break; break;
case 1: case 1:
@ -48,6 +79,7 @@ namespace VPet_Simulator.Core
DisplayClimb_Right_DOWN(); DisplayClimb_Right_DOWN();
break; break;
case 5: case 5:
case 6:
DisplayWalk_Right(); DisplayWalk_Right();
break; break;
case 10: case 10:
@ -57,9 +89,11 @@ namespace VPet_Simulator.Core
DisplayClimb_Top_Left(); DisplayClimb_Top_Left();
break; break;
case 15: case 15:
case 16:
DisplayBoring(); DisplayBoring();
break; break;
case 16: case 18:
case 17:
DisplaySquat(); DisplaySquat();
break; break;
default: default:

View File

@ -26,7 +26,21 @@ namespace VPet_Simulator.Core
InitializeComponent(); InitializeComponent();
EndTimer.Elapsed += EndTimer_Elapsed; EndTimer.Elapsed += EndTimer_Elapsed;
ShowTimer.Elapsed += ShowTimer_Elapsed; ShowTimer.Elapsed += ShowTimer_Elapsed;
CloseTimer.Elapsed += CloseTimer_Elapsed;
} }
private void CloseTimer_Elapsed(object sender, ElapsedEventArgs e)
{
if (Dispatcher.Invoke(() => Opacity) <= 0.05)
{
Dispatcher.Invoke(() => this.Visibility = Visibility.Collapsed);
EndAction?.Invoke();
}else
{
Dispatcher.Invoke(() => Opacity -= 0.02);
}
}
List<char> outputtext; List<char> outputtext;
private void ShowTimer_Elapsed(object sender, ElapsedEventArgs e) private void ShowTimer_Elapsed(object sender, ElapsedEventArgs e)
{ {
@ -45,13 +59,14 @@ namespace VPet_Simulator.Core
{ {
if (--timeleft <= 0) if (--timeleft <= 0)
{ {
Dispatcher.Invoke(() => this.Visibility = Visibility.Collapsed); EndTimer.Stop();
EndAction?.Invoke(); CloseTimer.Start();
} }
} }
public Timer EndTimer = new Timer() { Interval = 100 }; public Timer EndTimer = new Timer() { Interval = 100 };
public Timer ShowTimer = new Timer() { Interval = 20 }; public Timer ShowTimer = new Timer() { Interval = 20 };
public Timer CloseTimer = new Timer() { Interval = 10 };
int timeleft; int timeleft;
public void Show(string name, string text) public void Show(string name, string text)
{ {
@ -59,13 +74,16 @@ namespace VPet_Simulator.Core
outputtext = text.ToList(); outputtext = text.ToList();
LName.Content = name; LName.Content = name;
timeleft = text.Length + 5; timeleft = text.Length + 5;
ShowTimer.Start(); EndTimer.Stop(); ShowTimer.Start(); EndTimer.Stop(); CloseTimer.Stop();
this.Visibility = Visibility.Visible; this.Visibility = Visibility.Visible;
Opacity = 1;
} }
private void Border_MouseEnter(object sender, MouseEventArgs e) private void Border_MouseEnter(object sender, MouseEventArgs e)
{ {
EndTimer.Stop(); EndTimer.Stop();
CloseTimer.Stop();
this.Opacity = 1;
} }
private void Border_MouseLeave(object sender, MouseEventArgs e) private void Border_MouseLeave(object sender, MouseEventArgs e)
@ -76,7 +94,7 @@ namespace VPet_Simulator.Core
private void UserControl_MouseDoubleClick(object sender, MouseButtonEventArgs e) private void UserControl_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{ {
EndTimer.Stop(); ShowTimer.Stop(); EndTimer.Stop(); ShowTimer.Stop();CloseTimer.Close();
this.Visibility = Visibility.Collapsed; this.Visibility = Visibility.Collapsed;
EndAction?.Invoke(); EndAction?.Invoke();
} }

View File

@ -14,7 +14,7 @@
</UserControl.Resources> </UserControl.Resources>
<Grid> <Grid>
<Border x:Name="BdrPanel" VerticalAlignment="Bottom" Margin="0,0,0,55" TextBlock.FontSize="24" <Border x:Name="BdrPanel" VerticalAlignment="Bottom" Margin="0,0,0,55" TextBlock.FontSize="24"
Visibility="Collapsed" TextElement.FontSize="24" BorderBrush="{DynamicResource DARKPrimaryDarker}" TextElement.FontSize="24" BorderBrush="{DynamicResource DARKPrimaryDarker}"
BorderThickness="1" Background="{DynamicResource DARKPrimaryText}" CornerRadius="5" BorderThickness="1" Background="{DynamicResource DARKPrimaryText}" CornerRadius="5"
MouseLeave="MenuPanel_MouseLeave"> MouseLeave="MenuPanel_MouseLeave">
<Grid Margin="15"> <Grid Margin="15">
@ -56,7 +56,7 @@
Foreground="{DynamicResource ProgressBarForeground}" Foreground="{DynamicResource ProgressBarForeground}"
pu:ProgressBarHelper.IsPercentVisible="True" pu:ProgressBarHelper.IsPercentVisible="True"
pu:ProgressBarHelper.GeneratingPercentText="PgbExperience_GeneratingPercentText" /> pu:ProgressBarHelper.GeneratingPercentText="PgbExperience_GeneratingPercentText" />
<TextBlock x:Name="tExp" Grid.Row="3" Grid.Column="4" HorizontalAlignment="Right" Text="x1" <TextBlock x:Name="tExp" Grid.Row="3" Grid.Column="4" HorizontalAlignment="Right" Text="x1.0"
Foreground="{DynamicResource DARKPrimary}" /> Foreground="{DynamicResource DARKPrimary}" />
<TextBlock Grid.Row="4" Text="体力" VerticalAlignment="Center" /> <TextBlock Grid.Row="4" Text="体力" VerticalAlignment="Center" />
<ProgressBar x:Name="pStrength" Grid.Row="4" Grid.Column="2" Value="40" FontSize="20" Height="20" <ProgressBar x:Name="pStrength" Grid.Row="4" Grid.Column="2" Value="40" FontSize="20" Height="20"
@ -64,7 +64,7 @@
Foreground="{DynamicResource ProgressBarForeground}" Foreground="{DynamicResource ProgressBarForeground}"
pu:ProgressBarHelper.IsPercentVisible="True" pu:ProgressBarHelper.IsPercentVisible="True"
pu:ProgressBarHelper.GeneratingPercentText="PgbStrength_GeneratingPercentText" /> pu:ProgressBarHelper.GeneratingPercentText="PgbStrength_GeneratingPercentText" />
<TextBlock x:Name="tStrength" Grid.Row="4" Grid.Column="4" HorizontalAlignment="Right" Text="+1/m" <TextBlock x:Name="tStrength" Grid.Row="4" Grid.Column="4" HorizontalAlignment="Right" Text="+1/t"
Foreground="{DynamicResource DARKPrimary}" /> Foreground="{DynamicResource DARKPrimary}" />
<TextBlock Grid.Row="5" Text="心情" VerticalAlignment="Center" /> <TextBlock Grid.Row="5" Text="心情" VerticalAlignment="Center" />
<ProgressBar x:Name="pFeeling" Grid.Row="5" Grid.Column="2" Value="60" FontSize="20" Height="20" <ProgressBar x:Name="pFeeling" Grid.Row="5" Grid.Column="2" Value="60" FontSize="20" Height="20"
@ -72,7 +72,7 @@
Foreground="{DynamicResource ProgressBarForeground}" Foreground="{DynamicResource ProgressBarForeground}"
pu:ProgressBarHelper.IsPercentVisible="True" pu:ProgressBarHelper.IsPercentVisible="True"
pu:ProgressBarHelper.GeneratingPercentText="PgbSpirit_GeneratingPercentText" /> pu:ProgressBarHelper.GeneratingPercentText="PgbSpirit_GeneratingPercentText" />
<TextBlock x:Name="tFeeling" Grid.Row="5" Grid.Column="4" HorizontalAlignment="Right" Text="+1/m" <TextBlock x:Name="tFeeling" Grid.Row="5" Grid.Column="4" HorizontalAlignment="Right" Text="+1/t"
Foreground="{DynamicResource DARKPrimary}" /> Foreground="{DynamicResource DARKPrimary}" />
<TextBlock Grid.Row="6" Text="饱腹度" VerticalAlignment="Center" /> <TextBlock Grid.Row="6" Text="饱腹度" VerticalAlignment="Center" />
<ProgressBar x:Name="pStrengthFood" Grid.Row="6" Grid.Column="2" Value="80" FontSize="20" Height="20" <ProgressBar x:Name="pStrengthFood" Grid.Row="6" Grid.Column="2" Value="80" FontSize="20" Height="20"
@ -80,7 +80,7 @@
Foreground="{DynamicResource ProgressBarForeground}" Foreground="{DynamicResource ProgressBarForeground}"
pu:ProgressBarHelper.IsPercentVisible="True" pu:ProgressBarHelper.IsPercentVisible="True"
pu:ProgressBarHelper.GeneratingPercentText="PgbHunger_GeneratingPercentText" /> pu:ProgressBarHelper.GeneratingPercentText="PgbHunger_GeneratingPercentText" />
<TextBlock x:Name="tStrengthFood" Grid.Row="6" Grid.Column="4" HorizontalAlignment="Right" Text="+1/m" <TextBlock x:Name="tStrengthFood" Grid.Row="6" Grid.Column="4" HorizontalAlignment="Right" Text="+1/t"
Foreground="{DynamicResource DARKPrimary}" /> Foreground="{DynamicResource DARKPrimary}" />
<TextBlock Grid.Row="7" Text="口渴度" VerticalAlignment="Center" /> <TextBlock Grid.Row="7" Text="口渴度" VerticalAlignment="Center" />
<ProgressBar x:Name="pStrengthDrink" Grid.Row="7" Grid.Column="2" Value="20" FontSize="20" Height="20" <ProgressBar x:Name="pStrengthDrink" Grid.Row="7" Grid.Column="2" Value="20" FontSize="20" Height="20"
@ -88,7 +88,7 @@
Foreground="{DynamicResource ProgressBarForeground}" Foreground="{DynamicResource ProgressBarForeground}"
pu:ProgressBarHelper.IsPercentVisible="True" pu:ProgressBarHelper.IsPercentVisible="True"
pu:ProgressBarHelper.GeneratingPercentText="PgbThirsty_GeneratingPercentText" /> pu:ProgressBarHelper.GeneratingPercentText="PgbThirsty_GeneratingPercentText" />
<TextBlock x:Name="tStrengthDrink" Grid.Row="7" Grid.Column="4" HorizontalAlignment="Right" Text="+1/m" <TextBlock x:Name="tStrengthDrink" Grid.Row="7" Grid.Column="4" HorizontalAlignment="Right" Text="+1/t"
Foreground="{DynamicResource DARKPrimary}" /> Foreground="{DynamicResource DARKPrimary}" />
</Grid> </Grid>
</Border> </Border>

View File

@ -61,6 +61,10 @@ namespace VPet_Simulator.Core
pFeeling.Value = m.Core.Save.Feeling; pFeeling.Value = m.Core.Save.Feeling;
pStrengthFood.Value = m.Core.Save.StrengthFood; pStrengthFood.Value = m.Core.Save.StrengthFood;
pStrengthDrink.Value = m.Core.Save.StrengthDrink; pStrengthDrink.Value = m.Core.Save.StrengthDrink;
tStrength.Text = $"{m.Core.Save.ChangeStrength:f1}/t";
tFeeling.Text = $"{m.Core.Save.ChangeFeeling:f1}/t";
tStrengthDrink.Text = $"{m.Core.Save.ChangeStrengthDrink:f1}/t";
tStrengthFood.Text = $"{m.Core.Save.ChangeStrengthFood:f1}/t";
} }
} }

View File

@ -54,7 +54,7 @@ namespace VPet_Simulator.Core
public GraphCore.GraphType GraphType { get; private set; } public GraphCore.GraphType GraphType { get; private set; }
private Action endwilldo; //private Action endwilldo;
int nowid; int nowid;
/// <summary> /// <summary>
/// 新建 PNG 动画 /// 新建 PNG 动画
@ -184,7 +184,8 @@ namespace VPet_Simulator.Core
} }
else else
{ {
parent.endwilldo = () => parent.Dispatcher.Invoke(Hidden); //parent.endwilldo = () => parent.Dispatcher.Invoke(Hidden);
//parent.Dispatcher.Invoke(Hidden);
if (parent.DoEndAction) if (parent.DoEndAction)
EndAction?.Invoke();//运行结束动画时事件 EndAction?.Invoke();//运行结束动画时事件
@ -221,11 +222,11 @@ namespace VPet_Simulator.Core
/// </summary> /// </summary>
public void Run(Action EndAction = null) public void Run(Action EndAction = null)
{ {
if(endwilldo != null && nowid != Animations.Count) //if(endwilldo != null && nowid != Animations.Count)
{ //{
endwilldo.Invoke(); // endwilldo.Invoke();
endwilldo = null; // endwilldo = null;
} //}
nowid = 0; nowid = 0;
PlayState = true; PlayState = true;
DoEndAction = true; DoEndAction = true;

View File

@ -17,7 +17,7 @@ namespace VPet_Simulator.Core
/// 宠物名字 /// 宠物名字
/// </summary> /// </summary>
public string Name; public string Name;
/// <summary> /// <summary>
/// 金钱 /// 金钱
/// </summary> /// </summary>
@ -44,11 +44,29 @@ namespace VPet_Simulator.Core
private double strength; private double strength;
/// <summary> /// <summary>
/// 变化 体力
/// </summary>
public double ChangeStrength = 0;
public void StrengthChange(double value)
{
ChangeStrength += value;
Strength += value;
}
/// <summary>
/// 饱腹度 /// 饱腹度
/// </summary> /// </summary>
public double StrengthFood { get => strengthFood; set => strengthFood = Math.Min(100, Math.Max(0, value)); } public double StrengthFood { get => strengthFood; set => strengthFood = Math.Min(100, Math.Max(0, value)); }
private double strengthFood; private double strengthFood;
public void StrengthChangeFood(double value)
{
ChangeStrengthFood += value;
StrengthFood += value;
}
/// <summary>
/// 变化 食物
/// </summary>
public double ChangeStrengthFood = 0;
/// <summary> /// <summary>
/// 口渴度 /// 口渴度
/// </summary> /// </summary>
@ -56,12 +74,30 @@ namespace VPet_Simulator.Core
private double strengthDrink; private double strengthDrink;
/// <summary> /// <summary>
/// 变化 口渴度
/// </summary>
public double ChangeStrengthDrink = 0;
public void StrengthChangeDrink(double value)
{
ChangeStrengthDrink += value;
StrengthDrink += value;
}
/// <summary>
/// 心情 /// 心情
/// </summary> /// </summary>
public double Feeling { get => feeling; set => feeling = Math.Min(100, Math.Max(0, value)); } public double Feeling { get => feeling; set => feeling = Math.Min(100, Math.Max(0, value)); }
private double feeling; private double feeling;
/// <summary> /// <summary>
/// 变化 心情
/// </summary>
public double ChangeFeeling = 0;
public void FeelingChange(double value)
{
ChangeFeeling += value;
Feeling += value;
}
/// <summary>
/// 健康(生病)(隐藏) /// 健康(生病)(隐藏)
/// </summary> /// </summary>
public double Health { get => health; set => health = Math.Min(100, Math.Max(0, value)); } public double Health { get => health; set => health = Math.Min(100, Math.Max(0, value)); }
@ -73,6 +109,19 @@ namespace VPet_Simulator.Core
public double Likability { get => likability; set => likability = Math.Min(90 + Level * 10, Math.Max(0, value)); } public double Likability { get => likability; set => likability = Math.Min(90 + Level * 10, Math.Max(0, value)); }
private double likability; private double likability;
/// <summary>
/// 清除变化
/// </summary>
public void CleanChange()
{
ChangeStrength = 0;
ChangeFeeling = 0;
ChangeStrengthDrink = 0;
ChangeStrengthFood = 0;
}
/// <summary> /// <summary>
/// 宠物状态模式 /// 宠物状态模式
/// </summary> /// </summary>