Beispiel #1
0
        }         // Attack()

        public static void UseItem(int userId, int itemId)
        {
            Creature     user = Combatants.SingleOrDefault(x => x.Id == userId);
            CreatureItem item = user.Items.SingleOrDefault(x => x.ItemId == itemId);

            if (item.Item.ItemType == Enumerators.ItemTypeEnum.Healing)
            {
                user.HitPoints += item.Item.Strength;

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

                AddToLog(new string($"{user.Name} używa {item.Item.Name}, które przywraca {item.Item.Strength} punktów zdrowia."));
            }

            else if (item.Item.ItemType == Enumerators.ItemTypeEnum.Mana)
            {
                user.Mana += item.Item.Strength;

                if (user.Mana > user.MaxMana)
                {
                    user.Mana = user.MaxMana;
                }

                AddToLog(new string($"{user.Name} używa {item.Item.Name}, które przywraca {item.Item.Strength} punktów many."));
            }

            user.ActionPoints -= item.Item.ActionCost;

            if (item.Qty == 1)
            {
                user.Items.Remove(item);
            }

            else
            {
                item.Qty -= 1;
            }
        }         // UseItem()
Beispiel #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()