修正队伍类

This commit is contained in:
Longfeng Qin 2024-12-11 20:19:14 +08:00
parent 9368309049
commit f86e6ab1ce
2 changed files with 46 additions and 11 deletions

View File

@ -10,17 +10,18 @@ namespace PSO2SERVER.Party
{ {
public class Party public class Party
{ {
public string name; public string Name;
private List<Client> members; public Client Leader;
private Client host; public List<Client> members;
public PartyQuest currentQuest; public PartyQuest currentQuest;
public PartySettingsPacket partySetting; public PartySettingsPacket partySetting;
public string questname; public string questname;
public List<Tuple<int, PartyColor>> PartyColors = new List<Tuple<int, PartyColor>>();
public Party(string name, Client Leader) public Party(string name, Client leader)
{ {
this.name = name; Name = name;
this.host = Leader; Leader = leader;
members = new List<Client>(); members = new List<Client>();
currentQuest = new PartyQuest(); currentQuest = new PartyQuest();
partySetting = new PartySettingsPacket(); partySetting = new PartySettingsPacket();
@ -30,15 +31,15 @@ namespace PSO2SERVER.Party
public void addClientToParty(Client c) public void addClientToParty(Client c)
{ {
members.Add(c);
if (members.Count < 1) if (members.Count < 1)
{ {
c.SendPacket(new PartyInitPacket(members)); c.SendPacket(new PartyInitPacket(new List<Client> { c }));
} }
else else
{ {
// ??? // ???
} }
members.Add(c);
c.currentParty = this; c.currentParty = this;
} }
@ -46,7 +47,7 @@ namespace PSO2SERVER.Party
{ {
if (!members.Contains(c)) if (!members.Contains(c))
{ {
Logger.WriteWarning("[PTY] Client {0} was trying to be removed from {1}, but he was never in {1}!", c._account.Username, name); Logger.WriteWarning("[PTY] 客户端 {0} 尝试离开 {1}, 但他不在队伍 {1} 中!", c._account.Username, Name);
return; return;
} }
@ -61,7 +62,7 @@ namespace PSO2SERVER.Party
public Client getPartyHost() public Client getPartyHost()
{ {
return host; return Leader;
} }
public int getSize() public int getSize()
@ -73,6 +74,40 @@ namespace PSO2SERVER.Party
{ {
return members; 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 public enum PartyColor : byte

View File

@ -40,7 +40,7 @@ namespace PSO2SERVER.Protocol.Packets
entries[i].sublevel = (byte)character.Jobs.entries.hunter.level2; entries[i].sublevel = (byte)character.Jobs.entries.hunter.level2;
entries[i].mainClass = character.Jobs.mainClass; entries[i].mainClass = character.Jobs.mainClass;
entries[i].subClass = character.Jobs.subClass; entries[i].subClass = character.Jobs.subClass;
entries[i].color = (PartyColor)i; entries[i].color = Clients[0].currentParty.AddColor(i);
entries[i].unk2 = 0; entries[i].unk2 = 0;
entries[i].mapid = 0; entries[i].mapid = 0;
entries[i].unk3 = 0; entries[i].unk3 = 0;