Skip to content

Commit

Permalink
Add EventArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
C9Glax committed Jan 15, 2024
1 parent bc711d6 commit 1c161cd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
17 changes: 16 additions & 1 deletion CS2GSI/CS2EventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,20 @@

public class CS2EventArgs : EventArgs
{

public object? Value;

public CS2EventArgs(object? value = null)
{
this.Value = value;
}

public T? ValueAsOrDefault<T>()
{
return Value is T val ? val : default;
}

public override string ToString()
{
return Value?.ToString() ?? "NoArgs";
}
}
24 changes: 12 additions & 12 deletions CS2GSI/CS2EventGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ internal static List<ValueTuple<CS2Event, CS2EventArgs>> GenerateEvents(CS2GameS
events.AddRange(GenerateMapEvents(previousPlayerState, newGameState, lastGameState));

if(lastGameState.Player?.SteamId != newGameState.Player?.SteamId)
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnPlayerChange, new CS2EventArgs()));
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnPlayerChange, new CS2EventArgs(newGameState.Player?.SteamId)));

if(events.Count > 0)
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.AnyEvent, new CS2EventArgs()));
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.AnyEvent, new CS2EventArgs(events.Count)));

events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.AnyMessage, new CS2EventArgs()));
return events;
Expand Down Expand Up @@ -65,13 +65,13 @@ private static List<ValueTuple<CS2Event, CS2EventArgs>> GeneratePlayerEvents(CS2
return events;

if(newGameState.Player?.MatchStats?.Kills > previousPlayerState.Player?.MatchStats?.Kills && newGameState.Player is { MatchStats: not null})
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnKill, new CS2EventArgs()));
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnKill, new CS2EventArgs(newGameState.Player?.MatchStats?.Kills)));

if(newGameState.Player?.State?.RoundHs > previousPlayerState.Player?.State?.RoundHs && newGameState.Player is { State: not null})
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnHeadshot, new CS2EventArgs()));
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnHeadshot, new CS2EventArgs(newGameState.Player?.State?.RoundHs)));

if(newGameState.Player?.MatchStats?.Deaths > previousPlayerState.Player?.MatchStats?.Deaths && newGameState.Player is { MatchStats: not null})
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnDeath, new CS2EventArgs()));
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnDeath, new CS2EventArgs(newGameState.Player?.MatchStats?.Deaths)));

if(newGameState.Player?.State?.Flashed > 0 && newGameState.Player is { State: not null})
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnFlashed, new CS2EventArgs()));
Expand All @@ -83,25 +83,25 @@ private static List<ValueTuple<CS2Event, CS2EventArgs>> GeneratePlayerEvents(CS2
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnSmoked, new CS2EventArgs()));

if(newGameState.Player?.State?.Health < previousPlayerState.Player?.State?.Health && newGameState.Player is { State: not null})
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnDamageTaken, new CS2EventArgs()));
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnDamageTaken, new CS2EventArgs(newGameState.Player?.State?.Health)));

if(newGameState.Player?.State?.Health != previousPlayerState.Player?.State?.Health && newGameState.Player is { State: not null})
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnHealthChange, new CS2EventArgs()));
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnHealthChange, new CS2EventArgs(newGameState.Player?.State?.Health)));

if(newGameState.Player?.State?.Money != previousPlayerState.Player?.State?.Money && newGameState.Player is { State: not null})
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnMoneyChange, new CS2EventArgs()));
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnMoneyChange, new CS2EventArgs(newGameState.Player?.State?.Money)));

if(newGameState.Player?.State?.Armor != previousPlayerState.Player?.State?.Armor && newGameState.Player is { State: not null})
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnArmorChange, new CS2EventArgs()));
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnArmorChange, new CS2EventArgs(newGameState.Player?.State?.Armor)));

if(newGameState.Player?.State?.Helmet != previousPlayerState.Player?.State?.Helmet && newGameState.Player is { State: not null})
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnHelmetChange, new CS2EventArgs()));
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnHelmetChange, new CS2EventArgs(newGameState.Player?.State?.Helmet)));

if(newGameState.Player?.State?.EquipmentValue != previousPlayerState.Player?.State?.EquipmentValue && newGameState.Player is { State: not null})
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnEquipmentValueChange, new CS2EventArgs()));
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnEquipmentValueChange, new CS2EventArgs(newGameState.Player?.State?.EquipmentValue)));

if(newGameState.Player?.Team != previousPlayerState.Player?.Team && newGameState.Player is not null)
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnTeamChange, new CS2EventArgs()));
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnTeamChange, new CS2EventArgs(newGameState.Player?.Team)));


return events;
Expand Down
3 changes: 2 additions & 1 deletion TestApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// See https://aka.ms/new-console-template for more information

using CS2GSI.TestApp;
using Microsoft.Extensions.Logging;

public class TestApp
{
public static void Main(string[] args)
{
new CS2GSI.CS2GSI(new Logger());
new CS2GSI.CS2GSI(new Logger(LogLevel.Information));
}
}

0 comments on commit 1c161cd

Please sign in to comment.