| 
									
										
										
										
											2017-08-20 19:18:07 +12:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * CSkillHandler.h, part of VCMI engine | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Authors: listed in file AUTHORS in main folder | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * License: GNU General Public License v2.0 or later | 
					
						
							|  |  |  |  * Full text of license available in license.txt file, in main folder | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
											
										 
											2018-03-17 17:58:30 +03:00
										 |  |  | #include <vcmi/Skill.h>
 | 
					
						
							|  |  |  | #include <vcmi/SkillService.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 19:18:07 +12:00
										 |  |  | #include "../lib/HeroBonus.h"
 | 
					
						
							|  |  |  | #include "GameConstants.h"
 | 
					
						
							|  |  |  | #include "IHandlerBase.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-26 16:07:42 +03:00
										 |  |  | VCMI_LIB_NAMESPACE_BEGIN | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
											
										 
											2018-03-17 17:58:30 +03:00
										 |  |  | class JsonSerializeFormat; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class DLL_LINKAGE CSkill : public Skill | 
					
						
							| 
									
										
										
										
											2017-08-20 19:18:07 +12:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-03-31 18:56:40 +13:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2017-08-25 13:35:02 +12:00
										 |  |  | 	struct LevelInfo | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-03-31 18:56:40 +13:00
										 |  |  | 		std::string iconSmall; | 
					
						
							|  |  |  | 		std::string iconMedium; | 
					
						
							|  |  |  | 		std::string iconLarge; | 
					
						
							| 
									
										
										
										
											2017-08-25 13:35:02 +12:00
										 |  |  | 		std::vector<std::shared_ptr<Bonus>> effects; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		LevelInfo(); | 
					
						
							|  |  |  | 		~LevelInfo(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-30 19:19:54 +12:00
										 |  |  | 		template <typename Handler> void serialize(Handler & h, const int version) | 
					
						
							| 
									
										
										
										
											2017-08-25 13:35:02 +12:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-06-20 17:39:50 +03:00
										 |  |  | 			h & iconSmall; | 
					
						
							|  |  |  | 			h & iconMedium; | 
					
						
							|  |  |  | 			h & iconLarge; | 
					
						
							| 
									
										
										
										
											2017-08-30 19:19:54 +12:00
										 |  |  | 			h & effects; | 
					
						
							| 
									
										
										
										
											2017-08-25 13:35:02 +12:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-31 18:56:40 +13:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2017-08-25 13:35:02 +12:00
										 |  |  | 	std::vector<LevelInfo> levels; // bonuses provided by basic, advanced and expert level
 | 
					
						
							| 
									
										
										
										
											2018-03-31 18:56:40 +13:00
										 |  |  | 	void addNewBonus(const std::shared_ptr<Bonus> & b, int level); | 
					
						
							| 
									
										
										
										
											2017-08-20 19:18:07 +12:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-01 22:20:41 +02:00
										 |  |  | 	SecondarySkill id; | 
					
						
							|  |  |  | 	std::string modScope; | 
					
						
							|  |  |  | 	std::string identifier; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 19:18:07 +12:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2018-03-31 18:56:40 +13:00
										 |  |  | 	CSkill(SecondarySkill id = SecondarySkill::DEFAULT, std::string identifier = "default"); | 
					
						
							| 
									
										
										
										
											2017-08-30 16:23:03 +12:00
										 |  |  | 	~CSkill(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
											
										 
											2018-03-17 17:58:30 +03:00
										 |  |  | 	int32_t getIndex() const override; | 
					
						
							|  |  |  | 	int32_t getIconIndex() const override; | 
					
						
							| 
									
										
										
										
											2023-01-18 23:56:01 +02:00
										 |  |  | 	std::string getJsonKey() const override; | 
					
						
							| 
									
										
										
											
												Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
											
										 
											2018-03-17 17:58:30 +03:00
										 |  |  | 	void registerIcons(const IconRegistar & cb) const override; | 
					
						
							|  |  |  | 	SecondarySkill getId() const override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-18 23:56:01 +02:00
										 |  |  | 	std::string getNameTextID() const override; | 
					
						
							|  |  |  | 	std::string getNameTranslated() const override; | 
					
						
							| 
									
										
										
										
											2023-01-01 22:20:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	std::string getDescriptionTextID(int level) const; | 
					
						
							|  |  |  | 	std::string getDescriptionTranslated(int level) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-31 18:56:40 +13:00
										 |  |  | 	const LevelInfo & at(int level) const; | 
					
						
							|  |  |  | 	LevelInfo & at(int level); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-30 16:23:03 +12:00
										 |  |  | 	std::string toString() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-31 18:56:40 +13:00
										 |  |  | 	std::array<si32, 2> gainChance; // gainChance[0/1] = default gain chance on level-up for might/magic heroes
 | 
					
						
							| 
									
										
										
										
											2017-08-30 16:23:03 +12:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
											
												Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
											
										 
											2018-03-17 17:58:30 +03:00
										 |  |  | 	void updateFrom(const JsonNode & data); | 
					
						
							|  |  |  | 	void serializeJson(JsonSerializeFormat & handler); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-30 19:19:54 +12:00
										 |  |  | 	template <typename Handler> void serialize(Handler & h, const int version) | 
					
						
							| 
									
										
										
										
											2017-08-30 16:23:03 +12:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-08-30 19:19:54 +12:00
										 |  |  | 		h & id; | 
					
						
							|  |  |  | 		h & identifier; | 
					
						
							| 
									
										
										
										
											2022-06-20 17:39:50 +03:00
										 |  |  | 		h & gainChance; | 
					
						
							| 
									
										
										
										
											2017-08-30 16:23:03 +12:00
										 |  |  | 		h & levels; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	friend class CSkillHandler; | 
					
						
							| 
									
										
										
										
											2017-08-31 10:29:25 +12:00
										 |  |  | 	friend DLL_LINKAGE std::ostream & operator<<(std::ostream & out, const CSkill & skill); | 
					
						
							|  |  |  | 	friend DLL_LINKAGE std::ostream & operator<<(std::ostream & out, const CSkill::LevelInfo & info); | 
					
						
							| 
									
										
										
										
											2017-08-20 19:18:07 +12:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-01 22:20:41 +02:00
										 |  |  | class DLL_LINKAGE CSkillHandler: public CHandlerBase<SecondarySkill, CSkill, CSkill, SkillService> | 
					
						
							| 
									
										
										
										
											2017-08-20 19:18:07 +12:00
										 |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2017-08-30 16:23:03 +12:00
										 |  |  | 	CSkillHandler(); | 
					
						
							|  |  |  | 	virtual ~CSkillHandler(); | 
					
						
							| 
									
										
										
										
											2017-08-20 19:18:07 +12:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-30 16:23:03 +12:00
										 |  |  | 	///IHandler base
 | 
					
						
							|  |  |  | 	std::vector<JsonNode> loadLegacyData(size_t dataSize) override; | 
					
						
							|  |  |  | 	void afterLoadFinalization() override; | 
					
						
							|  |  |  | 	void beforeValidate(JsonNode & object) override; | 
					
						
							| 
									
										
										
										
											2017-08-20 19:18:07 +12:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-30 16:23:03 +12:00
										 |  |  | 	std::vector<bool> getDefaultAllowed() const override; | 
					
						
							| 
									
										
										
										
											2017-08-20 19:18:07 +12:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-31 18:56:40 +13:00
										 |  |  | 	///json serialization helpers
 | 
					
						
							|  |  |  | 	static si32 decodeSkill(const std::string & identifier); | 
					
						
							|  |  |  | 	static std::string encodeSkill(const si32 index); | 
					
						
							|  |  |  | 	static std::string encodeSkillWithType(const si32 index); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-30 19:19:54 +12:00
										 |  |  | 	template <typename Handler> void serialize(Handler & h, const int version) | 
					
						
							| 
									
										
										
										
											2017-08-30 16:23:03 +12:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-08-30 19:19:54 +12:00
										 |  |  | 		h & objects; | 
					
						
							| 
									
										
										
										
											2017-08-30 16:23:03 +12:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-08-20 19:18:07 +12:00
										 |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
											
												Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
											
										 
											2018-03-17 17:58:30 +03:00
										 |  |  | 	const std::vector<std::string> & getTypeNames() const override; | 
					
						
							|  |  |  | 	CSkill * loadFromJson(const std::string & scope, const JsonNode & json, const std::string & identifier, size_t index) override; | 
					
						
							| 
									
										
										
										
											2017-08-20 19:18:07 +12:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2022-07-26 16:07:42 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | VCMI_LIB_NAMESPACE_END |