1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Fixed Scholar handling

This commit is contained in:
Ivan Savenko
2023-10-18 17:14:22 +03:00
parent 48eba6c362
commit ce480c8c84
5 changed files with 87 additions and 29 deletions

View File

@@ -27,6 +27,7 @@
#include "../TerrainHandler.h"
#include "../TextOperations.h"
#include "../VCMI_Lib.h"
#include "../constants/StringConstants.h"
#include "../filesystem/CBinaryReader.h"
#include "../filesystem/Filesystem.h"
#include "../mapObjectConstructors/AObjectTypeHandler.h"
@@ -1189,11 +1190,53 @@ CGObjectInstance * CMapLoaderH3M::readScholar(const int3 & position, std::shared
};
auto * object = readGeneric(position, objectTemplate);
//auto * rewardable = dynamic_cast<CRewardableObject*>(object);
auto * rewardable = dynamic_cast<CRewardableObject*>(object);
uint8_t bonusTypeRaw = reader->readUInt8();
auto bonusType = static_cast<ScholarBonusType>(bonusTypeRaw);
auto bonusID = reader->readUInt8();
switch (bonusType)
{
case ScholarBonusType::PRIM_SKILL:
{
JsonNode variable;
JsonNode dice;
variable.String() = NPrimarySkill::names[bonusID];
variable.setMeta(ModScope::scopeGame());
dice.Integer() = 80;
rewardable->configuration.presetVariable("primarySkill", "gainedStat", variable);
rewardable->configuration.presetVariable("dice", "0", dice);
break;
}
case ScholarBonusType::SECONDARY_SKILL:
{
JsonNode variable;
JsonNode dice;
variable.String() = VLC->skills()->getByIndex(bonusID)->getJsonKey();
variable.setMeta(ModScope::scopeGame());
dice.Integer() = 50;
rewardable->configuration.presetVariable("secondarySkill", "gainedSkill", variable);
rewardable->configuration.presetVariable("dice", "0", dice);
break;
}
case ScholarBonusType::SPELL:
{
JsonNode variable;
JsonNode dice;
variable.String() = VLC->spells()->getByIndex(bonusID)->getJsonKey();
variable.setMeta(ModScope::scopeGame());
dice.Integer() = 20;
rewardable->configuration.presetVariable("spell", "gainedSpell", variable);
rewardable->configuration.presetVariable("dice", "0", dice);
break;
}
case ScholarBonusType::RANDOM:
break;// No-op
default:
logGlobal->warn("Map '%s': Invalid Scholar settings! Ignoring...", mapName);
}
/*uint8_t bonusTypeRaw =*/ reader->readUInt8();
/*auto bonusType = static_cast<ScholarBonusType>(bonusTypeRaw);*/
/*auto bonusID =*/ reader->readUInt8();
reader->skipZero(6);
return object;
}