Esempio n. 1
0
 public void SendMessage(Message msg)
 {
     try {
         if (!_isDisconnected)
         {
             if (msg.Type == MessageType.Build)
             {
                 BuildMessage bm = (BuildMessage)msg;
                 InfoLog.WriteInfo("Sending build message to player: " + this.Id, EPrefix.Test);
                 InfoLog.WriteInfo("Buildmessage data: " + bm.ToString(), EPrefix.Test);
             }
             if (msg.Type == MessageType.BuildUnitMessage)
             {
                 BuildUnitMessage bum = (BuildUnitMessage)msg;
                 InfoLog.WriteInfo("Sending build unit message to player: " + this.Id, EPrefix.Test);
                 InfoLog.WriteInfo("BuildUnitMessage data: " + bum.ToString(), EPrefix.Test);
             }
             msg.Serialize(_writeStream);
             _writeStream.Flush();
             if (msg.Type == MessageType.DoTurn)
             {
                 _tac.Unset(this.Login);
             }
         }
     }
     catch (Exception ex) {
         InfoLog.WriteException(ex);
         ExecuteOnConnectionLost();
     }
 }
Esempio n. 2
0
 protected override void onMessageBuildUnit(BuildUnitMessage msg)
 {
     InfoLog.WriteInfo("OnMessageBuildUnit: " + msg.ToString());
     if (GlobalSettings.Wrapper.sandwormsMap.ContainsKey(msg.UnitType))
     {
         //sandworm
     }
     else
     {
         //ordynary unit creation
         ObjectID id = new ObjectID(msg.IdPlayer, msg.CreatorID);
         Building b  = players[msg.IdPlayer].GetBuilding(id);
         if (null == b)
         {
             InfoLog.WriteInfo("Invalid onMessageBuildUnit", EPrefix.BMan);
             if (InvalidBuild != null)
             {
                 InvalidBuild(msg.CreatorID);
             }
             return;
         }
         int cost = GlobalSettings.GetUnitCost(msg.UnitType);
         if (players[msg.IdPlayer].Credits < cost)
         {
             InfoLog.WriteInfo("Invalid cost", EPrefix.BMan);
             if (InvalidBuild != null)
             {
                 InvalidBuild(msg.CreatorID);
             }
             return;
         }
         players[msg.IdPlayer].Credits -= cost;
         OnCreditsUpdate(msg.IdPlayer, cost);
         b.BuildStatus = new BuildStatus(msg.CreatorID, msg.UnitType, (short)GetUnitBuildTime(msg.UnitType), BuildType.Unit);
         b.State       = Building.BuildingState.creating;
     }
 }