Esempio n. 1
0
        public static DropDeck12 GetUniqueDropDeck(DropDeck12 ddCriteria, MwoADbContext db)
        {
            DropDeck12 dd12 = db.DropDeck12s.FirstOrDefault(dd =>
                                                            dd.ChassisId1 == ddCriteria.ChassisId1 &&
                                                            dd.ChassisId2 == ddCriteria.ChassisId2 &&
                                                            dd.ChassisId3 == ddCriteria.ChassisId3 &&
                                                            dd.ChassisId4 == ddCriteria.ChassisId4 &&
                                                            dd.ChassisId5 == ddCriteria.ChassisId5 &&
                                                            dd.ChassisId6 == ddCriteria.ChassisId6 &&
                                                            dd.ChassisId7 == ddCriteria.ChassisId7 &&
                                                            dd.ChassisId8 == ddCriteria.ChassisId8 &&
                                                            dd.ChassisId9 == ddCriteria.ChassisId9 &&
                                                            dd.ChassisId10 == ddCriteria.ChassisId10 &&
                                                            dd.ChassisId11 == ddCriteria.ChassisId11 &&
                                                            dd.ChassisId12 == ddCriteria.ChassisId12);

            if (dd12 == null)
            {
                db.DropDeck12s.Add(ddCriteria);
                db.SaveChanges();
            }
            else
            {
                ddCriteria = dd12;
            }
            return(ddCriteria);
        }
Esempio n. 2
0
        /*public static DropDeck12 SetChassis(this DropDeck12 dropdeck12, MwoADbContext db)
         * {
         *
         * }
         * */

        public static MatchDrop GetLoggedMatchDrop(this MatchLogger.MatchLogger.LoggedMatch value, MwoADbContext db)
        {
            List <String> friendlyMechs = value.FriendlyMatchStats.Select(f => f.mech).OrderBy(m => m).ToList();
            List <String> enemyMechs    = value.EnemyMatchStats.Select(f => f.mech).OrderBy(m => m).ToList();
            int           tdmg          = value.FriendlyMatchStats.Select(f => f.damage).Sum() + value.EnemyMatchStats.Select(e => e.damage).Sum();
            MatchStat     ms            = value.FriendlyMatchStats.FirstOrDefault(l => l.level != "" && l.level != null);
            DropDeck12    fdd           = SetDropDeck(friendlyMechs, db);
            DropDeck12    edd           = SetDropDeck(enemyMechs, db);
            Association   assoc         = db.Associations.FirstOrDefault(a => a.AssociationName == value.AssociationName);

            var md = new MatchDrop
            {
                AssociationName      = value.AssociationName,
                AssociationId        = assoc.AssociationId,
                Association          = db.Associations.FirstOrDefault(i => i.AssociationId == assoc.AssociationId),
                FriendlyDropDeck12   = db.DropDeck12s.FirstOrDefault(f => f.DropDeck12Id == fdd.DropDeck12Id),
                FriendlyDropDeck12Id = fdd.DropDeck12Id,
                EnemyDropDeck12      = db.DropDeck12s.FirstOrDefault(e => e.DropDeck12Id == edd.DropDeck12Id),
                EnemyDropDeck12Id    = edd.DropDeck12Id,
                Map = db.Maps.FirstOrDefault(a => a.MapAltName1 == ms.level)
            };

            md.MatchHash = md.CalcMatchHash(tdmg);

            if (db.MatchDrops.Any(m => m.MatchHash == md.MatchHash && m.AssociationName == value.AssociationName))
            {
                md = db.MatchDrops.FirstOrDefault(m => m.MatchHash == md.MatchHash && m.AssociationName == value.AssociationName);
            }
            else
            {
                db.MatchDrops.Add(md);
                db.SaveChanges();

                foreach (MatchStat fm in value.FriendlyMatchStats)
                {
                    MWA.Models.MwoAMatchMetric matchtopush = new MWA.Models.MwoAMatchMetric();
                    matchtopush.assists            = fm.assists;
                    matchtopush.damage             = fm.damage;
                    matchtopush.kills              = fm.kills;
                    matchtopush.lance              = fm.lance;
                    matchtopush.level              = fm.level;
                    matchtopush.matchType          = fm.matchType;
                    matchtopush.matchscore         = fm.matchscore;
                    matchtopush.mech               = fm.mech;
                    matchtopush.name               = fm.name;
                    matchtopush.ping               = fm.ping;
                    matchtopush.status             = fm.status;
                    matchtopush.team               = fm.team;
                    matchtopush.victory            = fm.victory;
                    matchtopush.victoryType        = fm.victoryType;
                    matchtopush.time               = fm.time.ToUniversalTime().ToString();
                    matchtopush.MatchHash          = value.MatchHash;
                    matchtopush.PublishFlag        = 1;
                    matchtopush.PublishingUserName = (value.PublishingUserName == fm.name);
                    matchtopush.MatchDrop          = db.MatchDrops.FirstOrDefault(m => m.MatchDropId == md.MatchDropId);
                    db.MwoAMatchMetrics.Add(matchtopush);
                    db.SaveChanges();
                }
                foreach (MatchStat em in value.EnemyMatchStats)
                {
                    MWA.Models.MwoAMatchMetric matchtopush = new MWA.Models.MwoAMatchMetric();
                    matchtopush.assists            = em.assists;
                    matchtopush.damage             = em.damage;
                    matchtopush.kills              = em.kills;
                    matchtopush.lance              = em.lance;
                    matchtopush.level              = em.level;
                    matchtopush.matchType          = em.matchType;
                    matchtopush.matchscore         = em.matchscore;
                    matchtopush.mech               = em.mech;
                    matchtopush.name               = em.name;
                    matchtopush.ping               = em.ping;
                    matchtopush.status             = em.status;
                    matchtopush.team               = em.team;
                    matchtopush.victory            = em.victory;
                    matchtopush.victoryType        = em.victoryType;
                    matchtopush.time               = em.time.ToUniversalTime().ToString();
                    matchtopush.MatchHash          = value.MatchHash;
                    matchtopush.PublishFlag        = 1;
                    matchtopush.PublishingUserName = (value.PublishingUserName == em.name);
                    matchtopush.MatchDrop          = db.MatchDrops.FirstOrDefault(m => m.MatchDropId == md.MatchDropId);
                    db.MwoAMatchMetrics.Add(matchtopush);
                    db.SaveChanges();
                }
            }
            return(md);
        }