Ejemplo n.º 1
0
        public void add(int nextTickNumber, GameRequestData data)
        {
            bool inserted = false;
            int i = 0;

            while (!inserted)
            {
                if (_requests.ContainsKey(nextTickNumber + i))
                {
                    i++;
                }
                else //found empty slot (tick, at which there is no request planned at the moment)
                {
                    _requests[nextTickNumber + i] = data;
                    inserted = true;
                }
            }
        }
Ejemplo n.º 2
0
        private void switchPreset(GameRequestData reqData, bool force)
        {
            if (!force)
                //get safe awaiting request with all valuable request data. Only receiving tick number from client
            {
                GameRequestData awaitingRequest = getAndRemoveAwaitingRequest(reqData);
                gotoNewMap();
            }
            else //force execution
                gotoNewMap();

            Console.WriteLine("switchPreset " + (this is NPCFieldSimulation ? " NPC " : " player"));
        }
Ejemplo n.º 3
0
        private void speedUp(GameRequestData reqData, bool force)
        {
            if (!force)
                //get safe awaiting request with all valuable request data. Only receiving tick number from client
            {
                GameRequestData awaitingRequest = getAndRemoveAwaitingRequest(reqData);
                _ballsManager.currentSpeed = Convert.ToInt16(awaitingRequest.data);
            }
            else //force execution
                _ballsManager.currentSpeed = Convert.ToInt16(reqData.data);

            Console.WriteLine("speedUp " + (this is NPCFieldSimulation ? " NPC " : " player") + " to: " +
                              _ballsManager.currentSpeed + " at " + _ballsManager.currentSpeed);
        }
Ejemplo n.º 4
0
        private void goWiggle(GameRequestData reqData, bool force)
        {
            if (!force)
                //get safe awaiting request with all valuable request data. Only receiving tick number from client
            {
                GameRequestData awaitingRequest = getAndRemoveAwaitingRequest(reqData);
            }

            _ballsManager.goWiggle();
        }
Ejemplo n.º 5
0
        private void goLaunchRocket(GameRequestData reqData, bool force)
        {
            Console.WriteLine("goLaunchRocket: force: " + force);
            if (!force)
                //get safe awaiting request with all valuable request data. Only receiving tick number from client
            {
                GameRequestData awaitingRequest = getAndRemoveAwaitingRequest(reqData);
            }

            _rocketLauncher.instaLaunchRocket();
        }
Ejemplo n.º 6
0
 private GameRequestData getAndRemoveAwaitingRequest(GameRequestData reqData)
 {
     var ar = new GameRequestData(-1, "abrakadabra");
     foreach (int key in _awaitingRequests.requests.Keys)
     {
         if (_awaitingRequests.requests[key].requestID == reqData.requestID)
             //found first request with ID which was requested
         {
             ar = _awaitingRequests.requests[key];
             _awaitingRequests.requests.Remove(key);
             break;
         }
     }
     if (ar.requestID == -1 && reqData.requestID != 1)
         //there was a problem with switch map request. Skipping it for now
         throw new Exception("Did not found target awaiting request");
     return ar;
 }
Ejemplo n.º 7
0
        private void executeRequest(GameRequestData reqData, bool force = false)
        {
            string result = "";

            switch (reqData.requestID)
            {
                case GameRequest.SPEED_UP:
                    speedUp(reqData, force);
                    result = _ballsManager.currentSpeed.ToString();
                    break;
                case GameRequest.NEW_MAP:
                    switchPreset(reqData, force);
                    break;
                case GameRequest.SPLIT_BALL_IN_TWO:
                    explodeBalls(2);
                    break;
                case GameRequest.SPLIT_BALL_IN_THREE:
                    explodeBalls(3);
                    break;
                case GameRequest.LIGHTNING_ONE:
                    fieldCells.hitLightning(1, reqData.data);
                    result = reqData.data;
                        //goes into requestsExecutedAt8Ticks and this stuff broadcasts to other players
                    break;
                case GameRequest.LIGHTNING_TWO:
                    fieldCells.hitLightning(2, reqData.data);
                    result = reqData.data;
                    break;
                case GameRequest.LIGHTNING_THREE:
                    fieldCells.hitLightning(3, reqData.data);
                    result = reqData.data;
                    break;
                case GameRequest.CHARM_BALLS:
                    goWiggle(reqData, force);
                    break;
                case GameRequest.FREEZE:
                    goFreeze(reqData, force);
                    break;
                case GameRequest.BOUNCY_SHIELD:
                    ballsManager.goBouncyShield();
                    break;
                case GameRequest.LASER_SHOTS:
                    _laserShotsManager.shoot();
                    break;
                case GameRequest.ROCKET:
                    goLaunchRocket(reqData, force);
                    break;
            }

            Console.WriteLine("[Request executed] at: " + ballsManager.currentTick + " request: " + reqData.requestID +
                              " spell name: " + GameRequest.getSpellNameByRequest(reqData.requestID) + " reqData: " +
                              reqData.data + " Result: " + result +
                              (this is NPCFieldSimulation ? " [NPC] " : "[Player]"));

            requestsExecutedAt8Ticks.Add(reqData.requestID + ":" + _ballsManager.currentTick + ":" + result);

            if (reqData.requestID == GameRequest.GAME_FINISH)
                finishGame();
        }