Ejemplo n.º 1
0
        /// <summary>
        /// Generates the embed message representing the monster
        /// </summary>
        /// <returns>Embed message</returns>
        public Embed GenerateMonsterCard(SocketCommandContext Context)
        {
            GuildConfig config = new GuildConfig(Context.Guild.Id.ToString());

            config.CheckForFile();
            config = config.Load() as GuildConfig;

            Random rand          = new Random();
            long   monsterHealth = (long)(Math.Pow(config.DungeonLevel, 1.2) + 5 + rand.Next(10));
            string monsterName   = MONSTER_NAMES[rand.Next(MONSTER_NAMES.Length)];

            EmbedBuilder monsterCard = new EmbedBuilder()
            {
                Title       = monsterName + " lvl " + config.DungeonLevel,
                Description = $"{monsterHealth} / {monsterHealth}\n```{img}```",
                Color       = new Color(0, 255, 0),
            };

            config.Save();
            return(monsterCard.Build());
        }
Ejemplo n.º 2
0
        private async Task ReactionAddedEvent(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            IUserMessage    msg  = message.DownloadAsync().Result;
            SocketGuildUser user = await channel.GetUserAsync(reaction.UserId) as SocketGuildUser;

            SocketGuild    guild   = user.Guild;
            DungeonManager manager = new DungeonManager();

            GuildConfig config = new GuildConfig(guild.Id.ToString());

            config.CheckForFile();
            config = config.Load() as GuildConfig;

            if (config.DungeonChannelID != channel.Id || config.DungeonMessageID != message.Id ||
                user.IsBot)
            {
                return;
            }

            // Check if valid emote
            for (int i = 0; i < DungeonManager.EMOTES.Length; i++)
            {
                if (DungeonManager.EMOTES[i].Equals(reaction.Emote))
                {
                    break;
                }
                else if (i == DungeonManager.EMOTES.Length - 1)
                {
                    return;
                }
            }

            Embed newEmbed = manager.RefreshMonsterCard(msg.Embeds.First(), guild, user);
            await msg.ModifyAsync(x => x.Embed = newEmbed);

            await msg.RemoveReactionAsync(reaction.Emote, reaction.User.Value);
        }
Ejemplo n.º 3
0
        public Embed RefreshMonsterCard(IEmbed mc, SocketGuild guild, SocketGuildUser user)
        {
            Random rand = new Random();

            // Configuration
            GuildConfig config = new GuildConfig(guild.Id.ToString());

            config.CheckForFile();
            config = config.Load() as GuildConfig;

            // Embed info
            EmbedBuilder monsterCard   = mc.ToEmbedBuilder();
            string       line          = monsterCard.Description.Split('\n')[0];
            long         currentHealth = Convert.ToInt64(line.Split('/')[0]);
            long         maxHealth     = Convert.ToInt64(line.Split('/')[1]);

            // Channels
            SocketTextChannel dungeonChannel = guild.GetTextChannel(config.DungeonChannelID);
            IUserMessage      log            = dungeonChannel.GetMessageAsync(config.DungeonCombatID).Result as IUserMessage;

            // Document action
            // Calculate damage
            int damage = rand.Next(6) + 1;

            bool crit     = false;
            int  critRoll = rand.Next(6) + 1;

            if (critRoll == 6)
            {
                crit    = true;
                damage *= 2;
            }

            currentHealth           -= damage;
            config.DungeonCombatLog += $"\n{DateTime.Now.ToString("HH:mm:ss")}|{user} {(crit ? "crit for" : "dealt")} {damage} damage!";

            // Slain monster
            if (currentHealth <= 0)
            {
                // Document action
                config.DungeonLevel++;
                config.DungeonCombatLog += $"\n{DateTime.Now.ToString("HH:mm:ss")}|{user} slew the {monsterCard.Title}!";

                // Generate new monster
                long   monsterHealth = (long)(Math.Pow(config.DungeonLevel, 1.2) + 5 + rand.Next(10));
                string monsterName   = MONSTER_NAMES[rand.Next(MONSTER_NAMES.Length)];

                EmbedBuilder newMonsterCard = new EmbedBuilder()
                {
                    Title       = monsterName + " lvl " + config.DungeonLevel,
                    Description = $"{monsterHealth} / {monsterHealth}\n```{img}```",
                    Color       = new Color(0, 255, 0),
                };

                log.ModifyAsync(x => x.Content = $"```{config.FormatedCombatLog()}```");

                config.Save();
                return(newMonsterCard.Build());
            }

            log.ModifyAsync(x => x.Content = $"```{config.FormatedCombatLog()}```");

            monsterCard.Description = $"{currentHealth} / {maxHealth}\n```{img}```";

            // Gradient the color from green to red based on remaining health
            Color healthColor = new Color(0, 255, 0);
            float healthRatio = (float)currentHealth / (float)maxHealth;

            if (healthRatio >= 0.5)
            {
                healthColor = new Color((int)(255 * (2 - (2 * healthRatio))), 255, 0);
            }
            else
            {
                healthColor = new Color(255, (int)(255 * (2 * healthRatio)), 0);
            }

            monsterCard.Color = healthColor;

            // Save and return
            config.Save();
            return(monsterCard.Build());
        }