Monster.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using UnityEngine;
  2. namespace MazeGen
  3. {
  4. /// <summary>
  5. /// A ScriptableObject that defines a monster template (stats, appearance, loot).
  6. /// Monsters are instantiated from this template when they spawn in a room.
  7. /// </summary>
  8. public class Monster : ScriptableObject
  9. {
  10. [SerializeField] private string _monsterName = "Goblin";
  11. [SerializeField] private Color _color = Color.green;
  12. [SerializeField] private CharacterStats _baseStats = new CharacterStats();
  13. // Optional starting equipment
  14. [SerializeField] private Weapon _startingWeapon;
  15. [SerializeField] private Armor _startingArmor;
  16. // Loot: what items might this monster drop when defeated (rough probabilities)
  17. [SerializeField] private Item[] _possibleLoot;
  18. public string MonsterName => _monsterName;
  19. public Color Color => _color;
  20. public CharacterStats BaseStats => _baseStats;
  21. public Weapon StartingWeapon => _startingWeapon;
  22. public Armor StartingArmor => _startingArmor;
  23. public Item[] PossibleLoot => _possibleLoot;
  24. /// <summary>Create a fresh character sheet for a monster instance (with a copy of stats).</summary>
  25. public CharacterSheet CreateCharacterSheet()
  26. {
  27. var sheet = new CharacterSheet(_baseStats.Clone());
  28. if (_startingWeapon != null)
  29. sheet.EquipWeapon(_startingWeapon);
  30. if (_startingArmor != null)
  31. sheet.EquipArmor(_startingArmor);
  32. return sheet;
  33. }
  34. /// <summary>
  35. /// Get a random loot item from this monster's loot table (null if no loot).
  36. /// You can extend this with probability tiers or rarity weighting later.
  37. /// </summary>
  38. public Item GetRandomLoot()
  39. {
  40. if (_possibleLoot == null || _possibleLoot.Length == 0)
  41. return null;
  42. return _possibleLoot[Random.Range(0, _possibleLoot.Length)];
  43. }
  44. #if UNITY_EDITOR
  45. private void OnValidate()
  46. {
  47. if (_baseStats == null)
  48. _baseStats = new CharacterStats();
  49. }
  50. #endif
  51. }
  52. }