From a11482ff23ee17dcdbc7357facd0a335ab2a8680 Mon Sep 17 00:00:00 2001 From: Kinglykrab <89047260+Kinglykrab@users.noreply.github.com> Date: Tue, 23 Nov 2021 18:25:02 -0500 Subject: [PATCH] [Cleanup] Utilize ConvertSecondsToTime() method. (#1805) * [Cleanup] Utilize ConvertSecondsToTime() method. * Lowercase. --- zone/bot.cpp | 11 +++- zone/client_packet.cpp | 123 ++++++++++++++++------------------------- zone/effects.cpp | 15 +++-- 3 files changed, 67 insertions(+), 82 deletions(-) diff --git a/zone/bot.cpp b/zone/bot.cpp index 8765fbb75..5de3bc7e9 100644 --- a/zone/bot.cpp +++ b/zone/bot.cpp @@ -9549,8 +9549,15 @@ bool Bot::UseDiscipline(uint32 spell_id, uint32 target) { if(spells[spell_id].timer_id > 0 && spells[spell_id].timer_id < MAX_DISCIPLINE_TIMERS) SetDisciplineRecastTimer(spells[spell_id].timer_id, spell.recast_time); } else { - uint32 remain = (GetDisciplineRemainingTime(this, spells[spell_id].timer_id) / 1000); - GetOwner()->Message(Chat::White, "%s can use this discipline in %d minutes %d seconds.", GetCleanName(), (remain / 60), (remain % 60)); + uint32 remaining_time = (GetDisciplineRemainingTime(this, spells[spell_id].timer_id) / 1000); + GetOwner()->Message( + Chat::White, + fmt::format( + "{} can use this discipline in {}.", + GetCleanName(), + ConvertSecondsToTime(remaining_time) + ).c_str() + ); return false; } } diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index ef62a693b..555d90144 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -857,39 +857,18 @@ void Client::CompleteConnect() } if (zone && zone->GetInstanceTimer()) { - - bool is_permanent = false; - uint32 remaining_time_seconds = database.GetTimeRemainingInstance(zone->GetInstanceID(), is_permanent); - uint32 day = (remaining_time_seconds / 86400); - uint32 hour = (remaining_time_seconds / 3600) % 24; - uint32 minute = (remaining_time_seconds / 60) % 60; - uint32 second = (remaining_time_seconds / 1) % 60; - - if (day) { - Message( - Chat::Yellow, "%s (%u) will expire in %u days, %u hours, %u minutes, and %u seconds.", - zone->GetLongName(), zone->GetInstanceID(), day, hour, minute, second - ); - } - else if (hour) { - Message( - Chat::Yellow, "%s (%u) will expire in %u hours, %u minutes, and %u seconds.", - zone->GetLongName(), zone->GetInstanceID(), hour, minute, second - ); - } - else if (minute) { - Message( - Chat::Yellow, "%s (%u) will expire in %u minutes, and %u seconds.", - zone->GetLongName(), zone->GetInstanceID(), minute, second - ); - } - else { - Message( - Chat::Yellow, "%s (%u) will expire in in %u seconds.", - zone->GetLongName(), zone->GetInstanceID(), second - ); - } - + bool is_permanent = false; + uint32 remaining_time = database.GetTimeRemainingInstance(zone->GetInstanceID(), is_permanent); + auto time_string = ConvertSecondsToTime(remaining_time); + Message( + Chat::Yellow, + fmt::format( + "{} ({}) will expire in {}.", + zone->GetLongName(), + zone->GetInstanceID(), + time_string + ).c_str() + ); } SendRewards(); @@ -4963,54 +4942,44 @@ void Client::Handle_OP_Consider(const EQApplicationPacket *app) void Client::Handle_OP_ConsiderCorpse(const EQApplicationPacket *app) { - if (app->size != sizeof(Consider_Struct)) - { + if (app->size != sizeof(Consider_Struct)) { LogDebug("Size mismatch in Consider corpse expected [{}] got [{}]", sizeof(Consider_Struct), app->size); return; } + Consider_Struct* conin = (Consider_Struct*)app->pBuffer; - Corpse* tcorpse = entity_list.GetCorpseByID(conin->targetid); + Corpse* target = entity_list.GetCorpseByID(conin->targetid); std::string export_string = fmt::format("{}", conin->targetid); - if (tcorpse && tcorpse->IsNPCCorpse()) { - if (parse->EventPlayer(EVENT_CONSIDER_CORPSE, this, export_string, 0) == 1) { - return; - } - - uint32 min; uint32 sec; uint32 ttime; - if ((ttime = tcorpse->GetDecayTime()) != 0) { - sec = (ttime / 1000) % 60; // Total seconds - min = (ttime / 60000) % 60; // Total seconds / 60 drop .00 - char val1[20] = { 0 }; - char val2[20] = { 0 }; - MessageString(Chat::NPCQuestSay, CORPSE_DECAY1, ConvertArray(min, val1), ConvertArray(sec, val2)); - } - else { - MessageString(Chat::NPCQuestSay, CORPSE_DECAY_NOW); - } + if (!target) { + return; } - else if (tcorpse && tcorpse->IsPlayerCorpse()) { - if (parse->EventPlayer(EVENT_CONSIDER_CORPSE, this, export_string, 0) == 1) { - return; - } - uint32 day, hour, min, sec, ttime; - if ((ttime = tcorpse->GetDecayTime()) != 0) { - sec = (ttime / 1000) % 60; // Total seconds - min = (ttime / 60000) % 60; // Total seconds - hour = (ttime / 3600000) % 24; // Total hours - day = ttime / 86400000; // Total Days - if (day) - Message(0, "This corpse will decay in %i days, %i hours, %i minutes and %i seconds.", day, hour, min, sec); - else if (hour) - Message(0, "This corpse will decay in %i hours, %i minutes and %i seconds.", hour, min, sec); - else - Message(0, "This corpse will decay in %i minutes and %i seconds.", min, sec); + if (parse->EventPlayer(EVENT_CONSIDER_CORPSE, this, export_string, 0)) { + return; + } - Message(0, "This corpse %s be resurrected.", tcorpse->IsRezzed() ? "cannot" : "can"); - } - else { - MessageString(Chat::NPCQuestSay, CORPSE_DECAY_NOW); + uint32 decay_time = target->GetDecayTime(); + if (decay_time) { + auto time_string = ConvertSecondsToTime(decay_time, true); + Message( + Chat::NPCQuestSay, + fmt::format( + "This corpse will decay in {}.", + time_string + ).c_str() + ); + + if (target->IsPlayerCorpse()) { + Message( + Chat::NPCQuestSay, + fmt::format( + "This corpse {} be resurrected.", + target->IsRezzed() ? "cannot" : "can" + ).c_str() + ); } + } else { + MessageString(Chat::NPCQuestSay, CORPSE_DECAY_NOW); } } @@ -12943,8 +12912,14 @@ void Client::Handle_OP_Shielding(const EQApplicationPacket *app) pTimerType timer = pTimerShieldAbility; if (!p_timers.Expired(&database, timer, false)) { - uint32 remain = p_timers.GetRemainingTime(timer); - Message(Chat::White, "You can use the ability /shield in %d minutes %d seconds.", ((remain) / 60), (remain % 60)); + uint32 remaining_time = p_timers.GetRemainingTime(timer); + Message( + Chat::White, + fmt::format( + "You can use the ability /shield in {}.", + ConvertSecondsToTime(remaining_time) + ).c_str() + ); return; } diff --git a/zone/effects.cpp b/zone/effects.cpp index 3749bc91b..32f836919 100644 --- a/zone/effects.cpp +++ b/zone/effects.cpp @@ -774,12 +774,15 @@ bool Client::UseDiscipline(uint32 spell_id, uint32 target) { //Check the disc timer pTimerType DiscTimer = pTimerDisciplineReuseStart + spell.timer_id; if(!p_timers.Expired(&database, DiscTimer, false)) { // lets not set the reuse timer in case CastSpell fails (or we would have to turn off the timer, but CastSpell will set it as well) - /*char val1[20]={0};*/ //unused - /*char val2[20]={0};*/ //unused - uint32 remain = p_timers.GetRemainingTime(DiscTimer); - //MessageString(Chat::White, DISCIPLINE_CANUSEIN, ConvertArray((remain)/60,val1), ConvertArray(remain%60,val2)); - Message(0, "You can use this discipline in %d minutes %d seconds.", ((remain)/60), (remain%60)); - return(false); + uint32 remaining_time = p_timers.GetRemainingTime(DiscTimer); + Message( + Chat::White, + fmt::format( + "You can use this discipline in {}.", + ConvertSecondsToTime(remaining_time) + ).c_str() + ); + return false; } if(spell.recast_time > 0)