public System.Object ServerCommunication(Version clientversion, ICommunicateable communicator, bool full, System.Object obj)
 {
     try
     {
         if (clientversion.Major > 0)
         {
             if (full)
             {
                 communicator.SendString(Id);
                 communicator.SendString(Name);
                 communicator.SendInt(StockIndexes.Count);
                 if (StockIndexes.Count > 0)
                 {
                     foreach (StockIndex stockindex in StockIndexes.Values)
                         communicator.SendString(stockindex.Id);
                 }
                 PriceHistory.ServerCommunication(clientversion, communicator, full, obj);
             }
             if (clientversion.Major > 0 && clientversion.Minor >= 1)
             {
                 communicator.SendDouble(MinPrice);
                 communicator.SendDouble(MaxPrice);
             }
             communicator.SendDouble(Price);
             communicator.SendInt(Available);
             communicator.SendInt(OwnedByPlayers);
         }
         return this;
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
 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;
     }
 }
示例#4
0
 public System.Object ServerCommunication(Version clientversion, ICommunicateable communicator, bool full, System.Object obj)
 {
     try
     {
         if (clientversion.Major > 0)
         {
             if (full)
             {
                 communicator.SendBool(IsComputer);
                 communicator.SendBool(Id == (int)obj);
                 ValueHistory.ServerCommunication(clientversion, communicator, full, obj);
             }
             if (Id == (int)obj && !full)
             {
                 Company = communicator.ReceiveString();
                 Name    = communicator.ReceiveString();
             }
             else
             {
                 communicator.SendString(Company);
                 communicator.SendString(Name);
             }
             Deposit.ServerCommunication(clientversion, communicator, full, obj);
             communicator.SendDouble(Capital);
         }
         return(this);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
 public System.Object ServerCommunication(Version clientversion, ICommunicateable communicator, bool full, System.Object obj)
 {
     try
     {
         if (clientversion.Major > 0)
         {
             communicator.SendInt(Count);
             communicator.SendDouble(LastBuyPrice);
             communicator.SendDouble(LastSellPrice);
         }
         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;
     }
 }
示例#7
0
 public System.Object ServerCommunication(Version clientversion, ICommunicateable communicator, bool full, System.Object obj)
 {
     try
     {
         if (clientversion.Major > 0)
         {
             communicator.SendInt((int)State);
             communicator.SendInt(Epochs);
             communicator.SendDouble(Brokerage);
         }
         return(this);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
 public System.Object ServerCommunication(Version clientversion, ICommunicateable communicator, bool full, System.Object obj)
 {
     try
     {
         if (clientversion.Major > 0)
         {
             communicator.SendInt(this.Count);
             if (this.Count > 0)
             {
                 foreach (double d in this)
                 {
                     communicator.SendDouble(d);
                 }
             }
         }
         return(this);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }