public float GetPrice(PortWareIdentifier identifier, float quantity, PortTradeDirection direction) { switch (direction) { case PortTradeDirection.ShipPurchaseFromPort: { if (_model.Prices_ShipPurchaseFromPort.ContainsKey(identifier)) { return(_model.Prices_ShipPurchaseFromPort[identifier] * quantity); } else { return(float.MaxValue); } } case PortTradeDirection.ShipSaleToPort: { if (_model.Prices_ShipSaleToPort.ContainsKey(identifier)) { return(_model.Prices_ShipSaleToPort[identifier] * quantity); } else { return(float.MaxValue); } } default: { throw new NotImplementedException("Sale direction " + direction.ToString() + " not implemented."); } } }
public float GetPrice(List <StatefulCargo> statefulCargoObjects, PortTradeDirection direction) { float sum = 0; foreach (var s in statefulCargoObjects) { sum += GetPrice(s.CargoType, 1, direction); } return(sum); }
/// <summary> /// Validates trade request and schedules awaitable transaction sequence /// Trades are all or nothing. /// Leave typesAndQuantites or statefulCargoIDs null if unused. /// </summary> /// <param name="sellingPort"></param> /// <param name="purchasingShip"></param> /// <param name="wareType"></param> /// <param name="quantity"></param> /// <param name="statefulCargoID"></param> /// <returns></returns> public async Task <PurchaseResult> TryTradeWithPort(Port port, IShip ship, PortTradeDirection direction, Dictionary <PortWareIdentifier, float> typesAndQuantities, HashSet <int> statefulCargoIDs) { switch (direction) { case PortTradeDirection.ShipSaleToPort: { return(await TrySellToPort(ship, port, typesAndQuantities, statefulCargoIDs)); } case PortTradeDirection.ShipPurchaseFromPort: { return(await TryPurchaseCargoFromPort(port, ship, typesAndQuantities, statefulCargoIDs)); } default: throw new NotImplementedException(direction.ToString() + " not implemented in " + this.GetType().Name); } }
public float GetPrice(Dictionary <StatelessCargoTypes, float> typesAndQuantities, PortTradeDirection direction) { float totalPrice = 0; foreach (var t in typesAndQuantities) { totalPrice += GetPrice(t.Key, t.Value, direction); } return(totalPrice); }
public float GetPrice(PortServiceTypes serviceType, float quantity, PortTradeDirection direction) { var identifier = PortHelper.GetPortWareIdentifier(serviceType); return(GetPrice(identifier, quantity, direction)); }
public float GetPrice(StatefulCargoTypes cargoType, int quantity, PortTradeDirection direction) { var identifier = PortHelper.GetPortWareIdentifier(cargoType); return(GetPrice(identifier, quantity, direction)); }