1
0
mirror of https://gitlab.com/Deukhoofd/BattleSim.git synced 2025-10-27 18:00:03 +00:00

Lots of stuff

This commit is contained in:
Deukhoofd
2016-02-01 23:19:30 +01:00
commit d7316d5799
6681 changed files with 527969 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
require '../../helpers'
{BattleServer} = require('../../../server/server')
{User} = require('../../../server/user')
{Conditions} = require '../../../shared/conditions'
{Factory} = require '../../factory'
should = require('should')
generateTeam = ->
[ Factory("Magikarp")
Factory("Gyarados")
Factory('Hitmonchan')
Factory("Celebi")
Factory("Blissey")
Factory("Alakazam") ]
describe 'Validations: Evasion Clause', ->
it "returns an error if a pokemon has an evasion move", ->
server = new BattleServer()
format = 'xy1000'
team = generateTeam()
team[0] = Factory("Umbreon", moves: [ "Double Team" ])
conditions = [ Conditions.EVASION_CLAUSE ]
server.validateTeam(team, format, conditions).should.not.be.empty
it "returns an error if a pokemon has a banned evasion ability", ->
server = new BattleServer()
format = 'xy1000'
team = generateTeam()
team[0] = Factory("Smeargle", ability: "Moody", moves: [ "Sketch" ])
conditions = [ Conditions.EVASION_CLAUSE ]
server.validateTeam(team, format, conditions).should.not.be.empty
it "returns no error if no pokemon has an evasion move", ->
server = new BattleServer()
format = 'xy1000'
team = generateTeam()
team[0] = Factory("Magikarp", moves: [ "Splash" ])
team[1] = Factory("Gyarados", moves: [ "Dragon Dance" ])
conditions = [ Conditions.EVASION_CLAUSE ]
server.validateTeam(team, format, conditions).should.be.empty
it "ignores invalid moves", ->
server = new BattleServer()
format = 'xy1000'
team = generateTeam()
team[0] = Factory("Magikarp", moves: [ "GHOSTFACE KILLAH" ])
team[1] = Factory("Gyarados", moves: [ "Dragon Dance" ])
conditions = [ Conditions.EVASION_CLAUSE ]
(-> server.validateTeam(team, format, conditions)).should.not.throw()

View File

@@ -0,0 +1,45 @@
require '../../helpers'
{BattleServer} = require('../../../server/server')
{User} = require('../../../server/user')
{Conditions} = require '../../../shared/conditions'
{Factory} = require '../../factory'
should = require('should')
generateTeam = ->
[ Factory("Magikarp")
Factory("Gyarados")
Factory('Hitmonchan')
Factory("Celebi")
Factory("Blissey")
Factory("Alakazam") ]
describe 'Validations: OHKO Clause', ->
it "returns an error if a pokemon has an OHKO move", ->
server = new BattleServer()
format = 'xy1000'
team = generateTeam()
team[0] = Factory("Lapras", moves: [ "Surf", "Sheer Cold" ])
conditions = [ Conditions.OHKO_CLAUSE ]
server.validateTeam(team, format, conditions).should.not.be.empty
it "returns no error if no pokemon has an evasion move", ->
server = new BattleServer()
format = 'xy1000'
team = generateTeam()
team[0] = Factory("Magikarp", moves: [ "Splash" ])
team[1] = Factory("Gyarados", moves: [ "Dragon Dance" ])
conditions = [ Conditions.OHKO_CLAUSE ]
server.validateTeam(team, format, conditions).should.be.empty
it "ignores invalid moves", ->
server = new BattleServer()
format = 'xy1000'
team = generateTeam()
team[0] = Factory("Magikarp", moves: [ "GHOSTFACE KILLAH" ])
team[1] = Factory("Gyarados", moves: [ "Dragon Dance" ])
conditions = [ Conditions.OHKO_CLAUSE ]
(-> server.validateTeam(team, format, conditions)).should.not.throw()

View File

@@ -0,0 +1,53 @@
require '../../helpers'
{BattleServer} = require('../../../server/server')
{User} = require('../../../server/user')
pbv = require('../../../shared/pokebattle_values')
{Factory} = require '../../factory'
should = require('should')
describe 'Validations: PBV 1000', ->
it "returns an error if the team is over 1000 PBV", ->
server = new BattleServer()
format = 'xy1000'
team = [ Factory("Arceus", move: "Recover")
Factory("Gyarados")
Factory('Hitmonchan')
Factory("Celebi")
Factory("Blissey")
Factory("Alakazam") ]
server.validateTeam(team, format).should.not.be.empty
it "returns an error if the team has under 6 pokemon", ->
server = new BattleServer()
format = 'xy1000'
team = [ Factory("Magikarp", moves: [ "Splash" ]) ]
server.validateTeam(team, format).should.not.be.empty
it "returns an error if the team has a pokemon that's over 1/3 the cap", ->
server = new BattleServer()
format = 'xy1000'
team = [ Factory("Magikarp")
Factory("Gyarados")
Factory('Hitmonchan')
Factory("Celebi")
Factory("Blissey")
Factory("Alakazam") ]
stub = @sandbox.stub(pbv, 'determinePBV', -> 335)
server.validateTeam(team, format).should.not.be.empty
it "returns no error if the team is under 1000 PBV", ->
server = new BattleServer()
format = 'xy1000'
team = [ Factory("Magikarp")
Factory("Gyarados")
Factory('Hitmonchan')
Factory("Celebi")
Factory("Blissey")
Factory("Alakazam") ]
server.validateTeam(team, format).should.be.empty

View File

@@ -0,0 +1,53 @@
require '../../helpers'
{BattleServer} = require('../../../server/server')
{User} = require('../../../server/user')
pbv = require('../../../shared/pokebattle_values')
{Factory} = require '../../factory'
should = require('should')
describe 'Validations: PBV 500', ->
it "returns an error if the team is over 500 PBV", ->
server = new BattleServer()
format = 'xy500'
team = [ Factory("Arceus", move: "Recover")
Factory("Gyarados")
Factory('Hitmonchan')
Factory("Celebi")
Factory("Blissey")
Factory("Alakazam") ]
server.validateTeam(team, format).should.not.be.empty
it "returns an error if the team has under 6 pokemon", ->
server = new BattleServer()
format = 'xy500'
team = [ Factory("Magikarp", moves: [ "Splash" ]) ]
server.validateTeam(team, format).should.not.be.empty
it "returns an error if the team has a pokemon that's over 1/3 the cap", ->
server = new BattleServer()
format = 'xy500'
team = [ Factory("Magikarp")
Factory("Gyarados")
Factory('Hitmonchan')
Factory("Celebi")
Factory("Blissey")
Factory("Alakazam") ]
stub = @sandbox.stub(pbv, 'determinePBV', -> 170)
server.validateTeam(team, format).should.not.be.empty
it "returns no error if the team is under 500 PBV", ->
server = new BattleServer()
format = 'xy500'
team = [ Factory("Magikarp")
Factory("Unown", moves: ['Hidden Power'])
Factory('Hitmonchan', moves: ['Mach Punch'])
Factory("Abra", moves: ['Psychic'])
Factory("Froakie", moves: ['Surf'])
Factory("Raticate", moves: ['Tackle']) ]
server.validateTeam(team, format).should.be.empty

View File

@@ -0,0 +1,32 @@
require '../../helpers'
{BattleServer} = require('../../../server/server')
{User} = require('../../../server/user')
{Conditions} = require '../../../shared/conditions'
{Factory} = require '../../factory'
should = require('should')
generateTeam = ->
[ Factory("Magikarp")
Factory("Gyarados")
Factory('Hitmonchan')
Factory("Celebi")
Factory("Blissey")
Factory("Alakazam") ]
describe 'Validations: Prankster + Swagger', ->
it "returns an error if the team has a Pokemon with Prankster + Swagger", ->
server = new BattleServer()
format = 'xy1000'
team = generateTeam()
team[0] = Factory("Sableye", ability: "Prankster", moves: [ "Swagger" ])
conditions = [ Conditions.PRANKSTER_SWAGGER_CLAUSE ]
server.validateTeam(team, format, conditions).should.not.be.empty
it "returns no error if the team has no Prankster + Swagger Pokemon", ->
server = new BattleServer()
format = 'xy1000'
conditions = [ Conditions.PRANKSTER_SWAGGER_CLAUSE ]
server.validateTeam(generateTeam(), format, conditions).should.be.empty

View File

@@ -0,0 +1,95 @@
require '../../helpers'
shared = require '../../shared'
{Conditions} = require '../../../shared/conditions'
{Attachment, Status} = require '../../../server/bw/attachment'
{Protocol} = require '../../../shared/protocol'
{Factory} = require '../../factory'
describe "Sleep Clause", ->
it "prevents Sleep if the opponent was already slept by this team", ->
conditions = [ Conditions.SLEEP_CLAUSE ]
team1 = [ Factory("Magikarp"), Factory("Magikarp") ]
team2 = [ Factory("Magikarp"), Factory("Magikarp") ]
shared.create.call(this, {conditions, team1, team2})
spore = @battle.getMove("Spore")
@battle.performMove(@p1, spore)
@battle.performSwitch(@p2, 1)
mock = @sandbox.mock(spore).expects('fail').once()
@battle.performMove(@p1, spore)
mock.verify()
@team2.at(0).has(Status.Sleep).should.be.false
@team2.at(1).has(Status.Sleep).should.be.true
it "prevents Sleep from Yawn", ->
conditions = [ Conditions.SLEEP_CLAUSE ]
team1 = [ Factory("Magikarp"), Factory("Magikarp") ]
team2 = [ Factory("Magikarp"), Factory("Magikarp") ]
shared.create.call(this, {conditions, team1, team2})
yawn = @battle.getMove("Yawn")
@battle.performMove(@p1, yawn)
@battle.endTurn()
@battle.endTurn()
@battle.performSwitch(@p2, 1)
@battle.performMove(@p1, yawn)
@battle.endTurn()
@battle.endTurn()
@team2.at(0).has(Status.Sleep).should.be.false
@team2.at(1).has(Status.Sleep).should.be.true
it "doesn't prevent other statuses", ->
conditions = [ Conditions.SLEEP_CLAUSE ]
team1 = [ Factory("Magikarp"), Factory("Magikarp") ]
team2 = [ Factory("Magikarp"), Factory("Magikarp") ]
shared.create.call(this, {conditions, team1, team2})
thunderWave = @battle.getMove("Thunder Wave")
@battle.performMove(@p1, thunderWave)
@battle.performSwitch(@p2, 1)
mock = @sandbox.mock(thunderWave).expects('fail').never()
@battle.performMove(@p1, thunderWave)
mock.verify()
@team2.at(0).has(Status.Paralyze).should.be.true
@team2.at(1).has(Status.Paralyze).should.be.true
it "doesn't prevent Sleep if the opponent was slept, but not by this team", ->
conditions = [ Conditions.SLEEP_CLAUSE ]
team1 = [ Factory("Magikarp"), Factory("Magikarp") ]
team2 = [ Factory("Magikarp"), Factory("Magikarp") ]
shared.create.call(this, {conditions, team1, team2})
@team2.at(1).attach(Status.Sleep)
spore = @battle.getMove("Spore")
mock = @sandbox.mock(spore).expects('fail').never()
@battle.performMove(@p1, spore)
mock.verify()
@team2.at(0).has(Status.Sleep).should.be.true
@team2.at(1).has(Status.Sleep).should.be.true
it "doesn't prevent Sleep if the opponent was slept, but fainted", ->
conditions = [ Conditions.SLEEP_CLAUSE ]
team1 = [ Factory("Magikarp"), Factory("Magikarp") ]
team2 = [ Factory("Magikarp"), Factory("Magikarp") ]
shared.create.call(this, {conditions, team1, team2})
spore = @battle.getMove("Spore")
@battle.performMove(@p1, spore)
@battle.performSwitch(@p2, 1)
@p2.faint()
mock = @sandbox.mock(spore).expects('fail').never()
@battle.performMove(@p1, spore)
mock.verify()
@team2.at(0).has(Status.Sleep).should.be.true

View File

@@ -0,0 +1,34 @@
require '../../helpers'
{BattleServer} = require('../../../server/server')
{User} = require('../../../server/user')
{Conditions} = require '../../../shared/conditions'
{Factory} = require '../../factory'
should = require('should')
generateTeam = ->
[ Factory("Magikarp")
Factory("Gyarados")
Factory('Hitmonchan')
Factory("Celebi")
Factory("Blissey")
Factory("Alakazam") ]
describe 'Validations: Species Clause', ->
it "returns an error if the team has more than one of the same species", ->
server = new BattleServer()
format = 'xy1000'
team = generateTeam()
team[0] = Factory("Rotom", forme: "wash")
team[1] = Factory("Rotom", forme: "heat")
conditions = [ Conditions.SPECIES_CLAUSE ]
server.validateTeam(team, format, conditions).should.not.be.empty
it "returns no error if the team shares no species", ->
server = new BattleServer()
format = 'xy1000'
team = generateTeam()
conditions = [ Conditions.SPECIES_CLAUSE ]
server.validateTeam(team, format, conditions).should.be.empty

View File

@@ -0,0 +1,136 @@
require '../../helpers'
shared = require '../../shared'
{Conditions} = require '../../../shared/conditions'
{Protocol} = require '../../../shared/protocol'
{Factory} = require '../../factory'
describe "Team preview", ->
it "starts the battle by passing team info and requesting team order", ->
conditions = [ Conditions.TEAM_PREVIEW ]
team1 = [ Factory("Magikarp") ]
team2 = [ Factory("Magikarp") ]
shared.build(this, {conditions, team1, team2})
mock = @sandbox.mock(@battle).expects('startBattle').never()
spy = @sandbox.spy(@battle, 'tell')
@controller.beginBattle()
mock.verify()
spy.calledWith(Protocol.TEAM_PREVIEW).should.be.true
it "waits until all players have arranged their teams before starting", ->
conditions = [ Conditions.TEAM_PREVIEW ]
team1 = [ Factory("Magikarp") ]
team2 = [ Factory("Magikarp") ]
shared.build(this, {conditions, team1, team2})
mock = @sandbox.mock(@battle).expects('startBattle').never()
@controller.beginBattle()
@controller.arrangeTeam(@id1, [ 0 ])
mock.verify()
@battle.startBattle.restore()
mock = @sandbox.mock(@battle).expects('startBattle').once()
@controller.arrangeTeam(@id2, [ 0 ])
mock.verify()
it "rejects team arrangements that aren't arrays", ->
conditions = [ Conditions.TEAM_PREVIEW ]
team1 = [ Factory("Magikarp") ]
team2 = [ Factory("Magikarp") ]
shared.create.call(this, {conditions, team1, team2})
arrangement = true
@controller.arrangeTeam(@id1, arrangement).should.be.false
it "accepts arrays of integers (arrangements) matching team length", ->
conditions = [ Conditions.TEAM_PREVIEW ]
team1 = [ Factory("Magikarp") ]
team2 = [ Factory("Magikarp") ]
shared.create.call(this, {conditions, team1, team2})
arrangement = [ 0 ]
@controller.arrangeTeam(@id1, arrangement).should.be.true
it "rejects team arrangements that are smaller than the team length", ->
conditions = [ Conditions.TEAM_PREVIEW ]
team1 = [ Factory("Magikarp") ]
team2 = [ Factory("Magikarp") ]
shared.create.call(this, {conditions, team1, team2})
arrangement = []
@controller.arrangeTeam(@id1, arrangement).should.be.false
it "rejects team arrangements that are larger than the team length", ->
conditions = [ Conditions.TEAM_PREVIEW ]
team1 = [ Factory("Magikarp") ]
team2 = [ Factory("Magikarp") ]
shared.create.call(this, {conditions, team1, team2})
arrangement = [ 0, 1 ]
@controller.arrangeTeam(@id1, arrangement).should.be.false
it "rejects team arrangements containing negative indices", ->
conditions = [ Conditions.TEAM_PREVIEW ]
team1 = [ Factory("Magikarp") ]
team2 = [ Factory("Magikarp") ]
shared.create.call(this, {conditions, team1, team2})
arrangement = [ -1 ]
@controller.arrangeTeam(@id1, arrangement).should.be.false
it "rejects team arrangements containing indices out of bounds", ->
conditions = [ Conditions.TEAM_PREVIEW ]
team1 = [ Factory("Magikarp") ]
team2 = [ Factory("Magikarp") ]
shared.create.call(this, {conditions, team1, team2})
arrangement = [ 1 ]
@controller.arrangeTeam(@id1, arrangement).should.be.false
it "rejects team arrangements containing non-unique indices", ->
conditions = [ Conditions.TEAM_PREVIEW ]
team1 = (Factory("Magikarp") for x in [0..1])
shared.create.call(this, {conditions, team1})
arrangement = [ 1, 1 ]
@controller.arrangeTeam(@id1, arrangement).should.be.false
it "rejects team arrangements that have some non-numbers", ->
conditions = [ Conditions.TEAM_PREVIEW ]
team1 = (Factory("Magikarp") for x in [0..1])
shared.create.call(this, {conditions, team1})
arrangement = [ 1, "a" ]
@controller.arrangeTeam(@id1, arrangement).should.be.false
it "rejects team arrangements that don't point to a correct index", ->
conditions = [ Conditions.TEAM_PREVIEW ]
team1 = (Factory("Magikarp") for x in [0..1])
shared.create.call(this, {conditions, team1})
arrangement = [ 1, .5 ]
@controller.arrangeTeam(@id1, arrangement).should.be.false
it "rejects team arrangements if the battle has already begun", ->
conditions = [ Conditions.TEAM_PREVIEW ]
team1 = (Factory("Magikarp") for x in [0..1])
shared.create.call(this, {conditions, team1})
arrangement = [ 1, 0 ]
@controller.arrangeTeam(@id1, arrangement)
@controller.arrangeTeam(@id2, arrangement)
@controller.arrangeTeam(@id1, arrangement).should.be.false
it "rearranges team when given a valid array of indices", ->
conditions = [ Conditions.TEAM_PREVIEW ]
team1 = [ Factory("Magikarp"), Factory("Gyarados"), Factory("Celebi") ]
team2 = [ Factory("Magikarp"), Factory("Gyarados"), Factory("Celebi") ]
shared.create.call(this, {conditions, team1, team2})
@controller.arrangeTeam(@id1, [ 0, 2, 1 ])
@controller.arrangeTeam(@id2, [ 2, 0, 1 ])
@team1.at(0).species.should.equal("Magikarp")
@team1.at(1).species.should.equal("Celebi")
@team1.at(2).species.should.equal("Gyarados")
@team2.at(0).species.should.equal("Celebi")
@team2.at(1).species.should.equal("Magikarp")
@team2.at(2).species.should.equal("Gyarados")
it "is isomorphic", ->
conditions = [ Conditions.TEAM_PREVIEW ]
team1 = [ Factory("Magikarp"), Factory("Gyarados"), Factory("Celebi") ]
team2 = [ Factory("Magikarp"), Factory("Gyarados"), Factory("Celebi") ]
arrangedTeamNames = [ "Celebi", "Magikarp", "Gyarados" ]
shared.create.call(this, {conditions, team1, team2})
@controller.arrangeTeam(@id1, [ 2, 0, 1 ])
@controller.arrangeTeam(@id1, [ 2, 0, 1 ])
@controller.arrangeTeam(@id2, [ 2, 0, 1 ])
@team1.pokemon.map((p) -> p.species).should.eql(arrangedTeamNames)

View File

@@ -0,0 +1,190 @@
require '../../helpers'
{_} = require 'underscore'
shared = require '../../shared'
{Conditions} = require '../../../shared/conditions'
{Protocol} = require '../../../shared/protocol'
describe "Battle timer", ->
describe "without team preview", ->
beforeEach ->
@clock.tick(10000)
shared.create.call this,
conditions: [ Conditions.TIMED_BATTLE ]
@battle.TIMER_CAP = Infinity
it "starts a timer that ends the battle in 5 minutes", ->
@battle.isOver().should.be.false
delta = 100
@clock.tick(@battle.DEFAULT_TIMER - delta)
@battle.isOver().should.be.false
@clock.tick(delta)
@battle.isOver().should.be.true
it "declares a timer win for the player that didn't run out of time", ->
@battle.playerTimes[@id1] += 1000
spy = @sandbox.spy(@battle, 'tell')
@clock.tick(@battle.DEFAULT_TIMER)
index1 = @battle.getPlayerIndex(@id1)
spy.calledWith(Protocol.TIMER_WIN, index1).should.be.true
it "increases time remaining by 20 seconds for each player each turn", ->
@battle.timeRemainingFor(@id1).should.equal(@battle.DEFAULT_TIMER)
@battle.beginTurn()
delta = @battle.TIMER_PER_TURN_INCREASE
@battle.timeRemainingFor(@id1).should.equal(@battle.DEFAULT_TIMER + delta)
@battle.timeRemainingFor(@id2).should.equal(@battle.DEFAULT_TIMER + delta)
@battle.beginTurn()
delta *= 2
@battle.timeRemainingFor(@id1).should.equal(@battle.DEFAULT_TIMER + delta)
@battle.timeRemainingFor(@id2).should.equal(@battle.DEFAULT_TIMER + delta)
it "recalculates timer after increasing time remaining", ->
@battle.beginTurn()
delta = @battle.TIMER_PER_TURN_INCREASE
spy = @sandbox.spy(@battle, 'tell')
@clock.tick(@battle.DEFAULT_TIMER + delta / 2)
spy.calledWith(Protocol.TIMER_WIN).should.be.false
@clock.tick(delta / 2)
spy.calledWith(Protocol.TIMER_WIN).should.be.true
it "stops timer for players who have moved", ->
delta = 5000
@battle.timeRemainingFor(@id1).should.equal(@battle.DEFAULT_TIMER)
@battle.timeRemainingFor(@id2).should.equal(@battle.DEFAULT_TIMER)
@clock.tick(delta)
@battle.timeRemainingFor(@id1).should.equal(@battle.DEFAULT_TIMER - delta)
@battle.timeRemainingFor(@id2).should.equal(@battle.DEFAULT_TIMER - delta)
@battle.recordMove(@id1, @battle.getMove("Splash"))
@clock.tick(delta)
@battle.timeRemainingFor(@id1).should.equal(@battle.DEFAULT_TIMER - delta)
@battle.timeRemainingFor(@id2).should.equal(@battle.DEFAULT_TIMER - 2 * delta)
it "recalculates the timer after a player chooses an action", ->
delta = 4000
# give player 2 more time
@battle.playerTimes[@id2] += delta
@battle.recordMove(@id1, @battle.getMove("Splash"))
spy = @sandbox.spy(@battle, 'tell')
@clock.tick(@battle.DEFAULT_TIMER)
spy.calledWith(Protocol.TIMER_WIN).should.be.false
@clock.tick(delta)
spy.calledWith(Protocol.TIMER_WIN).should.be.true
it "grants time if player selected a move before the battle continued", ->
@clock.tick(2500)
spy = @sandbox.spy(@battle, 'requestActions')
@controller.makeMove(@id1, "Splash")
# 5 seconds after the player moves, the battle progresses
@clock.tick(5000)
@controller.makeMove(@id2, "Splash")
(@battle.DEFAULT_TIMER + @battle.TIMER_PER_TURN_INCREASE -
@battle.timeRemainingFor(@id1)).should.equal(2500)
# Turn has progressed. Make another move and check the time.
@clock.tick(2500)
@controller.makeMove(@id1, "Splash")
@clock.tick(5000)
@controller.makeMove(@id2, "Splash")
(@battle.DEFAULT_TIMER + 2 * @battle.TIMER_PER_TURN_INCREASE -
@battle.timeRemainingFor(@id1)).should.equal(5000)
it "ends battle if canceling after which they'd lose to timer", ->
# So the second player won't trigger the end condition.
@battle.playerTimes[@id2] += 4000
@clock.tick(2500)
@controller.makeMove(@id1, "Splash")
@clock.tick(@battle.DEFAULT_TIMER)
mock = @sandbox.mock(@battle).expects('timerWin').once()
@controller.undoCompletedRequest(@id1)
@battle.timeRemainingFor(@id1).should.equal(-2500)
mock.verify()
it "sends timer updates when battle enters a new turn", ->
@battle.recordMove(@id1, @battle.getMove("Splash"))
@battle.recordMove(@id2, @battle.getMove("Splash"))
spy = @sandbox.spy(@battle, 'send')
@battle.continueTurn()
spy.calledWith('updateTimers').should.be.false
@battle.beginTurn()
spy.calledWith('updateTimers').should.be.true
it "gets cleared if the battle ends prematurely", ->
@battle.endBattle()
mock = @sandbox.mock(@battle).expects('timerWin').never()
@clock.tick(@battle.DEFAULT_TIMER)
mock.verify()
it "has a cap every time a new turn begins", ->
@battle.TIMER_CAP = @battle.DEFAULT_TIMER
@clock.tick(@battle.TIMER_PER_TURN_INCREASE >> 1)
@battle.beginTurn()
@battle.timeRemainingFor(@id1).should.equal(@battle.TIMER_CAP)
it "has a cap every time a player gains time after a new action request", ->
@battle.TIMER_CAP = @battle.DEFAULT_TIMER
@battle.recordMove(@id1, @battle.getMove("U-turn"))
@clock.tick(@battle.TIMER_PER_TURN_INCREASE >> 1)
@battle.continueTurn()
@battle.timeRemainingFor(@id1).should.equal(@battle.TIMER_CAP)
it "recalculates timer every time an action is requested", ->
# Player 2 has more time.
delta = 4000
@battle.playerTimes[@id2] += delta
@battle.recordMove(@id2, @battle.getMove("U-turn"))
@battle.recordMove(@id1, @battle.getMove("Splash"))
@battle.continueTurn()
# Action requested due to U-turn
spy = @sandbox.spy(@battle, 'tell')
@clock.tick(@battle.DEFAULT_TIMER)
spy.calledWith(Protocol.TIMER_WIN).should.be.false
@clock.tick(delta)
spy.calledWith(Protocol.TIMER_WIN).should.be.true
describe "with team preview", ->
beforeEach ->
@clock.tick(10000)
shared.create.call this,
conditions: [ Conditions.TIMED_BATTLE, Conditions.TEAM_PREVIEW ]
it "starts a timer that auto-starts the battle after 1.5 mins", ->
@battle.arranging.should.be.true
spy = @sandbox.spy(@battle, 'startBattle')
@clock.tick(@battle.TEAM_PREVIEW_TIMER)
spy.calledOnce.should.be.true
@battle.arranging.should.be.false
it "arranges teams of those who already submitted arrangements", ->
@battle.arranging.should.be.true
arrangement = [0...@team1.size()]
arrangement.reverse()
pokemon = _.clone(@team1.pokemon)
pokemon.reverse()
@controller.arrangeTeam(@id1, arrangement)
@clock.tick(@battle.TEAM_PREVIEW_TIMER)
@team1.pokemon.should.eql(pokemon)

View File

@@ -0,0 +1,70 @@
require '../../helpers'
{BattleServer} = require('../../../server/server')
{User} = require('../../../server/user')
{Conditions} = require '../../../shared/conditions'
{Factory} = require '../../factory'
should = require('should')
generateTeam = ->
[ Factory("Magikarp")
Factory("Gyarados")
Factory('Hitmonchan')
Factory("Celebi")
Factory("Blissey")
Factory("Alakazam") ]
describe 'Validations: Unreleased Ban', ->
it "returns an error if a pokemon is unreleased", ->
server = new BattleServer()
format = 'xy1000'
team = generateTeam()
team[0] = Factory("Hoopa", item: "Leftovers", moves: [ "Moonblast" ])
conditions = [ Conditions.UNRELEASED_BAN ]
server.validateTeam(team, format, conditions).should.not.be.empty
it "returns an error if a pokemon has an unreleased item", ->
server = new BattleServer()
format = 'xy1000'
team = generateTeam()
team[0] = Factory("Latias", item: "Soul Dew", moves: [ "Psychic" ])
conditions = [ Conditions.UNRELEASED_BAN ]
server.validateTeam(team, format, conditions).should.not.be.empty
it "returns an error if a pokemon has an unreleased ability", ->
server = new BattleServer()
format = 'xy1000'
team = generateTeam()
team[0] = Factory("Suicune", ability: "Water Absorb", moves: [ "Surf" ])
conditions = [ Conditions.UNRELEASED_BAN ]
server.validateTeam(team, format, conditions).should.not.be.empty
it "returns no error if all pokemon have nothing unreleased", ->
server = new BattleServer()
format = 'xy1000'
team = generateTeam()
team[0] = Factory("Latias", item: "Leftovers", moves: [ "Psychic" ])
conditions = [ Conditions.UNRELEASED_BAN ]
server.validateTeam(team, format, conditions).should.be.empty
it "returns no error if a pokemon has a dream world ability that is the same as a regular ability", ->
server = new BattleServer()
format = 'xy1000'
team = generateTeam()
team[0] = Factory("Metapod", ability: "Shed Skin", moves: [ "Tackle" ])
conditions = [ Conditions.UNRELEASED_BAN ]
server.validateTeam(team, format, conditions).should.be.empty
it "ignores invalid pokemon", ->
server = new BattleServer()
format = 'xy1000'
team = generateTeam()
team[0] = {species: "I'm a totally fake Pokemon."}
conditions = [ Conditions.UNRELEASED_BAN ]
(-> server.validateTeam(team, format, conditions)).should.not.throw()