public void ControlAndSendToServer() { if (PlayerList.Count <= 0) { return; } var ctrl = Controller.GetControl(); if (ctrl != ControlOrder.None) { if (ctrl != ControlOrder.Idle) { sendIdle = true; } if (ctrl != ControlOrder.Kick) { PlayerList[myName].Action(ctrl, PlayerList[myName].transform.position.x, PlayerList[myName].transform.position.y, false, false, Parameters.MoveSpeed); } if (ctrl == ControlOrder.Kick || sendIdle || myPos.x != PlayerList[myName].transform.position.x) { if (sendIdle && ctrl == ControlOrder.Idle) { sendIdle = false; } var actMessage = new PlayerActionMessage(); var act = new PlayerAction(); act.Name = myName; act.Control = ctrl; act.X = PlayerList[myName].transform.position.x; act.Y = PlayerList[myName].transform.position.y; act.Turn = PlayerList[myName].TurnFlag; act.Vx = Parameters.Vx * (act.Turn ? -1 : 1); actMessage.Data = act; if (Time.time > sendTime || (ctrl != ControlOrder.moveLeft && ctrl != ControlOrder.moveRight) || nowOrder != ctrl) { Send(Message.Act, actMessage); sendTime = Time.time + Time.deltaTime * Parameters.SendDistance; perTime = (sendTime - Time.time) / Parameters.SendDistance; } myPos = PlayerList[myName].transform.position; } nowOrder = ctrl; } }
void RecieveMessage(Message msg) { print("MESSAGE RECIEVED " + msg); switch (msg.type) { case MessageTypes.PlayerJoined: print("A NEW CHALLENGER APPROACHES"); PlayerJoinedMessage pjm = (PlayerJoinedMessage)msg; m_playerController.AddPlayer(new PlayerData { index = pjm.id, color = pjm.color, icon = (PhoneUserIcon)pjm.icon, name = pjm.name }); if (onPlayerCountChange != null) { onPlayerCountChange.Invoke(m_playerController.PlayerCount); } break; case MessageTypes.PlayerLeft: PlayerLeftMessage plm = (PlayerLeftMessage)msg; m_playerController.RemovePlayer(plm.id); if (onPlayerCountChange != null) { onPlayerCountChange.Invoke(m_playerController.PlayerCount); } SceneManager.LoadScene(0); break; case MessageTypes.PlayerMove: PlayerMoveMessage pmm = (PlayerMoveMessage)msg; ThirdPersonUserControl player = ThirdPersonUserControl.players[pmm.pid - 1]; //if(pmm.x != null && pmm.y != null) player.setAxis(pmm.x, pmm.y); if (pmm.jmp) { player.jump = pmm.jmp; } if (pmm.drp) { player.drop = pmm.drp; } break; case MessageTypes.PlayerAction: PlayerActionMessage pam = (PlayerActionMessage)msg; print(pam + " sad"); if (pam.jump) { ThirdPersonUserControl.players[pam.pid - 1].jump = true; } else { ThirdPersonUserControl.players[pam.pid - 1].drop = true; } break; } }
private void HandleMessage(GameMessage message) { if (message is PlayerActionMessage) { PlayerActionMessage actionMessage = (PlayerActionMessage)message; CardPanel relevantCardPanel = actionMessage.Player == _game.PlayerOne ? pYourHand : pOpponentsHand; switch (actionMessage.PlayerActionValue) { case PlayerActionMessage.PlayerAction.DrawDiscard: relevantCardPanel.AddCard(actionMessage.Card); pStacks.DiscardCount--; pStacks.VisibleDiscard = _game.GetVisibleDiscard(); pActions.AllowDraw = false; pActions.AllowTake = false; pActions.AllowDiscard = true; break; case PlayerActionMessage.PlayerAction.DrawStock: pStacks.StockCount--; relevantCardPanel.AddCard(actionMessage.Card); pActions.AllowDraw = false; pActions.AllowTake = false; pActions.AllowDiscard = true; break; case PlayerActionMessage.PlayerAction.SetDiscard: pStacks.DiscardCount++; pStacks.VisibleDiscard = actionMessage.Card; relevantCardPanel.RemoveCard(actionMessage.Card); pActions.AllowDraw = false; pActions.AllowTake = false; pActions.AllowDiscard = false; break; case PlayerActionMessage.PlayerAction.Knock: // TODO: handle Knock message break; default: break; } } else if (message is GameStatusMessage) { GameStatusMessage statusMessage = (GameStatusMessage)message; switch (statusMessage.GameStatusChangeValue) { case GameStatusMessage.GameStatusChange.GameInitialised: // TODO: assumes PlayerOne is always the human player pYourHand.Clear(); InitialisePlayerCardPanel(pYourHand); foreach (Card c in _game.PlayerOne.GetCards()) { pYourHand.AddCard(c); } pOpponentsHand.Clear(); InitialiseOpponentCardPanel(pOpponentsHand); foreach (Card c in _game.PlayerTwo.GetCards()) { pOpponentsHand.AddCard(c); } InitialiseStacks(_game.GetStockCount(), _game.GetVisibleDiscard()); InitialisePlayerActions(); break; case GameStatusMessage.GameStatusChange.StartTurn: if (statusMessage.Player == _game.PlayerOne) { pActions.AllowTake = true; pActions.AllowDraw = true; } else { pActions.AllowTake = false; pActions.AllowDraw = false; } break; default: break; } } }