Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Game Events #29

Merged
merged 24 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 142 additions & 5 deletions Dota2GSI Example program/Dota2GSI Example program/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;
using Dota2GSI;
using Dota2GSI.EventMessages;
using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.IO;
using Dota2GSI;
using Microsoft.Win32;
using System.Threading;

namespace Dota2GSI_Example_program
Expand All @@ -24,7 +25,18 @@ static void Main(string[] args)
}

_gsl = new GameStateListener(4000);
_gsl.NewGameState += OnNewGameState;

// There are many callbacks that can be subscribed.
// This example shows a few.
// _gsl.NewGameState += OnNewGameState; // `NewGameState` can be used alongside `GameEvent`. Just not in this example.
_gsl.GameEvent += OnGameEvent; // `GameEvent` can be used alongside `NewGameState`.
_gsl.TimeOfDayChanged += OnTimeOfDayChanged;
_gsl.TeamScoreChanged += OnTeamScoreChanged;
_gsl.PauseStateChanged += OnPauseStateChanged;
_gsl.PlayerGameplayEvent += OnPlayerGameplayEvent;
_gsl.TeamGameplayEvent += OnTeamGameplayEvent;
_gsl.InventoryItemAdded += OnInventoryItemAdded;
_gsl.InventoryItemRemoved += OnInventoryItemRemoved;

if (!_gsl.Start())
{
Expand All @@ -43,6 +55,131 @@ static void Main(string[] args)
}
} while (Console.ReadKey(true).Key != ConsoleKey.Escape);
}

private static void OnTimeOfDayChanged(TimeOfDayChanged game_event)
{
Console.WriteLine($"Is daytime: {game_event.IsDaytime} Is Nightstalker night: {game_event.IsNightstalkerNight}");
}
private static void OnTeamScoreChanged(TeamScoreChanged game_event)
{
Console.WriteLine($"New score for {game_event.Team} is {game_event.New}");
}

private static void OnPauseStateChanged(PauseStateChanged game_event)
{
Console.WriteLine($"New pause state is {(game_event.New ? "paused" : "not paused")}");
}

private static void OnPlayerGameplayEvent(PlayerGameplayEvent game_event)
{
Console.WriteLine($"Player {game_event.Player.Details.Name} did a thing: " + game_event.Value.EventType);
}

private static void OnTeamGameplayEvent(TeamGameplayEvent game_event)
{
Console.WriteLine($"Team {game_event.Team} did a thing: " + game_event.Value.EventType);
}

private static void OnInventoryItemAdded(InventoryItemAdded game_event)
{
Console.WriteLine($"Player {game_event.Player.Details.Name} gained an item in their inventory: " + game_event.Value.Name);
}

private static void OnInventoryItemRemoved(InventoryItemRemoved game_event)
{
Console.WriteLine($"Player {game_event.Player.Details.Name} lost an item from their inventory: " + game_event.Value.Name);
}

private static void OnGameEvent(DotaGameEvent game_event)
{
if (game_event is ProviderUpdated provider)
{
Console.WriteLine($"Current Game version: {provider.New.Version}");
Console.WriteLine($"Current Game time stamp: {provider.New.TimeStamp}");
}
else if (game_event is PlayerDetailsChanged player_details)
{
Console.WriteLine($"Player Name: {player_details.New.Name}");
Console.WriteLine($"Player Account ID: {player_details.New.AccountID}");
}
else if (game_event is HeroDetailsChanged hero_details)
{
Console.WriteLine($"Player {hero_details.Player.Details.Name} Hero ID: " + hero_details.New.ID);
Console.WriteLine($"Player {hero_details.Player.Details.Name} Hero XP: " + hero_details.New.Experience);
Console.WriteLine($"Player {hero_details.Player.Details.Name} Hero has Aghanims Shard upgrade: " + hero_details.New.HasAghanimsShardUpgrade);
Console.WriteLine($"Player {hero_details.Player.Details.Name} Hero Health: " + hero_details.New.Health);
Console.WriteLine($"Player {hero_details.Player.Details.Name} Hero Mana: " + hero_details.New.Mana);
Console.WriteLine($"Player {hero_details.Player.Details.Name} Hero Location: " + hero_details.New.Location);
}
else if (game_event is AbilityUpdated ability)
{
Console.WriteLine($"Player {ability.Player.Details.Name} updated their ability: " + ability.New);
}
else if (game_event is TowerUpdated tower_updated)
{
if (tower_updated.New.Health < tower_updated.Previous.Health)
{
Console.WriteLine($"{tower_updated.Team} {tower_updated.Location} tower is under attack! Health: " + tower_updated.New.Health);
}
else if (tower_updated.New.Health > tower_updated.Previous.Health)
{
Console.WriteLine($"{tower_updated.Team} {tower_updated.Location} tower is being healed! Health: " + tower_updated.New.Health);
}
}
else if (game_event is TowerDestroyed tower_destroyed)
{
Console.WriteLine($"{tower_destroyed.Team} {tower_destroyed.Location} tower is destroyed!");
}
else if (game_event is RacksUpdated racks_updated)
{
if (racks_updated.New.Health < racks_updated.Previous.Health)
{
Console.WriteLine($"{racks_updated.Team} {racks_updated.Location} {racks_updated.RacksType} racks are under attack! Health: " + racks_updated.New.Health);
}
else if (racks_updated.New.Health > racks_updated.Previous.Health)
{
Console.WriteLine($"{racks_updated.Team} {racks_updated.Location} {racks_updated.RacksType} tower are being healed! Health: " + racks_updated.New.Health);
}
}
else if (game_event is RacksDestroyed racks_destroyed)
{
Console.WriteLine($"{racks_destroyed.Team} {racks_destroyed.Location} {racks_destroyed.RacksType} racks is destroyed!");
}
else if (game_event is AncientUpdated ancient_updated)
{
if (ancient_updated.New.Health < ancient_updated.Previous.Health)
{
Console.WriteLine($"{ancient_updated.Team} ancient is under attack! Health: " + ancient_updated.New.Health);
}
else if (ancient_updated.New.Health > ancient_updated.Previous.Health)
{
Console.WriteLine($"{ancient_updated.Team} ancient is being healed! Health: " + ancient_updated.New.Health);
}
}
else if (game_event is TeamNeutralItemsUpdated team_neutral_items_updated)
{
Console.WriteLine($"{team_neutral_items_updated.Team} neutral items updated: {team_neutral_items_updated.New}");
}
else if (game_event is CourierUpdated courier_updated)
{
Console.WriteLine($"Player {courier_updated.Player.Details.Name} courier updated: {courier_updated.New}");
}
else if (game_event is TeamDraftDetailsUpdated draft_details_updated)
{
Console.WriteLine($"{draft_details_updated.Team} draft details updated: {draft_details_updated.New}");
}
else if (game_event is TeamDefeat team_defeat)
{
Console.WriteLine($"{team_defeat.Team} lost the game.");
}
else if (game_event is TeamVictory team_victory)
{
Console.WriteLine($"{team_victory.Team} won the game!");
}
}

// NewGameState example

static void OnNewGameState(GameState gs)
{
Console.Clear();
Expand Down Expand Up @@ -93,7 +230,7 @@ static void OnNewGameState(GameState gs)
Console.WriteLine($"{level}");
}

foreach(var game_event in gs.Events)
foreach (var game_event in gs.Events)
{
if (game_event.EventType == Dota2GSI.Nodes.EventsProvider.EventType.Bounty_rune_pickup)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
Expand Down
42 changes: 42 additions & 0 deletions Dota2GSI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,33 @@ PROJECT(${PRODUCT} VERSION ${PRODUCT_VERSION} LANGUAGES CSharp)
INCLUDE(CSharpUtilities)

SET(SOURCES
Dota2EventsInterface.cs
EventDispatcher.cs
EventHandler.cs
EventsInterface.cs
GameState.cs
GameStateListener.cs
GameStateHandler.cs
EventMessages/AbilitiesEvents.cs
EventMessages/AuthEvents.cs
EventMessages/BaseEvent.cs
EventMessages/BuildingsEvents.cs
EventMessages/CouriersEvents.cs
EventMessages/DotaGameEvent.cs
EventMessages/DraftEvents.cs
EventMessages/GameplayEvents.cs
EventMessages/FullDetailsEvents.cs
EventMessages/HeroEvents.cs
EventMessages/ItemsEvents.cs
EventMessages/LeagueEvents.cs
EventMessages/MapEvents.cs
EventMessages/MinimapEvents.cs
EventMessages/NeutralItemsEvents.cs
EventMessages/PlayerEvents.cs
EventMessages/ProviderEvents.cs
EventMessages/RoshanEvents.cs
EventMessages/UpdateEvent.cs
EventMessages/WearablesEvents.cs
Nodes/Roshan.cs
Nodes/HeroProvider/HeroDetails.cs
Nodes/CouriersProvider/Courier.cs
Expand Down Expand Up @@ -60,6 +85,23 @@ SET(SOURCES
Nodes/Provider.cs
Nodes/Map.cs
Nodes/Auth.cs
StateHandlers/AbilitiesHandler.cs
StateHandlers/AuthHandler.cs
StateHandlers/BuildingsHandler.cs
StateHandlers/CouriersHandler.cs
StateHandlers/DraftHandler.cs
StateHandlers/GameplayEventsHandler.cs
StateHandlers/FullDetailsHandler.cs
StateHandlers/HeroHandler.cs
StateHandlers/ItemsHandler.cs
StateHandlers/LeagueHandler.cs
StateHandlers/MapHandler.cs
StateHandlers/MinimapHandler.cs
StateHandlers/NeutralItemsHandler.cs
StateHandlers/PlayerHandler.cs
StateHandlers/ProviderHandler.cs
StateHandlers/RoshanHandler.cs
StateHandlers/WearablesHandler.cs
)

SET(README "${CMAKE_SOURCE_DIR}/README.md")
Expand Down
Loading