Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 23.61 KB | None | 0 0
  1. #----------------------------------------------------------------------------
  2. # Final Fantasy Tactics Advance Shop System By Mac      v. 0.7
  3. #----------------------------------------------------------------------------
  4. # Basically as it says in the title, this makes your shop system just like
  5. # that of FFTA but due to being aliased you have the option at any point to
  6. # switch it too and from the default system whenever you see fit.
  7. #----------------------------------------------------------------------------
  8. # Firstly to make this active in game you need to do a call script and call this:-
  9. # $game_temp.call_fftshopsystem = true
  10. #
  11. # Then at any point you can call it again but with false to return it to the
  12. # default shop system, or if you want this system to always stay on simply
  13. # change the line:-
  14. #
  15. # @call_fftshopsystem = false
  16. #
  17. # Too:-
  18. #
  19. # @call_fftshopsystem = true
  20. #----------------------------------------------------------------------------
  21. #==============================================================================
  22. # ** Game_Temp
  23. #==============================================================================
  24. class Game_Temp
  25.  #--------------------------------------------------------------------------
  26.  # * Public Instance Variables
  27.  #--------------------------------------------------------------------------
  28.  attr_accessor :call_fftshopsystem
  29.  #--------------------------------------------------------------------------
  30.  # * Object Initialization
  31.  #--------------------------------------------------------------------------
  32.  alias_method :mac_fftshop_init, :initialize
  33.  def initialize
  34.    # Original Initialization
  35.    mac_fftshop_init
  36.    # Set Call FFT Shop False
  37.    @call_fftshopsystem = false
  38.  end
  39. end
  40. #==============================================================================
  41. # ** Game_Party
  42. #==============================================================================
  43. class Game_Party
  44.  #--------------------------------------------------------------------------
  45.  # * Total Weapon Number
  46.  #--------------------------------------------------------------------------
  47.  def total_weapon_number(weapon_id)
  48.    n = weapon_number(weapon_id)
  49.    n += equipped_weapon_number(weapon_id)
  50.    return n
  51.  end
  52.  #--------------------------------------------------------------------------
  53.  # * Equipped Weapon Number
  54.  #--------------------------------------------------------------------------
  55.  def equipped_weapon_number(weapon_id)
  56.    n = 0
  57.    @actors.each do |actor|
  58.      n += 1 if actor.weapon_id == weapon_id
  59.    end
  60.    return n
  61.  end
  62.  #--------------------------------------------------------------------------
  63.  # * Total Armor Number
  64.  #--------------------------------------------------------------------------
  65.  def total_armor_number(armor_id)
  66.    n = armor_number(armor_id)
  67.    n += equipped_armor_number(armor_id)
  68.    return n
  69.  end
  70.  #--------------------------------------------------------------------------
  71.  # * Equipped Armor Number
  72.  #--------------------------------------------------------------------------
  73.  def equipped_armor_number(armor_id)
  74.    n = 0
  75.    @actors.each do |actor|
  76.      n += 1 if actor.armor1_id == armor_id
  77.      n += 1 if actor.armor2_id == armor_id
  78.      n += 1 if actor.armor3_id == armor_id
  79.      n += 1 if actor.armor4_id == armor_id
  80.    end
  81.    return n
  82.  end
  83. end
  84. #==============================================================================
  85. # ** Scene_Shop
  86. #==============================================================================
  87. class Scene_Shop
  88.  #--------------------------------------------------------------------------
  89.  # * Main Processing
  90.  #--------------------------------------------------------------------------
  91.  alias_method :mac_fftshop_main, :main
  92.  def main
  93.    # If Call FFT Shop
  94.    if $game_temp.call_fftshopsystem
  95.      # Change to FFT Shop
  96.      $scene = FFT_ShopSystem::Scene_Shop.new
  97.      # Turn call FFT Shop off
  98.      $game_temp.call_fftshopsystem = false
  99.      # End Method
  100.      return
  101.    end
  102.    # Original Method
  103.    mac_fftshop_main
  104.  end
  105. end
  106. #==============================================================================
  107. # ** FFT_ShopSystem
  108. #==============================================================================
  109. module FFT_ShopSystem
  110. #==========================================================================
  111. # ** Window_ShopCommand
  112. #==========================================================================
  113.  class Window_ShopCommand < ::Window_Command
  114.    #--------------------------------------------------------------------------
  115.    # * Object Initialization
  116.    #--------------------------------------------------------------------------
  117.    def initialize
  118.      super(180, ['Buy', 'Sell', 'Exit'])
  119.      # Reassign Window Parameters
  120.      self.x, self.y, self.opacity = 16, 336, 0
  121.      # Creates Background Graphic
  122.      @command_graphic = Sprite.new
  123.      @command_graphic.bitmap = RPG::Cache.picture('Shop Command')
  124.      @command_graphic.x = self.x + 1
  125.      @command_graphic.y = self.y + 7
  126.      @command_graphic.z = self.z - 1
  127.      @command_graphic.visible = true
  128.      @gold_graphic = Sprite.new
  129.      @gold_graphic.bitmap = RPG::Cache.picture('Gold Window')
  130.      @gold_graphic.x = self.x + 480
  131.      @gold_graphic.y = self.y + 104
  132.      @gold_graphic.z = self.z - 2
  133.      @gold_graphic.visible = true
  134.    end
  135.    #--------------------------------------------------------------------------
  136.    # * Frame Update
  137.    #--------------------------------------------------------------------------
  138.    def update
  139.      super
  140.      @command_graphic.visible = self.visible
  141.      @gold_graphic.visible = self.visible
  142.    end
  143.    #--------------------------------------------------------------------------
  144.    # * Dispose
  145.    #--------------------------------------------------------------------------
  146.    def dispose
  147.      super
  148.      @command_graphic.dispose
  149.      @gold_graphic.dispose
  150.    end
  151.  end
  152.  
  153. #==========================================================================
  154. # ** Window_ShopBuy
  155. #==========================================================================
  156.  class Window_ShopBuy < ::Window_ShopBuy
  157.    #--------------------------------------------------------------------------
  158.    # * Object Initialization
  159.    #--------------------------------------------------------------------------
  160.    def initialize(shop_goods)
  161.      super(shop_goods)
  162.      # Reassign Window Parameters
  163.      self.x, self.y, self.width, self.height = 16, 20, 600, 228
  164.      self.opacity, self.visible, self.active = 0, false, false
  165.      # Creates Showback Graphic
  166.      @showback_graphic = Sprite.new
  167.      @showback_graphic.bitmap = RPG::Cache.picture('Shop Window')
  168.      @showback_graphic.x = self.x + 1
  169.      @showback_graphic.y = self.y + 1
  170.      @showback_graphic.z = self.z - 1
  171.      @showback_graphic.visible = self.visible
  172.    end
  173.    #--------------------------------------------------------------------------
  174.    # * Draw Item
  175.    #--------------------------------------------------------------------------
  176.    def draw_item(index)
  177.      # Gets item Number
  178.      item = @data[index]
  179.      # Gets Number Owned & Equipped
  180.      case item
  181.      when RPG::Item
  182.        number = $game_party.item_number(item.id)
  183.        equipped_number = 0
  184.      when RPG::Weapon
  185.        number = $game_party.weapon_number(item.id)
  186.        equipped_number = $game_party.equipped_weapon_number(item.id)
  187.      when RPG::Armor
  188.        number = $game_party.armor_number(item.id)
  189.        equipped_number = $game_party.equipped_armor_number(item.id)
  190.      end
  191.      # Adjust Color By Price
  192.      if item.price <= $game_party.gold and number < 99
  193.        self.contents.font.color = normal_color
  194.      else
  195.        self.contents.font.color = disabled_color
  196.      end
  197.      # Clears Area
  198.      rect = Rect.new(0, index * 32, contents.width, 32)
  199.      self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  200.      # Draws Icon
  201.      bitmap = RPG::Cache.icon(item.icon_name)
  202.      opacity = self.contents.font.color == normal_color ? 255 : 128
  203.      self.contents.blt(4, index * 32 + 4, bitmap, Rect.new(0, 0, 24, 24),
  204.        opacity)
  205.      # Draws Item Name, Total, Equipped and Price
  206.      self.contents.draw_text(32, index * 32, 212, 32, item.name, 0)
  207.      self.contents.draw_text(374, index * 32, 88, 32,
  208.        (number + equipped_number).to_s, 2)
  209.      self.contents.draw_text(294, index * 32, 88, 32, equipped_number.to_s, 2)
  210.      self.contents.draw_text(464, index * 32, 88, 32, item.price.to_s, 2)
  211.    end
  212.    #--------------------------------------------------------------------------
  213.    # * Update
  214.    #--------------------------------------------------------------------------
  215.    def update
  216.      super
  217.      @showback_graphic.visible = self.visible
  218.    end
  219.    #--------------------------------------------------------------------------
  220.    # * Dispose
  221.    #--------------------------------------------------------------------------
  222.    def dispose
  223.      super
  224.      @showback_graphic.dispose
  225.    end
  226.  end
  227.  
  228. #==========================================================================
  229. # ** Window_ShopSell
  230. #==========================================================================
  231.  
  232.  class Window_ShopSell < ::Window_ShopSell
  233.    #--------------------------------------------------------------------------
  234.    # * Object Initialization
  235.    #--------------------------------------------------------------------------
  236.    def initialize
  237.      super
  238.      # Reassign Window Parameters
  239.      self.x, self.y, self.width, self.height = 16, 20, 600, 228
  240.      self.opacity, self.visible, self.active = 0, false, false
  241.      # Creates Showback Graphic
  242.      @showback_graphic = Sprite.new
  243.      @showback_graphic.bitmap = RPG::Cache.picture('Shop Window')
  244.      @showback_graphic.x = self.x + 1
  245.      @showback_graphic.y = self.y + 1
  246.      @showback_graphic.z = self.z - 1
  247.      @showback_graphic.visible = self.visible
  248.      # Adjust Column Max
  249.      @column_max = 1
  250.    end
  251.    #--------------------------------------------------------------------------
  252.    # * Draw Item
  253.    #--------------------------------------------------------------------------
  254.    def draw_item(index)
  255.      # Gets Item Data
  256.      item = @data[index]
  257.      # Gets Number & Equipped Number
  258.      case item
  259.      when RPG::Item
  260.        number = $game_party.item_number(item.id)
  261.        equipped_number = 0
  262.      when RPG::Weapon
  263.        number = $game_party.weapon_number(item.id)
  264.        equipped_number = $game_party.equipped_weapon_number(item.id)
  265.      when RPG::Armor
  266.        number = $game_party.armor_number(item.id)
  267.        equipped_number = $game_party.equipped_armor_number(item.id)
  268.      end
  269.      # Adjust Font Color By Price
  270.      if item.price > 0
  271.        self.contents.font.color = normal_color
  272.      else
  273.        self.contents.font.color = disabled_color
  274.      end
  275.      # Clears Area
  276.      rect = Rect.new(0, index * 32, contents.width, 32)
  277.      self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  278.      # Draws Icon
  279.      bitmap = RPG::Cache.icon(item.icon_name)
  280.      opacity = self.contents.font.color == normal_color ? 255 : 128
  281.      self.contents.blt(4, index * 32 + 4, bitmap, Rect.new(0, 0, 24, 24),
  282.        opacity)
  283.      # Draws Item Name, Total Owned, Equipped and Price
  284.      self.contents.draw_text(32, index * 32, 212, 32, item.name, 0)
  285.      self.contents.draw_text(374, index * 32, 88, 32,
  286.        (number + equipped_number).to_s, 2)
  287.      self.contents.draw_text(294, index * 32, 88, 32, equipped_number.to_s, 2)
  288.      self.contents.draw_text(464, index * 32, 88, 32,
  289.        (item.price / 2).to_s, 2)
  290.    end
  291.    #--------------------------------------------------------------------------
  292.    # * Update
  293.    #--------------------------------------------------------------------------
  294.    def update
  295.      super
  296.      @showback_graphic.visible = self.visible
  297.    end
  298.    #--------------------------------------------------------------------------
  299.    # * Dispose
  300.    #--------------------------------------------------------------------------
  301.    def dispose
  302.      super
  303.      @showback_graphic.dispose
  304.    end
  305.  end
  306.  
  307. #==========================================================================
  308. # ** Window_ShopNumber
  309. #==========================================================================
  310.  
  311.  class Window_ShopNumber < ::Window_ShopNumber
  312.    #--------------------------------------------------------------------------
  313.    # * Object Initialization
  314.    #--------------------------------------------------------------------------
  315.    def initialize
  316.      super
  317.      # Reassign Window Parameters
  318.      self.x, self.y, self.width, self.height, self.opacity = 450, 242, 65, 64, 0
  319.      # Recreates Window Contents
  320.      @number_graphic = Sprite.new
  321.      @number_graphic.bitmap = RPG::Cache.picture('Shop Number')
  322.      @number_graphic.x = self.x + 3
  323.      @number_graphic.y = self.y + 14
  324.      @number_graphic.z = self.z - 1
  325.      @number_graphic.visible = false
  326.      self.contents = Bitmap.new(width - 32, height - 32)
  327.      self.visible, self.active = false, false
  328.    end
  329.    #--------------------------------------------------------------------------
  330.    # * Update
  331.    #--------------------------------------------------------------------------
  332.      def update
  333.      super
  334.      @number_graphic.visible = self.visible
  335.    end
  336.    #--------------------------------------------------------------------------
  337.    # * Dispose
  338.    #--------------------------------------------------------------------------
  339.    def dispose
  340.      super
  341.      @number_graphic.dispose
  342.    end
  343.    #--------------------------------------------------------------------------
  344.    # * Refresh
  345.    #--------------------------------------------------------------------------
  346.    def refresh
  347.      self.contents.clear
  348.      self.contents.font.color = Color.new(0, 0, 0, 255)
  349.      self.contents.draw_text(0, 0, 25, 32, "?")
  350.      self.contents.draw_text(-25, 0, 56, 32, "#{@number}", 2)
  351.      self.cursor_rect.set(256, 0, 64, 32)
  352.      end
  353.  end
  354.  
  355. #==========================================================================
  356. # ** FFT_ShopSystem
  357. #==========================================================================
  358.  
  359.  
  360.  class Scene_Shop
  361.    #--------------------------------------------------------------------------
  362.    # * Main Processing
  363.    #--------------------------------------------------------------------------
  364.    def main
  365.      # Memorize BGM & Play Shop Music
  366.      $game_system.bgm_memorize
  367.      #$game_temp.map_bgm = $game_system.playing_bgm
  368.      Audio.bgm_play("Audio/BGM/Shop.mp3", 100, 100)
  369.      # Create Command Window
  370.      @command_window = Window_ShopCommand.new
  371.      # Create Spriteset
  372.      @spriteset = Spriteset_Map.new
  373.      # Create Gold Window
  374.      @gold_window = Window_Gold.new
  375.      @gold_window.opacity = 0
  376.      @gold_window.x = 650 - @gold_window.width - 16
  377.      @gold_window.y = 500 - @gold_window.height - 16
  378.      # Create Buy Window
  379.      @buy_window = FFT_ShopSystem::Window_ShopBuy.new($game_temp.shop_goods)
  380.      @buy_window.help_window = @help_window
  381.      # Create Sell Window
  382.      @sell_window = FFT_ShopSystem::Window_ShopSell.new
  383.      @sell_window.help_window = @help_window
  384.      # Create Number Window
  385.      @number_window = FFT_ShopSystem::Window_ShopNumber.new
  386.      # Transition run
  387.      Graphics.transition
  388.      # Main loop
  389.      loop do
  390.        # Update game screen
  391.        Graphics.update
  392.        # Update input information
  393.        Input.update
  394.        # Frame update
  395.        update
  396.        # Abort loop if screen is changed
  397.        if $scene != self
  398.          break
  399.        end
  400.      end
  401.      # Prepare for transition
  402.      Graphics.freeze
  403.      # Dispose Scene Objects
  404.      @spriteset.dispose
  405.      @command_window.dispose
  406.      @gold_window.dispose
  407.      @buy_window.dispose
  408.      @sell_window.dispose
  409.      @number_window.dispose
  410.    end
  411.    #--------------------------------------------------------------------------
  412.    # * Frame Update
  413.    #--------------------------------------------------------------------------
  414.    def update
  415.      # Update windows
  416.      @command_window.update
  417.      @gold_window.update
  418.      @buy_window.update
  419.      @sell_window.update
  420.      @number_window.update
  421.      # If command window is active: call update_command
  422.      if @command_window.active
  423.        update_command
  424.        return
  425.      # If buy window is active: call update_buy
  426.      elsif @buy_window.active
  427.        update_buy
  428.        return
  429.      # If sell window is active: call update_sell
  430.      elsif @sell_window.active
  431.        update_sell
  432.        return
  433.      # If quantity input window is active: call update_number
  434.      elsif @number_window.active
  435.        update_number
  436.        return
  437.      end
  438.    end
  439.    #--------------------------------------------------------------------------
  440.    # * Frame Update (when command window is active)
  441.    #--------------------------------------------------------------------------
  442.    def update_command
  443.      # If B button was pressed
  444.      if Input.trigger?(Input::B)
  445.        # Play cancel SE
  446.        $game_system.se_play($data_system.cancel_se)
  447.        $game_system.bgm_restore
  448.        # Switch to map screen
  449.        $scene = Scene_Map.new
  450.        return
  451.      end
  452.      # If C button was pressed
  453.      if Input.trigger?(Input::C)
  454.        # Play decision SE
  455.        $game_system.se_play($data_system.decision_se)
  456.        # Branch by command window cursor position
  457.        case @command_window.index
  458.        when 0  # buy
  459.          # Change windows to buy mode
  460.          @command_window.active = false
  461.          @buy_window.active = true
  462.          @buy_window.visible = true
  463.          @buy_window.refresh
  464.        when 1  # sell
  465.          # Change windows to sell mode
  466.          @command_window.active = false
  467.          @sell_window.active = true
  468.          @sell_window.visible = true
  469.          @sell_window.refresh
  470.        when 2  # quit
  471.          $game_system.bgm_restore
  472.          # Switch to map screen
  473.          $scene = Scene_Map.new
  474.        end
  475.        return
  476.      end
  477.    end
  478.    #--------------------------------------------------------------------------
  479.    # * Frame Update (when buy window is active)
  480.    #--------------------------------------------------------------------------
  481.    def update_buy
  482.      # If B button was pressed
  483.      if Input.trigger?(Input::B)
  484.        # Play cancel SE
  485.        $game_system.se_play($data_system.cancel_se)
  486.        # Change windows to initial mode
  487.        @command_window.active = true
  488.        @buy_window.active = false
  489.        @buy_window.visible = false
  490.        return
  491.      end
  492.      # If C button was pressed
  493.      if Input.trigger?(Input::C)
  494.        # Get item
  495.        @item = @buy_window.item
  496.        # If item is invalid, or price is higher than money possessed
  497.        if @item == nil or @item.price > $game_party.gold
  498.          # Play buzzer SE
  499.          $game_system.se_play($data_system.buzzer_se)
  500.          return
  501.        end
  502.        # Get items in possession count
  503.        case @item
  504.        when RPG::Item
  505.          number = $game_party.item_number(@item.id)
  506.        when RPG::Weapon
  507.          number = $game_party.weapon_number(@item.id)
  508.        when RPG::Armor
  509.          number = $game_party.armor_number(@item.id)
  510.        end
  511.        # If 99 items are already in possession
  512.        if number == 99
  513.          # Play buzzer SE
  514.          $game_system.se_play($data_system.buzzer_se)
  515.          return
  516.        end
  517.        # Play decision SE
  518.        $game_system.se_play($data_system.decision_se)
  519.        # Calculate maximum amount possible to buy
  520.        max = @item.price == 0 ? 99 : $game_party.gold / @item.price
  521.        max = [max, 99 - number].min
  522.        # Turn Buy Window Off
  523.        @buy_window.active = false
  524.        # Change windows to quantity input mode
  525.        @number_window.set(@item, max, @item.price)
  526.        @number_window.active = true
  527.        @number_window.visible = true
  528.      end
  529.    end
  530.    #--------------------------------------------------------------------------
  531.    # * Frame Update (when sell window is active)
  532.    #--------------------------------------------------------------------------
  533.    def update_sell
  534.      # If B button was pressed
  535.      if Input.trigger?(Input::B)
  536.        # Play cancel SE
  537.        $game_system.se_play($data_system.cancel_se)
  538.        # Change windows to initial mode
  539.        @command_window.active = true
  540.        @sell_window.active = false
  541.        @sell_window.visible = false
  542.        return
  543.      end
  544.      # If C button was pressed
  545.      if Input.trigger?(Input::C)
  546.        # Get item
  547.        @item = @sell_window.item
  548.        # If item is invalid, or item price is 0 (unable to sell)
  549.        if @item == nil or @item.price == 0
  550.          # Play buzzer SE
  551.          $game_system.se_play($data_system.buzzer_se)
  552.          return
  553.        end
  554.        # Play decision SE
  555.        $game_system.se_play($data_system.decision_se)
  556.        # Get items in possession count
  557.        case @item
  558.        when RPG::Item
  559.          number = $game_party.item_number(@item.id)
  560.        when RPG::Weapon
  561.          number = $game_party.weapon_number(@item.id)
  562.        when RPG::Armor
  563.          number = $game_party.armor_number(@item.id)
  564.        end
  565.        # Maximum quanitity to sell = number of items in possession
  566.        max = number
  567.        # Turn Sell Window Off
  568.        @sell_window.active = false
  569.        # Change windows to quantity input mode
  570.        @number_window.set(@item, max, @item.price / 2)
  571.        @number_window.active = true
  572.        @number_window.visible = true
  573.      end
  574.    end
  575.    #--------------------------------------------------------------------------
  576.    # * Frame Update (when quantity input window is active)
  577.    #--------------------------------------------------------------------------
  578.    def update_number
  579.      # If B button was pressed
  580.      if Input.trigger?(Input::B)
  581.        # Play cancel SE
  582.        $game_system.se_play($data_system.cancel_se)
  583.        # Set quantity input window to inactive / invisible
  584.        case @command_window.index
  585.        when 0
  586.        @buy_window.active = true
  587.        @number_window.active = false
  588.        @number_window.visible = false
  589.        when 1
  590.        @sell_window.active = true
  591.        @number_window.active = false
  592.        @number_window.visible = false
  593.        return
  594.      end
  595.      end
  596.      # If C button was pressed
  597.      if Input.trigger?(Input::C)
  598.        # Play shop SE
  599.        $game_system.se_play($data_system.shop_se)
  600.        # Set quantity input window to inactive / invisible
  601.        @number_window.active = false
  602.        @number_window.visible = false
  603.        # Branch by command window cursor position
  604.        case @command_window.index
  605.        when 0  # buy
  606.          # Buy process
  607.          $game_party.lose_gold(@number_window.number * @item.price)
  608.          case @item
  609.          when RPG::Item
  610.            $game_party.gain_item(@item.id, @number_window.number)
  611.          when RPG::Weapon
  612.            $game_party.gain_weapon(@item.id, @number_window.number)
  613.          when RPG::Armor
  614.            $game_party.gain_armor(@item.id, @number_window.number)
  615.          end
  616.          # Refresh each window
  617.          @gold_window.refresh
  618.          @buy_window.refresh
  619.          # Change windows to buy mode
  620.          @buy_window.active = true
  621.          @buy_window.visible = true
  622.        when 1  # sell
  623.          # Sell process
  624.          $game_party.gain_gold(@number_window.number * (@item.price / 2))
  625.          case @item
  626.          when RPG::Item
  627.            $game_party.lose_item(@item.id, @number_window.number)
  628.          when RPG::Weapon
  629.            $game_party.lose_weapon(@item.id, @number_window.number)
  630.          when RPG::Armor
  631.            $game_party.lose_armor(@item.id, @number_window.number)
  632.          end
  633.          # Refresh each window
  634.          @gold_window.refresh
  635.          @sell_window.refresh
  636.          # Change windows to sell mode
  637.          @sell_window.active = true
  638.          @sell_window.visible = true
  639.        end
  640.        return
  641.      end
  642.    end
  643.  end
  644. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement