Exemplo n.º 1
0
    void InitializeNext(FSMEvent ev)
    {
        _eventInjury = ev as AnimFSMEventInjuryBoss;
        string animName = Agent.AnimSet.GetInjuryPhaseAnim(++_curInjuryPhaseIDX);

        Tools.PlayAnimation(Agent.AnimEngine, animName, 0.1f);
        _endOfStateTime             = Agent.AnimEngine[animName].length + Time.timeSinceLevelLoad;
        Agent.BlackBoard.motionType = MotionType.NONE;
    }
Exemplo n.º 2
0
 protected override void Initialize(FSMEvent ev)
 {
     _eventMove = ev as AnimFSMEventMove;
     Agent.BlackBoard.desiredDirection = _eventMove.moveDir;
     _finalRotation.SetLookRotation(Agent.BlackBoard.desiredDirection);
     _startRotation = Agent.Transform.rotation;
     Agent.BlackBoard.motionType = GetMoveMotionType();
     _rotationProgress           = 0;
 }
Exemplo n.º 3
0
 public override bool OnEvent(FSMEvent ev)
 {
     if (ev is AnimFSMEventInjuryBoss)
     {
         InitializeNext(ev);
         return(true);
     }
     return(false);
 }
Exemplo n.º 4
0
 public override void OnEnter(FSMEvent ev = null)
 {
     base.OnEnter(ev);
     Agent.BlackBoard.invulnerable = true;
     if (Agent.particleSystemWhirlWind != null && Agent.BlackBoard.showMotionEffect)
     {
         ParticleTools.Instance.Play(Agent.particleSystemWhirlWind, 0, 1f);
     }
 }
Exemplo n.º 5
0
    /**/
    public void OnTriggerStay(Collider other)
    {
        FSMEvent evt = new FSMEvent();

        evt.msg = "stay";
        evt.obj = other.gameObject;
        fsm_.postEvent(evt);
        //this._cursor.transform.position = cell2position (position2cell (other.gameObject.transform.position));
    }
Exemplo n.º 6
0
    protected override void Initialize(FSMEvent ev = null)
    {
        _eventInjury = ev as AnimFSMEventInjuryBoss;

        _curInjuryPhaseIDX = 0;
        string animName = Agent.AnimSet.GetInjuryPhaseAnim(_curInjuryPhaseIDX);

        AnimationTools.PlayAnim(Agent.AnimEngine, animName, 0.1f);
        _endOfStateTime             = Agent.AnimEngine[animName].length + Time.timeSinceLevelLoad;
        Agent.BlackBoard.motionType = MotionType.NONE;
    }
Exemplo n.º 7
0
 public override bool OnEvent(FSMEvent ev)
 {
     if (ev is AnimFSMEventRotate)
     {
         if (_eventRotate != null)
         {
             _eventRotate.IsFinished = true;
         }
         Initialize(ev);
         return(true);
     }
     return(false);
 }
Exemplo n.º 8
0
    protected override void Initialize(FSMEvent ev)
    {
        _eventAttackRoll = ev as AnimFSMEventAttackRoll;

        _state = AttackRollState.PREPARE;
        AnimationTools.PlayAnim(Agent.AnimEngine, "attackRollStart", 0.4f);
        base.Initialize(_eventAttackRoll);
        Agent.BlackBoard.motionType = MotionType.NONE;
        _endOfStateTime             = Agent.AnimEngine["attackRollStart"].length * 0.95f + Time.timeSinceLevelLoad;
        _hitTimer = 0;
        UpdateFinalRotation();
        //Agent.SoundPlay(Agent.RollSounds[0]);
    }
Exemplo n.º 9
0
    protected override void Initialize(FSMEvent ev)
    {
        Agent.BlackBoard.motionType = MotionType.NONE;
        Agent.BlackBoard.moveDir    = Vector3.zero;
        Agent.BlackBoard.speed      = 0;
        _timeToFinishWeapon         = 0;
        _eventSword = null;

        if (ev is AnimFSMEvent)
        {
            (ev as AnimFSMEvent).IsFinished = true;
        }
    }
Exemplo n.º 10
0
    public override bool OnEvent(FSMEvent ev)
    {
        if (ev is AnimFSMEventAttackBow)
        {
            if (_eventAttack != null)
            {
                _eventAttack.IsFinished = true;
            }
            Initialize(ev);
            return(true);
        }

        return(false);
    }
Exemplo n.º 11
0
    public override bool OnEvent(FSMEvent ev)
    {
        if (ev is AnimFSMEventAttackMelee)
        {
            //if (_eventAttackMelee != null)
            //{
            //    _eventAttackMelee.IsFinished = true;
            //}
            Initialize(ev);
            return(true);
        }

        return(false);
    }
Exemplo n.º 12
0
    public override bool OnEvent(FSMEvent ev)
    {
        if (ev is AnimFSMEventFlash)
        {
            //if (_eventGoTo != null)
            //{
            //    _eventGoTo.IsFinished = true;
            //}
            Initialize(ev);
            return(true);
        }

        return(false);
    }
Exemplo n.º 13
0
    protected override void Initialize(FSMEvent ev = null)
    {
        _eventRotate = ev as AnimFSMEventRotate;
        //_currentRotationTime = 0;
        _rotationProgress = 0;
        _startRotation    = Agent.Transform.rotation;
        Vector3 finalDir;

        if (_eventRotate.target != null)
        {
            finalDir = (_eventRotate.target.Position + (_eventRotate.target.BlackBoard.moveDir *
                                                        _eventRotate.target.BlackBoard.speed * 0.5f)) - Agent.Transform.position;
            finalDir.Normalize();
        }
        else if (_eventRotate.direction != Vector3.zero)
        {
            finalDir = _eventRotate.direction;
        }
        else
        {
            finalDir = Agent.Transform.forward;
        }

        if (Vector3.Dot(finalDir, Agent.Transform.right) > 0)
        {
            _animName = Agent.AnimSet.GetRotateAnim(Agent.BlackBoard.motionType, RotationType.RIGHT);
        }
        else
        {
            _animName = Agent.AnimSet.GetRotateAnim(Agent.BlackBoard.motionType, RotationType.LEFT);
        }

        AnimationTools.PlayAnim(Agent.AnimEngine, _animName, 0.01f, QueueMode.CompleteOthers);

        _finalRotation.SetLookRotation(finalDir);

        /*_rotationTime = Vector3.Angle(Agent.Transform.forward, finalDir) / (360 * Agent.BlackBoard.rotationSmooth);
         *
         * if (_rotationTime == 0)
         * {
         *  IsFinished = true;
         *  _eventRotate.IsFinished = true;
         * }
         *
         * float animLen = Agent.AnimEngine[_animName].length;
         * int multi = Mathf.CeilToInt(_rotationTime / animLen);
         *
         * _rotationTime = animLen * multi + Time.timeSinceLevelLoad;*/
    }
Exemplo n.º 14
0
 public void RaiseEvent(FSMEvent evnt)
 {
     if (evnt != null)
     {
         if (EventsTransitions.ContainsKey(CurrentState.StateName + ":" + evnt.Name))
         {
             FSMState nextState = EventsTransitions[CurrentState.StateName + ":" + evnt.Name];
             ChangeState(nextState);
         }
         else
         {
             Debug.LogWarning("Event " + evnt.Name + " not mapped at " + CurrentState.StateName);
         }
     }
 }
Exemplo n.º 15
0
    public override bool OnEvent(FSMEvent ev)
    {
        if (ev is AnimFSMEventRoll)
        {
            /*if (_eventRoll != null)
             * {
             *  _eventRoll.IsFinished = true;
             * }
             * Initialize(ev);*/
            ev.IsFinished = true;
            return(true);
        }

        return(false);
    }
Exemplo n.º 16
0
 public override bool OnEvent(FSMEvent ev)
 {
     if (ev is AnimFSMEventKnockDown)
     {
         (ev as AnimFSMEventKnockDown).IsFinished = true;
         return(true);
     }
     if (ev is AnimFSMEventDeath)
     {
         _eventDeath = ev as AnimFSMEventDeath;
         InitializeDeath();
         return(true);
     }
     return(false);
 }
Exemplo n.º 17
0
    protected override void Initialize(FSMEvent ev)
    {
        _eventWhirl = ev as AnimFSMEventAttackWhirl;

        Tools.PlayAnimation(Agent.AnimEngine, _eventWhirl.data.animName, 0.2f);
        //UpdateFinalRotation();
        Agent.BlackBoard.motionType = MotionType.ATTACK;// MotionType.WALK;
        _rotationProgress           = 0;
        _timeToEndState             = Agent.AnimEngine[_eventWhirl.data.animName].length * 0.9f + Time.timeSinceLevelLoad;
        _hitTimer = Time.timeSinceLevelLoad + 0.75f;

        // Owner.PlayLoopSound(Owner.BerserkSound, 1, AnimEngine[Action.Data.AnimName].length - 1, 0.5f, 0.9f);

        _timeToStartEffect = Time.timeSinceLevelLoad + 1;
        _timeToEndEffect   = Time.timeSinceLevelLoad + Agent.AnimEngine[_eventWhirl.data.animName].length - 1;
    }
Exemplo n.º 18
0
    protected override void Initialize(FSMEvent ev = null)
    {
        _eventDeath = ev as AnimFSMEventDeath;

        string animName = Agent.AnimSet.GetDeathAnim(_eventDeath.fromWeapon, _eventDeath.damageType);

        Phenix.Unity.Utilities.Tools.PlayAnimation(Agent.AnimEngine, animName, 0.1f);

        Agent.BlackBoard.motionType = MotionType.NONE;
        _startPosition = Agent.Transform.position;

        if (_eventDeath.attacker != null)
        {
            //_finalPosition = _startPosition + _eventDeath.attacker.Forward;
            _finalPosition = _startPosition + _eventDeath.impuls;

            _startRotation = Agent.Transform.rotation;
            //_finalRotation.SetLookRotation(-_eventDeath.attacker.Forward);
            if (_eventDeath.damageType == DamageType.BACK)
            {
                _finalRotation.SetLookRotation(_eventDeath.attacker.Forward);
            }
            else if (_eventDeath.damageType == DamageType.FRONT)
            {
                _finalRotation.SetLookRotation(-_eventDeath.attacker.Forward);
            }

            _positionOK       = false;
            _rotationOk       = false;
            _rotationProgress = 0;
        }
        else
        {
            _finalPosition = _startPosition + _eventDeath.impuls;

            _positionOK = false;
            _rotationOk = true;
        }

        _curMoveTime = 0;
        _moveTime    = Agent.AnimEngine[animName].length * 0.6f;

        //Owner.Invoke("SpawnBlood", AnimEngine[animName].length);
        Agent.BlackBoard.motionType = MotionType.DEATH;
        Agent.DisableCollisions();
    }
Exemplo n.º 19
0
        //--------------------------------------------------------------------------------
        /// <summary>
        /// Check if an event equals another event
        /// </summary>
        /// <param name="obj">The other event</param>
        /// <returns>True if we are equal, false otherwise</returns>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (ReferenceEquals(this, obj))
            {
                return(true);
            }
            if (obj.GetType() != typeof(FSMEvent))
            {
                return(false);
            }
            FSMEvent other = (FSMEvent)obj;

            return(id == other.id);
        }
Exemplo n.º 20
0
        public void test_statemachine_addTransition()
        {
            FiniteStateMachine statemachine = new FiniteStateMachine();

            statemachine.addState("state_01", true);
            statemachine.addState("state_02", false);

            FSMEvent evt = statemachine.registerEvent("trigger");

            statemachine.addTransition("state_01", "state_02", evt);
            statemachine.start();

            Assert.That(statemachine.CurrentState.Name, Is.EqualTo("state_01"));

            statemachine.triggerEvent("trigger");

            Assert.That(statemachine.CurrentState.Name, Is.EqualTo("state_02"));
        }
Exemplo n.º 21
0
    protected override void Initialize(FSMEvent ev)
    {
        _eventAttack = ev as AnimFSMEventAttackBow;

        _startRotation = Agent.Transform.rotation;
        _eventAttack.attackPhaseDone = false;
        _fireTime = 0;

        float angle = 0;

        if (_eventAttack.target != null)
        {
            Vector3 dir = _eventAttack.target.Position - Agent.Transform.position;
            if (dir.sqrMagnitude > 0.1f * 0.1f)
            {
                dir.Normalize();
                angle = Vector3.Angle(Agent.Transform.forward, dir);
            }
            else
            {
                dir = Agent.Transform.forward;
            }

            _finalRotation.SetLookRotation(dir);
            _rotationTime = angle / 180.0f;
        }
        else
        {
            _finalRotation.SetLookRotation(_eventAttack.attackDir);
            _rotationTime = Vector3.Angle(Agent.Transform.forward, _eventAttack.attackDir) / 1040.0f;
        }

        _rotationOk      = (_rotationTime == 0);
        _curRotationTime = 0;

        _endOfStateTime = Time.timeSinceLevelLoad +
                          Mathf.Max(Agent.AnimEngine[_eventAttack.animAttackData.animName].length / Agent.AnimEngine[_eventAttack.animAttackData.animName].speed,
                                    _eventAttack.animAttackData.attackEndTime);

        _fireTime = Time.timeSinceLevelLoad + _eventAttack.animAttackData.hitTime;
        Agent.BlackBoard.motionType = MotionType.ATTACK;

        Tools.PlayAnimation(Agent.AnimEngine, _eventAttack.animAttackData.animName, 0.1f);
    }
Exemplo n.º 22
0
    protected override void Initialize(FSMEvent ev)
    {
        _eventRoll           = ev as AnimFSMEventRoll;
        _currentMoveTime     = 0;
        _currentRotationTime = 0;
        _startRotation       = Agent.Transform.rotation;
        _startPosition       = Agent.Transform.position;

        Vector3 finalDir;

        if (_eventRoll.toTarget != null)
        {
            finalDir = _eventRoll.toTarget.Position - Agent.Transform.position;
            finalDir.Normalize();

            _finalPosition = _eventRoll.toTarget.Position - finalDir * Agent.BlackBoard.weaponRange;
        }
        else
        {
            finalDir       = _eventRoll.direction;
            _finalPosition = _startPosition + _eventRoll.direction * Agent.BlackBoard.rollDistance;
        }

        string animName = Agent.AnimSet.GetRollAnim(Agent.BlackBoard.weaponSelected, Agent.BlackBoard.weaponState);

        AnimationTools.PlayAnim(Agent.AnimEngine, animName, 0.1f);

        _finalRotation.SetLookRotation(finalDir);
        _rotationTime   = Vector3.Angle(Agent.Transform.forward, finalDir) / 1000.0f;
        _moveTime       = Agent.AnimEngine[animName].length * 0.85f;
        _endOfStateTime = Agent.AnimEngine[animName].length * 0.9f + Time.timeSinceLevelLoad;

        _rotationOk = _rotationTime == 0;
        _positionOK = false;

        Agent.BlackBoard.motionType = MotionType.ROLL;

        if (Agent.BlackBoard.showMotionEffect)
        {
            ParticleTools.Instance.Play(Agent.particleSystemRollTust, Agent.gameObject.ForwardRadian(), 0f);
        }
    }
Exemplo n.º 23
0
        public void test_statemachine_addTransition_guard()
        {
            FiniteStateMachine statemachine = new FiniteStateMachine();

            statemachine.addState("state_01", true);
            statemachine.addState("state_02", false);

            FSMEvent evt = statemachine.registerEvent("trigger");

            Guard g = delegate(FSMEvent trigger, FSMState state) { return(false); };

            statemachine.addTransition("state_01", "state_02", evt, g, null);
            statemachine.start();

            Assert.That(statemachine.CurrentState.Name, Is.EqualTo("state_01"));

            statemachine.triggerEvent("trigger");

            Assert.That(statemachine.CurrentState.Name, Is.EqualTo("state_01"));    // We guarded the transition.
        }
Exemplo n.º 24
0
    public override bool OnEvent(FSMEvent ev)
    {
        if (ev is AnimFSMEventBreakBlock)
        {
            if ((ev as AnimFSMEventBreakBlock).success)
            {
                InitializeBlockSuccess();
            }
            else
            {
                InitializeBlockFailed();
            }
            ev.IsFinished = true;
            AnimFSMEventBreakBlock.pool.Collect(ev as AnimFSMEventBreakBlock); // 这里可以直接回收
            ev = null;
            return(true);
        }

        return(false);
    }
Exemplo n.º 25
0
    public override bool OnEvent(FSMEvent ev)
    {
        if (ev is AnimFSMEventGoTo)
        {
            //if (_eventGoTo != null)
            //{
            //    _eventGoTo.IsFinished = true;
            //}
            Initialize(ev);
            return(true);
        }

        if (ev is AnimFSMEventShowHideSword)
        {
            ev.IsFinished = true;
            PlayAnim(GetMotionType());
            return(true);
        }

        return(false);
    }
Exemplo n.º 26
0
    protected override void Initialize(FSMEvent ev = null)
    {
        _eventKnockDown = ev as AnimFSMEventKnockDown;

        string animName = Agent.AnimSet.GetKnockdowAnim(KnockdownState.Down, Agent.BlackBoard.weaponSelected);

        _startRotation = Agent.Transform.rotation;
        _startPosition = Agent.Transform.position;
        Vector3 dir   = _eventKnockDown.attacker.Position - Agent.Transform.position;
        float   angle = 0;

        if (dir.sqrMagnitude > 0.1f * 0.1f)
        {
            dir.Normalize();
            angle = Vector3.Angle(Agent.Transform.forward, dir);
        }
        else
        {
            dir = Agent.Transform.forward;
        }

        _finalRotation.SetLookRotation(dir);
        _rotationTime  = angle / 500.0f;
        _finalPosition = _startPosition + _eventKnockDown.impuls;
        _moveTime      = Agent.AnimEngine[animName].length * 0.4f;

        _rotationOk      = (_rotationTime == 0);
        _positionOK      = (_moveTime == 0);
        _curRotationTime = 0;
        _curMoveTime     = 0;

        Phenix.Unity.Utilities.Tools.PlayAnimation(Agent.AnimEngine, animName, 0.05f);

        _endOfStateTime = Time.timeSinceLevelLoad + Agent.AnimEngine[animName].length * 0.9f;
        _lyingEndTime   = _endOfStateTime + _eventKnockDown.lyingTime;

        _status = KnockdownStatus.FALL_DOWN;
    }
Exemplo n.º 27
0
    protected override void Initialize(FSMEvent ev = null)
    {
        _eventBlock = ev as AnimFSMEventBlock;

        string animName = Agent.AnimSet.GetBlockAnim(BlockState.START, Agent.BlackBoard.weaponSelected);

        _startRotation = Agent.Transform.rotation;
        _startPosition = Agent.Transform.position;

        Vector3 dir   = _eventBlock.attacker.Position - Agent.Transform.position;
        float   angle = 0;

        if (dir.sqrMagnitude > 0.1f * 0.1f)
        {
            dir.Normalize();
            angle = Vector3.Angle(Agent.Transform.forward, dir);
        }
        else
        {
            dir = Agent.Transform.forward;
        }

        _finalRotation.SetLookRotation(dir);
        _rotationTime = angle / 500.0f;
        _moveTime     = 0;

        _rotationOK = _rotationTime == 0;
        _positionOK = _moveTime == 0;

        _curRotationTime = 0;
        _curMoveTime     = 0;

        AnimationTools.PlayAnim(Agent.AnimEngine, animName, 0.05f);

        _endOfStateTime   = Time.timeSinceLevelLoad + Agent.AnimEngine[animName].length * 0.9f;
        _blockHoldEndTime = Time.timeSinceLevelLoad + _eventBlock.holdTime;
        _blockState       = BlockState.START;
    }
Exemplo n.º 28
0
    protected override void Initialize(FSMEvent ev = null)
    {
        _eventAttackMelee = ev as AnimFSMEventAttackMelee;

        _attackStatus = AttackStatus.PREPARING;
        Agent.BlackBoard.motionType = MotionType.ATTACK;
        _startRotation = Agent.Transform.rotation;
        _startPosition = Agent.Transform.position;

        if (_eventAttackMelee.target != null)
        {
            float angle    = 0;
            float distance = 0;

            Vector3 finalDir = _eventAttackMelee.target.Position - Agent.Transform.position;
            distance = finalDir.magnitude;
            if (distance > 0.1f)
            {
                finalDir.Normalize();
                angle = Vector3.Angle(Agent.Transform.forward, finalDir);
                if (angle < 40 && Vector3.Angle(Agent.Forward, _eventAttackMelee.target.Forward) < 80)
                {
                    _backHit = true;
                }
            }
            else
            {
                finalDir = Agent.Transform.forward;
            }

            _finalRotation.SetLookRotation(finalDir);

            if (distance < Agent.BlackBoard.weaponRange ||
                Agent.BlackBoard.allowedFlashToWeaponRange == false ||
                distance > Agent.BlackBoard.combatRange * 1.2f)
            {
                _finalPosition = _startPosition;
                _rotationTime  = angle / 720.0f;
            }
            else
            {
                // flash
                if (distance >= Agent.BlackBoard.weaponRange * 1.5)
                {
                    if (Agent.BlackBoard.showMotionEffect)
                    {
                        ParticleTools.Instance.Play(Agent.particleSystemFlashTust,
                                                    (_eventAttackMelee.target.Position - Agent.Position).RadianInXZ());
                    }
                }
                _finalPosition = _eventAttackMelee.target.transform.position - finalDir * Agent.BlackBoard.weaponRange;
                Agent.Transform.LookAt(_eventAttackMelee.target.transform);
                _rotationTime = 0;
            }

            _moveTime = (_finalPosition - _startPosition).magnitude / 20.0f;
        }
        else
        {
            _finalRotation.SetLookRotation(_eventAttackMelee.attackDir);
            _rotationTime = Vector3.Angle(Agent.Transform.forward, _eventAttackMelee.attackDir) / 720.0f;
            _moveTime     = 0;
        }

        _rotationOk          = (_rotationTime == 0);
        _positionOK          = (_moveTime == 0);
        _currentRotationTime = 0;
        _currentMoveTime     = 0;

        _isCritical = IsCritical();
        _knockdown  = IsKnockDown();

        _hitTimeStart = false;
    }
Exemplo n.º 29
0
 public void post(FSMEvent evt)
 {
     this.fsm_.post(evt);
 }
Exemplo n.º 30
0
 public virtual string postEvent(FSMEvent evt)
 {
     return("");
 }