Example #1
0
        public async Task MonsterAppears(DiscordSocketClient client)
        {
            if (ActiveMonster != null)
            {
                var monsterInactivated = await MonsterInactivate(client);

                if (!monsterInactivated)
                {
                    return;
                }
            }

            if (MonsterAppearTimer > 0)
            {
                MonsterAppearTimer -= 1;
                return;
            }

            var monsterRepository = new MonsterRepository(Settings.GetConnectionString("database"), Settings.GetDatabaseSchemaName());
            var channel           = client.GetChannel(Settings.GetDiscordChannelId()) as SocketTextChannel;

            if (channel == null)
            {
                return;
            }

            var minAppearTime = Settings.GetMinMonsterAppearTime();
            var maxAppearTime = Settings.GetMaxMonsterAppearTime();
            var rnd           = new Random();

            ActiveMonster = await monsterRepository.GetRandomMonster();

            ActiveMonster.GenerateLevel();
            MonsterAppearTimer = rnd.Next(minAppearTime, maxAppearTime);
            ActiveMonsterTimer = Settings.GetMonsterActiveMaxTime();

            await channel.SendMessageAsync($"{ActiveMonster.ImageUrl}\n A wild lvl{ActiveMonster.Level} {ActiveMonster.Name} appears!");

            Console.WriteLine($"Spawned new monster {ActiveMonster.Name}");
        }