feat(Core/Movement): Improved pathfinding, collisions and movements (#4220)
Npc positioning Implemented slope check to avoid unwanted climbing for some kind of movements (backwards, repositioning etc.) Implemented backwards movement Re-implemented circle repositioning algorithm (smartest than retail, but with the same feeling) Fixed random position of summoned minions Improved pet following movement. Also, they attack NPC from behind now. Thanks to @Footman Swimming creatures Fixed max_z coordinate for swimming creatures. Now only part of their body is allowed to be out of the water level Fixed pathfinder for swimming creatures creating shortcuts for specific segments, now they swim underwater to reach the seashore instead of flying above the water level. Creatures with water InhabitType but no swimming flag now, when not in combat, will walk on water depth instead of swimming. Thanks @jackpoz for the original code UNIT_FLAG_SWIMMING in UpdateEnvironmentIfNeeded to show the swimming animation correctly when underwater Implemented HasEnoughWater check to avoid swimming creatures to go where the water level is too low but also to properly enable swimming animation only when a creature has enough water to swim. Walking creatures Extended the DetourNavMeshQuery adding area cost based on walkability (slope angle + source height) to find better paths at runtime instead of completely remove them from mmaps improve Z height in certain conditions (see #4205, #4203, #4247 ) Flying creatures Rewriting of the hover system Removed hacks and improved the UpdateEnvironmentIfNeeded. Now creatures can properly switch from flying to walk etc. Spells LOS on spell effect must be calculated on CollisionHeight and HitSpherePoint instead of position coords. Improved position for object/creature spawned via spells Improved checks for Fleeing movements (fear spells) Other improvements Implemented method to calculate the CollisionWidth from dbc (used by repositioning algorithm etc.) Improved raycast and collision checks Co-authored-by: Footman <p.alexej@freenet.de> Co-authored-by: Helias <stefanoborzi32@gmail.com> Co-authored-by: Francesco Borzì <borzifrancesco@gmail.com> Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com>
This commit is contained in:
@@ -47,8 +47,6 @@
|
||||
#include "LuaEngine.h"
|
||||
#endif
|
||||
|
||||
constexpr uint32 DEF_CANNOT_REACH = 5 * IN_MILLISECONDS; // this is when creatures are in los / no path to the target, 5s wait time then they return to spawn pos with evade
|
||||
|
||||
TrainerSpell const* TrainerSpellData::Find(uint32 spell_id) const
|
||||
{
|
||||
TrainerSpellMap::const_iterator itr = spellList.find(spell_id);
|
||||
@@ -164,9 +162,10 @@ bool ForcedDespawnDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
|
||||
Creature::Creature(bool isWorldObject): Unit(isWorldObject), MovableMapObject(), m_groupLootTimer(0), lootingGroupLowGUID(0), m_PlayerDamageReq(0), m_lootRecipient(0), m_lootRecipientGroup(0),
|
||||
m_corpseRemoveTime(0), m_respawnTime(0), m_respawnDelay(300), m_corpseDelay(60), m_wanderDistance(0.0f),
|
||||
m_transportCheckTimer(1000), lootPickPocketRestoreTime(0), m_reactState(REACT_AGGRESSIVE), m_defaultMovementType(IDLE_MOTION_TYPE),
|
||||
m_DBTableGuid(0), m_equipmentId(0), m_originalEquipmentId(0), m_AlreadyCallAssistance(false),
|
||||
m_DBTableGuid(0), m_equipmentId(0), m_originalEquipmentId(0), m_originalAnimTier(UNIT_BYTE1_FLAG_GROUND), m_AlreadyCallAssistance(false),
|
||||
m_AlreadySearchedAssistance(false), m_regenHealth(true), m_AI_locked(false), m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL), m_originalEntry(0), m_moveInLineOfSightDisabled(false), m_moveInLineOfSightStrictlyDisabled(false),
|
||||
m_homePosition(), m_transportHomePosition(), m_creatureInfo(nullptr), m_creatureData(nullptr), m_waypointID(0), m_path_id(0), m_formation(nullptr), _lastDamagedTime(0), m_cannotReachTarget(false), m_cannotReachTimer(0)
|
||||
m_homePosition(), m_transportHomePosition(), m_creatureInfo(nullptr), m_creatureData(nullptr), m_waypointID(0), m_path_id(0), m_formation(nullptr), _lastDamagedTime(0), m_cannotReachTarget(false), m_cannotReachTimer(0),
|
||||
_isMissingSwimmingFlagOutOfCombat(false)
|
||||
{
|
||||
m_regenTimer = CREATURE_REGEN_INTERVAL;
|
||||
m_valuesCount = UNIT_END;
|
||||
@@ -591,6 +590,35 @@ void Creature::Update(uint32 diff)
|
||||
RemoveCharmAuras();
|
||||
}
|
||||
|
||||
if (Unit *victim = GetVictim())
|
||||
{
|
||||
// If we are closer than 50% of the combat reach we are going to reposition the victim
|
||||
if (diff >= m_moveBackwardsMovementTime)
|
||||
{
|
||||
float MaxRange = GetCollisionRadius() + GetVictim()->GetCollisionRadius();
|
||||
|
||||
if (IsInDist(victim, MaxRange))
|
||||
AI()->MoveBackwardsChecks();
|
||||
|
||||
m_moveBackwardsMovementTime = urand(MOVE_BACKWARDS_CHECK_INTERVAL, MOVE_BACKWARDS_CHECK_INTERVAL * 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_moveBackwardsMovementTime -= diff;
|
||||
}
|
||||
|
||||
// Circling the target
|
||||
if (diff >= m_moveCircleMovementTime)
|
||||
{
|
||||
AI()->MoveCircleChecks();
|
||||
m_moveCircleMovementTime = urand(MOVE_CIRCLE_CHECK_INTERVAL, MOVE_CIRCLE_CHECK_INTERVAL * 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_moveCircleMovementTime -= diff;
|
||||
}
|
||||
}
|
||||
|
||||
if (!IsInEvadeMode() && IsAIEnabled)
|
||||
{
|
||||
// do not allow the AI to be changed during update
|
||||
@@ -607,8 +635,24 @@ void Creature::Update(uint32 diff)
|
||||
m_regenTimer -= diff;
|
||||
if (m_regenTimer <= 0)
|
||||
{
|
||||
if (!IsInEvadeMode() && (!IsInCombat() || IsPolymorphed())) // regenerate health if not in combat or if polymorphed
|
||||
RegenerateHealth();
|
||||
if (!IsInEvadeMode())
|
||||
{
|
||||
// regenerate health if not in combat or if polymorphed)
|
||||
if (!IsInCombat() || IsPolymorphed())
|
||||
RegenerateHealth();
|
||||
else if (CanNotReachTarget())
|
||||
{
|
||||
// regenerate health if cannot reach the target and the setting is set to do so.
|
||||
// this allows to disable the health regen of raid bosses if pathfinding has issues for whatever reason
|
||||
if (sWorld->getBoolConfig(CONFIG_REGEN_HP_CANNOT_REACH_TARGET_IN_RAID) || !GetMap()->IsRaid())
|
||||
{
|
||||
RegenerateHealth();
|
||||
sLog->outDebug(LOG_FILTER_UNITS, "RegenerateHealth() enabled because Creature cannot reach the target. Detail: %s", GetDebugInfo().c_str());
|
||||
}
|
||||
else
|
||||
sLog->outDebug(LOG_FILTER_UNITS, "RegenerateHealth() disabled even if the Creature cannot reach the target. Detail: %s", GetDebugInfo().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
if (getPowerType() == POWER_ENERGY)
|
||||
Regenerate(POWER_ENERGY);
|
||||
@@ -621,7 +665,7 @@ void Creature::Update(uint32 diff)
|
||||
if (CanNotReachTarget() && !IsInEvadeMode() && !GetMap()->IsRaid())
|
||||
{
|
||||
m_cannotReachTimer += diff;
|
||||
if (m_cannotReachTimer >= DEF_CANNOT_REACH && IsAIEnabled)
|
||||
if (m_cannotReachTimer >= (sWorld->getIntConfig(CONFIG_NPC_EVADE_IF_NOT_REACHABLE)*IN_MILLISECONDS) && IsAIEnabled)
|
||||
{
|
||||
AI()->EnterEvadeMode();
|
||||
}
|
||||
@@ -660,6 +704,20 @@ void Creature::Update(uint32 diff)
|
||||
}
|
||||
}
|
||||
|
||||
bool Creature::IsFreeToMove()
|
||||
{
|
||||
uint32 moveFlags = m_movementInfo.GetMovementFlags();
|
||||
// Do not reposition ourself when we are not allowed to move
|
||||
if ((IsMovementPreventedByCasting() || isMoving() || !CanFreeMove()) &&
|
||||
(GetMotionMaster()->GetCurrentMovementGeneratorType() != CHASE_MOTION_TYPE ||
|
||||
moveFlags & MOVEMENTFLAG_SPLINE_ENABLED))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Creature::Regenerate(Powers power)
|
||||
{
|
||||
uint32 curValue = GetPower(power);
|
||||
@@ -900,6 +958,9 @@ bool Creature::Create(uint32 guidlow, Map* map, uint32 phaseMask, uint32 Entry,
|
||||
SetByteValue(UNIT_FIELD_BYTES_0, 2, minfo->gender);
|
||||
}
|
||||
|
||||
//! Need to be called after LoadCreaturesAddon - MOVEMENTFLAG_HOVER is set there
|
||||
m_positionZ += GetHoverHeight();
|
||||
|
||||
LastUsedScriptID = GetCreatureTemplate()->ScriptID;
|
||||
|
||||
if (IsSpiritHealer() || IsSpiritGuide() || (GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_GHOST_VISIBILITY))
|
||||
@@ -1524,8 +1585,10 @@ bool Creature::CanStartAttack(Unit const* who) const
|
||||
|
||||
// This set of checks is should be done only for creatures
|
||||
if ((HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC) && who->GetTypeId() != TYPEID_PLAYER) || // flag is valid only for non player characters
|
||||
(HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PC) && who->GetTypeId() == TYPEID_PLAYER)) // immune to PC and target is a player, return false
|
||||
(HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PC) && who->GetTypeId() == TYPEID_PLAYER)) // immune to PC and target is a player, return false
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Unit* owner = who->GetOwner())
|
||||
if (owner->GetTypeId() == TYPEID_PLAYER && HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PC)) // immune to PC and target has player owner
|
||||
@@ -1578,7 +1641,7 @@ void Creature::setDeathState(DeathState s, bool despawn)
|
||||
SetTarget(0); // remove target selection in any cases (can be set at aura remove in Unit::setDeathState)
|
||||
SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
|
||||
|
||||
SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID, 0); // if creature is mounted on a virtual mount, remove it at death
|
||||
Dismount(); // if creature is mounted on a virtual mount, remove it at death
|
||||
|
||||
setActive(false);
|
||||
|
||||
@@ -1597,7 +1660,11 @@ void Creature::setDeathState(DeathState s, bool despawn)
|
||||
if (m_formation && m_formation->getLeader() == this)
|
||||
m_formation->FormationReset(true);
|
||||
|
||||
if (!despawn && (CanFly() || IsFlying()) && !HasUnitMovementFlag(MOVEMENTFLAG_SWIMMING)) // pussywizard: added MOVEMENTFLAG_SWIMMING check because IsFlying() returns true when swimming creatures have MOVEMENTFLAG_DISABLE_GRAVITY
|
||||
bool needsFalling = !despawn && (IsFlying() || IsHovering()) && !IsUnderWater();
|
||||
SetHover(false, false);
|
||||
SetDisableGravity(false, false);
|
||||
|
||||
if (needsFalling)
|
||||
GetMotionMaster()->MoveFall(0, true);
|
||||
|
||||
Unit::setDeathState(CORPSE, despawn);
|
||||
@@ -1609,6 +1676,7 @@ void Creature::setDeathState(DeathState s, bool despawn)
|
||||
SetFullHealth();
|
||||
SetLootRecipient(nullptr);
|
||||
ResetPlayerDamageReq();
|
||||
SetCannotReachTarget(false);
|
||||
CreatureTemplate const* cinfo = GetCreatureTemplate();
|
||||
// Xinef: npc run by default
|
||||
//SetWalk(true);
|
||||
@@ -2203,11 +2271,12 @@ bool Creature::LoadCreaturesAddon(bool reload)
|
||||
// 2 StandFlags
|
||||
// 3 StandMiscFlags
|
||||
|
||||
SetByteValue(UNIT_FIELD_BYTES_1, 0, uint8(cainfo->bytes1 & 0xFF));
|
||||
//SetByteValue(UNIT_FIELD_BYTES_1, 1, uint8((cainfo->bytes1 >> 8) & 0xFF));
|
||||
SetByteValue(UNIT_FIELD_BYTES_1, 1, 0);
|
||||
SetByteValue(UNIT_FIELD_BYTES_1, 2, uint8((cainfo->bytes1 >> 16) & 0xFF));
|
||||
SetByteValue(UNIT_FIELD_BYTES_1, 3, uint8((cainfo->bytes1 >> 24) & 0xFF));
|
||||
SetByteValue(UNIT_FIELD_BYTES_1, UNIT_BYTES_1_OFFSET_STAND_STATE, uint8(cainfo->bytes1 & 0xFF));
|
||||
//SetByteValue(UNIT_FIELD_BYTES_1, UNIT_BYTES_1_OFFSET_PET_TALENTS, uint8((cainfo->bytes1 >> 8) & 0xFF));
|
||||
SetByteValue(UNIT_FIELD_BYTES_1, UNIT_BYTES_1_OFFSET_PET_TALENTS, 0);
|
||||
SetByteValue(UNIT_FIELD_BYTES_1, UNIT_BYTES_1_OFFSET_VIS_FLAG, uint8((cainfo->bytes1 >> 16) & 0xFF));
|
||||
m_originalAnimTier = uint8((cainfo->bytes1 >> 24) & 0xFF);
|
||||
SetByteValue(UNIT_FIELD_BYTES_1, UNIT_BYTES_1_OFFSET_ANIM_TIER, m_originalAnimTier);
|
||||
|
||||
//! Suspected correlation between UNIT_FIELD_BYTES_1, offset 3, value 0x2:
|
||||
//! If no inhabittype_fly (if no MovementFlag_DisableGravity or MovementFlag_CanFly flag found in sniffs)
|
||||
@@ -2660,10 +2729,6 @@ bool Creature::SetDisableGravity(bool disable, bool packetOnly/*=false*/)
|
||||
if (!movespline->Initialized())
|
||||
return true;
|
||||
|
||||
// pussywizard: artificial disable_gravity to hovering npcs, don't send!
|
||||
if (!disable && GetHoverHeight() >= 2.0f)
|
||||
return true;
|
||||
|
||||
WorldPacket data(disable ? SMSG_SPLINE_MOVE_GRAVITY_DISABLE : SMSG_SPLINE_MOVE_GRAVITY_ENABLE, 9);
|
||||
data.append(GetPackGUID());
|
||||
SendMessageToSet(&data, false);
|
||||
@@ -2684,6 +2749,43 @@ bool Creature::SetSwim(bool enable)
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This method check the current flag/status of a creature and its inhabit type
|
||||
*
|
||||
* Pets should swim by default to properly follow the player
|
||||
* NOTE: You can set the UNIT_FLAG_CANNOT_SWIM temporary to deny a creature to swim
|
||||
*
|
||||
*/
|
||||
bool Creature::CanSwim() const
|
||||
{
|
||||
if (Unit::CanSwim())
|
||||
return true;
|
||||
|
||||
if (IsPet() || IS_PLAYER_GUID(GetOwnerGUID()))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Creature::CanEnterWater() const
|
||||
{
|
||||
if (CanSwim())
|
||||
return true;
|
||||
|
||||
return GetCreatureTemplate()->InhabitType & INHABIT_WATER;
|
||||
}
|
||||
|
||||
void Creature::RefreshSwimmingFlag(bool recheck)
|
||||
{
|
||||
if (!_isMissingSwimmingFlagOutOfCombat || recheck)
|
||||
_isMissingSwimmingFlagOutOfCombat = !HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SWIMMING);
|
||||
|
||||
// Check if the creature has UNIT_FLAG_SWIMMING and add it if it's missing
|
||||
// Creatures must be able to chase a target in water if they can enter water
|
||||
if (_isMissingSwimmingFlagOutOfCombat && CanEnterWater())
|
||||
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SWIMMING);
|
||||
}
|
||||
|
||||
bool Creature::SetCanFly(bool enable, bool /*packetOnly*/ /* = false */)
|
||||
{
|
||||
if (!Unit::SetCanFly(enable))
|
||||
@@ -2698,6 +2800,14 @@ bool Creature::SetCanFly(bool enable, bool /*packetOnly*/ /* = false */)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Creature::CanFly() const
|
||||
{
|
||||
if (Unit::IsFlying())
|
||||
return true;
|
||||
|
||||
return GetCreatureTemplate()->InhabitType & INHABIT_AIR;
|
||||
}
|
||||
|
||||
bool Creature::SetWaterWalking(bool enable, bool packetOnly /* = false */)
|
||||
{
|
||||
if (!packetOnly && !Unit::SetWaterWalking(enable))
|
||||
@@ -2733,9 +2843,9 @@ bool Creature::SetHover(bool enable, bool packetOnly /*= false*/)
|
||||
|
||||
//! Unconfirmed for players:
|
||||
if (enable)
|
||||
SetByteFlag(UNIT_FIELD_BYTES_1, 3, UNIT_BYTE1_FLAG_HOVER);
|
||||
SetByteFlag(UNIT_FIELD_BYTES_1, UNIT_BYTES_1_OFFSET_ANIM_TIER, UNIT_BYTE1_FLAG_HOVER);
|
||||
else
|
||||
RemoveByteFlag(UNIT_FIELD_BYTES_1, 3, UNIT_BYTE1_FLAG_HOVER);
|
||||
RemoveByteFlag(UNIT_FIELD_BYTES_1, UNIT_BYTES_1_OFFSET_ANIM_TIER, UNIT_BYTE1_FLAG_HOVER);
|
||||
|
||||
if (!movespline->Initialized())
|
||||
return true;
|
||||
@@ -2793,22 +2903,38 @@ void Creature::SetObjectScale(float scale)
|
||||
{
|
||||
Unit::SetObjectScale(scale);
|
||||
|
||||
float combatReach = DEFAULT_WORLD_OBJECT_SIZE;
|
||||
|
||||
if (CreatureModelInfo const* minfo = sObjectMgr->GetCreatureModelInfo(GetDisplayId()))
|
||||
{
|
||||
SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, (IsPet() ? 1.0f : minfo->bounding_radius) * scale);
|
||||
SetFloatValue(UNIT_FIELD_COMBATREACH, (IsPet() ? DEFAULT_COMBAT_REACH : minfo->combat_reach) * scale);
|
||||
if (minfo->combat_reach > 0)
|
||||
combatReach = minfo->combat_reach;
|
||||
}
|
||||
|
||||
if (IsPet())
|
||||
combatReach = DEFAULT_COMBAT_REACH;
|
||||
|
||||
SetFloatValue(UNIT_FIELD_COMBATREACH, combatReach * GetFloatValue(OBJECT_FIELD_SCALE_X) * scale);
|
||||
}
|
||||
|
||||
void Creature::SetDisplayId(uint32 modelId)
|
||||
{
|
||||
Unit::SetDisplayId(modelId);
|
||||
|
||||
float combatReach = DEFAULT_WORLD_OBJECT_SIZE;
|
||||
|
||||
if (CreatureModelInfo const* minfo = sObjectMgr->GetCreatureModelInfo(modelId))
|
||||
{
|
||||
SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, (IsPet() ? 1.0f : minfo->bounding_radius) * GetFloatValue(OBJECT_FIELD_SCALE_X));
|
||||
SetFloatValue(UNIT_FIELD_COMBATREACH, (IsPet() ? DEFAULT_COMBAT_REACH : minfo->combat_reach) * GetFloatValue(OBJECT_FIELD_SCALE_X));
|
||||
SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, (IsPet() ? 1.0f : minfo->bounding_radius) * GetObjectScale());
|
||||
if (minfo->combat_reach > 0)
|
||||
combatReach = minfo->combat_reach;
|
||||
}
|
||||
|
||||
if (IsPet())
|
||||
combatReach = DEFAULT_COMBAT_REACH;
|
||||
|
||||
SetFloatValue(UNIT_FIELD_COMBATREACH, combatReach * GetObjectScale());
|
||||
}
|
||||
|
||||
void Creature::SetTarget(uint64 guid)
|
||||
@@ -2835,6 +2961,16 @@ void Creature::FocusTarget(Spell const* focusSpell, WorldObject const* target)
|
||||
SetInFront(target);
|
||||
}
|
||||
|
||||
bool Creature::HasSpellFocus(Spell const* focusSpell) const
|
||||
{
|
||||
if (isDead()) // dead creatures cannot focus
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return focusSpell ? (focusSpell == _spellFocusInfo.Spell) : (_spellFocusInfo.Spell || _spellFocusInfo.Delay);
|
||||
}
|
||||
|
||||
void Creature::ReleaseFocus(Spell const* focusSpell)
|
||||
{
|
||||
// focused to something else
|
||||
@@ -2892,3 +3028,36 @@ float Creature::GetAttackDistance(Unit const* player) const
|
||||
|
||||
return (retDistance * aggroRate);
|
||||
}
|
||||
|
||||
bool Creature::IsMovementPreventedByCasting() const
|
||||
{
|
||||
Spell* spell = m_currentSpells[CURRENT_CHANNELED_SPELL];
|
||||
// first check if currently a movement allowed channel is active and we're not casting
|
||||
if (!!spell && spell->getState() != SPELL_STATE_FINISHED && spell->IsChannelActive() && spell->GetSpellInfo()->IsMoveAllowedChannel())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (HasSpellFocus())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (HasUnitState(UNIT_STATE_CASTING))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Creature::SetCannotReachTarget(bool cannotReach)
|
||||
{
|
||||
if (cannotReach == m_cannotReachTarget)
|
||||
return;
|
||||
m_cannotReachTarget = cannotReach;
|
||||
m_cannotReachTimer = 0;
|
||||
|
||||
if (cannotReach)
|
||||
sLog->outDebug(LOG_FILTER_UNITS, "Creature::SetCannotReachTarget() called with true. Details: %s", GetDebugInfo().c_str());
|
||||
}
|
||||
|
||||
@@ -465,8 +465,10 @@ public:
|
||||
[[nodiscard]] bool IsTrigger() const { return GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_TRIGGER; }
|
||||
[[nodiscard]] bool IsGuard() const { return GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_GUARD; }
|
||||
[[nodiscard]] bool CanWalk() const { return GetCreatureTemplate()->InhabitType & INHABIT_GROUND; }
|
||||
[[nodiscard]] bool CanSwim() const override { return (GetCreatureTemplate()->InhabitType & INHABIT_WATER) || IS_PLAYER_GUID(GetOwnerGUID()); }
|
||||
[[nodiscard]] bool CanFly() const override { return GetCreatureTemplate()->InhabitType & INHABIT_AIR; }
|
||||
[[nodiscard]] bool CanSwim() const override;
|
||||
[[nodiscard]] bool CanEnterWater() const override;
|
||||
[[nodiscard]] bool CanFly() const override;
|
||||
[[nodiscard]] bool CanHover() const { return m_originalAnimTier & UNIT_BYTE1_FLAG_HOVER || IsHovering(); }
|
||||
|
||||
void SetReactState(ReactStates st) { m_reactState = st; }
|
||||
[[nodiscard]] ReactStates GetReactState() const { return m_reactState; }
|
||||
@@ -521,6 +523,15 @@ public:
|
||||
bool SetWaterWalking(bool enable, bool packetOnly = false) override;
|
||||
bool SetFeatherFall(bool enable, bool packetOnly = false) override;
|
||||
bool SetHover(bool enable, bool packetOnly = false) override;
|
||||
bool HasSpellFocus(Spell const* focusSpell = nullptr) const;
|
||||
|
||||
struct
|
||||
{
|
||||
::Spell const* Spell = nullptr;
|
||||
uint32 Delay = 0; // ms until the creature's target should snap back (0 = no snapback scheduled)
|
||||
uint64 Target; // the creature's "real" target while casting
|
||||
float Orientation = 0.0f; // the creature's "real" orientation while casting
|
||||
} _spellFocusInfo;
|
||||
|
||||
[[nodiscard]] uint32 GetShieldBlockValue() const override
|
||||
{
|
||||
@@ -673,7 +684,7 @@ public:
|
||||
return m_charmInfo->GetCharmSpell(pos)->GetAction();
|
||||
}
|
||||
|
||||
void SetCannotReachTarget(bool cannotReach) { if (cannotReach == m_cannotReachTarget) return; m_cannotReachTarget = cannotReach; m_cannotReachTimer = 0; }
|
||||
void SetCannotReachTarget(bool cannotReach);
|
||||
[[nodiscard]] bool CanNotReachTarget() const { return m_cannotReachTarget; }
|
||||
|
||||
void SetPosition(float x, float y, float z, float o);
|
||||
@@ -725,11 +736,24 @@ public:
|
||||
void SetTarget(uint64 guid) override;
|
||||
void FocusTarget(Spell const* focusSpell, WorldObject const* target);
|
||||
void ReleaseFocus(Spell const* focusSpell);
|
||||
bool IsMovementPreventedByCasting() const;
|
||||
|
||||
// Part of Evade mechanics
|
||||
[[nodiscard]] time_t GetLastDamagedTime() const { return _lastDamagedTime; }
|
||||
void SetLastDamagedTime(time_t val) { _lastDamagedTime = val; }
|
||||
|
||||
bool IsFreeToMove();
|
||||
static constexpr uint32 MOVE_CIRCLE_CHECK_INTERVAL = 3000;
|
||||
static constexpr uint32 MOVE_BACKWARDS_CHECK_INTERVAL = 2000;
|
||||
uint32 m_moveCircleMovementTime = MOVE_CIRCLE_CHECK_INTERVAL;
|
||||
uint32 m_moveBackwardsMovementTime = MOVE_BACKWARDS_CHECK_INTERVAL;
|
||||
|
||||
bool HasSwimmingFlagOutOfCombat() const
|
||||
{
|
||||
return !_isMissingSwimmingFlagOutOfCombat;
|
||||
}
|
||||
void RefreshSwimmingFlag(bool recheck = false);
|
||||
|
||||
protected:
|
||||
bool CreateFromProto(uint32 guidlow, uint32 Entry, uint32 vehId, const CreatureData* data = nullptr);
|
||||
bool InitEntry(uint32 entry, const CreatureData* data = nullptr);
|
||||
@@ -759,6 +783,8 @@ protected:
|
||||
uint8 m_equipmentId;
|
||||
int8 m_originalEquipmentId; // can be -1
|
||||
|
||||
uint8 m_originalAnimTier;
|
||||
|
||||
bool m_AlreadyCallAssistance;
|
||||
bool m_AlreadySearchedAssistance;
|
||||
bool m_regenHealth;
|
||||
@@ -800,6 +826,8 @@ private:
|
||||
uint32 m_cannotReachTimer;
|
||||
|
||||
Spell const* _focusSpell; ///> Locks the target during spell cast for proper facing
|
||||
|
||||
bool _isMissingSwimmingFlagOutOfCombat;
|
||||
};
|
||||
|
||||
class AssistDelayEvent : public BasicEvent
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "Common.h"
|
||||
#include "Physics.h"
|
||||
#include "SharedDefines.h"
|
||||
#include "WorldPacket.h"
|
||||
#include "Opcodes.h"
|
||||
@@ -357,7 +358,7 @@ void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const
|
||||
|
||||
*data << object->GetPositionX();
|
||||
*data << object->GetPositionY();
|
||||
*data << object->GetPositionZ() + (unit ? unit->GetHoverHeight() : 0.0f);
|
||||
*data << object->GetPositionZ();
|
||||
|
||||
if (transport)
|
||||
{
|
||||
@@ -369,7 +370,7 @@ void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const
|
||||
{
|
||||
*data << object->GetPositionX();
|
||||
*data << object->GetPositionY();
|
||||
*data << object->GetPositionZ() + (unit ? unit->GetHoverHeight() : 0.0f);
|
||||
*data << object->GetPositionZ();
|
||||
}
|
||||
|
||||
*data << object->GetOrientation();
|
||||
@@ -386,7 +387,7 @@ void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const
|
||||
{
|
||||
*data << object->GetStationaryX();
|
||||
*data << object->GetStationaryY();
|
||||
*data << object->GetStationaryZ() + (unit ? unit->GetHoverHeight() : 0.0f);
|
||||
*data << object->GetStationaryZ();
|
||||
*data << object->GetStationaryO();
|
||||
}
|
||||
}
|
||||
@@ -897,6 +898,15 @@ bool Object::PrintIndexError(uint32 index, bool set) const
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Position::operator==(Position const& a)
|
||||
{
|
||||
return (G3D::fuzzyEq(a.m_positionX, m_positionX) &&
|
||||
G3D::fuzzyEq(a.m_positionY, m_positionY) &&
|
||||
G3D::fuzzyEq(a.m_positionZ, m_positionZ) &&
|
||||
G3D::fuzzyEq(a.m_orientation, m_orientation));
|
||||
}
|
||||
|
||||
void Position::RelocatePolarOffset(float angle, float dist, float z /*= 0.0f*/)
|
||||
{
|
||||
SetOrientation(GetOrientation() + angle);
|
||||
@@ -988,7 +998,7 @@ WorldObject::WorldObject(bool isWorldObject) : WorldLocation(),
|
||||
elunaEvents(nullptr),
|
||||
#endif
|
||||
LastUsedScriptID(0), m_name(""), m_isActive(false), m_isVisibilityDistanceOverride(false), m_isWorldObject(isWorldObject), m_zoneScript(nullptr),
|
||||
m_transport(nullptr), m_currMap(nullptr), m_InstanceId(0),
|
||||
m_staticFloorZ(INVALID_HEIGHT), m_transport(nullptr), m_currMap(nullptr), m_InstanceId(0),
|
||||
m_phaseMask(PHASEMASK_NORMAL), m_useCombinedPhases(true), m_notifyflags(0), m_executed_notifies(0)
|
||||
{
|
||||
m_serverSideVisibility.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_ALIVE | GHOST_VISIBILITY_GHOST);
|
||||
@@ -1139,7 +1149,7 @@ bool WorldObject::_IsWithinDist(WorldObject const* obj, float dist2compare, bool
|
||||
|
||||
Position WorldObject::GetHitSpherePointFor(Position const& dest) const
|
||||
{
|
||||
G3D::Vector3 vThis(GetPositionX(), GetPositionY(), GetPositionZ());
|
||||
G3D::Vector3 vThis(GetPositionX(), GetPositionY(), GetPositionZ() + GetCollisionHeight());
|
||||
G3D::Vector3 vObj(dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ());
|
||||
G3D::Vector3 contactPoint = vThis + (vObj - vThis).directionOrZero() * std::min(dest.GetExactDist(this), GetObjectSize());
|
||||
|
||||
@@ -1150,29 +1160,47 @@ bool WorldObject::IsWithinLOS(float ox, float oy, float oz, LineOfSightChecks ch
|
||||
{
|
||||
if (IsInWorld())
|
||||
{
|
||||
oz += GetCollisionHeight();
|
||||
float x, y, z;
|
||||
if (GetTypeId() == TYPEID_PLAYER)
|
||||
{
|
||||
GetPosition(x, y, z);
|
||||
z += GetCollisionHeight();
|
||||
}
|
||||
else
|
||||
{
|
||||
GetHitSpherePointFor({ ox, oy, oz }, x, y, z);
|
||||
}
|
||||
|
||||
return GetMap()->isInLineOfSight(x, y, z + 2.0f, ox, oy, oz + 2.0f, GetPhaseMask(), checks);
|
||||
return GetMap()->isInLineOfSight(x, y, z, ox, oy, oz, GetPhaseMask(), checks);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WorldObject::IsWithinLOSInMap(const WorldObject* obj, LineOfSightChecks checks) const
|
||||
{
|
||||
if (!IsInMap(obj))
|
||||
if (!IsInMap(obj))
|
||||
return false;
|
||||
|
||||
float x, y, z;
|
||||
float ox, oy, oz;
|
||||
if (obj->GetTypeId() == TYPEID_PLAYER)
|
||||
obj->GetPosition(x, y, z);
|
||||
{
|
||||
obj->GetPosition(ox, oy, oz);
|
||||
oz += GetCollisionHeight();
|
||||
}
|
||||
else
|
||||
obj->GetHitSpherePointFor(GetPosition(), x, y, z);
|
||||
obj->GetHitSpherePointFor({ GetPositionX(), GetPositionY(), GetPositionZ() + GetCollisionHeight() }, ox, oy, oz);
|
||||
|
||||
return IsWithinLOS(x, y, z, checks);
|
||||
float x, y, z;
|
||||
if (GetTypeId() == TYPEID_PLAYER)
|
||||
{
|
||||
GetPosition(x, y, z);
|
||||
z += GetCollisionHeight();
|
||||
}
|
||||
else
|
||||
GetHitSpherePointFor({ obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ() + obj->GetCollisionHeight() }, x, y, z);
|
||||
|
||||
return GetMap()->isInLineOfSight(x, y, z, ox, oy, oz, GetPhaseMask(), checks);
|
||||
}
|
||||
|
||||
void WorldObject::GetHitSpherePointFor(Position const& dest, float& x, float& y, float& z) const
|
||||
@@ -1302,12 +1330,7 @@ float Position::GetAngle(const Position* obj) const
|
||||
// Return angle in range 0..2*pi
|
||||
float Position::GetAngle(const float x, const float y) const
|
||||
{
|
||||
float dx = x - GetPositionX();
|
||||
float dy = y - GetPositionY();
|
||||
|
||||
float ang = atan2(dy, dx);
|
||||
ang = (ang >= 0) ? ang : 2 * M_PI + ang;
|
||||
return ang;
|
||||
return getAngle(GetPositionX(), GetPositionY(), x, y);
|
||||
}
|
||||
|
||||
void Position::GetSinCos(const float x, const float y, float& vsin, float& vcos) const
|
||||
@@ -1446,78 +1469,95 @@ void WorldObject::GetRandomPoint(const Position& pos, float distance, float& ran
|
||||
UpdateGroundPositionZ(rand_x, rand_y, rand_z); // update to LOS height if available
|
||||
}
|
||||
|
||||
void WorldObject::UpdateGroundPositionZ(float x, float y, float& z) const
|
||||
void WorldObject::UpdateGroundPositionZ(float x, float y, float &z) const
|
||||
{
|
||||
float new_z = GetMap()->GetHeight(GetPhaseMask(), x, y, z /*+ 2.0f*/, true); // pussywizard: +2.0f is added in all inner functions
|
||||
float new_z = GetMapHeight(x, y, z);
|
||||
if (new_z > INVALID_HEIGHT)
|
||||
z = new_z + 0.05f; // just to be sure that we are not a few pixel under the surface
|
||||
z = new_z + (isType(TYPEMASK_UNIT) ? static_cast<Unit const*>(this)->GetHoverHeight() : 0.0f);
|
||||
}
|
||||
|
||||
void WorldObject::UpdateAllowedPositionZ(float x, float y, float& z) const
|
||||
/**
|
||||
* @brief Get the minimum height of a object that should be in water
|
||||
* to start floating/swim
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
float WorldObject::GetMinHeightInWater() const
|
||||
{
|
||||
// TODO: Allow transports to be part of dynamic vmap tree
|
||||
//if (GetTransport())
|
||||
// return;
|
||||
// have a fun with Archimedes' formula
|
||||
auto height = GetCollisionHeight();
|
||||
auto width = GetCollisionWidth();
|
||||
auto weight = getWeight(height, width, 1040); // avg human specific weight
|
||||
auto heightOutOfWater = getOutOfWater(width, weight, 10202) * 4.0f; // avg human density
|
||||
auto heightInWater = height - heightOutOfWater;
|
||||
return (height > heightInWater ? heightInWater : (height - (height / 3)));
|
||||
}
|
||||
|
||||
switch (GetTypeId())
|
||||
void WorldObject::UpdateAllowedPositionZ(float x, float y, float& z, float* groundZ) const
|
||||
{
|
||||
if (GetTransport())
|
||||
{
|
||||
case TYPEID_UNIT:
|
||||
if (groundZ)
|
||||
*groundZ = z;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (Unit const* unit = ToUnit())
|
||||
{
|
||||
if (!unit->CanFly())
|
||||
{
|
||||
Creature const* c = unit->ToCreature();
|
||||
bool canSwim = c ? c->CanSwim() : true;
|
||||
float ground_z = z;
|
||||
float max_z;
|
||||
if (canSwim)
|
||||
max_z = GetMapWaterOrGroundLevel(x, y, z, &ground_z);
|
||||
else
|
||||
max_z = ground_z = GetMapHeight(x, y, z);
|
||||
|
||||
if (max_z > INVALID_HEIGHT)
|
||||
{
|
||||
// non fly unit don't must be in air
|
||||
// non swim unit must be at ground (mostly speedup, because it don't must be in water and water level check less fast
|
||||
if (!ToCreature()->CanFly())
|
||||
{
|
||||
bool canSwim = ToCreature()->CanSwim();
|
||||
float ground_z = z;
|
||||
float max_z = canSwim
|
||||
? GetMap()->GetWaterOrGroundLevel(GetPhaseMask(), x, y, z, &ground_z, !ToUnit()->HasAuraType(SPELL_AURA_WATER_WALK))
|
||||
: ((ground_z = GetMap()->GetHeight(GetPhaseMask(), x, y, z, true)));
|
||||
if (max_z > INVALID_HEIGHT)
|
||||
{
|
||||
if (z > max_z)
|
||||
z = max_z;
|
||||
else if (z < ground_z)
|
||||
z = ground_z;
|
||||
}
|
||||
if (canSwim && unit->GetMap()->IsInWater(x, y, max_z - WATER_HEIGHT_TOLERANCE)) {
|
||||
// do not allow creatures to walk on
|
||||
// water level while swimming
|
||||
max_z = max_z - GetMinHeightInWater();
|
||||
}
|
||||
else
|
||||
{
|
||||
float ground_z = GetMap()->GetHeight(GetPhaseMask(), x, y, z, true);
|
||||
if (z < ground_z)
|
||||
z = ground_z;
|
||||
// hovering units cannot go below their hover height
|
||||
float hoverOffset = unit->GetHoverHeight();
|
||||
max_z += hoverOffset;
|
||||
ground_z += hoverOffset;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TYPEID_PLAYER:
|
||||
{
|
||||
// for server controlled moves playr work same as creature (but it can always swim)
|
||||
if (!ToPlayer()->CanFly())
|
||||
{
|
||||
float ground_z = z;
|
||||
float max_z = GetMap()->GetWaterOrGroundLevel(GetPhaseMask(), x, y, z, &ground_z, !ToUnit()->HasAuraType(SPELL_AURA_WATER_WALK));
|
||||
if (max_z > INVALID_HEIGHT)
|
||||
{
|
||||
if (z > max_z)
|
||||
z = max_z;
|
||||
else if (z < ground_z)
|
||||
z = ground_z;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float ground_z = GetMap()->GetHeight(GetPhaseMask(), x, y, z, true);
|
||||
if (z < ground_z)
|
||||
z = ground_z;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
float ground_z = GetMap()->GetHeight(GetPhaseMask(), x, y, z, true);
|
||||
if (ground_z > INVALID_HEIGHT)
|
||||
|
||||
if (z > max_z)
|
||||
z = max_z;
|
||||
else if (z < ground_z)
|
||||
z = ground_z;
|
||||
break;
|
||||
}
|
||||
|
||||
if (groundZ)
|
||||
*groundZ = ground_z;
|
||||
}
|
||||
else
|
||||
{
|
||||
float ground_z = GetMapHeight(x, y, z) + unit->GetHoverHeight();
|
||||
if (z < ground_z)
|
||||
z = ground_z;
|
||||
|
||||
if (groundZ)
|
||||
*groundZ = ground_z;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float ground_z = GetMapHeight(x, y, z);
|
||||
if (ground_z > INVALID_HEIGHT)
|
||||
z = ground_z;
|
||||
|
||||
if (groundZ)
|
||||
*groundZ = ground_z;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2552,23 +2592,64 @@ namespace acore
|
||||
|
||||
//===================================================================================================
|
||||
|
||||
void WorldObject::GetNearPoint2D(float& x, float& y, float distance2d, float absAngle) const
|
||||
void WorldObject::GetNearPoint2D(WorldObject const* searcher, float& x, float& y, float distance2d, float absAngle) const
|
||||
{
|
||||
x = GetPositionX() + (GetObjectSize() + distance2d) * cos(absAngle);
|
||||
y = GetPositionY() + (GetObjectSize() + distance2d) * sin(absAngle);
|
||||
float effectiveReach = GetCombatReach();
|
||||
|
||||
if (searcher)
|
||||
{
|
||||
effectiveReach += searcher->GetCombatReach();
|
||||
|
||||
if (this != searcher)
|
||||
{
|
||||
float myHover = 0.0f, searcherHover = 0.0f;
|
||||
if (Unit const* unit = ToUnit())
|
||||
myHover = unit->GetHoverHeight();
|
||||
if (Unit const* searchUnit = searcher->ToUnit())
|
||||
searcherHover = searchUnit->GetHoverHeight();
|
||||
|
||||
float hoverDelta = myHover - searcherHover;
|
||||
if (hoverDelta != 0.0f)
|
||||
effectiveReach = std::sqrt(std::max(effectiveReach * effectiveReach - hoverDelta * hoverDelta, 0.0f));
|
||||
}
|
||||
}
|
||||
|
||||
x = GetPositionX() + (effectiveReach + distance2d) * std::cos(absAngle);
|
||||
y = GetPositionY() + (effectiveReach + distance2d) * std::sin(absAngle);
|
||||
|
||||
acore::NormalizeMapCoord(x);
|
||||
acore::NormalizeMapCoord(y);
|
||||
}
|
||||
|
||||
void WorldObject::GetNearPoint2D(float& x, float& y, float distance2d, float absAngle) const
|
||||
{
|
||||
GetNearPoint2D(nullptr, x, y, distance2d, absAngle);
|
||||
}
|
||||
|
||||
void WorldObject::GetNearPoint(WorldObject const* searcher, float& x, float& y, float& z, float searcher_size, float distance2d, float absAngle, float controlZ) const
|
||||
{
|
||||
GetNearPoint2D(x, y, distance2d + searcher_size, absAngle);
|
||||
z = GetPositionZ();
|
||||
if (searcher)
|
||||
|
||||
if (searcher) {
|
||||
if (Unit const* unit = searcher->ToUnit(); Unit const* target = ToUnit())
|
||||
{
|
||||
if (unit && target && unit->IsInWater() && target->IsInWater())
|
||||
{
|
||||
// if the searcher is in water
|
||||
// we have no ground so we can
|
||||
// set the target height to the
|
||||
// z-coord to keep the searcher
|
||||
// at the correct height (face to face)
|
||||
z += GetCollisionHeight() - unit->GetCollisionHeight();
|
||||
}
|
||||
}
|
||||
searcher->UpdateAllowedPositionZ(x, y, z);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateAllowedPositionZ(x, y, z);
|
||||
}
|
||||
|
||||
// if detection disabled, return first point
|
||||
if (!sWorld->getBoolConfig(CONFIG_DETECT_POS_COLLISION))
|
||||
@@ -2679,8 +2760,8 @@ void WorldObject::MovePosition(Position& pos, float dist, float angle)
|
||||
return;
|
||||
}
|
||||
|
||||
ground = GetMap()->GetHeight(GetPhaseMask(), destx, desty, MAX_HEIGHT, true);
|
||||
floor = GetMap()->GetHeight(GetPhaseMask(), destx, desty, pos.m_positionZ, true);
|
||||
ground = GetMapHeight(destx, desty, MAX_HEIGHT);
|
||||
floor = GetMapHeight(destx, desty, pos.m_positionZ);
|
||||
destz = fabs(ground - pos.m_positionZ) <= fabs(floor - pos.m_positionZ) ? ground : floor;
|
||||
|
||||
float step = dist / 10.0f;
|
||||
@@ -2692,215 +2773,74 @@ void WorldObject::MovePosition(Position& pos, float dist, float angle)
|
||||
{
|
||||
destx -= step * cos(angle);
|
||||
desty -= step * sin(angle);
|
||||
ground = GetMap()->GetHeight(GetPhaseMask(), destx, desty, MAX_HEIGHT, true);
|
||||
floor = GetMap()->GetHeight(GetPhaseMask(), destx, desty, pos.m_positionZ, true);
|
||||
ground = GetMapHeight(destx, desty, MAX_HEIGHT);
|
||||
floor = GetMapHeight(destx, desty, pos.m_positionZ);
|
||||
destz = fabs(ground - pos.m_positionZ) <= fabs(floor - pos.m_positionZ) ? ground : floor;
|
||||
}
|
||||
// we have correct destz now
|
||||
else
|
||||
{
|
||||
pos.Relocate(destx, desty, destz);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pos.Relocate(destx, desty, destz);
|
||||
|
||||
acore::NormalizeMapCoord(pos.m_positionX);
|
||||
acore::NormalizeMapCoord(pos.m_positionY);
|
||||
UpdateGroundPositionZ(pos.m_positionX, pos.m_positionY, pos.m_positionZ);
|
||||
pos.m_orientation = m_orientation;
|
||||
}
|
||||
|
||||
Position WorldObject::GetFirstCollisionPosition(float startX, float startY, float startZ, float destX, float destY)
|
||||
{
|
||||
auto dx = destX - startX;
|
||||
auto dy = destY - startY;
|
||||
|
||||
auto ang = atan2(dy, dx);
|
||||
ang = (ang >= 0) ? ang : 2 * M_PI + ang;
|
||||
Position pos = Position(startX, startY, startZ, ang);
|
||||
|
||||
auto distance = pos.GetExactDist2d(destX,destY);
|
||||
|
||||
MovePositionToFirstCollision(pos, distance, ang);
|
||||
return pos;
|
||||
};
|
||||
|
||||
Position WorldObject::GetFirstCollisionPosition(float destX, float destY, float destZ)
|
||||
{
|
||||
Position pos = GetPosition();
|
||||
auto distance = GetExactDistSq(destX,destY,destZ);
|
||||
|
||||
auto dx = destX - pos.GetPositionX();
|
||||
auto dy = destY - pos.GetPositionY();
|
||||
|
||||
auto ang = atan2(dy, dx);
|
||||
ang = (ang >= 0) ? ang : 2 * M_PI + ang;
|
||||
|
||||
MovePositionToFirstCollision(pos, distance, ang);
|
||||
return pos;
|
||||
};
|
||||
|
||||
Position WorldObject::GetFirstCollisionPosition(float dist, float angle)
|
||||
{
|
||||
Position pos = GetPosition();
|
||||
GetFirstCollisionPosition(pos, dist, angle);
|
||||
return pos;
|
||||
}
|
||||
|
||||
void WorldObject::MovePositionToFirstCollision(Position& pos, float dist, float angle)
|
||||
{
|
||||
angle += m_orientation;
|
||||
angle += GetOrientation();
|
||||
float destx, desty, destz;
|
||||
destx = pos.m_positionX + dist * cos(angle);
|
||||
desty = pos.m_positionY + dist * sin(angle);
|
||||
destz = pos.m_positionZ;
|
||||
if (isType(TYPEMASK_UNIT | TYPEMASK_PLAYER) && !ToUnit()->IsInWater())
|
||||
destz += 2.0f;
|
||||
|
||||
// Prevent invalid coordinates here, position is unchanged
|
||||
if (!acore::IsValidMapCoord(destx, desty))
|
||||
{
|
||||
sLog->outCrash("WorldObject::MovePositionToFirstCollision invalid coordinates X: %f and Y: %f were passed!", destx, desty);
|
||||
if (!GetMap()->CheckCollisionAndGetValidCoords(this, pos.m_positionX, pos.m_positionY, pos.m_positionZ, destx, desty, destz, false))
|
||||
return;
|
||||
}
|
||||
|
||||
// Xinef: ugly hack for dalaran arena
|
||||
float selfAddition = 1.5f;
|
||||
float allowedDiff = 6.0f;
|
||||
float newDist = dist;
|
||||
if (GetMapId() == 617)
|
||||
{
|
||||
allowedDiff = 3.5f;
|
||||
selfAddition = 1.0f;
|
||||
destz = pos.m_positionZ + 1.0f;
|
||||
}
|
||||
else
|
||||
UpdateAllowedPositionZ(destx, desty, destz);
|
||||
|
||||
bool col = VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(GetMapId(), pos.m_positionX, pos.m_positionY, pos.m_positionZ + selfAddition, destx, desty, destz + 0.5f, destx, desty, destz, -0.5f);
|
||||
|
||||
// collision occured
|
||||
if (col)
|
||||
{
|
||||
// move back a bit
|
||||
if (pos.GetExactDist2d(destx, desty) > CONTACT_DISTANCE)
|
||||
{
|
||||
destx -= CONTACT_DISTANCE * cos(angle);
|
||||
desty -= CONTACT_DISTANCE * sin(angle);
|
||||
}
|
||||
|
||||
newDist = sqrt((pos.m_positionX - destx) * (pos.m_positionX - destx) + (pos.m_positionY - desty) * (pos.m_positionY - desty));
|
||||
}
|
||||
|
||||
// check dynamic collision
|
||||
col = GetMap()->getObjectHitPos(GetPhaseMask(), pos.m_positionX, pos.m_positionY, pos.m_positionZ + selfAddition, destx, desty, destz + 0.5f, destx, desty, destz, -0.5f);
|
||||
|
||||
// Collided with a gameobject
|
||||
if (col)
|
||||
{
|
||||
// move back a bit
|
||||
if (pos.GetExactDist2d(destx, desty) > CONTACT_DISTANCE)
|
||||
{
|
||||
destx -= CONTACT_DISTANCE * cos(angle);
|
||||
desty -= CONTACT_DISTANCE * sin(angle);
|
||||
}
|
||||
newDist = sqrt((pos.m_positionX - destx) * (pos.m_positionX - destx) + (pos.m_positionY - desty) * (pos.m_positionY - desty));
|
||||
}
|
||||
|
||||
float step = newDist / 10.0f;
|
||||
|
||||
for (uint8 j = 0; j < 10; ++j)
|
||||
{
|
||||
// do not allow too big z changes
|
||||
if (fabs(pos.m_positionZ - destz) > allowedDiff)
|
||||
{
|
||||
destx -= step * cos(angle);
|
||||
desty -= step * sin(angle);
|
||||
UpdateAllowedPositionZ(destx, desty, destz);
|
||||
}
|
||||
// we have correct destz now
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
acore::NormalizeMapCoord(destx);
|
||||
acore::NormalizeMapCoord(desty);
|
||||
UpdateAllowedPositionZ(destx, desty, destz);
|
||||
|
||||
float ground = GetMap()->GetHeight(GetPhaseMask(), destx, desty, MAX_HEIGHT, true);
|
||||
float floor = GetMap()->GetHeight(GetPhaseMask(), destx, desty, destz, true);
|
||||
ground = fabs(ground - destz) <= fabs(floor - pos.m_positionZ) ? ground : floor;
|
||||
if (destz < ground)
|
||||
destz = ground;
|
||||
|
||||
// Xinef: check if last z updates did not move z too far away
|
||||
//newDist = pos.GetExactDist(destx, desty, destz);
|
||||
//float ratio = newDist / dist;
|
||||
//if (ratio > 1.3f)
|
||||
//{
|
||||
// ratio = (1 / ratio) + (0.3f / ratio);
|
||||
// destx = pos.GetPositionX() + (fabs(destx - pos.GetPositionX()) * cos(angle) * ratio);
|
||||
// desty = pos.GetPositionY() + (fabs(desty - pos.GetPositionY()) * sin(angle) * ratio);
|
||||
// destz = pos.GetPositionZ() + (fabs(destz - pos.GetPositionZ()) * ratio * (destz < pos.GetPositionZ() ? -1.0f : 1.0f));
|
||||
//}
|
||||
|
||||
pos.SetOrientation(GetOrientation());
|
||||
pos.Relocate(destx, desty, destz);
|
||||
pos.m_orientation = m_orientation;
|
||||
}
|
||||
|
||||
void WorldObject::MovePositionToFirstCollisionForTotem(Position& pos, float dist, float angle, bool forGameObject)
|
||||
{
|
||||
angle += m_orientation;
|
||||
float destx, desty, destz, ground, floor;
|
||||
pos.m_positionZ += 2.0f;
|
||||
destx = pos.m_positionX + dist * cos(angle);
|
||||
desty = pos.m_positionY + dist * sin(angle);
|
||||
destz = pos.GetPositionZ();
|
||||
|
||||
// Prevent invalid coordinates here, position is unchanged
|
||||
if (!acore::IsValidMapCoord(destx, desty))
|
||||
{
|
||||
sLog->outCrash("WorldObject::MovePositionToFirstCollision invalid coordinates X: %f and Y: %f were passed!", destx, desty);
|
||||
return;
|
||||
}
|
||||
|
||||
bool col = VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(GetMapId(), pos.m_positionX, pos.m_positionY, pos.m_positionZ, destx, desty, destz, destx, desty, destz, -0.5f);
|
||||
|
||||
// collision occured
|
||||
if (col)
|
||||
{
|
||||
// move back a bit
|
||||
if (pos.GetExactDist2d(destx, desty) > CONTACT_DISTANCE)
|
||||
{
|
||||
destx -= CONTACT_DISTANCE * cos(angle);
|
||||
desty -= CONTACT_DISTANCE * sin(angle);
|
||||
}
|
||||
|
||||
dist = sqrt((pos.m_positionX - destx) * (pos.m_positionX - destx) + (pos.m_positionY - desty) * (pos.m_positionY - desty));
|
||||
}
|
||||
|
||||
// check dynamic collision
|
||||
col = GetMap()->getObjectHitPos(GetPhaseMask(), pos.m_positionX, pos.m_positionY, pos.m_positionZ + 0.5f, destx, desty, destz + 0.5f, destx, desty, destz, -0.5f);
|
||||
|
||||
// Collided with a gameobject
|
||||
if (col)
|
||||
{
|
||||
// move back a bit
|
||||
if (pos.GetExactDist2d(destx, desty) > CONTACT_DISTANCE)
|
||||
{
|
||||
destx -= CONTACT_DISTANCE * cos(angle);
|
||||
desty -= CONTACT_DISTANCE * sin(angle);
|
||||
}
|
||||
dist = sqrt((pos.m_positionX - destx) * (pos.m_positionX - destx) + (pos.m_positionY - desty) * (pos.m_positionY - desty));
|
||||
}
|
||||
|
||||
float prevdx = destx, prevdy = desty, prevdz = destz;
|
||||
bool anyvalid = false;
|
||||
|
||||
ground = GetMap()->GetHeight(GetPhaseMask(), destx, desty, MAX_HEIGHT, true);
|
||||
floor = GetMap()->GetHeight(GetPhaseMask(), destx, desty, pos.m_positionZ, true);
|
||||
destz = fabs(ground - pos.m_positionZ) <= fabs(floor - pos.m_positionZ) ? ground : floor;
|
||||
|
||||
// xinef: if we have gameobject, store last valid ground position
|
||||
// xinef: I assume you wanted to spawn totem in air and allow it to fall down if no valid position was found
|
||||
if (forGameObject)
|
||||
prevdz = destz;
|
||||
|
||||
float step = dist / 10.0f;
|
||||
for (uint8 j = 0; j < 10; ++j)
|
||||
{
|
||||
// do not allow too big z changes
|
||||
if (fabs(pos.m_positionZ - destz) > 4.0f)
|
||||
{
|
||||
destx -= step * cos(angle);
|
||||
desty -= step * sin(angle);
|
||||
ground = GetMap()->GetHeight(GetPhaseMask(), destx, desty, MAX_HEIGHT, true);
|
||||
floor = GetMap()->GetHeight(GetPhaseMask(), destx, desty, pos.m_positionZ, true);
|
||||
destz = fabs(ground - pos.m_positionZ) <= fabs(floor - pos.m_positionZ) ? ground : floor;
|
||||
if (j == 9 && fabs(pos.m_positionZ - destz) <= 4.0f)
|
||||
anyvalid = true;
|
||||
}
|
||||
// we have correct destz now
|
||||
else
|
||||
{
|
||||
anyvalid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!anyvalid)
|
||||
{
|
||||
destx = prevdx;
|
||||
desty = prevdy;
|
||||
destz = prevdz;
|
||||
}
|
||||
|
||||
acore::NormalizeMapCoord(destx);
|
||||
acore::NormalizeMapCoord(desty);
|
||||
|
||||
pos.Relocate(destx, desty, destz);
|
||||
pos.m_orientation = m_orientation;
|
||||
}
|
||||
|
||||
void WorldObject::SetPhaseMask(uint32 newPhaseMask, bool update)
|
||||
@@ -3116,3 +3056,26 @@ uint64 WorldObject::GetTransGUID() const
|
||||
return GetTransport()->GetGUID();
|
||||
return 0;
|
||||
}
|
||||
|
||||
float WorldObject::GetMapHeight(float x, float y, float z, bool vmap/* = true*/, float distanceToSearch/* = DEFAULT_HEIGHT_SEARCH*/) const
|
||||
{
|
||||
if (z != MAX_HEIGHT)
|
||||
z += GetCollisionHeight();
|
||||
|
||||
return GetMap()->GetHeight(GetPhaseMask(), x, y, z, vmap, distanceToSearch);
|
||||
}
|
||||
|
||||
float WorldObject::GetMapWaterOrGroundLevel(float x, float y, float z, float* ground/* = nullptr*/) const
|
||||
{
|
||||
return GetMap()->GetWaterOrGroundLevel(GetPhaseMask(), x, y, z, ground,
|
||||
isType(TYPEMASK_UNIT) ? !static_cast<Unit const*>(this)->HasAuraType(SPELL_AURA_WATER_WALK) : false,
|
||||
GetCollisionHeight());
|
||||
}
|
||||
|
||||
float WorldObject::GetFloorZ() const
|
||||
{
|
||||
if (!IsInWorld())
|
||||
return m_staticFloorZ;
|
||||
|
||||
return std::max<float>(m_staticFloorZ, GetMap()->GetGameObjectFloor(GetPhaseMask(), GetPositionX(), GetPositionY(), GetPositionZ() + GetCollisionHeight()));
|
||||
}
|
||||
|
||||
@@ -24,26 +24,6 @@ class ElunaEventProcessor;
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#define CONTACT_DISTANCE 0.5f
|
||||
#define INTERACTION_DISTANCE 5.5f
|
||||
#define ATTACK_DISTANCE 5.0f
|
||||
#define MAX_SEARCHER_DISTANCE 150.0f // pussywizard: replace the use of MAX_VISIBILITY_DISTANCE in searchers, because MAX_VISIBILITY_DISTANCE is quite too big for this purpose
|
||||
#define MAX_VISIBILITY_DISTANCE 250.0f // max distance for visible objects, experimental
|
||||
#define VISIBILITY_INC_FOR_GOBJECTS 30.0f // pussywizard
|
||||
#define VISIBILITY_COMPENSATION 15.0f // increase searchers
|
||||
#define SPELL_SEARCHER_COMPENSATION 30.0f // increase searchers size in case we have large npc near cell border
|
||||
#define VISIBILITY_DIST_WINTERGRASP 175.0f
|
||||
#define SIGHT_RANGE_UNIT 50.0f
|
||||
#define DEFAULT_VISIBILITY_DISTANCE 90.0f // default visible distance, 90 yards on continents
|
||||
#define DEFAULT_VISIBILITY_INSTANCE 120.0f // default visible distance in instances, 120 yards
|
||||
#define DEFAULT_VISIBILITY_BGARENAS 150.0f // default visible distance in BG/Arenas, 150 yards
|
||||
|
||||
#define DEFAULT_WORLD_OBJECT_SIZE 0.388999998569489f // player size, also currently used (correctly?) for any non Unit world objects
|
||||
#define DEFAULT_COMBAT_REACH 1.5f
|
||||
#define MIN_MELEE_REACH 2.0f
|
||||
#define NOMINAL_MELEE_RANGE 5.0f
|
||||
#define MELEE_RANGE (NOMINAL_MELEE_RANGE - MIN_MELEE_REACH * 2) //center to center for players
|
||||
|
||||
enum TypeMask
|
||||
{
|
||||
TYPEMASK_OBJECT = 0x0001,
|
||||
@@ -138,6 +118,7 @@ public:
|
||||
[[nodiscard]] uint32 GetEntry() const { return GetUInt32Value(OBJECT_FIELD_ENTRY); }
|
||||
void SetEntry(uint32 entry) { SetUInt32Value(OBJECT_FIELD_ENTRY, entry); }
|
||||
|
||||
float GetObjectScale() const { return GetFloatValue(OBJECT_FIELD_SCALE_X); }
|
||||
virtual void SetObjectScale(float scale) { SetFloatValue(OBJECT_FIELD_SCALE_X, scale); }
|
||||
|
||||
[[nodiscard]] TypeID GetTypeId() const { return m_objectTypeId; }
|
||||
@@ -540,11 +521,19 @@ struct Position
|
||||
|
||||
float GetAngle(const Position* pos) const;
|
||||
[[nodiscard]] float GetAngle(float x, float y) const;
|
||||
float GetAbsoluteAngle(float x, float y) const
|
||||
{
|
||||
float dx = x - m_positionX;
|
||||
float dy = y - m_positionY;
|
||||
return NormalizeOrientation(std::atan2(dy, dx));
|
||||
}
|
||||
float GetRelativeAngle(const Position* pos) const
|
||||
{
|
||||
return GetAngle(pos) - m_orientation;
|
||||
}
|
||||
[[nodiscard]] float GetRelativeAngle(float x, float y) const { return GetAngle(x, y) - m_orientation; }
|
||||
float ToAbsoluteAngle(float relAngle) const { return NormalizeOrientation(relAngle + m_orientation); }
|
||||
|
||||
void GetSinCos(float x, float y, float& vsin, float& vcos) const;
|
||||
|
||||
[[nodiscard]] bool IsInDist2d(float x, float y, float dist) const
|
||||
@@ -782,6 +771,7 @@ public:
|
||||
ElunaEventProcessor* elunaEvents;
|
||||
#endif
|
||||
|
||||
void GetNearPoint2D(WorldObject const* searcher, float& x, float& y, float distance, float absAngle) const;
|
||||
void GetNearPoint2D(float& x, float& y, float distance, float absAngle) const;
|
||||
void GetNearPoint(WorldObject const* searcher, float& x, float& y, float& z, float searcher_size, float distance2d, float absAngle, float controlZ = 0) const;
|
||||
void GetVoidClosePoint(float& x, float& y, float& z, float size, float distance2d = 0, float relAngle = 0, float controlZ = 0) const;
|
||||
@@ -793,17 +783,14 @@ public:
|
||||
MovePosition(pos, dist, angle);
|
||||
}
|
||||
void MovePositionToFirstCollision(Position& pos, float dist, float angle);
|
||||
Position GetFirstCollisionPosition(float startX, float startY, float startZ, float destX, float destY);
|
||||
Position GetFirstCollisionPosition(float destX, float destY, float destZ);
|
||||
Position GetFirstCollisionPosition(float dist, float angle);
|
||||
void GetFirstCollisionPosition(Position& pos, float dist, float angle)
|
||||
{
|
||||
GetPosition(&pos);
|
||||
MovePositionToFirstCollision(pos, dist, angle);
|
||||
}
|
||||
void MovePositionToFirstCollisionForTotem(Position& pos, float dist, float angle, bool forGameObject);
|
||||
void GetFirstCollisionPositionForTotem(Position& pos, float dist, float angle, bool forGameObject)
|
||||
{
|
||||
GetPosition(&pos);
|
||||
MovePositionToFirstCollisionForTotem(pos, dist, angle, forGameObject);
|
||||
}
|
||||
void GetRandomNearPosition(Position& pos, float radius)
|
||||
{
|
||||
GetPosition(&pos);
|
||||
@@ -815,12 +802,12 @@ public:
|
||||
|
||||
[[nodiscard]] float GetObjectSize() const
|
||||
{
|
||||
return (m_valuesCount > UNIT_FIELD_COMBATREACH) ? m_floatValues[UNIT_FIELD_COMBATREACH] : DEFAULT_WORLD_OBJECT_SIZE;
|
||||
return (m_valuesCount > UNIT_FIELD_COMBATREACH) ? m_floatValues[UNIT_FIELD_COMBATREACH] : DEFAULT_WORLD_OBJECT_SIZE * GetObjectScale();
|
||||
}
|
||||
|
||||
[[nodiscard]] virtual float GetCombatReach() const { return 0.0f; } // overridden (only) in Unit
|
||||
void UpdateGroundPositionZ(float x, float y, float& z) const;
|
||||
void UpdateAllowedPositionZ(float x, float y, float& z) const;
|
||||
void UpdateAllowedPositionZ(float x, float y, float& z, float* groundZ = nullptr) const;
|
||||
|
||||
void GetRandomPoint(const Position& srcPos, float distance, float& rand_x, float& rand_y, float& rand_z) const;
|
||||
void GetRandomPoint(const Position& srcPos, float distance, Position& pos) const
|
||||
@@ -1057,6 +1044,16 @@ public:
|
||||
[[nodiscard]] virtual float GetStationaryZ() const { return GetPositionZ(); }
|
||||
[[nodiscard]] virtual float GetStationaryO() const { return GetOrientation(); }
|
||||
|
||||
[[nodiscard]] float GetMapWaterOrGroundLevel(float x, float y, float z, float* ground = nullptr) const;
|
||||
[[nodiscard]] float GetMapHeight(float x, float y, float z, bool vmap = true, float distanceToSearch = 50.0f) const; // DEFAULT_HEIGHT_SEARCH in map.h
|
||||
|
||||
[[nodiscard]] float GetFloorZ() const;
|
||||
[[nodiscard]] float GetMinHeightInWater() const;
|
||||
|
||||
[[nodiscard]] virtual float GetCollisionHeight() const { return 0.0f; }
|
||||
[[nodiscard]] virtual float GetCollisionWidth() const { return GetObjectSize(); }
|
||||
[[nodiscard]] virtual float GetCollisionRadius() const { return GetObjectSize() / 2; }
|
||||
|
||||
protected:
|
||||
std::string m_name;
|
||||
bool m_isActive;
|
||||
@@ -1064,6 +1061,8 @@ protected:
|
||||
const bool m_isWorldObject;
|
||||
ZoneScript* m_zoneScript;
|
||||
|
||||
float m_staticFloorZ;
|
||||
|
||||
// transports
|
||||
Transport* m_transport;
|
||||
|
||||
|
||||
@@ -9,6 +9,27 @@
|
||||
|
||||
#include "Define.h"
|
||||
|
||||
#define CONTACT_DISTANCE 0.5f
|
||||
#define INTERACTION_DISTANCE 5.5f
|
||||
#define ATTACK_DISTANCE 5.0f
|
||||
#define MAX_SEARCHER_DISTANCE 150.0f // pussywizard: replace the use of MAX_VISIBILITY_DISTANCE in searchers, because MAX_VISIBILITY_DISTANCE is quite too big for this purpose
|
||||
#define MAX_VISIBILITY_DISTANCE 250.0f // max distance for visible objects, experimental
|
||||
#define VISIBILITY_INC_FOR_GOBJECTS 30.0f // pussywizard
|
||||
#define VISIBILITY_COMPENSATION 15.0f // increase searchers
|
||||
#define SPELL_SEARCHER_COMPENSATION 30.0f // increase searchers size in case we have large npc near cell border
|
||||
#define VISIBILITY_DIST_WINTERGRASP 175.0f
|
||||
#define SIGHT_RANGE_UNIT 50.0f
|
||||
#define DEFAULT_VISIBILITY_DISTANCE 90.0f // default visible distance, 90 yards on continents
|
||||
#define DEFAULT_VISIBILITY_INSTANCE 120.0f // default visible distance in instances, 120 yards
|
||||
#define DEFAULT_VISIBILITY_BGARENAS 150.0f // default visible distance in BG/Arenas, 150 yards
|
||||
|
||||
#define DEFAULT_WORLD_OBJECT_SIZE 0.388999998569489f // player size, also currently used (correctly?) for any non Unit world objects
|
||||
#define DEFAULT_COMBAT_REACH 1.5f
|
||||
#define MIN_MELEE_REACH 2.0f
|
||||
#define NOMINAL_MELEE_RANGE 5.0f
|
||||
#define MELEE_RANGE (NOMINAL_MELEE_RANGE - MIN_MELEE_REACH * 2) //center to center for players
|
||||
#define DEFAULT_COLLISION_HEIGHT 2.03128f // Most common value in dbc
|
||||
|
||||
enum HighGuid
|
||||
{
|
||||
HIGHGUID_ITEM = 0x4000, // blizz 4000
|
||||
|
||||
@@ -140,7 +140,7 @@ public:
|
||||
|
||||
uint8 GetMaxTalentPointsForLevel(uint8 level);
|
||||
uint8 GetFreeTalentPoints() { return GetByteValue(UNIT_FIELD_BYTES_1, 1); }
|
||||
void SetFreeTalentPoints(uint8 points) { SetByteValue(UNIT_FIELD_BYTES_1, 1, points); }
|
||||
void SetFreeTalentPoints(uint8 points) { SetByteValue(UNIT_FIELD_BYTES_1, UNIT_BYTES_1_OFFSET_PET_TALENTS, points); }
|
||||
|
||||
uint32 m_usedTalentCount;
|
||||
|
||||
|
||||
@@ -5264,7 +5264,7 @@ void Player::BuildPlayerRepop()
|
||||
StopMirrorTimers(); //disable timers(bars)
|
||||
|
||||
// set and clear other
|
||||
SetByteValue(UNIT_FIELD_BYTES_1, 3, UNIT_BYTE1_FLAG_ALWAYS_STAND);
|
||||
SetByteValue(UNIT_FIELD_BYTES_1, UNIT_BYTES_1_OFFSET_ANIM_TIER, UNIT_BYTE1_FLAG_ALWAYS_STAND);
|
||||
|
||||
sScriptMgr->OnPlayerReleasedGhost(this);
|
||||
}
|
||||
@@ -5281,7 +5281,7 @@ void Player::ResurrectPlayer(float restore_percent, bool applySickness)
|
||||
// speed change, land walk
|
||||
|
||||
// remove death flag + set aura
|
||||
SetByteValue(UNIT_FIELD_BYTES_1, 3, 0x00);
|
||||
SetByteValue(UNIT_FIELD_BYTES_1, UNIT_BYTES_1_OFFSET_ANIM_TIER, UNIT_BYTE1_FLAG_GROUND);
|
||||
RemoveAurasDueToSpell(20584); // speed bonuses
|
||||
RemoveAurasDueToSpell(8326); // SPELL_AURA_GHOST
|
||||
|
||||
|
||||
@@ -2559,40 +2559,7 @@ public:
|
||||
bool SetHover(bool enable, bool packetOnly = false) override;
|
||||
|
||||
[[nodiscard]] bool CanFly() const override { return m_movementInfo.HasMovementFlag(MOVEMENTFLAG_CAN_FLY); }
|
||||
|
||||
//! Return collision height sent to client
|
||||
float GetCollisionHeight(bool mounted)
|
||||
{
|
||||
if (mounted)
|
||||
{
|
||||
CreatureDisplayInfoEntry const* mountDisplayInfo = sCreatureDisplayInfoStore.LookupEntry(GetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID));
|
||||
if (!mountDisplayInfo)
|
||||
return GetCollisionHeight(false);
|
||||
|
||||
CreatureModelDataEntry const* mountModelData = sCreatureModelDataStore.LookupEntry(mountDisplayInfo->ModelId);
|
||||
if (!mountModelData)
|
||||
return GetCollisionHeight(false);
|
||||
|
||||
CreatureDisplayInfoEntry const* displayInfo = sCreatureDisplayInfoStore.LookupEntry(GetNativeDisplayId());
|
||||
ASSERT(displayInfo);
|
||||
CreatureModelDataEntry const* modelData = sCreatureModelDataStore.LookupEntry(displayInfo->ModelId);
|
||||
ASSERT(modelData);
|
||||
|
||||
float scaleMod = GetFloatValue(OBJECT_FIELD_SCALE_X); // 99% sure about this
|
||||
|
||||
return scaleMod * mountModelData->MountHeight + modelData->CollisionHeight * 0.5f;
|
||||
}
|
||||
else
|
||||
{
|
||||
//! Dismounting case - use basic default model data
|
||||
CreatureDisplayInfoEntry const* displayInfo = sCreatureDisplayInfoStore.LookupEntry(GetNativeDisplayId());
|
||||
ASSERT(displayInfo);
|
||||
CreatureModelDataEntry const* modelData = sCreatureModelDataStore.LookupEntry(displayInfo->ModelId);
|
||||
ASSERT(modelData);
|
||||
|
||||
return modelData->CollisionHeight;
|
||||
}
|
||||
}
|
||||
[[nodiscard]] bool CanEnterWater() const override { return true; }
|
||||
|
||||
// OURS
|
||||
// saving
|
||||
|
||||
@@ -153,9 +153,28 @@ ProcEventInfo::ProcEventInfo(Unit* actor, Unit* actionTarget, Unit* procTarget,
|
||||
#pragma warning(disable:4355)
|
||||
#endif
|
||||
Unit::Unit(bool isWorldObject) : WorldObject(isWorldObject),
|
||||
m_movedByPlayer(nullptr), m_lastSanctuaryTime(0), IsAIEnabled(false), NeedChangeAI(false),
|
||||
m_ControlledByPlayer(false), m_CreatedByPlayer(false), movespline(new Movement::MoveSpline()), i_AI(nullptr), i_disabledAI(nullptr), m_realRace(0), m_race(0), m_AutoRepeatFirstCast(false), m_procDeep(0), m_removedAurasCount(0),
|
||||
i_motionMaster(new MotionMaster(this)), m_regenTimer(0), m_ThreatManager(this), m_vehicle(nullptr), m_vehicleKit(nullptr), m_unitTypeMask(UNIT_MASK_NONE), m_HostileRefManager(this)
|
||||
m_movedByPlayer(nullptr),
|
||||
m_lastSanctuaryTime(0),
|
||||
IsAIEnabled(false),
|
||||
NeedChangeAI(false),
|
||||
m_ControlledByPlayer(false),
|
||||
m_CreatedByPlayer(false),
|
||||
movespline(new Movement::MoveSpline()),
|
||||
i_AI(nullptr),
|
||||
i_disabledAI(nullptr),
|
||||
m_realRace(0),
|
||||
m_race(0),
|
||||
m_AutoRepeatFirstCast(false),
|
||||
m_procDeep(0),
|
||||
m_removedAurasCount(0),
|
||||
i_motionMaster(new MotionMaster(this)),
|
||||
m_regenTimer(0),
|
||||
m_ThreatManager(this),
|
||||
m_vehicle(nullptr),
|
||||
m_vehicleKit(nullptr),
|
||||
m_unitTypeMask(UNIT_MASK_NONE),
|
||||
m_HostileRefManager(this),
|
||||
m_comboTarget(nullptr)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(default:4355)
|
||||
@@ -246,7 +265,6 @@ Unit::Unit(bool isWorldObject) : WorldObject(isWorldObject),
|
||||
|
||||
m_serverSideVisibility.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_ALIVE);
|
||||
|
||||
m_mmapNotAcceptableStartTime = 0;
|
||||
m_last_notify_position.Relocate(-5000.0f, -5000.0f, -5000.0f, 0.0f);
|
||||
m_last_notify_mstime = 0;
|
||||
m_delayed_unit_relocation_timer = 0;
|
||||
@@ -445,7 +463,7 @@ void Unit::SendMonsterMove(float NewPosX, float NewPosY, float NewPosZ, uint32 T
|
||||
data.append(GetPackGUID());
|
||||
|
||||
data << uint8(0); // new in 3.1
|
||||
data << GetPositionX() << GetPositionY() << GetPositionZ() + GetHoverHeight();
|
||||
data << GetPositionX() << GetPositionY() << GetPositionZ();
|
||||
data << World::GetGameTimeMS();
|
||||
data << uint8(0);
|
||||
data << uint32(sf);
|
||||
@@ -571,12 +589,32 @@ bool Unit::IsWithinMeleeRange(const Unit* obj, float dist) const
|
||||
float dz = GetPositionZ() - obj->GetPositionZ();
|
||||
float distsq = dx * dx + dy * dy + dz * dz;
|
||||
|
||||
float sizefactor = GetMeleeReach() + obj->GetMeleeReach();
|
||||
float maxdist = dist + sizefactor;
|
||||
float maxdist = dist + GetMeleeRange(obj);
|
||||
|
||||
return distsq < maxdist * maxdist;
|
||||
}
|
||||
|
||||
float Unit::GetMeleeRange(Unit const* target) const
|
||||
{
|
||||
float range = GetCombatReach() + target->GetCombatReach() + 4.0f / 3.0f;
|
||||
return std::max(range, NOMINAL_MELEE_RANGE);
|
||||
}
|
||||
|
||||
bool Unit::IsWithinRange(Unit const* obj, float dist) const
|
||||
{
|
||||
if (!obj || !IsInMap(obj) || !InSamePhase(obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto dx = GetPositionX() - obj->GetPositionX();
|
||||
auto dy = GetPositionY() - obj->GetPositionY();
|
||||
auto dz = GetPositionZ() - obj->GetPositionZ();
|
||||
auto distsq = dx * dx + dy * dy + dz * dz;
|
||||
|
||||
return distsq <= dist * dist;
|
||||
}
|
||||
|
||||
bool Unit::GetRandomContactPoint(const Unit* obj, float& x, float& y, float& z, bool force) const
|
||||
{
|
||||
float combat_reach = GetCombatReach();
|
||||
@@ -595,14 +633,14 @@ bool Unit::GetRandomContactPoint(const Unit* obj, float& x, float& y, float& z,
|
||||
GetAngle(obj) + (attacker_number ? (static_cast<float>(M_PI / 2) - static_cast<float>(M_PI) * (float)rand_norm()) * float(attacker_number) / combat_reach * 0.3f : 0));
|
||||
|
||||
// pussywizard
|
||||
if (fabs(this->GetPositionZ() - z) > 3.0f || !IsWithinLOS(x, y, z))
|
||||
if (fabs(this->GetPositionZ() - z) > this->GetCollisionHeight() || !IsWithinLOS(x, y, z))
|
||||
{
|
||||
x = this->GetPositionX();
|
||||
y = this->GetPositionY();
|
||||
z = this->GetPositionZ();
|
||||
obj->UpdateAllowedPositionZ(x, y, z);
|
||||
}
|
||||
float maxDist = MELEE_RANGE + GetMeleeReach() + obj->GetMeleeReach();
|
||||
float maxDist = GetMeleeRange(obj);
|
||||
if (GetExactDistSq(x, y, z) >= maxDist * maxDist)
|
||||
{
|
||||
if (force)
|
||||
@@ -2141,7 +2179,7 @@ void Unit::CalcHealAbsorb(Unit const* victim, const SpellInfo* healSpell, uint32
|
||||
healAmount = RemainingHeal;
|
||||
}
|
||||
|
||||
void Unit::AttackerStateUpdate (Unit* victim, WeaponAttackType attType, bool extra)
|
||||
void Unit::AttackerStateUpdate(Unit* victim, WeaponAttackType attType, bool extra)
|
||||
{
|
||||
if (HasUnitState(UNIT_STATE_CANNOT_AUTOATTACK) || HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED))
|
||||
return;
|
||||
@@ -2188,6 +2226,95 @@ void Unit::AttackerStateUpdate (Unit* victim, WeaponAttackType attType, bool ext
|
||||
}
|
||||
}
|
||||
|
||||
Position* Unit::GetMeleeAttackPoint(Unit* attacker)
|
||||
{
|
||||
if (!attacker)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AttackerSet attackers = getAttackers();
|
||||
|
||||
if (attackers.size() <= 1) // if the attackers are not more than one
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
float meleeReach = GetExactDist2d(attacker);
|
||||
if (meleeReach <= 0)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
float minAngle = 0;
|
||||
Unit *refUnit = nullptr;
|
||||
uint32 validAttackers = 0;
|
||||
|
||||
double attackerSize = attacker->GetCollisionRadius();
|
||||
|
||||
for (const auto& otherAttacker: attackers)
|
||||
{
|
||||
// if the otherAttacker is not valid, skip
|
||||
if (!otherAttacker ||
|
||||
otherAttacker->GetGUID() == attacker->GetGUID() ||
|
||||
!otherAttacker->IsWithinMeleeRange(this) ||
|
||||
otherAttacker->isMoving()
|
||||
)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float curretAngle = atan(attacker->GetExactDist2d(otherAttacker) / meleeReach);
|
||||
|
||||
if (minAngle == 0 || curretAngle < minAngle)
|
||||
{
|
||||
minAngle = curretAngle;
|
||||
refUnit = otherAttacker;
|
||||
}
|
||||
|
||||
validAttackers++;
|
||||
}
|
||||
|
||||
if (!validAttackers || !refUnit)
|
||||
return nullptr;
|
||||
|
||||
float contactDist = attackerSize + refUnit->GetCollisionRadius();
|
||||
float requiredAngle = atan(contactDist / meleeReach);
|
||||
float attackersAngle = atan(attacker->GetExactDist2d(refUnit) / meleeReach);
|
||||
|
||||
// in instance: the more attacker there are, the higher will be the tollerance
|
||||
// outside: creatures should not intersecate
|
||||
float angleTollerance = attacker->GetMap()->IsDungeon() ? requiredAngle - requiredAngle * tanh(validAttackers / 5.0f) : requiredAngle;
|
||||
|
||||
if (attackersAngle > angleTollerance)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
double angle = atan(contactDist / meleeReach);
|
||||
|
||||
float angularRadius = frand(0.1f, 0.3f) + angle;
|
||||
int8 direction = (urand(0, 1) ? -1 : 1);
|
||||
float currentAngle = GetAngle(refUnit);
|
||||
float absAngle = currentAngle + angularRadius * direction;
|
||||
|
||||
float x, y, z;
|
||||
float distance = meleeReach - GetObjectSize();
|
||||
GetNearPoint(attacker, x, y, z, distance, 0.0f, absAngle);
|
||||
|
||||
if (!GetMap()->CanReachPositionAndGetValidCoords(this, x, y, z, true, true))
|
||||
{
|
||||
GetNearPoint(attacker, x, y, z, distance, 0.0f, absAngle * -1); // try the other side
|
||||
|
||||
if (!GetMap()->CanReachPositionAndGetValidCoords(this, x, y, z, true, true))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return new Position(x,y,z);
|
||||
}
|
||||
|
||||
void Unit::HandleProcExtraAttackFor(Unit* victim)
|
||||
{
|
||||
while (m_extraAttacks)
|
||||
@@ -3514,7 +3641,7 @@ bool Unit::isInAccessiblePlaceFor(Creature const* c) const
|
||||
}
|
||||
|
||||
if (IsInWater())
|
||||
return IsUnderWater() ? c->CanSwim() : (c->CanSwim() || c->CanFly());
|
||||
return IsUnderWater() ? c->CanEnterWater() : (c->CanEnterWater() || c->CanFly());
|
||||
else
|
||||
return c->CanWalk() || c->CanFly() || (c->CanSwim() && IsInWater(true));
|
||||
}
|
||||
@@ -3534,33 +3661,38 @@ void Unit::UpdateEnvironmentIfNeeded(const uint8 option)
|
||||
return;
|
||||
}
|
||||
|
||||
if (option <= 1 && GetExactDistSq(&m_last_environment_position) < 2.5f * 2.5f)
|
||||
// run environment checks everytime the unit moves
|
||||
// more than it's average radius
|
||||
// TODO: find better solution here
|
||||
float radiusWidth = GetCollisionRadius();
|
||||
float radiusHeight = GetCollisionHeight() / 2;
|
||||
float radiusAvg = (radiusWidth + radiusHeight) / 2;
|
||||
if (option <= 1 && GetExactDistSq(&m_last_environment_position) < radiusAvg*radiusAvg)
|
||||
return;
|
||||
|
||||
m_last_environment_position.Relocate(GetPositionX(), GetPositionY(), GetPositionZ());
|
||||
m_staticFloorZ = GetMap()->GetHeight(GetPhaseMask(), GetPositionX(), GetPositionY(), GetPositionZ());
|
||||
|
||||
m_is_updating_environment = true;
|
||||
|
||||
bool changed = false;
|
||||
Creature* c = this->ToCreature();
|
||||
Map* baseMap = const_cast<Map*>(GetBaseMap());
|
||||
Creature* c = this->ToCreature();
|
||||
if (!c || !baseMap)
|
||||
{
|
||||
m_is_updating_environment = false;
|
||||
return;
|
||||
}
|
||||
|
||||
bool canChangeFlying = option == 3 || ((c->GetScriptId() == 0 || GetInstanceId() == 0) && GetMotionMaster()->GetMotionSlotType(MOTION_SLOT_CONTROLLED) == NULL_MOTION_TYPE);
|
||||
bool canChangeFlying = option == 3 || GetMotionMaster()->GetCurrentMovementGeneratorType() != WAYPOINT_MOTION_TYPE;
|
||||
bool canFallGround = option == 0 && canChangeFlying && GetInstanceId() == 0 && !IsInCombat() && !GetVehicle() && !GetTransport() && !HasUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT) && !c->IsTrigger() && !c->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE) && GetMotionMaster()->GetCurrentMovementGeneratorType() <= RANDOM_MOTION_TYPE && !HasUnitState(UNIT_STATE_EVADE) && !IsControlledByPlayer();
|
||||
float x = GetPositionX(), y = GetPositionY(), z = GetPositionZ();
|
||||
bool isInAir = true;
|
||||
float ground_z = z;
|
||||
LiquidData liquidData;
|
||||
liquidData.level = INVALID_HEIGHT;
|
||||
|
||||
ZLiquidStatus liquidStatus = baseMap->getLiquidStatus(x, y, z, MAP_ALL_LIQUIDS, &liquidData);
|
||||
|
||||
// IsInWater
|
||||
bool enoughWater = (liquidData.level > INVALID_HEIGHT && liquidData.level > liquidData.depth_level && liquidData.level - liquidData.depth_level >= 1.5f); // also check if theres enough water - at least 2yd
|
||||
bool enoughWater = baseMap->HasEnoughWater(this, liquidData);
|
||||
m_last_isinwater_status = (liquidStatus & (LIQUID_MAP_IN_WATER | LIQUID_MAP_UNDER_WATER)) && enoughWater;
|
||||
m_last_islittleabovewater_status = (liquidData.level > INVALID_HEIGHT && liquidData.level > liquidData.depth_level && liquidData.level <= z + 3.0f && liquidData.level > z - 1.0f);
|
||||
|
||||
@@ -3615,12 +3747,12 @@ void Unit::UpdateEnvironmentIfNeeded(const uint8 option)
|
||||
// Refresh being in water
|
||||
if (m_last_isinwater_status)
|
||||
{
|
||||
if (!c->CanFly() || z < liquidData.level - 2.0f)
|
||||
if (!c->CanFly() || enoughWater)
|
||||
{
|
||||
if (!HasUnitState(UNIT_STATE_NO_ENVIRONMENT_UPD) && c->CanSwim() && (!HasUnitMovementFlag(MOVEMENTFLAG_SWIMMING) || !HasUnitMovementFlag(MOVEMENTFLAG_DISABLE_GRAVITY)))
|
||||
{
|
||||
SetSwim(true);
|
||||
SetDisableGravity(true);
|
||||
// SetDisableGravity(true);
|
||||
changed = true;
|
||||
}
|
||||
isInAir = false;
|
||||
@@ -3648,11 +3780,12 @@ void Unit::UpdateEnvironmentIfNeeded(const uint8 option)
|
||||
{
|
||||
if (GetMap()->GetGrid(x, y))
|
||||
{
|
||||
float temp = GetMap()->GetHeight(GetPhaseMask(), x, y, z, true, 100.0f);
|
||||
float temp = GetFloorZ();
|
||||
if (temp > INVALID_HEIGHT)
|
||||
{
|
||||
ground_z = (c->CanSwim() && liquidData.level > INVALID_HEIGHT) ? liquidData.level : temp;
|
||||
isInAir = flyingBarelyInWater || G3D::fuzzyGt(z, ground_z + 0.75f) || G3D::fuzzyLt(z, ground_z - 0.5f);
|
||||
bool canHover = c->CanHover();
|
||||
isInAir = flyingBarelyInWater || (G3D::fuzzyGt(GetPositionZ(), ground_z + (canHover ? GetFloatValue(UNIT_FIELD_HOVERHEIGHT) : 0.0f) + GROUND_HEIGHT_TOLERANCE) || G3D::fuzzyLt(GetPositionZ(), ground_z - GROUND_HEIGHT_TOLERANCE)); // Can be underground too, prevent the falling
|
||||
}
|
||||
else
|
||||
isInAir = true;
|
||||
@@ -3685,24 +3818,26 @@ void Unit::UpdateEnvironmentIfNeeded(const uint8 option)
|
||||
}
|
||||
else if (c->CanFly() && isInAir)
|
||||
{
|
||||
if (!c->IsFalling() && (!HasUnitMovementFlag(MOVEMENTFLAG_CAN_FLY) || !HasUnitMovementFlag(MOVEMENTFLAG_DISABLE_GRAVITY) /*|| !HasUnitMovementFlag(MOVEMENTFLAG_HOVER)*/))
|
||||
if (!c->IsFalling() && (!HasUnitMovementFlag(MOVEMENTFLAG_CAN_FLY) || !HasUnitMovementFlag(MOVEMENTFLAG_DISABLE_GRAVITY) || !HasUnitMovementFlag(MOVEMENTFLAG_HOVER)))
|
||||
{
|
||||
SetCanFly(true);
|
||||
SetDisableGravity(true);
|
||||
//SetHover(true);
|
||||
if (IsAlive() && (c->CanHover() || HasAuraType(SPELL_AURA_HOVER)))
|
||||
SetHover(true);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (HasUnitMovementFlag(MOVEMENTFLAG_CAN_FLY) || HasUnitMovementFlag(MOVEMENTFLAG_FLYING) /*|| HasUnitMovementFlag(MOVEMENTFLAG_HOVER)*/)
|
||||
if (HasUnitMovementFlag(MOVEMENTFLAG_CAN_FLY) || HasUnitMovementFlag(MOVEMENTFLAG_FLYING) || HasUnitMovementFlag(MOVEMENTFLAG_HOVER))
|
||||
{
|
||||
SetCanFly(false);
|
||||
RemoveUnitMovementFlag(MOVEMENTFLAG_FLYING);
|
||||
//SetHover(false);
|
||||
if (!HasAuraType(SPELL_AURA_HOVER))
|
||||
SetHover(false);
|
||||
changed = true;
|
||||
}
|
||||
if (HasUnitMovementFlag(MOVEMENTFLAG_DISABLE_GRAVITY) && !HasUnitMovementFlag(MOVEMENTFLAG_SWIMMING) /*&& !HasUnitMovementFlag(MOVEMENTFLAG_HOVER)*/)
|
||||
if (HasUnitMovementFlag(MOVEMENTFLAG_DISABLE_GRAVITY) && !HasUnitMovementFlag(MOVEMENTFLAG_SWIMMING) && !HasUnitMovementFlag(MOVEMENTFLAG_HOVER))
|
||||
{
|
||||
SetDisableGravity(false);
|
||||
changed = true;
|
||||
@@ -9570,6 +9705,13 @@ bool Unit::Attack(Unit* victim, bool meleeAttack)
|
||||
if (GetTypeId() == TYPEID_PLAYER && IsMounted())
|
||||
return false;
|
||||
|
||||
// creatures cannot attack while evading
|
||||
Creature* creature = ToCreature();
|
||||
if (creature && creature->IsInEvadeMode())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED)) // pussywizard: wtf? why having this flag prevents from entering combat? it should just prevent melee attack
|
||||
// return false;
|
||||
|
||||
@@ -9638,7 +9780,7 @@ bool Unit::Attack(Unit* victim, bool meleeAttack)
|
||||
//if (GetTypeId() == TYPEID_UNIT)
|
||||
// ToCreature()->SetCombatStartPosition(GetPositionX(), GetPositionY(), GetPositionZ());
|
||||
|
||||
if (GetTypeId() == TYPEID_UNIT && !IsPet())
|
||||
if (creature && !IsPet())
|
||||
{
|
||||
// should not let player enter combat by right clicking target - doesn't helps
|
||||
SetInCombatWith(victim);
|
||||
@@ -9646,8 +9788,8 @@ bool Unit::Attack(Unit* victim, bool meleeAttack)
|
||||
victim->SetInCombatWith(this);
|
||||
AddThreat(victim, 0.0f);
|
||||
|
||||
ToCreature()->SendAIReaction(AI_REACTION_HOSTILE);
|
||||
ToCreature()->CallAssistance();
|
||||
creature->SendAIReaction(AI_REACTION_HOSTILE);
|
||||
creature->CallAssistance();
|
||||
}
|
||||
|
||||
// delay offhand weapon attack to next attack time
|
||||
@@ -9659,7 +9801,7 @@ bool Unit::Attack(Unit* victim, bool meleeAttack)
|
||||
|
||||
// Let the pet know we've started attacking someting. Handles melee attacks only
|
||||
// Spells such as auto-shot and others handled in WorldSession::HandleCastSpellOpcode
|
||||
if (this->GetTypeId() == TYPEID_PLAYER && !m_Controlled.empty())
|
||||
if (GetTypeId() == TYPEID_PLAYER && !m_Controlled.empty())
|
||||
for (Unit::ControlSet::iterator itr = m_Controlled.begin(); itr != m_Controlled.end(); ++itr)
|
||||
if (Unit* pet = *itr)
|
||||
if (pet->IsAlive() && pet->GetTypeId() == TYPEID_UNIT)
|
||||
@@ -12546,7 +12688,7 @@ void Unit::Mount(uint32 mount, uint32 VehicleId, uint32 creatureEntry)
|
||||
WorldPacket data(SMSG_MOVE_SET_COLLISION_HGT, GetPackGUID().size() + 4 + 4);
|
||||
data.append(GetPackGUID());
|
||||
data << uint32(sWorld->GetGameTime()); // Packet counter
|
||||
data << player->GetCollisionHeight(true);
|
||||
data << player->GetCollisionHeight();
|
||||
player->GetSession()->SendPacket(&data);
|
||||
}
|
||||
|
||||
@@ -12566,7 +12708,7 @@ void Unit::Dismount()
|
||||
WorldPacket data(SMSG_MOVE_SET_COLLISION_HGT, GetPackGUID().size() + 4 + 4);
|
||||
data.append(GetPackGUID());
|
||||
data << uint32(sWorld->GetGameTime()); // Packet counter
|
||||
data << thisPlayer->GetCollisionHeight(false);
|
||||
data << thisPlayer->GetCollisionHeight();
|
||||
thisPlayer->GetSession()->SendPacket(&data);
|
||||
}
|
||||
|
||||
@@ -12728,7 +12870,6 @@ void Unit::SetInCombatState(bool PvP, Unit* enemy, uint32 duration)
|
||||
|
||||
if (Creature* creature = ToCreature())
|
||||
{
|
||||
creature->m_targetsNotAcceptable.clear();
|
||||
creature->UpdateEnvironmentIfNeeded(2);
|
||||
|
||||
// Set home position at place of engaging combat for escorted creatures
|
||||
@@ -12746,6 +12887,8 @@ void Unit::SetInCombatState(bool PvP, Unit* enemy, uint32 duration)
|
||||
creature->GetFormation()->MemberAttackStart(creature, enemy);
|
||||
}
|
||||
|
||||
creature->RefreshSwimmingFlag();
|
||||
|
||||
if (IsPet())
|
||||
{
|
||||
UpdateSpeed(MOVE_RUN, true);
|
||||
@@ -12880,7 +13023,7 @@ bool Unit::_IsValidAttackTarget(Unit const* target, SpellInfo const* bySpell, Wo
|
||||
return false;
|
||||
}
|
||||
// check flags
|
||||
if (target->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_TAXI_FLIGHT | UNIT_FLAG_NOT_ATTACKABLE_1 | UNIT_FLAG_UNK_16)
|
||||
if (target->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_TAXI_FLIGHT | UNIT_FLAG_NOT_ATTACKABLE_1 | UNIT_FLAG_NON_ATTACKABLE_2)
|
||||
|| (!HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE) && target->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC))
|
||||
|| (!target->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE) && HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC))
|
||||
|| (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE) && target->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PC))
|
||||
@@ -13748,33 +13891,15 @@ Unit* Creature::SelectVictim()
|
||||
|
||||
if (target && _CanDetectFeignDeathOf(target) && CanCreatureAttack(target))
|
||||
{
|
||||
if (m_mmapNotAcceptableStartTime) m_mmapNotAcceptableStartTime = 0; // pussywizard: finding any valid target resets timer
|
||||
SetInFront(target);
|
||||
return target;
|
||||
}
|
||||
|
||||
// pussywizard: if victim is not acceptable only due to mmaps, it may be for example a knockback, wait for a few secs before evading
|
||||
if (!target && !isWorldBoss() && !GetInstanceId() && IsAlive() && (!CanHaveThreatList() || !getThreatManager().isThreatListEmpty()))
|
||||
if (Unit* v = GetVictim())
|
||||
if (isTargetNotAcceptableByMMaps(v->GetGUID(), sWorld->GetGameTime(), v))
|
||||
if (_CanDetectFeignDeathOf(v) && CanCreatureAttack(v))
|
||||
{
|
||||
if (m_mmapNotAcceptableStartTime)
|
||||
{
|
||||
if (sWorld->GetGameTime() <= m_mmapNotAcceptableStartTime + 4)
|
||||
return nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_mmapNotAcceptableStartTime = sWorld->GetGameTime();
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// pussywizard: not sure why it's here
|
||||
// pussywizard: if some npc (not player pet) is attacking us and we can't fight back - don't evade o_O
|
||||
// last case when creature must not go to evade mode:
|
||||
// it in combat but attacker not make any damage and not enter to aggro radius to have record in threat list
|
||||
// Note: creature does not have targeted movement generator but has attacker in this case
|
||||
for (AttackerSet::const_iterator itr = m_attackers.begin(); itr != m_attackers.end(); ++itr)
|
||||
if ((*itr) && !CanCreatureAttack(*itr) && (*itr)->GetTypeId() != TYPEID_PLAYER && !(*itr)->ToCreature()->HasUnitTypeMask(UNIT_MASK_CONTROLABLE_GUARDIAN))
|
||||
if ((*itr) && CanCreatureAttack(*itr) && (*itr)->GetTypeId() != TYPEID_PLAYER && !(*itr)->ToCreature()->HasUnitTypeMask(UNIT_MASK_CONTROLABLE_GUARDIAN))
|
||||
return nullptr;
|
||||
|
||||
if (GetVehicle())
|
||||
@@ -15812,7 +15937,7 @@ bool Unit::IsStandState() const
|
||||
|
||||
void Unit::SetStandState(uint8 state)
|
||||
{
|
||||
SetByteValue(UNIT_FIELD_BYTES_1, 0, state);
|
||||
SetByteValue(UNIT_FIELD_BYTES_1, UNIT_BYTES_1_OFFSET_STAND_STATE, state);
|
||||
|
||||
if (IsStandState())
|
||||
RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_SEATED);
|
||||
@@ -17442,6 +17567,9 @@ bool Unit::SetCharmedBy(Unit* charmer, CharmType type, AuraApplication const* au
|
||||
CombatStop();
|
||||
DeleteThreatList();
|
||||
|
||||
if (Creature* creature = ToCreature())
|
||||
creature->RefreshSwimmingFlag();
|
||||
|
||||
if (GetTypeId() == TYPEID_PLAYER)
|
||||
sScriptMgr->OnPlayerBeingCharmed(ToPlayer(), charmer, _oldFactionId, charmer->getFaction());
|
||||
|
||||
@@ -18634,7 +18762,7 @@ void Unit::_ExitVehicle(Position const* exitPosition)
|
||||
{
|
||||
float x = pos.GetPositionX() + 2.0f * cos(pos.GetOrientation() - M_PI / 2.0f);
|
||||
float y = pos.GetPositionY() + 2.0f * sin(pos.GetOrientation() - M_PI / 2.0f);
|
||||
float z = GetMap()->GetHeight(GetPhaseMask(), x, y, pos.GetPositionZ()) + 0.1f;
|
||||
float z = GetMapHeight(x, y, pos.GetPositionZ());
|
||||
if (z > INVALID_HEIGHT)
|
||||
pos.Relocate(x, y, z);
|
||||
}
|
||||
@@ -18718,15 +18846,12 @@ void Unit::_ExitVehicle(Position const* exitPosition)
|
||||
|
||||
void Unit::BuildMovementPacket(ByteBuffer* data) const
|
||||
{
|
||||
if (GetTypeId() == TYPEID_UNIT && GetHoverHeight() >= 2.0f && !HasUnitMovementFlag(MOVEMENTFLAG_FALLING) && !movespline->isFalling()) // pussywizard: add disable gravity to hover (artifically, not to spoil speed and other things)
|
||||
*data << uint32(GetUnitMovementFlags() | MOVEMENTFLAG_DISABLE_GRAVITY); // movement flags
|
||||
else
|
||||
*data << uint32(GetUnitMovementFlags()); // movement flags
|
||||
*data << uint32(GetUnitMovementFlags()); // movement flags
|
||||
*data << uint16(GetExtraUnitMovementFlags()); // 2.3.0
|
||||
*data << uint32(World::GetGameTimeMS()); // time / counter
|
||||
*data << GetPositionX();
|
||||
*data << GetPositionY();
|
||||
*data << GetPositionZ() + GetHoverHeight();
|
||||
*data << GetPositionZ();
|
||||
*data << GetOrientation();
|
||||
|
||||
// 0x00000200
|
||||
@@ -18776,6 +18901,13 @@ bool Unit::IsFalling() const
|
||||
return m_movementInfo.HasMovementFlag(MOVEMENTFLAG_FALLING | MOVEMENTFLAG_FALLING_FAR) || movespline->isFalling();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief this method checks the current flag of a unit
|
||||
*
|
||||
* These flags can be set within the database or dynamically changed at runtime
|
||||
* UNIT_FLAG_SWIMMING must be updated when a unit enters a swimmable area
|
||||
*
|
||||
*/
|
||||
bool Unit::CanSwim() const
|
||||
{
|
||||
// Mirror client behavior, if this method returns false then client will not use swimming animation and for players will apply gravity as if there was no water
|
||||
@@ -18787,7 +18919,7 @@ bool Unit::CanSwim() const
|
||||
return false;
|
||||
if (IsPet() && HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PET_IN_COMBAT))
|
||||
return true;
|
||||
return HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_RENAME | UNIT_FLAG_UNK_15);
|
||||
return HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_RENAME | UNIT_FLAG_SWIMMING);
|
||||
}
|
||||
|
||||
void Unit::NearTeleportTo(float x, float y, float z, float orientation, bool casting /*= false*/, bool vehicleTeleport /*= false*/, bool withPet /*= false*/, bool removeTransport /*= false*/)
|
||||
@@ -19496,9 +19628,15 @@ bool Unit::SetSwim(bool enable)
|
||||
return false;
|
||||
|
||||
if (enable)
|
||||
{
|
||||
AddUnitMovementFlag(MOVEMENTFLAG_SWIMMING);
|
||||
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SWIMMING);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveUnitMovementFlag(MOVEMENTFLAG_SWIMMING);
|
||||
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SWIMMING);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -19570,13 +19708,23 @@ bool Unit::SetHover(bool enable, bool /*packetOnly = false*/)
|
||||
if (enable == HasUnitMovementFlag(MOVEMENTFLAG_HOVER))
|
||||
return false;
|
||||
|
||||
float hoverHeight = GetFloatValue(UNIT_FIELD_HOVERHEIGHT);
|
||||
|
||||
if (enable)
|
||||
{
|
||||
AddUnitMovementFlag(MOVEMENTFLAG_HOVER);
|
||||
if (hoverHeight && GetPositionZ() - GetFloorZ() < hoverHeight)
|
||||
UpdateHeight(GetPositionZ() + hoverHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveUnitMovementFlag(MOVEMENTFLAG_HOVER);
|
||||
if (hoverHeight && (!isDying() || GetTypeId() != TYPEID_UNIT))
|
||||
{
|
||||
float newZ = std::max<float>(GetFloorZ(), GetPositionZ() - hoverHeight);
|
||||
UpdateAllowedPositionZ(GetPositionX(), GetPositionY(), newZ);
|
||||
UpdateHeight(newZ);
|
||||
}
|
||||
SendMovementFlagUpdate(); // pussywizard: needed for falling after death (instead of falling onto air at hover height)
|
||||
}
|
||||
|
||||
@@ -19835,3 +19983,78 @@ bool Unit::IsInCombatWith(Unit const* who) const
|
||||
// Nothing found, false.
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief this method gets the diameter of a Unit by DB if any value is defined, otherwise it gets the value by the DBC
|
||||
*
|
||||
* If the player is mounted the diameter also takes in consideration the mount size
|
||||
*
|
||||
* @return float The diameter of a unit
|
||||
*/
|
||||
float Unit::GetCollisionWidth() const
|
||||
{
|
||||
if (GetTypeId() == TYPEID_PLAYER)
|
||||
return GetObjectSize();
|
||||
|
||||
float scaleMod = GetObjectScale(); // 99% sure about this
|
||||
float objectSize = GetObjectSize();
|
||||
float defaultSize = DEFAULT_WORLD_OBJECT_SIZE * scaleMod;
|
||||
|
||||
//! Dismounting case - use basic default model data
|
||||
CreatureDisplayInfoEntry const* displayInfo = sCreatureDisplayInfoStore.AssertEntry(GetNativeDisplayId());
|
||||
CreatureModelDataEntry const* modelData = sCreatureModelDataStore.AssertEntry(displayInfo->ModelId);
|
||||
|
||||
if (IsMounted())
|
||||
{
|
||||
if (CreatureDisplayInfoEntry const* mountDisplayInfo = sCreatureDisplayInfoStore.LookupEntry(GetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID)))
|
||||
{
|
||||
if (CreatureModelDataEntry const* mountModelData = sCreatureModelDataStore.LookupEntry(mountDisplayInfo->ModelId))
|
||||
{
|
||||
if (G3D::fuzzyGt(mountModelData->CollisionWidth, modelData->CollisionWidth))
|
||||
modelData = mountModelData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float collisionWidth = scaleMod * modelData->CollisionWidth * modelData->Scale * displayInfo->scale * 2;
|
||||
// if the objectSize is the default value or the creature is mounted and we have a DBC value, then we can retrieve DBC value instead
|
||||
return G3D::fuzzyGt(collisionWidth, 0.0f) && (G3D::fuzzyEq(objectSize,defaultSize) || IsMounted()) ? collisionWidth : objectSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief this method gets the radius of a Unit by DB if any value is defined, otherwise it gets the value by the DBC
|
||||
*
|
||||
* If the player is mounted the radius also takes in consideration the mount size
|
||||
*
|
||||
* @return float The radius of a unit
|
||||
*/
|
||||
float Unit::GetCollisionRadius() const
|
||||
{
|
||||
return GetCollisionWidth() / 2;
|
||||
}
|
||||
|
||||
//! Return collision height sent to client
|
||||
float Unit::GetCollisionHeight() const
|
||||
{
|
||||
float scaleMod = GetObjectScale(); // 99% sure about this
|
||||
float defaultHeight = DEFAULT_WORLD_OBJECT_SIZE * scaleMod;
|
||||
|
||||
CreatureDisplayInfoEntry const* displayInfo = sCreatureDisplayInfoStore.AssertEntry(GetNativeDisplayId());
|
||||
CreatureModelDataEntry const* modelData = sCreatureModelDataStore.AssertEntry(displayInfo->ModelId);
|
||||
float collisionHeight = 0.0f;
|
||||
|
||||
if (IsMounted())
|
||||
{
|
||||
if (CreatureDisplayInfoEntry const* mountDisplayInfo = sCreatureDisplayInfoStore.LookupEntry(GetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID)))
|
||||
{
|
||||
if (CreatureModelDataEntry const* mountModelData = sCreatureModelDataStore.LookupEntry(mountDisplayInfo->ModelId))
|
||||
{
|
||||
collisionHeight = scaleMod * (mountModelData->MountHeight + modelData->CollisionHeight * modelData->Scale * displayInfo->scale * 0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
collisionHeight = scaleMod * modelData->CollisionHeight * modelData->Scale * displayInfo->scale;
|
||||
|
||||
return collisionHeight == 0.0f ? defaultHeight : collisionHeight;
|
||||
}
|
||||
|
||||
@@ -135,6 +135,14 @@ enum SpellFacingFlags
|
||||
#define BASE_MAXDAMAGE 2.0f
|
||||
#define BASE_ATTACK_TIME 2000
|
||||
|
||||
enum UnitBytes1Offsets : uint8
|
||||
{
|
||||
UNIT_BYTES_1_OFFSET_STAND_STATE = 0,
|
||||
UNIT_BYTES_1_OFFSET_PET_TALENTS = 1,
|
||||
UNIT_BYTES_1_OFFSET_VIS_FLAG = 2,
|
||||
UNIT_BYTES_1_OFFSET_ANIM_TIER = 3
|
||||
};
|
||||
|
||||
// byte value (UNIT_FIELD_BYTES_1, 0)
|
||||
enum UnitStandStateType
|
||||
{
|
||||
@@ -164,9 +172,11 @@ enum UnitStandFlags
|
||||
// byte flags value (UNIT_FIELD_BYTES_1, 3)
|
||||
enum UnitBytes1_Flags
|
||||
{
|
||||
UNIT_BYTE1_FLAG_GROUND = 0x00,
|
||||
UNIT_BYTE1_FLAG_ALWAYS_STAND = 0x01,
|
||||
UNIT_BYTE1_FLAG_HOVER = 0x02,
|
||||
UNIT_BYTE1_FLAG_UNK_3 = 0x04,
|
||||
UNIT_BYTE1_FLAG_FLY = 0x03,
|
||||
UNIT_BYTE1_FLAG_SUBMERGED = 0x04,
|
||||
UNIT_BYTE1_FLAG_ALL = 0xFF
|
||||
};
|
||||
|
||||
@@ -586,8 +596,8 @@ enum UnitFlags
|
||||
UNIT_FLAG_PVP = 0x00001000, // changed in 3.0.3
|
||||
UNIT_FLAG_SILENCED = 0x00002000, // silenced, 2.1.1
|
||||
UNIT_FLAG_CANNOT_SWIM = 0x00004000, // 2.0.8
|
||||
UNIT_FLAG_UNK_15 = 0x00008000,
|
||||
UNIT_FLAG_UNK_16 = 0x00010000,
|
||||
UNIT_FLAG_SWIMMING = 0x00008000, // shows swim animation in water
|
||||
UNIT_FLAG_NON_ATTACKABLE_2 = 0x00010000, // removes attackable icon, if on yourself, cannot assist self but can cast TARGET_SELF spells - added by SPELL_AURA_MOD_UNATTACKABLE
|
||||
UNIT_FLAG_PACIFIED = 0x00020000, // 3.0.3 ok
|
||||
UNIT_FLAG_STUNNED = 0x00040000, // 3.0.3 ok
|
||||
UNIT_FLAG_IN_COMBAT = 0x00080000,
|
||||
@@ -602,7 +612,7 @@ enum UnitFlags
|
||||
UNIT_FLAG_UNK_28 = 0x10000000,
|
||||
UNIT_FLAG_UNK_29 = 0x20000000, // used in Feing Death spell
|
||||
UNIT_FLAG_SHEATHE = 0x40000000,
|
||||
UNIT_FLAG_UNK_31 = 0x80000000
|
||||
UNIT_FLAG_IMMUNE = 0x80000000, // Immune to damage
|
||||
};
|
||||
|
||||
// Value masks for UNIT_FIELD_FLAGS_2
|
||||
@@ -1254,6 +1264,26 @@ private:
|
||||
GlobalCooldownMgr _GlobalCooldownMgr;
|
||||
};
|
||||
|
||||
struct AttackPosition {
|
||||
AttackPosition(Position pos) : _pos(pos), _taken(false) {}
|
||||
bool operator==(const int val)
|
||||
{
|
||||
return !val;
|
||||
};
|
||||
int operator=(const int val)
|
||||
{
|
||||
if (!val)
|
||||
{
|
||||
// _pos = NULL;
|
||||
_taken = false;
|
||||
return 0; // NULL
|
||||
}
|
||||
return 0; // NULL
|
||||
};
|
||||
Position _pos;
|
||||
bool _taken;
|
||||
};
|
||||
|
||||
// for clearing special attacks
|
||||
#define REACTIVE_TIMER_START 5000
|
||||
|
||||
@@ -1404,8 +1434,10 @@ public:
|
||||
virtual void SetCanDualWield(bool value) { m_canDualWield = value; }
|
||||
[[nodiscard]] float GetCombatReach() const override { return m_floatValues[UNIT_FIELD_COMBATREACH]; }
|
||||
[[nodiscard]] float GetMeleeReach() const { float reach = m_floatValues[UNIT_FIELD_COMBATREACH]; return reach > MIN_MELEE_REACH ? reach : MIN_MELEE_REACH; }
|
||||
[[nodiscard]] bool IsWithinRange(Unit const* obj, float dist) const;
|
||||
bool IsWithinCombatRange(const Unit* obj, float dist2compare) const;
|
||||
bool IsWithinMeleeRange(const Unit* obj, float dist = MELEE_RANGE) const;
|
||||
bool IsWithinMeleeRange(const Unit* obj, float dist = 0.f) const;
|
||||
float GetMeleeRange(Unit const* target) const;
|
||||
bool GetRandomContactPoint(const Unit* target, float& x, float& y, float& z, bool force = false) const;
|
||||
uint32 m_extraAttacks;
|
||||
bool m_canDualWield;
|
||||
@@ -1433,6 +1465,7 @@ public:
|
||||
bool AttackStop();
|
||||
void RemoveAllAttackers();
|
||||
[[nodiscard]] AttackerSet const& getAttackers() const { return m_attackers; }
|
||||
[[nodiscard]] Position* GetMeleeAttackPoint(Unit* attacker);
|
||||
[[nodiscard]] bool isAttackingPlayer() const;
|
||||
[[nodiscard]] Unit* GetVictim() const { return m_attacking; }
|
||||
|
||||
@@ -1570,8 +1603,8 @@ public:
|
||||
[[nodiscard]] bool IsStandState() const;
|
||||
void SetStandState(uint8 state);
|
||||
|
||||
void SetStandFlags(uint8 flags) { SetByteFlag(UNIT_FIELD_BYTES_1, 2, flags); }
|
||||
void RemoveStandFlags(uint8 flags) { RemoveByteFlag(UNIT_FIELD_BYTES_1, 2, flags); }
|
||||
void SetStandFlags(uint8 flags) { SetByteFlag(UNIT_FIELD_BYTES_1, UNIT_BYTES_1_OFFSET_VIS_FLAG, flags); }
|
||||
void RemoveStandFlags(uint8 flags) { RemoveByteFlag(UNIT_FIELD_BYTES_1, UNIT_BYTES_1_OFFSET_VIS_FLAG, flags); }
|
||||
|
||||
[[nodiscard]] bool IsMounted() const { return HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_MOUNT); }
|
||||
[[nodiscard]] uint32 GetMountID() const { return GetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID); }
|
||||
@@ -1789,8 +1822,6 @@ public:
|
||||
//void SendMonsterMove(float NewPosX, float NewPosY, float NewPosZ, uint8 type, uint32 MovementFlags, uint32 Time, Player* player = nullptr);
|
||||
void SendMovementFlagUpdate(bool self = false);
|
||||
|
||||
[[nodiscard]] bool IsLevitating() const { return m_movementInfo.HasMovementFlag(MOVEMENTFLAG_DISABLE_GRAVITY); }
|
||||
[[nodiscard]] bool IsWalking() const { return m_movementInfo.HasMovementFlag(MOVEMENTFLAG_WALKING); }
|
||||
virtual bool SetWalk(bool enable);
|
||||
virtual bool SetDisableGravity(bool disable, bool packetOnly = false);
|
||||
virtual bool SetSwim(bool enable);
|
||||
@@ -2173,7 +2204,7 @@ public:
|
||||
|
||||
uint32 GetDisplayId() { return GetUInt32Value(UNIT_FIELD_DISPLAYID); }
|
||||
virtual void SetDisplayId(uint32 modelId);
|
||||
uint32 GetNativeDisplayId() { return GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID); }
|
||||
[[nodiscard]] uint32 GetNativeDisplayId() const { return GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID); }
|
||||
void RestoreDisplayId();
|
||||
void SetNativeDisplayId(uint32 modelId) { SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID, modelId); }
|
||||
void setTransForm(uint32 spellid) { m_transform = spellid;}
|
||||
@@ -2365,6 +2396,8 @@ public:
|
||||
void BuildMovementPacket(ByteBuffer* data) const;
|
||||
|
||||
[[nodiscard]] virtual bool CanSwim() const;
|
||||
[[nodiscard]] bool IsLevitating() const { return m_movementInfo.HasMovementFlag(MOVEMENTFLAG_DISABLE_GRAVITY); }
|
||||
[[nodiscard]] bool IsWalking() const { return m_movementInfo.HasMovementFlag(MOVEMENTFLAG_WALKING); }
|
||||
[[nodiscard]] bool isMoving() const { return m_movementInfo.HasMovementFlag(MOVEMENTFLAG_MASK_MOVING); }
|
||||
[[nodiscard]] bool isTurning() const { return m_movementInfo.HasMovementFlag(MOVEMENTFLAG_MASK_TURNING); }
|
||||
[[nodiscard]] bool IsHovering() const { return m_movementInfo.HasMovementFlag(MOVEMENTFLAG_HOVER); }
|
||||
@@ -2373,6 +2406,7 @@ public:
|
||||
[[nodiscard]] bool IsFlying() const { return m_movementInfo.HasMovementFlag(MOVEMENTFLAG_FLYING | MOVEMENTFLAG_DISABLE_GRAVITY); }
|
||||
[[nodiscard]] bool IsFalling() const;
|
||||
[[nodiscard]] float GetHoverHeight() const { return IsHovering() ? GetFloatValue(UNIT_FIELD_HOVERHEIGHT) : 0.0f; }
|
||||
[[nodiscard]] virtual bool CanEnterWater() const = 0;
|
||||
|
||||
void RewardRage(uint32 damage, uint32 weaponSpeedHitFactor, bool attacker);
|
||||
|
||||
@@ -2387,11 +2421,6 @@ public:
|
||||
TempSummon* ToTempSummon() { if (IsSummon()) return reinterpret_cast<TempSummon*>(this); else return nullptr; }
|
||||
[[nodiscard]] const TempSummon* ToTempSummon() const { if (IsSummon()) return reinterpret_cast<const TempSummon*>(this); else return nullptr; }
|
||||
|
||||
// pussywizard:
|
||||
// MMaps
|
||||
std::map<uint64, MMapTargetData> m_targetsNotAcceptable;
|
||||
bool isTargetNotAcceptableByMMaps(uint64 guid, uint32 currTime, const Position* t = nullptr) const { std::map<uint64, MMapTargetData>::const_iterator itr = m_targetsNotAcceptable.find(guid); if (itr != m_targetsNotAcceptable.end() && (itr->second._endTime >= currTime || (t && !itr->second.PosChanged(*this, *t)))) return true; return false; }
|
||||
uint32 m_mmapNotAcceptableStartTime;
|
||||
// Safe mover
|
||||
std::set<SafeUnitPointer*> SafeUnitPointerSet;
|
||||
void AddPointedBy(SafeUnitPointer* sup) { SafeUnitPointerSet.insert(sup); }
|
||||
@@ -2450,6 +2479,10 @@ public:
|
||||
// Movement info
|
||||
Movement::MoveSpline* movespline;
|
||||
|
||||
[[nodiscard]] float GetCollisionHeight() const override;
|
||||
[[nodiscard]] float GetCollisionWidth() const override;
|
||||
[[nodiscard]] float GetCollisionRadius() const override;
|
||||
|
||||
protected:
|
||||
explicit Unit (bool isWorldObject);
|
||||
|
||||
@@ -2565,6 +2598,7 @@ private:
|
||||
HostileRefManager m_HostileRefManager;
|
||||
|
||||
FollowerRefManager m_FollowingRefManager;
|
||||
Unit* m_comboTarget;
|
||||
|
||||
ComboPointHolderSet m_ComboPointHolders;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user