Exemple #1
0
 public void AddPurchase(Transaction t)
 {
     purchases.Add(t);
 }
Exemple #2
0
        public bool Combine(Transaction add)
        {
            bool done = false;

            if (this.Type == add.Type)
            {
                foreach (TransactionItem t in add.Purchases)
                {
                    AddPurchase(t);
                }
                foreach (TransactionItem t in add.Sales)
                {
                    AddSale(t);
                }

                done = true;
            }

            return done;
        }
Exemple #3
0
        internal TransactionList GetItemTransactionList(Station source, Station destination, ItemType type)
        {
            TransactionList list = new TransactionList();

            Trade[] forSale = source.ItemsForSale[type].ToArray();
            Trade[] wanted = destination.ItemsWanted[type].ToArray();

            int buyIndex = 0;
            int sellIndex = 0;
            int buyAmount = 0;
            int sellAmount = 0;
            TransactionItem purchase = null;
            TransactionItem sale = null;
            Transaction currentTransaction = null;
            bool finished = false;
            int minQtyNeeded = 0;

            while (!finished)
            {
                // Source station has more than destination wants
                if ((forSale[buyIndex].Quantity - buyAmount) > (wanted[sellIndex].Quantity - sellAmount))
                {
                    // Set the amount (qty) of the transaction
                    int amount = (wanted[sellIndex].Quantity - sellAmount); 

                    // Create trades
                    purchase = new TransactionItem(forSale[buyIndex], amount);
                    if (minQtyNeeded > 0)
                    {
                        minQtyNeeded -= amount;
                    }
                    else
                    {
                        if (wanted[sellIndex].MinQuantity > amount)
                        {
                            sale = new TransactionItem(wanted[sellIndex]);
                            minQtyNeeded = wanted[sellIndex].MinQuantity - amount; 
                        }
                        else
                        {
                            sale = new TransactionItem(wanted[sellIndex], amount);
                        }
                    }

                    // Set the buy amount up by the amount that can be sold
                    buyAmount += amount;
                    // reset the sell amount
                    sellAmount = 0;
                    sellIndex++;
                }
                    // Source station has less than destination wants
                else if ((forSale[buyIndex].Quantity - buyAmount) < (wanted[sellIndex].Quantity - sellAmount))
                {
                    // Set the amount (qty) of the transaction
                    int amount = (forSale[buyIndex].Quantity - buyAmount);

                    // Create trades
                    purchase = new TransactionItem(forSale[buyIndex], amount);
                    if (minQtyNeeded > 0)
                    {
                        minQtyNeeded -= amount;
                    }
                    else
                    {
                        if (wanted[sellIndex].MinQuantity > amount)
                        {
                            sale = new TransactionItem(wanted[sellIndex]);
                            minQtyNeeded = wanted[sellIndex].MinQuantity - amount; 
                        }
                        else
                        {
                            sale = new TransactionItem(wanted[sellIndex], amount);
                        }
                    }

                    // Set the buy amount up by the amount that can be sold
                    sellAmount += amount;
                    // reset the buy amount
                    buyAmount = 0;
                    buyIndex++;
                }
                else
                {
                    // Set the amount (qty) of the transaction
                    int amount = (wanted[sellIndex].Quantity - sellAmount);

                    // Create trades
                    purchase = new TransactionItem(forSale[buyIndex], amount);
                    if (minQtyNeeded > 0)
                    {
                        minQtyNeeded -= amount;
                    }
                    else
                    {
                        if (wanted[sellIndex].MinQuantity > amount)
                        {
                            sale = new TransactionItem(wanted[sellIndex]);
                            minQtyNeeded = wanted[sellIndex].MinQuantity - amount;
                        }
                        else
                        {
                            sale = new TransactionItem(wanted[sellIndex], amount);
                        }
                    }


                    // Reset both buy and sell amount
                    buyAmount = 0;
                    sellAmount = 0;
                    buyIndex++;
                    sellIndex++;
                }

                if (currentTransaction == null)
                {
                    currentTransaction = new Transaction(purchase, sale);
                }
                else
                {
                    currentTransaction.AddPurchase(purchase);
                    if (sale != null)
                    {
                        currentTransaction.AddSale(sale);
                    }
                }

                purchase = null;
                sale = null;

                if ((wanted.Length <= sellIndex) ||
                    (forSale.Length <= buyIndex) ||
                    (wanted[sellIndex].UnitPrice <= forSale[buyIndex].UnitPrice))
                {
                    finished = true;
                }

                // If minimum quantity is achieved, add the transaction
                if ((finished) ||
                    ((minQtyNeeded <= 0) && 
                    (!((wanted[sellIndex].UnitPrice == wanted[Math.Max(sellIndex-1, 0)].UnitPrice) && 
                    (forSale[buyIndex].UnitPrice == forSale[Math.Max(buyIndex-1, 0)].UnitPrice)))
                    ))
                {
                    if (currentTransaction.Profit >= 0.0f)
                    {
                        list.Add(currentTransaction);
                    }
                    currentTransaction = null;
                    minQtyNeeded = 0;
                }

            }

            return list;
        }
Exemple #4
0
        public Transaction GetTransactionByLimits(float isk, float cargo)
        {
            UpdateValues();

            Transaction returnTransaction = new Transaction(type);
            int quantity = 0;

            foreach (TransactionItem t in purchases)
            {
                if (((t.Quantity * t.UnitPrice) <= isk) && ((t.Quantity * t.Type.Volume) <= cargo))
                {
                    returnTransaction.AddPurchase(t);
                    isk -= (t.Quantity * t.UnitPrice);
                    cargo -= (t.Quantity * t.Type.Volume);
                    quantity += t.Quantity;
                }
                else
                {
                    int maxAmountByCost = (int)(isk / t.UnitPrice);
                    int maxAmountByVolume = (int)(cargo / t.Type.Volume);
                    int amount = Math.Min(maxAmountByCost, maxAmountByVolume);

                    returnTransaction.AddPurchase(t.TradeItem, amount);
                    quantity += amount;
                    break;
                }
            }
            int saleQuantity = quantity;
            int minQty = 0;

            foreach (TransactionItem t in sales)
            {
                if (t.Quantity <= saleQuantity)
                {
                    minQty += t.MinQuantity;
                    returnTransaction.AddSale(t);
                    saleQuantity -= t.Quantity;
                }
                else
                {
                    returnTransaction.AddSale(t.TradeItem, saleQuantity);
                    minQty += t.MinQuantity;
                    break;
                }
            }

            if (quantity < minQty)
            {
                returnTransaction = null;
            }

            return returnTransaction;
        }