-
Notifications
You must be signed in to change notification settings - Fork 18
Group Matching V7
Group matching consist in assigning roles to players in the same group.
Currently the Matcher API supports automatic matching for pairs only, but it easy to assign roles in larger groups.
Ideally, you place this stage right before the stages in which roles are needed.
File: game.stages.js
// ... previus steps.
stager.stage('assignRoles')
// ... steps in which roles are needed.
In this example, we randomly assign role "BIDDER" to one player and role "RESPONDER" to the others.
File: logic.js
stager.extendStep('assignRoles', {
cb: function() {
// Prepare for role assignment.
let counter = 0;
let roles = [ 'BIDDER', 'RESPONDER' ];
// Random idx for role BIDDER.
let R = J.randomInt(node.game.playerList.size());
// Loop through connected players and send a message with role.
node.game.playerList.each(player => {
// Draw role and send message.
let role = ++counter === R ? roles[0] : roles[1];
node.say("ROLE", player.id, role);
// Reconnecting clients receive role automatically.
node.game.matcher.lastMatchesById[player.id] = {
role: role
};
});
}
});
The player waiting for role assignment must first set its own role in step 'assignRoles', and then carry over the role in the next step, where it is needed.
File: player.js
stager.extendStep('assignRoles', {
cb: function() {
node.on.data('ROLE', msg => {
// Manually set role.
this.role = msg.data;
// Mark done, so it can go to next step.
node.done();
})
}
});
stager.extendStage('stage_with_roles', {
// This line carries over the role set in previous stage.
role: function() { return this.role; }
// ...other step properties as needed (e.g., property roles must be set).
});
Go back to the wiki Home.
Copyright (C) 2021 Stefano Balietti
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.