MiscellaneousItem.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. using UnityEngine;
  2. /// <summary>
  3. /// Miscellaneous items with dice-based restoration effects
  4. ///
  5. /// EXAMPLES:
  6. /// Small Health Potion (1d6+1 = 2-7 health):
  7. /// - healthDiceCount: 1, healthDiceType: 6, healthBonus: 1
  8. ///
  9. /// Large Health Potion (2d8+2 = 4-18 health):
  10. /// - healthDiceCount: 2, healthDiceType: 8, healthBonus: 2
  11. ///
  12. /// Simple range-based (5-10 health):
  13. /// - healthDiceCount: 0, healthRestoreMin: 5, healthRestoreMax: 10
  14. ///
  15. /// Weak Mana Potion (1d4 = 1-4 mana):
  16. /// - manaDiceCount: 1, manaDiceType: 4, manaBonus: 0
  17. /// </summary>
  18. [CreateAssetMenu(fileName = "New Misc Item", menuName = "RPG/Items/Miscellaneous")]
  19. [System.Serializable]
  20. public class MiscellaneousItem : Item
  21. {
  22. [Header("Misc Item Properties")]
  23. public bool isConsumable;
  24. public bool isStackable = true;
  25. public int maxStackSize = 99;
  26. [Header("Effects (if consumable)")]
  27. [Header("Health Restoration")]
  28. [Tooltip("Minimum health restored (used when dice count is 0)")]
  29. public int healthRestoreMin = 0;
  30. [Tooltip("Maximum health restored (used when dice count is 0)")]
  31. public int healthRestoreMax = 0;
  32. [Tooltip("Number of dice to roll (e.g., 2 for 2d6). Leave 0 to use min/max directly")]
  33. public int healthDiceCount = 0;
  34. [Tooltip("Dice type (4, 6, 8, 10, 12, 20, etc.)")]
  35. public int healthDiceType = 6;
  36. [Tooltip("Flat bonus added to dice roll (can be negative)")]
  37. public int healthBonus = 0;
  38. [Header("Mana Restoration")]
  39. [Tooltip("Minimum mana restored (used when dice count is 0)")]
  40. public int manaRestoreMin = 0;
  41. [Tooltip("Maximum mana restored (used when dice count is 0)")]
  42. public int manaRestoreMax = 0;
  43. [Tooltip("Number of dice to roll (e.g., 1 for 1d4). Leave 0 to use min/max directly")]
  44. public int manaDiceCount = 0;
  45. [Tooltip("Dice type (4, 6, 8, 10, 12, 20, etc.)")]
  46. public int manaDiceType = 4;
  47. [Tooltip("Flat bonus added to dice roll (can be negative)")]
  48. public int manaBonus = 0;
  49. public int temporaryStrengthBonus;
  50. public int temporaryDexterityBonus;
  51. public int temporaryConstitutionBonus;
  52. public int temporaryWisdomBonus;
  53. public float effectDuration; // In seconds, 0 for permanent
  54. public MiscellaneousItem()
  55. {
  56. itemType = ItemType.Miscellaneous;
  57. }
  58. public virtual void UseItem(Character character)
  59. {
  60. if (!isConsumable)
  61. {
  62. Debug.Log($"{itemName} is not consumable");
  63. return;
  64. }
  65. // Apply effects
  66. if (healthRestoreMax > 0 || healthDiceCount > 0)
  67. {
  68. int healthRestored = CalculateHealthRestore();
  69. character.CurrentHealth = Mathf.Min(character.MaxHealth, character.CurrentHealth + healthRestored);
  70. string rollInfo = GetHealthRollDescription();
  71. Debug.Log($"{character.CharacterName} restored {healthRestored} health from {itemName} {rollInfo}");
  72. }
  73. if (manaRestoreMax > 0 || manaDiceCount > 0)
  74. {
  75. int manaRestored = CalculateManaRestore();
  76. string rollInfo = GetManaRollDescription();
  77. Debug.Log($"{character.CharacterName} restored {manaRestored} mana from {itemName} {rollInfo}");
  78. // TODO: Apply mana restoration when mana system is implemented
  79. }
  80. // Add temporary stat bonuses (would need a buff system to implement properly)
  81. if (temporaryStrengthBonus > 0 || temporaryDexterityBonus > 0 ||
  82. temporaryConstitutionBonus > 0 || temporaryWisdomBonus > 0)
  83. {
  84. Debug.Log($"{character.CharacterName} gained temporary stat bonuses from {itemName}");
  85. // TODO: Implement temporary buff system
  86. }
  87. }
  88. /// <summary>
  89. /// Calculate health restoration using dice rolls or min/max range
  90. /// </summary>
  91. private int CalculateHealthRestore()
  92. {
  93. if (healthDiceCount > 0 && healthDiceType > 0)
  94. {
  95. // Use dice system: XdY + bonus
  96. int total = healthBonus;
  97. for (int i = 0; i < healthDiceCount; i++)
  98. {
  99. total += Random.Range(1, healthDiceType + 1);
  100. }
  101. return total;
  102. }
  103. else if (healthRestoreMax > 0)
  104. {
  105. // Use min/max range
  106. return Random.Range(healthRestoreMin, healthRestoreMax + 1);
  107. }
  108. return 0;
  109. }
  110. /// <summary>
  111. /// Calculate mana restoration using dice rolls or min/max range
  112. /// </summary>
  113. private int CalculateManaRestore()
  114. {
  115. if (manaDiceCount > 0 && manaDiceType > 0)
  116. {
  117. // Use dice system: XdY + bonus
  118. int total = manaBonus;
  119. for (int i = 0; i < manaDiceCount; i++)
  120. {
  121. total += Random.Range(1, manaDiceType + 1);
  122. }
  123. return total;
  124. }
  125. else if (manaRestoreMax > 0)
  126. {
  127. // Use min/max range
  128. return Random.Range(manaRestoreMin, manaRestoreMax + 1);
  129. }
  130. return 0;
  131. }
  132. /// <summary>
  133. /// Get a description of the item's effects for tooltips
  134. /// </summary>
  135. public string GetEffectDescription()
  136. {
  137. string description = "";
  138. if (healthDiceCount > 0 && healthDiceType > 0)
  139. {
  140. description += $"Restores {healthDiceCount}d{healthDiceType}";
  141. if (healthBonus > 0) description += $"+{healthBonus}";
  142. else if (healthBonus < 0) description += $"{healthBonus}";
  143. description += " health";
  144. }
  145. else if (healthRestoreMax > 0)
  146. {
  147. if (healthRestoreMin == healthRestoreMax)
  148. description += $"Restores {healthRestoreMax} health";
  149. else
  150. description += $"Restores {healthRestoreMin}-{healthRestoreMax} health";
  151. }
  152. if (manaDiceCount > 0 && manaDiceType > 0)
  153. {
  154. if (description.Length > 0) description += "\n";
  155. description += $"Restores {manaDiceCount}d{manaDiceType}";
  156. if (manaBonus > 0) description += $"+{manaBonus}";
  157. else if (manaBonus < 0) description += $"{manaBonus}";
  158. description += " mana";
  159. }
  160. else if (manaRestoreMax > 0)
  161. {
  162. if (description.Length > 0) description += "\n";
  163. if (manaRestoreMin == manaRestoreMax)
  164. description += $"Restores {manaRestoreMax} mana";
  165. else
  166. description += $"Restores {manaRestoreMin}-{manaRestoreMax} mana";
  167. }
  168. return description;
  169. }
  170. /// <summary>
  171. /// Get description of the health roll for debug/UI purposes
  172. /// </summary>
  173. private string GetHealthRollDescription()
  174. {
  175. if (healthDiceCount > 0 && healthDiceType > 0)
  176. {
  177. string desc = $"({healthDiceCount}d{healthDiceType}";
  178. if (healthBonus > 0) desc += $"+{healthBonus}";
  179. else if (healthBonus < 0) desc += $"{healthBonus}";
  180. desc += ")";
  181. return desc;
  182. }
  183. else if (healthRestoreMax > 0)
  184. {
  185. return $"({healthRestoreMin}-{healthRestoreMax})";
  186. }
  187. return "";
  188. }
  189. /// <summary>
  190. /// Get description of the mana roll for debug/UI purposes
  191. /// </summary>
  192. private string GetManaRollDescription()
  193. {
  194. if (manaDiceCount > 0 && manaDiceType > 0)
  195. {
  196. string desc = $"({manaDiceCount}d{manaDiceType}";
  197. if (manaBonus > 0) desc += $"+{manaBonus}";
  198. else if (manaBonus < 0) desc += $"{manaBonus}";
  199. desc += ")";
  200. return desc;
  201. }
  202. else if (manaRestoreMax > 0)
  203. {
  204. return $"({manaRestoreMin}-{manaRestoreMax})";
  205. }
  206. return "";
  207. }
  208. }