Fix Confusion message grouping

This commit is contained in:
Guangcong Luo
2019-01-07 21:45:58 -06:00
parent fd5f54c99c
commit e489b36856
2 changed files with 26 additions and 5 deletions

View File

@@ -110,9 +110,13 @@ class BattleTextParser {
return {args, kwArgs};
}
extractMessage(line: string) {
const {args, kwArgs} = BattleTextParser.parseLine(line);
return this.parseArgs(args, kwArgs) || '';
extractMessage(buf: string) {
let out = '';
for (const line of buf.split('\n')) {
const {args, kwArgs} = BattleTextParser.parseLine(line);
out += this.parseArgs(args, kwArgs) || '';
}
return out;
}
fixLowercase(input: string) {
@@ -267,18 +271,22 @@ class BattleTextParser {
case '-damage': {
const id = BattleTextParser.effectId(kwArgs.from);
if (id === 'confusion') return 'major';
return 'postMajor';
}
case '-curestatus': {
const id = BattleTextParser.effectId(kwArgs.from);
if (id === 'naturalcure') return 'preMajor';
return 'postMajor';
}
case '-start': {
const id = BattleTextParser.effectId(kwArgs.from);
if (id === 'protean') return 'preMajor';
return 'postMajor';
}
case '-activate': {
const id = BattleTextParser.effectId(args[2]);
if (id === 'confusion' || id === 'attract') return 'preMajor';
return 'postMajor';
}
}
return (cmd.charAt(0) === '-' ? 'postMajor' : '');

View File

@@ -99,13 +99,26 @@ describe('Text parser', () => {
it('should process messages correctly', () => {
let parser = new BattleTextParser();
assert.equal(parser.extractMessage('|-activate|p2a: Cool.|move: Skill Swap|Speed Boost|Cute Charm|[of] p1a: Speedy'), ` [The opposing Cool.'s Speed Boost]
assert.equal(parser.extractMessage(`|-activate|p2a: Cool.|move: Skill Swap|Speed Boost|Cute Charm|[of] p1a: Speedy`), ` [The opposing Cool.'s Speed Boost]
[Speedy's Cute Charm]
The opposing Cool. swapped Abilities with its target!
`);
assert.equal(parser.extractMessage('|-activate|p2a: Cool.|move: Skill Swap|p1a: Speedy|[ability]Speed Boost|[ability2]Cute Charm'), ` [The opposing Cool.'s Speed Boost]
assert.equal(parser.extractMessage(`|-activate|p2a: Cool.|move: Skill Swap|p1a: Speedy|[ability]Speed Boost|[ability2]Cute Charm`), ` [The opposing Cool.'s Speed Boost]
[Speedy's Cute Charm]
The opposing Cool. swapped Abilities with its target!
`);
assert.equal(parser.extractMessage(`|move|p2a: Palkia|Swagger|p1a: Shroomish
|-boost|p1a: Shroomish|atk|2
|-start|p1a: Shroomish|confusion
|-activate|p1a: Shroomish|confusion
|move|p1a: Shroomish|Power-Up Punch|p2a: Palkia
`), `
The opposing Palkia used **Swagger**!
Shroomish's Attack rose sharply!
Shroomish became confused!
Shroomish is confused!
Shroomish used **Power-Up Punch**!
`);
});
});