ItemSystem.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using UnityEngine;
  3. [Serializable]
  4. public class ItemData
  5. {
  6. public int itemId;
  7. public string itemName;
  8. public string description;
  9. public int price;
  10. public ItemType itemType;
  11. public int value;
  12. public Sprite icon;
  13. }
  14. public enum ItemType
  15. {
  16. HealthPotion,
  17. Shield,
  18. DoubleGold,
  19. Hint,
  20. TimeExtension,
  21. Custom
  22. }
  23. public interface IItemEffect
  24. {
  25. void ApplyEffect(MapGenerator3D gameManager);
  26. string GetDescription();
  27. }
  28. public class HealthPotionEffect : IItemEffect
  29. {
  30. private int healAmount;
  31. public HealthPotionEffect(int amount)
  32. {
  33. healAmount = amount;
  34. }
  35. public void ApplyEffect(MapGenerator3D gameManager)
  36. {
  37. gameManager.HealPlayer(healAmount);
  38. }
  39. public string GetDescription()
  40. {
  41. return $"恢复 {healAmount} 点生命值";
  42. }
  43. }
  44. public class ShieldEffect : IItemEffect
  45. {
  46. private int shieldAmount;
  47. public ShieldEffect(int amount)
  48. {
  49. shieldAmount = amount;
  50. }
  51. public void ApplyEffect(MapGenerator3D gameManager)
  52. {
  53. gameManager.AddShield(shieldAmount);
  54. }
  55. public string GetDescription()
  56. {
  57. return $"获得 {shieldAmount} 点护盾";
  58. }
  59. }
  60. public class DoubleGoldEffect : IItemEffect
  61. {
  62. private int duration;
  63. public DoubleGoldEffect(int turns)
  64. {
  65. duration = turns;
  66. }
  67. public void ApplyEffect(MapGenerator3D gameManager)
  68. {
  69. gameManager.ActivateDoubleGold(duration);
  70. }
  71. public string GetDescription()
  72. {
  73. return $"接下来 {duration} 个房间金币翻倍";
  74. }
  75. }
  76. public class HintEffect : IItemEffect
  77. {
  78. public void ApplyEffect(MapGenerator3D gameManager)
  79. {
  80. gameManager.ActivateHint();
  81. }
  82. public string GetDescription()
  83. {
  84. return "下次答题显示提示";
  85. }
  86. }