From d79e336e4b13c8b8f9b379f6c2b38a95f09a27a1 Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Thu, 29 Sep 2016 15:23:28 +0300 Subject: [PATCH] Reworked SetStackEffect::applyGs * fixed applying different duration effects from spells (f.e. Blind) * reduced code duplication --- lib/NetPacksLib.cpp | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index 1592ac50f..722b14683 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -1543,38 +1543,34 @@ DLL_LINKAGE void SetStackEffect::applyGs( CGameState *gs ) int spellid = effect.begin()->sid; //effects' source ID + auto processEffect = [spellid, this](CStack * sta, const Bonus & effect) + { + if(!sta->hasBonus(Selector::source(Bonus::SPELL_EFFECT, spellid).And(Selector::typeSubtype(effect.type, effect.subtype))) + || spellid == SpellID::DISRUPTING_RAY || spellid == SpellID::ACID_BREATH_DEFENSE) + { + //no such effect or cumulative - add new + logBonus->traceStream() << sta->nodeName() << " receives a new bonus: " << effect.Description(); + sta->addNewBonus( new Bonus(effect)); + } + else + actualizeEffect(sta, effect); + }; + for(ui32 id : stacks) { CStack *s = gs->curB->getStack(id); if(s) - { - if(spellid == SpellID::DISRUPTING_RAY || spellid == SpellID::ACID_BREATH_DEFENSE || !s->hasBonus(Selector::source(Bonus::SPELL_EFFECT, spellid)))//disrupting ray or acid breath or not on the list - just add - { - for(Bonus &fromEffect : effect) - { - logBonus->traceStream() << s->nodeName() << " receives a new bonus: " << fromEffect.Description(); - s->addNewBonus( new Bonus(fromEffect)); - } - } - else //just actualize - { - actualizeEffect(s, effect); - } - } + for(const Bonus & fromEffect : effect) + processEffect(s, fromEffect); else logNetwork->errorStream() << "Cannot find stack " << id; } - typedef std::pair p; - for(p para : uniqueBonuses) + + for(auto & para : uniqueBonuses) { CStack *s = gs->curB->getStack(para.first); - if (s) - { - if (!s->hasBonus(Selector::source(Bonus::SPELL_EFFECT, spellid).And(Selector::typeSubtype(para.second.type, para.second.subtype)))) - s->addNewBonus(new Bonus(para.second)); - else - actualizeEffect(s, effect); - } + if(s) + processEffect(s, para.second); else logNetwork->errorStream() << "Cannot find stack " << para.first; }