public virtual CargoResult AddStatefulCargo(StatefulCargo c, bool suspendBoundsChecking)
        {
#if !ADMIN
            if (suspendBoundsChecking || CheckCargoSpace(c.CargoType, 1))
            {
#endif
            if (!_model.StatefulCargo.ContainsKey(c.Id))
            {
                _model.StatefulCargo.Add(c.Id, c);
                _model.FilledHolds += StatefulCargo.SpacePerObject(c.CargoType);
                _incrementStatefulCargoCount(c.CargoType);
                return(CargoResult.Success);
            }
            else
            {
                return(CargoResult.StatefulCargoIDAlreadyAdded);
            }
#if !ADMIN
        }

        else
        {
            return(CargoResult.NotEnoughCargoSpace);
        }
#endif
        }
示例#2
0
        public static StatefulCargo InstantiateStatefulCargo(StatefulCargoData data)
        {
            StatefulCargo c = null;

            switch (data.CargoType)
            {
            case StatefulCargoTypes.LaserTurret:
            {
                c = new CargoLaserTurret(data.Id, ((CargoLaserTurretData)data).Health, new LaserWeaponStats());
                break;
            }

            case StatefulCargoTypes.DefensiveMine:
            {
                c = new StatefulCargo(data.Id, StatefulCargoTypes.DefensiveMine);
                break;
            }

            case StatefulCargoTypes.Module:
            {
                c = InstantiateModule((CargoModuleData)data);
                break;
            }

            default:
                Console.WriteLine("StatefulCargoType " + data.CargoType.ToString() + " not implemented in ReadNewShip.");
                break;
            }

            return(c);
        }
示例#3
0
        public override CargoResult Process()
        {
            if (CargoID != null)
            {
                RemovedCargo = _cargoHandler.RemoveStatefulCargo((int)CargoID);
            }
            else
            {
                RemovedCargo = _cargoHandler.RemoveStatefulCargo(CargoType);
            }
            if (RemovedCargo != null)
            {
                ResultCompletionSource.SetResult(CargoResult.Success);
            }
            else
            {
                ResultCompletionSource.SetResult(CargoResult.CargoNotInHolds);
            }


            if (!IsInSequence && ResultTask.Result == CargoResult.Success)
            {
                CloseTransaction();
            }
            return(ResultTask.Result);
        }
示例#4
0
        public override CargoResult AddStatefulCargo(StatefulCargo c, bool suspendBoundsChecking)
        {
            _model.StatefulCargo.Add(c.Id, c);
            _model.FilledHolds += StatefulCargo.SpacePerObject(c.CargoType);
            _incrementStatefulCargoCount(c.CargoType);
            if (StatefulCargoPriceGetter != null)
            {
                SetCargoPurchasePrice(PortHelper.GetPortWareIdentifier(c.CargoType), StatefulCargoPriceGetter(new StatefulCargo_RO(c), GetCargoAmount(c.CargoType), PriceType.PortPurchasing));
                SetCargoSalePrice(PortHelper.GetPortWareIdentifier(c.CargoType), StatefulCargoPriceGetter(new StatefulCargo_RO(c), GetCargoAmount(c.CargoType), PriceType.PortSelling));
            }

            PortWareIdentifier identifier;

            if (c.CargoType == StatefulCargoTypes.Module)
            {
                _model.UIComponent.Modules.Add(c.Id, UIHelper.GetUIData((Module)c));
            }
            else if (Enum.TryParse(c.CargoType.ToString(), out identifier))
            {
                UpdateGoodCounts(identifier, +1);
                UpdateUIStatLists(identifier, c, true);
            }

            return(CargoResult.Success);
        }
示例#5
0
        /// <summary>
        /// For structures which originate as StatefulCargo, as they already have a GalaxyID
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public static IStructure CreateStructure(StatefulCargo c, float xPos, float yPos, Player owner, CommandCenter commandCenter, int currentAreaID, IPlayerLocator pl)
        {
            IStructure s;

            switch (c.CargoType)
            {
            case (StatefulCargoTypes.LaserTurret):
            {
                TurretTypes t = owner.GetArea().AreaType == AreaTypes.Planet ? TurretTypes.Planet : TurretTypes.Space;
                s = new Turret(c.Id, xPos, yPos, owner.Id, currentAreaID, t, pl);
                break;
            }

            case (StatefulCargoTypes.DefensiveMine):
            {
                s = new DefensiveMine(xPos, yPos, c.Id, owner.Id, currentAreaID, pl);
                break;
            }

            default:
                throw new Exception("CreateStructure not implemented for structure type " + c.CargoType.ToString());
            }
            _galaxyRegistrationManager.RegisterObject(s);

            return(s);
        }
示例#6
0
 public virtual bool CheckCargoSpace(Dictionary <StatefulCargoTypes, float> typesAndQuantities, ref float spaceOccupied)
 {
     foreach (var t in typesAndQuantities)
     {
         spaceOccupied += StatefulCargo.SpacePerObject(t.Key) * (int)t.Value;
     }
     return(spaceOccupied <= _model.TotalHolds - _model.FilledHolds);
 }
示例#7
0
        public virtual bool CheckCargoSpace(IEnumerable <StatefulCargo> statefulCargo, ref float spaceOccupied)
        {
            foreach (var s in statefulCargo)
            {
                spaceOccupied += StatefulCargo.SpacePerObject(s.CargoType);
            }

            return(spaceOccupied <= _model.TotalHolds - _model.FilledHolds);
        }
示例#8
0
        /// <summary>
        /// Leave cargoObject null to chain to a previous transaction in a sequence.
        /// </summary>
        /// <param name="recipient"></param>
        /// <param name="cargoObject"></param>
        /// <param name="suspendBoundsChecking"></param>
        public TransactionAddStatefulCargo(IHasCargo recipient, StatefulCargo cargoObject, bool suspendBoundsChecking) : base(recipient, CargoTransactionTypes.AddStatefulCargo)
        {
            if (cargoObject != null)
            {
                CargoType = cargoObject.CargoType;
            }


            CargoObject = cargoObject;
        }
示例#9
0
 /// <summary>
 /// Removes the stateful cargo with the given ID if it exists
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public virtual StatefulCargo RemoveStatefulCargo(int id)
 {
     if (_model.StatefulCargo.ContainsKey(id))
     {
         StatefulCargo s = _model.StatefulCargo[id];
         _model.FilledHolds -= Core.Models.StatefulCargo.SpacePerObject(s.CargoType);
         _decrementStatefulCargoCount(s.CargoType);
         _model.StatefulCargo.Remove(id);
         return(s);
     }
     else
     {
         return(null);
     }
 }
示例#10
0
        /// <summary>
        /// For structures which originate as StatefulCargo, as they already have a GalaxyID
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public static IStructure CreateStructure(StatefulCargo c, float xPos, float yPos, Player owner, CommandCenter commandCenter, int currentAreaID, IPlayerLocator pl)
        {
            IStructure s;

            switch (c.Type)
            {
            case (StatefulCargoTypes.LaserTurret):
                s = new Turret(_localIDManager.PopFreeID(), xPos, yPos, owner, commandCenter, currentAreaID, pl);
                break;

            default:
                throw new Exception("CreateStructure not implemented for structure type " + c.Type.ToString());
            }
            _galaxyRegistrationManager.RegisterObject(s);

            return(s);
        }
示例#11
0
        /// <summary>
        /// Notifies a player, if online, of a module added to his ship
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="transaction"></param>
        public void NotifyCargoAdded(object sender, ITransactionAddStatefulCargo transaction)
        {
            if (transaction.CargoHolder is IShip)
            {
                IShip  s = transaction.CargoHolder as IShip;
                Player p = s.GetPlayer();
                if (p.IsOnline)
                {
                    StatefulCargo         m    = transaction.CargoObject;
                    MessageAddCargoToShip data = new MessageAddCargoToShip();
                    data.ShipID = s.Id;
                    data.StatefulCargoData.Add(m.GetNetworkObject());

                    p.SendMessage(new NetworkMessageContainer(data, MessageTypes.AddCargoToShip));
                }
            }
        }
示例#12
0
 /// <summary>
 /// Adds if addOrRemove is true, removes otherwise
 /// </summary>
 /// <param name="statefulCargo"></param>
 /// <param name="addOrRemove"></param>
 void UpdateUIStatLists(PortWareIdentifier portGoodIdentifier, StatefulCargo statefulCargo, bool addOrRemove)
 {
     if (addOrRemove)
     {
         if (!_model.UIComponent.Goods.ContainsKey(portGoodIdentifier))
         {
             _model.UIComponent.Goods.Add(portGoodIdentifier, UIHelper.GetUIData(statefulCargo));
         }
     }
     else
     {
         if (_model.UIComponent.Goods.ContainsKey(portGoodIdentifier))
         {
             _model.UIComponent.Goods.Remove(portGoodIdentifier);
         }
     }
 }
示例#13
0
        /// <summary>
        /// Removes the stateful cargo with the given ID if it exists
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public override StatefulCargo RemoveStatefulCargo(int id)
        {
            if (_model.StatefulCargo.ContainsKey(id))
            {
                StatefulCargo s = _model.StatefulCargo[id];
                _model.FilledHolds -= Core.Models.StatefulCargo.SpacePerObject(s.CargoType);
                _decrementStatefulCargoCount(s.CargoType);
                if (StatefulCargoPriceGetter != null)
                {
                    SetCargoPurchasePrice(PortHelper.GetPortWareIdentifier(s.CargoType), StatefulCargoPriceGetter(new StatefulCargo_RO(s), GetCargoAmount(s.CargoType), PriceType.PortPurchasing));
                    SetCargoSalePrice(PortHelper.GetPortWareIdentifier(s.CargoType), StatefulCargoPriceGetter(new StatefulCargo_RO(s), GetCargoAmount(s.CargoType), PriceType.PortSelling));
                }


                PortWareIdentifier identifier = PortHelper.GetPortWareIdentifier(s.CargoType);

                if (s.CargoType == StatefulCargoTypes.Module)
                {
                    _model.UIComponent.Modules.Remove(id);
                }
                else if (identifier != PortWareIdentifier.Null)
                {
                    UpdateGoodCounts(identifier, -1);
                    UpdateUIStatLists(identifier, s, false);

                    if (!_model.PortGoodCounts.ContainsKey(identifier))//UpdateGoodCounts will have removed the key if no more goods of this type are in the inventory
                    {
                        _model.Prices_ShipSaleToPort.Remove(identifier);
                    }
                }
                return(s);
            }
            else
            {
                return(null);
            }
        }
示例#14
0
 public virtual bool IsCargoInHolds(StatefulCargo c)
 {
     return(_model.StatefulCargo.ContainsKey(c.Id));
 }
示例#15
0
 /// <summary>
 /// DON'T USE THIS EVER FOR ANYTHING UNDER ANY CIRCUMSTANCES
 /// </summary>
 /// <returns></returns>
 public void CHEATADDCARGO(StatefulCargo c)
 {
     //Adds without checking or changing capacity. Cheap way to f**k around with "infinite" holds. Will remove eventually.
     _model.StatefulCargo.Add(c.Id, c);
 }
示例#16
0
        async Task FillPorts(GalaxyManager galaxyManager, LocalIDManager galaxyIDManager, CargoSynchronizer cargoSynchronizer)
        {
            var ports = galaxyManager.GetAllAreas().Where(a => a.AreaType == AreaTypes.Port);
            CargoTransaction lastTransaction = null;

            foreach (var p in ports)
            {
                var port = p as Port;
                foreach (var s in _config.PortConfig.StatefulCargoCounts)
                {
                    StatefulCargo sc;
                    for (int i = 0; i < s.Value; i++)//Yes, this loop is lazy, but it's 11:30PM...
                    {
                        //TODO: make a StatefulCargoFactory
                        switch (s.Key)
                        {
                        case StatefulCargoTypes.Barge:
                        {
                            sc = new CargoShip(galaxyIDManager.PopFreeID(), 666, ShipStats[ShipTypes.Barge]);
                            break;
                        }

                        case StatefulCargoTypes.BattleCruiser:
                        {
                            sc = new CargoShip(galaxyIDManager.PopFreeID(), 666, ShipStats[ShipTypes.BattleCruiser]);
                            break;
                        }

                        case StatefulCargoTypes.Penguin:
                        {
                            sc = new CargoShip(galaxyIDManager.PopFreeID(), 666, ShipStats[ShipTypes.Penguin]);
                            break;
                        }

                        case StatefulCargoTypes.Reaper:
                        {
                            sc = new CargoShip(galaxyIDManager.PopFreeID(), 666, ShipStats[ShipTypes.Reaper]);
                            break;
                        }

                        case StatefulCargoTypes.LaserTurret:
                        {
                            sc = new CargoLaserTurret(galaxyIDManager.PopFreeID(), 666, new LaserWeaponStats());
                            break;
                        }

                        default:
                        {
                            sc = new StatefulCargo(galaxyIDManager.PopFreeID(), s.Key);
                            break;
                        }
                        }


                        CargoTransaction tr = new TransactionAddStatefulCargo(port, sc, true);
                        cargoSynchronizer.RequestTransaction(tr);
                        lastTransaction = tr;
                    }
                }

                foreach (var s in _config.PortConfig.StatelessCargoCounts)
                {
                    var tr = new TransactionAddStatelessCargo(port, s.Key, s.Value, true);
                    cargoSynchronizer.RequestTransaction(tr);
                    lastTransaction = tr;
                }

                foreach (var s in _config.PortConfig.ModuleCounts)
                {
                    Module m  = ModuleFactory.CreateModule(s.Key, galaxyIDManager.PopFreeID(), 1);
                    var    tr = new TransactionAddStatefulCargo(port, m, true);
                    cargoSynchronizer.RequestTransaction(tr);
                    lastTransaction = tr;
                }
            }
            if (lastTransaction != null)
            {
                await lastTransaction.ResultTask;
            }
        }
示例#17
0
        /// <summary>
        /// Set isPlayerShip if this is the client's ship, false otherwise.
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="world"></param>
        /// <param name="clientShipManager"></param>
        /// <param name="isPlayerShip"></param>
        /// <returns></returns>
        public static Ship InstantiateShip(ShipData data, World world, ClientShipManager clientShipManager, bool isPlayerShip)
        {
            ShipStats stats = new ShipStats();

            if (data.ShipStats != null)
            {
                stats = new ShipStats(data.ShipStats);
            }

            Vector2 position = new Vector2(data.PosX, data.PosY);
            Vector2 velocity = new Vector2(data.VelX, data.VelY);


            Ship newShip = null;

            if (!isPlayerShip)
            {
                newShip = clientShipManager.CreateShip(world, data.IsNPC, position, data.Id, data.Rotation, velocity, data.PlayerName, stats, data.WeaponTypes, data.TeamIDs);
            }
            else
            {
                if (data.PlayerID == null)
                {
                    throw new NotImplementedException("Null playerID not yet implemented on the client.");
                }

                newShip = clientShipManager.CreatePlayerShip(world, position, data.Id, data.Rotation, velocity, data.PlayerName, stats, data.WeaponTypes, data.TeamIDs);
            }


            newShip.CurrentHealth          = (int)data.CurrentHealth;
            newShip.Shields.CurrentShields = (int)data.CurrentShields;

            #region Cargo
            if (data.Cargo != null)
            {
                foreach (var sc in data.Cargo.StatelessCargo)
                {
                    newShip.Cargo.AddStatelessCargo(sc.CargoType, sc.Quantity, true);
                }

                foreach (var sc in data.Cargo.StatefulCargo)
                {
                    StatefulCargo c = InstantiateStatefulCargo(sc);
                    switch (c.CargoType)
                    {
                    case StatefulCargoTypes.Module:
                    {
                        newShip.AddModule((Module)c);
                        newShip.Cargo.AddStatefulCargo(c, true);
                        break;
                    }

                    default:
                    {
                        newShip.Cargo.AddStatefulCargo(c, true);
                        break;
                    }
                    }
                }


                newShip.RecalculateModuleBonuses();
            }
            #endregion

            newShip.MissileLauncher?.SetMissileType(data.SelectedMissileType);

            newShip.Pilot.IsAlive = !data.IsDead;

            return(newShip);
        }