public void Sell(MarketState marketstate, int stockstosell) { try { if (OnClientSellStocksEvent != null) { if (stockstosell > 0 && stockstosell <= Count && Stock.CalculatePrice(stockstosell) >= Stock.CalculateBrokerage(marketstate, stockstosell)) { OnClientSellStocksEvent(Stock.Id, this, marketstate, stockstosell); } } else if (stockstosell > 0 && stockstosell <= Count && Stock.CalculatePrice(stockstosell) >= Stock.CalculateBrokerage(marketstate, stockstosell)) { Count -= stockstosell; Stock.OwnedByPlayers -= stockstosell; Stock.Available += stockstosell; if (Count <= 0) { LastBuyPrice = 0; LastSellPrice = 0; } else { LastBuyPrice = Stock.Price; } Deposit.Player.Capital += Stock.CalculatePrice(stockstosell) - Stock.CalculateBrokerage(marketstate, stockstosell); } } catch (System.Exception ex) { throw ex; } }
public void ClientBuyStocks(Version serverversion, ICommunicateable communicator, MarketState marketstate, int stockstobuy) { try { if (serverversion.Major > 0) { Stock.Available = communicator.ReceiveInt(); if (stockstobuy > Stock.Available) { stockstobuy = Stock.Available; } communicator.SendInt(stockstobuy); communicator.SendDouble(Stock.Price); communicator.SendDouble(Stock.CalculatePrice(stockstobuy) + Stock.CalculateBrokerage(marketstate, stockstobuy)); Count = communicator.ReceiveInt(); Stock.Available = communicator.ReceiveInt(); Stock.OwnedByPlayers = communicator.ReceiveInt(); LastBuyPrice = communicator.ReceiveDouble(); Deposit.Player.Capital = communicator.ReceiveDouble(); } } catch (System.Exception ex) { throw ex; } }
public void Buy(MarketState marketstate, int stockstobuy) { try { if (OnClientBuyStocksEvent != null) { if (stockstobuy > 0 && stockstobuy <= Stock.Available && Deposit.Player.Capital >= Stock.CalculatePrice(stockstobuy) + Stock.CalculateBrokerage(marketstate, stockstobuy)) { OnClientBuyStocksEvent(Stock.Id, this, marketstate, stockstobuy); } } else if (stockstobuy > 0 && stockstobuy <= Stock.Available && Deposit.Player.Capital >= Stock.CalculatePrice(stockstobuy) + Stock.CalculateBrokerage(marketstate, stockstobuy)) { Count += stockstobuy; Stock.Available -= stockstobuy; Stock.OwnedByPlayers += stockstobuy; LastBuyPrice = Stock.Price; Deposit.Player.Capital -= Stock.CalculatePrice(stockstobuy) + Stock.CalculateBrokerage(marketstate, stockstobuy); } } catch (System.Exception ex) { throw ex; } }
public void UpdateTradeInformations() { try { System.Globalization.NumberFormatInfo nfi = System.Globalization.NumberFormatInfo.CurrentInfo; System.Globalization.RegionInfo ri = System.Globalization.RegionInfo.CurrentRegion; int max = 0; if (this.radioButtonTradeBuy.Checked) { if (Player.Capital / Stock.CalculatePrice(1) > int.MaxValue) { max = int.MaxValue; } else { max = (int)System.Math.Floor(Player.Capital / Stock.CalculatePrice(1)); } while (Player.Capital < Stock.CalculatePrice(max) + Stock.CalculateBrokerage(MarketState, max)) { max--; } if (max > Stock.Available) { max = Stock.Available; } } else if (this.radioButtonTradeSell.Checked) { if (DepositContent != null) { max = DepositContent.Count; } } this.numericUpDownTradeCount.Minimum = 0; if (this.numericUpDownTradeCount.Value > max) { this.numericUpDownTradeCount.Value = max; } this.numericUpDownTradeCount.Maximum = max; this.textBoxTradeCountValue.Text = Stock.CalculatePrice((int)this.numericUpDownTradeCount.Value).ToString("n", nfi) + " " + ri.ISOCurrencySymbol; this.textBoxTradeBrokerage.Text = MarketState.Brokerage.ToString("n", nfi) + " " + nfi.PercentSymbol; this.textBoxTradeBrokeragePrice.Text = Stock.CalculateBrokerage(MarketState, (int)this.numericUpDownTradeCount.Value).ToString("n", nfi) + " " + ri.ISOCurrencySymbol; if (this.radioButtonTradeBuy.Checked) { double d = Stock.CalculatePrice((int)this.numericUpDownTradeCount.Value) + Stock.CalculateBrokerage(MarketState, (int)this.numericUpDownTradeCount.Value); this.textBoxTradeTotal.Text = d.ToString("n", nfi) + " " + ri.ISOCurrencySymbol; } else if (this.radioButtonTradeSell.Checked) { double d = Stock.CalculatePrice((int)this.numericUpDownTradeCount.Value) - Stock.CalculateBrokerage(MarketState, (int)this.numericUpDownTradeCount.Value); this.textBoxTradeTotal.Text = d.ToString("n", nfi) + " " + ri.ISOCurrencySymbol; } else { this.textBoxTradeTotal.Text = string.Empty; } GrayItems(); } catch (System.Exception ex) { throw ex; } }