﻿// Decompiled with JetBrains decompiler
// Type: Wb.Lpw.Platform.Client.ObjectModule.ObjectProxy
// Assembly: Wb.Lpw.Client, Version=2.13.79.0, Culture=neutral, PublicKeyToken=null
// MVID: 14B98D9F-E3DE-4C32-ACFA-7AC2F99F8DDE
// Assembly location: C:\Users\CGA Computer\Desktop\LEGO Universe Stuff\LOCO Server\Unity Web Player Extractor\Saved Files\LOCO Server.unity3d_unpacked\Wb.Lpw.Client.dll

using System.Collections;
using System.Collections.Generic;
using Wb.Lpw.Platform.Protocol;

namespace Wb.Lpw.Platform.Client.ObjectModule
{
  public class ObjectProxy
  {
    public Dictionary<int, OnObjectOperationResult> m_operationResultHandlers = new Dictionary<int, OnObjectOperationResult>();
    public Dictionary<int, OnObjectOperationResultRaw> m_operationResultRawHandlers = new Dictionary<int, OnObjectOperationResultRaw>();
    public int m_roomId;
    public int m_objectId;
    public string m_objectName;
    protected IObjectHandler m_handler;

    public ObjectProxy(int roomId, int objectId, string objectName)
    {
      this.m_roomId = roomId;
      this.m_objectId = objectId;
      this.m_objectName = objectName;
    }

    public ResultCode SetObjectHandler(IObjectHandler handler)
    {
      this.m_handler = handler;
      return ResultCode.Ok;
    }

    public ResultCode ClearObjectHandler(bool dropPendingOperationResult)
    {
      this.m_handler = (IObjectHandler) null;
      if (dropPendingOperationResult)
        this.m_operationResultHandlers.Clear();
      return ResultCode.Ok;
    }

    public ResultCode AddOperationResultHandler(int invokeId, OnObjectOperationResult resultHandler)
    {
      this.m_operationResultHandlers.Add(invokeId, resultHandler);
      return ResultCode.Ok;
    }

    public ResultCode OnObjectEvent(int objectEventCode, Hashtable eventParams)
    {
      if (this.m_handler == null)
        return ResultCode.Failed;
      this.m_handler.OnObjectEvent(this.m_roomId, this.m_objectId, objectEventCode, eventParams);
      return ResultCode.Ok;
    }

    public ResultCode OnObjectPropertyUpdate(Hashtable properties)
    {
      if (this.m_handler == null)
        return ResultCode.Failed;
      this.m_handler.OnObjectPropertyUpdate(this.m_roomId, this.m_objectId, properties);
      return ResultCode.Ok;
    }

    public ResultCode OnObjectOperationResult(short invocationId, bool isSuccessful, Hashtable returnParams)
    {
      OnObjectOperationResult objectOperationResult = (OnObjectOperationResult) null;
      if (!this.m_operationResultHandlers.TryGetValue((int) invocationId, out objectOperationResult))
        return ResultCode.Failed;
      objectOperationResult(this.m_roomId, this.m_objectId, isSuccessful, returnParams);
      this.m_operationResultHandlers.Remove((int) invocationId);
      return ResultCode.Ok;
    }

    public ResultCode AddOperationResultHandler(int invokeId, OnObjectOperationResultRaw resultHandler)
    {
      this.m_operationResultRawHandlers.Add(invokeId, resultHandler);
      return ResultCode.Ok;
    }

    public ResultCode OnObjectEvent(int objectEventCode, byte[] eventParams)
    {
      if (this.m_handler == null)
        return ResultCode.Failed;
      this.m_handler.OnObjectEvent(this.m_roomId, this.m_objectId, objectEventCode, eventParams);
      return ResultCode.Ok;
    }

    public ResultCode OnObjectOperationResult(short invocationId, bool isSuccessful, byte[] returnParams)
    {
      OnObjectOperationResultRaw operationResultRaw = (OnObjectOperationResultRaw) null;
      if (!this.m_operationResultRawHandlers.TryGetValue((int) invocationId, out operationResultRaw))
        return ResultCode.Failed;
      operationResultRaw(this.m_roomId, this.m_objectId, isSuccessful, returnParams);
      this.m_operationResultHandlers.Remove((int) invocationId);
      return ResultCode.Ok;
    }
  }
}
