Skip to content

Commit 61b368a

Browse files
committed
Creature: fix SetBaseAC/GetBaseAC to use m_nACPolymorph when polymorphed
1 parent 51baea6 commit 61b368a

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ https://github.com/nwnxee/unified/compare/build8193.37.13...HEAD
2121
##### New NWScript Functions
2222
- Player: GetOpenStore()
2323
- Creature: GetNumberOfBonusSpells(), ModifyNumberBonusSpells()
24+
- Creature: {Get|Set}BaseACPolymorph()
2425
- Store: GetBlackMarket(), SetBlackMarket()
2526

2627
### Changed
2728
- Damage: Added bRangedAttack to the NWNX_Damage_AttackEventData struct.
2829
- Events: Added ID to the NWNX_ON_ITEMPROPERTY_EFFECT_* events data.
2930
- Utils: Change LOG_INFO to LOG_DEBUG for console commands.
31+
- Creature: GetBaseAC()/SetBaseAC() now include a note that these functions do not affect AC while polymorphed; use Get/SetBaseACPolymorph() instead.
3032

3133
### Deprecated
3234
- N/A

Plugins/Creature/Creature.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,26 @@ NWNX_EXPORT ArgumentStack GetBaseAC(ArgumentStack&& args)
391391
return -1;
392392
}
393393

394+
NWNX_EXPORT ArgumentStack SetBaseACPolymorph(ArgumentStack&& args)
395+
{
396+
if (auto *pCreature = Utils::PopCreature(args))
397+
{
398+
const auto ac = args.extract<int32_t>();
399+
ASSERT_OR_THROW(ac >= -128);
400+
ASSERT_OR_THROW(ac <= 127);
401+
pCreature->m_pStats->m_nACPolymorph = static_cast<int8_t>(ac);
402+
}
403+
return {};
404+
}
405+
406+
NWNX_EXPORT ArgumentStack GetBaseACPolymorph(ArgumentStack&& args)
407+
{
408+
if (auto *pCreature = Utils::PopCreature(args))
409+
return (int32_t)pCreature->m_pStats->m_nACPolymorph;
410+
411+
return -1;
412+
}
413+
394414
NWNX_EXPORT ArgumentStack SetRawAbilityScore(ArgumentStack&& args)
395415
{
396416
if (auto *pCreature = Utils::PopCreature(args))

Plugins/Creature/NWScript/nwnx_creature.nss

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,32 @@ void NWNX_Creature_SetSpecialAbility(object creature, int index, struct NWNX_Cre
173173
/// @return The class id.
174174
int NWNX_Creature_GetClassByLevel(object creature, int level);
175175

176-
/// @brief Sets the base AC for the creature.
176+
/// @brief Sets the base AC of a creature.
177177
/// @param creature The creature object.
178-
/// @param ac The base AC to set for the creature.
178+
/// @param ac The base AC to set.
179+
/// @note While polymorphed, the engine uses a separate variable for AC calculation.
180+
/// Use NWNX_Creature_SetBaseACPolymorph() to get/set AC when the creature is polymorphed.
179181
void NWNX_Creature_SetBaseAC(object creature, int ac);
180182

181-
/// @brief Get the base AC for the creature.
183+
/// @brief Gets the base AC of a creature.
182184
/// @param creature The creature object.
183185
/// @return The base AC.
186+
/// @note While polymorphed, the engine uses a separate variable for AC calculation.
187+
/// Use NWNX_Creature_GetBaseACPolymorph() to get/set AC when the creature is polymorphed.
184188
int NWNX_Creature_GetBaseAC(object creature);
185189

190+
/// @brief Sets the AC of a polymorphed creature.
191+
/// @param creature The creature object.
192+
/// @param ac The AC to set.
193+
/// @note This value is only used by the engine when the creature is polymorphed.
194+
void NWNX_Creature_SetBaseACPolymorph(object creature, int ac);
195+
196+
/// @brief Gets the AC of a polymorphed creature.
197+
/// @param creature The creature object.
198+
/// @return The polymorph AC.
199+
/// @note This value is only used by the engine when the creature is polymorphed.
200+
int NWNX_Creature_GetBaseACPolymorph(object creature);
201+
186202
/// @brief Sets the ability score of the creature to the provided value.
187203
/// @note Does not apply racial bonuses/penalties.
188204
/// @param creature The creature object.

0 commit comments

Comments
 (0)