Exemplo n.º 1
0
    private IEnumerator SendCityOptRequestCoroutine(CityOperationType opt,
                                                    int buildingIdx,
                                                    List <int> param)
    {
        using (new BlockingLayerHelper(0))
        {
            var array = new Int32Array();
            if (null != param)
            {
                {
                    var __list7      = param;
                    var __listCount7 = __list7.Count;
                    for (var __i7 = 0; __i7 < __listCount7; ++__i7)
                    {
                        var value = __list7[__i7];
                        {
                            array.Items.Add(value);
                        }
                    }
                }
            }

            var msg = NetManager.Instance.CityOperationRequest((int)opt, buildingIdx, array);
            yield return(msg.SendAndWaitUntilDone());

            if (msg.State != MessageState.Reply)
            {
                Logger.Debug("SendBuildRequestCoroutine:MessageState.Timeout");
                yield break;
            }

            if (msg.ErrorCode != (int)ErrorCodes.OK)
            {
                var errorCode = (ErrorCodes)msg.ErrorCode;
                switch (errorCode)
                {
                case ErrorCodes.Error_LevelNoEnough:
                {
                    EventDispatcher.Instance.DispatchEvent(new ShowUIHintBoard(200000108));
                }
                break;

                case ErrorCodes.Error_ResNoEnough:
                {
                    EventDispatcher.Instance.DispatchEvent(new ShowUIHintBoard(200002002));
                }
                break;

                case ErrorCodes.Error_BuildCountMax:
                {
                    EventDispatcher.Instance.DispatchEvent(new ShowUIHintBoard(200002801));
                }
                break;

                case ErrorCodes.Error_NeedCityLevelMore:
                {
                    EventDispatcher.Instance.DispatchEvent(new ShowUIHintBoard(200002803));
                }
                break;

                case ErrorCodes.Error_CityCanotBuildMore:
                {
                    EventDispatcher.Instance.DispatchEvent(new ShowUIHintBoard(300113));
                }
                break;

                default:
                    UIManager.Instance.ShowNetError(msg.ErrorCode);
                    break;
                }
                Logger.Debug("SendBuildRequestCoroutine error=[{0}]", msg.ErrorCode);

                EventDispatcher.Instance.DispatchEvent(new UIEvent_CityUpdateBuilding(buildingIdx));

                yield break;
            }
            switch (opt)
            {
            case CityOperationType.BUILD:
            {
                PlatformHelper.Event("city", "Build");
                //EventDispatcher.Instance.DispatchEvent(new ShowUIHintBoard(300108));
            }
            break;

            case CityOperationType.UPGRADE:
            {
                PlatformHelper.Event("city", "Upgrade");
                EventDispatcher.Instance.DispatchEvent(new UIEvent_OnCityBuildingOptEvent(buildingIdx, opt));
                //EventDispatcher.Instance.DispatchEvent(new ShowUIHintBoard(300107));
            }
            break;

            case CityOperationType.DESTROY:
            {
                //EventDispatcher.Instance.DispatchEvent(new ShowUIHintBoard("Destroy Ok"));

                var e          = new CityBuildingLevelupEvent(buildingIdx);
                var tbBuilding = Table.GetBuilding(GetBuildingByAreaId(buildingIdx).TypeId);
                e.HomeExp = Table.GetBuilding(tbBuilding.RemovedBuildID).GetMainHouseExp;
                EventDispatcher.Instance.DispatchEvent(e);
            }
            break;

            case CityOperationType.ASSIGNPET:
            case CityOperationType.ASSIGNPETINDEX:
            {
                EventDispatcher.Instance.DispatchEvent(new UIEvent_CityAssignPetEvent(buildingIdx));
            }
            break;
            }
        }
    }
Exemplo n.º 2
0
 //发送建筑请求
 public void SendCityOptRequest(CityOperationType opt, int buildingIdx, List <int> param = null)
 {
     NetManager.Instance.StartCoroutine(SendCityOptRequestCoroutine(opt, buildingIdx, param));
 }