FluidContainer.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #pragma once
  2. #include <Vec3.h>
  3. #include "BlockFilter.h"
  4. #include "Item.h"
  5. #include "ItemSkill.h"
  6. class FluidContainerItemType;
  7. class FluidContainerItem : public Item
  8. {
  9. private:
  10. int fluidTypeId;
  11. int fluidAmount;
  12. public:
  13. FluidContainerItem(int itemTypeId, Framework::Text name);
  14. virtual const BlockType* zPlacedBlockType() const override;
  15. virtual bool canBeStackedWith(const Item* zItem) const override;
  16. virtual bool canBePlacedAt(
  17. int dimensionId, Framework::Vec3<int> worldPos) const override;
  18. virtual void onPlaced();
  19. virtual Framework::Text getTooltipUIML() const override;
  20. virtual bool applyFoodEffects(Entity* zTarget) override;
  21. virtual bool canApplyFoodEffectsFully(Entity* zTarget) const override;
  22. int getAmount() const;
  23. void setAmount(int amount);
  24. int getFluidTypeId() const;
  25. void setFluidTypeId(int fluidTypeId);
  26. friend FluidContainerItemType;
  27. };
  28. class FluidContainerItemSkillConfig : public Framework::ReferenceCounter
  29. {
  30. private:
  31. BlockFilter* targetFilter;
  32. float staminaCost;
  33. float staminaCostDevider;
  34. float staminaCostDeviderPerLevel;
  35. int cooldownTicks;
  36. float xpGain;
  37. public:
  38. FluidContainerItemSkillConfig();
  39. ~FluidContainerItemSkillConfig();
  40. void setTargetFilter(BlockFilter* targetFilter);
  41. BlockFilter* zTargetFilter() const;
  42. void setStaminaCost(float staminaCost);
  43. float getStaminaCost() const;
  44. void setStaminaCostDevider(float staminaCostDevider);
  45. float getStaminaCostDevider() const;
  46. void setStaminaCostDeviderPerLevel(float staminaCostDeviderPerLevel);
  47. float getStaminaCostDeviderPerLevel() const;
  48. void setCooldownTicks(int cooldownTicks);
  49. int getCooldownTicks() const;
  50. void setXpGain(float xpGain);
  51. float getXpGain() const;
  52. };
  53. class FluidContainerItemSkillConfigFactory
  54. : public TypeFactory<FluidContainerItemSkillConfig>
  55. {
  56. public:
  57. FluidContainerItemSkillConfigFactory();
  58. FluidContainerItemSkillConfig* createValue(
  59. Framework::JSON::JSONObject* zJson) const override;
  60. void fromJson(FluidContainerItemSkillConfig* zResult,
  61. Framework::JSON::JSONObject* zJson) const override;
  62. void toJson(FluidContainerItemSkillConfig* zObject,
  63. Framework::JSON::JSONObject* zResult) const override;
  64. JSONObjectValidationBuilder* addToValidator(
  65. JSONObjectValidationBuilder* builder) const override;
  66. };
  67. class FluidContainerItemSkill : public ItemSkill
  68. {
  69. private:
  70. int cooldownTicks;
  71. FluidContainerItemSkillConfig* invalidUseConfig;
  72. Framework::RCArray<FluidContainerItemSkillConfig> configs;
  73. public:
  74. FluidContainerItemSkill();
  75. ~FluidContainerItemSkill();
  76. virtual bool use(Entity* zActor, Item* zUsedItem, Block* zTarget) override;
  77. virtual bool use(Entity* zActor, Item* zUsedItem, Entity* zTarget) override;
  78. void setInvalidUseConfig(FluidContainerItemSkillConfig* invalidUseConfig);
  79. FluidContainerItemSkillConfig* zInvalidUseConfig() const;
  80. void addConfig(FluidContainerItemSkillConfig* config);
  81. const Framework::RCArray<FluidContainerItemSkillConfig>& zConfigs() const;
  82. };
  83. class FluidContainerItemSkillFactory
  84. : public ItemSkillFactoryBase<FluidContainerItemSkill>
  85. {
  86. public:
  87. FluidContainerItemSkillFactory();
  88. FluidContainerItemSkill* createValue(
  89. Framework::JSON::JSONObject* zJson) const override;
  90. void fromJson(FluidContainerItemSkill* zResult,
  91. Framework::JSON::JSONObject* zJson) const override;
  92. void toJson(FluidContainerItemSkill* zObject,
  93. Framework::JSON::JSONObject* zResult) const override;
  94. JSONObjectValidationBuilder* addToValidator(
  95. JSONObjectValidationBuilder* builder) const override;
  96. Framework::Text getTypeToken() const override;
  97. };
  98. class FluidContainerItemType : public ItemType
  99. {
  100. private:
  101. int maxFluidAmount;
  102. Framework::JSON::JSONObject* itemSkillConfig;
  103. ItemSkillLevelUpRule* levelUpRule;
  104. public:
  105. FluidContainerItemType();
  106. ~FluidContainerItemType();
  107. protected:
  108. virtual void loadSuperItem(
  109. Item* zItem, Framework::StreamReader* zReader) const override;
  110. virtual void saveSuperItem(
  111. const Item* zItem, Framework::StreamWriter* zWriter) const override;
  112. public:
  113. virtual Item* createItem() const override;
  114. virtual ItemSkill* createDefaultItemSkill() const override;
  115. virtual void levelUpItemSkill(ItemSkill* zSkill) const override;
  116. virtual void setItemAttribute(Item* zItem,
  117. Framework::Text name,
  118. Framework::JSON::JSONValue* zValue) const override;
  119. virtual void addItemAttributes(
  120. Item* zItem, Framework::JSON::JSONObject* zItemObjet) const override;
  121. void setItemSkillConfig(Framework::JSON::JSONObject* itemSkillConfig);
  122. Framework::JSON::JSONObject* zItemSkillConfig() const;
  123. void setLevelUpRule(ItemSkillLevelUpRule* levelUpRule);
  124. ItemSkillLevelUpRule* zLevelUpRule() const;
  125. void setMaxFluidAmount(int maxFluidAmount);
  126. int getMaxFluidAmount() const;
  127. };
  128. class FluidContainerItemTypeFactory
  129. : public ItemTypeFactoryBase<FluidContainerItemType>
  130. {
  131. public:
  132. FluidContainerItemTypeFactory();
  133. FluidContainerItemType* createValue(
  134. Framework::JSON::JSONObject* zJson) const override;
  135. void fromJson(FluidContainerItemType* zResult,
  136. Framework::JSON::JSONObject* zJson) const override;
  137. void toJson(FluidContainerItemType* zObject,
  138. Framework::JSON::JSONObject* zResult) const override;
  139. JSONObjectValidationBuilder* addToValidator(
  140. JSONObjectValidationBuilder* builder) const override;
  141. Framework::Text getTypeToken() const override;
  142. };