1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-19 17:39:44 +00:00

Use SpellCast animation for creatures that have it (flame atronach)

This commit is contained in:
scrawl 2014-09-18 03:24:47 +02:00
parent 07cd647e75
commit 447e93bdb4
2 changed files with 61 additions and 17 deletions

View file

@ -745,29 +745,55 @@ bool CharacterController::updateCreatureState()
{
MWBase::Environment::get().getWorld()->breakInvisibility(mPtr);
// These are unique animations and not linked to movement type. Just pick one randomly.
int roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * 3; // [0, 2]
if (roll == 0)
mCurrentWeapon = "attack1";
else if (roll == 1)
mCurrentWeapon = "attack2";
else
mCurrentWeapon = "attack3";
mAnimation->play(mCurrentWeapon, Priority_Weapon,
MWRender::Animation::Group_All, true,
1, "start", "stop",
0.0f, 0);
mUpperBodyState = UpperCharState_StartToMinAttack;
std::string startKey = "start";
std::string stopKey = "stop";
if (weapType == WeapType_Spell)
{
const std::string spellid = stats.getSpells().getSelectedSpell();
if (!spellid.empty() && MWBase::Environment::get().getWorld()->startSpellCast(mPtr))
{
castSpell(spellid);
MWBase::Environment::get().getWorld()->castSpell(mPtr);
if (!mAnimation->hasAnimation("spellcast"))
MWBase::Environment::get().getWorld()->castSpell(mPtr); // No "release" text key to use, so cast immediately
else
{
const ESM::Spell *spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find(spellid);
const ESM::ENAMstruct &effectentry = spell->mEffects.mList.at(0);
switch(effectentry.mRange)
{
case 0: mAttackType = "self"; break;
case 1: mAttackType = "touch"; break;
case 2: mAttackType = "target"; break;
}
startKey = mAttackType + " " + startKey;
stopKey = mAttackType + " " + stopKey;
mCurrentWeapon = "spellcast";
}
}
else
mCurrentWeapon = "";
}
if (weapType != WeapType_Spell || !mAnimation->hasAnimation("spellcast")) // Not all creatures have a dedicated spellcast animation
{
int roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * 3; // [0, 2]
if (roll == 0)
mCurrentWeapon = "attack1";
else if (roll == 1)
mCurrentWeapon = "attack2";
else
mCurrentWeapon = "attack3";
}
if (!mCurrentWeapon.empty())
{
mAnimation->play(mCurrentWeapon, Priority_Weapon,
MWRender::Animation::Group_All, true,
1, startKey, stopKey,
0.0f, 0);
mUpperBodyState = UpperCharState_StartToMinAttack;
}
}

View file

@ -805,7 +805,25 @@ void Animation::handleTextKey(AnimState &state, const std::string &groupname, co
attachArrow();
else if (groupname == "spellcast" && evt.substr(evt.size()-7, 7) == "release")
MWBase::Environment::get().getWorld()->castSpell(mPtr);
{
// Make sure this key is actually for the RangeType we are casting. The flame atronach has
// the same animation for all range types, so there are 3 "release" keys on the same time, one for each range type.
// FIXME: This logic should really be in the CharacterController
const std::string& spellid = mPtr.getClass().getCreatureStats(mPtr).getSpells().getSelectedSpell();
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find(spellid);
const ESM::ENAMstruct &effectentry = spell->mEffects.mList.at(0);
int range = 0;
if (evt.compare(off, len, "self release") == 0)
range = 0;
else if (evt.compare(off, len, "touch release") == 0)
range = 1;
else if (evt.compare(off, len, "target release") == 0)
range = 2;
if (effectentry.mRange == range)
{
MWBase::Environment::get().getWorld()->castSpell(mPtr);
}
}
else if (groupname == "shield" && evt.compare(off, len, "block hit") == 0)
mPtr.getClass().block(mPtr);