From b7568a160cd033125e6bf6d5af30e1f0180b64d1 Mon Sep 17 00:00:00 2001
From: nordsoft <nordsoft@rambler.ru>
Date: Mon, 9 Oct 2023 04:26:08 +0200
Subject: [PATCH] Fixes

---
 lib/constants/EntityIdentifiers.cpp | 21 +++++++++++++++++++++
 lib/constants/EntityIdentifiers.h   |  4 ++++
 lib/rewardable/Limiter.cpp          |  6 +++---
 3 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/lib/constants/EntityIdentifiers.cpp b/lib/constants/EntityIdentifiers.cpp
index 4fe197b5c..eaa790c9b 100644
--- a/lib/constants/EntityIdentifiers.cpp
+++ b/lib/constants/EntityIdentifiers.cpp
@@ -19,6 +19,8 @@
 #include <vcmi/FactionService.h>
 #include <vcmi/HeroType.h>
 #include <vcmi/HeroTypeService.h>
+#include <vcmi/HeroClass.h>
+#include <vcmi/HeroClassService.h>
 
 #include <vcmi/spells/Spell.h>
 #include <vcmi/spells/Service.h>
@@ -103,6 +105,25 @@ namespace GameConstants
 #endif
 }
 
+si32 HeroClassID::decode(const std::string & identifier)
+{
+	auto rawId = VLC->identifiers()->getIdentifier(ModScope::scopeMap(), "heroClass", identifier);
+	if(rawId)
+		return rawId.value();
+	else
+		return -1;
+}
+
+std::string HeroClassID::encode(const si32 index)
+{
+	return VLC->heroClasses()->getByIndex(index)->getJsonKey();
+}
+
+std::string HeroClassID::entityType()
+{
+	return "heroClass";
+}
+
 si32 HeroTypeID::decode(const std::string & identifier)
 {
 	auto rawId = VLC->identifiers()->getIdentifier(ModScope::scopeMap(), "hero", identifier);
diff --git a/lib/constants/EntityIdentifiers.h b/lib/constants/EntityIdentifiers.h
index 7545d5a2a..7ca9a1333 100644
--- a/lib/constants/EntityIdentifiers.h
+++ b/lib/constants/EntityIdentifiers.h
@@ -223,6 +223,10 @@ class HeroClassID : public Identifier<HeroClassID>
 {
 public:
 	using Identifier<HeroClassID>::Identifier;
+	///json serialization helpers
+	DLL_LINKAGE static si32 decode(const std::string & identifier);
+	DLL_LINKAGE static std::string encode(const si32 index);
+	static std::string entityType();
 };
 
 class HeroTypeID : public Identifier<HeroTypeID>
diff --git a/lib/rewardable/Limiter.cpp b/lib/rewardable/Limiter.cpp
index 8167da026..9255fbbb1 100644
--- a/lib/rewardable/Limiter.cpp
+++ b/lib/rewardable/Limiter.cpp
@@ -154,9 +154,9 @@ void Rewardable::Limiter::serializeJson(JsonSerializeFormat & handler)
 	handler.serializeInt("manaPercentage", manaPercentage);
 	handler.serializeInt("heroExperience", heroExperience);
 	handler.serializeInt("heroLevel", heroLevel);
-	handler.serializeIdArray("hero", heroes);
-	handler.serializeIdArray("heroClass", heroClasses);
-	handler.serializeIdArray("color", players);
+	handler.serializeIdArray("heroes", heroes);
+	handler.serializeIdArray("heroClasses", heroClasses);
+	handler.serializeIdArray("colors", players);
 	handler.serializeInt("manaPoints", manaPoints);
 	handler.serializeIdArray("artifacts", artifacts);
 	handler.enterArray("creatures").serializeStruct(creatures);