//------------------------------------------------------------------------- // 玩家离开桌子 public Task <DesktopPlayerLeaveInfo> s2sPlayerLeave(string player_etguid) { EbLog.Note("CellDesktop.s2sPlayerLeave() PlayerEtGuid=" + player_etguid); DesktopPlayerLeaveInfo leave_info = new DesktopPlayerLeaveInfo(); // 玩家不在座位上 SeatInfo seat_cur = getSeat(player_etguid); if (seat_cur == null) { goto End; } End: CellActorMirror <DefActorMirror> co_playermirror = null; Entity et_playermirror = null; // 清空座位 if (MapAllPlayer.TryGetValue(player_etguid, out et_playermirror)) { co_playermirror = et_playermirror.getComponent <CellActorMirror <DefActorMirror> >(); leave_info.stack = co_playermirror.Def.PropGold.get(); byte actorid_indesktop = co_playermirror.Def.PropActorIdInDesktop.get(); _freePlayerId(actorid_indesktop); et_playermirror.close(); MapAllPlayer.Remove(player_etguid); MapAllPlayer1.Remove(actorid_indesktop); } foreach (var i in AllSeat) { if (i.et_playermirror != null && i.et_playermirror.Guid == player_etguid) { et_playermirror = i.et_playermirror; i.et_playermirror = null; } } // 更新DesktopInfo refreshDesktopInfo(); // 广播玩家离开桌子 { DesktopNotify desktop_notify; desktop_notify.id = DesktopNotifyId.PlayerLeave; desktop_notify.data = EbTool.protobufSerialize <string>(player_etguid); StreamData sd = new StreamData(); sd.event_id = StreamEventId.DesktopStreamEvent; sd.param1 = desktop_notify; var grain_desktop = Entity.getUserData <GrainCellDesktop>(); grain_desktop.AsyncStream.OnNextAsync(sd); } return(Task.FromResult(leave_info)); }
//------------------------------------------------------------------------- public override void init() { Init = false; CacheDesktopKey = "CacheDesktopData_" + Entity.Guid; DesktopConfigData = new DesktopConfigData(); DesktopConfigData.desktop_etguid = Entity.Guid; DesktopConfigData.seat_num = 6; DesktopConfigData.is_vip = false; DesktopConfigData.desktop_waitwhile_tm = 60; MapAllPlayer1 = new Dictionary <uint, Entity>(); MapAllPlayer = new Dictionary <string, Entity>(); byte index = 0; AllSeat = new SeatInfo[DesktopConfigData.seat_num]; foreach (var i in AllSeat) { SeatInfo seat_info = new SeatInfo(); seat_info.index = index; seat_info.et_player_rpcid = 0; seat_info.et_playermirror = null; AllSeat[index] = seat_info; index++; } DesktopInfo = new DesktopInfo(); DesktopInfo.desktop_etguid = Entity.Guid; DesktopInfo.seat_num = 6; DesktopInfo.desktop_tableid = 1; DesktopInfo.is_vip = false; DesktopInfo.list_seat_player = new List <DesktopPlayerInfo>(); DesktopInfo.all_player_num = 0; DesktopInfo.seat_player_num = 0; QueAoIEvent = new Queue <_tAoIEvent>(); QuePlayerId = new Queue <byte>(); MaxPlayerId = 0; for (int i = 0; i < 50; i++) { QuePlayerId.Enqueue(++MaxPlayerId); } TbDataRoom._eRoomType room_type = TbDataRoom._eRoomType.RT_Tenfold; bool fish_mustdie = true; bool is_single = false; float pumping_rate = 1f; string path_fishlord = Path.Combine(ServerPath.getPathMediaRoot(), "Fishing\\FishLord\\"); string path_route = Path.Combine(ServerPath.getPathMediaRoot(), "Fishing\\Route\\"); ILogicListener listener = new LogicListener(this); LogicScene = new CLogicScene(); LogicScene.create(1, 1.0f, is_single, fish_mustdie, listener, pumping_rate, _getRateList(room_type), CellApp.Instance.jsonCfg.json_packet_list, CellApp.Instance.jsonCfg.route_json_packet_list); }
//--------------------------------------------------------------------- public void onPlayerActionWaitingTimeEnd(string player_etguid) { SeatInfo seat_cur = getSeat(player_etguid); if (seat_cur == null) { return; } EbLog.Note("CellDesktop.onPlayerActionWaitingTimeEnd() PlayerEtGuid=" + player_etguid); }
//------------------------------------------------------------------------- public SeatInfo getNextSeat(string et_player_guid_cur) { SeatInfo seat_cur = null; foreach (var i in AllSeat) { if (i.et_playermirror != null && i.et_playermirror.Guid == et_player_guid_cur) { seat_cur = i; break; } } if (seat_cur == null) { return(null); } return(getNextSeat(seat_cur.index)); }
//--------------------------------------------------------------------- // 初始化桌子信息 public Task s2sSetupDesktop(DesktopInfo desktop_info) { var tb_desktop = EbDataMgr.Instance.getData <TbDataDesktopInfo>(DesktopInfo.desktop_tableid); if (tb_desktop == null) { EbLog.Error("CellDesktop.s2sSetupDesktop() Error DesktopTableId=" + DesktopInfo.desktop_tableid); return(TaskDone.Done); } Init = true; DesktopInfo.seat_num = desktop_info.seat_num; DesktopInfo.desktop_tableid = desktop_info.desktop_tableid; DesktopInfo.is_vip = desktop_info.is_vip; DesktopInfo.all_player_num = desktop_info.all_player_num; DesktopInfo.seat_player_num = desktop_info.seat_player_num; DesktopInfo.list_seat_player.Clear(); DesktopConfigData.is_vip = DesktopInfo.is_vip; byte index = 0; AllSeat = new SeatInfo[DesktopConfigData.seat_num]; foreach (var i in AllSeat) { SeatInfo seat_info = new SeatInfo(); seat_info.index = index; seat_info.et_playermirror = null; AllSeat[index] = seat_info; index++; } string data = EbTool.jsonSerialize(DesktopInfo); //DbClientCouchbase.Instance.asyncSave(CacheDesktopKey, data, TimeSpan.FromSeconds(15.0)); return(TaskDone.Done); }
//------------------------------------------------------------------------- // 桌子通知 void s2cPlayerDesktopNotify(DesktopNotify desktop_notify) { switch (desktop_notify.id) { case DesktopNotifyId.DesktopInit: // 桌子初始化 { EbLog.Note("ClientPlayerDesktop.s2cPlayerDesktopNotify() DesktopInit"); CoPlayer.CoPlayerLobby.hideLobby(); clearDesktop(); var desktop_data = EbTool.protobufDeserialize <DesktopData>(desktop_notify.data); DesktopConfigData = desktop_data.desktop_cfg_data; //UiMbPlayDesktop ui_desk = UiMgr.Instance.createUi<UiMbPlayDesktop>(_eUiLayer.Background); //ui_desk.setDeskInfo(this, 60f); byte index = 0; AllSeat = new SeatInfo[DesktopConfigData.seat_num]; foreach (var i in AllSeat) { SeatInfo seat_info = new SeatInfo(); seat_info.index = index; seat_info.et_playermirror = null; AllSeat[index] = seat_info; index++; } EntityData me_data = desktop_data.list_actormirror.Find((EntityData entity_data) => { return(entity_data.entity_guid.Equals(CoPlayer.Entity.Guid)); }); _initActorMirror(me_data); foreach (var i in desktop_data.list_actormirror) { if (i.entity_guid.Equals(CoPlayer.Entity.Guid)) { continue; } _initActorMirror(i); } var co_me = MeMirror.getComponent <ClientActorMirror <DefActorMirror> >(); byte me_id = co_me.Def.PropActorIdInDesktop.get(); RenderListener listener = new RenderListener(this); Scene = new CRenderScene(); //var loading = UiMgr.Instance.createUi<UiMbLoading>(_eUiLayer.Loading); //Scene.onSceneLoading = loading.setLoadProgress;//null;//ui_mgr.getLoading().setRateOfProgress; //Scene.create(mMyPlayerId, mbSingle, false, listener, "RenderSceneConfigure.json", // new JsonPacketReader("Media/Fishing/FishLord/").readJsonPacketList(), // new JsonPacketReader("Media/Fishing/Route/").readRouteJsonPacketList()); } break; case DesktopNotifyId.PlayerSceneAction: // 玩家场景操作 { var vec_param = EbTool.protobufDeserialize <List <string> >(desktop_notify.data); if (Scene != null) { Scene.sceneOnRecvFromLogic(vec_param); } } break; case DesktopNotifyId.PlayerSceneAoIUpdate: // 玩家场景广播 { var ev_aoi = EbTool.protobufDeserialize <_tAoIEvent>(desktop_notify.data); if (Scene != null && Init) { Scene.sceneOnRecvAoIFromLogic(ev_aoi.vec_param); } } break; case DesktopNotifyId.PlayerChat: // 玩家聊天广播 { if (string.IsNullOrEmpty(DesktopConfigData.desktop_etguid)) { return; } var msg_recv = EbTool.protobufDeserialize <ChatMsgRecv>(desktop_notify.data); Entity et_playermirror = null; MapEtActorMirrorByGuid.TryGetValue(msg_recv.et_player_guid_send, out et_playermirror); if (et_playermirror != null) { var co_playermirror = et_playermirror.getComponent <ClientActorMirror <DefActorMirror> >(); co_playermirror.desktopChat(msg_recv); } } break; case DesktopNotifyId.PlayerEnter: // 玩家进入桌子 { if (string.IsNullOrEmpty(DesktopConfigData.desktop_etguid)) { return; } EntityData et_playermirror_data = EbTool.protobufDeserialize <EntityData>(desktop_notify.data); if (MapEtActorMirrorByGuid.ContainsKey(et_playermirror_data.entity_guid)) { return; } var et_playermirror = EntityMgr.genEntity <EtPlayerMirror, Entity>(et_playermirror_data, Entity); var co_actormirror = et_playermirror.getComponent <ClientActorMirror <DefActorMirror> >(); MapEtActorMirrorByGuid[et_playermirror.Guid] = et_playermirror; //byte seat_index = co_actormirror.Def.mPropSeatIndex.get(); //if (isValidSeatIndex(seat_index)) //{ // AllSeat[seat_index].et_playermirror = et_playermirror; //} EbLog.Note("ClientPlayerDesktop.s2cPlayerDesktopNotify() PlayerEnter PlayerEtGuid=" + et_playermirror.Guid); } break; case DesktopNotifyId.PlayerLeave: // 玩家离开桌子 { if (string.IsNullOrEmpty(DesktopConfigData.desktop_etguid)) { return; } string player_et_guid = EbTool.protobufDeserialize <string>(desktop_notify.data); EbLog.Note("ClientPlayerDesktop.s2cPlayerDesktopNotify() PlayerLeave PlayerEtGuid=" + player_et_guid); Entity et_playermirror = null; if (MapEtActorMirrorByGuid.TryGetValue(player_et_guid, out et_playermirror)) { var co_actormirror = et_playermirror.getComponent <ClientActorMirror <DefActorMirror> >(); MapEtActorMirrorByGuid.Remove(player_et_guid); foreach (var i in AllSeat) { if (i.et_playermirror != null && i.et_playermirror.Guid == player_et_guid) { i.et_playermirror = null; break; } } et_playermirror.close(); } } break; case DesktopNotifyId.PlayerOb: // 玩家Ob { if (string.IsNullOrEmpty(DesktopConfigData.desktop_etguid)) { return; } string player_etguid = EbTool.protobufDeserialize <string>(desktop_notify.data); EbLog.Note("ClientPlayerDesktop.s2cPlayerDesktopNotify() PlayerOb PlayerEtGuid=" + player_etguid); Entity et_playermirror = null; if (MapEtActorMirrorByGuid.TryGetValue(player_etguid, out et_playermirror)) { var co_actormirror = et_playermirror.getComponent <ClientActorMirror <DefActorMirror> >(); co_actormirror.playerOb(); } } break; case DesktopNotifyId.PlayerSitdown: // 玩家坐下 { if (string.IsNullOrEmpty(DesktopConfigData.desktop_etguid)) { return; } var sitdown_data = EbTool.protobufDeserialize <PlayerSitdownData>(desktop_notify.data); EbLog.Note("ClientPlayerDesktop.s2cPlayerDesktopNotify() PlayerSitdown PlayerEtGuid=" + sitdown_data.player_etguid); Entity et_playermirror = null; if (MapEtActorMirrorByGuid.TryGetValue(sitdown_data.player_etguid, out et_playermirror)) { var co_actormirror = et_playermirror.getComponent <ClientActorMirror <DefActorMirror> >(); co_actormirror.playerSitdown(sitdown_data.seat_index, sitdown_data.stack, sitdown_data.state); } } break; case DesktopNotifyId.PlayerWaitWhile: // 玩家暂离 { if (string.IsNullOrEmpty(DesktopConfigData.desktop_etguid)) { return; } var waitwhile_data = EbTool.protobufDeserialize <PlayerWaitWhileData>(desktop_notify.data); EbLog.Note("ClientPlayerDesktop.s2cPlayerDesktopNotify() PlayerWaitWhile PlayerEtGuid=" + waitwhile_data.player_etguid); Entity et_playermirror = null; if (MapEtActorMirrorByGuid.TryGetValue(waitwhile_data.player_etguid, out et_playermirror)) { var co_actormirror = et_playermirror.getComponent <ClientActorMirror <DefActorMirror> >(); co_actormirror.playerWaitWhile(waitwhile_data.wait_while_tm); } } break; case DesktopNotifyId.PlayerReturn: // 玩家返回 { if (string.IsNullOrEmpty(DesktopConfigData.desktop_etguid)) { return; } var return_data = EbTool.protobufDeserialize <PlayerReturnData>(desktop_notify.data); EbLog.Note("ClientPlayerDesktop.s2cPlayerDesktopNotify() PlayerReturn PlayerEtGuid=" + return_data.player_etguid); Entity et_playermirror = null; if (MapEtActorMirrorByGuid.TryGetValue(return_data.player_etguid, out et_playermirror)) { var co_actormirror = et_playermirror.getComponent <ClientActorMirror <DefActorMirror> >(); co_actormirror.playerReturn(return_data.stack, return_data.state); } } break; default: break; } }