Last active
August 29, 2015 14:23
-
-
Save notblizzard/f5b91f9d720873129ee6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_team(message) | |
team = [] | |
data = JSON.parse(message) | |
for x in 0..5 do | |
team << { | |
:nick => data['side']['pokemon'][x]['ident'].split(': ')[1].downcase, | |
:name => data['side']['pokemon'][x]['details'].split(',')[0].gsub(/[^A-z0-9]/,'').downcase, | |
:moves => data['side']['pokemon'][x]['moves'].to_a.map(&:downcase), | |
:item => data['side']['pokemon'][x]['item'].downcase, | |
:ability => data['side']['pokemon'][x]['baseAbility'].downcase, | |
:mega => data['side']['pokemon'][x]['canMegaEvo'], | |
:speed => data['side']['pokemon'][x]['stats']['spe'], | |
:fainted => false, | |
# For some reason we have to do this the hard way. | |
:type => POKEDEX[data['side']['pokemon'][x]['details'].split(',')[0].downcase.gsub(/[^A-z0-9]/,'')]['types'].map(&:downcase) | |
} | |
end | |
puts "The team in the method is #{team}" | |
team | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
require 'byebug' | |
require './helpers.rb' | |
require './battle-helpers.rb' | |
require './battle-parser.rb' | |
class Battle | |
attr_accessor :team, :moves, :bot, :opponent, :tier, :room | |
include BattleHelpers | |
def initialize(tier, player_one) | |
@tier = tier | |
@team = [] | |
@moves = [] | |
@bot = {} | |
@opponent = {} | |
@player_one =player_one | |
@have_team = false | |
end | |
def run(ws, data, room) | |
handler = BattleParser.new(ws, @bot, @opponent, @tier, data, room) | |
@player_one = @challenged | |
message = data.split('|') | |
case message[1] | |
when 'request' | |
@moves = handler.get_moves if message[2].split(':')[0].include? "active" | |
unless @have_team | |
@team = handler.get_team(message[2]).freeze | |
@have_team = true | |
end | |
#handler.request(message[2], @room) | |
when 'win','lose','tie' | |
#handler.win_lose_tie(room) | |
when 'faint' | |
#handler.faint(room, @team) | |
when 'player' | |
#handler.player(@moves,@team) | |
when '-damage' | |
#handler.damage | |
when 'turn' | |
move = BattleHelpers.decide(@moves, @bot, @opponent) | |
#handler.mega_or_not(@team, @bot, ws) | |
when 'switch' | |
puts "Team Here is now #{@team}" | |
handler.switch(@team_holder) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
team in method is now [{:nick=>"leavanny", :name=>"leavanny", :moves=>["xscissor | |
", "stickyweb", "knockoff", "swordsdance"], :item=>"focussash", :ability=>"overc | |
oat", :mega=>false, :speed=>200, :fainted=>false, :type=>["bug", "grass"]}, {:ni | |
ck=>"metang", :name=>"metang", :moves=>["meteormash", "stealthrock", "zenheadbut | |
t", "bulletpunch"], :item=>"eviolite", :ability=>"clearbody", :mega=>false, :spe | |
ed=>132, :fainted=>false, :type=>["steel", "psychic"]}, {:nick=>"whimsicott", :n | |
ame=>"whimsicott", :moves=>["taunt", "stunspore", "tailwind", "moonblast"], :ite | |
m=>"leftovers", :ability=>"prankster", :mega=>false, :speed=>223, :fainted=>fals | |
e, :type=>["grass", "fairy"]}, {:nick=>"greninja", :name=>"greninja", :moves=>[" | |
toxicspikes", "gunkshot", "icebeam", "hydropump"], :item=>"lifeorb", :ability=>" | |
protean", :mega=>false, :speed=>224, :fainted=>false, :type=>["water", "dark"]}, | |
{:nick=>"magmortar", :name=>"magmortar", :moves=>["hiddenpowergrass60", "substi | |
tute", "earthquake", "fireblast"], :item=>"leftovers", :ability=>"vitalspirit", | |
:mega=>false, :speed=>181, :fainted=>false, :type=>["fire"]}, {:nick=>"braviary" | |
, :name=>"braviary", :moves=>["bravebird", "substitute", "return", "rockslide"], | |
:item=>"lifeorb", :ability=>"sheerforce", :mega=>false, :speed=>172, :fainted=> | |
false, :type=>["normal", "flying"]}] | |
>battle-randombattle-35361 | |
|player|p2|BlizzardQ|blizzardq.png | |
|gametype|singles | |
|gen|6 | |
|tier|Random Battle | |
|rule|Pokemon of the Day: Metang | |
|rule|Sleep Clause Mod: Limit one foe put to sleep | |
|rule|HP Percentage Mod: HP is shown in percentages | |
| | |
|start | |
|switch|p1a: Leavanny|Leavanny, L83, M|259/259 | |
Team Here is now [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment