Пример #1
0
        public static void Calculate(float bonusDamage, Race attacker, Race[] targets)
        {
            var stat = attacker.GetModule <StatModule> ();

            foreach (var target in targets)
            {
                var targetStat = target.GetModule <StatModule> ();
                var isHit      = AccuracyCalculator.IsHit(stat.attackRating, targetStat.attackRating);
                isHit = !isHit?AccuracyCalculator.MakeSureHit(attacker) : isHit;

                if (isHit)
                {
                    var isCritHit = AccuracyCalculator.IsCriticalHit(attacker, stat.criticalRating);
                    isCritHit = !isCritHit?AccuracyCalculator.MakeSureCritical(attacker) : isCritHit;

                    // optional Damage
                    var outputDamage = AttackPowerCalculator.TakeDamage(bonusDamage, targetStat.magicResist, isCritHit);
                    AccuracyCalculator.HandleCriticalDamage(ref outputDamage, attacker, target);
                    AttackPowerCalculator.HandleDamage(ref outputDamage, attacker, target);
                    target.GetModule <HealthPowerModule> (x => x.SubtractHp(outputDamage));
                }
                else
                {
                    var isCritHit = AccuracyCalculator.IsCriticalHit(attacker, stat.criticalRating);
                    var damage    = AttackPowerCalculator.TakeDamage(bonusDamage, targetStat.physicalDefend, isCritHit);
                    Affect.GetSubAffects <IMissingHandler>(target, handler => handler.HandleMissing(damage, attacker));
                }
            }
        }
Пример #2
0
        public static void Use(Race own, Affect affect)
        {
            var a = affect;

            foreach (var target in a.targets)
            {
                target.GetModule <AffectModule> ((am) => {
                    am.AddAffect(a);
                });
                var effectValueTransfer = own.GetModule <EffectValueTransferModule> ();
                if (typeof(IPhysicalAttackingEventHandler).IsAssignableFrom(a.GetType()))
                {
                    var physicalAttacking = ((IPhysicalAttackingEventHandler)a);
                    var stat       = own.GetModule <StatModule> ();
                    var targetStat = target.GetModule <StatModule> ();
                    var isHit      = AccuracyCalculator.IsHit(stat.attackRating, targetStat.attackRating);
                    isHit = !isHit?AccuracyCalculator.IsDodgeable(own, target) : isHit;

                    isHit = !isHit?AccuracyCalculator.MakeSureHit(own) : isHit;

                    effectValueTransfer.Add("isHit", isHit);
                    if (isHit)
                    {
                        var isCritHit = AccuracyCalculator.IsCriticalHit(own, stat.criticalRating);
                        isCritHit = !isCritHit?AccuracyCalculator.MakeSureCritical(own) : isCritHit;

                        // optional Damage
                        var outputDamage = AttackPowerCalculator.TakeDamage(physicalAttacking.bonusDamage, targetStat.physicalDefend, isCritHit);
                        AccuracyCalculator.HandleCriticalDamage(ref outputDamage, own, target);
                        AttackPowerCalculator.HandleDamage(ref outputDamage, own, target);

                        target.GetModule <HealthPowerModule> (x => x.SubtractHp(outputDamage));

                        effectValueTransfer.Add("damage", outputDamage);
                        effectValueTransfer.Add("targetHp", target.GetModule <HealthPowerModule> ().hp);
                        effectValueTransfer.Add("isCritHit", isCritHit);
                        effectValueTransfer.Add("targetNetId", target.netId.Value);

                        AttackPowerCalculator.OccurAffectChange(own, target);
                        AttackPowerCalculator.ExtraAttackableAffect(own, target);
                        physicalAttacking.HandleAttack(target);
                    }
                    else
                    {
                        var isCritHit = AccuracyCalculator.IsCriticalHit(own, stat.criticalRating);
                        var damage    = AttackPowerCalculator.TakeDamage(physicalAttacking.bonusDamage, targetStat.physicalDefend, isCritHit);

                        effectValueTransfer.Add("damage", damage);
                        effectValueTransfer.Add("targetHp", target.GetModule <HealthPowerModule> ().hp);
                        effectValueTransfer.Add("isCritHit", isCritHit);
                        effectValueTransfer.Add("targetNetId", target.netId.Value);

                        physicalAttacking.HandleAttack(target);
                    }
                }
                else if (typeof(IMagicalAttackingEventHandler).IsAssignableFrom(a.GetType()))
                {
                    var magicalAttacking = ((IMagicalAttackingEventHandler)a);
                    var stat             = own.GetModule <StatModule> ();
                    var targetStat       = target.GetModule <StatModule> ();
                    var isHit            = AccuracyCalculator.IsHit(stat.attackRating, targetStat.attackRating);
                    isHit = !isHit?AccuracyCalculator.IsDodgeable(own, target) : isHit;

                    isHit = !isHit?AccuracyCalculator.MakeSureHit(own) : isHit;

                    effectValueTransfer.Add("isHit", isHit);
                    if (isHit)
                    {
                        var isCritHit = AccuracyCalculator.IsCriticalHit(own, stat.criticalRating);
                        isCritHit = !isCritHit?AccuracyCalculator.MakeSureCritical(own) : isCritHit;

                        // optional Damage
                        var outputDamage = AttackPowerCalculator.TakeDamage(magicalAttacking.bonusDamage, targetStat.magicResist, isCritHit);
                        AccuracyCalculator.HandleCriticalDamage(ref outputDamage, own, target);
                        AttackPowerCalculator.HandleDamage(ref outputDamage, own, target);

                        target.GetModule <HealthPowerModule> (x => x.SubtractHp(outputDamage));

                        effectValueTransfer.Add("damage", outputDamage);
                        effectValueTransfer.Add("targetHp", target.GetModule <HealthPowerModule> ().hp);
                        effectValueTransfer.Add("isCritHit", isCritHit);
                        effectValueTransfer.Add("targetNetId", target.netId.Value);

                        AttackPowerCalculator.OccurAffectChange(own, target);
                        AttackPowerCalculator.ExtraAttackableAffect(own, target);
                        magicalAttacking.HandleAttack(target);
                    }
                    else
                    {
                        var isCritHit = AccuracyCalculator.IsCriticalHit(own, stat.criticalRating);
                        var damage    = AttackPowerCalculator.TakeDamage(magicalAttacking.bonusDamage, targetStat.physicalDefend, isCritHit);

                        effectValueTransfer.Add("damage", damage);
                        effectValueTransfer.Add("targetHp", target.GetModule <HealthPowerModule> ().hp);
                        effectValueTransfer.Add("isCritHit", isCritHit);
                        effectValueTransfer.Add("targetNetId", target.netId.Value);
                        magicalAttacking.HandleAttack(target);
                    }
                }
                else
                {
                    a.Execute(target);
                }

                EmitAffects(own, new EmitAffectArgs {
                    affect = a,
                    target = target
                });
            }
            a.Execute();
            a.AddGainPoint();
            a.HandlePlugins();
            a.FlushAll();
        }