2019-04-27 20:19:35 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2019-04-28 14:34:50 +00:00
|
|
|
public class EntityMonsterSlime : EntityMonster
|
2019-04-27 20:19:35 +00:00
|
|
|
{
|
2019-04-28 14:44:16 +00:00
|
|
|
public override string Name {
|
|
|
|
get {
|
|
|
|
return "Slime";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-27 23:34:30 +00:00
|
|
|
public float moveChance = 0.5f;
|
2019-04-28 16:00:11 +00:00
|
|
|
public float visionRange = 4f;
|
2019-04-29 13:27:26 +00:00
|
|
|
public float attackRange = 1f;
|
2019-04-29 13:00:35 +00:00
|
|
|
public float damage = 1f;
|
2019-04-29 08:39:48 +00:00
|
|
|
public GameObject attackAnimation;
|
2019-04-28 14:34:50 +00:00
|
|
|
protected EntityPlayer player;
|
2019-04-27 20:19:35 +00:00
|
|
|
|
|
|
|
protected new void Start() {
|
|
|
|
base.Start();
|
2019-04-28 14:34:50 +00:00
|
|
|
player = GameObject.FindGameObjectWithTag("Player").GetComponent<EntityPlayer>();
|
2019-04-27 20:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnTurn(){
|
2019-04-27 23:34:30 +00:00
|
|
|
if(Random.Range(0f, 1f) < moveChance) return;
|
2019-04-27 20:19:35 +00:00
|
|
|
if (CanSeePlayer()){
|
2019-04-27 22:29:23 +00:00
|
|
|
Vector2Int distance = player.MapPosition - MapPosition;
|
2019-04-29 13:27:26 +00:00
|
|
|
if(distance.magnitude <= attackRange) {
|
|
|
|
float actualDamage = Random.value * damage;
|
|
|
|
player.hp -= actualDamage;
|
|
|
|
Instantiate(attackAnimation, player.transform);
|
|
|
|
messageBar.Write("Took damage from a slime.", Color.red);
|
|
|
|
}
|
|
|
|
else if (distance.x < 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){
|
2019-04-27 22:29:23 +00:00
|
|
|
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);
|
|
|
|
}
|
2019-04-27 20:19:35 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-04-29 13:27:26 +00:00
|
|
|
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);
|
2019-04-27 20:19:35 +00:00
|
|
|
}
|
2019-04-29 13:27:26 +00:00
|
|
|
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);
|
2019-04-27 20:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool CanSeePlayer(){
|
|
|
|
return Vector3.Distance(player.transform.position, transform.position) < visionRange;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDrawGizmosSelected() {
|
|
|
|
Gizmos.color = Color.cyan;
|
|
|
|
Gizmos.DrawWireSphere(transform.position, visionRange);
|
|
|
|
}
|
|
|
|
}
|