public void RemoveOldOrders() { int i; for (i = 0; i < BuyList.List.Count; i++) { BuyList.List[i].Age = BuyList.List[i].Age + 1; if ((BuyList.List[i].Owner == null) && (BuyList.List[i].Age >= 30)) { BuyList.List.RemoveAt(i); i--; } } for (i = 0; i < SellList.List.Count; i++) { SellList.List[i].Age = SellList.List[i].Age + 1; if ((SellList.List[i].Owner == null) && (SellList.List[i].Age >= 30)) { int number = CompaniesList.FindNumber(SellList.List[i].CompanyName); CompaniesList.List[number].CurrentQuantity = CompaniesList.List[number].CurrentQuantity + SellList.List[i].CurrentQuantity; SellList.List.RemoveAt(i); i--; } } }
public void MakeDeals(List <SharePacket> buy, List <SharePacket> sell)// DODELAT { int i = 0; int j = 0; while (i < buy.Count && j < sell.Count) { if (buy[i].Owner != null && buy[i].Owner == sell[j].Owner) { i++; continue; } if (buy[i].Price < sell[j].Price) { break; } var qty = Math.Min(buy[i].CurrentQuantity, sell[j].CurrentQuantity); buy[i].CurrentQuantity -= qty; sell[j].CurrentQuantity -= qty; if (buy[i].Owner == Player.Current.Name) { var price = Math.Min(buy[i].Price, sell[j].Price); OnBuy(buy[i], qty, price); } else if (sell[j].Owner == Player.Current.Name) { var price = Math.Min(buy[i].Price, sell[j].Price); OnSell(sell[j], qty, price); } else { CompaniesList.List[CompaniesList.FindNumber(sell[j].CompanyName)].CurrentQuantity += qty; } if (buy[i].CurrentQuantity == 0) { i++; continue; } if (sell[j].CurrentQuantity == 0) { j++; continue; } } foreach (var packet in buy) { BuyList.List.Add(packet); } BuyList.RemoveEmptyEntries(); foreach (var packet in sell) { SellList.List.Add(packet); } SellList.RemoveEmptyEntries(); }