/// <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); }
private static ShipPartDNA GetRandomPart(PartCreateChance part) { ShipPartDNA retVal = null; switch (part.PartType) { case Thruster.PARTTYPE: #region Thruster ThrusterDNA dnaThrust = new ThrusterDNA() { PartType = part.PartType, Orientation = Math3D.GetRandomRotation(), Position = new Point3D(), Scale = GetRandomScale(part.ScaleBase), }; dnaThrust.ThrusterType = UtilityCore.GetRandomEnum <ThrusterType>(new[] { ThrusterType.Two_Two_One, ThrusterType.Two_Two_Two }); // only want 2D thrusters if (dnaThrust.ThrusterType == ThrusterType.Custom) { dnaThrust.ThrusterDirections = Enumerable.Range(0, StaticRandom.Next(2, 5)). Select(o => Math3D.GetRandomVector_Circular_Shell(1)). // only want 2D thrusters ToArray(); } retVal = dnaThrust; #endregion break; case ConverterRadiationToEnergy.PARTTYPE: #region ConverterRadiationToEnergy ConverterRadiationToEnergyDNA dnaCon = new ConverterRadiationToEnergyDNA() { PartType = part.PartType, Orientation = Math3D.GetRandomRotation(), Position = new Point3D(), Scale = GetRandomScale(part.ScaleBase), Shape = UtilityCore.GetRandomEnum <SolarPanelShape>(), }; retVal = dnaCon; #endregion break; default: #region default retVal = new ShipPartDNA() { PartType = part.PartType, Orientation = Math3D.GetRandomRotation(), Position = new Point3D(), Scale = GetRandomScale(part.ScaleBase), }; #endregion break; } return(retVal); }