示例#1
0
        ///<summary>
        ///Save Player to this
        ///</summary>
        public BBuild GetBuild(Player pl)
        {
            Abilities     = new HashSet <UnitAbilities>();
            Upgrades      = new HashSet <UnitUpgrades>();
            UpgradesLevel = new List <KeyValuePair <int, int> >();
            Units         = new List <KeyValuePair <int, int> >();
            Position      = new List <KeyValuePair <int, Vector2Ser> >();


            Dictionary <int, int> bunits = new Dictionary <int, int>();

            foreach (Unit unit in pl.Units.Where(x => x.Status != UnitStatuses.Available))
            {
                Unit defaultunit = UnitPool.Units.SingleOrDefault(x => x.Name == unit.Name);
                if (defaultunit == null)
                {
                    defaultunit = UnitPool.Units.SingleOrDefault(x => x.Name == "NA");
                }
                int id = defaultunit.ID;
                if (!bunits.ContainsKey(id))
                {
                    bunits[id] = 1;
                }
                else
                {
                    bunits[id]++;
                }

                Vector2Ser vec = new Vector2Ser();
                vec.x = unit.PlacePos.X;
                vec.y = unit.PlacePos.Y;
                this.Position.Add(new KeyValuePair <int, Vector2Ser>(id, vec));
            }

            foreach (var ent in bunits)
            {
                this.Units.Add(new KeyValuePair <int, int>(ent.Key, ent.Value));
            }

            foreach (UnitAbility ability in pl.AbilityUpgrades)
            {
                this.Abilities.Add(ability.Ability);
            }

            foreach (UnitUpgrade upgrade in pl.Upgrades)
            {
                this.Upgrades.Add(upgrade.Upgrade);
                this.UpgradesLevel.Add(new KeyValuePair <int, int>(UpgradePool.Upgrades.SingleOrDefault(x => x.Race == pl.Race && x.Name == upgrade.Upgrade).ID, upgrade.Level));
            }

            this.Name            = pl.Name;
            this.Pos             = pl.Pos;
            this.Race            = (int)pl.Race;
            this.MineralsCurrent = pl.MineralsCurrent;
            this.Tier            = pl.Tier;
            return(this);
        }
示例#2
0
        ///<summary>
        ///Restore player from this
        ///</summary>
        public void SetBuild(Player pl)
        {
            pl.SoftReset();
            lock (this)
            {
                foreach (var ent in Abilities)
                {
                    pl.MineralsCurrent += UnitService.AbilityUpgradeUnit(AbilityPool.Abilities.SingleOrDefault(x => x.Ability == ent), pl);
                }

                foreach (var ent in Upgrades)
                {
                    pl.MineralsCurrent += UnitService.UpgradeUnit(ent, pl);
                }

                foreach (var ent in Units)
                {
                    if (ent.Value > 0)
                    {
                        for (int i = 0; i < ent.Value; i++)
                        {
                            Unit unit      = UnitPool.Units.SingleOrDefault(x => x.ID == ent.Key).DeepCopy();
                            var  positions = Position.Where(x => x.Key == unit.ID).ToList();
                            if (positions.Count() >= i)
                            {
                                Vector2Ser vec = positions.ElementAt(i).Value;
                                unit.PlacePos = new Vector2(vec.x, vec.y);
                                UnitService.NewUnit(pl, unit);
                                pl.Units.Add(unit);
                                pl.MineralsCurrent += unit.Cost;
                            }
                        }
                    }
                }
            }
        }