Beispiel #1
0
        public async Task <HeroesManagementDto> GetHeroesToModify(int heroId)
        {
            HeroesManagementDto heroToReturn = new HeroesManagementDto();

            Heroes hero = await _context.Heroes.FirstOrDefaultAsync(x => x.Id == heroId);

            HeroeStats heroStats = await _context.HeroeStats.FirstOrDefaultAsync(x => x.HeroId == hero.Id);


            heroToReturn.AbilityPower          = heroStats.AbilityPower;
            heroToReturn.ApLifeSteal           = heroStats.ApLifeSteal;
            heroToReturn.Armour                = heroStats.Armour;
            heroToReturn.ArmourPenetration     = heroStats.ArmourPenetration;
            heroToReturn.ArmourPenetrationProc = heroStats.ArmourPenetrationProc;
            heroToReturn.AttackDamage          = heroStats.AttackDamage;
            heroToReturn.AttackSpeed           = heroStats.AttackSpeed;
            heroToReturn.CooldownReduction     = heroStats.CooldownReduction;
            heroToReturn.CriticalChance        = heroStats.CriticalChance;
            heroToReturn.HeroName              = hero.HeroName;
            heroToReturn.HitPoints             = heroStats.HitPoints;
            heroToReturn.HitPointsRegen        = heroStats.HitPointsRegen;
            heroToReturn.LifeSteal             = heroStats.LifeSteal;
            heroToReturn.MagicPenetration      = heroStats.MagicPenetration;
            heroToReturn.MagicPenetrationProc  = heroStats.MagicPenetrationProc;
            heroToReturn.MagicResistance       = heroStats.MagicResistance;
            heroToReturn.Mana          = heroStats.Mana;
            heroToReturn.ManaRegen     = heroStats.ManaRegen;
            heroToReturn.MovementSpeed = heroStats.MovementSpeed;
            heroToReturn.Range         = heroStats.Range;
            heroToReturn.Tenacity      = heroStats.Tenacity;

            return(heroToReturn);
        }
Beispiel #2
0
        //public async Task<bool> ModifyHero(Heroes heroToModify)
        //{
        //    var heroToModifyData = await _context.Heroes.FirstOrDefaultAsync(x => x.HeroName == heroToModify.HeroName);


        //    heroToModifyData.HeroName = heroToModify.HeroName;

        //    _context.Heroes.Update(heroToModifyData);

        //    await _context.SaveChangesAsync();

        //    return true;
        //}

        public async Task <bool> ModifyHeroStats(HeroeStats heroStats)
        {
            var heroStatsToModifyData = await _context.HeroeStats.FirstOrDefaultAsync(x => x.HeroId == heroStats.HeroId);


            heroStatsToModifyData.AbilityPower          = heroStats.AbilityPower;
            heroStatsToModifyData.ApLifeSteal           = heroStats.ApLifeSteal;
            heroStatsToModifyData.Armour                = heroStats.Armour;
            heroStatsToModifyData.ArmourPenetration     = heroStats.ArmourPenetration;
            heroStatsToModifyData.ArmourPenetrationProc = heroStats.ArmourPenetrationProc;
            heroStatsToModifyData.AttackDamage          = heroStats.AttackDamage;
            heroStatsToModifyData.AttackSpeed           = heroStats.AttackSpeed;
            heroStatsToModifyData.CooldownReduction     = heroStats.CooldownReduction;
            heroStatsToModifyData.CriticalChance        = heroStats.CriticalChance;
            heroStatsToModifyData.HitPoints             = heroStats.HitPoints;
            heroStatsToModifyData.HitPointsRegen        = heroStats.HitPointsRegen;
            heroStatsToModifyData.LifeSteal             = heroStats.LifeSteal;
            heroStatsToModifyData.MagicPenetration      = heroStats.MagicPenetration;
            heroStatsToModifyData.MagicPenetrationProc  = heroStats.MagicPenetrationProc;
            heroStatsToModifyData.MagicResistance       = heroStats.MagicResistance;
            heroStatsToModifyData.Mana          = heroStats.Mana;
            heroStatsToModifyData.ManaRegen     = heroStats.ManaRegen;
            heroStatsToModifyData.MovementSpeed = heroStats.MovementSpeed;
            heroStatsToModifyData.Range         = heroStats.Range;
            heroStatsToModifyData.Tenacity      = heroStats.Tenacity;


            _context.HeroeStats.Update(heroStatsToModifyData);

            await _context.SaveChangesAsync();

            return(true);
        }
Beispiel #3
0
        public async Task <HeroeStats> CreateHeroStats(HeroeStats heroStats)
        {
            int id = await _context.HeroeStats.MaxAsync(x => x.Id);

            heroStats.Id = id + 1;
            await _context.HeroeStats.AddAsync(heroStats);

            await _context.SaveChangesAsync();

            return(heroStats);
        }
        public async Task <IActionResult> AddHeroes([FromBody] HeroesManagementDto hero)
        {
            //nieuwzglenianie case sensitivity
            hero.HeroName = hero.HeroName.ToLower();

            // sprawdzenie czy taki bohater juz istnieje
            if (await _repo.ValidateHeroName(hero.HeroName))
            {
                return(BadRequest("Taka nazwa bohatera już istnieje"));
            }

            // dodanie bohatera
            var heroToCreate = new Heroes
            {
                HeroName = hero.HeroName,
                GameId   = hero.GameId
            };

            var createdHero = await _repo.CreateHero(heroToCreate);


            // dodanie statystyk bohatera
            var heroStats = new HeroeStats
            {
                AbilityPower          = hero.AbilityPower,
                ApLifeSteal           = hero.ApLifeSteal,
                Armour                = hero.Armour,
                ArmourPenetration     = hero.ArmourPenetration,
                ArmourPenetrationProc = hero.ArmourPenetrationProc,
                AttackDamage          = hero.AttackDamage,
                AttackSpeed           = hero.AttackSpeed,
                CooldownReduction     = hero.CooldownReduction,
                CriticalChance        = hero.CriticalChance,
                HitPoints             = hero.HitPoints,
                HitPointsRegen        = hero.HitPointsRegen,
                LifeSteal             = hero.LifeSteal,
                MagicPenetration      = hero.MagicPenetration,
                MagicPenetrationProc  = hero.MagicPenetrationProc,
                MagicResistance       = hero.MagicResistance,
                Mana          = hero.Mana,
                ManaRegen     = hero.ManaRegen,
                MovementSpeed = hero.MovementSpeed,
                Range         = hero.Range,
                Tenacity      = hero.Tenacity,
                HeroId        = heroToCreate.Id
            };

            var createdItemStats = await _repo.CreateHeroStats(heroStats);

            return(StatusCode(201));
        }
        public async Task <IActionResult> ModifyHeroes([FromBody] HeroesManagementDto hero)
        {
            //nieuwzglenianie case sensitivity
            hero.HeroName = hero.HeroName.ToLower();


            var heroIdFromDB = await _repo.GetHeroId(hero.HeroName);


            // dodanie statystyk bohatera
            var heroStats = new HeroeStats
            {
                AbilityPower          = hero.AbilityPower,
                ApLifeSteal           = hero.ApLifeSteal,
                Armour                = hero.Armour,
                ArmourPenetration     = hero.ArmourPenetration,
                ArmourPenetrationProc = hero.ArmourPenetrationProc,
                AttackDamage          = hero.AttackDamage,
                AttackSpeed           = hero.AttackSpeed,
                CooldownReduction     = hero.CooldownReduction,
                CriticalChance        = hero.CriticalChance,
                HitPoints             = hero.HitPoints,
                HitPointsRegen        = hero.HitPointsRegen,
                LifeSteal             = hero.LifeSteal,
                MagicPenetration      = hero.MagicPenetration,
                MagicPenetrationProc  = hero.MagicPenetrationProc,
                MagicResistance       = hero.MagicResistance,
                Mana          = hero.Mana,
                ManaRegen     = hero.ManaRegen,
                MovementSpeed = hero.MovementSpeed,
                Range         = hero.Range,
                Tenacity      = hero.Tenacity,
                HeroId        = heroIdFromDB
            };

            var createdItemStats = await _repo.ModifyHeroStats(heroStats);

            return(StatusCode(201));
        }
        /// <summary>
        /// metoda wylicza statystyki dla bohatera oraz jego ekwipunku
        /// </summary>
        /// <param name="hero"></param>
        /// <param name="eqDto"></param>
        /// <returns></returns>
        public async Task <StatisticsDto> CalculateStats(EquipmentStatisticDto eqDto)
        {
            StatisticsDto statisticsDto = new StatisticsDto();

            HeroeStats heroStats = await _context.HeroeStats.FirstOrDefaultAsync(x => x.Id == eqDto.HeroId);

            //współczynnik podnoszenia statystyk dla kolejnego poziomu bohatera - powstała na potrzeby aplikacji 10%
            decimal factorLvl = 0.1M;

            if (heroStats != null)
            {
                //ustawienie statystyk bohatera
                statisticsDto.HitPoints             = heroStats.HitPoints.HasValue ? (decimal)heroStats.HitPoints + ((decimal)heroStats.HitPoints * factorLvl * eqDto.HeroLvl) : 0;
                statisticsDto.HitPointsRegen        = heroStats.HitPointsRegen.HasValue ? (decimal)heroStats.HitPointsRegen + ((decimal)heroStats.HitPointsRegen * factorLvl * eqDto.HeroLvl) : 0;
                statisticsDto.Mana                  = heroStats.Mana.HasValue ? (decimal)heroStats.Mana + ((decimal)heroStats.Mana * factorLvl * eqDto.HeroLvl) : 0;
                statisticsDto.ManaRegen             = heroStats.ManaRegen.HasValue ? (decimal)heroStats.ManaRegen + ((decimal)heroStats.ManaRegen * factorLvl * eqDto.HeroLvl) : 0;
                statisticsDto.Range                 = heroStats.Range.HasValue ? (int)heroStats.Range : 0; //zasięg pozostaje bez zmian !
                statisticsDto.AttackDamage          = heroStats.AttackDamage.HasValue ? (decimal)heroStats.AttackDamage + ((decimal)heroStats.AttackDamage * factorLvl * eqDto.HeroLvl) : 0;
                statisticsDto.AttackSpeed           = heroStats.AttackSpeed.HasValue ? (decimal)heroStats.AttackSpeed + ((decimal)heroStats.AttackSpeed * factorLvl * eqDto.HeroLvl) : 0;
                statisticsDto.Armour                = heroStats.Armour.HasValue ? (decimal)heroStats.Armour + ((decimal)heroStats.Armour * factorLvl * eqDto.HeroLvl) : 0;
                statisticsDto.MagicResistance       = heroStats.MagicResistance.HasValue ? (decimal)heroStats.MagicResistance + ((decimal)heroStats.MagicResistance * factorLvl * eqDto.HeroLvl) : 0;
                statisticsDto.MovementSpeed         = heroStats.MovementSpeed.HasValue ? (decimal)heroStats.MovementSpeed + ((decimal)heroStats.MovementSpeed * factorLvl * eqDto.HeroLvl) : 0;
                statisticsDto.AbillityPower         = heroStats.AbilityPower.HasValue ? (decimal)heroStats.AbilityPower + ((decimal)heroStats.MovementSpeed * factorLvl * eqDto.HeroLvl) : 0;
                statisticsDto.CooldownReduction     = heroStats.CooldownReduction.HasValue ? (decimal)heroStats.CooldownReduction + ((decimal)heroStats.CooldownReduction * factorLvl * eqDto.HeroLvl) : 0;
                statisticsDto.ArmourPenetration     = heroStats.ArmourPenetration.HasValue ? (decimal)heroStats.ArmourPenetration + ((decimal)heroStats.ArmourPenetration * factorLvl * eqDto.HeroLvl) : 0;
                statisticsDto.ArmourPenetrationProc = heroStats.ArmourPenetrationProc.HasValue ? (decimal)heroStats.ArmourPenetrationProc + ((decimal)heroStats.ArmourPenetrationProc * factorLvl * eqDto.HeroLvl) : 0;
                statisticsDto.MagicPenetration      = heroStats.MagicPenetration.HasValue ? (decimal)heroStats.MagicPenetration + ((decimal)heroStats.MagicPenetration * factorLvl * eqDto.HeroLvl) : 0;
                statisticsDto.MagicPenetrationProc  = heroStats.MagicPenetrationProc.HasValue ? (decimal)heroStats.MagicPenetrationProc + ((decimal)heroStats.MagicPenetrationProc * factorLvl * eqDto.HeroLvl) : 0;
                statisticsDto.LifeSteal             = heroStats.LifeSteal.HasValue ? (decimal)heroStats.LifeSteal + ((decimal)heroStats.LifeSteal * factorLvl * eqDto.HeroLvl) : 0;
                statisticsDto.ApLifeSteal           = heroStats.ApLifeSteal.HasValue ? (decimal)heroStats.ApLifeSteal + ((decimal)heroStats.ApLifeSteal * factorLvl * eqDto.HeroLvl) : 0; // wampiryzm zaklęć
                statisticsDto.Tenacity              = heroStats.Tenacity.HasValue ? (decimal)heroStats.Tenacity + ((decimal)heroStats.Tenacity * factorLvl * eqDto.HeroLvl) : 0;          // nieustępliwość
                statisticsDto.CriticalChance        = heroStats.CriticalChance.HasValue ? (decimal)heroStats.CriticalChance + ((decimal)heroStats.CriticalChance * factorLvl * eqDto.HeroLvl) : 0;

                statisticsDto.TotalCost = 0; // ustawienie ceny początkowej

                // lista statystyk przedmiotów
                List <ItemStats> lstStats = new List <ItemStats>();

                // pobranie statystyk przedmiotów
                if (eqDto.FirtItemId != null && eqDto.FirtItemId > 0)
                {
                    ItemStats itemStat = await _context.ItemStats.FirstOrDefaultAsync(x => x.ItemId == eqDto.FirtItemId);

                    lstStats.Add(itemStat);
                }
                if (eqDto.SecondItemId != null && eqDto.SecondItemId > 0)
                {
                    ItemStats itemStat = await _context.ItemStats.FirstOrDefaultAsync(x => x.ItemId == eqDto.SecondItemId);

                    lstStats.Add(itemStat);
                }
                if (eqDto.ThirdItemId != null && eqDto.ThirdItemId > 0)
                {
                    ItemStats itemStat = await _context.ItemStats.FirstOrDefaultAsync(x => x.ItemId == eqDto.ThirdItemId);

                    lstStats.Add(itemStat);
                }
                if (eqDto.FourthItemId != null && eqDto.FourthItemId > 0)
                {
                    ItemStats itemStat = await _context.ItemStats.FirstOrDefaultAsync(x => x.ItemId == eqDto.FourthItemId);

                    lstStats.Add(itemStat);
                }
                if (eqDto.FifthItemId != null && eqDto.FifthItemId > 0)
                {
                    ItemStats itemStat = await _context.ItemStats.FirstOrDefaultAsync(x => x.ItemId == eqDto.FifthItemId);

                    lstStats.Add(itemStat);
                }
                if (eqDto.SixthItemId != null && eqDto.SixthItemId > 0)
                {
                    ItemStats itemStat = await _context.ItemStats.FirstOrDefaultAsync(x => x.ItemId == eqDto.SixthItemId);

                    lstStats.Add(itemStat);
                }

                // dodanie statystyk przedmiotów do statystyk bohatera
                foreach (ItemStats itemStat in lstStats)
                {
                    statisticsDto.HitPoints                 += itemStat.AdditionalHp.HasValue ? (decimal)itemStat.AdditionalHp : 0;
                    statisticsDto.HitPointsRegen            += itemStat.AdditionalBasicHpRegenPercentage.HasValue ? (statisticsDto.HitPointsRegen * (decimal)itemStat.AdditionalBasicHpRegenPercentage) : 0;
                    statisticsDto.Mana                      += itemStat.AdditionalMana.HasValue ? (decimal)itemStat.AdditionalMana : 0;
                    statisticsDto.ManaRegen                 += (itemStat.AdditionalManaRegen.HasValue ? (decimal)itemStat.AdditionalManaRegen : 0) + (itemStat.AdditionalBasicManaRegenPercentage.HasValue ? (statisticsDto.ManaRegen * (decimal)itemStat.AdditionalBasicManaRegenPercentage) : 0);
                    statisticsDto.AttackDamage              += itemStat.AdditionalDmg.HasValue ? (decimal)itemStat.AdditionalDmg : 0;
                    statisticsDto.AttackSpeed               += itemStat.AdditionalAttackSpeed.HasValue ? (decimal)itemStat.AdditionalAttackSpeed : 0;
                    statisticsDto.Armour                    += itemStat.AdditionalArmour.HasValue ? (decimal)itemStat.AdditionalArmour : 0;
                    statisticsDto.MagicResistance           += itemStat.AdditionalMagicResist.HasValue ? (decimal)itemStat.AdditionalMagicResist : 0;
                    statisticsDto.MovementSpeed             += itemStat.AdditionalMovementSpeed.HasValue ? (decimal)itemStat.AdditionalMovementSpeed : 0;
                    statisticsDto.AbillityPower             += itemStat.AdditionalAp.HasValue ? (decimal)itemStat.AdditionalAp : 0;
                    statisticsDto.CooldownReduction         += itemStat.AdditionalCooldownReduction.HasValue ? (decimal)itemStat.AdditionalCooldownReduction : 0;
                    statisticsDto.LifeSteal                 += itemStat.AdditionalLifeSteal.HasValue ? (decimal)itemStat.AdditionalLifeSteal : 0;
                    statisticsDto.CriticalChance            += itemStat.AdditionalCriticalChance.HasValue ? (decimal)itemStat.AdditionalCriticalChance : 0;
                    statisticsDto.AdditionalPotionPower     += itemStat.AdditionalPotionPower.HasValue ? (decimal)itemStat.AdditionalPotionPower : 0;
                    statisticsDto.AdditionalHitPointsPerHit += itemStat.AdditionalHitPointsPerHit.HasValue ? (decimal)itemStat.AdditionalHitPointsPerHit : 0;
                    statisticsDto.AdditionalGoldPerTenSec   += itemStat.AdditionalGoldPerTenSec.HasValue ? (decimal)itemStat.AdditionalGoldPerTenSec : 0;
                    statisticsDto.Description               += "\n" + itemStat.Descriptions;
                    statisticsDto.TotalCost                 += itemStat.Price.HasValue ? (decimal)itemStat.Price : 0;
                }
            }

            return(statisticsDto);
        }