forked from teamnwah/openmw-tes3coop
Fix projectile hit bug where the incorrect attackStrength would be used if a new attack has been performed in the meantime
This commit is contained in:
parent
4ef6aa6b7f
commit
5bc6513e2d
6 changed files with 14 additions and 7 deletions
|
@ -166,13 +166,11 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
|
|
||||||
void projectileHit(const MWWorld::Ptr &attacker, const MWWorld::Ptr &victim, MWWorld::Ptr weapon, const MWWorld::Ptr &projectile,
|
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();
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||||
const MWWorld::Store<ESM::GameSetting> &gmst = world->getStore().get<ESM::GameSetting>();
|
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())
|
if(victim.isEmpty() || !victim.getClass().isActor() || victim.getClass().getCreatureStats(victim).isDead())
|
||||||
// Can't hit non-actors or dead actors
|
// 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;
|
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
|
// Arrow/bolt damage
|
||||||
// NB in case of thrown weapons, we are applying the damage twice since projectile == weapon
|
// NB in case of thrown weapons, we are applying the damage twice since projectile == weapon
|
||||||
attack = projectile.get<ESM::Weapon>()->mBase->mData.mChop;
|
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);
|
adjustWeaponDamage(damage, weapon, attacker);
|
||||||
reduceWeaponCondition(damage, true, 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 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
|
/// @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,
|
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
|
/// 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);
|
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.mVelocity = orient * osg::Vec3f(0,1,0) * speed;
|
||||||
state.mId = projectile.getCellRef().getRefId();
|
state.mId = projectile.getCellRef().getRefId();
|
||||||
state.mCasterHandle = actor;
|
state.mCasterHandle = actor;
|
||||||
|
state.mAttackStrength = actor.getClass().getCreatureStats(actor).getAttackStrength();
|
||||||
|
|
||||||
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), projectile.getCellRef().getRefId());
|
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), projectile.getCellRef().getRefId());
|
||||||
MWWorld::Ptr ptr = ref.getPtr();
|
MWWorld::Ptr ptr = ref.getPtr();
|
||||||
|
@ -245,7 +246,7 @@ namespace MWWorld
|
||||||
if (caster.isEmpty())
|
if (caster.isEmpty())
|
||||||
caster = result.mHitObject;
|
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);
|
mParent->removeChild(it->mNode);
|
||||||
|
|
||||||
|
@ -286,6 +287,7 @@ namespace MWWorld
|
||||||
|
|
||||||
state.mBowId = it->mBowId;
|
state.mBowId = it->mBowId;
|
||||||
state.mVelocity = it->mVelocity;
|
state.mVelocity = it->mVelocity;
|
||||||
|
state.mAttackStrength = it->mAttackStrength;
|
||||||
|
|
||||||
state.save(writer);
|
state.save(writer);
|
||||||
|
|
||||||
|
@ -327,6 +329,7 @@ namespace MWWorld
|
||||||
state.mBowId = esm.mBowId;
|
state.mBowId = esm.mBowId;
|
||||||
state.mVelocity = esm.mVelocity;
|
state.mVelocity = esm.mVelocity;
|
||||||
state.mId = esm.mId;
|
state.mId = esm.mId;
|
||||||
|
state.mAttackStrength = esm.mAttackStrength;
|
||||||
|
|
||||||
std::string model;
|
std::string model;
|
||||||
try
|
try
|
||||||
|
|
|
@ -108,6 +108,7 @@ namespace MWWorld
|
||||||
std::string mBowId;
|
std::string mBowId;
|
||||||
|
|
||||||
osg::Vec3f mVelocity;
|
osg::Vec3f mVelocity;
|
||||||
|
float mAttackStrength;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<MagicBoltState> mMagicBolts;
|
std::vector<MagicBoltState> mMagicBolts;
|
||||||
|
|
|
@ -52,6 +52,7 @@ namespace ESM
|
||||||
|
|
||||||
esm.writeHNString ("BOW_", mBowId);
|
esm.writeHNString ("BOW_", mBowId);
|
||||||
esm.writeHNT ("VEL_", mVelocity);
|
esm.writeHNT ("VEL_", mVelocity);
|
||||||
|
esm.writeHNT ("STR_", mAttackStrength);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectileState::load(ESMReader &esm)
|
void ProjectileState::load(ESMReader &esm)
|
||||||
|
@ -60,6 +61,9 @@ namespace ESM
|
||||||
|
|
||||||
mBowId = esm.getHNString ("BOW_");
|
mBowId = esm.getHNString ("BOW_");
|
||||||
esm.getHNT (mVelocity, "VEL_");
|
esm.getHNT (mVelocity, "VEL_");
|
||||||
|
|
||||||
|
mAttackStrength = 1.f;
|
||||||
|
esm.getHNOT(mAttackStrength, "STR_");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ namespace ESM
|
||||||
{
|
{
|
||||||
std::string mBowId;
|
std::string mBowId;
|
||||||
Vector3 mVelocity;
|
Vector3 mVelocity;
|
||||||
|
float mAttackStrength;
|
||||||
|
|
||||||
void load (ESMReader &esm);
|
void load (ESMReader &esm);
|
||||||
void save (ESMWriter &esm) const;
|
void save (ESMWriter &esm) const;
|
||||||
|
|
Loading…
Reference in a new issue