Beispiel #1
0
        private async Task <CombatUser> BuildCombatUserAsync(Enemy enemyData, int level, DbService db)
        {
            var enemy = new CombatUser
            {
                Name           = enemyData.Name,
                Health         = 150 * level,
                AttackPower    = 10 + 1 * level,
                DmgTaken       = 0,
                CriticalChance = 10
            };

            if (enemyData.ArmorId.HasValue)
            {
                var eArmor = await db.Items.FindAsync(enemyData.ArmorId);

                enemy.Health         += 10 * eArmor.HealthIncrease;
                enemy.CriticalChance += 1 * eArmor.CritIncrease;
                enemy.AttackPower    += 2 * eArmor.DamageIncrease;
            }

            if (!enemyData.WeaponId.HasValue)
            {
                return(enemy);
            }
            var eWeapon = await db.Items.FindAsync(enemyData.WeaponId);

            enemy.AttackPower    += 2 * eWeapon.DamageIncrease;
            enemy.CriticalChance += 1 * eWeapon.CritIncrease;

            return(enemy);
        }
Beispiel #2
0
        private int CalculateDamage(CombatUser user)
        {
            var critChance = _random.Next(100);
            var dmg        = 1 * user.AttackPower;

            if (critChance >= user.CriticalChance)
            {
                dmg = Convert.ToInt32(dmg * 1.5);
            }

            var lowDmg = dmg / 1.5;

            if (lowDmg <= 0)
            {
                lowDmg = 5;
            }
            var highDmg = dmg * 1.5;

            if (lowDmg >= highDmg)
            {
                highDmg = lowDmg + 5;
            }

            return(_random.Next(Convert.ToInt32(lowDmg), Convert.ToInt32(highDmg)));
        }
Beispiel #3
0
        public async Task <CombatUser> BuildCombatUserAsync(SocketUser socketUser, User userData, DbService db)
        {
            var weapon = await db.Items.FindAsync(userData.WeaponId);

            var armor = await db.Items.FindAsync(userData.ArmorId);

            var user = new CombatUser
            {
                Name        = socketUser.Username,
                Health      = 100 + 10 * userData.Level + 10 * userData.HealthTalent + 10 * armor.HealthIncrease,
                AttackPower = 10 + 1 * userData.Level + 1 * userData.DamageTalent + 2 * weapon.DamageIncrease +
                              2 * armor.DamageIncrease,
                CriticalChance = 15 + 1 * weapon.CritIncrease + 10 * armor.CritIncrease,
                DmgTaken       = 0
            };

            if (Consumables.TryGetValue(userData.UserId, out var item) && item is Item consum)
            {
                user.AttackPower    += 10 * consum.DamageIncrease;
                user.CriticalChance += 1 * consum.CritIncrease;
                user.Health         += 10 * consum.HealthIncrease;
            }

            return(user);
        }
Beispiel #4
0
        public async Task <Stream> ProfileBuilder(SocketGuildUser socketUser, User user, CombatUser cbUser, DbService db)
        {
            var stream = new MemoryStream();

            using var img = new Image <Rgba32>(400, 400);
            var weaponItem = await db.Items.FindAsync(user.WeaponId);

            var armor = await db.Items.FindAsync(user.ArmorId);

            var zone = await db.Zones.FindAsync(user.ZoneId);

            var continent = await db.Continents.FindAsync(user.ContinentId);

            var progressBar = CreateProfileProgressBar(user);

            img.Mutate(x =>
            {
                x.DrawImage(_profileBackground, new Point(0, 0), GraphicsOptions.Default);              // Background
                x.DrawImage(Image.Load(weaponItem.ImageUrl), new Point(0, 0), GraphicsOptions.Default); // Weapon
                x.DrawImage(_profileWumpus, new Point(0, 0), GraphicsOptions.Default);                  // Wumpus
                x.DrawImage(_profileTemplate, new Point(0, 0), GraphicsOptions.Default);                // Shapes / Frame
                x.DrawImage(_profilePreText, new Point(0, 0), GraphicsOptions.Default);

                x.DrawText(new TextGraphicsOptions {
                    HorizontalAlignment = HorizontalAlignment.Center
                }, socketUser.Username, _profileHeader, Rgba32.White, new PointF(200, 12));
                x.DrawText($"{user.DamageTalent}", new Font(_arial, 15, FontStyle.Regular), Rgba32.White, new PointF(56, 153));
                x.DrawText($"{user.HealthTalent}", new Font(_arial, 15, FontStyle.Regular), Rgba32.White, new PointF(56, 185));
                x.DrawText(new TextGraphicsOptions {
                    HorizontalAlignment = HorizontalAlignment.Center
                }, $"{user.Level}", new Font(_arial, 20, FontStyle.Regular), Rgba32.White, new PointF(40, 95));

                if (progressBar.Count >= 2) // TODO: Make the color scheme of the profile customizable
                {
                    x.DrawLines(new GraphicsOptions(true), Rgba32.BlueViolet, 4, progressBar.ToArray());
                }

                x.DrawText(new TextGraphicsOptions {
                    HorizontalAlignment = HorizontalAlignment.Center
                }, $"{cbUser.Health}", new Font(_arial, 15, FontStyle.Regular), Rgba32.White, new PointF(348, 118));
                x.DrawText(new TextGraphicsOptions {
                    HorizontalAlignment = HorizontalAlignment.Center
                }, $"{cbUser.AttackPower}", new Font(_arial, 20, FontStyle.Regular), Rgba32.White, new PointF(348, 156));
                x.DrawText(new TextGraphicsOptions {
                    HorizontalAlignment = HorizontalAlignment.Center
                }, $"{cbUser.CriticalChance}%", new Font(_arial, 15, FontStyle.Regular), Rgba32.White, new PointF(348, 198));

                x.DrawText(new TextGraphicsOptions {
                    HorizontalAlignment = HorizontalAlignment.Center
                }, $"{continent.Name}", new Font(_arial, 12, FontStyle.Regular), Rgba32.White, new PointF(99, 357));
                x.DrawText(new TextGraphicsOptions {
                    HorizontalAlignment = HorizontalAlignment.Center
                }, $"{zone.Name}", new Font(_arial, 12, FontStyle.Regular), Rgba32.White, new PointF(99, 388));

                x.DrawText(new TextGraphicsOptions {
                    HorizontalAlignment = HorizontalAlignment.Center
                }, $"{weaponItem.Name}", new Font(_arial, 12, FontStyle.Regular), Rgba32.White, new PointF(300, 357));
                x.DrawText(new TextGraphicsOptions {
                    HorizontalAlignment = HorizontalAlignment.Center
                }, $"{armor.Name}", new Font(_arial, 12, FontStyle.Regular), Rgba32.White, new PointF(300, 388));
            }); // 348
            img.Save(stream, new PngEncoder());
            return(stream);
        }
Beispiel #5
0
        private async Task <CombatUser> CombatAsync(IUserMessage msg, CombatUser user, CombatUser enemy, DbService db,
                                                    LinkedList <string> msgLog, List <Inventory> userInventory)
        {
            EmbedBuilder embed;

            while (true)
            {
                // User always goes first
                if (Convert.ToInt32(user.DmgTaken / user.Health * 100) >= 70 &&
                    userInventory.Count(x => x.ItemType == ItemType.Food && x.ItemType == ItemType.Food) >
                    0)
                {
                    var potionId = userInventory.FirstOrDefault(x =>
                                                                x.ItemType == ItemType.Potion);
                    if (potionId != null)
                    {
                        var potion = await db.Items.FindAsync(potionId.ItemId);

                        UpdateBattleLog(msgLog,
                                        $"**{user.Name}** drank a **{potion.Name}** and regained **{potion.HealthIncrease} health**!");
                        user.DmgTaken -= potion.HealthIncrease;
                        if (potionId.Amount == 1)
                        {
                            db.Inventories.Remove(potionId);
                        }
                        else
                        {
                            potionId.Amount--;
                        }
                    }
                    else
                    {
                        var foodId = userInventory.FirstOrDefault(x =>
                                                                  x.ItemType == ItemType.Food);
                        if (foodId != null)
                        {
                            var food = await db.Items.FindAsync(foodId.ItemId);

                            UpdateBattleLog(msgLog,
                                            $"**{user.Name}** ate **{food.Name}** and regained **{food.Name} health**!");
                            user.DmgTaken -= food.HealthIncrease;
                            if (foodId.Amount == 1)
                            {
                                db.Inventories.Remove(foodId);
                            }
                            else
                            {
                                foodId.Amount--;
                            }
                        }
                    }
                }
                else
                {
                    var usDmg = CalculateDamage(user);

                    enemy.DmgTaken += usDmg;
                    if (enemy.DmgTaken >= enemy.Health)
                    {
                        UpdateBattleLog(msgLog,
                                        $"**{user.Name}** hit for **{usDmg}** damage and **defeated {enemy.Name}**");
                        embed             = msg.Embeds.First().ToEmbedBuilder();
                        embed.Description = msgLog.ListToString();
                        embed.Fields      = new List <EmbedFieldBuilder>
                        {
                            new EmbedFieldBuilder
                            {
                                Name     = "Your HP",
                                Value    = $"{user.Health - user.DmgTaken}/{user.Health}",
                                IsInline = true
                            },
                            new EmbedFieldBuilder
                            {
                                Name     = "Enemy HP",
                                Value    = $"0/{enemy.Health}",
                                IsInline = true
                            }
                        };
                        await msg.ModifyAsync(x => x.Embed = embed.Build());

                        await Task.Delay(2000);

                        return(user);
                    }

                    UpdateBattleLog(msgLog, $"**{user.Name}** hit **{enemy.Name}** for **{usDmg}** damage");
                }

                var enDmg = CalculateDamage(enemy);
                user.DmgTaken += enDmg;
                if (user.DmgTaken < user.Health)
                {
                    UpdateBattleLog(msgLog, $"**{enemy.Name}** hit **{user.Name}** for **{enDmg}** damage");
                    embed             = msg.Embeds.First().ToEmbedBuilder();
                    embed.Description = msgLog.ListToString();
                    embed.Fields      = new List <EmbedFieldBuilder>
                    {
                        new EmbedFieldBuilder
                        {
                            Name     = "Your HP",
                            Value    = $"{user.Health - user.DmgTaken}/{user.Health}",
                            IsInline = true
                        },
                        new EmbedFieldBuilder
                        {
                            Name     = "Enemy HP",
                            Value    = $"{enemy.Health - enemy.DmgTaken}/{enemy.Health}",
                            IsInline = true
                        }
                    };
                    await msg.ModifyAsync(x => x.Embed = embed.Build());

                    await Task.Delay(2000);

                    continue;
                }

                UpdateBattleLog(msgLog, $"**{enemy.Name}** hit for **{enDmg}** damage and **defeated {user.Name}**");
                UpdateBattleLog(msgLog, "You died :(");
                embed             = msg.Embeds.First().ToEmbedBuilder();
                embed.Description = msgLog.ListToString();
                embed.Color       = Color.Red;
                embed.Fields      = new List <EmbedFieldBuilder>
                {
                    new EmbedFieldBuilder
                    {
                        Name     = "Your HP",
                        Value    = $"0/{user.Health}",
                        IsInline = true
                    },
                    new EmbedFieldBuilder
                    {
                        Name     = "Enemy HP",
                        Value    = $"{enemy.Health - enemy.DmgTaken}/{enemy.Health}",
                        IsInline = true
                    }
                };
                await msg.ModifyAsync(x => x.Embed = embed.Build());

                await Task.Delay(2000);

                return(enemy);
            }
        }