From 691ba02115d49f36a3dae68bcb9b649f7f200544 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 20 Jul 2014 14:12:27 +0200 Subject: [PATCH] Reduce wepaon condition even if attack misses --- apps/openmw/mwclass/creature.cpp | 17 +++++++++++++++++ apps/openmw/mwclass/npc.cpp | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index e78134802..d521b1b33 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -254,6 +254,23 @@ namespace MWClass if((::rand()/(RAND_MAX+1.0)) > hitchance/100.0f) { victim.getClass().onHit(victim, 0.0f, false, MWWorld::Ptr(), ptr, false); + + // Weapon health is reduced by 1 even if the attack misses + const bool weaphashealth = !weapon.isEmpty() && weapon.getClass().hasItemHealth(weapon); + if(weaphashealth) + { + int weaphealth = weapon.getClass().getItemHealth(weapon); + + if (!MWBase::Environment::get().getWorld()->getGodModeState()) + { + weaphealth -= std::min(1, weaphealth); + weapon.getCellRef().setCharge(weaphealth); + } + + // Weapon broken? unequip it + if (weapon.getCellRef().getCharge() == 0) + weapon = *getInventoryStore(ptr).unequipItem(weapon, ptr); + } return; } diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index a5175c1f6..0dc679e1c 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -527,6 +527,24 @@ namespace MWClass if((::rand()/(RAND_MAX+1.0)) > hitchance/100.0f) { othercls.onHit(victim, 0.0f, false, weapon, ptr, false); + + // Weapon health is reduced by 1 even if the attack misses + const bool weaphashealth = !weapon.isEmpty() && weapon.getClass().hasItemHealth(weapon); + if(weaphashealth) + { + int weaphealth = weapon.getClass().getItemHealth(weapon); + + if (!MWBase::Environment::get().getWorld()->getGodModeState()) + { + weaphealth -= std::min(1, weaphealth); + weapon.getCellRef().setCharge(weaphealth); + } + + // Weapon broken? unequip it + if (weaphealth == 0) + weapon = *inv.unequipItem(weapon, ptr); + } + return; }