Aura.Channel.Skills.Combat.Counterattack.Handle C# (CSharp) Метод

Handle() публичный статический Метод

Returns true if target has counter active and used it.
public static Handle ( Creature target, Creature attacker ) : bool
target Aura.Channel.World.Entities.Creature
attacker Aura.Channel.World.Entities.Creature
Результат bool
		public static bool Handle(Creature target, Creature attacker)
		{
			// We currently have a race condition here, Counter is used if
			// it's in the Ready state, but handling Counter takes a moment,
			// in which another enemy might attack, before the state is set
			// to Used. Once AIs aren't handled by the server anymore,
			// this would be *very* unlikely to happen, since the state
			// setting could be moved, but for the moment this lock is needed.
			// If the client is told about 2 simultaneous Counter uses it
			// will lock the user in place.
			lock (target.Temp.CounterSyncLock)
			{
				if (!target.Skills.IsReady(SkillId.Counterattack))
					return false;

				var handler = ChannelServer.Instance.SkillManager.GetHandler<Counterattack>(SkillId.Counterattack);
				handler.Use(target, attacker);

				// TODO: Centralize this so we don't have to maintain the active
				//   skill and the regens in multiple places.
				// TODO: Remove the need for this null check... AIs reset ActiveSkill
				//   in Complete, which is called from the combat action handler
				//   before we get back here.
				if (target.Skills.ActiveSkill != null)
					target.Skills.ActiveSkill.State = SkillState.Used;

				target.Regens.Remove("ActiveSkillWait");
			}

			return true;
		}

Same methods

Counterattack::Handle ( ICollection targets, Creature attacker ) : bool

Usage Example

Пример #1
0
        /// <summary>
        /// Handles attack.
        /// </summary>
        /// <param name="attacker">The creature attacking.</param>
        /// <param name="skill">The skill being used.</param>
        /// <param name="targetEntityId">The entity id of the target.</param>
        /// <returns></returns>
        public CombatSkillResult Use(Creature attacker, Skill skill, long targetEntityId)
        {
            if (attacker.IsStunned)
            {
                return(CombatSkillResult.Okay);
            }

            var target = attacker.Region.GetCreature(targetEntityId);

            if (target == null)
            {
                return(CombatSkillResult.Okay);
            }

            if (!attacker.GetPosition().InRange(target.GetPosition(), attacker.AttackRangeFor(target)))
            {
                return(CombatSkillResult.OutOfRange);
            }

            attacker.StopMove();
            var targetPosition = target.StopMove();

            // Counter
            if (Counterattack.Handle(target, attacker))
            {
                return(CombatSkillResult.Okay);
            }

            var rightWeapon = attacker.Inventory.RightHand;
            var leftWeapon  = attacker.Inventory.LeftHand;
            var magazine    = attacker.Inventory.Magazine;
            var dualWield   = (rightWeapon != null && leftWeapon != null && leftWeapon.Data.WeaponType != 0);
            var maxHits     = (byte)(dualWield ? 2 : 1);
            int prevId      = 0;

            for (byte i = 1; i <= maxHits; ++i)
            {
                var weapon          = (i == 1 ? rightWeapon : leftWeapon);
                var weaponIsKnuckle = (weapon != null && weapon.Data.HasTag("/knuckle/"));

                var aAction = new AttackerAction(CombatActionType.Hit, attacker, skill.Info.Id, targetEntityId);
                var tAction = new TargetAction(CombatActionType.TakeHit, target, attacker, skill.Info.Id);

                var cap = new CombatActionPack(attacker, skill.Info.Id, aAction, tAction);
                cap.Hit     = i;
                cap.MaxHits = maxHits;
                cap.PrevId  = prevId;
                prevId      = cap.Id;

                // Default attacker options
                aAction.Set(AttackerOptions.Result);
                if (dualWield)
                {
                    aAction.Set(AttackerOptions.DualWield);
                }

                // Base damage
                var damage = attacker.GetRndDamage(weapon);

                // Critical Hit
                CriticalHit.Handle(attacker, attacker.GetCritChanceFor(target), ref damage, tAction);

                // Subtract target def/prot
                SkillHelper.HandleDefenseProtection(target, ref damage);

                // Defense
                Defense.Handle(aAction, tAction, ref damage);

                // Mana Shield
                ManaShield.Handle(target, ref damage, tAction);

                // Deal with it!
                if (damage > 0)
                {
                    target.TakeDamage(tAction.Damage = damage, attacker);
                }

                // Aggro
                target.Aggro(attacker);

                // Evaluate caused damage
                if (!target.IsDead)
                {
                    if (tAction.Type != CombatActionType.Defended)
                    {
                        target.Stability -= this.GetStabilityReduction(attacker, weapon) / maxHits;

                        // React normal for CombatMastery, knock down if
                        // FH and not dual wield, don't knock at all if dual.
                        if (skill.Info.Id != SkillId.FinalHit)
                        {
                            // Originally we thought you knock enemies back, unless it's a critical
                            // hit, but apparently you knock *down* under normal circumstances.
                            // More research to be done.
                            if (target.IsUnstable && target.Is(RaceStands.KnockBackable))
                            {
                                //tAction.Set(tAction.Has(TargetOptions.Critical) ? TargetOptions.KnockDown : TargetOptions.KnockBack);
                                tAction.Set(TargetOptions.KnockDown);
                            }
                        }
                        else if (!dualWield && !weaponIsKnuckle)
                        {
                            target.Stability = Creature.MinStability;
                            tAction.Set(TargetOptions.KnockDown);
                        }
                    }
                }
                else
                {
                    tAction.Set(TargetOptions.FinishingKnockDown);
                }

                // React to knock back
                if (tAction.IsKnockBack)
                {
                    attacker.Shove(target, KnockBackDistance);

                    aAction.Set(AttackerOptions.KnockBackHit2);

                    // Remove dual wield option if last hit doesn't come from
                    // the second weapon.
                    if (cap.MaxHits != cap.Hit)
                    {
                        aAction.Options &= ~AttackerOptions.DualWield;
                    }
                }

                // Set stun time
                if (tAction.Type != CombatActionType.Defended)
                {
                    aAction.Stun = GetAttackerStun(attacker, weapon, tAction.IsKnockBack && (skill.Info.Id != SkillId.FinalHit || !dualWield));
                    tAction.Stun = GetTargetStun(attacker, weapon, tAction.IsKnockBack);
                }

                // Second hit doubles stun time for normal hits
                if (cap.Hit == 2 && !tAction.IsKnockBack)
                {
                    aAction.Stun *= 2;
                }

                // Update current weapon
                SkillHelper.UpdateWeapon(attacker, target, weapon);

                cap.Handle();

                // No second hit if target was knocked back
                if (tAction.IsKnockBack)
                {
                    break;
                }
            }

            return(CombatSkillResult.Okay);
        }
All Usage Examples Of Aura.Channel.Skills.Combat.Counterattack::Handle