RecipePageInfo.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. using GadgetCore.API;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using UnityEngine;
  7. namespace VendingMachine.RecipePageRegistry
  8. {
  9. /// <summary>
  10. /// Defines a custom Chip. Make sure to call Register on it to register your Chip.
  11. /// </summary>
  12. public class RecipePageInfo : RegistryEntry<RecipePageInfo, RecipePageType>
  13. {
  14. /// <summary>
  15. /// The ChipType of this Chip
  16. /// </summary>
  17. public readonly RecipePageType Type;
  18. /// <summary>
  19. /// The name of this Chip
  20. /// </summary>
  21. public readonly string Title;
  22. /// <summary>
  23. /// The Texture associated with this Chip. May be null.
  24. /// </summary>
  25. public virtual Texture Tex { get; protected set; }
  26. /// <summary>
  27. /// The Material associated with this Chip. May be null.
  28. /// </summary>
  29. public virtual Material Mat { get; protected set; }
  30. /// <summary>
  31. /// Use to create a new ChipInfo. Make sure to call Register on it to register your Chip.
  32. /// </summary>
  33. public RecipePageInfo(RecipePageType Type, string Title, Texture Tex)
  34. {
  35. this.Type = Type;
  36. this.Title = Title;
  37. this.Tex = Tex;
  38. }
  39. /// <summary>
  40. /// Use to create a new ChipInfo. Make sure to call Register on it to register your Chip.
  41. /// </summary>
  42. public RecipePageInfo(RecipePageType Type, string Title, Material Mat)
  43. {
  44. this.Type = Type;
  45. this.Title = Title;
  46. this.Mat = Mat;
  47. }
  48. /// <summary>
  49. /// Registers this ChipInfo to the ChipRegistry.
  50. /// </summary>
  51. /// <param name="name">The registry name to use.</param>
  52. /// <param name="preferredID">If specified, will use this registry ID.</param>
  53. /// <param name="overrideExisting">If false, will not register if the preferred ID is already used. Ignored if no preferred ID is specified.</param>
  54. public virtual RecipePageInfo Register(string name)
  55. {
  56. return RegisterInternal(name) as RecipePageInfo;
  57. }
  58. /// <summary>
  59. /// Called after this Registry Entry has been registered to its Registry. You should never call this yourself.
  60. /// </summary>
  61. protected override void PostRegister()
  62. {
  63. if (Mat == null)
  64. {
  65. Mat = new Material(Shader.Find("Unlit/Transparent"))
  66. {
  67. mainTexture = Tex
  68. };
  69. }
  70. else
  71. {
  72. Tex = Mat.mainTexture;
  73. }
  74. }
  75. /// <summary>
  76. /// Returns the Registry Entry's Type enum. Used in the registration process, although it is safe to check this yourself by directly accessing the <see cref="Type"/> property.
  77. /// </summary>
  78. public override RecipePageType GetEntryType()
  79. {
  80. return Type;
  81. }
  82. /// <summary>
  83. /// Returns the singleton of the registry used for storing this type of Registry Entry.
  84. /// </summary>
  85. public override Registry<RecipePageInfo, RecipePageType> GetRegistry()
  86. {
  87. return RecipePageRegistry.Singleton;
  88. }
  89. /// <summary>
  90. /// Returns whether the specified ID is valid for this Registry Entry's Type.
  91. /// </summary>
  92. public override bool IsValidIDForType(int id)
  93. {
  94. return id > 0;
  95. }
  96. /// <summary>
  97. /// Returns the next valid ID for this Registry Entry's Type, after the provided lastValidID. Should skip the vanilla ID range.
  98. /// </summary>
  99. public override int GetNextIDForType(int lastValidID)
  100. {
  101. if (lastValidID < GetRegistry().GetIDStart() - 1) lastValidID = GetRegistry().GetIDStart() - 1;
  102. return ++lastValidID;
  103. }
  104. /// <summary>
  105. /// Checks if the chip should be considered to currently be in use, and should not be allowed to be activated again. Override to add custom behavior - by default, always returns false.
  106. /// </summary>
  107. public virtual bool IsChipActive(int slot) { return false; }
  108. /// <summary>
  109. /// Invoked whenever this chip is activated. Will never be invoked if the ChipType is not ACTIVE. The int parameter is the slot the chip is in.
  110. /// </summary>
  111. public event Action<int> OnUse;
  112. /// <summary>
  113. /// Invoked whenever this chip is equipped. The int parameter is the slot the chip is being equipped to. This is invoked immediately after the chip is placed into the slot.
  114. /// </summary>
  115. public event Action<int> OnEquip;
  116. /// <summary>
  117. /// Invoked whenever this chip is dequipped. The int parameter is the slot the chip is being dequipped from. This is invoked immediately before the chip is removed from the slot.
  118. /// </summary>
  119. public event Action<int> OnDequip;
  120. internal void InvokeOnUse(int slot) { OnUse?.Invoke(slot); }
  121. internal void InvokeOnEquip(int slot) { OnEquip?.Invoke(slot); }
  122. internal void InvokeOnDequip(int slot) { OnDequip?.Invoke(slot); }
  123. /// <summary>
  124. /// This indicates what should the active chip's cost represent.
  125. /// </summary>
  126. public enum ChipCostType
  127. {
  128. /// <summary>
  129. /// The cost represents a number of points of mana, as normal chips do.
  130. /// </summary>
  131. MANA,
  132. /// <summary>
  133. /// The cost represents a number of points of stamina.
  134. /// </summary>
  135. ENERGY,
  136. /// <summary>
  137. /// The cost represents a number of points of health, although activating the chip will be unable to kill the player, and if it would the activation fails.
  138. /// </summary>
  139. HEALTH_SAFE,
  140. /// <summary>
  141. /// The cost represents a number of points of health, and activating the chip is able to kill the player if they have less than or equal to the number of points of health that the cost requires. If the player dies from attempting to activate this chip, then the effect does not get activated.
  142. /// </summary>
  143. HEALTH_LETHAL,
  144. /// <summary>
  145. /// The cost represents a number of points of health, and activating the chip is able to kill the player if they have less than or equal to the number of points of health that the cost requires. If the player dies from attempting to activate this chip, then the effect still activates. Note that at the moment of invocation, the player well have 0 or less health, and will be flagged as dead (GameScript.dead == true) but the death screen will not have opened yet, and the death will be canceled if the chip restores the player's health.
  146. /// </summary>
  147. HEALTH_LETHAL_POSTMORTEM
  148. }
  149. }
  150. }