/// <summary> /// Saves the specified entity. /// </summary> /// <param name="Entity">The entity.</param> public static async Task Save(Player Entity) { var Result = await PlayerDb.Save(Entity); if (Result == null) { Logging.Error(typeof(Players), "Result == null at Save(Entity)."); } }
/// <summary> /// Gets the entity using the specified identifiers. /// </summary> /// <param name="HighId">The high identifier.</param> /// <param name="LowId">The low identifier.</param> /// <param name="Store">Whether it has to be stored.</param> public static async Task <Player> Get(int HighId, int LowId, bool Store = true) { long PlayerId = (long)HighId << 32 | (uint)LowId; PlayerDb PlayerDb = await PlayerDb.Load(HighId, LowId); Player Player = null; if (Players.Entities.TryGetValue(PlayerId, out Player)) { return(Player); } else { if (PlayerDb != null) { if (PlayerDb.Deserialize(out Player)) { if (Store) { Players.Add(Player); } return(Player); } else { Logging.Error(typeof(Players), "PlayerDb.Deserialize(out Player) != true at Get(" + HighId + ", " + LowId + ")."); } } else { Logging.Warning(typeof(Players), "PlayerDb == null at Get(HighId, LowId)."); } } return(Player); }
/// <summary> /// Creates the specified entity. /// </summary> /// <param name="Entity">The entity.</param> /// <param name="Store">Whether it has to be stored.</param> public static async Task <Player> Create(Player Entity = null, bool Store = true) { if (Entity == null) { Entity = new Player(); Entity.Initialize(); } if (Entity.HighId == 0) { Entity.HighId = Players.HighSeed; } if (Entity.LowId == 0) { Entity.LowId = Interlocked.Increment(ref Players.LowSeed); } JsonConvert.PopulateObject(Files.Home.Json.ToString(), Entity.Home); Entity.Home.HighId = Entity.HighId; Entity.Home.LowId = Entity.LowId; if (string.IsNullOrEmpty(Entity.Token)) { Entity.Token = XorShift.NextToken(); } await PlayerDb.Create(Entity); if (Store) { Players.Add(Entity); } return(Entity); }