protected virtual void ReadFirstInput() { Cmd cmd = ReadInput <Cmd>(m_taskInfo.Inputs[1]); m_taskInfo.Cmd = cmd; }
protected virtual void OnCommand(Cmd cmd) { }
private void BeginMutation(Cmd cmd) { m_dataController.ControlledData.Unit.MutationStartTick = m_currentTick; m_dataController.ControlledData.Unit.MutationDuration = cmd.Duration; }
protected abstract void OnExecuteCommand(Cmd cmd);
private void ExecuteCommand(Cmd cmd) { if (cmd.ErrorCode != CmdResultCode.Success) { Debug.LogWarningFormat("Cmd {0} failed with error {1}", cmd.Code, cmd.ErrorCode); if (m_controlledVoxel != null) { //Last command was failed go to idle state } } else { switch (cmd.Code) { case CmdCode.StateChanged: OnStateChanged(cmd); break; case CmdCode.Move: OnMove(cmd); break; case CmdCode.RotateLeft: OnRotateLeft(); break; case CmdCode.RotateRight: OnRotateRight(); break; case CmdCode.BeginSplit: OnBeginSplit(cmd); break; case CmdCode.Split: OnSplit(cmd); break; case CmdCode.BeginSplit4: OnBeginSplit4(cmd); break; case CmdCode.Split4: OnSplit4(cmd); break; case CmdCode.BeginGrow: OnBeginGrow(cmd); break; case CmdCode.Grow: OnGrow(); break; case CmdCode.BeginDiminish: OnBeginDiminish(cmd); break; case CmdCode.Diminish: OnDiminish(); break; case CmdCode.BeginConvert: OnBeginConvert(cmd); break; case CmdCode.Convert: OnConvert(cmd); break; case CmdCode.BeginSetHealth: OnBeginSetHealth(cmd); break; case CmdCode.SetHealth: OnSetHealth(cmd); break; case CmdCode.CreateAssignment: OnAddAssignment(cmd); break; case CmdCode.Cancel: OnCancel(cmd); break; default: OnCommand(cmd); break; } } }
private void OnEngineCommandSubmitted(int playerIndex, Cmd cmd) { m_replay.Record(playerIndex, cmd, m_tick); }
protected virtual void OnBeginSetHealth(Cmd cmd) { }
public PlayerCmd(int playerIndex, Cmd cmd) { PlayerIndex = playerIndex; Cmd = cmd; }
public void Submit(Guid clientId, int playerIndex, Cmd cmd, ServerEventHandler <Cmd> callback) { Error error = new Error(StatusCode.OK); if (!m_clientIdToPlayers.ContainsKey(clientId)) { error.Code = StatusCode.NotRegistered; callback(error, cmd); return; } if (cmd.Code == CmdCode.LeaveRoom) { error.Code = StatusCode.NotAllowed; } else { if (!m_initialized) { error.Code = StatusCode.NotAllowed; error.Message = "Match is not initialized"; } else if (!enabled) { error.Code = StatusCode.Paused; error.Message = "Match is paused"; } else if (playerIndex < 0 || playerIndex >= m_room.Players.Count) { error.Code = StatusCode.NotAllowed; error.Message = "Wrong player index"; } else { if (m_botControlManager.IsActiveBot(playerIndex)) { if (m_botControlManager.HasControl(clientId)) { m_engine.Submit(playerIndex, cmd); // if I will use RTT Ticks then it will be possible to reverse order of commands sent by client (which is BAD!) } else { error.Code = StatusCode.NotAuthorized; error.Message = "Not authorized"; } } else { Guid playerClientId; if (m_playerToClientId.TryGetValue(m_room.Players[playerIndex], out playerClientId)) { if (clientId == playerClientId) { m_engine.Submit(playerIndex, cmd); } else { error.Code = StatusCode.NotAuthorized; error.Message = "Not authorized"; } } else { error.Code = StatusCode.NotAuthorized; error.Message = "Not authorized"; } } } } callback(error, cmd); }
protected virtual Cmd HandleNextCmd(Cmd cmd) { return(cmd); }
protected override void OnSetCommand(Cmd cmd) { }
protected override Cmd OnTick(long tick) //Tick should be able return several commands { if (State == VoxelDataState.Moving) { if (m_commandsQueue.Count > 0 && !m_dataController.IsCollapsedOrBlocked) { Cmd cmd = m_commandsQueue.Peek(); m_ticksBeforeNextCommand = cmd.Duration; bool dequeue = true; switch (cmd.Code) { case CmdCode.Move: { cmd = HandleNextMoveCmd(cmd); if (cmd == null) { m_failedMoveAttempts++; m_failedMoveAttempts %= (m_maxFailedMoveAttempts + 1); } else { m_failedMoveAttempts = 0; } dequeue = cmd != null; //if null then wait a little bit and try again break; } case CmdCode.RotateLeft: { m_dataController.RotateLeft(); break; } case CmdCode.RotateRight: { m_dataController.RotateRight(); break; } default: { cmd = HandleNextCmd(cmd); dequeue = cmd != null; //if null then wait a little bit and try again break; } } if (dequeue && m_commandsQueue.Count > 0) { m_commandsQueue.Dequeue(); } if (m_commandsQueue.Count == 0) { RaiseCmdExecuted(); } return(cmd); } if (m_commandsQueue.Count == 0) { RaiseCmdExecuted(); } return(null); } else if ((State & VoxelDataState.Busy) == VoxelDataState.Busy) { if (m_commandsQueue.Count > 0) { Cmd cmd = m_commandsQueue.Dequeue(); m_ticksBeforeNextCommand = cmd.Duration; switch (cmd.Code) { case CmdCode.BeginSplit: case CmdCode.BeginSplit4: case CmdCode.BeginGrow: case CmdCode.BeginDiminish: case CmdCode.BeginConvert: case CmdCode.BeginSetHealth: { m_dataController.ControlledData.Unit.MutationStartTick = tick; return(cmd); } case CmdCode.Split: { CoordinateCmd coordinateCmd = new CoordinateCmd(cmd.Code, cmd.UnitIndex, cmd.Duration); Coordinate[] coordinates; CmdResultCode result = m_dataController.Split(out coordinates, EatOrDestroyCallback); if (result == CmdResultCode.Success) { coordinateCmd.Coordinates = coordinates; RaiseCmdExecuted(); } else { RaiseCmdFailed(coordinateCmd, result); } return(coordinateCmd); } case CmdCode.Split4: { CoordinateCmd coordinateCmd = new CoordinateCmd(cmd.Code, cmd.UnitIndex, cmd.Duration); Coordinate[] coordinates; CmdResultCode result = m_dataController.Split4(out coordinates); if (result == CmdResultCode.Success) { coordinateCmd.Coordinates = coordinates; RaiseCmdExecuted(); } else { RaiseCmdFailed(coordinateCmd, result); } return(coordinateCmd); } case CmdCode.Grow: { CmdResultCode result = m_dataController.Grow(EatOrDestroyCallback); if (result == CmdResultCode.Success) { RaiseCmdExecuted(); } else { RaiseCmdFailed(cmd, result); } return(cmd); } case CmdCode.Diminish: { CmdResultCode result = m_dataController.Diminish(); if (result == CmdResultCode.Success) { RaiseCmdExecuted(); } else { RaiseCmdFailed(cmd, result); } return(cmd); } case CmdCode.Convert: { ChangeParamsCmd convertCmd = (ChangeParamsCmd)cmd; int type = convertCmd.IntParams[0]; CmdResultCode result = m_dataController.Convert(type); if (result == CmdResultCode.Success) { RaiseCmdExecuted(); } else { RaiseCmdFailed(cmd, result); } return(cmd); } case CmdCode.SetHealth: { ChangeParamsCmd changeCmd = (ChangeParamsCmd)cmd; int health = changeCmd.IntParams[0]; m_dataController.SetHealth(health); RaiseCmdExecuted(); return(changeCmd); } case CmdCode.CreateAssignment: { CreateAssignmentCmd addCmd = (CreateAssignmentCmd)cmd; if (addCmd.CreatePreview) { CmdResultCode result = m_dataController.CreatePreview(addCmd.PreviewType, addCmd.PreviewCoordinate); if (result == CmdResultCode.Success) { RaiseCmdExecuted(); } else { RaiseCmdFailed(cmd, result); } } else { RaiseCmdExecuted(); } return(cmd); } case CmdCode.Cancel: { IMatchPlayerController playerController = m_engine.GetPlayerController(m_dataController.PlayerIndex); playerController.AssignmentsController.RemoveAssignment(this, null); RaiseCmdExecuted(); return(cmd); } } } } return(null); }
protected abstract void OnSetCommand(Cmd cmd);
public void Tick(long tick, out Cmd cmd) { if (m_createdVoxels.Count != 0) { m_createdVoxels.Clear(); } if (m_eatenOrDestroyedVoxels.Count != 0) { m_eatenOrDestroyedVoxels.Clear(); } if (!m_dataController.IsAlive) { if (State != VoxelDataState.Idle) { RaiseCmdFailed(null, CmdResultCode.Fail_NoUnit); } else { GoToIdleState(); } cmd = null; return; } if (m_ticksBeforeNextCommand == 0) { cmd = OnTick(tick); if (State != m_prevState) { if (cmd != null) { cmd = new CompositeCmd { UnitIndex = cmd.UnitIndex, Duration = cmd.Duration, Commands = new[] { cmd, new ChangeParamsCmd(CmdCode.StateChanged) { UnitIndex = cmd.UnitIndex, Duration = cmd.Duration, IntParams = new[] { (int)m_prevState, (int)State } } } }; } else { cmd = new ChangeParamsCmd(CmdCode.StateChanged) { UnitIndex = Id, IntParams = new[] { (int)m_prevState, (int)State } }; } CmdResultCode noFail = m_dataController.SetVoxelDataState(State); if (noFail != CmdResultCode.Success) { throw new InvalidOperationException(""); } m_prevState = State; } return; } else { m_ticksBeforeNextCommand--; } cmd = null; return; }
public virtual void Record(int playerIndex, Cmd cmd, long tick) { m_playerIndices.Enqueue(playerIndex); m_ticks.Enqueue(tick); m_commands.Enqueue(cmd); }
public override void Record(int playerId, Cmd cmd, long tick) { }