public static dsreplay GetTrackerevents(string replay_file, dynamic trackerevents_dec, dsreplay replay) { bool fix = false; if (replay.GAMETIME <= 20190121000000) { fix = true; } bool isBrawl_set = false; HashSet <string> Mutation = new HashSet <string>(); foreach (PythonDictionary pydic in trackerevents_dec) { if (pydic.ContainsKey("m_unitTypeName")) { if (pydic.ContainsKey("m_controlPlayerId")) { int playerid = (int)pydic["m_controlPlayerId"]; int gameloop = (int)pydic["_gameloop"]; if (playerid == 0 || playerid > 6) { continue; } dsplayer pl = replay.PLAYERS.Where(x => x.POS == playerid).FirstOrDefault(); if (pl == null) { continue; } Match m = rx_race2.Match(pydic["m_unitTypeName"].ToString()); if (m.Success && m.Groups[1].Value.Length > 0) { replay.PLAYERS[playerid - 1].RACE = m.Groups[1].Value; } else if (pydic.ContainsKey("m_creatorAbilityName") && pydic["m_creatorAbilityName"] == null) { if (gameloop < 480) { continue; } if (pydic["_event"].ToString() == "NNet.Replay.Tracker.SUnitBornEvent") { string born_unit = pydic["m_unitTypeName"].ToString(); if (born_unit == "TrophyRiftPremium") { continue; } if (born_unit == "MineralIncome") { continue; } if (born_unit == "ParasiticBombRelayDummy") { continue; } if (born_unit == "Biomass") { continue; } int fixloop = gameloop; if (pl.SPAWNS.Count() > 0) { int maxloop = pl.SPAWNS.ElementAt(pl.SPAWNS.Count() - 1).Key; if ((gameloop - maxloop) <= 470) { fixloop = maxloop; } } if (!pl.SPAWNS.ContainsKey(fixloop)) { pl.SPAWNS.Add(fixloop, new Dictionary <string, int>()); } if (!pl.SPAWNS[fixloop].ContainsKey(born_unit)) { pl.SPAWNS[fixloop].Add(born_unit, 1); } else { pl.SPAWNS[fixloop][born_unit]++; } if (pl.REALPOS == null || pl.REALPOS == 0) { int pos = 0; if (replay.PLAYERCOUNT == 2) { pos = 1; } else if ((gameloop - 480) % 1440 == 0) { pos = 1; } else if ((gameloop - 481) % 1440 == 0) { pos = 1; } else if ((gameloop - 960) % 1440 == 0) { pos = 2; } else if ((gameloop - 961) % 1440 == 0) { pos = 2; } else if ((gameloop - 1440) % 1440 == 0) { pos = 3; } else if ((gameloop - 1441) % 1440 == 0) { pos = 3; } if (replay.PLAYERCOUNT == 4 && pos == 3) { pos = 1; } if (pos > 0) { int team = REParea.GetTeam((int)pydic["m_x"], (int)pydic["m_y"]); if (team == 1) { pl.REALPOS = pos; } else if (team == 2) { pl.REALPOS = pos + 3; } pl.TEAM = team - 1; } } } } } } else if (pydic.ContainsKey("m_unitTagIndex") && (int)pydic["m_unitTagIndex"] == 20 && pydic.ContainsKey("_event") && pydic["_event"].ToString() == "NNet.Replay.Tracker.SUnitOwnerChangeEvent") { int gameloop = (int)pydic["_gameloop"]; int upkeepid = (int)pydic["m_upkeepPlayerId"]; KeyValuePair <int, int> Mid = new KeyValuePair <int, int>(0, 0); if (upkeepid == 13) { Mid = new KeyValuePair <int, int>(gameloop, 0); } else if (upkeepid == 14) { Mid = new KeyValuePair <int, int>(gameloop, 1); } if (Mid.Key > 0) { replay.MIDDLE.Add(Mid); } } else if (pydic.ContainsKey("m_stats")) { int playerid = (int)pydic["m_playerId"]; int gameloop = (int)pydic["_gameloop"]; if (playerid == 0 || playerid > 6) { continue; } dsplayer pl = replay.PLAYERS.Where(x => x.POS == playerid).FirstOrDefault(); if (pl == null) { continue; } if (isBrawl_set == false) { isBrawl_set = true; } PythonDictionary pystats = pydic["m_stats"] as PythonDictionary; M_stats m_stats = new M_stats(); m_stats.m_scoreValueFoodMade = (int)pystats["m_scoreValueFoodMade"]; m_stats.m_scoreValueFoodUsed = (int)pystats["m_scoreValueFoodUsed"]; m_stats.m_scoreValueMineralsCollectionRate = (int)pystats["m_scoreValueMineralsCollectionRate"]; m_stats.m_scoreValueMineralsCurrent = (int)pystats["m_scoreValueMineralsCurrent"]; m_stats.m_scoreValueMineralsFriendlyFireArmy = (int)pystats["m_scoreValueMineralsFriendlyFireArmy"]; m_stats.m_scoreValueMineralsFriendlyFireEconomy = (int)pystats["m_scoreValueMineralsFriendlyFireEconomy"]; m_stats.m_scoreValueMineralsFriendlyFireTechnology = (int)pystats["m_scoreValueMineralsFriendlyFireTechnology"]; m_stats.m_scoreValueMineralsKilledArmy = (int)pystats["m_scoreValueMineralsKilledArmy"]; m_stats.m_scoreValueMineralsKilledEconomy = (int)pystats["m_scoreValueMineralsKilledEconomy"]; m_stats.m_scoreValueMineralsKilledTechnology = (int)pystats["m_scoreValueMineralsKilledTechnology"]; m_stats.m_scoreValueMineralsLostArmy = (int)pystats["m_scoreValueMineralsLostArmy"]; m_stats.m_scoreValueMineralsLostEconomy = (int)pystats["m_scoreValueMineralsLostEconomy"]; m_stats.m_scoreValueMineralsLostTechnology = (int)pystats["m_scoreValueMineralsLostTechnology"]; m_stats.m_scoreValueMineralsUsedActiveForces = (int)pystats["m_scoreValueMineralsUsedActiveForces"]; m_stats.m_scoreValueMineralsUsedCurrentArmy = (int)pystats["m_scoreValueMineralsUsedCurrentArmy"]; m_stats.m_scoreValueMineralsUsedCurrentEconomy = (int)pystats["m_scoreValueMineralsUsedCurrentEconomy"]; m_stats.m_scoreValueMineralsUsedCurrentTechnology = (int)pystats["m_scoreValueMineralsUsedCurrentTechnology"]; /** * m_stats.m_scoreValueMineralsUsedInProgressArmy = (int)pystats["m_scoreValueMineralsUsedInProgressArmy"]; * m_stats.m_scoreValueMineralsUsedInProgressEconomy = (int)pystats["m_scoreValueMineralsUsedInProgressEconomy"]; * m_stats.m_scoreValueMineralsUsedInProgressTechnology = (int)pystats["m_scoreValueMineralsUsedInProgressTechnology"]; * m_stats.m_scoreValueVespeneCollectionRate = (int)pystats["m_scoreValueVespeneCollectionRate"]; * m_stats.m_scoreValueVespeneCurrent = (int)pystats["m_scoreValueVespeneCurrent"]; * m_stats.m_scoreValueVespeneFriendlyFireArmy = (int)pystats["m_scoreValueVespeneFriendlyFireArmy"]; * m_stats.m_scoreValueVespeneFriendlyFireEconomy = (int)pystats["m_scoreValueVespeneFriendlyFireEconomy"]; * m_stats.m_scoreValueVespeneFriendlyFireTechnology = (int)pystats["m_scoreValueVespeneFriendlyFireTechnology"]; * m_stats.m_scoreValueVespeneKilledArmy = (int)pystats["m_scoreValueVespeneKilledArmy"]; * m_stats.m_scoreValueVespeneKilledEconomy = (int)pystats["m_scoreValueVespeneKilledEconomy"]; * m_stats.m_scoreValueVespeneKilledTechnology = (int)pystats["m_scoreValueVespeneKilledTechnology"]; * m_stats.m_scoreValueVespeneLostArmy = (int)pystats["m_scoreValueVespeneLostArmy"]; * m_stats.m_scoreValueVespeneLostEconomy = (int)pystats["m_scoreValueVespeneLostEconomy"]; * m_stats.m_scoreValueVespeneLostTechnology = (int)pystats["m_scoreValueVespeneLostTechnology"]; * m_stats.m_scoreValueVespeneUsedActiveForces = (int)pystats["m_scoreValueVespeneUsedActiveForces"]; * m_stats.m_scoreValueVespeneUsedCurrentArmy = (int)pystats["m_scoreValueVespeneUsedCurrentArmy"]; * m_stats.m_scoreValueVespeneUsedCurrentEconomy = (int)pystats["m_scoreValueVespeneUsedCurrentEconomy"]; * m_stats.m_scoreValueVespeneUsedCurrentTechnology = (int)pystats["m_scoreValueVespeneUsedCurrentTechnology"]; * m_stats.m_scoreValueVespeneUsedInProgressArmy = (int)pystats["m_scoreValueVespeneUsedInProgressArmy"]; * m_stats.m_scoreValueVespeneUsedInProgressEconomy = (int)pystats["m_scoreValueVespeneUsedInProgressEconomy"]; * m_stats.m_scoreValueVespeneUsedInProgressTechnology = (int)pystats["m_scoreValueVespeneUsedInProgressTechnology"]; * m_stats.m_scoreValueWorkersActiveCount = (int)pystats["m_scoreValueWorkersActiveCount"]; **/ pl.STATS[gameloop] = m_stats; replay.DURATION = gameloop; pl.PDURATION = gameloop; int gas = 0; int income = pl.STATS[gameloop].m_scoreValueMineralsCollectionRate; pl.INCOME += (double)income / 9.15; KeyValuePair <int, int> lastMid = GetMiddle(replay); if (lastMid.Key > 160 && lastMid.Value == pl.TEAM) { income -= 60; } if (income < 470) { gas = 0; // base income } else if (income < 500) { gas = 1; } else if (income < 530 && gameloop > 2240) { gas = 2; } else if (income < 560 && gameloop > 4480) { gas = 3; } else if (income < 600 && gameloop > 13440) { gas = 4; } if (gas > pl.GAS) { pl.GAS = gas; } int pos = 0; if ((gameloop - 480) % 1440 == 0) { pos = 1; } else if ((gameloop - 960) % 1440 == 0) { pos = 2; } else if ((gameloop - 1440) % 1440 == 0) { pos = 3; } if (pos > 0) { if (replay.PLAYERCOUNT == 4 && pos == 3) { pos = 1; } if (pl.REALPOS == pos || pl.REALPOS == pos + 3 || replay.PLAYERCOUNT == 2) { int fixloop = gameloop; if (!pl.SPAWNS.ContainsKey(fixloop)) { pl.SPAWNS.Add(fixloop, new Dictionary <string, int>()); } pl.SPAWNS[fixloop]["Gas"] = pl.GAS; if (pl.TEAM == 0) { pl.SPAWNS[fixloop]["Mid"] = GetMiddle(replay, true).Key; } else { pl.SPAWNS[fixloop]["Mid"] = GetMiddle(replay, true).Value; } if (pl.STATS.Count() > 0) { pl.SPAWNS[fixloop]["Upgrades"] = pl.STATS.ElementAt(pl.STATS.Count() - 1).Value.m_scoreValueMineralsUsedCurrentTechnology; pl.ARMY += pl.STATS.ElementAt(pl.STATS.Count() - 1).Value.m_scoreValueMineralsUsedActiveForces; } } } } else if (isBrawl_set == false && pydic.ContainsKey("_gameloop") && (int)pydic["_gameloop"] == 0 && pydic.ContainsKey("m_upgradeTypeName")) { if (pydic["m_upgradeTypeName"].ToString().StartsWith("Mutation")) { Mutation.Add(pydic["m_upgradeTypeName"].ToString()); } } } if (Mutation.Contains("MutationCovenant")) { replay.GAMEMODE = "GameModeSwitch"; } else if (Mutation.Contains("MutationEquipment")) { replay.GAMEMODE = "GameModeGear"; } else if (Mutation.Contains("MutationExile") && Mutation.Contains("MutationRescue") && Mutation.Contains("MutationShroud") && Mutation.Contains("MutationSuperscan")) { replay.GAMEMODE = "GameModeSabotage"; } else if (Mutation.Contains("MutationCommanders")) { replay.GAMEMODE = "GameModeCommanders"; // fail safe if (Mutation.Count() == 3 && Mutation.Contains("MutationExpansion") && Mutation.Contains("MutationOvertime")) { replay.GAMEMODE = "GameModeCommandersHeroic"; } else if (Mutation.Count() == 2 && Mutation.Contains("MutationOvertime")) { replay.GAMEMODE = "GameModeCommanders"; } else if (Mutation.Count() >= 3) { replay.GAMEMODE = "GameModeBrawlCommanders"; } } else { if (replay.GAMEMODE == "unknown" && Mutation.Count() == 0) { replay.GAMEMODE = "GameModeStandard"; } else if (replay.GAMEMODE == "unknown" && Mutation.Count() > 0) { replay.GAMEMODE = "GameModeBrawlStandard"; } } replay.ISBRAWL = true; if (replay.GAMEMODE == "GameModeCommanders" || replay.GAMEMODE == "GameModeCommandersHeroic" || replay.GAMEMODE == "GameModeStandard") { replay.ISBRAWL = false; } GetMiddle(replay); SetUnits(replay); // fail safe FixPos(replay); FixWinner(replay); return(replay); }
public static async Task <StatsRound> GenRoundStats(GameHistory _game, bool mstats = true) { _game.Spawn++; float armyvaluet1 = 0; float armyvaluet2 = 0; if (!_game.Health.FirstOrDefault().Equals(default(KeyValuePair <float, float>))) { armyvaluet1 = _game.Health.First().Key; armyvaluet2 = _game.Health.First().Value; } int winner = 0; if (_game.Health.Any()) { if (_game.Health.Last().Key > 0 && _game.Health.Last().Value == 0) { winner = 1; } else if (_game.Health.Last().Key == 0 && _game.Health.Last().Value > 0) { winner = 2; } } StatsRound stats = new StatsRound(); stats.winner = winner; stats.ArmyHPT1 = armyvaluet1; stats.ArmyHPT2 = armyvaluet2; foreach (Player player in _game.Players.OrderBy(o => o.Pos)) { float damage = 0; float killed = 0; float army = 0; float tech = 0; Unit plmvp = new Unit(); foreach (UnitAbility ability in player.AbilityUpgrades) { tech += ability.Cost; } foreach (UnitUpgrade upgrade in player.Upgrades) { try { tech += UpgradePool.Upgrades.SingleOrDefault(x => x.Race == player.Race && x.Name == upgrade.Upgrade).Cost.ElementAt(upgrade.Level - 1).Value; } catch { } } foreach (Unit unit in _game.battlefield.Units.Where(x => x.Status == UnitStatuses.Spawned && x.Owner == player.Pos && x.Race == player.Race)) { damage += unit.DamageDoneRound; killed += unit.MineralValueKilledRound; army += unit.Cost; unit.DamageDone += damage; unit.MineralValueKilled += killed; if (unit.DamageDoneRound > plmvp.DamageDoneRound) { plmvp = unit; } } if (plmvp.DamageDoneRound > stats.MVP.DamageDoneRound) { stats.MVP = plmvp; } stats.Damage.Add(damage); stats.Killed.Add(killed); stats.Army.Add(army); stats.Tech.Add(tech); stats.Mvp.Add(plmvp); if (mstats == true) { M_stats chartstats = new M_stats(); chartstats.ArmyHPTeam1 = MathF.Round(stats.ArmyHPT1, 2); chartstats.ArmyHPTeam2 = MathF.Round(stats.ArmyHPT2, 2); chartstats.ArmyValue = MathF.Round(stats.Army.Last(), 2); chartstats.DamageDone = MathF.Round(stats.Damage.Last(), 2); if (winner == 1 && player.Pos <= 3) { chartstats.RoundsWon = 1; } else if (winner == 2 && player.Pos > 3) { chartstats.RoundsWon = 1; } chartstats.Upgrades = MathF.Round(stats.Tech.Last(), 2); chartstats.VlaueKilled = MathF.Round(stats.Killed.Last(), 2); player.Stats[_game.Spawn] = chartstats; } } _game.Stats.Add(stats); return(stats); }