Skip to content

Commit

Permalink
[12510] Fix take ammo for most ranged spells
Browse files Browse the repository at this point in the history
Fix spells like Arcane Shot not taking ammo while they should

Close cmangos/mangos-tbc#19

Signed-off-by: cala <calaftp@free.fr>
Signed-off-by: Schmoozerd <schmoozerd@cmangos.net>
  • Loading branch information
sidsukana authored and Schmoozerd committed May 21, 2013
1 parent 0b2324c commit c8b2a94
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
31 changes: 31 additions & 0 deletions src/game/Spell.cpp
Expand Up @@ -3325,6 +3325,7 @@ void Spell::cast(bool skipCheck)

TakePower();
TakeReagents(); // we must remove reagents before HandleEffects to allow place crafted item in same slot
TakeAmmo();

SendCastResult(castResult);
SendSpellGo(); // we must send smsg_spell_go packet before m_castItem delete in TakeCastItem()...
Expand Down Expand Up @@ -4527,6 +4528,36 @@ SpellCastResult Spell::CheckOrTakeRunePower(bool take)
return SPELL_CAST_OK;
}

void Spell::TakeAmmo()
{
if (m_attackType == RANGED_ATTACK && m_caster->GetTypeId() == TYPEID_PLAYER)
{
Item* pItem = ((Player*)m_caster)->GetWeaponForAttack(RANGED_ATTACK, true, false);

// wands don't have ammo
if (!pItem || pItem->GetProto()->SubClass == ITEM_SUBCLASS_WEAPON_WAND)
return;

if (pItem->GetProto()->InventoryType == INVTYPE_THROWN)
{
if (pItem->GetMaxStackCount() == 1)
{
// decrease durability for non-stackable throw weapon
((Player*)m_caster)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_RANGED);
}
else
{
// decrease items amount for stackable throw weapon
uint32 count = 1;
((Player*)m_caster)->DestroyItemCount(pItem, count, true);
}
}
else if (uint32 ammo = ((Player*)m_caster)->GetUInt32Value(PLAYER_AMMO_ID))
((Player*)m_caster)->DestroyItemCount(ammo, 1, true);
}
}


void Spell::TakeReagents()
{
if (m_caster->GetTypeId() != TYPEID_PLAYER)
Expand Down
1 change: 1 addition & 0 deletions src/game/Spell.h
Expand Up @@ -374,6 +374,7 @@ class Spell
void cast(bool skipCheck = false);
void finish(bool ok = true);
void TakePower();
void TakeAmmo();
void TakeReagents();
void TakeCastItem();

Expand Down
26 changes: 0 additions & 26 deletions src/game/SpellEffects.cpp
Expand Up @@ -6729,32 +6729,6 @@ void Spell::EffectWeaponDmg(SpellEffectIndex eff_idx)
((Player*)m_caster)->AddComboPoints(unitTarget, 1);
}

// take ammo
if (m_attackType == RANGED_ATTACK && m_caster->GetTypeId() == TYPEID_PLAYER)
{
Item* pItem = ((Player*)m_caster)->GetWeaponForAttack(RANGED_ATTACK, true, false);

// wands don't have ammo
if (!pItem || pItem->GetProto()->SubClass == ITEM_SUBCLASS_WEAPON_WAND)
return;

if (pItem->GetProto()->InventoryType == INVTYPE_THROWN)
{
if (pItem->GetMaxStackCount() == 1)
{
// decrease durability for non-stackable throw weapon
((Player*)m_caster)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_RANGED);
}
else
{
// decrease items amount for stackable throw weapon
uint32 count = 1;
((Player*)m_caster)->DestroyItemCount(pItem, count, true);
}
}
else if (uint32 ammo = ((Player*)m_caster)->GetUInt32Value(PLAYER_AMMO_ID))
((Player*)m_caster)->DestroyItemCount(ammo, 1, true);
}
}

void Spell::EffectThreat(SpellEffectIndex /*eff_idx*/)
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "12509"
#define REVISION_NR "12510"
#endif // __REVISION_NR_H__

0 comments on commit c8b2a94

Please sign in to comment.