Beispiel #1
0
    public override void OnUpdate()
    {
        _rotationProgress += Time.deltaTime * Agent.BlackBoard.rotationSmooth;
        _rotationProgress  = Mathf.Min(_rotationProgress, 1);
        Quaternion q = Quaternion.Slerp(_startRotation, _finalRotation, _rotationProgress);

        Agent.Transform.rotation = q;

        if (Quaternion.Angle(q, _finalRotation) > 40.0f)
        {
            return;
        }

        float maxSpeed = Mathf.Max(Agent.BlackBoard.maxWalkSpeed, Agent.BlackBoard.maxRunSpeed *
                                   Agent.BlackBoard.moveSpeedModifier);
        float curSmooth = Agent.BlackBoard.speedSmooth * Time.deltaTime;

        Agent.BlackBoard.speed   = Mathf.Lerp(Agent.BlackBoard.speed, maxSpeed, curSmooth);
        Agent.BlackBoard.moveDir = Agent.BlackBoard.desiredDirection;

        // MOVE
        if (TransformTools.MoveOnGround(Agent.Transform, Agent.CharacterController,
                                        Agent.BlackBoard.moveDir * Agent.BlackBoard.speed * Time.deltaTime, true) == false)
        {
            IsFinished            = true;
            _eventMove.IsFinished = true;
        }

        MotionType motion = GetMoveMotionType();

        if (motion != Agent.BlackBoard.motionType)
        {
            PlayAnim(motion);
        }
    }
Beispiel #2
0
    public override void OnUpdate()
    {
        switch (_state)
        {
        case AttackRollState.PREPARE:
        {
            UpdateFinalRotation();
            if (_rotationOk == false)
            {
                _curRotationTime += Time.deltaTime;
                if (_curRotationTime >= _rotationTime)
                {
                    _curRotationTime = _rotationTime;
                    _rotationOk      = true;
                }

                float      progress = _curRotationTime / _rotationTime;
                Quaternion q        = Quaternion.Lerp(_startRotation, _finalRotation, progress);
                Agent.Transform.rotation = q;
            }

            if (_endOfStateTime < Time.timeSinceLevelLoad)
            {
                InitializeRoll();
            }
        }
        break;

        case AttackRollState.ROLL:
        {
            if (TransformTools.MoveOnGround(Agent.Transform, Agent.CharacterController,
                                            Agent.Transform.forward * Agent.BlackBoard.attackRollSpeed * Time.deltaTime, false) == false)
            {
                HandleAttackResult.DoRollDamage(Agent, _eventAttackRoll.animAttackData, Agent.BlackBoard.attackRollWeaponRange);
                InitializeStandUp();
            }
            else if (_hitTimer < Time.timeSinceLevelLoad)
            {
                HandleAttackResult.DoRollDamage(Agent, _eventAttackRoll.animAttackData, Agent.BlackBoard.attackRollWeaponRange);
                _hitTimer = Time.timeSinceLevelLoad + Agent.BlackBoard.attackRollHitTime;        //0.2f;
            }
        }
        break;

        case AttackRollState.STAND_UP:
        {
            if (_endOfStateTime < Time.timeSinceLevelLoad)
            {
                IsFinished = true;
                _eventAttackRoll.IsFinished = true;
            }
        }
        break;
        }
    }
Beispiel #3
0
    public override void OnUpdate()
    {
        float   dist = (_eventGoTo.finalPosition - Agent.Transform.position).sqrMagnitude;
        Vector3 dir;

        if (_eventGoTo.motionType == MotionType.SPRINT)
        {
            if (dist < 0.5f * 0.5f)
            {
                _maxSpeed = Agent.BlackBoard.maxWalkSpeed;
            }
        }
        else
        {
            if (dist < 1.5f * 1.5f)
            {
                _maxSpeed = Agent.BlackBoard.maxWalkSpeed;
            }
        }

        _rotationProgress += Time.deltaTime * Agent.BlackBoard.rotationSmooth;
        _rotationProgress  = Mathf.Min(_rotationProgress, 1);
        Quaternion q = Quaternion.Slerp(_startRotation, _finalRotation, _rotationProgress);

        Agent.Transform.rotation = q;

        float curSmooth = Agent.BlackBoard.speedSmooth * Time.deltaTime;

        Agent.BlackBoard.speed = Mathf.Lerp(Agent.BlackBoard.speed, _maxSpeed, curSmooth);

        dir   = _eventGoTo.finalPosition - Agent.Transform.position;
        dir.y = 0;
        dir.Normalize();
        Agent.BlackBoard.moveDir = dir;

        // MOVE
        if (TransformTools.MoveOnGround(Agent.transform, Agent.CharacterController,
                                        Agent.BlackBoard.moveDir * Agent.BlackBoard.speed * Time.deltaTime, true) == false)
        {
            IsFinished = true;
        }
        else if ((_eventGoTo.finalPosition - Agent.Transform.position).sqrMagnitude < 0.3f * 0.3f)
        {
            IsFinished            = true;
            _eventGoTo.IsFinished = true;
        }
        else
        {
            MotionType motion = GetMotionType();
            if (motion != Agent.BlackBoard.motionType)
            {
                PlayAnim(motion);
            }
        }
    }
Beispiel #4
0
    public Transform FindNearEnemy(Vector3 position, float maxDistance)
    {
        var       minDistanceSqr = maxDistance * maxDistance;
        Transform result         = null;

        foreach (var team in enemyTeams)
        {
            TransformTools.FindNearChildToPos(team.transform, position, ref minDistanceSqr, ref result);
        }

        return(result);
    }
Beispiel #5
0
    public static void DoRollDamage(Agent1 agent, AnimAttackData data, float range)
    {
        if (agent == null || data == null)
        {
            return;
        }
        if (agent.BlackBoard.motionType != MotionType.ROLL)
        {
            return;
        }

        Vector3 attackerDir = agent.Forward;
        Vector3 dirToTarget = Vector3.zero;

        for (int i = 0; i < Game1.Instance.AgentMgr.agents.Count; i++)
        {
            Agent1 target = Game1.Instance.AgentMgr.agents[i];
            if (target == null || target == agent ||
                target.BlackBoard.IsAlive == false || target.BlackBoard.IsKnockedDown)
            {
                continue;
            }

            if (target.BlackBoard.invulnerable ||
                (target.BlackBoard.damageOnlyFromBack && TransformTools.IsBehindTarget(agent.Transform, target.Transform) == false))
            {
                // 攻击无效
                ReceiveHitCompletelyBlocked(target, agent);
                HandleSound.PlaySoundBlocked();
                continue;
            }

            dirToTarget = target.Position - agent.Position;

            if (dirToTarget.sqrMagnitude < range * range)
            {
                //if (data.useImpuls)
                //{
                //    ReceiveImpuls(target, agent, dirToTarget.normalized * data.hitMomentum);
                //}
                ReceiveDamage(target, agent, WeaponType.BODY, data.hitDamage, data.hitMomentum);
                HandleSound.PlaySoundHit();
            }
        }
    }
Beispiel #6
0
    public override void OnUpdate()
    {
        if (_rotationOk == false)
        {
            _currentRotationTime += Time.deltaTime;

            if (_currentRotationTime >= _rotationTime)
            {
                _currentRotationTime = _rotationTime;
                _rotationOk          = true;
            }

            float      progress = _currentRotationTime / _rotationTime;
            Quaternion q        = Quaternion.Lerp(_startRotation, _finalRotation, progress);
            Agent.Transform.rotation = q;
        }

        if (_positionOK == false)// && (RotationOk || (Quaternion.Angle(Owner.Transform.rotation, FinalRotation) > 40.0f))
        {
            _currentMoveTime += Time.deltaTime;
            if (_currentMoveTime >= _moveTime)
            {
                _currentMoveTime = _moveTime;
                _positionOK      = true;
            }

            float   progress = _currentMoveTime / _moveTime;
            Vector3 finalPos = Mathfx.Hermite(_startPosition, _finalPosition, progress);
            //MoveTo(finalPos);
            if (TransformTools.MoveOnGround(Agent.Transform, Agent.CharacterController,
                                            finalPos - Agent.Transform.position, false) == false)
            {
                _positionOK = true;
                ParticleTools.Instance.Stop(Agent.particleSystemRollTust);
            }
        }

        if (_endOfStateTime <= Time.timeSinceLevelLoad)
        {
            IsFinished            = true;
            _eventRoll.IsFinished = true;
        }
    }
Beispiel #7
0
    public override void OnUpdate()
    {
        UpdateFinalRotation();

        _rotationProgress += Time.deltaTime * Agent.BlackBoard.rotationSmoothInMove;
        _rotationProgress  = Mathf.Min(_rotationProgress, 1);
        Quaternion q = Quaternion.Slerp(_startRotation, _finalRotation, _rotationProgress);

        Agent.Transform.rotation = q;

        if (Quaternion.Angle(q, _finalRotation) > 40.0f)
        {
            return;
        }

        float curSmooth = Agent.BlackBoard.speedSmooth * Time.deltaTime;

        Agent.BlackBoard.speed = Mathf.Lerp(Agent.BlackBoard.speed, _maxSpeed, curSmooth);

        float dist = Agent.BlackBoard.speed * Time.deltaTime;

        if (TransformTools.MoveOnGround(Agent.transform, Agent.CharacterController, Agent.BlackBoard.moveDir * dist, true))
        {
            _movedDistance += dist;
            if (_movedDistance > _eventCombatMove.totalMoveDistance)
            {
                IsFinished = true;
                _eventCombatMove.IsFinished = true;
            }
        }
        else if (_eventCombatMove.minDistanceToTarget > Agent.BlackBoard.DistanceToDesiredTarget)
        {
            IsFinished = true;
            _eventCombatMove.IsFinished = true;
        }
        else
        {
            IsFinished = true;
        }
    }
    public override void OnUpdate()
    {
        UpdateFinalRotation();

        _rotationProgress       += Time.deltaTime * Agent.BlackBoard.rotationSmoothInMove;
        _rotationProgress        = Mathf.Min(_rotationProgress, 1);
        Agent.Transform.rotation = Quaternion.Slerp(_startRotation, _finalRotation, _rotationProgress);
        if (Agent.AnimEngine[_eventWhirl.data.animName].time >
            Agent.AnimEngine[_eventWhirl.data.animName].length * 0.1f /*为了防止动画开始时候的滑步*/)
        {
            float preSpeed  = Agent.BlackBoard.speed;
            float curSmooth = Agent.BlackBoard.speedSmooth * Time.deltaTime;
            Agent.BlackBoard.speed = Mathfx.Hermite(Agent.BlackBoard.speed,
                                                    Agent.BlackBoard.maxWhirlMoveSpeed, curSmooth);
            Agent.BlackBoard.moveDir = Agent.Forward;

            float dist    = Agent.BlackBoard.speed * Time.deltaTime;
            bool  _moveOk = TransformTools.MoveOnGround(Agent.transform, Agent.CharacterController,
                                                        Agent.BlackBoard.moveDir * dist, true);
            if (_moveOk == false)
            {
                Agent.BlackBoard.speed = preSpeed;
            }
        }

        if (_hitTimer < Time.timeSinceLevelLoad) // 伤害结算计时
        {
            HandleAttackResult.DoMeleeDamage(Agent, _eventWhirl.target /*Agent.BlackBoard.desiredTarget*/, Agent.BlackBoard.weaponSelected,
                                             _eventWhirl.data, false, false, false);
            _hitTimer = Time.timeSinceLevelLoad + Agent.BlackBoard.attackWhirlHitTime;//0.75f;
        }

        if (_timeToEndState < Time.timeSinceLevelLoad)
        {
            IsFinished             = true;
            _eventWhirl.IsFinished = true;
        }
    }
Beispiel #9
0
    public override void OnUpdate()
    {
        _rotationProgress += (Time.deltaTime * Agent.BlackBoard.rotationSmooth);
        if (_rotationProgress >= 1)
        {
            _rotationProgress       = 1;
            IsFinished              = true;
            _eventRotate.IsFinished = true;
        }

        Agent.Transform.rotation = Quaternion.Lerp(_startRotation, _finalRotation, _rotationProgress);
        Agent.BlackBoard.moveDir = Agent.Forward;

        float curSmooth = Agent.BlackBoard.speedSmooth * Time.deltaTime;

        Agent.BlackBoard.speed = Mathf.Lerp(Agent.BlackBoard.speed, Agent.BlackBoard.maxWalkSpeed, curSmooth);
        TransformTools.MoveOnGround(Agent.transform, Agent.CharacterController,
                                    Agent.BlackBoard.moveDir * Agent.BlackBoard.speed * Time.deltaTime, true);

        /*_currentRotationTime += Time.deltaTime;
         * if (_currentRotationTime >= _rotationTime)
         * {
         *  _currentRotationTime = _rotationTime;
         *  IsFinished = true;
         *  _eventRotate.IsFinished = true;
         *  return;
         * }
         *
         * float progress = _currentRotationTime / _rotationTime;
         * Agent.Transform.rotation = Quaternion.Lerp(_startRotation, _finalRotation, progress);
         * Agent.BlackBoard.moveDir = Agent.Forward;
         *
         * float curSmooth = Agent.BlackBoard.speedSmooth * Time.deltaTime;
         * Agent.BlackBoard.speed = Mathf.Lerp(Agent.BlackBoard.speed, Agent.BlackBoard.maxWalkSpeed, curSmooth);
         * TransformTools.MoveOnGround(Agent.transform, Agent.CharacterController,
         *  Agent.BlackBoard.moveDir * Agent.BlackBoard.speed * Time.deltaTime, true);*/
    }
Beispiel #10
0
    public override void OnUpdate()
    {
        if (_attackStatus == AttackStatus.PREPARING)
        {
            bool dontMove = false;
            if (_rotationOk == false)
            {
                _currentRotationTime += Time.deltaTime;
                if (_currentRotationTime >= _rotationTime)
                {
                    _currentRotationTime = _rotationTime;
                    _rotationOk          = true;
                }
                float      progress = _currentRotationTime / _rotationTime;
                Quaternion rotation = Quaternion.Lerp(_startRotation, _finalRotation, progress);
                Agent.Transform.rotation = rotation;
            }

            if (_positionOK == false)
            {
                _currentMoveTime += Time.deltaTime;
                if (_currentMoveTime >= _moveTime)
                {
                    _currentMoveTime = _moveTime;
                    _positionOK      = true;
                }

                if (_currentMoveTime > 0)
                {
                    float   progress = _currentMoveTime / _moveTime;
                    Vector3 finalPos = Mathfx.Hermite(_startPosition, _finalPosition, progress);
                    //if (MoveToCollideWithEnemy(finalPos, Transform.forward) == false)
                    if (TransformTools.MoveOnGround(Agent.transform, Agent.CharacterController,
                                                    finalPos - Agent.Transform.position, true) == false)
                    {
                        _positionOK = true;
                    }
                }
            }

            if (_rotationOk && _positionOK)
            {
                _attackStatus = AttackStatus.ATTACKING;
                InitializeAttacking();
            }
        }
        else if (_attackStatus == AttackStatus.ATTACKING)
        {
            _currentMoveTime += Time.deltaTime;
            if (_currentMoveTime >= _moveTime)
            {
                _currentMoveTime = _moveTime;
            }

            if (_currentMoveTime > 0 && _currentMoveTime <= _moveTime)
            {
                float   progress = Mathf.Min(1.0f, _currentMoveTime / _moveTime);
                Vector3 finalPos = Mathfx.Hermite(_startPosition, _finalPosition, progress);
                //if (MoveToCollideWithEnemy(finalPos, Transform.forward) == false)
                if (TransformTools.MoveOnGround(Agent.transform, Agent.CharacterController,
                                                finalPos - Agent.Transform.position, false) == false)
                {
                    _currentMoveTime = _moveTime;
                }
            }

            if (_hitTimeStart == false && _hitTime <= Time.timeSinceLevelLoad)
            {
                _hitTimeStart = true;
                HandleAttackResult.DoMeleeDamage(Agent, _eventAttackCross.target, Agent.BlackBoard.attackerWeapon,
                                                 _eventAttackCross.animAttackData, _isCritical, _knockdown,
                                                 _eventAttackCross.animAttackData.isFatal);
            }

            if (_attackPhaseTime < Time.timeSinceLevelLoad)
            {
                if (--_remainAttackCount > 0)
                {
                    // 再次攻击
                    InitializeAttacking(false);
                }
                else
                {
                    _attackStatus = AttackStatus.FINISHED;
                }
            }
        }
        else if (_attackStatus == AttackStatus.FINISHED && _endOfStateTime <= Time.timeSinceLevelLoad)
        {
            //Debug.Log(Time.timeSinceLevelLoad + " attack finished");
            IsFinished = true;
            _eventAttackCross.IsFinished = true;
        }
    }
Beispiel #11
0
    public override void OnUpdate()
    {
        UpdateFinalRotation();

        if (_rotationOK == false)
        {
            _curRotationTime += Time.deltaTime;
            if (_curRotationTime >= _rotationTime)
            {
                _curRotationTime = _rotationTime;
                _rotationOK      = true;
            }

            float      progress = _curRotationTime / _rotationTime;
            Quaternion q        = Quaternion.Lerp(_startRotation, _finalRotation, progress);
            Agent.Transform.rotation = q;
        }

        if (_positionOK == false)
        {
            _curMoveTime += Time.deltaTime;
            if (_curMoveTime >= _moveTime)
            {
                _curMoveTime = _moveTime;
                _positionOK  = true;
            }

            float   progress = _curMoveTime / _moveTime;
            Vector3 finalPos = Mathfx.Sinerp(_startPosition, _finalPosition, progress);
            if (TransformTools.MoveOnGround(Agent.Transform, Agent.CharacterController,
                                            finalPos - Agent.Transform.position, true) == false)
            {
                _positionOK = true;
            }
        }

        switch (_blockState)
        {
        case BlockState.START:
            if (_endOfStateTime <= Time.timeSinceLevelLoad)
            {
                InitializeHold();
            }
            break;

        case BlockState.HOLD:
            if (_endOfStateTime <= Time.timeSinceLevelLoad)
            {
                InitializeEnd();
            }

            /*else if (Agent.BlackBoard.blockResult == BlockResult.FAIL)
             * {
             *  InitializeBlockFailed();
             *  Agent.BlackBoard.blockResult = BlockResult.NONE;
             * }
             * else if (Agent.BlackBoard.blockResult == BlockResult.SUCCESS)
             * {
             *  InitializeBlockSuccess();
             *  Agent.BlackBoard.blockResult = BlockResult.NONE;
             * }*/
            break;

        case BlockState.BLOCK_SUCCESS:
            if (_endOfStateTime <= Time.timeSinceLevelLoad)
            {
                if (Time.timeSinceLevelLoad < _blockHoldEndTime)
                {
                    InitializeHold();
                }
                else
                {
                    InitializeEnd();
                }
            }
            break;

        case BlockState.END:
            if (_endOfStateTime <= Time.timeSinceLevelLoad)
            {
                IsFinished             = true;
                _eventBlock.IsFinished = true;
            }
            break;

        case BlockState.BLOCK_FAIL:
            if (_endOfStateTime <= Time.timeSinceLevelLoad)
            {
                IsFinished             = true;
                _eventBlock.IsFinished = true;
            }
            break;
        }
    }
Beispiel #12
0
    public override void OnUpdate()
    {
        if (_attackStatus == AttackStatus.PREPARING)
        {
            bool dontMove = false;
            if (_rotationOk == false)
            {
                _currentRotationTime += Time.deltaTime;
                if (_currentRotationTime >= _rotationTime)
                {
                    _currentRotationTime = _rotationTime;
                    _rotationOk          = true;
                }
                float      progress = _currentRotationTime / _rotationTime;
                Quaternion rotation = Quaternion.Lerp(_startRotation, _finalRotation, progress);
                Agent.Transform.rotation = rotation;
            }

            if (_positionOK == false)
            {
                _currentMoveTime += Time.deltaTime;
                if (_currentMoveTime >= _moveTime)
                {
                    _currentMoveTime = _moveTime;
                    _positionOK      = true;
                    ParticleTools.Instance.Stop(Agent.particleSystemFlashTust);
                }

                if (_currentMoveTime > 0)
                {
                    float   progress = _currentMoveTime / _moveTime;
                    Vector3 finalPos = Mathfx.Hermite(_startPosition, _finalPosition, progress);
                    //if (MoveToCollideWithEnemy(finalPos, Transform.forward) == false)
                    if (TransformTools.MoveOnGround(Agent.transform, Agent.CharacterController,
                                                    finalPos - Agent.Transform.position, true) == false)
                    {
                        _positionOK = true;
                        ParticleTools.Instance.Stop(Agent.particleSystemFlashTust);
                    }
                }
            }

            if (_rotationOk && _positionOK)
            {
                _attackStatus = AttackStatus.ATTACKING;
                InitializeAttacking();
            }
        }
        else if (_attackStatus == AttackStatus.ATTACKING)
        {
            _currentMoveTime += Time.deltaTime;
            if (_attackPhaseTime < Time.timeSinceLevelLoad)
            {
                //Debug.Log(Time.timeSinceLevelLoad + " attack phase done");
                _eventAttackMelee.attackPhaseDone = true;
                _attackStatus = AttackStatus.FINISHED;
            }

            if (_currentMoveTime >= _moveTime)
            {
                _currentMoveTime = _moveTime;
            }

            if (_currentMoveTime > 0 && _currentMoveTime <= _moveTime)
            {
                float   progress = Mathf.Min(1.0f, _currentMoveTime / _moveTime);
                Vector3 finalPos = Mathfx.Hermite(_startPosition, _finalPosition, progress);
                //if (MoveToCollideWithEnemy(finalPos, Transform.forward) == false)
                if (TransformTools.MoveOnGround(Agent.transform, Agent.CharacterController,
                                                finalPos - Agent.Transform.position, false) == false)
                {
                    _currentMoveTime = _moveTime;
                }
            }

            if (_hitTimeStart == false && _hitTime <= Time.timeSinceLevelLoad)
            {
                _hitTimeStart = true;
                HandleAttackResult.DoMeleeDamage(Agent, _eventAttackMelee.target, Agent.BlackBoard.attackerWeapon,
                                                 _eventAttackMelee.animAttackData, _isCritical, _knockdown,
                                                 _eventAttackMelee.animAttackData.isFatal);

                // 显示刀光(方案1:美术做好mesh,参见player)
                if (_eventAttackMelee.animAttackData.lastAttackInCombo)
                {
                    HandleTrail.ShowTrail(Agent, _eventAttackMelee.animAttackData, 0.4f);
                }
                else
                {
                    HandleTrail.ShowTrail(Agent, _eventAttackMelee.animAttackData, 0.5f);
                }

                /*// 屏幕震动
                 * if (AnimAttackData.LastAttackInCombo || AnimAttackData.ComboStep == 3)
                 *  CameraBehaviour.Instance.ComboShake(AnimAttackData.ComboStep - 3);
                 *
                 * if (Owner.IsPlayer && AnimAttackData.FullCombo)
                 *  GuiManager.Instance.ShowComboMessage(AnimAttackData.ComboIndex);*/
            }
        }
        else if (_attackStatus == AttackStatus.FINISHED && _endOfStateTime <= Time.timeSinceLevelLoad)
        {
            IsFinished = true;
            _eventAttackMelee.IsFinished = true;
        }
    }