示例#1
0
        public void RequestTrade(Player playerA, ITradeable itemA, Player playerB, ITradeable itemB)
        {
            if (playerA == playerB)
            {
                return;
            }

            if (playerB == null)
            {
                Money money = itemA as Money;
                Field field = itemB as Field;
                if (money != null && field != null && money.GetAmount() >= field.Price)
                {
                    FinalizeTrade(playerA, itemA, playerB, itemB);
                }
                return;
            }

            TradeMessage tradeMessage = new TradeMessage(playerA, itemA, playerB, itemB);

            if (playerA != null)
            {
                playerA.Messages.Add(tradeMessage);
                playerB.Messages.Add(tradeMessage);
            }
        }
示例#2
0
 public TradeNotification(ITrader seller, ITrader buyer, ITradeable tradedObject, bool isSuccessful)
 {
     this.seller       = seller;
     this.buyer        = buyer;
     this.tradedObject = tradedObject;
     this.isSuccessful = isSuccessful;
 }
示例#3
0
    public bool Has(ITradeable item)
    {
        if (item is Money)
        {
            return(Has(item as Money));
        }

        return(Items.Contains(item));
    }
    public TradeMessage(Player playerA, ITradeable itemA, Player playerB, ITradeable itemB)
        : base(null, "Trade request")
    {
        PlayerA = playerA;
        PlayerB = playerB;

        ItemA = itemA;
        ItemB = itemB;
    }
示例#5
0
 public void FinalizeTrade(Player playerA, ITradeable itemA, Player playerB, ITradeable itemB)
 {
     if ((playerA == null || playerA.Has(itemA)) && (playerB == null || playerB.Has(itemB)))
     {
         itemA.TakeFromPlayer(playerA, itemA.GetAmount());
         itemB.TakeFromPlayer(playerB, itemB.GetAmount());
         itemA.GiveToPlayer(playerB, itemA.GetAmount());
         itemB.GiveToPlayer(playerA, itemB.GetAmount());
     }
 }
示例#6
0
        public virtual void OnItemBought(ITradeable tradeable, ITrader seller)
        {
            AddGold(-tradeable.Cost);

            Item newItem      = (Item)tradeable;
            Item existingItem = Inventory.GetItemByName(newItem.Name);

            // Add new Item or stack repetitions
            if (existingItem == null)
            {
                Inventory.Add((Item)newItem.Clone());
            }
            else
            {
                existingItem.Quantity++;
            }

            NotifyRedrawObservers(new RedrawNotification($"Trader {Name} just bought [{tradeable.Name}] for {tradeable.Cost} Gold from {seller.Name}!"));
        }
示例#7
0
    public void ShowTrade(ITradeable Tradeable)
    {
        AudioManager.S.PlaySound("TradeComplete");
        if (CurrentTrade != null)
        {
            RemoveItemsFromTradeUI();
        }
        CurrentlyBeingTradedWith = Tradeable;
        CurrentTrade             = CurrentlyBeingTradedWith.GetTrade();
        TradesLeft = CurrentTrade.MaxNumberOfTrades;
        OutputSlot.Initialize(new OutputSlot());
        InputSlot.Initialize(new InputSlot());
        Background.SetActive(true);
        InputSlot.SetOutputSihlouette(CurrentTrade.WantedItem);
        InputSlot S = (InputSlot)InputSlot.ReferenceSlot;

        S.AcceptedItem = CurrentTrade.WantedItem;
        OutputSlot.SetOutputSihlouette(CurrentTrade.BaseTradedItem);
    }
示例#8
0
        public virtual void Sell(ITrader buyer)
        {
            ITradeable tradeable = Inventory.GetSelectedItem();

            if (tradeable == null)
            {
                return;
            }

            if (buyer.Gold <= 0 || buyer.Gold < tradeable.Cost)
            {
                NotifyRedrawObservers(new RedrawNotification($"Trader {buyer.Name} does not have enough gold to buy that! { buyer.Name }'s gold: {buyer.Gold}, item cost: {tradeable.Cost}"));
                NotifyTradeObservers(new TradeNotification(this, buyer, tradeable, isSuccessful: false));
                return;
            }

            if (--tradeable.Quantity <= 0)
            {
                Inventory.Remove((Item)tradeable);
            }

            AddGold(tradeable.Cost);
            NotifyTradeObservers(new TradeNotification(this, buyer, tradeable, isSuccessful: true));
        }
 public void CreateLocation43()
 {
     ITradeable[] iTradeables = new ITradeable[2];
     this.CreateLocation("‰", (IEnumerable <ITradeable>)iTradeables);
 }
 public void CreateLocation192()
 {
     ITradeable[] iTradeables = new ITradeable[0];
     this.CreateLocation("\0ĀĀ", (IEnumerable <ITradeable>)iTradeables);
 }
 public void CreateLocationThrowsArgumentNullException164()
 {
     ITradeable[] iTradeables = new ITradeable[0];
     this.CreateLocation("", (IEnumerable <ITradeable>)iTradeables);
 }
示例#12
0
 /// <summary>
 /// Trade Price of item for given transfer type.
 /// </summary>
 /// <param name="tradeableItem">Item to trade</param>
 /// <param name="type">Transfer type</param>
 /// <returns>Trade Price</returns>
 public decimal TradePrice(ITradeable tradeableItem, TransferType type)
 {
     return(type == TransferType.Buy ? tradeableItem.BuyPrice : tradeableItem.SellPrice);
 }
示例#13
0
 public int CalculateCost(ITradeable product, int quantity)
 {
     return(product.Price * quantity);
 }
示例#14
0
 public int CalculateCost(ITradeable product, int quantity)
 {
     return product.Price * quantity;
 }
 public void CreateLocationThrowsArgumentNullException316()
 {
     ITradeable[] iTradeables = new ITradeable[2];
     this.CreateLocation((string)null, (IEnumerable <ITradeable>)iTradeables);
 }
示例#16
0
        public Order MakeOrder(Client client, ITradeable product, OrderType type, int count)
        {
            Order order = new Order();
            order.Client = client;
            order.Product = product;
            order.Type = type;
            order.Count = count;

            Order tempOrder = (Order)order.Clone();
            Order [] brokerOrders = new Order[brokers.Count];
            bool [] rtnCdes = new bool[brokers.Count];
            int modCount = order.Count;
            int idx = 0;
            int maxCount = 0;
            decimal minBrokerValue = 0;
            int brokerValueIdx = -1;

            while (modCount > 0)
            {
                tempOrder.Count = modCount;

                maxCount = 0;
                idx = 0;
                foreach (Broker broker in brokers)
                {
                    rtnCdes[idx] = broker.PrepareOrder(tempOrder, out brokerOrders[idx]);
                    if (rtnCdes[idx])
                    {
                        if (brokerOrders[idx].Count > maxCount)
                            maxCount = brokerOrders[idx].Count;
                    }

                    idx++;
                }

                if (maxCount == 0)
                    return order;

                minBrokerValue = decimal.MaxValue;
                brokerValueIdx = -1;
                for(idx = 0; idx < brokers.Count; ++idx)
                {
                    if (rtnCdes[idx])
                    {
                        if (brokerOrders[idx].Count == maxCount)
                        {
                            if (brokerOrders[idx].BrokerValue < minBrokerValue)
                            {
                                minBrokerValue = brokerOrders[idx].BrokerValue;
                                brokerValueIdx = idx;
                            }
                        }
                    }
                }

                if (brokerValueIdx == -1)
                    return order;

                brokers[brokerValueIdx].AddOrder(brokerOrders[brokerValueIdx]);
                order.TotalValue += brokerOrders[brokerValueIdx].BrokerValue;
                modCount -= brokerOrders[brokerValueIdx].Count;
            }

            client.AddOrder(order);
            return order;
        }
示例#17
0
 public Quotation GetQuote(ITradeable product)
 {
     List<Quotation> quotationList = quotations[product.Symbol];
     return quotationList.LastOrDefault();
 }