PSO2SERVER/Server/Party/Party.cs
2024-12-11 20:19:14 +08:00

218 lines
6.5 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using PSO2SERVER.Database;
using PSO2SERVER.Models;
using PSO2SERVER.Protocol.Packets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PSO2SERVER.Party
{
public class Party
{
public string Name;
public Client Leader;
public List<Client> members;
public PartyQuest currentQuest;
public PartySettingsPacket partySetting;
public string questname;
public List<Tuple<int, PartyColor>> PartyColors = new List<Tuple<int, PartyColor>>();
public Party(string name, Client leader)
{
Name = name;
Leader = leader;
members = new List<Client>();
currentQuest = new PartyQuest();
partySetting = new PartySettingsPacket();
questname = string.Empty;
addClientToParty(Leader);
}
public void addClientToParty(Client c)
{
if (members.Count < 1)
{
c.SendPacket(new PartyInitPacket(new List<Client> { c }));
}
else
{
// ???
}
members.Add(c);
c.currentParty = this;
}
public void removeClientFromParty(Client c)
{
if (!members.Contains(c))
{
Logger.WriteWarning("[PTY] 客户端 {0} 尝试离开 {1}, 但他不在队伍 {1} 中!", c._account.Username, Name);
return;
}
members.Remove(c);
//TODO do stuff like send the "remove from party" packet.
}
public bool hasClientInParty(Client c)
{
return members.Contains(c);
}
public Client getPartyHost()
{
return Leader;
}
public int getSize()
{
return members.Count;
}
public List<Client> getMembers()
{
return members;
}
// 方法:根据 id 添加颜色
public PartyColor AddColor(int id)
{
// 颜色预定义集合
PartyColor[] colorOptions = new PartyColor[] { PartyColor.Red, PartyColor.Blue, PartyColor.Green, PartyColor.Yellow };
foreach (var color in colorOptions)
{
// 检查 PartyColors 列表中是否已有该颜色
if (this.PartyColors.Any(c => c.Item2 == color))
{
continue; // 如果已存在,跳过
}
// 向 PartyColors 列表中添加新的颜色
this.PartyColors.Add(new Tuple<int, PartyColor>(id, color));
return color; // 返回添加的颜色
}
// 如果所有颜色都已存在,返回 PartyColor.Red
return PartyColor.Red;
}
// 根据 ID 获取颜色
public PartyColor GetColor(int id)
{
// 查找与给定 id 匹配的颜色
var foundColor = this.PartyColors
.FirstOrDefault(c => c.Item1 == id); // 获取第一个匹配的项
// 如果找到了匹配的颜色,返回颜色,否则返回默认颜色
return foundColor.Equals(default(Tuple<int, PartyColor>)) ? PartyColor.Red : foundColor.Item2;
}
}
public enum PartyColor : byte
{
Red,
Green,
Yellow,
Blue,
}
[Serializable]
public unsafe struct PartyEntry
{
/// 玩家对象的头部信息包含ID、类型、区域ID等
public ObjectHeader id;
/// 玩家昵称。
public string nickname;
/// 玩家角色名称。
public string char_name;
/// 主职业的等级。
public byte level;
/// 副职业的等级。
public byte sublevel;
/// 玩家主职业类型(`ClassType` 枚举类型)。
public ClassType mainClass;
/// 玩家副职业类型(`ClassType` 枚举类型)。
public ClassType subClass;
/// 玩家在队伍中的颜色标识。
public PartyColor color;
/// 7字节的未知数据通常是填充或者未定义用途
public fixed byte unk1[7];
/// 一个未知的 uint 类型数据,具体用途不明。
public uint unk2;
/// 玩家HP体力的三个数值。具体原因为什么有三个值目前不明。
public fixed uint hp[3];
/// 玩家所在的地图ID。
public ushort mapid;
/// 另一个未知的 ushort 类型数据。
public ushort unk3;
/// 12字节的未知数据。
public fixed byte unk4[0x0C];
/// 3个未知的 uint 数组数据。
public fixed uint unk5[0x03];
/// 未知的字符串,可能是其他信息(如玩家状态或其他描述信息)。
public string unk6;
// PSO VITAPlayStation Vita相关字段已注释掉可能与Vita版本相关。
public string unk10;
// 玩家角色的 ASCII 字符串相关数据,已注释掉。
public string unk7; // ASCII 字符串
// 玩家语言设置(`ShortLanguage` 枚举类型),已注释掉。
public ShortLanguage lang;
// 3字节的未知数据已注释掉。
public fixed byte unk9[3];
}
[Serializable]
public unsafe struct PartyInfo
{
public fixed byte unk1[0x0C];
public ObjectHeader party_object; // Assuming ObjectHeader is another class
public string name; // Name of the party 0xE7E8, 0xFF
public fixed byte unk2[0x09];
public fixed byte unk3[0x03];
public uint unk4; // 32-bit unsigned integer
public uint invite_time; // Time when the player was invited
public uint unk6; // 32-bit unsigned integer
}
[Flags]
public enum PartyFlags : byte
{
/// Is the party only for friends.
FRIENDS_ONLY = 1 << 0, // 1
/// Is the party only for alliance members.
ALLIANCE_ONLY = 1 << 1, // 2
/// Limit multiplayer requests from other parties.
LIMIT_OTHERS = 1 << 2, // 4
/// Is the party only for a single run.
SINGLE_RUN = 1 << 3, // 8
/// Is the party actively looking for members.
OPEN = 1 << 4, // 16
/// Is the party voice chat focused.
VC_FOCUS = 1 << 6, // 64
// This flag would represent an invalid state (all bits set).
_ = byte.MaxValue, // 255 (all flags set)
}
}