Exemple #1
0
        public static DbBreakpoint GenBreakpoint(DSPlayer pl, int bp, string bpstring)
        {
            DbBreakpoint Bp = new DbBreakpoint();

            Bp.Player = pl;
            Bp.Gas    = pl.Refineries.Where(x => x.Gameloop > 0 && x.Gameloop <= bp).Count();
            Bp.Income = (int)pl.Stats.Where(x => x.Gameloop <= bp).Sum(s => s.MineralsCollectionRate / 9.15);
            DbStats statlast = null;

            foreach (DbStats stat in pl.Stats)
            {
                if (stat.Gameloop > bp)
                {
                    break;
                }
                statlast = stat;
            }
            if (statlast != null)
            {
                Bp.Army     = statlast.Army;
                Bp.Kills    = statlast.MineralsKilledArmy;
                Bp.Upgrades = statlast.MineralsUsedCurrentTechnology;
            }

            List <DbUnit> dbUnits = null;

            foreach (var ent in pl.Spawns)
            {
                if (ent.Gameloop > bp)
                {
                    break;
                }
                dbUnits = ent.Units.ToList();
            }
            Bp.Units   = new List <DSUnit>();
            Bp.DbUnits = new List <DbUnit>();
            if (dbUnits != null)
            {
                foreach (DbUnit unit in dbUnits)
                {
                    DSUnit dsUnit = Bp.Units.FirstOrDefault(s => s.Name == unit.Name);
                    if (dsUnit == null)
                    {
                        DSUnit newdsUnit = new DSUnit();
                        newdsUnit.Name       = unit.Name;
                        newdsUnit.BP         = bpstring;
                        newdsUnit.Breakpoint = Bp;
                        newdsUnit.Count      = 1;
                        newdsUnit.DSPlayer   = pl;
                        Bp.Units.Add(newdsUnit);
                    }
                    else
                    {
                        dsUnit.Count++;
                    }
                    unit.Breakpoint = Bp;
                    Bp.DbUnits.Add(unit);
                }
            }

            Bp.DbUpgrades = new List <DbUpgrade>();
            foreach (DbUpgrade upgrade in pl.Upgrades.Where(x => x.Breakpoint == null && x.Gameloop < bp))
            {
                upgrade.Breakpoint = Bp;
                Bp.DbUpgrades.Add(upgrade);
            }

            string dsUnitsString    = "";
            string dbUnitsString    = "";
            string dbUpgradesString = "";

            foreach (DSUnit unit in Bp.Units)
            {
                string        name  = unit.Name;
                UnitModelBase bunit = DSdata.Units.FirstOrDefault(s => s.Race == pl.RACE && s.Name == unit.Name);
                if (bunit != null)
                {
                    name = bunit.ID.ToString();
                }
                dsUnitsString += name + "," + unit.Count + "|";
            }
            if (dsUnitsString.Any())
            {
                dsUnitsString = dsUnitsString.Remove(dsUnitsString.Length - 1);
            }

            foreach (DbUnit unit in Bp.DbUnits)
            {
                string        name  = unit.Name;
                UnitModelBase bunit = DSdata.Units.FirstOrDefault(s => s.Race == pl.RACE && s.Name == unit.Name);
                if (bunit != null)
                {
                    name = bunit.ID.ToString();
                }
                dbUnitsString += name + "," + unit.BornX + "," + unit.BornY + "|";
            }
            if (dbUnitsString.Any())
            {
                dbUnitsString = dbUnitsString.Remove(dbUnitsString.Length - 1);
            }


            foreach (DbUpgrade upgrade in Bp.DbUpgrades)
            {
                dbUpgradesString += upgrade.Upgrade + "|";
            }
            if (dbUpgradesString.Any())
            {
                dbUpgradesString = dbUpgradesString.Remove(dbUpgradesString.Length - 1);
            }

            Bp.dsUnitsString    = dsUnitsString;
            Bp.dbUnitsString    = dbUnitsString;
            Bp.dbUpgradesString = dbUpgradesString;

            return(Bp);
        }
Exemple #2
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);
                    UnitModelBase dupgrade = DSdata.Upgrades.FirstOrDefault(s => s.Name == upgrade.Upgrade && s.Race == pl.RACE);
                    if (dupgrade != null)
                    {
                        upgrade.Upgrade = dupgrade.ID.ToString();
                    }
                    else
                    {
                        UnitModelBase udupgrade = DSdata.Upgrades.FirstOrDefault(s => s.Name == upgrade.Upgrade && s.Race == urace);
                        if (udupgrade != null)
                        {
                            upgrade.Upgrade = udupgrade.ID.ToString();
                        }
                        else if (upgrade.Upgrade.StartsWith("Tier4WeaponUpgradeLevel"))
                        {
                            UnitModelBase tudupgrade = DSdata.Upgrades.FirstOrDefault(s => s.Name == upgrade.Upgrade && s.Race == "");
                            if (tudupgrade != null)
                            {
                                upgrade.Upgrade = tudupgrade.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);

            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;
                    }
                }
            }
        }
Exemple #3
0
        public static DSReplay Rep(Dsreplays rep)
        {
            DSReplay dbrep = new DSReplay();

            dbrep.REPLAY      = rep.Replay;
            dbrep.REPLAYPATH  = String.Empty;
            dbrep.GAMETIME    = rep.Gametime;
            dbrep.WINNER      = (sbyte)rep.Winner;
            dbrep.DURATION    = (int)rep.Duration;
            dbrep.MINKILLSUM  = rep.Minkillsum;
            dbrep.MAXKILLSUM  = rep.Maxkillsum;
            dbrep.MINARMY     = rep.Minarmy;
            dbrep.MININCOME   = (int)rep.Minincome;
            dbrep.PLAYERCOUNT = (byte)rep.Playercount;
            dbrep.REPORTED    = (byte)rep.Reported;
            dbrep.ISBRAWL     = rep.Isbrawl;
            dbrep.GAMEMODE    = rep.Gamemode;
            dbrep.VERSION     = rep.Version;
            dbrep.MAXLEAVER   = 0;

            List <DSPlayer> pls = new List <DSPlayer>();

            foreach (Dsplayers pl in rep.Dsplayers)
            {
                DSPlayer dbpl = new DSPlayer();
                dbpl.POS     = (byte)pl.Pos;
                dbpl.REALPOS = (byte)pl.Realpos;
                dbpl.NAME    = pl.Name;
                dbpl.RACE    = pl.Race;
                if (pl.Team == rep.Winner)
                {
                    dbpl.WIN = true;
                }
                dbpl.TEAM      = (byte)pl.Team;
                dbpl.KILLSUM   = pl.Killsum;
                dbpl.INCOME    = (int)pl.Income;
                dbpl.PDURATION = (int)pl.Pduration;
                dbpl.ARMY      = pl.Army;
                dbpl.GAS       = (byte)pl.Gas;
                Dsplayers opp = GetOpp(pl.Realpos, rep);
                if (opp != null)
                {
                    dbpl.OPPRACE = opp.Race;
                }
                int diff = dbrep.DURATION - (int)pl.Pduration;
                if (diff > dbrep.MAXLEAVER)
                {
                    dbrep.MAXLEAVER = diff;
                }

                dbpl.DSReplay = dbrep;
                pls.Add(dbpl);

                List <DbBreakpoint> bps = new List <DbBreakpoint>();
                foreach (var bp in DSdata.s_breakpoints)
                {
                    DbBreakpoint dbbp = new DbBreakpoint();
                    dbbp.Breakpoint    = bp;
                    dbbp.dsUnitsString = "";
                    foreach (var runit in pl.Dsunits.Where(x => x.Bp == bp))
                    {
                        if (runit.Name == "Gas")
                        {
                            dbbp.Gas = runit.Count;
                        }
                        else if (runit.Name == "Upgrades")
                        {
                            dbbp.Upgrades = runit.Count;
                        }
                        else if (runit.Name == "Mid")
                        {
                            dbbp.Mid = runit.Count;
                        }
                        else
                        {
                            UnitModelBase unit = DSdata.Units.FirstOrDefault(f => f.Race == pl.Race && f.Name == Fix.UnitName(runit.Name));
                            if (unit != null)
                            {
                                dbbp.dsUnitsString += unit.ID + "," + runit.Count + "|";
                            }
                            else
                            {
                                dbbp.dsUnitsString += runit.Name + "," + runit.Count + "|";
                            }
                        }
                    }
                    if (!String.IsNullOrEmpty(dbbp.dsUnitsString))
                    {
                        dbbp.dsUnitsString = dbbp.dsUnitsString.Remove(dbbp.dsUnitsString.Length - 1);
                    }
                    bps.Add(dbbp);
                }
                dbpl.Breakpoints = bps;
            }
            dbrep.DSPlayer = pls as ICollection <DSPlayer>;
            dbrep.HASH     = dbrep.GenHash();
            dbrep.Upload   = DateTime.UtcNow;


            return(dbrep);
        }
Exemple #4
0
        // WebDatabase Replay
        // LocalDatabase Replay
        // DecodedReplay
        // OldReplay
        public static DSReplay Rep(dsreplay rep, string id = "player")
        {
            DSReplay dbrep = new DSReplay();

            dbrep.REPLAYPATH = rep.REPLAY;
            using (var md5 = MD5.Create())
            {
                string dirHash  = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(Path.GetDirectoryName(rep.REPLAY)))).Replace("-", "").ToLowerInvariant();
                string fileHash = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(Path.GetFileName(rep.REPLAY)))).Replace("-", "").ToLowerInvariant();
                dbrep.REPLAY = dirHash + fileHash;
            }
            string   gametime = rep.GAMETIME.ToString();
            int      year     = int.Parse(gametime.Substring(0, 4));
            int      month    = int.Parse(gametime.Substring(4, 2));
            int      day      = int.Parse(gametime.Substring(6, 2));
            int      hour     = int.Parse(gametime.Substring(8, 2));
            int      min      = int.Parse(gametime.Substring(10, 2));
            int      sec      = int.Parse(gametime.Substring(12, 2));
            DateTime gtime    = new DateTime(year, month, day, hour, min, sec);

            dbrep.GAMETIME = gtime;
            dbrep.WINNER   = (sbyte)rep.WINNER;
            TimeSpan d = TimeSpan.FromSeconds(rep.DURATION / 22.4);

            dbrep.DURATION    = (int)d.TotalSeconds;
            dbrep.MINKILLSUM  = rep.MINKILLSUM;
            dbrep.MAXKILLSUM  = rep.MAXKILLSUM;
            dbrep.MINARMY     = rep.MINARMY;
            dbrep.MININCOME   = (int)rep.MININCOME;
            dbrep.PLAYERCOUNT = (byte)rep.PLAYERCOUNT;
            dbrep.REPORTED    = (byte)rep.REPORTED;
            dbrep.ISBRAWL     = rep.ISBRAWL;
            dbrep.GAMEMODE    = rep.GAMEMODE;
            dbrep.VERSION     = rep.VERSION;
            dbrep.MAXLEAVER   = 0;

            List <DSPlayer> pls = new List <DSPlayer>();

            foreach (dsplayer pl in rep.PLAYERS)
            {
                DSPlayer dbpl = new DSPlayer();
                dbpl.POS     = (byte)pl.POS;
                dbpl.REALPOS = (byte)pl.REALPOS;
                if (pl.NAME == "player")
                {
                    dbpl.NAME = id;
                }
                else
                {
                    dbpl.NAME = pl.NAME;
                }
                dbpl.RACE = pl.RACE;
                if (pl.TEAM == rep.WINNER)
                {
                    dbpl.WIN = true;
                }
                dbpl.TEAM      = (byte)pl.TEAM;
                dbpl.KILLSUM   = pl.KILLSUM;
                dbpl.INCOME    = (int)pl.INCOME;
                dbpl.PDURATION = (int)TimeSpan.FromSeconds(pl.PDURATION / 22.4).TotalSeconds;
                dbpl.ARMY      = pl.ARMY;
                dbpl.GAS       = (byte)pl.GAS;
                dsplayer opp = rep.GetOpp(pl.REALPOS);
                if (opp != null)
                {
                    dbpl.OPPRACE = opp.RACE;
                }
                int diff = dbrep.DURATION - dbpl.PDURATION;
                if (diff > dbrep.MAXLEAVER)
                {
                    dbrep.MAXLEAVER = diff;
                }

                dbpl.DSReplay = dbrep;
                pls.Add(dbpl);

                List <DbBreakpoint> bps = new List <DbBreakpoint>();
                foreach (var bp in pl.UNITS.Keys)
                {
                    DbBreakpoint dbbp = new DbBreakpoint();
                    dbbp.Breakpoint    = bp;
                    dbbp.dsUnitsString = "";

                    foreach (var name in pl.UNITS[bp].Keys)
                    {
                        if (name == "Gas")
                        {
                            dbbp.Gas = pl.UNITS[bp][name];
                        }
                        else if (name == "Upgrades")
                        {
                            dbbp.Upgrades = pl.UNITS[bp][name];
                        }
                        else if (name == "Mid")
                        {
                            dbbp.Mid = pl.UNITS[bp][name];
                        }
                        else
                        {
                            UnitModelBase unit = DSdata.Units.FirstOrDefault(f => f.Race == pl.RACE && f.Name == Fix.UnitName(name));
                            if (unit != null)
                            {
                                dbbp.dsUnitsString += unit.ID + "," + pl.UNITS[bp][name] + "|";
                            }
                            else
                            {
                                dbbp.dsUnitsString += name + "," + pl.UNITS[bp][name] + "|";
                            }
                        }
                    }
                    if (!String.IsNullOrEmpty(dbbp.dsUnitsString))
                    {
                        dbbp.dsUnitsString = dbbp.dsUnitsString.Remove(dbbp.dsUnitsString.Length - 1);
                    }
                    bps.Add(dbbp);
                }
                dbpl.Breakpoints = bps;
            }
            dbrep.DSPlayer = pls as ICollection <DSPlayer>;
            dbrep.HASH     = dbrep.GenHash();
            dbrep.Upload   = DateTime.UtcNow;
            return(dbrep);
        }
Exemple #5
0
 public void setUnitModel(UnitModelBase unitModel)
 {
     this.model = unitModel;
 }