Spaces:
Sleeping
Sleeping
assign random role with probs
Browse files
convex/world.ts
CHANGED
@@ -22,6 +22,10 @@ export const defaultWorldStatus = query({
|
|
22 |
return worldStatus;
|
23 |
},
|
24 |
});
|
|
|
|
|
|
|
|
|
25 |
|
26 |
export const heartbeatWorld = mutation({
|
27 |
args: {
|
@@ -155,7 +159,9 @@ export const joinWorld = mutation({
|
|
155 |
);
|
156 |
|
157 |
const randomCharacter = availableDescriptions[Math.floor(Math.random() * availableDescriptions.length)];
|
158 |
-
|
|
|
|
|
159 |
// const { tokenIdentifier } = identity;
|
160 |
return await insertInput(ctx, world._id, 'join', {
|
161 |
name: randomCharacter.name,
|
@@ -164,7 +170,7 @@ export const joinWorld = mutation({
|
|
164 |
// description: `${identity.givenName} is a human player`,
|
165 |
tokenIdentifier: oauthToken, // TODO: change for multiplayer to oauth
|
166 |
// By default everybody is a villager
|
167 |
-
type:
|
168 |
});
|
169 |
},
|
170 |
});
|
|
|
22 |
return worldStatus;
|
23 |
},
|
24 |
});
|
25 |
+
function assignRole(): 'villager' | 'werewolf' {
|
26 |
+
const randomNum = Math.random();
|
27 |
+
return randomNum < 0.7 ? 'villager' : 'werewolf';
|
28 |
+
}
|
29 |
|
30 |
export const heartbeatWorld = mutation({
|
31 |
args: {
|
|
|
159 |
);
|
160 |
|
161 |
const randomCharacter = availableDescriptions[Math.floor(Math.random() * availableDescriptions.length)];
|
162 |
+
// Assign role with probability
|
163 |
+
const role = assignRole();
|
164 |
+
console.log("assignin : ", role)
|
165 |
// const { tokenIdentifier } = identity;
|
166 |
return await insertInput(ctx, world._id, 'join', {
|
167 |
name: randomCharacter.name,
|
|
|
170 |
// description: `${identity.givenName} is a human player`,
|
171 |
tokenIdentifier: oauthToken, // TODO: change for multiplayer to oauth
|
172 |
// By default everybody is a villager
|
173 |
+
type: role,
|
174 |
});
|
175 |
},
|
176 |
});
|
src/components/buttons/InteractButton.tsx
CHANGED
@@ -57,6 +57,7 @@ export default function InteractButton() {
|
|
57 |
if (isPlaying) {
|
58 |
console.log(`Leaving game for player ${userPlayerId}`);
|
59 |
void leave({ worldId , oauthToken});
|
|
|
60 |
game.world.players.delete(userPlayerId);
|
61 |
} else {
|
62 |
console.log(`Joining game`);
|
|
|
57 |
if (isPlaying) {
|
58 |
console.log(`Leaving game for player ${userPlayerId}`);
|
59 |
void leave({ worldId , oauthToken});
|
60 |
+
console.log("game.world.players",game.world.players)
|
61 |
game.world.players.delete(userPlayerId);
|
62 |
} else {
|
63 |
console.log(`Joining game`);
|