public static string CalcMatchHash(this MatchDrop md, int totdmg) { string matchHash = String.Empty; if (totdmg == 0) { matchHash = String.Format("{0}{1}{2}{3}:0-0", System.DateTime.UtcNow.Year, System.DateTime.UtcNow.DayOfYear, 1000000, 0); } else { int lvl = (md.Map != null)?md.Map.MapId:0; matchHash = String.Format("{0}{1}{2}{3}:{4}-{5}", System.DateTime.UtcNow.Year, System.DateTime.UtcNow.DayOfYear, totdmg, lvl, md.FriendlyDropDeck12.MechsHash(), md.EnemyDropDeck12.MechsHash()); } return(matchHash); }
public static MatchDrop getMatchDrop() { //TODO: think about what happens when two people are in the same drop drop but log it with different association names DropDeck12 friendlyDropDeck12 = GetDropDeck12(true); DropDeck12 enemyDropDeck12 = GetDropDeck12(false); Association association = getAssociation(); MWA.Models.MatchDrop matchDropToPush = new MWA.Models.MatchDrop(); matchDropToPush.Association = association; matchDropToPush.AssociationId = association.AssociationId; matchDropToPush.AssociationName = association.AssociationName; matchDropToPush.FriendlyDropDeck12 = friendlyDropDeck12; matchDropToPush.EnemyDropDeck12 = enemyDropDeck12; matchDropToPush.MatchHash = GetMatchHash(); string api = GetApiUrl("MatchDrop"); MatchDrop md; matchDrop = (MatchDrop)HttpUtility.MakeRequest(api, matchDropToPush, null, null, typeof(MatchDrop)); return(matchDrop); }
/*public static DropDeck12 SetChassis(this DropDeck12 dropdeck12, MwaDBContext db) * { * * } * */ public static MatchDrop GetLoggedMatchDrop(this MatchLogger.MatchLogger.LoggedMatch value, MwaDBContext 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); }