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); }
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 {0}) not created. Invalid coordinates (X: {0} Y: {1})", spell.Id, GetPositionX(), 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(); if (GetMiscTemplate().HasSplines()) { uint timeToTarget = GetMiscTemplate().TimeToTarget != 0 ? GetMiscTemplate().TimeToTarget : GetUInt32Value(AreaTriggerFields.Duration); 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(); 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); }