BasicTool.h 14 KB

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