Skip to content

Commit

Permalink
Improve hunter auto shot target switching
Browse files Browse the repository at this point in the history
With this change we can now verify target change before each cast spell.

As the logic is changed it might be interesting to get more feedback.

Parts of this commit are from @killerwife and @Phatcat work.
  • Loading branch information
cyberium committed Jun 27, 2017
1 parent a04102b commit 6edcf58
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
41 changes: 34 additions & 7 deletions src/game/Entities/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4301,7 +4301,7 @@ void Unit::_UpdateAutoRepeatSpell()
bool isAutoShot = m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo->Id == SPELL_ID_AUTOSHOT;

// check movement
if (GetTypeId() == TYPEID_PLAYER && ((Player*)this)->IsMoving())
if (IsMoving())
{
// cancel wand shoot
if (!isAutoShot)
Expand All @@ -4319,24 +4319,51 @@ void Unit::_UpdateAutoRepeatSpell()
InterruptSpell(CURRENT_AUTOREPEAT_SPELL);
return;
}
// auto shot is delayed by everythihng, except ranged(!) CURRENT_GENERIC_SPELL's -> recheck that
// auto shot is delayed by everything, except ranged(!) CURRENT_GENERIC_SPELL's -> recheck that
else if (!(m_currentSpells[CURRENT_GENERIC_SPELL] && m_currentSpells[CURRENT_GENERIC_SPELL]->IsRangedSpell()))
return;
}

// castroutine
// cast routine
if (isAttackReady(RANGED_ATTACK))
{
// Check if able to cast
if (m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->CheckCast(true) != SPELL_CAST_OK)
// be sure the unit is stand up
if (getStandState() != UNIT_STAND_STATE_STAND)
SetStandState(UNIT_STAND_STATE_STAND);

Unit* currSpellTarget = m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_targets.getUnitTarget();
Unit* currTarget = nullptr;

// Check i there is new target
ObjectGuid const& currTargetGuid = GetTargetGuid();
if (!currTargetGuid.IsEmpty() && currTargetGuid.IsUnit())
{
if (currTargetGuid != currSpellTarget->GetObjectGuid())
currTarget = GetMap()->GetUnit(currTargetGuid);
else
currTarget = currSpellTarget;
}

// some check about new target are necessary
if (!currTarget || !currTarget->isTargetableForAttack() || currTarget->IsFriendlyTo(this))
{
// no valid target
InterruptSpell(CURRENT_AUTOREPEAT_SPELL);
return;
}

SpellCastTargets targets;
targets.setUnitTarget(currTarget);

// we want to shoot
Spell* spell = new Spell(this, m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo, true);
spell->SpellStart(&(m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_targets));
Spell* spell = new Spell(this, m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo, TRIGGERED_AUTOREPEAT);

// Check if able to cast
if (spell->SpellStart(&targets) != SPELL_CAST_OK)
{
InterruptSpell(CURRENT_AUTOREPEAT_SPELL);
return;
}

// all went good, reset attack
resetAttackTimer(RANGED_ATTACK);
Expand Down
2 changes: 1 addition & 1 deletion src/game/Spells/Spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3198,7 +3198,7 @@ void Spell::cancel()
return;

// channeled spells don't display interrupted message even if they are interrupted, possible other cases with no "Interrupted" message
bool sendInterrupt = IsChanneledSpell(m_spellInfo) ? false : true;
bool sendInterrupt = (IsChanneledSpell(m_spellInfo) || m_autoRepeat) ? false : true;

m_autoRepeat = false;
switch (m_spellState)
Expand Down

0 comments on commit 6edcf58

Please sign in to comment.