예제 #1
0
 public static void Reload()
 {
     if (ReloadTask == null || ReloadTask.IsCompleted)
     {
         ReloadTask = Task.Run(() =>
         {
             if (!InitTask.IsCompleted)
             {
                 InitTask.Wait();
             }
             ReadLevelDifferences(true);
             ReadRecipeRotations(true);
             ReadCraftingActionData();
             Reloaded();
         });
     }
 }
예제 #2
0
 private static void GameDataReloaded()
 {
     if (ReloadTask == null || ReloadTask.IsCompleted)
     {
         ReloadTask = Task.Run(() =>
         {
             if (!InitTask.IsCompleted)
             {
                 InitTask.Wait();
             }
             ReadItems(true);
             ReadRecipes(true);
             ReadActions(true);
             Reloaded();
         });
     }
 }
예제 #3
0
파일: GuildTask.cs 프로젝트: zORg-alex/ZBot
        /// <summary>
        /// User changed state in voice lobbies (joined/left)
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public async Task VoiceStateUpdated(VoiceStateUpdateEventArgs e)
        {
            InitTask?.Wait();
            //DebugLogWriteLine("VoiceStateUpdated: ");

            if (e.After?.Channel != e.Before?.Channel)               //Channel changed
            {
                var beforeInLobbies     = DateVoiceLobbies.Contains(e.Before?.Channel);
                var afterInLobbies      = DateVoiceLobbies.Contains(e.After?.Channel);
                var beforeInSecretRooms = SecretRooms.Contains(e.Before?.Channel);
                var afterInSecretRooms  = SecretRooms.Contains(e.After?.Channel);

                if (!beforeInLobbies && !beforeInSecretRooms && afterInLobbies)
                {
                    //User connected to lobbies
                    DebugLogWriteLine($"User {e.User} connected to {e.Channel} ");
                    UserConnected_AddToActivity(e.User);
                    //Start matching session
                    TryStartMatchingTask();
                }
                else if ((beforeInLobbies || beforeInSecretRooms) && !afterInLobbies && !afterInSecretRooms)
                {
                    //User left activity
                    DebugLogWriteLine($"User {e.User} left activity ");
                    if (beforeInLobbies)
                    {
                        UsersInLobbies.Remove(e.User);
                        RemoveStateFor(e.User);
                    }
                    //remove disband secret room if one left TODO check logic
                    if (beforeInSecretRooms)
                    {
                        RemoveStateFor(e.User);
                        //DebugLogWrite($"trying to disbnad {e.Before.Channel}... ");
                        await disbandRemoveSecretRoom(e.Before.Channel).ConfigureAwait(false);

                        //DebugLogWrite($"{e.Before.Channel} removed/disbanded");
                    }
                }
                else if (beforeInLobbies && afterInLobbies)
                {
                    DebugLogWriteLine($"User {e.User} switched lobbies ");
                    //User switched Lobbies
                }
                else if (beforeInLobbies && afterInSecretRooms)
                {
                    DebugLogWriteLine($"User {e.User} moved to {e.After.Channel} ");
                    //Moved to secret room
                    UsersInLobbies.Remove(e.User);
                }
                else if (beforeInSecretRooms && afterInLobbies)
                {
                    //Returned from secret room
                    RemoveStateFor(e.User);
                    DebugLogWriteLine($"User {e.User} returned to lobby, trying to disbnad {e.Before.Channel}... ");
                    UserConnected_AddToActivity(e.User);
                    await disbandRemoveSecretRoom(e.Before.Channel).ConfigureAwait(false);

                    //DebugLogWrite($"{e.Before.Channel} removed/disbanded. Starting MatchingTask");
                    //Start matching session
                    TryStartMatchingTask();
                }

                TryCombLobbies();
            }

            async Task disbandRemoveSecretRoom(DiscordChannel channel)
            {
                //Remove empty room, if 1 user left, move him into lobby 0, later room will be removed
                if (channel.Users.Count() == 0)
                {
                    try {                     //usually shouldn't throw, but in debug
                        await channel.DeleteAsync().ConfigureAwait(false);
                    } catch {
                        //DebugLogWrite($"Exception while deleting ");
                    }
                }
                else if (channel.Users.Count() == 1)
                {
                    try {
                        var moveMember = await Guild.GetMemberAsync(channel.Users.First().Id);

                        await DateVoiceLobbies[0].PlaceMemberAsync(moveMember);
                    } catch {
                        //DebugLogWrite($"Exception while moving member ");
                    }
                }
            }
        }