diff --git a/Server/Party/Party.cs b/Server/Party/Party.cs index 1fb1a4f..a75f3cf 100644 --- a/Server/Party/Party.cs +++ b/Server/Party/Party.cs @@ -10,17 +10,18 @@ namespace PSO2SERVER.Party { public class Party { - public string name; - private List members; - private Client host; + public string Name; + public Client Leader; + public List members; public PartyQuest currentQuest; public PartySettingsPacket partySetting; public string questname; + public List> PartyColors = new List>(); - public Party(string name, Client Leader) + public Party(string name, Client leader) { - this.name = name; - this.host = Leader; + Name = name; + Leader = leader; members = new List(); currentQuest = new PartyQuest(); partySetting = new PartySettingsPacket(); @@ -30,15 +31,15 @@ namespace PSO2SERVER.Party public void addClientToParty(Client c) { - members.Add(c); if (members.Count < 1) { - c.SendPacket(new PartyInitPacket(members)); + c.SendPacket(new PartyInitPacket(new List { c })); } else { // ??? } + members.Add(c); c.currentParty = this; } @@ -46,7 +47,7 @@ namespace PSO2SERVER.Party { 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; } @@ -61,7 +62,7 @@ namespace PSO2SERVER.Party public Client getPartyHost() { - return host; + return Leader; } public int getSize() @@ -73,6 +74,40 @@ namespace PSO2SERVER.Party { 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(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)) ? PartyColor.Red : foundColor.Item2; + } } public enum PartyColor : byte diff --git a/Server/Protocol/Packets/0E-PartyPacket/0E-02-PartyInitPacket.cs b/Server/Protocol/Packets/0E-PartyPacket/0E-02-PartyInitPacket.cs index e57c689..f2bb3c2 100644 --- a/Server/Protocol/Packets/0E-PartyPacket/0E-02-PartyInitPacket.cs +++ b/Server/Protocol/Packets/0E-PartyPacket/0E-02-PartyInitPacket.cs @@ -40,7 +40,7 @@ namespace PSO2SERVER.Protocol.Packets entries[i].sublevel = (byte)character.Jobs.entries.hunter.level2; entries[i].mainClass = character.Jobs.mainClass; 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].mapid = 0; entries[i].unk3 = 0;