public void ServerBuyStocks(Version clientversion, ICommunicateable communicator) { try { if (clientversion.Major > 0) { communicator.SendInt(Stock.Available); int stockstobuy = communicator.ReceiveInt(); double stockprice = communicator.ReceiveDouble(); double price = communicator.ReceiveDouble(); if (stockstobuy > 0 && stockstobuy <= Stock.Available && Deposit.Player.Capital >= price) { Count += stockstobuy; Stock.Available -= stockstobuy; Stock.OwnedByPlayers += stockstobuy; LastBuyPrice = stockprice; Deposit.Player.Capital -= price; } communicator.SendInt(Count); communicator.SendInt(Stock.Available); communicator.SendInt(Stock.OwnedByPlayers); communicator.SendDouble(LastBuyPrice); communicator.SendDouble(Deposit.Player.Capital); } } 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 System.Object ClientCommunication(Version serverversion, ICommunicateable communicator, bool full, System.Object obj) { try { if (serverversion.Major > 0) { if (full) { Id = communicator.ReceiveString(); Name = communicator.ReceiveString(); int c = communicator.ReceiveInt(); if (c > 0) { StockIndexes stockindexes = (StockIndexes) obj; for (int i = 0; i < c; i++) { string id = communicator.ReceiveString(); StockIndex stockindex = null; if (stockindexes.TryGetValue(id, out stockindex)) { stockindex.Stocks.Add(Id, this); StockIndexes.Add(stockindex.Id, stockindex); } } } PriceHistory.ClientCommunication(serverversion, communicator, full, obj); } if (serverversion.Major > 0 && serverversion.Minor >= 1) { MinPrice = communicator.ReceiveDouble(); MaxPrice = communicator.ReceiveDouble(); } else { MinPrice = MIN_PRICE; MaxPrice = MAX_PRICE; } Price = communicator.ReceiveDouble(); if (full && PriceHistory.Count > 0) PriceHistory.RemoveAt(PriceHistory.Count - 1); Available = communicator.ReceiveInt(); OwnedByPlayers = communicator.ReceiveInt(); } return this; } catch (System.Exception ex) { throw ex; } }
public System.Object ClientCommunication(Version serverversion, ICommunicateable communicator, bool full, System.Object obj) { try { if (serverversion.Major > 0) { if (full) { IsComputer = communicator.ReceiveBool(); IsYou = communicator.ReceiveBool(); ValueHistory.ClientCommunication(serverversion, communicator, full, obj); } if (IsYou && !full) { communicator.SendString(Company); communicator.SendString(Name); } else { Company = communicator.ReceiveString(); Name = communicator.ReceiveString(); } Deposit.ClientCommunication(serverversion, communicator, full, obj); Capital = communicator.ReceiveDouble(); ValueHistory.AddHistory(Value); } return(this); } catch (System.Exception ex) { throw ex; } }
public System.Object ClientCommunication(Version serverversion, ICommunicateable communicator, bool full, System.Object obj) { try { if (serverversion.Major > 0) { while (this.Count > 0) { this.Clear(); } int c = communicator.ReceiveInt(); if (c > 0) { for (int i = 0; i < c; i++) { this.Add(communicator.ReceiveDouble()); } } } return(this); } catch (System.Exception ex) { throw ex; } }
public System.Object ClientCommunication(Version serverversion, ICommunicateable communicator, bool full, System.Object obj) { try { if (serverversion.Major > 0) { Count = communicator.ReceiveInt(); LastBuyPrice = communicator.ReceiveDouble(); LastSellPrice = communicator.ReceiveDouble(); } return(this); } catch (System.Exception ex) { throw ex; } }
public void ServerSellStocks(Version clientversion, ICommunicateable communicator) { try { if (clientversion.Major > 0) { int stockstosell = communicator.ReceiveInt(); double stockprice = communicator.ReceiveDouble(); double price = communicator.ReceiveDouble(); double brokerage = communicator.ReceiveDouble(); if (stockstosell > 0 && stockstosell < Count && price >= brokerage) { Count -= stockstosell; Stock.OwnedByPlayers -= stockstosell; Stock.Available += stockstosell; if (Count <= 0) { LastBuyPrice = 0; LastSellPrice = 0; } else { LastSellPrice = stockprice; } Deposit.Player.Capital += price - brokerage; } communicator.SendInt(Count); communicator.SendInt(Stock.OwnedByPlayers); communicator.SendInt(Stock.Available); communicator.SendDouble(LastBuyPrice); communicator.SendDouble(LastSellPrice); communicator.SendDouble(Deposit.Player.Capital); } } catch (System.Exception ex) { throw ex; } }
public System.Object ClientCommunication(Version serverversion, ICommunicateable communicator, bool full, System.Object obj) { try { if (serverversion.Major > 0) { State = (MarketStateType)communicator.ReceiveInt(); Epochs = communicator.ReceiveInt(); Brokerage = communicator.ReceiveDouble(); } return(this); } catch (System.Exception ex) { throw ex; } }