aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQAston <none@none>2009-05-15 16:37:22 +0200
committerQAston <none@none>2009-05-15 16:37:22 +0200
commit47d5fc51c512c3f53e70ca99bc0548840d515d97 (patch)
treec8d0ae3051f704adf447800fcec049224a1ae824
parenta796012723dd2410a150264a4f32f00bc570ef76 (diff)
*Item enchancment/proc patch - original code by Thenecromancer
-void Player::CastItemCombatSpell(Item *item,Unit* Target, WeaponAttackType attType) -{ - if(!item || item->IsBroken()) - return; - - ItemPrototype const *proto = item->GetProto(); - if(!proto) - return; +void Player::CastItemCombatSpell(Item *item, CalcDamageInfo *damageInfo, ItemPrototype const * proto) +{ + Unit * Target = damageInfo->target; + WeaponAttackType attType = damageInfo->attackType; if (!Target || Target == this ) return; - for (int i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i) - { - _Spell const& spellData = proto->Spells[i]; - - // no spell - if(!spellData.SpellId ) - continue; - - // wrong triggering type - if(spellData.SpellTrigger != ITEM_SPELLTRIGGER_CHANCE_ON_HIT) - continue; - - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellData.SpellId); - if(!spellInfo) - { - sLog.outError("WORLD: unknown Item spellid %i", spellData.SpellId); - continue; - } - - // not allow proc extra attack spell at extra attack - if( m_extraAttacks && IsSpellHaveEffect(spellInfo,SPELL_EFFECT_ADD_EXTRA_ATTACKS) ) - return; - - float chance = spellInfo->procChance; - - if(spellData.SpellPPMRate) - { - uint32 WeaponSpeed = GetAttackTime(attType); - chance = GetPPMProcChance(WeaponSpeed, spellData.SpellPPMRate, spellInfo); - } - else if(chance > 100.0f) - { - chance = GetWeaponProcChance(); - } - - if (roll_chance_f(chance)) - CastSpell(Target, spellInfo->Id, true, item); + // Can do effect if any damage done to target + if (damageInfo->damage) + { + for (int i = 0; i < 5; i++) + { + _Spell const& spellData = proto->Spells[i]; + + // no spell + if(!spellData.SpellId ) + continue; + + // wrong triggering type + if(spellData.SpellTrigger != ITEM_SPELLTRIGGER_CHANCE_ON_HIT) + continue; + + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellData.SpellId); + if(!spellInfo) + { + sLog.outError("WORLD: unknown Item spellid %i", spellData.SpellId); + continue; + } + + // not allow proc extra attack spell at extra attack + if( m_extraAttacks && IsSpellHaveEffect(spellInfo,SPELL_EFFECT_ADD_EXTRA_ATTACKS) ) + return; + + float chance = spellInfo->procChance; + + if(spellData.SpellPPMRate) + { + uint32 WeaponSpeed = GetAttackTime(attType); + chance = GetPPMProcChance(WeaponSpeed, spellData.SpellPPMRate, spellInfo); + } + else if(chance > 100.0f) + { + chance = GetWeaponProcChance(); + } + + if (roll_chance_f(chance)) + CastSpell(Target, spellInfo->Id, true, item); + } } // item combat enchantments @@ -6993,6 +6993,21 @@ if(pEnchant->type[s]!=ITEM_ENCHANTMENT_TYPE_COMBAT_SPELL) continue; + SpellEnchantProcEntry const* entry = spellmgr.GetSpellEnchantProcEvent(enchant_id); + + if (entry && entry->procEx) + { + // Check hit/crit/dodge/parry requirement + if((entry->procEx & damageInfo->procEx) == 0) + continue; + } + else + { + // Can do effect if any damage done to target + if (!(damageInfo->damage)) + continue; + } + SpellEntry const *spellInfo = sSpellStore.LookupEntry(pEnchant->spellid[s]); if (!spellInfo) { @@ -7001,6 +7016,18 @@ } float chance = pEnchant->amount[s] != 0 ? float(pEnchant->amount[s]) : GetWeaponProcChance(); + + if (entry && entry->PPMChance) + { + uint32 WeaponSpeed = GetAttackTime(attType); + chance = GetPPMProcChance(WeaponSpeed, entry->PPMChance, spellInfo); + } + else if (entry && entry->customChance) + chance = entry->customChance; + + // Apply spell mods + ApplySpellMod(pEnchant->spellid[s],SPELLMOD_CHANCE_OF_SUCCESS,chance); + if (roll_chance_f(chance)) { if(IsPositiveSpell(pEnchant->spellid[s])) @@ -7012,6 +7039,7 @@ } } + void Player::CastItemUseSpell(Item *item,SpellCastTargets const& targets,uint8 cast_count, uint32 glyphIndex) { ItemPrototype const* proto = item->GetProto(); --HG-- branch : trunk
-rw-r--r--src/game/Player.h2
-rw-r--r--src/game/SpellMgr.cpp52
-rw-r--r--src/game/SpellMgr.h19
-rw-r--r--src/game/Unit.cpp36
-rw-r--r--src/game/World.cpp3
5 files changed, 106 insertions, 6 deletions
diff --git a/src/game/Player.h b/src/game/Player.h
index 0223364cce0..230d80785a7 100644
--- a/src/game/Player.h
+++ b/src/game/Player.h
@@ -1714,7 +1714,7 @@ class TRINITY_DLL_SPEC Player : public Unit
void ApplyItemEquipSpell(Item *item, bool apply, bool form_change = false);
void ApplyEquipSpell(SpellEntry const* spellInfo, Item* item, bool apply, bool form_change = false);
void UpdateEquipSpellsAtFormChange();
- void CastItemCombatSpell(Item *item,Unit* Target, WeaponAttackType attType);
+ void CastItemCombatSpell(Item *item, CalcDamageInfo *damageInfo, ItemPrototype const * proto);
void CastItemUseSpell(Item *item,SpellCastTargets const& targets,uint8 cast_count, uint32 glyphIndex);
void SendInitWorldStates(uint32 zone, uint32 area);
diff --git a/src/game/SpellMgr.cpp b/src/game/SpellMgr.cpp
index 4e5a4744e9a..49c88086c7a 100644
--- a/src/game/SpellMgr.cpp
+++ b/src/game/SpellMgr.cpp
@@ -1351,6 +1351,58 @@ void SpellMgr::LoadSpellThreats()
sLog.outString();
}
+void SpellMgr::LoadSpellEnchantProcData()
+{
+ mSpellEnchantProcEventMap.clear(); // need for reload case
+
+ uint32 count = 0;
+
+ // 0 1 2 3
+ QueryResult *result = WorldDatabase.Query("SELECT entry, customChance, PPMChance, procEx FROM spell_enchant_proc_data");
+ if( !result )
+ {
+
+ barGoLink bar( 1 );
+
+ bar.step();
+
+ sLog.outString();
+ sLog.outString( ">> Loaded %u spell enchant proc event conditions", count );
+ return;
+ }
+
+ barGoLink bar( result->GetRowCount() );
+ do
+ {
+ Field *fields = result->Fetch();
+
+ bar.step();
+
+ uint32 enchantId = fields[0].GetUInt32();
+
+ SpellItemEnchantmentEntry const *ench = sSpellItemEnchantmentStore.LookupEntry(enchantId);
+ if (!ench)
+ {
+ sLog.outErrorDb("Enchancment %u listed in `spell_enchant_proc_data` does not exist", enchantId);
+ continue;
+ }
+
+ SpellEnchantProcEntry spe;
+
+ spe.customChance = fields[1].GetUInt32();
+ spe.PPMChance = fields[2].GetFloat();
+ spe.procEx = fields[3].GetUInt32();
+
+ mSpellEnchantProcEventMap[enchantId] = spe;
+
+ ++count;
+ } while( result->NextRow() );
+
+ delete result;
+
+ sLog.outString( ">> Loaded %u enchant proc data definitions", count);
+}
+
bool SpellMgr::IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const
{
SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2);
diff --git a/src/game/SpellMgr.h b/src/game/SpellMgr.h
index c6d251e5457..6869f2e529e 100644
--- a/src/game/SpellMgr.h
+++ b/src/game/SpellMgr.h
@@ -500,6 +500,15 @@ struct SpellBonusEntry
};
typedef UNORDERED_MAP<uint32, SpellProcEventEntry> SpellProcEventMap;
+
+struct SpellEnchantProcEntry
+{
+ uint32 customChance;
+ float PPMChance;
+ uint32 procEx;
+};
+
+typedef UNORDERED_MAP<uint32, SpellEnchantProcEntry> SpellEnchantProcEventMap;
typedef UNORDERED_MAP<uint32, SpellBonusEntry> SpellBonusMap;
#define ELIXIR_BATTLE_MASK 0x1
@@ -759,6 +768,14 @@ class SpellMgr
bool IsSpellProcEventCanTriggeredBy( SpellProcEventEntry const * spellProcEvent, uint32 EventProcFlag, SpellEntry const * procSpell, uint32 procFlags, uint32 procExtra, bool active);
+ SpellEnchantProcEntry const* GetSpellEnchantProcEvent(uint32 enchId) const
+ {
+ SpellEnchantProcEventMap::const_iterator itr = mSpellEnchantProcEventMap.find(enchId);
+ if( itr != mSpellEnchantProcEventMap.end( ) )
+ return &itr->second;
+ return NULL;
+ }
+
// Spell bonus data
SpellBonusEntry const* GetSpellBonusData(uint32 spellId) const
{
@@ -1020,6 +1037,7 @@ class SpellMgr
void LoadSkillLineAbilityMap();
void LoadSpellPetAuras();
void LoadSpellCustomAttr();
+ void LoadSpellEnchantProcData();
void LoadSpellLinked();
void LoadPetLevelupSpellMap();
void LoadSpellAreas();
@@ -1040,6 +1058,7 @@ class SpellMgr
SpellPetAuraMap mSpellPetAuraMap;
SpellCustomAttribute mSpellCustomAttr;
SpellLinkedMap mSpellLinkedMap;
+ SpellEnchantProcEventMap mSpellEnchantProcEventMap;
PetLevelupSpellMap mPetLevelupSpellMap;
SpellAreaMap mSpellAreaMap;
SpellAreaForQuestMap mSpellAreaForQuestMap;
diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
index e36c25883d4..3cd0c4fb2c7 100644
--- a/src/game/Unit.cpp
+++ b/src/game/Unit.cpp
@@ -1699,15 +1699,41 @@ void Unit::DealMeleeDamage(CalcDamageInfo *damageInfo, bool durabilityLoss)
CastSpell(pVictim, 1604, true);
}
- // If not miss
- if (!(damageInfo->HitInfo & HITINFO_MISS))
+ if(GetTypeId() == TYPEID_PLAYER && pVictim->isAlive())
{
- if(GetTypeId() == TYPEID_PLAYER && pVictim->isAlive())
+ for(int i = EQUIPMENT_SLOT_START; i < EQUIPMENT_SLOT_END; i++)
{
- for(int i = EQUIPMENT_SLOT_START; i < EQUIPMENT_SLOT_END; i++)
- ((Player*)this)->CastItemCombatSpell(((Player*)this)->GetUseableItemByPos(INVENTORY_SLOT_BAG_0,i), pVictim, damageInfo->attackType);
+ // If usable, try to cast item spell
+ if (Item * item = ((Player*)this)->GetUseableItemByPos(INVENTORY_SLOT_BAG_0,i))
+ if(!item->IsBroken())
+ if (ItemPrototype const *proto = item->GetProto())
+ {
+ // Additional check for weapons
+ if (proto->Class==ITEM_CLASS_WEAPON)
+ {
+ // offhand item cannot proc from main hand hit etc
+ EquipmentSlots slot;
+ switch (damageInfo->attackType)
+ {
+ case BASE_ATTACK: slot = EQUIPMENT_SLOT_MAINHAND; break;
+ case OFF_ATTACK: slot = EQUIPMENT_SLOT_OFFHAND; break;
+ case RANGED_ATTACK: slot = EQUIPMENT_SLOT_RANGED; break;
+ default: slot = EQUIPMENT_SLOT_END; break;
+ }
+ if (slot != i)
+ continue;
+ // Check if item is useable (forms or disarm)
+ if (((Player*)this)->IsInFeralForm())
+ continue;
+ }
+ ((Player*)this)->CastItemCombatSpell(item, damageInfo, proto);
+ }
}
+ }
+ // Do effect if any damage done to target
+ if (damageInfo->damage)
+ {
// victim's damage shield
std::set<AuraEffect*> alreadyDone;
uint32 removedAuras = pVictim->m_removedAurasCount;
diff --git a/src/game/World.cpp b/src/game/World.cpp
index 665fb6d4bdc..93d927c07eb 100644
--- a/src/game/World.cpp
+++ b/src/game/World.cpp
@@ -1223,6 +1223,9 @@ void World::SetInitialWorldSettings()
sLog.outString( "Loading NPC Texts..." );
objmgr.LoadGossipText();
+ sLog.outString( "Loading Enchant Spells Proc datas...");
+ spellmgr.LoadSpellEnchantProcData();
+
sLog.outString( "Loading Item Random Enchantments Table..." );
LoadRandomEnchantmentsTable();