1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Add PrepareHeroLevelUp netpack to keep secondary skills RNG in sync

This commit is contained in:
Arseniy Shestakov 2016-09-08 00:24:05 +03:00
parent ca819b3cda
commit 53502e84e3
4 changed files with 40 additions and 3 deletions

View File

@ -1093,6 +1093,23 @@ struct ChangeObjectVisitors : public CPackForClient // 1003
}
};
struct PrepareHeroLevelUp : public CPackForClient//1999
{
DLL_LINKAGE void applyGs(CGameState *gs);
const CGHeroInstance *hero;
/// Do not serialize, used by server only
std::vector<SecondarySkill> skills;
PrepareHeroLevelUp(){type = 1999;};
template <typename Handler> void serialize(Handler &h, const int version)
{
h & hero;
}
};
struct HeroLevelUp : public Query//2000
{
void applyCl(CClient *cl);

View File

@ -1162,6 +1162,21 @@ DLL_LINKAGE void SetObjectProperty::applyGs( CGameState *gs )
}
}
DLL_LINKAGE void PrepareHeroLevelUp::applyGs(CGameState *gs)
{
CGHeroInstance * h = gs->getHero(hero->id);
auto proposedSkills = h->getLevelUpProposedSecondarySkills();
if(skills.size() == 1 || hero->tempOwner == PlayerColor::NEUTRAL) //choose skill automatically
{
skills.push_back(*RandomGeneratorUtil::nextItem(proposedSkills, h->skillsInfo.rand));
}
else
{
skills = proposedSkills;
}
}
DLL_LINKAGE void HeroLevelUp::applyGs( CGameState *gs )
{
CGHeroInstance * h = gs->getHero(hero->id);

View File

@ -253,6 +253,7 @@ void registerTypesClientPacks1(Serializer &s)
s.template registerType<CPackForClient, SetCommanderProperty>();
s.template registerType<CPackForClient, ChangeObjectVisitors>();
s.template registerType<CPackForClient, ShowWorldViewEx>();
s.template registerType<CPackForClient, PrepareHeroLevelUp>();
}
template<typename Serializer>

View File

@ -213,20 +213,24 @@ void CGameHandler::levelUpHero(const CGHeroInstance * hero)
sps.val = 1;
sendAndApply(&sps);
PrepareHeroLevelUp pre;
pre.hero = hero;
sendAndApply(&pre);
HeroLevelUp hlu;
hlu.hero = hero;
hlu.primskill = primarySkill;
hlu.skills = hero->getLevelUpProposedSecondarySkills();
hlu.skills = pre.skills;
if(hlu.skills.size() == 0)
{
sendAndApply(&hlu);
levelUpHero(hero);
}
else if(hlu.skills.size() == 1 || hero->tempOwner == PlayerColor::NEUTRAL) //choose skill automatically
else if(hlu.skills.size() == 1)
{
sendAndApply(&hlu);
levelUpHero(hero, *RandomGeneratorUtil::nextItem(hlu.skills, hero->skillsInfo.rand));
levelUpHero(hero, pre.skills.front());
}
else if(hlu.skills.size() > 1)
{