Advertisement
roninator2

Kid Friendly Basic Quest - Weapon Menu with Bombs

Dec 14th, 2024
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 23.23 KB | None | 0 0
  1. # ╔═════════════════════════════════════╦════════════════════╗
  2. # ║ Title: KFBQ Weapon Screen + Bombs   ║  Version: 1.00     ║
  3. # ║ Author: Roninator2                  ║                    ║
  4. # ╠═════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                           ║   Date Created     ║
  6. # ║                                     ╠════════════════════╣
  7. # ║   FFMQ Style Weapon Screen          ║    09 Mar 2023     ║
  8. # ╚═════════════════════════════════════╩════════════════════╝
  9. # ╔══════════════════════════════════════════════════════════╗
  10. # ║ Instructions:                                            ║
  11. # ║                                                          ║
  12. # ║  When giving the player the bomb also use the            ║
  13. # ║  script command: give_bombs(25)                          ║
  14. # ║  then the player will be able to use bombs and the       ║
  15. # ║  weapons screen will reflect the current amount left     ║
  16. # ║  Same goes for the ninja stars for the second player     ║
  17. # ║  use script command: give_ninja_stars(75)                ║
  18. # ║                                                          ║
  19. # ╚══════════════════════════════════════════════════════════╝
  20. # ╔═════════════════════════════════════╗
  21. # ║ Terms of use:                       ║
  22. # ║ Free for all uses in RPG Maker      ║
  23. # ╚═════════════════════════════════════╝
  24.  
  25. #==============================================================================
  26. # ** Game_Party
  27. #==============================================================================
  28. class Game_Party < Game_Unit
  29.   #--------------------------------------------------------------------------
  30.   # * Public Instance Variables
  31.   #--------------------------------------------------------------------------
  32.   attr_reader   :bombs
  33.   attr_reader   :ninja_stars
  34.   #--------------------------------------------------------------------------
  35.   # * Initialize All Item Lists
  36.   #--------------------------------------------------------------------------
  37.   alias r2_init_bombs_init_all  init_all_items
  38.   def init_all_items
  39.     r2_init_bombs_init_all
  40.     @bomb_count = 0
  41.     @ninja_stars = 0
  42.   end
  43.   #--------------------------------------------------------------------------
  44.   # * Get Number of bomb in inventory
  45.   #--------------------------------------------------------------------------
  46.   def add_bombs(value)
  47.     @bomb_count += value
  48.   end
  49.   #--------------------------------------------------------------------------
  50.   # * Get Number of bomb in inventory
  51.   #--------------------------------------------------------------------------
  52.   def bombs?
  53.     return @bomb_count
  54.   end
  55.   #--------------------------------------------------------------------------
  56.   # * Remove 1 bomb from inventory
  57.   #--------------------------------------------------------------------------
  58.   def use_bomb(value = false)
  59.     @bomb_count -= 1 if value
  60.   end
  61.   #--------------------------------------------------------------------------
  62.   # * Get Number of ninja stars in inventory
  63.   #--------------------------------------------------------------------------
  64.   def add_ninja_stars(value)
  65.     @ninja_stars += value
  66.   end
  67.   #--------------------------------------------------------------------------
  68.   # * Get Number of ninja stars in inventory
  69.   #--------------------------------------------------------------------------
  70.   def ninja_stars?
  71.     return @ninja_stars
  72.   end
  73.   #--------------------------------------------------------------------------
  74.   # * Remove 1 ninja star from inventory
  75.   #--------------------------------------------------------------------------
  76.   def use_star(value = false)
  77.     @ninja_stars -= 1 if value
  78.   end
  79. end
  80.  
  81. #==============================================================================
  82. # ** Game_Interpreter
  83. #==============================================================================
  84. class Game_Interpreter
  85.   #--------------------------------------------------------------------------
  86.   # * Add Bombs to Party
  87.   #--------------------------------------------------------------------------
  88.   def add_bombs(value)
  89.     $game_party.add_bombs(value)
  90.   end
  91.   #--------------------------------------------------------------------------
  92.   # * Add Ninja Stars to Party
  93.   #--------------------------------------------------------------------------
  94.   def add_ninja_stars(value)
  95.     $game_party.add_ninja_stars(value)
  96.   end
  97. end
  98.  
  99. #==============================================================================
  100. # ** Window WeaponHelp
  101. #==============================================================================
  102. class Window_WeaponHelp < Window_Base
  103.   #--------------------------------------------------------------------------
  104.   # * Object Initialization
  105.   #--------------------------------------------------------------------------
  106.   def initialize(line_number = 1)
  107.     super(0, 0, Graphics.width / 2, fitting_height(line_number))
  108.   end
  109.   #--------------------------------------------------------------------------
  110.   # * Set Text
  111.   #--------------------------------------------------------------------------
  112.   def set_text(text)
  113.     if text != @text
  114.       @text = text
  115.       refresh
  116.     end
  117.   end
  118.   #--------------------------------------------------------------------------
  119.   # * Clear
  120.   #--------------------------------------------------------------------------
  121.   def clear
  122.     set_text("")
  123.   end
  124.   #--------------------------------------------------------------------------
  125.   # * Set Item
  126.   #     item : Skills and items etc.
  127.   #--------------------------------------------------------------------------
  128.   def set_item(item)
  129.     set_text(item ? item.name : "")
  130.   end
  131.   #--------------------------------------------------------------------------
  132.   # * Refresh
  133.   #--------------------------------------------------------------------------
  134.   def refresh
  135.     contents.clear
  136.     draw_text_ex(4, 0, @text)
  137.   end
  138. end
  139.  
  140. #==============================================================================
  141. # ** Window Weapon Description
  142. #==============================================================================
  143. class Window_WeaponDescription < Window_Base
  144.   #--------------------------------------------------------------------------
  145.   # * Object Initialization
  146.   #--------------------------------------------------------------------------
  147.   def initialize(line_number = 3)
  148.     super(0, 48, Graphics.width / 2 + 60, fitting_height(line_number))
  149.   end
  150.   #--------------------------------------------------------------------------
  151.   # * Set Text
  152.   #--------------------------------------------------------------------------
  153.   def set_text(text)
  154.     if text != @text
  155.       @text = text
  156.       refresh
  157.     end
  158.   end
  159.   #--------------------------------------------------------------------------
  160.   # * Clear
  161.   #--------------------------------------------------------------------------
  162.   def clear
  163.     set_text("")
  164.     @item = nil
  165.   end
  166.   #--------------------------------------------------------------------------
  167.   # * Set Item
  168.   #     item : Skills and items etc.
  169.   #--------------------------------------------------------------------------
  170.   def set_item(item)
  171.     @item = item
  172.     set_text(item ? item.description : "")
  173.   end
  174.   #--------------------------------------------------------------------------
  175.   # * Refresh
  176.   #--------------------------------------------------------------------------
  177.   def refresh
  178.     contents.clear
  179.     draw_text_ex(4, 0, @text)
  180.     draw_icons if @item
  181.   end
  182.   #--------------------------------------------------------------------------
  183.   # * Draw Icons
  184.   #--------------------------------------------------------------------------
  185.   def draw_icons
  186.     data = []
  187.     list = @item.features
  188.     list.each do |fet|
  189.       if fet.code == 14
  190.         state = $data_states[fet.data_id]
  191.         data << state
  192.       end
  193.     end
  194.     data.each do |st|
  195.       num = st.id
  196.       y = 24
  197.       y = 48 if num >= 11
  198.       num -= 11 if num >= 11
  199.       draw_icon(st.icon_index, num * 24, y)
  200.     end
  201.   end
  202.   #--------------------------------------------------------------------------
  203.   # * Update Bottom Padding
  204.   #--------------------------------------------------------------------------
  205.   def update_padding_bottom
  206.     surplus = (height - standard_padding * 2) % item_height
  207.     self.padding_bottom = padding + surplus - 20
  208.   end
  209.   #--------------------------------------------------------------------------
  210.   # * Draw Icon
  211.   #     enabled : Enabled flag. When false, draw semi-transparently.
  212.   #--------------------------------------------------------------------------
  213.   def draw_icon(icon_index, x, y, enabled = true)
  214.     bitmap = Cache.system("Iconset")
  215.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  216.     contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
  217.   end
  218. end
  219.  
  220. #==============================================================================
  221. # ** Window_Item_Command
  222. #==============================================================================
  223. class Window_Weapon_Command < Window_Base
  224.   #--------------------------------------------------------------------------
  225.   # Initialize
  226.   #--------------------------------------------------------------------------
  227.   def initialize
  228.     super(Graphics.width / 2, 0, Graphics.width / 2, fitting_height(1))
  229.     refresh
  230.   end
  231.   #--------------------------------------------------------------------------
  232.   # dispose
  233.   #--------------------------------------------------------------------------
  234.   def dispose
  235.     contents.dispose unless disposed?
  236.     super unless disposed?
  237.   end
  238.   #--------------------------------------------------------------------------
  239.   # refresh
  240.   #--------------------------------------------------------------------------
  241.   def refresh
  242.     contents.clear
  243.     change_color(crisis_color)
  244.     name = "Weapons"
  245.     draw_text(4, 0, 200, line_height, name, 1)
  246.   end
  247. end
  248.  
  249. #==============================================================================
  250. # ** Window_ItemList
  251. #==============================================================================
  252. class Window_WeaponList < Window_Selectable
  253.   #--------------------------------------------------------------------------
  254.   # * Object Initialization
  255.   #--------------------------------------------------------------------------
  256.   def initialize(x, y, width, height)
  257.     @height = height
  258.     super
  259.     @category = :none
  260.     @data = []
  261.   end
  262.   #--------------------------------------------------------------------------
  263.   # * Get Digit Count
  264.   #--------------------------------------------------------------------------
  265.   def col_max
  266.     return 4
  267.   end
  268.   #--------------------------------------------------------------------------
  269.   # * Get Number of Items
  270.   #--------------------------------------------------------------------------
  271.   def item_max
  272.     @data ? @data.size : 1
  273.   end
  274.   #--------------------------------------------------------------------------
  275.   # * Get Item
  276.   #--------------------------------------------------------------------------
  277.   def item
  278.     @data && index >= 0 ? @data[index] : nil
  279.   end
  280.   #--------------------------------------------------------------------------
  281.   # * Get Item Height
  282.   #--------------------------------------------------------------------------
  283.   def item_height
  284.     return 60
  285.   end
  286.   #--------------------------------------------------------------------------
  287.   # * Get Activation State of Selection Item
  288.   #--------------------------------------------------------------------------
  289.   def current_item_enabled?
  290.     return true
  291.   end
  292.   #--------------------------------------------------------------------------
  293.   # * Include in Item List?
  294.   #--------------------------------------------------------------------------
  295.   def include?(item)
  296.     case @category
  297.     when :weapon
  298.       item.is_a?(RPG::Weapon) && !item.kfbq_exclude?
  299.     else
  300.       false
  301.     end
  302.   end
  303.   #--------------------------------------------------------------------------
  304.   # * Display in Enabled State?
  305.   #--------------------------------------------------------------------------
  306.   def enable?(item)
  307.     return true
  308.   end
  309.   #--------------------------------------------------------------------------
  310.   # * Create Item List
  311.   #--------------------------------------------------------------------------
  312.   def make_item_list
  313.     @data = []
  314.     subtract = 0
  315.     for i in 1..$data_weapons.size - 1
  316.       weapon = $data_weapons[i]
  317.       if !weapon.kfbq_exclude?
  318.         @data[i-1] = nil unless !@data[i-1].nil?
  319.       else
  320.         subtract += 1
  321.         next
  322.       end
  323.       if $game_party.has_item?(weapon, true)
  324.         weapon.note.split(/[\r\n]+/).each { |line|
  325.           case line
  326.           when /<position:[-_ ](\d+)>/i
  327.             pos = $1.to_i
  328.             @data[pos-1-subtract] = weapon
  329.           end
  330.         }
  331.       end
  332.     end
  333.   end
  334.   #--------------------------------------------------------------------------
  335.   # * Determine if Specified Item Is Included in Members' Equipment
  336.   #--------------------------------------------------------------------------
  337.   def members_equip_include?(item)
  338.     members.any? {|actor|
  339.     return false if actor == members[1]
  340.     return true if actor.equips.include?(item) }
  341.   end
  342.   #--------------------------------------------------------------------------
  343.   # * Set Help Window
  344.   #--------------------------------------------------------------------------
  345.   def description_window=(help_window)
  346.     @description_window = help_window
  347.     call_update_help
  348.   end
  349.   #--------------------------------------------------------------------------
  350.   # * Restore Previous Selection Position
  351.   #--------------------------------------------------------------------------
  352.   def select_last
  353.     select(@data.index($game_party.last_item.object) || 0)
  354.   end
  355.   #--------------------------------------------------------------------------
  356.   # * Draw Item
  357.   #--------------------------------------------------------------------------
  358.   def draw_item(index)
  359.     item = @data[index]
  360.     if item
  361.       pos = index % 4
  362.       case pos
  363.       when 0
  364.         ox = 8
  365.       when 1
  366.         ox = 22
  367.       when 2
  368.         ox = 40
  369.       when 3
  370.         ox = 60
  371.       end
  372.       rect = item_rect(index)
  373.       rect.width -= 4
  374.       rect.x += ox
  375.       draw_icon(item.icon_index, rect.x, rect.y, true)
  376.       draw_item_number(rect, item) if item.bomb_item?
  377.     end
  378.   end
  379.   #--------------------------------------------------------------------------
  380.   # * Draw Number of Items
  381.   #--------------------------------------------------------------------------
  382.   def draw_item_number(rect, item)
  383.     make_font_bigger
  384.     rect.y -= 10
  385.     rect.x -= 20
  386.     draw_text(rect, sprintf("%2d", $game_party.bombs?),1) if $game_party.bombs? > 0
  387.     make_font_smaller
  388.   end
  389.   #--------------------------------------------------------------------------
  390.   # * Update Help Text
  391.   #--------------------------------------------------------------------------
  392.   def update_help
  393.     @help_window.set_item(item)
  394.     @description_window.set_item(item)
  395.   end
  396.   #--------------------------------------------------------------------------
  397.   # * Item Rect
  398.   #--------------------------------------------------------------------------
  399.   def item_rect(index)
  400.     rect = Rect.new
  401.     rect.width = 60
  402.     rect.height = 60
  403.     rect.x = index % col_max * (60)
  404.     rect.y = index / col_max * (60)
  405.     rect
  406.   end
  407.   #--------------------------------------------------------------------------
  408.   # * Refresh
  409.   #--------------------------------------------------------------------------
  410.   def refresh
  411.     @actor == $game_party.members[0]
  412.     @category = :weapon
  413.     make_item_list
  414.     contents.clear
  415.     draw_all_items
  416.   end
  417.   #--------------------------------------------------------------------------
  418.   # * Update Cursor
  419.   #--------------------------------------------------------------------------
  420.   def update_cursor
  421.     ensure_cursor_visible
  422.     cursor_rect.set(item_rect(@index))
  423.     cursor_rect.height += 2
  424.     cursor_rect.width += 8
  425.     pos = index % 4
  426.     case pos
  427.     when 0
  428.       ox = 1
  429.     when 1
  430.       ox = 16
  431.     when 2
  432.       ox = 32
  433.     when 3
  434.       ox = 52
  435.     end
  436.     cursor_rect.x += ox
  437.     cursor_rect.y -= 2
  438.   end
  439.   #--------------------------------------------------------------------------
  440.   # * Calculate Height of Window Contents
  441.   #--------------------------------------------------------------------------
  442.   def contents_height
  443.     rows = row_max - 3
  444.     rows = 0 if rows <= 0
  445.     return @height - standard_padding * 2 + rows * 60 + 60
  446.   end
  447.   #--------------------------------------------------------------------------
  448.   # * Calculate Height of Window Contents
  449.   #--------------------------------------------------------------------------
  450.   def standard_padding
  451.     return 12
  452.   end
  453.   #--------------------------------------------------------------------------
  454.   # * Update Bottom Padding
  455.   #--------------------------------------------------------------------------
  456.   def update_padding_bottom
  457.     rows = row_max - 3
  458.     rows = 0 if rows <= 0
  459.     surplus = (@height - standard_padding * 2) % item_height
  460.     self.padding_bottom = padding + surplus - 30
  461.   end
  462. end
  463.  
  464. #==============================================================================
  465. # ** Bomb Count Window
  466. #==============================================================================
  467. class Bomb_Count_Window < Window_Base
  468.   #--------------------------------------------------------------------------
  469.   # * Initialize
  470.   #--------------------------------------------------------------------------
  471.  def initialize(x, y, width, height)
  472.     super(x,y,width,height)
  473.     self.z = 140
  474.     self.windowskin = Cache.system("Window_Border")
  475.     self.opacity = 0
  476.     self.arrows_visible = false
  477.     self.pause = false
  478.     self.back_opacity = 0
  479.     self.contents_opacity = 255
  480.     refresh
  481.   end
  482.   #--------------------------------------------------------------------------
  483.   # * Remove Padding
  484.   #--------------------------------------------------------------------------
  485.   def standard_padding
  486.     return 0
  487.   end
  488.   #--------------------------------------------------------------------------
  489.   # * Refresh
  490.   #--------------------------------------------------------------------------
  491.   def refresh
  492.     contents.clear unless disposed?
  493.     return if disposed?
  494.     draw_bombs
  495.   end
  496.   #--------------------------------------------------------------------------
  497.   # * Draw Bombs in Inventory
  498.   #--------------------------------------------------------------------------
  499.   def draw_bombs
  500.     change_color(crisis_color)
  501.     if $game_party.has_item?($data_weapons[5])
  502.       text = "Weapons Left............ " + ($game_party.bombs?).to_s
  503.       draw_text(0,0,300, 24, text)
  504.     end
  505.   end
  506. end
  507.  
  508. #==============================================================================
  509. # ** Scene_Weapons
  510. #==============================================================================
  511. class Scene_Weapons < Scene_ItemBase
  512.   #--------------------------------------------------------------------------
  513.   # * Start Processing
  514.   #--------------------------------------------------------------------------
  515.   def start
  516.     super
  517.     create_help_window
  518.     create_description_window
  519.     create_weapon_window
  520.     create_actor2_equip_window if $game_party.members[1]
  521.     create_weapon_command
  522.     create_bomb_window
  523.   end
  524.   #--------------------------------------------------------------------------
  525.   # * Create Category Window
  526.   #--------------------------------------------------------------------------
  527.   def create_help_window
  528.     @help_window = Window_WeaponHelp.new
  529.     @help_window.viewport = @viewport
  530.   end
  531.   #--------------------------------------------------------------------------
  532.   # * Create Category Window
  533.   #--------------------------------------------------------------------------
  534.   def create_description_window
  535.     @description_window = Window_WeaponDescription.new
  536.     @description_window.viewport = @viewport
  537.   end
  538.   #--------------------------------------------------------------------------
  539.   # * Create Item Command Text Window
  540.   #--------------------------------------------------------------------------
  541.   def create_weapon_command
  542.     @command_window = Window_Weapon_Command.new
  543.     @command_window.viewport = @viewport
  544.   end
  545.   #--------------------------------------------------------------------------
  546.   # * Create Item Window
  547.   #--------------------------------------------------------------------------
  548.   def create_weapon_window
  549.     ww = Graphics.width / 2 + 60
  550.     wy = @description_window.y + @description_window.height
  551.     wh = Graphics.height - wy - 100
  552.     @weapon_window = Window_WeaponList.new(0, wy, ww, wh)
  553.     @weapon_window.viewport = @viewport
  554.     @weapon_window.help_window = @help_window
  555.     @weapon_window.description_window = @description_window
  556.     @weapon_window.set_handler(:ok,     method(:on_item_ok))
  557.     @weapon_window.set_handler(:cancel, method(:return_scene))
  558.     @weapon_window.refresh
  559.     @weapon_window.activate
  560.     @weapon_window.select(0)
  561.   end
  562.   #--------------------------------------------------------------------------
  563.   # * Create Item Command Text Window
  564.   #--------------------------------------------------------------------------
  565.   def create_bomb_window
  566.     @bomb_window = Bomb_Count_Window.new(50, 350, 300, 48)
  567.     @bomb_window.viewport = @viewport
  568.   end
  569.   #--------------------------------------------------------------------------
  570.   # * Create Item Window
  571.   #--------------------------------------------------------------------------
  572.   def create_actor2_equip_window
  573.     wx = Graphics.width / 2 + 60
  574.     ww = Graphics.width - wx
  575.     wh = Graphics.height - 148
  576.     @armour_window2 = Window_ArmourList2.new(wx, 48, ww, wh)
  577.     @armour_window2.viewport = @viewport
  578.     @armour_window2.help_window = @help_window
  579.     @armour_window2.set_handler(:cancel, method(:return_scene))
  580.     @armour_window2.refresh
  581.   end
  582.   #--------------------------------------------------------------------------
  583.   # * Item [OK]
  584.   #--------------------------------------------------------------------------
  585.   def on_item_ok
  586.     if @weapon_window.item.nil?
  587.       Sound.play_buzzer
  588.       @weapon_window.activate
  589.       return
  590.     end
  591.     Sound.play_equip
  592.     @actor.change_equip(0, @weapon_window.item)
  593.     @weapon_window.activate
  594.     @weapon_window.refresh
  595.     @actor1_hud.refresh
  596.     @actor2_hud.refresh if $game_party.members[1]
  597.   end
  598. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement