예제 #1
0
        /// <summary>
        /// Attempts to ad numToAdd objects of CargoType type
        /// Returns true if succesful
        /// </summary>
        /// <param name="type"></param>
        /// <param name="numToAdd"></param>
        /// <returns></returns>
        public override CargoResult AddStatelessCargo(StatelessCargoTypes type, float numToAdd, bool suspendBoundsChecking)
        {
            if (_model.StatelessCargo.ContainsKey(type))//If there is already at least one of this item type on the ship
            {
                _model.StatelessCargo[type].Quantity += numToAdd;
            }
            else
            {
                _model.StatelessCargo.Add(type, new StatelessCargo(type, numToAdd));
            }
            _model.FilledHolds += numToAdd * StatelessCargo.SpacePerObject(type);
            if (StatelessCargoPriceGetter != null)
            {
                SetCargoPurchasePrice(PortHelper.GetPortWareIdentifier(type), StatelessCargoPriceGetter(new StatelessCargo(_model.StatelessCargo[type]), PriceType.PortPurchasing));
                SetCargoSalePrice(PortHelper.GetPortWareIdentifier(type), StatelessCargoPriceGetter(new StatelessCargo(_model.StatelessCargo[type]), PriceType.PortSelling));
            }
            PortWareIdentifier portGoodIdentifier;

            if (Enum.TryParse(type.ToString(), out portGoodIdentifier))
            {
                UpdateGoodCounts(portGoodIdentifier, numToAdd);
                UpdateUIStatLists(portGoodIdentifier, _model.StatelessCargo[type]);
            }

            return(CargoResult.Success);
        }
예제 #2
0
 public virtual bool CheckCargoSpace(Dictionary <StatelessCargoTypes, float> typesAndQuantities, ref float spaceOccupied)
 {
     foreach (var t in typesAndQuantities)
     {
         spaceOccupied += StatelessCargo.SpacePerObject(t.Key) * t.Value;
     }
     return(spaceOccupied <= _model.TotalHolds - _model.FilledHolds);
 }
예제 #3
0
 /// <summary>
 /// If quantity <0, set statelessCargo to null to have it removed from the UIComponent
 /// </summary>
 /// <param name="portWareIdentifier"></param>
 /// <param name="statelessCargo"></param>
 void UpdateUIStatLists(PortWareIdentifier portWareIdentifier, StatelessCargo statelessCargo)
 {
     if (statelessCargo == null)
     {
         _model.UIComponent.Goods.Remove(portWareIdentifier);
     }
     else
     {
         var uiData = UIHelper.GetUIData(statelessCargo);
         if (!_model.UIComponent.Goods.ContainsKey(portWareIdentifier))
         {
             _model.UIComponent.Goods.Add(portWareIdentifier, uiData);
         }
         else
         {
             _model.UIComponent.Goods[portWareIdentifier] = uiData;
         }
     }
 }
예제 #4
0
        /// <summary>
        /// Checks to see if the ship has the cargo type and whether it has at least numToRemove
        /// Returns true is remove is succesful
        /// </summary>
        /// <param name="type"></param>
        /// <param name="numToRemove"></param>
        /// <returns></returns>
        public override CargoResult RemoveStatelessCargo(StatelessCargoTypes type, float numToRemove)
        {
            CargoResult result;

            if (!_model.StatelessCargo.ContainsKey(type))
            {
                result = CargoResult.CargoNotInHolds;
            }
            else if (_model.StatelessCargo[type].Quantity > numToRemove)//At least one item will remain
            {
                _model.StatelessCargo[type].Quantity -= numToRemove;
                _model.FilledHolds -= numToRemove * StatelessCargo.SpacePerObject(type);
                if (StatelessCargoPriceGetter != null)
                {
                    SetCargoPurchasePrice(PortHelper.GetPortWareIdentifier(type), StatelessCargoPriceGetter(new StatelessCargo(_model.StatelessCargo[type]), PriceType.PortPurchasing));
                    SetCargoSalePrice(PortHelper.GetPortWareIdentifier(type), StatelessCargoPriceGetter(new StatelessCargo(_model.StatelessCargo[type]), PriceType.PortSelling));
                }
                result = CargoResult.Success;
            }
            else if (_model.StatelessCargo[type].Quantity == numToRemove)//Last item will be removed
            {
                _model.StatelessCargo.Remove(type);

                _model.FilledHolds -= numToRemove * StatelessCargo.SpacePerObject(type);
                _model.Prices_ShipSaleToPort.Remove(PortHelper.GetPortWareIdentifier(type));
                result = CargoResult.Success;
            }
            result = CargoResult.CargoNotInHolds;

            if (result == CargoResult.Success)
            {
                PortWareIdentifier identifier;

                if (Enum.TryParse(type.ToString(), out identifier))
                {
                    UpdateGoodCounts(identifier, -numToRemove);
                }
            }

            return(result);
        }
예제 #5
0
        /// <summary>
        /// Checks to see if the ship has the cargo type and whether it has at least numToRemove
        /// Returns true is remove is succesful
        /// </summary>
        /// <param name="type"></param>
        /// <param name="numToRemove"></param>
        /// <returns></returns>
        public virtual CargoResult RemoveStatelessCargo(StatelessCargoTypes type, float numToRemove)
        {
            if (!_model.StatelessCargo.ContainsKey(type))
            {
                return(CargoResult.CargoNotInHolds);
            }
            else if (_model.StatelessCargo[type].Quantity > numToRemove)//At least one item will remain
            {
                _model.StatelessCargo[type].Quantity -= numToRemove;
                _model.FilledHolds -= numToRemove * StatelessCargo.SpacePerObject(type);

                return(CargoResult.Success);
            }
            else if (_model.StatelessCargo[type].Quantity == numToRemove)//Last item will be removed
            {
                _model.StatelessCargo.Remove(type);

                _model.FilledHolds -= numToRemove * StatelessCargo.SpacePerObject(type);
                return(CargoResult.Success);
            }
            return(CargoResult.CargoNotInHolds);
        }
        /// <summary>
        /// Attempts to add numToAdd objects of CargoType type. If suspendBoundsChecking, cargo is added without checking cargo space. Used for temporarily overflowing trades
        /// Returns true if succesful
        /// </summary>
        /// <param name="type"></param>
        /// <param name="numToAdd"></param>
        /// <returns></returns>
        public virtual CargoResult AddStatelessCargo(StatelessCargoTypes type, float numToAdd, bool suspendBoundsChecking)
        {
#if !ADMIN
            if (suspendBoundsChecking || CheckCargoSpace(type, numToAdd))//Check if there is enough space to add the cargo
            {
#endif
            if (_model.StatelessCargo.ContainsKey(type))//If there is already at least one of this item type on the ship
            {
                _model.StatelessCargo[type].Quantity += numToAdd;
            }
            else
            {
                _model.StatelessCargo.Add(type, new StatelessCargo(type, numToAdd));
            }
            _model.FilledHolds += numToAdd * StatelessCargo.SpacePerObject(type);
            return(CargoResult.Success);

#if !ADMIN
        }

        return(CargoResult.NotEnoughCargoSpace);
#endif
        }
예제 #7
0
 /// <summary>
 /// Checks if there is enough cargo space to add spaceOccupied + cargo space occupied by the specified cargo
 /// Increments spaceOccupied.
 /// returns true if there is enough space
 /// </summary>
 /// <param name="type"></param>
 /// <param name="quantity"></param>
 /// <param name="spaceOccupied">Adds the space occupied by the specified cargo</param>
 /// <returns></returns>
 public virtual bool CheckCargoSpace(StatelessCargoTypes type, float quantity, ref float spaceOccupied)
 {
     spaceOccupied += quantity * StatelessCargo.SpacePerObject(type);
     return(spaceOccupied <= _model.TotalHolds - _model.FilledHolds);
 }
예제 #8
0
 /// <summary>
 /// Callback given to CargoHandler to allow for the port to set the object's price
 /// </summary>
 /// <param name="c"></param>
 public float PriceGetter(StatelessCargo c, PriceType p)
 {
     return(666);
 }