2019-04-28 17:50:36 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class EntityMonsterMage : EntityMonster
|
|
|
|
|
{
|
|
|
|
|
public override string Name {
|
|
|
|
|
get {
|
|
|
|
|
return "Mage";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float moveChance = 0.5f;
|
|
|
|
|
public float visionRange = 7f;
|
2019-04-29 08:39:48 +00:00
|
|
|
|
public GameObject attackAnimation;
|
2019-04-28 17:50:36 +00:00
|
|
|
|
protected EntityPlayer player;
|
|
|
|
|
|
|
|
|
|
protected new void Start() {
|
|
|
|
|
base.Start();
|
|
|
|
|
player = GameObject.FindGameObjectWithTag("Player").GetComponent<EntityPlayer>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnTurn(){
|
|
|
|
|
if(Random.Range(0f, 1f) < moveChance) return;
|
|
|
|
|
if (CanSeePlayer()){
|
|
|
|
|
Vector2Int distance = player.MapPosition - MapPosition;
|
|
|
|
|
if (distance.x < 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){
|
|
|
|
|
transform.Translate(Vector3.left);
|
|
|
|
|
}
|
|
|
|
|
else if (distance.x > 0 && map.CanMoveTo(MapPosition + Vector2Int.right)){
|
|
|
|
|
transform.Translate(Vector3.right);
|
|
|
|
|
}
|
|
|
|
|
else if (distance.y > 0 && map.CanMoveTo(MapPosition + Vector2Int.up)){
|
|
|
|
|
transform.Translate(Vector3.up);
|
|
|
|
|
}
|
|
|
|
|
else if (distance.y < 0 && map.CanMoveTo(MapPosition + Vector2Int.down)){
|
|
|
|
|
transform.Translate(Vector3.down);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
int direction = Random.Range(0, 4);
|
|
|
|
|
if (direction == 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){
|
|
|
|
|
transform.Translate(Vector3.left);
|
|
|
|
|
}
|
|
|
|
|
else if (direction == 1 && map.CanMoveTo(MapPosition + Vector2Int.right)){
|
|
|
|
|
transform.Translate(Vector3.right);
|
|
|
|
|
}
|
|
|
|
|
else if (direction == 2 && map.CanMoveTo(MapPosition + Vector2Int.up)){
|
|
|
|
|
transform.Translate(Vector3.up);
|
|
|
|
|
}
|
|
|
|
|
else if (direction == 3 && map.CanMoveTo(MapPosition + Vector2Int.down)){
|
|
|
|
|
transform.Translate(Vector3.down);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool CanSeePlayer(){
|
|
|
|
|
return Vector3.Distance(player.transform.position, transform.position) < visionRange;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDrawGizmosSelected() {
|
|
|
|
|
Gizmos.color = Color.cyan;
|
|
|
|
|
Gizmos.DrawWireSphere(transform.position, visionRange);
|
|
|
|
|
}
|
|
|
|
|
}
|