aboutsummaryrefslogtreecommitdiff
path: root/src/game/Unit.cpp
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 /src/game/Unit.cpp
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
Diffstat (limited to 'src/game/Unit.cpp')
-rw-r--r--src/game/Unit.cpp36
1 files changed, 31 insertions, 5 deletions
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;