Exemplo n.º 1
0
        private void SaveSession(bool async, bool pruneAutosavesAfter)
        {
            Miner2DSession session = _session ?? new Miner2DSession();
            _session = session;

            List<Tuple<string, object>> items = new List<Tuple<string, object>>();

            // Player
            items.Add(new Tuple<string, object>("Player", new PlayerDNA()
            {
                Ship = _player.Ship.GetNewDNA(),

                Energy = _player.Ship.Energy != null ? _player.Ship.Energy.QuantityCurrent : 0d,
                Plasma = _player.Ship.Plasma != null ? _player.Ship.Plasma.QuantityCurrent : 0d,
                Fuel = _player.Ship.Fuel != null ? _player.Ship.Fuel.QuantityCurrent : 0d,
                Ammo = _player.Ship.Ammo != null ? _player.Ship.Ammo.QuantityCurrent : 0d,

                Credits = _player.Credits,
            }));

            // CargoBay Contents
            if (_player.Ship != null && _player.Ship.CargoBays != null)
            {
                Cargo[] cargo = _player.Ship.CargoBays.GetCargoSnapshot();
                if (cargo != null && cargo.Length > 0)
                {
                    items.AddRange(cargo.Select((o, i) => new Tuple<string, object>("Cargo_" + i.ToString(), o.GetNewDNA())));
                }
            }

            // Stations
            items.AddRange(_stations.Select((o, i) => new Tuple<string, object>("Station_" + i.ToString(), o.GetNewDNA())));

            SessionSaveLoad.Save(SAVENAME, session, items, false);

            if (pruneAutosavesAfter)
            {
                SessionSaveLoad.PruneAutosaves(session.LatestSessionFolder);
            }
        }
Exemplo n.º 2
0
        private bool LoadSession(SessionFolderResults results)
        {
            if (results == null || results.SavedFiles == null)
            {
                return false;
            }

            #region group classes

            SpaceStation2DDNA[] stations = results.SavedFiles.
                Select(o => o.Item2 as SpaceStation2DDNA).
                Where(o => o != null).
                ToArray();

            PlayerDNA player = results.SavedFiles.
                Select(o => o.Item2 as PlayerDNA).
                FirstOrDefault(o => o != null);

            CargoDNA[] cargo = results.SavedFiles.
                Select(o => o.Item2 as CargoDNA).
                Where(o => o != null).
                ToArray();

            #endregion

            if (player == null || player.Ship == null || stations == null || stations.Length == 0)
            {
                return false;
            }

            // Session
            _session = results.SessionFile as Miner2DSession;       // could be null

            // Stations
            CreateSpaceStations(stations);

            #region player

            CreateShip(player.Ship);        // this stores it in _player

            if (_player.Ship.Energy != null)
            {
                _player.Ship.Energy.QuantityCurrent = player.Energy;
            }
            if (_player.Ship.Plasma != null)
            {
                _player.Ship.Plasma.QuantityCurrent = player.Plasma;
            }
            if (_player.Ship.Fuel != null)
            {
                _player.Ship.Fuel.QuantityCurrent = player.Fuel;
            }
            if (_player.Ship.Ammo != null)
            {
                _player.Ship.Ammo.QuantityCurrent = player.Ammo;
            }

            if (_player.Ship.CargoBays != null && cargo != null && cargo.Length > 0)
            {
                foreach (CargoDNA cargoDNA in cargo)
                {
                    _player.Ship.CargoBays.Add(cargoDNA.ToCargo());
                }
            }

            _player.Ship.RecalculateMass();

            _player.Credits = player.Credits;

            #endregion

            return true;
        }
Exemplo n.º 3
0
        private void CreateNewSession()
        {
            DefaultShipType[] shipTypes = new[]
            {
                DefaultShipType.Basic,
                DefaultShipType.Horseshoe,
                DefaultShipType.Pusher,
                DefaultShipType.Star,
            };

            CreateShip(shipTypes[StaticRandom.Next(shipTypes.Length)]);
            //CreateShip(DefaultShipType.Basic);
            //CreateShip_3DFlyer();
            //CreateShip_FromFile();

            _player.Credits = 100;

            CreateSpaceStations();

            _session = null;
        }