Exemplo n.º 1
0
        private SpaceStation2D CreateSpaceStations_Build(Point3D position, FlagProps flag = null, int? purchasedVolume = null, Inventory[] playerInventory = null)
        {
            Vector3D axis = new Vector3D(0, 0, 1);
            Quaternion rotation = Math3D.GetRotation(axis, Math3D.GetRandomVector_Cone(axis, 30));

            SpaceStation2D retVal = new SpaceStation2D(position, _world, _material_SpaceStation, rotation, flag);

            retVal.SpinDegreesPerSecond = Math1D.GetNearZeroValue(.33, 1.1);

            retVal.RandomizeInventory(true);

            if (purchasedVolume != null && purchasedVolume.Value > retVal.PurchasedVolume)
            {
                retVal.PurchasedVolume = purchasedVolume.Value;
            }

            if (playerInventory != null)
            {
                retVal.PlayerInventory.AddRange(playerInventory);
            }

            _map.AddItem(retVal);

            return retVal;
        }
Exemplo n.º 2
0
 private void StoreInStation(ShipPartDNA dna)
 {
     Inventory inventory = new Inventory(dna);
     _spaceDock.AddInventory(inventory, true);
 }
        private void ShowShipCargo()
        {
            // Clear old
            foreach (InventoryEntry entry in pnlCargo.Children)
            {
                InventoryEntryRemoved(entry);
            }
            pnlCargo.Children.Clear();

            // Add new
            if (_player.Ship == null || _player.Ship.CargoBays == null)
            {
                return;
            }

            foreach (Cargo cargo in _player.Ship.CargoBays.GetCargoSnapshot())
            {
                Inventory inventory = null;

                switch (cargo.Type)
                {
                    case CargoType.Mineral:
                        Cargo_Mineral cargoMineral = (Cargo_Mineral)cargo;
                        inventory = new Inventory(ItemOptionsAstMin2D.GetMineral(cargoMineral.MineralType, cargoMineral.Volume));
                        break;

                    case CargoType.ShipPart:
                        Cargo_ShipPart part = (Cargo_ShipPart)cargo;
                        inventory = new Inventory(part.PartDNA);
                        break;

                    default:
                        throw new ApplicationException("Unknown CargoType: " + cargo.Type.ToString());
                }

                AddShipCargoGraphic(inventory);
            }
        }
        private void AddShipCargoGraphic(Inventory inventory)
        {
            string name = GetName(inventory);
            Tuple<decimal, decimal> credits = _station.GetPrice_Sell(inventory);

            string[] actions = inventory.Ship != null ?
                _actions_Player_Cargo_ship :
                _actions_Player_Cargo_nonship;

            InventoryEntry entry = new InventoryEntry();
            entry.SetInventory(inventory, name, credits.Item1 * credits.Item2, Convert.ToDouble(credits.Item2), null, _world, actions, _editorOptions);

            //pnlCargo.Children.Add(entry);
            AddToPanel(pnlCargo, entry);

            InventoryEntryAdded(entry);
        }
 private static string GetName(Inventory inventory)
 {
     if (inventory.Ship != null)
     {
         return GetName_Ship(inventory.Ship);
     }
     else if (inventory.Part != null)
     {
         return inventory.Part.PartType;
     }
     else if (inventory.Mineral != null)
     {
         return inventory.Mineral.MineralType.ToString();
     }
     else
     {
         throw new ApplicationException("Unknown type of inventory");
     }
 }
        private void AddStationMineralGraphic(Inventory inventory)
        {
            string name = GetName(inventory);
            Tuple<decimal, decimal> credits = _station.GetPrice_Buy(inventory);

            InventoryEntry entry = new InventoryEntry();
            entry.SetInventory(inventory, name, credits.Item1 * credits.Item2, Convert.ToDouble(credits.Item2), null, _world, _actions_Station_Minerals, _editorOptions);

            AddToPanel(pnlStationMinerals, entry);

            InventoryEntryAdded(entry);
        }
        private void StoreIn_Hangar_Nearby(Inventory inventory, string name)
        {
            // Figure out where to put it
            string[] actions;
            Panel panel;
            bool isHangar;

            if (_station.PurchasedVolume - _station.UsedVolume >= inventory.Volume)
            {
                // Hangar
                actions = inventory.Ship != null ? _actions_Player_Hangar_ship : _actions_Player_Hangar_nonship;
                panel = pnlHangar;
                isHangar = true;
            }
            else
            {
                // Nearby
                actions = inventory.Ship != null ? _actions_Player_FreeSpace_ship : _actions_Player_FreeSpace_nonship;
                panel = pnlNearbyItems;
                isHangar = false;
            }

            // Create an entry with the sell price
            Tuple<decimal, decimal> credits = _station.GetPrice_Sell(inventory);

            InventoryEntry newEntry = new InventoryEntry();
            newEntry.SetInventory(inventory, name, credits.Item1 * credits.Item2, Convert.ToDouble(credits.Item2), null, _world, actions, _editorOptions);

            // Store it
            //panel.Children.Add(newEntry);
            AddToPanel(panel, newEntry);
            InventoryEntryAdded(newEntry);

            if (isHangar)
            {
                _station.PlayerInventory.Add(inventory);
                OnHangarChanged();
            }
        }
 public InventoryActionClickedArgs(string action, Inventory inventory, string name, decimal credits)
 {
     this.Action = action;
     this.Inventory = inventory;
     this.Name = name;
     this.Credits = credits;
 }
        private async void SwapShip(InventoryEntry entry)
        {
            const double STARTPERCENT = .25;        // don't make it too high, or they will cheat and switch ships to refuel



            //TODO: Remember the cargo in a separate object
            //TODO: Remember the part damage in a separate object



            // Remove the old entry
            RemoveFrom_Cargo_Hangar_Neaby(entry);

            // Store the old ship
            if (_player.Ship != null)
            {
                Inventory prevInventory = new Inventory(_player.Ship.GetNewDNA(), 1d);
                string prevName = GetName_Ship(prevInventory.Ship);

                StoreIn_Hangar_Nearby(prevInventory, prevName);
            }

            //NOTE: Grabbing this now, because the ship creation is async, and station could be null
            // by the time it's finished
            Point3D stationPosition = _station.PositionWorld;

            // Need to do this now so that the old ship is off the map before adding a new one (the new one sometimes goes flying from the collision)
            _player.Ship = null;

            // Create the new ship
            ShipPlayer ship = ShipPlayer.GetNewShip(entry.Inventory.Ship, _world, _material_Ship, _map, _shipExtra);

            if (ship.Energy != null)
            {
                ship.Energy.QuantityCurrent = ship.Energy.QuantityMax * STARTPERCENT;
            }
            if (ship.Plasma != null)
            {
                ship.Plasma.QuantityCurrent = ship.Plasma.QuantityMax * STARTPERCENT;
            }
            if (ship.Fuel != null)
            {
                ship.Fuel.QuantityCurrent = ship.Fuel.QuantityMax * STARTPERCENT;
            }
            if (ship.Ammo != null)
            {
                ship.Ammo.QuantityCurrent = ship.Ammo.QuantityMax * STARTPERCENT;
            }
            ship.RecalculateMass();

            ship.PhysicsBody.Position = new Point3D(stationPosition.X, stationPosition.Y, 0);
            ship.PhysicsBody.Velocity = new Vector3D(0, 0, 0);
            ship.PhysicsBody.AngularVelocity = new Vector3D(0, 0, 0);

            _player.Ship = ship;        // the ship changed event listener will add the ship to the map
        }
Exemplo n.º 10
0
        private void StoreIn_Mineral_Part_Ship(Inventory inventory)
        {
            _station.StationInventory.Add(inventory);

            if (inventory.Ship != null)
            {
                AddStationShipGraphic(inventory);
            }
            else if (inventory.Part != null)
            {
                AddStationPartGraphic(inventory);
            }
            else if (inventory.Mineral != null)
            {
                AddStationMineralGraphic(inventory);
            }
            else
            {
                throw new ArgumentException("Unknown type of inventory");
            }
        }
Exemplo n.º 11
0
        private void ScrapShip(InventoryEntry entry)
        {
            if (entry == null || entry.Inventory == null || entry.Inventory.Ship == null)
            {
                throw new ArgumentException("entry is/contains null");
            }

            // Remove the old entry
            RemoveFrom_Cargo_Hangar_Neaby(entry);

            // Pull all the parts out of the ship, and turn them into inventory
            foreach (ShipPartDNA part in entry.Inventory.Ship.PartsByLayer.Values.SelectMany(o => o))
            {
                Inventory inventory = new Inventory(part);
                string name = GetName(inventory);

                StoreIn_Cargo_Hangar_Nearby(inventory, name);
            }
        }
Exemplo n.º 12
0
        private void btnLoadShipFromFile_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string foldername = System.IO.Path.Combine(UtilityCore.GetOptionsFolder(), ShipEditorWindow.SHIPFOLDER);

                ShipSelectorWindow dialog = new ShipSelectorWindow(foldername, _world);
                dialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;

                bool? dialogResult = dialog.ShowDialog();

                if (dialogResult == null || !dialogResult.Value)
                {
                    return;
                }

                foreach (ShipDNA dna in dialog.SelectedItems)
                {
                    Inventory inventory = new Inventory(dna, 1);

                    _station.StationInventory.Add(inventory);
                    AddStationShipGraphic(inventory);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), TITLE, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 13
0
 //TODO: There should be a viewmodel instead of implementing all of this list->panel logic here
 public void AddInventory(Inventory inventory, bool isPlayerOwned)
 {
     if (isPlayerOwned)
     {
         string name = GetName(inventory);
         StoreIn_Hangar_Nearby(inventory, name);
     }
     else
     {
         StoreIn_Mineral_Part_Ship(inventory);
     }
 }
Exemplo n.º 14
0
        private void StoreInStation(Cargo cargo)
        {
            Inventory inventory;
            if (cargo is Cargo_Mineral)
            {
                Cargo_Mineral cargoMineral = (Cargo_Mineral)cargo;
                MineralDNA mineralDNA = ItemOptionsAstMin2D.GetMineral(cargoMineral.MineralType, cargoMineral.Volume);
                inventory = new Inventory(mineralDNA);
            }
            else if (cargo is Cargo_ShipPart)
            {
                Cargo_ShipPart cargoPart = (Cargo_ShipPart)cargo;
                inventory = new Inventory(cargoPart.PartDNA);
            }
            else
            {
                throw new ApplicationException("Unknown type of cargo: " + cargo.GetType().ToString());
            }

            _spaceDock.AddInventory(inventory, true);
        }
Exemplo n.º 15
0
        private void StoreIn_Cargo_Hangar_Nearby(Inventory inventory, string name)
        {
            Cargo cargo = null;
            if (inventory.Mineral != null)
            {
                cargo = new Cargo_Mineral(inventory.Mineral.MineralType, inventory.Mineral.Density, inventory.Mineral.Volume);
            }
            else if (inventory.Part != null)
            {
                cargo = new Cargo_ShipPart(inventory.Part, _itemOptions, _editorOptions);
            }
            else
            {
                throw new ApplicationException("finish this");
            }

            if (_player.Ship.CargoBays != null && _player.Ship.CargoBays.Add(cargo))
            {
                AddShipCargoGraphic(inventory);
            }
            else
            {
                StoreIn_Hangar_Nearby(inventory, name);
            }
        }
Exemplo n.º 16
0
        private static Icon3D BuildIcon(Inventory inventory, World world, EditorOptions options, FrameworkElement parent)
        {
            Icon3D retVal = null;

            if (inventory.Ship != null)
            {
                retVal = new Icon3D("", inventory.Ship, world);       // don't want to autorotate the ship icons.  This is a 2D game, and the ships will always be viewed from the top
            }
            else if (inventory.Part != null)
            {
                retVal = new Icon3D(inventory.Part, options)
                {
                    AutoRotateOnMouseHover = true,
                    AutoRotateParent = parent,
                };
            }
            else if (inventory.Mineral != null)
            {
                retVal = new Icon3D(inventory.Mineral.MineralType)
                {
                    AutoRotateOnMouseHover = true,
                    AutoRotateParent = parent,
                };
            }

            if (retVal != null)
            {
                retVal.ShowName = false;
                retVal.ShowBorder = false;
            }

            return retVal;
        }
Exemplo n.º 17
0
        private void StoreIn_Nearby(Inventory inventory, string name)
        {
            // Create an entry with the sell price
            Tuple<decimal, decimal> credits = _station.GetPrice_Sell(inventory);

            string[] actions = inventory.Ship != null ?
                _actions_Player_FreeSpace_ship :
                _actions_Player_FreeSpace_nonship;

            InventoryEntry newEntry = new InventoryEntry();
            newEntry.SetInventory(inventory, name, credits.Item1 * credits.Item2, Convert.ToDouble(credits.Item2), null, _world, actions, _editorOptions);

            // Store it
            AddToPanel(pnlNearbyItems, newEntry);
            InventoryEntryAdded(newEntry);
        }
Exemplo n.º 18
0
        public void SetInventory(Inventory inventory, string name, decimal credits, double? creditsPercent, double? volumePercent, World world, string[] actionButtons, EditorOptions options)
        {
            // Icon
            pnlIcon.Content = BuildIcon(inventory, world, options, this);

            // Name
            lblName.Text = name;

            if (inventory.Count == 1)
            {
                lblMultipleX.Visibility = Visibility.Collapsed;
                lblMultiple.Visibility = Visibility.Collapsed;
            }
            else
            {
                lblMultipleX.Visibility = Visibility.Visible;
                lblMultiple.Visibility = Visibility.Visible;
                lblMultiple.Text = inventory.Count.ToString("N0");
            }

            // Price
            lblPrice.Text = credits.ToString("N0");
            if (creditsPercent == null)
            {
                lblPricePercent.Visibility = Visibility.Collapsed;
            }
            else
            {
                lblPricePercent.Text = GetPercentText(creditsPercent.Value);
            }

            // Volume
            lblVolume.Text = Math.Round(inventory.Volume, 2).ToString();
            if (volumePercent == null)
            {
                lblVolumePercent.Visibility = Visibility.Collapsed;
            }
            else
            {
                lblVolumePercent.Text = GetPercentText(volumePercent.Value);
            }

            // Mass
            //lblMass.Text = Math.Round(inventory.Mass, 2).ToString();
            lblMass.Text = inventory.Mass.ToStringSignificantDigits(2);

            // Action Buttons
            pnlActionButtons.Children.Clear();

            switch (actionButtons.Length)
            {
                case 2:
                case 4:
                    pnlActionButtons.Columns = 2;
                    break;

                default:
                    pnlActionButtons.Columns = 3;
                    break;
            }

            pnlActionButtons.Rows = Convert.ToInt32(Math.Ceiling(actionButtons.Length / Convert.ToDouble(pnlActionButtons.Columns)));

            foreach (string action in actionButtons)
            {
                pnlActionButtons.Children.Add(new Button()
                {
                    Content = action
                });
            }

            // Store props
            this.Inventory = inventory;
            this.InventoryName = name;
            this.Credits = credits;
        }
Exemplo n.º 19
0
        private void StoreInStation(ShipPartDNA dna)
        {
            Inventory inventory = new Inventory(dna);

            _spaceDock.AddInventory(inventory, true);
        }