using System; using GamecraftModdingAPI.Utility; namespace Leadercraft.Scoring { internal static class State { public static bool IsInGame { get; private set; }= false; public static bool IsPlayingGame { get; private set; } = false; public static DateTime GameEnterTime { get; private set; } public static DateTime GameStartTime { get; private set; } public static TimeSpan GamePlayTime { get; private set; } public static float[] PlayerLocation { get; private set; } public static ulong GameId { get; private set; } public static int Score { get; private set; } public static bool IsGameComplete { get; private set; } public static bool IsGameSynced { get; private set; } public static void EnterGame() { if (IsInGame) return; Logging.MetaDebugLog("Entering game"); IsInGame = true; IsGameSynced = false; IsGameComplete = false; GameId = Server.Tools.GameId; GameEnterTime = DateTime.UtcNow; } public static void ExitGame() { if (!IsInGame) return; Logging.MetaDebugLog("Exiting game"); IsInGame = false; } public static void StartPlayingGame() { if (IsPlayingGame) return; Logging.MetaDebugLog("Starting to play game"); Score = 0; IsPlayingGame = true; GameStartTime = DateTime.UtcNow; } public static void StopPlayingGame() { if (!IsPlayingGame) return; GamePlayTime = DateTime.UtcNow - GameStartTime; Logging.MetaDebugLog("Stopping game"); IsPlayingGame = false; } public static void SetLocation(float x, float y, float z) { PlayerLocation = new float[] { x, y, z }; } public static void AddScore(int points) { Score += points; } public static Server.CriteriaStruct Criteria() { IsGameSynced = true; return new Server.CriteriaStruct { Location = new float[][] { PlayerLocation, PlayerLocation }, Time = Convert.ToInt32(Math.Round(GamePlayTime.TotalSeconds, MidpointRounding.AwayFromZero)), GameID = GameId, PlayerID = 0, Complete = IsGameComplete, Points = Score, }; } } }