Пример #1
0
        /// <summary>
        /// This should get called on an infrequent basis, and randomize the available inventory
        /// </summary>
        public void RandomizeInventory(bool completelyNew)
        {
            RandomizePrices();

            if (completelyNew)
            {
                this.StationInventory.Clear();
            }

            List <Inventory> inventory = new List <Inventory>();

            // Ships
            inventory.AddRange(AdjustInventory(
                                   this.StationInventory.Where(o => o.Ship != null),
                                   3,
                                   () =>
            {
                DefaultShipType shipType = GetRandomItemChance(_shipChances).ShipType;
                ShipDNA shipDNA          = DefaultShips.GetDNA(shipType);
                return(new Inventory(shipDNA, StaticRandom.NextDouble(.5, 2)));
            }));


            // Parts
            inventory.AddRange(AdjustInventory(
                                   this.StationInventory.Where(o => o.Part != null),
                                   4,
                                   () =>
            {
                PartCreateChance partType = GetRandomItemChance(_partChances);
                ShipPartDNA partDNA       = GetRandomPart(partType);    //TODO: Have a chance to make 2 if it's something that could come in pairs (thruster, gun, etc)
                return(new Inventory(partDNA));
            }));

            // Minerals
            inventory.AddRange(AdjustInventory(
                                   this.StationInventory.Where(o => o.Mineral != null),
                                   4,
                                   () =>
            {
                MineralType type = UtilityCore.GetRandomEnum <MineralType>();
                double volume    = StaticRandom.NextPercent(ItemOptionsAstMin2D.MINERAL_AVGVOLUME, 2);
                return(new Inventory(ItemOptionsAstMin2D.GetMineral(type, volume)));
            }));

            this.StationInventory.Clear();
            this.StationInventory.AddRange(inventory);

            _inventoryRandomizeCountdown = StaticRandom.NextDouble(3 * 60, 8 * 60);
        }
Пример #2
0
        private void GetMineralBlipSprtCacheProps()
        {
            // Get the min/max values
            double minDollars = double.MaxValue;
            double maxDollars = double.MinValue;

            SortedList <MineralType, double> dollars = new SortedList <MineralType, double>();

            foreach (MineralType mineralType in Enum.GetValues(typeof(MineralType)))
            {
                //decimal suggestedDollars = Mineral.GetSuggestedCredits(mineralType);
                decimal suggestedDollars       = ItemOptionsAstMin2D.GetCredits_Mineral(mineralType);
                double  suggestedDollarsScaled = Math.Sqrt(Convert.ToDouble(suggestedDollars));   // taking the square root, because the values are exponential, and I want the color scale more linear
                dollars.Add(mineralType, suggestedDollarsScaled);

                if (suggestedDollarsScaled < minDollars)
                {
                    minDollars = suggestedDollarsScaled;
                }

                if (suggestedDollarsScaled > maxDollars)
                {
                    maxDollars = suggestedDollarsScaled;
                }
            }

            // Store color based on those values
            _mineralColors = new SortedList <MineralType, MineralBlipProps>();
            Color maxColor = Colors.Chartreuse;

            foreach (MineralType mineralType in Enum.GetValues(typeof(MineralType)))
            {
                Color  diffuse, specular;
                double size;

                double dollar = dollars[mineralType];

                double colorPercent = UtilityCore.GetScaledValue_Capped(.33d, 1d, minDollars, maxDollars, dollar);
                diffuse  = UtilityWPF.AlphaBlend(maxColor, Colors.Transparent, colorPercent);
                specular = diffuse;

                //size = UtilityCore.GetScaledValue_Capped(2d, 5d, minDollars, maxDollars, dollar);
                size = UtilityCore.GetScaledValue_Capped(4d, 10d, minDollars, maxDollars, dollar);

                _mineralColors.Add(mineralType, new MineralBlipProps(diffuse, specular, size));
            }
        }
Пример #3
0
        public MapPopulationManager(Map map, World world, Point3D boundryMin, Point3D boundryMax, int material_Asteroid, int material_Mineral, Func <double, ITriangleIndexed[], double> getAsteroidMassByRadius, Func <double, MineralDNA[]> getMineralsByDestroyedMass, double minChildAsteroidRadius)
        {
            _map   = map;
            _world = world;

            _boundry = new Boundry(boundryMin, boundryMax);

            _material_Asteroid = material_Asteroid;
            _material_Mineral  = material_Mineral;

            _getAsteroidMassByRadius    = getAsteroidMassByRadius;
            _getMineralsByDestroyedMass = getMineralsByDestroyedMass;

            _minChildAsteroidRadius = minChildAsteroidRadius;

            _mineralTypesByValue = ((MineralType[])Enum.GetValues(typeof(MineralType))).
                                   Select(o => new { Type = o, Value = ItemOptionsAstMin2D.GetCredits_Mineral(o) }).
                                   OrderBy(o => o.Value).
                                   Select(o => o.Type).
                                   ToArray();
        }
Пример #4
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);
        }
Пример #5
0
        public Tuple <decimal, decimal> GetPrice_Base(Inventory inventory)
        {
            if (inventory.Ship != null)
            {
                Tuple <decimal, decimal>[] prices = inventory.Ship.PartsByLayer.
                                                    SelectMany(o => o.Value).
                                                    Select(o =>
                {
                    decimal standPrice = ItemOptionsAstMin2D.GetCredits_ShipPart(o);
                    decimal mult1      = FindPriceMult(o.PartType);
                    return(Tuple.Create(standPrice, mult1));
                }).
                                                    ToArray();

                // Get the weighted percent (taking this % times the sum will be the same as taking the sum of each individual price*%)
                double mult2 = Math1D.Avg(prices.Select(o => Tuple.Create(Convert.ToDouble(o.Item2), Convert.ToDouble(o.Item1))).ToArray());

                // Make a completed ship more expensive than just parts
                return(Tuple.Create(prices.Sum(o => o.Item1) * 1.5m, Convert.ToDecimal(mult2)));
            }
            else if (inventory.Part != null)
            {
                decimal standPrice = ItemOptionsAstMin2D.GetCredits_ShipPart(inventory.Part);
                decimal mult       = FindPriceMult(inventory.Part.PartType);
                return(Tuple.Create(standPrice, mult));
            }
            else if (inventory.Mineral != null)
            {
                //return ItemOptionsAstMin2D.GetCredits_Mineral(inventory.Mineral.MineralType, inventory.Mineral.Volume);
                decimal mult = FindPriceMult(inventory.Mineral.MineralType);
                return(Tuple.Create(inventory.Mineral.Credits, mult));
            }
            else
            {
                throw new ApplicationException("Unknown type of inventory");
            }
        }
Пример #6
0
        public decimal GetPrice_Repair(PartBase part)
        {
            const decimal MULT_DESTROYED = .75m;
            const decimal MULT_PARTIAL   = .4m;

            if (!part.IsDestroyed && part.HitPoints_Current.IsNearValue(part.HitPoints_Max))
            {
                return(0m);
            }

            // Make the repair cost some fraction of the cost of a new part
            decimal purchasePrice = ItemOptionsAstMin2D.GetCredits_ShipPart(part.GetNewDNA());

            if (part.IsDestroyed)
            {
                return(purchasePrice * MULT_DESTROYED);
            }
            else
            {
                double percent = (part.HitPoints_Max - part.HitPoints_Current) / part.HitPoints_Max;

                return(Convert.ToDecimal(percent) * purchasePrice * MULT_PARTIAL);
            }
        }
Пример #7
0
 public decimal GetPrice_Buy_Ammo()
 {
     return(ItemOptionsAstMin2D.GetCredits_Ammo());
 }