public List <RaidBossFight> GetBossFights(FightDataCollection _FightDataCollection)
        {
            List <RaidBossFight> bossFights = new List <RaidBossFight>();

            var fightsOrdered = _GetDungeonFightsOrdered((string _DataFile) => { return(_FightDataCollection); });

            for (int i = 0; i < fightsOrdered.Count; ++i)
            {
                bossFights.Add(new RaidBossFight(this, i, fightsOrdered[i]));
            }
            return(bossFights);
        }
Пример #2
0
 private FightDataCollection _LoadRaidFightCollectionFile(string _FightFile)
 {
     if (_FightFile.StartsWith(VF_RealmPlayersDatabase.Utility.DefaultServerLocation + "VF_RealmPlayersData\\RDDatabase\\"))
     {
         _FightFile = _FightFile.Substring((VF_RealmPlayersDatabase.Utility.DefaultServerLocation + "VF_RealmPlayersData\\RDDatabase\\").Length);
     }
     VF_RaidDamageDatabase.FightDataCollection fightDataCollection = null;
     if (VF.Utility.LoadSerialize(m_RDDBFolder + _FightFile, out fightDataCollection) == false)
     {
         return(null);
     }
     return(fightDataCollection);
 }
Пример #3
0
        public List <RaidBossFight> GetBossFights(FightDataCollection _FightDataCollection, VF_RDDatabase.Raid _RaidSummary)
        {
            //_RaidSummary CAN BE NULL
            List <RaidBossFight> bossFights = new List <RaidBossFight>();

            var fightsOrdered = _GetRaidFightsOrdered((string _DataFile) => { return(_FightDataCollection); }, _RaidSummary);

            for (int i = 0; i < fightsOrdered.Count; ++i)
            {
                bossFights.Add(new RaidBossFight(this, i, fightsOrdered[i]));
            }
            return(bossFights);
        }
Пример #4
0
 public FightCacheData(FightData _Fight, FightDataCollection _FightDataCollection)
 {
     m_Fight = _Fight;
     m_FightDataCollection = _FightDataCollection;
 }
Пример #5
0
        public void AddFightCollection(FightDataCollection _Fights, string _DataFileName, List <RaidCollection_Raid> _ReturnRaidsModified, List <RaidCollection_Dungeon> _ReturnDungeonsModified)
        {
            List <int> raidsAdded    = new List <int>();
            List <int> dungeonsAdded = new List <int>();

            foreach (var fight in _Fights.Fights)
            {
                var realm = VF_RealmPlayersDatabase.StaticValues.ConvertRealm(fight.m_Fight.Realm);
                if (BossInformation.BossFights.ContainsKey(fight.m_Fight.FightName) == false && fight.m_Fight.FightName != "Trash")
                {
                    Logger.ConsoleWriteLine("Fightname(" + fight.m_Fight.FightName + ") is not a BossFight!", ConsoleColor.Red);
                    continue;
                }
                bool isDungeon = false;
                if (fight.m_Fight.RaidID == -1)
                {
                    isDungeon = true;
                }

                if (isDungeon == false && fight.m_Fight.RaidID == -1)
                {
                    Logger.ConsoleWriteLine("Fightname(" + fight.m_Fight.FightName + ") was RaidID -1 so it is skipped!", ConsoleColor.Yellow);
                    continue;//Skip RaidIDs that are -1
                }

                if (isDungeon == true)
                {
                    Logger.ConsoleWriteLine("Fightname(" + fight.m_Fight.FightName + ") was Dungeon so it is skipped!", ConsoleColor.Yellow);
                    continue;//Skip Dungeons...

                    Dictionary <string, int> zoneSlices = new Dictionary <string, int>();
                    foreach (var timeSlice in fight.m_Fight.TimeSlices)
                    {
                        if (BossInformation.IsDungeonZone(timeSlice.Zone) == true)
                        {
                            if (zoneSlices.ContainsKey(timeSlice.Zone) == true)
                            {
                                zoneSlices[timeSlice.Zone] = zoneSlices[timeSlice.Zone] + 1;
                            }
                            else
                            {
                                zoneSlices[timeSlice.Zone] = 1;
                            }
                        }
                    }
                    var orderedZones = zoneSlices.OrderByDescending((_Value) => _Value.Value);
                    if (orderedZones.Count() > 0)
                    {
                        string        dungeonZone  = orderedZones.First().Key;
                        List <string> groupMembers = new List <string>();
                        foreach (var timeSlice in fight.m_Fight.TimeSlices)
                        {
                            if (timeSlice.Zone == dungeonZone)
                            {
                                if (timeSlice.GroupMemberIDs != null)
                                {
                                    foreach (var groupMemberID in timeSlice.GroupMemberIDs)
                                    {
                                        groupMembers.AddUnique(_Fights.GetNameFromUnitID(groupMemberID));
                                    }
                                }
                            }
                        }
                        if (groupMembers.Count() == 0)
                        {
                            bool foundZone = false;
                            for (int i = fight.m_Fight.TimeSlices.Count - 1; i >= 0; --i)
                            {
                                var timeSlice = fight.m_Fight.TimeSlices[i];
                                if (timeSlice.Zone == dungeonZone)
                                {
                                    foundZone = true;
                                }
                                if (foundZone == true && timeSlice.GroupMemberIDs != null)
                                {
                                    foreach (var groupMemberID in timeSlice.GroupMemberIDs)
                                    {
                                        groupMembers.AddUnique(_Fights.GetNameFromUnitID(groupMemberID));
                                    }
                                    break;
                                }
                            }
                        }
                        var match = m_Dungeons.FirstOrDefault((_Value) =>
                        {
                            if (_Value.Value.Realm == realm && _Value.Value.m_Dungeon == dungeonZone &&
                                Math.Abs((_Value.Value.m_DungeonStartDate - fight.m_Fight.StartDateTime).TotalHours) < 4)
                            {
                                if (groupMembers.Count > _Value.Value.m_GroupMembers.Count)
                                {
                                    foreach (var groupMember in groupMembers)
                                    {
                                        if (_Value.Value.m_GroupMembers.Contains(groupMember) == false)
                                        {
                                            return(false);
                                        }
                                    }
                                }
                                else
                                {
                                    foreach (var groupMember in _Value.Value.m_GroupMembers)
                                    {
                                        if (groupMembers.Contains(groupMember) == false)
                                        {
                                            return(false);
                                        }
                                    }
                                }
                                return(true);
                            }
                            return(false);
                        });
                        RaidCollection_Dungeon currDungeon = null;
                        if (match.Equals(default(KeyValuePair <int, RaidCollection_Dungeon>)) == false)
                        {
                            currDungeon = match.Value;
                        }

                        if (currDungeon == null && fight.m_Fight.FightName == "Trash")
                        {
                            continue;
                        }

                        if (currDungeon == null)
                        {
                            currDungeon = new RaidCollection_Dungeon();
                            if (fight.m_Fight.FightName != "Trash")
                            {
                                currDungeon.m_Dungeon = BossInformation.BossFights[fight.m_Fight.FightName];
                            }
                            else
                            {
                                currDungeon.m_Dungeon = dungeonZone;
                            }
                            currDungeon.m_UniqueDungeonID = ++m_UniqueDungeonIDCounter;
                            currDungeon.Realm             = realm;
                            m_Dungeons.Add(currDungeon.m_UniqueDungeonID, currDungeon);
                            dungeonsAdded.Add(currDungeon.m_UniqueDungeonID);
                        }
                        if (currDungeon.AddDataFile(fight, _DataFileName) == true)
                        {
                            currDungeon.m_GroupMembers.AddRangeUnique(groupMembers);
                            if (_ReturnRaidsModified != null)
                            {
                                if (_ReturnDungeonsModified.Contains(currDungeon) == false)
                                {
                                    _ReturnDungeonsModified.Add(currDungeon);
                                }
                            }
                            if (fight.m_Fight.FightName != "Trash")
                            {
                                if (fight.m_Fight.StartDateTime < currDungeon.m_DungeonStartDate)
                                {
                                    currDungeon.m_DungeonStartDate = fight.m_Fight.StartDateTime;
                                }
                                if (fight.m_Fight.GetEndDateTime() > currDungeon.m_DungeonEndDate)
                                {
                                    currDungeon.m_DungeonEndDate = fight.m_Fight.GetEndDateTime();
                                }
                            }
                        }
                    }
                }
                else
                {
                    //Dictionary<string, int> zoneSlices = new Dictionary<string,int>();
                    //foreach(var timeSlice in fight.m_Fight.TimeSlices)
                    //{
                    //    if (BossInformation.IsRaidZone(timeSlice.Zone) == true)
                    //    {
                    //        if (zoneSlices.ContainsKey(timeSlice.Zone) == true)
                    //        {
                    //            zoneSlices[timeSlice.Zone] = zoneSlices[timeSlice.Zone] + 1;
                    //        }
                    //        else
                    //        {
                    //            zoneSlices[timeSlice.Zone] = 1;
                    //        }
                    //    }
                    //}
                    //var orderedZones = zoneSlices.OrderByDescending((_Value) => _Value.Value);
                    //string raidZone = null;
                    //List<string> groupMembers = new List<string>();
                    //if (orderedZones.Count() > 0)
                    //{
                    //    raidZone = orderedZones.First().Key;
                    //    foreach (var timeSlice in fight.m_Fight.TimeSlices)
                    //    {
                    //        if (timeSlice.Zone == raidZone)
                    //        {
                    //            if (timeSlice.GroupMemberIDs != null)
                    //            {
                    //                foreach (var groupMemberID in timeSlice.GroupMemberIDs)
                    //                {
                    //                    groupMembers.AddUnique(_Fights.GetNameFromUnitID(groupMemberID));
                    //                }
                    //            }
                    //        }
                    //    }
                    //    if (groupMembers.Count == 0)
                    //    {
                    //        bool foundZone = false;
                    //        for (int i = fight.m_Fight.TimeSlices.Count - 1; i >= 0; --i)
                    //        {
                    //            var timeSlice = fight.m_Fight.TimeSlices[i];
                    //            if (timeSlice.Zone == raidZone)
                    //            {
                    //                foundZone = true;
                    //            }
                    //            if (foundZone == true && timeSlice.GroupMemberIDs != null)
                    //            {
                    //                foreach (var groupMemberID in timeSlice.GroupMemberIDs)
                    //                {
                    //                    groupMembers.AddUnique(_Fights.GetNameFromUnitID(groupMemberID));
                    //                }
                    //                break;
                    //            }
                    //        }
                    //    }
                    //}
                    List <string> groupMembers = new List <string>(_Fights.m_RaidMembers);
                    var           match        = m_Raids.FirstOrDefault((_Value) =>
                    {
                        if (_Value.Value.RaidID == fight.m_Fight.RaidID)
                        {
                            if (_Value.Value.RaidID != -1)
                            {
                                if ((_Value.Value.RaidResetDateTime - fight.m_Fight.RaidResetDateTime).Days == 0 && _Value.Value.Realm == realm)
                                {
                                    if (_Value.Value.GetRecordedByPlayers().Contains(fight.m_Fight.RecordedByPlayer))
                                    {
                                        return(true);
                                    }
                                    if (groupMembers.Count > 0 && _Value.Value.m_GroupMembers != null && _Value.Value.m_GroupMembers.Count > 0)
                                    {
                                        int foundMembersCount = 0;
                                        foreach (var groupMember in groupMembers)
                                        {
                                            if (_Value.Value.m_GroupMembers.Contains(groupMember) == true)
                                            {
                                                foundMembersCount++;
                                            }
                                        }
                                        if (foundMembersCount < 5)
                                        {
                                            if (foundMembersCount < 1)
                                            {
                                                return(false);
                                            }
                                            if (_Value.Value.m_GroupMembers.Count >= 40 && groupMembers.Count >= 20)
                                            {
                                                return(false);
                                            }
                                        }
                                    }
                                    return(true);
                                }
                            }
                            //else
                            //{
                            //    throw new Exception("Does not support this anymore!");
                            //    if (raidsAdded.Contains(_Value.Key))
                            //    {
                            //        if (_Value.Value.RaidInstance == BossInformation.BossFights[fight.m_Fight.FightName])
                            //        {
                            //            return true;
                            //        }
                            //    }
                            //}
                        }
                        return(false);
                    });
                    RaidCollection_Raid currRaid = null;
                    if (match.Equals(default(KeyValuePair <int, RaidCollection_Raid>)) == false)
                    {
                        currRaid = match.Value;
                    }

                    if (currRaid == null)
                    {
                        currRaid                   = new RaidCollection_Raid();
                        currRaid.RaidID            = fight.m_Fight.RaidID;
                        currRaid.RaidResetDateTime = fight.m_Fight.RaidResetDateTime;
                        currRaid.RaidOwnerName     = "";// _DataFileName.Split('\\', '/').Last().Split('_').First();
                        if (fight.m_Fight.FightName != "Trash")
                        {
                            currRaid.RaidInstance = BossInformation.BossFights[fight.m_Fight.FightName];
                        }
                        else
                        {
                            //raidZone(if != null) can possibly be used here in the future since it is calculated by looking at players zones while in the raid.
                            var raidDefineFight = _Fights.Fights.FirstOrDefault((_Value) =>
                            {
                                return(_Value.m_Fight.RaidID == fight.m_Fight.RaidID &&
                                       (_Value.m_Fight.RaidResetDateTime - fight.m_Fight.RaidResetDateTime).Days == 0 &&
                                       VF_RealmPlayersDatabase.StaticValues.ConvertRealm(_Value.m_Fight.Realm) == realm &&
                                       _Value.m_Fight.FightName != "Trash");
                            });
                            if (raidDefineFight != null && raidDefineFight.Equals(default(KeyValuePair <int, RaidCollection_Raid>)) == false)
                            {
                                currRaid.RaidInstance = BossInformation.BossFights[raidDefineFight.m_Fight.FightName];
                            }
                            else
                            {
                                continue;//Skip this Trash!
                            }
                        }
                        currRaid.UniqueRaidID = ++m_UniqueRaidIDCounter;
                        currRaid.Realm        = realm;
                        m_Raids.Add(currRaid.UniqueRaidID, currRaid);
                        raidsAdded.Add(currRaid.UniqueRaidID);
                    }
                    if (currRaid.AddDataFile(fight, _DataFileName) == true)
                    {
                        if (currRaid.m_GroupMembers != null && groupMembers.Count > 0)
                        {
                            currRaid.m_GroupMembers.AddRangeUnique(groupMembers);
                        }
                        if (_ReturnRaidsModified != null)
                        {
                            if (_ReturnRaidsModified.Contains(currRaid) == false)
                            {
                                _ReturnRaidsModified.Add(currRaid);
                            }
                        }
                        if (fight.m_Fight.FightName != "Trash")
                        {
                            if (fight.m_Fight.StartDateTime < currRaid.RaidStartDate)
                            {
                                currRaid.RaidStartDate = fight.m_Fight.StartDateTime;
                            }
                            if (fight.m_Fight.GetEndDateTime() > currRaid.RaidEndDate)
                            {
                                currRaid.RaidEndDate = fight.m_Fight.GetEndDateTime();
                            }
                        }
                    }
                }
            }
        }
Пример #6
0
        static void Main(string[] args)
        {
            List <DamageDataSession> dataSessions     = new List <DamageDataSession>();
            List <string>            sessionDebugData = new List <string>();

            dataSessions = DamageDataParser.ParseFile("2014_05_03_20_59_00_FID0506.txt", ref sessionDebugData);

            var fights = FightDataCollection.GenerateFights(dataSessions);//, BossInformation.BossFights);

#if Use_Main
            RaidCollection raidCollection = null;
            if (System.IO.File.Exists("RaidCollection.dat") == true)
            {
                VF.Utility.LoadSerialize <RaidCollection>("RaidCollection.dat", out raidCollection);
            }
            else
            {
                raidCollection = new RaidCollection();
                if (System.IO.Directory.Exists("OldDataFiles\\"))
                {
                    string[] datFiles = System.IO.Directory.GetFiles("OldDataFiles\\");
                    foreach (string file in datFiles)
                    {
                        if (file.EndsWith(".dat") == true)
                        {
                            Logger.ConsoleWriteLine("Started Loading \"" + file + "\"", ConsoleColor.Green);
                            FightDataCollection loadedData = null;
                            VF.Utility.LoadSerialize(file, out loadedData);

                            string[] fileSplit = file.Split('_');
                            //string month = fileSplit[fileSplit.Count()-2];
                            //string year = fileSplit[fileSplit.Count()-3];
                            //string raidOwner = fileSplit[0].Split('\\')[1];
                            //for (int i = 1; i < fileSplit.Count() - 3; ++i)
                            //{
                            //    raidCollection.AddFightCollection(
                            //}
                            raidCollection.AddFightCollection(loadedData, file);
                            //foreach (var raid in raidCollection.m_Raids)
                            //{
                            //    if (raid.Value.m_DataFiles.Contains(file))
                            //    {
                            //        raid.Value.RaidOwnerName = fileSplit[0].Split('\\')[1];
                            //    }
                            //}
                        }
                    }
                }
            }
            bool        backupedUpRaidCollection = false;
            RPPDatabase rppDatabase = null;
            string[]    luaFiles    = System.IO.Directory.GetFiles("./");
            foreach (string file in luaFiles)
            {
                if (file.EndsWith(".lua") == true)
                {
                    string fightCollectionDatName = "DataFiles\\" + DateTime.UtcNow.ToString("yyyy_MM") + "\\" + file.Replace(".lua", ".dat");
                    fightCollectionDatName = VF.Utility.ConvertToUniqueFilename(fightCollectionDatName);
                    List <DamageDataSession> dataSessions = new List <DamageDataSession>();
                    dataSessions = DamageDataParser.ParseFile(file);

                    var fights = FightDataCollection.GenerateFights(dataSessions);//, BossInformation.BossFights);

                    Logger.ConsoleWriteLine(file + " contained " + fights.Fights.Count + " fights", ConsoleColor.Yellow);
                    if (fights.Fights.Count >= 1)
                    {
                        List <RaidCollection_Raid> raidsModified = new List <RaidCollection_Raid>();
                        raidCollection.AddFightCollection(fights, fightCollectionDatName, raidsModified);
                        //TESTING
                        if (raidsModified.Count > 0)
                        {
                            Logger.ConsoleWriteLine("--------------------", ConsoleColor.White);
                            int totalFightCount = 0;
                            foreach (var raid in raidsModified)
                            {
                                var bossFights = raid.GetBossFights(fights);
                                Logger.ConsoleWriteLine("Raid: " + raid.RaidInstance + "(" + raid.RaidID + ") by " + raid.RaidOwnerName, ConsoleColor.White);
                                foreach (var bossFight in bossFights)
                                {
                                    ++totalFightCount;
                                    bossFight.GetFightDetails(); //Trigger FightDetail request, so we get error here instead of later on the website.
                                    //Logger.ConsoleWriteLine("Fight: " + bossFight.GetBossName() + " added to RaidCollection", ConsoleColor.Green);
                                }
                                if (raid.RaidOwnerName.ToLower() == "unknown" || raid.RaidOwnerName == "")
                                {
                                    if (rppDatabase == null)
                                    {
                                        string rppDBDir       = VF_RealmPlayersDatabase.Utility.DefaultServerLocation + "VF_RealmPlayersData\\RPPDatabase\\Database\\";
                                        var    timeSinceWrite = DateTime.UtcNow - System.IO.File.GetLastWriteTime(rppDBDir + "Emerald_Dream\\PlayersData.dat");
                                        if (timeSinceWrite.TotalHours > 5)
                                        {
                                            if (timeSinceWrite.TotalDays > 20 ||
                                                System.Windows.Forms.MessageBox.Show("The file: \"" + rppDBDir + "Emerald_Dream\\PlayersData.dat\" is older than 5 hours. Do you want to use the database from the server instead?", "", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                                            {
                                                rppDBDir = "\\\\" + HiddenStrings.ServerComputerName + "\\VF_RealmPlayersData\\RPPDatabase\\Database\\";
                                            }
                                        }
                                        Logger.ConsoleWriteLine("Loaded RPPDatabase(\"" + rppDBDir + "\")", ConsoleColor.Magenta);
                                        rppDatabase = new RPPDatabase(rppDBDir);
                                    }
                                    var           realmDB          = rppDatabase.GetRealmDB(raid.Realm);
                                    List <string> attendingPlayers = new List <string>();
                                    foreach (var bossFight in bossFights)
                                    {
                                        attendingPlayers.AddRange(bossFight.GetAttendingUnits(realmDB.RD_IsPlayer));
                                    }
                                    if (attendingPlayers.Count() > 10)
                                    {
                                        Dictionary <string, int> guildCount = new Dictionary <string, int>();
                                        foreach (var attendingPlayer in attendingPlayers)
                                        {
                                            string guildName = realmDB.GetPlayer(attendingPlayer).Guild.GuildName;
                                            if (guildCount.ContainsKey(guildName))
                                            {
                                                guildCount[guildName] = guildCount[guildName] + 1;
                                            }
                                            else
                                            {
                                                guildCount.Add(guildName, 1);
                                            }
                                        }
                                        var biggestGuildCount = guildCount.OrderByDescending((_Value) => _Value.Value).First();
                                        if (biggestGuildCount.Value > attendingPlayers.Count / 2)
                                        {
                                            raid.RaidOwnerName = biggestGuildCount.Key;
                                        }
                                        else
                                        {
                                            raid.RaidOwnerName = "PUG";
                                        }

                                        Logger.ConsoleWriteLine("Raid: Changed RaidOwnerName for " + raid.RaidInstance + "(" + raid.RaidID + ") to " + raid.RaidOwnerName, ConsoleColor.White);
                                    }
                                }
                            }
                            Logger.ConsoleWriteLine("--------------------", ConsoleColor.White);
                            VF.Utility.BackupFile(/*VF_RealmPlayersDatabase.Utility.DefaultServerLocation + "VF_RealmPlayersData\\RDDatabase\\" + */ fightCollectionDatName);
                            VF.Utility.SaveSerialize(/*VF_RealmPlayersDatabase.Utility.DefaultServerLocation + "VF_RealmPlayersData\\RDDatabase\\" + */ fightCollectionDatName, fights);
                            string luaCopyFile = VF.Utility.ConvertToUniqueFilename("Lua\\" + file);
                            VF.Utility.AssertFilePath(luaCopyFile);
                            System.IO.File.Move(file, luaCopyFile);
                            if (backupedUpRaidCollection == false)
                            {
                                VF.Utility.BackupFile("RaidCollection.dat", VF.Utility.BackupMode.Backup_Always_TimeInFilename);
                                VF.Utility.BackupFile("RaidCollection.dat", VF.Utility.BackupMode.Backup_Daily);
                                backupedUpRaidCollection = true;
                            }
                            VF.Utility.SaveSerialize("RaidCollection.dat", raidCollection, false);
                            Logger.ConsoleWriteLine(file + " added " + totalFightCount + " fights to RaidCollection", ConsoleColor.Green);
                        }
                        else
                        {
                            Logger.ConsoleWriteLine(file + " already exists in RaidCollection, skipping", ConsoleColor.Green);
                        }
                    }
                    //Utility.BackupFile(VF_RealmPlayersDatabase.Utility.DefaultServerLocation + "VF_RealmPlayersData\\RDDatabase\\DamageDataSessions\\" + file.Replace(".lua", ".DamageDataSessions.dat"));
                    //Utility.SaveSerialize(VF_RealmPlayersDatabase.Utility.DefaultServerLocation + "VF_RealmPlayersData\\RDDatabase\\DamageDataSessions\\" + file.Replace(".lua", ".DamageDataSessions.dat"), dataSessions);
                }
            }
            Logger.ConsoleWriteLine("Done with all lua parsing", ConsoleColor.Green);
            Logger.ConsoleWriteLine("Press any key to exit", ConsoleColor.Green);
            if (System.Threading.Tasks.Task.Factory.StartNew(() => Console.ReadKey()).Wait(TimeSpan.FromSeconds(30.0)) == false)
            {
                Logger.ConsoleWriteLine("Aautomicly closing the program in 5 seconds", ConsoleColor.White);
                System.Threading.Tasks.Task.Factory.StartNew(() => Console.ReadKey()).Wait(TimeSpan.FromSeconds(5.0));
            }
#endif
        }