//On leave is also called when player is inside a room or got disconnected public override void OnLeave(ILeaveGameCallInfo info) { base.OnLeave(info); m_InfoRoom.I_NumberOfPlayers--; if (m_InfoRoom.I_NoOfClientReady >= 0) { m_InfoRoom.I_NoOfClientReady--; } int numberPlayerCounter = m_InfoRoom.I_NumberOfPlayers - 1; if ((m_InfoRoom.I_NoOfClientReady < numberPlayerCounter) || (m_InfoRoom.I_NoOfClientReady == 0 && numberPlayerCounter == 0)) { PluginHost.BroadcastEvent(target: ReciverGroup.Others, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, null }, { 254, 0 } }, evCode: (byte)MyOwnEventCode.S2C_Not_ReadyToStart, cacheOp: 0); } }
/// <summary> /// Sync player to current game state /// </summary> /// <param name="info"></param> protected virtual void SyncPlayer(IJoinGameCallInfo info) { PluginHost.LogError("Sync player" + info.ActorNr); PluginHost.BroadcastEvent(new List <int> { info.ActorNr }, 0, (byte)Event.GameStart, new Dictionary <byte, object>() { { (byte)0, board.Hight }, { (byte)1, board.Width }, { 2, board.MineCount } }, CacheOperations.DoNotCache); foreach (Dictionary <byte, object> dic in board.AllReveald()) { PluginHost.BroadcastEvent(new List <int> { info.ActorNr }, 0, (byte)Event.SyncFields, dic, CacheOperations.DoNotCache); } foreach (Dictionary <byte, object> dic in board.AllFlags()) { PluginHost.BroadcastEvent(new List <int> { info.ActorNr }, 0, (byte)Event.SyncFlags, dic, CacheOperations.DoNotCache); } }
public override void OnRaiseEvent(IRaiseEventCallInfo info) { try { base.OnRaiseEvent(info); } catch (Exception e) { this.PluginHost.BroadcastErrorInfoEvent(e.ToString(), info); return; } switch ((MyOwnEventCode)info.Request.EvCode) { case MyOwnEventCode.C2S_RequestRoomID: { //Broadcast back to the requesting client PluginHost.BroadcastEvent(recieverActors: new List <int> { info.ActorNr }, senderActor: 0, data: new Dictionary <byte, object>() { { (byte)245, m_InfoRoom.I_RoomNumber }, { 254, 0 } }, evCode: (byte)MyOwnEventCode.S2C_SendRoomID, cacheOp: 0); } break; case MyOwnEventCode.C2S_InformSuccessHost: { // send the enviro level index and level index stored in info.Request.Data to other clients //Broadcast back to other clients except master client PluginHost.BroadcastEvent(target: ReciverGroup.Others, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, info.Request.Data }, { 254, 0 } }, evCode: (byte)MyOwnEventCode.S2C_InformSuccessHost, cacheOp: 0); } break; case MyOwnEventCode.C2S_Ready: { m_InfoRoom.I_NoOfClientReady++; //Broadcast to other clients (except the sender client) PluginHost.BroadcastEvent(target: ReciverGroup.Others, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, info.Request.Data }, { 254, 0 } }, evCode: (byte)MyOwnEventCode.S2C_Ready, cacheOp: 0); //when total number of players excluding the master client equals or greater to the number of normal client ready to start the game //send a message to the master client to inform him that he can start the game. if (m_InfoRoom.I_NumberOfPlayers - 1 >= m_InfoRoom.I_NoOfClientReady) { PluginHost.BroadcastEvent(target: ReciverGroup.Others, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, null }, { 254, 0 } }, evCode: (byte)MyOwnEventCode.S2C_ReadyToStart, cacheOp: 0); } } break; case MyOwnEventCode.C2S_UnReady: { m_InfoRoom.I_NoOfClientReady--; PluginHost.BroadcastEvent(target: ReciverGroup.Others, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, info.Request.Data }, { 254, 0 } }, evCode: (byte)MyOwnEventCode.S2C_UnReady, cacheOp: 0); //Number of clients is lesser than the total number of players excluding the master client , indicate not all the players are ready to start the game if (m_InfoRoom.I_NoOfClientReady < m_InfoRoom.I_NumberOfPlayers - 1) { PluginHost.BroadcastEvent(target: ReciverGroup.Others, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, null }, { 254, 0 } }, evCode: (byte)MyOwnEventCode.S2C_Not_ReadyToStart, cacheOp: 0); } } break; case MyOwnEventCode.C2S_LeaveWaitingRoom: { //to all clients PluginHost.BroadcastEvent(target: ReciverGroup.All, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, null }, { 254, 0 } }, evCode: (byte)MyOwnEventCode.S2C_LeaveWaitingRoom, cacheOp: 0); } break; case MyOwnEventCode.C2S_Request_To_SpawnPlayers: { I_PlayerGoCount++; if (I_PlayerGoCount >= m_InfoRoom.I_NumberOfPlayers) { //broadcast back too all clients PluginHost.BroadcastEvent(target: ReciverGroup.All, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, info.Request.Data }, { 254, 0 } }, evCode: (byte)MyOwnEventCode.S2C_Request_To_SpawnPlayers, cacheOp: 0); } } break; case MyOwnEventCode.C2S_Anchor_Resolved_Success: { m_InfoRoom.I_NoOfSuccessfulResolved++; //When the number of successful anchors resolved is greater or equal to the total //number of clients (excluding the master client) if (m_InfoRoom.I_NoOfSuccessfulResolved >= m_InfoRoom.I_NumberOfPlayers - 1) { //broadcast back to all clients that they can start the game PluginHost.BroadcastEvent(target: ReciverGroup.All, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, null }, { 254, 0 } }, evCode: (byte)MyOwnEventCode.S2C_Anchor_Resolved_Success, cacheOp: 0); } } break; case MyOwnEventCode.C2S_Start_LoadingScreen: { PluginHost.BroadcastEvent(target: ReciverGroup.All, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, null }, { 254, 0 } }, evCode: (byte)MyOwnEventCode.S2C_Start_LoadingScreen, cacheOp: 0); } break; case MyOwnEventCode.C2S_InformFailHost: { //inform others about the failure to host PluginHost.BroadcastEvent(target: ReciverGroup.Others, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, null }, { 254, 0 } }, evCode: (byte)MyOwnEventCode.S2C_InformFailHost, cacheOp: 0); } break; case MyOwnEventCode.C2S_InfoAttemptToHost: { PluginHost.BroadcastEvent(target: ReciverGroup.Others, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, null }, { 254, 0 } }, evCode: (byte)MyOwnEventCode.S2C_InfoAttemptToHost, cacheOp: 0); } break; case MyOwnEventCode.C2S_LeftRoom: { PluginHost.BroadcastEvent(target: ReciverGroup.Others, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, info.Request.Data }, { 254, 0 } }, evCode: (byte)MyOwnEventCode.S2C_LeftRoom, cacheOp: 0); } break; case MyOwnEventCode.C2S_JoinedWaitingRoom: { PluginHost.BroadcastEvent(target: ReciverGroup.Others, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, info.Request.Data }, { 254, 0 } }, evCode: (byte)MyOwnEventCode.S2C_JoinedWaitingRoom, cacheOp: 0); } break; case MyOwnEventCode.C2S_MasterClientSwitchedInWaitngRoom: { m_InfoRoom.I_NoOfClientReady = 0; } break; case MyOwnEventCode.C2S_OneOftheClientWon: { PluginHost.BroadcastEvent(target: ReciverGroup.All, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, info.Request.Data }, { 254, 0 } }, evCode: (byte)MyOwnEventCode.S2C_OneOftheClientWon, cacheOp: 0); } break; case MyOwnEventCode.C2S_OneOftheClientLose: { PluginHost.BroadcastEvent(target: ReciverGroup.All, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, info.Request.Data }, { 254, 0 } }, evCode: (byte)MyOwnEventCode.S2C_OneOftheClientLose, cacheOp: 0); } break; case MyOwnEventCode.C2S_DestroyMapTile: { PluginHost.BroadcastEvent(target: ReciverGroup.Others, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, info.Request.Data }, { 254, 0 } }, evCode: (byte)MyOwnEventCode.S2C_DestroyMapTile, cacheOp: 0); } break; case MyOwnEventCode.C2S_StepOnTile: { PluginHost.BroadcastEvent(target: ReciverGroup.Others, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, info.Request.Data }, { 254, 0 } }, evCode: (byte)MyOwnEventCode.S2C_StepOnTile, cacheOp: 0); } break; case MyOwnEventCode.C2S_EnterOnTile: { PluginHost.BroadcastEvent(target: ReciverGroup.Others, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, info.Request.Data }, { 254, 0 } }, evCode: (byte)MyOwnEventCode.S2C_EnterOnTile, cacheOp: 0); } break; case MyOwnEventCode.C2S_InteractOnTile: { PluginHost.BroadcastEvent(target: ReciverGroup.Others, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, info.Request.Data }, { 254, 0 } }, evCode: (byte)MyOwnEventCode.S2C_InteractOnTile, cacheOp: 0); } break; case MyOwnEventCode.C2S_UpdatePosFromMasterClient: { I_NumberOfUpdatedPos++; if (I_NumberOfUpdatedPos >= m_InfoRoom.I_NumberOfPlayers - 1) { PluginHost.BroadcastEvent(target: ReciverGroup.All, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, null }, { 254, 0 } }, evCode: (byte)MyOwnEventCode.S2C_UpdatePosFromMasterClient, cacheOp: 0); } } break; } }