FluidContainer.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 ObjectTypeFactory<FluidContainerItemSkillConfig>
  55. {
  56. public:
  57. FluidContainerItemSkillConfigFactory();
  58. FluidContainerItemSkillConfig* fromJson(
  59. Framework::JSON::JSONObject* zJson) const override;
  60. Framework::JSON::JSONObject* toJsonObject(
  61. FluidContainerItemSkillConfig* zObject) const override;
  62. JSONObjectValidationBuilder* addToValidator(
  63. JSONObjectValidationBuilder* builder) const override;
  64. };
  65. class FluidContainerItemSkill : public ItemSkill
  66. {
  67. private:
  68. int cooldownTicks;
  69. FluidContainerItemSkillConfig* invalidUseConfig;
  70. Framework::RCArray<FluidContainerItemSkillConfig> configs;
  71. public:
  72. FluidContainerItemSkill();
  73. ~FluidContainerItemSkill();
  74. virtual bool use(Entity* zActor, Item* zUsedItem, Block* zTarget) override;
  75. virtual bool use(Entity* zActor, Item* zUsedItem, Entity* zTarget) override;
  76. void setInvalidUseConfig(FluidContainerItemSkillConfig* invalidUseConfig);
  77. FluidContainerItemSkillConfig* zInvalidUseConfig() const;
  78. void addConfig(FluidContainerItemSkillConfig* config);
  79. const Framework::RCArray<FluidContainerItemSkillConfig>& zConfigs() const;
  80. };
  81. class FluidContainerItemSkillFactory
  82. : public ItemSkillFactoryBase<FluidContainerItemSkill>
  83. {
  84. public:
  85. FluidContainerItemSkillFactory();
  86. FluidContainerItemSkill* createValue(
  87. Framework::JSON::JSONObject* zJson) const override;
  88. FluidContainerItemSkill* fromJson(
  89. Framework::JSON::JSONObject* zJson) const override;
  90. Framework::JSON::JSONObject* toJsonObject(
  91. FluidContainerItemSkill* zObject) const override;
  92. JSONObjectValidationBuilder* addToValidator(
  93. JSONObjectValidationBuilder* builder) const override;
  94. const char* getTypeToken() const override;
  95. };
  96. class FluidContainerItemType : public ItemType
  97. {
  98. private:
  99. int maxFluidAmount;
  100. Framework::JSON::JSONObject* itemSkillConfig;
  101. ItemSkillLevelUpRule* levelUpRule;
  102. public:
  103. FluidContainerItemType();
  104. ~FluidContainerItemType();
  105. protected:
  106. virtual void loadSuperItem(
  107. Item* zItem, Framework::StreamReader* zReader) const override;
  108. virtual void saveSuperItem(
  109. const Item* zItem, Framework::StreamWriter* zWriter) const override;
  110. public:
  111. virtual Item* createItem() const override;
  112. virtual ItemSkill* createDefaultItemSkill() const override;
  113. virtual void levelUpItemSkill(ItemSkill* zSkill) const override;
  114. virtual void setItemAttribute(Item* zItem,
  115. Framework::Text name,
  116. Framework::JSON::JSONValue* zValue) const override;
  117. virtual void addItemAttributes(
  118. Item* zItem, Framework::JSON::JSONObject* zItemObjet) const override;
  119. void setItemSkillConfig(Framework::JSON::JSONObject* itemSkillConfig);
  120. Framework::JSON::JSONObject* zItemSkillConfig() const;
  121. void setLevelUpRule(ItemSkillLevelUpRule* levelUpRule);
  122. ItemSkillLevelUpRule* zLevelUpRule() const;
  123. void setMaxFluidAmount(int maxFluidAmount);
  124. int getMaxFluidAmount() const;
  125. };
  126. class FluidContainerItemTypeFactory
  127. : public ItemTypeFactoryBase<FluidContainerItemType>
  128. {
  129. public:
  130. FluidContainerItemTypeFactory();
  131. FluidContainerItemType* createValue(
  132. Framework::JSON::JSONObject* zJson) const override;
  133. FluidContainerItemType* fromJson(
  134. Framework::JSON::JSONObject* zJson) const override;
  135. Framework::JSON::JSONObject* toJsonObject(
  136. FluidContainerItemType* zObject) const override;
  137. JSONObjectValidationBuilder* addToValidator(
  138. JSONObjectValidationBuilder* builder) const override;
  139. const char* getTypeToken() const override;
  140. };