示例#1
0
        public static GridSpawner ToSpawner(this DbSpawner dbSpawner)
        {
            var spawnType = (SpawnType)dbSpawner.SpawnType;

            switch (spawnType)
            {
            case SpawnType.Item:
                return(new GridItemSpawner(dbSpawner.MapId, dbSpawner.EntityId)
                {
                    ResetDuration = dbSpawner.Delay
                });

            case SpawnType.Entity:
                return(new GridEntitySpawner(dbSpawner.MapId, dbSpawner.EntityId)
                {
                    ResetDuration = dbSpawner.Delay
                });

            default:
                return(null);
            }
        }
示例#2
0
        public async Task <ISpawner> NewSpawnerAsync(IGame game, ISpawner spawner)
        {
            _logger.LogInformation("Saving new spawner");
            var sSpawner = (SingletonSpawner)spawner;

            // use some sort of mapper? to clean this up?
            var dbSpawner = new DbSpawner()
            {
                RecordBy   = "notlinktoausercontextyet",
                RecordDate = DateTimeOffset.Now,
                Enabled    = true,
                Delay      = sSpawner.ResetDuration,
                EntityId   = sSpawner.EntityId
            };

            using (var context = new GameDbContext())
            {
                var tracked = await context.Spawners.AddAsync(dbSpawner);

                await context.SaveChangesAsync();

                return(tracked.Entity.ToSpawner());
            }
        }