﻿// Decompiled with JetBrains decompiler
// Type: Building
// 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 Profiling;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using UnityEngine;
using Wb.Lpw.AssetPipeline.Client;
using Wb.Lpw.AssetPipeline.Client.Library;
using Wb.Lpw.AssetPipeline.Common.DataDefinition;
using Wb.Lpw.Game.Common;
using Wb.Lpw.Game.Common.GameRoomObject.Building;
using Wb.Lpw.Game.Common.Logging;
using Wb.Lpw.Platform.Client.ObjectModule;
using Wb.Lpw.Shared.Client.UnityEngine;
using Wb.Lpw.Shared.Common;
using Wb.Lpw.Shared.Network;

public class Building : FordGameRoomObject, IColorAnimationDelegate, IBuildable, IVisibilityStateListener, ISelectable
{
  protected Building.PlacementCursor _placementCursor = new Building.PlacementCursor();
  protected DomainBuildingResHandle BuildingPlaceHolder = new DomainBuildingResHandle();
  protected int _currentLevel = 1;
  protected int _maxLevels = 5;
  public BuildingProtocol.Orientation _orientation = BuildingProtocol.Orientation.South;
  protected int _actualFootprintX = 1;
  protected int _actualFootprintY = 1;
  private bool _displayModel = true;
  private bool _displayingModel = true;
  protected int _HitPoints = 100;
  protected Color _bkpColor = Color.get_white();
  private DateTime _visualsLoadedTimeoutHACK = DateTime.MaxValue;
  protected DomainBuildingResHandle MainVisualHolder = new DomainBuildingResHandle();
  private const float CVisualsLoadedTimeoutDurationHack = 10f;
  public static float _BlockingOperationTimeDelay;
  protected PathGridForMesh _currentGrid;
  protected bool _Locked;
  protected bool _TemplateMode;
  protected int _TemplateModeLayer;
  protected BuildingDescription _BuildingDescriptionDB;
  private bool _displayCursor;
  private bool _displayingBuildingPlaceholder;
  protected bool _MouseOver;
  protected bool _LiftingFromGround;
  protected bool _DroppingOnGround;
  protected UIGenericOverhead _uiBuiding;
  protected UIGenericOverhead _uiEditBuiding;
  private BuildingProtocol.eState _currentState;
  protected BuildingStatsPerLevel _CurrentLevelStatsDB;
  protected bool _Repairing;
  protected int _CurrentLevelPhase;
  protected GameObject _VisualsRoot;
  protected Building.Scaffolds _oScaffolds;
  protected MiniBuilder _oMiniBuilder;
  protected MiniWorker _oMiniWorker;
  protected LXFMLModel _lxfmlBuilder;
  protected GameObject _constructionVfx;
  protected bool _constructionDone;
  public bool Selected;
  public bool IsMoving;
  public int SpawnedByTouchcodeID;
  public bool m_ongoingConstructionSpeedUpRequest;
  public bool m_ongoingUpgradeSpeedUpRequest;
  private bool _visualsLoaded;
  private bool _visualsLoadedTimeoutLogged;
  private static Shader NormalShader;
  private static Shader OutlineShader;
  protected bool _outOfFrustum;
  protected bool StateVisualValid;
  public static bool IsSelectDisable;
  private float _secondsToWaitForInauguration;

  public long ItemId
  {
    get
    {
      return this.m_ItemID;
    }
    set
    {
      this.m_ItemID = value;
    }
  }

  public BuildingProtocol.Orientation Orientation
  {
    get
    {
      return this._orientation;
    }
  }

  public int Level
  {
    get
    {
      return this._currentLevel;
    }
  }

  public int ActualFootprintX
  {
    get
    {
      return this._actualFootprintX;
    }
  }

  public int ActualFootprintY
  {
    get
    {
      return this._actualFootprintY;
    }
  }

  public bool Locked
  {
    get
    {
      return this._Locked;
    }
  }

  protected BuildingProtocol.eState CurrentState
  {
    get
    {
      return this._currentState;
    }
    set
    {
      this._currentState = value;
      if (this._TemplateMode)
        return;
      this.OnBuildingStateChange();
    }
  }

  public Building.StateConstructing oConstructing { get; protected set; }

  public Building.StateWaitingForInauguration oWaitForInauguration { get; protected set; }

  public Building.StateInaugurating oInaugurating { get; protected set; }

  public Building.StateUpgrading oUpgrading { get; protected set; }

  public Building.StateWaitingForUpgradeCompletion oWaitForUpgradeCompletion { get; protected set; }

  public Building.StateCompleteUpgrade oCompleteUpgrade { get; protected set; }

  public Building.StateIdle oIdle { get; protected set; }

  public Building.StateWaitingToCollectReward oWaitToCollectReward { get; protected set; }

  public Building.StateDamaged oDamaged { get; protected set; }

  public Building.StateRepairing oRepairing { get; protected set; }

  public Building.StateDestruction oDestruction { get; protected set; }

  public Building.StateSelling oSelling { get; protected set; }

  public int Priority
  {
    get
    {
      return 9;
    }
  }

  public GameObject GameObject
  {
    get
    {
      return ((Component) this).get_gameObject();
    }
  }

  public FordClassId ClassId
  {
    get
    {
      return (FordClassId) this.m_ClassID;
    }
    set
    {
      this.SetClassID((int) value);
    }
  }

  Color IColorAnimationDelegate.OriginalColor()
  {
    return new Color(0.0f, 0.0f, 0.0f, 1f);
  }

  void IColorAnimationDelegate.HighlightObject(Color highlightColor)
  {
    foreach (MeshRenderer meshRenderer in (MeshRenderer[]) ((Component) this).GetComponentsInChildren<MeshRenderer>(false))
    {
      if (((Renderer) meshRenderer).get_material().HasProperty("_FeedbackColor"))
        ((Renderer) meshRenderer).get_material().SetColor("_FeedbackColor", highlightColor);
      else if (((Renderer) meshRenderer).get_material().HasProperty("_Color"))
        ((Renderer) meshRenderer).get_material().SetColor("_Color", highlightColor);
    }
    foreach (SkinnedMeshRenderer skinnedMeshRenderer in (SkinnedMeshRenderer[]) ((Component) this).GetComponentsInChildren<SkinnedMeshRenderer>(false))
    {
      if (((Renderer) skinnedMeshRenderer).get_material().HasProperty("_FeedbackColor"))
        ((Renderer) skinnedMeshRenderer).get_material().SetColor("_FeedbackColor", highlightColor);
      else if (((Renderer) skinnedMeshRenderer).get_material().HasProperty("_Color"))
        ((Renderer) skinnedMeshRenderer).get_material().SetColor("_Color", highlightColor);
    }
  }

  public void GetHP(out int current, out int max)
  {
    current = this._HitPoints;
    max = 20;
  }

  public virtual BuildingProtocol.Category GetBuildingCategory()
  {
    return BuildingProtocol.Category.Invalid;
  }

  public GameRoomObject GetGameRoomObject()
  {
    return (GameRoomObject) this;
  }

  public LootItem GetLootItem()
  {
    return (LootItem) null;
  }

  public virtual bool IsSelectable()
  {
    return !this._TemplateMode && !this.IsMoving && !UIHUDGoals.AreThereAnyOngoingGoalUIActivities();
  }

  public virtual void Select(bool bSelected)
  {
    if (DomainRoom.Instance.InBuildMode || DomainRoom.Instance.RoomOwnerId != NetworkMgr.Instance.PlayerId || Building.IsSelectDisable)
      return;
    this.OnSelected(bSelected);
  }

  public virtual void OnSelected(bool bSelected)
  {
    this.Selected = bSelected;
    if ((!this.Selected || !FordPanelManager.Instance.IsActiveLayout(FordPanelBase.FordHUDGroup.Domain)) && FordPanelManager.Instance.IsPanelOpened("UIBuildingDetails"))
      FordPanelManager.Instance.Dismiss("UIBuildingDetails");
    if (this.Selected)
    {
      if (this.IsReadyForInauguration())
      {
        UIBuildingOverviewV3.SelectedBuilding = (Building) null;
        IsoCamera.Instance.MainFollowTarget = ((Component) this).get_transform();
      }
      else
      {
        UIBuildingOverviewV3.SelectedBuilding = this;
        if (!FordPanelManager.Instance.IsPanelOpened("UIPanelBuildingOverview"))
          FordPanelManager.Instance.BringInAndMarkAsLayout("UIPanelBuildingOverview", (object) this, (Action<string, UIPanelBase>) null);
        IsoCamera.Instance.MainFollowTarget = ((Component) this).get_transform();
      }
    }
    else
    {
      GameRoomObject localAvatar = ((FordGameRoom) GameRoom.Instance).GetLocalAvatar();
      if (!Object.op_Inequality((Object) localAvatar, (Object) null))
        return;
      IsoCamera.Instance.MainFollowTarget = ((Component) localAvatar).get_gameObject().get_transform();
      IsoCamera.Instance.TargetOffset = Vector3.get_zero();
    }
  }

  public bool IsMouseOverEnabled()
  {
    return !this._TemplateMode;
  }

  public void MouseOver(MouseOverStatus status)
  {
    if (status == MouseOverStatus.Enter)
    {
      this.ContextualHighlight(FordInputMgr.Instance.IsContextualChatAvailable(), true);
    }
    else
    {
      if (status != MouseOverStatus.Exit)
        return;
      this.ContextualHighlight(FordInputMgr.Instance.IsContextualChatAvailable(), false);
    }
  }

  public override void BuildFromReplicationData(Hashtable oCreateObjectData, ClientSideGameRoomObjectReplicationData optionalCSReplicationData = null)
  {
    base.BuildFromReplicationData(oCreateObjectData, optionalCSReplicationData);
  }

  public override void Init()
  {
    base.Init();
    this._visualsLoadedTimeoutHACK = DateTime.Now.AddSeconds(10.0);
    this._visualsLoadedTimeoutLogged = false;
    Building.NormalShader = Shader.Find("Ford/Ford_Building_2UVs");
    Building.OutlineShader = Shader.Find("Ford/Ford_Building_2UVs_Outline");
    this.oConstructing = this.CreateStateContructingData();
    this.oWaitForInauguration = this.CreateStateWaitingForInaugurationData();
    this.oInaugurating = this.CreateStateInauguratingData();
    this.oUpgrading = this.CreateStateUpgradingData();
    this.oWaitForUpgradeCompletion = this.CreateStateWaitingForUpgradeCompletionData();
    this.oCompleteUpgrade = this.CreateStateCompleteUpgradeData();
    this.oIdle = this.CreateStateIdleData();
    this.oWaitToCollectReward = this.CreateWaitingToCollectRewardData();
    this.oDamaged = this.CreateStateDamagedData();
    this.oRepairing = this.CreateStateRepairingData();
    this.oDestruction = this.CreateStateDestructionData();
    this.oSelling = this.CreateStateSellingData();
    this._BuildingDescriptionDB = WbAssetDatabase.Instance.Db.GetObjectSync<BuildingDescription>(this.m_ItemID);
    this._CurrentLevelStatsDB = ((List<BuildingStatsPerLevel>) this._BuildingDescriptionDB.LevelProgression.Value.StatsPerLevel)[0];
    this._HitPoints = this._CurrentLevelStatsDB.HitPoints;
    this._actualFootprintX = this._BuildingDescriptionDB.FootPrintX;
    this._actualFootprintY = this._BuildingDescriptionDB.FootPrintY;
    this._VisualsRoot = new GameObject("VisualsRoot");
    this._VisualsRoot.get_transform().set_parent(((Component) this).get_transform());
    this._VisualsRoot.get_transform().set_localPosition(Vector3.get_zero());
    this._VisualsRoot.get_transform().set_localRotation(new Quaternion(0.0f, 0.0f, 0.0f, 1f));
    this._VisualsRoot.get_transform().set_localScale(Vector3.get_one());
    this._lxfmlBuilder = (LXFMLModel) this._VisualsRoot.AddComponent<LXFMLModel>();
    this._lxfmlBuilder.ModelPositionOffset = VectorExtensions.ToUnity(this._BuildingDescriptionDB.LXFMLPositionOffset);
    this._lxfmlBuilder.RotationOffset = Quaternion.AngleAxis(this._BuildingDescriptionDB.LXFMLRotationOffset, Vector3.get_up());
    this.SetOrientation(BuildingProtocol.Orientation.South);
    BoxCollider boxCollider = (BoxCollider) ((Component) this).GetComponent<BoxCollider>();
    if (Object.op_Inequality((Object) boxCollider, (Object) null))
      boxCollider.set_size(new Vector3((float) this._BuildingDescriptionDB.FootPrintX - 0.8f, 0.5f, (float) this._BuildingDescriptionDB.FootPrintY - 0.8f));
    this.StartStateIdle();
    if (!this._TemplateMode)
    {
      this.StartCoroutine(this.RegisterOverhead());
      this._oScaffolds = new Building.Scaffolds();
    }
    if (this._BuildingDescriptionDB.VisualEffects != null)
    {
      if (this._BuildingDescriptionDB.VisualEffects.Value.SpawnFX != null)
        ((ResourceItemRef<AssetBundleReference, StreamedResourceContainer>) this._BuildingDescriptionDB.VisualEffects.Value.SpawnFX).Load((object) this);
      if (this._BuildingDescriptionDB.VisualEffects.Value.InaugurationFX != null)
        ((ResourceItemRef<AssetBundleReference, StreamedResourceContainer>) this._BuildingDescriptionDB.VisualEffects.Value.InaugurationFX).Load((object) this);
      if (this._BuildingDescriptionDB.VisualEffects.Value.MoveLiftFX != null)
        ((ResourceItemRef<AssetBundleReference, StreamedResourceContainer>) this._BuildingDescriptionDB.VisualEffects.Value.MoveLiftFX).Load((object) this);
      if (this._BuildingDescriptionDB.VisualEffects.Value.MoveDropFX != null)
        ((ResourceItemRef<AssetBundleReference, StreamedResourceContainer>) this._BuildingDescriptionDB.VisualEffects.Value.MoveDropFX).Load((object) this);
    }
    if (this._BuildingDescriptionDB.SFX_Lift != null)
      WBAudioManager.Instance.Preload(this._BuildingDescriptionDB.SFX_Lift, (Object) this);
    if (this._BuildingDescriptionDB.SFX_Drop != null)
      WBAudioManager.Instance.Preload(this._BuildingDescriptionDB.SFX_Drop, (Object) this);
    if (this._BuildingDescriptionDB.SFX_Land != null)
      WBAudioManager.Instance.Preload(this._BuildingDescriptionDB.SFX_Land, (Object) this);
    if (this._BuildingDescriptionDB.SFX_Inauguration != null)
      WBAudioManager.Instance.Preload(this._BuildingDescriptionDB.SFX_Inauguration, (Object) this);
    ColorAnimation.SafelyAddComponentAndSetup(((Component) this).get_gameObject(), (IColorAnimationDelegate) this);
    Building.IsSelectDisable = false;
  }

  public override bool IsReady()
  {
    if (!this._visualsLoaded && !this._visualsLoadedTimeoutLogged && DateTime.Now > this._visualsLoadedTimeoutHACK)
    {
      if (!this._outOfFrustum)
      {
        string txt = string.Format("Could not fully download visuals for building {0} in a reasonnable time. Please check definition.", (object) WbAssetDatabase.Instance.Db.GetItemName(this.ItemId));
        CommonLog.Streaming.Warn((object) txt);
        WBConsole.LogWarning(txt);
      }
      this._visualsLoadedTimeoutLogged = true;
    }
    if (!this._outOfFrustum && !this._visualsLoaded)
      return DateTime.Now > this._visualsLoadedTimeoutHACK;
    return true;
  }

  [DebuggerHidden]
  protected virtual IEnumerator RegisterOverhead()
  {
    // ISSUE: object of a compiler-generated type is created
    return (IEnumerator) new Building.\u003CRegisterOverhead\u003Ec__Iterator37()
    {
      \u003C\u003Ef__this = this
    };
  }

  protected virtual Building.StateConstructing CreateStateContructingData()
  {
    return new Building.StateConstructing();
  }

  protected virtual Building.StateWaitingForInauguration CreateStateWaitingForInaugurationData()
  {
    return new Building.StateWaitingForInauguration();
  }

  protected virtual Building.StateInaugurating CreateStateInauguratingData()
  {
    return new Building.StateInaugurating();
  }

  protected virtual Building.StateUpgrading CreateStateUpgradingData()
  {
    return new Building.StateUpgrading();
  }

  protected virtual Building.StateWaitingForUpgradeCompletion CreateStateWaitingForUpgradeCompletionData()
  {
    return new Building.StateWaitingForUpgradeCompletion();
  }

  protected virtual Building.StateCompleteUpgrade CreateStateCompleteUpgradeData()
  {
    return new Building.StateCompleteUpgrade();
  }

  protected virtual Building.StateIdle CreateStateIdleData()
  {
    return new Building.StateIdle();
  }

  protected virtual Building.StateWaitingToCollectReward CreateWaitingToCollectRewardData()
  {
    return new Building.StateWaitingToCollectReward();
  }

  protected virtual Building.StateDamaged CreateStateDamagedData()
  {
    return new Building.StateDamaged();
  }

  protected virtual Building.StateRepairing CreateStateRepairingData()
  {
    return new Building.StateRepairing();
  }

  protected virtual Building.StateDestruction CreateStateDestructionData()
  {
    return new Building.StateDestruction();
  }

  protected virtual Building.StateSelling CreateStateSellingData()
  {
    return new Building.StateSelling();
  }

  protected override void SyncFromHashTable(Hashtable oInitdata)
  {
    base.SyncFromHashTable(oInitdata);
    this.SetLevel(SafeHashTable.ReadInt(oInitdata, 7, 0), true);
    this._HitPoints = SafeHashTable.ReadInt(oInitdata, 8, 0);
    BuildingProtocol.Orientation orientation = (BuildingProtocol.Orientation) SafeHashTable.ReadInt(oInitdata, 4, 0);
    this._Locked = SafeHashTable.ReadBool(oInitdata, 9, false);
    this.SetOrientation(orientation);
    this.SetPosition(this.m_Transform.get_position());
    BuildingProtocol.eState eState = (BuildingProtocol.eState) SafeHashTable.ReadInt(oInitdata, 3, 0);
    float num = (float) SafeHashTable.ReadInt(oInitdata, 6, 0);
    switch (eState)
    {
      case BuildingProtocol.eState.Construction:
        this.StartStateConstruction(num, false);
        break;
      case BuildingProtocol.eState.WaitingForInauguration:
        this.StartStateWaitingForInauguration();
        break;
      case BuildingProtocol.eState.Upgrading:
        this.StartStateUpgrading(num, true);
        break;
      case BuildingProtocol.eState.WaitingForUpgradeCompletion:
        this.StartStateWaitingForUpgradeCompletion(true);
        break;
      default:
        this.StartStateIdle();
        break;
    }
  }

  public override void Release()
  {
    if (this.IsMiniBuilderPresent())
      this.HideMiniBuilder();
    this.MainVisualHolder.DestroyAll();
    if (this._placementCursor != null && this._placementCursor.Cursor != null)
      this._placementCursor.Cursor.DestroyAll();
    this.BuildingPlaceHolder.DestroyAll();
    ResourceMgr.Instance.RemoveAllReferences((object) this);
    if (this._oScaffolds != null)
      this.DestroyScaffoldPieces();
    this.RemoveFromPathFindingGrid();
    base.Release();
  }

  public void SetLevel(int level, bool bFromSync = false)
  {
    this._currentLevel = level;
    this._CurrentLevelStatsDB = ((List<BuildingStatsPerLevel>) this._BuildingDescriptionDB.LevelProgression.Value.StatsPerLevel)[level - 1];
    this._HitPoints = this._CurrentLevelStatsDB.HitPoints;
  }

  public override void Process()
  {
    base.Process();
    this.ProcessCurrentState();
    this.ProcessCurrentStateVisuals();
    this.ProcessScaffolds();
    this.ProcessPlacementCursor();
    this.ProcessPlaceholderBuilding();
    if (this._LiftingFromGround)
    {
      this.ProcessLiftFromGround();
    }
    else
    {
      if (!this._DroppingOnGround)
        return;
      this.ProcessDropOnGround();
    }
  }

  protected virtual void ProcessCurrentState()
  {
    if (this._TemplateMode)
      return;
    switch (this.CurrentState)
    {
      case BuildingProtocol.eState.Construction:
        this.ProcessStateConstruction();
        break;
      case BuildingProtocol.eState.WaitingForInauguration:
        this.ProcessStateWaitingForInauguration();
        break;
      case BuildingProtocol.eState.Inaugurating:
        this.ProcessStateInaugurating();
        break;
      case BuildingProtocol.eState.Upgrading:
        this.ProcessStateUpgrading();
        break;
      case BuildingProtocol.eState.WaitingForUpgradeCompletion:
        this.ProcessStateWaitingForUpgradeCompletion();
        break;
      case BuildingProtocol.eState.UpgradeCompleting:
        this.ProcessStateCompleteUpgrade();
        break;
      case BuildingProtocol.eState.Idle:
        this.ProcessStateIdle();
        break;
      case BuildingProtocol.eState.Damaged:
        this.ProcessStateDamaged();
        break;
      case BuildingProtocol.eState.Destruction:
        this.ProcessStateDestruction();
        break;
      case BuildingProtocol.eState.Selling:
        this.ProcessStateSelling();
        break;
    }
  }

  protected virtual void StartStateConstruction(float fTimeLeft, bool bForceSync = false)
  {
    this.CurrentState = BuildingProtocol.eState.Construction;
    this.StateVisualValid = false;
    PerformanceProfilingMgr.Event("StartConstruction", GameEvent.EventType.BuildingCreate);
    this.oConstructing.TimeLeft = fTimeLeft;
    this.oConstructing.AnimComplete = false;
    if (this._BuildingDescriptionDB == null || this._BuildingDescriptionDB.VisualEffects == null || (this._BuildingDescriptionDB.VisualEffects.Value.SpawnFX == null || !this._BuildingDescriptionDB.VisualEffects.Value.SpawnFX.IsLoaded))
      return;
    GameObject gameObject = (GameObject) Object.Instantiate((Object) ((GameObjectItemRef) this._BuildingDescriptionDB.VisualEffects.Value.SpawnFX).GameObject);
    gameObject.get_transform().set_parent(this._VisualsRoot.get_transform());
    gameObject.get_transform().set_localPosition(Vector3.get_zero());
    gameObject.get_transform().set_localRotation(new Quaternion(0.0f, 0.0f, 0.0f, 1f));
    gameObject.get_transform().set_localScale(Vector3.get_one());
  }

  protected virtual void SpeedUpConstruction()
  {
    this.oConstructing.SpeedUpConstruction = true;
  }

  protected virtual void ProcessStateConstruction()
  {
    this.oConstructing.TimeLeft -= Time.get_deltaTime();
    if ((double) this.oConstructing.TimeLeft >= 0.0)
      return;
    this.oConstructing.TimeLeft = 0.0f;
  }

  protected virtual void StartStateWaitingForInauguration()
  {
    this.CurrentState = BuildingProtocol.eState.WaitingForInauguration;
    this.StateVisualValid = false;
    if (!Object.op_Inequality((Object) this._uiBuiding, (Object) null))
      return;
    UIBuildingOverhead buildingOverhead = this._uiBuiding as UIBuildingOverhead;
    if (!Object.op_Inequality((Object) buildingOverhead, (Object) null) || !Object.op_Inequality((Object) UIBuildingOverviewV3.SelectedBuilding, (Object) this))
      return;
    buildingOverhead.Show();
  }

  protected virtual void ProcessStateWaitingForInauguration()
  {
  }

  protected virtual void StartStateInaugurating()
  {
    this.CurrentState = BuildingProtocol.eState.Inaugurating;
    this.StateVisualValid = false;
    this.oInaugurating.AnimComplete = false;
    this.PlayInaugurationCelebration(0.0f);
    Building._BlockingOperationTimeDelay = Time.get_time() + 5f;
  }

  public void PlayInaugurationCelebration(float secondsToWait)
  {
    this._secondsToWaitForInauguration = secondsToWait;
    this.StartCoroutine("Inaugurate");
  }

  [DebuggerHidden]
  private IEnumerator Inaugurate()
  {
    // ISSUE: object of a compiler-generated type is created
    return (IEnumerator) new Building.\u003CInaugurate\u003Ec__Iterator38()
    {
      \u003C\u003Ef__this = this
    };
  }

  protected virtual void ProcessStateInaugurating()
  {
    if (!this.oInaugurating.AnimComplete)
      return;
    this.StartStateIdle();
  }

  protected virtual void StartStateUpgrading(float timeLeft, bool bMuteScaffoldSounds = false)
  {
    this.CurrentState = BuildingProtocol.eState.Upgrading;
    this.StateVisualValid = false;
    this.oUpgrading._timeLeft = timeLeft;
    this.oUpgrading.MuteScaffoldSounds = bMuteScaffoldSounds;
    PerformanceProfilingMgr.Event("StartUpgrade", GameEvent.EventType.BuildingUpgrade);
  }

  protected virtual void ProcessStateUpgrading()
  {
    this.oUpgrading._timeLeft -= Time.get_deltaTime();
    if ((double) this.oUpgrading._timeLeft >= 0.0)
      return;
    this.oUpgrading._timeLeft = 0.0f;
  }

  protected virtual void StartStateWaitingForUpgradeCompletion(bool bMuteScaffoldSounds = false)
  {
    GameLog.Ben.Debug((object) ("StartStateWaitingForUpgradeCompletion with current level = " + (object) this._currentLevel));
    this.oWaitForUpgradeCompletion.MuteScaffoldSounds = bMuteScaffoldSounds;
    this.CurrentState = BuildingProtocol.eState.WaitingForUpgradeCompletion;
    this.StateVisualValid = false;
    if (((DomainRoom) FordGameRoom.Instance).RoomOwnerId != NetworkMgr.Instance.PlayerId || !Object.op_Inequality((Object) this.GetOverHead(), (Object) null))
      return;
    this.GetOverHead().Show();
  }

  protected virtual void ProcessStateWaitingForUpgradeCompletion()
  {
  }

  protected virtual void StartStateCompleteUpgrade()
  {
    GameLog.Ben.Debug((object) ("StartStateCompleteUpgrade with current level = " + (object) this._currentLevel));
    this.CurrentState = BuildingProtocol.eState.UpgradeCompleting;
    this.StateVisualValid = false;
    this.oCompleteUpgrade.AnimComplete = false;
    PerformanceProfilingMgr.Event("UpgradeComplete", GameEvent.EventType.BuildingUpgrade);
    this.PlayInaugurationCelebration(0.0f);
    Building._BlockingOperationTimeDelay = Time.get_time() + 5f;
  }

  protected virtual void ProcessStateCompleteUpgrade()
  {
    if (!this.oCompleteUpgrade.AnimComplete)
      return;
    this.StartStateIdle();
  }

  protected virtual void StartStateIdle()
  {
    this.CurrentState = BuildingProtocol.eState.Idle;
    this.StateVisualValid = false;
  }

  protected virtual void ProcessStateIdle()
  {
    if (this.IsMiniWorkerPresent() || this.m_ItemID == 378091255224287482L)
      return;
    this.BringUpMiniWorker();
  }

  protected virtual void ProcessStateWaitingToCollectReward()
  {
  }

  protected virtual void StartStateDamaged()
  {
    this.CurrentState = BuildingProtocol.eState.Damaged;
    this.StateVisualValid = false;
  }

  protected virtual void ProcessStateDamaged()
  {
  }

  protected virtual void StartStateSelling()
  {
    this.CurrentState = BuildingProtocol.eState.Selling;
    this.StateVisualValid = false;
    this.oSelling._TimeLeft = 0.0f;
  }

  protected virtual void ProcessStateSelling()
  {
    this.oSelling._TimeLeft -= Time.get_deltaTime();
    if ((double) this.oSelling._TimeLeft >= 0.0)
      return;
    this.oSelling._TimeLeft = 0.0f;
    GameRoom.Instance.RemoveGameObject((GameRoomObject) this);
  }

  protected virtual void StartStateDestruction()
  {
    this.CurrentState = BuildingProtocol.eState.Destruction;
    this.StateVisualValid = false;
    PerformanceProfilingMgr.Event("StartDestruction", GameEvent.EventType.BuildingDestroy);
  }

  protected virtual void ProcessStateDestruction()
  {
  }

  public override void OnObjectEvent(int roomID, int objectID, int objectEventCode, Hashtable eventParams)
  {
    switch (objectEventCode)
    {
      case 2:
        BuildingProtocol.ConstructionBeginsCommand constructionBeginsCommand = new BuildingProtocol.ConstructionBeginsCommand();
        constructionBeginsCommand.FromHashtable(eventParams);
        this.StartStateConstruction((float) constructionBeginsCommand.TimeLeftInSeconds, false);
        break;
      case 3:
        new BuildingProtocol.ConstructionDoneCommand().FromHashtable(eventParams);
        this.StartStateWaitingForInauguration();
        break;
      case 5:
        new BuildingProtocol.SpeedUpConstructionCommand().FromHashtable(eventParams);
        this.SpeedUpConstruction();
        break;
      case 7:
        new BuildingProtocol.InaugurationDoneCommand().FromHashtable(eventParams);
        this.StartStateInaugurating();
        break;
      case 9:
        BuildingProtocol.UpgradeBeginsCommand upgradeBeginsCommand = new BuildingProtocol.UpgradeBeginsCommand();
        upgradeBeginsCommand.FromHashtable(eventParams);
        this.StartStateUpgrading((float) upgradeBeginsCommand.TimeLeftInSeconds, false);
        break;
      case 11:
        new BuildingProtocol.SpeedUpUpgradeCommand().FromHashtable(eventParams);
        break;
      case 12:
        BuildingProtocol.UpgradeDoneCommand upgradeDoneCommand = new BuildingProtocol.UpgradeDoneCommand();
        upgradeDoneCommand.FromHashtable(eventParams);
        CommonLog.Debug("BUILDING.ONOBJECTEVENT: cmd.NewLevel = " + (object) upgradeDoneCommand.NewLevel);
        this.SetLevel(upgradeDoneCommand.NewLevel, false);
        this.StartStateWaitingForUpgradeCompletion(false);
        break;
      case 14:
        new BuildingProtocol.CompleteUpgradeDoneCommand().FromHashtable(eventParams);
        this.StartStateCompleteUpgrade();
        break;
      case 16:
        new BuildingProtocol.SellCommand().FromHashtable(eventParams);
        this.StartStateSelling();
        break;
      case 18:
        BuildingProtocol.MoveValidationCmd moveValidationCmd = new BuildingProtocol.MoveValidationCmd();
        moveValidationCmd.FromHashtable(eventParams);
        this.OnMoveValidationResponse((BuildingProtocol.MoveValidationCode) moveValidationCmd.ValidationCode);
        break;
      case 19:
        BuildingProtocol.MoveCmd moveCmd = new BuildingProtocol.MoveCmd();
        moveCmd.FromHashtable(eventParams);
        this.DropOnGround(new Vector3(moveCmd.Position.x, (float) this.m_Transform.get_position().y, moveCmd.Position.z), moveCmd.Orientation);
        break;
      case 20:
        BuildingProtocol.SetLockedCmd setLockedCmd = new BuildingProtocol.SetLockedCmd();
        setLockedCmd.FromHashtable(eventParams);
        this.SetLocked(setLockedCmd.Locked);
        break;
      case 21:
        this.m_ongoingConstructionSpeedUpRequest = false;
        break;
      case 22:
        this.m_ongoingUpgradeSpeedUpRequest = false;
        break;
      default:
        base.OnObjectEvent(roomID, objectID, objectEventCode, eventParams);
        break;
    }
  }

  public void RequestMoveToServer()
  {
    this.SendCommand((GameRoomProtocol.Command) new BuildingProtocol.RequestMoveCmd()
    {
      Position = {
        x = (float) this.m_Transform.get_position().x,
        y = 0.0f,
        z = (float) this.m_Transform.get_position().z
      },
      Orientation = this._orientation
    });
  }

  protected virtual void OnMoveValidationResponse(BuildingProtocol.MoveValidationCode code)
  {
    switch (code)
    {
      case BuildingProtocol.MoveValidationCode.eSuccess:
        CommonLog.Debug(" OnMoveValidationResponse: SUCCESS");
        ((DomainRoom) GameRoom.Instance).LeaveMoveBuildingMode();
        break;
      case BuildingProtocol.MoveValidationCode.ePositionAlreadyOccupied:
      case BuildingProtocol.MoveValidationCode.eOtherError:
        CommonLog.Debug(" OnMoveValidationResponse: fail!");
        ((DomainRoom) GameRoom.Instance).CancelMoveBuildingMode();
        break;
    }
  }

  public override void SetPosition(Vector3 vPosition)
  {
    base.SetPosition(vPosition);
    if (this._TemplateMode || !this.m_Synchronized)
      return;
    this.RemoveFromPathFindingGrid();
    this.PlaceOnPathFindingGrid(vPosition);
    ((Component) this).get_transform().set_position(vPosition);
  }

  public void SetOrientation(BuildingProtocol.Orientation orientation)
  {
    switch (orientation)
    {
      case BuildingProtocol.Orientation.North:
        this.SetLookAtAlignUp(new Vector3(0.0f, 0.0f, 1f), Vector3.get_up());
        break;
      case BuildingProtocol.Orientation.East:
        this.SetLookAtAlignUp(new Vector3(1f, 0.0f, 0.0f), Vector3.get_up());
        break;
      case BuildingProtocol.Orientation.South:
        this.SetLookAtAlignUp(new Vector3(0.0f, 0.0f, -1f), Vector3.get_up());
        break;
      case BuildingProtocol.Orientation.West:
        this.SetLookAtAlignUp(new Vector3(-1f, 0.0f, 0.0f), Vector3.get_up());
        break;
    }
    if (orientation == BuildingProtocol.Orientation.North || orientation == BuildingProtocol.Orientation.South)
    {
      this._actualFootprintX = this._BuildingDescriptionDB.FootPrintX;
      this._actualFootprintY = this._BuildingDescriptionDB.FootPrintY;
    }
    else
    {
      this._actualFootprintX = this._BuildingDescriptionDB.FootPrintY;
      this._actualFootprintY = this._BuildingDescriptionDB.FootPrintX;
    }
    this._orientation = orientation;
  }

  protected virtual void SetLocked(bool bLocked)
  {
    this._Locked = bLocked;
  }

  public virtual bool CanUpgrade()
  {
    return this._currentLevel < this._maxLevels && this.CurrentState == BuildingProtocol.eState.Idle;
  }

  public virtual bool CanSell()
  {
    return this.CurrentState != BuildingProtocol.eState.Inaugurating && this.CurrentState != BuildingProtocol.eState.UpgradeCompleting && this.CurrentState != BuildingProtocol.eState.Destruction;
  }

  public virtual bool IsConstructing()
  {
    return this.CurrentState == BuildingProtocol.eState.Construction;
  }

  public virtual bool IsReadyForInauguration()
  {
    return this.CurrentState == BuildingProtocol.eState.WaitingForInauguration;
  }

  public virtual bool IsDoneWithRainOfBricks()
  {
    if (!Object.op_Equality((Object) this._lxfmlBuilder, (Object) null))
      return this._lxfmlBuilder.IsIdle;
    return true;
  }

  public virtual bool IsInaugurating()
  {
    return this.CurrentState == BuildingProtocol.eState.Inaugurating;
  }

  public virtual bool IsUpgrading()
  {
    return this.CurrentState == BuildingProtocol.eState.Upgrading;
  }

  public virtual bool IsReadyForUpgradeCompletion()
  {
    return this.CurrentState == BuildingProtocol.eState.WaitingForUpgradeCompletion;
  }

  public virtual bool IsCompletingUpgrade()
  {
    return this.CurrentState == BuildingProtocol.eState.UpgradeCompleting;
  }

  public virtual bool IsSelling()
  {
    return this.CurrentState == BuildingProtocol.eState.Selling;
  }

  public virtual bool IsCrafting()
  {
    return false;
  }

  public virtual bool IsWaitingForCollect()
  {
    return false;
  }

  public bool IsInaugurated()
  {
    if (this.CurrentState != BuildingProtocol.eState.Construction)
      return this.CurrentState != BuildingProtocol.eState.WaitingForInauguration;
    return false;
  }

  public int GetResaleValue()
  {
    int index = this.Level - 1;
    if (this.IsUpgrading())
      ++index;
    return ((List<BuildingStatsPerLevel>) this._BuildingDescriptionDB.LevelProgression.Value.StatsPerLevel)[index].ResaleValue;
  }

  public virtual void RequestInaugurationToServer()
  {
    BuildingProtocol.InaugurationRequestCommand inaugurationRequestCommand = new BuildingProtocol.InaugurationRequestCommand();
    this.SendOperation(inaugurationRequestCommand.Opcode, inaugurationRequestCommand.ToHashtable(), (OnObjectOperationResult) null);
  }

  public virtual void RequestUpgradeToServer()
  {
    BuildingProtocol.UpgradeRequestCommand upgradeRequestCommand = new BuildingProtocol.UpgradeRequestCommand();
    upgradeRequestCommand.StudsCollectedPerGroup = (Hashtable) FordGameRoom.Instance.GenerateCollectedStudHashTableAndResetCache();
    this.SendOperation(upgradeRequestCommand.Opcode, upgradeRequestCommand.ToHashtable(), (OnObjectOperationResult) null);
  }

  public virtual void RequestCompleteUpgradeToServer()
  {
    BuildingProtocol.CompleteUpgradeRequestCommand upgradeRequestCommand = new BuildingProtocol.CompleteUpgradeRequestCommand();
    this.SendOperation(upgradeRequestCommand.Opcode, upgradeRequestCommand.ToHashtable(), (OnObjectOperationResult) null);
  }

  public virtual void RequestSellToServer()
  {
    BuildingProtocol.SellRequestCommand sellRequestCommand = new BuildingProtocol.SellRequestCommand();
    sellRequestCommand.StudsCollectedPerGroup = (Hashtable) FordGameRoom.Instance.GenerateCollectedStudHashTableAndResetCache();
    this.SendOperation(sellRequestCommand.Opcode, sellRequestCommand.ToHashtable(), (OnObjectOperationResult) null);
  }

  public virtual bool CanRequestConstructionSpeedUpToServer()
  {
    if (this.IsConstructing())
      return !this.m_ongoingConstructionSpeedUpRequest;
    return false;
  }

  public virtual void RequestConstructionSpeedUpToServer()
  {
    BuildingProtocol.SpeedUpConstructionRequestCommand constructionRequestCommand = new BuildingProtocol.SpeedUpConstructionRequestCommand();
    this.SendOperation(constructionRequestCommand.Opcode, constructionRequestCommand.ToHashtable(), (OnObjectOperationResult) null);
    this.m_ongoingConstructionSpeedUpRequest = true;
  }

  public virtual bool CanRequestUpgradeSpeedUpToServer()
  {
    if (this.IsUpgrading())
      return !this.m_ongoingUpgradeSpeedUpRequest;
    return false;
  }

  public virtual void RequestUpgradeSpeedUpToServer()
  {
    BuildingProtocol.SpeedUpUpgradeRequestCommand upgradeRequestCommand = new BuildingProtocol.SpeedUpUpgradeRequestCommand();
    this.SendOperation(upgradeRequestCommand.Opcode, upgradeRequestCommand.ToHashtable(), (OnObjectOperationResult) null);
    this.m_ongoingUpgradeSpeedUpRequest = true;
  }

  public void CloseSelectionPanel()
  {
    FordInputMgr.Instance.DeselectObjectIfAlreadySelected((ISelectable) this);
    this.Selected = false;
  }

  public BuildingDescription GetDBDescription()
  {
    return this._BuildingDescriptionDB;
  }

  private void ProcessDisplayModel()
  {
    if (this is ChiPortal)
      return;
    if (!this._displayModel)
    {
      if (this._displayingModel && Object.op_Inequality((Object) this.MainVisualHolder.CurrentGob, (Object) null))
      {
        this._displayingModel = false;
        foreach (Renderer renderer in (Renderer[]) this._VisualsRoot.GetComponentsInChildren<Renderer>())
          renderer.set_enabled(false);
      }
      if (this._displayingBuildingPlaceholder || !Object.op_Inequality((Object) this.BuildingPlaceHolder.CurrentGob, (Object) null))
        return;
      DomainRoom domainRoom = GameRoom.Instance as DomainRoom;
      if (domainRoom.InBuildPlacement || domainRoom.InBuildMove)
      {
        this._displayingBuildingPlaceholder = true;
        foreach (Renderer renderer in (Renderer[]) this.BuildingPlaceHolder.CurrentGob.GetComponentsInChildren<Renderer>())
          renderer.set_enabled(true);
      }
      else
      {
        this._displayingBuildingPlaceholder = false;
        foreach (Renderer renderer in (Renderer[]) this.BuildingPlaceHolder.CurrentGob.GetComponentsInChildren<Renderer>())
          renderer.set_enabled(false);
      }
    }
    else
    {
      if (!this._displayingModel && Object.op_Inequality((Object) this.MainVisualHolder.CurrentGob, (Object) null))
      {
        this._displayingModel = true;
        foreach (Renderer renderer in (Renderer[]) this._VisualsRoot.GetComponentsInChildren<Renderer>())
          renderer.set_enabled(true);
      }
      if (Object.op_Equality((Object) this.MainVisualHolder.CurrentGob, (Object) null) && Object.op_Inequality((Object) this.BuildingPlaceHolder.CurrentGob, (Object) null))
      {
        DomainRoom domainRoom = GameRoom.Instance as DomainRoom;
        if (domainRoom.InBuildPlacement || domainRoom.InBuildMove)
        {
          if (this._displayingBuildingPlaceholder)
            return;
          this._displayingBuildingPlaceholder = true;
          foreach (Renderer renderer in (Renderer[]) this.BuildingPlaceHolder.CurrentGob.GetComponentsInChildren<Renderer>())
            renderer.set_enabled(true);
        }
        else
        {
          this._displayingBuildingPlaceholder = false;
          if (this.BuildingPlaceHolder == null || !Object.op_Inequality((Object) this.BuildingPlaceHolder.CurrentGob, (Object) null))
            return;
          this._displayingBuildingPlaceholder = false;
          foreach (Renderer renderer in (Renderer[]) this.BuildingPlaceHolder.CurrentGob.GetComponentsInChildren<Renderer>())
            renderer.set_enabled(false);
        }
      }
      else
      {
        if (!this._displayingBuildingPlaceholder || !Object.op_Inequality((Object) this.BuildingPlaceHolder.CurrentGob, (Object) null))
          return;
        this._displayingBuildingPlaceholder = false;
        foreach (Renderer renderer in (Renderer[]) this.BuildingPlaceHolder.CurrentGob.GetComponentsInChildren<Renderer>())
          renderer.set_enabled(false);
      }
    }
  }

  protected virtual void OnBuildingStateChange()
  {
    UIBuildingOverviewV3 buildingOverviewV3 = FordPanelManager.Instance.GetFordPanelRef("UIPanelBuildingOverview") as UIBuildingOverviewV3;
    if (!Object.op_Inequality((Object) buildingOverviewV3, (Object) null))
      return;
    buildingOverviewV3.RefreshLeft();
  }

  protected static void OnProductionStateChange()
  {
    UIBuildingOverviewV3 buildingOverviewV3 = FordPanelManager.Instance.GetFordPanelRef("UIPanelBuildingOverview") as UIBuildingOverviewV3;
    if (!Object.op_Inequality((Object) buildingOverviewV3, (Object) null))
      return;
    buildingOverviewV3.RefreshRight();
  }

  protected virtual void ProcessCurrentStateVisuals()
  {
    this.ProcessDisplayModel();
    switch (this.CurrentState)
    {
      case BuildingProtocol.eState.Construction:
        this.ProcessStateConstructionVisuals();
        break;
      case BuildingProtocol.eState.WaitingForInauguration:
        this.ProcessStateWaitingForInaugurationVisuals();
        break;
      case BuildingProtocol.eState.Inaugurating:
        this.ProcessStateInauguratingVisuals();
        break;
      case BuildingProtocol.eState.Upgrading:
        this.ProcessStateUpgradingVisuals();
        break;
      case BuildingProtocol.eState.WaitingForUpgradeCompletion:
        this.ProcessStateWaitingForUpgradeCompletionVisuals();
        break;
      case BuildingProtocol.eState.UpgradeCompleting:
        this.ProcessStateCompleteUpgradeVisuals();
        break;
      case BuildingProtocol.eState.Idle:
        this.ProcessStateIdleVisuals();
        break;
      case BuildingProtocol.eState.Damaged:
        this.ProcessStateDamagedVisuals();
        break;
      case BuildingProtocol.eState.Destruction:
        this.ProcessStateDestructionVisuals();
        break;
      case BuildingProtocol.eState.Selling:
        this.ProcessStateSellingVisuals();
        break;
    }
  }

  protected void SetMainBuildingVisual()
  {
    this.DeleteMainBuildingVisuals();
    GameObject gameObject = this.MainVisualHolder.SafeInstantiate(true);
    if (Object.op_Equality((Object) gameObject, (Object) null))
      return;
    gameObject.get_transform().set_parent(this._VisualsRoot.get_transform());
    gameObject.get_transform().set_localPosition(Vector3.get_zero());
    gameObject.get_transform().set_localRotation(new Quaternion(0.0f, 0.0f, 0.0f, 1f));
    gameObject.get_transform().set_localScale(Vector3.get_one());
    int layer = LayerMask.NameToLayer("Building");
    Building.RecursiveSetLayer(gameObject.get_transform(), layer);
    gameObject.set_tag("Building");
    Shader shader = Shader.Find("Ford/Ford_Building_2UVs");
    foreach (MeshRenderer meshRenderer in (MeshRenderer[]) ((Component) this).GetComponentsInChildren<MeshRenderer>(false))
    {
      if (Object.op_Inequality((Object) ((Renderer) meshRenderer).get_material().get_shader(), (Object) shader) && ((Object) ((Renderer) meshRenderer).get_material().get_shader()).get_name() == "Ford/Ford_Building_2UVs")
        ((Renderer) meshRenderer).get_material().set_shader(shader);
      ((Renderer) meshRenderer).set_useLightProbes(true);
    }
    foreach (SkinnedMeshRenderer skinnedMeshRenderer in (SkinnedMeshRenderer[]) ((Component) this).GetComponentsInChildren<SkinnedMeshRenderer>(false))
    {
      if (Object.op_Inequality((Object) ((Renderer) skinnedMeshRenderer).get_material().get_shader(), (Object) shader) && ((Object) ((Renderer) skinnedMeshRenderer).get_material().get_shader()).get_name() == "Ford/Ford_Building_2UVs")
        ((Renderer) skinnedMeshRenderer).get_material().set_shader(shader);
      ((Renderer) skinnedMeshRenderer).set_useLightProbes(true);
    }
    if (this._TemplateMode)
    {
      ((Component) this).get_gameObject().set_layer(this._TemplateModeLayer);
      Building.RecursiveSetLayer(((Component) this).get_gameObject().get_transform(), this._TemplateModeLayer);
    }
    this._visualsLoaded = true;
    this.ProcessDisplayModel();
  }

  protected void DeleteMainBuildingVisuals()
  {
    this.MainVisualHolder.DestroyLoaded();
    this._visualsLoaded = false;
    this._displayingModel = true;
  }

  private void DeleteCursorVisuals()
  {
    if (this._placementCursor.Cursor == null)
      return;
    this._placementCursor.Cursor.DestroyLoaded();
  }

  private bool StreamCurrentState(GameObjectItemRef currentRef)
  {
    if (currentRef == null)
      return false;
    if (this.MainVisualHolder.GetLoadState((ItemRef<AssetBundleReference>) currentRef) == DomainBuildingResHandle.State.NotLoaded)
      this.MainVisualHolder.Load(currentRef);
    switch (this.MainVisualHolder.GetLoadState((ItemRef<AssetBundleReference>) currentRef))
    {
      case DomainBuildingResHandle.State.Loaded:
        this.SetMainBuildingVisual();
        return true;
      case DomainBuildingResHandle.State.Instantiated:
        return true;
      default:
        return false;
    }
  }

  private bool StreamNextState(GameObjectItemRef nextRef)
  {
    if (nextRef == null)
      return false;
    if (this.MainVisualHolder.GetLoadState((ItemRef<AssetBundleReference>) nextRef) == DomainBuildingResHandle.State.NotLoaded)
      this.MainVisualHolder.Load(nextRef);
    return this.MainVisualHolder.GetLoadState((ItemRef<AssetBundleReference>) nextRef) == DomainBuildingResHandle.State.Loaded;
  }

  private bool StreamCurrentStateAndNextState(GameObjectItemRef currentRef, GameObjectItemRef nextRef)
  {
    if (currentRef == null || nextRef == null)
      return false;
    if (this.MainVisualHolder.GetLoadState((ItemRef<AssetBundleReference>) currentRef) == DomainBuildingResHandle.State.NotLoaded)
      this.MainVisualHolder.Load(currentRef);
    if (this.MainVisualHolder.GetLoadState((ItemRef<AssetBundleReference>) nextRef) == DomainBuildingResHandle.State.NotLoaded)
      this.MainVisualHolder.Load(nextRef);
    if (this.MainVisualHolder.GetLoadState((ItemRef<AssetBundleReference>) nextRef) == DomainBuildingResHandle.State.Loaded || this.MainVisualHolder.GetLoadState((ItemRef<AssetBundleReference>) nextRef) == DomainBuildingResHandle.State.Instantiated)
    {
      switch (this.MainVisualHolder.GetLoadState((ItemRef<AssetBundleReference>) currentRef))
      {
        case DomainBuildingResHandle.State.Loaded:
          this.SetMainBuildingVisual();
          return true;
        case DomainBuildingResHandle.State.Instantiated:
          return true;
      }
    }
    return false;
  }

  protected virtual void ProcessStateConstructionVisuals()
  {
    if (this._outOfFrustum || !this._displayModel)
      return;
    if (!this.oConstructing.StartedPhase1Anim && !this.StateVisualValid)
    {
      if (!this.StreamNextState((GameObjectItemRef) this._BuildingDescriptionDB.LevelProgression.Value.ConstructionVisual) || !this.StreamNextState(this.GetConstructionVisualItemRef()))
        return;
      if (!this.IsMiniBuilderPresent())
        this.BringUpMiniBuilder();
      this.StateVisualValid = true;
    }
    float num1 = (float) ((List<BuildingStatsPerLevel>) this._BuildingDescriptionDB.LevelProgression.Value.StatsPerLevel)[0].ConstructionTimeInSeconds - this.oConstructing.TimeLeft;
    float num2 = 5f;
    if (!this.oConstructing.StartedPhase1Anim)
    {
      if ((double) num1 < (double) num2)
      {
        // ISSUE: object of a compiler-generated type is created
        // ISSUE: variable of a compiler-generated type
        Building.\u003CProcessStateConstructionVisuals\u003Ec__AnonStorey1DE visualsCAnonStorey1De = new Building.\u003CProcessStateConstructionVisuals\u003Ec__AnonStorey1DE();
        // ISSUE: reference to a compiler-generated field
        visualsCAnonStorey1De.\u003C\u003Ef__this = this;
        // ISSUE: reference to a compiler-generated field
        visualsCAnonStorey1De.vfxBr = WBLoader.Instance.LoadAssetBundle(AssetPath.BuildPlatformAssetBundleName("Art/Vfx/Prefabs", "Vfx_Portal_Construction_Prefab"), WBLoader.Priority.Normal);
        this._constructionDone = false;
        // ISSUE: reference to a compiler-generated method
        // ISSUE: reference to a compiler-generated method
        this._lxfmlBuilder.LaunchConstruction(string.Empty, Path.GetFileNameWithoutExtension(this._BuildingDescriptionDB.LevelProgression.Value.ConstructionVisual.Value.Path), false, new Action(visualsCAnonStorey1De.\u003C\u003Em__A4), new Action<GameObject>(visualsCAnonStorey1De.\u003C\u003Em__A5));
      }
      else
        this.oConstructing.AnimComplete = true;
      this.oConstructing.StartedPhase1Anim = true;
    }
    else
    {
      if (!this.oConstructing.AnimComplete)
        return;
      if (this.MainVisualHolder.GetLoadState((ItemRef<AssetBundleReference>) this.GetConstructionVisualItemRef()) == DomainBuildingResHandle.State.Loaded)
        this.SetMainBuildingVisual();
      if (!this.oConstructing.SpeedUpConstruction)
        return;
      this.StartStateWaitingForInauguration();
    }
  }

  protected virtual void ProcessStateWaitingForInaugurationVisuals()
  {
    if (this._outOfFrustum || !this._displayModel)
      return;
    if (this.AreScaffoldsUp())
      this.HideScaffolds();
    if (this.StateVisualValid || !this.StreamCurrentState(this.GetConstructionVisualItemRef()))
      return;
    if (!this.IsMiniBuilderPresent())
      this.BringUpMiniBuilder();
    this.StateVisualValid = true;
  }

  protected virtual void ProcessStateInauguratingVisuals()
  {
    if (this._outOfFrustum || !this._displayModel)
      return;
    if (this.AreScaffoldsUp())
      this.BringDownScaffolds();
    if (this.StateVisualValid || !this.StreamCurrentStateAndNextState(this.GetConstructionVisualItemRef(), this.GetVisualItemRef(1)))
      return;
    // ISSUE: object of a compiler-generated type is created
    // ISSUE: variable of a compiler-generated type
    Building.\u003CProcessStateInauguratingVisuals\u003Ec__AnonStorey1DF visualsCAnonStorey1Df = new Building.\u003CProcessStateInauguratingVisuals\u003Ec__AnonStorey1DF();
    // ISSUE: reference to a compiler-generated field
    visualsCAnonStorey1Df.\u003C\u003Ef__this = this;
    if (!this.IsMiniBuilderPresent())
      this.BringUpMiniBuilder();
    if (!this.IsMiniWorkerPresent())
      this.BringUpMiniWorker();
    // ISSUE: reference to a compiler-generated field
    visualsCAnonStorey1Df.vfxBr = WBLoader.Instance.LoadAssetBundle(AssetPath.BuildPlatformAssetBundleName("Art/Vfx/Prefabs", "Vfx_Portal_Construction_Prefab"), WBLoader.Priority.Normal);
    this._constructionDone = false;
    // ISSUE: reference to a compiler-generated method
    // ISSUE: reference to a compiler-generated method
    this._lxfmlBuilder.LaunchConstruction(Path.GetFileNameWithoutExtension(this._BuildingDescriptionDB.LevelProgression.Value.ConstructionVisual.Value.Path), Path.GetFileNameWithoutExtension(((List<BuildingStatsPerLevel>) this._BuildingDescriptionDB.LevelProgression.Value.StatsPerLevel)[0].Visual.Value.Path), true, new Action(visualsCAnonStorey1Df.\u003C\u003Em__A6), new Action<GameObject>(visualsCAnonStorey1Df.\u003C\u003Em__A7));
    this.StateVisualValid = true;
  }

  protected virtual void ProcessStateUpgradingVisuals()
  {
    if (this._outOfFrustum || !this._displayModel || !this.m_Synchronized && !this._TemplateMode)
      return;
    if (!this.AreScaffoldsUp())
      this.BringUpScaffolds(this.oUpgrading.MuteScaffoldSounds);
    GameObjectItemRef visualItemRef = this.GetVisualItemRef(this._currentLevel);
    if (this.MainVisualHolder.GetLoadState((ItemRef<AssetBundleReference>) visualItemRef) == DomainBuildingResHandle.State.NotLoaded)
      this.StateVisualValid = false;
    if (this.StateVisualValid || !this.StreamCurrentState(visualItemRef))
      return;
    if (!this.IsMiniBuilderPresent())
      this.BringUpMiniBuilder();
    this.StateVisualValid = true;
  }

  protected virtual void ProcessStateWaitingForUpgradeCompletionVisuals()
  {
    if (this._outOfFrustum || !this._displayModel || !this.m_Synchronized && !this._TemplateMode)
      return;
    if (!this.AreScaffoldsUp())
      this.BringUpScaffolds(this.oWaitForUpgradeCompletion.MuteScaffoldSounds);
    GameObjectItemRef visualItemRef = this.GetVisualItemRef(this._currentLevel - 1);
    if (this.MainVisualHolder.GetLoadState((ItemRef<AssetBundleReference>) visualItemRef) == DomainBuildingResHandle.State.NotLoaded)
      this.StateVisualValid = false;
    if (this.StateVisualValid || !this.StreamCurrentState(visualItemRef))
      return;
    if (!this.IsMiniBuilderPresent())
      this.BringUpMiniBuilder();
    this.StateVisualValid = true;
  }

  protected virtual void ProcessStateCompleteUpgradeVisuals()
  {
    if (this._outOfFrustum || !this._displayModel || !this.m_Synchronized && !this._TemplateMode)
      return;
    if (this.AreScaffoldsUp())
      this.BringDownScaffolds();
    if (this.StateVisualValid || !this.StreamCurrentStateAndNextState(this.GetVisualItemRef(this._currentLevel - 1), this.GetVisualItemRef(this._currentLevel)))
      return;
    // ISSUE: object of a compiler-generated type is created
    // ISSUE: variable of a compiler-generated type
    Building.\u003CProcessStateCompleteUpgradeVisuals\u003Ec__AnonStorey1E0 visualsCAnonStorey1E0 = new Building.\u003CProcessStateCompleteUpgradeVisuals\u003Ec__AnonStorey1E0();
    // ISSUE: reference to a compiler-generated field
    visualsCAnonStorey1E0.\u003C\u003Ef__this = this;
    if (!this.IsMiniBuilderPresent())
      this.BringUpMiniBuilder();
    if (!this.IsMiniWorkerPresent())
      this.BringUpMiniWorker();
    string path1 = ((List<BuildingStatsPerLevel>) this._BuildingDescriptionDB.LevelProgression.Value.StatsPerLevel)[this._currentLevel - 2].Visual.Value.Path;
    string path2 = ((List<BuildingStatsPerLevel>) this._BuildingDescriptionDB.LevelProgression.Value.StatsPerLevel)[this._currentLevel - 1].Visual.Value.Path;
    if (path1 == path2)
    {
      this.oCompleteUpgrade.AnimComplete = true;
      this.StateVisualValid = true;
    }
    else
    {
      // ISSUE: reference to a compiler-generated field
      visualsCAnonStorey1E0.vfxBr = WBLoader.Instance.LoadAssetBundle(AssetPath.BuildPlatformAssetBundleName("Art/Vfx/Prefabs", "Vfx_Portal_Construction_Prefab"), WBLoader.Priority.Normal);
      this._constructionDone = false;
      // ISSUE: reference to a compiler-generated method
      // ISSUE: reference to a compiler-generated method
      this._lxfmlBuilder.LaunchConstruction(Path.GetFileNameWithoutExtension(path1), Path.GetFileNameWithoutExtension(path2), true, new Action(visualsCAnonStorey1E0.\u003C\u003Em__A8), new Action<GameObject>(visualsCAnonStorey1E0.\u003C\u003Em__A9));
      this.StateVisualValid = true;
    }
  }

  [DebuggerHidden]
  private IEnumerator DoSpawnConstructionVfx(WBLoader.BundleRequest vfxBr)
  {
    // ISSUE: object of a compiler-generated type is created
    return (IEnumerator) new Building.\u003CDoSpawnConstructionVfx\u003Ec__Iterator39()
    {
      vfxBr = vfxBr,
      \u003C\u0024\u003EvfxBr = vfxBr,
      \u003C\u003Ef__this = this
    };
  }

  public static void RecursiveSetLayer(Transform t, int layer)
  {
    IEnumerator enumerator = t.GetEnumerator();
    try
    {
      while (enumerator.MoveNext())
      {
        Transform t1 = (Transform) enumerator.Current;
        ((Component) t1).get_gameObject().set_layer(layer);
        Building.RecursiveSetLayer(t1, layer);
      }
    }
    finally
    {
      IDisposable disposable = enumerator as IDisposable;
      if (disposable != null)
        disposable.Dispose();
    }
    ((Component) t).get_gameObject().set_layer(layer);
  }

  protected virtual void ProcessStateIdleVisuals()
  {
    if (this._outOfFrustum || !this._displayModel || !this.m_Synchronized && !this._TemplateMode)
      return;
    if (!this._TemplateMode && this.AreScaffoldsUp())
      this.HideScaffolds();
    if (!this._TemplateMode && this.IsMiniBuilderPresent() && !this._oMiniBuilder.IsCurrentState(MiniBuilder.State.Inaugurate))
      this.HideMiniBuilder();
    GameObjectItemRef visualItemRef = this.GetVisualItemRef(this._currentLevel);
    if (this.MainVisualHolder.GetLoadState((ItemRef<AssetBundleReference>) visualItemRef) == DomainBuildingResHandle.State.NotLoaded)
      this.StateVisualValid = false;
    if (this.StateVisualValid || !this.StreamCurrentState(visualItemRef))
      return;
    this.StateVisualValid = true;
  }

  protected virtual void ProcessStateDamagedVisuals()
  {
  }

  protected virtual void ProcessStateSellingVisuals()
  {
  }

  protected virtual void ProcessStateDestructionVisuals()
  {
  }

  protected void BringUpScaffolds(bool bMuteSound)
  {
    if (this._oScaffolds.Visible)
      return;
    this.GenerateNewScaffolds();
    if (this._BuildingDescriptionDB.VisualEffects.Value.ScaffoldSound != null)
      WBAudioManager.Instance.Play(this._BuildingDescriptionDB.VisualEffects.Value.ScaffoldSound, (Object) this, AudioResourceUsage.Clear, ((Component) this).get_transform().get_position(), 0.0f, (AudioCompletionCallback) null);
    this._oScaffolds.Time = 0.0f;
    this._oScaffolds.Visible = true;
    this._oScaffolds.Hiding = false;
  }

  protected void BringDownScaffolds()
  {
    if (!this._oScaffolds.Visible || this._oScaffolds.Hiding)
      return;
    this._oScaffolds.Hiding = true;
    this._oScaffolds.Time = 0.0f;
  }

  protected void GenerateNewScaffolds()
  {
    GameObjectItemRef itemRef1 = (GameObjectItemRef) this._BuildingDescriptionDB.VisualEffects.Value.ScaffoldCornerPiece;
    GameObjectItemRef itemRef2 = (GameObjectItemRef) this._BuildingDescriptionDB.VisualEffects.Value.ScaffoldStraightPiece;
    int num1 = -1;
    int num2 = 1;
    int num3 = 1;
    for (int index = 0; index < 4; ++index)
    {
      float num4 = (float) ((double) num1 * ((double) this._BuildingDescriptionDB.FootPrintX + 2.0) * 0.5 - (double) num1 * 1.0);
      float num5 = (float) ((double) num2 * ((double) this._BuildingDescriptionDB.FootPrintY + 2.0) * 0.5 - (double) num2 * 1.0);
      Vector3 vPosition;
      vPosition.x = (__Null) (double) num4;
      vPosition.y = (__Null) 0.0;
      vPosition.z = (__Null) (double) num5;
      this.AddScaffoldPiece(itemRef1, vPosition, (float) index * 90f);
      int num6 = 2;
      int num7 = this._BuildingDescriptionDB.FootPrintX + 2;
      while (num6 < num7 - 3)
      {
        if (index % 2 == 0)
          vPosition.x = (__Null) ((double) num4 + (double) (num3 * num6));
        else
          vPosition.z = (__Null) ((double) num5 + (double) (num3 * num6));
        this.AddScaffoldPiece(itemRef2, vPosition, (float) ((double) index * 90.0 - 90.0));
        num6 += 2;
      }
      if (index % 2 == 0)
      {
        num3 *= -1;
        num1 *= -1;
      }
      if (index == 1)
        num2 *= -1;
    }
  }

  private void AddScaffoldPiece(GameObjectItemRef itemRef, Vector3 vPosition, float fRotation)
  {
    if (Random.Range(0, 4) < 2)
      return;
    DomainBuildingResHandle buildingResHandle = new DomainBuildingResHandle();
    buildingResHandle.Load(itemRef);
    this._oScaffolds.Pieces.Add(new Building.ScaffoldsPiece()
    {
      pieceHolder = buildingResHandle,
      itemToStream = itemRef,
      position = vPosition,
      rotation = fRotation
    });
  }

  public bool AreScaffoldsUp()
  {
    return this._oScaffolds.Visible;
  }

  private bool StreamScaffoldsInAndSetup()
  {
    if (!this._oScaffolds.AllStreamed)
    {
      using (List<Building.ScaffoldsPiece>.Enumerator enumerator = this._oScaffolds.Pieces.GetEnumerator())
      {
        while (enumerator.MoveNext())
        {
          Building.ScaffoldsPiece current = enumerator.Current;
          if (current.pieceHolder.GetLoadState((ItemRef<AssetBundleReference>) current.itemToStream) == DomainBuildingResHandle.State.NotLoaded || current.pieceHolder.GetLoadState((ItemRef<AssetBundleReference>) current.itemToStream) == DomainBuildingResHandle.State.Loading)
            return false;
        }
      }
      using (List<Building.ScaffoldsPiece>.Enumerator enumerator = this._oScaffolds.Pieces.GetEnumerator())
      {
        while (enumerator.MoveNext())
        {
          Building.ScaffoldsPiece current = enumerator.Current;
          if (current.pieceHolder.GetLoadState((ItemRef<AssetBundleReference>) current.itemToStream) == DomainBuildingResHandle.State.Loaded)
          {
            GameObject gameObject = current.pieceHolder.SafeInstantiate(true);
            gameObject.get_transform().set_parent(((Component) this).get_gameObject().get_transform());
            gameObject.get_transform().set_localPosition(current.position);
            gameObject.get_transform().set_localRotation(Quaternion.Euler(0.0f, current.rotation, 0.0f));
            gameObject.get_transform().set_localScale(Vector3.get_one());
          }
        }
      }
      for (int index = 0; index < this._oScaffolds.Pieces.Count; ++index)
      {
        Building.ScaffoldsPiece scaffoldsPiece = this._oScaffolds.Pieces[index];
        scaffoldsPiece.anim = (Animation) scaffoldsPiece.pieceHolder.CurrentGob.GetComponentInChildren<Animation>();
        if (Object.op_Equality((Object) scaffoldsPiece.anim, (Object) null))
          scaffoldsPiece.anim = (Animation) scaffoldsPiece.pieceHolder.CurrentGob.GetComponent<Animation>();
        scaffoldsPiece.startInTime = (float) index * 0.1f;
        scaffoldsPiece.startLoopTime = scaffoldsPiece.startInTime + scaffoldsPiece.anim.GetClip("BLD_Lion_Scaffolding_In").get_length();
        scaffoldsPiece.startOutTime = (float) this._oScaffolds.Pieces.Count * 0.1f + scaffoldsPiece.anim.GetClip("BLD_Lion_Scaffolding_In").get_length() + Random.Range(-0.1f, 0.1f);
        scaffoldsPiece.pieceHolder.CurrentGob.SetActive(false);
      }
      this._oScaffolds.AllStreamed = true;
    }
    return true;
  }

  protected void ProcessScaffolds()
  {
    if (this._TemplateMode || !this._oScaffolds.Visible || !this.StreamScaffoldsInAndSetup())
      return;
    this._oScaffolds.Time += Time.get_deltaTime();
    if (this._oScaffolds.Hiding && (double) this._oScaffolds.Time > 5.0)
    {
      this.HideScaffolds();
    }
    else
    {
      for (int index = 0; index < this._oScaffolds.Pieces.Count; ++index)
      {
        Building.ScaffoldsPiece scaffoldsPiece = this._oScaffolds.Pieces[index];
        if (scaffoldsPiece.pieceHolder != null && !Object.op_Equality((Object) scaffoldsPiece.pieceHolder.CurrentGob, (Object) null))
        {
          if (this._oScaffolds.Hiding)
          {
            if (!scaffoldsPiece.StartedPlayingUpAnim && (double) this._oScaffolds.Time > (double) scaffoldsPiece.startUpTime)
            {
              scaffoldsPiece.anim.Play("BLD_Lion_Scaffolding_Up");
              scaffoldsPiece.StartedPlayingUpAnim = true;
            }
          }
          else if (!scaffoldsPiece.StartedPlayingInAnim && (double) this._oScaffolds.Time > (double) scaffoldsPiece.startInTime)
          {
            scaffoldsPiece.pieceHolder.CurrentGob.SetActive(true);
            scaffoldsPiece.anim.Play("BLD_Lion_Scaffolding_In");
            scaffoldsPiece.StartedPlayingInAnim = true;
          }
          else if (!scaffoldsPiece.StartedPlayingLoopAnim && (double) this._oScaffolds.Time > (double) scaffoldsPiece.startLoopTime)
          {
            scaffoldsPiece.anim.Play("BLD_Lion_Scaffolding_Loop");
            scaffoldsPiece.StartedPlayingLoopAnim = true;
          }
          else if (!scaffoldsPiece.StartedPlayingOutAnim && (double) this._oScaffolds.Time > (double) scaffoldsPiece.startOutTime)
          {
            scaffoldsPiece.anim.Play("BLD_Lion_Scaffolding_Out");
            scaffoldsPiece.StartedPlayingOutAnim = true;
          }
        }
      }
    }
  }

  protected void HideScaffolds()
  {
    this.DestroyScaffoldPieces();
    this._oScaffolds.Visible = false;
  }

  protected void DestroyScaffoldPieces()
  {
    using (List<Building.ScaffoldsPiece>.Enumerator enumerator = this._oScaffolds.Pieces.GetEnumerator())
    {
      while (enumerator.MoveNext())
        enumerator.Current.pieceHolder.DestroyAll();
    }
    this._oScaffolds.AllStreamed = false;
    this._oScaffolds.Pieces.Clear();
  }

  protected bool IsMiniBuilderPresent()
  {
    return Object.op_Inequality((Object) this._oMiniBuilder, (Object) null);
  }

  protected bool IsMiniWorkerPresent()
  {
    return Object.op_Inequality((Object) this._oMiniWorker, (Object) null);
  }

  protected void BringUpMiniBuilder()
  {
  }

  protected void BringUpMiniWorker()
  {
  }

  protected void HideMiniBuilder()
  {
    if (!Object.op_Inequality((Object) this._oMiniBuilder, (Object) null))
      return;
    Object.Destroy((Object) ((Component) this._oMiniBuilder).get_gameObject());
    this._oMiniBuilder = (MiniBuilder) null;
  }

  protected void ProcessPlaceholderBuilding()
  {
    if (this._outOfFrustum && !DomainRoom.Instance.InBuildMode || (this._BuildingDescriptionDB.VisualEffects == null || this._BuildingDescriptionDB.VisualEffects.Value.BuildingPlaceholder == null))
      return;
    if (this.BuildingPlaceHolder.GetLoadState(this._BuildingDescriptionDB.VisualEffects.Value.BuildingPlaceholder) == DomainBuildingResHandle.State.NotLoaded)
      this.BuildingPlaceHolder.Load((GameObjectItemRef) this._BuildingDescriptionDB.VisualEffects.Value.BuildingPlaceholder);
    if (this.BuildingPlaceHolder.GetLoadState(this._BuildingDescriptionDB.VisualEffects.Value.BuildingPlaceholder) != DomainBuildingResHandle.State.Loaded)
      return;
    GameObject gameObject = this.BuildingPlaceHolder.SafeInstantiate(true);
    if (!Object.op_Inequality((Object) gameObject, (Object) null))
      return;
    gameObject.get_transform().set_parent(((Component) this).get_transform());
    Vector3 vector3;
    vector3.x = (__Null) 0.0;
    vector3.y = (__Null) 0.150000005960464;
    vector3.z = (__Null) 0.0500000007450581;
    gameObject.get_transform().set_localPosition(vector3);
    gameObject.get_transform().set_localRotation(Quaternion.get_identity());
    gameObject.get_transform().set_localScale(Vector3.get_one());
    this._displayingBuildingPlaceholder = true;
    this.ProcessDisplayModel();
  }

  protected void ProcessPlacementCursor()
  {
    if (!this._displayCursor || this._BuildingDescriptionDB.VisualEffects == null || this._BuildingDescriptionDB.VisualEffects.Value.PlacementCursor == null)
      return;
    if (this._placementCursor.Cursor.GetLoadState(this._BuildingDescriptionDB.VisualEffects.Value.PlacementCursor) == DomainBuildingResHandle.State.NotLoaded)
      this._placementCursor.Cursor.Load((GameObjectItemRef) this._BuildingDescriptionDB.VisualEffects.Value.PlacementCursor);
    if (this._placementCursor.Cursor.GetLoadState(this._BuildingDescriptionDB.VisualEffects.Value.PlacementCursor) != DomainBuildingResHandle.State.Loaded)
      return;
    GameObject gameObject = this._placementCursor.Cursor.SafeInstantiate(true);
    if (!Object.op_Inequality((Object) gameObject, (Object) null))
      return;
    gameObject.get_transform().set_parent(((Component) this).get_transform());
    Vector3 vector3;
    vector3.x = (__Null) 0.0;
    vector3.y = (__Null) 0.025000000372529;
    vector3.z = (__Null) 0.0500000007450581;
    gameObject.get_transform().set_localPosition(vector3);
    gameObject.get_transform().set_localRotation(Quaternion.get_identity());
    gameObject.get_transform().set_localScale(Vector3.get_one());
    ((Renderer) gameObject.GetComponentInChildren<MeshRenderer>()).get_material().SetColor("_TintColor", this._placementCursor.Color);
  }

  public void LiftFromGround()
  {
    this._LiftingFromGround = true;
    this._DroppingOnGround = false;
    this._VisualsRoot.get_transform().set_localPosition(new Vector3(0.0f, 0.0f, 0.0f));
    if (this._BuildingDescriptionDB != null && this._BuildingDescriptionDB.VisualEffects.Value != null && (this._BuildingDescriptionDB.VisualEffects.Value.MoveLiftFX != null && this._BuildingDescriptionDB.VisualEffects.Value.MoveLiftFX.IsLoaded))
    {
      GameObject gameObject = (GameObject) Object.Instantiate((Object) ((GameObjectItemRef) this._BuildingDescriptionDB.VisualEffects.Value.MoveLiftFX).GameObject);
      gameObject.get_transform().set_parent(this._VisualsRoot.get_transform());
      gameObject.get_transform().set_localPosition(Vector3.get_zero());
      gameObject.get_transform().set_localRotation(new Quaternion(0.0f, 0.0f, 0.0f, 1f));
      gameObject.get_transform().set_localScale(Vector3.get_one());
    }
    if (this._BuildingDescriptionDB.SFX_Lift == null)
      return;
    WBAudioManager.Instance.Play(this._BuildingDescriptionDB.SFX_Lift, (Object) this, AudioResourceUsage.Clear, ((Component) this).get_transform(), 0.0f, (AudioCompletionCallback) null);
  }

  protected void ProcessLiftFromGround()
  {
    Vector3 localPosition = this._VisualsRoot.get_transform().get_localPosition();
    localPosition.y = (__Null) (double) Mathf.MoveTowards((float) localPosition.y, 2f, 15f * Time.get_deltaTime());
    this._VisualsRoot.get_transform().set_localPosition(localPosition);
    if (localPosition.y != 2.0)
      return;
    this._LiftingFromGround = false;
  }

  public void DropOnGround(Vector3 vPosition, BuildingProtocol.Orientation orientation)
  {
    this._LiftingFromGround = false;
    this._DroppingOnGround = true;
    this._VisualsRoot.get_transform().set_localPosition(new Vector3(0.0f, 2f, 0.0f));
    this.SetOrientation(orientation);
    this.SetPosition(vPosition);
    if (this._BuildingDescriptionDB.SFX_Drop == null)
      return;
    WBAudioManager.Instance.Play(this._BuildingDescriptionDB.SFX_Drop, (Object) this, AudioResourceUsage.Clear, ((Component) this).get_transform().get_position(), 0.0f, (AudioCompletionCallback) null);
  }

  protected void ProcessDropOnGround()
  {
    Vector3 localPosition = this._VisualsRoot.get_transform().get_localPosition();
    localPosition.y = (__Null) (double) Mathf.MoveTowards((float) localPosition.y, 0.0f, 20f * Time.get_deltaTime());
    this._VisualsRoot.get_transform().set_localPosition(localPosition);
    if (localPosition.y != 0.0)
      return;
    this._DroppingOnGround = false;
    if (this._BuildingDescriptionDB != null && this._BuildingDescriptionDB.VisualEffects.Value != null && (this._BuildingDescriptionDB.VisualEffects.Value.MoveDropFX != null && this._BuildingDescriptionDB.VisualEffects.Value.MoveDropFX.IsLoaded))
    {
      GameObject gameObject = (GameObject) Object.Instantiate((Object) ((GameObjectItemRef) this._BuildingDescriptionDB.VisualEffects.Value.MoveDropFX).GameObject);
      gameObject.get_transform().set_parent(this._VisualsRoot.get_transform());
      gameObject.get_transform().set_localPosition(Vector3.get_zero());
      gameObject.get_transform().set_localRotation(new Quaternion(0.0f, 0.0f, 0.0f, 1f));
      gameObject.get_transform().set_localScale(Vector3.get_one());
    }
    if (this._BuildingDescriptionDB.SFX_Land == null)
      return;
    WBAudioManager.Instance.Play(this._BuildingDescriptionDB.SFX_Land, (Object) this, AudioResourceUsage.Clear, ((Component) this).get_transform().get_position(), 0.0f, (AudioCompletionCallback) null);
  }

  public void SetTemplateMode(bool templateMode, int layer)
  {
    this._TemplateMode = templateMode;
    this._TemplateModeLayer = layer;
  }

  public void ShowPlacementCursor()
  {
    this._displayCursor = true;
    this._placementCursor.Color = Color.get_green();
  }

  public void HidePlacementCursor()
  {
    this._displayCursor = false;
    this.DeleteCursorVisuals();
  }

  public void ShowBuilding()
  {
    this._displayModel = true;
  }

  public void HideBuilding()
  {
    this._displayModel = false;
  }

  public void SetPlacementCursorColor(Color oNewColor)
  {
    this._placementCursor.Color = oNewColor;
    if (this._placementCursor.Cursor == null || !Object.op_Inequality((Object) this._placementCursor.Cursor.CurrentGob, (Object) null))
      return;
    ((Renderer) this._placementCursor.Cursor.CurrentGob.GetComponentInChildren<MeshRenderer>()).get_material().SetColor("_TintColor", this._placementCursor.Color);
  }

  public void FindGridPlacementAtWorldPosition(Vector3 worldPosition, out PathGridForMesh newGrid, out int gridStartX, out int gridStartY, out Vector3 newAdjustedWorldPosition, out bool validPosition)
  {
    validPosition = false;
    newGrid = PathGridForMesh.GetPathGridAtPosition(worldPosition);
    if (Object.op_Equality((Object) newGrid, (Object) null))
    {
      newAdjustedWorldPosition = worldPosition;
      gridStartX = 0;
      gridStartY = 0;
    }
    else
    {
      int nx;
      int nz;
      newGrid.pfg.PosToGridPoint(VectorExtensions.ToLpw(worldPosition), out nx, out nz);
      gridStartX = nx - this._actualFootprintX / 2;
      gridStartY = nz - this._actualFootprintY / 2;
      newAdjustedWorldPosition = VectorExtensions.ToUnity(newGrid.pfg.GridPointToCenterPos(nx, nz));
      // ISSUE: explicit reference operation
      // ISSUE: variable of a reference type
      Vector3& local1 = @newAdjustedWorldPosition;
      // ISSUE: explicit reference operation
      double num1 = (^local1).x - (double) newGrid.pfg.terrScale * 0.5;
      // ISSUE: explicit reference operation
      (^local1).x = (__Null) num1;
      // ISSUE: explicit reference operation
      // ISSUE: variable of a reference type
      Vector3& local2 = @newAdjustedWorldPosition;
      // ISSUE: explicit reference operation
      double num2 = (^local2).z - (double) newGrid.pfg.terrScale * 0.5;
      // ISSUE: explicit reference operation
      (^local2).z = (__Null) num2;
      if (this._actualFootprintX % 2 == 1)
      {
        // ISSUE: explicit reference operation
        // ISSUE: variable of a reference type
        Vector3& local3 = @newAdjustedWorldPosition;
        // ISSUE: explicit reference operation
        double num3 = (^local3).x + (double) newGrid.pfg.terrScale * 0.5;
        // ISSUE: explicit reference operation
        (^local3).x = (__Null) num3;
      }
      if (this._actualFootprintY % 2 != 1)
        return;
      // ISSUE: explicit reference operation
      // ISSUE: variable of a reference type
      Vector3& local4 = @newAdjustedWorldPosition;
      // ISSUE: explicit reference operation
      double num4 = (^local4).z + (double) newGrid.pfg.terrScale * 0.5;
      // ISSUE: explicit reference operation
      (^local4).z = (__Null) num4;
    }
  }

  public virtual void RemoveFromPathFindingGrid()
  {
    if (!Object.op_Inequality((Object) this._currentGrid, (Object) null))
      return;
    this._currentGrid.pfg.RemoveObject((object) this);
  }

  public virtual void PlaceOnPathFindingGrid(Vector3 position)
  {
    PathGridForMesh newGrid;
    int gridStartX;
    int gridStartY;
    Vector3 newAdjustedWorldPosition;
    bool validPosition;
    this.FindGridPlacementAtWorldPosition(position, out newGrid, out gridStartX, out gridStartY, out newAdjustedWorldPosition, out validPosition);
    newAdjustedWorldPosition.y = position.y;
    if (Object.op_Equality((Object) newGrid, (Object) null))
      CommonLog.Engine.Error((object) ("Can't find pathfinding grid at " + (object) position));
    this._currentGrid = newGrid;
    this._currentGrid.pfg.PlaceRectangleObject((object) this, gridStartX, gridStartY, this._actualFootprintX, this._actualFootprintY);
  }

  public UIGenericOverhead GetEditOverHead()
  {
    return this._uiEditBuiding;
  }

  public UIGenericOverhead GetOverHead()
  {
    return this._uiBuiding;
  }

  protected GameObjectItemRef GetVisualItemRef(int level)
  {
    BuildingStatsPerLevel buildingStatsPerLevel = ((List<BuildingStatsPerLevel>) this._BuildingDescriptionDB.LevelProgression.Value.StatsPerLevel)[level - 1];
    if (this._TemplateMode || this.IsMoving || buildingStatsPerLevel.CulledVisuals == null)
      return (GameObjectItemRef) buildingStatsPerLevel.Visual;
    switch (this._orientation)
    {
      case BuildingProtocol.Orientation.North:
        return (GameObjectItemRef) buildingStatsPerLevel.CulledVisual90Deg;
      case BuildingProtocol.Orientation.East:
        return (GameObjectItemRef) buildingStatsPerLevel.CulledVisual0Deg;
      case BuildingProtocol.Orientation.South:
        return (GameObjectItemRef) buildingStatsPerLevel.CulledVisual270Deg;
      case BuildingProtocol.Orientation.West:
        return (GameObjectItemRef) buildingStatsPerLevel.CulledVisual180Deg;
      default:
        throw new NotSupportedException();
    }
  }

  protected GameObjectItemRef GetConstructionVisualItemRef()
  {
    BuildingLevelProgression levelProgression = this._BuildingDescriptionDB.LevelProgression.Value;
    switch (this._orientation)
    {
      case BuildingProtocol.Orientation.North:
        return (GameObjectItemRef) levelProgression.ConstructionVisual90Deg;
      case BuildingProtocol.Orientation.East:
        return (GameObjectItemRef) levelProgression.ConstructionVisual0Deg;
      case BuildingProtocol.Orientation.South:
        return (GameObjectItemRef) levelProgression.ConstructionVisual270Deg;
      case BuildingProtocol.Orientation.West:
        return (GameObjectItemRef) levelProgression.ConstructionVisual180Deg;
      default:
        throw new NotSupportedException();
    }
  }

  public void ContextualHighlight(bool contextual, bool mouseOver)
  {
    if (mouseOver)
    {
      foreach (Renderer renderer in (Renderer[]) ((Component) this).GetComponentsInChildren<Renderer>(false))
      {
        if (Object.op_Equality((Object) renderer.get_material().get_shader(), (Object) Building.NormalShader) || Object.op_Equality((Object) renderer.get_material().get_shader(), (Object) Building.OutlineShader))
        {
          renderer.get_material().set_shader(Building.OutlineShader);
          renderer.get_material().SetFloat("_GoodBad", 1f);
        }
      }
    }
    else if (contextual)
    {
      foreach (Renderer renderer in (Renderer[]) ((Component) this).GetComponentsInChildren<Renderer>(false))
      {
        if (Object.op_Equality((Object) renderer.get_material().get_shader(), (Object) Building.NormalShader) || Object.op_Equality((Object) renderer.get_material().get_shader(), (Object) Building.OutlineShader))
        {
          renderer.get_material().set_shader(Building.OutlineShader);
          renderer.get_material().SetFloat("_GoodBad", 0.0f);
        }
      }
    }
    else
    {
      foreach (Renderer renderer in (Renderer[]) ((Component) this).GetComponentsInChildren<Renderer>(false))
      {
        if (Object.op_Equality((Object) renderer.get_material().get_shader(), (Object) Building.OutlineShader))
          renderer.get_material().set_shader(Building.NormalShader);
      }
    }
  }

  public ContextualChatTrigger GetContextualChat()
  {
    return (ContextualChatTrigger) null;
  }

  public override bool IsOwnedByLocalClient()
  {
    if (!Object.op_Inequality((Object) DomainRoom.Instance, (Object) null) || DomainRoom.Instance.RoomOwnerId != NetworkMgr.Instance.PlayerId)
      return base.IsOwnedByLocalClient();
    return true;
  }

  public void OnProximityStateChanged(VisibilityState current)
  {
    if (current == VisibilityState.IN && this._outOfFrustum)
    {
      this._outOfFrustum = false;
    }
    else
    {
      if (current != VisibilityState.OUT || this._outOfFrustum)
        return;
      this._outOfFrustum = true;
      this.BuildingPlaceHolder.DestroyLoaded();
      if (this._displayModel)
        this.DeleteMainBuildingVisuals();
      this.DeleteCursorVisuals();
      this.StateVisualValid = false;
    }
  }

  public bool IsInProximityOfCamera()
  {
    return !this._outOfFrustum;
  }

  public class StateConstructing
  {
    public float TimeLeft = 10f;
    public bool AnimComplete;
    public bool StartedPhase1Anim;
    public bool SpeedUpConstruction;
  }

  public class StateWaitingForInauguration
  {
  }

  public class StateInaugurating
  {
    public bool AnimComplete;
  }

  public class StateUpgrading
  {
    public float _timeLeft = 10f;
    public bool MuteScaffoldSounds;
    public int _phase;
  }

  public class StateWaitingForUpgradeCompletion
  {
    public bool MuteScaffoldSounds;
  }

  public class StateCompleteUpgrade
  {
    public bool AnimComplete;
  }

  public class StateIdle
  {
  }

  public class StateWaitingToCollectReward
  {
    private int _bleh;
  }

  public class StateDamaged
  {
    private int _bleh;
  }

  public class StateRepairing
  {
    private int _bleh;
  }

  public class StateDestruction
  {
    public float _TimeLeft = 5f;
  }

  public class StateSelling
  {
    public float _TimeLeft = 5f;
  }

  protected class ScaffoldsPiece
  {
    public GameObjectItemRef itemToStream;
    public DomainBuildingResHandle pieceHolder;
    public Vector3 position;
    public float rotation;
    public float startInTime;
    public bool StartedPlayingInAnim;
    public float startLoopTime;
    public bool StartedPlayingLoopAnim;
    public float startOutTime;
    public bool StartedPlayingOutAnim;
    public float startUpTime;
    public bool StartedPlayingUpAnim;
    public Animation anim;
  }

  protected class Scaffolds
  {
    public List<Building.ScaffoldsPiece> Pieces = new List<Building.ScaffoldsPiece>();
    public bool AllStreamed;
    public bool Visible;
    public float Time;
    public bool Hiding;
  }

  protected class TempMiniBuilder
  {
    public bool StartedStreaming;
    public bool Streamed;
    public GameObject Worker;
    public bool Visible;
  }

  protected class PlacementCursor
  {
    public DomainBuildingResHandle Cursor = new DomainBuildingResHandle();
    public Color Color = Color.get_green();
  }
}
