Skeleton.cs 2.8 KB

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