aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorariel- <ariel-@users.noreply.github.com>2016-12-31 00:21:39 -0300
committerDoctorKraft <DoctorKraft@users.noreply.github.com>2018-03-18 00:19:47 +0100
commit8bf7fa369fcbda3a8830dbc45b291634bacfd744 (patch)
tree8bbd5c48a56c6eba0fd7c91a5583052725be6444 /src
parent1e96702b3a922688502c93b92baee3cfe8220575 (diff)
Core/Player: Recast lost by death item obtain spells of any items held in the inventory when resurrecting
I HAS BUKKIT Closes #5184 (cherry picked from commit e1354c72e81ca7158b9b002e02f3a7f534a31547)
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Entities/Player/Player.cpp64
-rw-r--r--src/server/game/Entities/Player/Player.h2
2 files changed, 50 insertions, 16 deletions
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index e964818fe12..be90bdea1be 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -4244,6 +4244,9 @@ void Player::ResurrectPlayer(float restore_percent, bool applySickness)
// update visibility
UpdateObjectVisibility();
+ // recast lost by death auras of any items held in the inventory
+ CastAllObtainSpells();
+
if (!applySickness)
return;
@@ -7631,6 +7634,46 @@ void Player::_ApplyWeaponDamage(uint8 slot, Item* item, bool apply)
UpdateDamagePhysical(attType);
}
+void Player::CastAllObtainSpells()
+{
+ for (uint8 slot = INVENTORY_SLOT_ITEM_START; slot < INVENTORY_SLOT_ITEM_END; ++slot)
+ if (Item* item = GetItemByPos(INVENTORY_SLOT_BAG_0, slot))
+ ApplyItemObtainSpells(item, true);
+
+ for (uint8 i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; ++i)
+ {
+ Bag* bag = GetBagByPos(i);
+ if (!bag)
+ continue;
+
+ for (uint32 slot = 0; slot < bag->GetBagSize(); ++slot)
+ if (Item* item = bag->GetItemByPos(slot))
+ ApplyItemObtainSpells(item, true);
+ }
+}
+
+void Player::ApplyItemObtainSpells(Item* item, bool apply)
+{
+ ItemTemplate const* itemTemplate = item->GetTemplate();
+ for (uint8 i = 0; i < itemTemplate->Effects.size(); ++i)
+ {
+ if (itemTemplate->Effects[i]->TriggerType != ITEM_SPELLTRIGGER_ON_OBTAIN) // On obtain trigger
+ continue;
+
+ int32 const spellId = itemTemplate->Effects[i]->SpellID;
+ if (spellId <= 0)
+ continue;
+
+ if (apply)
+ {
+ if (!HasAura(spellId))
+ CastSpell(this, spellId, true, item);
+ }
+ else
+ RemoveAurasDueToSpell(spellId);
+ }
+}
+
void Player::ApplyItemDependentAuras(Item* item, bool apply)
{
if (apply)
@@ -11820,12 +11863,8 @@ Item* Player::_StoreItem(uint16 pos, Item* pItem, uint32 count, bool clone, bool
AddEnchantmentDurations(pItem);
AddItemDurations(pItem);
- const ItemTemplate* proto = pItem->GetTemplate();
- for (uint8 i = 0; i < proto->Effects.size(); ++i)
- if (proto->Effects[i]->TriggerType == ITEM_SPELLTRIGGER_ON_OBTAIN) // On obtain trigger
- if (bag == INVENTORY_SLOT_BAG_0 || (bag >= INVENTORY_SLOT_BAG_START && bag < INVENTORY_SLOT_BAG_END))
- if (!HasAura(proto->Effects[i]->SpellID))
- CastSpell(this, proto->Effects[i]->SpellID, true, pItem);
+ if (bag == INVENTORY_SLOT_BAG_0 || (bag >= INVENTORY_SLOT_BAG_START && bag < INVENTORY_SLOT_BAG_END))
+ ApplyItemObtainSpells(pItem, true);
return pItem;
}
@@ -11863,12 +11902,8 @@ Item* Player::_StoreItem(uint16 pos, Item* pItem, uint32 count, bool clone, bool
pItem2->SetState(ITEM_CHANGED, this);
- const ItemTemplate* proto = pItem2->GetTemplate();
- for (uint8 i = 0; i < proto->Effects.size(); ++i)
- if (proto->Effects[i]->TriggerType == ITEM_SPELLTRIGGER_ON_OBTAIN) // On obtain trigger
- if (bag == INVENTORY_SLOT_BAG_0 || (bag >= INVENTORY_SLOT_BAG_START && bag < INVENTORY_SLOT_BAG_END))
- if (!HasAura(proto->Effects[i]->SpellID))
- CastSpell(this, proto->Effects[i]->SpellID, true, pItem2);
+ if (bag == INVENTORY_SLOT_BAG_0 || (bag >= INVENTORY_SLOT_BAG_START && bag < INVENTORY_SLOT_BAG_END))
+ ApplyItemObtainSpells(pItem2, true);
return pItem2;
}
@@ -12327,10 +12362,7 @@ void Player::DestroyItem(uint8 bag, uint8 slot, bool update)
pItem->ClearSoulboundTradeable(this);
RemoveTradeableItem(pItem);
- const ItemTemplate* proto = pItem->GetTemplate();
- for (uint8 i = 0; i < proto->Effects.size(); ++i)
- if (proto->Effects[i]->TriggerType == ITEM_SPELLTRIGGER_ON_OBTAIN) // On obtain trigger
- RemoveAurasDueToSpell(proto->Effects[i]->SpellID);
+ ApplyItemObtainSpells(pItem, false);
ItemRemovedQuestCheck(pItem->GetEntry(), pItem->GetCount());
sScriptMgr->OnItemRemove(this, pItem);
diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h
index 3884a0cbbc8..11076546fd5 100644
--- a/src/server/game/Entities/Player/Player.h
+++ b/src/server/game/Entities/Player/Player.h
@@ -2030,6 +2030,8 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
void ResetAllPowers();
+ void CastAllObtainSpells();
+ void ApplyItemObtainSpells(Item* item, bool apply);
void ApplyItemDependentAuras(Item* item, bool apply);
void _ApplyItemMods(Item* item, uint8 slot, bool apply, bool updateItemAuras = true);