Skip to content

Loading…

implement perish-song #15

Merged
merged 1 commit into from

2 participants

@pepijndevos

No description provided.

@sarenji sarenji merged commit 22843e4 into sarenji:master

1 check passed

Details default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 56 additions and 6 deletions.
  1. +6 −2 data/bw/moves.coffee
  2. +13 −0 server/attachment.coffee
  3. +1 −4 server/battle.coffee
  4. +4 −0 server/pokemon.coffee
  5. +32 −0 test/bw/moves.coffee
View
8 data/bw/moves.coffee
@@ -180,8 +180,7 @@ makeExplosionMove = (name) ->
oldExecute = @execute
@execute = (battle, user, targets) ->
if !_.any(targets, (target) -> target.hasAbility('Damp'))
- # TODO: Real faint?
- user.currentHP = 0
+ user.faint(battle)
oldExecute(battle, user, targets)
else
battle.message "#{user.name} cannot use #{@name}!"
@@ -806,6 +805,11 @@ extendMove 'psywave', ->
fraction = battle.rng.randInt(5, 15, "psywave") / 10
Math.floor(user.level * fraction)
+extendMove 'perish-song', ->
+ @execute = (battle, user, targets) ->
+ battle.message "All Pokemon hearing the song will faint in three turns!"
+ _.each(targets, (p) -> p.attach(new Attachment.PerishSong()))
+
extendMove 'splash', ->
# TODO: Cannot select if Gravity is in effect.
@execute = (battle, user, target) ->
View
13 server/attachment.coffee
@@ -166,3 +166,16 @@ class @Attachment.Wish extends @TeamAttachment
battle.message "#{@wisherName}'s wish came true!"
pokemon.damage(-@amount)
@remove()
+
+class @Attachment.PerishSong extends @VolatileAttachment
+ constructor: (attributes={}) ->
+ super("PerishSongAttachment", attributes)
+ @turns = 4
+ @turn = 0
+
+ endTurn: (battle) =>
+ @turn++
+ battle.message "#{@pokemon.name}'s perish count fell to #{@turns - @turn}!"
+ if @turn >= @turns
+ @pokemon.faint(battle)
+
View
5 server/battle.coffee
@@ -396,10 +396,7 @@ class @Battle
# TODO: Add your own party Pokemon as well.
@getOpponentPokemon(id, @numActive)
when 'entire-field'
- # TODO: Determine if this is actually what you want.
- pokemon = @getOpponentPokemon(id, @numActive)
- pokemon.push(@getTeam(id).at(0))
- pokemon
+ @getActivePokemon()
when 'random-opponent'
pokemon = @getOpponentPokemon(id, @numActive)
@rng.choice(pokemon)
View
4 server/pokemon.coffee
@@ -134,6 +134,10 @@ class @Pokemon
isFainted: =>
@currentHP <= 0
+ faint: (battle) =>
+ @currentHP = 0
+ battle.message "#{@name} fainted!"
+
damage: (amount) =>
@setHP(@currentHP - amount)
View
32 test/bw/moves.coffee
@@ -1248,3 +1248,35 @@ shared = require '../shared'
mock.restore()
mock.verify()
+
+ describe "Perish Song", ->
+ it "attaches to every pokemon in the field", ->
+ shared.create.call(this)
+ @battle.makeMove(@player1, 'perish-song')
+ @battle.makeMove(@player2, 'splash')
+
+ result = _.all @battle.getActivePokemon(), (pokemon) ->
+ pokemon.hasAttachment("PerishSongAttachment")
+ result.should.be.true
+
+ it "faints pokemon at the end of 4 turns", ->
+ shared.create.call(this)
+ @battle.makeMove(@player1, 'perish-song')
+ @battle.makeMove(@player2, 'splash')
+
+ @battle.makeMove(@player1, 'splash')
+ @battle.makeMove(@player2, 'splash')
+
+ @battle.makeMove(@player1, 'splash')
+ @battle.makeMove(@player2, 'splash')
+
+ result = _.all @battle.getActivePokemon(), (pokemon) ->
+ !pokemon.isFainted()
+ result.should.be.true
+
+ @battle.makeMove(@player1, 'splash')
+ @battle.makeMove(@player2, 'splash')
+
+ result = _.all @battle.getActivePokemon(), (pokemon) ->
+ pokemon.isFainted()
+ result.should.be.true
Something went wrong with that request. Please try again.