Esempio n. 1
0
File: Trade.cs Progetto: Corne/VOC
        public Trade(MaterialType[] offer, MaterialType[] request, IPlayer owner)
        {
            if (offer == null)
                throw new ArgumentNullException(nameof(offer));
            if (request == null)
                throw new ArgumentNullException(nameof(request));
            if (owner == null)
                throw new ArgumentNullException(nameof(owner));

            if (!offer.Any() && !request.Any())
                throw new ArgumentException("You can't create a trade without at least an offer or a request");
            if (offer.Any(m => INVALID_MATERIALS.Contains(m)) || request.Any(m => INVALID_MATERIALS.Contains(m)))
                throw new ArgumentException($"Can't create a trade with invalid material resources ({string.Join(", ", INVALID_MATERIALS)})");
            if (!owner.HasResources(offer))
                throw new InvalidOperationException("Can't offer materials if you don't have them");

            Id = Guid.NewGuid();
            Offer = offer;
            Request = request;
            Owner = owner;
            State = TradeState.Open;
        }