Ejemplo 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();
     }
 }
Ejemplo n.º 2
0
        private void RightBuildActiveClick(int id, bool isUnit)
        {
            InfoLog.WriteInfo("Enter RightBuildActiveClick", EPrefix.BMan);
            InfoLog.WriteInfo("lock cObjLock in RightBuildActiveClick", EPrefix.BMan);

            int current = -1;

            lock (cObjLock)
                current = _currentObjectID;

            InfoLog.WriteInfo("unlock cObjLock in RightBuildActiveClick", EPrefix.BMan);

            if (current == -1)
            {
                InfoLog.WriteInfo("Exit RightBuildingClick", EPrefix.BMan);
                return;
            }


            if (isUnit)
            {
                DeactivateOther(-1);
                _rightStripe.DeactivateAll();
                BuildUnitMessage buMessage = (BuildUnitMessage)MessageFactory.Create(MessageType.BuildUnitMessage);
                buMessage.UnitType  = (short)id;
                buMessage.CreatorID = current;
                buMessage.IdPlayer  = _gameLogic.CurrentPlayer.Id;
                Connection.Instance.SendMessage(buMessage);
                InfoLog.WriteInfo("Current: " + current, EPrefix.BMan);
                InfoLog.WriteInfo("Exit RightBuildingActiveClick", EPrefix.BMan);
                return;
            }
            else
            {
                InfoLog.WriteInfo("lock leftState in RightBuildActiveClick", EPrefix.BMan);

                lock (((ICollection)_leftState).SyncRoot)
                    _leftState[current] = RightStripState.Placing;

                InfoLog.WriteInfo("lock leftState in RightBuildActiveClick", EPrefix.BMan);

                InfoLog.WriteInfo("lock stripData in RightBuildActiveClick", EPrefix.BMan);
                lock (((ICollection)_stripData).SyncRoot)
                    _stripData[current][(short)id].State = StripButtonState.Ready;
                InfoLog.WriteInfo("unlock stripData in RightBuildActiveClick", EPrefix.BMan);
                DeactivateOther((short)id);
                _rightStripe.DeactivateAll();
                _rightStripe.SetState(id, StripButtonState.Ready);
                return;
            }

            /*InfoLog.WriteInfo("lock stripData in RightBuildActiveClick", EPrefix.BMan);
             * lock (((ICollection)_stripData).SyncRoot)
             *  UpdateView(current,false);
             * InfoLog.WriteInfo("unlock stripData in RightBuildActiveClick", EPrefix.BMan);
             * InfoLog.WriteInfo("Exit RightBuildingClick", EPrefix.BMan);*/
        }
Ejemplo n.º 3
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;
     }
 }
Ejemplo n.º 4
0
 protected abstract void onMessageBuildUnit(BuildUnitMessage msg);