|
- 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 (localPlayer == null) localPlayer = new Player(PlayerType.Local);
- if (!State.IsPlayingGame) return;
- FilteredChannelDataStruct[] channelInfo = entitiesDB.QueryEntities<FilteredChannelDataStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP).ToFastAccess(out uint count);
- for (uint i = 0; i < 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();
- }
- }
- }
- }
- }
- }
|