Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="spellCast"></param>
        /// <returns></returns>
        private bool Cast(SpellCast spellCast)
        {
            var spell = spellCast.Spell;

            if (spellCast.Target is Entity target)
            {
                // TODO: https://github.com/WorldOfMogwais/WoMNetCore/issues/22
                var concentrateRoll = 10;

                Adventure.Enqueue(AdventureLog.Info(this, target, ActivityLog.Create(ActivityLog.ActivityType.Cast, ActivityLog.ActivityState.Init, concentrateRoll, spell)));

                if (concentrateRoll > 1 && concentrateRoll > spell.Level)
                {
                    Adventure.Enqueue(AdventureLog.Info(this, target, ActivityLog.Create(ActivityLog.ActivityType.Cast, ActivityLog.ActivityState.Success, concentrateRoll, spell)));
                    spell.SpellEffect(this, target);
                }
                else
                {
                    Adventure.Enqueue(AdventureLog.Info(this, target, ActivityLog.Create(ActivityLog.ActivityType.Cast, ActivityLog.ActivityState.Fail, concentrateRoll, spell)));
                }

                Adventure.Enqueue(AdventureLog.Attacked(this, target));

                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="weaponAttack"></param>
        /// <returns></returns>
        private void Attack(WeaponAttack weaponAttack)
        {
            var attackTimes = weaponAttack.ActionType == ActionType.Full ? BaseAttackBonus.Length : 1;
            var weapon      = weaponAttack.Weapon;
            var target      = weaponAttack.Target as Entity;

            //Console.WriteLine($"{Name}: is attacking {attackTimes} times");

            // all attacks are calculated
            Parallel.For(0, attackTimes, (attackIndex, state) =>
            {
                // break when target is null or dead, no more attacks on dead monsters.
                if (target == null || target.IsDead)
                {
                    state.Break();
                }

                var attackRolls = AttackRolls(attackIndex, weapon.CriticalMinRoll);
                var attack      = AttackRoll(attackRolls, target.ArmorClass, out var criticalCounts);

                Adventure.Enqueue(AdventureLog.Info(this, target,
                                                    ActivityLog.Create(ActivityLog.ActivityType.Attack, ActivityLog.ActivityState.Init,
                                                                       new int[] { attackIndex, attack, criticalCounts }, weaponAttack)));

                if (attack > target.ArmorClass || criticalCounts > 0)
                {
                    var damage         = DamageRoll(weapon, Dice);
                    var criticalDamage = 0;
                    if (criticalCounts > 0)
                    {
                        for (var i = 0; i < weapon.CriticalMultiplier - 1; i++)
                        {
                            criticalDamage += DamageRoll(weapon, Dice);
                        }
                    }

                    Adventure.Enqueue(AdventureLog.Info(this, target,
                                                        ActivityLog.Create(ActivityLog.ActivityType.Attack, ActivityLog.ActivityState.Success,
                                                                           new int[]
                    {
                        attackIndex, attack, criticalCounts, damage, criticalDamage, (int)DamageType.Weapon
                    }, weaponAttack)));
                    target.Damage(damage + criticalDamage, DamageType.Weapon);
                }
                else
                {
                    Adventure.Enqueue(AdventureLog.Info(this, target,
                                                        ActivityLog.Create(ActivityLog.ActivityType.Attack, ActivityLog.ActivityState.Fail,
                                                                           new int[] { attackIndex, attack, criticalCounts }, weaponAttack)));
                }

                Adventure.Enqueue(AdventureLog.Attacked(this, target));
            });
        }