From 53a380132e095bc22e3c1e57de1606a50b077d31 Mon Sep 17 00:00:00 2001 From: insunaa Date: Mon, 1 Apr 2024 10:17:54 +0200 Subject: [PATCH] Chat/GM: Add unkillable command Closes https://github.com/cmangos/mangos-wotlk/pull/510 --- src/game/Chat/Chat.cpp | 1 + src/game/Chat/Chat.h | 1 + src/game/Chat/Level3.cpp | 15 +++++++++++++++ src/game/Entities/Player.cpp | 19 +++++++++++++++++++ src/game/Entities/Player.h | 6 ++++++ 5 files changed, 42 insertions(+) diff --git a/src/game/Chat/Chat.cpp b/src/game/Chat/Chat.cpp index fdee2742c8..f4b63b90d0 100644 --- a/src/game/Chat/Chat.cpp +++ b/src/game/Chat/Chat.cpp @@ -297,6 +297,7 @@ ChatCommand* ChatHandler::getCommandTable() { { "chat", SEC_ADMINISTRATOR, false, &ChatHandler::HandleGMChatCommand, "", nullptr }, { "fly", SEC_ADMINISTRATOR, false, &ChatHandler::HandleGMFlyCommand, "", nullptr }, + { "unkillable", SEC_ADMINISTRATOR, false, &ChatHandler::HandleGMUnkillableCommand, "", nullptr }, { "ingame", SEC_ADMINISTRATOR, true, &ChatHandler::HandleGMListIngameCommand, "", nullptr }, { "list", SEC_ADMINISTRATOR, true, &ChatHandler::HandleGMListFullCommand, "", nullptr }, { "mountup", SEC_ADMINISTRATOR, false, &ChatHandler::HandleGMMountUpCommand, "", nullptr }, diff --git a/src/game/Chat/Chat.h b/src/game/Chat/Chat.h index b3a1abcfbf..7233d8d6bd 100644 --- a/src/game/Chat/Chat.h +++ b/src/game/Chat/Chat.h @@ -350,6 +350,7 @@ class ChatHandler bool HandleGMCommand(char* args); bool HandleGMChatCommand(char* args); bool HandleGMFlyCommand(char* args); + bool HandleGMUnkillableCommand(char* args); bool HandleGMListFullCommand(char* args); bool HandleGMListIngameCommand(char* args); bool HandleGMMountUpCommand(char* args); diff --git a/src/game/Chat/Level3.cpp b/src/game/Chat/Level3.cpp index 99b9b192e5..b4d56d0463 100644 --- a/src/game/Chat/Level3.cpp +++ b/src/game/Chat/Level3.cpp @@ -5587,6 +5587,21 @@ bool ChatHandler::HandleGMFlyCommand(char* args) return true; } +bool ChatHandler::HandleGMUnkillableCommand(char* args) +{ + bool value; + if (!ExtractOnOff(&args, value)) + { + SendSysMessage(LANG_USE_BOL); + SetSentErrorMessage(true); + return false; + } + Player* target = m_session->GetPlayer(); + target->SetDeathPrevention(value); + PSendSysMessage("GM Unkillability %s.", value ? "enabled" : "disabled"); + return true; +} + bool ChatHandler::HandlePDumpLoadCommand(char* args) { char* file = ExtractQuotedOrLiteralArg(&args); diff --git a/src/game/Entities/Player.cpp b/src/game/Entities/Player.cpp index 623de8d8d6..180b4da6a2 100644 --- a/src/game/Entities/Player.cpp +++ b/src/game/Entities/Player.cpp @@ -21965,6 +21965,25 @@ void Player::SendLootError(ObjectGuid guid, LootError error) const SendDirectMessage(data); } +void Player::SetDeathPrevention(bool enable) +{ + if (enable) + m_ExtraFlags |= PLAYER_EXTRA_GM_UNKILLABLE; + else + m_ExtraFlags &= ~PLAYER_EXTRA_GM_UNKILLABLE; +} + +bool Player::IsPreventingDeath() const +{ + return m_ExtraFlags & PLAYER_EXTRA_GM_UNKILLABLE; +} + +void Player::ResetDeathTimer() +{ + // 6 minutes until repop at graveyard + m_deathTimer = 6 * MINUTE * IN_MILLISECONDS; +} + void Player::AddGCD(SpellEntry const& spellEntry, uint32 /*forcedDuration = 0*/, bool updateClient /*= false*/) { int32 gcdDuration = spellEntry.StartRecoveryTime; diff --git a/src/game/Entities/Player.h b/src/game/Entities/Player.h index f69ecece96..a25e45d6ee 100644 --- a/src/game/Entities/Player.h +++ b/src/game/Entities/Player.h @@ -520,6 +520,9 @@ enum PlayerExtraFlags // other states PLAYER_EXTRA_PVP_DEATH = 0x0100, // store PvP death status until corpse creating. PLAYER_EXTRA_WHISP_RESTRICTION = 0x0200, + + // death prevention + PLAYER_EXTRA_GM_UNKILLABLE = 0x0400, }; // 2^n values @@ -2294,6 +2297,9 @@ class Player : public Unit void SendLootError(ObjectGuid guid, LootError error) const; + void SetDeathPrevention(bool enable); + bool IsPreventingDeath() const override; + // cooldown system virtual void AddGCD(SpellEntry const& spellEntry, uint32 forcedDuration = 0, bool updateClient = false) override; virtual void AddCooldown(SpellEntry const& spellEntry, ItemPrototype const* itemProto = nullptr, bool permanent = false, uint32 forcedDuration = 0, bool ignoreCat = false) override;