예제 #1
0
        public static void Replay(DSReplay replay, bool GetDetails)
        {
            int maxleaver  = 0;
            int maxkillsum = 0;
            int minkillsum = -1;
            int minarmy    = -1;
            int minincome  = -1;

            FixPos(replay);

            Dictionary <string, double> Breakpoints = new Dictionary <string, double>(DSData.BreakpointMid);

            Breakpoints["ALL"] = replay.DURATION * 22.4;
            foreach (var ent in Breakpoints.Keys.ToArray())
            {
                if (ent == "ALL")
                {
                    continue;
                }
                if (Breakpoints[ent] >= Breakpoints["ALL"])
                {
                    Breakpoints.Remove(ent);
                }
            }

            foreach (DSPlayer pl in replay.DSPlayer)
            {
                int      opppos = DBFunctions.GetOpp(pl.REALPOS);
                DSPlayer opp    = replay.DSPlayer.SingleOrDefault(s => s.REALPOS == opppos);
                if (opp != null)
                {
                    pl.OPPRACE = opp.RACE;
                }
                if (pl.TEAM == replay.WINNER)
                {
                    pl.WIN = true;
                }
                if (pl.Stats.Any())
                {
                    pl.KILLSUM = pl.Stats.OrderBy(o => o.Gameloop).Last().MineralsKilledArmy;
                }
                else
                {
                    pl.KILLSUM = 0;
                }
                pl.INCOME = (int)pl.Stats.Sum(s => s.MineralsCollectionRate / 9.15);
                foreach (DbRefinery r in pl.Refineries.ToArray())
                {
                    if (r.Gameloop == 0)
                    {
                        pl.Refineries.Remove(r);
                    }
                }
                pl.GAS = (byte)pl.Refineries.Count();

                int diff = replay.DURATION - pl.PDURATION;
                if (diff > maxleaver)
                {
                    maxleaver = diff;
                }

                if (pl.KILLSUM > maxkillsum)
                {
                    maxkillsum = pl.KILLSUM;
                }

                if (minkillsum == -1)
                {
                    minkillsum = pl.KILLSUM;
                }
                else
                {
                    if (pl.KILLSUM < minkillsum)
                    {
                        minkillsum = pl.KILLSUM;
                    }
                }

                if (minarmy == -1)
                {
                    minarmy = pl.ARMY;
                }
                else
                {
                    if (pl.ARMY < minarmy)
                    {
                        minarmy = pl.ARMY;
                    }
                }

                if (minincome == -1)
                {
                    minincome = pl.INCOME;
                }
                else
                {
                    if (pl.INCOME < minincome)
                    {
                        minincome = pl.INCOME;
                    }
                }
                string urace = pl.RACE;
                if (pl.RACE == "Zagara" || pl.RACE == "Abathur" || pl.RACE == "Kerrigan")
                {
                    urace = "Zerg";
                }
                else if (pl.RACE == "Alarak" || pl.RACE == "Artanis" || pl.RACE == "Vorazun" || pl.RACE == "Fenix" || pl.RACE == "Karax")
                {
                    urace = "Protoss";
                }
                else if (pl.RACE == "Raynor" || pl.RACE == "Swann" || pl.RACE == "Nova" || pl.RACE == "Stukov")
                {
                    urace = "Terran";
                }

                HashSet <string> doubles = new HashSet <string>();
                foreach (DbUpgrade upgrade in pl.Upgrades.OrderBy(o => o.Gameloop).ToList())
                {
                    if (doubles.Contains(upgrade.Upgrade))
                    {
                        pl.Upgrades.Remove(upgrade);
                        continue;
                    }
                    doubles.Add(upgrade.Upgrade);
                    int id = NameService.GetUpgradeId(null, upgrade.Upgrade);
                    if (id >= 0)
                    {
                        upgrade.Upgrade = id.ToString();
                    }
                    else if (upgrade.Upgrade.StartsWith("Tier4WeaponUpgradeLevel"))
                    {
                        id = NameService.GetUpgradeId(null, "Tier4");
                        if (id >= 0)
                        {
                            upgrade.Upgrade = id.ToString();
                        }
                    }
                }

                pl.Breakpoints = new List <DbBreakpoint>();
                foreach (var ent in Breakpoints)
                {
                    DbBreakpoint bp = GenBreakpoint(pl, (int)ent.Value, ent.Key);
                    bp.Breakpoint = ent.Key;
                    pl.Breakpoints.Add(bp);
                }
            }

            replay.MAXLEAVER  = maxleaver;
            replay.MAXKILLSUM = maxkillsum;
            replay.MINKILLSUM = minkillsum;
            replay.MINARMY    = minarmy;
            replay.MININCOME  = minincome;

            FixWinner(replay);
            replay.HASH = GenHash(replay);

            //foreach (var pl in replay.DSPlayer)
            //{
            //    pl.RACE = ((byte)DSData.GetCommander(pl.RACE)).ToString();
            //    pl.OPPRACE = ((byte)DSData.GetCommander(pl.OPPRACE)).ToString();
            //}

            using (var md5 = MD5.Create())
            {
                string dirHash  = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(Path.GetDirectoryName(replay.REPLAYPATH)))).Replace("-", "").ToLowerInvariant();
                string fileHash = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(Path.GetFileName(replay.REPLAYPATH)))).Replace("-", "").ToLowerInvariant();
                replay.REPLAY = dirHash + fileHash;
            }

            if (GetDetails == false)
            {
                foreach (DSPlayer pl in replay.DSPlayer)
                {
                    pl.Stats.Clear();
                    pl.Stats = null;
                    pl.Spawns.Clear();
                    pl.Spawns = null;
                    pl.decUnits.Clear();
                    pl.decUnits = null;
                    pl.Refineries.Clear();
                    pl.Refineries = null;
                    pl.Upgrades.Clear();
                    pl.Upgrades = null;



                    foreach (DbBreakpoint bp in pl.Breakpoints)
                    {
                        bp.Units.Clear();
                        bp.Units = null;
                        bp.DbUnits.Clear();
                        bp.DbUnits = null;
                        bp.DbUpgrades.Clear();
                        bp.DbUpgrades = null;
                    }
                }
            }
        }