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

Add GetReactState to CreatureMethods and GetKnownTaxiNodes, SetKnownTaxiNodes to PlayerMethods #260

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions src/LuaEngine/LuaFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,8 @@ ElunaRegister<Player> PlayerMethods[] =
{ "SetLifetimeKills", &LuaPlayer::SetLifetimeKills },
{ "SetGameMaster", &LuaPlayer::SetGameMaster },
{ "SetGMChat", &LuaPlayer::SetGMChat },
{ "GetKnownTaxiNodes", &LuaPlayer::GetKnownTaxiNodes },
{ "SetKnownTaxiNodes", &LuaPlayer::SetKnownTaxiNodes },
{ "SetTaxiCheat", &LuaPlayer::SetTaxiCheat },
{ "SetGMVisible", &LuaPlayer::SetGMVisible },
{ "SetPvPDeath", &LuaPlayer::SetPvPDeath },
Expand Down Expand Up @@ -799,6 +801,7 @@ ElunaRegister<Creature> CreatureMethods[] =
{ "SetNPCFlags", &LuaCreature::SetNPCFlags },
{ "SetUnitFlags", &LuaCreature::SetUnitFlags },
{ "SetUnitFlagsTwo", &LuaCreature::SetUnitFlagsTwo },
{ "GetReactState", &LuaCreature::GetReactState },
{ "SetReactState", &LuaCreature::SetReactState },
{ "SetDeathState", &LuaCreature::SetDeathState },
{ "SetWalk", &LuaCreature::SetWalk },
Expand Down
12 changes: 12 additions & 0 deletions src/LuaEngine/methods/CreatureMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,18 @@ namespace LuaCreature
return 0;
}

/**
* Gets the [Creature]'s current ReactState.
*
* @return [ReactState] The current react state of the creature.
*/
int GetReactState(lua_State* L, Creature* creature)
{
ReactStates state = creature->GetReactState();
lua_pushinteger(L, (int)state);
return 1;
}

/**
* Sets the [Creature]'s ReactState to `state`.
*
Expand Down
66 changes: 66 additions & 0 deletions src/LuaEngine/methods/PlayerMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,40 @@ namespace LuaPlayer
return 1;
}

/**
* Returns known taxi nodes (flight paths) that the player has unlocked.
*
* @return table<int> A table containing the IDs of the known taxi nodes.
*/
int GetKnownTaxiNodes(lua_State* L, Player* player)
{
if (!player)
return 0;

lua_newtable(L);

ByteBuffer data;
player->m_taxi.AppendTaximaskTo(data, false);

for (uint8 i = 0; i < TaxiMaskSize; i++)
{
uint32 mask;
data >> mask;

for (uint8 bit = 0; bit < 32; bit++)
{
if (mask & (1 << bit))
{
uint8 nodeId = (i * 32) + bit + 1;
lua_pushinteger(L, nodeId);
lua_rawseti(L, -2, luaL_len(L, -2) + 1);
}
}
}

return 1;
}

/*int GetRecruiterId(lua_State* L, Player* player)
{
Eluna::Push(L, player->GetSession()->GetRecruiterId());
Expand Down Expand Up @@ -1893,6 +1927,38 @@ namespace LuaPlayer
return 0;
}

/**
* Sets the player's known taxi nodes (flight paths).
*
* @param table<int> A table containing the taxi node IDs to set as known.
*/
int SetKnownTaxiNodes(lua_State* L, Player* player)
{
if (!player)
return 0;

if (!lua_istable(L, 2))
{
return 0;
}

lua_pushnil(L);

while (lua_next(L, 2) != 0)
{
uint32 nodeId = luaL_checkinteger(L, -1);

if (nodeId > 0)
{
player->m_taxi.SetTaximaskNode(nodeId);
}

lua_pop(L, 1);
}

return 0;
}

/**
* Toggles whether the [Player] has taxi cheat enabled or not
*
Expand Down