public ScannerWindow(BotBitsClient client) { InitializeComponent(); this.client = client; EventLoader.Of(client).Load(this); }
public static void WithClient(BotBitsClient client, Action callback) { var oldClient = client; _client = client; callback(); _client = oldClient; }
private List<Map> OnLoadMaps(BotBitsClient botBits, ISignFormat signFormat, IPositionMapper positionMapper) { var maps = new List<Map>(); var blocks = Blocks.Of(botBits); for (var x = 1; x < blocks.Width - MapWidth; x++) { for (var y = 1; y < blocks.Height - MapHeight; y++) { var block = blocks.At(x, y).Foreground.Block; if (block.Type != ForegroundType.Sign) continue; MapData mapData; if (!signFormat.TryGetMapData(block.Text, Room.Of(botBits).Owner, out mapData)) continue; maps.Add(new Map(blocks, positionMapper.GetMapRectangle(new Point(x, y), MapWidth, MapHeight), mapData.Name, mapData.Creators)); } } return maps; }
public BotBase() { this._botBits = CakeServices.Client; if (this._botBits == null) throw new InvalidOperationException( "Please call CakeServices.WithClient before creating new BotBase objects."); this.EventLoader.Load(this); this.LoadCommands(); // Try to load commands as soon as possible }
internal static int? GetExtensionId(BotBitsClient client, Assembly assembly) { var exts = GetExtensions(client); for (var i = 0; i < exts.Length; i++) { if (exts[i].Assembly == assembly) return i; } return null; }
public LoginWindow(BotBitsClient client) { InitializeComponent(); this.client = client; emailBox.Text = Properties.Settings.Default.Email; passwordBox.Password = Properties.Settings.Default.Password; worldIdBox.Text = Properties.Settings.Default.WorldID; MapManagerExtension.LoadInto(client, 22, 11); }
/// <summary> /// Asynchronously load the maps from world with specified id. /// </summary> /// <returns>The loaded maps.</returns> /// <param name="worldId">World identifier.</param> public async Task<List<Map>> LoadMapsAsync(string worldId) { BotBits = new BotBitsClient(); await Login.Of(BotBits) .AsGuestAsync() .CreateJoinRoomAsync(worldId); Console.WriteLine("Connected"); WaitForInfoEvent(); WaitForInitEvent(); await connectResult.Task; var maps = OnLoadMaps(); ConnectionManager.Of(BotBits).Connection.Disconnect(); return maps; }
/// <summary> /// Asynchronously loads maps from world with the specified <see cref="worldId" />. /// </summary> /// <param name="worldId">World identifier.</param> /// <param name="signFormat"><see cref="MapData" /> reader.</param> /// <param name="positionMapper">The position mapper used to get map rectangle.</param> /// <returns>The loaded maps.</returns> public async Task<List<Map>> LoadMapsAsync(string worldId, ISignFormat signFormat, IPositionMapper positionMapper) { var botBits = new BotBitsClient(); await Login.Of(botBits).AsGuestAsync().CreateJoinRoomAsync(worldId); Console.WriteLine("Connected"); var connectResult = new TaskCompletionSource<bool>(); var cts = new CancellationTokenSource(); // Wait for init or info event // Only one of them is sent depending on visibility of the world WaitForInfoEvent(botBits, connectResult, cts.Token); WaitForInitEvent(botBits, connectResult, cts.Token); await connectResult.Task; cts.Cancel(); var maps = OnLoadMaps(botBits, signFormat, positionMapper); botBits.Dispose(); return maps; }
public static Type[] GetExtensions(BotBitsClient client) { lock (client.Extensions) return client.Extensions.ToArray(); }
public PackageLoader(BotBitsClient client) { this._client = client; }
internal Player([CanBeNull] BotBitsClient botBits, int userId) { this._botBits = botBits; this.UserId = userId; }
public static EventHandle <T> Of([NotNull] BotBitsClient client) { return(EventManager.Of(client).GetEvent <T>()); }
public static bool IsLoadedInto(BotBitsClient client) { return(client.Extensions.Contains(typeof(T))); }
void IPackage.Setup(BotBitsClient client) { this.BotBits = client; }
internal LoginClient(BotBitsClient botBitsClient, Client client) { this._botBitsClient = botBitsClient; this.Client = client; }
protected virtual void Initialize(BotBitsClient client, object args) { }
protected override void Initialize(BotBitsClient client, object args) { var handle = (ISchedulerHandle)args; Scheduler.Of(client).SetScheduler(handle); }
private static async void WaitForInitEvent(BotBitsClient botBits, TaskCompletionSource<bool> result, CancellationToken token) { try { await InitEvent.Of(botBits).WaitOneAsync(token); result.SetResult(true); } catch (TaskCanceledException) { } }
internal EventHandle(BotBitsClient botBits) { this.BotBits = botBits; }
public static bool LoadInto(BotBitsClient client, ISchedulerHandle handle) { return(LoadInto(client, (object)handle)); }
private static async void WaitForInfoEvent(BotBitsClient botBits, TaskCompletionSource<bool> result, CancellationToken token) { try { var e = await InfoEvent.Of(botBits).WaitOneAsync(token); result.SetException(new MapLoadException(e.Title, e.Text)); } catch (TaskCanceledException) { } }