Beispiel #1
0
        public override Settlement List(MarketPlace marketPlace)
        {
            Ensure.That(marketPlace).IsNotNull();
            Ensure.That(marketPlace.StarCluster.Equals(Item.Location.GetStarCluster()));

            var settlement = new Settlement();

            foreach (var sellOrder in marketPlace.SellOrders.For(Item).OrderBy(x => x.PricePerUnit))
            {
                if (OutOfRange(sellOrder) || sellOrder.OutOfRange(this))
                    continue;

                if (sellOrder.PricePerUnit > PricePerUnit)
                    continue;

                if (sellOrder.BlockSize > Quantity)
                    continue;

                if (BuyFrom(sellOrder, settlement))
                    return marketPlace.Settle(settlement);
            }

            marketPlace.Add(this);
            return marketPlace.Settle(settlement);
        }
Beispiel #2
0
            public static MarketPlaceState Save(MarketPlace marketPlace)
            {
                Ensure.That(marketPlace).IsNotNull();

                return new MarketPlaceState
                {
                    AuctionLength = marketPlace.AuctionLength,
                    SettlementDelay = marketPlace.SettlementDelay,
                    Settlements = marketPlace.Settlements.Save(),
                    Auctions = marketPlace.Auctions.Select(_ => _.ToObjectReference()),
                };
            }
Beispiel #3
0
            public static ObjectBuilder<MarketPlace> Build(MarketPlaceState state, StarCluster starCluster)
            {
                var marketPlace = new MarketPlace
                {
                    AuctionLength = state.AuctionLength,
                    SettlementDelay = state.SettlementDelay,
                    StarCluster = starCluster,
                };

                var builder = new ObjectBuilder<MarketPlace>(marketPlace);

                builder
                    .Dependents(state.Settlements)
                    .Build(Settlement.Builder.Build)
                    .Resolve((resolver, target, settlement) => target._settlements.Add(settlement));

                builder
                    .Resolve((resolver, target) => target._auctions.AddRange(state.Auctions.Select(resolver.Get<Auction>)));

                return builder;
            }
Beispiel #4
0
 public abstract Settlement List(MarketPlace marketPlace);
Beispiel #5
0
        public void SetUp()
        {
            _marketPlace = new MarketPlace();
            _sc = new StarCluster { MarketPlace = _marketPlace };
            _sol = new SolarSystem { Position = new Position(_sc, Vector.Zero) };
            _tradingStation = new TradingStation { Position = new Position(_sol, Vector.Zero) };

            _marketPlace.StarCluster = _sc;
            _marketPlace.ObjectType.ShouldBe(ObjectType.MarketPlace);
        }