﻿// Decompiled with JetBrains decompiler
// Type: Shake
// Assembly: Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 19851F1B-4780-4223-BA01-2C20F2CD781E
// Assembly location: C:\Users\CGA Computer\Desktop\LEGO Universe Stuff\LOCO Server\Unity Web Player Extractor\Saved Files\LOCO Server.unity3d_unpacked\Assembly-CSharp.dll

using UnityEngine;

public class Shake : EZAnimation
{
  protected const float PIx2 = 6.283185f;
  protected Vector3 start;
  protected Vector3 magnitude;
  protected float oscillations;
  protected GameObject subject;
  protected Transform subTrans;
  protected Vector3 temp;
  protected float factor;

  public Shake()
  {
    this.type = EZAnimation.ANIM_TYPE.Shake;
    this.pingPong = false;
  }

  public override object GetSubject()
  {
    return (object) this.subject;
  }

  public override void _end()
  {
    if (Object.op_Inequality((Object) this.subTrans, (Object) null))
    {
      this.subTrans.set_localPosition(this.start);
      ((Component) this.subTrans).BroadcastMessage("OnEZTranslated", (SendMessageOptions) 1);
    }
    base._end();
  }

  protected override void WaitDone()
  {
    base.WaitDone();
    if (!Object.op_Inequality((Object) this.subTrans, (Object) null))
      return;
    this.start = this.subTrans.get_localPosition();
  }

  protected override void DoAnim()
  {
    if (Object.op_Equality((Object) this.subTrans, (Object) null))
    {
      this._stop();
    }
    else
    {
      this.factor = Mathf.Sin((float) ((double) this.timeElapsed / (double) this.interval * 6.28318548202515) * this.oscillations);
      this.temp.x = (__Null) (this.start.x + (double) this.factor * this.magnitude.x);
      this.temp.y = (__Null) (this.start.y + (double) this.factor * this.magnitude.y);
      this.temp.z = (__Null) (this.start.z + (double) this.factor * this.magnitude.z);
      this.subTrans.set_localPosition(this.temp);
      ((Component) this.subTrans).BroadcastMessage("OnEZTranslated", (SendMessageOptions) 1);
    }
  }

  public static Shake Do(GameObject sub, Vector3 mag, float oscill, float dur, float delay, EZAnimation.CompletionDelegate startDel, EZAnimation.CompletionDelegate del)
  {
    Shake shake = (Shake) EZAnimator.instance.GetAnimation(EZAnimation.ANIM_TYPE.Shake);
    shake.Start(sub, mag, oscill, dur, delay, startDel, del);
    return shake;
  }

  public override bool Start(GameObject sub, AnimParams parms)
  {
    if (Object.op_Equality((Object) sub, (Object) null))
      return false;
    this.pingPong = parms.pingPong;
    this.restartOnRepeat = parms.restartOnRepeat;
    this.repeatDelay = parms.repeatDelay;
    this.Start(sub, sub.get_transform().get_localPosition(), parms.vec, parms.floatVal, parms.duration, parms.delay, (EZAnimation.CompletionDelegate) null, new EZAnimation.CompletionDelegate(parms.transition.OnAnimEnd));
    return true;
  }

  public void Start(GameObject sub, Vector3 mag, float oscill, float dur, float delay, EZAnimation.CompletionDelegate startDel, EZAnimation.CompletionDelegate del)
  {
    if (Object.op_Equality((Object) sub, (Object) null))
      return;
    this.Start(sub, sub.get_transform().get_localPosition(), mag, oscill, dur, delay, startDel, del);
  }

  public void Start(GameObject sub, Vector3 begin, Vector3 mag, float oscill, float dur, float delay, EZAnimation.CompletionDelegate startDel, EZAnimation.CompletionDelegate del)
  {
    this.subject = sub;
    this.subTrans = this.subject.get_transform();
    this.start = begin;
    this.subTrans.set_localPosition(this.start);
    if (mag.x < 0.0)
      mag.x = (__Null) (double) Random.Range(1f, (float) -mag.x);
    if (mag.y < 0.0)
      mag.y = (__Null) (double) Random.Range(1f, (float) -mag.y);
    if (mag.z < 0.0)
      mag.z = (__Null) (double) Random.Range(1f, (float) -mag.z);
    if ((double) oscill < 0.0)
      oscill = Random.Range(1f, -oscill);
    this.magnitude = mag;
    this.oscillations = oscill;
    this.m_mode = EZAnimation.ANIM_MODE.By;
    this.duration = dur;
    this.m_wait = delay;
    this.completedDelegate = del;
    this.startDelegate = startDel;
    this.StartCommon();
    EZAnimator.instance.Stop((object) this.subject, this.type, true);
    EZAnimator.instance.AddAnimation((EZAnimation) this);
  }
}
