diff options
author | treeston <treeston.mmoc@gmail.com> | 2016-04-02 02:50:44 +0200 |
---|---|---|
committer | treeston <treeston.mmoc@gmail.com> | 2016-04-02 02:51:06 +0200 |
commit | 1cf1d4a1eafb3a31bf87a615d9d947eed6eb0f62 (patch) | |
tree | 66f79cff0dfef3306d191df357c71cd39c928ad6 | |
parent | ddb5c0bf96bd8fae6b6c3fefa392adcb63c7fa7e (diff) |
- Clean up spell facing behavior a bit. Visual target behavior should now be a lot smoother.
- Clean up Creature.cpp. NULL -> nullptr, gotta love it.
- Renamed some recently added members of Creature to match code style.
-rw-r--r-- | src/server/game/Entities/Creature/Creature.cpp | 84 | ||||
-rw-r--r-- | src/server/game/Entities/Creature/Creature.h | 6 | ||||
-rw-r--r-- | src/server/game/Entities/Unit/Unit.h | 2 |
3 files changed, 43 insertions, 49 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 19642b498b6..61d5d7d9459 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -54,7 +54,7 @@ TrainerSpell const* TrainerSpellData::Find(uint32 spell_id) const if (itr != spellList.end()) return &itr->second; - return NULL; + return nullptr; } bool VendorItemData::RemoveItem(uint32 item_id) @@ -78,7 +78,7 @@ VendorItem const* VendorItemData::FindItemCostPair(uint32 item_id, uint32 extend for (VendorItemList::const_iterator i = m_items.begin(); i != m_items.end(); ++i) if ((*i)->item == item_id && (*i)->ExtendedCost == extendedCost) return *i; - return NULL; + return nullptr; } uint32 CreatureTemplate::GetRandomValidModelId() const @@ -183,7 +183,7 @@ m_lootRecipient(), m_lootRecipientGroup(0), _skinner(), _pickpocketLootRestore(0 m_respawnDelay(300), m_corpseDelay(60), m_respawnradius(0.0f), m_boundaryCheckTime(2500), m_combatPulseTime(0), m_combatPulseDelay(0), m_reactState(REACT_AGGRESSIVE), m_defaultMovementType(IDLE_MOTION_TYPE), m_spawnId(0), m_equipmentId(0), m_originalEquipmentId(0), m_AlreadyCallAssistance(false), m_AlreadySearchedAssistance(false), m_regenHealth(true), m_AI_locked(false), m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL), -m_originalEntry(0), m_homePosition(), m_transportHomePosition(), m_creatureInfo(NULL), m_creatureData(NULL), m_waypointID(0), m_path_id(0), m_formation(NULL) +m_originalEntry(0), m_homePosition(), m_transportHomePosition(), m_creatureInfo(nullptr), m_creatureData(nullptr), m_waypointID(0), m_path_id(0), m_formation(nullptr), m_focusSpell(nullptr), m_focusDelay(0) { m_regenTimer = CREATURE_REGEN_INTERVAL; m_valuesCount = UNIT_END; @@ -197,16 +197,14 @@ m_originalEntry(0), m_homePosition(), m_transportHomePosition(), m_creatureInfo( m_CombatDistance = 0;//MELEE_RANGE; ResetLootMode(); // restore default loot mode - TriggerJustRespawned = false; + m_TriggerJustRespawned = false; m_isTempWorldObject = false; - _focusSpell = NULL; - _focusDelay = 0; } Creature::~Creature() { delete i_AI; - i_AI = NULL; + i_AI = nullptr; //if (m_uint32Values) // TC_LOG_ERROR("entities.unit", "Deconstruct Creature Entry = %u", GetEntry()); @@ -490,9 +488,9 @@ bool Creature::UpdateEntry(uint32 entry, CreatureData const* data /*= nullptr*/) void Creature::Update(uint32 diff) { - if (IsAIEnabled && TriggerJustRespawned) + if (IsAIEnabled && m_TriggerJustRespawned) { - TriggerJustRespawned = false; + m_TriggerJustRespawned = false; AI()->JustRespawned(); if (m_vehicleKit) m_vehicleKit->Reset(); @@ -769,7 +767,7 @@ void Creature::DoFleeToGetAssistance() float radius = sWorld->getFloatConfig(CONFIG_CREATURE_FAMILY_FLEE_ASSISTANCE_RADIUS); if (radius >0) { - Creature* creature = NULL; + Creature* creature = nullptr; CellCoord p(Trinity::ComputeCellCoord(GetPositionX(), GetPositionY())); Cell cell(p); @@ -969,14 +967,14 @@ bool Creature::isCanTrainingAndResetTalentsOf(Player* player) const Player* Creature::GetLootRecipient() const { if (!m_lootRecipient) - return NULL; + return nullptr; return ObjectAccessor::FindConnectedPlayer(m_lootRecipient); } Group* Creature::GetLootRecipientGroup() const { if (!m_lootRecipientGroup) - return NULL; + return nullptr; return sGroupMgr->GetGroupByGUID(m_lootRecipientGroup); } @@ -984,7 +982,7 @@ void Creature::SetLootRecipient(Unit* unit) { // set the player whose group should receive the right // to loot the creature after it dies - // should be set to NULL after the loot disappears + // should be set to nullptr after the loot disappears if (!unit) { @@ -1608,7 +1606,7 @@ void Creature::setDeathState(DeathState s) if (sWorld->getBoolConfig(CONFIG_SAVE_RESPAWN_TIME_IMMEDIATELY) || isWorldBoss()) SaveRespawnTime(); - ReleaseFocus(); // remove spellcast focus (this also clears unit target) + ReleaseFocus(nullptr, false); // remove spellcast focus SetTarget(ObjectGuid::Empty); // drop target - dead mobs shouldn't ever target things SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE); @@ -1637,7 +1635,7 @@ void Creature::setDeathState(DeathState s) //if (IsPet()) // setActive(true); SetFullHealth(); - SetLootRecipient(NULL); + SetLootRecipient(nullptr); ResetPlayerDamageReq(); UpdateMovementFlags(); @@ -1717,7 +1715,7 @@ void Creature::Respawn(bool force) { //reset the AI to be sure no dirty or uninitialized values will be used till next tick AI()->Reset(); - TriggerJustRespawned = true;//delay event to next tick so all creatures are created on the map before processing + m_TriggerJustRespawned = true;//delay event to next tick so all creatures are created on the map before processing } uint32 poolid = GetSpawnId() ? sPoolMgr->IsPartOfAPool<Creature>(GetSpawnId()) : 0; @@ -1814,7 +1812,7 @@ bool Creature::isWorldBoss() const SpellInfo const* Creature::reachWithSpellAttack(Unit* victim) { if (!victim) - return NULL; + return nullptr; for (uint32 i=0; i < CREATURE_MAX_SPELLS; ++i) { @@ -1856,13 +1854,13 @@ SpellInfo const* Creature::reachWithSpellAttack(Unit* victim) continue; return spellInfo; } - return NULL; + return nullptr; } SpellInfo const* Creature::reachWithSpellCure(Unit* victim) { if (!victim) - return NULL; + return nullptr; for (uint32 i=0; i < CREATURE_MAX_SPELLS; ++i) { @@ -1903,7 +1901,7 @@ SpellInfo const* Creature::reachWithSpellCure(Unit* victim) continue; return spellInfo; } - return NULL; + return nullptr; } // select nearest hostile unit within the given distance (regardless of threat list). @@ -1913,7 +1911,7 @@ Unit* Creature::SelectNearestTarget(float dist, bool playerOnly /* = false */) c Cell cell(p); cell.SetNoCreate(); - Unit* target = NULL; + Unit* target = nullptr; { if (dist == 0.0f) @@ -1939,7 +1937,7 @@ Unit* Creature::SelectNearestTargetInAttackDistance(float dist) const Cell cell(p); cell.SetNoCreate(); - Unit* target = NULL; + Unit* target = nullptr; if (dist > MAX_VISIBILITY_DISTANCE) { @@ -1963,7 +1961,7 @@ Unit* Creature::SelectNearestTargetInAttackDistance(float dist) const Player* Creature::SelectNearestPlayer(float distance) const { - Player* target = NULL; + Player* target = nullptr; Trinity::NearestPlayerInObjectRangeCheck checker(this, distance); Trinity::PlayerLastSearcher<Trinity::NearestPlayerInObjectRangeCheck> searcher(this, target, checker); @@ -2260,7 +2258,7 @@ void Creature::SendZoneUnderAttackMessage(Player* attacker) WorldPacket data(SMSG_ZONE_UNDER_ATTACK, 4); data << (uint32)GetAreaId(); - sWorld->SendGlobalMessage(&data, NULL, (enemy_team == ALLIANCE ? HORDE : ALLIANCE)); + sWorld->SendGlobalMessage(&data, nullptr, (enemy_team == ALLIANCE ? HORDE : ALLIANCE)); } void Creature::SetInCombatWithZone() @@ -2757,13 +2755,13 @@ void Creature::SetTarget(ObjectGuid guid) bool Creature::FocusTarget(Spell const* focusSpell, WorldObject const* target) { // already focused - if (_focusSpell) + if (m_focusSpell) return false; if ((!target || target == this) && !focusSpell->GetCastTime()) // instant cast, untargeted (or self-targeted) spell doesn't need any facing updates return false; - _focusSpell = focusSpell; + m_focusSpell = focusSpell; // "instant" creature casts that require re-targeting will be delayed by a short moment to prevent facing bugs bool shouldDelay = false; @@ -2799,15 +2797,9 @@ bool Creature::FocusTarget(Spell const* focusSpell, WorldObject const* target) } if (shouldDelay) shouldDelay = !(focusSpell->IsTriggered() || focusSpell->GetCastTime() || focusSpell->GetSpellInfo()->IsChanneled()); - } } - // tell the creature that it should reacquire its current target after the cast is done (this is handled in ::Attack) - // player pets don't need to do this, as they automatically reacquire their target on focus release - if (!IsPet()) - MustReacquireTarget(); - bool canTurnDuringCast = !focusSpell->GetSpellInfo()->HasAttribute(SPELL_ATTR5_DONT_TURN_DURING_CAST); // Face the target - we need to do this before the unit state is modified for no-turn spells if (target) @@ -2830,16 +2822,16 @@ bool Creature::IsFocusing(Spell const* focusSpell, bool withDelay) return false; } - if (focusSpell && (focusSpell != _focusSpell)) + if (focusSpell && (focusSpell != m_focusSpell)) return false; - if (!_focusSpell) + if (!m_focusSpell) { - if (!withDelay || !_focusDelay) + if (!withDelay || !m_focusDelay) return false; - if (GetMSTimeDiffToNow(_focusDelay) > 1000) // @todo figure out if we can get rid of this magic number somehow + if (GetMSTimeDiffToNow(m_focusDelay) > 1000) // @todo figure out if we can get rid of this magic number somehow { - _focusDelay = 0; // save checks in the future + m_focusDelay = 0; // save checks in the future return false; } } @@ -2849,23 +2841,25 @@ bool Creature::IsFocusing(Spell const* focusSpell, bool withDelay) void Creature::ReleaseFocus(Spell const* focusSpell, bool withDelay) { - if (!_focusSpell) + if (!m_focusSpell) return; // focused to something else - if (focusSpell && focusSpell != _focusSpell) + if (focusSpell && focusSpell != m_focusSpell) return; - if (IsPet() && GetVictim()) // player pets do not use delay system - SetGuidValue(UNIT_FIELD_TARGET, EnsureVictim()->GetGUID()); + if (IsPet()) // player pets do not use delay system + SetGuidValue(UNIT_FIELD_TARGET, GetVictim() ? EnsureVictim()->GetGUID() : ObjectGuid::Empty); else - SetGuidValue(UNIT_FIELD_TARGET, ObjectGuid::Empty); + // tell the creature that it should reacquire its actual target after the delay expires (this is handled in ::Attack) + // player pets don't need to do this, as they automatically reacquire their target on focus release + MustReacquireTarget(); - if (_focusSpell->GetSpellInfo()->HasAttribute(SPELL_ATTR5_DONT_TURN_DURING_CAST)) + if (m_focusSpell->GetSpellInfo()->HasAttribute(SPELL_ATTR5_DONT_TURN_DURING_CAST)) ClearUnitState(UNIT_STATE_CANNOT_TURN); - _focusSpell = nullptr; - _focusDelay = (!IsPet() && withDelay) ? getMSTime() : 0; // don't allow re-target right away to prevent visual bugs + m_focusSpell = nullptr; + m_focusDelay = (!IsPet() && withDelay) ? getMSTime() : 0; // don't allow re-target right away to prevent visual bugs } void Creature::StartPickPocketRefillTimer() diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index c4b6776f30b..c6b19dbb939 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -746,10 +746,10 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma //Formation var CreatureGroup* m_formation; - bool TriggerJustRespawned; + bool m_TriggerJustRespawned; - Spell const* _focusSpell; ///> Locks the target during spell cast for proper facing - uint32 _focusDelay; + Spell const* m_focusSpell; ///> Locks the target during spell cast for proper facing + uint32 m_focusDelay; CreatureTextRepeatGroup m_textRepeat; }; diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index d82b2cd8422..4841cac84cf 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -1276,7 +1276,7 @@ class TC_GAME_API Unit : public WorldObject void _removeAttacker(Unit* pAttacker); // must be called only from Unit::AttackStop() Unit* getAttackerForHelper() const; // If someone wants to help, who to give them bool Attack(Unit* victim, bool meleeAttack); - void MustReacquireTarget() { m_shouldReacquireTarget = true; } // flags the Unit for forced target reacquisition in the next ::Attack call + void MustReacquireTarget() { m_shouldReacquireTarget = true; } // flags the Unit for forced (client displayed) target reacquisition in the next ::Attack call void CastStop(uint32 except_spellid = 0); bool AttackStop(); void RemoveAllAttackers(); |