Advertisement
Vendily

amie

Aug 7th, 2018
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.09 KB | None | 0 0
  1. class PokeAmieButton < SpriteWrapper
  2.   attr_reader :index
  3.   attr_reader :name
  4.   attr_accessor :selected
  5.  
  6.   def initialize(x,y,name="",index=0,viewport=nil)
  7.     super(viewport)
  8.     @index=index
  9.     @name=name
  10.     @selected=false
  11.     fembutton=pbResolveBitmap(sprintf("Graphics/Pictures/pokegearButtonf"))
  12.     if $Trainer.isFemale? && fembutton
  13.       @button=AnimatedBitmap.new("Graphics/Pictures/pokegearButtonf")
  14.     else
  15.       @button=AnimatedBitmap.new("Graphics/Pictures/pokegearButton")
  16.     end
  17.     @contents=BitmapWrapper.new(@button.width,@button.height)
  18.     self.bitmap=@contents
  19.     self.x=x
  20.     self.y=y
  21.     refresh
  22.     update
  23.   end
  24.  
  25.   def dispose
  26.     @button.dispose
  27.     @contents.dispose
  28.     super
  29.   end
  30.  
  31.   def refresh
  32.     self.bitmap.clear
  33.     self.bitmap.blt(0,0,@button.bitmap,Rect.new(0,0,@button.width,@button.height))
  34.     pbSetSystemFont(self.bitmap)
  35.     textpos=[          # Name is written on both unselected and selected buttons
  36.       [@name,self.bitmap.width/2,10,2,Color.new(248,248,248),Color.new(40,40,40)],
  37.       [@name,self.bitmap.width/2,62,2,Color.new(248,248,248),Color.new(40,40,40)]
  38.     ]
  39.     pbDrawTextPositions(self.bitmap,textpos)
  40.     icon=sprintf("Graphics/Pictures/pokegear"+@name)
  41.     imagepos=[        # Icon is put on both unselected and selected buttons
  42.       [icon,18,10,0,0,-1,-1],
  43.       [icon,18,62,0,0,-1,-1]
  44.     ]
  45.     pbDrawImagePositions(self.bitmap,imagepos)
  46.   end
  47.  
  48.   def update
  49.     if self.selected
  50.       self.src_rect.set(0,self.bitmap.height/2,self.bitmap.width,self.bitmap.height/2)
  51.     else
  52.       self.src_rect.set(0,0,self.bitmap.width,self.bitmap.height/2)
  53.     end
  54.     super
  55.   end
  56. end
  57.  
  58. module BeanColors
  59.   Red                = 0
  60.   Orange             = 1
  61.   Yellow             = 2
  62.   Green              = 3
  63.   LightBlue          = 4
  64.   Blue               = 5
  65.   Purple             = 6
  66.   Pink               = 7
  67.   RedPatterned       = 8
  68.   OrangePatterned    = 9
  69.   YellowPatterned    = 10
  70.   GreenPatterned     = 11
  71.   LightBluePatterned = 12
  72.   BluePatterned      = 13
  73.   PurplePatterned    = 14
  74.   PinkPatterned      = 15
  75.   Rainbow            = 16
  76.  
  77.   def BeanColors.getName(id)
  78.     names=[
  79.        _INTL("Red Bean"),
  80.        _INTL("Orange Bean"),
  81.        _INTL("Yellow Bean"),
  82.        _INTL("Green Bean"),
  83.        _INTL("Light Blue Bean"),
  84.        _INTL("Blue Bean"),
  85.        _INTL("Purple Bean"),
  86.        _INTL("Pink Bean"),
  87.        _INTL("Patterned Red Bean"),
  88.        _INTL("Patterned Orange Bean"),
  89.        _INTL("Patterned Yellow Bean"),
  90.        _INTL("Patterned Green Bean"),
  91.        _INTL("Patterned Light Blue Bean"),
  92.        _INTL("Patterned Blue Bean"),
  93.        _INTL("Patterned Purple Bean"),
  94.        _INTL("Patterned Pink Bean"),
  95.        _INTL("Rainbow Bean"),
  96.       ]
  97.     return names[id]
  98.   end
  99. end
  100.  
  101. class PokeBattle_Trainer
  102.   attr_accessor :beans
  103.  
  104.   alias amie_initialize initialize
  105.  
  106.   def initialize(name,trainertype)
  107.     amie_initialize(name,trainertype)
  108.     @beans=[]
  109.     for i in 0..16
  110.       @beans.push(0)
  111.     end
  112.   end
  113. end
  114.  
  115. def addBeans(bean,num)
  116.   if bean.is_a?(String) || bean.is_a?(Symbol)
  117.     bean=getID(BeanColors,bean)
  118.   end
  119.   if $Trainer.beans[bean]+num>255
  120.     num=255-$Trainer.beans[bean]
  121.   end
  122.   $Trainer.beans[bean]+=num
  123.   Kernel.pbMessage(_INTL("\\se[itemlevel]Obtained \\c[1]{1}\\c[0]!\\wtnp[30]",BeanColors.getName(bean)))
  124. end
  125.  
  126. #===============================================================================
  127. #  This class performs menu screen processing.
  128. #-------------------------------------------------------------------------------
  129. #  Adapted by rigbycwts for use with Pokemon-Amie for Essentials.
  130. #===============================================================================
  131. class PokeAmie_Essentials
  132.   #-----------------------------------------------------------------------------
  133.   # * Object Initialization
  134.   #    menu_index : command cursor's initial position
  135.   #-----------------------------------------------------------------------------
  136.   def initialize(pokemon, partyIndex, menu_index = 0)
  137.     @pokemon = pokemon
  138.     @partyIndex = partyIndex
  139.     @menu_index = menu_index
  140.   end
  141.   #-----------------------------------------------------------------------------
  142.   # * Main Processing
  143.   #-----------------------------------------------------------------------------
  144.   def main
  145.     # Make command window
  146.     fadein = true
  147.     # Makes the text window
  148.     @sprites={}
  149.     @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
  150.     @viewport.z=99999
  151.     @sprites["bgmap"] = IconSprite.new(0,0)
  152.     @sprites["bgmap"].setBitmap(self.pbBackdrop)
  153.     @sprites["bgmap"].z=200
  154.     @sprites["border"] = IconSprite.new(0,280)
  155.     @sprites["border"].setBitmap("Graphics/Pictures/AmieBottom")
  156.     @sprites["border"].z=240
  157.     @sprites["background"] = IconSprite.new(0,0)
  158.     @sprites["background"].setBitmap("Graphics/Pictures/PokeAmie/Choices")
  159.     @sprites["background"].z=255
  160.     @sprites["affection"]=IconSprite.new(40,120)
  161.     @sprites["affection"].setBitmap(@affectionbar)
  162.     @sprites["affection"].z=245
  163.     @sprites["pokemon"]=PokemonSprite.new(@viewport)
  164.     @sprites["pokemon"].setPokemonBitmap(@pokemon)
  165.     @sprites["pokemon"].mirror=false
  166.     @sprites["pokemon"].color=Color.new(0,0,0,0)
  167.     pbPositionPokemonSprite(@sprites["pokemon"],40,144)
  168.     @choices=[
  169.       _INTL("Pet"),
  170.       _INTL("Feed"),
  171.       _INTL("Exit")
  172.     ]
  173.     @sprites["header"]=Window_UnformattedTextPokemon.newWithSize(_INTL("Pokémon-Amie"),
  174.       2,-18,640,64,@viewport)
  175.     @sprites["header"].baseColor=Color.new(248,248,248)
  176.     @sprites["header"].shadowColor=Color.new(0,0,0)
  177.     @sprites["header"].windowskin=nil
  178.     @sprites["command_window"] = Window_CommandPokemon.new(@choices,324)
  179.     @sprites["command_window"].windowskin=nil
  180.     @sprites["command_window"].index = @menu_index
  181.     @sprites["command_window"].height = 224
  182.     @sprites["command_window"].width = 124
  183.     @sprites["command_window"].x = 320
  184.     @sprites["command_window"].y = 92
  185.     @sprites["command_window"].z = 256
  186.     @sprites["affection"].setBitmap("Graphics/Pictures/PokeAmie/affection")
  187.     if @pokemon.getAffectionLevel>=5
  188.       @sprites["affection"].setBitmap("Graphics/Pictures/PokeAmie/affection5")
  189.     elsif @pokemon.getAffectionLevel>=4
  190.       @sprites["affection"].setBitmap("Graphics/Pictures/PokeAmie/affection4")
  191.     elsif @pokemon.getAffectionLevel>=3
  192.       @sprites["affection"].setBitmap("Graphics/Pictures/PokeAmie/affection3")
  193.     elsif @pokemon.getAffectionLevel>=2
  194.       @sprites["affection"].setBitmap("Graphics/Pictures/PokeAmie/affection2")
  195.     elsif @pokemon.getAffectionLevel>=1
  196.       @sprites["affection"].setBitmap("Graphics/Pictures/PokeAmie/affection1")
  197.     end
  198.     @custom = false
  199.     # Execute transition
  200.     Graphics.transition
  201.     # Main loop
  202.     loop do
  203.       # Update game screen
  204.       Graphics.update
  205.       # Update input information
  206.       Input.update
  207.       # Frame update
  208.       update
  209.       # Abort loop if screen is changed
  210.       if $scene != self
  211.         break
  212.       end
  213.     end
  214.     # Prepares for transition
  215.     Graphics.freeze
  216.     # Disposes the windows
  217.     pbDisposeSpriteHash(@sprites)
  218.     @viewport.dispose
  219.   end
  220.  
  221.   def pbBackdrop
  222.     environ=pbGetEnvironment
  223.     # Choose backdrop
  224.     backdrop="Field"
  225.     if environ==PBEnvironment::Cave
  226.       backdrop="Cave"
  227.     elsif environ==PBEnvironment::MovingWater || environ==PBEnvironment::StillWater
  228.       backdrop="Water"
  229.     elsif environ==PBEnvironment::Underwater
  230.       backdrop="Underwater"
  231.     elsif environ==PBEnvironment::Rock
  232.       backdrop="Mountain"
  233.     else
  234.       if !$game_map || !pbGetMetadata($game_map.map_id,MetadataOutdoor)
  235.         backdrop="IndoorA"
  236.       end
  237.     end
  238.     if $game_map
  239.       back=pbGetMetadata($game_map.map_id,MetadataBattleBack)
  240.       if back && back!=""
  241.         backdrop=back
  242.       end
  243.     end
  244.     if $PokemonGlobal && $PokemonGlobal.nextBattleBack
  245.       backdrop=$PokemonGlobal.nextBattleBack
  246.     end
  247.     # Apply graphics
  248.     battlebg="Graphics/Battlebacks/battlebg"+backdrop
  249.     return battlebg
  250.  
  251.     #pbDayNightTint(@sprites["battlebg"])
  252.   end
  253.  
  254.   #-----------------------------------------------------------------------------
  255.   # * Frame Update
  256.   #-----------------------------------------------------------------------------
  257.   def update
  258.     # Update windows
  259.     @sprites["affection"].setBitmap("Graphics/Pictures/PokeAmie/affection")
  260.     if @pokemon.getAffectionLevel>=5
  261.       @sprites["affection"].setBitmap("Graphics/Pictures/PokeAmie/affection5")
  262.     elsif @pokemon.getAffectionLevel>=4
  263.       @sprites["affection"].setBitmap("Graphics/Pictures/PokeAmie/affection4")
  264.     elsif @pokemon.getAffectionLevel>=3
  265.       @sprites["affection"].setBitmap("Graphics/Pictures/PokeAmie/affection3")
  266.     elsif @pokemon.getAffectionLevel>=2
  267.       @sprites["affection"].setBitmap("Graphics/Pictures/PokeAmie/affection2")
  268.     elsif @pokemon.getAffectionLevel>=1
  269.       @sprites["affection"].setBitmap("Graphics/Pictures/PokeAmie/affection1")
  270.     end
  271.     pbUpdateSpriteHash(@sprites)
  272.     if @custom
  273.       updateCustom
  274.     else
  275.       update_command
  276.     end
  277.     return
  278.   end
  279.   #-----------------------------------------------------------------------------
  280.   # * Frame Update (when command window is active)
  281.   #-----------------------------------------------------------------------------
  282.   def updateCustom
  283.     if Input.trigger?(Input::B)
  284.       @sprites["command_window"].commands=@choices
  285.       @sprites["command_window"].index=2
  286.       @custom = false
  287.       return
  288.     end
  289.     if Input.trigger?(Input::C)
  290.       # if (self.nature%5)==flavor && (self.nature/5).floor!=(self.nature%5)
  291.       Kernel.pbMessage(_INTL("This feature is coming soon."))
  292.     end
  293.   end
  294.  
  295.   def hasBean?
  296.     if !$Trainer.beans
  297.       $Trainer.beans=[]
  298.       for i in 0..16
  299.         $Trainer.beans.push(0)
  300.       end
  301.     end
  302.     return $Trainer.beans.any? {|item| item > 0 }
  303.   end
  304.  
  305.   def canEat?(species)
  306.     return !(isConst?(species,PBSpecies,:METAPOD) ||
  307.       isConst?(species,PBSpecies,:KAKUNA) ||
  308.       isConst?(species,PBSpecies,:PINECO) ||
  309.       isConst?(species,PBSpecies,:SILCOON) ||
  310.       isConst?(species,PBSpecies,:CASCOON) ||
  311.       isConst?(species,PBSpecies,:SHEDNINJA) ||
  312.       isConst?(species,PBSpecies,:SPEWPA) ||
  313.       isConst?(species,PBSpecies,:COSMOEN))
  314.   end
  315.    
  316.   def update_command
  317.     # If B button was pressed
  318.     if Input.trigger?(Input::B)
  319.       pbPlayCancelSE()
  320.       # Switch to map screen
  321.       $scene = Scene_Pokegear.new
  322.       return
  323.     end
  324.     # If C button was pressed
  325.     if Input.trigger?(Input::C)
  326.       # Branch by command window cursor position
  327.       case @sprites["command_window"].index
  328.       when 0 # Pet
  329.         $Trainer.party[@partyIndex].changeAmieStats("pet")
  330.         Kernel.pbMessage(_INTL("Affection and Enjoyment increased."))
  331.       when 1 # Feed
  332.         if canEat?($Trainer.party[@partyIndex].species)
  333.           if hasBean?
  334.             commands=[]
  335.             for i in 0..16
  336.               commands.push(sprintf("x%03d - %s",$Trainer.beans[i],BeanColors.getName(i)))
  337.             end
  338.             bean=Kernel.pbMessage(_INTL("What do you want to feed them?"),commands,-1)
  339.             if bean==-1
  340.               return
  341.             elsif $Trainer.beans[bean]<1
  342.               Kernel.pbMessage(_INTL("You have no beans of that type."))
  343.               return
  344.             elsif bean<=BeanColors::Pink
  345.               $Trainer.party[@partyIndex].changeAmieStats("feedPlainBean")
  346.               $Trainer.beans[bean]-=1
  347.             elsif bean<=BeanColors::PinkPatterned
  348.               $Trainer.party[@partyIndex].changeAmieStats("feedPatternBean")
  349.               $Trainer.beans[bean]-=1
  350.             else
  351.               $Trainer.party[@partyIndex].changeAmieStats("feedRainbowBean")
  352.               $Trainer.beans[bean]-=1
  353.             end
  354.           else
  355.             Kernel.pbMessage(_INTL("You have no beans."))
  356.           end
  357.         else
  358.           Kernel.pbMessage(_INTL("{1} can't eat beans.",$Trainer.party[@partyIndex].name))
  359.         end
  360.       when 2 # Exit
  361.         pbPlayDecisionSE()
  362.         $scene = Scene_Pokegear.new
  363.       end
  364.       return
  365.     end
  366.   end
  367. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement