Advertisement
Vendily

Torterra Tree Minigame

Jul 25th, 2020 (edited)
2,198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.87 KB | None | 0 0
  1. =begin
  2. Torterra Tree Minigame by Vendily
  3. https://twitter.com/Vendily1/status/1287168317174800385
  4. pbTorterraState.pbStart(event_id of the leader, array of event ids for the trees (though it can really be anything))
  5. pbTorterraState.pbStart(@event_id,[2,3,4,5,6,7]) (current event and the tree ids)
  6. pbTorterraState.pbShowRound to start the minigame proper and do the shakes. you only need to call it once, unless you want to reshow the current round.
  7. Check if pbTorterraState.decision==1 is true for the game to be won.
  8. use pbInTorterra? to see if the minigame is still in progress. It doesn't end until pbTorterraState.pbEnd is called.
  9. put pbTorterraState.pbInteract(@event_id) in the events that activate. you don't need to check for in progress.
  10.  
  11. You will need to adjust the pbMoveRoute as they are still the same as my project and use hard coded character graphics.
  12. =end
  13. class PokemonGlobalMetadata
  14.   attr_accessor :torterraState
  15. end
  16.  
  17. class TorterraState
  18.   MAX_ROUNDS = 3
  19.   attr_accessor :decision
  20.   attr_accessor :moves
  21.   attr_accessor :round
  22.  
  23.   def initialize
  24.     @inProgress=false
  25.     @moves=nil
  26.     @round=0
  27.     @decision=0
  28.   end
  29.  
  30.   def inProgress?
  31.     return @inProgress
  32.   end
  33.  
  34.   def pbStart(leader_id,event_ids)
  35.     @inProgress=true
  36.     @decision=0
  37.     @moves=[]
  38.     @round=0
  39.     @leader=leader_id
  40.     @events=event_ids
  41.     @orders=[]
  42.     m=3
  43.     for r in 0...MAX_ROUNDS
  44.       tmp=[]
  45.       for i in 0...m
  46.         tmp.push(@events[rand(@events.length)])
  47.       end
  48.       @orders.push(tmp.clone)
  49.       m+=1
  50.     end
  51.   end
  52.  
  53.   def pbShowRound
  54.     shakes=@orders[@round]
  55.     event=$game_map.events[@leader]
  56.     pbMoveRoute(event,[
  57.      PBMoveRoute::Graphic,"sleepers",0,4,3,
  58.      PBMoveRoute::Wait,4,
  59.      PBMoveRoute::Graphic,"sleepers",0,6,0,
  60.      PBMoveRoute::Wait,8,
  61.      PBMoveRoute::Graphic,"sleepers",0,4,3,
  62.      PBMoveRoute::Wait,4
  63.     ])
  64.     pbWait(2*2*6)
  65.     for m in shakes
  66.       event=$game_map.events[m]
  67.       pbMoveRoute(event,[
  68.         PBMoveRoute::Graphic,"headbutt tree",0,2,0,
  69.         PBMoveRoute::Wait,4,
  70.         PBMoveRoute::Graphic,"headbutt tree",0,4,0,
  71.         PBMoveRoute::Wait,4,
  72.         PBMoveRoute::Graphic,"headbutt tree",0,8,0,
  73.         PBMoveRoute::Wait,4,
  74.         PBMoveRoute::Graphic,"headbutt tree",0,6,0,
  75.         PBMoveRoute::Wait,4,
  76.         PBMoveRoute::Graphic,"headbutt tree",0,2,0
  77.       ])
  78.       pbWait(2*2*10)
  79.     end
  80.   end
  81.  
  82.   def pbInteract(event_id)
  83.     return if !inProgress?
  84.     return if @decision>0
  85.     event=$game_map.events[event_id]
  86.     pbMoveRoute(event,[
  87.      PBMoveRoute::Graphic,"headbutt tree",0,2,0,
  88.      PBMoveRoute::Wait,4,
  89.      PBMoveRoute::Graphic,"headbutt tree",0,4,0,
  90.      PBMoveRoute::Wait,4,
  91.      PBMoveRoute::Graphic,"headbutt tree",0,8,0,
  92.      PBMoveRoute::Wait,4,
  93.      PBMoveRoute::Graphic,"headbutt tree",0,6,0,
  94.      PBMoveRoute::Wait,4,
  95.      PBMoveRoute::Graphic,"headbutt tree",0,2,0
  96.     ])
  97.     pbWait(2*2*4)
  98.     @moves.push(event_id)
  99.     pbVerify
  100.   end
  101.  
  102.   def pbVerify
  103.     ret=nil
  104.     for i in 0...@moves.length
  105.       ret=false if @moves[i]!=@orders[@round][i]
  106.     end
  107.     if ret.nil?
  108.       ret=true if @moves.length==@orders[@round].length
  109.     end
  110.     return if ret.nil?
  111.     if ret
  112.       Kernel.pbMessage(_INTL("Correct!"))
  113.       @round+=1
  114.     else
  115.       Kernel.pbMessage(_INTL("Incorrect!"))
  116.     end
  117.     if @round==MAX_ROUNDS
  118.       @decision=1
  119.       Kernel.pbMessage(_INTL("That's all three!\\1"))
  120.       Kernel.pbMessage(_INTL("Come back to me!"))
  121.       return
  122.     end
  123.     @moves=[]
  124.     pbShowRound
  125.   end
  126.  
  127.   def pbEnd
  128.     @start=nil
  129.     @inProgress=false
  130.     @steps=0
  131.     @decision=0
  132.     $game_map.need_refresh=true
  133.   end
  134. end
  135.  
  136. def pbInTorterra?
  137.   return pbTorterraState.inProgress?
  138. end
  139.  
  140. def pbTorterraState
  141.   if !$PokemonGlobal.torterraState
  142.     $PokemonGlobal.torterraState=TorterraState.new
  143.   end
  144.   return $PokemonGlobal.torterraState
  145. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement