- Timestamp:
- 11/21/08 16:54:14 (17 years ago)
- Location:
- trunk/src
- Files:
-
- 6 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bindings/scripts/include/sc_creature.cpp
r257 r267 74 74 void ScriptedAI::MoveInLineOfSight(Unit *who) 75 75 { 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)) 87 77 AttackStart(who); 88 78 } -
trunk/src/game/Creature.cpp
r266 r267 1544 1544 } 1545 1545 1546 bool 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 1546 1559 float Creature::GetAttackDistance(Unit const* pl) const 1547 1560 { … … 1825 1838 Unit* Creature::SelectNearestTarget(float dist) const 1826 1839 { 1827 /*CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY()));1840 CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); 1828 1841 Cell cell(p); 1829 1842 cell.data.Part.reserved = ALL_DISTRICT; 1830 1843 cell.SetNoCreate(); 1831 1844 1832 Unit *target ;1845 Unit *target = NULL; 1833 1846 1834 1847 { … … 1840 1853 1841 1854 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; 1846 1860 } 1847 1861 -
trunk/src/game/Creature.h
r266 r267 558 558 bool canSeeOrDetect(Unit const* u, bool detect, bool inVisibleList) const; 559 559 bool IsWithinSightDist(Unit const* u) const; 560 bool canStartAttack(Unit const* u) const; 560 561 float GetAttackDistance(Unit const* pl) const; 561 562 -
trunk/src/game/GridNotifiers.h
r266 r267 702 702 { 703 703 public: 704 explicit NearestHostileUnitInAttackDistanceCheck(Creature * creature, float dist = 0) : m_creature(creature)704 explicit NearestHostileUnitInAttackDistanceCheck(Creature const* creature, float dist = 0) : m_creature(creature) 705 705 { 706 706 m_range = (dist == 0 ? 9999 : dist); … … 709 709 bool operator()(Unit* u) 710 710 { 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 } 716 720 else 717 721 { 718 dist = m_creature->GetAttackDistance(u);719 if(dist > m_range) dist = m_range;722 if(!m_creature->canStartAttack(u)) 723 return false; 720 724 } 721 if(!m_creature->IsWithinDistInMap(u, dist))722 return false;723 724 if(!m_creature->canSeeOrDetect(u, true, false))725 return false;726 725 727 726 m_range = m_creature->GetDistance(u); … … 730 729 float GetLastRange() const { return m_range; } 731 730 private: 732 Creature * constm_creature;731 Creature const *m_creature; 733 732 float m_range; 734 733 bool m_force; -
trunk/src/game/SpellHandler.cpp
r260 r267 369 369 spellInfo->EffectApplyAuraName[i] == SPELL_AURA_BIND_SIGHT) 370 370 { 371 // Fix me: creature may be killed during player aura cancel 371 372 _player->RemoveAurasDueToSpellByCancel(spellId); 372 373 if (_player->GetCharm()) 373 374 _player->GetCharm()->RemoveAurasDueToSpellByCancel(spellId); 374 else if (_player->GetFarsightTarget() ->GetTypeId() != TYPEID_DYNAMICOBJECT)375 else if (_player->GetFarsightTarget() && _player->GetFarsightTarget()->GetTypeId() != TYPEID_DYNAMICOBJECT) 375 376 ((Unit*)_player->GetFarsightTarget())->RemoveAurasDueToSpellByCancel(spellId); 376 377 return; -
trunk/src/game/Unit.cpp
r266 r267 8543 8543 assert(target); 8544 8544 8545 if(!IsHostileTo(target)) 8546 return false; 8547 8545 8548 if(!target->isAttackableByAOE() || target->hasUnitState(UNIT_STAT_DIED)) 8546 8549 return false; … … 9127 9130 } 9128 9131 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 9129 9139 // enter in evade mode in other case 9130 9140 ((Creature*)this)->AI()->EnterEvadeMode();