FeaR616

FeaR Element Combination System

Jan 21st, 2015
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 48.92 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # ** FeaR - Element Combination v1.0
  4. # -- Release date: 21.01.2015
  5. # -- Level: Normal
  6. # -- Requires: n/a
  7. # -- Recommended Scripts: KilloZapit Word Wrapping Message Boxes
  8. #                         which can be found here http://www.rpgmakervxace.net/topic/6964-word-wrapping-message-boxes/
  9. #
  10. # -- Thanks for helping and understanding some things:
  11. #    shaz, Sixth, BoluBolu, Engr. Adiktuzmiko, Another Fen from http://forums.rpgmakerweb.com/
  12. #==============================================================================
  13.  
  14. $imported = {} if $imported.nil?
  15. $imported["FeaR_ElementCombination"] = true
  16.  
  17. #==============================================================================
  18. # * Changelog
  19. #==============================================================================
  20. # # v1.0 - 21.01.2015   - initial release
  21. # # v1.1 - 22.01.2015   - add some minor bugfixes
  22. #
  23. #==============================================================================
  24. # * Terms of use
  25. #==============================================================================
  26. # 1. You can use this script for non-commercial and commercial usage.
  27. # 2. You can modify this script for your own purposes.
  28. # 3. If you want to share this script, please refer to this link: http://forums.rpgmakerweb.com/index.php?/topic/36143-element-combination-system/
  29. # 4. Credits given to me would be nice if you use this script.
  30. #
  31. #==============================================================================
  32. # * Introduction
  33. #==============================================================================
  34. # This script allows you to set up new elements that can be created if the
  35. # player combines two or three elements together. For example, Earth and Water
  36. # elements combine together a new Plant element. But the choice order is important
  37. # too, so you can make a new Mud element by combining Water and Earth (not like
  38. # the other order which creates Plant).
  39. # This script even provides an own skill leveling system based on elements.
  40. # Instead of learning dozens of Fire, Water and Earth skills, the actor only learn
  41. # one skill per element. If the skill is used enough, element points can be
  42. # earned to level up the element itself and this results in a stronger skill.
  43. # Users of this script can determine how much a skill have to be used by the
  44. # player to gain one element point.
  45. #
  46. #==============================================================================
  47. # * Instructions
  48. #==============================================================================
  49. # To install this script, open up your script editor and copy/paste this script
  50. # to an open slot below Materials but above Main. Remember to save.
  51. #
  52. # -----------------------------------------------------------------------------
  53. # Skill Notetags - These notetags go in the skills notebox in the database.
  54. # -----------------------------------------------------------------------------
  55. # <combination_level: x, y, z>
  56. # This determines what level the skill is and how often the player have to use
  57. # it, to level up the skills element.
  58. #     x = current skill level e.g. 1
  59. #     y = maximum skill level e.g. 10
  60. #     z = frequency e.g. 10 => use Fire skill 10 times to gain one element point
  61. #                              and level up to Fire II skill or use it for
  62. #                              combination with other elements. Next level should
  63. #                              have a higher frequency, but its up to you.
  64. #
  65. # -----------------------------------------------------------------------------
  66. # !!! IMPORTANT THINGS, DO NOT FORGET THIS !!!
  67. # -----------------------------------------------------------------------------
  68. # 1. This script is designed that only one actor is in the position to use this
  69. #    system, the actor with the index 1.
  70. # 2. To work properly, every skill must have an element selected in the database!
  71. # 3. If you say in skill notetags, that the max level is 6, then you have to
  72. #    make 6 skills of this element!
  73. # 4. In the skills formula box you have to write v[x] += 1; where x is the index
  74. #    of the variable you use to determine how much the element is used.
  75. # 5. For the last skill level it is not neccessary to write a frequency number
  76. #    into the z position of the notetag, just write a 1, it is the last level.
  77. # 6. THIS IS VERY IMPORTANT: In the database, the actor mustn't have any
  78. #    skill learned that you want to use this system for. Why? Skills the actor
  79. #    knows at the beginning of a game (the ones in the database) can not be
  80. #    forgotten! So add some Level 1 skills via event at game start.
  81. #
  82. #==============================================================================
  83. # * Compatibility
  84. #==============================================================================
  85. # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
  86. # it will run with RPG Maker VX without adjusting.
  87. #
  88. # [Maybe in future: This script is compatible with Yanfly's Ace Menu Engine]
  89. #==============================================================================
  90.  
  91. $imported = {} if $imported.nil?
  92. $imported["FeaR_ElementCombination"] = true
  93.  
  94. module FeaR
  95.  
  96.   Elements = {
  97. #==============================================================================
  98. # * EDITABLE REGION
  99. #   Add here your elements.
  100. #==============================================================================
  101.  
  102.       "Fire" =>
  103.       {
  104.           :display_name     => "Fire",  # how the element is displayed in menu
  105.           :element_index    => 3,  # element index in database
  106.           :consists_of_1    => 0,  # this element consists of? element index from database
  107.           :consists_of_2    => 0,  # for example Plant consists of Earth
  108.           :consists_of_3    => 0,  # and Water.
  109.          
  110.           :usage_variable   => 11, # variable index where skill usage is counted
  111.           :enable_switch    => 0,  # index of switch which is used so this
  112.                                    # script hides the element until it is learned
  113.                                    # make this to 0 for a base element like fire
  114.                                        
  115.           :current_level    => 0,  # have always to be 0!
  116.           :max_level        => 0,  # have always to be 0!
  117.           :frequency        => 0,  # have always to be 0!
  118.           :current_skill_id => 0,  # have always to be 0!
  119.           :element_point    => 0,  # have always to be 0!
  120.          
  121.           # an info text which will be displayed when cursor selects an element
  122.           :info_text        => "Fire Element. Burns every Enemy down!"
  123.       },
  124.      
  125.       "Thunder" =>
  126.       {
  127.           :display_name     => "Thunder",
  128.           :element_index    => 5,
  129.           :consists_of_1    => 0,
  130.           :consists_of_2    => 0,
  131.           :consists_of_3    => 0,
  132.           :usage_variable   => 12,
  133.           :enable_switch    => 0,
  134.           :current_level    => 0, # have always to be 0
  135.           :max_level        => 0, # have always to be 0
  136.           :frequency        => 0, # have always to be 0
  137.           :current_skill_id => 0, # have always to be 0
  138.           :element_point    => 0, # have always to be 0
  139.           :info_text        => "Thunder Element. Hit the Lights!"
  140.       },
  141.      
  142.       "Water" =>
  143.       {
  144.           :display_name     => "Water",
  145.           :element_index    => 6,
  146.           :consists_of_1    => 0,
  147.           :consists_of_2    => 0,
  148.           :consists_of_3    => 0,
  149.           :usage_variable   => 13,
  150.           :enable_switch    => 0,
  151.           :current_level    => 0, # have always to be 0
  152.           :max_level        => 0, # have always to be 0
  153.           :frequency        => 0, # have always to be 0
  154.           :current_skill_id => 0, # have always to be 0
  155.           :element_point    => 0, # have always to be 0
  156.           :info_text        => "Water Element. May the Enemies drown!"
  157.       },
  158.      
  159.       "Earth" =>
  160.       {
  161.           :display_name     => "Earth",
  162.           :element_index    => 7,
  163.           :consists_of_1    => 0,
  164.           :consists_of_2    => 0,
  165.           :consists_of_3    => 0,
  166.           :usage_variable   => 14,
  167.           :enable_switch    => 0,
  168.           :current_level    => 0, # have always to be 0
  169.           :max_level        => 0, # have always to be 0
  170.           :frequency        => 0, # have always to be 0
  171.           :current_skill_id => 0, # have always to be 0
  172.           :element_point    => 0, # have always to be 0
  173.           :info_text        => "Earth Element. Hard hitting rocks!"
  174.       },
  175.      
  176.       "Wind" =>
  177.       {
  178.           :display_name     => "Wind",
  179.           :element_index    => 8,
  180.           :consists_of_1    => 0,
  181.           :consists_of_2    => 0,
  182.           :consists_of_3    => 0,
  183.           :usage_variable   => 15,
  184.           :enable_switch    => 0,
  185.           :current_level    => 0, # have always to be 0
  186.           :max_level        => 0, # have always to be 0
  187.           :frequency        => 0, # have always to be 0
  188.           :current_skill_id => 0, # have always to be 0
  189.           :element_point    => 0, # have always to be 0
  190.           :info_text        => "Wind Element. Roaring tempests!"
  191.       },
  192.      
  193.       "Plant" =>
  194.       {
  195.           :display_name     => "Plant",
  196.           :element_index    => 11,
  197.           :consists_of_1    => 7,
  198.           :consists_of_2    => 6,
  199.           :consists_of_3    => 0,
  200.           :usage_variable   => 16,
  201.           :enable_switch    => 12,
  202.           :current_level    => 0, # have always to be 0
  203.           :max_level        => 0, # have always to be 0
  204.           :frequency        => 0, # have always to be 0
  205.           :current_skill_id => 0, # have always to be 0
  206.           :element_point    => 0, # have always to be 0
  207.           :info_text        => "Wood Element. Used for Protection!"
  208.       },
  209.      
  210.       "Magma" =>
  211.       {
  212.           :display_name     => "Magma",
  213.           :element_index    => 12,
  214.           :consists_of_1    => 3,
  215.           :consists_of_2    => 7,
  216.           :consists_of_3    => 6,
  217.           :usage_variable   => 17,
  218.           :enable_switch    => 13,
  219.           :current_level    => 0, # have always to be 0
  220.           :max_level        => 0, # have always to be 0
  221.           :frequency        => 0, # have always to be 0
  222.           :current_skill_id => 0, # have always to be 0
  223.           :element_point    => 0, # have always to be 0
  224.           :info_text        => "Magma Element. Changes battlefield into sea of magma!"
  225.       },
  226.      
  227.       "Mud" =>
  228.       {
  229.           :display_name     => "Mud",
  230.           :element_index    => 13,
  231.           :consists_of_1    => 6,
  232.           :consists_of_2    => 7,
  233.           :consists_of_3    => 0,
  234.           :usage_variable   => 18,
  235.           :enable_switch    => 14,
  236.           :current_level    => 0, # have always to be 0
  237.           :max_level        => 0, # have always to be 0
  238.           :frequency        => 0, # have always to be 0
  239.           :current_skill_id => 0, # have always to be 0
  240.           :element_point    => 0, # have always to be 0
  241.           :info_text        => "Mud Element. Throws poisonous mud on enemies!"
  242.       },
  243.      
  244. #==============================================================================
  245. # * END OF EDITABLE REGION
  246. #==============================================================================
  247.   }
  248.  
  249. #==============================================================================
  250. # * Do not edit anything past this point unless you know what you do.
  251. #   I am not responsible for your editings.
  252. #==============================================================================
  253.  
  254.   # DO NOT TOUCH THIS!
  255.   REGEX = /<combination_level:[ ](\d+,s* \d+,s* \d+)>/i
  256.   #              notetag          lvl   maxlvl  frequency
  257.  
  258.   MenuCommandText = "Element Combination"
  259.   HelpWindowText1 = "Level up an element"
  260.   HelpWindowText2 = "or combine elements to create a new one."
  261.  
  262.   module VOCAB
  263.     CURRENT_SKILL = 'Current Skill: '
  264.     NEXT_SKILL    = 'Next Skill: '
  265.     NEW_ELEMENT   = 'New Element: '
  266.     COMBINE       = 'Combine those Elements?'
  267.     LVLUP         = 'Level up this Element?'
  268.   end
  269.  
  270. end
  271.  
  272. $Lvlup_switch    = true
  273. $Combine_switch  = false
  274.  
  275. #-------------------------------------------------------------------------------
  276. #    Window Combination Category
  277. #-------------------------------------------------------------------------------
  278. class Window_CombinationCategory < Window_ItemCategory #Command
  279.  
  280.   #--------------------------------------------------------------------------
  281.   # * Create Command List
  282.   #--------------------------------------------------------------------------
  283.   def make_command_list
  284.     add_command("Level Up", :lvlup)
  285.     add_command("Combine", :combine)
  286.   end
  287.  
  288. end # end Window Combination Category
  289.  
  290. #-------------------------------------------------------------------------------
  291. #    Window Yes No Option
  292. #-------------------------------------------------------------------------------
  293. class Window_YesNoOption < Window_ItemCategory #Command
  294.  
  295.   #--------------------------------------------------------------------------
  296.   # * Get Window Width
  297.   #--------------------------------------------------------------------------
  298.   def window_width
  299.     Graphics.width * 0.5
  300.   end
  301.   #--------------------------------------------------------------------------
  302.   # * Get Digit Count
  303.   #--------------------------------------------------------------------------
  304.   def col_max
  305.     return 2
  306.   end
  307.  
  308.   #--------------------------------------------------------------------------
  309.   # * Create Command List
  310.   #--------------------------------------------------------------------------
  311.   def make_command_list
  312.     add_command("Yes", :option_yes)
  313.     add_command("No",  :option_no)
  314.   end
  315.  
  316. end # end Window Yes No Option
  317.  
  318. #-------------------------------------------------------------------------------
  319. #    Window Result
  320. #-------------------------------------------------------------------------------
  321. class Window_YesNoText < Window_Base
  322.  
  323.   #--------------------------------------------------------------------------
  324.   # * Get Window Width
  325.   #--------------------------------------------------------------------------
  326.   def window_width
  327.     return Graphics.width * 0.5
  328.   end
  329.   #--------------------------------------------------------------------------
  330.   # * Draw Text with Control Characters
  331.   #--------------------------------------------------------------------------
  332.   def draw_text_ex(x, y, text)
  333.     #reset_font_settings
  334.     text = convert_escape_characters(text)
  335.     pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  336.     process_character(text.slice!(0, 1), text, pos) until text.empty?
  337.   end
  338.   #--------------------------------------------------------------------------
  339.   # * Draw Text for Yes No Options
  340.   #--------------------------------------------------------------------------
  341.   def draw_text_option()
  342.     contents.clear()
  343.     if $Lvlup_switch == true
  344.       contents.draw_text(0,0,width,line_height,FeaR::VOCAB::LVLUP)
  345.     elsif $Combine_switch == true
  346.       contents.draw_text(0,0,width,line_height,FeaR::VOCAB::COMBINE)
  347.     end
  348.   end
  349.   #--------------------------------------------------------------------------
  350.   # * Wait After Output of One Character
  351.   #--------------------------------------------------------------------------
  352.   def wait_for_one_character
  353.   end
  354.  
  355. end # end Window Yes No Text
  356.  
  357. #-------------------------------------------------------------------------------
  358. #    Window Available Elements
  359. #-------------------------------------------------------------------------------
  360. class Window_AvailableElements < Window_Command
  361.    
  362.   #--------------------------------------------------------------------------
  363.   # * Get Window Width
  364.   #--------------------------------------------------------------------------
  365.   def window_width
  366.     return Graphics.width * 0.5
  367.   end
  368.   #--------------------------------------------------------------------------
  369.   # * Get Alignment
  370.   #--------------------------------------------------------------------------
  371.   def alignment
  372.     return 0
  373.   end
  374.   #--------------------------------------------------------------------------
  375.   # * Make Command List
  376.   #--------------------------------------------------------------------------
  377.   def make_command_list()
  378.     FeaR::Elements.each_key do |key_name| # iterate over elements
  379.       switch_id = FeaR::Elements[key_name][:enable_switch]    # store switch id
  380.       skill_id = FeaR::Elements[key_name][:current_skill_id]  # store skill id
  381.       # next unless the switch is true OR the switch is zero AND the skill id is not zero
  382.       next unless $game_switches[switch_id] || switch_id == 0 && skill_id != 0
  383.       enable = true
  384.       if FeaR::Elements[key_name][:element_point] == 0
  385.         enable = false
  386.       end
  387.       add_command(FeaR::Elements[key_name][:display_name] + "  Lvl " + FeaR::Elements[key_name][:current_level].to_s,
  388.       key_name.to_sym, enable)
  389.     end
  390.   end
  391.      
  392. end # end Window Available Elements
  393.  
  394. #-------------------------------------------------------------------------------
  395. #    Window Result
  396. #-------------------------------------------------------------------------------
  397. class Window_Result < Window_Base
  398.  
  399.   #--------------------------------------------------------------------------
  400.   # * Get Window Width
  401.   #--------------------------------------------------------------------------
  402.   def window_width
  403.     return Graphics.width * 0.5
  404.   end
  405.   #--------------------------------------------------------------------------
  406.   # * Draw Text with Control Characters
  407.   #--------------------------------------------------------------------------
  408.   def draw_text_ex(x, y, text)
  409.     #reset_font_settings
  410.     text = convert_escape_characters(text)
  411.     pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  412.     process_character(text.slice!(0, 1), text, pos) until text.empty?
  413.   end
  414.  
  415.   #--------------------------------------------------------------------------
  416.   # * Draw Text for Combination
  417.   #--------------------------------------------------------------------------
  418.   def draw_skill_combine(chosen_element_1, chosen_element_2, chosen_element_3, new_element)
  419.     contents.clear()
  420.     # write 1.
  421.     contents.draw_text(0,0,width,line_height,"1.")
  422.     # write element 1
  423.     if chosen_element_1 != nil
  424.       icon = $data_skills[FeaR::Elements[chosen_element_1.to_s][:current_skill_id]].icon_index
  425.       draw_icon(icon, 25, 0, true)
  426.       contents.draw_text(55,0,width,line_height,FeaR::Elements[chosen_element_1.to_s][:display_name])
  427.     end
  428.     # write 2.
  429.     contents.draw_text(0,line_height,width,line_height,"2.")
  430.     # write element 2
  431.     if chosen_element_2 != nil
  432.       icon = $data_skills[FeaR::Elements[chosen_element_2.to_s][:current_skill_id]].icon_index
  433.       draw_icon(icon, 25, line_height, true)
  434.       contents.draw_text(55,line_height,width,line_height,FeaR::Elements[chosen_element_2.to_s][:display_name])
  435.     end
  436.     # write 3.
  437.     contents.draw_text(0,line_height*2,width,line_height,"3.")
  438.     # write element 3
  439.     if chosen_element_3 != nil
  440.       icon = $data_skills[FeaR::Elements[chosen_element_3.to_s][:current_skill_id]].icon_index
  441.       draw_icon(icon, 25, line_height*2, true)
  442.       contents.draw_text(55,line_height*2,width,line_height,FeaR::Elements[chosen_element_3.to_s][:display_name])
  443.     end
  444.    
  445.     # draw horizontal line
  446.     draw_horz_line(line_height * 6)
  447.    
  448.     # write new element
  449.     contents.draw_text(0,line_height*7,width,line_height,FeaR::VOCAB::NEW_ELEMENT)
  450.     if new_element != nil
  451.       contents.draw_text(FeaR::VOCAB::NEW_ELEMENT.length*10,line_height*7,width,line_height,FeaR::Elements[new_element.to_s][:display_name])
  452.       contents.draw_text(0,line_height*8,width,line_height,FeaR::Elements[new_element.to_s][:info_text])
  453.     end
  454.    
  455.   end
  456.  
  457.   #--------------------------------------------------------------------------
  458.   # * Draw Text for Level Up
  459.   #--------------------------------------------------------------------------
  460.     def draw_skill_lvl_up(current_skill_id, next_skill_id)
  461.     # clear window
  462.     contents.clear()
  463.    
  464.     x_pos_current = FeaR::VOCAB::CURRENT_SKILL.length
  465.     x_pos_next    = FeaR::VOCAB::NEXT_SKILL.length
  466.     current_skill = $data_skills[current_skill_id]
  467.     next_skill    = $data_skills[next_skill_id]
  468.    
  469.     # write Current Skill:
  470.     change_color(system_color)
  471.     contents.draw_text(0,0,width,line_height,FeaR::VOCAB::CURRENT_SKILL)
  472.     change_color(normal_color)
  473.     # draw skill icon
  474.     draw_icon(current_skill.icon_index, 0, line_height, true)
  475.     # write skill name
  476.     contents.draw_text(25,line_height,width,line_height,current_skill.name)
  477.     # write skill mp cost
  478.     change_color(mp_cost_color)
  479.     contents.font.size = 18
  480.     contents.draw_text(200,(line_height)+2,width,line_height,current_skill.mp_cost.to_s + " MP")
  481.     change_color(normal_color)
  482.     contents.font.size = Font.default_size
  483.     # write skill description
  484.     contents.draw_text(0, line_height*2,width,line_height,current_skill.description)
  485.    
  486.     # draw horizontal line
  487.     draw_horz_line(line_height * 5)
  488.    
  489.     # write Next Skill
  490.     change_color(system_color)
  491.     contents.draw_text(0,line_height*6,width,line_height,FeaR::VOCAB::NEXT_SKILL)
  492.     change_color(normal_color)
  493.     # draw skill icon
  494.     draw_icon(next_skill.icon_index, 0,line_height*7,true)
  495.     # write skill name
  496.     contents.draw_text(25,line_height*7,width,line_height,next_skill.name)
  497.     # write skill mp cost
  498.     change_color(mp_cost_color)
  499.     contents.font.size = 18
  500.     contents.draw_text(200,2+line_height*7,width,line_height,next_skill.mp_cost.to_s + " MP")
  501.     change_color(normal_color)
  502.     contents.font.size = Font.default_size
  503.     # write skill description
  504.     contents.draw_text(0,line_height*8,width,line_height,next_skill.description)
  505.  
  506. end
  507.  
  508.   #--------------------------------------------------------------------------
  509.   # * Displays an horizontal line
  510.   #--------------------------------------------------------------------------
  511.   def draw_horz_line(y)
  512.     line_y = y + line_height / 2 - 1
  513.     color = normal_color
  514.     color.alpha = 50
  515.     contents.fill_rect(0, line_y, contents_width, 2, color)
  516.   end
  517.  
  518.   #--------------------------------------------------------------------------
  519.   # * Wait After Output of One Character
  520.   #--------------------------------------------------------------------------
  521.   def wait_for_one_character
  522.   end
  523.    
  524. end # end Window Result
  525.  
  526. #-------------------------------------------------------------------------------
  527. #    Scene Element Combination
  528. #-------------------------------------------------------------------------------
  529. class Scene_ElementCombination < Scene_MenuBase
  530.  
  531.   #--------------------------------------------------------------------------
  532.   # * Initializing
  533.   #--------------------------------------------------------------------------
  534.   def start
  535.     super()
  536.     # Setting up Background
  537.     create_background
  538.  
  539.     check_available_elements()
  540.     # Setting up Help Window
  541.     @help_window = Window_Help.new()
  542.    
  543.     # Setting up Window Combination Categories
  544.     create_windowCombinationCategory()
  545.    
  546.     # Setting up Window Available Elements
  547.     create_windowAvailableElements()
  548.    
  549.     # Setting up Window Results
  550.     create_windowResults()
  551.    
  552.     @current_symbol = nil
  553.     @choice1_made   = false
  554.     @choice2_made   = false
  555.     @choice3_made   = false
  556.     @element_1      = nil
  557.     @element_2      = nil
  558.     @element_3      = nil
  559.    
  560.     # Set the handlers
  561.     set_element_handlers()
  562.    
  563.     (1 ... $data_skills.size).each do |i|
  564.       if $data_skills[i].note.match(FeaR::REGEX)
  565.         # an array to store all skills in database which have the notetag
  566.         (@all_skills_indexes||=[]).push($data_skills[i].id)
  567.       end
  568.     end
  569.    
  570.     # Setting up Window for Yes/No Option
  571.     create_windowYesNoOption()
  572.    
  573.     # Setting up Window for Yes/No Option Text
  574.     create_windowYesNoText()
  575.    
  576.   end
  577.  
  578.   #--------------------------------------------------------------------------
  579.   # * Post-Start Processing
  580.   #--------------------------------------------------------------------------
  581.   def post_start
  582.     super()
  583.   end
  584.   #--------------------------------------------------------------------------
  585.   # * Frame Update
  586.   #--------------------------------------------------------------------------
  587.   def update
  588.     super()
  589.     update_help_window_text()
  590.     update_message_window_text()
  591.   end
  592.   #--------------------------------------------------------------------------
  593.   # * Pre-Termination Processing
  594.   #--------------------------------------------------------------------------
  595.   def pre_terminate
  596.   end
  597.   #--------------------------------------------------------------------------
  598.   # * Termination Processing
  599.   #--------------------------------------------------------------------------
  600.   def terminate
  601.     @category_window.dispose()  unless @category_window.disposed?
  602.     @ae_window.dispose()        unless @ae_window.disposed?
  603.     @result_window.dispose()    unless @result_window.disposed?
  604.     @help_window.dispose()      unless @help_window.disposed?
  605.     @yesNo_window.dispose()     unless @yesNo_window.disposed?
  606.     @yesNoText_window.dispose() unless @yesNoText_window.disposed?
  607.     super()
  608.   end
  609.  
  610.   #--------------------------------------------------------------------------
  611.   # * Create the window for the categories Level Up and Combination
  612.   #--------------------------------------------------------------------------
  613.   def create_windowCombinationCategory()
  614.     @category_window = Window_CombinationCategory.new
  615.     #@category_window.help_window = @help_window
  616.     @category_window.y = @help_window.height
  617.     @category_window.set_handler(:lvlup, method(:deactivate_category_window_1))
  618.     @category_window.set_handler(:combine, method(:deactivate_category_window_2))
  619.     @category_window.set_handler(:cancel, method(:return_scene))
  620.   end
  621.  
  622.   #--------------------------------------------------------------------------
  623.   # * Creates the window to choose yes or no when leveling up/combine elements
  624.   #--------------------------------------------------------------------------
  625.   def create_windowYesNoOption()
  626.     @yesNo_window = Window_YesNoOption.new()
  627.     @yesNo_window.x = Graphics.width * 0.25
  628.     @yesNo_window.y = Graphics.height * 0.5
  629.     @yesNo_window.set_handler(:option_yes, method(:execute_yes))
  630.     @yesNo_window.set_handler(:option_no,  method(:execute_no))
  631.     @yesNo_window.openness = 0
  632.     @yesNo_window.deactivate()
  633.   end
  634.  
  635.   #--------------------------------------------------------------------------
  636.   # * Creates the window that shows the text for level up or combine
  637.   #--------------------------------------------------------------------------
  638.   def create_windowYesNoText()
  639.     x = Graphics.width * 0.25
  640.     height = @yesNo_window.height
  641.     y = Graphics.height * 0.5 - @yesNo_window.height
  642.     @yesNoText_window = Window_YesNoText.new(x, y, Graphics.width*0.5, height)
  643.     @yesNoText_window.draw_text_option()
  644.     @yesNoText_window.openness = 0
  645.   end
  646.    
  647.   #--------------------------------------------------------------------------
  648.   # * Creates the window with the known elements of the actor
  649.   #--------------------------------------------------------------------------
  650.   def create_windowAvailableElements()
  651.     # ae = abbreviation for available elements
  652.     wy = @category_window.height + @help_window.height
  653.     height = Graphics.height - @help_window.height - @category_window.height
  654.     @ae_window = Window_AvailableElements.new(0, wy)
  655.     @ae_window.height = height
  656.     @ae_window.deactivate()
  657.     @ae_window.set_handler(:cancel, method(:activate_category_window))
  658.   end
  659.  
  660.   #--------------------------------------------------------------------------
  661.   # * Creates the window where the results are shown
  662.   #--------------------------------------------------------------------------
  663.   def create_windowResults()
  664.     x = Graphics.width * 0.5
  665.     y = @help_window.height + @category_window.height
  666.     height = Graphics.height - @help_window.height - @category_window.height
  667.     @result_window = Window_Result.new(x, y, x, height)
  668.     @result_window.openness = 255
  669.   end
  670.  
  671.   #--------------------------------------------------------------------------
  672.   # * This method turns the lvl up switch true
  673.   # * and activates the available elements window
  674.   #--------------------------------------------------------------------------
  675.   def deactivate_category_window_1()
  676.     $Lvlup_switch = true
  677.     $Combine_switch = false
  678.     @category_window.deactivate()
  679.     @ae_window.clear_command_list()
  680.     check_available_elements()
  681.     @ae_window.make_command_list()
  682.     @ae_window.refresh()
  683.     @ae_window.activate()
  684.   end
  685.  
  686.   #--------------------------------------------------------------------------
  687.   # * This method turns the combine switch true
  688.   # * and activates the available elements window
  689.   #--------------------------------------------------------------------------
  690.   def deactivate_category_window_2()
  691.     $Combine_switch = true
  692.     $Lvlup_switch   = false
  693.     @category_window.deactivate()
  694.     @ae_window.clear_command_list()
  695.     check_available_elements()
  696.     @ae_window.make_command_list()
  697.     @ae_window.refresh()
  698.     @ae_window.activate()
  699.   end
  700.  
  701.   #--------------------------------------------------------------------------
  702.   # * This method deactivates the available elements window and set
  703.   # * the variables to zero or nil
  704.   #--------------------------------------------------------------------------
  705.   def activate_category_window()
  706.     $Lvlup_switch     = false
  707.     $Combine_switch   = false
  708.     @element_1        = nil
  709.     @element_2        = nil
  710.     @element_3        = nil
  711.     @choice1_made     = false
  712.     @choice2_made     = false
  713.     @choice3_made     = false
  714.     @chosen_element_1 = nil
  715.     @chosen_element_2 = nil
  716.     @chosen_element_3 = nil
  717.     @new_element      = nil
  718.     @category_window.activate()
  719.     @ae_window.deactivate()
  720.     @result_window.contents.clear()
  721.   end
  722.  
  723.   #--------------------------------------------------------------------------
  724.   # * This method updates the help window text
  725.   #--------------------------------------------------------------------------
  726.   def update_help_window_text()
  727.     # if the category window is active
  728.     if @category_window.active
  729.       @help_window.set_text(FeaR::HelpWindowText1 + "\n" + FeaR::HelpWindowText2)
  730.     # if available elements is active
  731.     elsif @ae_window.active
  732.       if @current_symbol != @ae_window.current_symbol
  733.         @current_symbol = @ae_window.current_symbol
  734.         @help_window.set_text(FeaR::Elements[@current_symbol.to_s][:info_text])
  735.       end
  736.     end
  737.   end
  738.  
  739.   #--------------------------------------------------------------------------
  740.   # * This method updates the result window texts
  741.   #--------------------------------------------------------------------------
  742.   def update_message_window_text()
  743.     if @ae_window.active  # only if the available elements window is active
  744.       if $Lvlup_switch == true  # if level up is choosen
  745.         @current_symbol = @ae_window.current_symbol # set current symbol
  746.         # the skill id of the element from actors skill
  747.         actor_skill_id = FeaR::Elements[@current_symbol.to_s][:current_skill_id]
  748.         # element id
  749.         element_id = FeaR::Elements[@current_symbol.to_s][:element_index]
  750.         @all_skills_indexes.each do |skill_id| # iterate over all skills with notetags
  751.           # if one skill have a different id as the known skill from actor AND
  752.           # if the element id's are the same, the skills are from same element
  753.           # and different level
  754.           if skill_id != actor_skill_id && $data_skills[skill_id].damage.element_id == element_id
  755.             # store current level of skill
  756.             current_level = FeaR::Elements[@current_symbol.to_s][:current_level]
  757.             note_tags = []
  758.             text = $data_skills[skill_id].note.match(FeaR::REGEX).to_s
  759.             text.to_s.scan(/\d+/).each {|i| note_tags.push(i.to_i)}
  760.             # if current level + 1 is equal to skills level
  761.             # skill is the next level for element
  762.             # (current level + 1 => 1 + 1 == 2 => next level
  763.             if current_level+1 == note_tags[0]
  764.               # draw in result window the current skill and what the next skill is
  765.               @result_window.draw_skill_lvl_up(actor_skill_id, skill_id)
  766.               break
  767.             # if the current level is equal to the max level, show nothing
  768.             elsif current_level == FeaR::Elements[@current_symbol.to_s][:max_level]
  769.               @result_window.contents.clear()
  770.               break
  771.             end
  772.           end
  773.         end
  774.       elsif $Combine_switch == true # if combine is choosen
  775.         @current_symbol = @ae_window.current_symbol
  776.         @result_window.draw_skill_combine(@chosen_element_1, @chosen_element_2, @chosen_element_3, @new_element)
  777.       end
  778.     end
  779.     if $Combine_switch == true # this repeats here for reasons...
  780.       @current_symbol = @ae_window.current_symbol
  781.       @result_window.draw_skill_combine(@chosen_element_1, @chosen_element_2, @chosen_element_3, @new_element)
  782.     end
  783.   end
  784.  
  785.   #--------------------------------------------------------------------------
  786.   # * This method set the handlers for all the elements
  787.   #--------------------------------------------------------------------------
  788.   def set_element_handlers()
  789.     FeaR::Elements.each_key do |key_name|
  790.       @ae_window.set_handler(key_name.to_sym, method(:execute_command))
  791.     end
  792.   end
  793.          
  794.   #--------------------------------------------------------------------------
  795.   # * This method checks what skills and so what elements the actor knows
  796.   # * and writes the skill id and levels and frequency into the hash
  797.   #--------------------------------------------------------------------------
  798.   def check_available_elements()
  799.     $game_actors[1].skills.each do |skill|      # iterate over skills from actor 1
  800.       if skill.note.match(FeaR::REGEX)          # check if current skill have notetag combination_level
  801.         combination_levels = []                 # array to store notetags values (level, usage)
  802.         notetag = skill.note.match(FeaR::REGEX) # store regular expression match
  803.         text = notetag.to_s                     # store match as text
  804.         # scan over text to store values in array
  805.         text.to_s.scan(/\d+/).each {|i| combination_levels.push(i.to_i)}
  806.         FeaR::Elements.each_key do |key_name|
  807.           # if element index is equal to skill element index,
  808.           # the character knows that element
  809.           if FeaR::Elements[key_name][:element_index] == skill.damage.element_id
  810.             FeaR::Elements[key_name][:current_level]    = combination_levels[0]
  811.             FeaR::Elements[key_name][:max_level]        = combination_levels[1]
  812.             FeaR::Elements[key_name][:frequency]        = combination_levels[2]
  813.             FeaR::Elements[key_name][:current_skill_id] = skill.id
  814.             if FeaR::Elements[key_name][:usage_variable] != 0
  815.               FeaR::Elements[key_name][:element_point] = 0
  816.               variable_value = $game_variables[FeaR::Elements[key_name][:usage_variable]]
  817.               # if the value in variable is higher or equal to elements frequency
  818.               # add one element point so the element can be used
  819.               if variable_value >= FeaR::Elements[key_name][:frequency]
  820.                 if $Lvlup_switch == true && FeaR::Elements[key_name][:current_level] != FeaR::Elements[key_name][:max_level]
  821.                   FeaR::Elements[key_name][:element_point] = 1
  822.                 end
  823.                 if $Combine_switch == true
  824.                   FeaR::Elements[key_name][:element_point] = 1
  825.                 end
  826.               end
  827.             end
  828.             # if the switch id is not zero, turn switch to true
  829.             # because actor knows a skill with this element
  830.             if FeaR::Elements[key_name][:enable_switch] != 0
  831.               $game_switches[FeaR::Elements[key_name][:enable_switch]] = true
  832.             end        
  833.           end # if
  834.         end # Elements iteration
  835.       end # if regex
  836.     end # skills iteration
  837.   end # list available elements
  838.  
  839.   #--------------------------------------------------------------------------
  840.   # * This method execute the level up and combine process
  841.   #--------------------------------------------------------------------------
  842.   def execute_command()  
  843.     # if level up is selected, process element level up
  844.     if $Lvlup_switch == true
  845.       element_id        = FeaR::Elements[@current_symbol.to_s][:element_index]
  846.       @actor_skill_id    = FeaR::Elements[@current_symbol.to_s][:current_skill_id]
  847.       @all_skills_indexes.each do |skill_id|  # iterate over all skills with notetag
  848.         # check if skill id from array is different as actors skill id AND
  849.         # check if the element ids are the same
  850.         if skill_id != @actor_skill_id && $data_skills[skill_id].damage.element_id == element_id
  851.           current_level = FeaR::Elements[@current_symbol.to_s][:current_level]
  852.           note_tags = []  # get the notetag from the skill
  853.           text = $data_skills[skill_id].note.match(FeaR::REGEX).to_s
  854.           text.to_s.scan(/\d+/).each {|i| note_tags.push(i.to_i)}
  855.           # check if the skill from array is 1 level above current skill level
  856.           # (actors skill level = 1, next skill level = 2, 1+1 == 2, MATCH!
  857.           if current_level+1 == note_tags[0]
  858.             @next_skill_id = skill_id
  859.             # open yes no window to ask player if he wants to level up
  860.             activate_yes_no_window()
  861.             break
  862.           end
  863.         end
  864.       end
  865.      
  866.     # if combine is selected, process element combination
  867.     elsif $Combine_switch == true  
  868.       if @choice1_made == false # select first element
  869.         @element_1 = FeaR::Elements[@current_symbol.to_s][:element_index]
  870.         @chosen_element_1 = @current_symbol
  871.         @choice1_made = true
  872.         @ae_window.activate()
  873.       elsif @choice1_made == true && @choice2_made == false # select second element
  874.         @element_2 = FeaR::Elements[@current_symbol.to_s][:element_index]
  875.         @chosen_element_2 = @current_symbol
  876.         @choice2_made = true
  877.         @ae_window.activate()
  878.       elsif @choice1_made == true && @choice2_made == true && @choice3_made == false # select third element (optional)
  879.         @element_3 = FeaR::Elements[@current_symbol.to_s][:element_index]
  880.         @chosen_element_3 = @current_symbol
  881.         @choice3_made = true
  882.         @ae_window.activate()
  883.       end
  884.       check_chosen_elements()
  885.     end
  886.   end
  887.  
  888.   #--------------------------------------------------------------------------
  889.   # * This method checks if the selected elements can combined together
  890.   #--------------------------------------------------------------------------
  891.   def check_chosen_elements()
  892.     @new_element = nil
  893.     # when elements are selected, check if they can combined together
  894.     if @element_1 != nil && @element_2 != nil && @element_3 == nil
  895.       FeaR::Elements.each_key do |key_name| # iterate over elements
  896.         # and check, if the selected elements can create a new one
  897.         if FeaR::Elements[key_name][:consists_of_1] == @element_1 && FeaR::Elements[key_name][:consists_of_2] == @element_2 && FeaR::Elements[key_name][:consists_of_3] == 0
  898.           # MATCH
  899.           @new_element = key_name.to_sym
  900.           # open yes no options for player
  901.           activate_yes_no_window()
  902.           break
  903.         end
  904.       end
  905.     end
  906.     # this is for three elements
  907.     if @element_1 != nil && @element_2 != nil && @element_3 != nil
  908.       FeaR::Elements.each_key do |key_name|
  909.         if FeaR::Elements[key_name][:consists_of_1] == @element_1 && FeaR::Elements[key_name][:consists_of_2] == @element_2 && FeaR::Elements[key_name][:consists_of_3] == @element_3
  910.           @new_element = key_name.to_sym
  911.           activate_yes_no_window()
  912.           break
  913.         elsif
  914.           @ae_window.activate()
  915.         end
  916.       end
  917.     end
  918.   end
  919.  
  920.   #--------------------------------------------------------------------------
  921.   # * This method performs if the player select yes
  922.   #--------------------------------------------------------------------------
  923.   def execute_yes()
  924.     if $Lvlup_switch == true
  925.       $game_actors[1].forget_skill(@actor_skill_id)  # forget lvl n skill
  926.       $game_actors[1].learn_skill(@next_skill_id)    # learn lvl n+1 skill
  927.       # substract the frequency for lvl n skill from variable
  928.       $game_variables[FeaR::Elements[@current_symbol.to_s][:usage_variable]] -= FeaR::Elements[@current_symbol.to_s][:frequency]
  929.       # substract 1 element point
  930.       FeaR::Elements[@current_symbol.to_s][:element_point] = 0
  931.       refresh_available_elements_window()
  932.     elsif $Combine_switch == true
  933.       if @choice1_made == true && @choice2_made == true && @choice3_made == false
  934.         @all_skills_indexes.each do |skill_id|
  935.           if $data_skills[skill_id].damage.element_id == FeaR::Elements[@new_element.to_s][:element_index]
  936.             note_tags = []  # get the notetag from the skill
  937.             text = $data_skills[skill_id].note.match(FeaR::REGEX).to_s
  938.             text.to_s.scan(/\d+/).each {|i| note_tags.push(i.to_i)}
  939.             if note_tags[0] == 1 # if the new element skill is level 1
  940.               $game_actors[1].learn_skill(skill_id)
  941.               $game_variables[FeaR::Elements[@chosen_element_1.to_s][:usage_variable]] -= FeaR::Elements[@chosen_element_1.to_s][:frequency]
  942.               $game_variables[FeaR::Elements[@chosen_element_2.to_s][:usage_variable]] -= FeaR::Elements[@chosen_element_2.to_s][:frequency]
  943.               FeaR::Elements[@chosen_element_1.to_s][:element_point] = 0
  944.               FeaR::Elements[@chosen_element_2.to_s][:element_point] = 0
  945.               @choice1_made     = false
  946.               @choice2_made     = false
  947.               @element_1        = nil
  948.               @element_2        = nil
  949.               @chosen_element_1 = nil
  950.               @chosen_element_2 = nil
  951.               refresh_available_elements_window()
  952.               break
  953.             end
  954.           end
  955.         end
  956.       end
  957.       if @choice1_made == true && @choice2_made == true && @choice3_made == true
  958.         @all_skills_indexes.each do |skill_id|
  959.           if $data_skills[skill_id].damage.element_id == FeaR::Elements[@new_element.to_s][:element_index]
  960.             note_tags = []  # get the notetag from the skill
  961.             text = $data_skills[skill_id].note.match(FeaR::REGEX).to_s
  962.             text.to_s.scan(/\d+/).each {|i| note_tags.push(i.to_i)}
  963.             if note_tags[0] == 1 # if the new element skill is level 1
  964.               $game_actors[1].learn_skill(skill_id)
  965.               $game_variables[FeaR::Elements[@chosen_element_1.to_s][:usage_variable]] -= FeaR::Elements[@chosen_element_1.to_s][:frequency]
  966.               $game_variables[FeaR::Elements[@chosen_element_2.to_s][:usage_variable]] -= FeaR::Elements[@chosen_element_2.to_s][:frequency]
  967.               $game_variables[FeaR::Elements[@chosen_element_3.to_s][:usage_variable]] -= FeaR::Elements[@chosen_element_3.to_s][:frequency]
  968.               FeaR::Elements[@chosen_element_1.to_s][:element_point] = 0
  969.               FeaR::Elements[@chosen_element_2.to_s][:element_point] = 0
  970.               FeaR::Elements[@chosen_element_3.to_s][:element_point] = 0
  971.               @choice1_made     = false
  972.               @choice2_made     = false
  973.               @choice3_made     = false
  974.               @element_1        = nil
  975.               @element_2        = nil
  976.               @element_3        = nil
  977.               @chosen_element_1 = nil
  978.               @chosen_element_2 = nil
  979.               @chosen_element_3 = nil
  980.               refresh_available_elements_window()
  981.               break
  982.             end
  983.           end
  984.         end
  985.       end
  986.     end
  987.       @yesNo_window.openness = 0
  988.       @yesNo_window.deactivate()
  989.       @yesNoText_window.openness = 0
  990.       @new_element      = nil
  991.   end
  992.    
  993.   #--------------------------------------------------------------------------
  994.   # * This method performes if the player select no
  995.   #--------------------------------------------------------------------------
  996.   def execute_no()
  997.     if $Lvlup_switch == true
  998.       deactivate_yes_no_window()
  999.     elsif $Combine_switch == true
  1000.       if @choice1_made == true && @choice2_made == true && @choice3_made == true
  1001.         deactivate_yes_no_window()
  1002.         @element_1        = nil
  1003.         @element_2        = nil
  1004.         @element_3        = nil
  1005.         @choice1_made     = false
  1006.         @choice2_made     = false
  1007.         @choice3_made     = false
  1008.         @chosen_element_1 = nil
  1009.         @chosen_element_2 = nil
  1010.         @chosen_element_3 = nil
  1011.         @new_element      = nil
  1012.       elsif
  1013.         deactivate_yes_no_window()
  1014.       end
  1015.     end
  1016.   end
  1017.  
  1018.   #--------------------------------------------------------------------------
  1019.   # * This method deactivates the yes/no window and activates the available
  1020.   # * elements window
  1021.   #--------------------------------------------------------------------------
  1022.   def deactivate_yes_no_window()
  1023.     @yesNo_window.openness = 0
  1024.     @yesNo_window.deactivate()
  1025.     @yesNoText_window.openness = 0
  1026.     @ae_window.activate()
  1027.   end
  1028.  
  1029.   #--------------------------------------------------------------------------
  1030.   # * This method activates the yes/no window and deactivates the available
  1031.   # * elements window
  1032.   #--------------------------------------------------------------------------
  1033.   def activate_yes_no_window()
  1034.     @yesNo_window.openness = 255
  1035.     @yesNoText_window.openness = 255
  1036.     @yesNoText_window.draw_text_option()
  1037.     @yesNo_window.activate()
  1038.     @ae_window.deactivate()
  1039.   end
  1040.  
  1041.   #--------------------------------------------------------------------------
  1042.   # * This method activates the available elements window and refreshes its text
  1043.   #--------------------------------------------------------------------------
  1044.   def refresh_available_elements_window()
  1045.     @ae_window.clear_command_list()
  1046.     check_available_elements()
  1047.     @ae_window.make_command_list()
  1048.     @ae_window.refresh()
  1049.     @ae_window.activate()
  1050.   end
  1051.  
  1052. end # of Scene Element Combination
  1053.  
  1054. ## Menu inclusion, with Yanfly's Ace Menu Engine
  1055. if $imported["YEA-AceMenuEngine"]
  1056.  
  1057.   #==========================================================================
  1058.   #  * Scene_Menu
  1059.   #==========================================================================
  1060.    
  1061.   class Scene_Menu < Scene_MenuBase
  1062.     #--------------------------------------------------------------------------
  1063.     # * Switch to the synthesis scene
  1064.     #--------------------------------------------------------------------------
  1065.     def command_elemcomb()
  1066.       SceneManager.call(Scene_ElementCombination)
  1067.     end
  1068.   end
  1069.  
  1070. else ## End of Yanfly's Menu inclusion
  1071.  
  1072.   #==============================================================================
  1073.   # ** Window_MenuCommand
  1074.   #------------------------------------------------------------------------------
  1075.   #  This command window appears on the menu screen.
  1076.   #==============================================================================
  1077.  
  1078.   class Window_MenuCommand < Window_Command
  1079.     #--------------------------------------------------------------------------
  1080.     # * Add Formation to Command List
  1081.     #--------------------------------------------------------------------------
  1082.     alias fear_elementcombination_windowmenucommand_addformationcommand_fg4r add_formation_command
  1083.     #--------------------------------------------------------------------------
  1084.     def add_formation_command
  1085.       fear_elementcombination_windowmenucommand_addformationcommand_fg4r()
  1086.       add_command(FeaR::MenuCommandText, :element_combination)
  1087.     end
  1088.   end
  1089.  
  1090.   #==============================================================================
  1091.   # ** Scene_Menu
  1092.   #------------------------------------------------------------------------------
  1093.   #  This class performs the menu screen processing.
  1094.   #==============================================================================
  1095.  
  1096.   class Scene_Menu < Scene_MenuBase
  1097.     #--------------------------------------------------------------------------
  1098.     # * Create Command Window
  1099.     #--------------------------------------------------------------------------
  1100.     alias fear_elementcombination_scenemenu_createcommandwindow_fg4r create_command_window
  1101.     #--------------------------------------------------------------------------
  1102.     def create_command_window()
  1103.       fear_elementcombination_scenemenu_createcommandwindow_fg4r()    
  1104.       @command_window.set_handler(:element_combination,    method(:command_elemcomb))
  1105.     end
  1106.    
  1107.     #--------------------------------------------------------------------------
  1108.     # * Command Element Combination
  1109.     #--------------------------------------------------------------------------
  1110.     def command_elemcomb()
  1111.       SceneManager.call(Scene_ElementCombination)
  1112.     end
  1113.      
  1114.   end # Scene Menu
  1115.  
  1116. end
Add Comment
Please, Sign In to add comment