private void GetCommandChangeResultPosReal(CommandChangeResultPos _command, PlayerData _playerData) { if (_command.pos > -1 && _command.pos < _playerData.result.Length) { DishResult result = _playerData.result[_command.pos]; if (result != null) { if (_command.targetPos == -1) { _playerData.result[_command.pos] = null; eventCallBack?.Invoke(_command); } else { if (_command.targetPos > -1 && _command.targetPos < _playerData.result.Length && _command.pos != _command.targetPos) { _playerData.result[_command.pos] = _playerData.result[_command.targetPos]; _playerData.result[_command.targetPos] = result; eventCallBack?.Invoke(_command); } } } } }
internal void GetCommandChangeResultPos(CommandChangeResultPos _command) { if (_command.isMine) { GetCommandChangeResultPosReal(_command, mData); } else { GetCommandChangeResultPosReal(_command, oData); } }
private void ServerGetCommand(bool _isMine, BinaryReader _br) { ICommand command; CommandType commandType = (CommandType)_br.ReadByte(); switch (commandType) { case CommandType.CHANGE_WORKER_POS: command = new CommandChangeWorkerPos(); break; case CommandType.CHANGE_RESULT_POS: command = new CommandChangeResultPos(); break; case CommandType.COMPLETE_DISH: command = new CommandCompleteDish(); break; default: command = new CommandCompleteRequirement(); break; } command.FromBytes(_br); command.SetIsMine(_isMine); commandList.Add(command); }
private void Update(BinaryReader _br) { ushort tick = _br.ReadUInt16(); if (tick != main.tick) { throw new Exception("tick is not match! client:" + main.tick + " server:" + tick); } if (tick % CookConst.REQUIRE_PRODUCE_TIME == 0) { ushort randomSeed = _br.ReadUInt16(); main.SetSeed(randomSeed); } main.Update(); ushort num = _br.ReadUInt16(); for (int i = 0; i < num; i++) { CommandType commandType = (CommandType)_br.ReadByte(); switch (commandType) { case CommandType.CHANGE_RESULT_POS: CommandChangeResultPos commandChangeResultPos = new CommandChangeResultPos(); commandChangeResultPos.FromBytes(_br); main.GetCommandChangeResultPos(commandChangeResultPos); break; case CommandType.CHANGE_WORKER_POS: CommandChangeWorkerPos commandChangeWorkerPos = new CommandChangeWorkerPos(); commandChangeWorkerPos.FromBytes(_br); main.GetCommandChangeWorkerPos(commandChangeWorkerPos); break; case CommandType.COMPLETE_DISH: CommandCompleteDish commandCompleteDish = new CommandCompleteDish(); commandCompleteDish.FromBytes(_br); main.GetCommandCompleteDish(commandCompleteDish); break; default: CommandCompleteRequirement commandCompleteRequirement = new CommandCompleteRequirement(); commandCompleteRequirement.FromBytes(_br); main.GetCommandCompleteRequirement(commandCompleteRequirement); break; } } if (num > 0) { CheckSync(); } GameResult gameResult; if (main.tick > CookConst.MAX_TIME * CookConst.TICK_NUM_PER_SECOND) { gameResult = main.GetGameResult(); } else { gameResult = GameResult.NOT_OVER; } client.UpdateCallBack(gameResult); }
public void ChangeResultPos(int _pos, int _targetPos) { CommandChangeResultPos command = new CommandChangeResultPos(clientIsMine, _pos, _targetPos); SendCommand(command); }