mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-15 00:05:02 +02:00
Bonusing objects are now configured in json
This commit is contained in:
@ -472,190 +472,6 @@ CRewardableObject::CRewardableObject():
|
||||
canRefuse(false)
|
||||
{}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// END OF CODE FOR CREWARDABLEOBJECT AND RELATED CLASSES ///
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CGBonusingObject::CGBonusingObject()
|
||||
{
|
||||
visitMode = VISIT_BONUS;
|
||||
selectMode = SELECT_FIRST;
|
||||
}
|
||||
|
||||
void CGBonusingObject::initObj(CRandomGenerator & rand)
|
||||
{
|
||||
auto configureBonusDuration = [&](CVisitInfo & visit, Bonus::BonusDuration duration, Bonus::BonusType type, si32 value, si32 descrID)
|
||||
{
|
||||
Bonus b(duration, type, Bonus::OBJECT, value, ID, descrID != 0 ? VLC->generaltexth->advobtxt[descrID] : "");
|
||||
visit.reward.bonuses.push_back(b);
|
||||
if (type == Bonus::MORALE)
|
||||
visit.reward.extraComponents.push_back(Component(Component::MORALE, 0, value, 0));
|
||||
if (type == Bonus::LUCK)
|
||||
visit.reward.extraComponents.push_back(Component(Component::LUCK, 0, value, 0));
|
||||
};
|
||||
|
||||
auto configureBonus = [&](CVisitInfo & visit, Bonus::BonusType type, si32 value, si32 descrID)
|
||||
{
|
||||
configureBonusDuration(visit, Bonus::ONE_BATTLE, type, value, descrID);
|
||||
};
|
||||
|
||||
auto configureMessage = [&](CVisitInfo & visit, int onGrantID, int onVisitedID)
|
||||
{
|
||||
visit.message.addTxt(MetaString::ADVOB_TXT, onGrantID);
|
||||
onVisited.addTxt(MetaString::ADVOB_TXT, onVisitedID);
|
||||
};
|
||||
|
||||
info.resize(1);
|
||||
|
||||
switch(ID)
|
||||
{
|
||||
case Obj::BUOY:
|
||||
blockVisit = true;
|
||||
configureMessage(info[0], 21, 22);
|
||||
configureBonus(info[0], Bonus::MORALE, +1, 94);
|
||||
break;
|
||||
case Obj::SWAN_POND:
|
||||
configureMessage(info[0], 29, 30);
|
||||
configureBonus(info[0], Bonus::LUCK, 2, 67);
|
||||
info[0].reward.movePercentage = 0;
|
||||
break;
|
||||
case Obj::FAERIE_RING:
|
||||
configureMessage(info[0], 49, 50);
|
||||
configureBonus(info[0], Bonus::LUCK, 1, 71);
|
||||
break;
|
||||
case Obj::FOUNTAIN_OF_FORTUNE:
|
||||
selectMode = SELECT_RANDOM;
|
||||
info.resize(5);
|
||||
for (int i=0; i<5; i++)
|
||||
{
|
||||
configureBonus(info[i], Bonus::LUCK, i-1, 69); //NOTE: description have %d that should be replaced with value
|
||||
info[i].message.addTxt(MetaString::ADVOB_TXT, 55);
|
||||
}
|
||||
onVisited.addTxt(MetaString::ADVOB_TXT, 56);
|
||||
break;
|
||||
case Obj::IDOL_OF_FORTUNE:
|
||||
|
||||
info.resize(7);
|
||||
for (int i=0; i<6; i++)
|
||||
{
|
||||
info[i].limiter.dayOfWeek = i+1;
|
||||
configureBonus(info[i], (i%2) ? Bonus::MORALE : Bonus::LUCK, 1, 68);
|
||||
info[i].message.addTxt(MetaString::ADVOB_TXT, 62);
|
||||
}
|
||||
info.back().limiter.dayOfWeek = 7;
|
||||
configureBonus(info.back(), Bonus::MORALE, 1, 68); // on last day of week
|
||||
configureBonus(info.back(), Bonus::LUCK, 1, 68);
|
||||
configureMessage(info.back(), 62, 63);
|
||||
|
||||
break;
|
||||
case Obj::MERMAID:
|
||||
blockVisit = true;
|
||||
configureMessage(info[0], 83, 82);
|
||||
configureBonus(info[0], Bonus::LUCK, 1, 72);
|
||||
break;
|
||||
case Obj::RALLY_FLAG:
|
||||
configureMessage(info[0], 111, 110);
|
||||
configureBonus(info[0], Bonus::MORALE, 1, 102);
|
||||
configureBonus(info[0], Bonus::LUCK, 1, 102);
|
||||
info[0].reward.movePoints = 400;
|
||||
break;
|
||||
case Obj::OASIS:
|
||||
configureMessage(info[0], 95, 94);
|
||||
configureBonus(info[0], Bonus::MORALE, 1, 95);
|
||||
info[0].reward.movePoints = 800;
|
||||
break;
|
||||
case Obj::TEMPLE:
|
||||
info[0].limiter.dayOfWeek = 7;
|
||||
info.resize(2);
|
||||
configureBonus(info[0], Bonus::MORALE, 2, 96);
|
||||
configureBonus(info[1], Bonus::MORALE, 1, 97);
|
||||
|
||||
info[0].message.addTxt(MetaString::ADVOB_TXT, 140);
|
||||
info[1].message.addTxt(MetaString::ADVOB_TXT, 140);
|
||||
onVisited.addTxt(MetaString::ADVOB_TXT, 141);
|
||||
break;
|
||||
case Obj::WATERING_HOLE:
|
||||
configureMessage(info[0], 166, 167);
|
||||
configureBonus(info[0], Bonus::MORALE, 1, 100);
|
||||
info[0].reward.movePoints = 400;
|
||||
break;
|
||||
case Obj::FOUNTAIN_OF_YOUTH:
|
||||
configureMessage(info[0], 57, 58);
|
||||
configureBonus(info[0], Bonus::MORALE, 1, 103);
|
||||
info[0].reward.movePoints = 400;
|
||||
break;
|
||||
case Obj::STABLES:
|
||||
configureMessage(info[0], 137, 136);
|
||||
configureBonusDuration(info[0], Bonus::ONE_WEEK, Bonus::LAND_MOVEMENT, 400, 0);
|
||||
info[0].reward.movePoints = 400;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CVisitInfo CGBonusingObject::getVisitInfo(int index, const CGHeroInstance *h) const
|
||||
{
|
||||
if(ID == Obj::STABLES)
|
||||
{
|
||||
assert(index == 0);
|
||||
for(auto& slot : h->Slots())
|
||||
{
|
||||
if(slot.second->type->idNumber == CreatureID::CAVALIER)
|
||||
{
|
||||
CVisitInfo vi(info[0]);
|
||||
vi.message.clear();
|
||||
vi.message.addTxt(MetaString::ADVOB_TXT, 138);
|
||||
vi.reward.extraComponents.push_back(Component(
|
||||
Component::CREATURE, CreatureID::CHAMPION, 0, 1));
|
||||
return vi;
|
||||
}
|
||||
}
|
||||
}
|
||||
return info[index];
|
||||
}
|
||||
|
||||
void CGBonusingObject::onHeroVisit(const CGHeroInstance *h) const
|
||||
{
|
||||
CRewardableObject::onHeroVisit(h);
|
||||
if(ID == Obj::STABLES)
|
||||
{
|
||||
//regardless of whether this hero visited stables or not, cavaliers must be upgraded
|
||||
for(auto& slot : h->Slots())
|
||||
{
|
||||
if(slot.second->type->idNumber == CreatureID::CAVALIER)
|
||||
{
|
||||
cb->changeStackType(StackLocation(h, slot.first),
|
||||
VLC->creh->objects[CreatureID::CHAMPION]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CGBonusingObject::wasVisited(const CGHeroInstance * h) const
|
||||
{
|
||||
if(ID == Obj::STABLES)
|
||||
{
|
||||
for(auto& slot : h->Slots())
|
||||
{
|
||||
if(slot.second->type->idNumber == CreatureID::CAVALIER)
|
||||
{
|
||||
// always display the reward message if the hero got cavaliers
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return CRewardableObject::wasVisited(h);
|
||||
}
|
||||
|
||||
void CGBonusingObject::grantReward(ui32 rewardID, const CGHeroInstance * hero) const
|
||||
{
|
||||
if(ID == Obj::STABLES && CRewardableObject::wasVisited(hero))
|
||||
{
|
||||
// reward message has been displayed - do not give the actual bonus
|
||||
return;
|
||||
}
|
||||
CRewardableObject::grantReward(rewardID, hero);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CGVisitableOPH::CGVisitableOPH()
|
||||
|
Reference in New Issue
Block a user