Skeleton.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEngine.EventSystems;
  4. namespace RPG_Fight_Test.Assets.Scripts.Creatures {
  5. public class Skeleton : Creature {
  6. private List<Creature> combatants;
  7. private void Start() {
  8. Dex = Random.Range(0, 20);
  9. movementRate = 20;
  10. CreatureHealth = Random.Range(10, 20);
  11. CurrentHealth = CreatureHealth;
  12. MaxHealth = CreatureHealth;
  13. IsCreatureAlive = true;
  14. }
  15. private void DecideFirstAction() {
  16. List<Creature> closeEnemies = EnemiesInSquareNextToCreature(this, combatants);
  17. if (closeEnemies.Count > 0) {
  18. SetFirstAction(new AttackAction(closeEnemies[0]));
  19. } else {
  20. // Move towards closest enemy
  21. Creature closestEnemy = FindClosestEnemy(this, combatants);
  22. MoveAction action = new MoveAction();
  23. action.SetStartPosition(CurrentPos);
  24. action.SetTargetCreature(closestEnemy);
  25. action.SetCreatureToMove(this);
  26. SetFirstAction(action);
  27. }
  28. }
  29. // Just a copy of first action for now, should have its own logic
  30. private void DecideSecondAction() {
  31. List<Creature> closeEnemies = EnemiesInSquareNextToCreature(this, combatants);
  32. if (closeEnemies.Count > 0) {
  33. SetSecondAction(new AttackAction(closeEnemies[0]));
  34. } else {
  35. // Move towards closest enemy
  36. Creature closestEnemy = FindClosestEnemy(this, combatants);
  37. MoveAction action = new MoveAction();
  38. action.SetStartPosition(CurrentPos);
  39. action.SetTargetCreature(closestEnemy);
  40. action.SetCreatureToMove(this);
  41. SetSecondAction(action);
  42. }
  43. }
  44. public void DecideActions(List<Creature> combatants) {
  45. this.combatants = combatants;
  46. List<Creature> closeEnemies = EnemiesInSquareNextToCreature(this, combatants);
  47. DecideFirstAction();
  48. DecideSecondAction();
  49. Debug.Log("Number of close enemies " + closeEnemies.Count);
  50. }
  51. public void ShowInfo() {
  52. }
  53. }
  54. }