Advertisement
roninator2

Spell Charge System Shop

Nov 17th, 2024 (edited)
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 38.25 KB | Gaming | 0 0
  1. # ╔═══════════════════════════════════════════════╦════════════════════╗
  2. # ║ Title: Spell Charge System Shop               ║  Version: 1.01     ║
  3. # ║ Author: Roninator2                            ║                    ║
  4. # ╠═══════════════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                                     ║   Date Created     ║
  6. # ║                                               ╠════════════════════╣
  7. # ║  Purchase Spells                              ║    12 Feb 2024     ║
  8. # ╚═══════════════════════════════════════════════╩════════════════════╝
  9. # ╔════════════════════════════════════════════════════════════════════╗
  10. # ║ Requires: Spell Charge System Base                                 ║
  11. # ╚════════════════════════════════════════════════════════════════════╝
  12. # ╔════════════════════════════════════════════════════════════════════╗
  13. # ║ Brief Description:                                                 ║
  14. # ║ Allows to buy spells like Final Fantasy 1                          ║
  15. # ╚════════════════════════════════════════════════════════════════════╝
  16. # ╔════════════════════════════════════════════════════════════════════╗
  17. # ║ Instructions:                                                      ║
  18. # ║ Shop Setup:                                                        ║
  19. # ║                                                                    ║
  20. # ║ To create a skill shop, you'll need to do a script call            ║
  21. # ║   Step 1. Under the event commands, choose tab 3                   ║
  22. # ║      then under advanced choose Script.                            ║
  23. # ║   Step 2. In the script window, you'll need to enter               ║
  24. # ║                                                                    ║
  25. # ║      goods = [35,36,37,38]                                         ║
  26. # ║      shop = "White Magic"                                          ║
  27. # ║      SceneManager.call(Scene_Spell_Shop)                           ║
  28. # ║      SceneManager.scene.prepare(goods, shop)                       ║
  29. # ║                                                                    ║
  30. # ║   Description of goods                                             ║
  31. # ║      goods = [3, 4, 5, 6] <= skill id numbers                      ║
  32. # ║                                                                    ║
  33. # ║                                                                    ║
  34. # ╚════════════════════════════════════════════════════════════════════╝
  35. # ╔════════════════════════════════════════════════════════════════════╗
  36. # ║ Updates:                                                           ║
  37. # ║ 1.00 - 12 Feb 2024 - Script finished                               ║
  38. # ║ 1.01 - 29 Jul 2024 - Fixed documentation                           ║
  39. # ╚════════════════════════════════════════════════════════════════════╝
  40. # ╔════════════════════════════════════════════════════════════════════╗
  41. # ║ Credits and Thanks:                                                ║
  42. # ║   Roninator2                                                       ║
  43. # ║                                                                    ║
  44. # ╚════════════════════════════════════════════════════════════════════╝
  45. # ╔════════════════════════════════════════════════════════════════════╗
  46. # ║ Terms of use:                                                      ║
  47. # ║  Follow the original Authors terms of use where applicable         ║
  48. # ║    - When not made by me (Roninator2)                              ║
  49. # ║  Free for all uses in RPG Maker except nudity                      ║
  50. # ║  Anyone using this script in their project before these terms      ║
  51. # ║  were changed are allowed to use this script even if it conflicts  ║
  52. # ║  with these new terms. New terms effective 03 Apr 2024             ║
  53. # ║  No part of this code can be used with AI programs or tools        ║
  54. # ║  Credit must be given                                              ║
  55. # ╚════════════════════════════════════════════════════════════════════╝
  56.  
  57. #==============================================================================
  58. # ** Vocab
  59. #==============================================================================
  60. module Vocab
  61.  
  62.   # Spell Shop Screen
  63.   Spell_Buy     = "Buy"
  64.   Spell_Cancel  = "Exit"
  65.   Shop_Title    = "Welcome to my Magic Shop"
  66.   Not_Usable    = "This cannot be used by you"
  67.   Spells_Full   = "Your spells are full"
  68.   Spell_Owned   = "You already have this spell"
  69.  
  70. end
  71.  
  72. #==============================================================================
  73. # ** Spell Charge
  74. #==============================================================================
  75. module Spell_Charge
  76.  
  77. #==============================================================================
  78. # ** Shop Options
  79. #==============================================================================
  80.   module Shop
  81.    
  82.     # maximum number of party members in Image Window
  83.     MAX_PARTY = 4
  84.    
  85.   end
  86.  
  87.   module Options
  88.    
  89.     # time to wait before message window disappears
  90.     # this window is for messages regading purchases are not possible
  91.     MESSAGE_WAIT = 160
  92.    
  93.   end
  94. #==============================================================================
  95. # ** Spell Settings
  96. #==============================================================================
  97.   module Spell
  98.     # ╔══════════════════════════════════════════════════════════╗
  99.     # ║ Instructions:                                            ║
  100.     # ║                                                          ║
  101.     # ║ Note tags                                                ║
  102.     # ║   Skills                                                 ║
  103.     # ║     <spell cost: 100>                                    ║
  104.     # ║       Will make the spell cost 100 gold to buy           ║
  105.     # ║                                                          ║
  106.     # ╚══════════════════════════════════════════════════════════╝
  107.    
  108.     # Skill notetag
  109.     # <spell cost: 100> # specify the cost to buy the skill
  110.     SPELL_COST = /<spell[ -_]cost:[ -_](\d+)>/i
  111.    
  112.   end
  113. end
  114. # ╔══════════════════════════════════════════════════════════╗
  115. # ║              End of Editable section                     ║
  116. # ╚══════════════════════════════════════════════════════════╝
  117.  
  118. #==============================================================================
  119. # ** Window_Spell_Group
  120. #==============================================================================
  121.  
  122. class Window_Spell_Group < Window_Base
  123.   #--------------------------------------------------------------------------
  124.   # * Object Initialization
  125.   #--------------------------------------------------------------------------
  126.   def initialize
  127.     super(0, 0, window_width, window_height)
  128.     @text = ""
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   # * Set Text
  132.   #--------------------------------------------------------------------------
  133.   def group(text)
  134.     if text != @text
  135.       @text = text.to_s
  136.       refresh
  137.     end
  138.   end
  139.   #--------------------------------------------------------------------------
  140.   # * window_width
  141.   #--------------------------------------------------------------------------
  142.   def window_width
  143.     160
  144.   end
  145.   #--------------------------------------------------------------------------
  146.   # * window_height
  147.   #--------------------------------------------------------------------------
  148.   def window_height
  149.     fitting_height(1)
  150.   end
  151.   #--------------------------------------------------------------------------
  152.   # * Refresh
  153.   #--------------------------------------------------------------------------
  154.   def refresh
  155.     contents.clear
  156.     draw_text_ex(4, 0, @text)
  157.   end
  158. end
  159.  
  160. #==============================================================================
  161. # ** Window_Spell_Title
  162. #==============================================================================
  163.  
  164. class Window_Spell_Title < Window_Base
  165.   #--------------------------------------------------------------------------
  166.   # * Object Initialization
  167.   #--------------------------------------------------------------------------
  168.   def initialize(line_number = 1)
  169.     super(0, 0, Graphics.width - 160, fitting_height(line_number))
  170.     refresh
  171.   end
  172.   #--------------------------------------------------------------------------
  173.   # * Refresh
  174.   #--------------------------------------------------------------------------
  175.   def refresh
  176.     contents.clear
  177.     text = Vocab::Shop_Title
  178.     draw_text(0, 0, contents.width, 24, text, 1)
  179.   end
  180. end
  181.  
  182. #==============================================================================
  183. # ** Window_Spell_Message
  184. #==============================================================================
  185.  
  186. class Window_Spell_Message < Window_Base
  187.   #--------------------------------------------------------------------------
  188.   # * Object Initialization
  189.   #--------------------------------------------------------------------------
  190.   def initialize(line_number = 1)
  191.     @text = ""
  192.     super(Graphics.width / 4, Graphics.height / 2, window_width, fitting_height(line_number))
  193.     @timer = -1
  194.     refresh
  195.   end
  196.   #--------------------------------------------------------------------------
  197.   # * Window Width
  198.   #--------------------------------------------------------------------------
  199.   def window_width
  200.     @text.size * 12
  201.   end
  202.   #--------------------------------------------------------------------------
  203.   # * Set Text
  204.   #--------------------------------------------------------------------------
  205.   def set_text(text)
  206.     if text != @text
  207.       @text = text
  208.       @timer = 0
  209.       refresh
  210.     end
  211.   end
  212.   #--------------------------------------------------------------------------
  213.   # * Clear
  214.   #--------------------------------------------------------------------------
  215.   def clear
  216.     set_text("")
  217.     refresh
  218.   end
  219.   #--------------------------------------------------------------------------
  220.   # * Update
  221.   #--------------------------------------------------------------------------
  222.   def update
  223.     super
  224.     @timer += 1 if @timer >= 0
  225.     if @timer >= Spell_Charge::Options::MESSAGE_WAIT
  226.       set_text("")
  227.       self.hide
  228.       @timer = -1
  229.     end
  230.   end
  231.   #--------------------------------------------------------------------------
  232.   # * Refresh
  233.   #--------------------------------------------------------------------------
  234.   def refresh
  235.     self.width = window_width
  236.     contents.clear
  237.     contents.dispose
  238.     create_contents
  239.     draw_text_ex(4, 0, @text)
  240.   end
  241. end
  242.  
  243. #==============================================================================
  244. # ** Window_Spell_Help
  245. #==============================================================================
  246.  
  247. class Window_Spell_Help < Window_Base
  248.   #--------------------------------------------------------------------------
  249.   # * Object Initialization
  250.   #--------------------------------------------------------------------------
  251.   def initialize(line_number = 1)
  252.     super(0, 0, Graphics.width, fitting_height(line_number))
  253.   end
  254.   #--------------------------------------------------------------------------
  255.   # * Set Text
  256.   #--------------------------------------------------------------------------
  257.   def set_text(text)
  258.     if text != @text
  259.       @text = text
  260.       refresh
  261.     end
  262.   end
  263.   #--------------------------------------------------------------------------
  264.   # * Clear
  265.   #--------------------------------------------------------------------------
  266.   def clear
  267.     set_text("")
  268.   end
  269.   #--------------------------------------------------------------------------
  270.   # * Set Item
  271.   #     item : Skills and items etc.
  272.   #--------------------------------------------------------------------------
  273.   def set_item(item)
  274.     set_text(item ? item.description : "")
  275.   end
  276.   #--------------------------------------------------------------------------
  277.   # * Refresh
  278.   #--------------------------------------------------------------------------
  279.   def refresh
  280.     contents.clear
  281.     draw_text_ex(4, 0, @text)
  282.   end
  283. end
  284.  
  285. #==============================================================================
  286. # ** Window_SpellShopCommand
  287. #==============================================================================
  288.  
  289. class Window_SpellShopCommand < Window_HorzCommand
  290.   #--------------------------------------------------------------------------
  291.   # * Object Initialization
  292.   #--------------------------------------------------------------------------
  293.   def initialize(window_width)
  294.     @window_width = window_width
  295.     super(0, 0)
  296.   end
  297.   #--------------------------------------------------------------------------
  298.   # * Get Window Width
  299.   #--------------------------------------------------------------------------
  300.   def window_width
  301.     @window_width
  302.   end
  303.   #--------------------------------------------------------------------------
  304.   # * Get Digit Count
  305.   #--------------------------------------------------------------------------
  306.   def col_max
  307.     return 2
  308.   end
  309.   #--------------------------------------------------------------------------
  310.   # * Create Command List
  311.   #--------------------------------------------------------------------------
  312.   def make_command_list
  313.     add_command(Vocab::Spell_Buy,    :buy)
  314.     add_command(Vocab::Spell_Cancel, :cancel)
  315.   end
  316. end
  317.  
  318. #==============================================================================
  319. # ** Window_ClassStatus
  320. #==============================================================================
  321.  
  322. class Window_ClassStatus < Window_Base
  323.   #--------------------------------------------------------------------------
  324.   # * Object Initialization
  325.   #--------------------------------------------------------------------------
  326.   def initialize(x, y, wh)
  327.     super(x, y, window_width, wh)
  328.     @item = nil
  329.     refresh
  330.   end
  331.   #--------------------------------------------------------------------------
  332.   # * Get Window Width
  333.   #--------------------------------------------------------------------------
  334.   def window_width
  335.     200
  336.   end
  337.   #--------------------------------------------------------------------------
  338.   # * Refresh
  339.   #--------------------------------------------------------------------------
  340.   def refresh
  341.     contents.clear
  342.     draw_class_use
  343.   end
  344.   #--------------------------------------------------------------------------
  345.   # * Set Item
  346.   #--------------------------------------------------------------------------
  347.   def item=(item)
  348.     @item = item
  349.     refresh
  350.   end
  351.   #--------------------------------------------------------------------------
  352.   # * Draw classes that can use spell
  353.   #--------------------------------------------------------------------------
  354.   def draw_class_use
  355.     return if @item.nil?
  356.     y = 0
  357.     @item.class_learn.each do |id|
  358.       act_cls = $data_classes[id]
  359.       draw_text(0, y, 160, 24, act_cls.name, 1)
  360.       y += 24
  361.     end
  362.   end
  363. end # Window_ClassStatus
  364.  
  365. #==============================================================================
  366. # ** Window_SpellBuy
  367. #==============================================================================
  368.  
  369. class Window_SpellBuy < Window_Selectable
  370.   #--------------------------------------------------------------------------
  371.   # * Public Instance Variables
  372.   #--------------------------------------------------------------------------
  373.   attr_reader   :class_window            # Status window
  374.   attr_reader   :image_window            # Status window
  375.   #--------------------------------------------------------------------------
  376.   # * Object Initialization
  377.   #--------------------------------------------------------------------------
  378.   def initialize(y, w, h, shop_goods)
  379.     super(0, y, w, h)
  380.     @shop_goods = shop_goods
  381.     @money = 0
  382.     refresh
  383.     select(0)
  384.   end
  385.   #--------------------------------------------------------------------------
  386.   # * Get Number of Items
  387.   #--------------------------------------------------------------------------
  388.   def item_max
  389.     @data ? @data.size : 1
  390.   end
  391.   #--------------------------------------------------------------------------
  392.   # * Get Item
  393.   #--------------------------------------------------------------------------
  394.   def item
  395.     @data[index]
  396.   end
  397.   #--------------------------------------------------------------------------
  398.   # * Set Party Gold
  399.   #--------------------------------------------------------------------------
  400.   def money=(money)
  401.     @money = money
  402.     refresh
  403.   end
  404.   #--------------------------------------------------------------------------
  405.   # * Get Activation State of Selection Item
  406.   #--------------------------------------------------------------------------
  407.   def current_item_enabled?
  408.     enable?(@data[index])
  409.   end
  410.   #--------------------------------------------------------------------------
  411.   # * Get Price of Item
  412.   #--------------------------------------------------------------------------
  413.   def price(item)
  414.     @price[item]
  415.   end
  416.   #--------------------------------------------------------------------------
  417.   # * Display in Enabled State?
  418.   #--------------------------------------------------------------------------
  419.   def enable?(item)
  420.     item && price(item) <= @money
  421.   end
  422.   #--------------------------------------------------------------------------
  423.   # * Refresh
  424.   #--------------------------------------------------------------------------
  425.   def refresh
  426.     make_item_list
  427.     create_contents
  428.     draw_all_items
  429.   end
  430.   #--------------------------------------------------------------------------
  431.   # * Create Item List
  432.   #--------------------------------------------------------------------------
  433.   def make_item_list
  434.     @data = []
  435.     @price = {}
  436.     @shop_goods.each do |goods|
  437.       item = $data_skills[goods] if goods != nil
  438.       if item
  439.         @data.push(item)
  440.         @price[item] = item.spell_cost
  441.       end
  442.     end
  443.   end
  444.   #--------------------------------------------------------------------------
  445.   # * Draw Item
  446.   #--------------------------------------------------------------------------
  447.   def draw_item(index)
  448.     item = @data[index]
  449.     rect = item_rect(index)
  450.     draw_item_name(item, rect.x, rect.y, enable?(item))
  451.     rect.width -= 4
  452.     draw_text(rect, price(item), 2)
  453.   end
  454.   #--------------------------------------------------------------------------
  455.   # * Set Status Window
  456.   #--------------------------------------------------------------------------
  457.   def class_window=(class_window)
  458.     @class_window = class_window
  459.     call_update_help
  460.   end
  461.   #--------------------------------------------------------------------------
  462.   # * Set Status Window
  463.   #--------------------------------------------------------------------------
  464.   def image_window=(image_window)
  465.     @image_window = image_window
  466.     call_update_help
  467.   end
  468.   #--------------------------------------------------------------------------
  469.   # * Update Help Text
  470.   #--------------------------------------------------------------------------
  471.   def update_help
  472.     @help_window.set_item(item) if @help_window
  473.     @class_window.item = item if @class_window
  474.     @image_window.item = item if @image_window
  475.   end
  476. end # Window_SpellBuy
  477.  
  478. #==============================================================================
  479. # ** Window_ImageStatus
  480. #==============================================================================
  481.  
  482. class Window_ImageStatus < Window_Selectable
  483.   #--------------------------------------------------------------------------
  484.   # * Object Initialization
  485.   #--------------------------------------------------------------------------
  486.   def initialize(x, y, width, height)
  487.     super(x, y, width, height)
  488.     @index = -1
  489.     @walk = 0
  490.     @page_index = 0
  491.     @animtime = 0
  492.     @data = []
  493.   end
  494.   #--------------------------------------------------------------------------
  495.   # * Get Digit Count
  496.   #--------------------------------------------------------------------------
  497.   def col_max
  498.     return page_size
  499.   end
  500.   #--------------------------------------------------------------------------
  501.   # * Get Number of Items
  502.   #--------------------------------------------------------------------------
  503.   def item_max
  504.     @data ? @data.size : 1
  505.   end
  506.   #--------------------------------------------------------------------------
  507.   # * Set Item
  508.   #--------------------------------------------------------------------------
  509.   def item=(item)
  510.     @item = item
  511.     refresh
  512.   end
  513.   #--------------------------------------------------------------------------
  514.   # * Refresh
  515.   #--------------------------------------------------------------------------
  516.   def refresh
  517.     contents.clear
  518.     return if @item.nil?
  519.     make_actor_list
  520.     page_size.times do |i|
  521.       draw_party(i)
  522.     end
  523.   end
  524.   #--------------------------------------------------------------------------
  525.   # * Create Actor List
  526.   #--------------------------------------------------------------------------
  527.   def make_actor_list
  528.     @data = status_members
  529.   end
  530.   #--------------------------------------------------------------------------
  531.   # * Draw Quantity Possessed
  532.   #--------------------------------------------------------------------------
  533.   def draw_party(i)
  534.     x = i * (item_width + spacing) + 84
  535.     rect = Rect.new(x, 40, 48, 48)
  536.     return if @data[i].nil?
  537.     draw_actor_graphic(@data[i], rect.x, rect.y, @data[i].skill_purchase?(@item))
  538.   end
  539.   #--------------------------------------------------------------------------
  540.   # * Get Spacing for Items Arranged Side by Side
  541.   #--------------------------------------------------------------------------
  542.   def spacing
  543.     return Graphics.width / page_size - item_width - page_size * 4
  544.   end
  545.   #--------------------------------------------------------------------------
  546.   # * Number of Actors Displayable at Once
  547.   #--------------------------------------------------------------------------
  548.   def page_size
  549.     return Spell_Charge::Shop::MAX_PARTY
  550.   end
  551.   #--------------------------------------------------------------------------
  552.   # * Calculate Width of Window Contents
  553.   #--------------------------------------------------------------------------
  554.   def contents_width
  555.     Graphics.width - standard_padding * 2
  556.   end
  557.   #--------------------------------------------------------------------------
  558.   # * Get Maximum Number of Pages
  559.   #--------------------------------------------------------------------------
  560.   def page_max
  561.     ($game_party.members.size + page_size - 1) / page_size
  562.   end
  563.   #--------------------------------------------------------------------------
  564.   # * Array of Actors for Which to Draw Equipment Information
  565.   #--------------------------------------------------------------------------
  566.   def status_members
  567.     $game_party.members[@page_index * page_size, page_size]
  568.   end
  569.   #--------------------------------------------------------------------------
  570.   # * Overwrite: draw_character
  571.   #--------------------------------------------------------------------------
  572.   def draw_character(character_name, character_index, x, y, ani = false)
  573.     return unless character_name
  574.     bitmap = Cache.character(character_name)
  575.     sign = character_name[/^[\!\$]./]
  576.     if sign && sign.include?('$')
  577.       cw = bitmap.width / 3
  578.       ch = bitmap.height / 4
  579.     else
  580.       cw = bitmap.width / 12
  581.       ch = bitmap.height / 8
  582.     end
  583.     n = character_index
  584.     step = 0
  585.     step = @walk if ani
  586.     src_rect = Rect.new((n%4*3+1+step)*cw, (n/4*4)*ch, cw, ch)
  587.     contents.blt(x - cw / 2, y - ch, bitmap, src_rect, ani ? 255 : translucent_alpha)
  588.   end
  589.   #--------------------------------------------------------------------------
  590.   # * Overwrite: draw_actor_graphic
  591.   #--------------------------------------------------------------------------
  592.   def draw_actor_graphic(actor, x, y, ani = false)
  593.     draw_character(actor.character_name, actor.character_index, x, y, ani)
  594.   end
  595.   #--------------------------------------------------------------------------
  596.   # * New Method: ani_motion
  597.   #--------------------------------------------------------------------------
  598.   def ani_motion
  599.     @animtime += 1
  600.     if @animtime == 10
  601.       case @walk
  602.       when 1; @walk -= 1
  603.       when -1; @walk += 1
  604.       when 0
  605.         if @step == 1
  606.           @walk = -1
  607.           @step = 0
  608.         else
  609.           @walk = 1
  610.           @step = 1
  611.         end
  612.       end
  613.       refresh
  614.       @animtime = 0
  615.     end
  616.   end
  617.   #--------------------------------------------------------------------------
  618.   # * Frame Update
  619.   #--------------------------------------------------------------------------
  620.   def update
  621.     super
  622.     ani_motion
  623.   end
  624.   #--------------------------------------------------------------------------
  625.   # * Update Page
  626.   #--------------------------------------------------------------------------
  627.   def update_page
  628.     if visible && Input.trigger?(:A) && page_max > 1
  629.       @page_index = (@page_index + 1) % page_max
  630.       refresh
  631.     end
  632.   end
  633.   #--------------------------------------------------------------------------
  634.   # * Get Item Width
  635.   #--------------------------------------------------------------------------
  636.   def item_width
  637.     48
  638.   end
  639.   #--------------------------------------------------------------------------
  640.   # * Get Item Height
  641.   #--------------------------------------------------------------------------
  642.   def item_height
  643.     48
  644.   end
  645.   #--------------------------------------------------------------------------
  646.   # * Calculate Height of Window Contents
  647.   #--------------------------------------------------------------------------
  648.   def contents_height
  649.     item_height
  650.   end
  651.   #--------------------------------------------------------------------------
  652.   # * Get Leading Digits
  653.   #--------------------------------------------------------------------------
  654.   def top_col
  655.     ox / (item_width + spacing)
  656.   end
  657.   #--------------------------------------------------------------------------
  658.   # * Set Leading Digits
  659.   #--------------------------------------------------------------------------
  660.   def top_col=(col)
  661.     col = 0 if col < 0
  662.     col = col_max - 1 if col > col_max - 1
  663.     self.ox = col * (item_width + spacing)
  664.   end
  665.   #--------------------------------------------------------------------------
  666.   # * Get Trailing Digits
  667.   #--------------------------------------------------------------------------
  668.   def bottom_col
  669.     top_col + col_max - 1
  670.   end
  671.   #--------------------------------------------------------------------------
  672.   # * Set Trailing Digits
  673.   #--------------------------------------------------------------------------
  674.   def bottom_col=(col)
  675.     self.top_col = col - (col_max - 1)
  676.   end
  677.   #--------------------------------------------------------------------------
  678.   # * Scroll Cursor to Position Within Screen
  679.   #--------------------------------------------------------------------------
  680.   def ensure_cursor_visible
  681.     self.top_col = index if index < top_col
  682.     self.bottom_col = index if index > bottom_col
  683.   end
  684.   #--------------------------------------------------------------------------
  685.   # * Get Rectangle for Displaying Items
  686.   #--------------------------------------------------------------------------
  687.   def item_rect(index)
  688.     rect = super
  689.     rect.x = index * (item_width + spacing) + 60
  690.     rect.y = 0
  691.     rect
  692.   end
  693.   #--------------------------------------------------------------------------
  694.   # * Get Alignment
  695.   #--------------------------------------------------------------------------
  696.   def alignment
  697.     return 1
  698.   end
  699. end # Window_ImageStatus
  700.  
  701. #==============================================================================
  702. # ** Spell_Shop
  703. #==============================================================================
  704.  
  705. class Scene_Spell_Shop < Scene_MenuBase
  706.   #--------------------------------------------------------------------------
  707.   # * Prepare
  708.   #--------------------------------------------------------------------------
  709.   def prepare(goods, shop)
  710.     @goods = goods
  711.     @shop = shop
  712.   end
  713.   #--------------------------------------------------------------------------
  714.   # * Start Processing
  715.   #--------------------------------------------------------------------------
  716.   def start
  717.     super
  718.     create_spell_class_window
  719.     create_title_window
  720.     create_gold_window
  721.     create_command_window
  722.     create_help_window
  723.     create_class_window
  724.     create_image_window
  725.     create_buy_window
  726.     create_msg_window
  727.   end
  728.   #--------------------------------------------------------------------------
  729.   # * Create Spell Class Window
  730.   #--------------------------------------------------------------------------
  731.   def create_spell_class_window
  732.     @spell_class_window = Window_Spell_Group.new
  733.     @spell_class_window.viewport = @viewport
  734.     @spell_class_window.x = Graphics.width - @spell_class_window.width
  735.     @spell_class_window.group(@shop)
  736.   end
  737.   #--------------------------------------------------------------------------
  738.   # * Create Help Window
  739.   #--------------------------------------------------------------------------
  740.   def create_title_window
  741.     @title_window = Window_Spell_Title.new
  742.     @title_window.viewport = @viewport
  743.   end
  744.   #--------------------------------------------------------------------------
  745.   # * Create Help Window
  746.   #--------------------------------------------------------------------------
  747.   def create_msg_window
  748.     @msg_window = Window_Spell_Message.new
  749.     @msg_window.viewport = @viewport
  750.     @msg_window.z = 210
  751.     @msg_window.hide
  752.   end
  753.   #--------------------------------------------------------------------------
  754.   # * Create Gold Window
  755.   #--------------------------------------------------------------------------
  756.   def create_gold_window
  757.     @gold_window = Window_Gold.new
  758.     @gold_window.viewport = @viewport
  759.     @gold_window.x = Graphics.width - @gold_window.width
  760.     @gold_window.y = @spell_class_window.height
  761.   end
  762.   #--------------------------------------------------------------------------
  763.   # * Create Command Window
  764.   #--------------------------------------------------------------------------
  765.   def create_command_window
  766.     ww = Graphics.width - @gold_window.width
  767.     @command_window = Window_SpellShopCommand.new(ww)
  768.     @command_window.viewport = @viewport
  769.     @command_window.y = @title_window.height
  770.     @command_window.set_handler(:buy,    method(:command_buy))
  771.     @command_window.set_handler(:cancel, method(:return_scene))
  772.   end
  773.   #--------------------------------------------------------------------------
  774.   # * Create Help Window
  775.   #--------------------------------------------------------------------------
  776.   def create_help_window
  777.     @help_window = Window_Spell_Help.new
  778.     @help_window.viewport = @viewport
  779.     @help_window.y = @command_window.y + @command_window.height
  780.   end
  781.   #--------------------------------------------------------------------------
  782.   # * Create Status Window
  783.   #--------------------------------------------------------------------------
  784.   def create_class_window
  785.     wy = @help_window.y + @help_window.height
  786.     wh = Graphics.height - @help_window.y - @help_window.height - 72
  787.     @class_window = Window_ClassStatus.new(0, wy, wh)
  788.     @class_window.viewport = @viewport
  789.     @class_window.x = Graphics.width - @class_window.width
  790.   end
  791.   #--------------------------------------------------------------------------
  792.   # * Create Status Window
  793.   #--------------------------------------------------------------------------
  794.   def create_image_window
  795.     wy = Graphics.height - 72
  796.     ww = Graphics.width
  797.     wh = 72
  798.     @image_window = Window_ImageStatus.new(0, wy, ww, wh)
  799.     @image_window.viewport = @viewport
  800.     @image_window.set_handler(:ok,     method(:on_image_ok))
  801.     @image_window.set_handler(:cancel, method(:on_image_cancel))
  802.   end
  803.   #--------------------------------------------------------------------------
  804.   # * Create Purchase Window
  805.   #--------------------------------------------------------------------------
  806.   def create_buy_window
  807.     wy = @help_window.y + @help_window.height
  808.     ww = Graphics.width - @class_window.width
  809.     wh = Graphics.height - @help_window.height - @help_window.y - @image_window.height
  810.     @buy_window = Window_SpellBuy.new(wy, ww, wh, @goods)
  811.     @buy_window.viewport = @viewport
  812.     @buy_window.help_window = @help_window
  813.     @buy_window.class_window = @class_window
  814.     @buy_window.image_window = @image_window
  815.     @buy_window.set_handler(:ok,     method(:on_buy_ok))
  816.     @buy_window.set_handler(:cancel, method(:on_buy_cancel))
  817.   end
  818.   #--------------------------------------------------------------------------
  819.   # * Activate Purchase Window
  820.   #--------------------------------------------------------------------------
  821.   def command_buy
  822.     @buy_window.money = money
  823.     @buy_window.show.activate
  824.     @buy_window.select(0)
  825.   end
  826.   #--------------------------------------------------------------------------
  827.   # * Buy [OK]
  828.   #--------------------------------------------------------------------------
  829.   def on_buy_ok
  830.     @item = @buy_window.item
  831.     @image_window.activate
  832.     @image_window.select(0)
  833.   end
  834.   #--------------------------------------------------------------------------
  835.   # * Buy [Cancel]
  836.   #--------------------------------------------------------------------------
  837.   def on_buy_cancel
  838.     @buy_window.unselect
  839.     @image_window.item = nil
  840.     @class_window.item = nil
  841.     @command_window.activate
  842.     @help_window.clear
  843.   end
  844.   #--------------------------------------------------------------------------
  845.   # * Actor [OK]
  846.   #--------------------------------------------------------------------------
  847.   def on_image_ok
  848.     index = @image_window.index
  849.     act = $game_party.members[index]
  850.     not_usable = true
  851.     buy = false
  852.     if act.skill_purchase?(@item)
  853.       not_usable = false
  854.       buy = true
  855.       if act.spell_list[@item.spell_level] != nil
  856.         buy = false if act.spell_list[@item.spell_level].include?(@item.id)
  857.         buy = false if act.spell_list[@item.spell_level].size == Spell_Charge::Options::MAX_PER_LEVEL
  858.       end
  859.     else
  860.       Sound.play_buzzer
  861.       @image_window.activate
  862.     end
  863.     if buy
  864.       $game_party.lose_gold(@item.spell_cost)
  865.       @gold_window.refresh
  866.       act.learn_spell(@item.id)
  867.       @image_window.activate
  868.     else
  869.       if not_usable
  870.         @msg_window.set_text(Vocab::Not_Usable)
  871.         @msg_window.show
  872.         @image_window.activate
  873.       else
  874.         if act.spell_list[@item.spell_level].size == Spell_Charge::Options::MAX_PER_LEVEL
  875.           @msg_window.set_text(Vocab::Spells_Full)
  876.           @msg_window.show
  877.           @image_window.activate
  878.         else
  879.           @msg_window.set_text(Vocab::Spell_Owned)
  880.           @msg_window.show
  881.           @image_window.activate
  882.         end
  883.       end
  884.     end
  885.   end
  886.   #--------------------------------------------------------------------------
  887.   # * Actor [Cancel]
  888.   #--------------------------------------------------------------------------
  889.   def on_image_cancel
  890.     @image_window.unselect
  891.     @image_window.deactivate
  892.     @buy_window.activate
  893.   end
  894.   #--------------------------------------------------------------------------
  895.   # * Get Party Gold
  896.   #--------------------------------------------------------------------------
  897.   def money
  898.     @gold_window.value
  899.   end
  900.   #--------------------------------------------------------------------------
  901.   # Get Currency Unit
  902.   #--------------------------------------------------------------------------
  903.   def currency_unit
  904.     @gold_window.currency_unit
  905.   end
  906.   #--------------------------------------------------------------------------
  907.   # * Get Purchase Price
  908.   #--------------------------------------------------------------------------
  909.   def buying_price
  910.     @buy_window.price(@item)
  911.   end
  912. end
  913.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement