public Task <Void> MoveDirection(Direction direction) { SendCommandData( new CommandData(0, CommandKind.MoveDirection, 0, new object[] { direction }) ); return(botCommands.MoveDirection(direction)); }
public void FromCommandData(CommandData commandData, IBotCommands botCommands) { switch (commandData.kind) { case CommandKind.Move: botCommands.Move((Direction)(Int64)commandData.parameters[0], (uint)(Int64)commandData.parameters[1]); break; case CommandKind.MoveDirection: botCommands.MoveDirection((Direction)(Int64)commandData.parameters[0]); break; case CommandKind.MoveShotRotation: botCommands.MoveShotRotation((float)(double)commandData.parameters[0]); break; case CommandKind.Shot: botCommands.Shot(); break; case CommandKind.MeleeAttack: botCommands.MeleeAttack(); break; default: throw new ArgumentOutOfRangeException(); } }
private Engine CreateEngine(CancellationToken cancellationToken, int processId) { var engine = new Engine(options => { options.DebugMode(); }); engine.Step += (s, e) => { if (cancellationToken.IsCancellationRequested) { throw new OperationCanceledException(); } return(StepMode.Into); }; engine.SetValue("KeyCode", TypeReference.CreateTypeReference(engine, typeof(KeyCode))); engine.SetValue("GetKey", new Func <KeyCode, bool>(code => { var task = botCommands.GetKey(code); task.Wait(); return(task.Result); })); engine.SetValue("GetKeyDown", new Func <KeyCode, bool>(code => { var task = botCommands.GetKeyDown(code); task.Wait(); return(task.Result); })); engine.SetValue("GetKeyUp", new Func <KeyCode, bool>(code => { var task = botCommands.GetKeyUp(code); task.Wait(); return(task.Result); })); engine.SetValue("Dir", TypeReference.CreateTypeReference(engine, typeof(Direction))); engine.SetValue("Pos", TypeReference.CreateTypeReference(engine, typeof(GridPosition))); engine.SetValue("TileType", TypeReference.CreateTypeReference(engine, typeof(TileType))); engine.SetValue("Coroutine", new Action <uint, JsValue>((frameTime, jsfunc) => { botCommands.Coroutine(frameTime, () => jsfunc.Invoke()); })); engine.SetValue("Shot", new Action(() => botCommands.Shot())); engine.SetValue("Attack", new Action(() => botCommands.MeleeAttack())); engine.SetValue("Move", new Action <Direction, uint>((dir, mass) => botCommands.Move(dir, mass).Wait() )); engine.SetValue("MoveDir", new Action <Direction>(dir => botCommands.MoveDirection(dir).Wait() )); engine.SetValue("ShotDir", new Action <float>(dir => botCommands.MoveShotRotation(dir).Wait() )); engine.SetValue("GetMyPos", new Func <GridPosition>(() => { var task = botCommands.GetMyPosition(); task.Wait(); return(task.Result); })); engine.SetValue("GetPosAngle", new Func <GridPosition, float>(pos => { var task = botCommands.GetPositionAngle(pos); task.Wait(); return(task.Result); })); engine.SetValue("GetTileType", new Func <GridPosition, TileType>(pos => { var task = botCommands.GetTileType(pos); task.Wait(); return(task.Result); })); engine.SetValue("Print", new Action <object>(obj => ConsoleLogger.Log(DateTime.Now, processId, obj) )); engine.SetValue("Wait", new Action <int>((milliSeconds) => Task.Delay(milliSeconds).Wait())); return(engine); }
public async Task <Void> MoveDirection(Direction direction) { SendCommandData(CommandKind.MoveDirection, new object[] { direction }); return(await botCommands.MoveDirection(direction)); }