From a67c6eeddff5a7207a4da7ff1abfc34427e2c6df Mon Sep 17 00:00:00 2001 From: Matteo Emili Date: Sat, 21 Jan 2017 14:10:00 +0100 Subject: [PATCH] New hooks OnAfterUpdateMaxPower and OnBeforeRollMeleeOutcomeAgainst --- src/game/Entities/Unit/StatSystem.cpp | 3 +++ src/game/Entities/Unit/Unit.cpp | 16 +++++++++------- src/game/Scripting/ScriptMgr.cpp | 15 +++++++++++++++ src/game/Scripting/ScriptMgr.h | 12 +++++++++++- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/game/Entities/Unit/StatSystem.cpp b/src/game/Entities/Unit/StatSystem.cpp index 9d6fa6a16..9110e2a0a 100644 --- a/src/game/Entities/Unit/StatSystem.cpp +++ b/src/game/Entities/Unit/StatSystem.cpp @@ -12,6 +12,7 @@ #include "SpellAuras.h" #include "SpellAuraEffects.h" #include "SpellMgr.h" +#include "ScriptMgr.h" inline bool _ModifyUInt32(bool apply, uint32& baseValue, int32& amount) { @@ -291,6 +292,8 @@ void Player::UpdateMaxPower(Powers power) float bonusPower = (power == POWER_MANA && GetCreatePowers(power) > 0) ? GetManaBonusFromIntellect() : 0; + sScriptMgr->OnAfterUpdateMaxPower(this, power, bonusPower); + float value = GetModifierValue(unitMod, BASE_VALUE) + GetCreatePowers(power); value *= GetModifierValue(unitMod, BASE_PCT); value += GetModifierValue(unitMod, TOTAL_VALUE) + bonusPower; diff --git a/src/game/Entities/Unit/Unit.cpp b/src/game/Entities/Unit/Unit.cpp index a4062b3f1..d01d56265 100644 --- a/src/game/Entities/Unit/Unit.cpp +++ b/src/game/Entities/Unit/Unit.cpp @@ -2184,13 +2184,15 @@ MeleeHitOutcome Unit::RollMeleeOutcomeAgainst(const Unit* victim, WeaponAttackTy float parry_chance = victim->GetUnitParryChance(); // Useful if want to specify crit & miss chances for melee, else it could be removed - ;//sLog->outStaticDebug("MELEE OUTCOME: miss %f crit %f dodge %f parry %f block %f", miss_chance, crit_chance, dodge_chance, parry_chance, block_chance); + //sLog->outStaticDebug("MELEE OUTCOME: miss %f crit %f dodge %f parry %f block %f", miss_chance, crit_chance, dodge_chance, parry_chance, block_chance); - return RollMeleeOutcomeAgainst(victim, attType, int32(crit_chance*100), int32(miss_chance*100), int32(dodge_chance*100), int32(parry_chance*100), int32(block_chance*100)); + return RollMeleeOutcomeAgainst(victim, attType, int32(crit_chance * 100), int32(miss_chance * 100), int32(dodge_chance * 100), int32(parry_chance * 100), int32(block_chance * 100)); } -MeleeHitOutcome Unit::RollMeleeOutcomeAgainst (const Unit* victim, WeaponAttackType attType, int32 crit_chance, int32 miss_chance, int32 dodge_chance, int32 parry_chance, int32 block_chance) const +MeleeHitOutcome Unit::RollMeleeOutcomeAgainst(const Unit* victim, WeaponAttackType attType, int32 crit_chance, int32 miss_chance, int32 dodge_chance, int32 parry_chance, int32 block_chance) const { + sScriptMgr->OnBeforeRollMeleeOutcomeAgainst(this, victim, attType, crit_chance, miss_chance, dodge_chance, parry_chance, block_chance); + if (victim->GetTypeId() == TYPEID_UNIT && victim->ToCreature()->IsInEvadeMode()) return MELEE_HIT_EVADE; @@ -2205,15 +2207,15 @@ MeleeHitOutcome Unit::RollMeleeOutcomeAgainst (const Unit* victim, WeaponAttackT int32 sum = 0, tmp = 0; int32 roll = urand (0, 10000); - ;//sLog->outStaticDebug ("RollMeleeOutcomeAgainst: skill bonus of %d for attacker", skillBonus); - ;//sLog->outStaticDebug ("RollMeleeOutcomeAgainst: rolled %d, miss %d, dodge %d, parry %d, block %d, crit %d", + //sLog->outStaticDebug ("RollMeleeOutcomeAgainst: skill bonus of %d for attacker", skillBonus); + //sLog->outStaticDebug ("RollMeleeOutcomeAgainst: rolled %d, miss %d, dodge %d, parry %d, block %d, crit %d", // roll, miss_chance, dodge_chance, parry_chance, block_chance, crit_chance); tmp = miss_chance; if (tmp > 0 && roll < (sum += tmp)) { - ;//sLog->outStaticDebug ("RollMeleeOutcomeAgainst: MISS"); + //sLog->outStaticDebug ("RollMeleeOutcomeAgainst: MISS"); return MELEE_HIT_MISS; } @@ -2229,7 +2231,7 @@ MeleeHitOutcome Unit::RollMeleeOutcomeAgainst (const Unit* victim, WeaponAttackT // only players can't dodge if attacker is behind if (victim->GetTypeId() == TYPEID_PLAYER && !victim->HasInArc(M_PI, this) && !victim->HasAuraType(SPELL_AURA_IGNORE_HIT_DIRECTION)) { - ;//sLog->outStaticDebug ("RollMeleeOutcomeAgainst: attack came from behind and victim was a player."); + //sLog->outStaticDebug ("RollMeleeOutcomeAgainst: attack came from behind and victim was a player."); } // Xinef: do not allow to dodge with CREATURE_FLAG_EXTRA_NO_DODGE flag else if (victim->GetTypeId() == TYPEID_PLAYER || !(victim->ToCreature()->GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_NO_DODGE)) diff --git a/src/game/Scripting/ScriptMgr.cpp b/src/game/Scripting/ScriptMgr.cpp index f516c0201..b3eb459b9 100644 --- a/src/game/Scripting/ScriptMgr.cpp +++ b/src/game/Scripting/ScriptMgr.cpp @@ -1525,6 +1525,11 @@ void ScriptMgr::ModifyHealRecieved(Unit* target, Unit* attacker, uint32& damage) FOREACH_SCRIPT(UnitScript)->ModifyHealRecieved(target, attacker, damage); } +void ScriptMgr::OnBeforeRollMeleeOutcomeAgainst(const Unit* attacker, const Unit* victim, WeaponAttackType attType, int32 &crit_chance, int32 &miss_chance, int32 &dodge_chance, int32 &parry_chance, int32 &block_chance) +{ + FOREACH_SCRIPT(UnitScript)->OnBeforeRollMeleeOutcomeAgainst(attacker, victim, attType, crit_chance, miss_chance, dodge_chance, parry_chance, block_chance); +} + void ScriptMgr::OnPlayerMove(Player* player, MovementInfo movementInfo, uint32 opcode) { FOREACH_SCRIPT(MovementHandlerScript)->OnPlayerMove(player, movementInfo, opcode); @@ -1535,6 +1540,16 @@ void ScriptMgr::OnBeforeBuyItemFromVendor(Player* player, uint64 vendorguid, uin FOREACH_SCRIPT(PlayerScript)->OnBeforeBuyItemFromVendor(player, vendorguid, vendorslot, item, count, bag, slot); } +void ScriptMgr::OnAfterStoreOrEquipNewItem(Player* player, uint32 vendorslot, uint32 &item, uint8 count, uint8 bag, uint8 slot, ItemTemplate const* pProto, Creature* pVendor, VendorItem const* crItem, bool bStore) +{ + FOREACH_SCRIPT(PlayerScript)->OnAfterStoreOrEquipNewItem(player, vendorslot, item, count, bag, slot, pProto, pVendor, crItem, bStore); +} + +void ScriptMgr::OnAfterUpdateMaxPower(Player* player, Powers& power, float& value) +{ + FOREACH_SCRIPT(PlayerScript)->OnAfterUpdateMaxPower(player, power, value); +} + AllMapScript::AllMapScript(const char* name) : ScriptObject(name) { diff --git a/src/game/Scripting/ScriptMgr.h b/src/game/Scripting/ScriptMgr.h index e8c96a495..dc9b53fb5 100644 --- a/src/game/Scripting/ScriptMgr.h +++ b/src/game/Scripting/ScriptMgr.h @@ -444,6 +444,8 @@ public: //Called when Damage is Dealt virtual uint32 DealDamage(Unit* AttackerUnit, Unit *pVictim, uint32 damage, DamageEffectType damagetype) { return damage; } + + virtual void OnBeforeRollMeleeOutcomeAgainst(const Unit* /*attacker*/, const Unit* /*victim*/, WeaponAttackType /*attType*/, int32& /*crit_chance*/, int32& /*miss_chance*/ , int32& /*dodge_chance*/ , int32& /*parry_chance*/ , int32& /*block_chance*/ ) { }; }; class MovementHandlerScript : public ScriptObject @@ -883,8 +885,12 @@ class PlayerScript : public ScriptObject virtual void OnQuestRewardItem(Player* player, Item* item, uint32 count) { } //Before buying something from any vendor - virtual void OnBeforeBuyItemFromVendor(Player* player, uint64 vendorguid, uint32 vendorslot, uint32 &item, uint8 count, uint8 bag, uint8 slot) { }; + virtual void OnBeforeBuyItemFromVendor(Player* /*player*/, uint64 /*vendorguid*/, uint32 /*vendorslot*/, uint32 &/*item*/, uint8 /*count*/, uint8 /*bag*/, uint8 /*slot*/) { }; + //Before buying something from any vendor + virtual void OnAfterStoreOrEquipNewItem(Player* /*player*/, uint32 /*vendorslot*/, uint32& /*item*/, uint8 /*count*/, uint8 /*bag*/, uint8 /*slot*/, ItemTemplate const* /*pProto*/, Creature* /*pVendor*/, VendorItem const* /*crItem*/, bool /*bStore*/) { }; + + virtual void OnAfterUpdateMaxPower(Player* /*player*/, Powers& /*power*/, float& /*value*/) { } }; class GuildScript : public ScriptObject @@ -1195,6 +1201,8 @@ class ScriptMgr void OnCreateItem(Player* player, Item* item, uint32 count); void OnQuestRewardItem(Player* player, Item* item, uint32 count); void OnBeforeBuyItemFromVendor(Player * player, uint64 vendorguid, uint32 vendorslot, uint32 &item, uint8 count, uint8 bag, uint8 slot); + void OnAfterStoreOrEquipNewItem(Player* player, uint32 vendorslot, uint32 &item, uint8 count, uint8 bag, uint8 slot, ItemTemplate const* pProto, Creature* pVendor, VendorItem const* crItem, bool bStore); + void OnAfterUpdateMaxPower(Player* player, Powers& power, float& value); public: /* GuildScript */ @@ -1242,6 +1250,8 @@ class ScriptMgr void ModifySpellDamageTaken(Unit* target, Unit* attacker, int32& damage); void ModifyHealRecieved(Unit* target, Unit* attacker, uint32& addHealth); uint32 DealDamage(Unit* AttackerUnit, Unit *pVictim, uint32 damage, DamageEffectType damagetype); + void OnBeforeRollMeleeOutcomeAgainst(const Unit* attacker, const Unit* victim, WeaponAttackType attType, int32 &crit_chance, int32 &miss_chance, int32 &dodge_chance, int32 &parry_chance, int32 &block_chance); + public: /* MovementHandlerScript */