Пример #1
0
        private void RunActorAuras(float deltaTime, Turn turn, Actor actor)
        {
            var damageDone = 0f;

            foreach (var aura in actor.Auras)
            {
                aura.Cooldown.Cool(deltaTime);
                aura.Duration -= deltaTime;

                if (aura.Cooldown.IsReady)
                {
                    var combatTable = new CombatTable(new Random(), aura.Owner.CurrentStatistics, actor.CurrentStatistics);
                    var roll = combatTable.Roll();
                    var damage = aura.Damage.CalculateDamage(aura.Owner, actor);
                    var healing = aura.Healing.CalculateHealing(aura.Owner, actor);
                    if (roll.IsCrit)
                    {
                        damage *= 2;
                        healing *= 2;
                    }

                    if (damage > 0)
                    {
                        damageDone += damage;
                        Event.Raise(new ActorTookDamage { Source = aura.Owner, Target = actor, Damage = damage, IsCrit = roll.IsCrit });
                        turn.Events.Add(new OldEvent(EventTypes.AuraDamage) { Actor = aura.Owner, Target = actor, Damage = damage });
                        actor.CurrentHealth -= damage;
                    }
                    if (healing > 0)
                    {
                        Event.Raise(new ActorWasHealed { Source = aura.Owner, Target = actor, Healing = healing, IsCrit = roll.IsCrit });
                        turn.Events.Add(new OldEvent(EventTypes.AuraHealing) { Actor = aura.Owner, Target = actor, Healing = healing });
                        actor.CurrentHealth += healing;
                    }
                    aura.Cooldown.Incur();
                }
            }

            if (damageDone > 0)
                actor.Auras.RemoveAll(x => x.BreaksOnDamage);

            actor.Auras.ForEach(aura =>
            {
                if (aura.Duration <= 0f)
                {
                    turn.Events.Add(new OldEvent(EventTypes.AuraExpired) { Actor = actor, Target = actor });
                }
            });

            actor.Auras.RemoveAll(aura => aura.Duration <= 0f);
        }
Пример #2
0
        private void ApplyAbilityOutcome(Turn turn, Actor actor, Ability ability, Actor target)
        {
            var combatTable = new CombatTable(random, actor.CurrentStatistics, target.CurrentStatistics, ability);
            var combatOutcome = combatTable.Roll();

            var abilityDamage = ability.Damage.CalculateDamage(actor, target);
            var abilityHealing = ability.Healing.CalculateHealing(actor, target);

            var damage = 0f;
            var damage2 = 0f;
            var healing = 0f;
            var blocked = 0f;

            if (combatOutcome.IsMiss)
                Event.Raise(new ActorMissed { Source = actor, Target = target });

            if (combatOutcome.IsDodge)
                Event.Raise(new ActorDodged { Source = actor, Target = target });

            if (combatOutcome.IsHit)
            {
                damage = abilityDamage;
                healing = abilityHealing;
            }

            if (combatOutcome.IsCrit)
            {
                damage = damage * 2f;
                healing = healing * 2f;
            }

            if (combatOutcome.IsBlock)
            {
                blocked = Math.Min(damage, actor.CurrentStatistics.For<Armor>().Rating * 0.1f);
                damage -= blocked;
                Event.Raise(new ActorBlocked { Source = actor, Target = target });
            }

            actor.CurrentMana -= ability.ManaCost;
            actor.CurrentEnergy -= ability.EnergyCost;

            if (damage > 0)
            {
                target.CurrentHealth -= (damage);
                Event.Raise(new ActorTookDamage { Source = actor, Target = target, Damage = damage, IsCrit = combatOutcome.IsCrit });

                actor.Auras.RemoveAll(x => x.BreaksOnDamage);
            }

            if (healing > 0)
            {
                target.CurrentHealth += (healing);
                Event.Raise(new ActorWasHealed { Source = actor, Target = target, Healing = healing, IsCrit = combatOutcome.IsCrit });
            }

            // Calculate damage threat
            target.ThreatList.Increase(actor, (int)(damage * ability.ThreatModifier));

            // Calculate healing threat for all enemies who knows the healer exists
            foreach (var enemyActor in Actors.Where(a => a.Faction != actor.Faction && a.ThreatList.Exists(healedActor => healedActor.Actor == target)))
            {
                enemyActor.ThreatList.Increase(actor, (int)(healing * 0.05f));
            }

            // Apply auras
            foreach (var aura in ability.AurasApplied)
            {
                target.Auras.Add(new Aura { Owner = actor, Cooldown = aura.Cooldown, Damage = aura.Damage, Healing = aura.Healing, Duration = aura.Duration, Name = aura.Name, Statistics = aura.Statistics, BreaksOnDamage = aura.BreaksOnDamage });
            }

            turn.Events.Add(new OldEvent(EventTypes.Ability)
            {
                Actor = actor,
                Target = target,
                Damage = damage,
                Damage2 = damage2,
                Healing = healing,
                Blocked = blocked,
                Ability = ability,
                CombatOutcome = combatOutcome
            });
        }