Ejemplo n.º 1
0
    protected override AgentAction MakeAgentAction()
    {
        AgentActionAttackMelee agentAction = AgentActionFactory.Get(AgentActionType.ATTACK_MELEE, Owner) as AgentActionAttackMelee;

        if (Owner.BlackBoard.IsBlocking)
        {
            agentAction.attackType = AttackType.Counter;  // 反击
        }
        else
        {
            agentAction.attackType = AttackType.X;
        }
        agentAction.hit             = false;
        agentAction.attackPhaseDone = false;
        return(agentAction);
    }
    protected override AgentAction MakeAgentAction()
    {
        AgentActionAttackMelee agentAction = AgentActionFactory.Get(AgentActionType.ATTACK_MELEE, Owner) as AgentActionAttackMelee;

        agentAction.attackType = CurrentAttacktype;

/*
 *      if (Owner.BlackBoard.desiredTarget)
 *      {
 *          Owner.BlackBoard.desiredDirection = Owner.BlackBoard.desiredTarget.Position - Owner.Position;
 *          Owner.BlackBoard.desiredDirection.Normalize();
 *          agentAction.attackDir = Owner.BlackBoard.desiredDirection;
 *      }
 *      else
 *          agentAction.attackDir = Owner.Forward;*/

        agentAction.hit             = false;
        agentAction.attackPhaseDone = false;
        --NumberOfAttacks;

        return(agentAction);
    }
Ejemplo n.º 3
0
    public AgentAction GetInputAction()
    {
        Vector3 moveDir = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); // phenix 添加

        if (moveDir != Vector3.zero)
        {
            AgentActionMove moveAction = AgentActionFactory.Get(AgentActionType.MOVE, _owner) as AgentActionMove;
            moveAction.moveDir = moveDir;
            AddOrder(moveAction);
        }
        if (Input.GetKeyUp(KeyCode.Space))
        {
            AgentActionRoll rollAction = AgentActionFactory.Get(AgentActionType.ROLL, _owner) as AgentActionRoll;
            rollAction.direction = transform.forward;
            rollAction.toTarget  = null;
            AddOrder(rollAction);
        }
        if (Input.GetKeyUp(KeyCode.J))
        {
            AgentActionAttackMelee attackMeleeAction = AgentActionFactory.Get(AgentActionType.ATTACK_MELEE, _owner) as AgentActionAttackMelee;
            attackMeleeAction.attackType = OrderAttackType.X;
            AddOrder(attackMeleeAction);
        }
        if (Input.GetKeyUp(KeyCode.K))
        {
            AgentActionAttackMelee attackMeleeAction = AgentActionFactory.Get(AgentActionType.ATTACK_MELEE, _owner) as AgentActionAttackMelee;
            attackMeleeAction.attackType = OrderAttackType.O;
            AddOrder(attackMeleeAction);
        }

        if (_inputOrders.Count > 0)
        {
            return(_inputOrders.Dequeue());
        }
        return(null);
    }
Ejemplo n.º 4
0
    protected override void Initialize(AgentAction action)
    {
        //Debug.Log("attack");
        base.Initialize(action);
        _attackAction = Owner.BlackBoard.curAction as AgentActionAttackMelee;
        _attackAction.Initialize(/*Trans.GetComponent<Agent>()*/);

        _attackStatus = AttackStatus.PREPARING;
        Owner.BlackBoard.motionType = MotionType.ATTACK;

        _attackAction.attackPhaseDone = false;
        _attackAction.hit             = false;

        //if (_attackAction.data == null)
        //_attackAction.data = AnimSet.GetFirstAttackAnim(BlackBoard.weaponSelected, _attackAction.attackType);
        if (_attackAction.data == null)
        {
            Debug.LogError("AnimAttackData == null");
        }

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

        float angle = 0;

        bool backHit = false;

        float distance = 0;

        if (_attackAction.target != null)
        {
            Vector3 dir = _attackAction.target.Position - Owner.Transform.position;
            distance = dir.magnitude;

            if (distance > 0.1f)
            {
                dir.Normalize();
                angle = Vector3.Angle(Owner.Transform.forward, dir);

                if (angle < 40 && Vector3.Angle(Owner.Forward, _attackAction.target.Forward) < 80)
                {
                    backHit = true;
                }
            }
            else
            {
                dir = Owner.Transform.forward;
            }


            _finalRotation.SetLookRotation(dir);

            if (distance < Owner.BlackBoard.weaponRange)
            {
                _finalPosition = _startPosition;
            }
            else
            {
                _finalPosition = _attackAction.target.transform.position - dir * Owner.BlackBoard.weaponRange;
            }

            _moveTime     = (_finalPosition - _startPosition).magnitude / 20.0f;
            _rotationTime = angle / 720.0f;
        }
        else
        {
            _finalRotation.SetLookRotation(_attackAction.attackDir);

            _rotationTime = Vector3.Angle(Owner.Transform.forward, _attackAction.attackDir) / 720.0f;
            _moveTime     = 0;
        }

        _rotationOk = _rotationTime == 0;
        _positionOK = _moveTime == 0;

        _currentRotationTime = 0;
        _currentMoveTime     = 0;

        if (Owner.isPlayer && _attackAction.data.hitCriticalType != CriticalHitType.None && _attackAction.target &&
            _attackAction.target.GetComponent <BlackBoard>().criticalAllowed&& _attackAction.target.GetComponent <BlackBoard>().IsBlocking == false &&
            _attackAction.target.GetComponent <BlackBoard>().invulnerable == false)
        {
            if (backHit)
            {
                _isCritical = true;
            }
            else
            {
                // Debug.Log("critical chance" + Owner.GetCriticalChance() * AnimAttackData.CriticalModificator * Action.Target.BlackBoard.CriticalHitModifier);
                _isCritical = Random.Range(0, 100) < Owner.BlackBoard.criticalChance * _attackAction.data.criticalModificator * _attackAction.target.GetComponent <BlackBoard>().criticalHitModifier;
            }
        }
        else
        {
            _isCritical = false;
        }

        _knockdown = _attackAction.data.hitAreaKnockdown && Random.Range(0, 100) < 60 * Owner.BlackBoard.criticalChance;

        if (Owner.isPlayer == false)
        {
            Owner.BlackBoard.Vigor -= Owner.BlackBoard.vigorAttackCost;
            Owner.BlackBoard.Rage   = 0;
            Owner.BlackBoard.Fear  += Owner.BlackBoard.fearAttackModificator;
        }
    }