//------------------------------------------------------------------------- public override void update(float elapsed_tm) { if (LogicScene != null) { LogicScene.update(elapsed_tm); } // 更新座位上所有玩家 foreach (var i in AllSeat) { if (i.et_playermirror != null) { i.et_playermirror.update(elapsed_tm); } } while (QueAoIEvent.Count > 0) { var ev_aoi = QueAoIEvent.Dequeue(); DesktopNotify desktop_notify; desktop_notify.id = DesktopNotifyId.PlayerSceneAoIUpdate; desktop_notify.data = EbTool.protobufSerialize <_tAoIEvent>(ev_aoi); StreamData sd = new StreamData(); sd.event_id = StreamEventId.DesktopStreamEvent; sd.param1 = desktop_notify; var grain_desktop = Entity.getUserData <GrainCellDesktop>(); grain_desktop.AsyncStream.OnNextAsync(sd); } }
//------------------------------------------------------------------------- // 玩家离开桌子 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 void broadcast(ref DesktopNotify desktop_notify) { StreamData sd = new StreamData(); sd.event_id = StreamEventId.DesktopStreamEvent; sd.param1 = desktop_notify; var grain_desktop = Entity.getUserData <GrainCellDesktop>(); grain_desktop.AsyncStream.OnNextAsync(sd); }
//------------------------------------------------------------------------- void _broadcastFriendNotify(PlayerFriendNotify friend_notify) { StreamData sd = new StreamData(); sd.event_id = StreamEventId.FriendStreamEvent; sd.param1 = friend_notify; var grain = Entity.getUserData <GrainCellPlayer>(); grain.AsyncStream.OnNextAsync(sd); }
//--------------------------------------------------------------------- public async Task onDesktopStreamEvent(StreamData data) { MethodData notify_data = new MethodData(); notify_data.method_id = MethodType.None; if (string.IsNullOrEmpty(DesktopEtGuid)) { goto End; } switch (data.event_id) { case StreamEventId.DesktopStreamEvent: // 通知成员更新 { var desktop_notify = (DesktopNotify)data.param1; switch (desktop_notify.id) { case DesktopNotifyId.PlayerChat: { var msg_recv = EbTool.protobufDeserialize <ChatMsgRecv>(desktop_notify.data); CoPlayer.CoPlayerChat.s2sRecvChatFromDesktop(msg_recv); } break; default: { notify_data.method_id = MethodType.s2cPlayerDesktopNotify; notify_data.param1 = EbTool.protobufSerialize(desktop_notify); } break; } } break; default: break; } End: if (notify_data.method_id != MethodType.None) { var grain = Entity.getUserData <GrainCellPlayer>(); var grain_player = grain.GF.GetGrain <ICellPlayer>(new Guid(Entity.Guid)); await grain_player.s2sNotify(notify_data); } }
//--------------------------------------------------------------------- public async Task onFriendStreamEvent(StreamData data) { MethodData notify_data = new MethodData(); notify_data.method_id = MethodType.None; switch (data.event_id) { case StreamEventId.FriendStreamEvent: { var friend_notify = (PlayerFriendNotify)data.param1; switch (friend_notify.id) { case PlayerFriendNotifyId.OnFriendLogin: { //var d = EbTool.protobufDeserialize<DesktopNotifyDesktopPreFlopS>(desktop_notify.data); //DesktopNotify dn; //dn.id = DesktopNotifyId.DesktopPreFlop; //dn.data = EbTool.protobufSerialize(desktop_preflop); //notify_data.method_id = MethodType.s2cPlayerDesktopNotify; //notify_data.param1 = EbTool.protobufSerialize(dn); } break; default: { notify_data.method_id = MethodType.s2cPlayerDesktopNotify; notify_data.param1 = EbTool.protobufSerialize(friend_notify); } break; } } break; default: break; } End: if (notify_data.method_id != MethodType.None) { var grain = Entity.getUserData <GrainCellPlayer>(); var grain_player = grain.GF.GetGrain <ICellPlayer>(new Guid(Entity.Guid)); await grain_player.s2sNotify(notify_data); } }
//--------------------------------------------------------------------- // 桌子内聊天广播 public Task s2sDesktopChat(ChatMsgRecv msg) { DesktopNotify desktop_notify; desktop_notify.id = DesktopNotifyId.PlayerChat; desktop_notify.data = EbTool.protobufSerialize <ChatMsgRecv>(msg); 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(TaskDone.Done); }
//------------------------------------------------------------------------- // 玩家进入桌子 public Task <DesktopData> s2sPlayerEnter(DesktopRequestPlayerEnter request_enter, EntityData etdata_playermirror) { byte seat_index = request_enter.seat_index; if (getPlayerCountInSeat() >= DesktopConfigData.seat_num) { // 没有空座位了,观战 seat_index = 255; } if (!isValidSeatIndex(seat_index)) { // 座位索引范围不合法,重新分配空座位 foreach (var i in AllSeat) { if (i.et_playermirror == null) { seat_index = i.index; break; } } } if (isValidSeatIndex(seat_index) && AllSeat[seat_index].et_playermirror != null) { // 座位上已经有人坐了,重新分配空座位 foreach (var i in AllSeat) { if (i.et_playermirror == null) { seat_index = i.index; break; } } } var et_playermirror = EntityMgr.genEntity <EtPlayerMirror, Entity>(etdata_playermirror, Entity); var co_actormirror = et_playermirror.getComponent <CellActorMirror <DefActorMirror> >(); var co_ai = et_playermirror.getComponent <CellActorMirrorAi <DefActorMirrorAi> >(); byte actorid_indesktop = _genPlayerId(); co_actormirror.Def.PropActorIdInDesktop.set(actorid_indesktop); EbLog.Note("CellDesktop.s2sPlayerEnter() PlayerEtGuid=" + et_playermirror.Guid); MapAllPlayer1[actorid_indesktop] = et_playermirror; MapAllPlayer[et_playermirror.Guid] = et_playermirror; if (isValidSeatIndex(seat_index)) { AllSeat[seat_index].et_playermirror = et_playermirror; } co_actormirror.onEnterDesktop(seat_index); // 更新DesktopInfo refreshDesktopInfo(); // 广播玩家进入桌子 DesktopNotify desktop_notify; desktop_notify.id = DesktopNotifyId.PlayerEnter; desktop_notify.data = EbTool.protobufSerialize <EntityData>(et_playermirror.genEntityData4All()); StreamData sd = new StreamData(); sd.event_id = StreamEventId.DesktopStreamEvent; sd.param1 = desktop_notify; var grain_desktop = Entity.getUserData <GrainCellDesktop>(); grain_desktop.AsyncStream.OnNextAsync(sd); // 通知场景玩家坐下 LogicScene.scenePlayerEnter(actorid_indesktop, 1, "aabb", false, -1, TbDataTurret.TurretType.NormalTurret); float player_rate = 1.0f;// mEtDesktopPumping.getPlayerUpgradeRate();// 抽水率 LogicScene.scenePlayerRateChanged(1, player_rate); DesktopData desktop_data = _getDesktopData(); return(Task.FromResult(desktop_data)); }