Changeset 267 for trunk

Show
Ignore:
Timestamp:
11/21/08 16:54:14 (17 years ago)
Author:
yumileroy
Message:

*Let creature search nearby target before enter evade mode
*Add function canStartAttack to reduce code in MoveInLineOfSight?
*Fix a bug that cancelling bind sight auras may crash the server

Original author: megamage
Date: 2008-11-21 10:07:11-06:00

Location:
trunk/src
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/bindings/scripts/include/sc_creature.cpp

    r257 r267  
    7474void ScriptedAI::MoveInLineOfSight(Unit *who) 
    7575{ 
    76     if(m_creature->getVictim() || !m_creature->IsHostileTo(who) || !who->isInAccessiblePlaceFor(m_creature)) 
    77         return; 
    78  
    79     if(!m_creature->canFly() && m_creature->GetDistanceZ(who) > CREATURE_Z_ATTACK_RANGE) 
    80         return; 
    81  
    82     if(!m_creature->IsWithinDistInMap(who, m_creature->GetAttackDistance(who)) || !m_creature->IsWithinLOSInMap(who)) 
    83         return; 
    84      
    85     if(m_creature->canAttack(who)) 
    86         //who->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH); 
     76    if(!m_creature->getVictim() && m_creature->canStartAttack(who)) 
    8777        AttackStart(who); 
    8878} 
  • trunk/src/game/Creature.cpp

    r266 r267  
    15441544} 
    15451545 
     1546bool Creature::canStartAttack(Unit const* who) const 
     1547{ 
     1548    if(!who->isInAccessiblePlaceFor(this) 
     1549        || !canFly() && GetDistanceZ(who) > CREATURE_Z_ATTACK_RANGE 
     1550        || !IsWithinDistInMap(who, GetAttackDistance(who))) 
     1551        return false; 
     1552 
     1553    if(!canAttack(who)) 
     1554        return false; 
     1555 
     1556    return IsWithinLOSInMap(who); 
     1557} 
     1558 
    15461559float Creature::GetAttackDistance(Unit const* pl) const 
    15471560{ 
     
    18251838Unit* Creature::SelectNearestTarget(float dist) const 
    18261839{ 
    1827     /*CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); 
     1840    CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); 
    18281841    Cell cell(p); 
    18291842    cell.data.Part.reserved = ALL_DISTRICT; 
    18301843    cell.SetNoCreate(); 
    18311844 
    1832     Unit *target; 
     1845    Unit *target = NULL; 
    18331846 
    18341847    { 
     
    18401853 
    18411854        CellLock<GridReadGuard> cell_lock(cell, p); 
    1842         cell_lock->Visit(cell_lock, world_unit_searcher, GetMap()); 
    1843         cell_lock->Visit(cell_lock, grid_unit_searcher, GetMap()); 
    1844     }*/ 
    1845     return NULL; 
     1855        cell_lock->Visit(cell_lock, world_unit_searcher, *GetMap()); 
     1856        cell_lock->Visit(cell_lock, grid_unit_searcher, *GetMap()); 
     1857    } 
     1858 
     1859    return target; 
    18461860} 
    18471861 
  • trunk/src/game/Creature.h

    r266 r267  
    558558        bool canSeeOrDetect(Unit const* u, bool detect, bool inVisibleList) const; 
    559559        bool IsWithinSightDist(Unit const* u) const; 
     560        bool canStartAttack(Unit const* u) const; 
    560561        float GetAttackDistance(Unit const* pl) const; 
    561562 
  • trunk/src/game/GridNotifiers.h

    r266 r267  
    702702    { 
    703703        public: 
    704             explicit NearestHostileUnitInAttackDistanceCheck(Creature* creature, float dist = 0) : m_creature(creature)  
     704            explicit NearestHostileUnitInAttackDistanceCheck(Creature const* creature, float dist = 0) : m_creature(creature)  
    705705            { 
    706706                m_range = (dist == 0 ? 9999 : dist); 
     
    709709            bool operator()(Unit* u) 
    710710            { 
    711                 if(!u->isAlive() || !m_creature->IsHostileTo(u)) 
    712                     return false; 
    713  
    714                 float dist; 
    715                 if(m_force) dist = m_range; 
     711                // TODO: addthreat for every enemy in range? 
     712                if(!m_creature->IsWithinDistInMap(u, m_range)) 
     713                    return false; 
     714 
     715                if(m_force) 
     716                { 
     717                    if(!m_creature->canAttack(u)) 
     718                        return false; 
     719                } 
    716720                else 
    717721                { 
    718                     dist = m_creature->GetAttackDistance(u); 
    719                     if(dist > m_range) dist = m_range; 
     722                    if(!m_creature->canStartAttack(u)) 
     723                        return false; 
    720724                } 
    721                 if(!m_creature->IsWithinDistInMap(u, dist)) 
    722                     return false; 
    723  
    724                 if(!m_creature->canSeeOrDetect(u, true, false)) 
    725                     return false; 
    726725 
    727726                m_range = m_creature->GetDistance(u); 
     
    730729            float GetLastRange() const { return m_range; } 
    731730        private: 
    732             Creature* const m_creature; 
     731            Creature const *m_creature; 
    733732            float m_range; 
    734733            bool m_force; 
  • trunk/src/game/SpellHandler.cpp

    r260 r267  
    369369                spellInfo->EffectApplyAuraName[i] == SPELL_AURA_BIND_SIGHT) 
    370370            { 
     371                // Fix me: creature may be killed during player aura cancel 
    371372                _player->RemoveAurasDueToSpellByCancel(spellId); 
    372373                if (_player->GetCharm()) 
    373374                    _player->GetCharm()->RemoveAurasDueToSpellByCancel(spellId); 
    374                 else if (_player->GetFarsightTarget()->GetTypeId() != TYPEID_DYNAMICOBJECT) 
     375                else if (_player->GetFarsightTarget() && _player->GetFarsightTarget()->GetTypeId() != TYPEID_DYNAMICOBJECT) 
    375376                    ((Unit*)_player->GetFarsightTarget())->RemoveAurasDueToSpellByCancel(spellId); 
    376377                return; 
  • trunk/src/game/Unit.cpp

    r266 r267  
    85438543    assert(target); 
    85448544 
     8545    if(!IsHostileTo(target)) 
     8546        return false; 
     8547 
    85458548    if(!target->isAttackableByAOE() || target->hasUnitState(UNIT_STAT_DIED)) 
    85468549        return false; 
     
    91279130    } 
    91289131 
     9132    // search nearby enemy before enter evade mode 
     9133    if(Unit *target = ((Creature*)this)->SelectNearestTarget()) 
     9134    { 
     9135        ((Creature*)this)->AI()->AttackStart(target); 
     9136        return true; 
     9137    } 
     9138 
    91299139    // enter in evade mode in other case 
    91309140    ((Creature*)this)->AI()->EnterEvadeMode();