Example #1
0
        /// <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);
        }