public ScannerWindow(BotBitsClient client)
        {
            InitializeComponent();

            this.client = client;
            EventLoader.Of(client).Load(this);
        }
Beispiel #2
0
 public static void WithClient(BotBitsClient client, Action callback)
 {
     var oldClient = client;
     _client = client;
     callback();
     _client = oldClient;
 }
Beispiel #3
0
        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;
        }
Beispiel #4
0
        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);
        }
Beispiel #7
0
        /// <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;
        }
Beispiel #8
0
        /// <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();
 }
Beispiel #10
0
 public PackageLoader(BotBitsClient client)
 {
     this._client = client;
 }
Beispiel #11
0
 internal Player([CanBeNull] BotBitsClient botBits, int userId)
 {
     this._botBits = botBits;
     this.UserId   = userId;
 }
Beispiel #12
0
 public static EventHandle <T> Of([NotNull] BotBitsClient client)
 {
     return(EventManager.Of(client).GetEvent <T>());
 }
Beispiel #13
0
 public static bool IsLoadedInto(BotBitsClient client)
 {
     return(client.Extensions.Contains(typeof(T)));
 }
Beispiel #14
0
 void IPackage.Setup(BotBitsClient client)
 {
     this.BotBits = client;
 }
Beispiel #15
0
 internal LoginClient(BotBitsClient botBitsClient, Client client)
 {
     this._botBitsClient = botBitsClient;
     this.Client         = client;
 }
Beispiel #16
0
 protected virtual void Initialize(BotBitsClient client, object args)
 {
 }
Beispiel #17
0
        protected override void Initialize(BotBitsClient client, object args)
        {
            var handle = (ISchedulerHandle)args;

            Scheduler.Of(client).SetScheduler(handle);
        }
Beispiel #18
0
 private static async void WaitForInitEvent(BotBitsClient botBits, TaskCompletionSource<bool> result,
     CancellationToken token)
 {
     try
     {
         await InitEvent.Of(botBits).WaitOneAsync(token);
         result.SetResult(true);
     }
     catch (TaskCanceledException)
     {
     }
 }
Beispiel #19
0
 internal EventHandle(BotBitsClient botBits)
 {
     this.BotBits = botBits;
 }
Beispiel #20
0
 public static bool LoadInto(BotBitsClient client, ISchedulerHandle handle)
 {
     return(LoadInto(client, (object)handle));
 }
Beispiel #21
0
 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)
     {
     }
 }