﻿// Decompiled with JetBrains decompiler
// Type: StagingTask_MovementDelimiter
// 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 System.Collections.Generic;
using UnityEngine;
using Wb.Lpw.Game.Common.Descriptions;
using Wb.Lpw.Shared.Client.UnityEngine;
using Wb.Lpw.Shared.Common;
using Wb.Lpw.Shared.Common.DataTypes;

public class StagingTask_MovementDelimiter : StagingTask
{
  private StagingTaskDesc_MovementDelimiter m_TaskDescription;

  public override void InitFromDescription(StagingTaskBaseDesc desc)
  {
    base.InitFromDescription(desc);
    this.m_TaskDescription = this.m_Description as StagingTaskDesc_MovementDelimiter;
    if (this.m_TaskDescription.Action == StagingTaskDesc_MovementDelimiter.AddRemoveAction.AddDelimiter)
      this.AddDelimiter();
    else
      this.RemoveDelimiter();
  }

  private void AddDelimiter()
  {
    PathGridForMesh pathGridAtPosition = PathGridForMesh.GetPathGridAtPosition(VectorExtensions.ToUnity(this.m_TaskDescription.Position));
    if (Object.op_Equality((Object) pathGridAtPosition, (Object) null))
    {
      CommonLog.Error("StagingTask_MovementDelimiter.AddDelimiter: FAILED TO FIND THE PATHFINDING GRID");
    }
    else
    {
      GameObject gameObject = new GameObject(this.m_TaskDescription.DelimiterName);
      gameObject.get_transform().set_parent(((Component) FordGameRoom.Instance).get_transform());
      int nx;
      int nz;
      pathGridAtPosition.pfg.PosToGridPoint(this.m_TaskDescription.Position.x, this.m_TaskDescription.Position.z, out nx, out nz);
      int x1 = nx - this.m_TaskDescription.SquareWidth / 2;
      int x2 = nx + this.m_TaskDescription.SquareWidth / 2;
      int y1 = nz - this.m_TaskDescription.SquareWidth / 2;
      int y2 = nz + this.m_TaskDescription.SquareWidth / 2;
      List<IntVector2> list = new List<IntVector2>();
      for (int x3 = x1; x3 <= x2; ++x3)
      {
        list.Add(new IntVector2(x3, y1));
        list.Add(new IntVector2(x3, y2));
      }
      for (int y3 = y1; y3 <= y2; ++y3)
      {
        list.Add(new IntVector2(x1, y3));
        list.Add(new IntVector2(x2, y3));
      }
      pathGridAtPosition.pfg.PlaceObject((object) gameObject, (IEnumerable<IntVector2>) list);
    }
  }

  private void RemoveDelimiter()
  {
    PathGridForMesh pathGridAtPosition = PathGridForMesh.GetPathGridAtPosition(VectorExtensions.ToUnity(this.m_TaskDescription.Position));
    if (Object.op_Equality((Object) pathGridAtPosition, (Object) null))
    {
      CommonLog.Error("StagingTask_MovementDelimiter.RemoveDelimiter: FAILED TO FIND THE PATHFINDING GRID");
    }
    else
    {
      Transform child = ((Component) FordGameRoom.Instance).get_gameObject().get_transform().FindChild(this.m_TaskDescription.DelimiterName);
      if (Object.op_Equality((Object) child, (Object) null))
      {
        CommonLog.Error("StagingTask_MovementDelimiter.RemoveDelimiter: FAILED TO FIND THE DELIMITER OBJECT. MAKE SURE THE DELIMITER NAME MATCHES THE NAME FOR THE ADDDELIMITER TASK");
      }
      else
      {
        pathGridAtPosition.pfg.RemoveObject((object) ((Component) child).get_gameObject());
        child.set_parent((Transform) null);
        Object.DestroyObject((Object) ((Component) child).get_gameObject());
      }
    }
  }

  public override void Process()
  {
    base.Process();
    this.SetCompleted();
  }
}
