Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/multi duel #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wizards-duel/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ var Effects = {
var resultantEffects;
do {
({ remainingEffects, resultantEffects } = this.getCombinationResults(allEffectNames, output, playerName));
console.log(remainingEffects, resultantEffects)
// console.log(remainingEffects, resultantEffects)
if (resultantEffects.length) {
allEffectNames = remainingEffects.concat(resultantEffects);
allNewEffectNames = allNewEffectNames.concat(resultantEffects);
Expand Down
7 changes: 6 additions & 1 deletion src/wizards-duel/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ class Manager {
}

duelEnded(challenger, challengee, results) {
// Should be Manager.setPlayerState(challenger, STATUS_NOT_DUELING) ?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would be better

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would be better

this.brain.set(Manager.getPlayerStateKey(challenger), STATUS_NOT_DUELING);
this.brain.set(Manager.getPlayerStateKey(challengee), STATUS_NOT_DUELING);
this.setDuelStatus(challenger, challengee, STATUS_NOT_DUELING);
Expand Down Expand Up @@ -285,7 +286,11 @@ class Manager {
}

acceptChallenge(challenger, challengee) {
if (this.getDuelStatus(challenger, challengee) === STATUS_CHALLENGE_SENT) {
var challengeeState = this.getPlayerState(challengee);
if (challengeeState) {
this.output.reply(`Thou art already dueling with @${challengeeState.opponent}!`);
}
else if (this.getDuelStatus(challenger, challengee) === STATUS_CHALLENGE_SENT) {
this.setInitialPlayerState(challenger, true, challengee);
this.setInitialPlayerState(challengee, false, challenger);
this.setDuelStatus(challenger, challengee, STATUS_DUELING);
Expand Down
54 changes: 44 additions & 10 deletions test/manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ var helper = new Helper('../src/wizards-duel.js');


describe('Manager', () => {
var message1 = 'I challenge @bob to a wizards duel!';
var message2 = 'I accept @alice\'s challenge';
var challengeMessage = 'I challenge @bob to a wizards duel!';
var acceptMessage = 'I accept @alice\'s challenge';

describe('Sending a Challenge', () => {
var room;

before((done) => {
room = helper.createRoom();
room.user.say('alice', message1).then(() => {
room.user.say('alice', challengeMessage).then(() => {
done();
});
});
Expand All @@ -28,7 +28,7 @@ describe('Manager', () => {

it('responds to challenges - messages', () => {
var expectedResult = [
['alice', message1],
['alice', challengeMessage],
['hubot', [
'@alice has challenged @bob to a wizard\'s duel! _Does @bob accept?_',
'Type "I accept @alice\'s challenge." to accept.'
Expand All @@ -43,7 +43,6 @@ describe('Manager', () => {

expect(room.robot.brain.data._private[duelKey]).to.eql(Manager.STATUS_CHALLENGE_SENT);
});

});

describe('Accepting a Challenge', () => {
Expand All @@ -52,8 +51,8 @@ describe('Manager', () => {

before((done) => {
room = helper.createRoom();
room.user.say('alice', message1).then(() => {
room.user.say('bob', message2).then(() => {
room.user.say('alice', challengeMessage).then(() => {
room.user.say('bob', acceptMessage).then(() => {
var turnKey = Manager.getTurnKey('alice', 'bob');
turnData = room.robot.brain.data._private[turnKey];
done();
Expand All @@ -72,7 +71,7 @@ describe('Manager', () => {
it('handles challenge accepting - messages', () => {
var startingPlayer = turnData.player;
var expectedLast2Messages = [
['bob', message2],
['bob', acceptMessage],
['hubot', [
'*Hear ye! Hear ye!*',
`A duel shall now commence between @alice and @bob! ` +
Expand All @@ -97,6 +96,41 @@ describe('Manager', () => {

});

describe('Accepting challenges during a duel', () => {
var room;
var turnData;

before((done) => {
room = helper.createRoom();
room.user.say('alice', challengeMessage).then(() => {
done();
});
});

after(() => {
room.destroy();
});

it('disallows accepting a challenge during a duel', () => {
// Alice already challenged Bob
// Bob challenges Alice
return room.user.say('bob', 'I challenge @alice to a wizards duel!').then(() => {
// Alice accepts Bob's challenge
return room.user.say('alice', 'I accept @bob\'s challenge').then(() => {
// Bob accepts Alice's challenge <-- Should fail
return room.user.say('bob', 'I accept @alice\'s challenge').then(() => {
var challengeResults = [
'hubot', '@bob Thou art already dueling with @alice!'
];

// Compare last message
expect(room.messages[room.messages.length - 1]).to.deep.equal(challengeResults);
});
});
});
});
});

describe('First attack applies effects and sets turn to next player', () => {
var room;
var firstPlayer;
Expand All @@ -114,8 +148,8 @@ describe('Manager', () => {
});

room = helper.createRoom();
room.user.say('alice', message1).then(() => {
room.user.say('bob', message2).then(() => {
room.user.say('alice', challengeMessage).then(() => {
room.user.say('bob', acceptMessage).then(() => {
var turnKey = Manager.getTurnKey('alice', 'bob');
var turnData = room.robot.brain.data._private[turnKey];
firstPlayer = turnData.player;
Expand Down