Skip to content

Commit

Permalink
Battle: Support for 'best of n' game rule
Browse files Browse the repository at this point in the history
- Prevent the bot from leaving the 'game-' rooms early.
- Auto accept the next rounds.
  • Loading branch information
AgustinSRG committed Nov 7, 2023
1 parent bc26e81 commit f4cd21c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/bot-modules/battle/battle-ai/battle-majors.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,5 +448,13 @@ exports.setup = function (App, BattleData) {
}
this.makeDecision(true);
},

cantleave: function () {
this.leaveForbidden = true;
},

allowleave: function () {
this.leaveForbidden = false;
},
};
};
10 changes: 9 additions & 1 deletion src/bot-modules/battle/battle-ai/battle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

const MAX_RECURSIVE = 5;
const MIN_TIME_LOCK = 3 * 1000; // 3 secods to avoid send spam
const MIN_TIME_LOCK = 3 * 1000; // 3 seconds to avoid send spam

const Path = require('path');
const Util = require('util');
Expand Down Expand Up @@ -79,6 +79,7 @@ exports.setup = function (App, CustomModules) {
rqid: -1,
bp: 50,
};
this.leaveForbidden = false;
}

send(data) {
Expand Down Expand Up @@ -208,6 +209,10 @@ exports.setup = function (App, CustomModules) {
}

leave() {
if (this.leaveForbidden) {
this.send("/confirmready");
return;
}
if (!this.leaveInterval) {
this.leaveInterval = setInterval(function () {
this.send("/leave");
Expand All @@ -217,6 +222,9 @@ exports.setup = function (App, CustomModules) {
}

leaveBattle() {
if (this.id.indexOf("game-") === 0) {
return;
}
this.send('/leavebattle');
}

Expand Down

0 comments on commit f4cd21c

Please sign in to comment.