同步游戏数据

This commit is contained in:
ZouJin 2024-03-21 16:24:07 +08:00
parent 7fa99f1e70
commit 969d52c2f7
7 changed files with 74 additions and 39 deletions

View File

@ -49,9 +49,9 @@
</Button.ContentTemplate> </Button.ContentTemplate>
</Button> </Button>
<TextBlock x:Name="till" Grid.Row="1" Grid.ColumnSpan="5" Foreground="#FF4C4C" <TextBlock x:Name="till" Grid.Row="1" Grid.ColumnSpan="5" Foreground="#FF4C4C"
Text="{ll:Str 宠物已经生病\, 通过服用药物可以恢复}" TextWrapping="Wrap" /> Text="{ll:Str 宠物已经生病\, 通过服用药物可以恢复}" TextWrapping="Wrap" x:FieldModifier="public" />
<TextBlock x:Name="tfun" Grid.Row="1" Grid.ColumnSpan="5" Foreground="#4caf50" <TextBlock x:Name="tfun" Grid.Row="1" Grid.ColumnSpan="5" Foreground="#4caf50"
Text="{ll:Str 已关闭数据计算\, 可放心挂机}" TextWrapping="Wrap" /> Text="{ll:Str 已关闭数据计算\, 可放心挂机}" TextWrapping="Wrap" x:FieldModifier="public" />
<TextBlock Grid.Row="2" VerticalAlignment="Center" Text="{ll:Str 金钱}" /> <TextBlock Grid.Row="2" VerticalAlignment="Center" Text="{ll:Str 金钱}" />
<TextBlock x:Name="tMoney" Grid.Row="2" Grid.Column="2" Foreground="{DynamicResource DARKPrimary}" <TextBlock x:Name="tMoney" Grid.Row="2" Grid.Column="2" Foreground="{DynamicResource DARKPrimary}"
Text="$100,000" /> Text="$100,000" />

View File

@ -63,7 +63,9 @@ namespace VPet_Simulator.Core
if (m.StartWork(w)) if (m.StartWork(w))
Visibility = Visibility.Collapsed; Visibility = Visibility.Collapsed;
} }
/// <summary>
/// 加载默认工作
/// </summary>
public void LoadWork() public void LoadWork()
{ {
LoadClean(); LoadClean();
@ -156,8 +158,10 @@ namespace VPet_Simulator.Core
{ {
StartWork(wplay); StartWork(wplay);
} }
/// <summary>
private void M_TimeUIHandle(Main m) /// 刷新显示UI
/// </summary>
public void M_TimeUIHandle(Main m)
{ {
if (BdrPanel.Visibility == Visibility.Visible) if (BdrPanel.Visibility == Visibility.Visible)
{ {

View File

@ -867,6 +867,10 @@ namespace VPet_Simulator.Windows
SteamFriends.SetRichPresence("steam_player_group", winMutiPlayer.LobbyID.ToString("x")); SteamFriends.SetRichPresence("steam_player_group", winMutiPlayer.LobbyID.ToString("x"));
SteamFriends.SetRichPresence("steam_player_group_size", winMutiPlayer.lb.MemberCount.ToString()); SteamFriends.SetRichPresence("steam_player_group_size", winMutiPlayer.lb.MemberCount.ToString());
} }
else
{
SteamFriends.SetRichPresence("steam_player_group_size", "0");
}
if (App.MainWindows.Count > 1) if (App.MainWindows.Count > 1)
{ {
if (App.MainWindows.FirstOrDefault() != this) if (App.MainWindows.FirstOrDefault() != this)

View File

@ -167,20 +167,35 @@ public partial class MPFriends : WindowX, IMPFriend
Main.Event_TouchHead += Main_Event_TouchHead; Main.Event_TouchHead += Main_Event_TouchHead;
Main.Event_TouchBody += Main_Event_TouchBody; Main.Event_TouchBody += Main_Event_TouchBody;
SteamMatchmaking.OnLobbyMemberDataChanged += SteamMatchmaking_OnLobbyMemberDataChanged;
}); });
} }
private void SteamMatchmaking_OnLobbyMemberDataChanged(Lobby lobby, Friend friend)
{
if (lobby.Id == lb.Id && friend.Id == this.friend.Id)
{
string tmp = lb.GetMemberData(friend, "save");
if (!string.IsNullOrEmpty(tmp))
{
Core.Save = GameSave_VPet.Load(new Line(tmp));
Main.ToolBar.M_TimeUIHandle(Main);
Main.ToolBar.tfun.Visibility = Visibility.Collapsed;
}
}
}
private void Main_Event_TouchHead() private void Main_Event_TouchHead()
{ {
Main.LabelDisplayShow("{0}在摸{1}的头".Translate(SteamClient.Name, Core.Save.Name)); Main.LabelDisplayShow("{0}在摸{1}的头".Translate(SteamClient.Name, Core.Save.Name), 5000);
var msg = new MPMessage() { Type = (int)MSGType.Interact, To = friend.Id }; var msg = new MPMessage() { Type = (int)MSGType.Interact, To = friend.Id };
msg.SetContent(Interact.TouchHead); msg.SetContent(Interact.TouchHead);
wmp.SendMessageALL(msg); wmp.SendMessageALL(msg);
} }
private void Main_Event_TouchBody() private void Main_Event_TouchBody()
{ {
Main.LabelDisplayShow("{0}在摸{1}的头".Translate(SteamClient.Name, Core.Save.Name)); Main.LabelDisplayShow("{0}在摸{1}的头".Translate(SteamClient.Name, Core.Save.Name), 5000);
var msg = new MPMessage() { Type = (int)MSGType.Interact, To = friend.Id }; var msg = new MPMessage() { Type = (int)MSGType.Interact, To = friend.Id };
msg.SetContent(Interact.TouchBody); msg.SetContent(Interact.TouchBody);
wmp.SendMessageALL(msg); wmp.SendMessageALL(msg);
@ -253,15 +268,15 @@ public partial class MPFriends : WindowX, IMPFriend
petloader ??= Pets[0]; petloader ??= Pets[0];
////加载数据合理化:食物 //加载数据合理化:食物
//foreach (Food f in Foods) foreach (Food f in Foods)
//{ {
// if (f.IsOverLoad()) if (f.IsOverLoad())
// { {
// f.Price = Math.Max((int)f.RealPrice, 1); f.Price = Math.Max((int)f.RealPrice, 1);
// f.isoverload = false; f.isoverload = false;
// } }
//} }
await Dispatcher.InvokeAsync(new Action(() => await Dispatcher.InvokeAsync(new Action(() =>
{ {
LoadingText.Content = "尝试加载动画和生成缓存\n该步骤可能会耗时比较长\n请耐心等待".Translate(); LoadingText.Content = "尝试加载动画和生成缓存\n该步骤可能会耗时比较长\n请耐心等待".Translate();
@ -277,6 +292,14 @@ public partial class MPFriends : WindowX, IMPFriend
Main.Load_2_TouchEvent(); Main.Load_2_TouchEvent();
Task.Run(Main.Load_24_WaitAndStart); Task.Run(Main.Load_24_WaitAndStart);
Main.ToolBar.MenuInteract.Items.Clear();
Main.ToolBar.AddMenuButton(ToolBar.MenuType.Interact, "摸头".Translate(), Main.DisplayTouchHead);
Main.ToolBar.AddMenuButton(ToolBar.MenuType.Interact, "摸身体".Translate(), Main.DisplayTouchBody);
Main.ToolBar.AddMenuButton(ToolBar.MenuType.Interact, "捏脸".Translate(), () => DisplayPinch());
Main.ToolBar.AddMenuButton(ToolBar.MenuType.Setting, "退出访客表".Translate(), wmp.Close);
Main.ToolBar.tfun.Visibility = Visibility.Collapsed;
Main.EventTimer.AutoReset = false; Main.EventTimer.AutoReset = false;
Main.EventTimer.Enabled = false; Main.EventTimer.Enabled = false;
@ -373,7 +396,7 @@ public partial class MPFriends : WindowX, IMPFriend
return false; return false;
} }
Main.CountNomal = 0; Main.CountNomal = 0;
Main.LabelDisplayShow("{0}在捏{1}的脸".Translate(SteamClient.Name, Core.Save.Name), 5000);
if (Main.DisplayType.Name == "pinch") if (Main.DisplayType.Name == "pinch")
{ {
if (Main.DisplayType.Animat == AnimatType.A_Start) if (Main.DisplayType.Animat == AnimatType.A_Start)
@ -396,19 +419,12 @@ public partial class MPFriends : WindowX, IMPFriend
} }
private void DisplayPinch_loop() private void DisplayPinch_loop()
{ {
Main.LabelDisplayShow("{0}在捏{1}的脸".Translate(SteamClient.Name, Core.Save.Name)); Main.LabelDisplayShow("{0}在捏{1}的脸".Translate(SteamClient.Name, Core.Save.Name), 5000);
var msg = new MPMessage() { Type = (int)MSGType.Interact, To = friend.Id }; var msg = new MPMessage() { Type = (int)MSGType.Interact, To = friend.Id };
msg.SetContent(Interact.TouchPinch); msg.SetContent(Interact.TouchPinch);
wmp.SendMessageALL(msg); wmp.SendMessageALL(msg);
if (Main.isPress && Main.DisplayType.Name == "pinch" && Main.DisplayType.Animat == AnimatType.B_Loop) if (Main.isPress && Main.DisplayType.Name == "pinch" && Main.DisplayType.Animat == AnimatType.B_Loop)
{ {
if (Core.Controller.EnableFunction && Core.Save.Strength >= 10 && Core.Save.Feeling < 100)
{
Core.Save.StrengthChange(-2);
Core.Save.FeelingChange(1);
Core.Save.Mode = Core.Save.CalMode();
Main.LabelDisplayShowChangeNumber(LocalizeCore.Translate("体力-{0:f0} 心情+{1:f0}"), 2, 1);
}
Main.Display("pinch", AnimatType.B_Loop, DisplayPinch_loop); Main.Display("pinch", AnimatType.B_Loop, DisplayPinch_loop);
} }
else else
@ -509,7 +525,7 @@ public partial class MPFriends : WindowX, IMPFriend
{ {
case Interact.TouchHead: case Interact.TouchHead:
case Interact.TouchBody: case Interact.TouchBody:
Main.LabelDisplayShow("{0}在摸{1}的头".Translate(byname, Core.Save.Name)); Main.LabelDisplayShow("{0}在摸{1}的头".Translate(byname, Core.Save.Name), 5000);
break; break;
case Interact.TouchPinch: case Interact.TouchPinch:
Main.LabelDisplayShow("{0}在捏{1}的脸".Translate(byname, Core.Save.Name)); Main.LabelDisplayShow("{0}在捏{1}的脸".Translate(byname, Core.Save.Name));
@ -521,15 +537,15 @@ public partial class MPFriends : WindowX, IMPFriend
{ {
case Interact.TouchHead: case Interact.TouchHead:
DisplayNOCALTouchHead(); DisplayNOCALTouchHead();
Main.LabelDisplayShow("{0}在摸{1}的头".Translate(byname, Core.Save.Name)); Main.LabelDisplayShow("{0}在摸{1}的头".Translate(byname, Core.Save.Name), 5000);
break; break;
case Interact.TouchBody: case Interact.TouchBody:
DisplayNOCALTouchBody(); DisplayNOCALTouchBody();
Main.LabelDisplayShow("{0}在摸{1}的头".Translate(byname, Core.Save.Name)); Main.LabelDisplayShow("{0}在摸{1}的头".Translate(byname, Core.Save.Name), 5000);
break; break;
case Interact.TouchPinch: case Interact.TouchPinch:
DisplayNOCALTouchPinch(); DisplayNOCALTouchPinch();
Main.LabelDisplayShow("{0}在捏{1}的脸".Translate(byname, Core.Save.Name)); Main.LabelDisplayShow("{0}在捏{1}的脸".Translate(byname, Core.Save.Name), 5000);
break; break;
} }
} }
@ -631,6 +647,7 @@ public partial class MPFriends : WindowX, IMPFriend
} }
} }
} }
SteamMatchmaking.OnLobbyMemberDataChanged -= SteamMatchmaking_OnLobbyMemberDataChanged;
winMPBetterBuy?.Close(); winMPBetterBuy?.Close();
Main?.Dispose(); Main?.Dispose();
mw.Windows.Remove(this); mw.Windows.Remove(this);

View File

@ -7,10 +7,10 @@
mc:Ignorable="d" Margin="5" Width="340" Height="100" Background="{DynamicResource SecondaryLight}" mc:Ignorable="d" Margin="5" Width="340" Height="100" Background="{DynamicResource SecondaryLight}"
BorderBrush="{DynamicResource Secondary}"> BorderBrush="{DynamicResource Secondary}">
<Grid> <Grid>
<pu:ContentControlX HorizontalAlignment="Left" Margin="4" CornerRadius="43"> <pu:ContentControlX HorizontalAlignment="Left" Margin="12" CornerRadius="35">
<Image x:Name="uimg" Source="/Res/TopLogo2019.PNG" /> <Image x:Name="uimg" Source="/Res/TopLogo2019.PNG" />
</pu:ContentControlX> </pu:ContentControlX>
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Margin="100,0,0,0" <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Margin="90,0,0,0"
Foreground="{DynamicResource DARKPrimaryDarker}" FontSize="16"> Foreground="{DynamicResource DARKPrimaryDarker}" FontSize="16">
<Run Text="{ll:Str 访客}" />: <Run x:Name="rPetName" Text="{ll:Str 萝莉斯}" FontSize="20" FontWeight="Bold" /> <Run Text="{ll:Str 访客}" />: <Run x:Name="rPetName" Text="{ll:Str 萝莉斯}" FontSize="20" FontWeight="Bold" />
<LineBreak /> <LineBreak />

View File

@ -201,9 +201,9 @@ namespace VPet_Simulator.Windows
mf.DisplayFoodAnimation(item.GetGraph(), item.ImageSource); mf.DisplayFoodAnimation(item.GetGraph(), item.ImageSource);
if (EnableFunction) if (EnableFunction)
mf.Main.LabelDisplayShow("{0}花费${3}\n给{1}买了{2}".Translate(SteamClient.Name, mf.Core.Save.Name, item.TranslateName, item.Price)); mf.Main.LabelDisplayShow("{0}花费${3}\n给{1}买了{2}".Translate(SteamClient.Name, mf.Core.Save.Name, item.TranslateName, item.Price), 10000);
else else
mf.Main.LabelDisplayShow("{0}给{1}买了{2}".Translate(SteamClient.Name, mf.Core.Save.Name, item.TranslateName)); mf.Main.LabelDisplayShow("{0}给{1}买了{2}".Translate(SteamClient.Name, mf.Core.Save.Name, item.TranslateName), 10000);
var msg = new MPMessage() var msg = new MPMessage()
{ {

View File

@ -136,6 +136,7 @@ public partial class winMutiPlayer : Window, IMPWindows
SteamMatchmaking.OnLobbyMemberJoined += SteamMatchmaking_OnLobbyMemberJoined; SteamMatchmaking.OnLobbyMemberJoined += SteamMatchmaking_OnLobbyMemberJoined;
SteamMatchmaking.OnLobbyMemberLeave += SteamMatchmaking_OnLobbyMemberLeave; SteamMatchmaking.OnLobbyMemberLeave += SteamMatchmaking_OnLobbyMemberLeave;
SteamMatchmaking.OnLobbyDataChanged += SteamMatchmaking_OnLobbyDataChanged; SteamMatchmaking.OnLobbyDataChanged += SteamMatchmaking_OnLobbyDataChanged;
Steamworks.Data.Image? img = await lb.Owner.GetMediumAvatarAsync(); Steamworks.Data.Image? img = await lb.Owner.GetMediumAvatarAsync();
Dispatcher.Invoke(() => Dispatcher.Invoke(() =>
@ -154,6 +155,7 @@ public partial class winMutiPlayer : Window, IMPWindows
//给自己动画添加绑定 //给自己动画添加绑定
mw.Main.GraphDisplayHandler += Main_GraphDisplayHandler; mw.Main.GraphDisplayHandler += Main_GraphDisplayHandler;
mw.Main.TimeHandle += Main_TimeHandle;
if (IsHost) if (IsHost)
{ {
Dispatcher.Invoke(() => Dispatcher.Invoke(() =>
@ -196,6 +198,11 @@ public partial class winMutiPlayer : Window, IMPWindows
}); });
} }
private void Main_TimeHandle(Main obj)
{
lb.SetMemberData("save", mw.GameSavesData.GameSave.ToLine().ToString());
}
private void SteamMatchmaking_OnLobbyDataChanged(Lobby lobby) private void SteamMatchmaking_OnLobbyDataChanged(Lobby lobby)
{ {
if (lb.Id == lobby.Id) if (lb.Id == lobby.Id)
@ -341,17 +348,17 @@ public partial class winMutiPlayer : Window, IMPWindows
switch (interact) switch (interact)
{ {
case Interact.TouchHead: case Interact.TouchHead:
mw.Main.LabelDisplayShow("{0}在摸{1}的头".Translate(byname, mw.Core.Save.Name)); mw.Main.LabelDisplayShow("{0}在摸{1}的头".Translate(byname, mw.Core.Save.Name), 5000);
if (isok) if (isok)
DisplayNOCALTouchHead(); DisplayNOCALTouchHead();
break; break;
case Interact.TouchBody: case Interact.TouchBody:
mw.Main.LabelDisplayShow("{0}在摸{1}的头".Translate(byname, mw.Core.Save.Name)); mw.Main.LabelDisplayShow("{0}在摸{1}的头".Translate(byname, mw.Core.Save.Name), 5000);
if (isok) if (isok)
DisplayNOCALTouchBody(); DisplayNOCALTouchBody();
break; break;
case Interact.TouchPinch: case Interact.TouchPinch:
mw.Main.LabelDisplayShow("{0}在捏{1}的脸".Translate(byname, mw.Core.Save.Name)); mw.Main.LabelDisplayShow("{0}在捏{1}的脸".Translate(byname, mw.Core.Save.Name), 5000);
if (isok) if (isok)
DisplayNOCALTouchPinch(); DisplayNOCALTouchPinch();
break; break;
@ -373,7 +380,7 @@ public partial class winMutiPlayer : Window, IMPWindows
mw.DisplayFoodAnimation(feed.Item.GetGraph(), feed.Item.ImageSource); mw.DisplayFoodAnimation(feed.Item.GetGraph(), feed.Item.ImageSource);
if (feed.EnableFunction) if (feed.EnableFunction)
{ {
mw.Main.LabelDisplayShow("{0}花费${3}给{1}买了{2}".Translate(byname, mw.GameSavesData.GameSave.Name, feed.Item.TranslateName, feed.Item.Price)); mw.Main.LabelDisplayShow("{0}花费${3}给{1}买了{2}".Translate(byname, mw.GameSavesData.GameSave.Name, feed.Item.TranslateName, feed.Item.Price), 10000);
//对于要修改数据的物品一定要再次检查,避免联机开挂毁存档 //对于要修改数据的物品一定要再次检查,避免联机开挂毁存档
if (item.Price >= 10 && item.Price <= 1000 && item.Health >= 0 && item.Exp >= 0 && item.Likability >= 0 && giveprice < 1000) if (item.Price >= 10 && item.Price <= 1000 && item.Health >= 0 && item.Exp >= 0 && item.Likability >= 0 && giveprice < 1000)
{//单次联机收礼物上限1000 {//单次联机收礼物上限1000
@ -382,7 +389,7 @@ public partial class winMutiPlayer : Window, IMPWindows
} }
} }
else else
mw.Main.LabelDisplayShow("{0}给{1}买了{2}".Translate(byname, mw.GameSavesData.GameSave.Name, feed.Item.TranslateName)); mw.Main.LabelDisplayShow("{0}给{1}买了{2}".Translate(byname, mw.GameSavesData.GameSave.Name, feed.Item.TranslateName), 10000);
} }
else else
{ {
@ -406,8 +413,11 @@ public partial class winMutiPlayer : Window, IMPWindows
public event Action<ulong, MPMessage> ReceivedMessage; public event Action<ulong, MPMessage> ReceivedMessage;
private void Window_Closed(object sender, EventArgs e) private void Window_Closed(object sender, EventArgs e)
{ {
mw.Main.TimeHandle -= Main_TimeHandle;
mw.Main.GraphDisplayHandler -= Main_GraphDisplayHandler; mw.Main.GraphDisplayHandler -= Main_GraphDisplayHandler;
SteamMatchmaking.OnLobbyMemberJoined -= SteamMatchmaking_OnLobbyMemberJoined; SteamMatchmaking.OnLobbyMemberJoined -= SteamMatchmaking_OnLobbyMemberJoined;
SteamMatchmaking.OnLobbyMemberLeave -= SteamMatchmaking_OnLobbyMemberLeave;
SteamMatchmaking.OnLobbyDataChanged -= SteamMatchmaking_OnLobbyDataChanged;
lb.Leave(); lb.Leave();
for (int i = 0; i < MPFriends.Count; i++) for (int i = 0; i < MPFriends.Count; i++)
{ {