diff --git a/Leadercraft/Leadercraft.csproj b/Leadercraft/Leadercraft.csproj index a7d0fa1..c722a93 100644 --- a/Leadercraft/Leadercraft.csproj +++ b/Leadercraft/Leadercraft.csproj @@ -3,15 +3,14 @@ net472 true - 0.0.1 - Me + 1.0.0 + NGnius MIT - https://git.exmods.org/modtainers/HelloModdingWorld + https://git.exmods.org/NGnius/leadercraft en-CA - @@ -77,10 +76,6 @@ ..\ref\Gamecraft_Data\Managed\Blocks.HUDFeedbackBlocks.dll ..\..\ref\Gamecraft_Data\Managed\Blocks.HUDFeedbackBlocks.dll - - ..\ref\Gamecraft_Data\Managed\ClusterToWireConversion.Mock.dll - ..\..\ref\Gamecraft_Data\Managed\ClusterToWireConversion.Mock.dll - ..\ref\Gamecraft_Data\Managed\CommandLine.dll ..\..\ref\Gamecraft_Data\Managed\CommandLine.dll diff --git a/Leadercraft/LeadercraftPlugin.cs b/Leadercraft/LeadercraftPlugin.cs index 5468d0b..54160bb 100644 --- a/Leadercraft/LeadercraftPlugin.cs +++ b/Leadercraft/LeadercraftPlugin.cs @@ -2,7 +2,7 @@ using IllusionPlugin; using GamecraftModdingAPI.Utility; - +using Leadercraft.Scoring; using Leadercraft.Server; namespace Leadercraft @@ -21,14 +21,14 @@ namespace Leadercraft #if DEBUG "http://192.168.122.229:1337/token"; #else - "https://leadercraft.exmods.org/token"; + "https://leadercraft.exmods.org/s/token"; #endif private static string criteriaUrl = #if DEBUG - "http://192.168.122.229:7048/criteria"; + "http://192.168.122.229:7048/c/criteria"; #else - "https://board.exmods.org/criteria"; + "https://leadercraft.exmods.org/criteria"; #endif public static void BuildApi() { @@ -62,9 +62,10 @@ namespace Leadercraft // check out the modding API docs here: https://mod.exmods.org/ // Initialize this mod - GamecraftModdingAPI.Utility.GameEngineManager.AddGameEngine(new Scoring.LeadercraftSimEventHandler()); - GamecraftModdingAPI.Utility.GameEngineManager.AddGameEngine(new Scoring.LeadercraftGameEventHandler()); - GamecraftModdingAPI.Events.EventManager.AddEventHandler(new Scoring.GameLoop()); + GamecraftModdingAPI.App.Game.Simulate += (_, __) => State.StartPlayingGame(); + GamecraftModdingAPI.App.Game.Edit += (_, __) => State.StopPlayingGame(); + GamecraftModdingAPI.App.Game.Enter += (_, __) => State.EnterGame(); + GamecraftModdingAPI.App.Game.Exit += (_, __) => State.ExitGame(); GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has started up"); // Debug mode diff --git a/Leadercraft/Scoring/GameEventHandlers.cs b/Leadercraft/Scoring/GameEventHandlers.cs deleted file mode 100644 index b89ed87..0000000 --- a/Leadercraft/Scoring/GameEventHandlers.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using GamecraftModdingAPI.Events; -namespace Leadercraft.Scoring -{ - internal class LeadercraftGameEventHandler : SimpleEventHandlerEngine - { - public LeadercraftGameEventHandler(): base(State.EnterGame, State.ExitGame, EventType.GameSwitchedTo, "LeadercraftGameEventHandler") - { - - } - } - - internal class LeadercraftSimEventHandler : SimpleEventHandlerEngine - { - public LeadercraftSimEventHandler() : base(State.StartPlayingGame, State.StopPlayingGame, EventType.SimulationSwitchedTo, "LeadercraftSimEventHandler") - { - - } - } -} diff --git a/Leadercraft/Scoring/GameLoop.cs b/Leadercraft/Scoring/GameLoop.cs deleted file mode 100644 index 8296bd8..0000000 --- a/Leadercraft/Scoring/GameLoop.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; - -using RobocraftX.Common; -using Gamecraft.Blocks.HUDFeedbackBlocks; - -using GamecraftModdingAPI; -using GamecraftModdingAPI.Engines; -using GamecraftModdingAPI.Events; -using GamecraftModdingAPI.Players; -using GamecraftModdingAPI.Tasks; -using GamecraftModdingAPI.Utility; -using Svelto.ECS; -using Unity.Jobs; - -using Leadercraft.Server; - -namespace Leadercraft.Scoring -{ - internal class GameLoop : SimpleEventHandlerEngine - { - - private static Player localPlayer; - - public GameLoop() : base (OnGameEnter, (_) => {}, EventType.GameSwitchedTo, "LeadercraftGameLoopGameEngine") { } - - public static void OnGameEnter(EntitiesDB entitiesDB) - { - // schedule game loop async task - Action loop = () => { loopPass(entitiesDB); }; - ISchedulable looper = new Repeatable(loop, () => { return State.IsInGame; }, LeadercraftPlugin.LoopDelay); - Scheduler.Schedule(looper); - } - - private static void loopPass(EntitiesDB entitiesDB) - { - if (!State.IsPlayingGame) return; - if (localPlayer == null && Player.Exists(PlayerType.Local)) localPlayer = new Player(PlayerType.Local); - EntityCollection channelInfo = entitiesDB.QueryEntities(CommonExclusiveGroups.OWNED_BLOCKS_GROUP); - for (uint i = 0; i < channelInfo.count; i++) - { - FilteredChannelDataStruct data = channelInfo[i]; - if(data.channelSignals.any && entitiesDB.Exists(data.ID)) - { - GameOverHudTextEntityStruct hudText = entitiesDB.QueryEntity(data.ID); - if (((string)hudText.headerText).ToLower().Contains("win") || ((string)hudText.bodyText).ToLower().Contains("win")) - { - State.StopPlayingGame(); - //State.GamePlayTime.TotalSeconds - UploadJob scoreJob = new UploadJob(State.Score, State.GamePlayTime.TotalSeconds, localPlayer.Position, Tools.UserId, Tools.UserName, Tools.GameId); - scoreJob.RunInNewThread(); - } - } - } - } - } -} diff --git a/Leadercraft/Scoring/State.cs b/Leadercraft/Scoring/State.cs index 6da561b..67ec1e7 100644 --- a/Leadercraft/Scoring/State.cs +++ b/Leadercraft/Scoring/State.cs @@ -1,6 +1,11 @@ using System; +using GamecraftModdingAPI; +using GamecraftModdingAPI.Players; +using GamecraftModdingAPI.Tasks; using GamecraftModdingAPI.Utility; +using Leadercraft.Server; + namespace Leadercraft.Scoring { internal static class State @@ -25,6 +30,8 @@ namespace Leadercraft.Scoring public static bool IsGameSynced { get; private set; } + private static Player localPlayer = null; + public static void EnterGame() { if (IsInGame) return; @@ -50,6 +57,10 @@ namespace Leadercraft.Scoring Score = 0; IsPlayingGame = true; GameStartTime = DateTime.UtcNow; + // schedule game loop async task + Action loop = () => { loopPass(); }; + ISchedulable looper = new Repeatable(loop, () => { return State.IsInGame; }, LeadercraftPlugin.LoopDelay); + Scheduler.Schedule(looper); } public static void StopPlayingGame() @@ -83,5 +94,19 @@ namespace Leadercraft.Scoring Points = Score, }; } + + private static void loopPass() + { + if (!State.IsPlayingGame) return; + if (localPlayer == null && Player.Exists(PlayerType.Local)) localPlayer = new Player(PlayerType.Local); + if (localPlayer == null) return; + if (localPlayer.GameOver && !localPlayer.Dead) + { + State.StopPlayingGame(); + //State.GamePlayTime.TotalSeconds + UploadJob scoreJob = new UploadJob(State.Score, State.GamePlayTime.TotalSeconds, localPlayer.Position, Tools.UserId, Tools.UserName, Tools.GameId); + scoreJob.RunInNewThread(); + } + } } }