feat(LuaEngine): Add GetInventoryFreeSlots and GetBankFreeSlots to Player class (#369)

This commit is contained in:
arielcami
2026-03-18 16:35:37 -05:00
committed by GitHub
parent 9ecb0f6d10
commit e665ae2f38
2 changed files with 69 additions and 0 deletions

View File

@@ -478,6 +478,8 @@ ALERegister<Unit> UnitMethods[] =
ALERegister<Player> PlayerMethods[] = ALERegister<Player> PlayerMethods[] =
{ {
// Getters // Getters
{ "GetInventoryFreeSlots", &LuaPlayer::GetInventoryFreeSlots },
{ "GetBankFreeSlots", &LuaPlayer::GetBankFreeSlots },
{ "GetSelection", &LuaPlayer::GetSelection }, { "GetSelection", &LuaPlayer::GetSelection },
{ "GetGMRank", &LuaPlayer::GetGMRank }, { "GetGMRank", &LuaPlayer::GetGMRank },
{ "GetGuildId", &LuaPlayer::GetGuildId }, { "GetGuildId", &LuaPlayer::GetGuildId },

View File

@@ -316,6 +316,73 @@ namespace LuaPlayer
return 1; return 1;
} }
/**
* Returns the number of free slots in the [Player]'s inventory (backpack and equipped bags).
*
* @return uint32 freeSlots
*/
int GetInventoryFreeSlots(lua_State* L, Player* player)
{
uint32 freeSlots = 0;
// Backpack slots in INVENTORY_SLOT_BAG_0 (INVENTORY_SLOT_ITEM_START to INVENTORY_SLOT_ITEM_END)
for (uint8 i = INVENTORY_SLOT_ITEM_START; i < INVENTORY_SLOT_ITEM_END; ++i)
{
if (!player->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
++freeSlots;
}
// Check equipped bags slots (INVENTORY_SLOT_BAG_START to INVENTORY_SLOT_BAG_END)
for (uint8 i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; ++i)
{
if (Bag* bag = player->GetBagByPos(i))
{
for (uint32 j = 0; j < bag->GetBagSize(); ++j)
{
if (!player->GetItemByPos(i, j))
++freeSlots;
}
}
}
ALE::Push(L, freeSlots);
return 1;
}
/**
* Returns the number of free slots in the [Player]'s bank (main bank and bank bags).
*
* @return uint32 freeSlots
*/
int GetBankFreeSlots(lua_State* L, Player* player)
{
uint32 freeSlots = 0;
// Check main bank slots (BANK_SLOT_ITEM_START to BANK_SLOT_ITEM_END)
for (uint8 i = BANK_SLOT_ITEM_START; i < BANK_SLOT_ITEM_END; ++i)
{
if (!player->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
++freeSlots;
}
// Check bank bags slots (BANK_SLOT_BAG_START to BANK_SLOT_BAG_END)
for (uint8 i = BANK_SLOT_BAG_START; i < BANK_SLOT_BAG_END; ++i)
{
if (Bag* bag = player->GetBagByPos(i))
{
for (uint32 j = 0; j < bag->GetBagSize(); ++j)
{
if (!player->GetItemByPos(i, j))
++freeSlots;
}
}
}
ALE::Push(L, freeSlots);
return 1;
}
/** /**
* Returns `true` if the [Player] has a Tank Specialization, `false` otherwise. * Returns `true` if the [Player] has a Tank Specialization, `false` otherwise.
* *