Example #1
0
        /// <summary>
        /// Gets a string array of all players & pets among the combatants.
        /// </summary>
        /// <returns>A string array.</returns>
        protected string[] GetPlayerListing()
        {
            List <string> playerStrings = new List <string>();

            playerStrings.Add(Resources.PublicResources.All);

            using (Database.AccessToTheDatabase dbAccess = new AccessToTheDatabase())
            {
                if (dbAccess.HasAccess)
                {
                    var playersFighting = from b in dbAccess.Database.Combatants
                                          where (((EntityType)b.CombatantType == EntityType.Player ||
                                                  (EntityType)b.CombatantType == EntityType.Pet ||
                                                  (EntityType)b.CombatantType == EntityType.Fellow) &&
                                                 b.GetInteractionsRowsByActorCombatantRelation().Any() == true)
                                          orderby b.CombatantName
                                          select b.CombatantName;

                    foreach (var player in playersFighting)
                    {
                        playerStrings.Add(player);
                    }
                }
            }

            return(playerStrings.ToArray());
        }
Example #2
0
        public static void UpdateWithPlayerList(this ToolStripComboBox combo)
        {
            if (combo.ComboBox.InvokeRequired)
            {
                Action <ToolStripComboBox> thisFunc = UpdateWithPlayerList;
                combo.ComboBox.Invoke(thisFunc, new object[] { combo });
                return;
            }

            string[] currentPlayerList = new string[combo.Items.Count];
            combo.Items.CopyTo(currentPlayerList, 0);


            List <string> playerStrings = new List <string>();

            playerStrings.Add(Resources.PublicResources.All);

            using (Database.AccessToTheDatabase dbAccess = new AccessToTheDatabase())
            {
                if (dbAccess.HasAccess)
                {
                    var playersFighting = from b in dbAccess.Database.Combatants
                                          where (((EntityType)b.CombatantType == EntityType.Player ||
                                                  (EntityType)b.CombatantType == EntityType.Pet ||
                                                  (EntityType)b.CombatantType == EntityType.Fellow ||
                                                  (EntityType)b.CombatantType == EntityType.CharmedMob) &&
                                                 b.GetInteractionsRowsByActorCombatantRelation().Any() == true)
                                          orderby b.CombatantName
                                          select b.CombatantName;

                    foreach (var player in playersFighting)
                    {
                        playerStrings.Add(player);
                    }
                }
            }

            string[] newPlayerList = playerStrings.ToArray();


            if (Array.Equals(currentPlayerList, newPlayerList) == true)
            {
                return;
            }


            combo.Items.Clear();

            combo.Items.AddRange(newPlayerList);
        }
Example #3
0
        public PlayerInfoDlg(ParserWindow parentWin)
        {
            InitializeComponent();

            parentWindow = parentWin;

            // Load information from the database and work with it
            // in a disconnected state.

            if (DatabaseManager.Instance.IsDatabaseOpen == false)
            {
                throw new InvalidOperationException();
            }

            databaseFilename = DatabaseManager.Instance.DatabaseFilename;

            using (AccessToTheDatabase db = new AccessToTheDatabase("PlayerInfo"))
            {
                if (db.Database.Combatants.Count > 0)
                {
                    var playerData = from com in db.Database.Combatants
                                     where ((EntityType)com.CombatantType == EntityType.Player ||
                                            (EntityType)com.CombatantType == EntityType.Pet ||
                                            (EntityType)com.CombatantType == EntityType.Fellow ||
                                            (EntityType)com.CombatantType == EntityType.CharmedMob)
                                     orderby com.CombatantName
                                     select new PlayerInfo
                    {
                        Name          = com.CombatantName,
                        CombatantType = (EntityType)com.CombatantType,
                        Info          = com.PlayerInfo
                    };

                    // Put the acquired data in the listbox

                    playerDataList = playerData.ToArray();

                    combatantListBox.Items.Clear();
                    foreach (var player in playerDataList)
                    {
                        combatantListBox.Items.Add(player.Name);
                    }

                    combatantListBox.SelectedIndex = 0;
                }
            }
        }
Example #4
0
        public static void UpdateWithSpeakerList(this ToolStripComboBox combo)
        {
            if (combo.ComboBox.InvokeRequired)
            {
                Action <ToolStripComboBox> thisFunc = UpdateWithSpeakerList;
                combo.ComboBox.Invoke(thisFunc, new object[] { combo });
                return;
            }

            string[] currentSpeakerList = new string[combo.Items.Count];
            combo.Items.CopyTo(currentSpeakerList, 0);


            List <string> speakerStrings = new List <string>();

            speakerStrings.Add(Resources.PublicResources.All);

            using (Database.AccessToTheDatabase dbAccess = new AccessToTheDatabase())
            {
                if (dbAccess.HasAccess)
                {
                    var speakers = from s in dbAccess.Database.ChatSpeakers
                                   orderby s.SpeakerName
                                   select s.SpeakerName;

                    foreach (var speaker in speakers)
                    {
                        speakerStrings.Add(speaker);
                    }
                }
            }

            string[] newSpeakerList = speakerStrings.ToArray();

            if (Array.Equals(currentSpeakerList, newSpeakerList) == true)
            {
                return;
            }

            combo.Items.Clear();
            combo.Items.AddRange(newSpeakerList);
        }
Example #5
0
        /// <summary>
        /// Gets a list of all speakers in the chat table.
        /// </summary>
        /// <returns></returns>
        protected string[] GetSpeakerListing()
        {
            List <string> speakerStrings = new List <string>();

            speakerStrings.Add("All");

            using (Database.AccessToTheDatabase dbAccess = new AccessToTheDatabase())
            {
                if (dbAccess.HasAccess)
                {
                    var speakers = from s in dbAccess.Database.ChatSpeakers
                                   orderby s.SpeakerName
                                   select s.SpeakerName;

                    foreach (var speaker in speakers)
                    {
                        speakerStrings.Add(speaker);
                    }
                }
            }

            return(speakerStrings.ToArray());
        }
Example #6
0
        private void ResetAndEnable()
        {
            // Only attempt to load info if a parse is open but not running.
            if ((DatabaseManager.Instance.IsDatabaseOpen == true) &&
                (Monitoring.Monitor.Instance.IsRunning == false))
            {
                startGroup.Enabled   = true;
                endGroup.Enabled     = true;
                acceptButton.Enabled = true;

                using (Database.AccessToTheDatabase dbAccess = new AccessToTheDatabase())
                {
                    if (dbAccess.HasAccess)
                    {
                        // Determine the first and last timestamp of the database
                        var  firstLine = dbAccess.Database.RecordLog.FirstOrDefault();
                        bool hasData   = (firstLine != null);

                        startAtBeginningOfParse.Enabled = hasData;
                        endAtEndOfParse.Enabled         = hasData;
                        startAtTime.Enabled             = hasData;
                        endAtTime.Enabled = hasData;

                        if (hasData == true)
                        {
                            firstTime = firstLine.Timestamp;

                            var lastLine = dbAccess.Database.RecordLog.Last();
                            lastTime = lastLine.Timestamp;

                            // Set these values as the min/max value for the datetimepickers.
                            startDateTimePicker.MinDate = firstTime.ToLocalTime();
                            startDateTimePicker.MaxDate = lastTime.ToLocalTime();
                            startDateTimePicker.Value   = firstTime.ToLocalTime();
                            endDateTimePicker.MinDate   = firstTime.ToLocalTime();
                            endDateTimePicker.MaxDate   = lastTime.ToLocalTime();
                            endDateTimePicker.Value     = lastTime.ToLocalTime();

                            // And update the default choices and boundaries with these values.
                            startAtBeginningOfParse.Checked = true;
                            endAtEndOfParse.Checked         = true;
                            StartBoundary = firstTime;
                            EndBoundary   = lastTime;
                        }
                        else
                        {
                            // If there's nothing in the database, default the values and return.
                            firstTime = DateTime.MinValue;
                            lastTime  = DateTime.MinValue;

                            // Disable everything if there's nothing in the database.
                            startGroup.Enabled   = false;
                            endGroup.Enabled     = false;
                            acceptButton.Enabled = false;

                            return;
                        }

                        // If there are any fights in the database, enable the options
                        // to use those as demarcations, and load the battle list.
                        bool hasBattles = dbAccess.Database.Battles.Any(b => b.DefaultBattle == false);

                        startAtStartOfFight.Enabled = hasBattles;
                        startAtEndOfFight.Enabled   = hasBattles;
                        endAtStartOfFight.Enabled   = hasBattles;
                        endAtEndOfFight.Enabled     = hasBattles;

                        if (hasBattles == true)
                        {
                            LoadBattleLists(dbAccess);
                        }
                    }
                }
            }
            else
            {
                // Disable everything if basic conditions aren't met.
                startGroup.Enabled   = false;
                endGroup.Enabled     = false;
                acceptButton.Enabled = false;
            }
        }
Example #7
0
        /// <summary>
        /// Gets a string array of mob names with formatting for either fight number or XP gained.
        /// </summary>
        /// <param name="groupMobs">Whether mobs should be grouped by name/XP.</param>
        /// <param name="exclude0XPMobs">Whether to include mobs that gave no XP.</param>
        /// <returns>A string array.</returns>
        protected string[] GetMobListing(bool groupMobs, bool exclude0XPMobs)
        {
            List <string> mobStrings = new List <string>();

            mobStrings.Add(Resources.PublicResources.All);

            // Group enemies check

            using (Database.AccessToTheDatabase dbAccess = new AccessToTheDatabase())
            {
                if (dbAccess.HasAccess)
                {
                    if (groupMobs == true)
                    {
                        // Enemy group listing

                        var mobsKilled = from b in dbAccess.Database.Battles
                                         where ((b.DefaultBattle == false) &&
                                                (b.IsEnemyIDNull() == false) &&
                                                ((EntityType)b.CombatantsRowByEnemyCombatantRelation.CombatantType == EntityType.Mob))
                                         orderby b.CombatantsRowByEnemyCombatantRelation.CombatantName
                                         group b by b.CombatantsRowByEnemyCombatantRelation.CombatantName into bn
                                         select new
                        {
                            Name = bn.Key,
                            XP   = from xb in bn
                                   group xb by xb.MinBaseExperience() into xbn
                                   orderby xbn.Key
                                   select new { BaseXP = xbn.Key }
                        };

                        foreach (var mob in mobsKilled)
                        {
                            if (mob.XP.Count() > 1)
                            {
                                if (exclude0XPMobs == true)
                                {
                                    if (mob.XP.Any(x => x.BaseXP > 0) == true)
                                    {
                                        mobStrings.Add(mob.Name);
                                    }
                                }
                                else
                                {
                                    mobStrings.Add(mob.Name);
                                }
                            }

                            foreach (var xp in mob.XP)
                            {
                                if (exclude0XPMobs == true)
                                {
                                    if (xp.BaseXP > 0)
                                    {
                                        mobStrings.Add(string.Format("{0} ({1})", mob.Name, xp.BaseXP));
                                    }
                                }
                                else
                                {
                                    mobStrings.Add(string.Format("{0} ({1})", mob.Name, xp.BaseXP));
                                }
                            }
                        }
                    }
                    else
                    {
                        // Enemy battle listing

                        var mobsKilled = from b in dbAccess.Database.Battles
                                         where ((b.DefaultBattle == false) &&
                                                (b.IsEnemyIDNull() == false) &&
                                                ((EntityType)b.CombatantsRowByEnemyCombatantRelation.CombatantType == EntityType.Mob))
                                         orderby b.BattleID
                                         select new
                        {
                            Name   = b.CombatantsRowByEnemyCombatantRelation.CombatantName,
                            Battle = b.BattleID,
                            XP     = b.BaseExperience()
                        };

                        foreach (var mob in mobsKilled)
                        {
                            if (exclude0XPMobs == true)
                            {
                                if (mob.XP > 0)
                                {
                                    mobStrings.Add(string.Format("{0,3}: {1}", mob.Battle, mob.Name));
                                }
                            }
                            else
                            {
                                mobStrings.Add(string.Format("{0,3}: {1}", mob.Battle, mob.Name));
                            }
                        }
                    }
                }
            }

            return(mobStrings.ToArray());
        }
Example #8
0
        protected void HandleDataset(KPDatabaseDataSet databaseChanges)
        {
            if (InvokeRequired)
            {
                Action <KPDatabaseDataSet> handleDataset = new Action <KPDatabaseDataSet>(HandleDataset);
                object[] dbChanges = new object[1] {
                    databaseChanges
                };

                //BeginInvoke(handleDataset, dbChanges);
                Invoke(handleDataset, dbChanges);
                return;
            }

            // Lock in case a UI update sends a message to start reprocessing
            // at the same time as the code is processing a message from the
            // database being updated, or vice versa.
            lock (privateLock)
            {
                try
                {
                    // Retain current cursor position and/or selection
                    int currentSelectionStart  = richTextBox.SelectionStart;
                    int currentSelectionLength = richTextBox.SelectionLength;

                    richTextBox.SuspendLayout();

                    if (databaseChanges == null)
                    {
                        using (AccessToTheDatabase dbAccess = new AccessToTheDatabase())
                        {
                            if (dbAccess.HasAccess)
                            {
                                ProcessData(dbAccess.Database);
                            }
                        }
                    }
                    else
                    {
                        ProcessData(databaseChanges);
                    }

                    // After processing, re-select the same section as before, or
                    // set it to the start of the display.
                    if (currentSelectionStart <= richTextBox.Text.Length)
                    {
                        richTextBox.Select(currentSelectionStart, currentSelectionLength);
                    }
                    else
                    {
                        richTextBox.Select(0, 0);
                    }

                    //richTextBox.Select(richTextBox.Text.Length, richTextBox.Text.Length);

                    richTextBox.ResumeLayout();
                }
                catch (Exception e)
                {
                    Logger.Instance.Log(e);
                    MessageBox.Show("Error while processing plugin: \n" + e.Message);
                }
            }
        }