Beispiel #1
0
        //---------------------------------------------------------------------
        public Task asyncSaveState()
        {
            if (EtPlayer == null)
            {
                return(TaskDone.Done);
            }

            State = EtPlayer.genEntityData4SaveDb();
            WriteStateAsync();

            return(TaskDone.Done);
        }
Beispiel #2
0
        //---------------------------------------------------------------------
        // Client->Cell的请求
        async Task <EntityData> ICellPlayer.c2sEnterWorld(NewPlayerInfo new_player_info)
        {
            Logger.Info("c2sEnterWorld() GrainId={0}", this.GetPrimaryKey().ToString());

            // 新建角色
            if (EtPlayer == null)
            {
                if (AsyncStream == null)
                {
                    IStreamProvider stream_provider = GetStreamProvider(StringDef.SMSProvider);
                    AsyncStream = stream_provider.GetStream <StreamData>(this.GetPrimaryKey(), "Friend");
                }

                bool  exist     = true;
                ulong player_id = 100;
                //do
                //{
                //    player_id = (ulong)CellApp.Instance.Rd.next(1000000, 9999999);
                //    var grain_playerservice = GF.GetGrain<ICellPlayerService>(0);
                //    exist = await grain_playerservice.playerIdExist(player_id);
                //} while (exist);

                EbLog.Note("-------------------------------");
                EbLog.Note("新创建玩家");
                EbLog.Note("AccountName=" + new_player_info.account_name);
                EbLog.Note("PlayerId=" + player_id);
                EbLog.Note("-------------------------------");

                var et_player_data = new EntityData();
                et_player_data.entity_type                 = typeof(EtPlayer).Name;
                et_player_data.entity_guid                 = new_player_info.et_player_guid;
                et_player_data.list_component              = new List <ComponentData>();
                et_player_data.cache_data                  = new Dictionary <string, object>();
                et_player_data.cache_data["NewPlayer"]     = true;
                et_player_data.cache_data["NewPlayerInfo"] = new_player_info;
                et_player_data.cache_data["NewPlayerId"]   = player_id;
                EtPlayer = EntityMgr.Instance.genEntity <EtPlayer, GrainCellPlayer>(et_player_data, this);
                State    = EtPlayer.genEntityData4SaveDb();
                await WriteStateAsync();
            }

            return(EtPlayer.genEntityData4NetSync((byte)NodeType.Client));
        }