1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-29 23:07:48 +02:00

We need to know caster stack ID for proper projectile animation

This commit is contained in:
AlexVinS
2014-11-27 20:47:37 +03:00
parent 6893509f65
commit 657385e32c
4 changed files with 30 additions and 19 deletions

View File

@@ -1315,7 +1315,19 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc )
// displayEffect (spell.mainEffectAnim, sc->tile);
// }
std::string casterCreatureName = "";
{
const auto casterStackID = sc->casterStack;
if(casterStackID > 0)
{
const CStack * casterStack = curInt->cb->battleGetStackByID(casterStackID);
if(casterStack != nullptr)
{
casterCreatureName = casterStack->type->namePl;
}
}
}
//displaying message in console
bool customSpell = false;
if(sc->affectedCres.size() == 1)
@@ -1373,7 +1385,7 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc )
}
//The %s shrivel with age, and lose %d hit points."
TBonusListPtr bl = curInt->cb->battleGetStackByID(*sc->affectedCres.begin(), false)->getBonuses(Selector::type(Bonus::STACK_HEALTH));
bl->remove_if(Selector::source(Bonus::SPELL_EFFECT, 75));
bl->remove_if(Selector::source(Bonus::SPELL_EFFECT, SpellID::AGE));
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(bl->totalValue()/2));
}
break;
@@ -1407,15 +1419,15 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc )
text = CGI->generaltexth->allTexts[118]; //One %s dies under the terrible gaze of the %s.
boost::algorithm::replace_first(text, "%s", curInt->cb->battleGetStackByID(*sc->affectedCres.begin())->type->nameSing);
}
boost::algorithm::replace_first(text, "%s", CGI->creh->creatures[sc->attackerType]->namePl); //casting stack
boost::algorithm::replace_first(text, "%s", casterCreatureName); //casting stack
}
else
text = "";
break;
default:
text = CGI->generaltexth->allTexts[565]; //The %s casts %s
if(auto castingCreature = vstd::atOrDefault(CGI->creh->creatures, sc->attackerType, nullptr))
boost::algorithm::replace_first(text, "%s", castingCreature->namePl); //casting stack
if(casterCreatureName != "")
boost::algorithm::replace_first(text, "%s", casterCreatureName); //casting stack
else
boost::algorithm::replace_first(text, "%s", "@Unknown caster@"); //should not happen
}
@@ -1445,9 +1457,9 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc )
{
boost::algorithm::replace_first(text, "%s", curInt->cb->battleGetHeroInfo(sc->side).name);
}
if(auto castingCreature = vstd::atOrDefault(CGI->creh->creatures, sc->attackerType, nullptr))
if(casterCreatureName != "")
{
boost::algorithm::replace_first(text, "%s", castingCreature->namePl); //creature caster
boost::algorithm::replace_first(text, "%s", casterCreatureName); //creature caster
}
else
{

View File

@@ -1440,7 +1440,7 @@ struct EndAction : public CPackForClient//3008
struct BattleSpellCast : public CPackForClient//3009
{
BattleSpellCast(){type = 3009;};
BattleSpellCast(){type = 3009; casterStack = -1;};
DLL_LINKAGE void applyGs(CGameState *gs);
void applyCl(CClient *cl);
@@ -1452,11 +1452,11 @@ struct BattleSpellCast : public CPackForClient//3009
BattleHex tile; //destination tile (may not be set in some global/mass spells
std::vector<ui32> resisted; //ids of creatures that resisted this spell
std::set<ui32> affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure)
CreatureID attackerType;//id of caster to generate console message; -1 if not set (eg. spell casted by artifact)
si32 casterStack;// -1 if not cated by creature, >=0 caster stack ID
bool castedByHero; //if true - spell has been casted by hero, otherwise by a creature
template <typename Handler> void serialize(Handler &h, const int version)
{
h & dmgToDisplay & side & id & skill & manaGained & tile & resisted & affectedCres & attackerType & castedByHero;
h & dmgToDisplay & side & id & skill & manaGained & tile & resisted & affectedCres & casterStack & castedByHero;
}
};

View File

@@ -1335,13 +1335,6 @@ DLL_LINKAGE void StartAction::applyGs( CGameState *gs )
DLL_LINKAGE void BattleSpellCast::applyGs( CGameState *gs )
{
assert(gs->curB);
if (castedByHero)
{
if (side < 2)
{
gs->curB->sides[side].castSpellsCount++;
}
}
const CSpell * spell = SpellID(id).toSpell();

View File

@@ -336,7 +336,13 @@ ISpellMechanics * ISpellMechanics::createMechanics(CSpell * s)
///DefaultSpellMechanics
void DefaultSpellMechanics::afterCast(BattleInfo * battle, const BattleSpellCast * packet) const
{
//TODO: may be move all from BattleSpellCast::applyGs here
if (packet->castedByHero)
{
if (packet->side < 2)
{
battle->sides[packet->side].castSpellsCount++;
}
}
//handle countering spells
for(auto stackID : packet->affectedCres)
@@ -366,7 +372,7 @@ void DefaultSpellMechanics::battleCast(const SpellCastEnvironment * env, BattleS
sc.tile = parameters.destination;
sc.dmgToDisplay = 0;
sc.castedByHero = nullptr != parameters.caster;
sc.attackerType = (parameters.casterStack ? parameters.casterStack->type->idNumber : CreatureID(CreatureID::NONE));
sc.casterStack = (parameters.casterStack ? parameters.casterStack->ID : -1);
sc.manaGained = 0;
int spellCost = 0;