Skip to content

Commit

Permalink
Add command to take tactical timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
JensForstmann committed Jan 9, 2024
1 parent e3bf1c0 commit 5babc4b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
4 changes: 4 additions & 0 deletions backend/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ const Commands = [
'STAY',
'SWITCH',
'TEAM',
'TACTICAL',
'RESTART',
'VERSION',
'*',
] as const;
export type TCommand = (typeof Commands)[number];

// mapping from "ingame chat command" to "command enum"
const commandMapping = new Map<string, TCommand>();
commandMapping.set('ban', 'BAN');
commandMapping.set('pick', 'PICK');
Expand All @@ -35,11 +37,13 @@ commandMapping.set('unpause', 'READY');
commandMapping.set('unready', 'UNREADY');
commandMapping.set('unrdy', 'UNREADY');
commandMapping.set('pause', 'PAUSE');
commandMapping.set('tech', 'PAUSE');
commandMapping.set('help', 'HELP');
commandMapping.set('stay', 'STAY');
commandMapping.set('switch', 'SWITCH');
commandMapping.set('swap', 'SWITCH');
commandMapping.set('team', 'TEAM');
commandMapping.set('tac', 'TACTICAL');
commandMapping.set('restart', 'RESTART');
commandMapping.set('version', 'VERSION');

Expand Down
34 changes: 33 additions & 1 deletion backend/src/matchMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const getAvailableCommandsEnums = (state: TMatchMapSate): commands.TCommand[] =>
case 'FINISHED':
return [];
case 'IN_PROGRESS':
return ['PAUSE'];
return ['PAUSE', 'TACTICAL'];
case 'KNIFE':
return ['RESTART'];
case 'MAP_CHANGE':
Expand Down Expand Up @@ -392,6 +392,37 @@ const onPauseCommand: commands.CommandHandler = async (e) => {
await Match.execRcon(match, 'mp_pause_match');
};

const onTacticalCommand: commands.CommandHandler = async (e) => {
const matchMap = Match.getCurrentMatchMap(e.match);
if (!matchMap || e.match.data.state !== 'MATCH_MAP' || matchMap.state !== 'IN_PROGRESS') {
return;
}
const { match, player } = e;
if (e.teamString !== 'CT' && e.teamString !== 'TERRORIST') {
await Match.say(
match,
`${escapeRconString(player.name)} NEEDS TO BE IN A TEAM TO TAKE A TACTICAL TIMEOUT`
);
match.log(`${player.name} needs to be in a team to take a tactical timeout`);
return;
}
const command = e.teamString === 'CT' ? 'timeout_ct_start' : 'timeout_terrorist_start';
const response = await Match.execRcon(match, command);
if (response.trim().indexOf('Match pause is enabled') === -1) {
// could not take tactical pause
// either one is already requested, or one is in progress or no timeouts are left
return;
}
if (player.team) {
const team = Match.getTeamByAB(match, player.team);
await Match.say(match, `${escapeRconString(team.name)} TOOK A TACTICAL TIMEOUT`);
match.log(`${player.team} (${team.name} - ${player.name}) took a tactical timeout`);
} else {
await Match.say(match, `${escapeRconString(player.name)} TOOK A TACTICAL TIMEOUT`);
match.log(`${player.name} took a tactical timeout`);
}
};

const onStayCommand: commands.CommandHandler = async (e) => {
const enrichedEvent = await enrichEvent(e);
if (!enrichedEvent) {
Expand Down Expand Up @@ -484,6 +515,7 @@ export const registerCommandHandlers = () => {
commands.registerHandler('READY', onReadyCommand);
commands.registerHandler('UNREADY', onUnreadyCommand);
commands.registerHandler('PAUSE', onPauseCommand);
commands.registerHandler('TACTICAL', onTacticalCommand);
};

const enrichEvent = async (e: commands.CommandEvent) => {
Expand Down

0 comments on commit 5babc4b

Please sign in to comment.