mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-07-27 13:57:02 -05:00
Revert "Hangman: Prevent impossible guesses and fix HTML escape (#8929)"
This reverts commit abca806d00.
This commit is contained in:
parent
9c5d654b89
commit
e170e51466
|
|
@ -7,9 +7,6 @@ import {FS, Utils} from '../../lib';
|
|||
const HANGMAN_FILE = 'config/chat-plugins/hangman.json';
|
||||
|
||||
const DIACRITICS_AFTER_UNDERSCORE = /_[\u0300-\u036f\u0483-\u0489\u0610-\u0615\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06ED\u0E31\u0E34-\u0E3A\u0E47-\u0E4E]+/g;
|
||||
const MAX_HANGMAN_LENGTH = 30;
|
||||
const MAX_INDIVIDUAL_WORD_LENGTH = 20;
|
||||
const MAX_HINT_LENGTH = 150;
|
||||
|
||||
interface HangmanEntry {
|
||||
hints: string[];
|
||||
|
|
@ -101,9 +98,7 @@ export class Hangman extends Rooms.SimpleRoomGame {
|
|||
if (normalized.length < 1) {
|
||||
throw new Chat.ErrorMessage(`Use "/guess [letter]" to guess a letter, or "/guess [phrase]" to guess the entire Hangman phrase.`);
|
||||
}
|
||||
if (sanitized.length > MAX_HANGMAN_LENGTH) {
|
||||
throw new Chat.ErrorMessage(`Guesses must be ${MAX_HANGMAN_LENGTH} or fewer letters – "${word}" is too long.`);
|
||||
}
|
||||
if (sanitized.length > 30) throw new Chat.ErrorMessage(`Guesses must be 30 or fewer letters – "${word}" is too long.`);
|
||||
|
||||
for (const guessid of this.guesses) {
|
||||
if (normalized === toID(guessid)) throw new Chat.ErrorMessage(`Your guess "${word}" has already been guessed.`);
|
||||
|
|
@ -155,15 +150,6 @@ export class Hangman extends Rooms.SimpleRoomGame {
|
|||
guessWord(word: string, guesser: string) {
|
||||
const ourWord = toID(this.word.replace(/[0-9]+/g, ''));
|
||||
const guessedWord = toID(word.replace(/[0-9]+/g, ''));
|
||||
|
||||
// Can't be a correct guess if the lengths don't match
|
||||
if (ourWord.length !== guessedWord.length) return false;
|
||||
|
||||
// Can't be a correct guess if the guess has incorrect letters in already guessed indexes
|
||||
for (let i = 0; i < ourWord.length; i++) {
|
||||
if (ourWord.charAt(i) !== '_' && ourWord.charAt(i) !== guessedWord.charAt(i)) return false;
|
||||
}
|
||||
|
||||
if (ourWord === guessedWord) {
|
||||
for (const [i, letter] of this.wordSoFar.entries()) {
|
||||
if (letter === '_') {
|
||||
|
|
@ -174,13 +160,15 @@ export class Hangman extends Rooms.SimpleRoomGame {
|
|||
this.guesses.push(word);
|
||||
this.lastGuesser = guesser;
|
||||
this.finish();
|
||||
} else {
|
||||
return true;
|
||||
} else if (ourWord.length === guessedWord.length) {
|
||||
this.incorrectGuesses++;
|
||||
this.guesses.push(word);
|
||||
this.lastGuesser = guesser;
|
||||
this.update();
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
hangingMan() {
|
||||
|
|
@ -213,7 +201,7 @@ export class Hangman extends Rooms.SimpleRoomGame {
|
|||
wordString = wordString.replace(DIACRITICS_AFTER_UNDERSCORE, '_');
|
||||
|
||||
if (this.hint) output += Utils.html`<div>(Hint: ${this.hint})</div>`;
|
||||
output += `<p style="font-weight:bold;font-size:12pt;letter-spacing:3pt">${Utils.escapeHTML(wordString)}</p>`;
|
||||
output += `<p style="font-weight:bold;font-size:12pt;letter-spacing:3pt">${wordString}</p>`;
|
||||
if (this.guesses.length) {
|
||||
if (this.letterGuesses.length) {
|
||||
output += 'Letters: ' + this.letterGuesses.map(
|
||||
|
|
@ -294,19 +282,15 @@ export class Hangman extends Rooms.SimpleRoomGame {
|
|||
const phrase = params[0].normalize('NFD').trim().replace(/_/g, '\uFF3F');
|
||||
|
||||
if (!phrase.length) throw new Chat.ErrorMessage("Enter a valid word");
|
||||
if (phrase.length > MAX_HANGMAN_LENGTH) {
|
||||
throw new Chat.ErrorMessage(`Phrase must be less than ${MAX_HANGMAN_LENGTH} characters long.`);
|
||||
}
|
||||
if (phrase.split(' ').some(w => w.length > MAX_INDIVIDUAL_WORD_LENGTH)) {
|
||||
throw new Chat.ErrorMessage(`Each word in the phrase must be less than ${MAX_INDIVIDUAL_WORD_LENGTH} characters long.`);
|
||||
if (phrase.length > 30) throw new Chat.ErrorMessage("Phrase must be less than 30 characters long.");
|
||||
if (phrase.split(' ').some(w => w.length > 20)) {
|
||||
throw new Chat.ErrorMessage("Each word in the phrase must be less than 20 characters long.");
|
||||
}
|
||||
if (!/[a-zA-Z]/.test(phrase)) throw new Chat.ErrorMessage("Word must contain at least one letter.");
|
||||
let hint;
|
||||
if (params.length > 1) {
|
||||
hint = params.slice(1).join(',').trim();
|
||||
if (hint.length > MAX_HINT_LENGTH) {
|
||||
throw new Chat.ErrorMessage(`Hint must be less than ${MAX_HINT_LENGTH} characters long.`);
|
||||
}
|
||||
if (hint.length > 150) throw new Chat.ErrorMessage("Hint too long.");
|
||||
}
|
||||
return {phrase, hint};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user