public byte[] GenerateAction(SendData data, int hashCode) { ByteArray array = new ByteArray(10); array.writeChar((char)data.cmd); array.writeInt(hashCode); array.writeInt(GameGlobalData.fd); array.writeByteArray(SendActionData.ToBytes(data.action)); return(array.getByteData()); }
public void SendKillOneAction(int fd) { SendData data = new SendData(); data.fd = GameGlobalData.fd; data.cmd = SendDataType.Action; SendActionData actionData = new SendActionData(); actionData.action = (char)SendActionData.ActionType.KillOne; actionData.killOne = new SendActionData.KillOne(); actionData.killOne.fd = fd; data.action = actionData; logicSwap.ForceSend(data); }
public void DispatchPlayerAction(SendActionData data) { if ((SendActionData.ActionType)data.action == SendActionData.ActionType.Bubble) { playerInputController.PlayerAttack(data.bubble.row, data.bubble.col, data.bubble.power); } else if ((SendActionData.ActionType)data.action == SendActionData.ActionType.SaveOne) { playerInputController.GetComponent <PlayerExplore>().removeFd(data.saveOne.fd); } else if ((SendActionData.ActionType)data.action == SendActionData.ActionType.KillOne) { playerInputController.GetComponent <PlayerExplore>().removeFd(data.killOne.fd); } }
//从客户端发送给服务器的回应消息 public void DispatchMessage(SendData data) { switch ((SendDataType)data.cmd) { case SendDataType.Action: SendActionData action = data.action; DispatchPlayerAction(data.action); break; case SendDataType.State: SendStateData state = data.state; DispatchPlayerState(data.state); break; case SendDataType.CheckTime: break; } }
public static byte[] ToBytes(SendActionData data) { ByteArray array = new ByteArray(10); array.writeChar(data.action); if ((ActionType)data.action == ActionType.Bubble) { array.writeChar(data.bubble.row); array.writeChar(data.bubble.col); array.writeChar(data.bubble.power); } else if ((ActionType)data.action == ActionType.SaveOne) { array.writeInt(data.saveOne.fd); } else if ((ActionType)data.action == ActionType.KillOne) { array.writeInt(data.killOne.fd); } return(array.getByteData()); }
//*********************************Action public void SendBubbleAction() { Vector3 center = colliderBox.Center; SendData data = new SendData(); data.fd = GameGlobalData.fd; data.cmd = SendDataType.Action; SendActionData actionData = new SendActionData(); int row = (int)-center.y / GameConst.tileHeight; int col = (int)center.x / GameConst.tileWidth; int power = input.power; actionData.action = (char)SendActionData.ActionType.Bubble; SendActionData.SendActionBubble bubble = new SendActionData.SendActionBubble(); bubble.row = (char)row; bubble.col = (char)col; bubble.power = (char)power; actionData.bubble = bubble; data.action = actionData; logicSwap.ForceSend(data); }