Пример #1
0
        /// <summary>
        /// If amountRequested is greater than amount allowed (e.g. more health requested than MaxHealth), returns amount corresponding to max allowed
        /// </summary>
        /// <param name="ship"></param>
        /// <param name="serviceType"></param>
        /// <param name="amountAllowed"></param>
        /// <returns></returns>
        public float GetTotalServicePrice(PortServiceRequestData serviceData)
        {
            if (!_servicesForSale.ContainsKey(serviceData.ServiceType))//Ideally we'll never get here
            {
                return(float.MaxValue);
            }

            return(_servicesForSale[serviceData.ServiceType].GetTotalPrice(serviceData));
        }
Пример #2
0
 public override bool Execute(PortServiceRequestData serviceRequestData)
 {
     serviceRequestData.ReceivingShip.CurrentHealth += serviceRequestData.NumUnits;
     if (serviceRequestData.ReceivingShip.CurrentHealth > serviceRequestData.ReceivingShip.MaxHealth)
     {
         serviceRequestData.ReceivingShip.CurrentHealth = serviceRequestData.ReceivingShip.MaxHealth;
     }
     return(true);
 }
Пример #3
0
        /// <summary>
        /// May modify serviceRequestData.NumUnits
        /// </summary>
        /// <param name="serviceRequestData"></param>
        /// <returns></returns>
        public virtual PurchaseResult ValidateRequest(PortServiceRequestData serviceRequestData)
        {
            var ship = serviceRequestData.ReceivingShip;

            if (GetNumAllowed(serviceRequestData) < serviceRequestData.NumUnits)
            {
                return(PurchaseResult.TooManyUnitsRequested);
            }

            serviceRequestData.TotalPrice = port.GetTotalServicePrice(serviceRequestData);

            if (ship.Cargo.GetCargoAmount(StatelessCargoTypes.Cash) < serviceRequestData.TotalPrice)
            {
                return(PurchaseResult.NotEnoughCash);
            }

            return(PurchaseResult.Success);
        }
Пример #4
0
        /// <summary>
        /// Checks if a service request is valid. Sets serviceRequestData.TotalPrice
        /// </summary>
        /// <param name="serviceRequestData"></param>
        /// <returns></returns>
        public PurchaseResult ValidatePurchaseResult(PortServiceRequestData serviceRequestData)
        {
            var ship = serviceRequestData.ReceivingShip;

            if (!ServicesForSale.ContainsKey(serviceRequestData.ServiceType))//Make sure port offers this service
            {
                return(PurchaseResult.ServiceNotAvailable);
            }
            else if (Id != ship.CurrentAreaId)//Make sure the IShip is actually docked
            {
                return(PurchaseResult.WrongArea);
            }
            else if (!ShipIDs.Contains(ship.Id))
            {
                ConsoleManager.WriteLine("Inconsistent state between Ship.CurrentAreaID and port.ShipIDs", ConsoleMessageType.Error);
                return(PurchaseResult.WrongArea);
            }
            else
            {
                return(_servicesForSale[serviceRequestData.ServiceType].ValidateRequest(serviceRequestData));
            }
        }
Пример #5
0
 public override float GetTotalPrice(PortServiceRequestData serviceRequestData)
 {
     return(serviceRequestData.NumUnits * CurrentPrice);
 }
Пример #6
0
 public override float GetNumAllowed(PortServiceRequestData serviceRequestData)
 {
     return(serviceRequestData.ReceivingShip.MaxHealth - serviceRequestData.ReceivingShip.CurrentHealth);
 }
Пример #7
0
 public abstract float GetNumAllowed(PortServiceRequestData serviceRequestData);
Пример #8
0
 public abstract float GetTotalPrice(PortServiceRequestData serviceRequestData);
Пример #9
0
 /// <summary>
 /// Should return true upon succesful completion.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public abstract bool Execute(PortServiceRequestData requestData);