[Quest API] Adds new methods to NPCs and Corpses (#1510)

- Add $npc->HasItem(item_id) to Perl.
- Add $npc->CountItem(item_id) to Perl.
- Add $npc->GetItemIDBySlot(loot_slot) to Perl.
- Add $npc->GetFirstSlotByItemID(item_id) to Perl.
- Add $corpse->HasItem(item_id) to Perl.
- Add $corpse->CountItem(item_id) to Perl.
- Add $corpse->GetItemIDBySlot(loot_slot) to Perl.
- Add $corpse->GetFirstSlotByItemID(item_id) to Perl.
- Add npc:HasItem(item_id) to Lua.
- Add npc:CountItem(item_id) to Lua.
- Add npc:GetItemIDBySlot(loot_slot) to Lua.
- Add npc:GetFirstSlotByItemID(item_id) to Lua.
- Add corpse:HasItem(item_id) to Lua.
- Add corpse:CountItem(item_id) to Lua.
- Add corpse:GetItemIDBySlot(loot_slot) to Lua.
- Add corpse:GetFirstSlotByItemID(item_id) to Lua.

These methods will allow server operators to view the loot a current has in a slot, the first slot found by item ID, count the item by ID, and see if the NPC has the item.

With that functionality you could build a custom loot system and modify loot more dynamically.
This commit is contained in:
Kinglykrab
2021-08-31 01:42:08 -04:00
committed by GitHub
parent 642cbfcadc
commit 26299354b6
10 changed files with 358 additions and 2 deletions
+25 -1
View File
@@ -152,6 +152,26 @@ void Lua_Corpse::AddLooter(Lua_Mob who) {
self->AddLooter(who);
}
bool Lua_Corpse::HasItem(uint32 item_id) {
Lua_Safe_Call_Bool();
return self->HasItem(item_id);
}
uint16 Lua_Corpse::CountItem(uint32 item_id) {
Lua_Safe_Call_Int();
return self->CountItem(item_id);
}
uint32 Lua_Corpse::GetItemIDBySlot(uint16 loot_slot) {
Lua_Safe_Call_Int();
return self->GetItemIDBySlot(loot_slot);
}
uint16 Lua_Corpse::GetFirstSlotByItemID(uint32 item_id) {
Lua_Safe_Call_Int();
return self->GetFirstSlotByItemID(item_id);
}
luabind::scope lua_register_corpse() {
return luabind::class_<Lua_Corpse, Lua_Mob>("Corpse")
.def(luabind::constructor<>())
@@ -185,7 +205,11 @@ luabind::scope lua_register_corpse() {
.def("GetSilver", (uint32(Lua_Corpse::*)(void))&Lua_Corpse::GetSilver)
.def("GetGold", (uint32(Lua_Corpse::*)(void))&Lua_Corpse::GetGold)
.def("GetPlatinum", (uint32(Lua_Corpse::*)(void))&Lua_Corpse::GetPlatinum)
.def("AddLooter", (void(Lua_Corpse::*)(Lua_Mob))&Lua_Corpse::AddLooter);
.def("AddLooter", (void(Lua_Corpse::*)(Lua_Mob))&Lua_Corpse::AddLooter)
.def("HasItem", (bool(Lua_Corpse::*)(uint32))&Lua_Corpse::HasItem)
.def("CountItem", (uint16(Lua_Corpse::*)(uint32))&Lua_Corpse::CountItem)
.def("GetItemIDBySlot", (uint32(Lua_Corpse::*)(uint16))&Lua_Corpse::GetItemIDBySlot)
.def("GetFirstSlotByItemID", (uint16(Lua_Corpse::*)(uint32))&Lua_Corpse::GetFirstSlotByItemID);
}
#endif