From e9c71a3808f966167fd07fe71f43ce62f1dcec3d Mon Sep 17 00:00:00 2001 From: capostrophic Date: Wed, 31 Jul 2019 13:10:51 +0300 Subject: [PATCH] Ignore on-strike enchanted projectile charge (#5104) --- CHANGELOG.md | 1 + apps/openmw/mwmechanics/spellcasting.cpp | 25 ++++++++++------------ apps/openmw/mwmechanics/weaponpriority.cpp | 3 ++- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29e310b58..eaa71736f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -115,6 +115,7 @@ Bug #5092: NPCs with enchanted weapons play sound when out of charges Bug #5093: Hand to hand sound plays on knocked out enemies Bug #5099: Non-swimming enemies will enter water if player is water walking + Bug #5104: Black Dart's enchantment doesn't trigger at low Enchant levels Bug #5105: NPCs start combat with werewolves from any distance Bug #5110: ModRegion with a redundant numerical argument breaks script execution Feature #1774: Handle AvoidNode diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index 2c178a40e..d95d84210 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -823,18 +823,22 @@ namespace MWMechanics mStack = false; bool godmode = mCaster == MWMechanics::getPlayer() && MWBase::Environment::get().getWorld()->getGodModeState(); + bool isProjectile = false; + if (item.getTypeName() == typeid(ESM::Weapon).name()) + { + const ESM::Weapon* ref = item.get()->mBase; + isProjectile = ref->mData.mType >= ESM::Weapon::MarksmanThrown; + } + int type = enchantment->mData.mType; // Check if there's enough charge left - if (enchantment->mData.mType == ESM::Enchantment::WhenUsed || enchantment->mData.mType == ESM::Enchantment::WhenStrikes) + if (!godmode && (type == ESM::Enchantment::WhenUsed || (!isProjectile && type == ESM::Enchantment::WhenStrikes))) { int castCost = getEffectiveEnchantmentCastCost(static_cast(enchantment->mData.mCost), mCaster); if (item.getCellRef().getEnchantmentCharge() == -1) item.getCellRef().setEnchantmentCharge(static_cast(enchantment->mData.mCharge)); - if (godmode) - castCost = 0; - if (item.getCellRef().getEnchantmentCharge() < castCost) { if (mCaster == getPlayer()) @@ -862,17 +866,17 @@ namespace MWMechanics item.getCellRef().setEnchantmentCharge(item.getCellRef().getEnchantmentCharge() - castCost); } - if (enchantment->mData.mType == ESM::Enchantment::WhenUsed) + if (type == ESM::Enchantment::WhenUsed) { if (mCaster == getPlayer()) mCaster.getClass().skillUsageSucceeded (mCaster, ESM::Skill::Enchant, 1); } - else if (enchantment->mData.mType == ESM::Enchantment::CastOnce) + else if (type == ESM::Enchantment::CastOnce) { if (!godmode) item.getContainerStore()->remove(item, 1, mCaster); } - else if (enchantment->mData.mType == ESM::Enchantment::WhenStrikes) + else if (type == ESM::Enchantment::WhenStrikes) { if (mCaster == getPlayer()) mCaster.getClass().skillUsageSucceeded (mCaster, ESM::Skill::Enchant, 3); @@ -880,13 +884,6 @@ namespace MWMechanics inflict(mCaster, mCaster, enchantment->mEffects, ESM::RT_Self); - bool isProjectile = false; - if (item.getTypeName() == typeid(ESM::Weapon).name()) - { - const MWWorld::LiveCellRef *ref = item.get(); - isProjectile = ref->mBase->mData.mType == ESM::Weapon::Arrow || ref->mBase->mData.mType == ESM::Weapon::Bolt || ref->mBase->mData.mType == ESM::Weapon::MarksmanThrown; - } - if (isProjectile || !mTarget.isEmpty()) inflict(mTarget, mCaster, enchantment->mEffects, ESM::RT_Touch); diff --git a/apps/openmw/mwmechanics/weaponpriority.cpp b/apps/openmw/mwmechanics/weaponpriority.cpp index 118c0297f..37f37d4c7 100644 --- a/apps/openmw/mwmechanics/weaponpriority.cpp +++ b/apps/openmw/mwmechanics/weaponpriority.cpp @@ -102,8 +102,9 @@ namespace MWMechanics if (enchantment->mData.mType == ESM::Enchantment::WhenStrikes) { int castCost = getEffectiveEnchantmentCastCost(static_cast(enchantment->mData.mCost), actor); + float charge = item.getCellRef().getEnchantmentCharge(); - if (item.getCellRef().getEnchantmentCharge() == -1 || item.getCellRef().getEnchantmentCharge() >= castCost) + if (charge == -1 || charge >= castCost || weapon->mData.mType >= ESM::Weapon::MarksmanThrown) rating += rateEffects(enchantment->mEffects, actor, enemy); } }