Beispiel #1
0
        /// <summary>
        /// Returns the number of holds each cargo object occupies
        /// </summary>
        public static float SpacePerObject(StatefulCargoTypes type)
        {
            switch (type)
            {
            case StatefulCargoTypes.LaserTurret:
                return(2f);

            case StatefulCargoTypes.Laser:
                return(.5f);

            case StatefulCargoTypes.Barge:
                return(25000f);

            case StatefulCargoTypes.Reaper:
                return(15000f);

            case StatefulCargoTypes.BattleCruiser:
                return(20000f);

            case StatefulCargoTypes.Penguin:
                return(12000f);

            case StatefulCargoTypes.Module:
                return(4f);

            case StatefulCargoTypes.DefensiveMine:
                return(2f);

            default:
                Console.WriteLine("SpacePerObject not implemented for this cargo of type " + type.ToString());
                return(1);
            }
        }
Beispiel #2
0
        public static bool GetCargoType(PortWareIdentifier wareType, out StatefulCargoTypes cargoType)
        {
            bool success = Enum.TryParse(wareType.ToString(), out cargoType);

            if (!success)
            {
                cargoType = StatefulCargoTypes.Null;
            }

            return(success);
        }
 protected virtual void _decrementStatefulCargoCount(StatefulCargoTypes t)
 {
     if (_model.StatefulCargoCounts.ContainsKey(t))
     {
         _model.StatefulCargoCounts[t]--;
         if (_model.StatefulCargoCounts[t] == 0)
         {
             _model.StatefulCargoCounts.Remove(t);//Might be excessive to remove it
         }
     }
 }
 protected virtual void _incrementStatefulCargoCount(StatefulCargoTypes t)
 {
     if (_model.StatefulCargoCounts.ContainsKey(t))
     {
         _model.StatefulCargoCounts[t]++;
     }
     else
     {
         _model.StatefulCargoCounts.Add(t, 1);
     }
 }
Beispiel #5
0
        /// <summary>
        /// Returns an object of with matching type, if any exists in the CargoHandler, Null otherwise
        /// Does not remove the object.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public virtual StatefulCargo GetAnyStatefulCargo(StatefulCargoTypes type)
        {
            var s = _model.StatefulCargo.FirstOrDefault(e => e.Value.CargoType == type);

            if (s.Value != null)//This might crash?
            {
                return(s.Value);
            }
            else
            {
                return(null);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Removes the stateful cargo with the given ID if it exists
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual StatefulCargo RemoveStatefulCargo(StatefulCargoTypes type)
        {
            var s = _model.StatefulCargo.First(e => e.Value.CargoType == type);

            if (s.Value != null)//This might crash?
            {
                _model.StatefulCargo.Remove(s.Key);
                _model.FilledHolds -= Core.Models.StatefulCargo.SpacePerObject(type);
                _decrementStatefulCargoCount(type);
                _model.StatefulCargo.Remove(s.Key);
                return(s.Value);
            }
            else
            {
                return(null);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Removes the stateful cargo with the given ID if it exists
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public override StatefulCargo RemoveStatefulCargo(StatefulCargoTypes type)
        {
            var s = _model.StatefulCargo.First(e => e.Value.CargoType == type);

            if (s.Value != null)//This might crash?
            {
                _model.StatefulCargo.Remove(s.Key);
                _model.FilledHolds -= Core.Models.StatefulCargo.SpacePerObject(type);
                _decrementStatefulCargoCount(type);
                if (StatefulCargoPriceGetter != null)
                {
                    SetCargoPurchasePrice(PortHelper.GetPortWareIdentifier(type), StatefulCargoPriceGetter(new StatefulCargo_RO(s.Value), GetCargoAmount(s.Value.CargoType), PriceType.PortPurchasing));
                    SetCargoSalePrice(PortHelper.GetPortWareIdentifier(type), StatefulCargoPriceGetter(new StatefulCargo_RO(s.Value), GetCargoAmount(s.Value.CargoType), PriceType.PortSelling));
                }
                return(s.Value);
            }
            else
            {
                return(null);
            }
        }
Beispiel #8
0
        /// <summary>
        /// TODO: consider hardcoding values, or preloading a dictionary, to avoid parsing strings?
        /// </summary>
        /// <param name="cargoType"></param>
        /// <returns></returns>
        public static PortWareIdentifier GetPortWareIdentifier(StatefulCargoTypes cargoType)
        {
            PortWareIdentifier identifier;

            return(Enum.TryParse(cargoType.ToString(), out identifier) ? identifier : PortWareIdentifier.Null);
        }
Beispiel #9
0
 public int GetCargoAmount(StatefulCargoTypes type)
 {
     return(_model.StatefulCargoCounts[type]);
 }
Beispiel #10
0
        public virtual bool CheckCargoSpace(StatefulCargoTypes type, int quantity)
        {
            float spaceOccupied = 0;

            return(CheckCargoSpace(type, quantity, ref spaceOccupied));
        }
Beispiel #11
0
 public virtual bool CheckCargoSpace(StatefulCargoTypes type, int quantity, ref float spaceOccupied)
 {
     spaceOccupied += Core.Models.StatefulCargo.SpacePerObject(type) * quantity;
     return(spaceOccupied <= _model.TotalHolds - _model.FilledHolds);
 }
Beispiel #12
0
 /// <summary>
 /// Returns true if the specified quantity of StatefulCargo with matching type exists.
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public virtual bool IsCargoInHolds(StatefulCargoTypes type, int quantity)
 {
     return(_model.StatefulCargo.Select(c => { return c.Value.CargoType == type; }).Count() >= quantity);
 }
        public float GetPrice(StatefulCargoTypes cargoType, int quantity, PortTradeDirection direction)
        {
            var identifier = PortHelper.GetPortWareIdentifier(cargoType);

            return(GetPrice(identifier, quantity, direction));
        }
Beispiel #14
0
 public StatefulCargo(int ID, StatefulCargoTypes type)
 {
     IsForSale = true;
     _model.Id = ID;
     CargoType = type;
 }
Beispiel #15
0
 public override bool CheckCargoSpace(StatefulCargoTypes type, int quantity)
 {
     return(true);
 }
Beispiel #16
0
 /// <summary>
 /// Set cargoID to null if transaction applies to first cargo found in IHasCargo object
 /// </summary>
 /// <param name="objectID"></param>
 /// <param name="cargoType"></param>
 /// <param name="cargoID"></param>
 /// <param name="transferToNextTransaction">If true, and this transaction occurs as part of a SequentialTransaction, and the next transaction is of type AddStatefulCargo, then the cargo object removed by this transaction will serve as the Cargo added in the subsequent AddStatefulCargoTransaction</param>
 public TransactionRemoveStatefulCargo(IHasCargo donor, StatefulCargoTypes cargoType, int?cargoID, bool transferToNextTransaction = false) : base(donor, CargoTransactionTypes.RemoveStatefulCargo)
 {
     CargoType = cargoType;
     CargoID   = cargoID;
     TransferToNextTransaction = transferToNextTransaction;
 }