Attempt on converting updatewaterstate for use with units (pets and vehicles)

This commit is contained in:
Kandera
2012-03-29 13:14:21 -04:00
parent 413cfac953
commit bb97ff7601
4 changed files with 50 additions and 5 deletions

View File

@@ -3089,6 +3089,48 @@ bool Unit::IsUnderWater() const
return GetBaseMap()->IsUnderWater(GetPositionX(), GetPositionY(), GetPositionZ());
}
void Unit::UpdateUnderwaterState(Map* m, float x, float y, float z)
{
if (!isPet() && !IsVehicle())
return;
LiquidData liquid_status;
ZLiquidStatus res = m->getLiquidStatus(x, y, z, MAP_ALL_LIQUIDS, &liquid_status);
if (!res)
{
if (_lastLiquid && _lastLiquid->SpellId)
RemoveAurasDueToSpell(_lastLiquid->SpellId);
RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_UNDERWATER);
_lastLiquid = NULL;
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))
CastSpell(this, liquid->SpellId, true);
else
RemoveAurasDueToSpell(liquid->SpellId);
}
RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_ABOVEWATER);
_lastLiquid = liquid;
}
else if (_lastLiquid && _lastLiquid->SpellId)
{
RemoveAurasDueToSpell(_lastLiquid->SpellId);
RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_UNDERWATER);
_lastLiquid = NULL;
}
}
void Unit::DeMorph()
{
SetDisplayId(GetNativeDisplayId());
@@ -17255,6 +17297,9 @@ bool Unit::UpdatePosition(float x, float y, float z, float orientation, bool tel
else if (turn)
UpdateOrientation(orientation);
// code block for underwater state update
UpdateUnderwaterState(GetMap(), x, y, z);
return (relocated || turn);
}