Skip to content

Commit

Permalink
Race: Suppress and Reactive for temp disabling nwnx_race effects (#1784)
Browse files Browse the repository at this point in the history
* Race: Suppress and Reactive for temp disabling nwnx_race effects

* Revert Race-effect removal method
  • Loading branch information
WilliamDraco authored Oct 22, 2024
1 parent c176945 commit 8c56c4e
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ https://github.com/nwnxee/unified/compare/build8193.36.12...HEAD
- Store: {Get|Set}MarkUp()
- Player: ReloadTlk()
- Player: ReloadColorPalettes()
- Race: SuppressCreatureRaceEffects()
- Race: ReactivateCreatureRaceEffects()

### Changed
- Player: added bChatWindow parameter to FloatingTextStringOnCreature()
Expand Down
26 changes: 26 additions & 0 deletions Plugins/Race/NWScript/nwnx_race.nss
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ int NWNX_Race_GetParentRace(int iRace);
/// or Favored Enemy: Wild Elf
void NWNX_Race_SetFavoredEnemyFeat(int iRace, int iFeat);

/// @brief Removes any nwnx_race 'Effects' on the targeted creature. Suppression lasts until levelup, next login, or Reactivated by function.
/// @param oCreature The creature to suppress
/// @note Not all nwnx_race modifiers are achieved via effect. Those that are not directly consider the creatures current race.
void NWNX_Race_SuppressCreatureRaceEffects(object oCreature);

/// @brief Reactivates the nwnx_race 'Effects' on the targeted creature after they were Suppressed.
/// @param oCreature The creature to reactive
/// @note Safe to use on non-suppressed creatures - Triggers a refresh of effects but won't stack.
void NWNX_Race_ReactivateCreatureRaceEffects(object oCreature);

/// @}

void NWNX_Race_SetRacialModifier(int iRace, int iMod, int iParam1, int iParam2 = 0xDEADBEEF, int iParam3 = 0xDEADBEEF)
Expand Down Expand Up @@ -88,3 +98,19 @@ void NWNX_Race_SetFavoredEnemyFeat(int iRace, int iFeat)

NWNX_CallFunction(NWNX_Race, sFunc);
}

void NWNX_Race_SuppressCreatureRaceEffects(object creature)
{
string sFunc = "SuppressCreatureRaceEffects";

NWNX_PushArgumentObject(creature);
NWNX_CallFunction(NWNX_Race, sFunc);
}

void NWNX_Race_ReactivateCreatureRaceEffects(object oCreature)
{
string sFunc = "ReactivateCreatureRaceEffects";

NWNX_PushArgumentObject(oCreature);
NWNX_CallFunction(NWNX_Race, sFunc);
}
51 changes: 40 additions & 11 deletions Plugins/Race/Race.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,27 @@ void Race::DoEffect(CNWSCreature *pCreature,
pCreature->ApplyEffect(eff, true, true);
}

void Race::RemoveRaceEffects(CNWSCreature *pCreature)
{
auto effectsLevelAdded = *pCreature->nwnxGet<int>("RACEMODS_ADDED_LEVEL");
if (pCreature->m_pStats == nullptr || effectsLevelAdded == 0)
return;

std::vector<uint64_t> remove(128);
for (int i = pCreature->m_appliedEffects.num; i >= 0; --i)
{
auto eff = (CGameEffect*)pCreature->m_appliedEffects.element[i];
if (eff->m_sCustomTag == "NWNX_Race_RacialMod")
{
remove.push_back(eff->m_nID);
}
}
for (auto id: remove)
pCreature->RemoveEffectById(id);

pCreature->nwnxRemove("RACEMODS_ADDED_LEVEL");
}

void Race::ApplyRaceEffects(CNWSCreature *pCreature)
{
auto effectsLevelAdded = *pCreature->nwnxGet<int>("RACEMODS_ADDED_LEVEL");
Expand All @@ -192,17 +213,7 @@ void Race::ApplyRaceEffects(CNWSCreature *pCreature)
// the racial modifiers.
if (effectsLevelAdded)
{
std::vector<uint64_t> remove(128);
for (int i = 0; i < pCreature->m_appliedEffects.num; i++)
{
auto eff = (CGameEffect*)pCreature->m_appliedEffects.element[i];
if (eff->m_sCustomTag == "NWNX_Race_RacialMod")
{
remove.push_back(eff->m_nID);
}
}
for (auto id: remove)
pCreature->RemoveEffectById(id);
RemoveRaceEffects(pCreature);
}

// AB
Expand Down Expand Up @@ -1190,6 +1201,24 @@ ArgumentStack Race::SetFavoredEnemyFeat(ArgumentStack&& args)
return ScriptAPI::Arguments();
}

NWNX_EXPORT ArgumentStack Race::SuppressCreatureRaceEffects(ArgumentStack&& args)
{
if(auto* pCreature = Utils::PopCreature(args))
{
RemoveRaceEffects(pCreature);
}
return {};
}

NWNX_EXPORT ArgumentStack Race::ReactivateCreatureRaceEffects(ArgumentStack&& args)
{
if(auto* pCreature = Utils::PopCreature(args))
{
ApplyRaceEffects(pCreature);
}
return {};
}

int32_t Race::GetAttackModifierVersusHook(CNWSCreatureStats* pStats, CNWSCreature* pCreature)
{
int32_t modABVSRaceBonus = 0;
Expand Down
3 changes: 3 additions & 0 deletions Plugins/Race/Race.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Race : public NWNXLib::Plugin
ArgumentStack SetRacialModifier(ArgumentStack&& args);
ArgumentStack GetParentRace(ArgumentStack&& args);
ArgumentStack SetFavoredEnemyFeat(ArgumentStack&& args);
ArgumentStack SuppressCreatureRaceEffects(ArgumentStack&& args);
ArgumentStack ReactivateCreatureRaceEffects(ArgumentStack&& args);

enum RaceModifier
{
Expand Down Expand Up @@ -80,6 +82,7 @@ class Race : public NWNXLib::Plugin


static void DoEffect(CNWSCreature*, uint16_t, int32_t, int32_t = 0, int32_t = 0, int32_t = 0, int32_t = 0, int32_t = 0);
static void RemoveRaceEffects(CNWSCreature*);
static void ApplyRaceEffects(CNWSCreature*);
static void SetOrRestoreRace(bool, CNWSCreatureStats*, CNWSCreatureStats* = nullptr);
static void SetRaceModifier(int32_t, RaceModifier, int32_t, int32_t, int32_t);
Expand Down

0 comments on commit 8c56c4e

Please sign in to comment.