Ejemplo n.º 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 = pl.Stats.Where(x => x.Gameloop <= bp).LastOrDefault();

            if (statlast != null)
            {
                Bp.Army     = statlast.Army;
                Bp.Kills    = statlast.MineralsKilledArmy;
                Bp.Upgrades = statlast.MineralsUsedCurrentTechnology;
            }

            List <DbUnit> dbUnits   = null;
            var           spawnlast = pl.Spawns.Where(x => x.Gameloop <= bp).LastOrDefault();

            if (spawnlast != null)
            {
                dbUnits = spawnlast.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)
                    {
                        Bp.Units.Add(new DSUnit()
                        {
                            Name       = unit.Name,
                            BP         = bpstring,
                            Breakpoint = Bp,
                            Count      = 1,
                            DSPlayer   = pl
                        });
                    }
                    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;
                int    id   = NameService.GetUnitId(null, unit.Name);
                if (id >= 0)
                {
                    name = 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;
                int    id   = NameService.GetUnitId(null, unit.Name);
                if (id >= 0)
                {
                    name = 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);
        }