feat(LuaEngine): Add GetInventoryFreeSlots and GetBankFreeSlots to Player class (#369)
This commit is contained in:
@@ -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 },
|
||||||
|
|||||||
@@ -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.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user