MrTrivel

MrTS_Crafting_Simple

Jun 25th, 2014
3,996
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 36.85 KB | None | 0 0
  1. # )----------------------------------------------------------------------------(
  2. # )--     AUTHOR:     Mr. Trivel                                             --(
  3. # )--     NAME:       Crafting Simple                                        --(
  4. # )--     CREATED:    2014-06-25                                             --(
  5. # )--     VERSION:    1.0                                                    --(
  6. # )----------------------------------------------------------------------------(
  7. # )--                         VERSION HISTORY                                --(
  8. # )--  1.0 - Initial Release                                                 --(
  9. # )----------------------------------------------------------------------------(
  10. # )--                          DESCRIPTION                                   --(
  11. # )--  Adds crafting. Infinite amount of different crafting Disciplines, each--(
  12. # )--  having it's own level. Recipes can be learned by calling a method or  --(
  13. # )--  by gaining a higher level in specific crafting discipline.            --(
  14. # )----------------------------------------------------------------------------(
  15. # )--                          INSTRUCTIONS                                  --(
  16. # )--                  Carefully set up everything.                          --(
  17. # )--          Learn new recipes by calling learn_recipe(id) method          --(
  18. # )--  Call crafting scene by calling SceneManager.call(MrTS_Scene_Crafting) --(
  19. # )----------------------------------------------------------------------------(
  20. # )--                          LICENSE INFO                                  --(
  21. # )--    http://mrtrivelvx.wordpress.com/terms-of-use/                       --(
  22. # )----------------------------------------------------------------------------(
  23.  
  24. # )----------------------------------------------------------------------------(
  25. # )--         Main Crafting module - Setup all data you want here.           --(
  26. # )----------------------------------------------------------------------------(
  27. module MrTS
  28.   module Crafting
  29.     # )------------------------------------------------------------------------(
  30.     # )--  Formula for craft levels exp requirements.                        --(
  31.     # )--  "50 * lvl" would mean level 1 requires 50 EXP, level 2 - 100 EXP..--(
  32.     # )------------------------------------------------------------------------(
  33.     CRAFT_EXP_FORMULA = "50 * lvl"
  34.    
  35.     # )------------------------------------------------------------------------(
  36.     # )--  Max level of Discipline player can reach.                         --(
  37.     # )------------------------------------------------------------------------(
  38.     CRAFT_MAX_LEVEL = 175
  39.    
  40.     # )------------------------------------------------------------------------(
  41.     # )--  Setup your Discipline names here.                                 --(
  42.     # )------------------------------------------------------------------------(
  43.     DISCIPLINES = { 0 => "Smithing",
  44.                     1 => "Alchemy",
  45.                     2 => "Bowmaking"
  46.                   }
  47.     # )------------------------------------------------------------------------(
  48.     # )--  Setup Recipes here.                                               --(
  49.     # )------------------------------------------------------------------------(
  50.     # )--  TYPE - 0: Item, 1: Weapon: 2: Armor                               --(
  51.     # )--  ITEM = [TYPE, ID, AMOUNT]                                         --(
  52.     # )------------------------------------------------------------------------(
  53.     # )--  :discipline => ID of the Discipline, the DISCIPLINES Key value.   --(
  54.     # )--                                                                    --(
  55.     # )--  :item => [TYPE, ID, AMOUNT] - What item Player gets from crafting --(
  56.     # )--  with this recipe. ID from database. AMOUNT - how much of the item --(
  57.     # )--  Player gets                                                       --(
  58.     # )--                                                                    --(
  59.     # )--  :exp => AMOUNT - How much Discipline EXP Player gets.             --(
  60.     # )--                                                                    --(
  61.     # )--  :ingredients => [ITEM, ITEM, ITEM]                                --(
  62.     # )--  What items Player requires to be able to craft using this Recipe. --(
  63.     # )--  E.g. [[0, 10, 7], [1, 15, 1]]                                     --(
  64.     # )--                                                                    --(
  65.     # )--  :unlocking => HOW - "default" it will be there by default (only   --(
  66.     # )--  shown if playe has sufficient discipline level requirement.       --(
  67.     # )--  "learn" - learned from method call learn_recipe(ID)               --(
  68.     # )--                                                                    --(
  69.     # )--  :level_req - LEVEL - Discipline level requirement                 --(
  70.     # )------------------------------------------------------------------------(
  71.     RECIPES = {
  72.       0 => {
  73.           :discipline   => 0,
  74.           :item         => [1,9,1],
  75.           :exp          => 10,
  76.           :ingredients  => [[0,23,1],[0,24,10]],      
  77.           :unlocking    => "default",
  78.           :level_req    => 0
  79.       },
  80.       1 => {
  81.           :discipline   => 0,
  82.           :item         => [2,3,1],
  83.           :exp          => 10,
  84.           :ingredients  => [[0,24,15],[0,21,5]],      
  85.           :unlocking    => "default",
  86.           :level_req    => 0        
  87.       },
  88.       2 => {
  89.           :discipline   => 0,
  90.           :item         => [0,23,1],
  91.           :exp          => 10,
  92.           :ingredients  => [[0,24,3]],    
  93.           :unlocking    => "learn",
  94.           :level_req    => 0
  95.       },
  96.       3 => {
  97.           :discipline   => 2,
  98.           :item         => [1,34,1],
  99.           :exp          => 25,
  100.           :ingredients  => [[0,24,3]],        
  101.           :unlocking    => "default",
  102.           :level_req    => 1
  103.       }
  104.     }
  105.    
  106.     # )------------------------------------------------------------------------(
  107.     # )--  Crafting command text.                                            --(
  108.     # )------------------------------------------------------------------------(
  109.     TEXT_CRAFT = "Craft"
  110.    
  111.     # )------------------------------------------------------------------------(
  112.     # )--  Disciplines command text                                          --(
  113.     # )------------------------------------------------------------------------(
  114.     TEXT_DISCIPLINES = "Disciplines"
  115.    
  116.     # )------------------------------------------------------------------------(
  117.     # )--                  Setting up part - finished.                       --(
  118.     # )------------------------------------------------------------------------(
  119.    
  120.     # )------------------------------------------------------------------------(
  121.     # )--  Method: self.get_all_recipes                                      --(
  122.     # )------------------------------------------------------------------------(
  123.     def self.get_all_recipes(discipline)
  124.       recipes = []
  125.       RECIPES.each_key do |key|
  126.         data = RECIPES[key]
  127.         if  data[:discipline] == discipline &&
  128.             data[:level_req] <= $game_party.get_discipline_level(discipline) &&
  129.             (data[:unlocking] == "default" || $game_party.known_recipe?(key))
  130.           recipes.push(key)
  131.         end
  132.       end
  133.       return recipes
  134.     end
  135.    
  136.   end
  137. end
  138.  
  139. # )----------------------------------------------------------------------------(
  140. # )--  Don't worry about this one.                                           --(
  141. # )--                                                                        --(
  142. $imported ||= {} ; $imported["MrTS_Crafting_Main"] = true #                  --(
  143. # )----------------------------------------------------------------------------(
  144.  
  145. # )----------------------------------------------------------------------------(
  146. # )--  Class: MrTS_Scene_Crafting                                            --(
  147. # )----------------------------------------------------------------------------(
  148. class MrTS_Scene_Crafting < Scene_Base
  149.  
  150.   # )--------------------------------------------------------------------------(
  151.   # )--  Method: start                                                       --(
  152.   # )--------------------------------------------------------------------------(
  153.   def start
  154.     create_main_viewport
  155.     create_all_windows
  156.   end
  157.  
  158.   # )--------------------------------------------------------------------------(
  159.   # )--  Method: create_all_windows                                          --(
  160.   # )--------------------------------------------------------------------------(
  161.   def create_all_windows
  162.     create_help_window
  163.     create_main_command_window
  164.     create_discipline_info_window
  165.     create_item_list_window
  166.     create_requirements_window
  167.     create_disciplines_command_window
  168.   end
  169.  
  170.   # )--------------------------------------------------------------------------(
  171.   # )-- All Windows
  172.   # )-----
  173.  
  174.   # )--------------------------------------------------------------------------(
  175.   # )--  Method: create_help_window                                          --(
  176.   # )--------------------------------------------------------------------------(
  177.   def create_help_window
  178.     @help_window = Window_Help.new
  179.     @help_window.viewport = @viewport
  180.     @help_window.y = Graphics.height - @help_window.height
  181.   end
  182.  
  183.   # )--------------------------------------------------------------------------(
  184.   # )--  Method: create_main_command_window                                  --(
  185.   # )--------------------------------------------------------------------------(
  186.   def create_main_command_window
  187.     @command_window = MrTS_Main_Command_Window.new
  188.     @command_window.set_handler(:discover_on, method(:command_discover_on))
  189.     @command_window.set_handler(:discipline_on, method(:command_discipline_on))
  190.     @command_window.set_handler(:craft_on, method(:command_craft_on))
  191.     @command_window.set_handler(:cancel, method(:command_cancel_on))
  192.   end
  193.  
  194.   # )--------------------------------------------------------------------------(
  195.   # )--  Method: create_discipline_info_window                               --(
  196.   # )--------------------------------------------------------------------------(
  197.   def create_discipline_info_window
  198.     @discipline_info_window = MrTS_Discipline_Info_Window.new
  199.   end
  200.  
  201.   # )--------------------------------------------------------------------------(
  202.   # )--  Method: create_item_list_window                                     --(
  203.   # )--------------------------------------------------------------------------(
  204.   def create_item_list_window
  205.     @item_window = MrTS_Item_Window.new(@command_window.height, Graphics.height-@command_window.height-@help_window.height)
  206.     @item_window.set_handler(:cancel, method(:item_list_cancel_on))
  207.     @item_window.set_handler(:ok, method(:item_list_ok_on))
  208.     @item_window.help_window = @help_window
  209.   end
  210.  
  211.   # )--------------------------------------------------------------------------(
  212.   # )--  Method: create_requirements_window                                  --(
  213.   # )--------------------------------------------------------------------------(
  214.   def create_requirements_window
  215.     @requirements_window = MrTS_Requirements_Window.new(@item_window.y, @item_window.height)
  216.     @item_window.requirement_window = @requirements_window
  217.   end
  218.  
  219.   # )--------------------------------------------------------------------------(
  220.   # )--  Method: create_disciplines_command_window                           --(
  221.   # )--------------------------------------------------------------------------(
  222.   def create_disciplines_command_window
  223.     @discipline_command_window = MrTS_Discipline_Command_Window.new(@command_window.width/2, @command_window.height)
  224.     @discipline_command_window.set_handler(:ok, method(:discipline_choice_on))
  225.     @discipline_command_window.set_handler(:cancel, method(:discipline_cancel_on))
  226.   end
  227.  
  228.   # )--------------------------------------------------------------------------(
  229.   # )-- All methods for windows
  230.   # )-----
  231.   # )---
  232.   # )--  Command Window
  233.   # )-
  234.  
  235.   # )--------------------------------------------------------------------------(
  236.   # )--  Method: command_discover_on                                         --(
  237.   # )--------------------------------------------------------------------------(
  238.   def command_discover_on
  239.     @item_window.activate
  240.     @item_window.type = 0
  241.     @requirements_window.type = 0
  242.     @item_window.refresh
  243.     @item_window.select(0)
  244.   end
  245.  
  246.   # )--------------------------------------------------------------------------(
  247.   # )--  Method: command_craft_on                                    --(
  248.   # )--------------------------------------------------------------------------(
  249.   def command_craft_on
  250.     @item_window.activate
  251.     @item_window.type = 1
  252.     @requirements_window.type = 1
  253.     @item_window.refresh
  254.     @item_window.select(0)
  255.   end
  256.  
  257.   # )--------------------------------------------------------------------------(
  258.   # )--  Method: command_discipline_on                                       --(
  259.   # )--------------------------------------------------------------------------(
  260.   def command_discipline_on
  261.     @discipline_command_window.open
  262.     @discipline_command_window.activate
  263.   end
  264.  
  265.   # )--------------------------------------------------------------------------(
  266.   # )--  Method: command_cancel_on                                           --(
  267.   # )--------------------------------------------------------------------------(
  268.   def command_cancel_on
  269.     return_scene
  270.   end
  271.  
  272.   # )---
  273.   # )--  Item List Window
  274.   # )-
  275.  
  276.   # )--------------------------------------------------------------------------(
  277.   # )--  Method: item_list_cancel_on                                         --(
  278.   # )--------------------------------------------------------------------------(
  279.   def item_list_cancel_on
  280.     @item_window.unselect
  281.     @command_window.activate
  282.   end
  283.  
  284.   # )--------------------------------------------------------------------------(
  285.   # )--  Method: item_list_ok_on                                             --(
  286.   # )--------------------------------------------------------------------------(
  287.   def item_list_ok_on
  288.     @requirements_window.craft_item
  289.     @item_window.activate
  290.     @discipline_info_window.refresh
  291.     @item_window.refresh
  292.   end
  293.  
  294.   # )---
  295.   # )--  Discipline Command List Window
  296.   # )-
  297.  
  298.   # )--------------------------------------------------------------------------(
  299.   # )--  Method: discipline_choice_on                                        --(
  300.   # )--------------------------------------------------------------------------(
  301.   def discipline_choice_on
  302.     i = @discipline_command_window.index
  303.     @item_window.discipline = i
  304.     @item_window.refresh
  305.     @discipline_info_window.discipline = i
  306.     @discipline_info_window.refresh
  307.     @command_window.activate
  308.     @discipline_command_window.close
  309.   end
  310.  
  311.   # )--------------------------------------------------------------------------(
  312.   # )--  Method: discipline_cancel_on                                        --(
  313.   # )--------------------------------------------------------------------------(
  314.   def discipline_cancel_on
  315.     @command_window.activate
  316.     @discipline_command_window.close
  317.   end  
  318. end
  319.  
  320.  
  321. # )----------------------------------------------------------------------------(
  322. # )--  Class: MrTS_Requirements_Window                                       --(
  323. # )----------------------------------------------------------------------------(
  324. class MrTS_Requirements_Window < Window_Base
  325.  
  326.   # )--------------------------------------------------------------------------(
  327.   # )--  Method: initialize                                                  --(
  328.   # )--------------------------------------------------------------------------(
  329.   def initialize(y, height)
  330.     super(Graphics.width/2, y, Graphics.width/2, height)
  331.     @type = 0
  332.   end
  333.  
  334.   # )--------------------------------------------------------------------------(
  335.   # )--  Method: type=                                                       --(
  336.   # )--------------------------------------------------------------------------(
  337.   def type=(value)
  338.     @type = value
  339.   end
  340.  
  341.   # )--------------------------------------------------------------------------(
  342.   # )--  Method: get_true_item                                               --(
  343.   # )--------------------------------------------------------------------------(
  344.   def get_true_item(i)
  345.     return unless i
  346.     return [$data_items[i[1]], i[2]] if i[0] == 0
  347.     return [$data_weapons[i[1]], i[2]] if i[0] == 1
  348.     return [$data_armors[i[1]], i[2]] if i[0] == 2
  349.   end
  350.  
  351.   # )--------------------------------------------------------------------------(
  352.   # )--  Method: set_recipe                                                  --(
  353.   # )--------------------------------------------------------------------------(
  354.   def set_recipe(item)
  355.     return unless item
  356.     @recipe = item
  357.     @item_list = []
  358.     MrTS::Crafting::RECIPES[@recipe][:ingredients].each { |i| @item_list.push(get_true_item(i)) }
  359.     refresh
  360.   end
  361.  
  362.   # )--------------------------------------------------------------------------(
  363.   # )--  Method: refresh                                                     --(
  364.   # )--------------------------------------------------------------------------(
  365.   def refresh
  366.     contents.clear
  367.     draw_window_name
  368.     draw_item_requirements
  369.   end
  370.  
  371.   # )--------------------------------------------------------------------------(
  372.   # )--  Method: draw_window_name                                            --(
  373.   # )--------------------------------------------------------------------------(
  374.   def draw_window_name
  375.     change_color(system_color)
  376.     draw_text(0,0,contents.width, line_height, @type == 1 ? "Requirements" : "Items added:", 1)
  377.     change_color(normal_color)
  378.   end
  379.  
  380.   # )--------------------------------------------------------------------------(
  381.   # )--  Method: draw_item_requirements                                      --(
  382.   # )--------------------------------------------------------------------------(
  383.   def draw_item_requirements
  384.     return unless @recipe    
  385.     a = 0
  386.     @item_list.each do |il|
  387.       y = line_height + line_height*a
  388.       draw_item_name(il[0], 0, y)
  389.       txt = "/" + il[1].to_s
  390.       draw_text(0, y, contents.width, line_height, txt, 2)
  391.       nmb = $game_party.item_number(il[0])
  392.       change_color(nmb >= il[1] ? tp_cost_color : nmb == 0 ? power_down_color : crisis_color)
  393.       draw_text(0, y, contents.width-text_size(txt).width, line_height, nmb, 2)
  394.       a += 1
  395.     end
  396.     change_color(system_color)
  397.     txt = "EXP Given: "
  398.     txtw = text_size(txt).width
  399.     draw_text(0, contents.height - line_height, contents.width-txtw, line_height, txt, 1)
  400.     change_color(crisis_color)
  401.     draw_text(0, contents.height - line_height, contents.width+txtw, line_height, MrTS::Crafting::RECIPES[@recipe][:exp].to_s, 1)
  402.   end
  403.  
  404.   # )--------------------------------------------------------------------------(
  405.   # )--  Method: craft_item                                                  --(
  406.   # )--------------------------------------------------------------------------(
  407.   def craft_item
  408.     @item_list.each do |il|
  409.       if $game_party.item_number(il[0]) < il[1]
  410.         Sound.play_buzzer
  411.         return
  412.       end
  413.     end
  414.     @item_list.each do |il|
  415.       $game_party.lose_item(il[0], il[1])
  416.     end
  417.     geto = get_true_item(MrTS::Crafting::RECIPES[@recipe][:item])
  418.     $game_party.gain_item(geto[0], geto[1])
  419.     $game_party.add_craft_exp(MrTS::Crafting::RECIPES[@recipe][:discipline], MrTS::Crafting::RECIPES[@recipe][:exp])
  420.   end
  421. end
  422.  
  423.  
  424. # )----------------------------------------------------------------------------(
  425. # )--  Class: MrTS_Item_Window                                               --(
  426. # )----------------------------------------------------------------------------(
  427. class MrTS_Item_Window < Window_Selectable
  428.  
  429.   # )--------------------------------------------------------------------------(
  430.   # )--  Method: initialize                                                  --(
  431.   # )--------------------------------------------------------------------------(
  432.   def initialize(y, height)
  433.     super(0, y, Graphics.width/2, height)
  434.     @discipline = 0
  435.     @type = 1
  436.     @data = []
  437.     @requirement_window = nil
  438.     refresh
  439.   end
  440.  
  441.   # )--------------------------------------------------------------------------(
  442.   # )--  Method: type=                                                       --(
  443.   # )--------------------------------------------------------------------------(
  444.   def type=(value)
  445.     @type = value
  446.   end
  447.  
  448.   # )--------------------------------------------------------------------------(
  449.   # )--  Method: discipline=                                                 --(
  450.   # )--------------------------------------------------------------------------(
  451.   def discipline=(value)
  452.     @discipline = value
  453.   end
  454.  
  455.   # )--------------------------------------------------------------------------(
  456.   # )--  Method: requirement_window=                                         --(
  457.   # )--------------------------------------------------------------------------(
  458.   def requirement_window=(value)
  459.     @requirement_window = value
  460.   end
  461.  
  462.   # )--------------------------------------------------------------------------(
  463.   # )--  Method: col_max                                                     --(
  464.   # )--------------------------------------------------------------------------(
  465.   def col_max
  466.     return 1
  467.   end
  468.  
  469.   # )--------------------------------------------------------------------------(
  470.   # )--  Method: item_max                                                    --(
  471.   # )--------------------------------------------------------------------------(
  472.   def item_max
  473.     @data ? @data.size : 1
  474.   end
  475.  
  476.   # )--------------------------------------------------------------------------(
  477.   # )--  Method: item                                                        --(
  478.   # )--------------------------------------------------------------------------(
  479.   def item
  480.     @data && index >= 0 ? @data[index] : nil
  481.   end
  482.  
  483.   # )--------------------------------------------------------------------------(
  484.   # )--  Method: current_item_enabled?                                       --(
  485.   # )--------------------------------------------------------------------------(
  486.   def current_item_enabled? ; true ;  end
  487.  
  488.   # )--------------------------------------------------------------------------(
  489.   # )--  Method: include?                                                    --(
  490.   # )--------------------------------------------------------------------------(
  491.   def include?(item) ; true ;  end
  492.  
  493.   # )--------------------------------------------------------------------------(
  494.   # )--  Method: discipline_cancel_on                                        --(
  495.   # )--------------------------------------------------------------------------(
  496.   def make_item_list
  497.     @data = @type == 0 ? $game_party.all_items : MrTS::Crafting::get_all_recipes(@discipline)
  498.   end
  499.  
  500.   # )--------------------------------------------------------------------------(
  501.   # )--  Method: select_last                                                 --(
  502.   # )--------------------------------------------------------------------------(
  503.   def select_last
  504.     select(@data.index($game_party.last_item.object) || 0)
  505.   end
  506.  
  507.   # )--------------------------------------------------------------------------(
  508.   # )--  Method: draw_item                                                   --(
  509.   # )--------------------------------------------------------------------------(
  510.   def draw_item(index)
  511.     case @type
  512.     when 0
  513.       item = @data[index]
  514.       if item
  515.         rect = item_rect(index)
  516.         rect.width -= 4
  517.         draw_item_name(item, rect.x, rect.y, true)
  518.         draw_item_number(rect, item)
  519.       end
  520.     when 1
  521.       item = @data[index]
  522.       if item
  523.         rect = item_rect(index)
  524.         rect.width -= 4
  525.         draw_recipe_name(item, rect.x, rect.y, true)
  526.       end
  527.     end    
  528.   end
  529.  
  530.   # )--------------------------------------------------------------------------(
  531.   # )--  Method: draw_recipe_name                                            --(
  532.   # )--------------------------------------------------------------------------(
  533.   def draw_recipe_name(item, x, y, enabled)
  534.     return unless item
  535.     true_item = get_true_item(item)
  536.     draw_icon(true_item.icon_index, x, y, enabled)
  537.     change_color(normal_color, enabled)
  538.     draw_text(x + 24, y, width, line_height, true_item.name)
  539.     draw_text(x, y, contents.width, line_height, sprintf("x%2d", $game_party.item_number(true_item)), 2)
  540.   end
  541.  
  542.   # )--------------------------------------------------------------------------(
  543.   # )--  Method: get_true_item                                               --(
  544.   # )--------------------------------------------------------------------------(
  545.   def get_true_item(i)
  546.     return unless i
  547.     temp = MrTS::Crafting::RECIPES[i][:item]
  548.     return $data_items[temp[1]] if temp[0] == 0
  549.     return $data_weapons[temp[1]] if temp[0] == 1
  550.     return $data_armors[temp[1]] if temp[0] == 2
  551.   end
  552.  
  553.   # )--------------------------------------------------------------------------(
  554.   # )--  Method: draw_item_number                                            --(
  555.   # )--------------------------------------------------------------------------(
  556.   def draw_item_number(rect, item)
  557.     draw_text(rect, sprintf(":%2d", $game_party.item_number(item)), 2)
  558.   end
  559.  
  560.   # )--------------------------------------------------------------------------(
  561.   # )--  Method: update_help                                                 --(
  562.   # )--------------------------------------------------------------------------(
  563.   def update_help
  564.     @help_window.set_item(@type == 0 ? item : get_true_item(item))
  565.     @requirement_window.set_recipe(item) if @type == 1
  566.   end
  567.  
  568.   # )--------------------------------------------------------------------------(
  569.   # )--  Method: refresh                                                     --(
  570.   # )--------------------------------------------------------------------------(
  571.   def refresh
  572.     make_item_list
  573.     create_contents
  574.     draw_all_items
  575.   end
  576. end
  577.  
  578.  
  579. # )----------------------------------------------------------------------------(
  580. # )--  Class: MrTS_Discipline_Info_Window                                    --(
  581. # )----------------------------------------------------------------------------(
  582. class MrTS_Discipline_Info_Window < Window_Base
  583.  
  584.   # )--------------------------------------------------------------------------(
  585.   # )--  Public Instance Variables                                           --(
  586.   # )--------------------------------------------------------------------------(
  587.   attr_writer :discipline
  588.  
  589.   # )--------------------------------------------------------------------------(
  590.   # )--  Method: initialize                                                  --(
  591.   # )--------------------------------------------------------------------------(
  592.   def initialize
  593.     super(Graphics.width - Graphics.width/2+50, 0, Graphics.width/2-50, line_height + standard_padding*2)
  594.     @discipline = 0
  595.     refresh
  596.   end
  597.  
  598.   # )--------------------------------------------------------------------------(
  599.   # )--  Method: refresh                                                     --(
  600.   # )--------------------------------------------------------------------------(
  601.   def refresh
  602.     contents.clear
  603.     change_color(system_color)
  604.     draw_text(0,-5,contents.width, line_height, MrTS::Crafting::DISCIPLINES[@discipline].to_s)
  605.     change_color(normal_color)
  606.     draw_text(0,-5,contents.width, line_height, "Lv: " + $game_party.get_discipline_level(@discipline).to_s,2)
  607.     draw_gauge(0, 4, contents.width, $game_party.get_discipline_rate(@discipline), normal_color, crisis_color)
  608.     make_font_smaller
  609.     change_color(power_down_color)
  610.     draw_text(10, 7, contents.width, line_height, $game_party.get_discipline_exp(@discipline).to_s + "/" + $game_party.get_discipline_next_level_exp(@discipline).to_s, 1)
  611.     change_color(normal_color)
  612.     make_font_bigger
  613.   end
  614. end
  615.  
  616.  
  617. # )----------------------------------------------------------------------------(
  618. # )--  Class: MrTS_Main_Command_Window                                       --(
  619. # )----------------------------------------------------------------------------(
  620. class MrTS_Main_Command_Window < Window_HorzCommand
  621.  
  622.   # )--------------------------------------------------------------------------(
  623.   # )--  Method: initialize                                                  --(
  624.   # )--------------------------------------------------------------------------(
  625.   def initialize
  626.     super(0,0)
  627.   end
  628.  
  629.   # )--------------------------------------------------------------------------(
  630.   # )--  Method: window_width                                                --(
  631.   # )--------------------------------------------------------------------------(
  632.   def window_width
  633.     (Graphics.width/2)+50
  634.   end
  635.  
  636.   # )--------------------------------------------------------------------------(
  637.   # )--  Method: col_max                                                     --(
  638.   # )--------------------------------------------------------------------------(
  639.   def col_max
  640.     return 2
  641.   end
  642.  
  643.   # )--------------------------------------------------------------------------(
  644.   # )--  Method: spacing                                                     --(
  645.   # )--------------------------------------------------------------------------(
  646.   def spacing
  647.     return 3
  648.   end
  649.  
  650.   # )--------------------------------------------------------------------------(
  651.   # )--  Method: make_command_list                                           --(
  652.   # )--------------------------------------------------------------------------(
  653.   def make_command_list
  654.     add_command(MrTS::Crafting::TEXT_CRAFT, :craft_on)
  655.     add_command(MrTS::Crafting::TEXT_DISCIPLINES, :discipline_on)
  656.   end
  657.  
  658.   # )--------------------------------------------------------------------------(
  659.   # )--  Method: item_rect_for_text                                          --(
  660.   # )--------------------------------------------------------------------------(
  661.   def item_rect_for_text(index)
  662.     rect = item_rect(index)
  663.     rect
  664.   end
  665. end
  666.  
  667.  
  668. # )----------------------------------------------------------------------------(
  669. # )--  Class: MrTS_Discipline_Command_Window                                 --(
  670. # )----------------------------------------------------------------------------(
  671. class MrTS_Discipline_Command_Window < Window_Command
  672.  
  673.   # )--------------------------------------------------------------------------(
  674.   # )--  Method: initialize                                                  --(
  675.   # )--------------------------------------------------------------------------(
  676.   def initialize(x, y)
  677.     super(x, y)
  678.     self.openness = 0
  679.   end
  680.  
  681.   # )--------------------------------------------------------------------------(
  682.   # )--  Method: window_width                                                --(
  683.   # )--------------------------------------------------------------------------(
  684.   def window_width
  685.     ((Graphics.width/2)+50)/2
  686.   end
  687.  
  688.   # )--------------------------------------------------------------------------(
  689.   # )--  Method: make_command_list                                           --(
  690.   # )--------------------------------------------------------------------------(
  691.   def make_command_list
  692.     MrTS::Crafting::DISCIPLINES.each_value { |d| add_command(d, :ok) }
  693.   end
  694. end
  695.  
  696. # )----------------------------------------------------------------------------(
  697. # )--  Class: Game_Party                                                     --(
  698. # )----------------------------------------------------------------------------(
  699. class Game_Party < Game_Unit
  700.  
  701.   # )--------------------------------------------------------------------------(
  702.   # )--  Public Instance Variables                                           --(
  703.   # )--------------------------------------------------------------------------(
  704.   attr_reader   :disciplines #lv, xp
  705.   attr_reader   :learned_recipes
  706.  
  707.   # )--------------------------------------------------------------------------(
  708.   # )--  Alias to: initialize                                                --(
  709.   # )--------------------------------------------------------------------------(
  710.   alias mrts_gp_initialize initialize
  711.   def initialize
  712.     mrts_gp_initialize
  713.     initialize_disciplines
  714.     initialize_recipes
  715.   end
  716.  
  717.   # )--------------------------------------------------------------------------(
  718.   # )--  Method: initialize_disciplines                                      --(
  719.   # )--------------------------------------------------------------------------(
  720.   def initialize_disciplines
  721.     @disciplines = []
  722.     MrTS::Crafting::DISCIPLINES.each_value { |value| @disciplines.push([1, 0]) }
  723.   end
  724.  
  725.   # )--------------------------------------------------------------------------(
  726.   # )--  Method: initialize_recipes                                          --(
  727.   # )--------------------------------------------------------------------------(
  728.   def initialize_recipes
  729.     @learned_recipes = []
  730.   end
  731.  
  732.   # )--------------------------------------------------------------------------(
  733.   # )--  Method: add_craft_exp                                               --(
  734.   # )--------------------------------------------------------------------------(
  735.   def add_craft_exp(id, exp)
  736.     @disciplines[id][1] += exp
  737.     craft_level_up(id)
  738.   end
  739.  
  740.   # )--------------------------------------------------------------------------(
  741.   # )--  Method: craft_level_up                                              --(
  742.   # )--------------------------------------------------------------------------(
  743.   def craft_level_up(id)
  744.     while get_discipline_exp(id) >= get_discipline_next_level_exp(id) && get_discipline_level(id) < MrTS::Crafting::CRAFT_MAX_LEVEL
  745.       @disciplines[id][0] += 1
  746.       @disciplines[id][1] -= get_discipline_current_level_exp(id)
  747.     end
  748.   end
  749.  
  750.   # )--------------------------------------------------------------------------(
  751.   # )--  Method: get_discipline_exp                                          --(
  752.   # )--------------------------------------------------------------------------(
  753.   def get_discipline_exp(id)
  754.     return @disciplines[id][1]
  755.   end
  756.  
  757.   # )--------------------------------------------------------------------------(
  758.   # )--  Method: get_discipline_level                                        --(
  759.   # )--------------------------------------------------------------------------(
  760.   def get_discipline_level(id)
  761.     return @disciplines[id][0]
  762.   end
  763.  
  764.   # )--------------------------------------------------------------------------(
  765.   # )--  Method: known_recipe?                                               --(
  766.   # )--------------------------------------------------------------------------(
  767.   def known_recipe?(id)
  768.     @learned_recipes.include?(id)
  769.   end
  770.  
  771.   # )--------------------------------------------------------------------------(
  772.   # )--  Method: get_discipline_current_level_exp                            --(
  773.   # )--------------------------------------------------------------------------(
  774.   def get_discipline_current_level_exp(id)
  775.     lvl = get_discipline_level(id)-1
  776.     return eval(MrTS::Crafting::CRAFT_EXP_FORMULA)
  777.   end
  778.  
  779.   # )--------------------------------------------------------------------------(
  780.   # )--  Method: get_discipline_next_level_exp                               --(
  781.   # )--------------------------------------------------------------------------(
  782.   def get_discipline_next_level_exp(id)
  783.     lvl = get_discipline_level(id)
  784.     return eval(MrTS::Crafting::CRAFT_EXP_FORMULA)
  785.   end
  786.  
  787.   # )--------------------------------------------------------------------------(
  788.   # )--  Method: get_discipline_rate                                         --(
  789.   # )--------------------------------------------------------------------------(
  790.   def get_discipline_rate(id)
  791.     return 1.0 if get_discipline_level(id) == MrTS::Crafting::CRAFT_MAX_LEVEL
  792.     return get_discipline_exp(id).to_f / get_discipline_next_level_exp(id).to_f
  793.   end
  794. end
  795.  
  796. # )----------------------------------------------------------------------------(
  797. # )--  Class: Game_Interpreter                                               --(
  798. # )----------------------------------------------------------------------------(
  799. class Game_Interpreter
  800.  
  801.   # )--------------------------------------------------------------------------(
  802.   # )--  Method: learn_recipe                                                --(
  803.   # )--------------------------------------------------------------------------(
  804.   def learn_recipe(id)
  805.     $game_party.learned_recipes.push(id)
  806.   end
  807. end
Advertisement
Add Comment
Please, Sign In to add comment