BasicTool.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. #pragma once
  2. #include "BasicItems.h"
  3. #include "BlockFilter.h"
  4. #include "Item.h"
  5. #include "ItemSkill.h"
  6. class BasicToolItemType;
  7. class XPBasedLevelUpRule : public ItemSkillLevelUpRule
  8. {
  9. private:
  10. float xpIncrease;
  11. float xpMultiplier;
  12. float levelIncrease;
  13. float levelMultiplier;
  14. float maxLevel;
  15. public:
  16. XPBasedLevelUpRule();
  17. virtual void applyOn(ItemSkill* zSkill) override;
  18. void setXpIncrease(float xpIncrease);
  19. float getXpIncrease() const;
  20. void setXpMultiplier(float xpMultiplier);
  21. float getXpMultiplier() const;
  22. void setLevelIncrease(float levelIncrease);
  23. float getLevelIncrease() const;
  24. void setLevelMultiplier(float levelMultiplier);
  25. float getLevelMultiplier() const;
  26. void setMaxLevel(float maxLevel);
  27. float getMaxLevel() const;
  28. };
  29. class XPBasedLevelUpRuleFactory
  30. : public SubTypeFactory<ItemSkillLevelUpRule, XPBasedLevelUpRule>
  31. {
  32. public:
  33. XPBasedLevelUpRuleFactory();
  34. XPBasedLevelUpRule* fromJson(
  35. Framework::JSON::JSONObject* zJson) const override;
  36. Framework::JSON::JSONObject* toJsonObject(
  37. XPBasedLevelUpRule* zObject) const override;
  38. JSONObjectValidationBuilder* addToValidator(
  39. JSONObjectValidationBuilder* builder) const override;
  40. const char* getTypeToken() const override;
  41. };
  42. class BasicToolItem : public Item
  43. {
  44. private:
  45. float headMaterialHardness;
  46. float rodMaterialHardness;
  47. float handleMaterialHardness;
  48. public:
  49. BasicToolItem(
  50. int itemTypeId, Framework::Text name, float maxHp, float maxDurability);
  51. void setHeadMaterialHardness(float hardness);
  52. void setRodMaterialHardness(float hardness);
  53. void setHandleMaterialHardness(float hardness);
  54. float getHeadMaterialHardness() const;
  55. float getRodMaterialHardness() const;
  56. float getHandleMaterialHardness() const;
  57. };
  58. class BasicToolItemType : public ItemType
  59. {
  60. private:
  61. float headMaterialHardness;
  62. float rodMaterialHardness;
  63. float handleMaterialHardness;
  64. float baseDurability;
  65. float baseDurabilityMultiplier;
  66. float headMaterialDurability;
  67. float headMaterialDurabilityMultiplier;
  68. float rodMaterialDurability;
  69. float rodMaterialDurabilityMultiplier;
  70. float handleMaterialDurability;
  71. float handleMaterialDurabilityMultiplier;
  72. ItemSkillLevelUpRule* levelUpRule;
  73. int brokenItemTypeId;
  74. Framework::Text brokenItemTypeName;
  75. Framework::JSON::JSONObject* itemSkillConfigJson;
  76. public:
  77. BasicToolItemType();
  78. ~BasicToolItemType();
  79. protected:
  80. virtual void loadSuperItem(
  81. Item* zItem, Framework::StreamReader* zReader) const override;
  82. virtual void saveSuperItem(
  83. const Item* zItem, Framework::StreamWriter* zWriter) const override;
  84. public:
  85. virtual bool initialize(Game* zGame) override;
  86. virtual const ItemType* zBrokenItemType() const override;
  87. virtual Item* createItem() const override;
  88. virtual void levelUpItemSkill(ItemSkill* zSkill) const override;
  89. virtual void setItemAttribute(Item* zItem,
  90. Framework::Text name,
  91. Framework::JSON::JSONValue* zValue) const override;
  92. virtual void addItemAttributes(
  93. Item* zItem, Framework::JSON::JSONObject* zItemObjet) const override;
  94. virtual ItemSkill* createDefaultItemSkill() const override;
  95. void setBrokenItemTypeName(Framework::Text brokenItemTypeName);
  96. Framework::Text getBrokenItemTypeName() const;
  97. void setHeadMaterialHardness(float hardness);
  98. float getHeadMaterialHardness() const;
  99. void setRodMaterialHardness(float hardness);
  100. float getRodMaterialHardness() const;
  101. void setHandleMaterialHardness(float hardness);
  102. float getHandleMaterialHardness() const;
  103. void setBaseDurability(float durability);
  104. float getBaseDurablility() const;
  105. void setBaseDurabilityMultiplier(float multiplier);
  106. float getBaseDurabilityMultiplier() const;
  107. void setHeadMaterialDurability(float durability);
  108. float getHeadMaterialDurability() const;
  109. void setHeadMaterialDurabilityMultiplier(float multiplier);
  110. float getHeadMaterialDurabilityMultiplier() const;
  111. void setRodMaterialDurability(float durability);
  112. float getRodMaterialDurability() const;
  113. void setRodMaterialDurabilityMultiplier(float multiplier);
  114. float getRodMaterialDurabilityMultiplier() const;
  115. void setHandleMaterialDurability(float durability);
  116. float getHandleMaterialDurability() const;
  117. void setHandleMaterialDurabilityMultiplier(float multiplier);
  118. float getHandleMaterialDurabilityMultiplier() const;
  119. void setLevelUpRule(ItemSkillLevelUpRule* rule);
  120. ItemSkillLevelUpRule* zLevelUpRule() const;
  121. void setItemSkillConfigJson(Framework::JSON::JSONObject* zJson);
  122. Framework::JSON::JSONObject* getItemSkillConfigJson() const;
  123. };
  124. class BasicToolItemTypeFactory : public ItemTypeFactoryBase<BasicToolItemType>
  125. {
  126. public:
  127. BasicToolItemTypeFactory();
  128. BasicToolItemType* createValue(
  129. Framework::JSON::JSONObject* zJson) const override;
  130. BasicToolItemType* fromJson(
  131. Framework::JSON::JSONObject* zJson) const override;
  132. Framework::JSON::JSONObject* toJsonObject(
  133. BasicToolItemType* zObject) const override;
  134. JSONObjectValidationBuilder* addToValidator(
  135. JSONObjectValidationBuilder* builder) const override;
  136. const char* getTypeToken() const override;
  137. };
  138. class BlockReplaceItemSkillConfig : public Framework::ReferenceCounter
  139. {
  140. private:
  141. BlockFilter* targetBlockFilter;
  142. int replacementBlockTypeId;
  143. int cooldownTicks;
  144. float staminaCost;
  145. float staminaCostDevider;
  146. float additionalStaminaCostDeviderPerLevel;
  147. float durabilityCost;
  148. float durabilityCostDevider;
  149. float additionalDurabilityCostDeviderPerLevel;
  150. float xpGain;
  151. public:
  152. BlockReplaceItemSkillConfig();
  153. ~BlockReplaceItemSkillConfig();
  154. void setTargetBlockFilter(BlockFilter* targetBlockFilter);
  155. BlockFilter* zTargetBlockFilter() const;
  156. void setReplacementBlockTypeId(int replacementBlockTypeId);
  157. int getReplacementBlockTypeId() const;
  158. void setCooldownTicks(int cooldownTicks);
  159. int getCooldownTicks() const;
  160. void setStaminaCost(float staminaCost);
  161. float getStaminaCost() const;
  162. void setStaminaCostDevider(float staminaCostDevider);
  163. float getStaminaCostDevider() const;
  164. void setAdditionalStaminaCostDeviderPerLevel(
  165. float additionalStaminaCostDeviderPerLevel);
  166. float getAdditionalStaminaCostDeviderPerLevel() const;
  167. void setDurabilityCost(float durabilityCost);
  168. float getDurabilityCost() const;
  169. void setDurabilityCostDevider(float durabilityCostDevider);
  170. float getDurabilityCostDevider() const;
  171. void setAdditionalDurabilityCostDeviderPerLevel(
  172. float additionalDurabilityCostDeviderPerLevel);
  173. float getAdditionalDurabilityCostDeviderPerLevel() const;
  174. void setXpGain(float xpGain);
  175. float getXpGain() const;
  176. };
  177. class BlockReplaceItemSkillConfigFactory
  178. : public ObjectTypeFactory<BlockReplaceItemSkillConfig>
  179. {
  180. public:
  181. BlockReplaceItemSkillConfigFactory();
  182. BlockReplaceItemSkillConfig* fromJson(
  183. Framework::JSON::JSONObject* zJson) const override;
  184. Framework::JSON::JSONObject* toJsonObject(
  185. BlockReplaceItemSkillConfig* zObject) const override;
  186. JSONObjectValidationBuilder* addToValidator(
  187. JSONObjectValidationBuilder* builder) const override;
  188. };
  189. class BlockReplaceItemSkill : public ItemSkill
  190. {
  191. private:
  192. BlockReplaceItemSkillConfig* invalidUseConfig;
  193. Framework::RCArray<BlockReplaceItemSkillConfig> configs;
  194. int cooldownTicks;
  195. public:
  196. BlockReplaceItemSkill();
  197. ~BlockReplaceItemSkill();
  198. virtual void load(Framework::StreamReader* zReader) override;
  199. virtual void save(Framework::StreamWriter* zWriter) override;
  200. virtual bool use(Entity* zActor, Item* zUsedItem, Block* zTarget) override;
  201. virtual bool use(Entity* zActor, Item* zUsedItem, Entity* zTarget) override;
  202. void setInvalidUseConfig(BlockReplaceItemSkillConfig* config);
  203. BlockReplaceItemSkillConfig* zInvalidUseConfig() const;
  204. void addConfig(BlockReplaceItemSkillConfig* config);
  205. const Framework::RCArray<BlockReplaceItemSkillConfig>& getConfigs() const;
  206. void setCooldownTicks(int cooldownTicks);
  207. int getCooldownTicks() const;
  208. };
  209. class BlockReplaceItemSkillFactory
  210. : public ItemSkillFactoryBase<BlockReplaceItemSkill>
  211. {
  212. public:
  213. BlockReplaceItemSkillFactory();
  214. BlockReplaceItemSkill* createValue(
  215. Framework::JSON::JSONObject* zJson) const override;
  216. BlockReplaceItemSkill* fromJson(
  217. Framework::JSON::JSONObject* zJson) const override;
  218. Framework::JSON::JSONObject* toJsonObject(
  219. BlockReplaceItemSkill* zObject) const override;
  220. JSONObjectValidationBuilder* addToValidator(
  221. JSONObjectValidationBuilder* builder) const override;
  222. const char* getTypeToken() const override;
  223. };
  224. class DamagingItemSkillConfig : public Framework::ReferenceCounter
  225. {
  226. private:
  227. BlockFilter* targetBlockFilter;
  228. float damage;
  229. float damagePerHeadHardness;
  230. float baseDamageMultiplier;
  231. float damageMultiplierPerHeadHardness;
  232. float damagePerLevel;
  233. float damageMultiplierPerLevel;
  234. float damageDevider;
  235. float damageDeviderPerHardness;
  236. float staminaCost;
  237. float staminaCostPerDamage;
  238. float staminaCostPerHardness;
  239. float staminaCostDevider;
  240. float staminaCostDeviderPerLevel;
  241. float durabilityCost;
  242. float durabilityCostPerDamage;
  243. float durabilityCostPerHardness;
  244. float durabilityCostDevider;
  245. float additionalDurabilityCostDeviderPerLevel;
  246. float xpGainPerDamage;
  247. public:
  248. DamagingItemSkillConfig();
  249. ~DamagingItemSkillConfig();
  250. void setTargetBlockFilter(BlockFilter* targetBlockFilter);
  251. BlockFilter* zTargetBlockFilter() const;
  252. void setDamage(float damage);
  253. float getDamage() const;
  254. void setDamagePerHeadHardness(float damagePerHeadHardness);
  255. float getDamagePerHeadHardness() const;
  256. void setBaseDamageMultiplier(float baseDamageMultiplier);
  257. float getBaseDamageMultiplier() const;
  258. void setDamageMultiplierPerHeadHardness(
  259. float damageMupliplierPerHeadHardness);
  260. float getDamageMultiplierPerHeadHardness() const;
  261. void setDamagePerLevel(float damagePerLevel);
  262. float getDamagePerLevel() const;
  263. void setDamageMultiplierPerLevel(float damageMultiplierPerLevel);
  264. float getDamageMultiplierPerLevel() const;
  265. void setDamageDevider(float damageDevider);
  266. float getDamageDevider() const;
  267. void setDamageDeviderPerHardness(float damageDeviderPerHardness);
  268. float getDamageDeviderPerHardness() const;
  269. void setStaminaCost(float staminaCost);
  270. float getStaminaCost() const;
  271. void setStaminaCostPerDamage(float staminaCostPerDamage);
  272. float getStaminaCostPerDamage() const;
  273. void setStaminaCostPerHardness(float staminaCostPerHardness);
  274. float getStaminaCostPerHardness() const;
  275. void setStaminaCostDevider(float staminaCostDevider);
  276. float getStaminaCostDevider() const;
  277. void setStaminaCostDeviderPerLevel(float staminaCostDeviderPerLevel);
  278. float getStaminaCostDeviderPerLevel() const;
  279. void setDurabilityCost(float durabilityCost);
  280. float getDurabilityCost() const;
  281. void setDurabilityCostPerDamage(float durabilityCostPerDamage);
  282. float getDurabilityCostPerDamage() const;
  283. void setDurabilityCostPerHardness(float durabilityCostPerHardness);
  284. float getDurabilityCostPerHardness() const;
  285. void setDurabilityCostDevider(float durabilityCostDevider);
  286. float getDurabilityCostDevider() const;
  287. void setAdditionalDurabilityCostDeviderPerLevel(
  288. float additionalDurabilityCostDeviderPerLevel);
  289. float getAdditionalDurabilityCostDeviderPerLevel() const;
  290. void setXpGainPerDamage(float xpGainPerDamage);
  291. float getXpGainPerDamage() const;
  292. };
  293. class DamagingItemSkillConfigFactory
  294. : public ObjectTypeFactory<DamagingItemSkillConfig>
  295. {
  296. public:
  297. DamagingItemSkillConfigFactory();
  298. DamagingItemSkillConfig* fromJson(
  299. Framework::JSON::JSONObject* zJson) const override;
  300. Framework::JSON::JSONObject* toJsonObject(
  301. DamagingItemSkillConfig* zObject) const override;
  302. JSONObjectValidationBuilder* addToValidator(
  303. JSONObjectValidationBuilder* builder) const override;
  304. };
  305. class DamagingItemSkill : public ItemSkill
  306. {
  307. private:
  308. DamagingItemSkillConfig* invalidUseConfig;
  309. Framework::RCArray<DamagingItemSkillConfig> configs;
  310. public:
  311. DamagingItemSkill();
  312. ~DamagingItemSkill();
  313. virtual bool use(Entity* zActor, Item* zUsedItem, Block* zTarget) override;
  314. virtual bool use(Entity* zActor, Item* zUsedItem, Entity* zTarget) override;
  315. void setInvalidUseConfig(DamagingItemSkillConfig* config);
  316. DamagingItemSkillConfig* zInvalidUseConfig() const;
  317. void addConfig(DamagingItemSkillConfig* config);
  318. const Framework::RCArray<DamagingItemSkillConfig>& getConfigs() const;
  319. };
  320. class DamagingItemSkillFactory : public ItemSkillFactoryBase<DamagingItemSkill>
  321. {
  322. public:
  323. DamagingItemSkillFactory();
  324. DamagingItemSkill* createValue(
  325. Framework::JSON::JSONObject* zJson) const override;
  326. DamagingItemSkill* fromJson(
  327. Framework::JSON::JSONObject* zJson) const override;
  328. Framework::JSON::JSONObject* toJsonObject(
  329. DamagingItemSkill* zObject) const override;
  330. JSONObjectValidationBuilder* addToValidator(
  331. JSONObjectValidationBuilder* builder) const override;
  332. const char* getTypeToken() const override;
  333. };