@@ -3,15 +3,14 @@ | |||
<PropertyGroup> | |||
<TargetFramework>net472</TargetFramework> | |||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | |||
<Version>0.0.1</Version> | |||
<Authors>Me</Authors> | |||
<Version>1.0.0</Version> | |||
<Authors>NGnius</Authors> | |||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | |||
<PackageProjectUrl>https://git.exmods.org/modtainers/HelloModdingWorld</PackageProjectUrl> | |||
<PackageProjectUrl>https://git.exmods.org/NGnius/leadercraft</PackageProjectUrl> | |||
<NeutralLanguage>en-CA</NeutralLanguage> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Lib.Harmony" Version="1.2.0.1" /> | |||
<PackageReference Include="NUnit" Version="3.12.0" /> | |||
</ItemGroup> | |||
@@ -77,10 +76,6 @@ | |||
<HintPath>..\ref\Gamecraft_Data\Managed\Blocks.HUDFeedbackBlocks.dll</HintPath> | |||
<HintPath>..\..\ref\Gamecraft_Data\Managed\Blocks.HUDFeedbackBlocks.dll</HintPath> | |||
</Reference> | |||
<Reference Include="ClusterToWireConversion.Mock"> | |||
<HintPath>..\ref\Gamecraft_Data\Managed\ClusterToWireConversion.Mock.dll</HintPath> | |||
<HintPath>..\..\ref\Gamecraft_Data\Managed\ClusterToWireConversion.Mock.dll</HintPath> | |||
</Reference> | |||
<Reference Include="CommandLine"> | |||
<HintPath>..\ref\Gamecraft_Data\Managed\CommandLine.dll</HintPath> | |||
<HintPath>..\..\ref\Gamecraft_Data\Managed\CommandLine.dll</HintPath> | |||
@@ -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 | |||
@@ -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") | |||
{ | |||
} | |||
} | |||
} |
@@ -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<FilteredChannelDataStruct> channelInfo = entitiesDB.QueryEntities<FilteredChannelDataStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP); | |||
for (uint i = 0; i < channelInfo.count; i++) | |||
{ | |||
FilteredChannelDataStruct data = channelInfo[i]; | |||
if(data.channelSignals.any && entitiesDB.Exists<GameOverHudBlockEntityStruct>(data.ID)) | |||
{ | |||
GameOverHudTextEntityStruct hudText = entitiesDB.QueryEntity<GameOverHudTextEntityStruct>(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(); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} |
@@ -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(); | |||
} | |||
} | |||
} | |||
} |