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"); } }
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); } }