예제 #1
0
        private IEnumerator CreateRoleCoroutine()
        {
            using (var blockingLayer = new BlockingLayerHelper(0))
            {
                var _msg = NetManager.Instance.CreateCharacter(PlayerDataManager.Instance.ServerId, DataModel.CreateType,
                                                               DataModel.CreateName);
                yield return(_msg.SendAndWaitUntilDone());

                if (_msg.State == MessageState.Reply)
                {
                    if (_msg.ErrorCode == (int)ErrorCodes.OK)
                    {
                        var _list = PlayerDataManager.Instance.CharacterLists;
                        _list = _msg.Response.Info;
                        // RefreshDate(msg.Response.Info, msg.Response.SelectId);
                        //新需求,创建完人物直接进入游戏
                        GameLogic.PlayFirstEnterGameCG = 1;
                        var _role           = _list[_list.Count - 1];
                        var _SelectedRoleId = _role.CharacterId;

                        var _serverName = PlayerDataManager.Instance.ServerName;
                        var _serverId   = PlayerDataManager.Instance.ServerId;
                        PlayerDataManager.Instance.CharacterFoundTime = Extension.FromServerBinary(_msg.Response.CharacterFoundTime);
                        var _ts   = PlayerDataManager.Instance.CharacterFoundTime - DateTime.Parse("1970-1-1");
                        var _time = (int)_ts.TotalSeconds;
                        PlatformHelper.CollectionCreateRoleDataForKuaifa(_SelectedRoleId.ToString(), DataModel.CreateName,
                                                                         _serverId.ToString(), _serverName, _time.ToString());

                        {
                            //这里实现给主角名字赋值,为了后面对话时用
                            PlayerDataManager.Instance.PlayerDataModel.CharacterBase.Name = _role.Name;
                        }
#if UNITY_EDITOR
                        var _skip = true;
#else
                        bool _skip = true;
                        //bool skip = list.Count>1;
#endif
                        //播放创建角色时的CG

                        /*
                         * if (0 == DataModel.CreateType)
                         * {
                         * PlayCG.Instance.PlayCGFile("Video/jianshi.txt",
                         *  () => { NetManager.Instance.CallEnterGame(SelectedRoleId); }, skip, false);
                         * }
                         * else if (1 == DataModel.CreateType)
                         * {
                         * PlayCG.Instance.PlayCGFile("Video/fashi.txt",
                         *  () => { NetManager.Instance.CallEnterGame(SelectedRoleId); }, skip, false);
                         * }
                         * else if (2 == DataModel.CreateType)
                         * {
                         * PlayCG.Instance.PlayCGFile("Video/gongshou.txt",
                         *  () => { NetManager.Instance.CallEnterGame(SelectedRoleId); }, skip, false);
                         * }
                         * else
                         * {
                         * NetManager.Instance.CallEnterGame(SelectedRoleId);
                         * }*/
                        NetManager.Instance.CallEnterGame(_SelectedRoleId);
                    }
                    else
                    {
                        if (_msg.ErrorCode == (int)ErrorCodes.Error_NAME_IN_USE)
                        {
                            if (GameSetting.Instance.ReviewState == 1)
                            {
                                // 防止无限递归
                                if (RandomNameCount > 100)
                                {
                                    yield break;
                                }

                                RandomNameCount++;
                                DataModel.CreateType = UnityEngine.Random.Range(0, 3);
                                var actorTable = Table.GetActor(DataModel.CreateType);
                                DataModel.CreateName = StringConvert.GetRandomName(actorTable.Sex);
                                DataModel.CreateName = DataModel.CreateName.Trim();

                                NetManager.Instance.StartCoroutine(CreateRoleCoroutine());
                            }
                            else
                            {
                                var _dicId = _msg.ErrorCode + 200000000;
                                var _tbDic = Table.GetDictionary(_dicId);
                                var _info  = "";
                                _info = _tbDic.Desc[GameUtils.LanguageIndex];
                                UIManager.Instance.ShowMessage(MessageBoxType.Ok, _info, "");
                            }
                        }
                        else
                        {
                            UIManager.Instance.ShowNetError(_msg.ErrorCode);
                        }
                    }
                }
                else
                {
                    Logger.Debug("CreateCharacter.................." + _msg.State);
                }
            }
        }
예제 #2
0
    public IEnumerator CreateCharacterCoroutine()
    {
        using (var blockingLayer = new BlockingLayerHelper(0))
        {
            var msg = NetManager.Instance.CreateCharacter(PlayerDataManager.Instance.ServerId, DataModel.CreateType,
                                                          DataModel.CreateName);
            yield return(msg.SendAndWaitUntilDone());

            if (msg.State == MessageState.Reply)
            {
                if (msg.ErrorCode == (int)ErrorCodes.OK)
                {
                    var list = PlayerDataManager.Instance.CharacterLists;
                    list = msg.Response.Info;
                    // RefreshDate(msg.Response.Info, msg.Response.SelectId);
                    //新需求,创建完人物直接进入游戏
                    GameLogic.PlayFirstEnterGameCG = 1;
                    var role           = list[list.Count - 1];
                    var SelectedRoleId = role.CharacterId;

                    var serverName = PlayerDataManager.Instance.ServerName;
                    var serverId   = PlayerDataManager.Instance.ServerId;
                    PlayerDataManager.Instance.CharacterFoundTime = Extension.FromServerBinary(msg.Response.CharacterFoundTime);
                    var ts   = PlayerDataManager.Instance.CharacterFoundTime - DateTime.Parse("1970-1-1");
                    var time = (int)ts.TotalSeconds;
                    PlatformHelper.CollectionCreateRoleDataForKuaifa(SelectedRoleId.ToString(), DataModel.CreateName,
                                                                     serverId.ToString(), serverName, time.ToString());

                    {
//这里实现给主角名字赋值,为了后面对话时用
                        PlayerDataManager.Instance.PlayerDataModel.CharacterBase.Name = role.Name;
                    }
#if UNITY_EDITOR
                    var skip = true;
#else
                    bool skip = true;
                    //bool skip = list.Count>1;
#endif
                    //播放创建角色时的CG

                    /*
                     * if (0 == DataModel.CreateType)
                     * {
                     * PlayCG.Instance.PlayCGFile("Video/jianshi.txt",
                     * () => { NetManager.Instance.CallEnterGame(SelectedRoleId); }, skip, false);
                     * }
                     * else if (1 == DataModel.CreateType)
                     * {
                     * PlayCG.Instance.PlayCGFile("Video/fashi.txt",
                     * () => { NetManager.Instance.CallEnterGame(SelectedRoleId); }, skip, false);
                     * }
                     * else if (2 == DataModel.CreateType)
                     * {
                     * PlayCG.Instance.PlayCGFile("Video/gongshou.txt",
                     * () => { NetManager.Instance.CallEnterGame(SelectedRoleId); }, skip, false);
                     * }
                     * else
                     * {
                     * NetManager.Instance.CallEnterGame(SelectedRoleId);
                     * }*/
                    NetManager.Instance.CallEnterGame(SelectedRoleId);
                }
                else
                {
                    if (msg.ErrorCode == (int)ErrorCodes.Error_NAME_IN_USE)
                    {
                        var dicId = msg.ErrorCode + 200000000;
                        var tbDic = Table.GetDictionary(dicId);
                        var info  = "";
                        info = tbDic.Desc[GameUtils.LanguageIndex];
                        UIManager.Instance.ShowMessage(MessageBoxType.Ok, info, "");
                    }
                    else
                    {
                        UIManager.Instance.ShowNetError(msg.ErrorCode);
                    }
                }
            }
            else
            {
                Logger.Debug("CreateCharacter.................." + msg.State);
            }
        }
    }