From 760540f68733cb17c22260c6130fc7dd136635cb Mon Sep 17 00:00:00 2001 From: Flerp Date: Tue, 4 Nov 2025 17:19:09 -0800 Subject: [PATCH] Forked from https://github.com/ZhengPeiRu21/mod-leech --- LICENSE | 20 ++++++++++++++++---- README.md | 2 +- conf/leech.conf.dist | 32 ++++++++++++++++++++++++++++++++ src/Leech.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ src/Leech.h | 15 +++++++++++++++ src/Leech_loader.cpp | 14 ++++++++++++++ 6 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 conf/leech.conf.dist create mode 100644 src/Leech.cpp create mode 100644 src/Leech.h create mode 100644 src/Leech_loader.cpp diff --git a/LICENSE b/LICENSE index d2ddc54..9031171 100644 --- a/LICENSE +++ b/LICENSE @@ -1,9 +1,21 @@ MIT License -Copyright (c) 2025 AzerothCore +Copyright (c) 2021 AzerothCore -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index de92ec3..e08ae73 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # mod-leech - +An AzerothCore module that heals players when dealing damage. diff --git a/conf/leech.conf.dist b/conf/leech.conf.dist new file mode 100644 index 0000000..8571f08 --- /dev/null +++ b/conf/leech.conf.dist @@ -0,0 +1,32 @@ +# +# Copyright (C) 2016+ AzerothCore , released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3 +# + +[worldserver] + +######################################## +# Leech Config +######################################## +# +# Leech.Enable +# Description: Enable the module +# Default: 0 - Disabled +# 1 - Enabled +# + +Leech.Enable = 1 +# +# Leech.DungeonsOnly +# Description: Enable leeching only in content that would normally be group content (ie, dungeons and raids) +# Default: 1 - Enabled +# 0 - Disabled +# + +Leech.DungeonsOnly = 1 +# +# Leech.Amount +# Description: Amount of damage dealt that will be applied as a heal on the player. 0 is none, 0.5 is 50%, 1 is 100%, 2 is 200%, etc. +# Default: 0.05 - 5% +# + +Leech.Amount = 0.05 diff --git a/src/Leech.cpp b/src/Leech.cpp new file mode 100644 index 0000000..582e1e6 --- /dev/null +++ b/src/Leech.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2016+ AzerothCore , released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3 + */ + +#include "Leech.h" + +class Leech_UnitScript : public UnitScript +{ +public: + Leech_UnitScript() : UnitScript("Leech_UnitScript") { } + + void OnDamage(Unit* attacker, Unit* victim, uint32& damage) override + { + if (!sConfigMgr->GetOption("Leech.Enable", true) || !attacker) + { + return; + } + + bool isPet = attacker->GetOwner() && attacker->GetOwner()->GetTypeId() == TYPEID_PLAYER; + if (!isPet && attacker->GetTypeId() != TYPEID_PLAYER) + { + return; + } + Player* player = isPet ? attacker->GetOwner()->ToPlayer() : attacker->ToPlayer(); + + if (sConfigMgr->GetOption("Leech.DungeonsOnly", true) && !(player->GetMap()->IsDungeon())) + { + return; + } + + auto leechAmount = sConfigMgr->GetOption("Leech.Amount", 0.05f); + auto bp1 = static_cast(leechAmount * float(damage)); + player->CastCustomSpell(attacker, SPELL_HEAL, &bp1, nullptr, nullptr, true); + } +}; + + +// Add all scripts in one +void AddSC_mod_leech() +{ + new Leech_UnitScript(); +} diff --git a/src/Leech.h b/src/Leech.h new file mode 100644 index 0000000..c042a93 --- /dev/null +++ b/src/Leech.h @@ -0,0 +1,15 @@ + +#ifndef AZEROTHCORE_LEECH_H +#define AZEROTHCORE_LEECH_H +#include "ScriptMgr.h" +#include "Player.h" +#include "Config.h" +#include + +enum LeechSpells +{ + SPELL_HEAL = 18984 +}; + + +#endif //AZEROTHCORE_LEECH_H diff --git a/src/Leech_loader.cpp b/src/Leech_loader.cpp new file mode 100644 index 0000000..dc8ea05 --- /dev/null +++ b/src/Leech_loader.cpp @@ -0,0 +1,14 @@ +/* + * Copyright (C) 2016+ AzerothCore , released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3 + */ + +// From SC +void AddSC_mod_leech(); + +// Add all +// cf. the naming convention https://github.com/azerothcore/azerothcore-wotlk/blob/master/doc/changelog/master.md#how-to-upgrade-4 +// additionally replace all '-' in the module folder name with '_' here +void Addmod_leechScripts() +{ + AddSC_mod_leech(); +}