Exemplo n.º 1
0
    public virtual void Roam()
    {
        if (agent.destination == null || agent.remainingDistance < 0.1f)
        {
            agent.SetDestination(GetNavMeshLocation(3f));
        }

        foreach (Client client in ServerLogic.clients.Values)
        {
            Player player = client.player;
            if (player == null)
            {
                continue;
            }
            float distance = Vector3.Distance(transform.position, player.transform.position);
            if (distance < chaseDistance)
            {
                if (targetPlayer == null || distance < Vector3.Distance(targetPlayer.transform.position, transform.position))
                {
                    targetPlayer = player;
                }
            }
        }

        if (targetPlayer != null)
        {
            monsterStates = MonsterStates.Chase;
        }
    }
Exemplo n.º 2
0
 public void Aggro()
 {
     if (state == MonsterStates.Idle)
     {
         state = MonsterStates.Aggro;
         this.OnAggro();
     }
 }
Exemplo n.º 3
0
 public virtual void Return()
 {
     agent.SetDestination(spawnPosition);
     if (agent.remainingDistance < 1f)
     {
         monsterStates = MonsterStates.Roam;
     }
 }
Exemplo n.º 4
0
 void OnTriggerStay(Collider collider)
 {
     // if player stays in spiders attack range, the spider is locked in attack state
     if (collider.tag == "Player")
     {
         m_isPlayerInAttackRange = true;
         //Debug.Log("player stays trigger");
         m_state = MonsterStates.ATTACK;
     }
 }
Exemplo n.º 5
0
    //상태 설정
    public void setState(MonsterStates newState)
    {
        if (_init)
        {
            _states[currentState].enabled = false;
            _states[currentState].EndState();
        }

        currentState     = newState;
        IsTargetPosReach = true;
        _states[currentState].enabled = true;
        _states[currentState].BeginState();
    }
Exemplo n.º 6
0
    // Use this for initialization

    void Start()
    {
        if (Application.isPlaying)
        {
            CoroutineManager.DoCoroutine(_actionChangeCoroutine);         //행동체인지 코루틴 시작
            CoroutineManager.DoCoroutine(_moveCoroutine);                 //이동 코루틴 시작
            startState  = MonsterStates.Stand;                            //처음 상태
            startAction = this.GetRandomMonsterAction <MonsterActions>(); //랜덤행동 가져오기
            setState(startState);                                         //상태 초기화
            setAction(startAction);                                       //행동 초기화
            _init = true;
        }
    }
Exemplo n.º 7
0
    public void SetState(MonsterStates newState)
    {
        if (_isinit)
        {
            _state[_currentState].enabled = false;
            _state[_currentState].EndState();
        }
        _currentState = newState;
        _state[_currentState].BeginState();


        _state[_currentState].enabled = true; // 지정한 친구만 로그를 보여준다.
        _anim.SetInteger("MonsterState", (int)_currentState);
    }
Exemplo n.º 8
0
    // Use this for initialization
    void Start()
    {
        m_rigidbody       = this.GetComponent <Rigidbody>();
        m_alertCollider   = alertRange.GetComponent <BoxCollider>();
        m_playerTransform = CharactersConfigManager.GetPlayerGameObject().transform;
        m_animator        = GetComponent <Animator>();

        m_state           = MonsterStates.IDLE;
        m_isInCombatRange = true;

        m_isAttackLocked = false;

        this.transform.position = startPosition.transform.position;
        m_targetPosition        = endPosition.transform.position;
        m_rigidbody.velocity    = new Vector3(speed, 0, 0);

        repellT = 0;
    }
Exemplo n.º 9
0
    void OnTriggerEnter(Collider collider)
    {
        // when player touches the spider, it must immediately cast damage, even if its damage skill is in CD
        if (collider.tag == "Player")
        {
            m_isPlayerInAttackRange = true;
            //Debug.Log("player enter trigger");
            m_state = MonsterStates.ATTACK;
        }

        if (collider.tag == "Sword")
        {
            GetAttack(PlayerStatus.Attack, m_playerTransform.gameObject);
        }

        if (collider.tag == "Fu")
        {
            GetAttack(10, m_playerTransform.gameObject);
        }
    }
Exemplo n.º 10
0
    private void ChangeState(MonsterStates nextState)
    {
        switch (nextState)
        {
        case MonsterStates.Patrol:
            PlayClip(step, true);
            PlayerDetected = false;
            break;

        case MonsterStates.Chase:
            PlayClip(step, true);
            break;

        case MonsterStates.Wait:
            break;

        case MonsterStates.FinalSprint:
            PlayClip(stepFinal, true);
            break;
        }

        if (actualState == nextState)
        {
            return;
        }

        if (actualState == MonsterStates.Wait)
        {
            waitTimer = 0;
        }
        if (actualState == MonsterStates.FinalSprint)
        {
            transform.position = ChasePoint.position;
            navMeshAgent.speed = finalSpeed;
            PlayClip(spawnFinal, false);
        }

        actualState = nextState;
    }
Exemplo n.º 11
0
 public virtual void Chase()
 {
     Debug.Log("Chase");
     if (Vector3.Distance(transform.position, targetPlayer.transform.position) > chaseDistance)
     {
         targetPlayer  = null;
         monsterStates = MonsterStates.Return;
     }
     else
     {
         agent.SetDestination(targetPlayer.transform.position);
         if (agent.remainingDistance < attackDistance)
         {
             monsterStates = MonsterStates.Attack;
             return;
         }
         if (Vector3.Distance(spawnPosition, transform.position) > chaseDistance)
         {
             targetPlayer  = null;
             monsterStates = MonsterStates.Return;
             return;
         }
     }
 }
Exemplo n.º 12
0
 //------------------------------
 // Use this for initialization
 //------------------------------
 void Start()
 {
     _currentState = MonsterStates.IDLE;
 }
Exemplo n.º 13
0
    // Update is called once per frame
    void Update()
    {
        if (hp <= 0)
        {
            m_state = MonsterStates.DEAD;
            m_animator.SetBool(k_isDead, true);
        }

        if (m_state == MonsterStates.HURT)
        {
            m_animator.SetBool(k_isHurt, true);
            AnimatorStateInfo animatorInfo;
            animatorInfo = m_animator.GetCurrentAnimatorStateInfo(0);

            //if ((animatorInfo.normalizedTime < 1.0f) && (animatorInfo.IsName("Hurt"))) //  animation playing
            //{

            if (m_currentAttacker)
            {
                Vector3 dir = (this.transform.position - m_currentAttacker.transform.position).normalized;
                //m_rigidbody.AddForce(dir * repellFacter);

                m_rigidbody.velocity = Vector3.Lerp(dir * speed * 20f, new Vector3(0, 0, 0), repellT);
                repellT += Time.deltaTime / 0.1f;
            }

            //}
            if (repellT > 1f) //  animation ends
            {
                repellT           = 0.0f;
                m_currentAttacker = null;
                m_animator.SetBool(k_isHurt, false);
                m_state = MonsterStates.IDLE;
            }
        }
        else
        {
            GoTowardTarget();

            if (m_state == MonsterStates.DEAD)
            {
                m_targetPosition     = this.transform.position; // stay still
                m_rigidbody.velocity = new Vector3(0, 0, 0);

                m_animator.SetBool(k_isAttack, false);

                // after death animation
                AnimatorStateInfo animatorInfo;
                animatorInfo = m_animator.GetCurrentAnimatorStateInfo(0);

                if ((animatorInfo.normalizedTime > 1.0f) && (animatorInfo.IsName("Death"))) // attack animation ends
                {
                    if (objectRoot.activeInHierarchy)
                    {
                        objectRoot.SetActive(false);
                        GameObject g = Instantiate(Resources.Load("Prefabs/Effects/Particles/SpiderDeathParticle"), this.transform.position + new Vector3(0, 1, 0), Quaternion.identity) as GameObject;
                        Destroy(g, 5);
                    }
                }
            }

            if (m_state == MonsterStates.IDLE)    // go around
            {
                m_animator.SetBool(k_isAttack, false);
                m_animator.SetBool(k_isHurt, false);

                AdjustFacingRotation();
                // spider only move in x direction

                if (transform.position.x >= endPosition.transform.position.x)
                {
                    m_targetPosition = startPosition.transform.position;
                }

                if (transform.position.x <= startPosition.transform.position.x)
                {
                    m_targetPosition = endPosition.transform.position;
                }
            }

            if (m_state == MonsterStates.CHASE_PLAYER)
            {
                m_animator.SetBool(k_isAttack, false);
                m_animator.SetBool(k_isDead, false);

                AdjustFacingRotation();
                m_targetPosition = m_playerTransform.position;

                if (!m_isPlayerInAttackRange) // A不到player
                {
                    if (!m_isInCombatRange)   // 出追人范围了
                    {
                        m_state = MonsterStates.IDLE;
                    }
                }
            }

            if (m_state == MonsterStates.ATTACK)
            {
                // movement control
                if (transform.position.x < m_playerTransform.position.x) // player is on the right -> face right
                {
                    this.transform.rotation = Quaternion.Euler(0, 90, 0);
                }
                else
                {
                    this.transform.rotation = Quaternion.Euler(0, -90, 0);
                }
                m_targetPosition = this.transform.position;


                //m_animator.SetBool(k_isIdle, false);
                m_animator.SetBool(k_isAttack, true);

                // cannot move before animator ends
                AnimatorStateInfo animatorInfo;
                animatorInfo = m_animator.GetCurrentAnimatorStateInfo(0);

                if ((animatorInfo.normalizedTime > 1.0f) && (animatorInfo.IsName("Attack"))) // attack animation ends
                {
                    //Debug.Log(animatorInfo.normalizedTime);
                    if (!m_isPlayerInAttackRange) // A不到player
                    {
                        if (!m_isInCombatRange)   // 出追人范围了
                        {
                            m_state = MonsterStates.IDLE;
                        }
                        else  // otherwise try to chase player
                        {
                            m_state = MonsterStates.CHASE_PLAYER;
                        }
                    }
                    else
                    {
                        // animator stays in attack state
                        if (!m_isAttackLocked)
                        {
                            // do attack
                            m_playerTransform.GetComponent <PlayerTestController>().GetDamage(attack);
                            // lock
                            m_isAttackLocked = true;
                            CDTime           = 0;
                        }
                    }
                }


                if (m_isAttackLocked)
                {
                    CDTime += Time.deltaTime;
                    if (CDTime >= 0.5f) // after 0.5s release attack lock
                    {
                        m_isAttackLocked = false;
                    }
                }
            }
        }
    }
Exemplo n.º 14
0
 public void GetAttack(double damage, GameObject attacker)
 {
     hp               -= damage;
     m_state           = MonsterStates.HURT;
     m_currentAttacker = attacker;
 }
Exemplo n.º 15
0
 public void SetStatus(MonsterStates state)
 {
     m_state = state;
 }