diff --git a/common/inventory_profile.cpp b/common/inventory_profile.cpp index 3f4c3b3dc..fbc794351 100644 --- a/common/inventory_profile.cpp +++ b/common/inventory_profile.cpp @@ -621,6 +621,37 @@ int EQ::InventoryProfile::CountAugmentEquippedByID(uint32 item_id) return quantity; } +bool EQ::InventoryProfile::HasItemEquippedByID(uint32 item_id) +{ + bool has_equipped = false; + ItemInstance* item = nullptr; + + for (int slot_id = EQ::invslot::EQUIPMENT_BEGIN; slot_id <= EQ::invslot::EQUIPMENT_END; ++slot_id) { + item = GetItem(slot_id); + if (item && item->GetID() == item_id) { + has_equipped = true; + break; + } + } + + return has_equipped; +} + +int EQ::InventoryProfile::CountItemEquippedByID(uint32 item_id) +{ + int quantity = 0; + ItemInstance* item = nullptr; + + for (int slot_id = EQ::invslot::EQUIPMENT_BEGIN; slot_id <= EQ::invslot::EQUIPMENT_END; ++slot_id) { + item = GetItem(slot_id); + if (item && item->GetID() == item_id) { + quantity += item->IsStackable() ? item->GetCharges() : 1; + } + } + + return quantity; +} + //This function has a flaw in that it only returns the last stack that it looked at //when quantity is greater than 1 and not all of quantity can be found in 1 stack. int16 EQ::InventoryProfile::HasItem(uint32 item_id, uint8 quantity, uint8 where) diff --git a/common/inventory_profile.h b/common/inventory_profile.h index b32b028fb..c35f5679d 100644 --- a/common/inventory_profile.h +++ b/common/inventory_profile.h @@ -140,6 +140,12 @@ namespace EQ // Remove item from inventory (and take control of memory) ItemInstance* PopItem(int16 slot_id); + // Check if player has a specific item equipped by Item ID + bool HasItemEquippedByID(uint32 item_id); + + // Check how many of a specific item the player has equipped by Item ID + int CountItemEquippedByID(uint32 item_id); + // Check if player has a specific augment equipped by Item ID bool HasAugmentEquippedByID(uint32 item_id); diff --git a/zone/lua_inventory.cpp b/zone/lua_inventory.cpp index f19b9af87..9c5b9c599 100644 --- a/zone/lua_inventory.cpp +++ b/zone/lua_inventory.cpp @@ -174,6 +174,16 @@ bool Lua_Inventory::HasAugmentEquippedByID(uint32 item_id) { return self->HasAugmentEquippedByID(item_id); } +int Lua_Inventory::CountItemEquippedByID(uint32 item_id) { + Lua_Safe_Call_Int(); + return self->CountItemEquippedByID(item_id); +} + +bool Lua_Inventory::HasItemEquippedByID(uint32 item_id) { + Lua_Safe_Call_Bool(); + return self->HasItemEquippedByID(item_id); +} + luabind::scope lua_register_inventory() { return luabind::class_("Inventory") .def(luabind::constructor<>()) @@ -185,6 +195,7 @@ luabind::scope lua_register_inventory() { .def("CanItemFitInContainer", (bool(Lua_Inventory::*)(Lua_Item,Lua_Item))&Lua_Inventory::CanItemFitInContainer) .def("CheckNoDrop", (bool(Lua_Inventory::*)(int))&Lua_Inventory::CheckNoDrop) .def("CountAugmentEquippedByID", (int(Lua_Inventory::*)(uint32))&Lua_Inventory::CountAugmentEquippedByID) + .def("CountItemEquippedByID", (int(Lua_Inventory::*)(uint32))&Lua_Inventory::CountItemEquippedByID) .def("DeleteItem", (bool(Lua_Inventory::*)(int))&Lua_Inventory::DeleteItem) .def("DeleteItem", (bool(Lua_Inventory::*)(int,int))&Lua_Inventory::DeleteItem) .def("FindFreeSlot", (int(Lua_Inventory::*)(bool,bool))&Lua_Inventory::FindFreeSlot) @@ -202,6 +213,7 @@ luabind::scope lua_register_inventory() { .def("HasItemByUse", (int(Lua_Inventory::*)(int))&Lua_Inventory::HasItemByUse) .def("HasItemByUse", (int(Lua_Inventory::*)(int,uint8))&Lua_Inventory::HasItemByUse) .def("HasItemByUse", (int(Lua_Inventory::*)(int,uint8,uint8))&Lua_Inventory::HasItemByUse) + .def("HasItemEquippedByID", (bool(Lua_Inventory::*)(uint32))&Lua_Inventory::HasItemEquippedByID) .def("HasSpaceForItem", (bool(Lua_Inventory::*)(Lua_Item,int))&Lua_Inventory::HasSpaceForItem) .def("PopItem", (Lua_ItemInst(Lua_Inventory::*)(int))&Lua_Inventory::PopItem) .def("PushCursor", (int(Lua_Inventory::*)(Lua_ItemInst))&Lua_Inventory::PushCursor) diff --git a/zone/lua_inventory.h b/zone/lua_inventory.h index 33ba80b39..17966b4f4 100644 --- a/zone/lua_inventory.h +++ b/zone/lua_inventory.h @@ -44,8 +44,10 @@ public: bool DeleteItem(int slot_id, int quantity); bool CheckNoDrop(int slot_id); int CountAugmentEquippedByID(uint32 item_id); + int CountItemEquippedByID(uint32 item_id); Lua_ItemInst PopItem(int slot_id); bool HasAugmentEquippedByID(uint32 item_id); + bool HasItemEquippedByID(uint32 item_id); int HasItem(int item_id); int HasItem(int item_id, int quantity); int HasItem(int item_id, int quantity, int where); diff --git a/zone/perl_inventory.cpp b/zone/perl_inventory.cpp index 140042a47..ad3cfc08a 100644 --- a/zone/perl_inventory.cpp +++ b/zone/perl_inventory.cpp @@ -449,6 +449,41 @@ XS(XS_Inventory_CountAugmentEquippedByID) { XSRETURN(1); } +XS(XS_Inventory_HasItemEquippedByID); +XS(XS_Inventory_HasItemEquippedByID) { + dXSARGS; + if (items != 2) + Perl_croak(aTHX_ "Usage: Inventory::HasItemEquippedByID(THIS, uint32 item_id)"); + { + EQ::InventoryProfile* THIS; + bool has_equipped = false; + uint32 item_id = (uint32) SvUV(ST(1)); + VALIDATE_THIS_IS_INVENTORY; + has_equipped = THIS->HasItemEquippedByID(item_id); + ST(0) = boolSV(has_equipped); + sv_2mortal(ST(0)); + } + XSRETURN(1); +} + +XS(XS_Inventory_CountItemEquippedByID); +XS(XS_Inventory_CountItemEquippedByID) { + dXSARGS; + if (items != 2) + Perl_croak(aTHX_ "Usage: Inventory::CountItemEquippedByID(THIS, uint32 item_id)"); + { + EQ::InventoryProfile* THIS; + int quantity = 0; + uint32 item_id = (uint32) SvUV(ST(1)); + dXSTARG; + VALIDATE_THIS_IS_INVENTORY; + quantity = THIS->CountItemEquippedByID(item_id); + XSprePUSH; + PUSHi((IV)quantity); + } + XSRETURN(1); +} + #ifdef __cplusplus extern "C" #endif @@ -466,6 +501,7 @@ XS(boot_Inventory) { XS_VERSION_BOOTCHECK; newXSproto(strcpy(buf, "CanItemFitInContainer"), XS_Inventory_CanItemFitInContainer, file, "$$$"); newXSproto(strcpy(buf, "CountAugmentEquippedByID"), XS_Inventory_CountAugmentEquippedByID, file, "$$"); + newXSproto(strcpy(buf, "CountItemEquippedByID"), XS_Inventory_CountItemEquippedByID, file, "$$"); newXSproto(strcpy(buf, "CheckNoDrop"), XS_Inventory_CheckNoDrop, file, "$$"); newXSproto(strcpy(buf, "DeleteItem"), XS_Inventory_DeleteItem, file, "$$;$"); newXSproto(strcpy(buf, "FindFreeSlot"), XS_Inventory_FindFreeSlot, file, "$$$;$$"); @@ -479,6 +515,7 @@ XS(boot_Inventory) { newXSproto(strcpy(buf, "HasItem"), XS_Inventory_HasItem, file, "$$;$$"); newXSproto(strcpy(buf, "HasItemByLoreGroup"), XS_Inventory_HasItemByLoreGroup, file, "$$;$"); newXSproto(strcpy(buf, "HasItemByUse"), XS_Inventory_HasItemByUse, file, "$$;$$"); + newXSproto(strcpy(buf, "HasItemEquippedByID"), XS_Inventory_HasItemEquippedByID, file, "$$"); newXSproto(strcpy(buf, "HasSpaceForItem"), XS_Inventory_HasSpaceForItem, file, "$$$"); newXSproto(strcpy(buf, "PopItem"), XS_Inventory_PopItem, file, "$$"); newXSproto(strcpy(buf, "PushCursor"), XS_Inventory_PushCursor, file, "$$");