Skip to content

Commit

Permalink
feat(LuaEngine/UnitMethods): add GetThreat, ClearThreat, ResetAllThre…
Browse files Browse the repository at this point in the history
…at methods (#234)
  • Loading branch information
iThorgrim authored Feb 1, 2025
1 parent 8ebf1f4 commit 0fda6f8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/LuaEngine/LuaFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ ElunaRegister<Unit> UnitMethods[] =
// {"GetVehicle", &LuaUnit::GetVehicle}, // :GetVehicle() - UNDOCUMENTED - Gets the Vehicle kit of the vehicle the unit is on
{ "GetMovementType", &LuaUnit::GetMovementType },
{ "GetAttackers", &LuaUnit::GetAttackers },
{ "GetThreat", &LuaUnit::GetThreat },

// Setters
{ "SetFaction", &LuaUnit::SetFaction },
Expand Down Expand Up @@ -454,6 +455,8 @@ ElunaRegister<Unit> UnitMethods[] =
{ "DealHeal", &LuaUnit::DealHeal },
{ "AddThreat", &LuaUnit::AddThreat },
{ "ModifyThreatPct", &LuaUnit::ModifyThreatPct },
{ "ClearThreat", &LuaUnit::ClearThreat },
{ "ResetAllThreat", &LuaUnit::ResetAllThreat },

{ NULL, NULL }
};
Expand Down
36 changes: 36 additions & 0 deletions src/LuaEngine/methods/UnitMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -2714,5 +2714,41 @@ namespace LuaUnit
Eluna::Push(L, summon);
return 1;
}*/

/**
* Clear the threat of a [Unit] in the threat list.
*
* @param [Unit] target
*/
int ClearThreat(lua_State* L, Unit* unit)
{
Unit* target = Eluna::CHECKOBJ<Unit>(L, 2);

unit->GetThreatMgr().ClearThreat(target);
return 0;
}

/**
* Resets the [Unit]'s threat list, setting all threat targets' threat to 0.
*/
int ResetAllThreat(lua_State* /*L*/, Unit* unit)
{
unit->GetThreatMgr().ResetAllThreat();
return 0;
}

/**
* Returns the threat of a [Unit].
*
* @param [Unit] target
* @return float threat
*/
int GetThreat(lua_State* L, Unit* unit)
{
Unit* target = Eluna::CHECKOBJ<Unit>(L, 2);

Eluna::Push(L, unit->GetThreatMgr().GetThreat(target));
return 1;
}
};
#endif

0 comments on commit 0fda6f8

Please sign in to comment.