diff --git a/zone/lua_bot.cpp b/zone/lua_bot.cpp index 096fcd9e7..70cedec07 100644 --- a/zone/lua_bot.cpp +++ b/zone/lua_bot.cpp @@ -8,6 +8,7 @@ #include "lua_iteminst.h" #include "lua_mob.h" #include "lua_group.h" +#include "lua_item.h" void Lua_Bot::AddBotItem(uint16 slot_id, uint32 item_id) { Lua_Safe_Call_Void(); @@ -393,6 +394,66 @@ void Lua_Bot::SendSpellAnim(uint16 target_id, uint16 spell_id) self->SendSpellAnim(target_id, spell_id); } +luabind::object Lua_Bot::GetAugmentIDsBySlotID(lua_State* L, int16 slot_id) const { + auto lua_table = luabind::newtable(L); + if (d_) { + auto self = reinterpret_cast(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; +} + +void Lua_Bot::AddItem(const luabind::object& item_table) { + Lua_Safe_Call_Void(); + if (luabind::type(item_table) != LUA_TTABLE) { + return; + } + + auto item_id = luabind::object_cast(item_table["item_id"]); + int16 charges = luabind::object_cast(item_table["charges"]); + uint32 augment_one = luabind::type(item_table["augment_one"]) != LUA_TNIL ? luabind::object_cast(item_table["augment_one"]) : 0; + uint32 augment_two = luabind::type(item_table["augment_two"]) != LUA_TNIL ? luabind::object_cast(item_table["augment_two"]) : 0; + uint32 augment_three = luabind::type(item_table["augment_three"]) != LUA_TNIL ? luabind::object_cast(item_table["augment_three"]) : 0; + uint32 augment_four = luabind::type(item_table["augment_four"]) != LUA_TNIL ? luabind::object_cast(item_table["augment_four"]) : 0; + uint32 augment_five = luabind::type(item_table["augment_five"]) != LUA_TNIL ? luabind::object_cast(item_table["augment_five"]) : 0; + uint32 augment_six = luabind::type(item_table["augment_six"]) != LUA_TNIL ? luabind::object_cast(item_table["augment_six"]) : 0; + bool attuned = luabind::type(item_table["attuned"]) != LUA_TNIL ? luabind::object_cast(item_table["attuned"]) : false; + uint16 slot_id = luabind::type(item_table["slot_id"]) != LUA_TNIL ? luabind::object_cast(item_table["slot_id"]) : EQ::invslot::slotCursor; + + if (slot_id <= EQ::invslot::slotAmmo) { + self->AddBotItem( + slot_id, + item_id, + charges, + attuned, + augment_one, + augment_two, + augment_three, + augment_four, + augment_five, + augment_six + ); + } else { + self->GetOwner()->CastToClient()->SummonItem( + item_id, + charges, + augment_one, + augment_two, + augment_three, + augment_four, + augment_five, + augment_six, + attuned, + slot_id + ); + } +} + luabind::scope lua_register_bot() { return luabind::class_("Bot") .def(luabind::constructor<>()) @@ -405,6 +466,7 @@ luabind::scope lua_register_bot() { .def("AddBotItem", (void(Lua_Bot::*)(uint16,uint32,int16,bool,uint32,uint32,uint32,uint32))&Lua_Bot::AddBotItem) .def("AddBotItem", (void(Lua_Bot::*)(uint16,uint32,int16,bool,uint32,uint32,uint32,uint32,uint32))&Lua_Bot::AddBotItem) .def("AddBotItem", (void(Lua_Bot::*)(uint16,uint32,int16,bool,uint32,uint32,uint32,uint32,uint32,uint32))&Lua_Bot::AddBotItem) + .def("AddItem", (void(Lua_Bot::*)(luabind::adl::object))&Lua_Bot::AddItem) .def("ApplySpell", (void(Lua_Bot::*)(int))&Lua_Bot::ApplySpell) .def("ApplySpell", (void(Lua_Bot::*)(int,int))&Lua_Bot::ApplySpell) .def("ApplySpell", (void(Lua_Bot::*)(int,int,bool))&Lua_Bot::ApplySpell) @@ -424,6 +486,7 @@ luabind::scope lua_register_bot() { .def("Fling", (void(Lua_Bot::*)(float,float,float,float,bool,bool))&Lua_Bot::Fling) .def("GetAugmentAt", (Lua_ItemInst(Lua_Bot::*)(int16,uint8))&Lua_Bot::GetAugmentAt) .def("GetAugmentIDAt", (int(Lua_Bot::*)(int16,uint8))&Lua_Bot::GetAugmentIDAt) + .def("GetAugmentIDsBySlotID", (luabind::object(Lua_Bot::*)(lua_State* L,int16))&Lua_Bot::GetAugmentIDsBySlotID) .def("GetBaseAGI", (int(Lua_Bot::*)(void))&Lua_Bot::GetBaseAGI) .def("GetBaseCHA", (int(Lua_Bot::*)(void))&Lua_Bot::GetBaseCHA) .def("GetBaseDEX", (int(Lua_Bot::*)(void))&Lua_Bot::GetBaseDEX) diff --git a/zone/lua_bot.h b/zone/lua_bot.h index 8e25f5b5e..1577252d0 100644 --- a/zone/lua_bot.h +++ b/zone/lua_bot.h @@ -8,6 +8,7 @@ class Bot; class Lua_Bot; class Lua_Mob; class Lua_Group; +class Lua_Inventory; namespace luabind { struct scope; @@ -36,6 +37,7 @@ public: void AddBotItem(uint16 slot_id, uint32 item_id, int16 charges, bool attuned, uint32 augment_one, uint32 augment_two, uint32 augment_three, uint32 augment_four); void AddBotItem(uint16 slot_id, uint32 item_id, int16 charges, bool attuned, uint32 augment_one, uint32 augment_two, uint32 augment_three, uint32 augment_four, uint32 augment_five); void AddBotItem(uint16 slot_id, uint32 item_id, int16 charges, bool attuned, uint32 augment_one, uint32 augment_two, uint32 augment_three, uint32 augment_four, uint32 augment_five, uint32 augment_six); + void AddItem(const luabind::object& item_table); uint32 CountBotItem(uint32 item_id); Lua_ItemInst GetBotItem(uint16 slot_id); uint32 GetBotItemIDBySlot(uint16 slot_id); @@ -59,6 +61,7 @@ public: void Camp(bool save_to_database); Lua_ItemInst GetAugmentAt(int16 slot_id, uint8 augment_index); int GetAugmentIDAt(int16 slot_id, uint8 augment_index); + luabind::object GetAugmentIDsBySlotID(lua_State* L, int16 slot_id) const; Lua_ItemInst GetItemAt(int16 slot_id); int GetItemIDAt(int16 slot_id); void SendSpellAnim(uint16 target_id, uint16 spell_id); diff --git a/zone/perl_bot.cpp b/zone/perl_bot.cpp index ccbb0a936..019ec81d2 100644 --- a/zone/perl_bot.cpp +++ b/zone/perl_bot.cpp @@ -385,6 +385,66 @@ void Perl_Bot_Camp(Bot* self, bool save_to_database) // @categories Script Utili self->Camp(save_to_database); } +perl::array Perl_Bot_GetAugmentIDsBySlotID(Bot* 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; +} + +void Perl_Bot_AddItem(Bot *self, perl::reference table_ref) +{ + perl::hash table = table_ref; + if (!table.exists("item_id") || !table.exists("charges")) + { + return; + } + + uint32 item_id = table["item_id"]; + int16 charges = table["charges"]; + uint32 augment_one = table.exists("augment_one") ? table["augment_one"] : 0; + uint32 augment_two = table.exists("augment_two") ? table["augment_two"] : 0; + uint32 augment_three = table.exists("augment_three") ? table["augment_three"] : 0; + uint32 augment_four = table.exists("augment_four") ? table["augment_four"] : 0; + uint32 augment_five = table.exists("augment_five") ? table["augment_five"] : 0; + uint32 augment_six = table.exists("augment_six") ? table["augment_six"] : 0; + bool attuned = table.exists("attuned") && table["attuned"]; + uint16 slot_id = table.exists("slot_id") ? table["slot_id"] : EQ::invslot::slotCursor; + + if (slot_id <= EQ::invslot::slotAmmo) { + self->AddBotItem( + slot_id, + item_id, + charges, + attuned, + augment_one, + augment_two, + augment_three, + augment_four, + augment_five, + augment_six + ); + } else { + self->GetOwner()->CastToClient()->SummonItem( + item_id, + charges, + augment_one, + augment_two, + augment_three, + augment_four, + augment_five, + augment_six, + attuned, + slot_id + ); + } +} + void perl_register_bot() { perl::interpreter state(PERL_GET_THX); @@ -400,6 +460,7 @@ void perl_register_bot() package.add("AddBotItem", (void(*)(Bot*, uint16, uint32, uint16, bool, uint32, uint32, uint32, uint32))&Perl_Bot_AddBotItem); package.add("AddBotItem", (void(*)(Bot*, uint16, uint32, uint16, bool, uint32, uint32, uint32, uint32, uint32))&Perl_Bot_AddBotItem); package.add("AddBotItem", (void(*)(Bot*, uint16, uint32, uint16, bool, uint32, uint32, uint32, uint32, uint32, uint32))&Perl_Bot_AddBotItem); + package.add("AddItem", &Perl_Bot_AddItem); package.add("ApplySpell", (void(*)(Bot*, int))&Perl_Bot_ApplySpell); package.add("ApplySpell", (void(*)(Bot*, int, int))&Perl_Bot_ApplySpell); package.add("ApplySpell", (void(*)(Bot*, int, int, bool))&Perl_Bot_ApplySpell); @@ -420,6 +481,7 @@ void perl_register_bot() package.add("Fling", (void(*)(Bot*, float, float, float, float, bool, bool))&Perl_Bot_Fling); package.add("GetAugmentAt", &Perl_Bot_GetAugmentAt); package.add("GetAugmentIDAt", &Perl_Bot_GetAugmentIDAt); + package.add("GetAugmentIDsBySlotID", &Perl_Bot_GetAugmentIDsBySlotID); package.add("GetBaseAGI", &Perl_Bot_GetBaseAGI); package.add("GetBaseCHA", &Perl_Bot_GetBaseCHA); package.add("GetBaseDEX", &Perl_Bot_GetBaseDEX);