Monster.cs 2.4 KB

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