示例#1
0
    private IEnumerable <DB_Rankings> GetSearchSpace(short type)
    {
        //short.TryParse(pmType.Value, out type);
        List <int> selected = GetSelectedNpcs(m_EncounterVal);
        var        query    = App.m_Rankings.Where(x => x.Type == type && selected.Contains(x.NpcID) && x.CharID >= 301000);

        if (pmRealm.Value != "0")
        {
            short id = 0;
            if (short.TryParse(pmRealm.Value, out id) && id != 0)
            {
                query = query.Where(x => App.GetChar(x.CharID).ServerID == id);
            }
        }
        if (pmFaction.Value != "0")
        {
            short id = 0;
            if (short.TryParse(pmFaction.Value, out id) && id != 0)
            {
                query = query.Where(x => App.GetChar(x.CharID).Faction == id);
            }
        }
        if (pmClass.Value != "0")
        {
            short id = 0;
            if (short.TryParse(pmClass.Value, out id) && id != 0)
            {
                query = query.Where(x => App.GetChar(x.CharID).RefMisc.Class == id - 1); // This might not be changed everywhere xD
            }
        }

        if (pmSelection.Value == "0")
        {
            query = query.Where(x => x.Average.Count(y => y.Time > 0) >= 5);
        }

        if (selected.Count <= 1)
        {
            return(query);
        }

        List <DB_Rankings> newList = new List <DB_Rankings>();

        foreach (var grp in query.GroupBy(x => new{ x.CharID, x.Type })) // Is that correct grouping?
        {
            DB_Rankings temp = new DB_Rankings();
            int         value, time, attempt;
            uint        killed = 0;
            value = time = attempt = 0;
            int count = grp.Count();
            temp.Average = new List <DB_Ranking>();

            // Checking if all selected bosses have been killed by this character
            if ((grp.Count() < selected.Count) &&
                (grp.FirstOrDefault().InstanceID != 0)
                )
            {
                if (grp.FirstOrDefault().InstanceID == 19)
                {
                    if (grp.Count() < selected.Count - 3)
                    {
                        continue;
                    }
                }
                else
                {
                    continue;
                }
            }

            foreach (var item in grp)
            {
                temp.CharID     = item.CharID;
                temp.InstanceID = item.InstanceID;
                temp.NpcID      = item.NpcID;
                temp.Type       = item.Type;
                temp.Average.Add(new DB_Ranking()
                {
                    Value   = (int)item.Average.Average(x => x.Value),
                    Time    = (int)item.Average.Average(x => x.Time),
                    Killed  = item.Average[0].Killed,
                    Attempt = item.Average[0].Attempt
                });
                value += item.Best.Value;
                time  += item.Best.Time;
                if (killed >= item.Best.Killed)
                {
                    continue;
                }
                killed  = item.Best.Killed;
                attempt = item.Best.Attempt;
            }
            value    /= count;
            time     /= count;
            temp.Best = new DB_Ranking()
            {
                Attempt = attempt,
                Killed  = killed,
                Time    = time,
                Value   = value,
            };
            newList.Add(temp);
        }
        return(newList);
    }
示例#2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!App.loaded && !Server.MapPath(".").ToLower().Contains("loading"))
        {
            try { Response.Redirect("/Loading/", false); Context.ApplicationInstance.CompleteRequest(); } catch (System.Threading.ThreadAbortException) { }
            return;
        }

        this.Title = "LegacyPlayers | Bosses";
        //App.UpdateRaidSpecificData();
        //App.GetChar(0, true);
        //App.GetGuild(0, true);
        Utility.GetClassList(ref pmClass);
        Utility.GetFactionList(ref pmFaction);
        Utility.GetExpansionList(ref pmExpansion);

        if (IsPostBack)
        {
            Utility.SetCookie(Response, Request, "Bosses_Class", pmClass.Value);
            Utility.SetCookie(Response, Request, "Bosses_Faction", pmFaction.Value);
            Utility.SetCookie(Response, Request, "Bosses_Realm", pmRealm.Value);
            Utility.SetCookie(Response, Request, "Bosses_Expansion", pmExpansion.Value);
        }
        else
        {
            pmClass.Value     = Utility.GetCookie(Request, "Bosses_Class", "0");
            pmFaction.Value   = Utility.GetCookie(Request, "Bosses_Faction", "0");
            pmRealm.Value     = Utility.GetCookie(Request, "Bosses_Realm", "0");
            pmExpansion.Value = Utility.GetCookie(Request, "Bosses_Expansion", "0");
        }

        int expansion = Int32.Parse(pmExpansion.Value);

        Utility.GetRealmList(ref pmRealm, false, expansion);

        var db = App.GetDB(expansion + 1);
        // TODO improve query
        MySqlDataReader dr      = db.Query("SELECT a.npcid, c.instanceid, MIN((a.end-a.start)), MAX(a.id), COUNT(a.id) FROM rs_attempts a JOIN rs_instance_uploader b ON a.uploaderid = b.id JOIN rs_instances c ON b.instanceid = c.id WHERE a.killed=1 GROUP BY a.npcid ORDER BY c.instanceid, a.npcid").ExecuteReaderRpll();
        var             query   = App.m_Rankings.AsQueryable();
        var             skQuery = App.m_SpeedkillRankings.AsQueryable();

        if (pmRealm.Value != "0")
        {
            short id = 0;
            if (short.TryParse(pmRealm.Value, out id) && id != 0)
            {
                query   = query.Where(x => App.GetChar(x.CharID, false).ServerID == id);
                skQuery = skQuery.Where(x => App.GetGuild(x.GuildID, false).ServerID == id);
            }
        }
        if (pmFaction.Value != "0")
        {
            short id = 0;
            if (short.TryParse(pmFaction.Value, out id) && id != 0)
            {
                query   = query.Where(x => App.GetChar(x.CharID, false).Faction == id);
                skQuery = skQuery.Where(x => App.GetGuild(x.GuildID, false).Faction == id);
            }
        }
        if (pmClass.Value != "0")
        {
            short id = 0;
            if (short.TryParse(pmClass.Value, out id) && id != 0)
            {
                query = query.Where(x => App.GetChar(x.CharID, false).RefMisc.Class == id - 1);
            }
        }

        var npcspecific   = query.GroupBy(x => x.NpcID).ToDictionary(x => x.Key, x => x.ToArray());
        var spkillspecifc = skQuery.GroupBy(x => x.NpcID).ToDictionary(x => x.Key, x => x.OrderBy(y => y.Best.Time).ToArray());

        while (dr.Read())
        {
            try
            {
                var _id = dr.GetInt32(0);
                if (!npcspecific.ContainsKey(_id))
                {
                    continue;
                }
                var dpsArr = npcspecific[_id].Where(x => x.Type == 0)
                             .OrderByDescending(x => 1000.0 * x.Best.Value / x.Best.Time);
                var hpsArr = npcspecific[_id].Where(x => x.Type == 1)
                             .OrderByDescending(x => 1000.0 * x.Best.Value / x.Best.Time);

                DB_Rankings          dps = dpsArr.Any() ? dpsArr.First() : App.m_Rankings[0];
                DB_Rankings          hps = hpsArr.Any() ? hpsArr.First() : App.m_Rankings[0];
                DB_SpeedkillRankings sk  = spkillspecifc.ContainsKey(_id) ? spkillspecifc[_id].First() : App.m_SpeedkillRankings[0];
                var imgType = Utility.GetImageType(Request, "png");
                m_Table.Append(
                    "<tr><td><div class=\"sp bbdesign\" style=\"background-image:url(/Assets/raids/" + dr.GetInt16(1) + "." + imgType + ")\"><div>" +
                    App.m_Instances[dr.GetInt16(1)].Name +
                    "</div></div></td><td>" + App.GetNpc(dr.GetInt32(0), expansion).Name + "</td>" +
                    "<td><a href=\"/Raids/Viewer/?atmt=" + dps.Best.Attempt + "&exp=" + expansion + "\" onmouseover=\"tt_show(this, 5, " +
                    dps.CharID + ", [])\" class=\"color-c" + App.GetChar(dps.CharID, false).RefMisc.Class + "\">" + App.GetChar(dps.CharID, false).Name + " (" +
                    Math.Round(1000.0 * dps.Best.Value / dps.Best.Time, 1) +
                    ")</a></td><td><a href=\"/Raids/Viewer/?atmt=" + hps.Best.Attempt +
                    "&exp=" + expansion + "\" onmouseover=\"tt_show(this, 5, " + hps.CharID + ", [])\" class=\"color-c" + App.GetChar(hps.CharID, false).RefMisc.Class + "\">" +
                    App.GetChar(hps.CharID, false).Name + " (" +
                    Math.Round(1000.0 * hps.Best.Value / hps.Best.Time, 1) + ")</a></td>" +
                    "<td><a href=\"/Raids/Viewer/?atmt=" +
                    sk.Best.Attempt + "&exp=" + expansion + "\">" + Math.Round(sk.Best.Time / 1000.0, 2) +
                    " seconds</a></td><td><a href=\"/Raids/?atmt=" + dr.GetInt32(3) + "&exp=" + expansion + "\">" + dr.GetInt32(4) +
                    "</a></td></tr>");
            }
            catch (ArgumentOutOfRangeException ee)
            {
                Response.Write(ee.Message + "<br /><br />");
            }
        }

        dr.CloseRpll();
    }