Example #1
0
        public IActionResult OnPostCastSpell(int userId)
        {
            if (SelectedSpell != -1)
            {
                Spell spell = new GetSpell(_ctx).Get(SelectedSpell);

                if (spell.Type == Enumerators.SpellTypeEnum.Healing)
                {
                    BattleStatus.CastSpell(userId, userId, SelectedSpell, _ctx);
                }

                else
                {
                    BattleStatus.CastSpell(userId, SelectedEnemy, SelectedSpell, _ctx);
                }
            }

            return(RedirectToPage("BattleField"));
        }
Example #2
0
        }         // UseItem()

        public static void CastSpell(int userId, int targetId, int spellId, ApplicationDbContext ctx)
        {
            Creature user = Combatants.SingleOrDefault(x => x.Id == userId);
            Creature target;
            Spell    spell = new GetSpell(ctx).Get(spellId);

            user.Mana         -= spell.ManaCost;
            user.ActionPoints -= spell.ActionCost;

            if ((spell.Level * 10) >= random.Next(1, 100))
            {
                int selfharm;
                selfharm        = (int)Math.Round((double)(spell.Strength / 4));
                user.HitPoints -= selfharm;

                if (spell.Type == Enumerators.SpellTypeEnum.Healing)
                {
                    AddToLog(new string($"Zaklęcie {spell.Name} wymyka się spod kontoli i {user.Name} zamiast uleczyć rani się tracąc {selfharm} punktów życia."));
                }

                else
                {
                    AddToLog(new string($"Zaklęcie {spell.Name} wymyka się spod kontoli i {user.Name} zamiast trafić w przeciwnika rani siebie tracąc {selfharm} punktów życia."));
                }
            }             /// higher spell level means higher chance for failure and % of dmg done to the caster 0 - 0% , 10 - 10%

            else
            {
                if (userId != targetId)
                {
                    target = Combatants.SingleOrDefault(x => x.Id == targetId);
                }

                else
                {
                    target = user;
                }

                if (spell.Type == Enumerators.SpellTypeEnum.Healing)
                {
                    user.HitPoints += spell.Strength;

                    if (user.HitPoints > user.MaxHP)
                    {
                        user.HitPoints = user.MaxHP;
                    }

                    AddToLog(new string($"{user.Name} rzuca {spell.Name}, które przywraca {spell.Strength} punktów zdrowia."));
                }

                else
                {
                    if (random.Next(0, 100) < target.Willpower)
                    {
                        AddToLog(new string($"{target.Name} dzięki sile woli odrzuca zaklęcie wychodząc z ataku bez szwanku."));
                    }

                    else
                    {
                        int damage = (int)Math.Round((double)(spell.Strength * (100 / (100 + (double)target.MagicResistance))));

                        if (damage > 0)
                        {
                            target.HitPoints -= damage;
                        }

                        AddToLog(new string($"{user.Name} rzuca {spell.Name}, które trafia {target.Name} zadając mu {damage} punktów obrażeń."));
                    }
                }

                VerifyStatus(targetId, ctx);
            }
        }         // CastSpell()