Advertisement
Guest User

PWT Script

a guest
Aug 25th, 2014
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 38.37 KB | None | 0 0
  1. #===============================================================================
  2. # Pokemon World Tournament script created by Luka S.J.
  3. # Please give credit when used
  4. #===============================================================================
  5. # Place the script above Main and you're ready to go. This script aims to
  6. # provide a full PWT experience for Essentials (minus the nice visual part).
  7. # I've even gone a little further, and added some things not present in the
  8. # official PWT.
  9. # Call it in a script/even script as PokemonWorldTournament.new
  10. #
  11. #===============================================================================
  12. # Settings
  13. #===============================================================================
  14. # Here you can configure the various aspects of the system.
  15. # Trainers should be defined through the editor, or the PBS file, but should be
  16. # linked/called here just the same way you would in a normal trainer event
  17. #
  18. # This is a list of the types of battles available
  19. # Make sure that World Leaders is in the list after all the other Gym Leader
  20. # Tournament branches.
  21.   BATTLE_LIST = [
  22.                   "Kanto Leaders",
  23.                   "Johto Leaders",
  24.                   "Hoenn Leaders",
  25.                   "Sinnoh Leaders",
  26.                   "Unova Leaders",
  27.                   "World Leaders",
  28.                   "World Champions",
  29.                   "Rental Masters", # not yet implemented
  30.                   "Mix Master" # not yet implemented
  31.                 ]
  32. # This is a list of the Pokemon that cannot be used in the PWT                
  33.   BAN_LIST = [
  34.               PBSpecies::MEWTWO,
  35.               PBSpecies::MEW,
  36.               PBSpecies::HOOH,
  37.               PBSpecies::LUGIA,
  38.               PBSpecies::CELEBI,
  39.               PBSpecies::KYOGRE,
  40.               PBSpecies::GROUDON,
  41.               PBSpecies::RAYQUAZA,
  42.               PBSpecies::DEOXYS,
  43.               PBSpecies::JIRACHI,
  44.               PBSpecies::DIALGA,
  45.               PBSpecies::PALKIA,
  46.               PBSpecies::GIRATINA,
  47.               PBSpecies::HEATRAN,
  48.               PBSpecies::DARKRAI,
  49.               PBSpecies::SHAYMIN,
  50.               PBSpecies::ARCEUS,
  51.               PBSpecies::ZEKROM,
  52.               PBSpecies::RESHIRAM,
  53.               PBSpecies::KYUREM,
  54.               PBSpecies::LANDORUS,
  55.               PBSpecies::MELOETTA,
  56.               PBSpecies::KELDEO,
  57.               PBSpecies::GENESECT
  58.             ]
  59.                  
  60. # This is the list of all the defined trainers
  61. # Trainers are defined as arrays containing:
  62. # [ trainer type , trainer name , player victory speech , player loss speech , region they are from , City/Town they are from , Sprite image name (this can be left blank, and the sprite will be used as Leader_Name) ]
  63. #
  64. # The index of the trainer list has to correspond with the category type.
  65. # If you're creating your own trainer list, make sure it has at least 8 entries, otherwise it won't work.
  66.   TRAINER_LIST = [
  67.                   #-------------------------------------------------------------
  68.                   [
  69.                   # List of all the trainers for the Kanto Leaders Tournament
  70.                     [PBTrainers::LEADER_0,"Brock","Looks like you were the sturdier of us.","My barrier was tough to break. Maybe next time.","Kanto","Pewter City"],
  71.                     [PBTrainers::LEADER_1,"Misty","You are a skilled Trainer, I have to admit that.","Looks like out of the two of us, I was the better Trainer.","Kanto","Cerulean City"],
  72.                     [PBTrainers::LEADER_2,"Lt.Surge","You shocked my very core, soldier!","At ease son, not everyone can beat me.","Kanto","Vermillion City"],
  73.                     [PBTrainers::LEADER_3,"Erika","Oh my! \n Looks like I've underestimated you.","Keep practicing hard, and one day you will be the victor.","Kanto","Celadon City"],
  74.                     [PBTrainers::LEADER_4,"Sabrina","Impossible! I did not predict this!","The outcome was just as I predicted.","Kanto","Saffron City"],
  75.                     [PBTrainers::LEADER_5,"Janine","You've got a great battle technique!","My technique was the superior one!","Kanto","Fuchsia City"],
  76.                     [PBTrainers::LEADER_6,"Blaine","Your flame burnt me up!","My flames are not something everyone can handle.","Kanto","Cinnabar Island"],
  77.                     [PBTrainers::LEADER_7,"Giovanni","What? \nMe, lose?!","I could have never lost to a kid like you!","Kanto","Viridian City"]
  78.                   ],
  79.                   #-------------------------------------------------------------
  80.                   #-------------------------------------------------------------
  81.                   [
  82.                   # List of all the trainers for the Johto Leaders Tournament
  83.                     [PBTrainers::LEADER_8,"Falkner","I understand... I'll bow out gracefully.","My birds and I will always fly!","Johto","Violet City"],
  84.                     [PBTrainers::LEADER_9,"Bugsy","Aw, that's the end of it...","My tough Bug Pokemon cannot be defeated easily.","Johto","Azlea Town"],
  85.                     [PBTrainers::LEADER_10,"Whitney","Ugh...","You really are strong! But I won't lose to you!","Johto","Goldenrod City"],
  86.                     [PBTrainers::LEADER_11,"Morty","How is this possible...","We've got more discipline than anyone else!","Johto","Ecruteak City"],
  87.                     [PBTrainers::LEADER_12,"Chuck","We...lost...","No... Not...yet...","Johto","Cianwood City"],
  88.                     [PBTrainers::LEADER_13,"Jasmine","Well done...","Steel will hang on to the very last!","Johto","Olivine City"],
  89.                     [PBTrainers::LEADER_14,"Pryce","Hmm. Seems as if my luck has run out.","My luck has not run out just yet.","Johto","Mahogany Town"],
  90.                     [PBTrainers::LEADER_15,"Clair","I lost... I don't believe it. There must be some mistake...","I was destined to win! I had already decided that!","Johto","Blackthorn City"]
  91.                   ],
  92.                   #-------------------------------------------------------------
  93.                   #-------------------------------------------------------------
  94.                   [
  95.                   # List of all the trainers for the Hoenn Leaders Tournament
  96.                     [PBTrainers::LEADER_16,"Roxanne","So... I lost...","I learned many things from our battle.","Hoenn","Rustboro City"],
  97.                     [PBTrainers::LEADER_17,"Brawly","Whoa, wow! You made a much bigger splash than I expected!","All right! I rode the big wave!","Hoenn","Dewford Town"],
  98.                     [PBTrainers::LEADER_18,"Wattson","Wahahahah! Fine, I lost! You ended up giving me a thrill!","Wahahahah! Well, I won! How was the battle? Thrilling, right?","Hoenn","Mauville City"],
  99.                     [PBTrainers::LEADER_19,"Flannery","Oh... I guess I was trying too hard...","I... I won! I guess my well-honed moves worked!","Hoenn","Lavaridge Town"],
  100.                     [PBTrainers::LEADER_20,"Norman","... I... I can't... I can't believe it. I lost to you?","We both gave everything we had. That was a wonderful match.","Hoenn","Petalburg City"],
  101.                     [PBTrainers::LEADER_21,"Winona","A Trainer that commands Pokémon with more grace than I...","Our elegant dance is finished!","Hoenn","Fortree City"],
  102.                     [PBTrainers::LEADER_22,"Tate&Liza","Oh! The combination of me and my Pokémon...","The combination of me and my Pokémon was superior!","Hoenn","Mossdeep City"],
  103.                     [PBTrainers::LEADER_24,"Juan","Ahahaha, excellent! Very well, you are the winner.","Ahahaha, I'm the winner! Which is to say, you lost.","Hoenn","Sootopolis City"]
  104.                   ],
  105.                   #-------------------------------------------------------------
  106.                   #-------------------------------------------------------------
  107.                   [
  108.                   # List of all the trainers for the Sinnoh Leaders Tournament
  109.                     [PBTrainers::LEADER_25,"Roark","W-what? That can't be! My buffed-up Pokémon!","No way I would have lost to you!","Sinnoh","Oreburgh City"],
  110.                     [PBTrainers::LEADER_26,"Gardenia","Amazing! You're very good, aren't you?","You did not have me concerned at all.","Sinnoh","Eterna City"],
  111.                     [PBTrainers::LEADER_27,"Fantina","You are so fantastically strong. I know now why I have lost.","Never give up, never surrender!","Sinnoh","Hearthome City"],
  112.                     [PBTrainers::LEADER_28,"Mayleene","I shall admit defeat... You are much too strong.","I take battling very seriously.","Sinnoh","Veilstone City"],
  113.                     [PBTrainers::LEADER_29,"Wake","Hunwah! It's gone and ended! How will I say... I want more! I wanted to battle a lot more!","I had a great time battling with you!","Sinnoh","Solaceon"],
  114.                     [PBTrainers::LEADER_30,"Byron","Hmm! My sturdy Pokémon, defeated!","Though you may lost today, the road of a great Trainer still lies ahead of you.","Sinnoh","Canalave City"],
  115.                     [PBTrainers::LEADER_31,"Candice","I must say, I've warmed up to you! I might even admire you a little.","I'm tough because I know how to focus. It's all about focus!","Sinnoh","Snowpoint City"],
  116.                     [PBTrainers::LEADER_32,"Volkner","You've got me beat... Your desire and the noble way your Pokémon battled for you... I even felt thrilled during our match. That was a very good battle.","You guys are tough! But we surpass your toughness!","Sinnoh","Sunyshore City"]
  117.                   ],
  118.                   #-------------------------------------------------------------
  119.                   #-------------------------------------------------------------
  120.                   [
  121.                   # List of all the trainers for the Unova Leaders Tournament
  122.                     [PBTrainers::LEADER_33,"Cheren","This! This is what a real Pokémon battle is!","You were a powerful opponent, there is no denying that.","Unova","Aspertia City"],
  123.                     [PBTrainers::LEADER_34,"Roxie","Wait! I was right in the middle of the chorus!","Looks like I knocked some sense outta ya!","Unova","Virbank City"],
  124.                     [PBTrainers::LEADER_35,"Burgh","Is it over? Has my muse abandoned me?"," bug Pokémon are scurrying with excitement of battling!","Unova","Castelia City"],
  125.                     [PBTrainers::LEADER_36,"Elesa","I meant to make your head spin, but you shocked me instead.","My Pokemon shined brilliantly!","Unova","Nimbasa City"],
  126.                     [PBTrainers::LEADER_37,"Clay","Well, I've had enough... and just so you know, I didn't go easy on you.","Sorry, I didn't go easy on you.","Unova","Driftveil City"],
  127.                     [PBTrainers::LEADER_38,"Skyla","Being your opponent in battle is a new source of strength to me. Thank you!","Next time, why don't you try something else?","Unova","Mistralton City"],
  128.                     [PBTrainers::LEADER_39,"Drayden","This intense feeling that floods me after a defeat... I don't know how to describe it.","I'm grateful we had a chance to meet and battle.","Unova","Opelucid City"],
  129.                     [PBTrainers::LEADER_40,"Marlon","You totally rocked that! You're raising some wicked Pokémon. You got this Trainer thing down!","Fightin' you felt real good, so I kept goin' and goin'.","Unova","Humilau City"]
  130.                   ],
  131.                   #-------------------------------------------------------------
  132.                   # Generates the list for the World Leaders Tournament
  133.                   [ "slot reserved for World Leaders Tournament" ],
  134.                   #-------------------------------------------------------------
  135.                   #-------------------------------------------------------------
  136.                   [
  137.                   # List of all the trainers for the World Champions Tournament
  138.                     [PBTrainers::CHAMPION_0,"Blue","So this is the standard over here...","Just as I expected! We were too much for you!","Kanto","Indigo Plateau"],
  139.                     [PBTrainers::CHAMPION_1,"Lance","…It’s over. But it’s an odd feeling. I’m not angry that I lost. In fact, I feel happy.","I never give up, no matter what. You must be the same?","Johto","Indigo Plateau"],
  140.                     [PBTrainers::CHAMPION_2,"Wallace","I, the Champion, fall in defeat... That was wonderful work.","The Pokémon you sent into battle...at times they were strong, at times they were weak. One day you will overcome your weakness.","Hoenn","Evergrande City"],
  141.                     [PBTrainers::CHAMPION_3,"Cynthia","It seems that you are the most powerful Trainer.","For now, you're just a powerful challenger.","Sinnoh","Pokemon League"],
  142.                     [PBTrainers::CHAMPION_4,"Iris","Aghhhh... I did my best, but we lost...","Hah! I knew that we could win!","Unova","Pokemon League"],
  143.                     [PBTrainers::CHAMPION_5,"Alder","Well done! You certainly are an unmatched talent!","Use the battle with me as a stepping stone and move forward!","Unova","Pokemon League"],
  144.                     [PBTrainers::CHAMPION_6,"Red","...\n...","...\n...","Kanto","Mt. Silver"],
  145.                     [PBTrainers::CHAMPION_7,"Steven","I, the Champion, fall in defeat... Kudos to you, \PN! You are a truly noble Pokemon Trainer!","You might not have won today, but that does not make you a weak Trainer.","Hoenn","Evergrande City"]
  146.                   ],
  147.                   #-------------------------------------------------------------
  148.                   # Generates the list for the Rental Masters Tournament
  149.                   [ "slot reserved for Rental Masters Tournament" ],
  150.                   #-------------------------------------------------------------
  151.                   #-------------------------------------------------------------
  152.                   # Generates the list for the Mix Masters Tournament
  153.                   [ "slot reserved for Mix Masters Tournament" ]
  154.                   #-------------------------------------------------------------
  155.                 ]
  156. #===============================================================================
  157.  
  158. class PokemonWorldTournament
  159.  
  160. # Starts up the PWT system and generates missing trainer categories  
  161.   def initialize(announce=false)
  162.     @sprites={}
  163.     @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
  164.     @viewport.z=9999
  165.     @sprites["scoreboard"]=Sprite.new(@viewport)
  166.     @sprites["scoreboard"].bitmap=Bitmap.new(Graphics.width,Graphics.height)
  167.     @sprites["scoreboard"].bitmap.fill_rect(0,0,Graphics.width,Graphics.height,Color.new(0,0,0))
  168.     @sprites["scoreboard"].opacity=0
  169.    
  170.     $Trainer.battle_points=0 if !$Trainer.battle_points
  171.     if !$Trainer.pwt_wins or $Trainer.pwt_wins.length<BATTLE_LIST.length
  172.       $Trainer.pwt_wins=[]
  173.       for i in 0...BATTLE_LIST.length
  174.         $Trainer.pwt_wins.push(0)
  175.       end
  176.     end
  177.        
  178.     @current_party = $Trainer.party
  179.    
  180.     self.generateWorldLeaders if BATTLE_LIST.include?("World Leaders")
  181.     self.generateRentalMasters if BATTLE_LIST.include?("Rental Masters")
  182.     self.generateMixMasters if BATTLE_LIST.include?("Mix Masters")
  183.    
  184.     self.introduction
  185.     @tournament_type = chooseTournament
  186.     return cancelEntry if !@tournament_type
  187.     @battle_type = chooseBattle
  188.     return cancelEntry if !@battle_type
  189.     @modified_party = choosePokemon
  190.     if @modified_party=="notEligible"
  191.       Kernel.pbMessage(_INTL("We're terribly sorry, but your Pokemon are not eligible for the Tournament."))
  192.       Kernel.pbMessage(_INTL(showBanList))
  193.       Kernel.pbMessage(_INTL("Please come back once your Pokemon Party has been adjusted."))
  194.     elsif !@modified_party
  195.       cancelEntry
  196.     else
  197.       self.generateRounds
  198.       ret=self.startTournament(announce)
  199.     end
  200.    
  201.     @sprites["scoreboard"].bitmap.clear
  202.     @sprites["scoreboard"].bitmap.fill_rect(0,0,Graphics.width,Graphics.height,Color.new(0,0,0))
  203.     15.times do
  204.       @sprites["scoreboard"].opacity-=17
  205.       pbWait(1)
  206.     end
  207.     case ret
  208.     when "win"
  209.       Kernel.pbMessage(_INTL("Congratulations on today's win."))
  210.       Kernel.pbMessage(_INTL("For your victory you have earned 3 BP."))
  211.       Kernel.pbMessage(_INTL("We hope to see you again."))
  212.       $Trainer.pwt_wins[@tournament_type]+=1
  213.       $Trainer.battle_points+=3
  214.     when "loss"
  215.       Kernel.pbMessage(_INTL("I'm sorry that you lost this tournament."))
  216.       Kernel.pbMessage(_INTL("Maybe you'll have better luck next time."))
  217.       cancelEntry
  218.     end
  219.     $Trainer.party = @current_party
  220.   end
  221.    
  222. # The function used to generate the World Leaders Tournament trainers
  223.   def generateWorldLeaders
  224.     index = BATTLE_LIST.index("World Leaders")
  225.     return false if index.nil?
  226.     full_list = []
  227.     for i in 0...index
  228.       for j in 0...TRAINER_LIST[i].length
  229.         full_list.push(TRAINER_LIST[i][j])
  230.       end
  231.     end
  232.     trainers = []
  233.    
  234.     loop do
  235.       n = rand(full_list.length)
  236.       trainer = full_list[n]
  237.       full_list.delete_at(n)
  238.       trainers.push(trainer)
  239.       break if trainers.length>7
  240.     end
  241.          
  242.     TRAINER_LIST[index] = trainers
  243.   end  
  244.  
  245. # The function used to generate the RentalMasters Tournament trainers
  246.   def generateRentalMasters
  247.     index = BATTLE_LIST.index("Rental Masters")
  248.     return false if index.nil?
  249.     full_list = []
  250.     for i in 0...index
  251.       if i!=BATTLE_LIST.index("World Leaders")
  252.         for j in 0...TRAINER_LIST[i].length
  253.           full_list.push(TRAINER_LIST[i][j])
  254.         end
  255.       end
  256.     end
  257.     trainers = []
  258.    
  259.     loop do
  260.       n = rand(full_list.length)
  261.       trainer = full_list[n]
  262.       full_list.delete_at(n)
  263.       trainers.push(trainer)
  264.       break if trainers.length>7
  265.     end
  266.          
  267.     TRAINER_LIST[index] = trainers
  268.   end  
  269.  
  270. # The function used to generate the RentalMasters Tournament trainers
  271.   def generateMixMasters
  272.     index = BATTLE_LIST.index("Mix Master")
  273.     return false if index.nil?
  274.     full_list = []
  275.     for i in 0...index
  276.       if i!=BATTLE_LIST.index("World Leaders") or i!=BATTLE_LIST.index("Rental Masters")
  277.         for j in 0...TRAINER_LIST[i].length
  278.           full_list.push(TRAINER_LIST[i][j])
  279.         end
  280.       end
  281.     end
  282.     trainers = []
  283.    
  284.     loop do
  285.       n = rand(full_list.length)
  286.       trainer = full_list[n]
  287.       full_list.delete_at(n)
  288.       trainers.push(trainer)
  289.       break if trainers.length>7
  290.     end
  291.          
  292.     TRAINER_LIST[index] = trainers
  293.   end  
  294.  
  295. # Creates a small introductory conversation
  296.   def introduction
  297.     Kernel.pbMessage(_INTL("Hello, and welcome to the Pokemon World Tournament!"))
  298.     Kernel.pbMessage(_INTL("The place where the strongest gather to compete."))
  299.   end
  300.  
  301.   def announceContest(trainer,i)
  302.     n=rand(4)
  303.     if i==7
  304.       Kernel.pbMessage(_INTL("Announcer: Last but not least, joining us is our very own #{$Trainer.name}!")) if (@player_index==i)
  305.       Kernel.pbMessage(_INTL("Announcer: Last but not least, joining our stadium is #{trainer[1]} from #{trainer[5]}, #{trainer[4]}!")) if !(@player_index==i)
  306.       return true
  307.     end
  308.     case n
  309.     when 0
  310.       Kernel.pbMessage(_INTL("Announcer: Our local youth has talent too, please join me in welcoming #{$Trainer.name}!")) if (@player_index==i)
  311.       Kernel.pbMessage(_INTL("Announcer: Visiting us all the way from #{trainer[5]}, #{trainer[4]}, is #{trainer[1]}!")) if !(@player_index==i)
  312.     when 1
  313.       Kernel.pbMessage(_INTL("Announcer: Spot no. #{i+1} takes a local trainer by the name, #{$Trainer.name}!")) if (@player_index==i)
  314.       Kernel.pbMessage(_INTL("Announcer: Spot no. #{i+1} takes #{trainer[1]} from #{trainer[5]}, #{trainer[4]}!")) if !(@player_index==i)
  315.     when 2
  316.       Kernel.pbMessage(_INTL("Announcer: Our very own aspiring challenger #{$Trainer.name} is here to make a name for themself!")) if (@player_index==i)
  317.       Kernel.pbMessage(_INTL("Announcer: From #{trainer[5]}, #{trainer[4]}, comes the legendary #{trainer[1]}!")) if !(@player_index==i)
  318.     when 3
  319.       Kernel.pbMessage(_INTL("Announcer: The next trainer is #{$Trainer.name} from our very own region!")) if (@player_index==i)
  320.       Kernel.pbMessage(_INTL("Announcer: The next trainer is from #{trainer[5]}, #{trainer[4]}. Please, put your hands together for #{trainer[1]}!")) if !(@player_index==i)
  321.     end
  322.    
  323.   end
  324.  
  325. # Cancels the entry into the Tournament
  326.   def cancelEntry
  327.     Kernel.pbMessage(_INTL("We hope to see you again."))
  328.     return false
  329.   end
  330.  
  331. # Creates a list of choices depending on the types of battles in BATTLE_LIST
  332.   def chooseTournament
  333.     choices = []
  334.     for i in 0...BATTLE_LIST.index("World Leaders")
  335.       choices.push(BATTLE_LIST[i])
  336.     end
  337.     if ($Trainer.pwt_wins[BATTLE_LIST.index("Kanto Leaders")]>0 &&
  338.         $Trainer.pwt_wins[BATTLE_LIST.index("Johto Leaders")]>0 &&
  339.         $Trainer.pwt_wins[BATTLE_LIST.index("Hoenn Leaders")]>0 &&
  340.         $Trainer.pwt_wins[BATTLE_LIST.index("Sinnoh Leaders")]>0 &&
  341.         $Trainer.pwt_wins[BATTLE_LIST.index("Unova Leaders")]>0)
  342.       choices.push("World Leaders")
  343.     end
  344.     if ($Trainer.pwt_wins[BATTLE_LIST.index("World Champions")]>0)
  345.       choices.push("Rental Masters")
  346.     end
  347.     if ($Trainer.pwt_wins[BATTLE_LIST.index("World Champions")]>0)
  348.       choices.push("Mix Master")
  349.     end
  350.     if ($Trainer.pwt_wins[BATTLE_LIST.index("World Leaders")]>0)
  351.       choices.push("World Champions")
  352.     end
  353.     choices.push("Cancel")
  354.     cmd=Kernel.pbMessage(_INTL("Which Tournament would you like to participate in?"),choices,choices.index("Cancel"))
  355.     return false if choices[cmd]=="Cancel"
  356.     return cmd
  357.   end
  358.  
  359. # Allows the player to choose which style of battle they would like to do
  360.   def chooseBattle
  361.     choices = ["Single","Double","Full","Sudden Death","Cancel"]
  362.     cmd=Kernel.pbMessage(_INTL("Which type of Battle would you like to participate in?"),choices,choices.length-1)
  363.     return false if cmd==choices.length-1
  364.     return cmd
  365.   end
  366.  
  367. # Checks if the party is eligible
  368.   def partyEligible?
  369.     case @battle_type
  370.     when 0
  371.       length = 3
  372.     when 1
  373.       length = 4
  374.     when 2
  375.       length = 6
  376.     when 3
  377.       length = 1
  378.     end
  379.     count=0
  380.     return false if $Trainer.party.length<length
  381.     for i in 0...$Trainer.party.length
  382.       count+=1 if !(BAN_LIST.include?($Trainer.party[i].species)) && !($Trainer.party[i].egg?)
  383.     end
  384.    
  385.     return true if count>=length
  386.     return false
  387.   end
  388.  
  389. # Creates a new trainer party based on the battle type, and the Pokemon chosen to enter
  390.   def choosePokemon
  391.     ret=false
  392.     return "notEligible" if !partyEligible?
  393.     case @battle_type
  394.     when 0
  395.       length = 3
  396.     when 1
  397.       length = 4
  398.     when 2
  399.       length = 6
  400.     when 3
  401.       length = 1
  402.     end
  403.     Kernel.pbMessage(_INTL("Please choose the Pokemon you would like to participate."))
  404.     ruleset=PokemonRuleSet.new
  405.     ruleset.addPokemonRule(RestrictSpecies.new)
  406.     ruleset.setNumberRange(length,length)
  407.     pbFadeOutIn(99999){
  408.        scene=PokemonScreen_Scene.new
  409.        screen=PokemonScreen.new(scene,$Trainer.party)
  410.        ret=screen.pbPokemonMultipleEntryScreenEx(ruleset)
  411.     }
  412.     return ret
  413.   end
  414.  
  415. # Creates the initial trainer list for the first round, depending on the category chosen
  416.   def generateRounds
  417.     for i in 0...@modified_party.length
  418.       @modified_party[i].level=50
  419.       @modified_party[i].calcStats
  420.     end
  421.    
  422.     @trainer_list = []
  423.     full_list = TRAINER_LIST[@tournament_type]
  424.    
  425.     loop do
  426.       n = rand(full_list.length)
  427.       trainer = full_list[n]
  428.       full_list.delete_at(n)
  429.       @trainer_list.push(trainer)
  430.       break if @trainer_list.length>7
  431.     end
  432.    
  433.     n = rand(8)
  434.     @player_index = n
  435.     @player_index_int = @player_index
  436.     for i in 0...@trainer_list.length
  437.       @trainer_list[i].push("Leader_#{@trainer_list[i][1]}") if @trainer_list[i][6].nil?
  438.     end
  439.     @trainer_list[n] = @modified_party    
  440.     $Trainer.party = @modified_party
  441.     @trainer_list_int=@trainer_list
  442.   end
  443.  
  444. # Outputs a message which lists all the Pokemon banned from the Tournament
  445.   def showBanList
  446.     msg = ""
  447.     for i in 0...BAN_LIST.length
  448.      
  449.       pkmn = PokeBattle_Pokemon.new(BAN_LIST[i],1,nil,false)
  450.       msg+="#{pkmn.name}, "
  451.     end
  452.     msg+="and Eggs are not eligible for entry in the Tournament."
  453.    
  454.     return msg
  455.   end
  456.  
  457. # Handles the tournament branch
  458. # and adds some additional flavour such as an announcer talking
  459.   def startTournament(announce)
  460.     @round=0
  461.     doublebattle=false
  462.     doublebattle=true if @battle_type==1
  463.     15.times do
  464.       @sprites["scoreboard"].opacity+=17
  465.       pbWait(1)
  466.     end
  467.     Kernel.pbMessage(_INTL("Announcer: Welcome to the #{BATTLE_LIST[@tournament_type]} Tournament!"))
  468.     Kernel.pbMessage(_INTL("Announcer: Today we have 8 very eager contestants, waiting to compete for the title of \"Champion\"."))
  469.     Kernel.pbMessage(_INTL("Announcer: Let us turn our attention to the scoreboard, to see who will be competing today."))
  470.     self.createScoreBoard(@trainer_list)
  471.     for i in 0...8
  472.       announceContest(@trainer_list[i],i) if announce
  473.     end
  474.     Kernel.pbMessage(_INTL("Announcer: Without further ado, let the first match begin."))
  475.     trainer=self.generateRound1
  476.     Kernel.pbMessage(_INTL("Announcer: This will be a battle between #{$Trainer.name} and #{trainer[1]}."))
  477.     outcome=pbPWTTrainerBattle(trainer[0],trainer[1],trainer[2],trainer[3],doublebattle)
  478.     if outcome==1
  479.       @round=1
  480.       Kernel.pbMessage(_INTL("Announcer: Wow! What an exciting first round!"))
  481.       Kernel.pbMessage(_INTL("Announcer: The stadium is getting heated up, and the contestants are on fire!"))
  482.       Kernel.pbMessage(_INTL("Announcer: Let us turn our attention back to the scoreboard for the results."))
  483.       trainer=self.generateRound2
  484.       self.createScoreBoard(@trainer_list)
  485.       Kernel.pbMessage(_INTL("Announcer: It looks like the next match will be between #{$Trainer.name} and #{trainer[1]}."))
  486.       Kernel.pbMessage(_INTL("Announcer: Let the battle begin!"))
  487.       outcome=pbPWTTrainerBattle(trainer[0],trainer[1],trainer[2],trainer[3],doublebattle)
  488.       if outcome==1
  489.         @round=2
  490.         Kernel.pbMessage(_INTL("Announcer: What spectacular matches!"))
  491.         Kernel.pbMessage(_INTL("Announcer: These trainers are really giving it all."))
  492.         Kernel.pbMessage(_INTL("Announcer: Let's direct our attention at the scoreboard one final time."))
  493.         trainer=self.generateRound3
  494.         self.createScoreBoard(@trainer_list)
  495.         Kernel.pbMessage(_INTL("Announcer: Alright! It's all set!"))
  496.         Kernel.pbMessage(_INTL("Announcer: The final match of this tournament will be between #{$Trainer.name} and #{trainer[1]}!"))
  497.         Kernel.pbMessage(_INTL("Announcer: May the best trainer win!"))
  498.         outcome=pbPWTTrainerBattle(trainer[0],trainer[1],trainer[2],trainer[3],doublebattle)
  499.         if outcome==1
  500.           Kernel.pbMessage(_INTL("Announcer: What an amazing battle!"))
  501.           Kernel.pbMessage(_INTL("Announcer: Both the trainers put up a great fight, but our very own #{$Trainer.name} was the one to come out on top!"))
  502.           Kernel.pbMessage(_INTL("Announcer: Congratulations #{$Trainer.name}! You have certainly earned today's title of \"Champion\"!"))
  503.  
  504.           Kernel.pbMessage(_INTL("Announcer: That's all we have time for. I hope you enjoyed todays contest. And we hope to see you again soon."))
  505.           return "win"
  506.         end
  507.       end
  508.     end
  509.     return "loss"
  510.   end
  511.  
  512. # Creates a basic Image illustrating a scoreboard
  513.   def createScoreBoard(list)
  514.     nlist=[]
  515.     for i in 0...list.length
  516.       nlist.push(list[i][0])
  517.     end
  518.     x=0
  519.     y=0
  520.     @sprites["scoreboard"].bitmap.clear
  521.     @sprites["scoreboard"].bitmap.fill_rect(0,0,Graphics.width,Graphics.height,Color.new(0,0,0))
  522.     @sprites["scoreboard"].bitmap.blt(0,0,BitmapCache.load_bitmap("Graphics/Pictures/scoreboard"),Rect.new(0,0,Graphics.width,Graphics.height))
  523.     pbSetSystemFont(@sprites["scoreboard"].bitmap)
  524.     for i in 0...@trainer_list_int.length
  525.       opacity=255
  526.       if i==@player_index_int
  527.         trname="#{$Trainer.name}"
  528.         meta=pbGetMetadata(0,MetadataPlayerA+$PokemonGlobal.playerID)
  529.         char=pbGetPlayerCharset(meta,1)
  530.         bitmap=BitmapCache.load_bitmap("Graphics/Characters/#{char}")
  531.       else
  532.         opacity=80 if !(nlist.include?(@trainer_list_int[i][0]))
  533.         trname=@trainer_list_int[i][1]
  534.         bitmap=BitmapCache.load_bitmap("Graphics/Characters/#{@trainer_list_int[i][6]}")
  535.       end
  536.       @sprites["scoreboard"].bitmap.blt(20+(Graphics.width-24-(bitmap.width/4))*x,20+(Graphics.height/6)*y,bitmap,Rect.new(0,0,bitmap.width/4,bitmap.height/4),opacity)
  537.       text=[["#{trname}",24+(bitmap.width/4)+(Graphics.width-32-(bitmap.width/2))*x,34+(Graphics.height/6)*y,x*1,Color.new(255,255,255),Color.new(80,80,80)]]
  538.       pbDrawTextPositions(@sprites["scoreboard"].bitmap,text)
  539.       y+=1
  540.       x+=1 if y>3
  541.       y=0 if y>3
  542.     end
  543.      
  544.   end
  545.    
  546. # Heals your party
  547.   def healParty
  548.     for pokemon in $Trainer.party
  549.       pokemon.heal
  550.     end
  551.   end
  552.  
  553.   def generateRound1
  554.     healParty
  555.     case @player_index
  556.     when 0
  557.       trainer=@trainer_list[1]
  558.     when 1
  559.       trainer=@trainer_list[0]
  560.     when 2
  561.       trainer=@trainer_list[3]
  562.     when 3
  563.       trainer=@trainer_list[2]
  564.     when 4
  565.       trainer=@trainer_list[5]
  566.     when 5
  567.       trainer=@trainer_list[4]
  568.     when 6
  569.       trainer=@trainer_list[7]
  570.     when 7
  571.       trainer=@trainer_list[6]
  572.     end
  573.     return trainer
  574.   end
  575.  
  576.   def generateRound2
  577.     healParty
  578.     list=["","","",""]
  579.     case @player_index
  580.     when 0
  581.       @player_index=0
  582.       list[0]=@modified_party
  583.       list[1]=@trainer_list[2+rand(2)]
  584.       list[2]=@trainer_list[4+rand(2)]
  585.       list[3]=@trainer_list[6+rand(2)]
  586.     when 1
  587.       @player_index=0
  588.       list[0]=@modified_party
  589.       list[1]=@trainer_list[2+rand(2)]
  590.       list[2]=@trainer_list[4+rand(2)]
  591.       list[3]=@trainer_list[6+rand(2)]
  592.     when 2
  593.       @player_index=1
  594.       list[1]=@modified_party
  595.       list[0]=@trainer_list[0+rand(2)]
  596.       list[2]=@trainer_list[4+rand(2)]
  597.       list[3]=@trainer_list[6+rand(2)]
  598.     when 3
  599.       @player_index=1
  600.       list[1]=@modified_party
  601.       list[0]=@trainer_list[0+rand(2)]
  602.       list[2]=@trainer_list[4+rand(2)]
  603.       list[3]=@trainer_list[6+rand(2)]
  604.     when 4
  605.       @player_index=2
  606.       list[2]=@modified_party
  607.       list[0]=@trainer_list[0+rand(2)]
  608.       list[1]=@trainer_list[2+rand(2)]
  609.       list[3]=@trainer_list[6+rand(2)]
  610.     when 5
  611.       @player_index=2
  612.       list[2]=@modified_party
  613.       list[0]=@trainer_list[0+rand(2)]
  614.       list[1]=@trainer_list[2+rand(2)]
  615.       list[3]=@trainer_list[6+rand(2)]
  616.     when 6
  617.       @player_index=3
  618.       list[3]=@modified_party
  619.       list[0]=@trainer_list[0+rand(2)]
  620.       list[1]=@trainer_list[2+rand(2)]
  621.       list[2]=@trainer_list[4+rand(2)]
  622.     when 7
  623.       @player_index=3
  624.       list[3]=@modified_party
  625.       list[0]=@trainer_list[0+rand(2)]
  626.       list[1]=@trainer_list[2+rand(2)]
  627.       list[2]=@trainer_list[4+rand(2)]
  628.     end
  629.     @trainer_list=list
  630.     case @player_index
  631.     when 0
  632.       trainer=@trainer_list[1]
  633.     when 1
  634.       trainer=@trainer_list[0]
  635.     when 2
  636.       trainer=@trainer_list[3]
  637.     when 3
  638.       trainer=@trainer_list[2]
  639.     end
  640.     return trainer
  641.   end
  642.  
  643.   def generateRound3
  644.     healParty
  645.     list=["","","",""]
  646.     case @player_index
  647.     when 0
  648.       @player_index=0
  649.       list[0]=@modified_party
  650.       list[1]=@trainer_list[2+rand(2)]
  651.     when 1
  652.       @player_index=0
  653.       list[0]=@modified_party
  654.       list[1]=@trainer_list[2+rand(2)]
  655.     when 2
  656.       @player_index=1
  657.       list[1]=@modified_party
  658.       list[0]=@trainer_list[0+rand(2)]
  659.     when 3
  660.       @player_index=1
  661.       list[1]=@modified_party
  662.       list[0]=@trainer_list[0+rand(2)]
  663.     end
  664.     @trainer_list=list
  665.     case @player_index
  666.     when 0
  667.       trainer=@trainer_list[1]
  668.     when 1
  669.       trainer=@trainer_list[0]
  670.     end
  671.     return trainer
  672.   end
  673.  
  674. end
  675.  
  676. #===============================================================================
  677. # PWT battle rules
  678. #===============================================================================
  679. class RestrictSpecies
  680.  def initialize
  681.   @specieslist=BAN_LIST.clone
  682.  end
  683.  def isSpecies?(species,specieslist)
  684.   for s in specieslist
  685.    return true if species==s
  686.   end
  687.   return false  
  688.  end
  689.  def isValid?(pokemon)
  690.    count=0
  691.     if isSpecies?(pokemon.species,@specieslist) && !(pokemon.egg?)
  692.      count+=1
  693.     end
  694.    return count==0
  695.  end
  696. end
  697.  
  698. #===============================================================================
  699. # Exta classes and functions for PWT trainer and battle generation
  700. #===============================================================================
  701.  
  702. class PokeBattle_Trainer
  703.   attr_accessor(:battle_points)
  704.   attr_accessor(:pwt_wins)
  705. end
  706.  
  707. # Generates a new PWT styled trainer, where the party is randomized (from the options in the trainer party definition of PBS/trainers.txt)
  708. def pbPWTLoadTrainer(trainerid,trainername,partyid=0)
  709.   success=false
  710.   items=[]
  711.   party=[]
  712.   opponent=nil
  713.   trainers=load_data("Data/trainers.dat")
  714.   case @battle_type
  715.   when 0
  716.     length = 3
  717.   when 1
  718.     length = 4
  719.   when 2
  720.     length = 6
  721.   when 3
  722.     length = 1
  723.   end
  724.   for trainer in trainers
  725.     name=trainer[1]
  726.     thistrainerid=trainer[0]
  727.     thispartyid=trainer[4]
  728.     next if trainerid!=thistrainerid || name!=trainername || partyid!=thispartyid
  729.     items=trainer[2].clone
  730.     name=pbGetMessageFromHash(MessageTypes::TrainerNames,name)
  731.     for i in RIVALNAMES
  732.       if isConst?(trainerid,PBTrainers,i[0]) && $game_variables[i[1]]!=0
  733.         name=$game_variables[i[1]]
  734.       end
  735.     end
  736.     opponent=PokeBattle_Trainer.new(name,thistrainerid)
  737.     opponent.setForeignID($Trainer) if $Trainer
  738.     for poke in trainer[3]
  739.       species=poke[TPSPECIES]
  740.       level=poke[TPLEVEL]
  741.       pokemon=PokeBattle_Pokemon.new(species,level,opponent)
  742.       pokemon.form=poke[TPFORM]
  743.       pokemon.resetMoves
  744.       pokemon.item=poke[TPITEM]
  745.       if poke[TPMOVE1]>0 || poke[TPMOVE2]>0 || poke[TPMOVE3]>0 || poke[TPMOVE4]>0
  746.         k=0
  747.         for move in [TPMOVE1,TPMOVE2,TPMOVE3,TPMOVE4]
  748.           pokemon.moves[k]=PBMove.new(poke[move])
  749.           k+=1
  750.         end
  751.         pokemon.moves.compact!
  752.       end
  753.       pokemon.setAbility(poke[TPABILITY])
  754.       pokemon.setGender(poke[TPGENDER])
  755.       if poke[TPSHINY]   # if this is a shiny Pokémon
  756.         pokemon.makeShiny
  757.       else
  758.         pokemon.makeNotShiny
  759.       end
  760.       pokemon.setNature(poke[TPNATURE])
  761.       iv=poke[TPIV]
  762.       for i in 0...6
  763.         pokemon.iv[i]=iv&0x1F
  764.         pokemon.ev[i]=[85,level*3/2].min
  765.       end
  766.       pokemon.happiness=poke[TPHAPPINESS]
  767.       pokemon.name=poke[TPNAME] if poke[TPNAME] && poke[TPNAME]!=""
  768.       if poke[TPSHADOW]   # if this is a Shadow Pokémon
  769.         pokemon.makeShadow rescue nil
  770.         pokemon.pbUpdateShadowMoves(true) rescue nil
  771.         pokemon.makeNotShiny
  772.       end
  773.       pokemon.ballused=poke[TPBALL]
  774.       pokemon.calcStats
  775.       party.push(pokemon)
  776.     end
  777.     old_party=party
  778.     new_party=[]
  779.     count=0
  780.     loop do
  781.       n=rand(old_party.length)
  782.       new_party.push(old_party[n])
  783.       old_party.delete_at(n)
  784.       break if new_party.length>=length
  785.     end
  786.     party=new_party
  787.     success=true
  788.     break
  789.   end
  790.   return success ? [opponent,items,party] : nil
  791. end
  792.  
  793. # Creates the PWT styled battle, where exp gain, money gain and switching is disabled
  794. def pbPWTTrainerBattle(trainerid,trainername,endspeech,endspeechwin,
  795.                     doublebattle=false,trainerparty=0,canlose=true)
  796.   if $Trainer.pokemonCount==0
  797.     Kernel.pbMessage(_INTL("SKIPPING BATTLE...")) if $DEBUG
  798.     return false
  799.   end
  800.   if !$PokemonTemp.waitingTrainer && $Trainer.ablePokemonCount>1 &&
  801.      pbMapInterpreterRunning?
  802.     thisEvent=pbMapInterpreter.get_character(0)
  803.     triggeredEvents=$game_player.pbTriggeredTrainerEvents([2],false)
  804.     otherEvent=[]
  805.     for i in triggeredEvents
  806.       if i.id!=thisEvent.id && !$game_self_switches[[$game_map.map_id,i.id,"A"]]
  807.         otherEvent.push(i)
  808.       end
  809.     end
  810.     if otherEvent.length==1
  811.       trainer=pbLoadTrainer(trainerid,trainername,trainerparty)
  812.       if !trainer
  813.         pbMissingTrainer(trainerid,trainername,trainerparty)
  814.         return false
  815.       end
  816.       if trainer[2].length<=3
  817.         $PokemonTemp.waitingTrainer=[trainer,thisEvent.id,endspeech,doublebattle]
  818.         return false
  819.       end
  820.     end
  821.   end
  822.   trainer=pbPWTLoadTrainer(trainerid,trainername,trainerparty)
  823.   if !trainer
  824.     pbMissingTrainer(trainerid,trainername,trainerparty)
  825.     return false
  826.   end
  827.   playerparty=$Trainer.party
  828.   playertrainer=$Trainer
  829.   fullparty1=false
  830.   scene=pbNewBattleScene
  831.   battle=PokeBattle_Battle.new(scene,playerparty,trainer[2],playertrainer,trainer[0])
  832.   battle.fullparty1=fullparty1
  833.   battle.doublebattle=doublebattle
  834.   battle.endspeech=endspeech
  835.   battle.endspeechwin=endspeechwin
  836.   battle.items=trainer[1]
  837.   trainerbgm=pbGetTrainerBattleBGM(trainer[0])
  838.   trainerbgm="PWT Finals.mp3" if @round==2 && !(["World Champions","Rental Masters","Mix Master"].include?(BATTLE_LIST[@tournament_type]))
  839.   if Input.press?(Input::CTRL) && $DEBUG
  840.     Kernel.pbMessage(_INTL("SKIPPING BATTLE..."))
  841.     Kernel.pbMessage(_INTL("AFTER LOSING..."))
  842.     Kernel.pbMessage(battle.endspeech)
  843.     Kernel.pbMessage(battle.endspeech2) if battle.endspeech2
  844.     if $PokemonTemp.waitingTrainer
  845.       pbMapInterpreter.pbSetSelfSwitch(
  846.          $PokemonTemp.waitingTrainer[1],"A",true
  847.       )
  848.       $PokemonTemp.waitingTrainer=nil
  849.     end
  850.     return true
  851.   end
  852.   Events.onStartBattle.trigger(nil,nil)
  853.   battle.internalbattle=false
  854.   pbPrepareBattle(battle)
  855.   restorebgm=true
  856.   decision=0
  857.   pbBattleAnimation(trainerbgm,trainer[0].trainertype,trainer[0].name) {
  858.      pbSceneStandby {
  859.         decision=battle.pbStartBattle(canlose)
  860.      }
  861.      for i in $Trainer.party; (i.makeUnmega rescue nil); end
  862.      if $PokemonGlobal.partner
  863.        pbHealAll
  864.        for i in $PokemonGlobal.partner[3]
  865.          i.heal
  866.          i.makeUnmega rescue nil
  867.        end
  868.      end
  869.      if decision==2 || decision==5
  870.        if canlose
  871.          for i in $Trainer.party; i.heal; end
  872.          for i in 0...10
  873.            Graphics.update
  874.          end
  875.        else
  876.          $game_system.bgm_unpause
  877.          $game_system.bgs_unpause
  878.          Kernel.pbStartOver
  879.        end
  880.      else
  881.        Events.onEndBattle.trigger(nil,decision)
  882.        if decision==1
  883.          if $PokemonTemp.waitingTrainer
  884.            pbMapInterpreter.pbSetSelfSwitch(
  885.               $PokemonTemp.waitingTrainer[1],"A",true
  886.            )
  887.          end
  888.        end
  889.      end
  890.   }
  891.   Input.update
  892.   $PokemonTemp.waitingTrainer=nil
  893.   return decision
  894. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement