private static void UpdateCache(List <CheckPlayer> players, RaidOrgaPlusCache playerCache, long raidID)
 {
     foreach (var p in players)
     {
         if (p.Player.Type != p.BecomesType)
         {
             playerCache.Set(raidID, p.Player.AccountName, p.BecomesAccount?.ID ?? 1);
         }
     }
     playerCache.Save();
 }
        public static Raid UpdateRaid(Raid raid, IEnumerable <CachedLog> logs, Action <Delegate> invoker, IProgress <ProgressMessage> progress = null)
        {
            progress?.Report(new ProgressMessage(0.01, "Remove outdated logs"));
            logs = logs.Where(l => l.DataVersion >= MIN_DATA_VERSION);
            progress?.Report(new ProgressMessage(0.02, "Remove duplicated bosses"));
            logs = OnlyGetOnePerBoss(logs);
            CondenseStatues(logs);

            MatchCMandNormal(raid, logs);
            progress?.Report(new ProgressMessage(0.03, "Remove unused bosses from RO+ data"));
            RemoveUnused(raid, logs);

            progress?.Report(new ProgressMessage(0.04, "Create missing bosses"));
            InsertLogs(raid, logs);

            progress?.Report(new ProgressMessage(0.05, "Build encounters"));
            var encounters = GetEncounters(raid, logs);

            progress?.Report(new ProgressMessage(0.08, "Gather players"));
            var players = GetAllPlayers(raid, encounters);

            progress?.Report(new ProgressMessage(0.09, "Loading cached players"));
            var playerCache = new RaidOrgaPlusCache();

            progress?.Report(new ProgressMessage(0.10, "Applying cached players"));
            ApplyCache(players, playerCache, raid);

            progress?.Report(new ProgressMessage(0.11, "Assigen players"));
            ShowCorrectPlayerUI(players, raid, invoker);

            progress?.Report(new ProgressMessage(0.15, "Update players and cache"));
            UpdateCache(players, playerCache, raid.RaidID);

            progress?.Report(new ProgressMessage(0.16, "Update players and cache"));
            CorrectPlayers(players, encounters);

            UpdateRaidOrgaPlusData(raid, encounters, new Progress <ProgressMessage>((p) => progress?.Report(new ProgressMessage((p.Percent * 0.81) + 0.17, "Update boss " + p.Message))));

            progress?.Report(new ProgressMessage(0.98, "Update players to invite"));
            UpdatePlayersToInvite(raid, encounters);
            progress?.Report(new ProgressMessage(1, "Done"));
            return(raid);
        }
        private static void ApplyCache(List <CheckPlayer> players, RaidOrgaPlusCache playerCache, Raid r)
        {
            foreach (var p in players)
            {
                if (p.Player.Type != PlayerType.MEMBER)
                {
                    var becomesID = playerCache.Get(r.RaidID, p.Player.AccountName);
                    switch (becomesID)
                    {
                    case -1:     //Not in cache
                        break;

                    case 1:     //LFG
                        p.BecomesAccount = null;
                        p.BecomesType    = PlayerType.LFG;
                        break;

                    default:     //Knowen Account
                        if (r.IsMember(becomesID))
                        {
                            p.BecomesAccount = r.GetMember(becomesID);
                            p.BecomesType    = PlayerType.MEMBER;
                        }
                        else if (r.IsInviteable(becomesID))
                        {
                            p.BecomesAccount = r.GetInviteable(becomesID);
                            p.BecomesType    = PlayerType.INVITEABLE;
                        }
                        else if (r.IsHelper(becomesID))
                        {
                            p.BecomesAccount = r.GetHelper(becomesID);
                            p.BecomesType    = PlayerType.HELPER;
                        }
                        break;
                    }
                }
            }
        }