Beispiel #1
0
    IEnumerator IDoDamage(MORPG_CharacterStats stats, float attackDelay)
    {
        yield return(new WaitForSeconds(attackDelay));

        Debug.Log(stats.gameObject.name + "에게 Damage를 준다.");
        //stats.TakeDamage(myStats.damage)
    }
    private IEnumerator IDoDamage(MORPG_CharacterStats stats, float damage, float delay)
    {
        yield return(new WaitForSeconds(delay));

        // TODO (장현명) : 이쪽이 문제
        Instantiate(attackEffect, transform.position, Quaternion.identity);
        stats.TakeDamage(damage);
    }
    /// <summary>
    /// 공격한다
    /// </summary>
    /// <param name="targetStats">타겟 캐릭터 상태</param>
    /// <param name="damage">데미지 값</param>
    public void Attack(MORPG_CharacterStats targetStats, float damage)
    {
        if (attackCooldown <= 0)
        {
            StartCoroutine(IDoDamage(targetStats, damage, attackDelay));

            attackCooldown = 1f / attackSpeed;
        }
    }
    private void Start()
    {
        target = GameObject.FindWithTag("MORPG_Player").GetComponent <Transform>();
        agent  = GetComponent <NavMeshAgent>();
        combat = GetComponent <MORPG_CharacterCombat>();

        stats = GetComponent <MORPG_CharacterStats>();

        anim            = GetComponentInChildren <Animator>();
        respawnPosition = transform.position;
    }
    void Start()
    {
        motor  = GetComponent <MORPG_PlayerMotor>();
        anim   = GetComponent <Animator>();
        combat = GetComponent <MORPG_CharacterCombat>();
        stats  = GetComponent <MORPG_CharacterStats>();


        // 플레이어 스텟 설정하기
        stats.damage     = PlayerInformation.userData.TotalAtk;
        stats.maxDefence = stats.currentDefence = PlayerInformation.userData.def;
        stats.maxHealth  = stats.currentHealth = PlayerInformation.userData.hp;
    }
Beispiel #6
0
 /// <summary>
 /// 데미지를 준다
 /// </summary>
 /// <param name="targetStats">타겟 상태</param>
 public void Attack(MORPG_CharacterStats targetStats)
 {
     if (attackCooldown <= 0)
     {
         StartCoroutine(IDoDamage(targetStats, attackDelay));
         anim.SetBool(isAttackHash, true);
         if (OnAttack != null)
         {
             OnAttack();
         }
         attackCooldown = 1.0f / attackSpeed;
     }
 }
    private void Update()
    {
        // TODO (장현명) : Test 후 리펙토링
        float distance;

        if (target != null)
        {
            distance = Vector3.Distance(target.position, transform.position);
        }
        else
        {
            distance = lookRadius + 1f; //범위보다 크게 설정해서 순찰할 수 있게 한다.
        }

        if (distance <= lookRadius)
        {
            eState = EState.attack;
        }
        else
        {
            eState = EState.patrol;
        }
        switch (eState)
        {
        case EState.patrol:
            Patrol();
            break;

        case EState.attack:
            agent.SetDestination(target.position);

            if (distance <= agent.stoppingDistance)     // 거리 안으로 들어오면
            {
                MORPG_CharacterStats targetStats = target.GetComponent <MORPG_CharacterStats>();
                combat.Attack(targetStats, stats.damage);
            }
            break;
        }
    }
    // Update is called once per frame
    void Update()
    {
        // TODO (장현명) : Test 후 리펙토링
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        // Click screen
        if (Input.GetButtonDown("MORPG_Fire1"))
        {
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            // Click ground
            if (Physics.Raycast(ray, out hit))
            {
                if (hit.transform.CompareTag("MORPG_Npc"))
                {
                    Debug.Log("Npc");
                    MORPG_Interactable interactable = hit.collider.GetComponent <MORPG_Interactable>();

                    if (interactable != null)
                    {
                        Debug.Log("interactable은 null이 아니다");
                        SetFocus(interactable);
                    }
                    else
                    {
                        Debug.Log("interactable은 null이다.?");
                        RemoveFocus();
                    }
                }
                if (hit.transform.CompareTag("MORPG_Ground"))
                {
                    //Debug.Log("Ground");
                    mouseClickParticle.UseObject(hit.point);
                    motor.MoveToPoint(hit.point);
                    RemoveFocus();
                }
                if (hit.transform.CompareTag("MORPG_Monster"))
                {
                    motor.MoveToPoint(hit.point);

                    MORPG_Interactable    interactable    = hit.collider.GetComponent <MORPG_Interactable>();
                    MORPG_EnemyController enemyController = hit.collider.GetComponent <MORPG_EnemyController>();
                    MORPG_CharacterStats  enemyStats      = hit.collider.GetComponent <MORPG_CharacterStats>();
                    if (interactable != null)
                    {
                        SetFocus(interactable);
                        combat.Attack(enemyStats, stats.damage);
                    }

                    else
                    {
                        RemoveFocus();
                    }
                    Debug.Log("Monster");
                }
            }


            // LayerMask를 이용한 코드

            //// Click ground
            //if (Physics.Raycast(ray, out hit, movementMask))
            //{
            //    //Debug.Log("movementMask : " + movementMask.value);
            //    mouseClickParticle.UseObject(hit.point);
            //    motor.MoveToPoint(hit.point);
            //    RemoveFocus();
            //}

            //// Click monster
            //if(Physics.Raycast(ray,out hit, monsterMask))
            //{
            //    //Debug.Log("monsterMask : " + monsterMask.value);
            //}
            //// Click npc
            //if (Physics.Raycast(ray, out hit, npcMask))
            //{
            //    //Debug.Log("npcMask : " + npcMask.value);
            //    MORPG_Interactable interactable = hit.collider.GetComponent<MORPG_Interactable>();

            //    if (interactable != null)
            //    {
            //        Debug.Log("interactable은 null이 아니다");
            //        SetFocus(interactable);
            //    } else
            //    {
            //        Debug.Log("interactable은 null이다.?");
            //        RemoveFocus();
            //    }
            //}
        }
    }
Beispiel #9
0
 // Start is called before the first frame update
 void Start()
 {
     myStats = GetComponent <MORPG_CharacterStats>();
     anim    = GetComponentInChildren <Animator>();
 }