示例#1
0
文件: Ship.cs 项目: andy-uq/Echo
        public Ship(Agent pilot)
            : this()
        {
            if (pilot == null)
                throw new ArgumentNullException("pilot");

            Owner = pilot.Employer;
            Pilot = pilot;
        }
示例#2
0
        public IItem Buy(Auction auction, uint quantity, Agent agent)
        {
            if (agent.Location.StarCluster != this.starCluster)
                throw new InvalidOperationException("The agent needs to be within the same star cluster as this market place");

            if (this.auctions.Contains(auction) == false)
                throw new ItemNotFoundException("Auction", auction);

            if (quantity % auction.BlockSize != 0)
                throw new InvalidOperationException("Need to purchase this item in {0:n0} increments.".Expand(auction.BlockSize));

            if (quantity > auction.Quantity)
                quantity = auction.Quantity;

            ulong totalPrice = quantity*auction.PricePerUnit;
            if (totalPrice > agent.Employer.Bank)
            {
                throw new ArgumentException("This corporation cannot afford to make this purchase");
            }

            IItem auctionItem = auction.Item;

            agent.Employer.Bank -= totalPrice;
            auctionItem.Owner.Bank += totalPrice;

            if (auction.Quantity == quantity)
            {
                this.auctions.Remove(auction);
            }
            else
            {
                auctionItem = auctionItem.Unstack(quantity);
            }

            auction.Owner.AuctionSold(auction);
            auctionItem.Owner = agent.Employer;

            Universe.EventPump.RaiseEvent(agent.Employer, EventType.AuctionBuy, "{0} bought {1} from {2}", agent.Name, auctionItem, auction.Owner);
            Universe.EventPump.RaiseEvent(auction.Owner, EventType.AuctionSold, "{0} bought {1}", agent.Name, auctionItem);

            return auctionItem;
        }
示例#3
0
文件: Structure.cs 项目: andy-uq/Echo
        public bool Undock(Ship ship, Agent pilot)
        {
            if (this.ships.Contains(ship) == false)
                throw new InvalidOperationException("This ship is not docked with this station");

            if (this.personnel.Contains(pilot) == false)
                throw new InvalidOperationException("This pilot is not present in this station");

            this.ships.Remove(ship);
            this.personnel.Remove(pilot);

            ship.Pilot = pilot;
            ship.Location = Location;

            if (SolarSystem.Objects.Contains(ship) == false)
                SolarSystem.EnterSystem(ship, LocalCoordinates);

            return true;
        }