Ejemplo n.º 1
0
        PurchaseResult GenerateSaleTransactionSequence(IShip sellingShip, Port purchasingPort, HashSet <int> statefulCargoIDs, ref List <CargoTransaction> transactionsToSchedule, ref float totalPrice)
        {
            var cargoToSell = sellingShip.Cargo.GetStatefulCargo(statefulCargoIDs.ToList());

            if (cargoToSell.Count != statefulCargoIDs.Count)
            {
                return(PurchaseResult.CargoNotInHolds);
            }

            totalPrice += purchasingPort.Cargo.GetPrice(cargoToSell, PortTradeDirection.ShipSaleToPort);


            foreach (var i in statefulCargoIDs)
            {
                var fromShip = new TransactionRemoveStatefulCargo(sellingShip, StatefulCargoTypes.Null, i, true);
                var toPort   = new TransactionAddStatefulCargo(purchasingPort, null, true);

                transactionsToSchedule.Add(fromShip);
                transactionsToSchedule.Add(toPort);
            }

            return(PurchaseResult.Success);
        }
Ejemplo n.º 2
0
        public IShip KillShip(IShip s, ICanFire killingObject)
        {
            if (s.IsDead)
            {
                ConsoleManager.WriteLine("Killing a ship which was already dead.", ConsoleMessageType.Warning);
                return(s);
            }


            s.IsDead           = true;
            s.KillTimeStamp    = TimeKeeper.MsSinceInitialization;
            s.RespawnTimeDelay = 3000;//TODO: This will be a problem later, if a IShip warps into a new system where a dead IShip is waiting to respawn, the warping IShip will see a live ship. Needs to be fully implemented.
            s.CurrentHealth    = 0;

            if (s.GetPlayer().IsTrading)
            {
                _tradeTerminator.TerminateTrade(s.Id, true);
            }

            var currentArea = s.GetArea();

            if (currentArea.NumOnlinePlayers > 0)
            {
                MessageRemoveKillRevive msgData = new MessageRemoveKillRevive();
                msgData.ActionType = ActionType.Kill;
                msgData.ObjectType = RemovableObjectTypes.Ship;
                msgData.ObjectIDs.Add(s.Id);

                currentArea.BroadcastMessage(new NetworkMessageContainer(msgData, MessageTypes.RemoveKillRevive));

                // Send chat messages
                if (killingObject is IShip)
                {
                    ((IShip)killingObject).GetPlayer().PlayersKilled++;
                    var killingPlayer = ((IShip)killingObject).GetPlayer();

                    killingPlayer.PlayersKilled++;

                    var killText = string.Format("{0} was shot down by {1}!", s.GetPlayer().Username, killingPlayer.Username);

                    _chatManager.BroadcastSimpleChat(s.GetArea(), "", killText, ChatTypes.None);
                }
                else if (killingObject is Turret)
                {
                    _playerLocator.GetPlayerAsync(((Turret)killingObject).OwnerID).Result.PlayersKilled++;

                    var killedPlayer = s.GetPlayer();

                    var defensesOwner = _playerLocator.GetPlayerAsync(((Turret)killingObject).OwnerID).Result.Username;

                    var killText = string.Format("{0} was shot down by defenses of {1}!", killedPlayer.Username, defensesOwner);

                    _chatManager.BroadcastSimpleChat(s.GetArea(), "", killText, ChatTypes.None);
                }
            }

            #region Modules
            //For now, just make the ship drop one mod to space. Later we'll figure out how many to destroy/keep with the ship
            var moduleToRemove = s.Cargo.GetAnyStatefulCargo(StatefulCargoTypes.Module);
            if (moduleToRemove != null)
            {
                var ct = new TransactionRemoveStatefulCargo(s, StatefulCargoTypes.Module, moduleToRemove.Id);
                ct.OnCompletion += s.CargoRemoved;
                ct.OnCompletion += _messageManager.NotifyCargoRemoved;
                ct.OnCompletion += _addCargoToArea;


                var mod = moduleToRemove as Module;
                mod.PosX       = s.PosX;
                mod.PosY       = s.PosY;
                mod.Rotation   = s.Rotation;
                mod.NextAreaID = (int)s.CurrentAreaId;

                _cargoSynchronizer.RequestTransaction(ct);
            }


            #endregion


            s.CurrentHealth = s.ShipStats.MaxHealth;
            //s.IsDead = false;
            float tempx = 0;
            float tempy = 0;
            SpatialOperations.GetRandomPointInRadius(ref tempx, ref tempy, 10, 20);

            s.PosX = tempx;
            s.PosY = tempy;


            return(s);
        }