[Quest API] Add GetAugmentIDsBySlotID() to Perl/Lua. (#2673)

* [Quest API] Add GetAugmentIDsBySlotID() to Perl/Lua.

# Perl
- Add `$client->GetAugmentIDsBySlotID(slot_id)`.
- Add `$inventory->GetAugmentIDsBySlotID(slot_id)`.

# Lua
- Add `client:GetAugmentIDsBySlotID(slot_id)`.
- Add `inventory:GetAugmentIDsBySlotID(slot_id)`.

# Notes
- Allows operators to get a list of augments from a specific slot instead of having to build a plugin or something to do it.
- Fix issue with Lua tables starting at index `1` versus index `0`, so you lost the first value of the table due to this.

* Update inventory_profile.cpp
This commit is contained in:
Alex King 2022-12-25 15:14:54 -05:00 committed by GitHub
parent 6229852331
commit d7ae3d5c6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 85 additions and 9 deletions

View File

@ -1718,3 +1718,17 @@ int16 EQ::InventoryProfile::_HasItemByLoreGroup(ItemInstQueue& iqueue, uint32 lo
return EQ::invslot::SLOT_INVALID; return EQ::invslot::SLOT_INVALID;
} }
std::vector<uint32> EQ::InventoryProfile::GetAugmentIDsBySlotID(int16 slot_id)
{
std::vector<uint32> augments;
const auto* item = GetItem(slot_id);
if (item) {
for (uint8 i = invaug::SOCKET_BEGIN; i <= invaug::SOCKET_END; i++) {
augments.push_back(item->GetAugment(i) ? item->GetAugmentItemID(i) : 0);
}
}
return augments;
}

View File

@ -28,6 +28,7 @@
#include "item_instance.h" #include "item_instance.h"
#include <list> #include <list>
#include <vector>
//FatherNitwit: location bits for searching specific //FatherNitwit: location bits for searching specific
@ -152,6 +153,9 @@ namespace EQ
// Check how many of a specific augment the player has equipped by Item ID // Check how many of a specific augment the player has equipped by Item ID
int CountAugmentEquippedByID(uint32 item_id); int CountAugmentEquippedByID(uint32 item_id);
// Get a list of augments from a specific slot ID
std::vector<uint32> GetAugmentIDsBySlotID(int16 slot_id);
// Check whether there is space for the specified number of the specified item. // Check whether there is space for the specified number of the specified item.
bool HasSpaceForItem(const ItemData *ItemToTry, int16 Quantity); bool HasSpaceForItem(const ItemData *ItemToTry, int16 Quantity);

View File

@ -650,7 +650,7 @@ luabind::object Lua_Client::GetLearnableDisciplines(lua_State* L) {
if (d_) { if (d_) {
auto self = reinterpret_cast<NativeType*>(d_); auto self = reinterpret_cast<NativeType*>(d_);
auto learnable_disciplines = self->GetLearnableDisciplines(); auto learnable_disciplines = self->GetLearnableDisciplines();
int index = 0; int index = 1;
for (auto spell_id : learnable_disciplines) { for (auto spell_id : learnable_disciplines) {
lua_table[index] = spell_id; lua_table[index] = spell_id;
index++; index++;
@ -664,7 +664,7 @@ luabind::object Lua_Client::GetLearnableDisciplines(lua_State* L, uint8 min_leve
if (d_) { if (d_) {
auto self = reinterpret_cast<NativeType*>(d_); auto self = reinterpret_cast<NativeType*>(d_);
auto learnable_disciplines = self->GetLearnableDisciplines(min_level); auto learnable_disciplines = self->GetLearnableDisciplines(min_level);
int index = 0; int index = 1;
for (auto spell_id : learnable_disciplines) { for (auto spell_id : learnable_disciplines) {
lua_table[index] = spell_id; lua_table[index] = spell_id;
index++; index++;
@ -678,7 +678,7 @@ luabind::object Lua_Client::GetLearnableDisciplines(lua_State* L, uint8 min_leve
if (d_) { if (d_) {
auto self = reinterpret_cast<NativeType*>(d_); auto self = reinterpret_cast<NativeType*>(d_);
auto learnable_disciplines = self->GetLearnableDisciplines(min_level, max_level); auto learnable_disciplines = self->GetLearnableDisciplines(min_level, max_level);
int index = 0; int index = 1;
for (auto spell_id : learnable_disciplines) { for (auto spell_id : learnable_disciplines) {
lua_table[index] = spell_id; lua_table[index] = spell_id;
index++; index++;
@ -692,7 +692,7 @@ luabind::object Lua_Client::GetLearnedDisciplines(lua_State* L) {
if (d_) { if (d_) {
auto self = reinterpret_cast<NativeType*>(d_); auto self = reinterpret_cast<NativeType*>(d_);
auto learned_disciplines = self->GetLearnedDisciplines(); auto learned_disciplines = self->GetLearnedDisciplines();
int index = 0; int index = 1;
for (auto spell_id : learned_disciplines) { for (auto spell_id : learned_disciplines) {
lua_table[index] = spell_id; lua_table[index] = spell_id;
index++; index++;
@ -706,7 +706,7 @@ luabind::object Lua_Client::GetMemmedSpells(lua_State* L) {
if (d_) { if (d_) {
auto self = reinterpret_cast<NativeType*>(d_); auto self = reinterpret_cast<NativeType*>(d_);
auto memmed_spells = self->GetMemmedSpells(); auto memmed_spells = self->GetMemmedSpells();
int index = 0; int index = 1;
for (auto spell_id : memmed_spells) { for (auto spell_id : memmed_spells) {
lua_table[index] = spell_id; lua_table[index] = spell_id;
index++; index++;
@ -720,7 +720,7 @@ luabind::object Lua_Client::GetScribeableSpells(lua_State* L) {
if (d_) { if (d_) {
auto self = reinterpret_cast<NativeType*>(d_); auto self = reinterpret_cast<NativeType*>(d_);
auto scribeable_spells = self->GetScribeableSpells(); auto scribeable_spells = self->GetScribeableSpells();
int index = 0; int index = 1;
for (auto spell_id : scribeable_spells) { for (auto spell_id : scribeable_spells) {
lua_table[index] = spell_id; lua_table[index] = spell_id;
index++; index++;
@ -734,7 +734,7 @@ luabind::object Lua_Client::GetScribeableSpells(lua_State* L, uint8 min_level) {
if (d_) { if (d_) {
auto self = reinterpret_cast<NativeType*>(d_); auto self = reinterpret_cast<NativeType*>(d_);
auto scribeable_spells = self->GetScribeableSpells(min_level); auto scribeable_spells = self->GetScribeableSpells(min_level);
int index = 0; int index = 1;
for (auto spell_id : scribeable_spells) { for (auto spell_id : scribeable_spells) {
lua_table[index] = spell_id; lua_table[index] = spell_id;
index++; index++;
@ -748,7 +748,7 @@ luabind::object Lua_Client::GetScribeableSpells(lua_State* L, uint8 min_level, u
if (d_) { if (d_) {
auto self = reinterpret_cast<NativeType*>(d_); auto self = reinterpret_cast<NativeType*>(d_);
auto scribeable_spells = self->GetScribeableSpells(min_level, max_level); auto scribeable_spells = self->GetScribeableSpells(min_level, max_level);
int index = 0; int index = 1;
for (auto spell_id : scribeable_spells) { for (auto spell_id : scribeable_spells) {
lua_table[index] = spell_id; lua_table[index] = spell_id;
index++; index++;
@ -762,7 +762,7 @@ luabind::object Lua_Client::GetScribedSpells(lua_State* L) {
if (d_) { if (d_) {
auto self = reinterpret_cast<NativeType*>(d_); auto self = reinterpret_cast<NativeType*>(d_);
auto scribed_spells = self->GetScribedSpells(); auto scribed_spells = self->GetScribedSpells();
int index = 0; int index = 1;
for (auto spell_id : scribed_spells) { for (auto spell_id : scribed_spells) {
lua_table[index] = spell_id; lua_table[index] = spell_id;
index++; index++;
@ -2892,6 +2892,20 @@ void Lua_Client::MaxSkills()
self->MaxSkills(); self->MaxSkills();
} }
luabind::object Lua_Client::GetAugmentIDsBySlotID(lua_State* L, int16 slot_id) {
auto lua_table = luabind::newtable(L);
if (d_) {
auto self = reinterpret_cast<NativeType*>(d_);
auto augments = self->GetInv().GetAugmentIDsBySlotID(slot_id);
int index = 1;
for (auto item_id : augments) {
lua_table[index] = item_id;
index++;
}
}
return lua_table;
}
#ifdef BOTS #ifdef BOTS
int Lua_Client::GetBotRequiredLevel() int Lua_Client::GetBotRequiredLevel()
@ -3092,6 +3106,7 @@ luabind::scope lua_register_client() {
.def("GetAlternateCurrencyValue", (int(Lua_Client::*)(uint32))&Lua_Client::GetAlternateCurrencyValue) .def("GetAlternateCurrencyValue", (int(Lua_Client::*)(uint32))&Lua_Client::GetAlternateCurrencyValue)
.def("GetAnon", (int(Lua_Client::*)(void))&Lua_Client::GetAnon) .def("GetAnon", (int(Lua_Client::*)(void))&Lua_Client::GetAnon)
.def("GetAugmentIDAt", (int(Lua_Client::*)(int,int))&Lua_Client::GetAugmentIDAt) .def("GetAugmentIDAt", (int(Lua_Client::*)(int,int))&Lua_Client::GetAugmentIDAt)
.def("GetAugmentIDsBySlotID", (luabind::object(Lua_Client::*)(lua_State* L,int16))&Lua_Client::GetAugmentIDsBySlotID)
.def("GetBaseAGI", (int(Lua_Client::*)(void))&Lua_Client::GetBaseAGI) .def("GetBaseAGI", (int(Lua_Client::*)(void))&Lua_Client::GetBaseAGI)
.def("GetBaseCHA", (int(Lua_Client::*)(void))&Lua_Client::GetBaseCHA) .def("GetBaseCHA", (int(Lua_Client::*)(void))&Lua_Client::GetBaseCHA)
.def("GetBaseDEX", (int(Lua_Client::*)(void))&Lua_Client::GetBaseDEX) .def("GetBaseDEX", (int(Lua_Client::*)(void))&Lua_Client::GetBaseDEX)

View File

@ -454,6 +454,7 @@ public:
void SendPayload(int payload_id, std::string payload_value); void SendPayload(int payload_id, std::string payload_value);
std::string GetGuildPublicNote(); std::string GetGuildPublicNote();
void MaxSkills(); void MaxSkills();
luabind::object GetAugmentIDsBySlotID(lua_State* L, int16 slot_id);
void ApplySpell(int spell_id); void ApplySpell(int spell_id);
void ApplySpell(int spell_id, int duration); void ApplySpell(int spell_id, int duration);

View File

@ -184,6 +184,20 @@ bool Lua_Inventory::HasItemEquippedByID(uint32 item_id) {
return self->HasItemEquippedByID(item_id); return self->HasItemEquippedByID(item_id);
} }
luabind::object Lua_Inventory::GetAugmentIDsBySlotID(lua_State* L, int16 slot_id) {
auto lua_table = luabind::newtable(L);
if (d_) {
auto self = reinterpret_cast<NativeType*>(d_);
auto augments = self->GetAugmentIDsBySlotID(slot_id);
int index = 1;
for (auto item_id : augments) {
lua_table[index] = item_id;
index++;
}
}
return lua_table;
}
luabind::scope lua_register_inventory() { luabind::scope lua_register_inventory() {
return luabind::class_<Lua_Inventory>("Inventory") return luabind::class_<Lua_Inventory>("Inventory")
.def(luabind::constructor<>()) .def(luabind::constructor<>())
@ -201,6 +215,7 @@ luabind::scope lua_register_inventory() {
.def("FindFreeSlot", (int(Lua_Inventory::*)(bool,bool))&Lua_Inventory::FindFreeSlot) .def("FindFreeSlot", (int(Lua_Inventory::*)(bool,bool))&Lua_Inventory::FindFreeSlot)
.def("FindFreeSlot", (int(Lua_Inventory::*)(bool,bool,int))&Lua_Inventory::FindFreeSlot) .def("FindFreeSlot", (int(Lua_Inventory::*)(bool,bool,int))&Lua_Inventory::FindFreeSlot)
.def("FindFreeSlot", (int(Lua_Inventory::*)(bool,bool,int,bool))&Lua_Inventory::FindFreeSlot) .def("FindFreeSlot", (int(Lua_Inventory::*)(bool,bool,int,bool))&Lua_Inventory::FindFreeSlot)
.def("GetAugmentIDsBySlotID", (luabind::object(Lua_Inventory::*)(lua_State* L,int16))&Lua_Inventory::GetAugmentIDsBySlotID)
.def("GetItem", (Lua_ItemInst(Lua_Inventory::*)(int))&Lua_Inventory::GetItem) .def("GetItem", (Lua_ItemInst(Lua_Inventory::*)(int))&Lua_Inventory::GetItem)
.def("GetItem", (Lua_ItemInst(Lua_Inventory::*)(int,int))&Lua_Inventory::GetItem) .def("GetItem", (Lua_ItemInst(Lua_Inventory::*)(int,int))&Lua_Inventory::GetItem)
.def("GetSlotByItemInst", (int(Lua_Inventory::*)(Lua_ItemInst))&Lua_Inventory::GetSlotByItemInst) .def("GetSlotByItemInst", (int(Lua_Inventory::*)(Lua_ItemInst))&Lua_Inventory::GetSlotByItemInst)

View File

@ -68,6 +68,7 @@ public:
bool CanItemFitInContainer(Lua_Item item, Lua_Item container); bool CanItemFitInContainer(Lua_Item item, Lua_Item container);
bool SupportsContainers(int slot_id); bool SupportsContainers(int slot_id);
int GetSlotByItemInst(Lua_ItemInst inst); int GetSlotByItemInst(Lua_ItemInst inst);
luabind::object GetAugmentIDsBySlotID(lua_State* L, int16 slot_id);
}; };
#endif #endif

View File

@ -2772,6 +2772,18 @@ void Perl_Client_MaxSkills(Client* self)
self->MaxSkills(); self->MaxSkills();
} }
perl::array Perl_Client_GetAugmentIDsBySlotID(Client* self, int16 slot_id)
{
perl::array result;
auto augments = self->GetInv().GetAugmentIDsBySlotID(slot_id);
for (int i = 0; i < augments.size(); ++i) {
result.push_back(augments[i]);
}
return result;
}
#ifdef BOTS #ifdef BOTS
int Perl_Client_GetBotRequiredLevel(Client* self) int Perl_Client_GetBotRequiredLevel(Client* self)
@ -2958,6 +2970,7 @@ void perl_register_client()
package.add("GetAnon", &Perl_Client_GetAnon); package.add("GetAnon", &Perl_Client_GetAnon);
package.add("GetAugmentAt", &Perl_Client_GetAugmentAt); package.add("GetAugmentAt", &Perl_Client_GetAugmentAt);
package.add("GetAugmentIDAt", &Perl_Client_GetAugmentIDAt); package.add("GetAugmentIDAt", &Perl_Client_GetAugmentIDAt);
package.add("GetAugmentIDsBySlotID", &Perl_Client_GetAugmentIDsBySlotID);
package.add("GetBaseAGI", &Perl_Client_GetBaseAGI); package.add("GetBaseAGI", &Perl_Client_GetBaseAGI);
package.add("GetBaseCHA", &Perl_Client_GetBaseCHA); package.add("GetBaseCHA", &Perl_Client_GetBaseCHA);
package.add("GetBaseDEX", &Perl_Client_GetBaseDEX); package.add("GetBaseDEX", &Perl_Client_GetBaseDEX);

View File

@ -166,6 +166,18 @@ int Perl_Inventory_CountItemEquippedByID(EQ::InventoryProfile* self, uint32_t it
return self->CountItemEquippedByID(item_id); return self->CountItemEquippedByID(item_id);
} }
perl::array Perl_Inventory_GetAugmentIDsBySlotID(EQ::InventoryProfile* self, int16 slot_id)
{
perl::array result;
auto augments = self->GetAugmentIDsBySlotID(slot_id);
for (int i = 0; i < augments.size(); ++i) {
result.push_back(augments[i]);
}
return result;
}
void perl_register_inventory() void perl_register_inventory()
{ {
perl::interpreter perl(PERL_GET_THX); perl::interpreter perl(PERL_GET_THX);
@ -180,6 +192,7 @@ void perl_register_inventory()
package.add("FindFreeSlot", (int(*)(EQ::InventoryProfile*, bool, bool))&Perl_Inventory_FindFreeSlot); package.add("FindFreeSlot", (int(*)(EQ::InventoryProfile*, bool, bool))&Perl_Inventory_FindFreeSlot);
package.add("FindFreeSlot", (int(*)(EQ::InventoryProfile*, bool, bool, uint8_t))&Perl_Inventory_FindFreeSlot); package.add("FindFreeSlot", (int(*)(EQ::InventoryProfile*, bool, bool, uint8_t))&Perl_Inventory_FindFreeSlot);
package.add("FindFreeSlot", (int(*)(EQ::InventoryProfile*, bool, bool, uint8_t, bool))&Perl_Inventory_FindFreeSlot); package.add("FindFreeSlot", (int(*)(EQ::InventoryProfile*, bool, bool, uint8_t, bool))&Perl_Inventory_FindFreeSlot);
package.add("GetAugmentIDsBySlotID", &Perl_Inventory_GetAugmentIDsBySlotID);
package.add("GetBagIndex", &Perl_Inventory_GetBagIndex); package.add("GetBagIndex", &Perl_Inventory_GetBagIndex);
package.add("GetItem", &Perl_Inventory_GetItem); package.add("GetItem", &Perl_Inventory_GetItem);
package.add("GetMaterialFromSlot", &Perl_Inventory_GetMaterialFromSlot); package.add("GetMaterialFromSlot", &Perl_Inventory_GetMaterialFromSlot);