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: add DoCleaveAttack #1630

Merged
merged 3 commits into from
Apr 15, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ https://github.com/nwnxee/unified/compare/build8193.35.37...HEAD

##### New NWScript Functions
- Util: GetStringLevenshteinDistance()
- Creature: DoCleaveAttack()
- Creature: {Get|Set}LockOrientationToObject()
- Creature: BroadcastAttackOfOpportunity()

Expand Down
29 changes: 29 additions & 0 deletions Plugins/Creature/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3305,6 +3305,35 @@ NWNX_EXPORT ArgumentStack SetMaximumBonusAttacks(ArgumentStack&& args)
return {};
}

NWNX_EXPORT ArgumentStack DoCleaveAttack(ArgumentStack&& args)
{
if (auto *pCreature = Utils::PopCreature(args))
{
auto *pCombatRound = pCreature->m_pcCombatRound;

if (pCombatRound->GetTotalAttacks() < 50)
{
bool bHasGreatCleave = pCreature->m_pStats->HasFeat(Constants::Feat::GreatCleave);
if (bHasGreatCleave || (pCreature->m_pStats->HasFeat(Constants::Feat::Cleave) && pCombatRound->m_nCleaveAttacks > 0))
{
float fAttackRange = pCreature->MaxAttackRange(pCreature->m_idSelf, false, true);
auto oidNearestEnemy = pCreature->GetNearestEnemy(fAttackRange, pCreature->m_oidAttackTarget, true, false);
if (oidNearestEnemy != Constants::OBJECT_INVALID)
{
pCombatRound->m_oidNewAttackTarget = oidNearestEnemy;
pCombatRound->AddCleaveAttack(oidNearestEnemy, bHasGreatCleave);
pCreature->m_bPassiveAttackBehaviour = 1;

if (!bHasGreatCleave)
pCombatRound->m_nCleaveAttacks--;
}
}
}
}

return {};
}

NWNX_EXPORT ArgumentStack GetLockOrientationToObject(ArgumentStack&& args)
{
ObjectID retval = Constants::OBJECT_INVALID;
Expand Down
13 changes: 13 additions & 0 deletions Plugins/Creature/NWScript/nwnx_creature.nss
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,11 @@ int NWNX_Creature_GetMaximumBonusAttacks(object oCreature);
/// @note Persistence is enabled after a server reset by the first use of this function. Recommended to trigger on a dummy target OnModuleLoad to enable persistence.
void NWNX_Creature_SetMaximumBonusAttacks(object oCreature, int nMaxBonusAttacks, int bPersist = FALSE);

/// @brief Inserts a cleave or great cleave attack into oCreature's current attack round against the nearest enemy within melee reach.
/// @param oCreature The creature object.
/// @note oCreature must have the cleave or great cleave feats, must be in combat, and must have available attacks remaining in their combat round to use for cleave attack.
void NWNX_Creature_DoCleaveAttack(object oCreature);

/// @brief Gets the current object oCreature's orientation is locked to.
/// @param oCreature The creature object.
/// @return The object oCreature's orientation is locked to, or OBJECT_INVALID if oCreature's orientation is not locked.
Expand Down Expand Up @@ -2483,6 +2488,14 @@ void NWNX_Creature_SetMaximumBonusAttacks(object oCreature, int nMaxBonusAttacks
NWNX_CallFunction(NWNX_Creature, sFunc);
}

void NWNX_Creature_DoCleaveAttack(object oCreature)
{
string sFunc = "DoCleaveAttack";

NWNX_PushArgumentObject(oCreature);
NWNX_CallFunction(NWNX_Creature, sFunc);
}

object NWNX_Creature_GetLockOrientationToObject(object oCreature)
{
string sFunc = "GetLockOrientationToObject";
Expand Down