220 lines
5.0 KiB
Plaintext
220 lines
5.0 KiB
Plaintext
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class PHomeMonster : PHomeUnit
|
|
{
|
|
#region Define
|
|
|
|
public enum MonsterTypes { Minion, EnterLevel }
|
|
|
|
#endregion
|
|
|
|
[SerializeField]
|
|
private MonsterTypes m_monsterType;
|
|
public MonsterTypes MonsterType
|
|
{
|
|
get
|
|
{
|
|
return m_monsterType;
|
|
}
|
|
}
|
|
|
|
[SerializeField]
|
|
private float m_guardDis;
|
|
private Vector3 m_spawnPos;
|
|
private Vector3 m_targetPos;
|
|
private bool m_isGuardTarget;
|
|
[SerializeField]
|
|
private float m_followDis;
|
|
private bool m_isFollowing;
|
|
[SerializeField]
|
|
private float m_arriveDis;
|
|
|
|
[SerializeField]
|
|
private bool m_runAway;
|
|
|
|
#region Movement
|
|
|
|
private float m_mysticalScentTime;
|
|
Vector3 m_dir;
|
|
Vector3 m_dirNor;
|
|
float m_dirLength;
|
|
private void Update_Movement()
|
|
{
|
|
if (DuringAttackInterval)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//Vector2 velocity = Vector2.right * Input.GetAxisRaw("Horizontal") + Vector2.up * Input.GetAxisRaw("Vertical");
|
|
//m_movement.DestVelocity = velocity * m_speed;
|
|
Vector2 moveDir;
|
|
|
|
#region MysticalScent
|
|
m_mysticalScentTime = PHomeGameMode.main.MysticalScentTime;
|
|
if (m_mysticalScentTime > 0)
|
|
{
|
|
moveDir = PHomeGameMode.main.m_mysticalScentPos.position - transform.position;
|
|
}
|
|
#endregion
|
|
|
|
#region Follow
|
|
|
|
PHomePlayer playerUnit = PHomeGameMode.main.PlayerUnit;
|
|
if (playerUnit != null)
|
|
{
|
|
m_dir = playerUnit.transform.position - transform.position;
|
|
if (m_runAway)
|
|
{
|
|
m_dir *= -1;
|
|
}
|
|
if (m_dir.magnitude <= m_followDis)
|
|
{
|
|
if (!m_isFollowing)
|
|
{
|
|
Debug.Log("[Master]FollowPlayer");
|
|
}
|
|
m_isFollowing = true;
|
|
m_dirNor = m_dir.normalized;
|
|
m_dirLength = m_dir.magnitude;
|
|
if (m_dirLength < m_attackRangeBase)
|
|
{
|
|
return;
|
|
}
|
|
|
|
moveDir = m_dirNor;
|
|
}
|
|
else if (m_isFollowing)
|
|
{
|
|
m_dir = m_spawnPos - transform.position;
|
|
m_dirNor = m_dir.normalized;
|
|
m_dirLength = m_dir.magnitude;
|
|
if (m_dirLength < m_arriveDis)
|
|
{
|
|
Debug.Log("[Master]ArriveSpawnPos");
|
|
m_isFollowing = false;
|
|
return;
|
|
}
|
|
|
|
moveDir = m_dirNor;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region Guard
|
|
|
|
if (!m_isFollowing)
|
|
{
|
|
if (!m_isGuardTarget)
|
|
{
|
|
GetRandomPos();
|
|
}
|
|
if (m_isGuardTarget)
|
|
{
|
|
m_dir = m_targetPos - transform.position;
|
|
m_dirNor = m_dir.normalized;
|
|
m_dirLength = m_dir.magnitude;
|
|
if (m_dirLength < m_arriveDis)
|
|
{
|
|
Debug.Log("[Master]ArriveGuardPos");
|
|
m_isGuardTarget = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
moveDir = m_dirNor;
|
|
#endregion
|
|
|
|
|
|
Move(moveDir);
|
|
}
|
|
|
|
private void GetRandomPos()
|
|
{
|
|
float x = Random.Range(-m_guardDis, m_guardDis);
|
|
float yMax = Mathf.Sqrt(m_guardDis * m_guardDis - x * x);
|
|
float y = Random.Range(-yMax, yMax);
|
|
m_targetPos = m_spawnPos + new Vector3(x, y, 0);
|
|
m_isGuardTarget = true;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Attack
|
|
|
|
private void Update_Attack()
|
|
{
|
|
if (DuringAttackInterval)
|
|
{
|
|
return;
|
|
}
|
|
|
|
PHomePlayer playerUnit = PHomeGameMode.main.PlayerUnit;
|
|
if (playerUnit == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Vector2 dir = playerUnit.transform.position - transform.position;
|
|
float length = dir.magnitude;
|
|
if (length >= AttackRange)
|
|
{
|
|
return;
|
|
}
|
|
|
|
switch (m_monsterType)
|
|
{
|
|
case MonsterTypes.Minion:
|
|
{
|
|
PHomeGameMode.main.DoUnitAttack(this, playerUnit);
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Drop Gem
|
|
|
|
public int GemDropMin;
|
|
|
|
public int GemDropMax;
|
|
|
|
#endregion
|
|
|
|
#region Callback
|
|
|
|
public override void OnAfterHitted(PHomeUnit attacker, PHomeUnit victim)
|
|
{
|
|
base.OnAfterHitted(attacker, victim);
|
|
|
|
AudioManager.instance.AttackAudio();
|
|
}
|
|
|
|
#endregion
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
m_spawnPos = transform.position;
|
|
}
|
|
|
|
protected override void VirtualUpdate()
|
|
{
|
|
base.VirtualUpdate();
|
|
|
|
Update_Movement();
|
|
Update_Attack();
|
|
}
|
|
|
|
private void OnDrawGizmosSelected()
|
|
{
|
|
Gizmos.color = Color.red;
|
|
Gizmos.DrawSphere(transform.position, AttackRange);
|
|
}
|
|
}
|