Skip to content

Commit

Permalink
支持宠物自己吃东西
Browse files Browse the repository at this point in the history
  • Loading branch information
LorisYounger committed Aug 23, 2023
1 parent 6abe8e0 commit a711ec8
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 127 deletions.
17 changes: 17 additions & 0 deletions VPet-Simulator.Core/Display/MainDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using static VPet_Simulator.Core.GraphInfo;
using System.Xml.Linq;
using System.Linq;
using System.Windows.Media;

namespace VPet_Simulator.Core
{
Expand Down Expand Up @@ -641,5 +642,21 @@ public Border FindDisplayBorder(IGraph graph)
}

}
/// <summary>
/// 显示夹层动画
/// </summary>
/// <param name="Type">动画类型</param>
/// <param name="img">夹层内容</param>
/// <param name="EndAction">动画结束后操作</param>
public void Display(GraphType Type, ImageSource img, Action EndAction)
{
var name = Core.Graph.FindName(Type);
var ig = Core.Graph.FindGraph(name, AnimatType.Single, Core.Save.Mode);
if (ig != null)
{
var b = FindDisplayBorder(ig);
ig.Run(b, img, EndAction);
}
}
}
}
21 changes: 18 additions & 3 deletions VPet-Simulator.Windows.Interface/Mod/Food.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public enum FoodType
/// 礼品 (没做)
/// </summary>
Gift,
/// <summary>
/// 不超模的好食物
/// </summary>
NoOverLoad,
}
/// <summary>
/// 食物类型
Expand Down Expand Up @@ -128,7 +132,7 @@ public string Description
sb.Append("好感度".Translate() + ":\t").Append(Likability > 0 ? "+" : "").Append(Likability.ToString("f2"));
desc = sb.ToString();
}

return desc + '\n' + descs + '\n' + Desc.Translate();
}
}
Expand All @@ -145,8 +149,19 @@ public string Description
/// </summary>
[Line(ignoreCase: true)]
public string Image;


private bool? isoverload = null;
/// <summary>
/// 该食物是否超模
/// </summary>
public bool IsOverLoad()
{
if (isoverload == null)
{
double realp = ((Exp / 4 + Strength / 5 + StrengthDrink / 3 + StrengthFood / 2 + Feeling / 6) / 3 + Health + Likability * 5);
isoverload = Price > realp * 1.3 || Price < realp * 0.7;//30%容错
}
return isoverload.Value;
}
/// <summary>
/// 加载物品图片
/// </summary>
Expand Down
14 changes: 14 additions & 0 deletions VPet-Simulator.Windows.Interface/Setting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,5 +415,19 @@ public int Resolution
get => this["gameconfig"].GetInt("resolution", 500);
set => this["gameconfig"].SetInt("resolution", value);
}

bool autobuy;
/// <summary>
/// 允许桌宠自动购买食品
/// </summary>
public bool AutoBuy
{
get => autobuy;
set
{
autobuy = value;
this["gameconfig"].SetBool("allowmove", !value);
}
}
}
}
91 changes: 90 additions & 1 deletion VPet-Simulator.Windows/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using CSCore.CoreAudioAPI;
using LinePutScript;
using LinePutScript.Localization.WPF;
using Panuon.WPF.UI;
using Steamworks;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -236,7 +237,42 @@ public void ShowBetterBuy(Food.FoodType type)
int lowstrengthAskCountDrink = 20;
private void lowStrength()
{
if (Core.Save.Mode == GameSave.ModeType.Happy || Core.Save.Mode == GameSave.ModeType.Nomal)
if (Set.AutoBuy && Core.Save.Money >= 100)
{
var havemoney = Core.Save.Money * 1.2;
List<Food> food = Foods.FindAll(x => x.Price >= 2 && x.Health >= 0 && x.Exp >= 0 && x.Likability >= 0 && x.Price < havemoney //桌宠不吃负面的食物
&& x.IsOverLoad() // 不吃超模食物
);

if (Core.Save.StrengthFood < 75)
{
if (Core.Save.StrengthFood < 50)
{//太饿了,找正餐
food = food.FindAll(x => x.Type == Food.FoodType.Meal && x.StrengthFood > 20);
}
else
{//找零食
food = food.FindAll(x => x.Type == Food.FoodType.Snack && x.StrengthFood > 10);
}
if (food.Count == 0)
return;
var item = food[Function.Rnd.Next(food.Count)];
Core.Save.Money -= item.Price * 1.2;
TakeItem(item);
Main.Display(GraphType.Eat, item.ImageSource, Main.DisplayToNomal);
}
else if (Core.Save.StrengthDrink < 75)
{
food = food.FindAll(x => x.Type == Food.FoodType.Drink && x.StrengthDrink > 10);
if (food.Count == 0)
return;
var item = food[Function.Rnd.Next(food.Count)];
Core.Save.Money -= item.Price * 1.2;
TakeItem(item);
Main.Display(GraphType.Drink, item.ImageSource, Main.DisplayToNomal);
}
}
else if (Core.Save.Mode == GameSave.ModeType.Happy || Core.Save.Mode == GameSave.ModeType.Nomal)
{
if (Core.Save.StrengthFood < 75 && Function.Rnd.Next(lowstrengthAskCountFood--) == 0)
{
Expand Down Expand Up @@ -339,6 +375,59 @@ private void lowStrength()


}
/// <summary>
/// 使用/食用物品 (不包括显示动画)
/// </summary>
/// <param name="item">物品</param>
public void TakeItem(Food item)
{
//获取吃腻时间
DateTime now = DateTime.Now;
DateTime eattime = Set.PetData.GetDateTime("buytime_" + item.Name, now);
double eattimes = 0;
if (eattime > now)
{
eattimes = (eattime - now).TotalHours;
}
//开始加点
Core.Save.EatFood(item, Math.Max(0.5, 1 - Math.Pow(eattimes, 2) * 0.01));
//吃腻了
eattimes += 2;
Set.PetData.SetDateTime("buytime_" + item.Name, now.AddHours(eattimes));
//通知
item.LoadEatTimeSource(this);
item.NotifyOfPropertyChange("Eattime");

Core.Save.Money -= item.Price;
//统计
Set.Statistics[(gint)("buy_" + item.Name)]++;
Set.Statistics[(gdbe)"stat_betterbuy"] += item.Price;
switch (item.Type)
{
case Food.FoodType.Food:
Set.Statistics[(gdbe)"stat_bb_food"] += item.Price;
break;
case Food.FoodType.Drink:
Set.Statistics[(gdbe)"stat_bb_drink"] += item.Price;
break;
case Food.FoodType.Drug:
Set.Statistics[(gdbe)"stat_bb_drug"] += item.Price;
break;
case Food.FoodType.Snack:
Set.Statistics[(gdbe)"stat_bb_snack"] += item.Price;
break;
case Food.FoodType.Functional:
Set.Statistics[(gdbe)"stat_bb_functional"] += item.Price;
break;
case Food.FoodType.Meal:
Set.Statistics[(gdbe)"stat_bb_meal"] += item.Price;
break;
case Food.FoodType.Gift:
Set.Statistics[(gdbe)"stat_bb_gift"] += item.Price;
break;
}
}


public void RunAction(string action)
{
Expand Down
7 changes: 0 additions & 7 deletions VPet-Simulator.Windows/VPet-Simulator.Windows.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@
<Compile Include="WinDesign\winReport.xaml.cs">
<DependentUpon>winReport.xaml</DependentUpon>
</Compile>
<Compile Include="WinDesign\winTrusteeShip.xaml.cs">
<DependentUpon>winTrusteeShip.xaml</DependentUpon>
</Compile>
<Page Include="PetHelper.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -234,10 +231,6 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="WinDesign\winTrusteeShip.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup Condition="'$(Platform)' == 'x86'">
<Reference Include="Facepunch.Steamworks.Win32, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
Expand Down
31 changes: 23 additions & 8 deletions VPet-Simulator.Windows/WinDesign/winBetterBuy.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,31 @@
Click="BtnSearch_Click" />
</Grid>
<TextBlock VerticalAlignment="Center" Margin="20,0,0,0" FontSize="16" FontWeight="Bold">
<Run Text="{ll:Str 金钱}" />: $ <Run x:Name="rMoney" Loaded="rMoney_Loaded" Text=""/>
<Run Text="{ll:Str 金钱}" />: $ <Run x:Name="rMoney" Loaded="rMoney_Loaded" Text="" />
</TextBlock>
</StackPanel>
<pu:Switch Content="{ll:Str 购买后不自动关闭窗口}" Grid.Column="2" FontSize="14" Margin="10,0,5,0" Height="20"
VerticalAlignment="Center" HorizontalAlignment="Right" BoxHeight="14" ToggleSize="18"
CheckedBackground="{DynamicResource Primary}" CheckedBorderBrush="{DynamicResource Primary}"
Background="Transparent" ToggleShadowColor="{x:Null}" IsChecked="{Binding StateOpen}"
CheckedToggleBrush="{DynamicResource DARKPrimaryText}"
ToggleBrush="{DynamicResource PrimaryDark}" pu:WindowX.IsDragMoveArea="False" BoxWidth="30"
Loaded="Switch_Loaded" />
<Grid HorizontalAlignment="Right">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<pu:Switch Content="{ll:Str 购买后不自动关闭窗口}" Grid.Column="2" FontSize="14" Margin="10,0,5,0" Height="20"
VerticalAlignment="Center" HorizontalAlignment="Left" BoxHeight="14" ToggleSize="18"
CheckedBackground="{DynamicResource Primary}" CheckedBorderBrush="{DynamicResource Primary}"
Background="Transparent" ToggleShadowColor="{x:Null}" IsChecked="{Binding StateOpen}"
CheckedToggleBrush="{DynamicResource DARKPrimaryText}"
ToggleBrush="{DynamicResource PrimaryDark}" pu:WindowX.IsDragMoveArea="False" BoxWidth="30"
Loaded="Switch_Loaded" />
<pu:Switch Content="{ll:Str 让宠物自己买东西吃}" Grid.Column="2" FontSize="14" Margin="10,0,5,0" Height="20"
VerticalAlignment="Center" HorizontalAlignment="Left" BoxHeight="14" ToggleSize="18"
CheckedBackground="{DynamicResource Primary}" CheckedBorderBrush="{DynamicResource Primary}"
Background="Transparent" ToggleShadowColor="{x:Null}" IsChecked="{Binding StateOpen}"
CheckedToggleBrush="{DynamicResource DARKPrimaryText}" Grid.Row="1"
ToggleBrush="{DynamicResource PrimaryDark}" pu:WindowX.IsDragMoveArea="False" BoxWidth="30"
ToolTip="{ll:Str '当宠物口渴或者饥饿的时候会自己买东西吃\&#13;请注意,宠物可能会乱花钱和吃错误的东西\&#13;额外加收20%外卖运送费用'}"
Loaded="Switch_Loaded_1" />
</Grid>

</Grid>
</DataTemplate>
</pu:WindowXCaption.HeaderTemplate>
Expand Down
89 changes: 24 additions & 65 deletions VPet-Simulator.Windows/WinDesign/winBetterBuy.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,11 @@ private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e
//PageDetail.RaiseEvent(eventArg);
}
bool showeatanm = true;

private void BtnBuy_Click(object sender, RoutedEventArgs e)
{

var Button = sender as Button;
var item = Button.DataContext as Food;

//看是什么模式
if (mw.Set.EnableFunction)
{
Expand All @@ -209,58 +208,7 @@ private void BtnBuy_Click(object sender, RoutedEventArgs e)
, "金钱不足".Translate());
return;
}

//获取吃腻时间

DateTime now = DateTime.Now;
DateTime eattime = mw.Set.PetData.GetDateTime("buytime_" + item.Name, now);
double eattimes = 0;
if (eattime <= now)
{
eattime = now;
}
else
{
eattimes = (eattime - now).TotalHours;
}
//开始加点
mw.Core.Save.EatFood(item, Math.Max(0.5, 1 - Math.Pow(eattimes, 2) * 0.01));
//吃腻了
eattimes += 2;
mw.Set.PetData.SetDateTime("buytime_" + item.Name, now.AddHours(eattimes));
//通知
item.LoadEatTimeSource(mw);
item.NotifyOfPropertyChange(DateTime.Now.ToString());

mw.Core.Save.Money -= item.Price;
//统计
mw.Set.Statistics[(gint)("buy_" + item.Name)]++;
mw.Set.Statistics[(gdbe)"stat_betterbuy"] += item.Price;
switch (item.Type)
{
case Food.FoodType.Food:
mw.Set.Statistics[(gdbe)"stat_bb_food"] += item.Price;
break;
case Food.FoodType.Drink:
mw.Set.Statistics[(gdbe)"stat_bb_drink"] += item.Price;
break;
case Food.FoodType.Drug:
mw.Set.Statistics[(gdbe)"stat_bb_drug"] += item.Price;
break;
case Food.FoodType.Snack:
mw.Set.Statistics[(gdbe)"stat_bb_snack"] += item.Price;
break;
case Food.FoodType.Functional:
mw.Set.Statistics[(gdbe)"stat_bb_functional"] += item.Price;
break;
case Food.FoodType.Meal:
mw.Set.Statistics[(gdbe)"stat_bb_meal"] += item.Price;
break;
case Food.FoodType.Gift:
mw.Set.Statistics[(gdbe)"stat_bb_gift"] += item.Price;
break;
}

mw.TakeItem(item);
}
if (showeatanm)
{//显示动画
Expand All @@ -278,18 +226,12 @@ private void BtnBuy_Click(object sender, RoutedEventArgs e)
gt = GraphType.Gift;
break;
}
var name = mw.Core.Graph.FindName(gt);
var ig = mw.Core.Graph.FindGraph(name, AnimatType.Single, mw.Core.Save.Mode);
if (ig != null)
mw.Main.Display(gt, item.ImageSource, () =>
{
var b = mw.Main.FindDisplayBorder(ig);
ig.Run(b, item.ImageSource, () =>
{
showeatanm = true;
mw.Main.DisplayToNomal();
mw.Main.EventTimer_Elapsed();
});
}
showeatanm = true;
mw.Main.DisplayToNomal();
mw.Main.EventTimer_Elapsed();
});
}
if (!_puswitch.IsChecked.Value)
{
Expand Down Expand Up @@ -394,5 +336,22 @@ private void rMoney_Loaded(object sender, RoutedEventArgs e)
rMoney = sender as Run;
rMoney.Text = mw.Core.Save.Money.ToString("f2");
}
private Switch _puswitchautobuy;
private void Switch_Loaded_1(object sender, RoutedEventArgs e)
{
_puswitchautobuy = sender as Switch;
_puswitchautobuy.IsChecked = mw.Set.AutoBuy;
_puswitchautobuy.Click += Switch_AutoBuy_Checked;
}
private void Switch_AutoBuy_Checked(object sender, RoutedEventArgs e)
{
if (_puswitchautobuy.IsChecked.Value && mw.Core.Save.Money < 100)
{
_puswitchautobuy.IsChecked = false;
MessageBoxX.Show(mw, "余额不足100,无法开启自动购买".Translate(), "更好买".Translate());
return;
}
mw.Set.AutoBuy = _puswitchautobuy.IsChecked.Value;
}
}
}
13 changes: 0 additions & 13 deletions VPet-Simulator.Windows/WinDesign/winTrusteeShip.xaml

This file was deleted.

Loading

0 comments on commit a711ec8

Please sign in to comment.