diff --git a/zone/bot.cpp b/zone/bot.cpp index 24e6865f1..3d3377fd4 100644 --- a/zone/bot.cpp +++ b/zone/bot.cpp @@ -8752,18 +8752,32 @@ Bot* EntityList::GetBotByBotName(std::string botName) { return Result; } -Client* EntityList::GetBotOwnerByBotEntityID(uint16 entityID) { - Client* Result = nullptr; - if (entityID > 0) { - for (std::list::iterator botListItr = bot_list.begin(); botListItr != bot_list.end(); ++botListItr) { - Bot* tempBot = *botListItr; - if (tempBot && tempBot->GetID() == entityID) { - Result = tempBot->GetBotOwner()->CastToClient(); +Client* EntityList::GetBotOwnerByBotEntityID(uint32 entity_id) { + Client* c = nullptr; + + if (entity_id) { + for (const auto& b : bot_list) { + if (b && b->GetID() == entity_id) { + c = b->GetBotOwner()->CastToClient(); break; } } } - return Result; + + return c; +} + +Client* EntityList::GetBotOwnerByBotID(const uint32 bot_id) { + Client* c = nullptr; + + if (bot_id) { + const auto owner_id = database.botdb.GetOwnerID(bot_id); + if (owner_id) { + c = GetClientByCharID(owner_id); + } + } + + return c; } void EntityList::AddBot(Bot *new_bot, bool send_spawn_packet, bool dont_queue) { @@ -8790,7 +8804,7 @@ void EntityList::AddBot(Bot *new_bot, bool send_spawn_packet, bool dont_queue) { mob_list.insert(std::pair(new_bot->GetID(), new_bot)); parse->EventBot(EVENT_SPAWN, new_bot, nullptr, "", 0); - + new_bot->DispatchZoneControllerEvent(EVENT_SPAWN_ZONE, new_bot, "", 0, nullptr); } } diff --git a/zone/bot_database.cpp b/zone/bot_database.cpp index 0f87e8408..a4e3ea475 100644 --- a/zone/bot_database.cpp +++ b/zone/bot_database.cpp @@ -319,6 +319,20 @@ bool BotDatabase::LoadOwnerID(const uint32 bot_id, uint32& owner_id) return true; } +uint32 BotDatabase::GetOwnerID(const uint32 bot_id) +{ + if (!bot_id) { + return 0; + } + + const auto& l = BotDataRepository::FindOne(database, bot_id); + if (!l.bot_id) { + return 0; + } + + return l.owner_id; +} + bool BotDatabase::LoadBotID(const uint32 owner_id, const std::string& bot_name, uint32& bot_id) { if (!owner_id || bot_name.empty()) { diff --git a/zone/bot_database.h b/zone/bot_database.h index 923811211..24c973afe 100644 --- a/zone/bot_database.h +++ b/zone/bot_database.h @@ -55,6 +55,7 @@ public: bool LoadOwnerID(const std::string& bot_name, uint32& owner_id); bool LoadOwnerID(const uint32 bot_id, uint32& owner_id); + uint32 GetOwnerID(const uint32 bot_id); bool LoadBotID(const uint32 owner_id, const std::string& bot_name, uint32& bot_id); bool LoadBotID(const uint32 owner_id, const std::string& bot_name, uint32& bot_id, uint8& bot_class_id); diff --git a/zone/embparser.cpp b/zone/embparser.cpp index 2ffc7829d..e7faa608b 100644 --- a/zone/embparser.cpp +++ b/zone/embparser.cpp @@ -2025,6 +2025,21 @@ void PerlembParser::ExportEventVariables( break; } + case EVENT_DESPAWN: { + ExportVar(package_name.c_str(), "despawned_entity_id", npcmob->GetID()); + + if (npcmob->IsNPC()) { + ExportVar(package_name.c_str(), "despawned_bot_id", 0); + ExportVar(package_name.c_str(), "despawned_npc_id", npcmob->GetNPCTypeID()); +#ifdef BOTS + } else if (npcmob->IsBot()) { + ExportVar(package_name.c_str(), "despawned_bot_id", npcmob->CastToBot()->GetBotID()); + ExportVar(package_name.c_str(), "despawned_npc_id", 0); +#endif + } + + break; + } case EVENT_DESPAWN_ZONE: { ExportVar(package_name.c_str(), "despawned_entity_id", mob->GetID()); diff --git a/zone/entity.h b/zone/entity.h index b173861a5..a277779a5 100644 --- a/zone/entity.h +++ b/zone/entity.h @@ -628,7 +628,8 @@ private: Mob* GetMobByBotID(uint32 botID); Bot* GetBotByBotID(uint32 botID); Bot* GetBotByBotName(std::string botName); - Client* GetBotOwnerByBotEntityID(uint16 entityID); + Client* GetBotOwnerByBotEntityID(uint32 entity_id); + Client* GetBotOwnerByBotID(const uint32 bot_id); std::list GetBotsByBotOwnerCharacterID(uint32 botOwnerCharacterID); bool Bot_AICheckCloseBeneficialSpells(Bot* caster, uint8 iChance, float iRange, uint32 iSpellTypes); // TODO: Evaluate this closesly in hopes to eliminate diff --git a/zone/lua_entity_list.cpp b/zone/lua_entity_list.cpp index 223456451..79c5a0236 100644 --- a/zone/lua_entity_list.cpp +++ b/zone/lua_entity_list.cpp @@ -399,6 +399,16 @@ Lua_Bot_List Lua_EntityList::GetBotList() { return ret; } +Lua_Client Lua_EntityList::GetBotOwnerByBotEntityID(uint32 entity_id) { + Lua_Safe_Call_Class(Lua_Client); + return Lua_Client(self->GetBotOwnerByBotEntityID(entity_id)); +} + +Lua_Client Lua_EntityList::GetBotOwnerByBotID(uint32 bot_id) { + Lua_Safe_Call_Class(Lua_Client); + return Lua_Client(self->GetBotOwnerByBotID(bot_id)); +} + Lua_Bot_List Lua_EntityList::GetBotListByCharacterID(uint32 character_id) { Lua_Safe_Call_Class(Lua_Bot_List); Lua_Bot_List ret; @@ -649,6 +659,8 @@ luabind::scope lua_register_entity_list() { .def("GetBotByID", (Lua_Bot(Lua_EntityList::*)(uint32))&Lua_EntityList::GetBotByID) .def("GetBotByName", (Lua_Bot(Lua_EntityList::*)(std::string))&Lua_EntityList::GetBotByName) .def("GetBotList", (Lua_Bot_List(Lua_EntityList::*)(void))&Lua_EntityList::GetBotList) + .def("GetBotOwnerByBotEntityID", (Lua_Client(Lua_EntityList::*)(uint32))&Lua_EntityList::GetBotOwnerByBotEntityID) + .def("GetBotOwnerByBotID", (Lua_Client(Lua_EntityList::*)(uint32))&Lua_EntityList::GetBotOwnerByBotID) .def("GetBotListByCharacterID", (Lua_Bot_List(Lua_EntityList::*)(uint32))&Lua_EntityList::GetBotListByCharacterID) .def("GetBotListByCharacterID", (Lua_Bot_List(Lua_EntityList::*)(uint32,uint8))&Lua_EntityList::GetBotListByCharacterID) .def("GetBotListByClientName", (Lua_Bot_List(Lua_EntityList::*)(std::string))&Lua_EntityList::GetBotListByClientName) diff --git a/zone/lua_entity_list.h b/zone/lua_entity_list.h index c90a9e79c..3d4a4444d 100644 --- a/zone/lua_entity_list.h +++ b/zone/lua_entity_list.h @@ -133,6 +133,8 @@ public: #ifdef BOTS Lua_Bot GetBotByID(uint32 bot_id); Lua_Bot GetBotByName(std::string bot_name); + Lua_Client GetBotOwnerByBotEntityID(uint32 entity_id); + Lua_Client GetBotOwnerByBotID(uint32 bot_id); Lua_Bot_List GetBotList(); Lua_Bot_List GetBotListByCharacterID(uint32 character_id); Lua_Bot_List GetBotListByCharacterID(uint32 character_id, uint8 class_id); diff --git a/zone/lua_parser.cpp b/zone/lua_parser.cpp index f7b258841..579219580 100644 --- a/zone/lua_parser.cpp +++ b/zone/lua_parser.cpp @@ -213,6 +213,7 @@ LuaParser::LuaParser() { NPCArgumentDispatch[EVENT_LOOT_ZONE] = handle_npc_loot_zone; NPCArgumentDispatch[EVENT_SPAWN_ZONE] = handle_npc_spawn_zone; NPCArgumentDispatch[EVENT_PAYLOAD] = handle_npc_payload; + NPCArgumentDispatch[EVENT_DESPAWN_ZONE] = handle_npc_despawn_zone; PlayerArgumentDispatch[EVENT_SAY] = handle_player_say; PlayerArgumentDispatch[EVENT_ENVIRONMENTAL_DAMAGE] = handle_player_environmental_damage; diff --git a/zone/lua_parser_events.cpp b/zone/lua_parser_events.cpp index 1b6984229..9780ae08f 100644 --- a/zone/lua_parser_events.cpp +++ b/zone/lua_parser_events.cpp @@ -438,6 +438,21 @@ void handle_npc_spawn_zone( lua_setfield(L, -2, "other"); } +void handle_npc_despawn_zone( + QuestInterface *parse, + lua_State* L, + NPC* npc, + Mob *init, + std::string data, + uint32 extra_data, + std::vector *extra_pointers +) { + Lua_Mob l_mob(init); + luabind::adl::object l_mob_o = luabind::adl::object(L, l_mob); + l_mob_o.push(L); + lua_setfield(L, -2, "other"); +} + // Player void handle_player_say( QuestInterface *parse, diff --git a/zone/lua_parser_events.h b/zone/lua_parser_events.h index a2e19ca8a..0c44214c3 100644 --- a/zone/lua_parser_events.h +++ b/zone/lua_parser_events.h @@ -203,6 +203,16 @@ void handle_npc_payload( std::vector *extra_pointers ); +void handle_npc_despawn_zone( + QuestInterface *parse, + lua_State* L, + NPC* npc, + Mob *init, + std::string data, + uint32 extra_data, + std::vector *extra_pointers +); + // Player void handle_player_say( QuestInterface *parse, diff --git a/zone/perl_entity.cpp b/zone/perl_entity.cpp index 34763d122..0c9b08275 100644 --- a/zone/perl_entity.cpp +++ b/zone/perl_entity.cpp @@ -406,6 +406,16 @@ Bot* Perl_EntityList_GetBotByName(EntityList* self, std::string bot_name) // @ca return self->GetBotByBotName(bot_name); } +Client* Perl_EntityList_GetBotOwnerByBotEntityID(EntityList* self, uint32_t entity_id) // @categories Script Utility, Bot +{ + return self->GetBotOwnerByBotEntityID(entity_id); +} + +Client* Perl_EntityList_GetBotOwnerByBotID(EntityList* self, uint32_t bot_id) // @categories Script Utility, Bot +{ + return self->GetBotOwnerByBotID(bot_id); +} + perl::array Perl_EntityList_GetBotList(EntityList* self) // @categories Script Utility, Bot { perl::array result; @@ -618,6 +628,8 @@ void perl_register_entitylist() package.add("GetBotByID", &Perl_EntityList_GetBotByID); package.add("GetBotByName", &Perl_EntityList_GetBotByName); package.add("GetBotList", &Perl_EntityList_GetBotList); + package.add("GetBotOwnerByBotEntityID", (Client*(*)(EntityList*, uint32))&Perl_EntityList_GetBotOwnerByBotEntityID); + package.add("GetBotOwnerByBotID", (Client*(*)(EntityList*, uint32))&Perl_EntityList_GetBotOwnerByBotID); package.add("GetBotListByCharacterID", (perl::array(*)(EntityList*, uint32))&Perl_EntityList_GetBotListByCharacterID); package.add("GetBotListByCharacterID", (perl::array(*)(EntityList*, uint32, uint8))&Perl_EntityList_GetBotListByCharacterID); package.add("GetBotListByClientName", (perl::array(*)(EntityList*, std::string))&Perl_EntityList_GetBotListByClientName);