コード例 #1
0
        public ActionResult EquipWeapon(int id, int hand, int weaponId)
        {
            string currentUserId = User.Identity.GetUserId();

            var  ctx                       = new ProjectStrawberryEntities();
            int  characterId               = ctx.Characters.FirstOrDefault(c => c.AccountId == currentUserId && c.Alive).Id;
            bool doesUserOwnWeapon         = ctx.EquipmentCharacters.Any(wc => wc.Id == id && wc.CharacterId == characterId && wc.WeaponId == weaponId);
            bool isMainHandAlreadyEquipped = ctx.EquipmentCharacters.Any(wc => wc.Id == id && wc.CharacterId == characterId && wc.MainHandEquipped == true);
            bool isOffHandAlredyEquipped   = ctx.EquipmentCharacters.Any(wc => wc.Id == id && wc.CharacterId == characterId && wc.OffHandEquipped == true);

            if (!isMainHandAlreadyEquipped && hand == 1 && doesUserOwnWeapon)
            {
                ctx.EquipmentCharacters
                .FirstOrDefault(wc => wc.Id == id && wc.OffHandEquipped == false)
                .MainHandEquipped = true;
                ctx.SaveChanges();
            }
            else if (!isOffHandAlredyEquipped && hand == 2 && doesUserOwnWeapon)
            {
                ctx.EquipmentCharacters
                .FirstOrDefault(wc => wc.Id == id && wc.MainHandEquipped == false)
                .OffHandEquipped = true;
                ctx.SaveChanges();
            }

            return(RedirectToAction("GetEquipment"));
        }
コード例 #2
0
        public ActionResult Update()
        {
            string currentUserId = currentUserId = User.Identity.GetUserId();

            var ctx = new ProjectStrawberryEntities();
            //var combatlog = ctx.CombatLogs.FirstOrDefault(c => c.Character.AccountId == currentUserId && c.Character1.AccountId == currentUserId);

            //if (combatlog != null)
            //{
            //    List<Round> list = new List<Round>();

            //    using (MemoryStream ms = new MemoryStream(combatlog.Log))
            //    {
            //        BinaryFormatter bf = new BinaryFormatter();
            //        list = (List<Round>)bf.Deserialize(ms);
            //    }

            //    return PartialView("CombatLog", list);
            //}

            var arenaModel = ctx.Arenas.FirstOrDefault(a => a.Character.AccountId == currentUserId);

            DateTime currentDateTime = DateTime.Now;
            DateTime queuedDateTime  = arenaModel.Queued; // if any combatlog.date > queueddatetime show dat

            if (queuedDateTime.AddSeconds(2) <= currentDateTime)
            {
                var combatLog = BattleNPC(arenaModel.CharacterId, arenaModel.Forfeit, null, null);
                ctx.SaveChanges();

                return(PartialView("CombatLog", combatLog));
            }

            return(PartialView(""));
        }
コード例 #3
0
        public ActionResult RandomDuel()
        {
            var    ctx           = new ProjectStrawberryEntities();
            string currentUserId = currentUserId = User.Identity.GetUserId();

            if (ctx.Arenas.Any(a => a.Character.Level == ctx.Characters.FirstOrDefault(c => c.AccountId == currentUserId && c.Alive).Level&& a.CharacterId != ctx.Characters.FirstOrDefault(c => c.AccountId == currentUserId).Id))
            {
                //Battle();
            }
            else
            {
                if (!ctx.Arenas.Any(a => a.Character.AccountId == currentUserId && a.Character.Alive))
                {
                    ctx.Arenas.Add(new Arena {
                        CharacterId = ctx.Characters.FirstOrDefault(c => c.AccountId == currentUserId && c.Alive).Id, Forfeit = 25, Queued = DateTime.Now
                    });
                    ctx.SaveChanges();
                }
                else
                {
                    return(PartialView("RandomDuel", true));
                }
            }
            return(PartialView("RandomDuel", false));
        }
コード例 #4
0
        public string BuyArmor(string id)
        {
            int armorId = -1;

            int.TryParse(id, out armorId);

            if (armorId > 0)
            {
                var ctx         = new ProjectStrawberryEntities();
                var currentUser = User.Identity.GetUserId();

                var armor     = ctx.Armors.FirstOrDefault(s => s.Id == armorId);
                var character = ctx.Characters.FirstOrDefault(c => c.AccountId == currentUser && c.Alive);

                if (armor != null && character != null && character.Gold - armor.Price >= 0)
                {
                    ctx.EquipmentCharacters.Add(new EquipmentCharacter {
                        Armor = armor, Character = character
                    });
                    character.Gold -= armor.Price;
                    ctx.SaveChanges();

                    return("You pay the storeowner " + armor.Price + " glods and recieve " + armor.Name);
                }
                else
                {
                    return("The storeowner looks at you with an eyebrow raised");
                }
            }
            else
            {
                return("The storeowner looks at you with an eyebrow raised");
            }
        }
コード例 #5
0
        public ActionResult Delete()
        {
            string currentUserId = User.Identity.GetUserId();

            var ctx = new ProjectStrawberryEntities();

            Character character = ctx.Characters.FirstOrDefault(c => c.AccountId == currentUserId && c.Alive);

            character.Alive = false;
            ctx.SaveChanges();

            return(RedirectToAction("Index"));
        }
コード例 #6
0
        // update character to DB
        public void UpdateCharacter(CharacterCombatModel model)
        {
            var ctx = new ProjectStrawberryEntities();

            var character = ctx.Characters.FirstOrDefault(c => c.Id == model.Id);

            character.Alive  = model.Alive;
            character.Gold   = model.Gold;
            character.Health = model.Health;
            character.Level  = model.Level;

            ctx.SaveChanges();
        }
コード例 #7
0
        public ActionResult UnequipWeapon(int id, int hand) // Måste säkra denna metod så inte andra spelare ändrar status på vapen andras karaktärer
        {
            var ctx = new ProjectStrawberryEntities();

            if (hand == 1)
            {
                ctx.EquipmentCharacters.FirstOrDefault(wc => wc.Id == id).MainHandEquipped = false;
            }
            else if (hand == 2)
            {
                ctx.EquipmentCharacters.FirstOrDefault(wc => wc.Id == id).OffHandEquipped = false;
            }

            ctx.SaveChanges();

            return(RedirectToAction("GetEquipment"));
        }
コード例 #8
0
        public ActionResult UnequipArmor(int id)
        {
            string currentUserId = User.Identity.GetUserId();

            var ctx         = new ProjectStrawberryEntities();
            int characterId = ctx.Characters.FirstOrDefault(c => c.AccountId == currentUserId && c.Alive).Id;

            bool doesUserOwnEqiupment = ctx.EquipmentCharacters.Any(ec => ec.CharacterId == characterId && ec.Id == id && ec.Equipped);

            if (doesUserOwnEqiupment)
            {
                ctx.EquipmentCharacters.FirstOrDefault(ec => ec.Id == id && ec.CharacterId == characterId).Equipped = false;
                ctx.SaveChanges();
            }

            return(RedirectToAction("GetEquipment"));
        }
コード例 #9
0
        private static void SaveCombatLogToDatabase(ProjectStrawberryEntities ctx, List <Round> fullFight, CharacterCombatModel character, string spoiler)
        {
            byte[] log;

            using (MemoryStream ms = new MemoryStream())
            {
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(ms, fullFight);

                log = ms.ToArray();

                ctx.CombatLogs.Add(new CombatLog()
                {
                    Player = character.Id, Log = log, GameDate = DateTime.Now, Spoiler = spoiler
                });
                ctx.SaveChanges();
            }
        }
コード例 #10
0
        public List <Round> BattleNPC(int player1Id, int player1Forfeit, int?player2Id, int?player2Forfeit)
        {
            var ctx      = new ProjectStrawberryEntities();
            var random   = new Random();
            var generate = new CombatTextGenerator();
            var ccm      = new CharacterModelGenerator();

            // Generate Player1 model and properties
            var player1 = new CharacterCombatModel();

            player1 = ccm.ModelizeCharacter(player1Id);

            double player1HitChanceMainHand = PlayerHitChance(player1);
            double player1HitChanceOffHand  = PlayerHitChance(player1);
            double player1ParryChance       = diminishing_returns(player1.Parry, 7.5);
            double player1DodgeChance       = diminishing_returns(player1.Evasion, 7.5);
            double player1BlockChance       = diminishing_returns(player1.Block, 7.5);

            bool player1HasShield = player1.OffHand.shld != null;
            bool player1HasWeapon = player1.MainHand != null && player1.OffHand.wep != null;

            // Generate Player2 model and properties
            var player2 = new CharacterCombatModel();

            if (player2Id != null)
            {
                player2 = ccm.ModelizeCharacter((int)player2Id);
            }
            else
            {
                var gen = new NpcGenerator(player1, random.Next(0, 47), random.Next(0, 71));
                player2        = gen.GenerateMirrorNpc();
                player2Forfeit = 20;
            }

            double player2HitChanceMainHand = PlayerHitChance(player2);
            double player2HitChanceOffHand  = PlayerHitChance(player2);
            double player2ParryChance       = diminishing_returns(player2.Parry, 7.5);
            double player2DodgeChance       = diminishing_returns(player2.Evasion, 7.5);
            double player2BlockChance       = diminishing_returns(player2.Block, 7.5);

            bool player2HasShield = player2.OffHand.shld != null;
            bool player2HasWeapon = player2.MainHand != null && player2.OffHand.wep != null;

            // Combatlog properties
            List <Round> fullFight = new List <Round>();
            int          roundNr   = 0;
            string       roundLog  = "";
            string       spoiler   = "";

            bool keepFighting = true;
            bool player1HasHighestQuickness = player1.Quickness >= player2.Quickness;
            bool player1Won = false;
            bool player2Won = false;

            while (keepFighting)
            {
                int combatflavorindex = 2;

                int damage      = 0;
                int bonusDamage = 0;
                int minDamage   = 0;
                int maxDamage   = 0;

                roundNr++;

                // Player1 # of attacks + Avoidance chance
                bool player1AttackWithMainHand = false;
                bool player1AttackWithOffHand  = false;

                AttacksPlayerCanDoThisRound(player1, ref player1AttackWithMainHand, ref player1AttackWithOffHand);

                // Player2 # of attacks.
                bool player2AttackWithMainHand = false;
                bool player2AttackWithOffHand  = false;

                AttacksPlayerCanDoThisRound(player2, ref player2AttackWithMainHand, ref player2AttackWithOffHand);

                if (player1HasHighestQuickness)
                {
                    if (keepFighting && player1AttackWithMainHand)
                    {
                        bonusDamage = player1.Strength / 10;
                        minDamage   = player1.MainHand.MinimumDamage + bonusDamage;
                        maxDamage   = player1.MainHand.MaximumDamage + bonusDamage;

                        var bodyPartId = DiceForBodyPart(random.Next(1, 97), player1.MainHand.WeaponType.Name);
                        var bodyPart   = player2.Equipment.FirstOrDefault(e => e.ArmorTypeId == bodyPartId);

                        if (bodyPart == null)
                        {
                            bodyPart = new ArmorModel()
                            {
                                ArmorValue = 0, Name = "skin"
                            };
                        }

                        if (minDamage - bodyPart.ArmorValue < 0)
                        {
                            minDamage = 0;
                        }
                        else
                        {
                            minDamage -= bodyPart.ArmorValue;
                        }

                        if (maxDamage - bodyPart.ArmorValue < 0)
                        {
                            maxDamage = 0;
                        }
                        else
                        {
                            maxDamage -= bodyPart.ArmorValue;
                        }

                        string action = WhatHappenedThatHit(player1HitChanceMainHand, player2DodgeChance, player2ParryChance, player2BlockChance, player2HasShield, player2HasWeapon, random);

                        if (action == "h")
                        {
                            damage          = random.Next(minDamage, maxDamage + 1);
                            roundLog       += generate.CombatTextMaleAttacker(player1.Name, player2.Name, damage, bodyPart.Name, random.Next(0, combatflavorindex));
                            player2.Health -= damage;
                        }
                        else if (action == "b")
                        {
                            roundLog += generate.CombatTextBlock(player1.Name, player2.Name, player1.MainHand.Name.ToLower(), player2.OffHand.shld.Name, random.Next(0, 1));
                        }
                        else if (action == "p")
                        {
                            roundLog += generate.CombatTextParry(player1.Name, player2.Name, random.Next(0, 1));
                        }
                        else if (action == "d")
                        {
                            roundLog += generate.CombatTextDodge(player1.Name, player1.MainHand.Name, player2.Name, random.Next(0, 1));
                        }

                        player1AttackWithMainHand = false;
                    }
                    else if (keepFighting && player1AttackWithOffHand)
                    {
                        bonusDamage = player1.Strength / 10;
                        minDamage   = player1.OffHand.wep.MinimumDamage + bonusDamage;
                        maxDamage   = player1.OffHand.wep.MaximumDamage + bonusDamage;

                        var bodyPartId = DiceForBodyPart(random.Next(1, 97), player1.OffHand.wep.Name);
                        var bodyPart   = player2.Equipment.FirstOrDefault(e => e.ArmorTypeId == bodyPartId);

                        if (minDamage - bodyPart.ArmorValue < 0)
                        {
                            minDamage = 0;
                        }
                        else
                        {
                            minDamage -= bodyPart.ArmorValue;
                        }

                        if (maxDamage - bodyPart.ArmorValue < 0)
                        {
                            maxDamage = 0;
                        }
                        else
                        {
                            maxDamage -= bodyPart.ArmorValue;
                        }

                        string action = WhatHappenedThatHit(player1HitChanceMainHand, player2DodgeChance, player2ParryChance, player2BlockChance, player2HasShield, player2HasWeapon, random);

                        if (action == "h")
                        {
                            damage          = random.Next(minDamage, maxDamage + 1);
                            roundLog       += generate.CombatTextMaleAttacker(player1.Name, player2.Name, damage, bodyPart.Name, random.Next(0, combatflavorindex));
                            player2.Health -= damage;
                        }
                        else if (action == "b")
                        {
                            roundLog += generate.CombatTextBlock(player1.Name, player2.Name, player1.MainHand.Name.ToLower(), player2.OffHand.shld.Name, random.Next(0, 1));
                        }
                        else if (action == "p")
                        {
                            roundLog += generate.CombatTextParry(player1.Name, player2.Name, random.Next(0, 1));
                        }
                        else if (action == "d")
                        {
                            roundLog += generate.CombatTextDodge(player1.Name, player1.MainHand.Name, player2.Name, random.Next(0, 1));
                        }

                        player1AttackWithOffHand = false;
                    }

                    // Check if Player2 forfeits
                    if (player2.Health <= player2.Vitality * (player2Forfeit / 100))
                    {
                        keepFighting = false;
                        player1Won   = true;
                    }

                    if (keepFighting && player2AttackWithMainHand)
                    {
                        bonusDamage = player2.Strength / 10;
                        minDamage   = player2.MainHand.MinimumDamage + bonusDamage;
                        maxDamage   = player2.MainHand.MaximumDamage + bonusDamage;

                        var bodyPartId = DiceForBodyPart(random.Next(1, 97), player2.MainHand.Name);
                        var bodyPart   = player1.Equipment.FirstOrDefault(ec => ec.ArmorTypeId == bodyPartId);

                        if (minDamage - bodyPart.ArmorValue < 0)
                        {
                            minDamage = 0;
                        }
                        else
                        {
                            minDamage -= bodyPart.ArmorValue;
                        }

                        if (maxDamage - bodyPart.ArmorValue < 0)
                        {
                            maxDamage = 0;
                        }
                        else
                        {
                            maxDamage -= bodyPart.ArmorValue;
                        }

                        string action = WhatHappenedThatHit(player2HitChanceMainHand, player1DodgeChance, player1ParryChance, player1BlockChance, player1HasShield, player1HasWeapon, random);

                        if (action == "h")
                        {
                            damage          = random.Next(minDamage, maxDamage + 1);
                            roundLog       += generate.CombatTextMaleAttacker(player2.Name, player1.Name, damage, bodyPart.Name, random.Next(0, combatflavorindex));
                            player1.Health -= damage;
                        }
                        else if (action == "b")
                        {
                            roundLog += generate.CombatTextBlock(player2.Name, player1.Name, player2.MainHand.Name.ToLower(), player1.OffHand.shld.Name, random.Next(0, 1));
                        }
                        else if (action == "p")
                        {
                            roundLog += generate.CombatTextParry(player2.Name, player1.Name, random.Next(0, 1));
                        }
                        else if (action == "d")
                        {
                            roundLog += generate.CombatTextDodge(player2.Name, player2.MainHand.Name, player1.Name, random.Next(0, 1));
                        }

                        player2AttackWithMainHand = false;
                    }
                    else if (keepFighting && player2AttackWithOffHand)
                    {
                        bonusDamage = player2.Strength / 10;
                        minDamage   = player2.OffHand.wep.MinimumDamage + bonusDamage;
                        maxDamage   = player2.OffHand.wep.MaximumDamage + bonusDamage;

                        var bodyPartId = DiceForBodyPart(random.Next(1, 97), player2.OffHand.wep.Name);
                        var bodyPart   = player1.Equipment.FirstOrDefault(ec => ec.ArmorTypeId == bodyPartId);

                        if (minDamage - bodyPart.ArmorValue < 0)
                        {
                            minDamage = 0;
                        }
                        else
                        {
                            minDamage -= bodyPart.ArmorValue;
                        }

                        if (maxDamage - bodyPart.ArmorValue < 0)
                        {
                            maxDamage = 0;
                        }
                        else
                        {
                            maxDamage -= bodyPart.ArmorValue;
                        }

                        string action = WhatHappenedThatHit(player2HitChanceMainHand, player1DodgeChance, player1ParryChance, player1BlockChance, player1HasShield, player1HasWeapon, random);

                        if (action == "h")
                        {
                            damage          = random.Next(minDamage, maxDamage + 1);
                            roundLog       += generate.CombatTextMaleAttacker(player2.Name, player1.Name, damage, bodyPart.Name, random.Next(0, combatflavorindex));
                            player1.Health -= damage;
                        }
                        else if (action == "b")
                        {
                            roundLog += generate.CombatTextBlock(player2.Name, player1.Name, player2.MainHand.Name.ToLower(), player1.OffHand.shld.Name, random.Next(0, 1));
                        }
                        else if (action == "p")
                        {
                            roundLog += generate.CombatTextParry(player2.Name, player1.Name, random.Next(0, 1));
                        }
                        else if (action == "d")
                        {
                            roundLog += generate.CombatTextDodge(player2.Name, player2.MainHand.Name, player1.Name, random.Next(0, 1));
                        }

                        player2AttackWithOffHand = false;
                    }

                    // Check if player1 forfeits
                    if (player1.Health <= player1.Vitality * (player1Forfeit / 100))
                    {
                        keepFighting = false;
                        player2Won   = true;
                    }
                }
                else
                {
                    if (keepFighting && player2AttackWithMainHand)
                    {
                        bonusDamage = player2.Strength / 10;
                        minDamage   = player2.MainHand.MinimumDamage + bonusDamage;
                        maxDamage   = player2.MainHand.MaximumDamage + bonusDamage;

                        var bodyPartId = DiceForBodyPart(random.Next(1, 97), player2.MainHand.Name);
                        var bodyPart   = player1.Equipment.FirstOrDefault(ec => ec.ArmorTypeId == bodyPartId);

                        if (minDamage - bodyPart.ArmorValue < 0)
                        {
                            minDamage = 0;
                        }
                        else
                        {
                            minDamage -= bodyPart.ArmorValue;
                        }

                        if (maxDamage - bodyPart.ArmorValue < 0)
                        {
                            maxDamage = 0;
                        }
                        else
                        {
                            maxDamage -= bodyPart.ArmorValue;
                        }

                        string action = WhatHappenedThatHit(player2HitChanceMainHand, player1DodgeChance, player1ParryChance, player1BlockChance, player1HasShield, player1HasWeapon, random);

                        if (action == "h")
                        {
                            damage          = random.Next(minDamage, maxDamage + 1);
                            roundLog       += generate.CombatTextMaleAttacker(player2.Name, player1.Name, damage, bodyPart.Name, random.Next(0, combatflavorindex));
                            player1.Health -= damage;
                        }
                        else if (action == "b")
                        {
                            roundLog += generate.CombatTextBlock(player2.Name, player1.Name, player2.MainHand.Name.ToLower(), player1.OffHand.shld.Name, random.Next(0, 1));
                        }
                        else if (action == "p")
                        {
                            roundLog += generate.CombatTextParry(player2.Name, player1.Name, random.Next(0, 1));
                        }
                        else if (action == "d")
                        {
                            roundLog += generate.CombatTextDodge(player2.Name, player2.MainHand.Name, player1.Name, random.Next(0, 1));
                        }

                        player2AttackWithMainHand = false;
                    }
                    else if (keepFighting && player2AttackWithOffHand)
                    {
                        bonusDamage = player2.Strength / 10;
                        minDamage   = player2.OffHand.wep.MinimumDamage + bonusDamage;
                        maxDamage   = player2.OffHand.wep.MaximumDamage + bonusDamage;

                        var bodyPartId = DiceForBodyPart(random.Next(1, 97), player2.OffHand.wep.Name);
                        var bodyPart   = player1.Equipment.FirstOrDefault(ec => ec.ArmorTypeId == bodyPartId);

                        if (minDamage - bodyPart.ArmorValue < 0)
                        {
                            minDamage = 0;
                        }
                        else
                        {
                            minDamage -= bodyPart.ArmorValue;
                        }

                        if (maxDamage - bodyPart.ArmorValue < 0)
                        {
                            maxDamage = 0;
                        }
                        else
                        {
                            maxDamage -= bodyPart.ArmorValue;
                        }

                        string action = WhatHappenedThatHit(player2HitChanceMainHand, player1DodgeChance, player1ParryChance, player1BlockChance, player1HasShield, player1HasWeapon, random);

                        if (action == "h")
                        {
                            damage          = random.Next(minDamage, maxDamage + 1);
                            roundLog       += generate.CombatTextMaleAttacker(player2.Name, player1.Name, damage, bodyPart.Name, random.Next(0, combatflavorindex));
                            player1.Health -= damage;
                        }
                        else if (action == "b")
                        {
                            roundLog += generate.CombatTextBlock(player2.Name, player1.Name, player2.MainHand.Name.ToLower(), player1.OffHand.shld.Name, random.Next(0, 1));
                        }
                        else if (action == "p")
                        {
                            roundLog += generate.CombatTextParry(player2.Name, player1.Name, random.Next(0, 1));
                        }
                        else if (action == "d")
                        {
                            roundLog += generate.CombatTextDodge(player2.Name, player2.MainHand.Name, player1.Name, random.Next(0, 1));
                        }

                        player2AttackWithOffHand = false;
                    }

                    // Check if player 1 forfeits
                    if (player1.Health <= player1.Vitality * (player1Forfeit / 100))
                    {
                        keepFighting = false;
                        player2Won   = true;
                    }

                    if (keepFighting && player1AttackWithMainHand)
                    {
                        bonusDamage = player1.Strength / 10;
                        minDamage   = player1.MainHand.MinimumDamage + bonusDamage;
                        maxDamage   = player1.MainHand.MaximumDamage + bonusDamage;

                        var bodyPartId = DiceForBodyPart(random.Next(1, 97), player1.MainHand.Name);
                        var bodyPart   = player2.Equipment.FirstOrDefault(al => al.ArmorTypeId == bodyPartId);

                        if (minDamage - bodyPart.ArmorValue < 0)
                        {
                            minDamage = 0;
                        }
                        else
                        {
                            minDamage -= bodyPart.ArmorValue;
                        }

                        if (maxDamage - bodyPart.ArmorValue < 0)
                        {
                            maxDamage = 0;
                        }
                        else
                        {
                            maxDamage -= bodyPart.ArmorValue;
                        }

                        string action = WhatHappenedThatHit(player1HitChanceMainHand, player2DodgeChance, player2ParryChance, player2BlockChance, player2HasShield, player2HasWeapon, random);

                        if (action == "h")
                        {
                            damage          = random.Next(minDamage, maxDamage + 1);
                            roundLog       += generate.CombatTextMaleAttacker(player1.Name, player2.Name, damage, bodyPart.Name, random.Next(0, combatflavorindex));
                            player2.Health -= damage;
                        }
                        else if (action == "b")
                        {
                            roundLog += generate.CombatTextBlock(player1.Name, player2.Name, player1.MainHand.Name.ToLower(), player2.OffHand.shld.Name, random.Next(0, 1));
                        }
                        else if (action == "p")
                        {
                            roundLog += generate.CombatTextParry(player1.Name, player2.Name, random.Next(0, 1));
                        }
                        else if (action == "d")
                        {
                            roundLog += generate.CombatTextDodge(player1.Name, player1.MainHand.Name, player2.Name, random.Next(0, 1));
                        }

                        player1AttackWithMainHand = false;
                    }
                    else if (keepFighting && player1AttackWithOffHand)
                    {
                        bonusDamage = player1.Strength / 10;
                        minDamage   = player2.OffHand.wep.MinimumDamage + bonusDamage;
                        maxDamage   = player2.OffHand.wep.MaximumDamage + bonusDamage;

                        var bodyPartId = DiceForBodyPart(random.Next(1, 97), player2.OffHand.wep.Name);
                        var bodyPart   = player2.Equipment.FirstOrDefault(al => al.ArmorTypeId == bodyPartId);

                        if (minDamage - bodyPart.ArmorValue < 0)
                        {
                            minDamage = 0;
                        }
                        else
                        {
                            minDamage -= bodyPart.ArmorValue;
                        }

                        if (maxDamage - bodyPart.ArmorValue < 0)
                        {
                            maxDamage = 0;
                        }
                        else
                        {
                            maxDamage -= bodyPart.ArmorValue;
                        }

                        string action = WhatHappenedThatHit(player1HitChanceMainHand, player2DodgeChance, player2ParryChance, player2BlockChance, player2HasShield, player2HasWeapon, random);

                        if (action == "h")
                        {
                            damage          = random.Next(minDamage, maxDamage + 1);
                            roundLog       += generate.CombatTextMaleAttacker(player1.Name, player2.Name, damage, bodyPart.Name, random.Next(0, combatflavorindex));
                            player2.Health -= damage;
                        }
                        else if (action == "b")
                        {
                            roundLog += generate.CombatTextBlock(player1.Name, player2.Name, player1.MainHand.Name.ToLower(), player2.OffHand.shld.Name, random.Next(0, 1));
                        }
                        else if (action == "p")
                        {
                            roundLog += generate.CombatTextParry(player1.Name, player2.Name, random.Next(0, 1));
                        }
                        else if (action == "d")
                        {
                            roundLog += generate.CombatTextDodge(player1.Name, player1.MainHand.Name, player2.Name, random.Next(0, 1));
                        }

                        player1AttackWithOffHand = false;
                    }

                    // check if player2 forfeits
                    if (player2.Health <= player2.Vitality * (player2Forfeit / 100))
                    {
                        keepFighting = false;
                        player1Won   = true;
                    }
                }

                if (!keepFighting)
                {
                    if (player1Won)
                    {
                        roundLog += player2.Name + " choose to yield, " + player1.Name + " wins the duel.";
                        spoiler   = player1.Name + " defeated " + player2.Name + " in a random duel.";
                    }
                    if (player2Won)
                    {
                        roundLog += player1.Name + " choose to yield, " + player2.Name + " wins the duel.";
                        spoiler   = player2.Name + " defeated " + player1.Name + " in a random duel.";
                    }
                }

                var round = new Round()
                {
                    RoundNr = roundNr,
                    Log     = roundLog,
                };

                fullFight.Add(round);

                roundLog = string.Empty;
            }

            if (player1.Health < 0)
            {
                int  survivalDice  = random.Next(1, 6);
                bool characterDied = FateOfCharacter(survivalDice, player1);

                if (characterDied)
                {
                    player1.Alive = false;

                    roundNr++;
                    var round = new Round()
                    {
                        RoundNr = roundNr,
                        Log     = player1.Name + " dies from the wounds ",
                    };
                }
            }
            else if (player2.Health < 0)
            {
                int  survivalDice  = random.Next(1, 6);
                bool characterDied = FateOfCharacter(survivalDice, player2);

                if (characterDied)
                {
                    player2.Alive = false;

                    roundNr++;
                    var round = new Round()
                    {
                        RoundNr = roundNr,
                        Log     = player2.Name + " dies from the wounds ",
                    };
                }
            }

            SaveCombatLogToDatabase(ctx, fullFight, player1, spoiler);

            if (player2Id != null)
            {
                SaveCombatLogToDatabase(ctx, fullFight, player2, spoiler);
            }

            ctx.Arenas.Remove(ctx.Arenas.FirstOrDefault(a => a.CharacterId == player1.Id));

            if (ctx.Arenas.Any(a => a.CharacterId == player2Id))
            {
                ctx.Arenas.Remove(ctx.Arenas.FirstOrDefault(a => a.CharacterId == player2.Id));
            }

            if (player1Won)
            {
                UpdateCharacterStats(player1);
            }
            else
            {
                if (player2Id != null)
                {
                    UpdateCharacterStats(player2);
                }
            }

            ctx.SaveChanges();

            return(fullFight);
        }