mirror of
https://github.com/MrOkiDoki/BattleBit-Community-Server-API.git
synced 2025-01-09 11:17:30 -03:00
Squad leader implementation
This commit is contained in:
parent
d6d2962250
commit
76cd1bd8a2
8 changed files with 265 additions and 4 deletions
13
BattleBitAPI/Common/Enums/VehicleType.cs
Normal file
13
BattleBitAPI/Common/Enums/VehicleType.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
[System.Flags]
|
||||
public enum VehicleType : byte
|
||||
{
|
||||
None = 0,
|
||||
|
||||
Tank = 1 << 1,
|
||||
Transport = 1 << 2,
|
||||
SeaVehicle = 1 << 3,
|
||||
APC = 1 << 4,
|
||||
Helicopters = 1 << 5,
|
||||
|
||||
All = 255,
|
||||
}
|
|
@ -42,5 +42,6 @@
|
|||
OnSquadPointsChanged = 72,
|
||||
NotifyNewRoundID = 73,
|
||||
Log = 74,
|
||||
OnSquadLeaderChanged = 75,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using BattleBitAPI.Common;
|
||||
using BattleBitAPI.Common.Extentions;
|
||||
|
@ -26,8 +27,6 @@ namespace BattleBitAPI.Server
|
|||
public int CurrentPlayerCount => mInternal.CurrentPlayerCount;
|
||||
public int InQueuePlayerCount => mInternal.InQueuePlayerCount;
|
||||
public int MaxPlayerCount => mInternal.MaxPlayerCount;
|
||||
public string LoadingScreenText => mInternal.LoadingScreenText;
|
||||
public string ServerRulesText => mInternal.ServerRulesText;
|
||||
public uint RoundIndex => mInternal.RoundIndex;
|
||||
public long SessionID => mInternal.SessionID;
|
||||
public ServerSettings<TPlayer> ServerSettings => mInternal.ServerSettings;
|
||||
|
@ -36,6 +35,24 @@ namespace BattleBitAPI.Server
|
|||
public RoundSettings<TPlayer> RoundSettings => mInternal.RoundSettings;
|
||||
public string TerminationReason => mInternal.TerminationReason;
|
||||
public bool ReconnectFlag => mInternal.ReconnectFlag;
|
||||
public string LoadingScreenText
|
||||
{
|
||||
get => mInternal.LoadingScreenText;
|
||||
set
|
||||
{
|
||||
mInternal.LoadingScreenText = value;
|
||||
SetLoadingScreenText(value);
|
||||
}
|
||||
}
|
||||
public string ServerRulesText
|
||||
{
|
||||
get => mInternal.ServerRulesText;
|
||||
set
|
||||
{
|
||||
mInternal.ServerRulesText = value;
|
||||
SetRulesScreenText(value);
|
||||
}
|
||||
}
|
||||
public IEnumerable<Squad<TPlayer>> TeamASquads
|
||||
{
|
||||
get
|
||||
|
@ -445,6 +462,10 @@ namespace BattleBitAPI.Server
|
|||
public virtual async Task OnPlayerJoinedSquad(TPlayer player, Squad<TPlayer> squad)
|
||||
{
|
||||
|
||||
}
|
||||
public virtual async Task OnSquadLeaderChanged(Squad<TPlayer> squad, TPlayer newLeader)
|
||||
{
|
||||
|
||||
}
|
||||
public virtual async Task OnPlayerLeftSquad(TPlayer player, Squad<TPlayer> squad)
|
||||
{
|
||||
|
@ -567,6 +588,14 @@ namespace BattleBitAPI.Server
|
|||
SayToChat(msg, player.SteamID);
|
||||
}
|
||||
|
||||
public void SetLoadingScreenText(string newText)
|
||||
{
|
||||
ExecuteCommand("setloadingscreentext " + newText);
|
||||
}
|
||||
public void SetRulesScreenText(string newText)
|
||||
{
|
||||
ExecuteCommand("setrulesscreentext " + newText);
|
||||
}
|
||||
public void StopServer()
|
||||
{
|
||||
ExecuteCommand("stop");
|
||||
|
|
|
@ -303,6 +303,17 @@ namespace BattleBitAPI.Server
|
|||
@internal._Modifications.IsDirtyFlag = true;
|
||||
}
|
||||
}
|
||||
public VehicleType AllowedVehicles
|
||||
{
|
||||
get => @internal._Modifications.AllowedVehicles;
|
||||
set
|
||||
{
|
||||
if (@internal._Modifications.AllowedVehicles == value)
|
||||
return;
|
||||
@internal._Modifications.AllowedVehicles = value;
|
||||
@internal._Modifications.IsDirtyFlag = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void DisableBleeding()
|
||||
{
|
||||
|
@ -344,6 +355,7 @@ namespace BattleBitAPI.Server
|
|||
public bool KillFeed = false;
|
||||
public bool IsExposedOnMap = false;
|
||||
public SpawningRule SpawningRule;
|
||||
public VehicleType AllowedVehicles;
|
||||
|
||||
public bool IsDirtyFlag = false;
|
||||
public void Write(BattleBitAPI.Common.Serialization.Stream ser)
|
||||
|
@ -375,6 +387,7 @@ namespace BattleBitAPI.Server
|
|||
ser.Write(this.KillFeed);
|
||||
ser.Write(this.IsExposedOnMap);
|
||||
ser.Write((ulong)this.SpawningRule);
|
||||
ser.Write((byte)this.AllowedVehicles);
|
||||
}
|
||||
public void Read(BattleBitAPI.Common.Serialization.Stream ser)
|
||||
{
|
||||
|
@ -408,6 +421,7 @@ namespace BattleBitAPI.Server
|
|||
this.KillFeed = ser.ReadBool();
|
||||
this.IsExposedOnMap = ser.ReadBool();
|
||||
this.SpawningRule = (SpawningRule)ser.ReadUInt64();
|
||||
this.AllowedVehicles = (VehicleType)ser.ReadInt8();
|
||||
}
|
||||
public void Reset()
|
||||
{
|
||||
|
@ -436,6 +450,7 @@ namespace BattleBitAPI.Server
|
|||
this.PointLogHudEnabled = true;
|
||||
this.KillFeed = false;
|
||||
this.SpawningRule = SpawningRule.All;
|
||||
this.AllowedVehicles = VehicleType.All;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,6 +79,106 @@ namespace BattleBitAPI.Server
|
|||
}
|
||||
}
|
||||
|
||||
public byte MedicLimitPerSquad
|
||||
{
|
||||
get => mResources._RoomSettings.MedicLimitPerSquad;
|
||||
set
|
||||
{
|
||||
if (mResources._RoomSettings.MedicLimitPerSquad == value)
|
||||
return;
|
||||
mResources._RoomSettings.MedicLimitPerSquad = value;
|
||||
mResources.IsDirtyRoomSettings = true;
|
||||
}
|
||||
}
|
||||
public byte EngineerLimitPerSquad
|
||||
{
|
||||
get => mResources._RoomSettings.EngineerLimitPerSquad;
|
||||
set
|
||||
{
|
||||
if (mResources._RoomSettings.EngineerLimitPerSquad == value)
|
||||
return;
|
||||
mResources._RoomSettings.EngineerLimitPerSquad = value;
|
||||
mResources.IsDirtyRoomSettings = true;
|
||||
}
|
||||
}
|
||||
public byte SupportLimitPerSquad
|
||||
{
|
||||
get => mResources._RoomSettings.SupportLimitPerSquad;
|
||||
set
|
||||
{
|
||||
if (mResources._RoomSettings.SupportLimitPerSquad == value)
|
||||
return;
|
||||
mResources._RoomSettings.SupportLimitPerSquad = value;
|
||||
mResources.IsDirtyRoomSettings = true;
|
||||
}
|
||||
}
|
||||
public byte ReconLimitPerSquad
|
||||
{
|
||||
get => mResources._RoomSettings.ReconLimitPerSquad;
|
||||
set
|
||||
{
|
||||
if (mResources._RoomSettings.ReconLimitPerSquad == value)
|
||||
return;
|
||||
mResources._RoomSettings.ReconLimitPerSquad = value;
|
||||
mResources.IsDirtyRoomSettings = true;
|
||||
}
|
||||
}
|
||||
|
||||
public float TankSpawnDelayMultipler
|
||||
{
|
||||
get => mResources._RoomSettings.TankSpawnDelayMultipler;
|
||||
set
|
||||
{
|
||||
if (mResources._RoomSettings.TankSpawnDelayMultipler == value)
|
||||
return;
|
||||
mResources._RoomSettings.TankSpawnDelayMultipler = value;
|
||||
mResources.IsDirtyRoomSettings = true;
|
||||
}
|
||||
}
|
||||
public float TransportSpawnDelayMultipler
|
||||
{
|
||||
get => mResources._RoomSettings.TransportSpawnDelayMultipler;
|
||||
set
|
||||
{
|
||||
if (mResources._RoomSettings.TransportSpawnDelayMultipler == value)
|
||||
return;
|
||||
mResources._RoomSettings.TransportSpawnDelayMultipler = value;
|
||||
mResources.IsDirtyRoomSettings = true;
|
||||
}
|
||||
}
|
||||
public float SeaVehicleSpawnDelayMultipler
|
||||
{
|
||||
get => mResources._RoomSettings.SeaVehicleSpawnDelayMultipler;
|
||||
set
|
||||
{
|
||||
if (mResources._RoomSettings.SeaVehicleSpawnDelayMultipler == value)
|
||||
return;
|
||||
mResources._RoomSettings.SeaVehicleSpawnDelayMultipler = value;
|
||||
mResources.IsDirtyRoomSettings = true;
|
||||
}
|
||||
}
|
||||
public float APCSpawnDelayMultipler
|
||||
{
|
||||
get => mResources._RoomSettings.APCSpawnDelayMultipler;
|
||||
set
|
||||
{
|
||||
if (mResources._RoomSettings.APCSpawnDelayMultipler == value)
|
||||
return;
|
||||
mResources._RoomSettings.APCSpawnDelayMultipler = value;
|
||||
mResources.IsDirtyRoomSettings = true;
|
||||
}
|
||||
}
|
||||
public float HelicopterSpawnDelayMultipler
|
||||
{
|
||||
get => mResources._RoomSettings.HelicopterSpawnDelayMultipler;
|
||||
set
|
||||
{
|
||||
if (mResources._RoomSettings.HelicopterSpawnDelayMultipler == value)
|
||||
return;
|
||||
mResources._RoomSettings.HelicopterSpawnDelayMultipler = value;
|
||||
mResources.IsDirtyRoomSettings = true;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Reset ----
|
||||
public void Reset()
|
||||
|
@ -103,6 +203,12 @@ namespace BattleBitAPI.Server
|
|||
public bool CanVoteDay = true;
|
||||
public bool CanVoteNight = true;
|
||||
|
||||
public float TankSpawnDelayMultipler = 1.0f;
|
||||
public float TransportSpawnDelayMultipler = 1.0f;
|
||||
public float SeaVehicleSpawnDelayMultipler = 1.0f;
|
||||
public float APCSpawnDelayMultipler = 1.0f;
|
||||
public float HelicopterSpawnDelayMultipler = 1.0f;
|
||||
|
||||
public void Write(Common.Serialization.Stream ser)
|
||||
{
|
||||
ser.Write(this.DamageMultiplier);
|
||||
|
@ -118,6 +224,12 @@ namespace BattleBitAPI.Server
|
|||
|
||||
ser.Write(this.CanVoteDay);
|
||||
ser.Write(this.CanVoteNight);
|
||||
|
||||
ser.Write(this.TankSpawnDelayMultipler);
|
||||
ser.Write(this.TransportSpawnDelayMultipler);
|
||||
ser.Write(this.SeaVehicleSpawnDelayMultipler);
|
||||
ser.Write(this.APCSpawnDelayMultipler);
|
||||
ser.Write(this.HelicopterSpawnDelayMultipler);
|
||||
}
|
||||
public void Read(Common.Serialization.Stream ser)
|
||||
{
|
||||
|
@ -134,6 +246,12 @@ namespace BattleBitAPI.Server
|
|||
|
||||
this.CanVoteDay = ser.ReadBool();
|
||||
this.CanVoteNight = ser.ReadBool();
|
||||
|
||||
this.TankSpawnDelayMultipler = ser.ReadFloat();
|
||||
this.TransportSpawnDelayMultipler = ser.ReadFloat();
|
||||
this.SeaVehicleSpawnDelayMultipler = ser.ReadFloat();
|
||||
this.APCSpawnDelayMultipler = ser.ReadFloat();
|
||||
this.HelicopterSpawnDelayMultipler = ser.ReadFloat();
|
||||
}
|
||||
public void Reset()
|
||||
{
|
||||
|
@ -150,6 +268,12 @@ namespace BattleBitAPI.Server
|
|||
|
||||
this.CanVoteDay = true;
|
||||
this.CanVoteNight = true;
|
||||
|
||||
this.TankSpawnDelayMultipler = 1.0f;
|
||||
this.TransportSpawnDelayMultipler = 1.0f;
|
||||
this.SeaVehicleSpawnDelayMultipler = 1.0f;
|
||||
this.APCSpawnDelayMultipler = 1.0f;
|
||||
this.HelicopterSpawnDelayMultipler = 1.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,23 @@ namespace BattleBitAPI.Server
|
|||
Server.SetSquadPointsOf(@internal.Team, @internal.Name, value);
|
||||
}
|
||||
}
|
||||
public TPlayer Leader
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.@internal.SquadLeader != 0 && this.Server.TryGetPlayer(this.@internal.SquadLeader, out var captain))
|
||||
return captain;
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
if (!value.IsSquadLeader)
|
||||
value.PromoteToSquadLeader();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Internal @internal;
|
||||
public Squad(Internal @internal)
|
||||
|
@ -27,6 +44,13 @@ namespace BattleBitAPI.Server
|
|||
this.@internal = @internal;
|
||||
}
|
||||
|
||||
public void DisbandSquad()
|
||||
{
|
||||
var leader = this.Leader;
|
||||
if (leader != null)
|
||||
leader.DisbandTheSquad();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Squad " + Name;
|
||||
|
@ -40,6 +64,7 @@ namespace BattleBitAPI.Server
|
|||
public int SquadPoints;
|
||||
public GameServer<TPlayer> Server;
|
||||
public HashSet<TPlayer> Members;
|
||||
public ulong SquadLeader;
|
||||
|
||||
public Internal(GameServer<TPlayer> server, Team team, Squads squads)
|
||||
{
|
||||
|
@ -47,6 +72,7 @@ namespace BattleBitAPI.Server
|
|||
this.Name = squads;
|
||||
this.Server = server;
|
||||
this.Members = new HashSet<TPlayer>(8);
|
||||
this.SquadLeader = 0;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
|
|
|
@ -67,6 +67,18 @@ namespace BattleBitAPI
|
|||
public bool InSquad => mInternal.SquadName != Squads.NoSquad;
|
||||
public int PingMs => mInternal.PingMs;
|
||||
public long CurrentSessionID => mInternal.SessionID;
|
||||
public bool IsSquadLeader
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.SquadName != Squads.NoSquad)
|
||||
{
|
||||
var squad = this.Squad;
|
||||
return squad.Leader == this;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool IsConnected => mInternal.SessionID != 0;
|
||||
|
||||
public float HP
|
||||
|
@ -150,6 +162,10 @@ namespace BattleBitAPI
|
|||
public virtual async Task OnJoinedSquad(Squad<TPlayer> newSquad)
|
||||
{
|
||||
|
||||
}
|
||||
public virtual async Task OnPlayerPromotedToSquadLeader()
|
||||
{
|
||||
|
||||
}
|
||||
public virtual async Task OnLeftSquad(Squad<TPlayer> oldSquad)
|
||||
{
|
||||
|
|
|
@ -1119,10 +1119,11 @@ namespace BattleBitAPI.Server
|
|||
}
|
||||
case NetworkCommuncation.OnPlayerJoinedASquad:
|
||||
{
|
||||
if (stream.CanRead(8 + 1))
|
||||
if (stream.CanRead(8 + 1 + 1))
|
||||
{
|
||||
ulong steamID = stream.ReadUInt64();
|
||||
Squads squad = (Squads)stream.ReadInt8();
|
||||
bool asCaptain = stream.ReadBool();
|
||||
|
||||
if (resources.TryGetPlayer(steamID, out var player))
|
||||
{
|
||||
|
@ -1134,11 +1135,24 @@ namespace BattleBitAPI.Server
|
|||
lock (rsquad.Members)
|
||||
rsquad.Members.Add((TPlayer)player);
|
||||
|
||||
//Assign as leader if needed.
|
||||
if (asCaptain)
|
||||
rsquad.SquadLeader = steamID;
|
||||
|
||||
player.OnJoinedSquad(msquad);
|
||||
server.OnPlayerJoinedSquad((TPlayer)player, msquad);
|
||||
|
||||
if (this.LogLevel.HasFlag(LogLevel.Squads))
|
||||
OnLog(LogLevel.Squads, $"{player} has joined to {msquad}", msquad);
|
||||
|
||||
if (asCaptain)
|
||||
{
|
||||
player.OnPlayerPromotedToSquadLeader();
|
||||
server.OnSquadLeaderChanged(msquad, (TPlayer)player);
|
||||
|
||||
if (this.LogLevel.HasFlag(LogLevel.Squads))
|
||||
OnLog(LogLevel.Squads, $"{player} has promoted to squad leader", player);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -1444,7 +1458,7 @@ namespace BattleBitAPI.Server
|
|||
//Heal
|
||||
OnLog(LogLevel.HealtChanges, $"{player} was healed by {dtHP} HP (new HP is {newHP} HP)", player);
|
||||
}
|
||||
else if(dtHP < 0)
|
||||
else if (dtHP < 0)
|
||||
{
|
||||
//Damage
|
||||
OnLog(LogLevel.HealtChanges, $"{player} was damaged by {(-dtHP)} HP (new HP is {newHP} HP)", player);
|
||||
|
@ -1572,6 +1586,29 @@ namespace BattleBitAPI.Server
|
|||
}
|
||||
break;
|
||||
}
|
||||
case NetworkCommuncation.OnSquadLeaderChanged:
|
||||
{
|
||||
if (stream.CanRead(8 + 1))
|
||||
{
|
||||
ulong steamID = stream.ReadUInt64();
|
||||
byte squadIndex = stream.ReadInt8();
|
||||
|
||||
if (resources.TryGetPlayer(steamID, out var player))
|
||||
{
|
||||
var msquad = server.GetSquad(player.Team, (Squads)squadIndex);
|
||||
var rsquad = resources.GetSquadInternal(msquad);
|
||||
|
||||
rsquad.SquadLeader = steamID;
|
||||
|
||||
player.OnPlayerPromotedToSquadLeader();
|
||||
server.OnSquadLeaderChanged(msquad, (TPlayer)player);
|
||||
|
||||
if (this.LogLevel.HasFlag(LogLevel.Squads))
|
||||
OnLog(LogLevel.Squads, $"{player} has promoted to squad leader", player);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue