Skip to content

Commit

Permalink
Tweaks: add NWNX_TWEAKS_UNHARDCODE_SPECIAL_ABILITY_TARGET_TYPE (#1817)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daztek authored Feb 10, 2025
1 parent 2f18b7c commit b8b5d41
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ https://github.com/nwnxee/unified/compare/build8193.37.13...HEAD

### Added
- Tweaks: added `NWNX_TWEAKS_RESIST_ENERGY_STACKS_WITH_EPIC_ENERGY_RESISTANCE` to make Resist Energy feats stack with Epic Energy Resistance.
- Tweaks: added `NWNX_TWEAKS_UNHARDCODE_SPECIAL_ABILITY_TARGET_TYPE` to allow special abilities to be used on target types other than creatures.

##### New Plugins
- N/A
Expand Down
3 changes: 2 additions & 1 deletion Plugins/Tweaks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ add_plugin(Tweaks
"EquipUnequipEventTweaks.cpp"
"CutsceneModeNoTURD.cpp"
"CanUseItemsWhilePolymorphed.cpp"
"ResistEnergyStacksWithEpicEnergyResistance.cpp")
"ResistEnergyStacksWithEpicEnergyResistance.cpp"
"UnhardcodeSpecialAbilityTargetType.cpp")
1 change: 1 addition & 0 deletions Plugins/Tweaks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Tweaks stuff. See below.
| `NWNX_TWEAKS_CUTSCENE_MODE_NO_TURD` | true or false | SetCutsceneMode() will not cause a TURD to be dropped. |
| `NWNX_TWEAKS_CAN_USE_ITEMS_WHILE_POLYMORPHED` | true or false | Allow all items to be used while polymorphed. |
| `NWNX_TWEAKS_RESIST_ENERGY_STACKS_WITH_EPIC_ENERGY_RESISTANCE` | true or false | Resist Energy feats stack with Epic Energy Resistance. |
| `NWNX_TWEAKS_UNHARDCODE_SPECIAL_ABILITY_TARGET_TYPE` | true or false | Allows special abilities to be used on target types other than creatures. |

## Environment variable values

Expand Down
71 changes: 71 additions & 0 deletions Plugins/Tweaks/UnhardcodeSpecialAbilityTargetType.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include "nwnx.hpp"
#include "API/CNWSArea.hpp"
#include "API/CNWSCreature.hpp"
#include "API/CAppManager.hpp"
#include "API/CServerExoApp.hpp"


namespace Tweaks {

using namespace NWNXLib;
using namespace NWNXLib::API;

void UnhardcodeSpecialAbilityTargetType() __attribute__((constructor));
void UnhardcodeSpecialAbilityTargetType()
{
if (!Config::Get<bool>("UNHARDCODE_SPECIAL_ABILITY_TARGET_TYPE", false))
return;

LOG_INFO("Special abilities can also be used on target types other than creatures.");

static Hooks::Hook s_AddUseTalentOnObjectActionsHook = Hooks::HookFunction(&CNWSCreature::AddUseTalentOnObjectActions,
+[](CNWSCreature *pThis, int32_t nType, int32_t nId, OBJECT_ID oidTarget, uint8_t nMultiClass, OBJECT_ID oidItem,
int32_t nItemPropertyIndex, uint8_t nCasterLevel, uint8_t nMetaType) -> int32_t
{
auto *pTargetObject = Utils::AsNWSObject(Utils::GetGameObject(oidTarget));
if ((nType == 0 && !pTargetObject) || (nType != 0 && !Utils::AsNWSCreature(pTargetObject)))
return false;
if (!pThis->m_bAbleToModifyActionQueue)
return false;

const Vector vTargetLocation = pTargetObject->m_vPosition;
ObjectID oidTargetArea;
if (auto *pArea = pThis->GetArea())
oidTargetArea = pArea->m_idSelf;
else
oidTargetArea = Constants::OBJECT_INVALID;

switch (nType)
{
case 0: // TALENT_TYPE_SPELL
{
if (oidItem != Constants::OBJECT_INVALID && nItemPropertyIndex != -1)
pThis->UseItem(oidItem, nItemPropertyIndex, 0, oidTarget, vTargetLocation, oidTargetArea);
else
{
pThis->AddCastSpellActions(nId, nMultiClass, 0, nMetaType, false, vTargetLocation, oidTarget,
false, false, false, 0, false, false, -1, nCasterLevel);
}
break;
}
case 1: // TALENT_TYPE_FEAT
{
uint16_t nSubFeat = 0;
if (nId == Constants::Feat::CalledShot)
nSubFeat = rand() % 2 ? 65001 : 65000;
pThis->UseFeat(nId, nSubFeat, oidTarget, oidTargetArea);
break;
}
case 2: // TALENT_TYPE_SKILL
{
pThis->UseSkill(nId, 0, oidTarget, vTargetLocation, oidTargetArea);
break;
}
default: break;
}

return true;
}, Hooks::Order::Final);
}

}

0 comments on commit b8b5d41

Please sign in to comment.