Fix projectile hit bug where the incorrect attackStrength would be used if a new attack has been performed in the meantime

c++11
scrawl 10 years ago
parent 4ef6aa6b7f
commit 5bc6513e2d

@ -166,13 +166,11 @@ namespace MWMechanics
}
void projectileHit(const MWWorld::Ptr &attacker, const MWWorld::Ptr &victim, MWWorld::Ptr weapon, const MWWorld::Ptr &projectile,
const osg::Vec3f& hitPosition)
const osg::Vec3f& hitPosition, float attackStrength)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
const MWWorld::Store<ESM::GameSetting> &gmst = world->getStore().get<ESM::GameSetting>();
MWMechanics::CreatureStats& attackerStats = attacker.getClass().getCreatureStats(attacker);
if(victim.isEmpty() || !victim.getClass().isActor() || victim.getClass().getCreatureStats(victim).isDead())
// Can't hit non-actors or dead actors
{
@ -199,12 +197,12 @@ namespace MWMechanics
const unsigned char* attack = weapon.get<ESM::Weapon>()->mBase->mData.mChop;
float damage = attack[0] + ((attack[1]-attack[0])*attackerStats.getAttackStrength()); // Bow/crossbow damage
float damage = attack[0] + ((attack[1]-attack[0])*attackStrength); // Bow/crossbow damage
// Arrow/bolt damage
// NB in case of thrown weapons, we are applying the damage twice since projectile == weapon
attack = projectile.get<ESM::Weapon>()->mBase->mData.mChop;
damage += attack[0] + ((attack[1]-attack[0])*attackerStats.getAttackStrength());
damage += attack[0] + ((attack[1]-attack[0])*attackStrength);
adjustWeaponDamage(damage, weapon, attacker);
reduceWeaponCondition(damage, true, weapon, attacker);

@ -14,7 +14,7 @@ void resistNormalWeapon (const MWWorld::Ptr& actor, const MWWorld::Ptr& attacker
/// @note for a thrown weapon, \a weapon == \a projectile, for bows/crossbows, \a projectile is the arrow/bolt
/// @note \a victim may be empty (e.g. for a hit on terrain), a non-actor (environment objects) or an actor
void projectileHit (const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim, MWWorld::Ptr weapon, const MWWorld::Ptr& projectile,
const osg::Vec3f& hitPosition);
const osg::Vec3f& hitPosition, float attackStrength);
/// Get the chance (in percent) for \a attacker to successfully hit \a victim with a given weapon skill value
float getHitChance (const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim, int skillValue);

@ -123,6 +123,7 @@ namespace MWWorld
state.mVelocity = orient * osg::Vec3f(0,1,0) * speed;
state.mId = projectile.getCellRef().getRefId();
state.mCasterHandle = actor;
state.mAttackStrength = actor.getClass().getCreatureStats(actor).getAttackStrength();
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), projectile.getCellRef().getRefId());
MWWorld::Ptr ptr = ref.getPtr();
@ -245,7 +246,7 @@ namespace MWWorld
if (caster.isEmpty())
caster = result.mHitObject;
MWMechanics::projectileHit(caster, result.mHitObject, bow, projectileRef.getPtr(), result.mHitPos);
MWMechanics::projectileHit(caster, result.mHitObject, bow, projectileRef.getPtr(), result.mHitPos, it->mAttackStrength);
mParent->removeChild(it->mNode);
@ -286,6 +287,7 @@ namespace MWWorld
state.mBowId = it->mBowId;
state.mVelocity = it->mVelocity;
state.mAttackStrength = it->mAttackStrength;
state.save(writer);
@ -327,6 +329,7 @@ namespace MWWorld
state.mBowId = esm.mBowId;
state.mVelocity = esm.mVelocity;
state.mId = esm.mId;
state.mAttackStrength = esm.mAttackStrength;
std::string model;
try

@ -108,6 +108,7 @@ namespace MWWorld
std::string mBowId;
osg::Vec3f mVelocity;
float mAttackStrength;
};
std::vector<MagicBoltState> mMagicBolts;

@ -52,6 +52,7 @@ namespace ESM
esm.writeHNString ("BOW_", mBowId);
esm.writeHNT ("VEL_", mVelocity);
esm.writeHNT ("STR_", mAttackStrength);
}
void ProjectileState::load(ESMReader &esm)
@ -60,6 +61,9 @@ namespace ESM
mBowId = esm.getHNString ("BOW_");
esm.getHNT (mVelocity, "VEL_");
mAttackStrength = 1.f;
esm.getHNOT(mAttackStrength, "STR_");
}
}

@ -45,6 +45,7 @@ namespace ESM
{
std::string mBowId;
Vector3 mVelocity;
float mAttackStrength;
void load (ESMReader &esm);
void save (ESMWriter &esm) const;

Loading…
Cancel
Save