|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- 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();
- }
- }
- }
- }
- }
- }
|