/// <summary> /// Raised by the controller when a message is received /// </summary> public override void OnMessageReceived(IMessage rMessage) { if (rMessage == null) { return; } //if (mActorController.State.Stance != EnumControllerStance.SPELL_CASTING) { return; } MagicMessage lMagicMessage = rMessage as MagicMessage; if (lMagicMessage != null) { if (lMagicMessage.ID == MagicMessage.MSG_MAGIC_CAST) { mSpellIndex = lMagicMessage.SpellIndex; mMotionController.ActivateMotion(this); lMagicMessage.IsHandled = true; lMagicMessage.Recipient = this; } else if (lMagicMessage.ID == MagicMessage.MSG_MAGIC_CONTINUE) { if (mIsActive) { if (mStoredAnimatorSpeed > 0f) { mMotionController.Animator.speed = mStoredAnimatorSpeed; } mMotionController.SetAnimatorMotionPhase(mMotionLayer.AnimatorLayerIndex, PHASE_CONTINUE, mSpellInstance.CastingStyle, 0, false); lMagicMessage.IsHandled = true; lMagicMessage.Recipient = this; } } return; } // If we're not active, the other coditions don't matter if (!mIsActive) { CombatMessage lCombatMessage = rMessage as CombatMessage; if (lCombatMessage != null) { // Attack message if (lCombatMessage.Attacker == mMotionController.gameObject) { // Call for an attack if (rMessage.ID == CombatMessage.MSG_COMBATANT_ATTACK) { if (lCombatMessage.Defender != null) { mTargetForward = (lCombatMessage.Defender.transform.position - mMotionController._Transform.position).normalized; } else if (lCombatMessage.HitDirection.sqrMagnitude > 0f) { mTargetForward = lCombatMessage.HitDirection; } else { mTargetForward = mMotionController._Transform.forward; } lCombatMessage.IsHandled = true; lCombatMessage.Recipient = this; mMotionController.ActivateMotion(this); } } } } // If we are, we may need to cancel else { MotionMessage lMotionMessage = rMessage as MotionMessage; if (lMotionMessage != null) { // Continue with the casting if (lMotionMessage.ID == MotionMessage.MSG_MOTION_CONTINUE) { if (mStoredAnimatorSpeed > 0f) { mMotionController.Animator.speed = mStoredAnimatorSpeed; } mMotionController.SetAnimatorMotionPhase(mMotionLayer.AnimatorLayerIndex, PHASE_CONTINUE, mSpellInstance.CastingStyle, 0, false); lMotionMessage.IsHandled = true; lMotionMessage.Recipient = this; } // Cancel the casting else if (lMotionMessage.ID == MotionMessage.MSG_MOTION_DEACTIVATE) { if (mStoredAnimatorSpeed > 0f) { mMotionController.Animator.speed = mStoredAnimatorSpeed; } int lMotionParameter = (mWasTraversal ? 1 : 0); mMotionController.SetAnimatorMotionPhase(mMotionLayer.AnimatorLayerIndex, PHASE_CANCEL, lMotionParameter, false); lMotionMessage.IsHandled = true; lMotionMessage.Recipient = this; } } CombatMessage lCombatMessage = rMessage as CombatMessage; if (lCombatMessage != null) { // Attack messages if (lCombatMessage.Defender == mMotionController.gameObject) { // Determine if we're being attacked if (rMessage.ID == CombatMessage.MSG_DEFENDER_ATTACKED) { } // Gives us a chance to respond to the defender's reaction (post attack) else if (rMessage.ID == CombatMessage.MSG_DEFENDER_ATTACKED_BLOCKED) { mIsInterrupted = true; // The damaged and death animation may take over. So, cancel the instance now. if (mSpellInstance != null) { mSpellInstance.Cancel(); } } // Final hit (post attack) else if (rMessage.ID == CombatMessage.MSG_DEFENDER_ATTACKED_PARRIED || rMessage.ID == CombatMessage.MSG_DEFENDER_DAMAGED || rMessage.ID == CombatMessage.MSG_DEFENDER_KILLED) { mIsInterrupted = true; // The damaged and death animation may take over. So, cancel the instance now. if (mSpellInstance != null) { mSpellInstance.Cancel(); } } } // Defender messages else if (lCombatMessage.Defender == mMotionController.gameObject) { } } DamageMessage lDamageMessage = rMessage as DamageMessage; if (lDamageMessage != null) { mIsInterrupted = true; // The damaged and death animation may take over. So, cancel the instance now. if (mSpellInstance != null) { mSpellInstance.Cancel(); } } } }
/// <summary> /// Called to start the specific motion. If the motion /// were something like 'jump', this would start the jumping process /// </summary> /// <param name="rPrevMotion">Motion that this motion is taking over from</param> public override bool Activate(MotionControllerMotion rPrevMotion) { // Ensure we're not holding onto an old spell mSpellInstance = null; mStoredAnimatorSpeed = 0f; // Default the spell int lSpellIndex = mSpellIndex; // If a spell was specified (through the parameter), use it if (mParameter > 0) { lSpellIndex = mParameter; } // Allow the spell to be modified before the attack occurs MagicMessage lMessage = MagicMessage.Allocate(); lMessage.ID = MagicMessage.MSG_MAGIC_PRE_CAST; lMessage.Caster = mMotionController.gameObject; lMessage.SpellIndex = lSpellIndex; lMessage.CastingMotion = this; lMessage.Data = this; IActorCore lActorCore = mMotionController.gameObject.GetComponent <ActorCore>(); if (lActorCore != null) { lActorCore.SendMessage(lMessage); lSpellIndex = lMessage.SpellIndex; } #if USE_MESSAGE_DISPATCHER || OOTII_MD MessageDispatcher.SendMessage(lMessage); lSpellIndex = lMessage.SpellIndex; #endif MagicMessage.Release(lMessage); // Ensure we know what spell to cast if (mSpellInventory != null) { mSpellInstance = mSpellInventory.InstantiateSpell(lSpellIndex); } if (mSpellInstance == null) { return(false); } // Allow the casting mIKWeight = 0f; mHasCast = false; mIsInterrupted = false; mIsInterruptedReported = false; mHasReachedForward = false; mWasTraversal = (mActorController.State.Stance == EnumControllerStance.TRAVERSAL); // Rotate towards this target. If there's no camera, we'll // assume we're dealing with an NPC if (mMotionController._CameraTransform != null) { mTargetForward = mMotionController._CameraTransform.forward; } //// Ensure our combatant is setup //if (mCombatant != null) //{ // if (!mCombatant.OnAttackActivated(this)) // { // return false; // } //} // Run the approapriate cast int lMotionPhase = (mWasTraversal ? PHASE_STANDING_START : PHASE_START); mMotionController.SetAnimatorMotionPhase(mMotionLayer.AnimatorLayerIndex, lMotionPhase, mSpellInstance.CastingStyle, 0, true); // Now, activate the motion return(base.Activate(rPrevMotion)); }