Advertisement
polectron

maze handling

Jul 16th, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.89 KB | None | 0 0
  1. def pbSetFloor(floor)
  2.  $PokemonGlobal.floor =  floor
  3.  $PokemonGlobal.visited_floors.push($PokemonGlobal.floors[floor])
  4.  $PokemonGlobal.visitedrooms = 0
  5. end
  6.  
  7. def pbSetDoors(status)
  8.   mapinfos = pbLoadRxData("Data/MapInfos")
  9.   #Kernel.pbMessage(_INTL("{1}",mapinfos[$PokemonGlobal.oldmap].name))
  10.  
  11.   for event in $game_map.events
  12.     if(event[1].name.include? "DOOR")
  13.       $game_self_switches[[$game_map.map_id, event[1].id, "A"]] = status
  14.     end
  15.   end
  16.  
  17.   $game_map.refresh
  18.  
  19.   for event in $game_map.events
  20.     if(event[1].name.include? "DOOR")
  21.       if(!status && event[1].name == "DOOR_"+mapinfos[$PokemonGlobal.oldmap].name)
  22.         event[1].character_name = "no_"+event[1].character_name
  23.       end
  24.     end
  25.   end
  26.  
  27.   $game_map.refresh
  28. end
  29.  
  30. def pbSetDoor(door, status)
  31.   for event in $game_map.events
  32.     if(event[1].name == door)
  33.       $game_self_switches[[$game_map.map_id, event[1].id, "A"]] = status
  34.     end
  35.   end
  36.  
  37.   $game_map.refresh
  38. end
  39.  
  40. def pbCountDefeated
  41.   for event in $game_map.events
  42.     if(event[1].name.include? "Battle Event")
  43.       if !$game_self_switches[[$game_map.map_id, event[1].id, "B"]]
  44.         return false
  45.       end
  46.     end
  47.   end
  48.   return true
  49. end
  50.  
  51. def pbResetPowerups()
  52.   for event in $game_map.events
  53.     if(event[1].name.include? "PowerUp")
  54.       $game_self_switches[[$game_map.map_id, event[1].id, "A"]] = false
  55.     end
  56.   end
  57.  
  58.   $game_map.refresh
  59. end
  60.  
  61. def pbResetLocalSwitches()
  62.   #Kernel.pbMessage(_INTL("{1}",$game_map.events[1].event.class))
  63.   #$game_self_switches[[$game_map.map_id, 1, "A"]] = false
  64.   pbResetPowerups
  65.   for event in $game_map.events
  66.     if(event[1].name == "Battle Event" || event[1].name == "Item Event")
  67.       $game_self_switches[[$game_map.map_id, event[1].id, "A"]] = false
  68.       $game_self_switches[[$game_map.map_id, event[1].id, "B"]] = false
  69.     end
  70.   end
  71.   $game_map.refresh
  72. end
  73.  
  74. def pbOpenDoors
  75.   mapinfos = pbLoadRxData("Data/MapInfos")
  76.   #Kernel.pbMessage(_INTL("{1} -> {2}",mapinfos[$PokemonGlobal.oldmap].name,mapinfos[$game_map.map_id].name))
  77.   if mapinfos[$PokemonGlobal.oldmap].name.include? "Hall"
  78.     for event in $game_map.events
  79.       if(event[1].name.include? ("DOOR") && event[1].name != "DOOR_Hall")
  80.         $game_self_switches[[$game_map.map_id, event[1].id, "A"]] = true
  81.       end
  82.     end
  83.   else
  84.     for event in $game_map.events
  85.       if(event[1].name.include? ("DOOR") && event[1].name != "DOOR_Hall" && event[1].name != "DOOR_"+mapinfos[$PokemonGlobal.oldmap].name)
  86.         $game_self_switches[[$game_map.map_id, event[1].id, "A"]] = true
  87.       end
  88.     end
  89.   end
  90.  
  91.   #Kernel.pbMessage(_INTL("{1}",mapinfos[$PokemonGlobal.oldmap].name))
  92.   for event in $game_map.events
  93.     if mapinfos[$PokemonGlobal.oldmap].name.include? "Hall"
  94.       if(event[1].name.include? ("PowerUp"))
  95.         $game_self_switches[[$game_map.map_id, event[1].id, "A"]] = true
  96.       end
  97.     else
  98.       if(event[1].name.include?("PowerUp") && event[1].name != "PowerUp_"+mapinfos[$PokemonGlobal.oldmap].name)
  99.         #Kernel.pbMessage(_INTL("{1}",event[1].name))
  100.         $game_self_switches[[$game_map.map_id, event[1].id, "A"]] = true
  101.       end
  102.     end
  103.   end
  104.    
  105.   $game_map.refresh
  106. end
  107.  
  108. def pbGivePowerUp(powerup)
  109.   $PokemonGlobal.powerup = powerup
  110.   $PokemonGlobal.lastpowerup = Time.new.to_i
  111.   $PokemonGlobal.powerupperiod = 1*60
  112.   pbIncreaseCombo
  113. end
  114.  
  115. def pbIncreaseCombo
  116.  
  117.   if $PokemonGlobal.combo == 1
  118.     $PokemonGlobal.combo = 1.2
  119.   elsif $PokemonGlobal.combo == 1.2
  120.     $PokemonGlobal.combo = 1.5
  121.   elsif $PokemonGlobal.combo == 1.5
  122.     $PokemonGlobal.combo = 1.7
  123.   elsif $PokemonGlobal.combo == 1.7
  124.     $PokemonGlobal.combo = 2
  125.   elsif $PokemonGlobal.combo == 2
  126.     $PokemonGlobal.combo = 2.2
  127.   elsif $PokemonGlobal.combo == 2.2
  128.     $PokemonGlobal.combo = 2.5
  129.   end
  130.  
  131. end
  132.  
  133. def pbShowItem
  134.   if $PokemonGlobal.powerup == "Loot" || $PokemonGlobal.powerup == "RareLoot"
  135.     return true
  136.   else
  137.     if pbRandPercentage(25)
  138.       return true
  139.     else
  140.       return false
  141.     end
  142.   end
  143. end
  144.  
  145. def pbLootItem
  146.   items = [[PBItems::POTION]]
  147.   rareitems = [[PBItems::POKEBALL]]
  148.   if $PokemonGlobal.powerup == "Loot"
  149.     items = items
  150.   elsif $PokemonGlobal.powerup == "RareLoot" && pbRandPercentage(15)
  151.     items = rareitems
  152.   else
  153.     items = items + rareitems
  154.   end
  155.  
  156.   Kernel.pbItemBall(items[$PokemonGlobal.floor].shuffle[0])
  157. end
  158.  
  159. def pbSetBattles
  160.   hasdominant = false
  161.   for event in $game_map.events
  162.     if(event[1].name == "Battle Event")
  163.       $game_self_switches[[$game_map.map_id, event[1].id, "A"]] = true
  164.       $game_map.refresh
  165.       hasdominant = pbRandBattle(event[1].id, hasdominant)
  166.     end
  167.   end
  168. end
  169.  
  170. def pbRandBattle(eventid, hasdominant)
  171.  
  172.   mapinfos = pbLoadRxData("Data/MapInfos")
  173.   pokemon = {
  174.     0=>{
  175.       "Top-Left"=>[[PBSpecies::SAWK,78],[PBSpecies::MACHOKE,77],[PBSpecies::PRIMEAPE,77],[PBSpecies::HITMONCHAN,78]],
  176.       "Top-Center"=>[[PBSpecies::SKARMORY,78],[PBSpecies::AGGRON,80],[PBSpecies::MAWILE,78],[PBSpecies::MAGNETON,79]],
  177.       "Top-Right"=>[[PBSpecies::KECLEON,85],[PBSpecies::SOLROCK,74],[PBSpecies::QUAGSIRE,79],[PBSpecies::FORRETRESS,79]],
  178.       "Center-Left"=>[[PBSpecies::DUGTRIO,78],[PBSpecies::SANDSLASH,76],[PBSpecies::MAROWAK,78],[PBSpecies::RHYDON,78]],
  179.       "Center-Right"=>[[PBSpecies::GOLEM,78],[PBSpecies::SUDOWOODO,80],[PBSpecies::OMASTAR,78],[PBSpecies::LUNATONE,74]],
  180.       "Bottom-Left"=>[[PBSpecies::HERACROSS,78],[PBSpecies::LUCARIO,77],[PBSpecies::METAGROSS,82],[PBSpecies::DONPHAN,75]],
  181.       "Bottom-Center"=>[[PBSpecies::MACHOKE,75],[PBSpecies::PRIMEAPE,75],[PBSpecies::HITMONLEE,78],[PBSpecies::THROH,78]],
  182.       "Bottom-Right"=>[[PBSpecies::CLAYDOL,79],[PBSpecies::FLYGON,82],[PBSpecies::RHYDON,79],[PBSpecies::SANDSLASH,75]]
  183.     }
  184.   }
  185.  
  186.   rarepokemon = {
  187.     0=>{
  188.       "Top-Left"=>[[PBSpecies::KECLEON,90]],
  189.       "Top-Center"=>[[PBSpecies::KECLEON,90]],
  190.       "Top-Right"=>[[PBSpecies::KECLEON,90]],
  191.       "Center-Left"=>[[PBSpecies::KECLEON,90]],
  192.       "Center-Right"=>[[PBSpecies::KECLEON,90]],
  193.       "Bottom-Left"=>[[PBSpecies::KECLEON,90]],
  194.       "Bottom-Center"=>[[PBSpecies::KECLEON,90]],
  195.       "Bottom-Right"=>[[PBSpecies::KECLEON,90]]
  196.     }
  197.   }
  198.  
  199.   dominant = {
  200.     0=>{
  201.       "Top-Left"=>[[PBSpecies::BASTIODON,84]],
  202.       "Top-Center"=>[[PBSpecies::BASTIODON,84]],
  203.       "Top-Right"=>[[PBSpecies::BASTIODON,84]],
  204.       "Center-Left"=>[[PBSpecies::BASTIODON,84]],
  205.       "Center-Right"=>[[PBSpecies::BASTIODON,84]],
  206.       "Bottom-Left"=>[[PBSpecies::BASTIODON,84]],
  207.       "Bottom-Center"=>[[PBSpecies::BASTIODON,84]],
  208.       "Bottom-Right"=>[[PBSpecies::BASTIODON,84]]
  209.     }
  210.   }
  211.  
  212.   if $PokemonGlobal.powerup == "Hunter" and pbRandPercentage(50)
  213.     pokemon = rarepokemon
  214.   else
  215.    
  216.     if(pbRandPercentage(2*$PokemonGlobal.visitedrooms)) && !hasdominant
  217.       pokemon = dominant
  218.       hasdominant = true
  219.     elsif(pbRandPercentage(95))
  220.       pokemon = pokemon
  221.     else
  222.       pokemon = rarepokemon
  223.     end
  224.   end
  225.  
  226.   pokemon = pokemon[$PokemonGlobal.floor][mapinfos[$game_map.map_id].name].shuffle
  227.   #Kernel.pbMessage(_INTL("{1}",pokemon.inspect))
  228.   $game_map.events[eventid].character_name = pokemon[0][0].to_s.rjust(3, "0")
  229.   $game_map.events[eventid].name = $game_map.events[eventid].name+","+pokemon[0][0].to_s+","+pokemon[0][1].to_s
  230.   $game_map.refresh
  231.   return hasdominant
  232. end
  233.  
  234. def pbStartBattle(eventid)
  235.   Graphics.frame_rate = 200
  236.   pokemon = $game_map.events[eventid].name.split(",")[1].to_i
  237.   level = $game_map.events[eventid].name.split(",")[2].to_i
  238.   #Kernel.pbMessage(_INTL("{1}",pokemon))
  239.   pbWildBattle(pokemon,level,26,false,false)
  240.   Graphics.frame_rate = 40
  241.   #Kernel.pbMessage(_INTL("{1}",$game_variables[26]))
  242.  
  243.   if $game_variables[26] == 1 && $PokemonGlobal.floor != 5#won
  244.     if $game_switches[61]
  245.      
  246.       $PokemonGlobal.oldmap = $game_map.map_id
  247.      
  248.       if $game_switches[60] #survival mode
  249.         maps = $PokemonGlobal.floors.shuffle - $PokemonGlobal.floors[$PokemonGlobal.floor]
  250.         $MapFactory.setup(maps[0])
  251.       else #story mode
  252.         if($PokemonGlobal.floors.length > $PokemonGlobal.floor+1)
  253.           maps = $PokemonGlobal.floors[1..-2].shuffle - $PokemonGlobal.visited_floors
  254.           $PokemonGlobal.lastcombo = Time.new.to_i
  255.           if $PokemonGlobal.floor == 4
  256.             $MapFactory.setup(48)
  257.           elsif maps.length == 0
  258.             $MapFactory.setup($PokemonGlobal.floors[-1])
  259.           else
  260.             $MapFactory.setup(maps[0])
  261.           end
  262.          
  263.         end
  264.       end
  265.  
  266.       $game_player.moveto(10,7)
  267.       $game_map.refresh
  268.     end
  269.   end
  270.  
  271. end
  272.  
  273. def pbRandPercentage(percentage)
  274.   rnd = rand(100)
  275.   return rnd >= 0 && rnd <= percentage
  276. end
  277.  
  278. def pbCheckDirection(dir)
  279.   direction = $game_player.direction
  280.   if direction == 6 && dir == "right" #Right
  281.     return true
  282.   elsif direction == 4 && dir == "left" #Left
  283.     return true
  284.   elsif direction == 2 && dir == "bottom" #Bottom
  285.     return true
  286.   elsif direction == 8 && dir == "top" #Top
  287.     return true
  288.   else
  289.     return false
  290.   end
  291. end
  292.  
  293. def pbInspectEvent(eventid)
  294.   $game_map.events[eventid].event.pages[1].character_name = "002"
  295.   #Kernel.pbMessage(_INTL("{1}",$game_map.events[eventid].event.pages.inspect))
  296. end
  297.  
  298. Events.onMapUpdate+=proc{
  299.  
  300.   time_now = Time.new.to_i - $PokemonGlobal.lastcombo
  301.  
  302.   if $PokemonGlobal.lastcombo != -1
  303.     if time_now >= 20 and $PokemonGlobal.lastmazemessage == -1
  304.       $PokemonGlobal.lastmazemessage += 1
  305.       pbWait(20)
  306.       Kernel.pbMessage("Mensaje 1")
  307.       pbWait(20)
  308.     elsif time_now >= 40 and $PokemonGlobal.lastmazemessage == 0
  309.       $PokemonGlobal.lastmazemessage += 1
  310.       pbWait(20)
  311.       Kernel.pbMessage("Mensaje 2")
  312.       pbWait(20)
  313.     end
  314.   end
  315.  
  316.   if time_now > $PokemonGlobal.comboperiod and $PokemonGlobal.comboperiod != -1
  317.     $PokemonGlobal.combo = 1
  318.     $PokemonGlobal.comboperiod = -1
  319.     $PokemonGlobal.powerup = ""
  320.     $PokemonGlobal.powerupperiod = -1
  321.    
  322.   end
  323. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement