/// <summary>
        /// Used to test if the reactor should process
        /// </summary>
        /// <returns></returns>
        public override bool TestActivate(IMessage rMessage)
        {
            if (!base.TestActivate(rMessage))
            {
                return(false);
            }
            if (mActorCore == null || !mActorCore.IsAlive)
            {
                return(false);
            }

            MotionMessage lMessage = rMessage as MotionMessage;

            if (lMessage == null || lMessage.Motion == null)
            {
                return(false);
            }

            // We want to activate or deactivate the hand pose animator states is response to
            // motions being activated or deactivated
            if (lMessage.ID == EnumMessageID.MSG_MOTION_ACTIVATE ||
                lMessage.ID == EnumMessageID.MSG_MOTION_DEACTIVATE)
            {
                mMessage = lMessage;
                return(true);
            }

            return(false);
        }
示例#2
0
        /// <summary>
        /// Called when the reactor is first activated
        /// </summary>
        /// <returns>Determines if other reactors should process.</returns>
        public override bool Activate()
        {
            base.Activate();

            MotionMessage lMessage = (MotionMessage)mMessage;

            // We want to release the hand pose motion when the "Store" motion is activated (otherwise the hand will stay closed
            // until the animation has completed)
            if (lMessage.ID == EnumMessageID.MSG_MOTION_ACTIVATE)
            {
                if (mActorController.UseTransformPosition)
                {
                    SetUseTransform(false);
                }
            }
            // We want to set the hand pose motion when the "Equip" motion deactivates (after the animation is finished) so that
            // the hand doesn't close too early
            else if (lMessage.ID == EnumMessageID.MSG_MOTION_DEACTIVATE)
            {
                if (!mActorController.UseTransformPosition)
                {
                    SetUseTransform(true);
                }
            }

            // Disable the reactor
            Deactivate();

            // Allow other reactors to continue
            return(true);
        }
        /// <summary>
        /// Called when the reactor is first activated
        /// </summary>
        /// <returns>Determines if other reactors should process.</returns>
        public override bool Activate()
        {
            base.Activate();

            MotionMessage lMessage = (MotionMessage)mMessage;

            // We want to release the hand pose motion when the "Store" motion is activated (otherwise the hand will stay closed
            // until the animation has completed)
            if (lMessage.ID == EnumMessageID.MSG_MOTION_ACTIVATE)
            {
                if (lMessage.Motion is IStoreMotion)
                {
                    if (mRightHandPose == null)
                    {
                        mRightHandPose = mMotionController.GetMotion(EnumMotionLayer.RIGHT_HAND, RightHandPoseName) as BasicHandPose;
                    }
                    if (mLeftHandPose == null)
                    {
                        mLeftHandPose = mMotionController.GetMotion(EnumMotionLayer.LEFT_HAND, LeftHandPoseName) as BasicHandPose;
                    }

                    ReleaseHandPose(mRightHandPose);
                    ReleaseHandPose(mLeftHandPose);
                }
            }
            // We want to set the hand pose motion when the "Equip" motion deactivates (after the animation is finished) so that
            // the hand doesn't close too early
            else if (lMessage.ID == EnumMessageID.MSG_MOTION_DEACTIVATE)
            {
                if (lMessage.Motion is IEquipMotion)
                {
                    if (mRightHandPose == null)
                    {
                        mRightHandPose = mMotionController.GetMotion(EnumMotionLayer.RIGHT_HAND, RightHandPoseName) as BasicHandPose;
                    }
                    if (mLeftHandPose == null)
                    {
                        mLeftHandPose = mMotionController.GetMotion(EnumMotionLayer.LEFT_HAND, LeftHandPoseName) as BasicHandPose;
                    }

                    // TODO: check for two-handed weapon, as we don't want the left hand to stay closed ... or the LH pose state may simply be Empty
                    // May need to use a ReleaseOffHandPose tag for motions like Jump where one hand will come off the weapon.
                    SetHandPose(mRightHandPose);
                    SetHandPose(mLeftHandPose);
                }
            }


            // Disable the reactor
            Deactivate();

            // Allow other reactors to continue
            return(true);
        }
示例#4
0
        /// <summary>
        /// Deactivates the motion on the specified target
        /// </summary>
        /// <param name="rTarget">GameObject to activate the motion on</param>
        /// <returns>Bool that determines if the motion was activated</returns>
        public void ActivateInstance(GameObject rTarget)
        {
            MotionController lMotionController = rTarget.GetComponent <MotionController>();

            if (lMotionController != null)
            {
                MotionMessage lMessage = MotionMessage.Allocate();
                lMessage.ID = MessageID;

                lMotionController.SendMessage(lMessage);

                lMessage.Release();
            }
        }
示例#5
0
        /// <summary>
        /// Used to test if the reactor should process
        /// </summary>
        /// <returns></returns>
        public override bool TestActivate(IMessage rMessage)
        {
            // if the ActorController didn't start off set to Use Transform, then do nothing
            if (!mInitialUseTransform)
            {
                return(false);
            }
            if (!base.TestActivate(rMessage))
            {
                return(false);
            }
            if (mActorCore == null || !mActorCore.IsAlive)
            {
                return(false);
            }

            MotionMessage lMessage = rMessage as MotionMessage;

            // We're only responding to Activated and Deactivated Motion events
            if (lMessage == null || lMessage.Motion == null ||
                (lMessage.ID == EnumMessageID.MSG_MOTION_ACTIVATE &&
                 lMessage.ID == EnumMessageID.MSG_MOTION_DEACTIVATE))
            {
                return(false);
            }

            // For certain motion types, we want to disable Use Transform
            // on the agent's ActorController so that the root motion data
            // can move the character. Only on layer 0.
            if (lMessage.Motion.MotionLayer.Index != 0)
            {
                return(false);
            }

            // Only process motions that are correctly tagged
            if (!lMessage.Motion.TagExists(_RootMotionTag))
            {
                return(false);
            }

            mMessage = lMessage;
            return(true);
        }
示例#6
0
    private void BroadcastMotionToRelevantPlayers()
    {
        if (m_RelChecker.RelevantTo.Count == 0)
        {
            return;
        }

        if (!CompressRotation)
        {
            var msg = new MotionMessage
            {
                Pos         = m_LastPos,
                Rot         = m_LastRot,
                TargetNetID = netId
            };

            foreach (var nc in m_RelChecker.RelevantTo)
            {
                nc.Send(MessageType.Motion, msg);
            }
        }
        else
        {
            var msg = new CompressedMotionMessage
            {
                Pos         = m_LastPos,
                RotX        = (short)m_LastRot.eulerAngles.x,
                RotY        = (short)m_LastRot.eulerAngles.y,
                RotZ        = (short)m_LastRot.eulerAngles.z,
                TargetNetID = netId
            };

            foreach (var nc in m_RelChecker.RelevantTo)
            {
                nc.Send(MessageType.CompressedMotion, msg);
            }
        }
    }
示例#7
0
        /// <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();
                    }
                }
            }
        }
示例#8
0
 public void ReceiveMotionMessage(MotionMessage msg)
 {
     m_SyncPos = msg.Pos;
     m_SyncRot = msg.Rot;
 }