khanhdu

XaiL System - Core

Oct 4th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 17.39 KB | None | 0 0
  1. #==============================================================================
  2. #   XaiL System - Core
  3. #   Author: Nicke
  4. #   Created: 07/01/2012
  5. #   Edited: 08/10/2013
  6. #   Version: 2.1f
  7. #==============================================================================
  8. # Instructions
  9. # -----------------------------------------------------------------------------
  10. # To install this script, open up your script editor and copy/paste this script
  11. # to an open slot below ? Materials but above ? Main. Remember to save.
  12. #
  13. # Core script for XaiL System.
  14. # Caution! This needs to be located before any other XS scripts.
  15. #
  16. # *** Only for RPG Maker VX Ace. ***
  17. #==============================================================================
  18. ($imported ||= {})["XAIL-XS-CORE"] = true
  19.  
  20. module Colors
  21.   #--------------------------------------------------------------------------#
  22.   # * Colors
  23.   #--------------------------------------------------------------------------#
  24.   White = Color.new(255,255,255)
  25.   LightRed = Color.new(255,150,150)
  26.   LightGreen = Color.new(150,255,150)
  27.   LightBlue = Color.new(150,150,255)
  28.   DarkYellow = Color.new(225,225,20)
  29.   Alpha = Color.new(0,0,0,128)
  30.   AlphaMenu = 100
  31. end
  32. module XAIL
  33.   module CORE
  34.   #--------------------------------------------------------------------------#
  35.   # * Settings
  36.   #--------------------------------------------------------------------------#
  37.   # Graphics.resize_screen(width, height )
  38.  
  39.   # FONT DEFAULTS:
  40.   Font.default_name = ["UTM NguyenHa 02"]
  41.   Font.default_size = 20
  42.   Font.default_bold = false
  43.   Font.default_italic = false
  44.   Font.default_shadow = true
  45.   Font.default_outline = true
  46.   Font.default_color = Colors::White
  47.   Font.default_out_color = Colors::Alpha
  48.  
  49.   # USE_TONE = true/false:
  50.   # Window tone for all windows ingame. Default: true.
  51.   USE_TONE = false
  52.  
  53.   # SAVE
  54.   SAVE_MAX = 20       # Default 16.
  55.   SAVE_FILE_VIS = 4   # Default 4.
  56.  
  57.   # JAPANESE = true/false
  58.   JAPANESE = false
  59.  
  60.   end
  61. end
  62. # *** Don't edit below unless you know what you are doing. ***
  63. #==============================================================================#
  64. # ** Game_System
  65. #==============================================================================#
  66. class Game_System
  67.  
  68.   # // Method to determine japanese game.
  69.   def japanese? ; return XAIL::CORE::JAPANESE ; end
  70.  
  71. end
  72. #==============================================================================#
  73. # ** String
  74. #==============================================================================#
  75. class String
  76.  
  77.   def to_class(parent = Kernel)
  78.     # // Method to convert string to class.
  79.     chain = self.split "::"
  80.     klass = parent.const_get chain.shift
  81.     return chain.size < 1 ? (klass.is_a?(Class) ? klass : nil) : chain.join("::").to_class(klass)
  82.     rescue
  83.     nil
  84.   end
  85.  
  86.   def cap_words
  87.     # // Method to capitalize every word.
  88.     self.split(' ').map {|w| w.capitalize }.join(' ')
  89.   end
  90.  
  91.   def slice_char(char)
  92.     # // Method to slice char.
  93.     self.split(char).map {|w| w.sub(char, " ") }.join(" ")
  94.   end
  95.  
  96. end
  97. #==============================================================================#
  98. # ** Vocab
  99. #==============================================================================#
  100. class << Vocab
  101.  
  102.   def xparam(id)
  103.     # // Method to return xparam name.
  104.     case id
  105.     when 0 ; "Hit Chance"
  106.     when 1 ; "Evasion"
  107.     when 2 ; "Critical Chance"
  108.     when 3 ; "Critical Evasion"
  109.     when 4 ; "Magic Evasion"
  110.     when 5 ; "Magic Reflection"
  111.     when 6 ; "Counter Attack"
  112.     when 7 ; "HP Regeneration"
  113.     when 8 ; "MP Regeneration"
  114.     when 9 ; "TP Regeneration"
  115.     end
  116.   end
  117.  
  118. end
  119. #==============================================================================
  120. # ** Sound
  121. #==============================================================================
  122. class << Sound
  123.  
  124.   def play(name, volume, pitch, type = :se)
  125.     # // Method to play a sound. If specified name isn't valid throw an error.
  126.     case type
  127.     when :se   ; RPG::SE.new(name, volume, pitch).play rescue valid?(name)
  128.     when :me   ; RPG::ME.new(name, volume, pitch).play rescue valid?(name)
  129.     when :bgm  ; RPG::BGM.new(name, volume, pitch).play rescue valid?(name)
  130.     when :bgs  ; RPG::BGS.new(name, volume, pitch).play rescue valid?(name)
  131.     end
  132.   end
  133.  
  134.   def valid?(name)
  135.     # // Method to raise error if specified sound name is invalid.
  136.     msgbox("Error. Unable to find sound file: " + name)
  137.     exit
  138.   end
  139.  
  140. end
  141. #==============================================================================
  142. # ** DataManager
  143. #==============================================================================
  144. class << DataManager
  145.  
  146.   def savefile_max
  147.     # // Method override, save file max.
  148.     return XAIL::CORE::SAVE_MAX
  149.   end
  150.  
  151. end
  152. #==============================================================================
  153. # ** SceneManager
  154. #==============================================================================
  155. class << SceneManager
  156.  
  157.   def call_ext(scene_class, args = nil)
  158.     # // Method to call a scene with arguments.
  159.     @stack.push(@scene)
  160.     @scene = scene_class.new(args)
  161.   end
  162.  
  163. end
  164. #==============================================================================
  165. # ** Scene_File
  166. #==============================================================================
  167. class Scene_File < Scene_MenuBase
  168.  
  169.   def visible_max
  170.     # // Method override, visible_max for save files.
  171.     return XAIL::CORE::SAVE_FILE_VIS
  172.   end
  173.  
  174. end
  175. #==============================================================================
  176. # ** Window_Base
  177. #------------------------------------------------------------------------------
  178. # Importing font fix that will remove weird characters.
  179. # Adding new methods such as new gauge, actor param, font text, icon drawing,
  180. # big icon drawing and a line with a shadow.
  181. #==============================================================================
  182. class Window_Base < Window
  183.  
  184.   # // Importing Custom font fix. (Credit Lone Wolf).
  185.   alias :process_normal_character_vxa :process_normal_character
  186.   def process_normal_character(c, pos)
  187.     return unless c >= ' '
  188.     process_normal_character_vxa(c, pos)
  189.   end unless method_defined? :process_normal_character
  190.  
  191.   def draw_text_ex_no_reset(x, y, text)
  192.     # // Method to draw ex text without resetting the font.
  193.     text = convert_escape_characters(text)
  194.     pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  195.     process_character(text.slice!(0, 1), text, pos) until text.empty?
  196.   end
  197.  
  198.   alias xail_core_winbase_upt_tone update_tone
  199.   def update_tone(*args, &block)
  200.     # // Method to change tone of the window.
  201.     return unless XAIL::CORE::USE_TONE
  202.     xail_core_winbase_upt_tone(*args, &block)
  203.   end
  204.  
  205.   def draw_gauge_ex(x, y, width, height, rate, color1, color2)
  206.     # // Method to draw a gauge.
  207.     fill_w = (width * rate).to_i
  208.     gauge_y = y + line_height - 8
  209.     contents.fill_rect(x, gauge_y, width + 1, height + 1, Color.new(255,255,255,64))
  210.     contents.fill_rect(x, gauge_y, width, height, Color.new(0,0,0,100))
  211.     contents.gradient_fill_rect(x, gauge_y, fill_w, height, color1, color2)
  212.   end
  213.  
  214.   def draw_actor_param_gauge(actor, x, y, width, param_id, font, size, bar_color1, bar_color2, txt_color1, txt_color2)
  215.     # // Method to draw actor parameters with a gauge.
  216.     case param_id
  217.     when 2 ; param_rate = actor.param(2) / actor.param_max(2).to_f
  218.     when 3 ; param_rate = actor.param(3) / actor.param_max(3).to_f
  219.     when 4 ; param_rate = actor.param(4) / actor.param_max(4).to_f
  220.     when 5 ; param_rate = actor.param(5) / actor.param_max(5).to_f
  221.     when 6 ; param_rate = actor.param(6) / actor.param_max(6).to_f
  222.     when 7 ; param_rate = actor.param(7) / actor.param_max(7).to_f
  223.     end
  224.     contents.font.name = font
  225.     contents.font.size = size
  226.     contents.font.bold = true
  227.     contents.font.shadow = false
  228.     draw_gauge_ex(x, y - 14, width, 20, param_rate, bar_color1, bar_color2)
  229.     contents.font.color = txt_color1
  230.     draw_text(x + 10, y, 120, line_height, Vocab::param(param_id))
  231.     contents.font.color = txt_color2
  232.     draw_text(x + width - 38, y, 36, line_height, actor.param(param_id), 2)
  233.     reset_font_settings
  234.   end
  235.  
  236.   def draw_actor_xparam_gauge(actor, x, y, width, xparam_id, font, size, bar_color1, bar_color2, txt_color1, txt_color2)
  237.     # // Method to draw actor xparameters with a gauge.
  238.     case xparam_id
  239.     when 0
  240.       xparam_rate = actor.xparam(0) / 100.to_f
  241.       xparam_name = Vocab.xparam(0)
  242.     when 1
  243.       xparam_rate = actor.xparam(1) / 100.to_f
  244.       xparam_name = Vocab.xparam(1)
  245.     when 2
  246.       xparam_rate = actor.xparam(2) / 100.to_f
  247.       xparam_name = Vocab.xparam(2)
  248.     when 3
  249.       xparam_rate = actor.xparam(3) / 100.to_f
  250.       xparam_name = Vocab.xparam(3)
  251.     when 4
  252.       xparam_rate = actor.xparam(4) / 100.to_f
  253.       xparam_name = Vocab.xparam(4)
  254.     when 5
  255.       xparam_rate = actor.xparam(5) / 100.to_f
  256.       xparam_name = Vocab.xparam(5)
  257.     when 6
  258.       xparam_rate = actor.xparam(6) / 100.to_f
  259.       xparam_name = Vocab.xparam(6)
  260.     when 7
  261.       xparam_rate = actor.xparam(7) / 100.to_f
  262.       xparam_name = Vocab.xparam(7)
  263.     when 8
  264.       xparam_rate = actor.xparam(8) / 100.to_f
  265.       xparam_name = Vocab.xparam(8)
  266.     when 9
  267.       xparam_rate = actor.xparam(9) / 100.to_f
  268.       xparam_name = Vocab.xparam(9)
  269.     end
  270.     contents.font.name = font
  271.     contents.font.size = size
  272.     contents.font.bold = true
  273.     contents.font.shadow = false
  274.     draw_gauge_ex(x, y - 14, width, 20, xparam_rate, bar_color1, bar_color2)
  275.     contents.font.color = txt_color1
  276.     draw_text(x + 10, y, 120, line_height, xparam_name)
  277.     contents.font.color = txt_color2
  278.     draw_text(x + width - 38, y, 36, line_height, "#{actor.xparam(xparam_id)}%", 2)
  279.     reset_font_settings
  280.   end
  281.  
  282.   def draw_line_ex(x, y, color, shadow)
  283.     # // Method to draw a horizontal line with a shadow.
  284.     line_y = y + line_height / 2 - 1
  285.     contents.fill_rect(x, line_y, contents_width, 2, color)
  286.     line_y += 1
  287.     contents.fill_rect(x, line_y, contents_width, 2, shadow)
  288.   end
  289.  
  290.   def draw_box(x, y, width, height, color, shadow)
  291.     # // Method to draw a box with shadow.
  292.     contents.fill_rect(x, y, width, height, color)
  293.     x += 1
  294.     y += 1
  295.     contents.fill_rect(x, y, width, height, shadow)
  296.   end
  297.  
  298.   def draw_vertical_line_ex(x, y, color, shadow)
  299.     # // Method to draw a vertical line with a shadow.
  300.     line_x = x + line_height / 2 - 1
  301.     contents.fill_rect(line_x, y, 2, contents_height, color)
  302.     line_x += 1
  303.     contents.fill_rect(line_x, y, 2, contents_height, shadow)
  304.   end
  305.  
  306.   def draw_icons(icons, alignment, x = 0, y = 0, offset_icon = [])
  307.     # // Method to draw icons in a horizonal or vertical alignment.
  308.     icons.each {|icon|
  309.       next if icon.nil?
  310.       # // If included in offset do extra spacing.
  311.       offset_icon.each {|offset|
  312.         if icon == offset
  313.           y += line_height * 1 if alignment == :vertical
  314.           x += line_height * 1 if alignment == :horizontal
  315.         end
  316.       }
  317.       draw_icon(icon.nil? ? nil : icon, x.nil? ? 0 : x, y.nil? ? 0 : y) rescue nil
  318.       y += line_height if alignment == :vertical
  319.       x += line_height if alignment == :horizontal
  320.     }
  321.   end
  322.  
  323.   def draw_big_icon(icon, x, y, width, height, opacity = 255)
  324.     # // Method to draw a big icon.
  325.     bitmap = Cache.system("Iconset")
  326.     rect = Rect.new(icon % 16 * 24, icon / 16 * 24, 24, 24)
  327.     rect2 = Rect.new(x, y, width, height)
  328.     contents.stretch_blt(rect2, bitmap, rect, opacity)
  329.   end
  330.  
  331.   def draw_font_text(text, x, y, width, alignment, font, size, color, bold = true, shadow = true)
  332.     # // Method to draw font text.
  333.     contents.font.name = font
  334.     contents.font.size = size
  335.     contents.font.color = color
  336.     contents.font.bold = bold
  337.     contents.font.shadow = shadow
  338.     contents.font.out_color = Color.new(0,0,0,255)
  339.     draw_text(x, y, width, calc_line_height(text), text, alignment)
  340.     reset_font_settings
  341.   end
  342.  
  343.   def draw_font_text_ex(text, x, y, font, size, color, bold = true, shadow = true)
  344.     # // Method to draw font text ex.
  345.     contents.font.name = font
  346.     contents.font.size = size
  347.     contents.font.color = color
  348.     contents.font.bold = bold
  349.     contents.font.shadow = shadow
  350.     contents.font.out_color = Color.new(0,0,0,255)
  351.     text = convert_escape_characters(text)
  352.     pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  353.     process_character(text.slice!(0, 1), text, pos) until text.empty?
  354.     reset_font_settings
  355.   end
  356.  
  357. end
  358. #==============================================================================#
  359. # ** Window_Selectable
  360. #------------------------------------------------------------------------------
  361. #  Adding support for pageleft and pageright for window selectable.
  362. #==============================================================================#
  363. class Window_Selectable < Window_Base
  364.  
  365.   def cursor_pageright ; end
  366.   def cursor_pageleft ; end
  367.  
  368.   alias xail_core_winselect_process_cursor_move process_cursor_move
  369.   def process_cursor_move(*args, &block)
  370.     # // Method to process cursor movement.
  371.     xail_core_winselect_process_cursor_move(*args, &block)
  372.     cursor_pageright if !handle?(:pageright) && Input.trigger?(:RIGHT)
  373.     cursor_pageright if !handle?(:pageleft) && Input.trigger?(:LEFT)
  374.   end
  375.  
  376.   alias xail_core_winselect_process_handling process_handling
  377.   def process_handling(*args, &block)
  378.     # // Method to process handling.
  379.     xail_core_winselect_process_handling(*args, &block)
  380.     return process_pageright if handle?(:pageright) && Input.trigger?(:RIGHT)
  381.     return process_pageleft if handle?(:pageleft) && Input.trigger?(:LEFT)
  382.   end
  383.    
  384.   def process_pageright
  385.     # // Method to process page right.
  386.     Sound.play_cursor
  387.     Input.update
  388.     deactivate
  389.     call_handler(:pageright)
  390.   end
  391.  
  392.   def process_pageleft
  393.     # // Method to process page left.
  394.     Sound.play_cursor
  395.     Input.update
  396.     deactivate
  397.     call_handler(:pageleft)
  398.   end
  399.  
  400. end
  401. #==============================================================================#
  402. # ** Window_Icon
  403. #------------------------------------------------------------------------------
  404. #  New Window :: Window_Icon - A window for drawing icon(s).
  405. #==============================================================================#
  406. class Window_Icon < Window_Base
  407.  
  408.   attr_accessor :enabled
  409.   attr_accessor :alignment
  410.  
  411.   def initialize(x, y, window_width, hsize)
  412.     # // Method to initialize the icon window.
  413.     super(0, 0, window_width, window_height(hsize))
  414.     @icons = []
  415.     @index = 0
  416.     @enabled = true
  417.     @alignment = 0
  418.     refresh
  419.   end
  420.  
  421.   def window_height(hsize)
  422.     # // Method to return the height.
  423.     fitting_height(hsize)
  424.   end
  425.  
  426.   def refresh
  427.     # // Method to refresh the icon window.
  428.     contents.clear
  429.   end
  430.  
  431.   def draw_cmd_icons(icons, index)
  432.     # // Draw all of the icons.
  433.     return if !@enabled
  434.     count = 0
  435.     for i in icons
  436.       align = 0
  437.       x = 110
  438.       next if i[index].nil?
  439.       case @alignment
  440.       when 1, 2 ; align = -110
  441.       end
  442.       draw_icon(i[index], x + align, 24 * count)
  443.       count += 1
  444.       break if (24 * count > height - 24)
  445.     end
  446.   end
  447.  
  448. end
  449. #==============================================================================
  450. # ** Game_Party
  451. #------------------------------------------------------------------------------
  452. # Adding check item method to return a item based on the type.
  453. #==============================================================================
  454. class Game_Party < Game_Unit
  455.  
  456.   def check_item?(item, type)
  457.     # // Method to return a item based on the type.
  458.     case type
  459.     when :items    ; $data_items[item]
  460.     when :weapons  ; $data_weapons[item]
  461.     when :armors   ; $data_armors[item]
  462.     when :gold     ; item
  463.     when :exp      ; item
  464.     end
  465.   end
  466.  
  467. end
  468. #==============================================================================
  469. # ** Game_Event
  470. #------------------------------------------------------------------------------
  471. # Adding methods to check for comments on events.
  472. #==============================================================================
  473. class Game_Event < Game_Character
  474.  
  475.   def comment?(comment)
  476.     # // Method to check if comment is included in event.
  477.     unless empty? or @list.nil?
  478.       for evt in @list
  479.         if evt.code == 108 or evt.code == 408
  480.           if evt.parameters[0].include?(comment)
  481.             return true
  482.           end
  483.         end
  484.       end
  485.     end
  486.     return false
  487.   end
  488.  
  489.   def comment_int?(comment)
  490.     # // Method to check for a integer in event.
  491.     unless empty? or @list.nil?
  492.       for evt in @list
  493.         if evt.code == 108 or evt.code == 408
  494.           if evt.parameters[0] =~ /<#{comment}:[ ]?(\d*)>?/
  495.             return ($1.to_i > 0 ? $1.to_i : 0)
  496.           end
  497.         end
  498.       end
  499.     end
  500.   end
  501.  
  502.   def comment_string?(comment)
  503.     # // Method to check for a string in event.
  504.     unless empty? or @list.nil?
  505.       for evt in @list
  506.         if evt.code == 108 or evt.code == 408
  507.           if evt.parameters[0] =~ /<#{comment}:[ ]?(\w*)>?/
  508.             return $1.to_s
  509.           end
  510.         end
  511.       end
  512.     end
  513.   end
  514.  
  515.  
  516. end # END OF FILE
  517.  
  518. #=*==========================================================================*=#
  519. # ** END OF FILE
  520. #=*==========================================================================*=#
Add Comment
Please, Sign In to add comment