예제 #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
파일: MarketPlace.cs 프로젝트: andy-uq/Echo
        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;
        }