Skip to content

Commit

Permalink
Prepare for community servers
Browse files Browse the repository at this point in the history
* Bump API to 1.0.7
* Add new event handler for squad promotion
* Implement IMount on BitPlayer and BitServer
  • Loading branch information
Mooshua committed Aug 31, 2023
1 parent 3ceadf8 commit b24a38f
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 12 deletions.
2 changes: 1 addition & 1 deletion api/BitMod/BitMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommunityServerAPI" Version="1.0.4.1" />
<PackageReference Include="CommunityServerAPI" Version="1.0.7" />
<PackageReference Include="Lilikoi" Version="0.1.0-prerelease.28" />
<PackageReference Include="Serilog" Version="3.0.2-dev-02044" />
</ItemGroup>
Expand Down
17 changes: 16 additions & 1 deletion api/BitMod/Compatibility/BitPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@

namespace BitMod.Compatibility;

public class BitPlayer : Player<BitPlayer>, IBitObject
public class BitPlayer : Player<BitPlayer>, IBitObject, IMount
{
public Mount Mount { get; } = new Mount();

public void Store<T>(T value) where T : class
=> Mount.Store(value);

public T? Get<T>() where T : class
=> Mount.Get<T>();

public T? Super<T>(Type super) where T : class
=> Mount.Super<T>(super);

public bool Has<T>()
=> Mount.Has<T>();

public bool Has(Type t)
=> Mount.Has(t);
}
17 changes: 16 additions & 1 deletion api/BitMod/Compatibility/BitServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,25 @@

namespace BitMod.Compatibility;

public class BitServer : GameServer<BitPlayer>, IBitObject
public class BitServer : GameServer<BitPlayer>, IBitObject, IMount
{
public Mount Mount { get; }

public void Store<T>(T value) where T : class
=> Mount.Store(value);

public T? Get<T>() where T : class
=> Mount.Get<T>();

public T? Super<T>(Type super) where T : class
=> Mount.Super<T>(super);

public bool Has<T>()
=> Mount.Has<T>();

public bool Has(Type t)
=> Mount.Has(t);

public override string ToString()
=> $"{this.GameIP}:{this.GamePort}";

Expand Down
34 changes: 34 additions & 0 deletions api/BitMod/Events/Squad/SquadLeaderChangedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using BattleBitAPI.Server;

using BitMod.Compatibility;
using BitMod.Events.Accessors;
using BitMod.Events.Base;

namespace BitMod.Events.Squad;

public class SquadLeaderChangedEventArgs : IEventArgs, IGameserverEvent, IResponsiblePlayerEvent
{
public SquadLeaderChangedEventArgs(BitServer server, Squad<BitPlayer> squad, BitPlayer leader)
{
Server = server;
Leader = leader;
Squad = squad;
}

/// <summary>
/// The squad that had it's leadership changed
/// </summary>
public Squad<BitPlayer> Squad { get; }

/// <summary>
/// The new leader
/// </summary>
public BitPlayer Leader { get; }

/// <summary>
/// The server this event happened on
/// </summary>
public BitServer Server { get; }

public BitPlayer? ResponsiblePlayer => Leader;
}
25 changes: 16 additions & 9 deletions api/BitMod/Handler/RoutingGameserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,6 @@ public override async Task OnPlayerChangeTeam(BitPlayer player, Team team)
public override async Task<bool> OnPlayerRequestingToChangeTeam(BitPlayer player, Team requestedTeam)
=> _invoker.Hook(new PlayerChangingTeamEventArgs(this, player, requestedTeam), true);

public override async Task OnPlayerJoinedSquad(BitPlayer player, Squad<BitPlayer> squad)
=> _invoker.Event(new PlayerJoinedSquadEventArgs(this, player, squad));

public override async Task OnPlayerLeftSquad(BitPlayer player, Squad<BitPlayer> squad)
=> _invoker.Event(new PlayerLeftSquadEventArgs(this, player, squad));

public override async Task OnSquadPointsChanged(Squad<BitPlayer> squad, int newPoints)
=> _invoker.Event(new SquadPointsChangedEventArgs(this, squad, newPoints));

public override async Task OnPlayerGivenUp(BitPlayer player)
=> _invoker.Event(new PlayerGivenUpEventArgs(this, player));

Expand All @@ -78,6 +69,22 @@ public override async Task<bool> OnPlayerRequestingToChangeRole(BitPlayer player

#endregion

#region Squad

public override async Task OnSquadLeaderChanged(Squad<BitPlayer> squad, BitPlayer newLeader)
=> _invoker.Event(new SquadLeaderChangedEventArgs(this, squad, newLeader));

public override async Task OnPlayerJoinedSquad(BitPlayer player, Squad<BitPlayer> squad)
=> _invoker.Event(new PlayerJoinedSquadEventArgs(this, player, squad));

public override async Task OnPlayerLeftSquad(BitPlayer player, Squad<BitPlayer> squad)
=> _invoker.Event(new PlayerLeftSquadEventArgs(this, player, squad));

public override async Task OnSquadPointsChanged(Squad<BitPlayer> squad, int newPoints)
=> _invoker.Event(new SquadPointsChangedEventArgs(this, squad, newPoints));

#endregion

#region Gameserver

public override async Task OnConnected()
Expand Down

0 comments on commit b24a38f

Please sign in to comment.