MAPG-219 send 'end_round' when all members are finished
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				default-pipeline default-pipeline #83
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	default-pipeline default-pipeline #83
				
			This commit is contained in:
		
							parent
							
								
									cc49c56075
								
							
						
					
					
						commit
						a2f2080959
					
				@ -97,28 +97,15 @@ class MultiGame {
 | 
			
		||||
        room.updated = new Date();
 | 
			
		||||
 | 
			
		||||
        var round = room.rounds[room.currentRound];
 | 
			
		||||
 | 
			
		||||
        clearTimeout(round.timeoutHandler);
 | 
			
		||||
        round.timeout = round.timeout - (new Date() - round.timeoutStarted);
 | 
			
		||||
        if (round.timeout > MultiGame.ROUND_TIMEOUT_DIVIDER * MultiGame.ROUND_TIMEOUT_MINIMUM) {
 | 
			
		||||
            round.timeout = round.timeout / MultiGame.ROUND_TIMEOUT_DIVIDER;
 | 
			
		||||
        } else if (round.timeout > MultiGame.ROUND_TIMEOUT_MINIMUM) {
 | 
			
		||||
            round.timeout = MultiGame.ROUND_TIMEOUT_MINIMUM;
 | 
			
		||||
        }
 | 
			
		||||
        round.timeoutStarted = new Date();
 | 
			
		||||
        var self = this;
 | 
			
		||||
        round.timeoutHandler = setTimeout(function () {
 | 
			
		||||
            self._endRoundTimeout(room, round);
 | 
			
		||||
        }, round.timeout + MultiGame.ROUND_TIMEOUT_OFFSET);
 | 
			
		||||
 | 
			
		||||
        var member = room.members.get(token);
 | 
			
		||||
        var allResults = this._collectResultsInRound(room, round);
 | 
			
		||||
 | 
			
		||||
        this._broadcastTimeout(room, round);
 | 
			
		||||
        this._broadcastGuess(room, member.userName, guessPosition, distance, score);
 | 
			
		||||
 | 
			
		||||
        round.results.set(token, { guessPosition: guessPosition, distance: distance, score: score });
 | 
			
		||||
 | 
			
		||||
        this._setNewTimeout(room, round);
 | 
			
		||||
 | 
			
		||||
        return allResults;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -139,7 +126,7 @@ class MultiGame {
 | 
			
		||||
        round.timeoutStarted = new Date();
 | 
			
		||||
        var self = this;
 | 
			
		||||
        round.timeoutHandler = setTimeout(function () {
 | 
			
		||||
            self._endRoundTimeout(room, round);
 | 
			
		||||
            self._endRound(room, round);
 | 
			
		||||
        }, round.timeout + MultiGame.ROUND_TIMEOUT_OFFSET);
 | 
			
		||||
 | 
			
		||||
        var data = {};
 | 
			
		||||
@ -152,16 +139,35 @@ class MultiGame {
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    _endRoundTimeout(room, round) {
 | 
			
		||||
    _setNewTimeout(room, round) {
 | 
			
		||||
        clearTimeout(round.timeoutHandler);
 | 
			
		||||
 | 
			
		||||
        var data = { position: round.place.position, allResults: this._collectResultsInRound(room, round) };
 | 
			
		||||
        if (room.members.size === round.results.size) {
 | 
			
		||||
            round.timeout = 0;
 | 
			
		||||
            round.timeoutStarted = new Date();
 | 
			
		||||
 | 
			
		||||
            this._endRound(room, round);
 | 
			
		||||
        } else {
 | 
			
		||||
            round.timeout = round.timeout - (new Date() - round.timeoutStarted);
 | 
			
		||||
            if (round.timeout > MultiGame.ROUND_TIMEOUT_DIVIDER * MultiGame.ROUND_TIMEOUT_MINIMUM) {
 | 
			
		||||
                round.timeout = round.timeout / MultiGame.ROUND_TIMEOUT_DIVIDER;
 | 
			
		||||
            } else if (round.timeout > MultiGame.ROUND_TIMEOUT_MINIMUM) {
 | 
			
		||||
                round.timeout = MultiGame.ROUND_TIMEOUT_MINIMUM;
 | 
			
		||||
            }
 | 
			
		||||
            round.timeoutStarted = new Date();
 | 
			
		||||
            var self = this;
 | 
			
		||||
        room.members.forEach(function (member, token) {
 | 
			
		||||
            if (round.results.has(token)) {
 | 
			
		||||
                return;
 | 
			
		||||
            round.timeoutHandler = setTimeout(function () {
 | 
			
		||||
                self._endRound(room, round);
 | 
			
		||||
            }, round.timeout + MultiGame.ROUND_TIMEOUT_OFFSET);
 | 
			
		||||
 | 
			
		||||
            this._broadcastTimeout(room, round);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    _endRound(room, round) {
 | 
			
		||||
        var data = { position: round.place.position, allResults: this._collectResultsInRound(room, round) };
 | 
			
		||||
        var self = this;
 | 
			
		||||
        room.members.forEach(function (member) {
 | 
			
		||||
            self._sendToMember(member, 'end_round', data);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user