COPY_PASTE_EXAMPLES.cs 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. // This file contains copy-paste examples for setting up the combat system.
  2. // Replace YOUR_NAMESPACE with your actual namespace.
  3. using UnityEngine;
  4. using MazeGen;
  5. namespace MazeGen
  6. {
  7. // EXAMPLE 1: Creating a weapon in editor via script
  8. [System.Obsolete("This is just an example - create weapons via Create > Weapon in editor instead")]
  9. public class WeaponCreationExample : MonoBehaviour
  10. {
  11. public void CreateExampleWeapon()
  12. {
  13. var weapon = ScriptableObject.CreateInstance<Weapon>();
  14. weapon.name = "Iron Sword";
  15. // Note: You'll need to expose attack bonus as public or via reflection to set it
  16. // Best practice: create via editor!
  17. }
  18. }
  19. // EXAMPLE 2: Creating a monster programmatically
  20. public class MonsterCreationExample : MonoBehaviour
  21. {
  22. public Monster CreateGoblin()
  23. {
  24. var goblin = ScriptableObject.CreateInstance<Monster>();
  25. goblin.name = "Goblin";
  26. // Create stats
  27. var stats = new CharacterStats();
  28. // stats fields are private - you'd need public setters or reflection
  29. // Best practice: create via editor!
  30. return goblin;
  31. }
  32. }
  33. // EXAMPLE 3: Setting up agents with character sheets in MazeSceneBuilder
  34. public class AgentSetupExample : MonoBehaviour
  35. {
  36. private Weapon[] _startingWeapons;
  37. private Armor[] _startingArmor;
  38. private void LoadResources()
  39. {
  40. // Load weapon templates
  41. _startingWeapons = Resources.LoadAll<Weapon>("Items/Weapons/");
  42. if (_startingWeapons.Length == 0)
  43. Debug.LogWarning("No weapons found in Resources/Items/Weapons/");
  44. // Load armor templates
  45. _startingArmor = Resources.LoadAll<Armor>("Items/Armor/");
  46. if (_startingArmor.Length == 0)
  47. Debug.LogWarning("No armor found in Resources/Items/Armor/");
  48. }
  49. private MazeAgent CreateAgentWithEquipment(string name, Room startRoom)
  50. {
  51. // Create base stats
  52. var stats = new CharacterStats();
  53. var sheet = new CharacterSheet(stats);
  54. // Equip weapon
  55. if (_startingWeapons.Length > 0)
  56. {
  57. var weapon = _startingWeapons[Random.Range(0, _startingWeapons.Length)];
  58. sheet.EquipWeapon(weapon);
  59. }
  60. // Equip armor
  61. if (_startingArmor.Length > 0)
  62. {
  63. var armor = _startingArmor[Random.Range(0, _startingArmor.Length)];
  64. sheet.EquipArmor(armor);
  65. }
  66. // Create agent with character sheet
  67. var agent = new MazeAgent(name, startRoom, sheet);
  68. return agent;
  69. }
  70. }
  71. // EXAMPLE 4: Spawning encounters when generating rooms
  72. public class EncounterSpawningExample : MonoBehaviour
  73. {
  74. private Monster[] _monsterPool;
  75. private float _encounterChance = 0.7f;
  76. private int _minMonstersPerRoom = 1;
  77. private int _maxMonstersPerRoom = 3;
  78. private void LoadMonsters()
  79. {
  80. _monsterPool = Resources.LoadAll<Monster>("Monsters/");
  81. if (_monsterPool.Length == 0)
  82. Debug.LogWarning("No monsters found in Resources/Monsters/");
  83. }
  84. private void SpawnEncounterInRoom(Room room)
  85. {
  86. // Don't spawn in start or exit rooms
  87. if (room.Kind == RoomKind.Start || room.Kind == RoomKind.Exit)
  88. return;
  89. // Random chance to spawn
  90. if (Random.value > _encounterChance)
  91. return;
  92. if (_monsterPool.Length == 0)
  93. return;
  94. // Create and populate encounter
  95. var encounter = new MonsterEncounter();
  96. encounter.SpawnMonsters(
  97. _monsterPool,
  98. _minMonstersPerRoom,
  99. _maxMonstersPerRoom
  100. );
  101. room.Encounter = encounter;
  102. Debug.Log($"Spawned encounter in {room.Id} with {encounter.AliveMonsterCount} monsters");
  103. }
  104. }
  105. // EXAMPLE 5: Triggering combat when agent enters a room
  106. public class CombatTriggerExample : MonoBehaviour
  107. {
  108. private MazeAgent _agent;
  109. private void UpdateAgentCombat()
  110. {
  111. // Check if agent entered a room with monsters
  112. if (_agent.CurrentRoom.Encounter != null &&
  113. _agent.CurrentRoom.Encounter.HasLivingMonsters &&
  114. !_agent.IsDead)
  115. {
  116. ResolveCombat();
  117. }
  118. }
  119. private void ResolveCombat()
  120. {
  121. var outcome = CombatResolver.ResolveCombat(_agent, _agent.CurrentRoom.Encounter);
  122. switch (outcome)
  123. {
  124. case CombatResolver.CombatOutcome.AgentVictory:
  125. Debug.Log($"{_agent.Name} won!");
  126. // TODO: Award loot
  127. // TODO: Update UI
  128. break;
  129. case CombatResolver.CombatOutcome.AgentDefeated:
  130. Debug.Log($"{_agent.Name} was defeated!");
  131. // Agent is now dead - they stop automatically
  132. // TODO: Update UI (show death)
  133. break;
  134. case CombatResolver.CombatOutcome.Fleeing:
  135. Debug.Log($"{_agent.Name} fled!");
  136. // TODO: Force retreat back through entrance
  137. break;
  138. }
  139. }
  140. }
  141. // EXAMPLE 6: Peeking at a room's threat level
  142. public class PeekingExample : MonoBehaviour
  143. {
  144. private MazeAgent _agent;
  145. private AutonomousAgentBrain _brain;
  146. private void CheckThreatOfAdjacentRooms()
  147. {
  148. foreach (var exit in _agent.CurrentRoom.Exits)
  149. {
  150. float threatLevel = _brain.PeekThroughExit(exit, _agent);
  151. string threatDescription = threatLevel < 0.5f ? "Safe" :
  152. threatLevel < 1.5f ? "Moderate" :
  153. threatLevel < 3.0f ? "Dangerous" : "Deadly";
  154. Debug.Log($"Exit leads to {threatDescription} room (CR: {threatLevel:F2})");
  155. }
  156. }
  157. }
  158. // EXAMPLE 7: Setting up weapon with specific bonuses (for reference)
  159. [System.Obsolete("Example only - create Weapons via editor")]
  160. public class WeaponBonusExample : MonoBehaviour
  161. {
  162. private void ExampleWeaponBonuses()
  163. {
  164. // When you create a Weapon, these are the fields:
  165. // - itemName: "Iron Sword"
  166. // - description: "A sturdy iron sword"
  167. // - icon: (sprite reference)
  168. // - rarity: 1 (common)
  169. // - attackBonus: 5.0f
  170. // - magicBonus: 0.0f (no magic effect)
  171. // - defenseBonus: 1.0f (slight parry bonus)
  172. // - speedBonus: 0.0f (no speed effect)
  173. // When equipped, applies:
  174. // - +5 attack
  175. // - +1 defense
  176. // Modifiers stack with other equipment
  177. }
  178. }
  179. // EXAMPLE 8: Armor with penalties
  180. [System.Obsolete("Example only - create Armor via editor")]
  181. public class ArmorExample : MonoBehaviour
  182. {
  183. private void ExampleArmorStats()
  184. {
  185. // Heavy Armor example:
  186. // - defenseBonus: 10.0f (good protection)
  187. // - healthBonus: 5.0f (extra durability)
  188. // - speedPenalty: 2.0f (slow movement)
  189. // - magicResistance: 0.0f (no special resistances)
  190. // Light Armor example:
  191. // - defenseBonus: 3.0f (basic protection)
  192. // - healthBonus: 0.0f
  193. // - speedPenalty: 0.0f (no penalty)
  194. // - magicResistance: 2.0f (magic resistance)
  195. }
  196. }
  197. // EXAMPLE 9: Initializing AutonomousAgentBrain with retreat settings
  198. public class BrainInitializationExample : MonoBehaviour
  199. {
  200. private void InitBrainBrave(AutonomousAgentBrain brain, MazeAgentController controller, MazeGenerator gen)
  201. {
  202. // Brave agent - will enter dangerous rooms
  203. brain.Initialize(
  204. controller,
  205. gen,
  206. initialDelay: 0.5f,
  207. decisionInterval: 0.5f,
  208. exploreChance: 0.8f,
  209. retreatThreshold: 3.0f, // Very high threshold - rarely retreats
  210. isLevelEnded: () => false
  211. );
  212. }
  213. private void InitBrainCautious(AutonomousAgentBrain brain, MazeAgentController controller, MazeGenerator gen)
  214. {
  215. // Cautious agent - avoids danger
  216. brain.Initialize(
  217. controller,
  218. gen,
  219. initialDelay: 0.5f,
  220. decisionInterval: 0.5f,
  221. exploreChance: 0.5f,
  222. retreatThreshold: 0.8f, // Low threshold - retreats often
  223. isLevelEnded: () => false
  224. );
  225. }
  226. private void InitBrainNormal(AutonomousAgentBrain brain, MazeAgentController controller, MazeGenerator gen)
  227. {
  228. // Balanced agent
  229. brain.Initialize(
  230. controller,
  231. gen,
  232. initialDelay: 0.5f,
  233. decisionInterval: 0.5f,
  234. exploreChance: 0.7f,
  235. retreatThreshold: 1.5f, // Medium threshold
  236. isLevelEnded: () => false
  237. );
  238. }
  239. }
  240. // EXAMPLE 10: Monster loot table setup (in editor)
  241. [System.Obsolete("Example only - create Monsters via editor")]
  242. public class MonsterLootExample : MonoBehaviour
  243. {
  244. private void ExampleLootTables()
  245. {
  246. // Goblin's loot table might include:
  247. // [0] Common Dagger
  248. // [1] Leather Armor
  249. // [2] Health Potion
  250. // [3] (empty for "no drop" chance)
  251. // Boss monster's loot table might include:
  252. // [0] Rare Sword
  253. // [1] Legendary Armor
  254. // [2] Magic Scroll
  255. // (no empty slots - always drops something)
  256. }
  257. }
  258. }