|
|
|
@ -169,12 +169,12 @@ namespace MWMechanics
|
|
|
|
|
|
|
|
|
|
MWMechanics::CreatureStats& attackerStats = attacker.getClass().getCreatureStats(attacker);
|
|
|
|
|
|
|
|
|
|
const MWWorld::Class &othercls = victim.getClass();
|
|
|
|
|
if(!othercls.isActor()) // Can't hit non-actors
|
|
|
|
|
return;
|
|
|
|
|
MWMechanics::CreatureStats &otherstats = victim.getClass().getCreatureStats(victim);
|
|
|
|
|
if(otherstats.isDead()) // Can't hit dead actors
|
|
|
|
|
if(victim.isEmpty() || !victim.getClass().isActor() || victim.getClass().getCreatureStats(victim).isDead())
|
|
|
|
|
// Can't hit non-actors or dead actors
|
|
|
|
|
{
|
|
|
|
|
reduceWeaponCondition(0.f, false, weapon, attacker);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(attacker.getRefData().getHandle() == "player")
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->setEnemy(victim);
|
|
|
|
@ -189,6 +189,7 @@ namespace MWMechanics
|
|
|
|
|
if((::rand()/(RAND_MAX+1.0)) > getHitChance(attacker, victim, skillValue)/100.0f)
|
|
|
|
|
{
|
|
|
|
|
victim.getClass().onHit(victim, 0.0f, false, projectile, attacker, false);
|
|
|
|
|
MWMechanics::reduceWeaponCondition(0.f, false, weapon, attacker);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -209,6 +210,8 @@ namespace MWMechanics
|
|
|
|
|
damage *= fDamageStrengthBase +
|
|
|
|
|
(attackerStats.getAttribute(ESM::Attribute::Strength).getModified() * fDamageStrengthMult * 0.1);
|
|
|
|
|
|
|
|
|
|
adjustWeaponDamage(damage, weapon);
|
|
|
|
|
reduceWeaponCondition(damage, true, weapon, attacker);
|
|
|
|
|
|
|
|
|
|
if(attacker.getRefData().getHandle() == "player")
|
|
|
|
|
attacker.getClass().skillUsageSucceeded(attacker, weapskill, 0);
|
|
|
|
@ -295,4 +298,42 @@ namespace MWMechanics
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void reduceWeaponCondition(float damage, bool hit, MWWorld::Ptr &weapon, const MWWorld::Ptr &attacker)
|
|
|
|
|
{
|
|
|
|
|
if (weapon.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!hit)
|
|
|
|
|
damage = 0.f;
|
|
|
|
|
|
|
|
|
|
const bool weaphashealth = weapon.getClass().hasItemHealth(weapon);
|
|
|
|
|
if(weaphashealth)
|
|
|
|
|
{
|
|
|
|
|
int weaphealth = weapon.getClass().getItemHealth(weapon);
|
|
|
|
|
|
|
|
|
|
const float fWeaponDamageMult = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fWeaponDamageMult")->getFloat();
|
|
|
|
|
float x = std::max(1.f, fWeaponDamageMult * damage);
|
|
|
|
|
|
|
|
|
|
weaphealth -= std::min(int(x), weaphealth);
|
|
|
|
|
weapon.getCellRef().setCharge(weaphealth);
|
|
|
|
|
|
|
|
|
|
// Weapon broken? unequip it
|
|
|
|
|
if (weaphealth == 0)
|
|
|
|
|
weapon = *attacker.getClass().getInventoryStore(attacker).unequipItem(weapon, attacker);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void adjustWeaponDamage(float &damage, const MWWorld::Ptr &weapon)
|
|
|
|
|
{
|
|
|
|
|
if (weapon.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const bool weaphashealth = weapon.getClass().hasItemHealth(weapon);
|
|
|
|
|
if(weaphashealth)
|
|
|
|
|
{
|
|
|
|
|
int weaphealth = weapon.getClass().getItemHealth(weapon);
|
|
|
|
|
int weapmaxhealth = weapon.getClass().getItemMaxHealth(weapon);
|
|
|
|
|
damage *= (float(weaphealth) / weapmaxhealth);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|