From d75afd468834b7fca885113e914cc036fac50619 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Mon, 5 Nov 2018 00:26:52 -0600 Subject: [PATCH] Allow display window to be snoozed --- common/emu_constants.h | 5 +++ zone/attack.cpp | 12 +++++- zone/client.cpp | 96 ++++++++++++++++++++++++++++-------------- zone/client.h | 5 +++ zone/client_packet.cpp | 45 +++++++++++++------- zone/command.cpp | 2 +- zone/mob.cpp | 4 +- zone/mob_info.cpp | 13 +++++- 8 files changed, 131 insertions(+), 51 deletions(-) diff --git a/common/emu_constants.h b/common/emu_constants.h index db49252a3..4fbdd107d 100644 --- a/common/emu_constants.h +++ b/common/emu_constants.h @@ -77,6 +77,11 @@ namespace EQEmu } // namespace invtype + namespace popupresponse { + const int32 SERVER_INTERNAL_USE_BASE = 2000000000; + const int32 MOB_INFO_DISMISS = 2000000001; + } + namespace invslot { using namespace RoF2::invslot::enum_; diff --git a/zone/attack.cpp b/zone/attack.cpp index 22e10f842..8ddd5e139 100644 --- a/zone/attack.cpp +++ b/zone/attack.cpp @@ -5468,4 +5468,14 @@ void Mob::SetSpawnedInWater(bool spawned_in_water) { int32 Mob::GetHPRegen() const { return hp_regen; -} \ No newline at end of file +} + +bool Client::GetDisplayMobInfoWindow() const +{ + return display_mob_info_window; +} + +void Client::SetDisplayMobInfoWindow(bool display_mob_info_window) +{ + Client::display_mob_info_window = display_mob_info_window; +} diff --git a/zone/client.cpp b/zone/client.cpp index 564db321c..3877410d3 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -166,6 +166,7 @@ Client::Client(EQStreamInterface* ieqs) for (int client_filter = 0; client_filter < _FilterCount; client_filter++) ClientFilters[client_filter] = FilterShow; + display_mob_info_window = true; character_id = 0; conn_state = NoPacketsReceived; client_data_loaded = false; @@ -4031,9 +4032,9 @@ void Client::SetHoTT(uint32 mobid) { void Client::SendPopupToClient(const char *Title, const char *Text, uint32 PopupID, uint32 Buttons, uint32 Duration) { - auto outapp = new EQApplicationPacket(OP_OnLevelMessage, sizeof(OnLevelMessage_Struct)); - OnLevelMessage_Struct *olms = (OnLevelMessage_Struct *)outapp->pBuffer; + + OnLevelMessage_Struct *olms = (OnLevelMessage_Struct *) outapp->pBuffer; if ((strlen(Title) > (sizeof(olms->Title) - 1)) || (strlen(Text) > (sizeof(olms->Text) - 1))) { safe_delete(outapp); @@ -4045,12 +4046,14 @@ void Client::SendPopupToClient(const char *Title, const char *Text, uint32 Popup olms->Buttons = Buttons; - if (Duration > 0) + if (Duration > 0) { olms->Duration = Duration * 1000; - else + } + else { olms->Duration = 0xffffffff; + } - olms->PopupID = PopupID; + olms->PopupID = PopupID; olms->NegativeID = 0; sprintf(olms->ButtonName0, "%s", "Yes"); @@ -4059,16 +4062,29 @@ void Client::SendPopupToClient(const char *Title, const char *Text, uint32 Popup safe_delete(outapp); } -void Client::SendFullPopup(const char *Title, const char *Text, uint32 PopupID, uint32 NegativeID, uint32 Buttons, uint32 Duration, const char *ButtonName0, const char *ButtonName1, uint32 SoundControls) { +void Client::SendFullPopup( + const char *Title, + const char *Text, + uint32 PopupID, + uint32 NegativeID, + uint32 Buttons, + uint32 Duration, + const char *ButtonName0, + const char *ButtonName1, + uint32 SoundControls +) +{ auto outapp = new EQApplicationPacket(OP_OnLevelMessage, sizeof(OnLevelMessage_Struct)); - OnLevelMessage_Struct *olms = (OnLevelMessage_Struct *)outapp->pBuffer; - if((strlen(Text) > (sizeof(olms->Text)-1)) || (strlen(Title) > (sizeof(olms->Title) - 1)) ) { + OnLevelMessage_Struct *olms = (OnLevelMessage_Struct *) outapp->pBuffer; + + if ((strlen(Text) > (sizeof(olms->Text) - 1)) || (strlen(Title) > (sizeof(olms->Title) - 1))) { safe_delete(outapp); return; } - if (ButtonName0 && ButtonName1 && ( (strlen(ButtonName0) > (sizeof(olms->ButtonName0) - 1)) || (strlen(ButtonName1) > (sizeof(olms->ButtonName1) - 1)) ) ) { + if (ButtonName0 && ButtonName1 && ((strlen(ButtonName0) > (sizeof(olms->ButtonName0) - 1)) || + (strlen(ButtonName1) > (sizeof(olms->ButtonName1) - 1)))) { safe_delete(outapp); return; } @@ -4077,31 +4093,47 @@ void Client::SendFullPopup(const char *Title, const char *Text, uint32 PopupID, strcpy(olms->Text, Text); olms->Buttons = Buttons; - - if (ButtonName0 == NULL || ButtonName1 == NULL) { + + if (ButtonName0 == nullptr || ButtonName1 == nullptr) { sprintf(olms->ButtonName0, "%s", "Yes"); sprintf(olms->ButtonName1, "%s", "No"); - } else { + } + else { strcpy(olms->ButtonName0, ButtonName0); strcpy(olms->ButtonName1, ButtonName1); } - if(Duration > 0) + if (Duration > 0) { olms->Duration = Duration * 1000; - else + } + else { olms->Duration = 0xffffffff; + } - olms->PopupID = PopupID; - olms->NegativeID = NegativeID; + olms->PopupID = PopupID; + olms->NegativeID = NegativeID; olms->SoundControls = SoundControls; QueuePacket(outapp); safe_delete(outapp); } -void Client::SendWindow(uint32 PopupID, uint32 NegativeID, uint32 Buttons, const char *ButtonName0, const char *ButtonName1, uint32 Duration, int title_type, Client* target, const char *Title, const char *Text, ...) { +void Client::SendWindow( + uint32 PopupID, + uint32 NegativeID, + uint32 Buttons, + const char *ButtonName0, + const char *ButtonName1, + uint32 Duration, + int title_type, + Client *target, + const char *Title, + const char *Text, + ... +) +{ va_list argptr; - char buffer[4096]; + char buffer[4096]; va_start(argptr, Text); vsnprintf(buffer, sizeof(buffer), Text, argptr); @@ -4109,23 +4141,23 @@ void Client::SendWindow(uint32 PopupID, uint32 NegativeID, uint32 Buttons, const size_t len = strlen(buffer); - auto app = new EQApplicationPacket(OP_OnLevelMessage, sizeof(OnLevelMessage_Struct)); - OnLevelMessage_Struct* olms=(OnLevelMessage_Struct*)app->pBuffer; + auto app = new EQApplicationPacket(OP_OnLevelMessage, sizeof(OnLevelMessage_Struct)); + OnLevelMessage_Struct *olms = (OnLevelMessage_Struct *) app->pBuffer; - if(strlen(Text) > (sizeof(olms->Text)-1)) { + if (strlen(Text) > (sizeof(olms->Text) - 1)) { safe_delete(app); return; } - if(!target) + if (!target) { title_type = 0; + } - switch (title_type) - { + switch (title_type) { case 1: { char name[64] = ""; strcpy(name, target->GetName()); - if(target->GetLastName()) { + if (target->GetLastName()) { char last_name[64] = ""; strcpy(last_name, target->GetLastName()); strcat(name, " "); @@ -4135,8 +4167,8 @@ void Client::SendWindow(uint32 PopupID, uint32 NegativeID, uint32 Buttons, const break; } case 2: { - if(target->GuildID()) { - char *guild_name = (char*)guild_mgr.GetGuildName(target->GuildID()); + if (target->GuildID()) { + char *guild_name = (char *) guild_mgr.GetGuildName(target->GuildID()); strcpy(olms->Title, guild_name); } else { @@ -4150,19 +4182,21 @@ void Client::SendWindow(uint32 PopupID, uint32 NegativeID, uint32 Buttons, const } } - memcpy(olms->Text, buffer, len+1); + memcpy(olms->Text, buffer, len + 1); olms->Buttons = Buttons; sprintf(olms->ButtonName0, "%s", ButtonName0); sprintf(olms->ButtonName1, "%s", ButtonName1); - if(Duration > 0) + if (Duration > 0) { olms->Duration = Duration * 1000; - else + } + else { olms->Duration = 0xffffffff; + } - olms->PopupID = PopupID; + olms->PopupID = PopupID; olms->NegativeID = NegativeID; FastQueuePacket(&app); diff --git a/zone/client.h b/zone/client.h index f14dc9336..9e2a459f9 100644 --- a/zone/client.h +++ b/zone/client.h @@ -246,6 +246,9 @@ public: std::unordered_map close_mobs; bool is_client_moving; + void SetDisplayMobInfoWindow(bool display_mob_info_window); + bool GetDisplayMobInfoWindow() const; + //abstract virtual function implementations required by base abstract class virtual bool Death(Mob* killerMob, int32 damage, uint16 spell_id, EQEmu::skills::SkillType attack_skill); virtual void Damage(Mob* from, int32 damage, uint16 spell_id, EQEmu::skills::SkillType attack_skill, bool avoidable = true, int8 buffslot = -1, bool iBuffTic = false, eSpecialAttacks special = eSpecialAttacks::None); @@ -1458,6 +1461,8 @@ private: int Haste; //precalced value uint32 tmSitting; // time stamp started sitting, used for HP regen bonus added on MAY 5, 2004 + bool display_mob_info_window; + int32 max_end; int32 current_endurance; diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index ceb242890..84f486055 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -10885,33 +10885,46 @@ void Client::Handle_OP_PopupResponse(const EQApplicationPacket *app) { if (app->size != sizeof(PopupResponse_Struct)) { - Log(Logs::General, Logs::None, "Size mismatch in OP_PopupResponse expected %i got %i", - sizeof(PopupResponse_Struct), app->size); + Log(Logs::General, + Logs::None, + "Size mismatch in OP_PopupResponse expected %i got %i", + sizeof(PopupResponse_Struct), + app->size); + DumpPacket(app); return; } - PopupResponse_Struct *prs = (PopupResponse_Struct*)app->pBuffer; - // Handle any EQEmu defined popup Ids first - switch (prs->popupid) - { - case POPUPID_UPDATE_SHOWSTATSWINDOW: - if (GetTarget() && GetTarget()->IsClient()) - GetTarget()->CastToClient()->SendStatsWindow(this, true); - else - SendStatsWindow(this, true); - return; + PopupResponse_Struct *popup_response = (PopupResponse_Struct *) app->pBuffer; - default: - break; + /** + * Handle any EQEmu defined popup Ids first + */ + switch (popup_response->popupid) { + case POPUPID_UPDATE_SHOWSTATSWINDOW: + if (GetTarget() && GetTarget()->IsClient()) { + GetTarget()->CastToClient()->SendStatsWindow(this, true); + } + else { + SendStatsWindow(this, true); + } + return; + break; + + case EQEmu::popupresponse::MOB_INFO_DISMISS: + this->SetDisplayMobInfoWindow(false); + this->Message(15, "GM Mob display window snoozed in this zone..."); + break; + default: + break; } char buf[16]; - sprintf(buf, "%d\0", prs->popupid); + sprintf(buf, "%d\0", popup_response->popupid); parse->EventPlayer(EVENT_POPUP_RESPONSE, this, buf, 0); - Mob* Target = GetTarget(); + Mob *Target = GetTarget(); if (Target && Target->IsNPC()) { parse->EventNPC(EVENT_POPUP_RESPONSE, Target->CastToNPC(), this, buf, 0); } diff --git a/zone/command.cpp b/zone/command.cpp index 4cc8b8a54..40f9d7a91 100644 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -249,7 +249,7 @@ int command_init(void) command_add("lastname", "[new lastname] - Set your or your player target's lastname", 50, command_lastname) || command_add("level", "[level] - Set your or your target's level", 10, command_level) || command_add("listnpcs", "[name/range] - Search NPCs", 20, command_listnpcs) || - command_add("list", "[npc] [name|all] - Search entities", 20, command_list) || + command_add("list", "[npcs|players|corpses|doors|objects] [search] - Search entities", 20, command_list) || command_add("listpetition", "- List petitions", 50, command_listpetition) || command_add("load_shared_memory", "[shared_memory_name] - Reloads shared memory and uses the input as output", 250, command_load_shared_memory) || command_add("loc", "- Print out your or your target's current location and heading", 0, command_loc) || diff --git a/zone/mob.cpp b/zone/mob.cpp index 90a999a0f..0976b3783 100644 --- a/zone/mob.cpp +++ b/zone/mob.cpp @@ -3489,7 +3489,9 @@ void Mob::SetTarget(Mob *mob) else if (IsClient()) { parse->EventPlayer(EVENT_TARGET_CHANGE, CastToClient(), "", 0); - this->DisplayInfo(mob); + if (this->CastToClient()->admin > 200) { + this->DisplayInfo(mob); + } } if (IsPet() && GetOwner() && GetOwner()->IsClient()) { diff --git a/zone/mob_info.cpp b/zone/mob_info.cpp index 7ae249393..bb6598641 100644 --- a/zone/mob_info.cpp +++ b/zone/mob_info.cpp @@ -362,6 +362,17 @@ void Mob::DisplayInfo(Mob *mob) std::cout << "Window Length: " << window_text.length() << std::endl; // std::cout << "Window " << window_text << std::endl; - client->SendPopupToClient("Entity Info", window_text.c_str()); + if (client->GetDisplayMobInfoWindow()) { + client->SendFullPopup( + "GM: Entity Info", + window_text.c_str(), + EQEmu::popupresponse::MOB_INFO_DISMISS, + 0, + 100, + 10, + "Snooze", + "OK" + ); + } } }