Reworking OnDamage to allow for better checks
This commit is contained in:
parent
fb88182e52
commit
9b41773110
@ -12,30 +12,27 @@ public:
|
||||
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 (!player)
|
||||
return;
|
||||
|
||||
|
||||
if (sConfigMgr->GetOption<bool>("Leech.DungeonsOnly", true) && !player->GetMap()->IsDungeon())
|
||||
return;
|
||||
uint32 requiredItem = sConfigMgr->GetOption<uint32>("Leech.RequiredItemId", 0u);
|
||||
if (requiredItem != 0)
|
||||
{
|
||||
if (!player || !player->HasItemCount(requiredItem, 1, false ))
|
||||
{
|
||||
if (!player->HasItemCount(requiredItem, 1, false))
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (sConfigMgr->GetOption<bool>("Leech.DungeonsOnly", true) && !(player->GetMap()->IsDungeon()))
|
||||
{
|
||||
|
||||
if (damage == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
auto leechAmount = sConfigMgr->GetOption<float>("Leech.Amount", 0.05f);
|
||||
auto bp1 = static_cast<int32>(leechAmount * float(damage));
|
||||
@ -43,7 +40,6 @@ if (sConfigMgr->GetOption<bool>("Leech.DungeonsOnly", true) && !(player->GetMap(
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Add all scripts in one
|
||||
void AddSC_mod_leech()
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user