From d9ae70396b27879db8d53ac2d017c4254b544903 Mon Sep 17 00:00:00 2001 From: Aokromes Date: Mon, 3 Oct 2016 14:51:20 +0200 Subject: [PATCH] Core/Player: Implemented Titan's Grip damage reduction --- src/server/game/Entities/Player/Player.cpp | 53 ++++++++++++++++++++++ src/server/game/Entities/Player/Player.h | 5 +- src/server/game/Spells/SpellEffects.cpp | 4 +- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 99e4494a6f..6f45a8f7d1 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -412,6 +412,7 @@ Player::Player(WorldSession* session): Unit(true) m_canParry = false; m_canBlock = false; m_canTitanGrip = false; + m_titanGripPenaltySpellId = 0; m_temporaryUnsummonedPetNumber = 0; //cache for UNIT_CREATED_BY_SPELL to allow @@ -11942,6 +11943,9 @@ Item* Player::EquipItem(uint16 pos, Item* pItem, bool update) return pItem2; } + if (slot == EQUIPMENT_SLOT_MAINHAND || slot == EQUIPMENT_SLOT_OFFHAND) + CheckTitanGripPenalty(); + // only for full equip instead adding to stack UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EQUIP_ITEM, pItem->GetEntry()); UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EQUIP_EPIC_ITEM, pItem->GetEntry(), slot); @@ -11965,6 +11969,9 @@ void Player::QuickEquipItem(uint16 pos, Item* pItem) pItem->SendUpdateToPlayer(this); } + if (slot == EQUIPMENT_SLOT_MAINHAND || slot == EQUIPMENT_SLOT_OFFHAND) + CheckTitanGripPenalty(); + UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EQUIP_ITEM, pItem->GetEntry()); UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EQUIP_EPIC_ITEM, pItem->GetEntry(), slot); } @@ -12085,7 +12092,11 @@ void Player::RemoveItem(uint8 bag, uint8 slot, bool update) SetGuidValue(PLAYER_FIELD_INV_SLOT_HEAD + (slot * 2), ObjectGuid::Empty); if (slot < EQUIPMENT_SLOT_END) + { SetVisibleItemSlot(slot, nullptr); + if (slot == EQUIPMENT_SLOT_MAINHAND || slot == EQUIPMENT_SLOT_OFFHAND) + CheckTitanGripPenalty(); + } } else if (Bag* pBag = GetBagByPos(bag)) pBag->RemoveItem(slot, update); @@ -13125,12 +13136,54 @@ bool Player::IsUseEquipedWeapon(bool mainhand) const return !IsInFeralForm() && (!mainhand || !HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISARMED)); } +void Player::SetCanTitanGrip(bool value, uint32 penaltySpellId /*= 0*/) +{ + if (value == m_canTitanGrip) + return; + + if (!value) + CheckTitanGripPenalty(); + + m_canTitanGrip = value; + m_titanGripPenaltySpellId = penaltySpellId; +} + +void Player::CheckTitanGripPenalty() +{ + if (!CanTitanGrip()) + return; + + bool apply = IsUsingTwoHandedWeaponInOneHand(); + if (apply) + { + if (!HasAura(m_titanGripPenaltySpellId)) + CastSpell((Unit*)nullptr, m_titanGripPenaltySpellId, true); + } + else + RemoveAurasDueToSpell(m_titanGripPenaltySpellId); +} + bool Player::IsTwoHandUsed() const { Item* mainItem = GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); return mainItem && mainItem->GetTemplate()->InventoryType == INVTYPE_2HWEAPON && !CanTitanGrip(); } +bool Player::IsUsingTwoHandedWeaponInOneHand() const +{ + Item* mainItem = GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); + Item* offItem = GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND); + + if (!mainItem || !offItem) + return false; + + if (mainItem->GetTemplate()->InventoryType != INVTYPE_2HWEAPON && + offItem->GetTemplate()->InventoryType != INVTYPE_2HWEAPON) + return false; + + return true; +} + void Player::TradeCancel(bool sendback) { if (m_trade) diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index 056be1f6cc..545e1ff48b 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -1466,6 +1466,7 @@ class TC_GAME_API Player : public Unit, public GridObject uint32 GetArmorProficiency() const { return m_ArmorProficiency; } bool IsUseEquipedWeapon(bool mainhand) const; bool IsTwoHandUsed() const; + bool IsUsingTwoHandedWeaponInOneHand() const; void SendNewItem(Item* item, uint32 count, bool received, bool created, bool broadcast = false); bool BuyItemFromVendorSlot(ObjectGuid vendorguid, uint32 vendorslot, uint32 item, uint8 count, uint8 bag, uint8 slot); bool BuyCurrencyFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorSlot, uint32 currency, uint32 count); @@ -2152,7 +2153,8 @@ class TC_GAME_API Player : public Unit, public GridObject bool CanBlock() const { return m_canBlock; } void SetCanBlock(bool value); bool CanTitanGrip() const { return m_canTitanGrip; } - void SetCanTitanGrip(bool value) { m_canTitanGrip = value; } + void SetCanTitanGrip(bool value, uint32 penaltySpellId = 0); + void CheckTitanGripPenalty(); bool CanTameExoticPets() const { return IsGameMaster() || HasAuraType(SPELL_AURA_ALLOW_TAME_PET_TYPE); } void SetRegularAttackTime(); @@ -2746,6 +2748,7 @@ class TC_GAME_API Player : public Unit, public GridObject bool m_canParry; bool m_canBlock; bool m_canTitanGrip; + uint32 m_titanGripPenaltySpellId; uint8 m_swingErrorMsg; ////////////////////Rest System///////////////////// diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index 3bb674898e..c1c0952a3f 100644 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -5274,13 +5274,13 @@ void Spell::EffectDiscoverTaxi(SpellEffIndex effIndex) unitTarget->ToPlayer()->GetSession()->SendDiscoverNewTaxiNode(nodeid); } -void Spell::EffectTitanGrip(SpellEffIndex /*effIndex*/) +void Spell::EffectTitanGrip(SpellEffIndex effIndex) { if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) return; if (m_caster->GetTypeId() == TYPEID_PLAYER) - m_caster->ToPlayer()->SetCanTitanGrip(true); + m_caster->ToPlayer()->SetCanTitanGrip(true, m_spellInfo->Effects[effIndex].MiscValue); } void Spell::EffectRedirectThreat(SpellEffIndex /*effIndex*/)