Position CalculateCircularMovementPosition() { Position centerPos = GetCircularMovementCenterPosition(); if (centerPos == null) { return(GetPosition()); } AreaTriggerCircularMovementInfo cmi = _circularMovementInfo.Value; // AreaTrigger make exactly "Duration / TimeToTarget" loops during his life time float pathProgress = (float)cmi.ElapsedTimeForMovement / cmi.TimeToTarget; // We already made one circle and can't loop if (!cmi.CanLoop) { pathProgress = Math.Min(1.0f, pathProgress); } float radius = cmi.Radius; if (MathFunctions.fuzzyNe(cmi.BlendFromRadius, radius)) { float blendCurve = (cmi.BlendFromRadius - radius) / radius; // 4.f Defines four quarters blendCurve = MathFunctions.RoundToInterval(ref blendCurve, 1.0f, 4.0f) / 4.0f; float blendProgress = Math.Min(1.0f, pathProgress / blendCurve); radius = MathFunctions.lerp(cmi.BlendFromRadius, cmi.Radius, blendProgress); } // Adapt Path progress depending of circle direction if (!cmi.CounterClockwise) { pathProgress *= -1; } float angle = cmi.InitialAngle + 2.0f * (float)Math.PI * pathProgress; float x = centerPos.GetPositionX() + (radius * (float)Math.Cos(angle)); float y = centerPos.GetPositionY() + (radius * (float)Math.Sin(angle)); float z = centerPos.GetPositionZ() + cmi.ZOffset; return(new Position(x, y, z, angle)); }
void InitCircularMovement(AreaTriggerCircularMovementInfo cmi, uint timeToTarget) { // Circular movement requires either a center position or an attached unit Cypher.Assert(cmi.Center.HasValue || cmi.TargetGUID.HasValue); // should be sent in object create packets only updateValues[(int)AreaTriggerFields.TimeToTarget].UnsignedValue = timeToTarget; _circularMovementInfo.Set(cmi); _circularMovementInfo.Value.TimeToTarget = timeToTarget; _circularMovementInfo.Value.ElapsedTimeForMovement = 0; if (IsInWorld) { AreaTriggerReShape reshape = new AreaTriggerReShape(); reshape.TriggerGUID = GetGUID(); reshape.AreaTriggerCircularMovement = _circularMovementInfo; SendMessageToSet(reshape, true); } }
void InitCircularMovement(AreaTriggerCircularMovementInfo cmi, uint timeToTarget) { // Circular movement requires either a center position or an attached unit Cypher.Assert(cmi.Center.HasValue || cmi.PathTarget.HasValue); // should be sent in object create packets only SetUpdateFieldValue(m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.TimeToTarget), timeToTarget); m_areaTriggerData.ClearChanged(m_areaTriggerData.TimeToTarget); _circularMovementInfo.Set(cmi); _circularMovementInfo.Value.TimeToTarget = timeToTarget; _circularMovementInfo.Value.ElapsedTimeForMovement = 0; if (IsInWorld) { AreaTriggerRePath reshape = new AreaTriggerRePath(); reshape.TriggerGUID = GetGUID(); reshape.AreaTriggerCircularMovement = _circularMovementInfo; SendMessageToSet(reshape, true); } }
bool Create(uint spellMiscId, Unit caster, Unit target, SpellInfo spell, Position pos, int duration, uint spellXSpellVisualId, ObjectGuid castId, AuraEffect aurEff) { _targetGuid = target ? target.GetGUID() : ObjectGuid.Empty; _aurEff = aurEff; SetMap(caster.GetMap()); Relocate(pos); if (!IsPositionValid()) { Log.outError(LogFilter.AreaTrigger, $"AreaTrigger (spell {spell.Id}) not created. Invalid coordinates (X: {GetPositionX()} Y: {GetPositionY()})"); return(false); } _areaTriggerMiscTemplate = Global.AreaTriggerDataStorage.GetAreaTriggerMiscTemplate(spellMiscId); if (_areaTriggerMiscTemplate == null) { Log.outError(LogFilter.AreaTrigger, "AreaTrigger (spellMiscId {0}) not created. Invalid areatrigger miscid ({1})", spellMiscId, spellMiscId); return(false); } _Create(ObjectGuid.Create(HighGuid.AreaTrigger, GetMapId(), GetTemplate().Id, caster.GetMap().GenerateLowGuid(HighGuid.AreaTrigger))); SetEntry(GetTemplate().Id); SetDuration(duration); SetObjectScale(1.0f); SetGuidValue(AreaTriggerFields.Caster, caster.GetGUID()); SetGuidValue(AreaTriggerFields.CreatingEffectGuid, castId); SetUInt32Value(AreaTriggerFields.SpellId, spell.Id); SetUInt32Value(AreaTriggerFields.SpellForVisuals, spell.Id); SetUInt32Value(AreaTriggerFields.SpellXSpellVisualId, spellXSpellVisualId); SetUInt32Value(AreaTriggerFields.TimeToTargetScale, GetMiscTemplate().TimeToTargetScale != 0 ? GetMiscTemplate().TimeToTargetScale : GetUInt32Value(AreaTriggerFields.Duration)); SetFloatValue(AreaTriggerFields.BoundsRadius2d, GetTemplate().MaxSearchRadius); SetUInt32Value(AreaTriggerFields.DecalPropertiesId, GetMiscTemplate().DecalPropertiesId); for (byte scaleCurveIndex = 0; scaleCurveIndex < SharedConst.MaxAreatriggerScale; ++scaleCurveIndex) { if (GetMiscTemplate().ScaleInfo.ExtraScale[scaleCurveIndex].AsInt32 != 0) { SetUInt32Value(AreaTriggerFields.ExtraScaleCurve + scaleCurveIndex, (uint)GetMiscTemplate().ScaleInfo.ExtraScale[scaleCurveIndex].AsInt32); } } PhasingHandler.InheritPhaseShift(this, caster); if (target && GetTemplate().HasFlag(AreaTriggerFlags.HasAttached)) { m_movementInfo.transport.guid = target.GetGUID(); } UpdateShape(); uint timeToTarget = GetMiscTemplate().TimeToTarget != 0 ? GetMiscTemplate().TimeToTarget : GetUInt32Value(AreaTriggerFields.Duration); if (GetTemplate().HasFlag(AreaTriggerFlags.HasCircularMovement)) { AreaTriggerCircularMovementInfo cmi = GetMiscTemplate().CircularMovementInfo; if (target && GetTemplate().HasFlag(AreaTriggerFlags.HasAttached)) { cmi.TargetGUID.Set(target.GetGUID()); } else { cmi.Center.Set(new Vector3(pos.posX, pos.posY, pos.posZ)); } InitCircularMovement(cmi, timeToTarget); } else if (GetMiscTemplate().HasSplines()) { InitSplineOffsets(GetMiscTemplate().SplinePoints, timeToTarget); } // movement on transport of areatriggers on unit is handled by themself Transport transport = m_movementInfo.transport.guid.IsEmpty() ? caster.GetTransport() : null; if (transport) { float x, y, z, o; pos.GetPosition(out x, out y, out z, out o); transport.CalculatePassengerOffset(ref x, ref y, ref z, ref o); m_movementInfo.transport.pos.Relocate(x, y, z, o); // This object must be added to transport before adding to map for the client to properly display it transport.AddPassenger(this); } AI_Initialize(); // Relocate areatriggers with circular movement again if (HasCircularMovement()) { Relocate(CalculateCircularMovementPosition()); } if (!GetMap().AddToMap(this)) { // Returning false will cause the object to be deleted - remove from transport if (transport) { transport.RemovePassenger(this); } return(false); } caster._RegisterAreaTrigger(this); _ai.OnCreate(); return(true); }
unsafe bool Create(uint spellMiscId, Unit caster, Unit target, SpellInfo spell, Position pos, int duration, uint spellXSpellVisualId, ObjectGuid castId, AuraEffect aurEff) { _targetGuid = target ? target.GetGUID() : ObjectGuid.Empty; _aurEff = aurEff; SetMap(caster.GetMap()); Relocate(pos); if (!IsPositionValid()) { Log.outError(LogFilter.AreaTrigger, $"AreaTrigger (spell {spell.Id}) not created. Invalid coordinates (X: {GetPositionX()} Y: {GetPositionY()})"); return(false); } _areaTriggerMiscTemplate = Global.AreaTriggerDataStorage.GetAreaTriggerMiscTemplate(spellMiscId); if (_areaTriggerMiscTemplate == null) { Log.outError(LogFilter.AreaTrigger, "AreaTrigger (spellMiscId {0}) not created. Invalid areatrigger miscid ({1})", spellMiscId, spellMiscId); return(false); } _Create(ObjectGuid.Create(HighGuid.AreaTrigger, GetMapId(), GetTemplate().Id, caster.GetMap().GenerateLowGuid(HighGuid.AreaTrigger))); SetEntry(GetTemplate().Id); SetDuration(duration); SetObjectScale(1.0f); SetUpdateFieldValue(m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.Caster), caster.GetGUID()); SetUpdateFieldValue(m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.CreatingEffectGUID), castId); SetUpdateFieldValue(m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.SpellID), spell.Id); SetUpdateFieldValue(m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.SpellForVisuals), spell.Id); SetUpdateFieldValue(m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.SpellXSpellVisualID), spellXSpellVisualId); SetUpdateFieldValue(m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.TimeToTargetScale), GetMiscTemplate().TimeToTargetScale != 0 ? GetMiscTemplate().TimeToTargetScale : m_areaTriggerData.Duration); SetUpdateFieldValue(m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.BoundsRadius2D), GetTemplate().MaxSearchRadius); SetUpdateFieldValue(m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.DecalPropertiesID), GetMiscTemplate().DecalPropertiesId); ScaleCurve extraScaleCurve = m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.ExtraScaleCurve); if (GetMiscTemplate().ExtraScale.Structured.StartTimeOffset != 0) { SetUpdateFieldValue(extraScaleCurve.ModifyValue(extraScaleCurve.StartTimeOffset), GetMiscTemplate().ExtraScale.Structured.StartTimeOffset); } if (GetMiscTemplate().ExtraScale.Structured.X != 0 || GetMiscTemplate().ExtraScale.Structured.Y != 0) { Vector2 point = new Vector2(GetMiscTemplate().ExtraScale.Structured.X, GetMiscTemplate().ExtraScale.Structured.Y); SetUpdateFieldValue(ref extraScaleCurve.ModifyValue(extraScaleCurve.Points, 0), point); } if (GetMiscTemplate().ExtraScale.Structured.Z != 0 || GetMiscTemplate().ExtraScale.Structured.W != 0) { Vector2 point = new Vector2(GetMiscTemplate().ExtraScale.Structured.Z, GetMiscTemplate().ExtraScale.Structured.W); SetUpdateFieldValue(ref extraScaleCurve.ModifyValue(extraScaleCurve.Points, 1), point); } if (GetMiscTemplate().ExtraScale.Raw.Data[5] != 0) { SetUpdateFieldValue(extraScaleCurve.ModifyValue(extraScaleCurve.ParameterCurve), GetMiscTemplate().ExtraScale.Raw.Data[5]); } if (GetMiscTemplate().ExtraScale.Structured.OverrideActive != 0) { SetUpdateFieldValue(extraScaleCurve.ModifyValue(extraScaleCurve.OverrideActive), GetMiscTemplate().ExtraScale.Structured.OverrideActive != 0 ? true : false); } PhasingHandler.InheritPhaseShift(this, caster); if (target && GetTemplate().HasFlag(AreaTriggerFlags.HasAttached)) { m_movementInfo.transport.guid = target.GetGUID(); } UpdateShape(); uint timeToTarget = GetMiscTemplate().TimeToTarget != 0 ? GetMiscTemplate().TimeToTarget : m_areaTriggerData.Duration; if (GetTemplate().HasFlag(AreaTriggerFlags.HasCircularMovement)) { AreaTriggerCircularMovementInfo cmi = GetMiscTemplate().CircularMovementInfo; if (target && GetTemplate().HasFlag(AreaTriggerFlags.HasAttached)) { cmi.PathTarget.Set(target.GetGUID()); } else { cmi.Center.Set(new Vector3(pos.posX, pos.posY, pos.posZ)); } InitCircularMovement(cmi, timeToTarget); } else if (GetMiscTemplate().HasSplines()) { InitSplineOffsets(GetMiscTemplate().SplinePoints, timeToTarget); } // movement on transport of areatriggers on unit is handled by themself Transport transport = m_movementInfo.transport.guid.IsEmpty() ? caster.GetTransport() : null; if (transport) { float x, y, z, o; pos.GetPosition(out x, out y, out z, out o); transport.CalculatePassengerOffset(ref x, ref y, ref z, ref o); m_movementInfo.transport.pos.Relocate(x, y, z, o); // This object must be added to transport before adding to map for the client to properly display it transport.AddPassenger(this); } AI_Initialize(); // Relocate areatriggers with circular movement again if (HasCircularMovement()) { Relocate(CalculateCircularMovementPosition()); } if (!GetMap().AddToMap(this)) { // Returning false will cause the object to be deleted - remove from transport if (transport) { transport.RemovePassenger(this); } return(false); } caster._RegisterAreaTrigger(this); _ai.OnCreate(); return(true); }