Snowflake/RPG.Services.Gameserver/Game/Team/PlayerTeam.cs

67 lines
1.5 KiB
C#

using RPG.Network.Proto;
namespace RPG.Services.Gameserver.Game.Team;
internal class PlayerTeam
{
private const int TeamMemberCount = 4;
public TeamMember?[] Members { get; } = new TeamMember[TeamMemberCount];
private uint _leaderSlot;
public TeamMember Leader => Members[_leaderSlot]!;
public bool ChangeLeader(uint leaderSlot)
{
if (Members[leaderSlot] == null) return false;
_leaderSlot = leaderSlot;
return true;
}
public TeamMember? Get(uint slot)
{
return Members[slot];
}
public TeamMember? GetMemberByAvatarId(uint avatarId)
{
return Members.FirstOrDefault(member => member?.AvatarId == avatarId);
}
public void Join(uint avatarId, AvatarType type, uint slot)
{
if (GetMemberByAvatarId(avatarId) != null) return;
Members[slot] = new(avatarId, type, slot);
}
public void Leave(uint slot)
{
Members[slot] = null;
}
public LineupInfo LineupInfo
{
get
{
LineupInfo info = new()
{
ExtraLineupType = ExtraLineupType.LineupNone,
LeaderSlot = _leaderSlot,
Index = 0,
Mp = 3,
Name = "Lineup"
};
foreach (TeamMember? member in Members)
{
if (member == null) continue;
info.AvatarList.Add(member.LineupAvatarInfo);
}
return info;
}
}
}