Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweaks: add NWNX_TWEAKS_UNHARDCODE_SPECIAL_ABILITY_TARGET_TYPE #1817

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}

}