-
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 #1641 from summonFox/Tweaks--Ranged-weapons-cast-o…
…n-hit-spells Tweaks: Add `NWNX_TWEAKS_RANGED_WEAPONS_USE_ON_HIT_CAST_SPELL_ITEM_PROPERTIES`
- Loading branch information
Showing
4 changed files
with
54 additions
and
1 deletion.
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/RangedWeaponsUseOnHitCastSpellItemProperties.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 RangedWeaponsUseOnHitCastSpellItemProperties() __attribute__((constructor)); | ||
void RangedWeaponsUseOnHitCastSpellItemProperties() | ||
{ | ||
if (!Config::Get<bool>("RANGED_WEAPONS_USE_ON_HIT_CAST_SPELL_ITEM_PROPERTIES", false)) | ||
return; | ||
|
||
LOG_INFO("Ranged weapons will use On Hit: Cast Spell item properties"); | ||
|
||
static Hooks::Hook s_ResolveItemCastSpellHook = Hooks::HookFunction(&CNWSCreature::ResolveItemCastSpell, | ||
(void*)+[](CNWSCreature *pCreature, CNWSObject *pTarget) -> 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_ResolveItemCastSpellHook->CallOriginal<void>(pCreature, pTarget); | ||
pWeapon->m_nBaseItem = nBaseItem; | ||
} | ||
} | ||
} | ||
|
||
s_ResolveItemCastSpellHook->CallOriginal<void>(pCreature, pTarget); | ||
|
||
}, Hooks::Order::Earliest); | ||
} | ||
|
||
} | ||
|