1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-01 12:15:35 +00:00

Handle creature attack animations in character controller

This commit is contained in:
scrawl 2014-01-17 16:31:27 +01:00
parent c76a0448a3
commit 228254c890
3 changed files with 47 additions and 5 deletions

View file

@ -479,9 +479,47 @@ void CharacterController::updatePtr(const MWWorld::Ptr &ptr)
mPtr = ptr;
}
bool CharacterController::updateNpcState(bool onground, bool inwater, bool isrunning, bool sneak)
bool CharacterController::updateCreatureState()
{
const MWWorld::Class &cls = MWWorld::Class::get(mPtr);
const MWWorld::Class &cls = mPtr.getClass();
CreatureStats &stats = cls.getCreatureStats(mPtr);
if(stats.getAttackingOrSpell())
{
if(mUpperBodyState == UpperCharState_Nothing && mHitState == CharState_None)
{
MWBase::Environment::get().getWorld()->breakInvisibility(mPtr);
switch (stats.getAttackType())
{
case CreatureStats::AT_Chop:
mCurrentWeapon = "attack1";
break;
case CreatureStats::AT_Thrust:
mCurrentWeapon = "attack2";
break;
case CreatureStats::AT_Slash:
mCurrentWeapon = "attack3";
break;
}
mAnimation->play(mCurrentWeapon, Priority_Weapon,
MWRender::Animation::Group_UpperBody, true,
1, "start", "stop",
0.0f, 0);
mUpperBodyState = UpperCharState_StartToMinAttack;
}
}
bool animPlaying = mAnimation->getInfo(mCurrentWeapon);
if (!animPlaying)
mUpperBodyState = UpperCharState_Nothing;
return false;
}
bool CharacterController::updateNpcState(bool inwater, bool isrunning)
{
const MWWorld::Class &cls = MWWorld::Class::get(mPtr);
NpcStats &stats = cls.getNpcStats(mPtr);
WeaponType weaptype = WeapType_None;
MWWorld::InventoryStore &inv = cls.getInventoryStore(mPtr);
@ -1091,7 +1129,9 @@ void CharacterController::update(float duration)
}
if(cls.isNpc())
forcestateupdate = updateNpcState(onground, inwater, isrunning, sneak) || forcestateupdate;
forcestateupdate = updateNpcState(inwater, isrunning) || forcestateupdate;
else
forcestateupdate = updateCreatureState() || forcestateupdate;
refreshCurrentAnims(idlestate, movestate, forcestateupdate);

View file

@ -176,7 +176,8 @@ class CharacterController
void clearAnimQueue();
bool updateNpcState(bool onground, bool inwater, bool isrunning, bool sneak);
bool updateNpcState(bool inwater, bool isrunning);
bool updateCreatureState();
void updateVisibility();

View file

@ -2282,7 +2282,8 @@ namespace MWWorld
void World::breakInvisibility(const Ptr &actor)
{
actor.getClass().getCreatureStats(actor).getActiveSpells().purgeEffect(ESM::MagicEffect::Invisibility);
actor.getClass().getInventoryStore(actor).purgeEffect(ESM::MagicEffect::Invisibility);
if (actor.getClass().isNpc())
actor.getClass().getInventoryStore(actor).purgeEffect(ESM::MagicEffect::Invisibility);
}
bool World::isDark() const