TeamCohesionManager.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. public class TeamCohesionManager : MonoBehaviour
  4. {
  5. public List<CharacterInGroup> groupMembers;
  6. public enum ActionType { Heal, Defend, Betray, Ignore }
  7. public void ApplyActionEffect(string from, string to, ActionType action)
  8. {
  9. var source = groupMembers.Find(c => c.characterName == from);
  10. var target = groupMembers.Find(c => c.characterName == to);
  11. if (source == null || target == null) return;
  12. float delta = action switch
  13. {
  14. ActionType.Heal => 5f,
  15. ActionType.Defend => 3f,
  16. ActionType.Betray => -10f,
  17. ActionType.Ignore => -2f,
  18. _ => 0f
  19. };
  20. // Race effects
  21. if (source.race == CharacterInGroup.RaceType.Elf && target.race == CharacterInGroup.RaceType.Orc)
  22. delta -= 3f;
  23. if (source.race == CharacterInGroup.RaceType.Human && target.race == CharacterInGroup.RaceType.Human)
  24. delta += 1f;
  25. // Age difference
  26. int ageDiff = Mathf.Abs(source.age - target.age);
  27. if (ageDiff > 30) delta -= 1f;
  28. // Personality reaction
  29. switch (target.personality)
  30. {
  31. case CharacterInGroup.PersonalityType.Loyal:
  32. if (action == ActionType.Defend) delta += 2f;
  33. if (action == ActionType.Betray) delta -= 5f;
  34. break;
  35. case CharacterInGroup.PersonalityType.Ambitious:
  36. if (action == ActionType.Heal) delta -= 1f;
  37. if (action == ActionType.Ignore) delta -= 2f;
  38. break;
  39. case CharacterInGroup.PersonalityType.Peaceful:
  40. if (action == ActionType.Betray) delta -= 5f;
  41. break;
  42. case CharacterInGroup.PersonalityType.Impulsive:
  43. delta *= 1.5f;
  44. break;
  45. case CharacterInGroup.PersonalityType.Opportunist:
  46. if (action == ActionType.Heal || action == ActionType.Defend) delta += 1f;
  47. if (action == ActionType.Ignore) delta -= 3f;
  48. break;
  49. }
  50. target.relations.Modify(from, delta);
  51. Debug.Log($"{from} affecte {to} avec {action}, nouvelle relation : {target.relations.Get(from)}");
  52. }
  53. public void OnCharacterHurt(string hurtName)
  54. {
  55. var hurt = groupMembers.Find(c => c.characterName == hurtName);
  56. if (hurt == null) return;
  57. if (hurt.characterType == CharacterInGroup.CharacterType.Priest)
  58. {
  59. foreach (var ally in groupMembers)
  60. {
  61. if (ally.characterType == CharacterInGroup.CharacterType.Warrior && ally.gridY > hurt.gridY)
  62. {
  63. ally.relations.Modify(hurt.characterName, -5f);
  64. Debug.Log($"{ally.characterName} en veut à {hurt.characterName} pour s'être mis en danger devant lui.");
  65. }
  66. }
  67. }
  68. }
  69. }