Пример #1
0
 internal CommandData(string command, Channel channel, PlayerIdentity playerIdentity, ChatIdentity chatIdentity)
 {
     this.command   = command;
     this.channel   = channel;
     PlayerIdentity = playerIdentity;
     ChatIdentity   = chatIdentity;
 }
 internal CommandData(string command, Channel channel, ChatIdentity chatIdentity, bool isFriend, string playerName, PlayerIdentity playerIdentity)
 {
     Command        = command;
     Channel        = channel;
     ChatIdentity   = chatIdentity;
     IsFriend       = isFriend;
     PlayerName     = playerName;
     PlayerIdentity = playerIdentity;
 }
Пример #3
0
        /// <summary>
        /// Tracks player slots.
        /// </summary>
        /// <param name="playerTracker"></param>
        /// <param name="slotFlags">Slots to track.</param>
        public void TrackPlayers(PlayerTracker playerTracker, SlotFlags slotFlags = SlotFlags.All)
        {
            if (playerTracker == null)
            {
                throw new ArgumentNullException(nameof(playerTracker));
            }

            using (LockHandler.Interactive)
            {
                List <int> changedSlots = GetUpdatedSlots(playerTracker.SlotInfo, slotFlags);

                var slots = GetSlots(slotFlags);

                foreach (int slot in changedSlots)
                {
                    if (slots.Contains(slot))
                    {
                        PlayerIdentity newIdentity = GetPlayerIdentity(slot);
                        if (newIdentity == null)
                        {
                            continue;
                        }

                        var pi = playerTracker._players.FirstOrDefault(p => Identity.Compare(newIdentity, p.PlayerIdentity));

                        // New player joined the game
                        if (pi == null)
                        {
                            playerTracker._players.Add(new PlayerTrackerSlot(newIdentity, slot));
                        }
                        // Player swapped slots
                        else
                        {
                            pi.Slot = slot;
                            newIdentity.Dispose();
                        }
                    }
                }

                // Remove players that left the game.
                for (int i = playerTracker._players.Count - 1; i >= 0; i--)
                {
                    if (!slots.Contains(playerTracker._players[i].Slot))
                    {
                        playerTracker._players[i].PlayerIdentity.Dispose();
                        playerTracker._players.RemoveAt(i);
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Gets the player's slot from a player's identity.
        /// </summary>
        /// <param name="identity">The identity of the player.</param>
        /// <returns>Returns the slot of the player. Returns -1 if it is not found.</returns>
        public int SlotFromPlayerIdentity(PlayerIdentity identity)
        {
            if (identity == null)
            {
                throw new ArgumentNullException(nameof(identity), $"{nameof(identity)} was null.");
            }

            foreach (var player in _players)
            {
                if (Identity.Compare(player.PlayerIdentity, identity))
                {
                    return(player.Slot);
                }
            }
            return(-1);
        }
        /// <summary>
        /// Gets the identity and name of a slot.
        /// </summary>
        /// <param name="slot">Slot to check.</param>
        /// <param name="pi">The <see cref="PlayerIdentity" /> of the slot.</param>
        /// <param name="name">The name of the slot.</param>
        public void GetPlayerIdentityAndName(int slot, out PlayerIdentity pi, out string name)
        {
            using (LockHandler.Interactive)
            {
                bool careerProfileOpenSuccess = Interact.ClickOption(slot, Markups.VIEW_CAREER_PROFILE);
                if (!careerProfileOpenSuccess)
                {
                    pi   = null;
                    name = null;
                    return;
                }

                WaitForCareerProfileToLoad();

                UpdateScreen();

                pi   = new PlayerIdentity(Capture.Clone(Rectangles.LOBBY_CAREER_PROFILE));
                name = GetPlayerName();

                GoBack(1);

                Thread.Sleep(500);
            }
        }
 /// <summary>
 /// Compares player identities.
 /// </summary>
 /// <param name="other">The other PlayerIdentity to compare to.</param>
 /// <returns>Returns true if the player identities are equal.</returns>
 public bool CompareIdentities(PlayerIdentity other)
 {
     return(CompareIdentities(this, other));
 }
        // Checks if an executed command should be added to the list of commands, then adds it.
        private string AddExecutedCommand(int y, int namelength, int[] seed, string command
#if DEBUG
                                          , List <LetterResult> letterInfos
#endif
                                          )
        {
            #region Command Cleanup
            ListenTo ltd = null;

            int nameSeperator = command.IndexOf(']') + 2;

            if (nameSeperator == 1 || nameSeperator > command.Length)
            {
                return(command);
            }

            command = command.Substring(nameSeperator)
                      .Trim();
            string firstWord = command.Split(' ')[0];

#if DEBUG
            letterInfos.RemoveRange(0, nameSeperator);
            cg.DebugMenu?.ShowScan(letterInfos);
#endif

            lock (ListenToAccessLock)
                foreach (ListenTo listenData in ListenTo)
                {
                    if (listenData.Command == firstWord)
                    {
                        ltd = listenData;
                        break;
                    }
                }

            if (ltd == null || !ltd.Listen)
            {
                return(command);
            }
            #endregion

            #region Chat Identity
            // Store executor noise data in a bitmap.
            var          executorscan = new Rectangle(0, y - 4, namelength, 6);
            DirectBitmap executor     = Capture.Clone(executorscan);
            // Set name pixels to black and everything else to white
            for (int xi = 0; xi < executor.Width; xi++)
            {
                for (int yi = 0; yi < executor.Height; yi++)
                {
                    if (executor.CompareColor(xi, yi, seed, Chat.ChatFade))
                    {
                        executor.SetPixel(xi, yi, Color.Black);
                    }
                    else
                    {
                        executor.SetPixel(xi, yi, Color.White);
                    }
                }
            }

            ChatIdentity ci = new ChatIdentity(executor);
            #endregion

            #region Profile and Friend Check
            bool           isFriend = false;
            string         name     = null;
            PlayerIdentity pi       = null;

            // If it was not found, pi is still null. Register the profile if _registerPlayerProfiles is true.
            if (ltd.GetNameAndProfile || ltd.CheckIfFriend)
            {
                Point openMenuAt = new Point(56, y);

                // Open the chat
                cg.Chat.OpenChat();

                // Open the career profile
                cg.RightClick(openMenuAt, Timing.OPTION_MENU);

                // If the Send Friend Request option exists, they are not a friend.
                isFriend = !(bool)cg.Interact.MenuOptionScan(openMenuAt, OptionScanFlags.ReturnFound, null, Markups.SEND_FRIEND_REQUEST);

                if (ltd.GetNameAndProfile)
                {
                    using (cg.LockHandler.Interactive)
                    {
                        // By default, the career profile option is selected and we can just press enter to open it.
                        cg.KeyPress(Keys.Enter);

                        // Wait for the career profile to load.
                        WaitForCareerProfileToLoad();

                        // Get the player name
                        name = cg.GetPlayerName();

                        // Take a screenshot of the career profile.
                        DirectBitmap careerProfileSnapshot = Capture.Clone(Rectangles.LOBBY_CAREER_PROFILE);

                        // Register the player identity.
                        pi = new PlayerIdentity(careerProfileSnapshot);

                        // Go back to the lobby.
                        cg.GoBack(1);
                        //cg.//ResetMouse();

                        // If opening the career profile failed, the state of the chat could be incorrect,
                        // like being wrongly opened or wrongly closed because of when enter was pressed earlier.
                        // This will fix it.
                        cg.Chat.OpenChat();
                        if (!cg.OpenChatIsDefault)
                        {
                            cg.KeyPress(Keys.Enter);
                        }
                    }
                }
                else
                {
                    cg.Interact.CloseOptionMenu();
                }
            }
            #endregion

            CommandData commandData = new CommandData(command, GetChannelFromSeed(seed), ci, isFriend, name, pi);
            if (ltd.Callback != null)
            {
                ltd.Callback.Invoke(commandData);
            }
            else
            {
                commandData.ChatIdentity.Dispose();
                commandData.PlayerIdentity?.Dispose();
            }

            return(command);
        }
Пример #8
0
 internal PlayerTrackerSlot(PlayerIdentity identity, int slot)
 {
     PlayerIdentity = identity;
     Slot           = slot;
 }
Пример #9
0
 /// <summary>
 /// Returns true if the 2 player identities are identicle.
 /// </summary>
 /// <param name="pi1">First player identity</param>
 /// <param name="pi2">Second player identity</param>
 /// <returns>Returns true if the player identities are identicle.</returns>
 public static bool ComparePlayerIdentities(PlayerIdentity pi1, PlayerIdentity pi2)
 {
     return(CompareIdentities(pi1, pi2));
 }
Пример #10
0
        // Checks if an executed command should be added to the list of commands, then adds it.
        void AddExecutedCommand(Bitmap bmp, int y, int namelength, int[] seed, int seedfade, string word)
        {
            // Clean up the word. makes something like "] $APPLE " into "$APPLE"
            var wordtemp = word.Split(new char[] { ']' }, 2);

            if (wordtemp.Length > 1)
            {
                word = wordtemp[1];
            }
            word = word.Trim();

            string   commandFirstWord = word.Split(' ')[0];
            ListenTo ltd = ListenTo.FirstOrDefault(v => v.Command == commandFirstWord);

            // See if command is being listened to. If it is, continue.
            if (word.Length > 0 && ltd != null && ltd.Listen)
            {
                lock (CommandLock)
                {
                    PlayerIdentity pi = null;

                    // If it was not found, pi is still null. Register the profile if _registerPlayerProfiles is true.
                    if (ltd.RegisterProfile)
                    {
                        Point openMenuAt = new Point(54, Rectangles.LOBBY_CHATBOX.Y + y);

                        // Open the chat
                        cg.Chat.OpenChat();

                        // Open the career profile
                        cg.RightClick(openMenuAt, 500);

                        // By default, the career profile option is selected and we can just press enter to open it.
                        cg.KeyPress(Keys.Enter);

                        // Wait for the career profile to load.
                        WaitForCareerProfileToLoad();

                        // Take a screenshot of the career profile.
                        cg.updateScreen();
                        Bitmap careerProfileSnapshot = cg.BmpClone(Rectangles.LOBBY_CAREER_PROFILE);

                        // Register the player identity.
                        pi = new PlayerIdentity(careerProfileSnapshot);

                        // Go back to the lobby.
                        cg.GoBack(1);
                        cg.ResetMouse();

                        // If opening the career profile failed, the state of the chat could be incorrect,
                        // like being wrongly opened or wrongly closed because of when enter was pressed earlier.
                        // This will fix it.
                        cg.Chat.OpenChat();
                        if (!cg.OpenChatIsDefault)
                        {
                            cg.KeyPress(Keys.Enter);
                        }
                    }

                    // Store executor noise data in a bitmap.
                    var    executorscan = new Rectangle(0, y - 4, namelength, 6);
                    Bitmap executor     = bmp.Clone(executorscan, bmp.PixelFormat);
                    // Set name pixels to black and everything else to white
                    for (int xi = 0; xi < executor.Width; xi++)
                    {
                        for (int yi = 0; yi < executor.Height; yi++)
                        {
                            if (executor.CompareColor(xi, yi, seed, seedfade))
                            {
                                executor.SetPixel(xi, yi, Color.Black);
                            }
                            else
                            {
                                executor.SetPixel(xi, yi, Color.White);
                            }
                        }
                    }

                    ChatIdentity ci = new ChatIdentity(executor);

                    CommandData commandData = new CommandData(word, GetChannelFromSeed(seed), pi, ci);
                    if (ltd?.Callback != null)
                    {
                        ltd.Callback.Invoke(commandData);
                    }

                    System.Threading.Thread.Sleep(50);
                } // lock
            }     // if command is being listened to
        }