fix(Core/Movement): (#7008)

- Get zone/area IDs from vmap data in the liquid update
- Add new method Map::getFullVMapDataForPosition to get area info and liquid info in a single vmap lookup
- Adjust GetZoneId/GetAreaId on WorldObject to always return these cached fields.
- Clean up liquid state handling on Unit and Player
- Implemented getting area id from gameobject spawns.
- Removed old core related to getting movement flags dependent on environment.
- Movement flags are now processed more precisely and dynamically.

Original source: TrinityCore.

- Closes #5086
- Updates #2208.
This commit is contained in:
UltraNix
2021-08-25 12:41:20 +02:00
committed by GitHub
parent 909c3e5799
commit a8c0a2cc89
47 changed files with 1086 additions and 883 deletions

View File

@@ -268,9 +268,7 @@ void Player::Update(uint32 p_time)
}
uint32 newzone, newarea;
GetZoneAndAreaId(newzone, newarea, true);
m_last_zone_id = newzone;
m_last_area_id = newarea;
GetZoneAndAreaId(newzone, newarea);
if (m_zoneUpdateId != newzone)
UpdateZone(newzone, newarea); // also update area
@@ -354,7 +352,7 @@ void Player::Update(uint32 p_time)
}
// not auto-free ghost from body in instances
if (m_deathTimer > 0 && !GetBaseMap()->Instanceable() &&
if (m_deathTimer > 0 && !GetMap()->Instanceable() &&
!HasAuraType(SPELL_AURA_PREVENT_RESURRECTION))
{
if (p_time >= m_deathTimer)
@@ -1975,96 +1973,6 @@ void Player::UpdateCorpseReclaimDelay()
m_deathExpireTime = now + DEATH_EXPIRE_STEP;
}
void Player::UpdateUnderwaterState(Map* m, float x, float y, float z)
{
// pussywizard: optimization
if (GetExactDistSq(&m_last_underwaterstate_position) < 3.0f * 3.0f)
return;
m_last_underwaterstate_position.Relocate(m_positionX, m_positionY,
m_positionZ);
if (!IsPositionValid()) // pussywizard: crashfix if calculated grid coords
// would be out of range 0-64
return;
LiquidData liquid_status;
ZLiquidStatus res = m->getLiquidStatus(
x, y, z, MAP_ALL_LIQUIDS, &liquid_status, GetCollisionHeight());
if (!res)
{
m_MirrorTimerFlags &= ~(UNDERWATER_INWATER | UNDERWATER_INLAVA |
UNDERWATER_INSLIME | UNDERWARER_INDARKWATER);
if (_lastLiquid && _lastLiquid->SpellId)
RemoveAurasDueToSpell(_lastLiquid->SpellId);
_lastLiquid = nullptr;
return;
}
if (uint32 liqEntry = liquid_status.entry)
{
LiquidTypeEntry const* liquid = sLiquidTypeStore.LookupEntry(liqEntry);
if (_lastLiquid && _lastLiquid->SpellId && _lastLiquid->Id != liqEntry)
RemoveAurasDueToSpell(_lastLiquid->SpellId);
if (liquid && liquid->SpellId)
{
if (res & (LIQUID_MAP_UNDER_WATER | LIQUID_MAP_IN_WATER))
{
if (!HasAura(liquid->SpellId))
CastSpell(this, liquid->SpellId, true);
}
else
RemoveAurasDueToSpell(liquid->SpellId);
}
_lastLiquid = liquid;
}
else if (_lastLiquid && _lastLiquid->SpellId)
{
RemoveAurasDueToSpell(_lastLiquid->SpellId);
_lastLiquid = nullptr;
}
// All liquids type - check under water position
if (liquid_status.type_flags &
(MAP_LIQUID_TYPE_WATER | MAP_LIQUID_TYPE_OCEAN | MAP_LIQUID_TYPE_MAGMA |
MAP_LIQUID_TYPE_SLIME))
{
if (res & LIQUID_MAP_UNDER_WATER)
m_MirrorTimerFlags |= UNDERWATER_INWATER;
else
m_MirrorTimerFlags &= ~UNDERWATER_INWATER;
}
// Allow travel in dark water on taxi or transport
if ((liquid_status.type_flags & MAP_LIQUID_TYPE_DARK_WATER) &&
!IsInFlight() && !GetTransport())
m_MirrorTimerFlags |= UNDERWARER_INDARKWATER;
else
m_MirrorTimerFlags &= ~UNDERWARER_INDARKWATER;
// in lava check, anywhere in lava level
if (liquid_status.type_flags & MAP_LIQUID_TYPE_MAGMA)
{
if (res & (LIQUID_MAP_UNDER_WATER | LIQUID_MAP_IN_WATER |
LIQUID_MAP_WATER_WALK))
m_MirrorTimerFlags |= UNDERWATER_INLAVA;
else
m_MirrorTimerFlags &= ~UNDERWATER_INLAVA;
}
// in slime check, anywhere in slime level
if (liquid_status.type_flags & MAP_LIQUID_TYPE_SLIME)
{
if (res & (LIQUID_MAP_UNDER_WATER | LIQUID_MAP_IN_WATER |
LIQUID_MAP_WATER_WALK))
m_MirrorTimerFlags |= UNDERWATER_INSLIME;
else
m_MirrorTimerFlags &= ~UNDERWATER_INSLIME;
}
}
void Player::UpdateCharmedAI()
{
// Xinef: maybe passed as argument?
@@ -2361,3 +2269,58 @@ void Player::SendUpdateWorldState(uint32 Field, uint32 Value)
data << Value;
GetSession()->SendPacket(&data);
}
void Player::ProcessTerrainStatusUpdate()
{
// process liquid auras using generic unit code
Unit::ProcessTerrainStatusUpdate();
LiquidData const& liquidData = GetLiquidData();
// player specific logic for mirror timers
if (liquidData.Status != LIQUID_MAP_NO_WATER)
{
// Breath bar state (under water in any liquid type)
if ((liquidData.Flags & MAP_ALL_LIQUIDS) != 0)
{
if ((liquidData.Status & LIQUID_MAP_UNDER_WATER) != 0)
m_MirrorTimerFlags |= UNDERWATER_INWATER;
else
m_MirrorTimerFlags &= ~UNDERWATER_INWATER;
}
// Fatigue bar state (if not on flight path or transport)
if ((liquidData.Flags & MAP_LIQUID_TYPE_DARK_WATER) && !IsInFlight() && !GetTransport())
{
// Exclude also uncontrollable vehicles
Vehicle* vehicle = GetVehicle();
VehicleSeatEntry const* vehicleSeat = vehicle ? vehicle->GetSeatForPassenger(this) : nullptr;
if (!vehicleSeat || vehicleSeat->CanControl())
m_MirrorTimerFlags |= UNDERWATER_INDARKWATER;
else
m_MirrorTimerFlags &= ~UNDERWATER_INDARKWATER;
}
else
m_MirrorTimerFlags &= ~UNDERWATER_INDARKWATER;
// Lava state (any contact)
if (liquidData.Flags & MAP_LIQUID_TYPE_MAGMA)
{
if (liquidData.Status & MAP_LIQUID_STATUS_IN_CONTACT)
m_MirrorTimerFlags |= UNDERWATER_INLAVA;
else
m_MirrorTimerFlags &= ~UNDERWATER_INLAVA;
}
// Slime state (any contact)
if (liquidData.Flags & MAP_LIQUID_TYPE_SLIME)
{
if (liquidData.Status & MAP_LIQUID_STATUS_IN_CONTACT)
m_MirrorTimerFlags |= UNDERWATER_INSLIME;
else
m_MirrorTimerFlags &= ~UNDERWATER_INSLIME;
}
}
else
m_MirrorTimerFlags &= ~(UNDERWATER_INWATER | UNDERWATER_INLAVA | UNDERWATER_INSLIME | UNDERWATER_INDARKWATER);
}