mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-15 17:12:59 -04:00
no duplicate reward slots
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -11,8 +11,8 @@
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
||||
<meta name="apple-mobile-web-app-title" content="Multi Roomba Rover" />
|
||||
<title>Multi Roomba Rover</title>
|
||||
<script type="module" crossorigin src="/assets/index-BaS9tmKz.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-DTYY_hd_.css">
|
||||
<script type="module" crossorigin src="/assets/index-C1njEZEY.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-7nrE9xLC.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
@@ -7,7 +7,7 @@ function randLetter() {
|
||||
module.exports = {
|
||||
id: 'chatSpam',
|
||||
name: 'Chat Spam',
|
||||
goal: 50,
|
||||
goal: 100,
|
||||
async run(ctx) {
|
||||
const nickname = randLetter();
|
||||
const messageCount = 100;
|
||||
|
||||
@@ -5,7 +5,7 @@ const { app } = require('../globals/http');
|
||||
const io = require('../globals/io');
|
||||
const logger = require('../globals/logger').child('buttonBoxService');
|
||||
const { publishEvent } = require('./eventBus');
|
||||
const { getRewardById, pickRandomReward } = require('../rewards');
|
||||
const { getRewardById, listRewards } = require('../rewards');
|
||||
const roverManager = require('./roverManager');
|
||||
const { issueCommand } = require('./commandService');
|
||||
const { sendAlert } = require('./alertService');
|
||||
@@ -108,9 +108,11 @@ function loadState() {
|
||||
|
||||
function ensureRewardAssignments() {
|
||||
if (!state) return;
|
||||
const seen = new Set();
|
||||
state.buttons.forEach((button) => {
|
||||
const reward = getRewardById(button.rewardId);
|
||||
if (reward) {
|
||||
if (reward && !seen.has(reward.id)) {
|
||||
seen.add(reward.id);
|
||||
button.rewardName = reward.name || null;
|
||||
button.rewardNumber = reward.number;
|
||||
button.goal = reward.goal;
|
||||
@@ -120,14 +122,27 @@ function ensureRewardAssignments() {
|
||||
return;
|
||||
}
|
||||
assignNewReward(button);
|
||||
if (button.rewardId) {
|
||||
seen.add(button.rewardId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function assignNewReward(button) {
|
||||
const reward = pickRandomReward(button?.rewardId || null) || pickRandomReward(null);
|
||||
if (!reward) {
|
||||
throw new Error('No rewards configured');
|
||||
}
|
||||
const allRewards = listRewards();
|
||||
if (!allRewards.length) throw new Error('No rewards configured');
|
||||
|
||||
const usedByOtherButtons = new Set(
|
||||
state.buttons
|
||||
.filter((entry) => entry.id !== button.id)
|
||||
.map((entry) => entry.rewardId)
|
||||
.filter((rewardId) => typeof rewardId === 'string' && rewardId.length > 0),
|
||||
);
|
||||
const uniqueCandidates = allRewards.filter((reward) => !usedByOtherButtons.has(reward.id));
|
||||
const pool = uniqueCandidates.length ? uniqueCandidates : allRewards;
|
||||
const reward = pool[Math.floor(Math.random() * pool.length)] || null;
|
||||
if (!reward) throw new Error('No rewards configured');
|
||||
|
||||
button.rewardId = reward.id;
|
||||
button.rewardName = reward.name || null;
|
||||
button.rewardNumber = reward.number;
|
||||
|
||||
Reference in New Issue
Block a user