using System;
using System.Threading;
using System.Threading.Tasks;
using SharedLibraryCore.Events;
using SharedLibraryCore.Events.Game;
namespace SharedLibraryCore.Interfaces.Events;
public interface IGameEventSubscriptions
{
///
/// Raised when game log prints that match has started
/// InitGame
///
///
static event Func MatchStarted;
///
/// Raised when game log prints that match has ended
/// ShutdownGame:
///
///
static event Func MatchEnded;
///
/// Raised when game log printed that client has entered the match
/// J;clientNetworkId;clientSlotNumber;clientName
/// J;110000100000000;0;bot
///
///
public static event Func ClientEnteredMatch;
///
/// Raised when game log prints that client has exited the match
/// Q;clientNetworkId;clientSlotNumber;clientName
/// Q;110000100000000;0;bot
///
///
static event Func ClientExitedMatch;
///
/// Raised when game log prints that client has joined a team
/// JT;clientNetworkId;clientSlotNumber;clientTeam;clientName
/// JT;110000100000000;0;axis;bot
///
///
static event Func ClientJoinedTeam;
///
/// Raised when game log prints that client has been damaged
/// D;victimNetworkId;victimSlotNumber;victimTeam;victimName;attackerNetworkId;attackerSlotNumber;attackerTeam;attackerName;weapon;damage;meansOfDeath;hitLocation
/// D;110000100000000;17;axis;bot_0;110000100000001;4;allies;bot_1;scar_mp;38;MOD_HEAD_SHOT;head
///
///
static event Func ClientDamaged;
///
/// Raised when game log prints that client has been killed
/// K;victimNetworkId;victimSlotNumber;victimTeam;victimName;attackerNetworkId;attackerSlotNumber;attackerTeam;attackerName;weapon;damage;meansOfDeath;hitLocation
/// K;110000100000000;17;axis;bot_0;110000100000001;4;allies;bot_1;scar_mp;100;MOD_HEAD_SHOT;head
///
///
static event Func ClientKilled;
///
/// Raised when game log prints that client entered a chat message
/// say;clientNetworkId;clientSlotNumber;clientName;message
/// say;110000100000000;0;bot;hello world!
///
///
static event Func ClientMessaged;
///
/// Raised when game log prints that client entered a command (chat message prefixed with command character(s))
/// say;clientNetworkId;clientSlotNumber;clientName;command
/// say;110000100000000;0;bot;!command
///
///
static event Func ClientEnteredCommand;
///
/// Raised when game log prints user generated script event
/// GSE;data
/// GSE;loadBank=1
///
///
static event Func ScriptEventTriggered;
static Task InvokeEventAsync(CoreEvent coreEvent, CancellationToken token)
{
return coreEvent switch
{
MatchStartEvent matchStartEvent => MatchStarted?.InvokeAsync(matchStartEvent, token) ?? Task.CompletedTask,
MatchEndEvent matchEndEvent => MatchEnded?.InvokeAsync(matchEndEvent, token) ?? Task.CompletedTask,
ClientEnterMatchEvent clientEnterMatchEvent => ClientEnteredMatch?.InvokeAsync(clientEnterMatchEvent, token) ?? Task.CompletedTask,
ClientExitMatchEvent clientExitMatchEvent => ClientExitedMatch?.InvokeAsync(clientExitMatchEvent, token) ?? Task.CompletedTask,
ClientJoinTeamEvent clientJoinTeamEvent => ClientJoinedTeam?.InvokeAsync(clientJoinTeamEvent, token) ?? Task.CompletedTask,
ClientKillEvent clientKillEvent => ClientKilled?.InvokeAsync(clientKillEvent, token) ?? Task.CompletedTask,
ClientDamageEvent clientDamageEvent => ClientDamaged?.InvokeAsync(clientDamageEvent, token) ?? Task.CompletedTask,
ClientCommandEvent clientCommandEvent => ClientEnteredCommand?.InvokeAsync(clientCommandEvent, token) ?? Task.CompletedTask,
ClientMessageEvent clientMessageEvent => ClientMessaged?.InvokeAsync(clientMessageEvent, token) ?? Task.CompletedTask,
GameScriptEvent gameScriptEvent => ScriptEventTriggered?.InvokeAsync(gameScriptEvent, token) ?? Task.CompletedTask,
_ => Task.CompletedTask
};
}
static void ClearEventInvocations()
{
MatchStarted = null;
MatchEnded = null;
ClientEnteredMatch = null;
ClientExitedMatch = null;
ClientJoinedTeam = null;
ClientDamaged = null;
ClientKilled = null;
ClientMessaged = null;
ClientEnteredCommand = null;
ScriptEventTriggered = null;
}
}