コード例 #1
0
        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.");
            }
            }
        }
コード例 #2
0
        /// <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);
            }
        }