Example #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);
        }
Example #2
0
        public static bool GetCargoType(PortWareIdentifier wareType, out StatelessCargoTypes cargoType)
        {
            bool success = Enum.TryParse(wareType.ToString(), out cargoType);

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

            return(success);
        }
Example #3
0
 /// <summary>
 /// Returns the current number of StatelessCargo for the given type
 /// </summary>
 /// <param name="type"></param>
 /// <param name="amount"></param>
 /// <returns></returns>
 public float GetCargoAmount(StatelessCargoTypes type)
 {
     if (_model.StatelessCargo.ContainsKey(type))
     {
         return(_model.StatelessCargo[type].Quantity);
     }
     else
     {
         return(0);
     }
 }
Example #4
0
 /// <summary>
 /// DON'T USE THIS EVER FOR ANYTHING UNDER ANY CIRCUMSTANCES
 /// </summary>
 /// <returns></returns>
 public void CHEATADDCARGO(StatelessCargoTypes type, int amount)
 {
     //Adds without checking or changing capacity. Cheap way to f**k around with "infinite" holds. Will remove eventually.
     if (_model.StatelessCargo.ContainsKey(type))
     {
         _model.StatelessCargo[type].Quantity += amount;
     }
     else
     {
         _model.StatelessCargo.Add(type, new StatelessCargo(type, amount));
     }
 }
Example #5
0
        public MissileLauncherStats(ProjectileTypes missileType)
        {
            Weight = 0;

            if (!Validation.IsMissileType(missileType))
            {
                throw new InvalidOperationException("Non missile type passed to MissileLauncherStats constructor");
            }

            MissileType    = (StatelessCargoTypes)Enum.Parse(typeof(StatelessCargoTypes), missileType.ToString());
            ProjectileType = missileType;
            NumProjectiles = 1;
            FirePeriod     = 100f;
            EnergyCost     = 100f;
            WeaponType     = WeaponTypes.MissileLauncher;
        }
Example #6
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);
        }
Example #7
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
        }
Example #9
0
        /// <summary>
        /// Returns the number of holds each cargo object occupies
        /// Needs to be synced client side
        /// </summary>
        public static float SpacePerObject(StatelessCargoTypes type)
        {
            switch (type)
            {
            case StatelessCargoTypes.Biodome:
                return(50);


            case StatelessCargoTypes.AmbassadorMissile:
                return(1f);

            case StatelessCargoTypes.HellHoundMissile:
                return(1f);

            case StatelessCargoTypes.MissileType1:
                return(1f);

            case StatelessCargoTypes.MissileType2:
                return(1f);

            case StatelessCargoTypes.MissileType3:
                return(1f);

            case StatelessCargoTypes.MissileType4:
                return(1f);

            case StatelessCargoTypes.Hydrocarbons:
                return(.1f);

            case StatelessCargoTypes.Organics:
                return(.1f);

            default:
                Console.WriteLine("SpacePerObject not implemented for this cargo of type " + type.ToString());
                return(1);
            }
        }
Example #10
0
        public virtual bool CheckCargoSpace(StatelessCargoTypes type, float quantity)
        {
            float spaceOccupied = 0;

            return(CheckCargoSpace(type, quantity, ref spaceOccupied));
        }
Example #11
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);
 }
Example #12
0
 public virtual bool IsCargoInHolds(StatelessCargoTypes type, float quantity)
 {
     return(_model.StatelessCargo.ContainsKey(type) || _model.StatelessCargo[type].Quantity >= quantity);
 }
        public float GetPrice(StatelessCargoTypes cargoType, float quantity, PortTradeDirection direction)
        {
            var identifier = PortHelper.GetPortWareIdentifier(cargoType);

            return(GetPrice(identifier, quantity, direction));
        }
Example #14
0
 public TransactionRemoveStatelessCargo(IHasCargo donor, StatelessCargoTypes cargoType, float amount) : base(donor, CargoTransactionTypes.RemoveStatelessCargo)
 {
     CargoType = cargoType;
     Quantity  = amount;
 }
Example #15
0
 public virtual bool CheckCargoSpace(StatelessCargoTypes type, int numToAdd)
 {
     return(true);
 }
Example #16
0
 public StatelessCargo(StatelessCargo c)
 {
     Type     = c.Type;
     Quantity = c.Quantity;
 }
Example #17
0
 public StatelessCargo(StatelessCargoTypes type, float quantity)
 {
     Type     = type;
     Quantity = quantity;
 }
Example #18
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(StatelessCargoTypes cargoType)
        {
            PortWareIdentifier identifier;

            return(Enum.TryParse(cargoType.ToString(), out identifier) ? identifier : PortWareIdentifier.Null);
        }
Example #19
0
 public TransactionAddStatelessCargo(IHasCargo recipient, StatelessCargoTypes cargoType, float amount, bool suspendBoundsChecking) : base(recipient, CargoTransactionTypes.AddStatelessCargo)
 {
     CargoType = cargoType;
     Quantity  = amount;
 }