diff --git a/src/PvPScript.cpp b/src/PvPScript.cpp index 9e0d5fe..93559a0 100644 --- a/src/PvPScript.cpp +++ b/src/PvPScript.cpp @@ -19,14 +19,13 @@ class PvPScript : public PlayerScript public: PvPScript() : PlayerScript("PvPScript") {} - void OnPlayerKilledByCreature(Creature* killer, Player* killed) + void OnPlayerKilledByCreature(Creature* killer, Player* killed/*, bool& durabilityLoss*/) { if (!sConfigMgr->GetOption("PvPChest", true)) return; if (!killer->IsPet()) - return; - + return; std::string name = killer->GetOwner()->GetName(); @@ -35,64 +34,18 @@ class PvPScript : public PlayerScript if (Pet* pet = killer->ToPet()) if (Player* owner = pet->GetOwner()) { - if (owner->GetSession()->GetRemoteAddress() == killed->GetSession()->GetRemoteAddress()) - return; - - // Dont drop loot if killed is not worth honor for owner - if (!owner->isHonorOrXPTarget(killed)) + if (!CheckConditions(owner, killed)) return; } - // if player has Ress sickness do not spawn chest - if (killed->HasAura(15007)) - return; - - //Gurubashi Arena - if (killed->GetMapId() == 0 && killed->GetZoneId() == 33) - for (int i = 0; i < int(AreatoIgnore.size()); ++i) - if (killed->GetAreaId() == AreatoIgnore[i]) - return; - - - // Dont drop chess if player is in battleground - if (killed->GetMap()->IsBattlegroundOrArena()) - return; - - //Dont Drop chest if player is no worth XP - if (!killed->isHonorOrXPTarget(killer->GetOwner())) + if (!CheckConditions(nullptr, killed)) return; // if target is killed and killer is pet if (!killed->IsAlive() && killer->IsPet()) { - if (GameObject* go = killer->SummonGameObject(SummonChest, killed->GetPositionX(), killed->GetPositionY(), killed->GetPositionZ(), killed->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, chestDespawn, false)) - { - switch (KillAnnounce) - { - case 1: //Announce in chat handler - ChatHandler(killed->GetSession()).PSendSysMessage("You have been killed by player [%s] ", name.c_str()); - break; - case 2: //Announce in notifaction - killed->GetSession()->SendNotification("You have been slain by [%s]", name.c_str()); - break; - case 3: // Announe in Notifaction and chathandler - killed->GetSession()->SendNotification("You have been slain by [%s]", name.c_str()); - ChatHandler(killed->GetSession()).PSendSysMessage("You have been killed by player [%s] ", name.c_str()); - break; - } - - killer->AddGameObject(go); - go->SetOwnerGUID(ObjectGuid::Empty); //This is so killed players can also loot the chest - - for (int i = EQUIPMENT_SLOT_START; i < EQUIPMENT_SLOT_END; ++i) - if (Item* pItem = killed->GetItemByPos(INVENTORY_SLOT_BAG_0, i)) - { - uint8 slot = pItem->GetSlot(); - LootStoreItem storeItem = LootStoreItem(pItem->GetEntry(), 0, 100, 0, LOOT_MODE_DEFAULT, 0, 1, 1); - go->loot.AddItem(storeItem); - killed->DestroyItem(INVENTORY_SLOT_BAG_0, slot, true); - } - } + AnnounceKill(KillAnnounce, killed, name.c_str()); + SpawnChest(killer, killed); } } @@ -103,64 +56,85 @@ class PvPScript : public PlayerScript std::string name = killer->GetName(); + if (!CheckConditions(killer, killed)) + return; + + if (!killed->IsAlive()) + { + SpawnChest(killer, killed); + AnnounceKill(KillAnnounce, killed, name.c_str()); + } + } + + void SpawnChest(Unit* killer, Player* killed) + { + if (GameObject* go = killer->SummonGameObject(SummonChest, killed->GetPositionX(), killed->GetPositionY(), killed->GetPositionZ(), killed->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, chestDespawn, false)) + { + killer->AddGameObject(go); + go->SetOwnerGUID(ObjectGuid::Empty); //This is so killed players can also loot the chest + AddChestItems(killed, go); + } + } + + bool CheckConditions(Player* killer, Player* killed) + { //if killer has same IP as death player do not drop loot as its cheating! if (spawnchestIP) if (killer->GetSession()->GetRemoteAddress() == killed->GetSession()->GetRemoteAddress()) - return; + return false; // if player has Ress sickness do not spawn chest if (killed->HasAura(15007)) - return; + return false; // If player kills self do not drop loot if (killer->GetGUID() == killed->GetGUID()) - return; - - //Gurubashi Arena - if (killed->GetMapId() == 0 && killed->GetZoneId() == 33) - for (int i = 0; i < int(AreatoIgnore.size()); ++i) - if (killed->GetAreaId() == AreatoIgnore[i]) - return; + return false; // if killer not worth honnor do not drop loot if (!killer->isHonorOrXPTarget(killed)) - return; + return false; // Dont drop chess if player is in battleground if (killed->GetMap()->IsBattlegroundOrArena()) - return; + return false; - if (!killed->IsAlive()) + //Gurubashi Arena + if (killed->GetMapId() == 0 && killed->GetZoneId() == 33) + for (int i = 0; i < int(AreatoIgnore.size()); ++i) + if (killed->GetAreaId() == AreatoIgnore[i]) + return false; + + return true; + } + + void AnnounceKill(uint32 phase, Player* killed, std::string name) + { + switch (phase) { - if (GameObject* go = killer->SummonGameObject(SummonChest, killed->GetPositionX(), killed->GetPositionY(), killed->GetPositionZ(), killed->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, chestDespawn, false)) - { - switch (KillAnnounce) - { - case 1: //Announce in chat handler - ChatHandler(killed->GetSession()).PSendSysMessage("You have been killed by player [%s] ", name.c_str()); - break; - case 2: //Announce in notifaction - killed->GetSession()->SendNotification("You have been slain by [%s]", name.c_str()); - break; - case 3: // Announe in Notifaction and chathandler - killed->GetSession()->SendNotification("You have been slain by [%s]", name.c_str()); - ChatHandler(killed->GetSession()).PSendSysMessage("You have been killed by player [%s] ", name.c_str()); - break; - } + case 1: //Announce in chat handler + ChatHandler(killed->GetSession()).PSendSysMessage("You have been killed by player [%s] ", name.c_str()); + break; + case 2: //Announce in notifaction + killed->GetSession()->SendNotification("You have been slain by [%s]", name.c_str()); + break; + case 3: // Announe in Notifaction and chathandler + killed->GetSession()->SendNotification("You have been slain by [%s]", name.c_str()); + ChatHandler(killed->GetSession()).PSendSysMessage("You have been killed by player [%s] ", name.c_str()); + break; + } + } - killer->AddGameObject(go); - go->SetOwnerGUID(ObjectGuid::Empty); //This is so killed players can also loot the chest - - for (uint8 i = EQUIPMENT_SLOT_START; i < EQUIPMENT_SLOT_END; ++i) - if (Item* pItem = killed->GetItemByPos(INVENTORY_SLOT_BAG_0, i)) - { - uint8 slot = pItem->GetSlot(); - LootStoreItem storeItem = LootStoreItem(pItem->GetEntry(), 0, 100, 0, LOOT_MODE_DEFAULT, 0, 1, 1); - go->loot.AddItem(storeItem); - killed->DestroyItem(INVENTORY_SLOT_BAG_0, slot, true); - } + void AddChestItems(Player* killed, GameObject* go) + { + for (uint8 i = EQUIPMENT_SLOT_START; i < EQUIPMENT_SLOT_END; ++i) + if (Item* pItem = killed->GetItemByPos(INVENTORY_SLOT_BAG_0, i)) + { + uint8 slot = pItem->GetSlot(); + LootStoreItem storeItem = LootStoreItem(pItem->GetEntry(), 0, 100, 0, LOOT_MODE_DEFAULT, 0, 1, 1); + go->loot.AddItem(storeItem); + killed->DestroyItem(INVENTORY_SLOT_BAG_0, slot, true); } - } } };