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

Creature: DoItemCastSpell () allow setting casting item and impact script #1637

Merged
merged 2 commits into from
Apr 14, 2023
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ https://github.com/nwnxee/unified/compare/build8193.35.37...HEAD
- N/A

### Changed
- N/A
- ***ABI BREAKING:*** Creature: DoItemCastSpell() can now override the spell impact script, and set the spell cast item retrieved by GetSpellCastItem().

### Deprecated
- N/A
Expand Down
7 changes: 5 additions & 2 deletions Plugins/Creature/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2850,9 +2850,12 @@ NWNX_EXPORT ArgumentStack DoItemCastSpell(ArgumentStack&& args)
ASSERT_OR_THROW(delay >= 0.0f);
auto projectilePathType = args.extract<int32_t>();
auto projectileSpellID = args.extract<int32_t>();
auto oidItem = args.extract<ObjectID>();
auto impactScript = args.extract<std::string>();
Comment on lines +2853 to +2854
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like your other PR, this is also a breaking ABI change, would be nice to mention it in the changelog.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, my bad! I didn't realize that would be ABI breaking. Can I blame inexperience? I'll note it in the changelog, same with the other PR.


auto *pSpell = Globals::Rules()->m_pSpellArray->GetSpell(spellID);
auto *pTarget = Utils::AsNWSObject(Utils::GetGameObject(oidTarget));
auto *pItem = Utils::AsNWSObject(Utils::GetGameObject(oidItem));
auto *pArea = Utils::AsNWSArea(Utils::GetGameObject(oidArea));

if (!pSpell || (!pTarget && !pArea))
Expand Down Expand Up @@ -2887,9 +2890,9 @@ NWNX_EXPORT ArgumentStack DoItemCastSpell(ArgumentStack&& args)
pSpellScriptData->m_nFeatId = 0xFFFF;
pSpellScriptData->m_oidCaster = pCaster->m_idSelf;
pSpellScriptData->m_oidTarget = pTarget ? pTarget->m_idSelf : Constants::OBJECT_INVALID;
pSpellScriptData->m_oidItem = Constants::OBJECT_INVALID;
pSpellScriptData->m_oidItem = pItem ? pItem->m_idSelf : Constants::OBJECT_INVALID;
pSpellScriptData->m_vTargetPosition = vTargetPosition;
pSpellScriptData->m_sScript = pSpell->m_sImpactScript;
pSpellScriptData->m_sScript = !impactScript.empty() ? CExoString(impactScript) : pSpell->m_sImpactScript;
pSpellScriptData->m_oidArea = oidTargetArea;
pSpellScriptData->m_nItemCastLevel = casterLevel;

Expand Down
8 changes: 6 additions & 2 deletions Plugins/Creature/NWScript/nwnx_creature.nss
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,9 @@ void NWNX_Creature_SetLastKiller(object oCreature, object oKiller);
/// @param fProjectileTime The time in seconds for the projectile to reach the target. 0.0f for no projectile.
/// @param nProjectilePathType A PROJECTILE_PATH_TYPE_* constant.
/// @param nProjectileSpellID An optional spell ID which to use the projectile vfx of. -1 to use nSpellID's projectile vfx.
void NWNX_Creature_DoItemCastSpell(object oCreature, object oTarget, location locTarget, int nSpellID, int nCasterLevel, float fProjectileTime, int nProjectilePathType = PROJECTILE_PATH_TYPE_DEFAULT, int nProjectileSpellID = -1);
/// @param oItem The spell cast item retrieved by GetSpellCastItem().
/// @param sImpactScript The spell impact script. Set to "****"" to not run any impact script. If left blank, will execute nSpellID's impact script.
void NWNX_Creature_DoItemCastSpell(object oCreature, object oTarget, location locTarget, int nSpellID, int nCasterLevel, float fProjectileTime, int nProjectilePathType = PROJECTILE_PATH_TYPE_DEFAULT, int nProjectileSpellID = -1, object oItem = OBJECT_INVALID, string sImpactScript = "");

/// @brief Have oCreature instantly equip oItem to nInventorySlot.
/// @param oCreature The creature.
Expand Down Expand Up @@ -2307,13 +2309,15 @@ void NWNX_Creature_SetLastKiller(object oCreature, object oKiller)
NWNX_CallFunction(NWNX_Creature, sFunc);
}

void NWNX_Creature_DoItemCastSpell(object oCreature, object oTarget, location locTarget, int nSpellID, int nCasterLevel, float fProjectileTime, int nProjectilePathType = PROJECTILE_PATH_TYPE_DEFAULT, int nProjectileSpellID = -1)
void NWNX_Creature_DoItemCastSpell(object oCreature, object oTarget, location locTarget, int nSpellID, int nCasterLevel, float fProjectileTime, int nProjectilePathType = PROJECTILE_PATH_TYPE_DEFAULT, int nProjectileSpellID = -1, object oItem = OBJECT_INVALID, string sImpactScript = "")
{
string sFunc = "DoItemCastSpell";

object oArea = GetAreaFromLocation(locTarget);
vector vPosition = GetPositionFromLocation(locTarget);

NWNX_PushArgumentString(sImpactScript);
NWNX_PushArgumentObject(oItem);
NWNX_PushArgumentInt(nProjectileSpellID);
NWNX_PushArgumentInt(nProjectilePathType);
NWNX_PushArgumentFloat(fProjectileTime);
Expand Down