2024-03-15 17:33:56 +00:00
|
|
|
|
using LinePutScript;
|
2024-03-16 16:41:20 +00:00
|
|
|
|
using LinePutScript.Converter;
|
2024-03-15 17:33:56 +00:00
|
|
|
|
using LinePutScript.Localization.WPF;
|
2024-03-22 09:28:37 +00:00
|
|
|
|
using Microsoft.VisualBasic.Logging;
|
2024-03-15 17:33:56 +00:00
|
|
|
|
using Panuon.WPF.UI;
|
|
|
|
|
using Steamworks;
|
|
|
|
|
using Steamworks.Data;
|
2024-03-16 16:41:20 +00:00
|
|
|
|
using Steamworks.ServerList;
|
2024-03-15 17:33:56 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2024-03-19 15:14:19 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
2024-03-15 17:33:56 +00:00
|
|
|
|
using System.Text;
|
2024-03-16 16:41:20 +00:00
|
|
|
|
using System.Threading;
|
2024-03-15 17:33:56 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
using System.Windows.Documents;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
2024-03-19 18:36:35 +00:00
|
|
|
|
using System.Xml.Linq;
|
2024-03-16 16:41:20 +00:00
|
|
|
|
using VPet_Simulator.Core;
|
|
|
|
|
using VPet_Simulator.Windows.Interface;
|
2024-03-17 16:25:04 +00:00
|
|
|
|
using static VPet_Simulator.Core.GraphInfo;
|
2024-03-18 13:34:41 +00:00
|
|
|
|
using static VPet_Simulator.Windows.Interface.MPMessage;
|
2024-03-15 17:33:56 +00:00
|
|
|
|
|
|
|
|
|
namespace VPet_Simulator.Windows;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// winMutiPlayer.xaml 的交互逻辑
|
|
|
|
|
/// </summary>
|
2024-03-19 15:14:19 +00:00
|
|
|
|
public partial class winMutiPlayer : Window, IMPWindows
|
2024-03-15 17:33:56 +00:00
|
|
|
|
{
|
2024-03-21 07:53:03 +00:00
|
|
|
|
public Lobby lb;
|
2024-03-15 17:33:56 +00:00
|
|
|
|
MainWindow mw;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 好友宠物模块
|
|
|
|
|
/// </summary>
|
2024-03-16 16:41:20 +00:00
|
|
|
|
public List<MPFriends> MPFriends = new List<MPFriends>();
|
2024-03-17 16:25:04 +00:00
|
|
|
|
public List<MPUserControl> MPUserControls = new List<MPUserControl>();
|
2024-03-15 17:33:56 +00:00
|
|
|
|
public winMutiPlayer(MainWindow mw, ulong? lobbyid = null)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
this.mw = mw;
|
|
|
|
|
if (lobbyid == null)
|
|
|
|
|
CreateLobby();
|
|
|
|
|
else
|
2024-03-16 17:02:08 +00:00
|
|
|
|
JoinLobby(lobbyid.Value);
|
2024-03-15 17:33:56 +00:00
|
|
|
|
}
|
2024-03-16 17:02:08 +00:00
|
|
|
|
public async void JoinLobby(ulong lobbyid)
|
2024-03-15 17:33:56 +00:00
|
|
|
|
{
|
2024-03-16 11:21:37 +00:00
|
|
|
|
var lbt = (await SteamMatchmaking.JoinLobbyAsync((SteamId)lobbyid));
|
2024-03-16 14:39:25 +00:00
|
|
|
|
if (!lbt.HasValue || lbt.Value.Owner.Id.Value == 0)
|
2024-03-16 11:21:37 +00:00
|
|
|
|
{
|
|
|
|
|
MessageBoxX.Show("加入/创建访客表失败,请检查网络连接或重启游戏".Translate());
|
|
|
|
|
Close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
lb = lbt.Value;
|
2024-03-15 17:33:56 +00:00
|
|
|
|
ShowLobbyInfo();
|
|
|
|
|
}
|
|
|
|
|
public async void CreateLobby()
|
|
|
|
|
{
|
2024-03-16 11:21:37 +00:00
|
|
|
|
var lbt = (await SteamMatchmaking.CreateLobbyAsync());
|
|
|
|
|
if (!lbt.HasValue)
|
|
|
|
|
{
|
|
|
|
|
MessageBoxX.Show("加入/创建访客表失败,请检查网络连接或重启游戏".Translate());
|
|
|
|
|
Close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
lb = lbt.Value;
|
2024-03-15 17:33:56 +00:00
|
|
|
|
lb.SetJoinable(true);
|
|
|
|
|
lb.SetPublic();
|
2024-03-21 07:53:03 +00:00
|
|
|
|
IsHost = true;
|
|
|
|
|
swAllowJoin.IsEnabled = true;
|
2024-03-15 17:33:56 +00:00
|
|
|
|
ShowLobbyInfo();
|
|
|
|
|
}
|
2024-03-16 16:41:20 +00:00
|
|
|
|
public static ImageSource ConvertToImageSource(Steamworks.Data.Image? img)
|
2024-03-15 17:33:56 +00:00
|
|
|
|
{
|
2024-03-16 16:41:20 +00:00
|
|
|
|
if (img == null)
|
|
|
|
|
{
|
|
|
|
|
return new BitmapImage(new Uri("pack://application:,,,/Res/vpeticon.png"));
|
|
|
|
|
}
|
|
|
|
|
var image = img.Value;
|
2024-03-15 17:33:56 +00:00
|
|
|
|
int stride = (int)((image.Width * 32 + 7) / 8); // 32 bits per pixel
|
|
|
|
|
// Convert RGBA to BGRA
|
|
|
|
|
for (int i = 0; i < image.Data.Length; i += 4)
|
|
|
|
|
{
|
|
|
|
|
byte r = image.Data[i];
|
|
|
|
|
image.Data[i] = image.Data[i + 2];
|
|
|
|
|
image.Data[i + 2] = r;
|
|
|
|
|
}
|
|
|
|
|
var bitmap = BitmapSource.Create(
|
|
|
|
|
(int)image.Width,
|
|
|
|
|
(int)image.Height,
|
|
|
|
|
96, 96, // dpi x, dpi y
|
|
|
|
|
PixelFormats.Bgra32, // Pixel format
|
|
|
|
|
null, // Bitmap palette
|
|
|
|
|
image.Data, // Pixel data
|
|
|
|
|
stride // Stride
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Convert to ImageSource
|
|
|
|
|
var stream = new MemoryStream();
|
|
|
|
|
var encoder = new PngBitmapEncoder(); // or use another encoder if you want
|
|
|
|
|
encoder.Frames.Add(BitmapFrame.Create(bitmap));
|
|
|
|
|
encoder.Save(stream);
|
|
|
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
|
|
|
|
|
BitmapFrame result = BitmapFrame.Create(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2024-03-19 18:36:35 +00:00
|
|
|
|
|
2024-03-21 07:53:03 +00:00
|
|
|
|
public ulong HostID { get; set; }
|
|
|
|
|
public bool IsHost { get; set; } = false;
|
2024-03-19 15:14:19 +00:00
|
|
|
|
|
|
|
|
|
public ulong LobbyID => lb.Id.Value;
|
|
|
|
|
|
2024-03-21 07:53:03 +00:00
|
|
|
|
public bool Joinable { get; set; } = true;
|
|
|
|
|
|
2024-03-19 15:14:19 +00:00
|
|
|
|
public IEnumerable<IMPFriend> Friends => MPFriends;
|
|
|
|
|
|
2024-03-19 18:36:35 +00:00
|
|
|
|
public bool IsGameRunning { get; set; }
|
|
|
|
|
|
2024-03-20 05:17:14 +00:00
|
|
|
|
public TabControl TabControl => tabControl;
|
|
|
|
|
|
2024-03-18 06:59:05 +00:00
|
|
|
|
public void ShowLobbyInfo()
|
2024-03-15 17:33:56 +00:00
|
|
|
|
{
|
2024-03-18 06:59:05 +00:00
|
|
|
|
_ = Task.Run(async () =>
|
2024-03-17 18:22:47 +00:00
|
|
|
|
{
|
2024-03-18 06:59:05 +00:00
|
|
|
|
lb.SetMemberData("save", mw.GameSavesData.GameSave.ToLine().ToString());
|
|
|
|
|
lb.SetMemberData("onmod", mw.Set.FindLine("onmod")?.ToString() ?? "onmod");
|
|
|
|
|
lb.SetMemberData("petgraph", mw.Set.PetGraph);
|
2024-03-22 13:48:07 +00:00
|
|
|
|
lb.SetMemberData("notouch", mw.Set.MPNOTouch.ToString());
|
2024-03-16 16:41:20 +00:00
|
|
|
|
|
2024-03-18 06:59:05 +00:00
|
|
|
|
SteamMatchmaking.OnLobbyMemberJoined += SteamMatchmaking_OnLobbyMemberJoined;
|
|
|
|
|
SteamMatchmaking.OnLobbyMemberLeave += SteamMatchmaking_OnLobbyMemberLeave;
|
2024-03-20 05:17:14 +00:00
|
|
|
|
SteamMatchmaking.OnLobbyDataChanged += SteamMatchmaking_OnLobbyDataChanged;
|
2024-03-22 09:28:37 +00:00
|
|
|
|
|
2024-03-18 06:59:05 +00:00
|
|
|
|
Steamworks.Data.Image? img = await lb.Owner.GetMediumAvatarAsync();
|
|
|
|
|
|
|
|
|
|
Dispatcher.Invoke(() =>
|
|
|
|
|
{
|
|
|
|
|
hostName.Text = lb.Owner.Name;
|
2024-03-21 07:53:03 +00:00
|
|
|
|
HostID = lb.Owner.Id.Value;
|
2024-03-18 06:59:05 +00:00
|
|
|
|
lbLid.Text = lb.Id.Value.ToString("x");
|
|
|
|
|
HostHead.Source = ConvertToImageSource(img.Value);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
SteamNetworking.AllowP2PPacketRelay(true);
|
|
|
|
|
SteamNetworking.OnP2PSessionRequest = (steamid) =>
|
|
|
|
|
{
|
|
|
|
|
SteamNetworking.AcceptP2PSessionWithUser(steamid);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//给自己动画添加绑定
|
|
|
|
|
mw.Main.GraphDisplayHandler += Main_GraphDisplayHandler;
|
2024-03-21 08:24:07 +00:00
|
|
|
|
mw.Main.TimeHandle += Main_TimeHandle;
|
2024-03-21 07:53:03 +00:00
|
|
|
|
if (IsHost)
|
2024-03-18 06:59:05 +00:00
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(() =>
|
2024-03-16 16:41:20 +00:00
|
|
|
|
{
|
2024-03-18 06:59:05 +00:00
|
|
|
|
hostPet.Text = mw.GameSavesData.GameSave.Name;
|
|
|
|
|
Title = "{0}的访客表".Translate(mw.GameSavesData.GameSave.Name);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
//获取成员列表
|
|
|
|
|
foreach (var v in lb.Members)
|
|
|
|
|
{
|
|
|
|
|
if (v.Id == SteamClient.SteamId) continue;
|
|
|
|
|
var mpf = Dispatcher.Invoke(() =>
|
|
|
|
|
{
|
|
|
|
|
var mpf = new MPFriends(this, mw, lb, v);
|
|
|
|
|
MPFriends.Add(mpf);
|
|
|
|
|
mpf.Show();
|
|
|
|
|
var mpuc = new MPUserControl(this, mpf);
|
|
|
|
|
MUUCList.Children.Add(mpuc);
|
|
|
|
|
MPUserControls.Add(mpuc);
|
|
|
|
|
return mpf;
|
|
|
|
|
});
|
|
|
|
|
if (v.Id == lb.Owner.Id)
|
|
|
|
|
_ = Task.Run(() =>
|
2024-03-16 16:41:20 +00:00
|
|
|
|
{
|
2024-03-18 06:59:05 +00:00
|
|
|
|
//加载lobby传过来的数据
|
|
|
|
|
while (!mpf.Loaded)
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(500);
|
|
|
|
|
}
|
|
|
|
|
Dispatcher.Invoke(() =>
|
|
|
|
|
{
|
|
|
|
|
Title = "{0}的访客表".Translate(mpf.Core.Save.Name);
|
|
|
|
|
hostPet.Text = mpf.Core.Save.Name;
|
|
|
|
|
});
|
2024-03-16 16:41:20 +00:00
|
|
|
|
});
|
2024-03-18 06:59:05 +00:00
|
|
|
|
}
|
2024-03-19 15:14:19 +00:00
|
|
|
|
mw.MutiPlayerStart(this);
|
2024-03-22 09:28:37 +00:00
|
|
|
|
Log("已成功连接到访客表".Translate());
|
2024-03-18 06:59:05 +00:00
|
|
|
|
LoopP2PPacket();
|
|
|
|
|
});
|
2024-03-15 17:33:56 +00:00
|
|
|
|
}
|
2024-03-20 05:17:14 +00:00
|
|
|
|
|
2024-03-21 08:24:07 +00:00
|
|
|
|
private void Main_TimeHandle(Main obj)
|
|
|
|
|
{
|
|
|
|
|
lb.SetMemberData("save", mw.GameSavesData.GameSave.ToLine().ToString());
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-20 05:17:14 +00:00
|
|
|
|
private void SteamMatchmaking_OnLobbyDataChanged(Lobby lobby)
|
|
|
|
|
{
|
|
|
|
|
if (lb.Id == lobby.Id)
|
|
|
|
|
{
|
|
|
|
|
if (lb.GetData("kick") == SteamClient.SteamId.Value.ToString())
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() => MessageBox.Show("访客表已被房主{0}关闭".Translate(lb.Owner.Name)));//温柔的谎言
|
2024-03-21 07:53:03 +00:00
|
|
|
|
lb.Leave();
|
2024-03-20 05:17:14 +00:00
|
|
|
|
lb = default(Lobby);
|
|
|
|
|
Close();
|
|
|
|
|
}
|
2024-03-21 07:53:03 +00:00
|
|
|
|
|
|
|
|
|
if (lb.GetData("nojoin") == "true")
|
|
|
|
|
{
|
|
|
|
|
Joinable = false;
|
|
|
|
|
Dispatcher.Invoke(() => swAllowJoin.IsChecked = false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Joinable = true;
|
|
|
|
|
Dispatcher.Invoke(() => swAllowJoin.IsChecked = true);
|
|
|
|
|
}
|
2024-03-20 05:17:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-19 15:14:19 +00:00
|
|
|
|
public event Action<ulong> OnMemberLeave;
|
2024-03-17 16:25:04 +00:00
|
|
|
|
private void SteamMatchmaking_OnLobbyMemberLeave(Lobby lobby, Friend friend)
|
2024-03-16 16:41:20 +00:00
|
|
|
|
{
|
2024-03-19 15:14:19 +00:00
|
|
|
|
if (lobby.Id != lb.Id) return;
|
|
|
|
|
OnMemberLeave?.Invoke(friend.Id);
|
2024-03-21 07:53:03 +00:00
|
|
|
|
if (friend.Id == HostID)
|
2024-03-17 16:25:04 +00:00
|
|
|
|
{
|
|
|
|
|
Task.Run(() => MessageBox.Show("访客表已被房主{0}关闭".Translate(friend.Name)));
|
|
|
|
|
lb = default(Lobby);
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var mpuc = MPUserControls.Find(x => x.mpf.friend.Id == friend.Id);
|
|
|
|
|
if (mpuc != null)
|
|
|
|
|
{
|
|
|
|
|
MPUserControls.Remove(mpuc);
|
|
|
|
|
MUUCList.Children.Remove(mpuc);
|
|
|
|
|
MPFriends.Remove(mpuc.mpf);
|
2024-03-17 18:22:47 +00:00
|
|
|
|
mpuc.mpf.Quit();
|
2024-03-17 16:25:04 +00:00
|
|
|
|
}
|
2024-03-22 09:28:37 +00:00
|
|
|
|
Log("好友{0}已退出访客表".Translate(friend.Name));
|
2024-03-17 16:25:04 +00:00
|
|
|
|
}
|
2024-03-16 16:41:20 +00:00
|
|
|
|
}
|
2024-03-18 17:55:25 +00:00
|
|
|
|
GraphInfo lastgraph = new GraphInfo() { Type = GraphType.Common };
|
2024-03-17 16:25:04 +00:00
|
|
|
|
private void Main_GraphDisplayHandler(GraphInfo info)
|
2024-03-15 17:33:56 +00:00
|
|
|
|
{
|
2024-03-17 16:25:04 +00:00
|
|
|
|
if (info.Type == GraphType.Shutdown || info.Type == GraphType.Common || info.Type == GraphType.Move
|
2024-03-19 13:25:35 +00:00
|
|
|
|
|| info.Type == GraphType.Raised_Dynamic || info.Type == GraphType.Raised_Static || info.Type == GraphType.Say)
|
2024-03-15 17:33:56 +00:00
|
|
|
|
{
|
2024-03-17 16:25:04 +00:00
|
|
|
|
return;
|
2024-03-15 17:33:56 +00:00
|
|
|
|
}
|
2024-03-18 17:55:25 +00:00
|
|
|
|
//如果是同一个动画就不发送
|
|
|
|
|
if (lastgraph.Type == info.Type && lastgraph.Animat == info.Animat && info.Name == lastgraph.Name)
|
|
|
|
|
return;
|
|
|
|
|
lastgraph = info;
|
2024-03-17 18:22:47 +00:00
|
|
|
|
MPMessage msg = new MPMessage();
|
2024-03-19 15:14:19 +00:00
|
|
|
|
msg.Type = (int)MSGType.DispayGraph;
|
2024-03-18 13:34:41 +00:00
|
|
|
|
msg.SetContent(info);
|
2024-03-17 18:22:47 +00:00
|
|
|
|
msg.To = SteamClient.SteamId.Value;
|
2024-03-18 13:34:41 +00:00
|
|
|
|
SendMessageALL(msg);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 给指定好友发送消息
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void SendMessage(ulong friendid, MPMessage msg)
|
|
|
|
|
{
|
|
|
|
|
byte[] data = ConverTo(msg);
|
|
|
|
|
SteamNetworking.SendP2PPacket(friendid, data);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 给所有人发送消息
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void SendMessageALL(MPMessage msg)
|
|
|
|
|
{
|
|
|
|
|
byte[] data = ConverTo(msg);
|
2024-03-17 18:22:47 +00:00
|
|
|
|
for (int i = 0; i < MPFriends.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
MPFriends v = MPFriends[i];
|
|
|
|
|
SteamNetworking.SendP2PPacket(v.friend.Id, data);
|
|
|
|
|
}
|
2024-03-15 17:33:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-19 15:14:19 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 发送日志消息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message">日志</param>
|
|
|
|
|
public void Log(string message)
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(() => tbLog.AppendText($"[{DateTime.Now.ToShortTimeString()}]{message}\n"));
|
|
|
|
|
}
|
2024-03-18 13:34:41 +00:00
|
|
|
|
|
2024-03-19 15:14:19 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 事件:成员加入
|
|
|
|
|
/// </summary>
|
|
|
|
|
public event Action<ulong> OnMemberJoined;
|
2024-03-17 16:25:04 +00:00
|
|
|
|
private void SteamMatchmaking_OnLobbyMemberJoined(Lobby lobby, Friend friend)
|
2024-03-15 17:33:56 +00:00
|
|
|
|
{
|
|
|
|
|
if (lobby.Id == lb.Id)
|
|
|
|
|
{
|
2024-03-22 09:28:37 +00:00
|
|
|
|
Log("好友{0}已加入访客表".Translate(friend.Name));
|
2024-03-17 18:22:47 +00:00
|
|
|
|
var mpf = new MPFriends(this, mw, lb, friend);
|
|
|
|
|
MPFriends.Add(mpf);
|
|
|
|
|
mpf.Show();
|
|
|
|
|
var mpuc = new MPUserControl(this, mpf);
|
|
|
|
|
MUUCList.Children.Add(mpuc);
|
|
|
|
|
MPUserControls.Add(mpuc);
|
2024-03-19 15:14:19 +00:00
|
|
|
|
OnMemberJoined?.Invoke(friend.Id);
|
2024-03-15 17:33:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-17 18:22:47 +00:00
|
|
|
|
private void LoopP2PPacket()
|
|
|
|
|
{
|
2024-03-18 17:55:25 +00:00
|
|
|
|
while (isOPEN)
|
|
|
|
|
try
|
2024-03-17 18:22:47 +00:00
|
|
|
|
{
|
2024-03-18 17:55:25 +00:00
|
|
|
|
while (SteamNetworking.IsP2PPacketAvailable())
|
2024-03-17 18:22:47 +00:00
|
|
|
|
{
|
2024-03-18 17:55:25 +00:00
|
|
|
|
var packet = SteamNetworking.ReadP2PPacket();
|
|
|
|
|
if (packet.HasValue)
|
2024-03-18 13:34:41 +00:00
|
|
|
|
{
|
2024-03-19 15:14:19 +00:00
|
|
|
|
SteamId From = packet.Value.SteamId;
|
2024-03-18 17:55:25 +00:00
|
|
|
|
var MSG = ConverTo(packet.Value.Data);
|
2024-03-19 15:14:19 +00:00
|
|
|
|
ReceivedMessage?.Invoke(From.Value, MSG);
|
2024-03-18 17:55:25 +00:00
|
|
|
|
switch (MSG.Type)
|
|
|
|
|
{
|
2024-03-19 15:14:19 +00:00
|
|
|
|
case (int)MSGType.DispayGraph:
|
|
|
|
|
var To = MPFriends.Find(x => x.friend.Id == MSG.To);
|
2024-03-18 17:55:25 +00:00
|
|
|
|
To.DisplayGraph(MSG.GetContent<GraphInfo>());
|
|
|
|
|
break;
|
2024-03-19 15:14:19 +00:00
|
|
|
|
case (int)MSGType.Chat:
|
|
|
|
|
To = MPFriends.Find(x => x.friend.Id == MSG.To);
|
2024-03-18 17:55:25 +00:00
|
|
|
|
To.DisplayMessage(MSG.GetContent<Chat>());
|
|
|
|
|
break;
|
2024-03-19 18:36:35 +00:00
|
|
|
|
case (int)MSGType.Interact:
|
2024-03-20 18:59:11 +00:00
|
|
|
|
var byname = lb.Members.First(x => x.Id == From).Name;
|
|
|
|
|
var interact = MSG.GetContent<Interact>();
|
2024-03-19 18:36:35 +00:00
|
|
|
|
if (MSG.To == SteamClient.SteamId.Value)
|
|
|
|
|
{
|
|
|
|
|
bool isok = !IMPFriend.InConvenience(mw.Main);
|
2024-03-20 18:59:11 +00:00
|
|
|
|
switch (interact)
|
2024-03-19 18:36:35 +00:00
|
|
|
|
{
|
|
|
|
|
case Interact.TouchHead:
|
2024-03-21 08:24:07 +00:00
|
|
|
|
mw.Main.LabelDisplayShow("{0}在摸{1}的头".Translate(byname, mw.Core.Save.Name), 5000);
|
2024-03-19 18:36:35 +00:00
|
|
|
|
if (isok)
|
|
|
|
|
DisplayNOCALTouchHead();
|
|
|
|
|
break;
|
|
|
|
|
case Interact.TouchBody:
|
2024-03-21 08:24:07 +00:00
|
|
|
|
mw.Main.LabelDisplayShow("{0}在摸{1}的头".Translate(byname, mw.Core.Save.Name), 5000);
|
2024-03-19 18:36:35 +00:00
|
|
|
|
if (isok)
|
|
|
|
|
DisplayNOCALTouchBody();
|
|
|
|
|
break;
|
|
|
|
|
case Interact.TouchPinch:
|
2024-03-21 08:24:07 +00:00
|
|
|
|
mw.Main.LabelDisplayShow("{0}在捏{1}的脸".Translate(byname, mw.Core.Save.Name), 5000);
|
2024-03-19 18:36:35 +00:00
|
|
|
|
if (isok)
|
|
|
|
|
DisplayNOCALTouchPinch();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-20 18:59:11 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
To = MPFriends.Find(x => x.friend.Id == MSG.To);
|
|
|
|
|
To.ActiveInteract(byname, interact);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case (int)MSGType.Feed:
|
|
|
|
|
byname = lb.Members.First(x => x.Id == From).Name;
|
|
|
|
|
var feed = MSG.GetContent<Feed>();
|
|
|
|
|
if (MSG.To == SteamClient.SteamId.Value)
|
|
|
|
|
{
|
|
|
|
|
var item = feed.Item;
|
|
|
|
|
feed.Item.ImageSource = Dispatcher.Invoke(() => mw.ImageSources.FindImage("food_" + (item.Image ?? item.Name), "food"));
|
|
|
|
|
mw.DisplayFoodAnimation(feed.Item.GetGraph(), feed.Item.ImageSource);
|
|
|
|
|
if (feed.EnableFunction)
|
|
|
|
|
{
|
2024-03-21 08:24:07 +00:00
|
|
|
|
mw.Main.LabelDisplayShow("{0}花费${3}给{1}买了{2}".Translate(byname, mw.GameSavesData.GameSave.Name, feed.Item.TranslateName, feed.Item.Price), 10000);
|
2024-03-22 09:28:37 +00:00
|
|
|
|
Log("{0}花费${3}给{1}买了{2}".Translate(byname, mw.GameSavesData.GameSave.Name, feed.Item.TranslateName, feed.Item.Price));
|
2024-03-20 18:59:11 +00:00
|
|
|
|
//对于要修改数据的物品一定要再次检查,避免联机开挂毁存档
|
2024-03-22 12:17:40 +00:00
|
|
|
|
if (item.Price >= 10 && item.Price <= 1000 && item.Health >= 0 && item.Exp >= 0 && item.Likability >= 0 && giveprice < 1000
|
|
|
|
|
&& item.Strength >= 0 && item.StrengthDrink >= 0 && item.StrengthFood >= 0 && item.Feeling >= 0)
|
2024-03-20 18:59:11 +00:00
|
|
|
|
{//单次联机收礼物上限1000
|
|
|
|
|
giveprice += item.Price;
|
|
|
|
|
mw.TakeItem(feed.Item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2024-03-22 09:28:37 +00:00
|
|
|
|
{
|
2024-03-21 08:24:07 +00:00
|
|
|
|
mw.Main.LabelDisplayShow("{0}给{1}买了{2}".Translate(byname, mw.GameSavesData.GameSave.Name, feed.Item.TranslateName), 10000);
|
2024-03-22 09:28:37 +00:00
|
|
|
|
Log("{0}给{1}买了{2}".Translate(byname, mw.GameSavesData.GameSave.Name, feed.Item.TranslateName));
|
|
|
|
|
}
|
2024-03-20 18:59:11 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
To = MPFriends.Find(x => x.friend.Id == MSG.To);
|
|
|
|
|
To.Feed(byname, feed);
|
|
|
|
|
}
|
2024-03-19 18:36:35 +00:00
|
|
|
|
break;
|
2024-03-18 17:55:25 +00:00
|
|
|
|
}
|
2024-03-18 13:34:41 +00:00
|
|
|
|
}
|
2024-03-18 17:55:25 +00:00
|
|
|
|
Thread.Sleep(100);
|
2024-03-17 18:22:47 +00:00
|
|
|
|
}
|
2024-03-18 17:55:25 +00:00
|
|
|
|
Thread.Sleep(1000);
|
2024-03-17 18:22:47 +00:00
|
|
|
|
}
|
2024-03-18 17:55:25 +00:00
|
|
|
|
catch
|
|
|
|
|
{
|
2024-03-18 06:59:05 +00:00
|
|
|
|
|
2024-03-18 17:55:25 +00:00
|
|
|
|
}
|
2024-03-17 18:22:47 +00:00
|
|
|
|
}
|
2024-03-20 18:59:11 +00:00
|
|
|
|
private double giveprice = 0;
|
2024-03-19 15:14:19 +00:00
|
|
|
|
public event Action<ulong, MPMessage> ReceivedMessage;
|
2024-03-15 17:33:56 +00:00
|
|
|
|
private void Window_Closed(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-03-21 08:24:07 +00:00
|
|
|
|
mw.Main.TimeHandle -= Main_TimeHandle;
|
2024-03-16 16:41:20 +00:00
|
|
|
|
mw.Main.GraphDisplayHandler -= Main_GraphDisplayHandler;
|
2024-03-18 13:34:41 +00:00
|
|
|
|
SteamMatchmaking.OnLobbyMemberJoined -= SteamMatchmaking_OnLobbyMemberJoined;
|
2024-03-21 08:24:07 +00:00
|
|
|
|
SteamMatchmaking.OnLobbyMemberLeave -= SteamMatchmaking_OnLobbyMemberLeave;
|
|
|
|
|
SteamMatchmaking.OnLobbyDataChanged -= SteamMatchmaking_OnLobbyDataChanged;
|
2024-03-15 17:33:56 +00:00
|
|
|
|
lb.Leave();
|
2024-03-16 16:41:20 +00:00
|
|
|
|
for (int i = 0; i < MPFriends.Count; i++)
|
2024-03-15 17:33:56 +00:00
|
|
|
|
{
|
2024-03-16 16:41:20 +00:00
|
|
|
|
MPFriends[i].Quit();
|
2024-03-15 17:33:56 +00:00
|
|
|
|
}
|
|
|
|
|
mw.winMutiPlayer = null;
|
|
|
|
|
}
|
2024-03-17 18:22:47 +00:00
|
|
|
|
bool isOPEN = true;
|
2024-03-19 15:14:19 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 事件: 结束访客表, 窗口关闭
|
|
|
|
|
/// </summary>
|
|
|
|
|
public event Action ClosingMutiPlayer;
|
2024-03-15 17:33:56 +00:00
|
|
|
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
|
|
|
|
{
|
2024-03-16 14:39:25 +00:00
|
|
|
|
if (!lb.Equals(default(Lobby)))
|
|
|
|
|
if (MessageBoxX.Show("确定要关闭访客表吗?".Translate(), "离开游戏", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
e.Cancel = true;
|
2024-03-17 18:22:47 +00:00
|
|
|
|
return;
|
2024-03-16 14:39:25 +00:00
|
|
|
|
}
|
2024-03-19 15:14:19 +00:00
|
|
|
|
ClosingMutiPlayer?.Invoke();
|
2024-03-17 18:22:47 +00:00
|
|
|
|
isOPEN = false;
|
2024-03-15 17:33:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void swAllowJoin_Checked(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2024-03-21 07:53:03 +00:00
|
|
|
|
lb.SetData("nojoin", "false");
|
2024-03-15 17:33:56 +00:00
|
|
|
|
lb.SetJoinable(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void swAllowJoin_Unchecked(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2024-03-21 07:53:03 +00:00
|
|
|
|
lb.SetData("nojoin", "true");
|
2024-03-15 17:33:56 +00:00
|
|
|
|
lb.SetJoinable(false);
|
|
|
|
|
}
|
2024-03-19 18:36:35 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 显示本体摸头情况 (会无损加心情)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void DisplayNOCALTouchHead()
|
|
|
|
|
{
|
|
|
|
|
mw.Main.Core.Save.FeelingChange(1);
|
|
|
|
|
if (mw.Main.DisplayType.Type == GraphType.Touch_Head)
|
|
|
|
|
{
|
|
|
|
|
if (mw.Main.DisplayType.Animat == AnimatType.A_Start)
|
|
|
|
|
return;
|
|
|
|
|
else if (mw.Main.DisplayType.Animat == AnimatType.B_Loop)
|
|
|
|
|
if (Dispatcher.Invoke(() => mw.Main.PetGrid.Tag) is IGraph ig && ig.GraphInfo.Type == GraphType.Touch_Head && ig.GraphInfo.Animat == AnimatType.B_Loop)
|
|
|
|
|
{
|
|
|
|
|
ig.IsContinue = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (Dispatcher.Invoke(() => mw.Main.PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Type == GraphType.Touch_Head && ig2.GraphInfo.Animat == AnimatType.B_Loop)
|
|
|
|
|
{
|
|
|
|
|
ig2.IsContinue = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mw.Main.Display(GraphType.Touch_Head, AnimatType.A_Start, (graphname) =>
|
|
|
|
|
mw.Main.Display(graphname, AnimatType.B_Loop, (graphname) =>
|
|
|
|
|
mw.Main.Display(graphname, AnimatType.B_Loop, (graphname) =>
|
|
|
|
|
mw.Main.DisplayCEndtoNomal(graphname))));
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 显示摸身体情况 (会无损加心情)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void DisplayNOCALTouchBody()
|
|
|
|
|
{
|
|
|
|
|
mw.Main.Core.Save.FeelingChange(1);
|
|
|
|
|
if (mw.Main.DisplayType.Type == GraphType.Touch_Body)
|
|
|
|
|
{
|
|
|
|
|
if (mw.Main.DisplayType.Animat == AnimatType.A_Start)
|
|
|
|
|
return;
|
|
|
|
|
else if (mw.Main.DisplayType.Animat == AnimatType.B_Loop)
|
|
|
|
|
if (Dispatcher.Invoke(() => mw.Main.PetGrid.Tag) is IGraph ig && ig.GraphInfo.Type == GraphType.Touch_Body && ig.GraphInfo.Animat == AnimatType.B_Loop)
|
|
|
|
|
{
|
|
|
|
|
ig.IsContinue = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (Dispatcher.Invoke(() => mw.Main.PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Type == GraphType.Touch_Body && ig2.GraphInfo.Animat == AnimatType.B_Loop)
|
|
|
|
|
{
|
|
|
|
|
ig2.IsContinue = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mw.Main.Display(GraphType.Touch_Body, AnimatType.A_Start, (graphname) =>
|
|
|
|
|
mw.Main.Display(graphname, AnimatType.B_Loop, (graphname) =>
|
|
|
|
|
mw.Main.Display(graphname, AnimatType.B_Loop, (graphname) =>
|
|
|
|
|
mw.Main.DisplayCEndtoNomal(graphname))));
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 显示本体捏脸情况 (会无损加心情)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void DisplayNOCALTouchPinch()
|
|
|
|
|
{
|
|
|
|
|
mw.Main.Core.Save.FeelingChange(1);
|
|
|
|
|
if (mw.Main.DisplayType.Name == "pinch")
|
|
|
|
|
{
|
|
|
|
|
if (mw.Main.DisplayType.Animat == AnimatType.A_Start)
|
|
|
|
|
return;
|
|
|
|
|
else if (mw.Main.DisplayType.Animat == AnimatType.B_Loop)
|
|
|
|
|
if (Dispatcher.Invoke(() => mw.Main.PetGrid.Tag) is IGraph ig && ig.GraphInfo.Type == GraphType.Touch_Head && ig.GraphInfo.Animat == AnimatType.B_Loop)
|
|
|
|
|
{
|
|
|
|
|
ig.IsContinue = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (Dispatcher.Invoke(() => mw.Main.PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Type == GraphType.Touch_Head && ig2.GraphInfo.Animat == AnimatType.B_Loop)
|
|
|
|
|
{
|
|
|
|
|
ig2.IsContinue = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mw.Main.Display("pinch", AnimatType.A_Start, (graphname) =>
|
|
|
|
|
mw.Main.Display(graphname, AnimatType.B_Loop, (graphname) =>
|
|
|
|
|
mw.Main.Display(graphname, AnimatType.B_Loop, (graphname) =>
|
|
|
|
|
mw.Main.DisplayCEndtoNomal(graphname))));
|
|
|
|
|
}
|
2024-03-22 13:48:07 +00:00
|
|
|
|
|
|
|
|
|
private void swAllowTouch_Checked(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2024-03-22 14:09:03 +00:00
|
|
|
|
if (mw == null) return;
|
2024-03-22 13:48:07 +00:00
|
|
|
|
lb.SetMemberData("notouch", "true");
|
|
|
|
|
mw.Set.MPNOTouch = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void swAllowTouch_Unchecked(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
lb.SetMemberData("notouch", "false");
|
|
|
|
|
mw.Set.MPNOTouch = false;
|
|
|
|
|
}
|
2024-03-15 17:33:56 +00:00
|
|
|
|
}
|