Forked from https://github.com/ZhengPeiRu21/mod-leech
This commit is contained in:
42
src/Leech.cpp
Normal file
42
src/Leech.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, 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<bool>("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<bool>("Leech.DungeonsOnly", true) && !(player->GetMap()->IsDungeon()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto leechAmount = sConfigMgr->GetOption<float>("Leech.Amount", 0.05f);
|
||||
auto bp1 = static_cast<int32>(leechAmount * float(damage));
|
||||
player->CastCustomSpell(attacker, SPELL_HEAL, &bp1, nullptr, nullptr, true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Add all scripts in one
|
||||
void AddSC_mod_leech()
|
||||
{
|
||||
new Leech_UnitScript();
|
||||
}
|
||||
15
src/Leech.h
Normal file
15
src/Leech.h
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
#ifndef AZEROTHCORE_LEECH_H
|
||||
#define AZEROTHCORE_LEECH_H
|
||||
#include "ScriptMgr.h"
|
||||
#include "Player.h"
|
||||
#include "Config.h"
|
||||
#include <map>
|
||||
|
||||
enum LeechSpells
|
||||
{
|
||||
SPELL_HEAL = 18984
|
||||
};
|
||||
|
||||
|
||||
#endif //AZEROTHCORE_LEECH_H
|
||||
14
src/Leech_loader.cpp
Normal file
14
src/Leech_loader.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, 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();
|
||||
}
|
||||
Reference in New Issue
Block a user