Esempio n. 1
0
        public JsonResult DamageCalculation(int battleID, int weaponQuality, bool isAttacker)
        {
            try
            {
                var citizen = SessionHelper.CurrentEntity.Citizen;
                var battle  = battleRepository.GetById(battleID);

                if (battle == null)
                {
                    return(JsonError("Battle does not exist!"));
                }

                if (weaponQuality > 0)
                {
                    if (citizen.Entity.GetEquipmentItem(ProductTypeEnum.Weapon, weaponQuality, productRepository).Amount == 0)
                    {
                        return(JsonError("You do not have such weapon in inventory!"));
                    }
                }


                var info = new
                {
                    damage                    = battleService.CalculateDamage(citizen, battle, weaponQuality, isAttacker),
                    weaponBonus               = battleService.CalculateWeaponBonus(weaponQuality),
                    healthModifier            = Percentage.ConvertToPercent(battleService.CalculateHealthModifier(citizen.HitPoints)),
                    militaryRankModifier      = Percentage.ConvertToPercent(battleService.CalculateMilitaryRankModifier((double)citizen.MilitaryRank)),
                    weaponAndStrengthModifier = Percentage.ConvertToPercent(battleService.CalculateStrengthModifier((double)citizen.Strength, weaponQuality)),
                    distanceModifier          = Percentage.ConvertToPercent(battleService.CalculateDistanceModifier(citizen, battle, isAttacker)),
                    developmentModifier       = Percentage.ConvertToPercent(battleService.CalculateDevelopmentModifier(battle, isAttacker)),
                    overallModifier           = Percentage.ConvertToPercent(battleService.CalculateOverallModifier(citizen, battle, weaponQuality, isAttacker))
                };

                return(JsonData(info));
            }
            catch (Exception e)
            {
                return(JsonDebugError(e));
            }
        }