-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1642 from summonFox/Tweaks-RangedWeaponsUseOnHitI…
…temProperties Tweaks: Add `NWNX_TWEAKS_RANGED_WEAPONS_USE_ON_HIT_EFFECT_ITEM_PROPERTIES`
- Loading branch information
Showing
4 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
Plugins/Tweaks/RangedWeaponsUseOnHitEffectItemProperties.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "nwnx.hpp" | ||
|
||
#include "API/CNWSCreature.hpp" | ||
#include "API/CNWSCombatRound.hpp" | ||
#include "API/CNWSItem.hpp" | ||
#include "API/CNWBaseItemArray.hpp" | ||
#include "API/CNWBaseItem.hpp" | ||
#include "API/CNWRules.hpp" | ||
|
||
namespace Tweaks { | ||
|
||
using namespace NWNXLib; | ||
using namespace NWNXLib::API; | ||
|
||
void RangedWeaponsUseOnHitEffectItemProperties() __attribute__((constructor)); | ||
void RangedWeaponsUseOnHitEffectItemProperties() | ||
{ | ||
if (!Config::Get<bool>("RANGED_WEAPONS_USE_ON_HIT_EFFECT_ITEM_PROPERTIES", false)) | ||
return; | ||
|
||
LOG_INFO("Ranged weapons will use On Hit: Effect item properties."); | ||
|
||
static Hooks::Hook s_ResolveOnHitEffectHook = Hooks::HookFunction(&CNWSCreature::ResolveOnHitEffect, | ||
(void*)+[](CNWSCreature *pCreature, CNWSObject *pTarget, BOOL bOffHandAttack, BOOL bCritical) -> void | ||
{ | ||
if (auto *pCombatRound = pCreature->m_pcCombatRound) | ||
{ | ||
if (auto *pWeapon = pCombatRound->GetCurrentAttackWeapon(pCombatRound->GetWeaponAttackType())) | ||
{ | ||
auto nBaseItem = pWeapon->m_nBaseItem; | ||
|
||
if (nBaseItem == Constants::BaseItem::HeavyCrossbow || | ||
nBaseItem == Constants::BaseItem::LightCrossbow || | ||
nBaseItem == Constants::BaseItem::Longbow || | ||
nBaseItem == Constants::BaseItem::Shortbow || | ||
nBaseItem == Constants::BaseItem::Sling) | ||
{ | ||
pWeapon->m_nBaseItem = Constants::BaseItem::Shortsword; | ||
s_ResolveOnHitEffectHook->CallOriginal<void>(pCreature, pTarget, bOffHandAttack, bCritical); | ||
pWeapon->m_nBaseItem = nBaseItem; | ||
} | ||
} | ||
} | ||
|
||
s_ResolveOnHitEffectHook->CallOriginal<void>(pCreature, pTarget, bOffHandAttack, bCritical); | ||
|
||
}, Hooks::Order::Earliest); | ||
} | ||
|
||
} | ||
|