1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-05-31 22:59:54 +02:00

Do not crash if Scholar is not a rewardable object

This commit is contained in:
Ivan Savenko 2023-12-16 12:47:45 +02:00
parent 16e845e1c8
commit 9ff00d75dc

View File

@ -1206,45 +1206,52 @@ CGObjectInstance * CMapLoaderH3M::readScholar(const int3 & position, std::shared
auto bonusType = static_cast<ScholarBonusType>(bonusTypeRaw);
auto bonusID = reader->readUInt8();
switch (bonusType)
if (rewardable)
{
case ScholarBonusType::PRIM_SKILL:
switch (bonusType)
{
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::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);
}
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);
}
else
{
logGlobal->warn("Failed to set reward parameters for a Scholar! Object is not rewardable!");
}
reader->skipZero(6);