Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # ** Method & Class Library
- #------------------------------------------------------------------------------
- # Build Date - 09-17-2006
- # Version 1.0 - 09-17-2006 - Trickster
- # Version 1.1 - 10-03-2006 - Trickster
- # Version 1.2 - 11-01-2006 - Trickster & Selwyn
- # Version 1.3 - 11-10-2006 - Trickster
- # Version 1.4 - 12-01-2006 - Trickster
- # Version 1.5 - 01-01-2007 - Trickster, Yeyinde & Lobosque
- # Version 2.0 - 04-26-2007 - MACL Authors
- # Version 2.1 - 07-22-2007 - MACL Authors
- # Version 2.2 - 11-20-2007 - MACL Authors & SephirothSpawn
- # Version 2.3 - 06-19-2008 - SephirothSpawn & Zeriab
- #==============================================================================
- #==============================================================================
- # ** Method & Class Library Settings
- #------------------------------------------------------------------------------
- # ** General MACL Settings
- #
- # * Pose Names for Charactersets
- # - Poses = ['down', 'left', 'right', 'up']
- # * Number of Frames Per Pose for charactersets
- # - Frames = 4
- # * Real Elements
- # - Real_Elements = 1, 2, 3, 4, 5, 6, 7, 8
- #
- # ** Action Test Setup
- #
- # * Attack Using
- # - Set this to the basic ids that perform an attack effect
- # * Skill Using
- # - Set this to the kinds that perform an skill effect
- # * Defend Using
- # - Set this to the basic ids that perform an defend effect
- # * Item Using
- # - Set this to the kinds that perform a item using effect
- # * Escape Using
- # - Set this to the basic ids that perform an escape effect
- # * Wait Using
- # - Set this to the basic ids that perform a wait effect
- #
- # ** Font
- #
- # * Default Text Underline Setting
- # - Default_Underline = true or false
- # * Default Text Underline Full Setting
- # - Default_Underline_Full = true or false
- # * Default Text Strikethrough Setting
- # - Default_Strikethrough = true or false
- # * Default Text Stikethrough Full Setting
- # - Default_Strikethrough_Full = true or false
- # * Default Text Shadow Setting
- # - Default_Shadow = true or false
- # * Default Text Shadow Color Setting
- # - Default_Shadow_Color = Color.new(0, 0, 0, 100)
- # * Default Text Outline Setting
- # - Default_Outline = true or false
- # * Default Text Outline Color Setting
- # - Default_Outline_Color = Color.new(0, 0, 0, 100)
- # * Default Text Vertical Gradient Setting
- # - Default_Vert_Grad = true or false
- # * Default Text Horizontal Gradient Setting
- # - Default_Horiz_Grad = true or false
- # * Default Text Gradient Start Color Setting
- # - Default_Grad_S_Color = Color.new(0, 0, 0, 100)
- # * Default Text Gradient End Color Setting
- # - Default_Grad_E_Color = Color.new(0, 0, 0, 100)
- # * Default Font Addon Order (For multi-add settings)
- # - Font_Addon_Order = [:method_name, :method_name, ...]
- #
- # ** State Icon Settings
- #
- # * Normal Icon Filename
- # - Normal_Icon = 'filename'
- # * State Specific Icons
- # - Icon_Name = {state_id => 'filename', ...}
- #
- # ** Bitmap Draw Settings
- #
- # * Bitmap.draw_equip settings (Icon Type Settings When Item Not Equipped)
- # - Draw_Equipment_Icon_Settings = {type_id => icon_name, ...}
- # * Bitmap.draw_blur settings
- # - Blur_Settings = {setting_key => setting, ...}
- # Setting Keys
- # 'offset' - Pixels to be offseted when bluring
- # 'spacing' - Number of times to offset blur
- # 'opacity' - Max Opacity of blur
- # * Bitmap.draw_anim_sprite settings
- # - Anim_Sprite_Settings = {setting_key => setting, ...}
- # Settings
- # 'f' - Frame count reset
- # 'w' - Number of frames wide in sprite set
- # 'h' - Height of frames wide in sprite set
- #==============================================================================
- module MACL
- #-------------------------------------------------------------------------
- # * Author Settings (DO NOT TOUCH)
- #-------------------------------------------------------------------------
- Version = 2.3
- Loaded = []
- #-------------------------------------------------------------------------
- # * General Settings
- #-------------------------------------------------------------------------
- Poses = ['down', 'left', 'right', 'up']
- Frames = 4
- Real_Elements = 1, 2, 3, 4, 5, 6, 7, 8
- #-------------------------------------------------------------------------
- # * Action Test Setup
- #-------------------------------------------------------------------------
- Game_BattleAction::ATTACK_USING = [0]
- Game_BattleAction::SKILL_USING = [1]
- Game_BattleAction::DEFEND_USING = [1]
- Game_BattleAction::ITEM_USING = [2]
- Game_BattleAction::ESCAPE_USING = [2]
- Game_BattleAction::WAIT_USING = [3]
- #-------------------------------------------------------------------------
- # * Font Settings
- #-------------------------------------------------------------------------
- Font::Default_Underline = false
- Font::Default_Underline_Full = false
- Font::Default_Strikethrough = false
- Font::Default_Strikethrough_Full = false
- Font::Default_Shadow = true
- Font::Default_Shadow_Color = Color.new(0, 0, 0, 100)
- Font::Default_Outline = false
- Font::Default_Outline_Color = Color.new(0, 0, 0)
- Font::Default_Vert_Grad = false
- Font::Default_Horiz_Grad = false
- Font::Default_Grad_S_Color = Color.new(255, 255, 255)
- Font::Default_Grad_E_Color = Color.new(128, 128, 128)
- Font::Addon_Order = [
- :draw_text_shadow,
- :draw_text_outline,
- :draw_text,
- :draw_text_underline,
- :draw_text_strikethrough,
- :draw_text_gradient
- ]
- #-------------------------------------------------------------------------
- # * State Icon Settings
- #-------------------------------------------------------------------------
- RPG::State::Normal_Icon = '050-Skill07'
- RPG::State::Icon_Name = {
- 1 => '046-Skill03',
- 2 => 'Stop',
- 3 => 'Venom',
- 4 => 'Darkness',
- 5 => 'Mute',
- 6 => 'Confused',
- 7 => 'Sleep',
- 8 => 'Paralysis',
- 9 => '047-Skill04',
- 10 => '047-Skill04',
- 11 => 'Slow',
- 12 => '047-Skill04',
- 13 => '045-Skill06',
- 14 => '045-Skill06',
- 15 => '045-Skill06',
- 16 => '045-Skill06'
- }
- RPG::State::Icon_Name.default = nil
- #-------------------------------------------------------------------------
- # * Bitmap Draw Settings
- #-------------------------------------------------------------------------
- Bitmap::Draw_Equipment_Icon_Settings = {
- 0 => '001-Weapon01',
- 1 => '009-Shield01',
- 2 => '010-Head01',
- 3 => '014-Body02',
- 4 => '016-Accessory01'
- }
- Bitmap::Draw_Equipment_Icon_Settings.default = '001-Weapon01'
- Bitmap::Blur_Settings = {
- 'offset' => 2,
- 'spacing' => 1,
- 'opacity' => 255
- }
- Bitmap::Anim_Sprite_Settings = {
- 'f' => 8,
- 'w' => 4,
- 'h' => 4
- }
- #-------------------------------------------------------------------------
- # * Animated Autotile Settings
- #-------------------------------------------------------------------------
- RPG::Cache::Animated_Autotiles_Frames = 16
- end
- #==============================================================================
- # ** SDK Log
- #==============================================================================
- if Object.const_defined?(:SDK)
- SDK.log('Method & Class Library', 'MACL Authors', 2.11, '2007-08-29')
- end
- #==============================================================================
- # ** Method and Class Library - Documentation
- #------------------------------------------------------------------------------
- # * Outline
- #
- # This script set provides a utility for other scripters by: adding extra
- # methods, classes & modules to prevent other scripters from
- # "reinventing the wheel" and adding methods, classes & modules for other
- # scripters to use
- #------------------------------------------------------------------------------
- # * How to Install
- #
- # - The main setup should be placed below all default scripts, but above
- # custom ones, that is, below Scene_Debug, but above main. If SDK is present
- # then below SDK.
- # - Non scripters can just add the set so that scripts that utilize these
- # methods/classes will work without any errors.
- # - Notice the System Setup this controls constants which may affect some
- # scripts using them.
- #------------------------------------------------------------------------------
- # * How to Use
- #
- # - Please refer to the individual files for method/class information
- # - If you see a method/class you want to use copy the whole set into your
- # script preferably in a new script telling what set it is so for people who
- # have the whole set can just remove that script since it is already included
- # - Do not just copy the method/class you want to use copy the whole set since
- # some methods in a set depend on other methods.
- # - DO NOT EDIT ANY OF THE METHODS IN MACL!!!
- # If you want to edit a method make a copy of it change the name and edit it
- # If you want to edit a class make a new class w/a copy the methods from
- # there
- # - Be sure to follow the method call instructions given
- # - If you have any questions then post in the following topic:
- # http://www.rmxp.org/forums/showthread.php?t=9417
- #------------------------------------------------------------------------------
- # * Submitting an Item to the library
- #
- # Naming
- # ------
- # - Method names should be in all lowercase letters, this is to prevent the
- # Ruby Interpreter from confusing methods with constants.
- # - Dangerous (Modifies Itself) Methods should be followed by an !
- # - Query (Testing, Checking) Methods should be followed by an ?
- # - Commonly created methods (gradient bars, etc.) should have the author's
- # name in it as well to prevent incompatibilty
- # - Class names should begin with a Capital letter
- #
- # Headers
- # -------
- # - Methods should use this header
- #-------------------------------------------------------------------------
- # * Name :
- # Info :
- # Author :
- # Call Info :
- # Comments :
- #-------------------------------------------------------------------------
- # - Classes should use this header
- #==============================================================================
- # ** Class Name By Author
- #------------------------------------------------------------------------------
- # A Description of your class here
- #==============================================================================
- #
- # Approval
- # --------
- # - All Items must be approved before being put in the library, this is to
- # maintain quality and to ensure that methods/classes work, are functional
- # and stable.
- #
- # Improvements
- # ------------
- # - If you want to improve a method, such as adding new functionality or
- # improving a method, you can directly edit it, but the old and new calls
- # to a method must be compatible, that is it should do the same thing it
- # did with the original call. You must update the method header and then
- # submit it for approval.
- #==============================================================================
- #==============================================================================
- # ** Ruby.Higher Classes
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Methods created to enhance the higher classes in Ruby.
- #
- # Method List:
- # ------------
- #
- # Module
- # ------
- # attr_sec_accessor
- # attr_sec_reader
- # class_accessor
- # class_writer
- # class_reader
- # class_sec_accessor
- # class_sec_reader
- # super_skip
- #
- # Kernel
- # ------
- # class_type
- # rand_between
- # rand_name
- #==============================================================================
- MACL::Loaded << 'Ruby.Higher Classes'
- #==============================================================================
- # ** Module
- #==============================================================================
- class Module
- #-------------------------------------------------------------------------
- # * Name : Secondary Accessor (Reader with a default)
- # Info : Creates reader and writer method for one or more
- # instance variables, with the reader methods having
- # default values
- # Author : Zeriab
- # Call Info : Symbol & Default Pairs, and optional Block
- #-------------------------------------------------------------------------
- def attr_sec_accessor(sym, *args, &block)
- if block.nil? # default actions
- args = [0] if args.size == 0 #default = 0
- if args.size < 2 # One pair
- attr_writer sym
- attr_sec_reader sym, *args
- else # loads of methods followed by a default value.
- default = args[-1]
- syms = [sym].concat(args)
- syms.pop
- for sym in syms
- attr_writer sym
- attr_sec_reader sym, default
- end
- end
- else # when a block is given
- # currently just pair sematics
- args.unshift(sym)
- i = 0
- while i < args.size
- attr_writer args[i]
- attr_sec_reader args[i], args[i+1]
- i += 2
- end
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Secondary Reader (Reader with a default)
- # Info : Creates reader method for one instance variable,
- # with the reader methods having default a value
- # Author : Zeriab
- # Call Info : Symbol & Default Pair
- #-------------------------------------------------------------------------
- def attr_sec_reader(sym, default = 0)
- sym = sym.id2name
- string = "def #{sym};" +
- " @#{sym} = #{default} if @#{sym}.nil?;" +
- " @#{sym};" +
- "end;"
- module_eval(string)
- end
- #-------------------------------------------------------------------------
- # * Name : Class Attribute
- # Info : Calls class_reader/writer for a symbol
- # Author : Yeyinde
- # Call Info : symbol, writable
- # symbol: A Symbol
- # writable: Boolean telling is symbol is writable
- #-------------------------------------------------------------------------
- private
- def class_attr(symbol, writable = false)
- class_reader(symbol)
- class_writer(symbol) if writable
- return nil
- end
- #-------------------------------------------------------------------------
- # * Name : Class Accessor
- # Info : Creates reader and writer methods for one or more class
- # variables
- # Author : Yeyinde
- # Call Info : One or more Symbols
- #-------------------------------------------------------------------------
- def class_accessor(*symbols)
- class_writer(*symbols)
- class_reader(*symbols)
- end
- #-------------------------------------------------------------------------
- # * Name : Class Writer
- # Info : Creates writer method for one or more class variables
- # Author : Yeyinde
- # Call Info : One or more Symbols
- #-------------------------------------------------------------------------
- def class_writer(*symbols)
- symbols.each do |symbol|
- method = symbol.id2name
- module_eval("def self.#{method}=(var); @@#{method} = var; end")
- end
- return nil
- end
- #-------------------------------------------------------------------------
- # * Name : Class Reader
- # Info : Creates reader method for one or more class variables
- # Author : Yeyinde
- # Call Info : One or more Symbols
- #-------------------------------------------------------------------------
- def class_reader(*symbols)
- symbols.each do |symbol|
- method = symbol.id2name
- module_eval("def self.#{method}; return @@#{method}; end")
- end
- return nil
- end
- #-------------------------------------------------------------------------
- # * Name : Class Secondary Accessor (Reader with a default)
- # Info : Creates reader and writer method for one or more
- # class variables, with the reader methods having
- # default values
- # Author : Zeriab, Yeyinde & SephirothSpawn
- # Call Info : Symbol & Default Pairs, and optional Block
- #-------------------------------------------------------------------------
- def class_sec_accessor(sym, *args, &block)
- if block.nil? # default actions
- args = [0] if args.size == 0 #default = 0
- if args.size < 2 # One pair
- class_writer sym
- class_sec_reader sym, *args
- else # loads of methods followed by a default value.
- default = args[-1]
- syms = [sym].concat(args)
- syms.pop
- for sym in syms
- class_writer sym
- class_sec_reader sym, default
- end
- end
- else # when a block is given
- # currently just pair sematics
- args.unshift(sym)
- i = 0
- while i < args.size
- class_writer args[i]
- class_sec_reader args[i], args[i+1]
- i += 2
- end
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Class Secondary Reader (Reader with a default)
- # Info : Creates reader method for one class variable,
- # with the reader methods having default a value
- # Author : Zeriab, Yeyinde & SephirothSpawn
- # Call Info : Symbol & Default Pair
- #-------------------------------------------------------------------------
- def class_sec_reader(sym, default = 0)
- sym = sym.id2name
- string = "def self.#{sym};" +
- " @@#{sym} = #{default} if @@#{sym}.nil?;" +
- " @@#{sym};" +
- "end;"
- module_eval(string)
- end
- #-------------------------------------------------------------------------
- # * Name : Super Skip
- # Info : Allows you to call ancestor super method, without calling
- # ancestors between target ancestor.
- # Author : SephirothSpawn
- # Call Info : Method Name (Symbol)
- # Target Parent Class (Class Name)
- # Script Name (String)
- #-------------------------------------------------------------------------
- def super_skip(method_name, tpc, script_name = 'modulemethodskip')
- # Gets String Version of Method Name
- method_name = method_name.id2name
- # Gets Array of Ancstors
- ancestors = self.ancestors
- # If Target Parent Class not part of Ancestors
- unless ancestors.include?(tpc)
- p 'Un-defined Parents Class - ' + tpc.to_s
- return
- end
- # Starts Index
- index = 0
- # Gets Target Parent Index
- target_index = ancestors.index(tpc)
- # Loop
- loop do
- # Adds Index
- index += 1
- # Break if Passed Target Index
- break if index >= target_index
- # Gets Class Names
- cname1 = ancestors[index].to_s
- cname2 = ancestors[index - 1].to_s
- # Gets Alias Name
- aliasn = "seph_#{script_name}_#{cname1.downcase}_#{method_name}"
- # Gets String
- string = "class ::#{cname1};"
- string += " alias_method :#{aliasn}, :#{method_name};"
- string += " def #{method_name}(*args);"
- string += " super(*args);"
- string += " return if self.is_a?(#{ancestors[index - 1]});"
- string += " self.#{aliasn}(*args);"
- string += " end;"
- string += "end;"
- # Evaulates String
- eval string
- end
- end
- end
- #==============================================================================
- # ** Kernel
- #==============================================================================
- module Kernel
- #-------------------------------------------------------------------------
- # Name : Class Type
- # Info : Returns a string representing the class type
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def class_type
- # Branch By Object's class
- case self
- when FalseClass, TrueClass, NilClass, Numeric, Range, Regexp, String, Symbol
- # Inspection
- string = inspect
- when Array
- # If Object Is Empty
- if empty?
- # Set String
- string = 'Empty Array'
- else
- # Get Class
- data_type = compact[0].class
- # Setup flag
- flag = true
- # Run Through Compacted data checking class
- compact.each {|data| flag &&= data.class == data_type}
- # Setup Extra String to class if flag is true
- string = 'Array - ' + (flag ? data_type.to_s : 'Object')
- end
- when Hash
- # If Object Is Empty
- if empty?
- # Set String
- string = 'Empty Hash'
- else
- # Get Class
- key_type = keys.compact[0].class
- # Setup flag
- key = true
- # Run Through Compacted data checking class
- keys.compact.each {|data| key &&= data.class == key_type}
- # Get Class
- value_type = values.compact[0].class
- # Setup flag
- value = true
- # Run Through Compacted data checking class
- values.compact.each {|data| value &&= data.class == value_type}
- # Setup Extra String to class if flag is true
- string = 'Hash - ' + (key ? key_type.to_s : 'Object') + ' => ' +
- (value ? value_type.to_s : 'Object')
- end
- when Class
- string = self.to_s + ':Class'
- when Module
- string = self.to_s + ':Module'
- else
- # Get Class Name
- string = self.class.to_s
- end
- # Return String
- return string
- end
- #-------------------------------------------------------------------------
- # * Name : Random Number Between
- # Info : Creates a random number between two numbers
- # Author : SephirothSpawn
- # Call Info : Min and Max Number
- #-------------------------------------------------------------------------
- def rand_between(min, max)
- return min + rand(max - min + 1)
- end
- #-------------------------------------------------------------------------
- # * Name : Random Name
- # Info : Creates a random name
- # Author : Trickster
- # Call Info : Variable - Format Strings If none then strings from Setup
- # Are Used
- # Comments : Format C - consonant V - vowel
- #-------------------------------------------------------------------------
- def rand_name(*formats)
- format = formats.random
- name = ''
- format.split(//).each do |char|
- case char
- when 'C'
- name += %w( B C D F G H J K L M N P R S T V W X Y Z ).random
- when 'V'
- name += %w( A E I O U Y ).random
- when 'c'
- name += %w( b c d f g h j k l m n p r s t v w x y z ).random
- when 'v'
- name += %w( a e i o u y ).random
- else
- name += char
- end
- end
- return name
- end
- end
- #==============================================================================
- # ** Ruby.Array.find
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Methods created for finding and returning objects inside of an array.
- #
- # Method List:
- # ------------
- # all_indexes
- # find_index
- # includes?
- # includes_any?
- # include_times
- # of_index
- #==============================================================================
- MACL::Loaded << 'Ruby.Array.find'
- #==============================================================================
- # ** Array
- #==============================================================================
- class Array
- #-------------------------------------------------------------------------
- # * Name : All Indexes
- # Info : Returns All indexes where obj is (see find_index)
- # Author : Trickster
- # Call Info : One Argument. Value (Object)
- # Comment : Synonym for find_index
- #-------------------------------------------------------------------------
- def all_indexes(obj)
- # Setup Array
- array = []
- # Run Through Push index if objects are equal
- each_index {|index| array << index if obj == self[index]}
- # Return Array
- return array
- end
- #-------------------------------------------------------------------------
- # * Name : Finds Index
- # Info : Finds all indexes with the value sent to it
- # Author : Trickster
- # Call Info : One Argument. a Object
- #-------------------------------------------------------------------------
- def find_index(value)
- # Setup Array of Indexes
- indexes = []
- # Run Through each with index and add index if the same
- each_with_index {|element, index| indexes << index if element == value}
- # Return Indexes
- return indexes
- end
- #-------------------------------------------------------------------------
- # Name : Includes?
- # Info : Returns true if all of the values sent is included
- # Author : Trickster
- # Call Info : Variable Amount, Objects
- # Comment : If using an array and want to check each element,
- # use argument expansion to expand the array.
- #-------------------------------------------------------------------------
- def includes?(*args)
- # Return false if object is not included
- args.each {|object| return false unless include?(object)}
- # Everything is included
- return true
- end
- #-------------------------------------------------------------------------
- # Name : Includes Any?
- # Info : Returns true if any of the values sent is included
- # Author : Trickster
- # Call Info : Variable Amount, Objects
- # Comment : If using an array and want to check each element,
- # use argument expansion to expand the array.
- #-------------------------------------------------------------------------
- def includes_any?(*args)
- # Return true if args is empty
- return true if args.empty?
- # Return true if any of the objects is included
- args.each {|object| return true if include?(object)}
- # Not Included
- return false
- end
- #-------------------------------------------------------------------------
- # * Name : Include Times
- # Info : Returns how many times the value sent is included
- # Author : Trickster
- # Call Info : One Argument. anObject
- #-------------------------------------------------------------------------
- def include_times(obj)
- # Setup Local Variable
- times = 0
- # Run Through Each Increaing Times if object is equal
- each {|element| times += 1 if element == obj}
- # Return number of times included
- return times
- end
- #-------------------------------------------------------------------------
- # * Name : Of index
- # Info : Assuming Self is an Array of Arrays returns the values at index
- # Author : Trickster
- # Call Info : One - Integer index index of the values you want to return
- #-------------------------------------------------------------------------
- def of_index(index)
- # Create Array
- array = []
- # Run Through and get array at index
- each {|sub_array| array << sub_array[index] if sub_array.is_a?(Array)}
- # Return Array
- return array
- end
- end
- #==============================================================================
- # ** Ruby.Array.math
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # More Mathematical methods for the Array class, these methods however assume
- # all objects in the array are of class Numeric.
- #
- # Method List:
- # ------------
- # average
- # geometric_average
- # product
- # sum
- #==============================================================================
- MACL::Loaded << 'Ruby.Array.math'
- #==============================================================================
- # ** Array
- #==============================================================================
- class Array
- #---------------------------------------------------------------------------
- # * Name : Average
- # Info : Averages all values in the array
- # Author : Trickster
- # Call Info : Zero To One Arguments Defaults to False
- # Boolean float if true always returns a Float else returns a
- # Float or a Integer depending on the Types in the array
- #---------------------------------------------------------------------------
- def average(float = false)
- # Divide By Number
- return sum / (float ? size.to_f : size)
- end
- #---------------------------------------------------------------------------
- # * Name : Geometric Average
- # Info : Returns the Geometric Mean of all values in the array
- # Author : Trickster
- # Call Info : Zero To One Arguments Defaults to False
- # Boolean to_float if true always returns a Float else
- # always returns an Integer regardless of the Types in the
- # array
- #---------------------------------------------------------------------------
- def geometric_average(float = false)
- # Return 0 if empty
- return 0 if empty?
- # Get Geometric Average
- average = product ** (1.0 / size)
- # If Float return average else convert to integer
- return (float ? average : average.to_i)
- end
- #---------------------------------------------------------------------------
- # * Name : Product
- # Info : Returns the product of all values in the array
- # Author : Trickster
- # Call Info : No Arguments
- #---------------------------------------------------------------------------
- def product
- # Setup N initialize to 1
- n = 1
- # Run Through and Find Product
- each {|num| n *= num}
- # Return Product
- return n
- end
- #---------------------------------------------------------------------------
- # * Name : Sum
- # Info : Sums all values in the array
- # Author : Trickster
- # Call Info : No Arguments
- #---------------------------------------------------------------------------
- def sum
- # Initialize local variable n
- n = 0
- # Sum Up Values in Array
- each {|num| n += num}
- # Return number
- return n
- end
- end
- #==============================================================================
- # ** Ruby.Array.iterator
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # More Iterator Methods for the array class Iterator methods are methods that
- # iterate over an object Each of these methods require a block as an example
- #
- # anArray.each {|iterators| <code>}
- #
- # anArray.each do |iterators|
- # code_to_execute
- # end
- #
- # anArray.each { |iterators|
- # code_to_execute
- # }
- #
- #
- # Method List:
- # ------------
- # each_nth_index
- # each_nth_index_with_index
- # each_ntuple
- # each_pair
- # each_triple
- # each_with_array
- # each_with_array_and_index
- # each_with_next
- # each_with_next_and_index
- #==============================================================================
- MACL::Loaded << 'Ruby.Array.iterator'
- #==============================================================================
- # ** Array
- #==============================================================================
- class Array
- #-------------------------------------------------------------------------
- # Name : Each Nth Index
- # Info : An Iterator Method calls block for every nth in the
- # array of arrays
- # Author : Trickster
- # Call Info : Integer index the index to iterate over, A Block
- #-------------------------------------------------------------------------
- def each_nth_index(index)
- # Run Through Each Sub Array and return the value at index
- each {|array| yield(array[index])}
- end
- #-------------------------------------------------------------------------
- # Name : Each Nth Index with index
- # Info : An Iterator Method calls block for every nth in the
- # array of arrays with index
- # Author : Trickster
- # Call Info : Integer index the index to iterate over, A Block
- #-------------------------------------------------------------------------
- def each_nth_index_with_index(index)
- # Run Through Each Sub Array and return the value at index
- each_with_index {|array, i| yield(array[index], i)}
- end
- #-------------------------------------------------------------------------
- # Name : Each N-tuple
- # Info : An Iterator Method calls block for every tuple in the array
- # Author : Trickster
- # Call Info : Number an Integer value for how many to iterate over, A Block
- #-------------------------------------------------------------------------
- def each_ntuple(number)
- # Get Last Index (last index divisible by number)
- end_num = size - size % number - 1
- # Run Through each index 0, number, 2*number, ..., end_num
- # and yield i, i+1, i+2, ... i + (number - 1)
- 0.step(end_num, number) {|i| yield(*self[i, number])}
- end
- #-------------------------------------------------------------------------
- # Name : Each Pair
- # Info : An Iterator Method calls block for every pair in the array
- # Author : Trickster
- # Call Info : A Block
- #-------------------------------------------------------------------------
- def each_pair
- # Get Last Index (last even numbered index)
- end_num = size - size % 2 - 1
- # Run Through each index 0, 2, 4, ..., end_num and yield i and i+1
- 0.step(end_num, 2) {|i| yield(*self[i,2])}
- end
- #-------------------------------------------------------------------------
- # Name : Each Triple
- # Info : An Iterator Method calls block for every triple in the array
- # Author : Trickster
- # Call Info : A Block
- #-------------------------------------------------------------------------
- def each_triple
- # Get Last Index (last index divisible by 3)
- end_num = size - size % 3 - 1
- # Run Through each index 0, 3, 6, ..., end_num and yield i, i+1, and i+2
- 0.step(end_num, 3) {|i| yield(*self[i,3])}
- end
- #-------------------------------------------------------------------------
- # Name : Each With Array
- # Info : An Iterator Method calls block for each object in both arrays
- # Author : Trickster
- # Call Info : Variable Amount, Object obj objects to be iterated over. A Block
- #-------------------------------------------------------------------------
- def each_with_array(*array)
- # Run Through Each Index and yield self at i and array at i
- each_index {|i| yield(self[i], array[i])}
- end
- #-------------------------------------------------------------------------
- # Name : Each With Array and Index
- # Info : An Iterator Method calls block for each object in both arrays
- # with the index
- # Author : Trickster
- # Call Info : Variable Amount, Object obj objects to be iterated over. A Block
- #-------------------------------------------------------------------------
- def each_with_array_and_index(*array)
- # Run Through Each Index and yield self at i and array at i and index
- each_index {|i| yield(self[i],array[i], i)}
- end
- #-------------------------------------------------------------------------
- # Name : Each With Next
- # Info : Runs Through with Next num elements
- # Author : Trickster
- # Call Info : Integer num - next few elements to send as well
- # A Block
- #-------------------------------------------------------------------------
- def each_with_next(num = 1)
- (size - num).times {|i| yield(*self[i..(i+num)])}
- end
- #-------------------------------------------------------------------------
- # Name : Each With Next And Index
- # Info : Runs Through with Next num elements with index
- # Author : Trickster
- # Call Info : Integer num - next few elements to send as well
- # A Block
- #-------------------------------------------------------------------------
- def each_with_next_and_index(num = 1)
- (size - num).times {|i| yield(*(self[i..(i+num)] << i))}
- end
- end
- #==============================================================================
- # ** Ruby.Array.list
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Methods created that treats an array as a list.
- #
- # Method List:
- # ------------
- # random
- # random!
- # rate
- # series_string
- # sort_by!
- # unsort
- #==============================================================================
- MACL::Loaded << 'Ruby.Array.list'
- #==============================================================================
- # ** Array
- #==============================================================================
- class Array
- #-------------------------------------------------------------------------
- # Name : Random
- # Info : Returns a Random element in the array
- # Author : SephirothSpawn
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def random
- return self[rand(size)]
- end
- #-------------------------------------------------------------------------
- # Name : Random!
- # Info : Returns and Deletes a Random element in the array
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def random!
- return delete_at(rand(size))
- end
- #-------------------------------------------------------------------------
- # Name : Rate
- # Info : Rates all indexes from least(0) to greatest(size-1)
- # Author : Trickster
- # Call Info : Zero or One Arguemtns Boolean Same (Defaults to true)
- # If same is true then rating increases for same values in the
- # array
- #-------------------------------------------------------------------------
- def rate(same = true)
- # Create Rated Array
- rated = []
- # Create A Copy of the Array
- copy = self.dup
- # Initialize rate
- rate = 1
- # Run Through Size number of times
- size.times do
- # For each index where minimum is found
- copy.find_index(copy.compact.min).each do |index|
- # Set Rated at index to rating
- rated[index] = rate
- # Set Copy at index to nil
- copy[index] = nil
- # Increase Rating if false sent (increase for same)
- rate += 1 if !same
- end
- # Increase Rating if same is true (don't increase for same valued)
- rate += 1 if same
- # Break if no more non nil items
- break if copy.nitems == 0
- end
- # Return Rated Array
- return rated
- end
- #-------------------------------------------------------------------------
- # * Name : Series String
- # Info : Returns a String with a list of the objects in the array
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def series_string
- # Setup String
- series = ''
- # If Size is 1
- if size == 1
- # Set Series to First
- series = self[0].to_s
- elsif size == 2
- # Set Battlers to battler and battler
- series = self[0].to_s + ' and ' + self[1].to_s
- else
- # Run Through Each Item with index
- each_with_index do |string, index|
- # Add String to Series
- series += string.to_s
- # Add , if not at last entry
- series += ', ' if index <= size - 2
- # Add and if at last entry
- series += 'and ' if index == size - 2
- end
- end
- return series
- end
- #-------------------------------------------------------------------------
- # Name : Sort By!
- # Info : Modifies Itself, Performs sort_by on the array
- # Author : Trickster
- # Call Info : A Block
- # Comment : See Enumerable#sort_by
- #-------------------------------------------------------------------------
- def sort_by!(&block)
- # Duplicate Array
- saved = self.dup
- # Sort Array Call Block Sent
- sorted = sort_by {|object| block.call(object)}
- # Modify Original Array
- sorted.each_with_index {|item, index| self[index] = item}
- # If Changes Made Return self else nil
- return (saved == self ? nil : self)
- end
- #-------------------------------------------------------------------------
- # * Name : self.unsort
- # Info : return a array of mixed elements
- # Author : Hanmac
- # Call Info : with min one Argument from type can this be everything
- #-------------------------------------------------------------------------
- def self.unsort(*arrays)
- array = arrays.flatten
- Array.new(array.size) {
- zufall = rand(array.size)
- array.delete_at(zufall)
- }
- end
- end
- #==============================================================================
- # ** Ruby.Comparable/Enumerable
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Miscellaneous New stuff for the Comparable/Enumerable module
- #
- # Method List:
- # ------------
- #
- # Enumerable
- # ----------
- # unsort
- #==============================================================================
- MACL::Loaded << 'Ruby.Comparable/Enumerable'
- #==============================================================================
- # ** Enumerable
- #==============================================================================
- module Enumerable
- #-------------------------------------------------------------------------
- # Name : unsort
- # Info : return a array of mixed elements
- # Author : Hanmac
- # Call Info : with no Arguments
- # Comments : can make nosense with strings
- #-------------------------------------------------------------------------
- def unsort
- Array.unsort(self.entries)
- end
- end
- #==============================================================================
- # ** Ruby.Dir
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Miscellaneous New stuff for the Dir class.
- #
- # Method List:
- # ------------
- # make_dir
- #==============================================================================
- MACL::Loaded << 'Ruby.Dir'
- #==============================================================================
- # ** Dir
- #==============================================================================
- class Dir
- #-------------------------------------------------------------------------
- # * Name : Make Dir
- # Info : Creates Folder Dir
- # Author : ??? - http://www.66rpg.com/htm/news624.htm
- # Call Info : One Arguments
- # Path : Path to create directory
- #-------------------------------------------------------------------------
- def self.make_dir(path)
- dir = path.split("/")
- for i in 0...dir.size
- unless dir == "."
- add_dir = dir[0..i].join("/")
- begin
- Dir.mkdir(add_dir)
- rescue
- end
- end
- end
- end
- end
- #==============================================================================
- # ** Ruby.Float
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Miscellaneous New stuff for the Float class.
- #
- # Method List:
- # ------------
- # float_points
- #==============================================================================
- MACL::Loaded << 'Ruby.Float'
- #==============================================================================
- # ** Float
- #==============================================================================
- class Float
- #-------------------------------------------------------------------------
- # Name : Float Points
- # Info : Sets number of float points
- # Author : SephirothSpawn
- # Call Info : One Argument, an Integer, number of float points
- #-------------------------------------------------------------------------
- def float_points(points = 2)
- # Gets Self
- n = self
- # Multiple N
- n *= 10 ** points
- # Converts N to Integer
- n = n.round.to_f
- # Divide back to float
- n /= 10.0 ** points
- # Return N
- return n
- end
- end
- #==============================================================================
- # ** Ruby.Hash
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Miscellaneous New stuff for the Hash class.
- #
- # Method List:
- # ------------
- # contains_key?
- # get_value
- #==============================================================================
- MACL::Loaded << 'Ruby.Hash'
- #==============================================================================
- # ** Hash
- #==============================================================================
- class Hash
- #-------------------------------------------------------------------------
- # Name : Contains Key?
- # Info : Compares all Keys using == similiar to has_key?
- # Author : Trickster
- # Call Info : One, Key an Object
- #-------------------------------------------------------------------------
- def contains_key?(key)
- # Run Through and Return true if keys are equal
- each_key {|other_key| return true if key == other_key}
- # Return false
- return false
- end
- #-------------------------------------------------------------------------
- # Name : Get Value
- # Info : Gets Value using == similiar to []
- # Author : Trickster
- # Call Info : One, Key an Object
- #-------------------------------------------------------------------------
- def get_value(key)
- # Run Through and Return Key if equal
- each_key {|other_key| return self[other_key] if key == other_key}
- # If Default Proc is undefined return default else call proc
- return default_proc.nil? ? default : default_proc.call(self, key)
- end
- end
- #==============================================================================
- # ** Ruby.Integer
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Miscellaneous New stuff for the Integer class.
- #
- # Method List:
- # ------------
- # factorial
- # primorial
- # multifactorial
- #==============================================================================
- MACL::Loaded << 'Ruby.Integer'
- #==============================================================================
- # ** Integer
- #==============================================================================
- class Integer
- #-------------------------------------------------------------------------
- # Name : Factorial
- # Info : Return the factorial of number
- # Author : Tibuda
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def factorial
- result = 1
- self.downto(2) {|i| result *= i }
- return result
- end
- #-------------------------------------------------------------------------
- # Name : Primorial
- # Info : Return the primorial of number
- # Author : Tibuda
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def primorial
- result = 1
- self.downto(2) {|i| result *= i if i.is_prime? }
- return result
- end
- #-------------------------------------------------------------------------
- # Name : Multifactorial
- # Info : Return the multifactorial of number
- # Author : Tibuda
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def multifactorial(n = 2)
- result = self
- n.downto(1) {|i| result = result.factorial }
- return result
- end
- end
- #==============================================================================
- # ** Ruby.Math
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Miscellaneous new methods for the Math module
- #
- # Method List:
- # ------------
- # A (Ackermann function)
- # cw_between_angles?
- # ccw_between_angles?
- # cw_percent_between_angles
- # ccw_percent_between_angles
- #==============================================================================
- MACL::Loaded << 'Ruby.Math'
- module Math
- #-------------------------------------------------------------------------
- # * Name : Ackermann function
- # Info : returns the Natural Number of an A(m,n) Integer
- # Author : Me(tm)
- # Call Info : m as Integer, n as Integer, both 0 or positive.
- #-------------------------------------------------------------------------
- def Math.A(m,n)
- raise ArgumentError.new('Ackermann: No negative values allowed.') if m < 0 or n < 0
- return n + 1 if m == 0
- return Math.A(m - 1, 1) if n == 0
- return Math.A(m - 1, Math.A(m, n - 1))
- end
- #-------------------------------------------------------------------------
- # * Name : Angle Between Angles (Clockwise)
- # Info : Returns boolean of angle between 2 angles
- # Author : SephirothSpawn
- # Call Info : Test Angle, Start Angle, End Angle
- # Radians boolean (if true, converts to degrees)
- #-------------------------------------------------------------------------
- def self.cw_between_angles?(ang, a1, a2, radians = false)
- # Convert from degrees to radians, if radians
- a1 *= 180 / PI if radians
- a2 *= 180 / PI if radians
- # Make Degrees between 0 - 360
- a1 %= 360 ; a2 %= 360
- # Make a1 Greater than a2
- a1 += 360 if a1 < a2
- # Returns Angle Between Angles
- return ang.between?(a2, 360) || ang.between?(0, a1 - 360) if a1 > 360
- return ang.between?(a2, a1)
- end
- #-------------------------------------------------------------------------
- # * Name : Angle Between Angles (Counter-Clockwise)
- # Info : Returns boolean of angle between 2 angles
- # Author : SephirothSpawn
- # Call Info : Test Angle, Start Angle, End Angle
- # Radians boolean (if true, converts to degrees)
- #-------------------------------------------------------------------------
- def self.ccw_between_angles?(ang, a1, a2, radians = false)
- # Convert from degrees to radians, if radians
- a1 *= 180 / PI if radians
- a2 *= 180 / PI if radians
- # Make Degrees between 0 - 360
- a1 %= 360 ; a2 %= 360
- # Make a2 Greater than a1
- a2 += 360 if a2 < a1
- # Returns Angle Between Angles
- return ang.between?(a1, 360) || ang.between?(0, a2 - 360) if a2 > 360
- return ang.between?(a1, a2)
- end
- #-------------------------------------------------------------------------
- # * Name : Angle Percnt Between Angles (Clockwise)
- # Info : Returns boolean of angle between 2 angles
- # Author : SephirothSpawn
- # Call Info : Test Angle, Start Angle, End Angle
- # Radians boolean (if true, converts to degrees)
- #-------------------------------------------------------------------------
- def self.cw_percent_between_angles(ang, a1, a2, radians = false)
- # Convert from degrees to radians, if radians
- a1 *= 180 / PI if radians
- a2 *= 180 / PI if radians
- # Make Degrees between 0 - 360
- a1 %= 360 ; a2 %= 360
- # Make aa Greater than a2
- a1 += 360 if a1 < a2
- # Gets Percent
- per = (ang - a2) / (a1 - a2).to_f
- # If Negative, and 360 to Angle
- per = (ang + 360 - a2) / (a1 - a2).to_f if per < 0
- # Return Percent
- return per
- end
- #-------------------------------------------------------------------------
- # * Name : Angle Percent Between Angles (Counter-Clockwise)
- # Info : Returns boolean of angle between 2 angles
- # Author : SephirothSpawn
- # Call Info : Test Angle, Start Angle, End Angle
- # Radians boolean (if true, converts to degrees)
- #-------------------------------------------------------------------------
- def self.ccw_percent_between_angles(ang, a1, a2, radians = false)
- # Convert from degrees to radians, if radians
- a1 *= 180 / PI if radians
- a2 *= 180 / PI if radians
- # Make Degrees between 0 - 360
- a1 %= 360 ; a2 %= 360
- # Make a2 Greater than a1
- a2 += 360 if a2 < a1
- # Gets Percent
- per = (ang - a1) / (a2 - a1).to_f
- # If Negative, and 360 to Angle
- per = (ang + 360 - a1) / (a2 - a1).to_f if per < 0
- # Return Percent
- return per
- end
- end
- #==============================================================================
- # ** Ruby.Math.dist
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # This set allows the generation of discrete distributed random values.
- #
- # Class List:
- # -----------
- # Math::Uniform
- # Math::Bernoulli
- # Math::Binomial
- # Math::Geometric
- # Math::Poisson
- #
- # Method List: (avaiable for all classes)
- # ------------
- # initialize
- # generate
- # generate_array
- # prob
- #==============================================================================
- MACL::Loaded << 'Ruby.Math.dist'
- #==============================================================================
- # ** Math
- #==============================================================================
- module Math
- #-------------------------------------------------------------------------
- # * Distribution precision (keep it high and float)
- #-------------------------------------------------------------------------
- Dist_precision = 1000.0
- #==============================================================================
- # ** Math::Uniform By: Tibuda
- #-----------------------------------------------------------------------------
- # A class for generating unform distributed random values. It's used as a
- # base for other distributions.
- #-----------------------------------------------------------------------------
- # The discrete uniform distribution can be characterized by saying that all
- # values of a finite set of possible values are equally probable.
- #==============================================================================
- class Uniform
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_reader :min
- attr_reader :max
- #-------------------------------------------------------------------------
- # * Name : Initialize
- # Info : Object Initialization
- # Author : Tibuda
- # Call Info : Zero to Two
- # Integer minumum value (default 0)
- # Integer maximum value (default 1)
- #-------------------------------------------------------------------------
- def initialize(min = 0, max = 1)
- @min = min
- @max = max
- @max += @min if max < min
- end
- #-------------------------------------------------------------------------
- # * Name : Generate
- # Info : Generates uniform distributed value
- # Author : Tibuda
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def generate
- return @min + rand(@max - @min)
- end
- def gen
- return generate
- end
- #-------------------------------------------------------------------------
- # * Name : Generate array
- # Info : Generates an array with uniform distributed values
- # Author : Tibuda
- # Call Info : One
- # Integer array size
- #-------------------------------------------------------------------------
- def generate_array(size)
- result = []
- for i in 0...size
- result << generate
- end
- return result
- end
- def gen_array(size)
- return generate_array(size)
- end
- #-------------------------------------------------------------------------
- # * Name : Probability mass function
- # Info : Returns the probability of observing a value
- # Author : Tibuda
- # Call Info : One
- # Integer tested value
- #-------------------------------------------------------------------------
- def prob(x)
- return (x < @min || x > @max) ? 0 : 1 / (@max - @min)
- end
- end
- #==============================================================================
- # ** Math::Bernoulli By: Tibuda
- #-----------------------------------------------------------------------------
- # A class for generating Bernoulli distributed random values. It's used as a
- # base class for binomial and geometric distributions.
- #-----------------------------------------------------------------------------
- # Bernoulli trial is an experiment whose outcome is random and can be either
- # of two possible outcomes, "success" and "failure". In practice it refers to
- # a single experiment which can have one of two possible outcomes, like "yes
- # or no" questions.
- #==============================================================================
- class Bernoulli < Uniform
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_reader :p
- attr_reader :success
- attr_reader :failure
- #-------------------------------------------------------------------------
- # * Name : Initialize
- # Info : Object Initialization
- # Author : Tibuda
- # Call Info : Zero to Three
- # Float probability of success (default 0.5)
- # Variant success return value (default 1)
- # Variant failure return value (default 0)
- #-------------------------------------------------------------------------
- def initialize(p = 0.5, success = 1, failure = 0)
- super(0, Dist_precision)
- @p = p
- @success = success
- @failure = failure
- end
- #-------------------------------------------------------------------------
- # * Name : Generate
- # Info : Generates Bernoulli distributed value
- # Author : Tibuda
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def generate
- return super.to_f / Dist_precision <= @p ? @success : @failure
- end
- #-------------------------------------------------------------------------
- # * Name : Probability mass function
- # Info : Returns the probability of observing a value
- # Author : Tibuda
- # Call Info : One
- # Integer tested value
- #-------------------------------------------------------------------------
- def prob(x)
- return @p if x == @success
- return 1 - @p if x == @failure
- return 0
- end
- end
- #==============================================================================
- # ** Math::Binomial By: Tibuda
- #-----------------------------------------------------------------------------
- # A class for generating binomial distributed random values.
- #-----------------------------------------------------------------------------
- # The binomial distribution is the probability distribution of the number of
- # "successes" in n independent Bernoulli trials, with the same probability of
- # "success" on each trial.
- #==============================================================================
- class Binomial < Bernoulli
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_reader :n
- #-------------------------------------------------------------------------
- # * Name : Initialize
- # Info : Object Initialization
- # Author : Tibuda
- # Call Info : Zero to Two
- # Integer number of trials (default 1)
- # Float probability of success (default 0.5)
- #-------------------------------------------------------------------------
- def initialize(n = 1, p = 0.5)
- super(p, 1, 0)
- @n = n
- end
- #-------------------------------------------------------------------------
- # * Name : Generate
- # Info : Generates binomial distributed value
- # Author : Tibuda
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def generate
- result = 0
- for i in 0...@n
- result += super
- end
- return result
- end
- #-------------------------------------------------------------------------
- # * Name : Probability mass function
- # Info : Returns the probability of observing a value
- # Author : Tibuda
- # Call Info : One
- # Integer tested value
- #-------------------------------------------------------------------------
- def prob(x)
- binomial_coef = @n.factorial / (x.factorial * (@n - x).factorial)
- return binomial_coef * @p ** x * (1 - @p) ** (@n - x)
- end
- end
- #==============================================================================
- # ** Math::Geometric By: Tibuda
- #-----------------------------------------------------------------------------
- # A class for generating geometric distributed random values.
- #-----------------------------------------------------------------------------
- # The geometric distribution is the probability distribution of the number
- # of Bernoulli trials needed to get one success.
- #==============================================================================
- class Geometric < Bernoulli
- #-------------------------------------------------------------------------
- # * Name : Initialize
- # Info : Object Initialization
- # Author : Tibuda
- # Call Info : Zero to One
- # Float probability of success (default 0.5)
- #-------------------------------------------------------------------------
- def initialize(p = 0.5)
- super(p, true, false)
- end
- #-------------------------------------------------------------------------
- # * Name : Generate
- # Info : Generates geometric distributed value
- # Author : Tibuda
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def generate
- k = 0
- while super == false
- k += 1
- end
- return k
- end
- #-------------------------------------------------------------------------
- # * Name : Probability mass function
- # Info : Returns the probability of observing a value
- # Author : Tibuda
- # Call Info : One
- # Integer tested value
- #-------------------------------------------------------------------------
- def prob(x)
- return @p * (1 - @p) ** x
- end
- end
- #==============================================================================
- # ** Math::Poisson By: Tibuda using Knuth algorithm
- #-----------------------------------------------------------------------------
- # A class for generating Poisson distributed random values.
- #-----------------------------------------------------------------------------
- # The Poisson distribution expresses the probability of a number of events
- # occurring in a fixed period of time if these events occur with a known
- # average rate, and are independent of the time since the last event.
- #==============================================================================
- class Poisson < Uniform
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_reader :lambda
- #-------------------------------------------------------------------------
- # * Name : Initialize
- # Info : Object Initialization
- # Author : Tibuda
- # Call Info : One
- # Float expected number of occurrences
- #-------------------------------------------------------------------------
- def initialize(lambda)
- super(0, Dist_precision)
- @lambda = lambda
- end
- #-------------------------------------------------------------------------
- # * Name : Generate
- # Info : Generates Poisson distributed value
- # Author : Tibuda using Knuth algorithm
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def generate
- k = 0
- p = 1.0
- while p >= Math.exp(-@lambda)
- k += 1
- p *= super.to_f / Dist_precision
- end
- return k - 1
- end
- #-------------------------------------------------------------------------
- # * Name : Probability mass function
- # Info : Returns the probability of observing a value
- # Author : Tibuda
- # Call Info : One
- # Integer tested value
- #-------------------------------------------------------------------------
- def prob(x)
- return Math.exp(-@lambda) * @lambda ** x / x.factorial
- end
- end
- end
- #==============================================================================
- # ** Ruby.Numeric
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Miscellaneous New stuff for the Numeric class.
- #
- # Method List:
- # ------------
- # is_prime?
- # linear?
- # sign
- #==============================================================================
- MACL::Loaded << 'Ruby.Numeric'
- #==============================================================================
- # ** Numeric
- #==============================================================================
- class Numeric
- #-------------------------------------------------------------------------
- # Name : Is Prime?
- # Info : Checks if a number is prime or not
- # Author : Lobosque/Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def is_prime?
- # Not Prime if 0 or one or even
- return false if [0,1].include?(self) or self % 2 == 0
- # Initialize Check Variable
- check = 3
- # While Check is less than self
- while check < Math.sqrt(self)
- # Return false if divisible
- return false if self % check == 0
- # Increase By 2 (Odd numbers only)
- check += 2
- end
- # Is Prime
- return true
- end
- #-------------------------------------------------------------------------
- # * Name : Linear?
- # Info : Tests if Num falls in a + bx
- # Author : Trickster
- # Call Info : Two or Three Arguments Integer A and B
- # Boolean Neg X allow for negative x
- #-------------------------------------------------------------------------
- def linear?(a, b, negx = true)
- n = self
- return (b == 0 && n == a) || ((n >= a || negx) && (n - a) % b == 0)
- end
- #-------------------------------------------------------------------------
- # Name : Sign
- # Info : Returns the Sign of the number (0 if 0 1 if + -1 if -)
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def sign
- return zero? ? 0 : (self / self.abs).to_i
- end
- end
- #==============================================================================
- # ** Ruby.Range
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Methods created for finding and returning objects inside of an array.
- #
- # Method List:
- # ------------
- # random
- # <=>
- #==============================================================================
- MACL::Loaded << 'Ruby.Range'
- #==============================================================================
- # ** Range
- #==============================================================================
- class Range
- #--------------------------------------------------------------------------
- # * Include Comparable
- #--------------------------------------------------------------------------
- include(Comparable)
- #--------------------------------------------------------------------------
- # * Name : Random
- # Info : Returns random object in array
- # Author : SephirothSpawn
- # Call Info : Nil
- #--------------------------------------------------------------------------
- def random
- return self.to_a.random
- end
- #--------------------------------------------------------------------------
- # * Name : <=>
- # Info : Compares ranges
- # Author : hanmac
- # Call Info : One Argument, Other range
- #--------------------------------------------------------------------------
- def <=>(other)
- temp = first <=> other.first
- temp = last <=> other.last if temp = 0
- return temp
- end
- end
- #==============================================================================
- # ** Ruby.String
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Miscellaneous New stuff for the String class.
- #
- # Method List:
- # ------------
- # clear
- # get_int
- # get_ints
- # seph_encrypt
- # seph_encrypt!
- # seph_decrypt
- # seph_decrypt!
- # to_filename
- # to_filename!
- #==============================================================================
- MACL::Loaded << 'Ruby.String'
- #==============================================================================
- # ** String
- #==============================================================================
- class String
- #-------------------------------------------------------------------------
- # * Name : Clear
- # Info : Removes string characters and returns self
- # Author : SephirothSpawn
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def clear
- slice!(0, self.size)
- end
- #-------------------------------------------------------------------------
- # * Name : Get Integer
- # Info : Gets the Integer from String
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def get_int
- m = self.gsub(/\D/,'')
- return m.to_i
- end
- #-------------------------------------------------------------------------
- # * Name : Get Integers
- # Info : Gets all Integers from String
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def get_ints
- array = self.split(/\D/)
- array.collect! {|item| item.to_i}
- return array
- end
- #-------------------------------------------------------------------------
- # * Name : Seph Encrypt
- # Info : Returns an encrypted version of a string with a keyword
- # Author : SephirothSpawn
- # Call Info : Encryption Word String
- #-------------------------------------------------------------------------
- def seph_encrypt(encryption_string = 'encrypt')
- # Collects Encryption String Bytes
- encryption_bytes = []
- encryption_string.each_byte {|c| encryption_bytes << c}
- # Creates New String
- string = ''
- # Pass Through Self
- for i in 0...self.size
- # Gets Encrypted Byte
- byte = self[i] * encryption_bytes[i % encryption_bytes.size]
- # Gets Base & Mod Value
- base, mod = byte / 255, byte % 255
- # Adds Encrypted Character
- string += base.chr + mod.chr
- end
- # Returns Encryption String
- return string
- end
- #-------------------------------------------------------------------------
- # * Name : Seph Encrypt!
- # Info : Encrypts self with a keyword. Returns modified self.
- # Author : SephirothSpawn
- # Call Info : Encryption Word String
- #-------------------------------------------------------------------------
- def seph_encrypt!(encryption_string = 'encrypt')
- # Gets Encryption String
- encrypted_string = seph_encrypt(encryption_string)
- # Clears self
- clear
- # Makes self encrypted string
- self.concat(encrypted_string)
- # Returns Decrypted String
- return self
- end
- #-------------------------------------------------------------------------
- # * Name : Seph Decrypt
- # Info : Returns an decrypted version of a string with a keyword
- # Author : SephirothSpawn
- # Call Info : Encryption Word String
- #-------------------------------------------------------------------------
- def seph_decrypt(encryption_string = 'encrypt')
- # Collects Encryption String Bytes
- encryption_bytes = []
- encryption_string.each_byte {|c| encryption_bytes << c}
- # Creates New String
- string = ''
- # Pass Through Self
- for i in 0...(self.size / 2)
- # Gets Base & Mod Value
- b, m = self[i * 2] * 255, self[i * 2 + 1]
- # Gets New Character
- string += ((b + m) / encryption_bytes[i % encryption_bytes.size]).chr
- end
- # Returns Decrypted String
- return string
- end
- #-------------------------------------------------------------------------
- # * Name : Seph Decrypt
- # Info : Decrypts a string with keyword. Returns modified self.
- # Author : SephirothSpawn
- # Call Info : Encryption Word String
- #-------------------------------------------------------------------------
- def seph_decrypt!(encryption_string = 'encrypt')
- # Gets Decrypted String
- decrypted_string = seph_decrypt(encryption_string)
- # Clears self
- clear
- # Makes self encrypted string
- self.concat(decrypted_string)
- # Returns Decrypted String
- return self
- end
- #-------------------------------------------------------------------------
- # * Name : To Filename
- # Info : Converts the string to a filename
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def to_filename
- string = self.clone
- string.downcase!
- string.gsub!(/\s/,'_')
- return string
- end
- #-------------------------------------------------------------------------
- # * Name : To Filename!
- # Info : Modifies Itself Converts the string to a filename
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def to_filename!
- string = self.clone
- self.downcase!
- self.gsub!(/\s/,'_')
- return string == self ? nil : self
- end
- end
- #==============================================================================
- # ** RGSS.Action Test
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # These Set of Methods test the type of action created by a player/enemy in
- # battle. If you are adding new commands based on Attack, Skill, Item, Defend,
- # or Escape then see the constants related to this set in the MACL Setup section.
- #
- # Method List:
- # ------------
- #
- # Game_Battler
- # -----------------
- # action?
- #
- # Game_BattleAction
- # -----------------
- # is_a_skill?
- # is_a_attack?
- # is_a_item?
- # is_a_defend?
- # is_a_escape?
- # is_a_wait?
- #==============================================================================
- MACL::Loaded << 'RGSS.Action Test'
- #==============================================================================
- # ** Game_Battler
- #==============================================================================
- class Game_Battler
- #-------------------------------------------------------------------------
- # Name : Action?
- # Info : Is Action of kind, basic, skill id, and item id
- # Author : Trickster
- # Call Info : Integer kind, basic, skill id, and item id
- #-------------------------------------------------------------------------
- def action?(kind, basic, skill_id = 0, item_id = 0)
- return (@current_action.kind == kind && @current_action.basic == basic &&
- (@current_action.skill_id == skill_id || skill_id == 0) &&
- (@current_action.item_id == item_id || item_id == 0))
- end
- end
- #==============================================================================
- # ** Game_BattleAction
- #==============================================================================
- class Game_BattleAction
- #-------------------------------------------------------------------------
- # Name : Is a Skill?
- # Info : Is Action a Skill (That is, if skill id is not zero
- # Or if the action's kind is included in skill using)
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def is_a_skill?
- return (@skill_id != 0) && SKILL_USING.include?(@kind)
- end
- #-------------------------------------------------------------------------
- # Name : Is a Attack?
- # Info : Is Action an Attack (That is, if kind is zero and
- # if the action's basic is zero or included in attack using)
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def is_a_attack?
- return (@kind == 0) && ((@basic == 0) || ATTACK_USING.include?(@basic))
- end
- #-------------------------------------------------------------------------
- # Name : Is a Item?
- # Info : Is Action a Item (That is, if item id is not zero
- # Or if the action's kind is included in item using)
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def is_a_item?
- return ITEM_USING.include?(@kind) && (@item_id != 0)
- end
- #-------------------------------------------------------------------------
- # Name : Is a Defend?
- # Info : Is Action a Defend (That is, if basic is one
- # Or if the action's basic is included in defend using and
- # the kind is 0)
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def is_a_defend?
- return (@kind == 0) && (DEFEND_USING.include?(@basic) || (@basic == 1))
- end
- #-------------------------------------------------------------------------
- # Name : Is a Wait?
- # Info : Is Action a wait like command (That is, if basic is three
- # Or if the action's basic is included in wait using and the
- # kind is 0)
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def is_a_wait?
- return (@kind == 0) && (WAIT_USING.include?(@basic) || @basic == 3)
- end
- #-------------------------------------------------------------------------
- # Name : Is a Escape?
- # Info : Is Action a Escape like command (That is, if basic is two
- # Or if the action's basic is included in the escape using and
- # the kind is 0)
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def is_a_escape?
- return (@kind == 0) && (ESCAPE_USING.include?(@basic) || @basic == 2)
- end
- end
- #==============================================================================
- # ** RGSS.Actor and Party Info
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # These set of methods add observer methods to the Game_Actor and Game_Party
- # classes, you can get information on how weak an enemy is to a state, all
- # of the enemies resistances and weaknesses, etc.
- #
- # Method List:
- # ------------
- #
- # Game_Battler
- # ------------
- # hp_percent
- # sp_percent
- #
- # Game_Actor
- # ----------
- # element_effectiveness
- # state_effectiveness
- # now_exp
- # next_exp
- # weapon_ids
- # armor_ids
- # equipment
- # element_test
- # weaknesses
- # resistance
- # next_exp_percent
- #
- # Game_Party
- # ----------
- # equipped_weapon?
- # equipped_armor?
- # has_actors?
- # strongest
- # weakest
- # existing_actors
- # average_level
- #==============================================================================
- MACL::Loaded << 'RGSS.Actor and Party Info'
- #==============================================================================
- # ** Game_Battler
- #==============================================================================
- class Game_Battler
- #-------------------------------------------------------------------------
- # * Name : Hp Percent
- # Info : Returns HP Percent
- # Author : SephirothSpawn
- # Call Info : Two Arguments
- # Integer truth, true for integer, false for float
- # Float points, integer value for number of float points
- #-------------------------------------------------------------------------
- def hp_percent(integer = false, float_points = 2)
- # Gets Float Percent
- n = (self.hp / self.maxhp.to_f * 100.0)
- # Return Percent
- return integer ? Integer(n) : n.float_points(float_points)
- end
- #-------------------------------------------------------------------------
- # * Name : Sp Percent
- # Info : Returns SP Percent
- # Author : SephirothSpawn
- # Call Info : Two Arguments
- # Integer truth, true for integer, false for float
- # Float points, integer value for number of float points
- #-------------------------------------------------------------------------
- def sp_percent(integer = false, float_points = 2)
- # Gets Float Percent
- n = (self.sp / self.maxsp.to_f * 100.0)
- # Return Percent
- return integer ? Integer(n) : n.float_points(float_points)
- end
- end
- #==============================================================================
- # ** Game_Actor
- #==============================================================================
- class Game_Actor
- #-------------------------------------------------------------------------
- # Name : Element Effectiveness
- # Info : How Effective Enemy is against an Element
- # An Integer from 0-5 (5: most effective 0: not effective at all)
- # Author : Trickster
- # Call Info : Integer Element_ID id of the element to check
- #-------------------------------------------------------------------------
- def element_effectiveness(element_id)
- # Get a numerical value corresponding to element effectiveness
- table = [0,5,4,3,2,1,0]
- effective = table[$data_classes[@class_id].element_ranks[element_id]]
- # If protected by state, this element is reduced by half
- for i in @states
- if $data_states[i].guard_element_set.include?(element_id)
- effective = (effective / 2.0).ceil
- end
- end
- # End Method
- return effective
- end
- #-------------------------------------------------------------------------
- # Name : State Effectiveness
- # Info : How Effective Enemy is against a State
- # An Integer from 0-5 (5: most effective 0: ineffective)
- # Author : Trickster
- # Call Info : Integer State_ID id of the state to check
- #-------------------------------------------------------------------------
- def state_effectiveness(state_id)
- table = [0,5,4,3,2,1,0]
- effective = table[$data_enemies[@enemy_id].state_ranks[state_id]]
- return effective
- end
- #-------------------------------------------------------------------------
- # * Name : Now Exp
- # Info : Gets Actors Next in Current Level
- # Author : Near Fantastica
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def now_exp
- return @exp - @exp_list[@level]
- end
- #-------------------------------------------------------------------------
- # * Name : Next Exp
- # Info : Gets Actors Exp for Next Level
- # Author : Near Fantastica
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def next_exp
- exp = @exp_list[@level+1] > 0 ? @exp_list[@level+1] - @exp_list[@level] : 0
- return exp
- end
- #-------------------------------------------------------------------------
- # * Name : Weapon Ids
- # Info : Gets ALL Weapon IDs - An Array of Weapon Ids
- # Author : Trickster
- # Call Info : No Arguments
- # Comment : Detects @weapon_id and @weapon(n)_id n >= 2
- #-------------------------------------------------------------------------
- def weapon_ids
- equipment = []
- equipment << @weapon_id
- i = 2
- while instance_eval("@weapon#{i}_id") != nil
- equipment << instance_eval("@weapon#{i}_id")
- i += 1
- end
- return equipment
- end
- #-------------------------------------------------------------------------
- # * Name : Armor Ids
- # Info : Gets All Armor IDs - An Array of Armor Ids
- # Author : Trickster
- # Call Info : No Arguments
- # Comment : Detects @armor(n)_id
- #-------------------------------------------------------------------------
- def armor_ids
- equipment = []
- i = 1
- while instance_eval("@armor#{i}_id") != nil
- equipment << instance_eval("@armor#{i}_id")
- i += 1
- end
- return equipment
- end
- #-------------------------------------------------------------------------
- # Name : Get Equipment
- # Info : Gets All Actor's Equipment
- # A Hash in this form {'weapons' => ids, 'armors' => ids}
- # Author : Trickster
- # Call Info : No Arguments
- # Comment : Must Follow Naming Conventions weapon#{n}_id armor#{n}_id
- #-------------------------------------------------------------------------
- def equipment
- @equipment = {'weapons' => [], 'armors' => []}
- @equipment['weapons'].push(@weapon_id)
- i = 1
- while instance_eval("@weapon#{i}_id") != nil
- @equipment['weapons'].push(instance_eval("@weapon#{i}_id"))
- i += 1
- end
- i = 1
- while instance_eval("@armor#{i}_id") != nil
- @equipment['armors'].push(instance_eval("@armor#{i}_id"))
- i += 1
- end
- return @equipment
- end
- #-------------------------------------------------------------------------
- # * Name : Element Test
- # Info : Returns Element Effiency Value
- # An Integer 1-6 representing the effiency
- # Author : Trickster
- # Call Info : One Argument Element_Id the element Id to test
- #-------------------------------------------------------------------------
- def element_test(element_id)
- # Get a numerical value corresponding to element effectiveness
- table = [0,6,5,4,3,2,1]
- result = table[$data_classes[@class_id].element_ranks[element_id]]
- return result
- end
- #-------------------------------------------------------------------------
- # * Name : Weaknesses
- # Info : Returns Enemy Weaknesses
- # An Array of Element Ids for which an A or B effiency
- # Author : Trickster
- # Call Info : None
- #-------------------------------------------------------------------------
- def weaknesses
- weak = []
- MACL::Real_Elements.each {|i| weak << i if [6,5].include?(element_test(i))}
- return weak
- end
- #-------------------------------------------------------------------------
- # * Name : Resistance
- # Info : Returns Enemy Resistance
- # An Array of Element Ids for which an D, E, or F effiency
- # Author : Trickster
- # Call Info : None
- #-------------------------------------------------------------------------
- def resistance
- resists = []
- MACL::Real_Elements.each {|i| resists << i if [1,2,3].include?(element_test(i))}
- return resists
- end
- #-------------------------------------------------------------------------
- # * Name : Next Exp Percent
- # Info : Returns Exp Percent
- # Author : SephirothSpawn
- # Call Info : Two Arguments
- # Integer truth, true for integer, false for float
- # Float points, integer value for number of float points
- #-------------------------------------------------------------------------
- def next_exp_percent(integer = false, float_points = 2)
- lst = @exp_list[@level] > 0 ? @exp_list[@level] : 0
- nxt = @exp_list[@level + 1] > 0 ? @exp_list[@level + 1] : 0
- rst = nxt - @exp
- begin
- n = 100 - (rst.to_f / (nxt - lst) * 100)
- return integer ? Integer(n) : n.float_points(float_points)
- rescue
- return 100
- end
- end
- end
- #==============================================================================
- # ** Game_Party
- #==============================================================================
- class Game_Party
- #-------------------------------------------------------------------------
- # * Name : Equipped Weapon?
- # Info : Does Someone in the party have Weapon Equipped
- # returns true if condition fulfilled false otherwise
- # Author : Trickster
- # Call Info : One Argument - Integer Weapon Id
- #-------------------------------------------------------------------------
- def equipped_weapon?(weapon_id)
- # Run through each actor and return if if weapon equipped
- @actors.each {|actor| return true if actor.weapon_ids.include?(weapon_id)}
- # Don't have it equipped
- return false
- end
- #-------------------------------------------------------------------------
- # * Name : Equipped Armor?
- # Info : Does Soeme in the party have Armor Eqipped
- # returns true if condition fulfilled false otherwise
- # Author : Trickster
- # Call Info : One Argument - Integer Armor Id
- #-------------------------------------------------------------------------
- def equipped_armor?(armor_id)
- # Run through each actor and return if if weapon equipped
- @actors.each {|actor| return true if actor.armor_ids.include?(armor_id)}
- # Don't have it equipped
- return false
- end
- #-------------------------------------------------------------------------
- # * Name : Has Actors?
- # Info : Are These Actor Ids in party?
- # returns true if those actors are in the party
- # Author : Trickster
- # Call Info : Variable Amount Integer Actor actor id to check
- #-------------------------------------------------------------------------
- def has_actors?(*actors)
- # Setup Array
- actor_ids = []
- # Get All Actor IDs
- @actors.each {|actor| actor_ids << actor.id}
- # If All Actors included
- return actor_ids.includes?(*actors)
- end
- #-------------------------------------------------------------------------
- # Name : Strongest Actor in Party
- # Info : Gets Strongest Actor
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def strongest
- array = actors.dup
- array.sort! {|a,b| b.hp - a.hp}
- return array[0]
- end
- #-------------------------------------------------------------------------
- # Name : Weakest Actor in Party
- # Info : Gets Weakest Actor
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def weakest
- array = existing_actors
- array.sort! {|a,b| b.hp - a.hp}
- return array[-1]
- end
- #-------------------------------------------------------------------------
- # Name : Get Existing Actors
- # Info : Gets All Non-Dead Actors
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def existing_actors
- array = []
- @actors.each {|actor| array << actor if actor.exist?}
- return array
- end
- #-------------------------------------------------------------------------
- # * Name : Average Level
- # Info : Returns the Average Level of Party
- # Author : Trickster
- # Call Info : None
- #-------------------------------------------------------------------------
- def average_level
- # Return 0 If 0 members are in the party
- return 0 if @actors.size == 0
- # Initialize local variable sum
- sum = 0
- # Sum Up Values in Array
- @actors.each {|actor| sum += actor.level}
- # Return Average
- return sum / @actors.size
- end
- end
- #==============================================================================
- # ** RGSS.Battle
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # These set of methods specialized in the Spriteset & Scene for battle.
- #
- # Method List:
- # ------------
- #
- # Spriteset_Battle
- # ----------------
- # enemy_sprites
- # actor_sprites
- # find_battler
- #
- # Scene_Battle
- # ------------
- # active_battler
- # priority
- #==============================================================================
- MACL::Loaded << 'RGSS.Battle'
- #==============================================================================
- # ** Spriteset_Battle
- #==============================================================================
- class Spriteset_Battle
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_reader :enemy_sprites
- attr_reader :actor_sprites
- #-------------------------------------------------------------------------
- # Name : Find Sprite Battler
- # Info : Returns Sprite_Battler object if found else nil
- # Author : Trickster
- # Call Info : One Argument, Game_Battler batter battler to search
- #-------------------------------------------------------------------------
- def find_battler(battler)
- # Run Through Each Sprite
- (@actor_sprites + @enemy_sprites).each do |sprite|
- # Return sprite if same battler
- return sprite if sprite.battler == battler
- end
- # Return nil
- return nil
- end
- end
- #==============================================================================
- # ** Scene_Battle
- #==============================================================================
- class Scene_Battle
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_reader :active_battler
- #-------------------------------------------------------------------------
- # Name : Update Priority
- # Info : Priority Update Rate
- # Author : Trickster
- # Call Info : One Argument Integer rating the rating of updating
- # Comment : Allows for easier aliasing of update_phase3
- #-------------------------------------------------------------------------
- def priority(rating = 0)
- flag = true
- flag &&= @enemy_arrow == nil if rating < 5
- flag &&= @actor_arrow == nil if rating < 4
- flag &&= @skill_window == nil if rating < 3
- flag &&= @item_window == nil if rating < 2
- flag &&= !@actor_command_window.active if rating < 1
- return flag
- end
- end
- #==============================================================================
- # ** RGSS.Bitmap.draw
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Methods created for the Bitmap class that handle general drawing functions.
- # Functions include drawing parts of bitmaps and drawing stretched bitmaps.
- #
- # Method List:
- # ------------
- # Bitmap.default_blur_settings=
- # Bitmap.default_blur_settings
- # Bitmap.default_anim_sprite_settings=
- # Bitmap.default_anim_sprite_settings
- # blur_settings=
- # blur_settings
- # anim_sprite_settings=
- # anim_sprite_settings
- # draw_char_bar
- # draw_line
- # draw_box
- # draw_circle
- # draw_ellipse
- # draw_polygon
- # draw_gradient_polygon
- # draw_anim_sprite
- # draw_sprite
- # draw_equipment
- # crop_blt
- # fit_blt
- # full_blt
- # full_fill
- # scale_blt
- # shade_section
- # shade_gradient_section
- #
- # Modified Methods:
- # -----------------
- # initialize
- #==============================================================================
- MACL::Loaded << 'RGSS.Bitmap.draw'
- #==============================================================================
- # ** Bitmap
- #==============================================================================
- class Bitmap
- #--------------------------------------------------------------------------
- # * Class Variable Declaration
- #--------------------------------------------------------------------------
- class_accessor :default_blur_settings
- class_accessor :default_anim_sprite_settings
- #--------------------------------------------------------------------------
- # * Class Variable Declaration
- #--------------------------------------------------------------------------
- Bitmap.default_blur_settings = Blur_Settings
- Bitmap.default_anim_sprite_settings = Anim_Sprite_Settings
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_accessor :blur_settings
- attr_accessor :anim_sprite_settings
- #--------------------------------------------------------------------------
- # * Alias Method
- #--------------------------------------------------------------------------
- alias_method :macl_bitmapdraw_init, :initialize
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(*args)
- # Set draw settings
- @blur_settings = Bitmap.default_blur_settings
- @anim_sprite_settings = Bitmap.default_anim_sprite_settings
- # Original Initialization
- macl_bitmapdraw_init(*args)
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Char Bar
- # Info : Draws a Character Bar
- # Author : Trickster
- # Call Info : Integer X, Y - Defines Position
- # Integer Min, Max - Defines How filled the bar is
- # Integer Width and height - Defines Dimensions
- # String Start Content and Finish
- #-------------------------------------------------------------------------
- def draw_char_bar(x, y, min = 1, max = 1, width = nil, height = 32, start = '[',
- content = 'ヲ', finish = ']', color = Color.new(255, 255, 255))
- # Get Width if width is nil
- width = text_size(start + (content * max) + finish).width if width == nil
- # save color
- saved = font.color
- # Set color
- self.font.color = color
- # Get Bar Text
- bar_text = start + content * min.to_i
- # Draw Bar Text
- draw_text(x, y, width, height, bar_text)
- # Draw Finish
- draw_text(x, y, width, height, finish, 2)
- # Restore Color
- self.font.color = saved
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Line
- # Info : Draws a line from x1,y1 to x2,y2
- # Author : Caesar (Rewrote By Trickster)
- # Call Info : Integer x1, y1, x2, y2 - Points of the line
- # Integer width - Thickness of the line
- # Color color - Color of the line
- # Comments : uses the Digital Differential Analyzer Algorithm
- #-------------------------------------------------------------------------
- def draw_line(x1, y1, x2, y2, width = 1, color = Color.new(255, 255, 255))
- # Return if width is less than or 0
- return if width <= 0
- # Reverse all parameters sent if 2 x is less than the first x
- x1, x2, y1, y2 = x2, x1, y2, y1 if x2 < x1
- # Get S (1/2 width)
- s = width / 2.0
- # If X Coordinates are equal
- if x1 == x2
- # Draw Vertical line
- fill_rect(x1 - s, [y1, y2].min, width, (y2 - y1).abs, color)
- # If Y Coordinates are equal
- elsif y1 == y2
- # Draw Horizontal line
- fill_rect(x1, y1 - s, x2 - x1, width, color)
- end
- # Get Length
- length = x2 - x1 < (y2 - y1).abs ? (y2 - y1).abs : x2 - x1
- # Get Increments
- x_increment, y_increment = (x2 - x1) / length.to_f, (y2 - y1) / length.to_f
- # Get Current X and Y
- x, y = x1, y1
- # While Current X is less than end X
- while x < x2
- # Draw Box of width width and width height
- fill_rect(x-s, y-s, width, width, color)
- # Increment X and Y
- x += x_increment
- y += y_increment
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Box
- # Info : Draws a Box
- # Author : Trickster
- # Call Info : Two to Four Arguments Rect Outer Rectangle to Draw Box
- # Color color color to draw the box in
- #-------------------------------------------------------------------------
- def draw_box(outer, color, width = 1, height = 1)
- fill_rect(outer, color)
- inner = Rect.new(outer.x + width, outer.y + height, outer.width - width * 2,
- outer.height - height * 2)
- fill_rect(inner, Color.new(0, 0, 0, 0))
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Circle
- # Info : Draws A Circle
- # Author : SephirothSpawn
- # Call Info : Integer X and Y Define Position Center Pt of Circle
- # Integer Radius Radius of the Circle to Draw
- # Color color Color of the circle to draw
- #-------------------------------------------------------------------------
- def draw_circle(x, y, radius, color = Color.new(255, 255, 255, 255))
- # Starts From Left
- for i in (x - radius)..(x + radius)
- # Finds Distance From Center
- sa = (x - i).abs
- # Finds X Position
- x_ = i < x ? x - sa : i == x ? x : x + sa
- # Finds Top Vertical Portion
- y_ = Integer((radius ** 2 - sa ** 2) ** 0.5)
- # Draws Vertical Bar
- self.fill_rect(x_, y - y_, 1, y_ * 2, color)
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Ellipse
- # Info : Draws a Ellispse
- # Author : SephirothSpawn
- # Call Info : Four or Five Arguments
- # Four Arguments: x, y, a, b
- # x the center position of circle
- # y the center position of circle
- # a the distance from center to right side
- # b the distance from center to top side
- # Five Arguments: (as above) + color
- # color the color of the circle drawn (defaults to white)
- #-------------------------------------------------------------------------
- def draw_ellipse(x, y, a, b, color = Color.new(255, 255, 255))
- # Converts Each Argument to Float
- x, y, a, b = x.to_f, y.to_f, a.to_f, b.to_f
- # Gets Square of a and b values
- a2, b2 = a * a, b * b
- # If a is smaller or equal to b
- if a <= b
- # Draws Center Line
- self.fill_rect(x, y - b, 1, b * 2, color)
- # Pass from center to right side
- for i in 1..a
- # Gets Y Distance
- y_ = Integer(Math.sqrt(b2 * (1 - (i ** 2) / a2)))
- # Draws Lines on Each Side
- self.fill_rect(x - i, y - y_, 1, y_ * 2, color)
- self.fill_rect(x + i, y - y_, 1, y_ * 2, color)
- end
- # If b is smaller than b
- else
- # Draws Center Line
- self.fill_rect(x - a, y, a * 2, 1, color)
- # Pass from center to right side
- for i in 1..b
- # Gets X Distance
- x_ = Integer(Math.sqrt(a2 * (1 - i ** 2 / b2)))
- # Draws Lines on Top & Bottom
- self.fill_rect(x - x_, y - i, x_ * 2, 1, color)
- self.fill_rect(x - x_, y + i, x_ * 2, 1, color)
- end
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Polygon
- # Info : Draws a Polygon
- # Author : Caesar (Rewrote By Trickster)
- # Call Info : Array vertices - Points of the polygon
- # Integer width - Thickness of the lines
- # Color color - color to draw it in
- # Boolean filled - false outline true filled
- # Integer step - fill steps
- # Comments : Example of vertices setup [[30, 80], [80, 80], [30, 60]]
- #-------------------------------------------------------------------------
- def draw_polygon(vertices, stroke = 1, color = Color.new(255, 255, 255),
- filled = false, step = 1)
- # Return if no width or not enough points
- return if stroke <= 0 or vertices.size <= 2
- # Get Count
- count = vertices.size
- # Get Points
- x1, y1, x2, y2 = vertices[-1] + vertices[0]
- # Draw Line
- draw_line(x1, y1, x2, y2, stroke, color)
- # Shade if filled
- shade_section(cx, cy, x1, y1, x2, y2, stroke, step, color) if filled
- # Run Through with next
- vertices.each_with_next do |start, point|
- # Get Points
- x1, y1, x2, y2 = start + point
- # Draw Line
- draw_line(x1, y1, x2, y2, stroke, color)
- # Shade if filled
- shade_section(cx, cy, x1, y1, x2, y2, stroke, step, color) if filled
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Gradient Polygon
- # Info : Draws a Gradient Polygon (Filled)
- # Author : Caesar (Rewrote By Trickster)
- # Call Info : Array vertices - Points of the polygon
- # Integer width - Thickness of the lines
- # Color color - color to draw it in
- # Boolean filled - false outline true filled
- # Integer step - fill steps
- # Comments : Example of vertices setup [[30, 80], [80, 80], [30, 60]]
- #-------------------------------------------------------------------------
- def draw_gradient_polygon(cx, cy, vertices, stroke = 1,
- start_color = Color.new(255, 255, 255), end_color = Color.new(0, 0, 0),
- step = 1)
- # Return if no width or not enough points
- return if stroke <= 0 or vertices.size <= 2
- # Get Count
- count = vertices.size
- # Get Points
- x1, y1, x2, y2 = vertices[-1] + vertices[0]
- # Draw Line
- draw_line(x1, y1, x2, y2, stroke, end_color)
- shade_gradient_section(cx, cy, x1, y1, x2, y2, 2, 1, start_color, end_color)
- # Run Through with next
- vertices.each_with_next do |start, point|
- # Get Points
- x1, y1, x2, y2 = start + point
- # Draw Line
- draw_line(x1, y1, x2, y2, stroke, end_color)
- shade_gradient_section(cx, cy, x1, y1, x2, y2, 1, 0.4, start_color, end_color)
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Animated Sprite
- # Info : Draws an Animated Sprite
- # Author : SephirothSpawn
- # Call Info : Six to Seven Arguments Integer x and y Defines Position
- # Integer W and H Defines Dimensions
- # String name Character Set Graphic
- # Integer hue sets hue displacement
- # Integer stance pose for character
- #-------------------------------------------------------------------------
- def draw_anim_sprite(x, y, w, h, name, hue, stance = 0)
- # Gets Frame
- frame = (Graphics.frame_count / @anim_sprite_settings['f']) %
- @anim_sprite_settings['w']
- # Draw Sprite
- draw_sprite(x, y, w, h, name, hue, stance, frame)
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Sprite
- # Info : Draws an Animated Sprite
- # Author : SephirothSpawn
- # Call Info : Six to Seven Arguments Integer x and y Defines Position
- # Integer W and H Defines Dimensions
- # String name Character Set Graphic
- # Integer hue sets hue displacement
- # Integer stance pose for character
- # Integer frame frame of pose to show
- #-------------------------------------------------------------------------
- def draw_sprite(x, y, w, h, name, hue, stance = 0, frame = 0)
- # Gets Bitmap
- bitmap = RPG::Cache.character(name, hue)
- # Bitmap Division
- cw = bitmap.width / @anim_sprite_settings['w']
- ch = bitmap.height / @anim_sprite_settings['h']
- # Gets Animation Offsets
- x_off, y_off = cw * frame, ch * stance
- # Clears Area
- self.fill_rect(Rect.new(x, y, w, h), Color.new(0, 0, 0, 0))
- # Draws Bitmap
- self.scale_blt(Rect.new(x, y, w, h), bitmap,
- Rect.new(x_off, y_off, cw, ch))
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Equip
- # Info : Draws Item or Equipment icon and name
- # Author : SephirothSpawn
- # Call Info : Three to Eight Arguments
- # Item - RPG::Item, RPG::Weapon or RPG::Armor
- # X - Position Icon & Text Being drawn
- # Y - Position Icon & Test Being drawn
- # W - Width for Icon & Text to be drawn in
- # H - Height for Icon & Text to be drawn in (24 min)
- # A - Alignment of text
- # T - Type of icon to be used when nil item (See MACL Setup)
- # Txt - Text when Item is nil
- #-------------------------------------------------------------------------
- def draw_equipment(i, x, y, w = 212, h = 32, a = 0, t = 0, txt = 'Nothing')
- # If Nil Item
- if i.nil?
- # Gets Unequipped Bitmap & Font Color
- bitmap = RPG::Cache.icon(Draw_Equipment_Icon_Settings[t])
- c = Color.disabled
- # If Item Exist
- else
- # Gets Bitmap, Font Color & Item Name
- bitmap = RPG::Cache.icon(i.icon_name)
- c, txt = Color.normal, i.name
- end
- # Sets Font Color, Draws Icon & Text
- old_color = self.font.color.dup
- self.blt(x + 4, y + (h - 24) / 2, bitmap, bitmap.rect, c.alpha)
- self.font.color = c
- self.draw_text(x + 32, y, w - 28, h, txt, a)
- self.font.color = old_color
- end
- #-------------------------------------------------------------------------
- # * Name : Crop BLT
- # Info : Crops to Width and Height, if needed
- # Author : Trickster
- # Call Info : Five - Eight Arguments, Integer X and Y Define Position
- # Integer Width and Height Defines Dimensions
- # Bitmap bitmap bitmap to transfer
- # Integer dir, part to crop
- # Integer align, alignment (0:left, 1:center, 2:right)
- # Integer opacity, opacity
- #-------------------------------------------------------------------------
- def crop_blt(x, y, width, height, bitmap, dir = 1, align = 1, opacity = 255)
- # Get Width and Height
- w, h = bitmap.width, bitmap.height
- # If Can Fit
- if w < width and h < height
- # Branch By alignment
- case align
- when 1
- # Add To Make it in the center
- x += (width - w) / 2
- when 2
- # Add to Make it in the right
- x += width - w
- end
- # Draw Bitmap
- full_blt(x, y, bitmap, opacity)
- # Return
- return
- end
- # Get I and J (Position)
- i, j = dir % 3, dir / 3
- # Initialize Crop X and Crop Y (Left Top Align)
- crop_x, crop_y = 0, 0
- # Branch by Horizontal Position
- case i
- when 1
- # Center Align
- crop_x = (w - width) / 2
- when 2
- # Right Align
- crop_x = w - width
- end
- # Branch by Vertical Position
- case j
- when 1
- # Center Align
- crop_y = (h - height) / 2
- when 2
- # Bottom Align
- crop_y = h - height
- end
- # Draw Bitmap Cropped
- blt(x, y, bitmap, Rect.new(crop_x, crop_y, width, height), opacity)
- end
- #-------------------------------------------------------------------------
- # * Name : Fit BLT
- # Info : Zooms to Width and Height, if needed
- # Author : Trickster
- # Call Info : Five-Seven Arguments, Integer X and Y Define Position
- # Integer Width and Height Defines Dimensions
- # Bitmap bitmap bitmap to transfer
- # Integer opacity, opacity
- # Integer Align, Alignment
- #-------------------------------------------------------------------------
- def fit_blt(x, y, width, height, bitmap, opacity = 255, align = 1)
- # Get Width and Height
- w, h = bitmap.width, bitmap.height
- # If Width or Height is Greater
- if w > width or h > height
- # Get Conversion
- conversion = w / h.to_f
- # if Conversion is smaller than or 1
- if conversion <= 1
- # Get Zoom X and Y
- zoom_x, zoom_y = width * conversion, height
- else
- # Get Zoom X and Y
- zoom_x, zoom_y = width, height / conversion
- end
- # Branch By Align
- case align
- when 1
- # Add To Make it in the center
- x += (width - zoom_x) / 2
- when 2
- # Add to Make it in the right
- x += width - zoom_x
- end
- # Get Destination Rect
- dest_rect = Rect.new(x, y, zoom_x, zoom_y)
- # Stretch to Fit
- stretch_blt(dest_rect, bitmap, bitmap.rect, opacity)
- else
- # Branch By alignment
- case align
- when 1
- # Add To Make it in the center
- x += (width - w) / 2
- when 2
- # Add to Make it in the right
- x += width - w
- end
- # Draw Bitmap
- full_blt(x, y, bitmap, opacity)
- end
- end
- #-------------------------------------------------------------------------
- # Name : Full Block Transfer
- # Info : Draws a Bitmap
- # Author : Trickster
- # Call Info : Three or Four Arguments
- # Integer X and Y define position
- # Bitmap bitmap is the bitmap to draw
- # Integer Opacity is the transparency (defaults to 255)
- # Comment : Lazy method for people who don't want to type bitmap.rect
- #-------------------------------------------------------------------------
- def full_blt(x, y, bitmap, opacity = 255)
- blt(x, y, bitmap, bitmap.rect, opacity)
- end
- #-------------------------------------------------------------------------
- # Name : Full Fill
- # Info : Fills Whole Bitmap
- # Author : Trickster
- # Call Info : One Argument, Color color the color to be filled
- # Comment : Lazy method for people who don't want to type bitmap.rect
- #-------------------------------------------------------------------------
- def full_fill(color)
- fill_rect(rect, color)
- end
- #-------------------------------------------------------------------------
- # * Name : Scale BLT
- # Info : Scales Bitmap to fit Rectangle
- # Author : SephirothSpawn
- # Call Info : Two to Four Arguments
- # Rect Dest_Rect - Destination Rectangle
- # Bitmap Src_Bitmap - Source Bitmap
- # Rect Src_Rect - Source Rectangle for Bitmap
- # Integer Opacity - Opacity
- #-------------------------------------------------------------------------
- def scale_blt(dest_rect, src_bitmap, src_rect = src_bitmap.rect, o = 255)
- w, h = src_rect.width, src_rect.height
- scale = [w / dest_rect.width.to_f, h / dest_rect.height.to_f].max
- ow, oh = (w / scale).to_i, (h / scale).to_i
- ox, oy = (dest_rect.width - ow) / 2, (dest_rect.height - oh) / 2
- stretch_blt(Rect.new(ox + dest_rect.x, oy + dest_rect.y, ow, oh),
- src_bitmap, src_rect, o)
- end
- #-------------------------------------------------------------------------
- # * Name : Shade Section
- # Info : Shades a section from (cx,cy), (x1,y1), (x2,y2)
- # Author : Trickster
- # Call Info : Six to Nine Arguments
- # Integer cx, cy, x1, y1, x2, y2 - Points
- # Integer Thick - Line Thickness
- # Integer Step - how many lines to draw (lower = higher accuracy)
- # Color color - color to shade in
- #-------------------------------------------------------------------------
- def shade_section(cx, cy, x1, y1, x2, y2, thick = 1, step = 1,
- color = Color.new(255, 255, 255))
- # Reverse all parameters sent if 2 x is less than the first x
- x1, x2, y1, y2 = x2, x1, y2, y1 if x2 < x1
- # Get Slope
- slope = (y2 - y1).to_f / (x2 - x1)
- # If Slope is infinite
- if slope.infinite?
- y1.step(y2, step) {|y| draw_line(cx, cy, x1, y, thick, color)}
- # If Slope is zero
- elsif slope.zero?
- x1.step(x2, step) {|x| draw_line(cx, cy, x, y1, thick, color)}
- elsif not slope.nan?
- # Get Y intercept
- yint = y1 - slope * x1
- x1.step(x2, step) {|x| draw_line(cx, cy, x, slope * x + yint, thick, color)}
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Shade Gradient Section
- # Info : Shades a section from (cx,cy), (x1,y1), (x2,y2) w/ gradient
- # Author : Trickster
- # Call Info : Six to Ten Arguments
- # Integer cx, cy, x1, y1, x2, y2 - Points
- # Integer Thick - Line Thickness
- # Integer Step - how many lines to draw (lower = higher accuracy)
- # Color start_color, end_color - Start and end colors
- #-------------------------------------------------------------------------
- def shade_gradient_section(cx, cy, x1, y1, x2, y2, thick = 1, step = 1,
- start_color = Color.new(0, 0, 0), end_color = start_color)
- # Reverse all parameters sent if 2 x is less than the first x
- x1, x2, y1, y2 = x2, x1, y2, y1 if x2 < x1
- # Get Slope
- slope = (y2 - y1).to_f / (x2 - x1)
- # If Slope is infinite
- if slope.infinite?
- y1.step(y2, step) {|y| draw_gradient_line(cx, cy, x1, y, thick, start_color, end_color)}
- # If Slope is zero
- elsif slope.zero?
- x1.step(x2, step) {|x| draw_gradient_line(cx, cy, x, y1, thick, start_color, end_color)}
- elsif not slope.nan?
- # Get Y intercept
- yint = y1 - slope * x1
- x1.step(x2, step) {|x| draw_gradient_line(cx, cy, x, slope * x + yint, thick, start_color, end_color)}
- end
- end
- end
- #==============================================================================
- # ** RGSS.Bitmap.gradient
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Methods created for the Bitmap class that draws different types of gradient
- # bars and other things some gradients from colors and others from images.
- #
- # Method List:
- # ------------
- # draw_gradient_line
- # draw_meter_line
- # draw_seph_gradient_bar
- # draw_seph_rev_gradient_bar
- # draw_slant_bar
- # draw_rev_slant_bar
- # draw_trick_circular_bar
- # draw_trick_rev_cirular_bar
- # draw_seph_v_gradient_bar
- # draw_seph_v_rev_gradient_bar
- # draw_v_slant_bar
- # draw_v_rev_slant_bar
- # draw_trick_v_circular_bar
- # draw_trick_v_rev_circular_bar
- # draw_cw_arc_region
- # draw_ccw_arc_region
- # draw_cw_grad_arc_region
- # draw_ccw_grad_arc_region
- # draw_trick_function_bar
- # draw_trick_gradient_bar
- # draw_trick_gradient_bar_back
- # draw_trick_gradient_bar_sub
- # shade_gradient_section
- # v_gradient_pixel_change
- # h_gradient_pixel_change
- #
- # Deprecated Stuff (V 2.0):
- # -------------------------
- # trick_draw_gradient_bar_circ
- # trick_draw_gradient_bar_func
- #
- # Renamed Stuff (V 2.0):
- # ----------------------
- # trick_draw_circular_bar -> draw_trick_circular_bar
- # trick_draw_function_bar -> draw_trick_function_bar
- #==============================================================================
- MACL::Loaded << 'RGSS.Bitmap.gradient'
- #==============================================================================
- # ** Bitmap
- #==============================================================================
- class Bitmap
- #-------------------------------------------------------------------------
- # * Name : Draw Gradient Line
- # Info : Draws a Gradient Line From (x, y) to (x1, y1) of a thickness
- # Author : RXS (Edited by Trickster)
- # Call Info : Four to Seven Arguments
- # Integer start_x, start_y, end_x, end_y - Defines Position
- # Integer thick - thickness of the line
- # Color start_color and end_color Colors for the line
- #-------------------------------------------------------------------------
- def draw_gradient_line(start_x, start_y, end_x, end_y, width = 1,
- start_color = Color.new(0, 0, 0), end_color = start_color)
- # Get Distance
- distance = (start_x - end_x).abs + (start_y - end_y).abs
- # If Same Color
- if end_color == start_color
- # Run Through from 1 to distance
- (1..distance).each do |i|
- # Get X and Y
- x = (start_x + (end_x.to_f - start_x) * i / distance).to_i
- y = (start_y + (end_y.to_f - start_y) * i / distance).to_i
- # Fill Rectangle
- fill_rect(x, y, width, width, start_color)
- end
- # Different Colors
- else
- # Run Through from 1 to distance
- (1..distance).each do |i|
- # Get Percent Disance and I Distance
- per_dist, i_dist = (distance - i.to_f) / distance, i.to_f / distance
- # Get Position
- x = (start_x + (end_x.to_f - start_x) * i_dist).to_i
- y = (start_y + (end_y.to_f - start_y) * i_dist).to_i
- # Get Color Information
- r = start_color.red * per_dist + end_color.red * i_dist
- g = start_color.green * per_dist + end_color.green * i_dist
- b = start_color.blue * per_dist + end_color.blue * i_dist
- a = start_color.alpha * per_dist + end_color.alpha * i_dist
- # Fill Rectangle
- fill_rect(x, y, width, width, Color.new(r, g, b, a))
- end
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Meter Line
- # Info : Draws a Slanted Gradient Bar
- # Author : XRXS Edited By Trickster
- # Call Info : Four to Nine Arguments Integer x and y Define Position
- # Integer min and max define percentage of bar's fill
- # Integer width and height defines dimensions
- # Color bar_start bar_end and background Defines Colors for bar
- #-------------------------------------------------------------------------
- def draw_meter_line(x, y, min, max, width = 156, height = 4,
- bar_start = Color.new(255, 0, 0, 192), bar_end = Color.new(255, 255, 0, 192),
- background = Color.new(0, 0, 0, 128))
- # Get Fill Width
- w = width * min / max
- # Do Four Times
- 4.times do
- # Draws Background
- fill_rect(x + 8, y + 4, width, height / 4, background)
- # Draw Gradient Line
- draw_gradient_line(x, y, x + w, y, height / 4, bar_start, bar_end)
- # Decrement X
- x -= 1
- # Increment Y by height / 4
- y += height / 4
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Gradient Bar
- # Info : Draws a Gradient Bar
- # Author : SephirothSpawn
- # Call Info : Four to Nince Arguments
- # Integer x and y Defines Position
- # Integer min and max Defines Dimensions of Bar
- # Start Bar Color and End Color - Colors for Gradient Bar
- # Background Bar Color
- #-------------------------------------------------------------------------
- def draw_seph_gradient_bar(x, y, cur, max, width = 152, height = 8,
- s_color = Color.red, e_color = Color.yellow, b_color = Color.black)
- # Draw Border
- self.fill_rect(x, y, width, height, b_color)
- # Draws Bar
- for i in 1...((cur / max.to_f) * (width - 1))
- c = Color.color_between(s_color, e_color, (i / width.to_f))
- self.fill_rect(x + i, y + 1, 1, height - 2, c)
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Reverse Gradient Bar
- # Info : Draws a Gradient Bar
- # Author : SephirothSpawn
- # Call Info : Four to Nine Arguments
- # Integer x and y Defines Position
- # Integer min and max Defines Dimensions of Bar
- # Start Bar Color and End Color - Colors for Gradient Bar
- # Background Bar Color
- #-------------------------------------------------------------------------
- def draw_seph_rev_gradient_bar(x, y, cur, max, width = 152, height = 8,
- s_color = Color.red, e_color = Color.yellow, b_color = Color.black)
- # Draw Border
- self.fill_rect(x, y, width, height, b_color)
- # Draws Bar
- for i in 1...((cur / max.to_f) * (width - 1))
- c = Color.color_between(s_color, e_color, (i / width.to_f))
- self.fill_rect(x + width - 1 - i, y + 1, 1, height - 2, c)
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Slant Bar
- # Info : Draws a slanted Gradient Bar
- # Author : SephirothSpawn
- # Call Info : Four to Nine Arguments
- # Integer x and y Defines Position
- # Integer min and max Defines Dimensions of Bar
- # Start Bar Color and End Color - Colors for Gradient Bar
- # Background Bar Color
- #-------------------------------------------------------------------------
- def draw_slant_bar(x, y, cur, max, width = 152, height = 8,
- s_color = Color.red, e_color = Color.yellow, b_color = Color.black)
- # Draw Border
- for i in 0..height
- self.fill_rect(x + i, y + height - i, width - height, 1, b_color)
- end
- # Draws Bar
- for i in 1...((cur / max.to_f) * (width - height - 1))
- for j in 1...(height)
- c = Color.color_between(s_color, e_color, (i / width.to_f))
- self.fill_rect(x + i + j, y + height - j, 1, 1, c)
- end
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Reverse Slant Bar
- # Info : Draws a slanted Gradient Bar
- # Author : SephirothSpawn
- # Call Info : Four to Nine Arguments
- # Integer x and y Defines Position
- # Integer min and max Defines Dimensions of Bar
- # Start Bar Color and End Color - Colors for Gradient Bar
- # Background Bar Color
- #-------------------------------------------------------------------------
- def draw_rev_slant_bar(x, y, cur, max, width = 152, height = 8,
- s_color = Color.red, e_color = Color.yellow, b_color = Color.black)
- # Draw Border
- for i in 0..height
- self.fill_rect(x + i, y + height - i, width - height, 1, b_color)
- end
- # Draws Bar
- for i in 1...((cur / max.to_f) * (width - height - 1))
- for j in 1...(height)
- c = Color.color_between(s_color, e_color, (i / width.to_f))
- self.fill_rect(x + width - 1 - i - j, y + j, 1, 1, c)
- end
- end
- end
- #-------------------------------------------------------------------------
- # Name : Draw Circular Gradient Bar
- # Info : Draws a Circular Gradient Bar
- # Author : Trickster
- # Call Info : Six to Nine Arguments
- # Integer X, Y, Width, Height, Current, and Max
- # Color start, finish, back all default to Black
- # X and Y Define Position
- # Width and Height defines dimensions
- # Current Defines How Much of the Bar to Draw
- # Max Defines the Maximum Value
- # start, finish, back is the starting, ending, and back color
- #-------------------------------------------------------------------------
- def draw_trick_circular_bar(x, y, width, height, current, max,
- start = Color.red, finish = Color.yellow, back = Color.black)
- # Draw Background
- radius = height / 2
- # Draw Rectangle Center
- fill_rect(x + radius, y, width - height, height, back)
- # Draws Ends
- (radius + 1).times do |x1|
- # Get Y
- y1 = Math.sqrt(radius ** 2 - (radius - x1) ** 2).round
- # Draw Line of Back Color at Left Edge
- fill_rect(x + x1, y - y1 + radius, 1, 2 * y1, back)
- # Draw Line of Back Color at Right Edge
- fill_rect(x + width - x1, y - y1 + radius, 1, 2 * y1, back)
- end
- # Get Percentage
- percentage = current / max.to_f
- # Return if not a finite number
- return if not percentage.finite?
- # Decrease Width and Height increase x and y
- x, y, width, height = x + 2, y + 2, width - 4, height - 4
- # Get new Radius
- radius = height / 2
- # Get Bar Width
- barwidth = width * percentage
- # Draws Left End
- (radius + 1).times do |x1|
- # Stop if Past Width
- break if x1 > barwidth
- # Get Y
- y1 = Math.sqrt(radius ** 2 - (radius - x1) ** 2).round
- # Get Color
- color = Color.color_between(start, finish, (x1 / width.to_f))
- # Draw Line
- fill_rect(x + x1, y - y1 + radius, 1, 2 * y1, color)
- end
- # Run From Radius upto Rectangles End
- (width - height + 1).times do |t|
- # Get X1
- x1 = t + radius
- # Break if Past Width
- break if x1 > barwidth
- # Get Color
- color = Color.color_between(start, finish, (x1 / width.to_f))
- # Draw Line
- fill_rect(x + x1, y, 1, height, color)
- end
- # Draws Right End
- radius.times do |t|
- # Get X
- x1 = width - radius + t
- # Stop if Past Width
- break if x1 > barwidth
- # Get Y
- y1 = Math.sqrt(radius ** 2 - t ** 2).round
- # Get Color
- color = Color.color_between(start, finish, (x1 / width.to_f))
- # Draw Line
- fill_rect(x + x1, y - y1 + radius, 1, 2 * y1, color)
- end
- end
- #-------------------------------------------------------------------------
- # Name : Draw Reverse Circular Gradient Bar
- # Info : Draws a Circular Gradient Bar
- # Author : Trickster / SephirothSpawn
- # Call Info : Six to Nine Arguments
- # Integer X, Y, Width, Height, Current, and Max
- # Color start, finish, back all default to Black
- # X and Y Define Position
- # Width and Height defines dimensions
- # Current Defines How Much of the Bar to Draw
- # Max Defines the Maximum Value
- # start, finish, back is the starting, ending, and back color
- #-------------------------------------------------------------------------
- def draw_trick_rev_circular_bar(x, y, width, height, current, max,
- start = Color.red, finish = Color.yellow, back = Color.black)
- # Draw Background
- radius = height / 2
- # Draw Rectangle Center
- fill_rect(x + radius, y, width - height, height, back)
- # Draws Ends
- (radius + 1).times do |x1|
- # Get Y
- y1 = Math.sqrt(radius ** 2 - (radius - x1) ** 2).round
- # Draw Line of Back Color at Left Edge
- fill_rect(x + x1, y - y1 + radius, 1, 2 * y1, back)
- # Draw Line of Back Color at Right Edge
- fill_rect(x + width - x1, y - y1 + radius, 1, 2 * y1, back)
- end
- # Get Percentage
- percentage = current / max.to_f
- # Return if not a finite number
- return if not percentage.finite?
- # Decrease Width and Height increase x and y
- x, y, width, height = x + 2, y + 2, width - 4, height - 4
- # Get new Radius
- radius = height / 2
- # Get Bar Width
- barwidth = width * percentage
- # Draws Left End
- (radius + 1).times do |x1|
- # Stop if Past Width
- break if x1 > barwidth
- # Get Y
- y1 = Math.sqrt(radius ** 2 - (radius - x1) ** 2).round
- # Get Color
- color = Color.color_between(start, finish, (x1 / width.to_f))
- # Draw Line
- fill_rect(x + width - x1, y - y1 + radius, 1, 2 * y1, color)
- end
- # Run From Radius upto Rectangles End
- (width - height + 1).times do |t|
- # Get X1
- x1 = t + radius
- # Break if Past Width
- break if x1 > barwidth
- # Get Color
- color = Color.color_between(start, finish, (x1 / width.to_f))
- # Draw Line
- fill_rect(x + width - x1, y, 1, height, color)
- end
- # Draws Right End
- radius.times do |t|
- # Get X
- x1 = width - radius + t
- # Stop if Past Width
- break if x1 > barwidth
- # Get Y
- y1 = Math.sqrt(radius ** 2 - t ** 2).round
- # Get Color
- color = Color.color_between(start, finish, (x1 / width.to_f))
- # Draw Line
- fill_rect(x + width - x1, y - y1 + radius, 1, 2 * y1, color)
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Vertical Gradient Bar
- # Info : Draws a Gradient Bar
- # Author : SephirothSpawn
- # Call Info : Four to Nine Arguments
- # Integer x and y Defines Position
- # Integer min and max Defines Dimensions of Bar
- # Start Bar Color and End Color - Colors for Gradient Bar
- # Background Bar Color
- #-------------------------------------------------------------------------
- def draw_seph_v_gradient_bar(x, y, cur, max, width = 8, height = 152,
- s_color = Color.red, e_color = Color.yellow, b_color = Color.black)
- # Draw Border
- self.fill_rect(x, y, width, height, b_color)
- # Draws Bar
- for i in 1...((cur / max.to_f) * (height - 1))
- c = Color.color_between(s_color, e_color, (i / height.to_f))
- self.fill_rect(x + 1, y + i, width - 2, 1, c)
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Vertical Reverse Gradient Bar
- # Info : Draws a Gradient Bar
- # Author : SephirothSpawn
- # Call Info : Four to Nine Arguments
- # Integer x and y Defines Position
- # Integer min and max Defines Dimensions of Bar
- # Start Bar Color and End Color - Colors for Gradient Bar
- # Background Bar Color
- #-------------------------------------------------------------------------
- def draw_seph_v_rev_gradient_bar(x, y, cur, max, width = 8, height = 152,
- s_color = Color.red, e_color = Color.yellow, b_color = Color.black)
- # Draw Border
- self.fill_rect(x, y, width, height, b_color)
- # Draws Bar
- for i in 1...((cur / max.to_f) * (height - 1))
- c = Color.color_between(s_color, e_color, (i / height.to_f))
- self.fill_rect(x + 1, y + height - 1 - i, width - 2, 1, c)
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Vertical Slant Bar
- # Info : Draws a slanted Gradient Bar
- # Author : SephirothSpawn
- # Call Info : Four to Nice Arguments
- # Integer x and y Defines Position
- # Integer min and max Defines Dimensions of Bar
- # Start Bar Color and End Color - Colors for Gradient Bar
- # Background Bar Color
- #-------------------------------------------------------------------------
- def draw_v_slant_bar(x, y, cur, max, width = 8, height = 152,
- s_color = Color.red, e_color = Color.yellow, b_color = Color.black)
- # Draw Border
- for i in 0..width
- self.fill_rect(x + i, y + i, 1, height - width, b_color)
- end
- # Draws Bar
- for i in 1...((cur / max.to_f) * (height - width - 1))
- for j in 1...(width)
- c = Color.color_between(s_color, e_color, (i / height.to_f))
- self.fill_rect(x + j, y + i + j, 1, 1, c)
- end
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Vertical Reverse Slant Bar
- # Info : Draws a slanted Gradient Bar
- # Author : SephirothSpawn
- # Call Info : Four to Nine Arguments
- # Integer x and y Defines Position
- # Integer min and max Defines Dimensions of Bar
- # Start Bar Color and End Color - Colors for Gradient Bar
- # Background Bar Color
- #-------------------------------------------------------------------------
- def draw_v_rev_slant_bar(x, y, cur, max, width = 8, height = 152,
- s_color = Color.red, e_color = Color.yellow, b_color = Color.black)
- # Draw Border
- for i in 0..width
- self.fill_rect(x + i, y + i, 1, height - width, b_color)
- end
- # Draws Bar
- for i in 1...( (cur / max.to_f) * (height - width - 1))
- for j in 1...(width)
- c = Color.color_between(s_color, e_color, (i / height.to_f))
- self.fill_rect(x + width - j, y + height - i - j - 1, 1, 1, c)
- end
- end
- end
- #-------------------------------------------------------------------------
- # Name : Draw Vertical Circular Gradient Bar
- # Info : Draws a Circular Gradient Bar
- # Author : Trickster / SephirothSpawn
- # Call Info : Six to Nine Arguments
- # Integer X, Y, Width, Height, Current, and Max
- # Color start, finish, back all default to Black
- # X and Y Define Position
- # Width and Height defines dimensions
- # Current Defines How Much of the Bar to Draw
- # Max Defines the Maximum Value
- # start, finish, back is the starting, ending, and back color
- #-------------------------------------------------------------------------
- def draw_trick_v_circular_bar(x, y, width, height, current, max,
- start = Color.red, finish = Color.yellow, back = Color.black)
- # Draw Background
- radius = width / 2
- # Draw Rectangle Center
- fill_rect(x, y + radius, width, height - width, back)
- # Draws Ends
- (radius + 1).times do |y1|
- # Get X
- x1 = Math.sqrt(radius ** 2 - (radius - y1) ** 2).round
- # Draw Line of Back Color at Left Edge
- fill_rect(x - x1 + radius, y + y1, 2 * x1, 1, back)
- # Draw Line of Back Color at Right Edge
- fill_rect(x - x1 + radius, y + height - y1, 2 * x1, 1, back)
- end
- # Get Percentage
- percentage = current / max.to_f
- # Return if not a finite number
- return if not percentage.finite?
- # Decrease Width and Height increase x and y
- x, y, width, height = x + 2, y + 2, width - 4, height - 4
- # Get new Radius
- radius = width / 2
- # Get Bar Height
- barheight = height * percentage
- # Draws Top End
- (radius + 1).times do |y1|
- # Stop if Past Height
- break if y1 > barheight
- # Get T (Parameter)
- t = radius - y1
- # Get X
- x1 = Math.sqrt(radius ** 2 - t ** 2).round
- # Get Color
- color = Color.color_between(start, finish, (y1 / height.to_f))
- # Draw Line
- fill_rect(x - x1 + radius, y + y1, 2 * x1, 1, color)
- end
- # Run From Radius upto Rectangles End
- (height - width + 1).times do |t|
- # Get Y1
- y1 = t + radius
- # Break if Past Width
- break if y1 > barheight
- # Get Color
- color = Color.color_between(start, finish, (y1 / height.to_f))
- # Draw Line
- fill_rect(x, y + y1, width, 1, color)
- end
- # Draws Bottom End
- radius.times do |t|
- # Get Y
- y1 = height - radius + t
- # Get X
- x1 = Math.sqrt(radius ** 2 - t ** 2).round
- # Stop if Past Height
- break if y1 > barheight
- # Get Color
- color = Color.color_between(start, finish, (y1 / height.to_f))
- # Draw Line
- fill_rect(x - x1 + radius, y + y1, 2 * x1, 1, color)
- end
- end
- #-------------------------------------------------------------------------
- # Name : Draw Vertical Reverse Circular Gradient Bar
- # Info : Draws a Circular Gradient Bar
- # Author : Trickster / SephirothSpawn
- # Call Info : Six to Nine Arguments
- # Integer X, Y, Width, Height, Current, and Max
- # Color start, finish, back all default to Black
- # X and Y Define Position
- # Width and Height defines dimensions
- # Current Defines How Much of the Bar to Draw
- # Max Defines the Maximum Value
- # start, finish, back is the starting, ending, and back color
- #-------------------------------------------------------------------------
- def draw_trick_v_rev_circular_bar(x, y, width, height, current, max,
- start = Color.red, finish = Color.yellow, back = Color.black)
- # Draw Background
- radius = width / 2
- # Draw Rectangle Center
- fill_rect(x, y + radius, width, height - width, back)
- # Draws Ends
- (radius + 1).times do |y1|
- # Get X
- x1 = Math.sqrt(radius ** 2 - (radius - y1) ** 2).round
- # Draw Line of Back Color at Left Edge
- fill_rect(x - x1 + radius, y + y1, 2 * x1, 1, back)
- # Draw Line of Back Color at Right Edge
- fill_rect(x - x1 + radius, y + height - y1, 2 * x1, 1, back)
- end
- # Get Percentage
- percentage = current / max.to_f
- # Return if not a finite number
- return if not percentage.finite?
- # Decrease Width and Height increase x and y
- x, y, width, height = x + 2, y + 2, width - 4, height - 4
- # Get new Radius
- radius = width / 2
- # Get Bar Height
- barheight = height * percentage
- # Draws Bottom End
- (radius + 1).times do |y1|
- # Stop if Past Height
- break if y1 > barheight
- # Get X
- x1 = Math.sqrt(radius ** 2 - (radius - y1) ** 2).round
- # Get Color
- color = Color.color_between(start, finish, (y1 / height.to_f))
- # Draw Line
- fill_rect(x - x1 + radius, y + height - y1, 2 * x1, 1, color)
- end
- # Run From Radius upto Rectangles End
- (height - width + 1).times do |t|
- # Get Y1
- y1 = t + radius
- # Break if Past Width
- break if y1 > barheight
- # Get Color
- color = Color.color_between(start, finish, (y1 / height.to_f))
- # Draw Line
- fill_rect(x, y + height - y1, width, 1, color)
- end
- # Draws Bottom End
- radius.times do |t|
- # Get Y
- y1 = radius - t
- # Stop if Past Height
- break if height - y1 > barheight
- # Get X
- x1 = Math.sqrt(radius ** 2 - t ** 2).round
- # Get Color
- color = Color.color_between(start, finish, ((height - y1) / height.to_f))
- # Draw Line
- fill_rect(x - x1 + radius, y + y1, 2 * x1, 1, color)
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Clockwise Circular Arc Region
- # Info : Draws Circular Gradient clockwise, from s_angle to e_angle
- # Author : SephirothSpawn
- # Call Info : Eight to Nine Arguments
- # center_x and center_y
- # min_radius, max_radius
- # s_angle & e_angle (in Degrees)
- # currect_value & max_value
- # bar_color
- #-------------------------------------------------------------------------
- def draw_cw_arc_region(x, y, min_rad, max_rad, s_angle, e_angle,
- cur_v, max_v, color = Color.red)
- # Calculate Inner Regions
- inner_region = {}
- for i in 0..min_rad
- y_ = Integer((min_rad ** 2 - i ** 2) ** 0.5)
- inner_region[x + i] = y_
- inner_region[x - i] = y_
- end
- # Make Degrees between 0 - 360
- s_angle %= 360 ; e_angle %= 360
- # Make s_angle Greater than e_angle
- s_angle += 360 if s_angle < e_angle
- # Calculate Difference
- diff = s_angle - e_angle
- # Get Percent Difference
- p_diff = Integer(diff * cur_v / max_v.to_f)
- # Modify e_angle with percent Diffence
- e_angle = s_angle - p_diff
- # Pass from left to right
- for i in (x - max_rad)..(x + max_rad)
- # Get Y max at that pixel
- y_max = Integer((max_rad ** 2 - (x - i).abs ** 2) ** 0.5)
- # Pass from top to bottom
- for j in (y - y_max)..(y + y_max)
- # If within inner-region limits
- if i.between?(x - min_rad, x + min_rad)
- # If Inner region has key
- if inner_region.has_key?(i)
- # Get Inner Value
- inner = inner_region[i]
- # Skip if Between inner region limits
- next if j.between?(x - inner, x + inner)
- end
- end
- # Gets Angle of pixel from center
- a = Math.atan2((j - y).abs, (i - x).abs.to_f) * 180 / Math::PI
- # Get 360 Degree Angle
- if (i - x) > 0
- a = 360 - a if (j - y) > 0
- else
- a = 180 + ((j - y) > 0 ? a : -a)
- end
- # Set Pixel if Between Angles
- if Math.cw_between_angles?(a, s_angle, e_angle)
- set_pixel(i, j, color)
- end
- end
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Counter-Clockwise Circular Arc Region
- # Info : Draws Circular Gradient ccw, from s_angle to e_angle
- # Author : SephirothSpawn
- # Call Info : Eight to Nine Arguments
- # center_x and center_y
- # min_radius, max_radius
- # s_angle & e_angle (in Degrees)
- # currect_value & max_value
- # bar_color
- #-------------------------------------------------------------------------
- def draw_ccw_arc_region(x, y, min_rad, max_rad, s_angle, e_angle,
- cur_v, max_v, color = Color.red)
- # Calculate Inner Regions
- inner_region = {}
- for i in 0..min_rad
- sa = i
- y_ = Integer((min_rad ** 2 - sa ** 2) ** 0.5)
- inner_region[x + i] = y_
- inner_region[x - i] = y_
- end
- # Make Degrees between 0 - 360
- s_angle %= 360 ; e_angle %= 360
- # Make s_angle Greater than e_angle
- e_angle += 360 if e_angle < s_angle
- # Calculate Difference
- diff = e_angle - s_angle
- # Get Percent Difference
- p_diff = Integer(diff * cur_v / max_v.to_f)
- # Modify e_angle with percent Diffence
- e_angle = s_angle + p_diff
- # Pass from left to right
- for i in (x - max_rad)..(x + max_rad)
- # Get Y max at that pixel
- y_max = Integer((max_rad ** 2 - (x - i).abs ** 2) ** 0.5)
- # Pass from top to bottom
- for j in (y - y_max)..(y + y_max)
- # If within inner-region limits
- if i.between?(x - min_rad, x + min_rad)
- # If Inner region has key
- if inner_region.has_key?(i)
- # Get Inner Value
- inner = inner_region[i]
- # Skip if Between inner region limits
- next if j.between?(x - inner, x + inner)
- end
- end
- # Gets Angle of pixel from center
- a = Math.atan2((j - y).abs, (i - x).abs.to_f) * 180 / Math::PI
- # Get 360 Degree Angle
- if (i - x) > 0
- a = 360 - a if (j - y) > 0
- else
- a = 180 + ((j - y) > 0 ? a : -a)
- end
- # Set Pixel if Between Angles
- if Math.cw_between_angles?(a, s_angle, e_angle)
- set_pixel(i, j, color)
- end
- end
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Clockwise Gradient Circular Arc Region
- # Info : Draws Circular Gradient clockwise, from s_angle to e_angle
- # Author : SephirothSpawn
- # Call Info : Eight to Ten Arguments
- # center_x and center_y
- # min_radius, max_radius
- # s_angle & e_angle (in Degrees)
- # currect_value & max_value
- # start_bar_color & end_bar _color
- #-------------------------------------------------------------------------
- def draw_cw_grad_arc_region(x, y, min_rad, max_rad, s_angle, e_angle,
- cur_v, max_v, s_color = Color.red,
- e_color = Color.blue)
- # Calculate Inner Regions
- inner_region = {}
- for i in 0..min_rad
- y_ = Integer((min_rad ** 2 - i ** 2) ** 0.5)
- inner_region[x + i] = y_
- inner_region[x - i] = y_
- end
- # Make Degrees between 0 - 360
- s_angle %= 360 ; e_angle %= 360
- # Make s_angle Greater than e_angle
- s_angle += 360 if s_angle < e_angle
- # Calculate Difference
- diff = s_angle - e_angle
- # Get Percent Difference
- p_diff = Integer(diff * cur_v / max_v.to_f)
- # Modify e_angle with percent Diffence
- e_angle = s_angle - p_diff
- # Pass from left to right
- for i in (x - max_rad)..(x + max_rad)
- # Get Y max at that pixel
- y_max = Integer((max_rad ** 2 - (x - i).abs ** 2) ** 0.5)
- # Pass from top to bottom
- for j in (y - y_max)..(y + y_max)
- # If within inner-region limits
- if i.between?(x - min_rad, x + min_rad)
- # If Inner region has key
- if inner_region.has_key?(i)
- # Get Inner Value
- inner = inner_region[i]
- # Skip if Between inner region limits
- next if j.between?(x - inner, x + inner)
- end
- end
- # Gets Angle of pixel from center
- a = Math.atan2((j - y).abs, (i - x).abs.to_f) * 180 / Math::PI
- # Get 360 Degree Angle
- if (i - x) > 0
- a = 360 - a if (j - y) > 0
- else
- a = 180 + ((j - y) > 0 ? a : -a)
- end
- # If Between Angles
- if Math.cw_between_angles?(a, s_angle, e_angle)
- # Get Color Value
- per = Math.cw_percent_between_angles(a, s_angle, s_angle - diff)
- color = Color.color_between(e_color, s_color, per)
- # Set Pixel
- set_pixel(i, j, color)
- end
- end
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Draw Counter-Clockwise Gradient Circular Arc Region
- # Info : Draws Circular Gradient ccw, from s_angle to e_angle
- # Author : SephirothSpawn
- # Call Info : Eight to Ten Arguments
- # center_x and center_y
- # min_radius, max_radius
- # s_angle & e_angle (in Degrees)
- # currect_value & max_value
- # start_bar_color & end_bar _color
- #-------------------------------------------------------------------------
- def draw_ccw_grad_arc_region(x, y, min_rad, max_rad, s_angle, e_angle,
- cur_v, max_v, s_color = Color.red,
- e_color = Color.blue)
- # Calculate Inner Regions
- inner_region = {}
- for i in 0..min_rad
- sa = i
- y_ = Integer((min_rad ** 2 - sa ** 2) ** 0.5)
- inner_region[x + i] = y_
- inner_region[x - i] = y_
- end
- # Make Degrees between 0 - 360
- s_angle %= 360 ; e_angle %= 360
- # Make s_angle Greater than e_angle
- e_angle += 360 if e_angle < s_angle
- # Calculate Difference
- diff = e_angle - s_angle
- # Get Percent Difference
- p_diff = Integer(diff * cur_v / max_v.to_f)
- # Modify e_angle with percent Diffence
- e_angle = s_angle + p_diff
- # Pass from left to right
- for i in (x - max_rad)..(x + max_rad)
- # Get Y max at that pixel
- y_max = Integer((max_rad ** 2 - (x - i).abs ** 2) ** 0.5)
- # Pass from top to bottom
- for j in (y - y_max)..(y + y_max)
- # If within inner-region limits
- if i.between?(x - min_rad, x + min_rad)
- # If Inner region has key
- if inner_region.has_key?(i)
- # Get Inner Value
- inner = inner_region[i]
- # Skip if Between inner region limits
- next if j.between?(x - inner, x + inner)
- end
- end
- # Gets Angle of pixel from center
- a = Math.atan2((j - y).abs, (i - x).abs.to_f) * 180 / Math::PI
- # Get 360 Degree Angle
- if (i - x) > 0
- a = 360 - a if (j - y) > 0
- else
- a = 180 + ((j - y) > 0 ? a : -a)
- end
- # If Between Angles
- if Math.cw_between_angles?(a, s_angle, e_angle)
- # Get Color Value
- per = Math.ccw_percent_between_angles(a, s_angle, s_angle + diff)
- color = Color.color_between(s_color, e_color, per)
- # Set Pixel
- set_pixel(i, j, color)
- end
- end
- end
- end
- #-------------------------------------------------------------------------
- # Name : Draw Functional Gradient Bar
- # Info : Draws a Functional Gradient Bar
- # Author : Trickster
- # Call Info : Seven to Nine Arguments
- # Integer X, Y, Width, Height, Current, and Max
- # Proc Function
- # Color start and finish both Default to Black
- # X and Y Define Position, Width and Height defines dimensions
- # Function is a function of r and x1
- # Example proc {Math.sqrt(r**2 - x1**2)} (Circular)
- # Current Defines How Much of the Bar to Draw
- # Max Defines the Maximum Value
- # start, finish is the starting and Ending Colors Respectively
- #-------------------------------------------------------------------------
- def draw_trick_function_bar(x, y, width, height, function, current, max,
- start = Color.new(0,0,0), finish = Color.new(0,0,0),
- back = Color.new(0,0,0))
- # Get Change in Colors
- chred, chblue = finish.red - start.red, finish.blue - start.blue
- chgreen, chalpha = finish.green - start.green, finish.alpha - start.alpha
- # Draw Background
- radius = height / 2
- # Setup Values Array
- values = []
- # Draw Rectangle Center
- fill_rect(x + radius, y, width - height, height, back)
- # Draws Ends
- (radius + 1).times do |x1|
- # Get Parameter
- t = radius - x1
- # Get Y
- y1 = function.call(radius, t).round
- # Get Height
- h = 2 * y1
- # Draw Line of Back Color at Left Edge
- fill_rect(x + x1, y - y1 + radius, 1, h, back)
- # Draw Line of Back Color at Right Edge
- fill_rect(x + width - x1, y - y1 + radius, 1, h, back)
- end
- # Get Percentage
- percentage = current / max.to_f
- # Return if not a finite number
- return if not percentage.finite?
- # Decrease Width and Height increase x and y
- width -= 4
- height -= 4
- x += 2
- y += 2
- # Get new Radius
- radius = height / 2
- # Get Bar Width
- barwidth = width * percentage
- # Draws Left End
- (radius + 1).times do |x1|
- # Stop if Past Width
- break if x1 > barwidth
- # Get T (Parameter)
- t = radius - x1
- # Get Width Change
- chwidth = x1
- # Get Colors
- red = start.red + chred * chwidth / width
- green = start.green + chgreen * chwidth / width
- blue = start.blue + chblue * chwidth / width
- alpha = start.alpha + chalpha * chwidth / width
- # Get Y
- y1 = function.call(radius, t).round
- # Push onto Values
- values << y1
- # Get Height
- h = 2 * y1
- # Get Color
- color = Color.new(red, green, blue, alpha) if alpha != 255
- color = Color.new(red, green, blue) if alpha == 255
- # Draw Line
- fill_rect(x + x1, y - y1 + radius, 1, h, color)
- end
- # Run From Radius upto Rectangles End
- (width - height + 1).times do |t|
- # Get X1
- x1 = t + radius
- # Break if Past Width
- break if x1 > barwidth
- # Get Width Change
- chwidth = x1
- # Get Colors
- red = start.red + chred * chwidth / width
- green = start.green + chgreen * chwidth / width
- blue = start.blue + chblue * chwidth / width
- alpha = start.alpha + chalpha * chwidth / width
- # Get Color
- color = Color.new(red, green, blue, alpha) if alpha != 255
- color = Color.new(red, green, blue) if alpha == 255
- # Draw Line
- fill_rect(x + x1, y, 1, height, color)
- end
- # Draws Right End
- radius.times do |t|
- # Get X
- x1 = width - radius + t
- # Stop if Past Width
- break if x1 > barwidth
- # Get Width Change
- chwidth = x1
- # Get Colors
- red = start.red + chred * chwidth / width
- green = start.green + chgreen * chwidth / width
- blue = start.blue + chblue * chwidth / width
- alpha = start.alpha + chalpha * chwidth / width
- # Get Y
- y1 = values[radius-t]
- # Get Height
- h = 2 * y1
- # Get Color
- color = Color.new(red, green, blue, alpha) if alpha != 255
- color = Color.new(red, green, blue) if alpha == 255
- # Draw Line
- fill_rect(x + x1, y - y1 + radius, 1, h, color)
- end
- end
- #-------------------------------------------------------------------------
- # Name : Draw Trick Gradient Bar
- # Info : Draws a Gradient Bar (Uses Pictures)
- # Author : Trickster
- # Call Info : Thirteen Arguments
- # Integer X and Y Define Position
- # Integer Min and Max Define How Much is Drawn
- # String File Is the File to load
- # Integer Width and Height defines dimensions (def bar size)
- # String Back and Back2 Are the Backgrounds for the bar
- # Integer cx,cy,dx,dy Define the Borders of the Backgrounds
- #-------------------------------------------------------------------------
- def draw_trick_gradient_bar(x, y, min, max, file, width = nil, height = nil,
- back = 'Back', back2 = 'Back2', cx = 1, cy = 1, dx = 1, dy = 1)
- # Get Bar and Background Bitmaps
- bar = RPG::Cache.gradient(file)
- back = RPG::Cache.gradient(back)
- back2 = RPG::Cache.gradient(back2)
- # Get Zoom X and Zoom Y
- zoom_x = width != nil ? width : back.width
- zoom_y = height != nil ? height : back.height
- # Get Percentage
- percent = max == 0 ? 0 : min / max.to_f
- # Create Destination Rect Objects
- back_dest = Rect.new(x, y, zoom_x, zoom_y)
- back2_dest = Rect.new(x + dx, y + dy, zoom_x - dx * 2, zoom_y - dy * 2)
- bar_dest = Rect.new(x + cx, y + cy, zoom_x * percent - cx*2, zoom_y - cy*2)
- # Get Source Rect
- source = Rect.new(0, 0, bar.width * percent, bar.height)
- # Draw Onto Window
- stretch_blt(back_dest, back, back.rect)
- stretch_blt(back2_dest, back2, back2.rect)
- stretch_blt(bar_dest, bar, source)
- end
- #-------------------------------------------------------------------------
- # Name : Draw Trick Vertical Gradient Bar
- # Info : Draws a Gradient Bar (Uses Pictures)
- # Author : Trickster
- # Call Info : Thirteen Arguments
- # Integer X and Y Define Position
- # Integer Min and Max Define How Much is Drawn
- # String File Is the File to load
- # Integer Width and Height defines dimensions (def bar size)
- # String Back and Back2 Are the Backgrounds for the bar
- # Integer cx,cy,dx,dy Define the Borders of the Backgrounds
- #-------------------------------------------------------------------------
- def draw_trick_vertical_gradient_bar(x, y, min, max, file, width = nil,
- height = nil, back = 'Back', back2 = 'Back2', cx = 1, cy = 1, dx = 1, dy = 1)
- # Ger Bar Bitmaps
- bar = RPG::Cache.gradient(file)
- back = RPG::Cache.gradient(back)
- back2 = RPG::Cache.gradient(back2)
- # Get Zoom X and Zoom Y
- zoom_x = width != nil ? width : back.width
- zoom_y = height != nil ? height : back.height
- # Get Percentage
- percent = max == 0 ? 0 : min / max.to_f
- # Get Bar Y
- bar_y = (zoom_y - zoom_y * percent).ceil
- # Get Bar Source Y
- source_y = bar.height - bar.height * percent
- # Get Bar Dest Y
- dest_y = (zoom_y * percent).to_i
- # Create Destination Rect Objects
- back_dest = Rect.new(x, y, zoom_x, zoom_y)
- back2_dest = Rect.new(x + dx, y + dy, zoom_x - dx * 2, zoom_y - dy * 2)
- bar_dest = Rect.new(x + cx, y + bar_y + cy, zoom_x - cx * 2, dest_y - cy * 2)
- # Get Source Rect
- source = Rect.new(0, source_y, bar.width, bar.height * percent)
- # Draw Onto Window
- stretch_blt(back_dest_rect, back, back_source_rect)
- stretch_blt(back2_dest_rect, back2, back2_source_rect)
- stretch_blt(bar_dest_rect, bar, source)
- end
- #-------------------------------------------------------------------------
- # Name : Draw Trick Gradient Bar Background
- # Info : Draws a Gradient Bar Background (Uses Pictures)
- # Author: Trickster
- # Call Info : Thirteen Arguments
- # Integer X and Y Define Position
- # Integer Min and Max Define How Much is Drawn
- # String File Is the File to load
- # Integer Width and Height is the width and height (Defaults to nil)
- # String Back and Back2 Are the Backgrounds for the bar
- # Integer cx,cy,dx,dy Define the Borders of the Backgrounds
- #-------------------------------------------------------------------------
- def draw_trick_gradient_bar_back(x, y, width = nil, height = nil, back = 'Back',
- back2 = 'Back2', dx = 1, dy = 1)
- # Get Bitmaps
- back = RPG::Cache.gradient(back)
- back2 = RPG::Cache.gradient(back2)
- # Get Zoom X and Zoom Y
- zoom_x = width != nil ? width : back.width
- zoom_y = height != nil ? height : back.height
- # Get Destination Rects
- back_dest_rect = Rect.new(x, y, zoom_x, zoom_y)
- back2_dest_rect = Rect.new(x + dx, y + dy, zoom_x - dx * 2, zoom_y - dy * 2)
- # Draw Border
- stretch_blt(back_dest_rect, back, back.rect)
- # Draw Background
- stretch_blt(back2_dest_rect, back2, back2.rect)
- end
- #-------------------------------------------------------------------------
- # Name : Draw Trick Gradient Bar Substance
- # Info : Draws a Gradient Bar w/o the Background(Uses Pictures)
- # Author: Trickster
- # Call Info : Ten Arguments
- # Integer X and Y Define Position
- # Integer Min and Max Define How Much is Drawn
- # String File Is the File to load
- # Integer Width and Height is the width and height (Defaults to nil)
- # String Back is the background used for the bar
- # Integer cx,cy Define the Borders of the Backgrounds
- #-------------------------------------------------------------------------
- def draw_trick_gradient_bar_sub(x, y, min, max, file, width = nil, height = nil,
- back = 'Back', cx = 1, cy = 1, slanted = false)
- # Get Bitmaps
- bar = RPG::Cache.gradient(file)
- back = RPG::Cache.gradient(back)
- # Get Zoom X and Zoom Y
- zoom_x = width != nil ? width : back.width
- zoom_y = height != nil ? height : back.height
- # Get Percentage
- percent = max == 0 ? 0 : min / max.to_f
- # Get Destination Rect
- bar_dest_rect = Rect.new(x+cx, y+cy, zoom_x * percent - cx*2, zoom_y - cy*2)
- # Get Source Rect
- bar_source_rect = Rect.new(0, 0, bar.width * percent, bar.height)
- # Draw Bitmap
- stretch_blt(bar_dest_rect, bar, bar_source_rect)
- # If Slanted
- if slanted
- # Setup Transparent Color
- color = Color.new(0,0,0,0)
- # Run Through and remove edges
- (0...zoom_y).each do |i|
- # Get Height
- x_i = zoom_y - 1 - i
- # Fill Lines at Start and End
- fill_rect(x + i, y, 1, x_i, color)
- fill_rect(x + zoom_x * percent - cx*2 - i, y + zoom_y - x_i, 1, x_i, color)
- end
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Shade Gradient Section
- # Info : Shades a section from (cx,cy), (x1,y1), (x2,y2) w/ gradient
- # Author : Trickster
- # Call Info : Six to Ten Arguments
- # Integer cx, cy, x1, y1, x2, y2 - Points
- # Integer Thick - Line Thickness
- # Integer Step - how many lines to draw (lower = higher accuracy)
- # Color start_color, end_color - Start and end colors
- #-------------------------------------------------------------------------
- def shade_gradient_section(cx, cy, x1, y1, x2, y2, thick = 1, step = 1,
- start_color = Color.new(0, 0, 0), end_color = start_color)
- # Reverse all parameters sent if 2 x is less than the first x
- x1, x2, y1, y2 = x2, x1, y2, y1 if x2 < x1
- # Get Slope
- slope = (y2 - y1).to_f / (x2 - x1)
- # If Slope is infinite
- if slope.infinite?
- y1.step(y2, step) {|y| draw_gradient_line(cx, cy, x1, y, thick, start_color, end_color)}
- # If Slope is zero
- elsif slope.zero?
- x1.step(x2, step) {|x| draw_gradient_line(cx, cy, x, y1, thick, start_color, end_color)}
- elsif not slope.nan?
- # Get Y intercept
- yint = y1 - slope * x1
- x1.step(x2, step) {|x| draw_gradient_line(cx, cy, x, slope * x + yint, thick, start_color, end_color)}
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Vertical Gradient Pixel Change
- # Info : Changes Pixels to Linear Gradient
- # Author : SephirothSpawn
- # Call Info : Two to Three Arguments
- # Start Color and End Color
- # Optional Rect, rect of bitmap being changed
- #-------------------------------------------------------------------------
- def v_gradient_pixel_change(sc = Color.red, ec = Color.blue, r = rect)
- # Pass From Top to Bottom
- for y_ in (r.y)...(r.y + r.height)
- # Get Color
- color = Color.color_between(sc, ec, (y_ / (r.height).to_f))
- # Pass From Left to Right
- for x_ in (r.x)...(r.x + r.width)
- # Gets Alpha Pixel
- a = get_pixel(x_, y_).alpha
- # Skip if 0 Alpha
- next if a == 0
- # Set Color Alpha
- color.alpha = a
- # Set Pixel
- set_pixel(x_, y_, color)
- end
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Horizontal Gradient Pixel Change
- # Info : Changes Pixels to Linear Gradient
- # Author : SephirothSpawn
- # Call Info : Two to Three Arguments
- # Start Color and End Color
- # Optional Rect, rect of bitmap being changed
- #-------------------------------------------------------------------------
- def h_gradient_pixel_change(sc = Color.red, ec = Color.blue, r = rect)
- # Passes From Left to Right
- for x_ in (r.x)...(r.x + r.width)
- # Get Color
- color = Color.color_between(sc, ec, (x_ / r.width.to_f))
- # Pass From Top to Bottom
- for y_ in (r.y)...(r.y + r.height)
- # Gets Alpha Pixel
- a = get_pixel(x_, y_).alpha
- # Skip if 0 Alpha
- next if a == 0
- # Set Color Alpha
- color.alpha = a
- # Set Pixel
- set_pixel(x_, y_, color)
- end
- end
- end
- end
- #==============================================================================
- # ** RGSS.Bitmap.image
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Methods created for the Bitmap class that manipulates the bitmap. Methods
- # include flipping, stretching, and erasing.
- #
- # Method List:
- # ------------
- # erase
- # flip_horizontal
- # flip_horizontal!
- # flip_vertical
- # flip_vertical!
- # frames_flip_horizontal!
- # frames_flip_vertical!
- # stretch
- # blur_area
- # add_bitmap_blend
- # sub_bitmap_blend
- #==============================================================================
- MACL::Loaded << 'RGSS.Bitmap.image'
- #==============================================================================
- # ** Bitmap
- #==============================================================================
- class Bitmap
- #-------------------------------------------------------------------------
- # * Name : Erase
- # Info : This method clears a part of the bitmap
- # Author : Selwyn
- # Call Info : One or Four arguments,
- # One Argument : Rect ; Four arguments : Integers
- # One Argument : Rect.new(x, y, width, height)
- # Four Arguments : x, y, width, height
- # Comment : works the same as the build-in method 'clear'
- # but only for a portion of the bitmap
- #-------------------------------------------------------------------------
- def erase(*args)
- # If One Argument Sent
- if args.size == 1
- # Set Rect
- rect = args
- # If Four Arguments Sent
- elsif args.size == 4
- # Create Rect
- rect = Rect.new(*args)
- end
- # Erase (Set To Transparent Color)
- fill_rect(rect, Color.new(0, 0, 0, 0))
- end
- #-------------------------------------------------------------------------
- # Name : Flip Horizontally
- # Info : Flips Bitmap Horizontally
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def flip_horizontal
- # Create Flipped Bitmap
- flipped = Bitmap.new(width, height)
- # Create Rect
- rect = Rect.new(0, 0, 1, height)
- # Do Width Times
- width.times do |i|
- # Set X
- rect.x = width - 1 - i
- # Draw on other side
- flipped.blt(i, 0, self, rect)
- end
- # Return Flipped Bitmap
- return flipped
- end
- #-------------------------------------------------------------------------
- # Name : Flip Horizontally!
- # Info : Flips Bitmap Horizontally Modifies the Bitmap
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def flip_horizontal!
- # Create Flipped Bitmap
- flipped = Bitmap.new(width, height)
- # Create Rect
- flip_rect = Rect.new(0, 0, 1, height)
- # Do Width Times
- width.times do |i|
- # Set X
- flip_rect.x = width - 1 - i
- # Draw on other side
- flipped.blt(i, 0, self, flip_rect)
- end
- # Clear Bitmap
- clear
- # Draw Flipped
- blt(0, 0, flipped, rect)
- # Dispose Flipped
- flipped.dispose
- end
- #-------------------------------------------------------------------------
- # Name : Flip Vertically
- # Info : Flips Bitmap Vertically
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def flip_vertical
- # Create Flipped Bitmap
- flipped = Bitmap.new(width, height)
- # Create Rect
- flip_rect = Rect.new(0, 0, width, 1)
- # Do Width Times
- height.times do |i|
- # Set Y
- flip_rect.y = height - 1 - i
- # Draw on Other Side
- flipped.blt(0, i, self, flip_rect)
- end
- # Return Flipped
- return flipped
- end
- #-------------------------------------------------------------------------
- # Name : Flip Vertically!
- # Info : Flips Bitmap Vertically Modifies the Bitmap
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def flip_vertical!
- # Create Flipped Bitmap
- flipped = Bitmap.new(width, height)
- # Create Rect
- flip_rect = Rect.new(0, 0, width, 1)
- # Do Width Times
- height.times do |i|
- # Set Y
- flip_rect.y = height - 1 - i
- # Draw on Other Side
- flipped.blt(0, i, self, flip_rect)
- end
- # Clear Bitmap
- clear
- # Draw Flipped
- blt(0, 0, flipped, rect)
- # Dispose Flipped
- flipped.dispose
- end
- #-------------------------------------------------------------------------
- # Name : Flip Each Frame Horizontally
- # Info : Flips Each Frame Horizontally Modifies Itself
- # Author : Trickster
- # Call Info : One Argument, Integer Frames the number of frames to split and
- # flip
- #-------------------------------------------------------------------------
- def frames_flip_horizontal!(frames)
- # Get Frame Width
- frame_width = width / frames
- # Create A Frame Dummy Bitmap
- frame_bitmap = Bitmap.new(frame_width, height)
- # Create Rect
- rect = Rect.new(0, 0, frame_width, height)
- # Do Frames times
- frames.times do |i|
- # Clear Bitmap
- frame_bitmap.clear
- # Get X
- x = i * frame_width
- # Set Rect.x
- rect.x = x
- # Draw Piece of Bitmap onto dummy
- frame_bitmap.blt(0, 0, self, rect)
- # Flip Horizontally
- frame_bitmap.flip_horizontal!
- # Draw Onto Self
- blt(x, 0, frame_bitmap, frame_bitmap.rect)
- end
- # Dispose Dummy Bitmap
- frame_bitmap.dispose
- end
- #-------------------------------------------------------------------------
- # Name : Flip Each Frame Vertically
- # Info : Flips Each Frame Vertically Modifies Itself
- # Author : Trickster
- # Call Info : One Argument, Integer Frames the number of frames to split and
- # flip
- #-------------------------------------------------------------------------
- def frames_flip_vertical!(frames)
- # Get Frame Height
- frame_height = height / frames
- # Create A Frame Dummy Bitmap
- frame_bitmap = Bitmap.new(width, frame_height)
- # Create Rect
- rect = Rect.new(0, 0, width, frame_height)
- # Do Frames times
- frames.times do |i|
- # Clear Bitmap
- frame_bitmap.clear
- # Get Y
- y = i * frame_height
- # Set Rect.y
- rect.y = y
- # Draw Piece Of Bitmap onto Dummy
- frame_bitmap.blt(0, 0, self, rect)
- # Flip Vertically
- frame_bitmap.flip_vertical!
- # Draw onto Self
- blt(0, y, frame_bitmap, frame_bitmap.rect)
- end
- # Dispose Dummy Bitmap
- frame_bitmap.dispose
- end
- #-------------------------------------------------------------------------
- # Name : Stretch
- # Info : Stretches and Returns Bitmap
- # Author : Trickster
- # Call Info : Two Arguments, Width and Height of Bitmap
- #-------------------------------------------------------------------------
- def stretch(width, height)
- # Create Dummy Bitmap
- dummy = Bitmap.new(width, height)
- # Stretch Blt onto dummy
- dummy.stretch_blt(Rect.new(0, 0, width, height), self, dummy.rect)
- # Return dummy
- return dummy
- end
- #-------------------------------------------------------------------------
- # * Name : Blur Area
- # Info : Blurs area of bitmap
- # Author : SephirothSpawn
- # Call Info : One Argument as hash
- #
- # Defining Area of Blur
- # hash['rect'] = Rect object
- # hash['x'], 'y', 'w', 'h' = Rect properties
- # nothing = Entire bitmap
- #
- # Optional Settings (Defaults to @blur_settings)
- # hash['spacing'] = Space between redraws
- # hash['opacity'] = Max opacity of blut
- # hash['offset'] = Number of times to space out blur
- #-------------------------------------------------------------------------
- def blur_area(settings = {})
- # Set Defaults
- @blur_settings.each do |default, setting|
- settings[default] = setting unless settings.has_key?(default)
- end
- # Collects Keys
- keys = settings.keys
- # Rect Defined Flag
- rect_defined = keys.include?('rect')
- # Rect Positions Defined
- rect_p_defined = keys.include?('x') && keys.include?('y') &&
- keys.include?('w') && keys.include?('h')
- # If Rect Defined
- if rect_defined
- # Gets Rect
- rect = settings['rect']
- # Set Position Arguments
- x, y, w, h = rect.x, rect.y, rect.width, rect.height
- # If Rect Positions Defined
- elsif rect_p_defined
- # Set Position Arguments
- x, y, w, h = settings['x'], settings['y'], settings['w'], settings['h']
- else
- # Set Entire Bitmap
- x, y, w, h = 0, 0, self.width, self.height
- end
- # Duplicated Bitmap
- dummy = self.dup
- # Gets Spacing & Max Opacity
- spacing = settings['spacing']
- opacity = settings['opacity']
- # Number of Offsets
- settings['offset'].times do |i|
- # Collects Src Rect
- src_rects = []
- src_rects << Rect.new(x + i * spacing, y + i * spacing, w, h)
- src_rects << Rect.new(x - i * spacing, y + i * spacing, w, h)
- src_rects << Rect.new(x + i * spacing, y - i * spacing, w, h)
- src_rects << Rect.new(x - i * spacing, y - i * spacing, w, h)
- # Gets Opacity
- o = Integer(opacity * (settings['offset'] - i) / (settings['offset']))
- # Draws Rects
- src_rects.each do |src_rect|
- blt(x, y, dummy, src_rect, o)
- end
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Add Bitmap Blend
- # Info : Adds Bitmap Pixel Values to another
- # Author : Gibmaker / SephirothSpawn
- # Call Info : Three to Four Arguments
- # X and Y position
- # src bitmap
- # src bitmap rect
- #-------------------------------------------------------------------------
- def add_bitmap_blend(x, y, bitmap, src_rect = bitmap.rect)
- for i in 0...src_rect.width
- for j in 0...src_rect.height
- c1 = get_pixel(x + i, y + j)
- c2 = bitmap.get_pixel(src_rect.x + i, src_rect.y + j)
- nc = Color.new(c1.red + c2.red, c1.green + c2.green, c1.blue + c2.blue)
- set_pixel(x + i, y + j, nc)
- end
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Subtract Bitmap Blend
- # Info : Subtracts Bitmap Pixel Values to another
- # Author : Gibmaker / SephirothSpawn
- # Call Info : Three to Four Arguments
- # X and Y position
- # src bitmap
- # src bitmap rect
- #-------------------------------------------------------------------------
- def sub_bitmap_blend(x, y, bitmap, src_rect = bitmap.rect)
- for i in 0...src_rect.width
- for j in 0...src_rect.height
- c1 = get_pixel(x + i, y + j)
- c2 = bitmap.get_pixel(src_rect.x + i, src_rect.y + j)
- nc = Color.new(c1.red - c2.red, c1.green - c2.green, c1.blue - c2.blue)
- set_pixel(x + i, y + j, nc)
- end
- end
- end
- end
- #==============================================================================
- # ** RGSS.Bitmap.memory
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Specialized Methods for tbe bitmap class for remembering text. Also includes
- # a non-laggy draw_text method based on the original draw text which stores the
- # text in memory and calls blt instead of draw_text if it is needed again. One
- # thing to remember is to call Bitmap.clear_text_memory
- # Bitmap.clear_formatted_text_memory to dispose of all memorized sprites
- # when you are finished (preferably at the end of a scene).
- #
- # When Benchmarked drawing the string 'Hello World '*5 100 times the results
- # draw_text_memory around 0.266 seconds
- # draw_wrap_text_memory around 1.969 seconds
- # draw_formatted_text_memory around 0.266 seconds
- # draw_text around 6.235 seconds
- #
- # Method List:
- # ------------
- # Bitmap.clear_text_memory
- # Bitmap.clear_formatted_text_memory
- # clear_memory
- # cleat_to_memory
- # draw_formatted_text_memory
- # draw_text_memory
- # draw_wrap_text_memory
- # get_formatted_size (from Bitmap.text)
- # set_memory
- #==============================================================================
- MACL::Loaded << 'RGSS.Bitmap.memory'
- #==============================================================================
- # ** Bitmap
- #==============================================================================
- class Bitmap
- #--------------------------------------------------------------------------
- # * Class Variables
- #--------------------------------------------------------------------------
- class_reader :text_memory, :formatted_text_memory
- #-------------------------------------------------------------------------
- # * Class Variables
- #-------------------------------------------------------------------------
- @@text_memory, @@formatted_text_memory = {}, {}
- #-------------------------------------------------------------------------
- # Name : Clear Text Memory
- # Info : Clears Text Memory
- # Author : Trickster
- # Call Info : No Arguments
- # Comment : Should be called at the end of every scene where
- # draw_text_memory or draw_wrap_text_memory is used
- #-------------------------------------------------------------------------
- def self.clear_text_memory
- # Run Through Each Bitmap In Text Memory and dispose
- @@text_memory.each_value {|bitmap| bitmap.dispose}
- # Clear
- @@text_memory.clear
- end
- #-------------------------------------------------------------------------
- # Name : Clear Formatted Text Memory
- # Info : Clears Formatted Text Memory
- # Author : Trickster
- # Call Info : No Arguments
- # Returns : Nothing
- # Comment : Should be called at the end of every scene where
- # draw_formatted_text_memory is used
- #-------------------------------------------------------------------------
- def self.clear_formatted_text_memory
- # Run Through Each Bitmap In Text Memory and dispose
- @@formatted_text_memory.each_value {|bitmap| bitmap.dispose}
- # Clear
- @@formatted_text_memory.clear
- end
- #-------------------------------------------------------------------------
- # Name : Clear Memory
- # Info : Clears Bitmap Memory
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def clear_memory
- # Dispose Memory
- @memory.dispose
- # Set To nil
- @memory = nil
- end
- #-------------------------------------------------------------------------
- # Name : Clear To Memory
- # Info : Clears to Bitmap Memory
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def clear_to_memory
- # Clear Bitmap
- clear
- # Draw Memory if it is a Bitmap
- blt(0, 0, @memory, rect) if @memory.is_a?(Bitmap)
- end
- #-------------------------------------------------------------------------
- # Name : Draw Formatted Text Memory
- # Info : Draws Formatted Wrapped Text from Memory
- # Author : Trickster
- # Call Info : Five Arguments
- # Integer Offset_x and Offset_Y, define starting position
- # Integer Width, defines the width of the text rectangle
- # Integer Height, defines the height of the text drawn
- # String Text, The text to be drawn
- # Comment : C[rrggbb] -> Change Color values are in hex
- # C[N] -> Change Color to Normal Color
- # B[] -> Turns on/off Bold
- # I[] -> Turns on/off Italics
- # T[] -> Tab (4 Spaces)
- # N[] -> Newline
- #-------------------------------------------------------------------------
- def draw_formatted_text_memory(x, y, width, height, text)
- # If Already drawn
- if @@formatted_text_memory.has_key?(text)
- # Get Bitmap
- bitmap = @@formatted_text_memory[text]
- # Draw Bitmap
- blt(x, y, bitmap, bitmap.rect)
- else
- # Get Height of Text Drawn
- height = get_formatted_size(x, y, width, height, text).height
- # Create Text Bitmap
- text_bitmap = Bitmap.new(width, height)
- # Initialize X and Y
- cx, cy = 0, 0
- # Setup Font Color
- text_bitmap.font.color = Color.new(255, 255, 255)
- # Setup Save String
- string = text.dup
- # Make a Copy of Text
- text = text.dup
- # Replace C[Hex+] or C[N] with \001[Matched]
- text.gsub!(/[Cc]\[([A-F a-f 0-9]+|N)\]/) {" \001[#{$1}] "}
- # Replace B[] with \002
- text.gsub!(/[Bb]\[\]/) {" \002 "}
- # Replace I[] with \003
- text.gsub!(/[Ii]\[\]/) {" \003 "}
- # Replace T[] with \004
- text.gsub!(/[Tt]\[\]/) {" \004 "}
- # Replace N[] with \005
- text.gsub!(/[Nn]\[\]/) {" \005 "}
- # Run Through each text
- text.split(/\s/).each do |word|
- # If String \001 is included
- if word.include?("\001")
- # Slice from String
- word.slice!("\001")
- # Change text color
- word.sub!(/[Cc]\[([A-F a-f 0-9]+|N)\]/, '')
- # If matched is not nil and size of match is > 1
- if $1 != nil and $1.size > 1
- # Create Color
- color = Color.new($1[0..1].hex, $1[2..3].hex, $1[4..5].hex)
- else
- # Normal Color
- color = Color.new(255, 255, 255)
- end
- # Set Color
- self.font.color = color
- # Go to next text
- next
- end
- # If String \002 is included
- if word.include?("\002")
- # Invert Bold Status
- self.font.bold = !self.font.bold
- # Go to next text
- next
- end
- # If String \003 is included
- if word.include?("\003")
- # Invert Italic Status
- self.font.italic = !self.font.italic
- # Go to next text
- next
- end
- # If String \004 is included
- if word.include?("\004")
- # Add Four Spaces
- x += text_size(' ').width
- # Go to next text
- next
- end
- # If String \005 is included
- if word.include?("\005")
- # Move to new line
- cy = cx / width + 1
- # Move to start
- cx = cy * width
- # Go to next text
- next
- end
- # Get Word Width
- word_width = text_size("#{word} ").width
- # If can't fit on line
- if (cx + word_width) % width < x % width
- # Move to new line
- cy = cx / width + 1
- # Move to start
- cx = cy * width
- end
- # Get Draw X
- dx = cx % width + x
- # Get Draw Y
- dy = cx / width * height + y
- # Draw Text
- text_bitmap.draw_text(dx, dy, word_width, 32, word)
- # Increase by Word Width
- cx += word_width
- end
- # Save Copy of Bitmap
- @@formatted_text_memory[string] = text_bitmap
- # Draw onto Bitmap
- blt(x, y, text_bitmap, text_bitmap.rect)
- end
- end
- #-------------------------------------------------------------------------
- # Name : Draw Text Memory
- # Info : Draws Text and Saves it to Text_Memory
- # Author : Trickster
- # Call Info : Two,Three,Five or Six Arguments
- # Two Arguments: rect, str
- # Rect rect for the text to be drawn
- # String str text to be drawn
- # Three Arguments: rect, str, align
- # Rect rect for the text to be drawn
- # String str text to be drawn
- # Integer align 0: left 1: center 2:right
- # Five Arguments: x,y,width,height,str
- # Integer X and Y, Defines Position
- # Width and Height, Defines Width and Hieght of the text drawn
- # String str text to be drawn
- # Six Arguments: x,y,width,height,str,align
- # Integer X and Y, Defines Position
- # Width and Height, Defines Width and Hieght of the text drawn
- # String str text to be drawn
- # Integer align 0: left 1: center 2:right
- #-------------------------------------------------------------------------
- def draw_text_memory(*args)
- # If Two Arguments Sent
- if args.size == 2
- # Default align, Rect and String were sent
- align, rect, str = 0, *args
- # If Three Arguments Sent
- elsif args.size == 3
- # All Were Sent Rect String and Alignment
- rect, str, align = args
- # If Five Arguments Sent
- elsif args.size == 5
- # Create Rect from (X,Y,Width,Height), Set String, Default align
- rect, str, align = Rect.new(*args[0, 4]), args[4], 0
- # If Six Arguments Sent
- elsif args.size == 6
- # Create Rect from (X,Y,Width,Height), Set String and align
- rect, str, align = Rect.new(*args[0, 4]), *args[4, 2]
- end
- # Create Text Rect from Rect
- txt_rect = Rect.new(0, 0, rect.width, rect.height)
- # If Key is contained
- if @@text_memory.contains_key?([font, txt_rect, str])
- # Get Bitmap
- bitmap = @@text_memory.get_value([font, txt_rect, str])
- # Draw Bitmap by getting value from hash
- blt(rect.x, rect.y, bitmap, txt_rect)
- else
- # Create Bitmap
- bitmap = Bitmap.new(rect.width, rect.height)
- # Make A Copy of the Font
- bitmap.font = font.dup
- # Draw Text on bitmap
- bitmap.draw_text(txt_rect, str, align)
- # Draw Bitmap
- blt(rect.x, rect.y, bitmap, txt_rect)
- # Set Text Memory
- @@text_memory[[font.dup, txt_rect, str]] = bitmap
- end
- end
- #-------------------------------------------------------------------------
- # Name : Draw Wrapped Text From Memory
- # Info : Draws Text with Text Wrap and Saves it
- # Author : Trickster
- # Call Info : Five
- # Integer X and Y, Define Position
- # Integer Width, defines the width of the text rectangle
- # Integer Height, defines the height of the text
- # String Text, Text to be drawn
- #-------------------------------------------------------------------------
- def draw_wrap_text_memory(x, y, width, height, text)
- # Get Array of Text
- strings = text.split
- # Run Through Array of Strings
- strings.each do |string|
- # Get Word
- word = string + ' '
- # Get Word Width
- word_width = text_size(word).width
- # If Can't Fit on Line move to next one
- x, y = 0, y + height if x + word_width > width
- # Draw Text Memory
- draw_text_memory(x, y, word_width, height, word)
- # Add To X
- x += word_width
- end
- end
- #-------------------------------------------------------------------------
- # Name : Get Formatted Text Size
- # Info : Gets Rect information for drawing formatted text
- # The Rect Object Returned will have this information
- # x, x coordinate where drawing ends
- # y, y coordinate where drawing ends
- # width, the width sent to this method
- # height, the height of all of the text drawn
- # Author : Trickster
- # Call Info : Five
- # Integer X and Y, Define Position
- # Integer Width, defines the width of the text rectangle
- # Integer Height, defines the height of the text
- # String Text, Text to get information for
- #-------------------------------------------------------------------------
- def get_formatted_size(x, y, width, height, text)
- # Make a Copy and Save
- text = text.dup
- # Replace C[Hex+ or N] I[] B[] with nothing
- text.gsub!(/[BbIiCc]\[([A-F a-f 0-9]+|N)*\]/) {''}
- # Replace T[] with \004
- text.gsub!(/[Tt]\[\]/) {" \004 "}
- # Replace N[] with \005
- text.gsub!(/[Nn]\[\]/) {" \005 "}
- # Setup Cx and Cy
- cx, cy = 0, 0
- # Declare Dx and Dx as local variables
- dx, dy = 0, 0
- # Run Through each text
- text.split(/\s/).each do |word|
- # If \004 is included
- if word.include?("\004")
- # Add Four Spaces
- x += text_size(' '*4).width
- # Go to Next Text
- next
- end
- # If \005 is included
- if word.include?("\005")
- # Move to new line
- cy = cx / width + 1
- # Move to start
- cx = cy * width
- # Go to Next Text
- next
- end
- # Get Word Width
- word_width = text_size("#{word} ").width
- # If can't fit on line
- if (cx + word_width) % width < x % width
- # Move to new line
- cy = cx / width + 1
- # Move to start
- cx = cy * width
- end
- # Add Width to X
- cx += word_width
- # Get Draw X and Y
- dx = cx % width + x
- dy = cx / width * height + y
- end
- # Return Rect Object
- return Rect.new(dx, dy, width, (dy - y + height).to_i)
- end
- #-------------------------------------------------------------------------
- # Name : Set Memory
- # Info : Sets Bitmap Memory
- # Author : Trickster
- # Call Info : No Arguments
- # Comment : Use with Clear To Memory
- #-------------------------------------------------------------------------
- def set_memory
- # Make A Clone of itself
- @memory = self.dup
- end
- end
- #==============================================================================
- # ** RGSS.Bitmap.misc
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Miscellaneous New stuff for the Bitmap class.
- #
- # Method List:
- # ------------
- # make_png
- #==============================================================================
- MACL::Loaded << 'RGSS.Bitmap.misc'
- #==============================================================================
- # ** Bitmap
- #==============================================================================
- class Bitmap
- #-------------------------------------------------------------------------
- # * Name : Make PNG
- # Info : Saves Bitmap to File
- # Author : ??? - http://www.66rpg.com/htm/news624.htm
- # Call Info : Zero to Three Arguments
- # Name : Name of filenam
- # Path : Directory in Game Folder
- # Mode : Mode of Writing
- #-------------------------------------------------------------------------
- def make_png(name = 'like', path = '', mode = 0)
- Dir.make_dir(path) if path != ''
- Zlib::Png_File.open('temp.gz') { |gz| gz.make_png(self, mode) }
- Zlib::GzipReader.open('temp.gz') { |gz| $read = gz.read }
- f = File.open(path + name + '.png', 'wb')
- f.write($read)
- f.close
- File.delete('temp.gz')
- end
- end
- #==============================================================================
- # ** RGSS.Bitmap.text
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Methods created for the Bitmap class that handle text drawing such as
- # drawing wrapped text and formatted text see Bitmap.memory for more text
- # drawing functions.
- #
- # Method List:
- # ------------
- # Bitmap.dummy=
- # Bitmap.dummy
- # Bitmap.text_size
- # Bitmap.string_to_text_icons
- # Bitmap.icon_text_sizes
- # get_formatted_size
- # text_wrap_size
- # draw_formatted_text
- # draw_paragraph
- # draw_wrap_text
- # draw_icon_text
- # draw_text_shadow
- # draw_text_outline
- # draw_text_underline
- # draw_text_strikethrough
- # draw_text_gradient
- #
- # Modified Methods:
- # -----------------
- # draw_text -> basic_draw_text
- #==============================================================================
- MACL::Loaded << 'RGSS.Bitmap.text'
- #==============================================================================
- # ** Bitmap
- #==============================================================================
- class Bitmap
- #--------------------------------------------------------------------------
- # * Class Variable Declaration
- #--------------------------------------------------------------------------
- class_accessor :dummy
- Bitmap.dummy = Bitmap.new(32, 32)
- #--------------------------------------------------------------------------
- # Name : Text Size
- # Info : Gets text size based off dummy bitmap
- # Author : SephirothSpawn
- # Call Info : One Argument, a String
- #--------------------------------------------------------------------------
- def Bitmap.text_size(text)
- return Bitmap.dummy.text_size(text)
- end
- #--------------------------------------------------------------------------
- # Name : Format String to Text & Icons
- # Info : Changes Strint to Array of Strings and Bitmaps
- # (Used for draw_icon_text)
- # Author : SephirothSpawn
- # Call Info : One Argument, a String
- # Comments : Format for String : "text [icon_filename] text text..."
- #--------------------------------------------------------------------------
- def Bitmap.string_to_text_icons(text)
- # Splits Text
- text = text.split
- # Start Icon List
- icons = []
- # Pass Through Text List
- for i in 0...text.size
- # Get Word
- word = text[i]
- # Sub [icon_filename]
- word.gsub(/\[(.+?)\]/, '')
- # Skip if nothing substituted
- next if $1.nil?
- # Replace Text Word with nil
- text[i] = nil
- # Add Icon to Icon List
- icons << RPG::Cache.icon($1)
- end
- # Return Text & Icons
- return text, icons
- end
- #--------------------------------------------------------------------------
- # Name : Get Icon Text Widths
- # Info : Determines size required to draw_icon_text
- # (Used for draw_icon_text)
- # Author : SephirothSpawn
- # Call Info : Two Arguments, an Array of strings and an Array of bitmaps
- #--------------------------------------------------------------------------
- def Bitmap.icon_text_sizes(text, icons)
- # Gets Icon Width
- icn_w = 0
- icons.each {|b| icn_w += b.width}
- # Gets Text Width
- txt_w = 0
- text.each do |w|
- next if w.nil?
- txt_w += @@dummy.text_size(w).width
- end
- # Gets Space Width
- spc_w = Bitmap.text_size(' ').width
- # Gets Total Width
- tot_w = icn_w + txt_w + (text.size - 1) * spc_w
- # Return Icon, Text, Space & Total Width
- return icn_w, txt_w, spc_w, tot_w
- end
- #-------------------------------------------------------------------------
- # Name : Get Formatted Text Size
- # Info : Gets Rect information for drawing formatted text
- # And Returns A Rect with this information
- # x, x coordinate where drawing ends
- # y, y coordinate where drawing ends
- # width, the width sent to this method
- # height, the height of all of the text drawn
- # Author : Trickster
- # Call Info : Five Arguments
- # Integer X and Y, Define Position
- # Integer Width, defines the width of the text rectangle
- # Integer Height, defines the height of the text
- # String Text, Text to get information for
- #-------------------------------------------------------------------------
- def get_formatted_size(x, y, width, height, text)
- # Make a Copy and Save
- text = text.dup
- # Replace C[Hex+ or N] I[] B[] with nothing
- text.gsub!(/[BbIiCc]\[([A-F a-f 0-9]+|N)*\]/) {''}
- # Replace T[] with \004
- text.gsub!(/[Tt]\[\]/) {" \004 "}
- # Replace N[] with \005
- text.gsub!(/[Nn]\[\]/) {" \005 "}
- # Setup Cx and Cy
- cx, cy = 0, 0
- # Run Through each text
- text.split(/\s/).each do |word|
- # If \004 is included
- if word.include?("\004")
- # Add Four Spaces
- x += text_size(' ').width
- # Go to Next Text
- next
- end
- # If \005 is included
- if word.include?("\005")
- # Move to new line
- cy = cx / width + 1
- # Move to start
- cx = cy * width
- # Go to Next Text
- next
- end
- # Get Word Width
- word_width = text_size("#{word} ").width
- # If can't fit on line
- if (cx + word_width) % width < x % width
- # Move to new line
- cy = cx / width + 1
- # Move to start
- cx = cy * width
- end
- # Add Width to X
- cx += word_width
- # Get Draw X and Y
- dx = cx % width + x
- dy = cx / width * height + y
- end
- # Return Rect Object
- return Rect.new(dx, dy, width, (dy - y + height).to_i)
- end
- #-------------------------------------------------------------------------
- # Name : Get Wrapped Text Size
- # Info : Gets Rect information for drawing wrapped text
- # And Returns A Rect with this information
- # x, x coordinate where drawing ends
- # y, y coordinate where drawing ends
- # width, the width sent to this method
- # height, the height of all of the text drawn
- # Author : Trickster
- # Call Info : Five Arguments
- # Integer X and Y, Define Position
- # Integer Width, defines the width of the text rectangle
- # Integer Height, defines the height of the text
- # String Text, Text to get information for
- #-------------------------------------------------------------------------
- def text_wrap_size(x, y, width, height, text)
- # Get Array of Text
- strings = text.split
- # Form Rect Object
- rect = Rect.new(x, y, width, 1)
- # Run Through Array of Strings
- strings.each do |string|
- # Get Word
- word = string + ' '
- # Get Word Width
- word_width = text_size(word).width
- # If Can't Fit on Line move to next one
- x, y = 0, y + height if x + word_width > width
- # Add To X
- x += word_width
- end
- # Set Rect Information
- rect.x, rect.height = x, y - rect.y
- rect.y = y
- # Return Rect
- return rect
- end
- #--------------------------------------------------------------------------
- # Name : Draw Formatted Text
- # Info : Draws Formatted Wrapped Text
- # Author : Trickster
- # Call Info : Five Arguments
- # Integer Offset_x and Offset_Y, define starting position
- # Integer Width, defines the width of the text rectangle
- # Integer Height, defines the height of the text drawn
- # String Text, The text to be drawn
- # Comment : C[rrggbb] -> Change Color values are in hex
- # C[N] -> Change Color to Normal Color (255, 255, 255)
- # B[] -> Turns on/off Bold
- # I[] -> Turns on/off Italics
- # T[] -> Tab (4 Spaces)
- # N[] -> Newline
- #-------------------------------------------------------------------------
- def draw_formatted_text(x, y, width, height, text)
- # Set to Normal Color (White)
- self.font.color = Color.new(255, 255, 255)
- # Make Copy of Text Sent
- text = text.dup
- # Replace C[Hex+] or C[N] with \001[Matched]
- text.gsub!(/[Cc]\[([A-F a-f 0-9]+|N)\]/) {" \001[#{$1}] "}
- # Replace B[] with \002
- text.gsub!(/[Bb]\[\]/) {" \002 "}
- # Replace I[] with \003
- text.gsub!(/[Ii]\[\]/) {" \003 "}
- # Replace T[] with \004
- text.gsub!(/[Tt]\[\]/) {" \004 "}
- # Replace N[] with \005
- text.gsub!(/[Nn]\[\]/) {" \005 "}
- # Setup Cx and Cy
- cx, cy = 0, 0
- # Run Through each text
- text.split(/\s/).each do |word|
- # If String \001 is included
- if word.include?("\001")
- # Slice from String
- word.slice!("\001")
- # Change text color
- word.sub!(/[Cc]\[([A-F a-f 0-9]+|N)\]/, '')
- # If matched is not nil and size of match is > 1
- if $1 != nil and $1.size > 1
- # Create Color
- color = Color.new($1[0..1].hex, $1[2..3].hex, $1[4..5].hex)
- else
- # Normal Color
- color = Color.new(255, 255, 255)
- end
- # Set Color
- self.font.color = color
- # Go to next text
- next
- end
- # If String \002 is included
- if word.include?("\002")
- # Invert Bold Status
- self.font.bold = !self.font.bold
- # Go to next text
- next
- end
- # If String \003 is included
- if word.include?("\003")
- # Invert Italic Status
- self.font.italic = !self.font.italic
- # Go to next text
- next
- end
- # If String \004 is included
- if word.include?("\004")
- # Add Four Spaces
- x += text_size(' ').width
- # Go to next text
- next
- end
- # If String \005 is included
- if word.include?("\005")
- # Move to new line
- cy = cx / width + 1
- # Move to start
- cx = cy * width
- # Go to next text
- next
- end
- # Get Word Width
- word_width = text_size("#{word} ").width
- # If can't fit on line
- if (cx + word_width) % width < x % width
- # Move to new line
- cy = cx / width + 1
- # Move to start
- cx = cy * width
- end
- # Get Draw X
- dx = cx % width + x
- # Get Draw Y
- dy = cx / width * height + y
- # Draw Text
- draw_text(dx, dy, word_width, 32, word)
- # Increase by Word Width
- cx += word_width
- end
- end
- #-------------------------------------------------------------------------
- # Name : Draw Paragraph
- # Info : Draws a Paragraph
- # Author : SephirothSpawn
- # Call Info : Five
- # Integer X and Y, Define Position
- # Integer Width, defines the width of the text rectangle
- # String Text, Information to Draw
- # Integer Indent Amount of Space to indent by
- # Integer Line_Height line height
- #-------------------------------------------------------------------------
- def draw_paragraph(x, y, width, text, indent = 32, line_height = 24)
- ox, oy = indent, 0
- for word in text.split
- ow = text_size(word).width
- if ow + ox > width
- ox = 0
- oy += line_height
- end
- ow = [ow, width].min
- draw_text(x + ox, y + oy, ow, line_height, word)
- ox += ow + text_size(' ').width
- end
- end
- #-------------------------------------------------------------------------
- # Name : Draw Wrapped Text
- # Info : Draws Text with Text Wrap
- # Author : Trickster
- # Call Info : Five Arguments
- # Integer X and Y, Define Position
- # Integer Width, defines the width of the text rectangle
- # Integer Height, defines the height of the text
- # String Text, Text to be drawn
- #-------------------------------------------------------------------------
- def draw_wrap_text(x, y, width, height, text)
- # Get Array of Text
- strings = text.split
- # Run Through Array of Strings
- strings.each do |string|
- # Get Word
- word = string + ' '
- # Get Word Width
- word_width = text_size(word).width
- # If Can't Fit on Line move to next one
- x, y = 0, y + height if x + word_width > width
- # Draw Text Memory
- self.draw_text(x, y, word_width, height, word)
- # Add To X
- x += word_width
- end
- end
- #--------------------------------------------------------------------------
- # Name : Draw Icon Text
- # Info : Draws Icons & Text together
- # Author : SephirothSpawn
- # Call Info : Five or Six Arguments
- # X & Y - Top-left coordinates of text rectangle
- # Width & Height - Size of text rectangle
- # Text - String or text and icons
- # A - alignment, same as draw_text alignment
- # Comments : Format for String : "text [icon_filename] text text..."
- #--------------------------------------------------------------------------
- def draw_icon_text(x, y, width, height, text, a = 0)
- # Gets Text & Icons
- text, icons = *Bitmap.string_to_text_icons(text)
- # Gets Icon, Text, Space & Total Width
- icn_w, txt_w, spc_w, tot_w = *Bitmap.icon_text_sizes(text, icons)
- # If Icon Width Greater than Width
- if icn_w + (icons.size - 1) * spc_w > width
- # Print Error
- p 'Text Width Not Big Enough.'
- return
- end
- # If Total Width Less than Text W
- if tot_w <= width
- # Gets Start Point
- ox = a == 0 ? 0 : a == 1 ? width / 2 - tot_w / 2 : width - tot_w
- # Pass Through Text
- text.each do |word|
- # If Word is nil
- if word.nil?
- # Gets Icon
- icon = icons.shift
- # Next if Nil Icon
- next if icon.nil?
- # Draws Icon
- x_, y_ = x + ox, y + (height - icon.height) / 2
- self.blt(x_, y_, icon, icon.rect, self.font.color.alpha)
- # Adds to OX
- ox += icon.width + spc_w
- next
- end
- # Draws Text
- self.draw_text(x + ox, y, width, height, word)
- # Adds to OX
- ox += self.text_size(word).width + spc_w
- end
- # If Total Width Greater than Text W
- else
- # Gets Difference
- diff = width - icn_w
- # Percent Txt Width
- percent = (txt_w + (icons.size - 1) * spc_w) / width.to_f
- # Alter Space Width
- spc_w = Integer(spc_w * percent)
- # Gets Start Point
- ox = 0
- # Pass Through Text
- text.each do |word|
- # If Word is nil
- if word.nil?
- # Gets Icon
- icon = icons.shift
- # Next if Nil Icon
- next if icon.nil?
- # Draws Icon
- x_, y_ = x + ox, y + (height - icon.height) / 2
- self.blt(x_, y_, icon, icon.rect, self.font.color.alpha)
- # Adds to OX
- ox += icon.width + spc_w
- next
- end
- # Draws Text
- w_ = Integer(self.text_size(word).width * percent)
- self.draw_text(x + ox, y, w_, height, word)
- # Adds to OX
- ox += w_ + spc_w
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Object Aliasing
- #--------------------------------------------------------------------------
- if @font_addons_alias.nil?
- alias_method :basic_draw_text, :draw_text
- @font_addons_alias = true
- end
- #--------------------------------------------------------------------------
- # * Draw Text
- #--------------------------------------------------------------------------
- def draw_text(*args)
- # Create Conditions Hash
- conditions = {
- :draw_text_shadow => self.font.shadow,
- :draw_text_outline => self.font.outline,
- :draw_text_underline => self.font.underline,
- :draw_text_strikethrough => self.font.strikethrough,
- :draw_text_gradient => self.font.vert_grad || self.font.horiz_grad
- }
- # Pass through font effects
- for effect in Font::Addon_Order
- # If Draw Text
- if effect == :draw_text
- basic_draw_text(*args)
- next
- end
- # If Condition
- if conditions[effect]
- # Call Method
- send(effect, *args)
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Draw Text : Get Positions
- #--------------------------------------------------------------------------
- def draw_text_positions(*args)
- if (r = args[0]).is_a?(Rect)
- x, y, w, h, t = r.x, r.y, r.width, r.height, args[1]
- a = args.size == 3 ? args[2] : 0
- else
- x, y, w, h, t = args[0], args[1], args[2], args[3], args[4]
- a = args.size == 6 ? args[5] : 0
- end
- return x, y, w, h, t, a
- end
- #--------------------------------------------------------------------------
- # * Draw Text : Effect Shadow
- #--------------------------------------------------------------------------
- def draw_text_shadow(*args)
- orig_color = font.color.dup
- self.font.color = self.font.shadow_color
- x, y, w, h, t, a = *draw_text_positions(*args)
- basic_draw_text(x + 2, y + 2, w, h, t, a)
- self.font.color = orig_color
- end
- #--------------------------------------------------------------------------
- # * Draw Text : Outline Shadow
- #--------------------------------------------------------------------------
- def draw_text_outline(*args)
- orig_color = font.color.dup
- self.font.color = self.font.outline_color
- x, y, w, h, t, a = *draw_text_positions(*args)
- for i in -1..1
- for j in -1..1
- basic_draw_text(x + i, y + j, w, h, t, a)
- end
- end
- self.font.color = orig_color
- end
- #--------------------------------------------------------------------------
- # * Draw Text : Effect Underline
- #--------------------------------------------------------------------------
- def draw_text_underline(*args)
- u_color = font.color.dup
- x, y, w, h, t, a = *draw_text_positions(*args)
- ux = x
- uy = y + h / 2 + font.size / 3
- if font.underline_full
- uw = w
- else
- uw = text_size(args[1]).width
- ux += a == 1 ? w / 2 - uw / 2 : w - uw
- end
- fill_rect(u_x, u_y, u_width, 1, u_color)
- end
- #--------------------------------------------------------------------------
- # * Draw Text : Effect Strikethrough
- #--------------------------------------------------------------------------
- def draw_text_strikethrough(*args)
- x, y, w, h, t, a = *draw_text_positions(*args)
- sx = x
- sy = y + h / 2
- if font.strikethrough_full
- sw = w
- else
- sw = text_size(args[1]).width
- sx += a == 1 ? w / 2 - sw / 2 : w - sw
- end
- fill_rect(s_x, s_y, s_width, 1, s_color)
- end
- #--------------------------------------------------------------------------
- # * Draw Text : Effect Gradient
- #--------------------------------------------------------------------------
- def draw_text_gradient(*args)
- x, y, w, h, t, a = *draw_text_positions(*args)
- # If Draw Vertical Font Gradient
- if self.font.vert_grad || self.font.horiz_grad
- # Creates Dummy Bitmap
- dummy = Bitmap.new(w, h)
- dummy.font = font
- dummy.font.vert_grad = false
- dummy.font.horiz_grad = false
- dummy.basic_draw_text(0, 0, w, h, t, a)
- # Gets Cached Bitmap
- if font.vert_grad
- # Applys Gradient Pixel Change
- dummy.v_gradient_pixel_change(font.grad_s_color, font.grad_e_color)
- else
- # Applys Gradient Pixel Change
- dummy.h_gradient_pixel_change(font.grad_s_color, font.grad_e_color)
- end
- # Draw Dummy Bitmap over self
- self.blt(x, y, dummy, dummy.rect)
- end
- end
- end
- #==============================================================================
- # ** RGSS.Character
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Miscellaneous methods for RGSS classes.
- #
- # Method List:
- # ------------
- #
- # Game_Character
- # --------------
- # opacity=
- # battler=
- # battler
- # critical=
- # critical
- # damage=
- # damage
- # damage_pop=
- # damage_pop
- # can_jump?
- # moving_down?
- # moving_left?
- # moving_right?
- # moving_up?
- # can_move_toward_event?
- # can_move_toward_target?
- # move_toward_event
- # move_toward_target
- # turn_toward_event
- # turn_toward_target
- #
- # Game_Player
- # -----------
- # disable_player_movement
- # disable_player_trigger
- #
- # Game_Event
- # ----------
- # event
- # erased
- # event_comment_list
- #==============================================================================
- MACL::Loaded << 'RGSS.Miscellaneous Methods'
- #==============================================================================
- # ** Game_Character
- #==============================================================================
- class Game_Character
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_writer :opacity
- attr_accessor :battler
- attr_accessor :critical
- attr_accessor :damage
- attr_accessor :damage_pop
- #--------------------------------------------------------------------------
- # * Alias Listings
- #--------------------------------------------------------------------------
- alias_method :macl_rgsschar_init, :initialize
- alias_method :macl_rgsschar_updt, :update
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(*args)
- # Set character settings
- @battler = nil
- @critical = false
- @damage = nil
- @damage_pop = false
- # Original Initialization
- macl_rgsschar_init(*args)
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- # Original Update
- macl_rgsschar_updt
- # Refresh
- refresh
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- # Set character file name and hue
- if @battler != nil
- # If Dead
- if @battler.dead?
- @character_name = ''
- @character_hue = 0
- return
- end
- @character_name = @battler.character_name
- @character_hue = @battler.character_hue
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Can Jump?
- # Info : Returns if Can Jump
- # Author : SephirothSpawn
- # Call Info : Integer Amounts, X & Y Plus
- #-------------------------------------------------------------------------
- def can_jump?(x_plus, y_plus)
- new_x = @x + x_plus
- new_y = @y + y_plus
- return (x_plus == 0 and y_plus == 0) || passable?(new_x, new_y, 0)
- end
- #-------------------------------------------------------------------------
- # * Name : Moving Down
- # Info : Returns if moving down
- # Author : SephirothSpawn
- # Call Info : None
- #-------------------------------------------------------------------------
- def moving_down?
- return @y * 128 > @real_y
- end
- #-------------------------------------------------------------------------
- # * Name : Moving Left
- # Info : Returns if moving left
- # Author : SephirothSpawn
- # Call Info : None
- #-------------------------------------------------------------------------
- def moving_left?
- return @x * 128 < @real_x
- end
- #-------------------------------------------------------------------------
- # * Name : Moving Right
- # Info : Returns if moving right
- # Author : SephirothSpawn
- # Call Info : None
- #-------------------------------------------------------------------------
- def moving_right?
- return @x * 128 > @real_x
- end
- #-------------------------------------------------------------------------
- # * Name : Moving Up
- # Info : Returns if moving up
- # Author : SephirothSpawn
- # Call Info : None
- #-------------------------------------------------------------------------
- def moving_up?
- return @y * 128 < @real_y
- end
- #-------------------------------------------------------------------------
- # * Name : Can Move Towards Event?
- # Info : Checks if character can move towards event
- # Author : SephirothSpawn
- # Call Info : Integer Amount, Event ID (or 0 for player)
- #-------------------------------------------------------------------------
- def can_move_toward_event?(event_id = 1)
- c = event_id == 0 ? $game_player : $game_map.events[event_id]
- return false if c.nil?
- return can_move_toward_target?(c.x, c.y)
- end
- #-------------------------------------------------------------------------
- # * Name : Can Move Towards Target?
- # Info : Checks if character can move towards target
- # Author : SephirothSpawn
- # Call Info : Integer Amounts, Destination X & Y
- #-------------------------------------------------------------------------
- def can_move_toward_target?(x, y)
- # Get difference in player coordinates
- sx = @x - x
- sy = @y - y
- # If coordinates are equal, return false
- return false if sx == 0 and sy == 0
- # Get absolute value of difference
- abs_sx = sx.abs
- abs_sy = sy.abs
- # Passable Testings
- pass = {2 => passable?(@x, @y, 2), 4 => passable?(@x, @y, 4),
- 6 => passable?(@x, @y, 6), 8 => passable?(@x, @y, 8),
- 24 => passable?(@x, @y, 2) && passable?(@x, @y + 1, 4),
- 26 => passable?(@x, @y, 2) && passable?(@x, @y + 1, 6),
- 42 => passable?(@x, @y, 4) && passable?(@x - 1, @y, 2),
- 48 => passable?(@x, @y, 4) && passable?(@x - 1, @y, 8),
- 62 => passable?(@x, @y, 6) && passable?(@x + 1, @y, 2),
- 68 => passable?(@x, @y, 6) && passable?(@x + 1, @y, 8),
- 84 => passable?(@x, @y, 8) && passable?(@x, @y - 1, 4),
- 86 => passable?(@x, @y, 8) && passable?(@x, @y - 1, 6)}
- # Movement Testings
- if abs_sx > abs_sy
- if sx != 0
- if sx > 0
- return true, 4 if pass[4]
- sy > 0 ? (return true, 8 if pass[84]) : (return true, 2 if pass[24])
- else
- return true, 6 if pass[6]
- sy > 0 ? (return true, 8 if pass[86]) : (return true, 2 if pass[26])
- end
- end
- if sy != 0
- if sy > 0
- return true, 8 if pass[8]
- sx > 0 ? (return true, 4 if pass[48]) : (return true, 6 if pass[68])
- else
- return true, 2 if pass[2]
- sx > 0 ? (return true, 4 if pass[42]) : (return true, 6 if pass[62])
- end
- end
- else
- if sy != 0
- if sy > 0
- return true, 8 if pass[8]
- sx > 0 ? (return true, 4 if pass[48]) : (return true, 6 if pass[68])
- else
- return true, 2 if pass[2]
- sx > 0 ? (return true, 4 if pass[42]) : (return true, 6 if pass[62])
- end
- end
- if sx != 0
- if sx > 0
- return true, 4 if pass[4]
- sy > 0 ? (return true, 8 if pass[84]) : (return true, 2 if pass[24])
- else
- return true, 6 if pass[6]
- sy > 0 ? (return true, 8 if pass[86]) : (return true, 2 if pass[26])
- end
- end
- end
- # Return False if No Possible Moves
- return false
- end
- #-------------------------------------------------------------------------
- # * Name : Move Towards Event
- # Info : Moves character towards event
- # Author : SephirothSpawn
- # Call Info : Integer Amount, Event ID (or 0 for player)
- #-------------------------------------------------------------------------
- def move_towards_event(event_id = 1)
- c = event_id == 0 ? $game_player : $game_map.events[event_id]
- return if c.nil?
- move_toward_target(c.x, c.y)
- end
- #-------------------------------------------------------------------------
- # * Name : Move Towards Target
- # Info : Moves character towards target position
- # Author : SephirothSpawn
- # Call Info : Integer Amounts, Destination X & Y
- #-------------------------------------------------------------------------
- def move_toward_target(x, y)
- # Gets Test Status
- can, dir = can_move_toward_target?(x, y)
- # Returns If Can't Move
- return unless can
- # Moves By Direction
- move_down if dir == 2
- move_left if dir == 4
- move_right if dir == 6
- move_up if dir == 8
- end
- #-------------------------------------------------------------------------
- # * Name : Turn Towards Event
- # Info : Turns character towards event
- # Author : SephirothSpawn
- # Call Info : Integer Amount, Event ID (or 0 for player)
- #-------------------------------------------------------------------------
- def turn_toward_event(event_id = 1)
- c = event_id == 0 ? $game_player : $game_map.events[event_id]
- return if c.nil?
- turn_toward_target(c.x, c.y)
- end
- #-------------------------------------------------------------------------
- # * Name : Turn Towards Target
- # Info : Turns character towards target position
- # Author : SephirothSpawn
- # Call Info : Integer Amounts, Destination X & Y
- #-------------------------------------------------------------------------
- def turn_toward_target(x, y)
- # Get difference in target coordinates
- sx, sy = @x - x, @y - y
- # If coordinates are equal
- return if sx == 0 && sy == 0
- # If horizontal distance is longer
- if sx.abs > sy.abs
- # Turn to the right or left towards player
- sx > 0 ? turn_left : turn_right
- # If vertical distance is longer
- else
- # Turn up or down towards player
- sy > 0 ? turn_up : turn_down
- end
- end
- end
- #==============================================================================
- # ** Game_Player
- #==============================================================================
- class Game_Player
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_accessor :disable_player_movement
- attr_accessor :disable_player_trigger
- #--------------------------------------------------------------------------
- # * Alias Listings
- #--------------------------------------------------------------------------
- alias_method :macl_gmplyr_init, :initialize
- alias_method :macl_gmplyr_pass?, :passable?
- alias_method :macl_gmplyr_ceth, :check_event_trigger_here
- alias_method :macl_gmplyr_cett, :check_event_trigger_there
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize
- # Original Initialization
- macl_gmplyr_init
- # Set game player settings
- @battler = $game_party.actors[0]
- @disable_player_movement = false
- @disable_player_trigger = false
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- # If party members = 0
- if $game_party.actors.size == 0
- # Clear character file name and hue
- @character_name = ''
- @character_hue = 0
- # End method
- return
- end
- # Set lead actor
- @battler = $game_party.actors[0]
- # Parent Refresh
- super
- # Initialize opacity level and blending method
- @opacity = 255
- @blend_type = 0
- end
- #--------------------------------------------------------------------------
- # * Passable Determinants
- #--------------------------------------------------------------------------
- def passable?(x, y, d)
- # Return false if Disable Player Movement
- return false if disable_player_movement
- # Return Orginal Result
- return macl_gmplyr_pass?(x, y, d)
- end
- #--------------------------------------------------------------------------
- # * Same Position Starting Determinant
- #--------------------------------------------------------------------------
- def check_event_trigger_here(triggers)
- # Return false if disable player trigger
- return false if disable_player_trigger
- # Return Orginal Result
- return macl_gmplyr_ceth(triggers)
- end
- #--------------------------------------------------------------------------
- # * Front Envent Starting Determinant
- #--------------------------------------------------------------------------
- def check_event_trigger_there(triggers)
- # Return false if disable player trigger
- return false if disable_player_trigger
- # Return Orginal Result
- return macl_gmplyr_cett(triggers)
- end
- end
- #==============================================================================
- # ** Game_Event
- #==============================================================================
- class Game_Event
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_reader :erased
- attr_reader :event
- #-------------------------------------------------------------------------
- # * Name : Event Comment List
- # Info : Gets the Info from the comments in events
- # returns A Hash setup like so {'trigger' => info}
- # Author : Trickster
- # Call Info : Variable Amount, String used for triggers
- # Comments : Detects Integers, Floats, Arrays and Hashes, else its a string
- #-------------------------------------------------------------------------
- def event_comment_list(*triggers)
- # Setup Parameters
- parameters = {}
- # Run Through Each Page With Index
- @event.pages.each_with_index do |page, index|
- parameters[index] = {}
- list = page.list
- return if list == nil or not list.is_a?(Array)
- list.each do |command|
- next if command.code != 108
- comment = command.parameters[0]
- array = comment.split
- trigger = array[0]
- value = array[1...array.size].join
- value = value.to_i if value =~ /\d+/
- value = value.to_f if value =~ /\d+\.\d+/
- value = eval(value) if value =~ /\[\.+\]/ or value =~ /\{\.+\}/
- parameters[index][trigger] = value if triggers.include?(trigger)
- end
- end
- return parameters
- end
- end
- #==============================================================================
- # ** Sprite_Character
- #==============================================================================
- class Sprite_Character
- #--------------------------------------------------------------------------
- # * Alias Listings
- #--------------------------------------------------------------------------
- alias_method :sephmaclchdp_schr_update, :update
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- sephmaclchdp_schr_update
- return if @character.nil? || self.visible == false || self.bitmap.nil?
- # Damage
- if @character.damage_pop
- damage(@character.damage, @character.critical)
- @character.damage = nil
- @character.critical = false
- @character.damage_pop = false
- end
- end
- end
- #==============================================================================
- # ** RGSS.Color.colors
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # This Set Defines the Basic Colors so now you can do Color.(color) to define a
- # Color Also Adds methods to create colors easily.
- #
- # Method List:
- # ------------
- # Color.color_between
- # Color.red
- # Color.green
- # Color.blue
- # Color.yellow
- # Color.orange
- # Color.purple
- # Color.white
- # Color.black
- # Color.gray
- # Color.clear
- # Color.normal
- # Color.disabled
- # Color.system
- # Color.crisis
- # Color.knockout
- # Color.get_color
- #==============================================================================
- MACL::Loaded << 'RGSS.Color.colors'
- #==============================================================================
- # ** Color
- #==============================================================================
- class Color
- #-------------------------------------------------------------------------
- # * Color Between Memory
- #-------------------------------------------------------------------------
- @color_between = {}
- #-------------------------------------------------------------------------
- # * Name : Color Between
- # Info : Gets Color Between Two colors given the percent
- # Author : SephirothSpawn
- # Call Info : Start Color, Finish Color, Percent
- #-------------------------------------------------------------------------
- def self.color_between(color_a, color_b, percent = 0.5)
- # Gets Save Key
- key = [color_a, color_b, percent]
- if @color_between.has_key?(key)
- return @color_between[key]
- end
- # Calculates New Color
- r = Integer(color_a.red + (color_b.red - color_a.red) * percent)
- g = Integer(color_a.green + (color_b.green - color_a.green) * percent)
- b = Integer(color_a.blue + (color_b.blue - color_a.blue) * percent)
- a = Integer(color_a.alpha + (color_b.alpha - color_a.alpha) * percent)
- # Saves Color
- @color_between[key] = Color.new(r, g, b, a)
- # Returns Color
- return @color_between[key]
- end
- #-------------------------------------------------------------------------
- # * Name : Red
- # Info : Red Color (255,0,0)
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def self.red
- return Color.new(255,0,0)
- end
- #-------------------------------------------------------------------------
- # Name : Green
- # Info : Green Color (0,128,0)
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def self.green
- return Color.new(0,128,0)
- end
- #-------------------------------------------------------------------------
- # Name : Blue
- # Info : Blue Color (0,0,255)
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def self.blue
- return Color.new(0,0,255)
- end
- #-------------------------------------------------------------------------
- # Name : Yellow
- # Info : Yellow Color (255, 255, 0)
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def self.yellow
- return Color.new(255,255,0)
- end
- #-------------------------------------------------------------------------
- # Name : Purple
- # Info : Purple Color (128,0,128)
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def self.purple
- return Color.new(128,0,128)
- end
- #-------------------------------------------------------------------------
- # Name : Orange
- # Info : Orange Color (255,128,0)
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def self.orange
- return Color.new(255, 128, 0)
- end
- #-------------------------------------------------------------------------
- # Name : White
- # Info : White Color (255,255,255)
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def self.white
- return Color.new(255, 255, 255)
- end
- #-------------------------------------------------------------------------
- # Name : Black
- # Info : Black Color (0,0,0)
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def self.black
- return Color.new(0,0,0)
- end
- #-------------------------------------------------------------------------
- # Name : Gray
- # Info : Gray Color (128,128,128)
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def self.gray
- return Color.new(128, 128, 128)
- end
- #-------------------------------------------------------------------------
- # Name : Clear
- # Info : Transparent Color
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def self.clear
- return Color.new(0, 0, 0, 0)
- end
- #-------------------------------------------------------------------------
- # Name : Normal
- # Info : Normal Color (255,255,255)
- # Author : SephirothSpawn
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def Color.normal
- return Color.new(255, 255, 255, 255)
- end
- #-------------------------------------------------------------------------
- # Name : Disabled
- # Info : Disabled Color (255,255,255,128)
- # Author : SephirothSpawn
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def Color.disabled
- return Color.new(255, 255, 255, 128)
- end
- #-------------------------------------------------------------------------
- # Name : System
- # Info : System Color (192,224,255)
- # Author : SephirothSpawn
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def Color.system
- return Color.new(192, 224, 255, 255)
- end
- #-------------------------------------------------------------------------
- # Name : Crisis
- # Info : Crisis Color (255,255,64)
- # Author : SephirothSpawn
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def Color.crisis
- return Color.new(255, 255, 64, 255)
- end
- #-------------------------------------------------------------------------
- # Name : Knockout
- # Info : Knockout Color (255,64,0)
- # Author : SephirothSpawn
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def Color.knockout
- return Color.new(255, 64, 0)
- end
- #-------------------------------------------------------------------------
- # Name : Get Color
- # Info : Gets a Color
- # Author : Trickster
- # Call Info : Integer Value the color code to get
- # Comment : 0: Clear 1: Red 2: Blue 3:Yellow 4: Purple 5:Orange 6:Green
- # 7:White 8: Black - 10 for lighter + 10 for darker
- #-------------------------------------------------------------------------
- def self.get_color(value)
- # Convert to 0-8
- color_value = value < 0 ? value + 10 : value % 10
- # Branch According to number
- case color_value
- when 0 # Clear
- return
- when 1 # Red
- r = 255; g = 0; b = 0
- when 2 # Blue
- r = 0; g = 0; b = 255
- when 3 # Yellow
- r = 255; g = 255; b = 0
- when 4 # Purple
- r = 255; g = 0; b = 255
- when 5 # Orange
- r = 255; g = 128; b = 0
- when 6 # Green
- r = 0; g = 255; b = 0
- when 7 # White
- r = 255; g = 255; b = 255
- when 8 # Black
- r = 0; g = 0; b = 0
- end
- # Convert if Lighter/Darker
- if value < 0
- r += 64; g += 64; b += 64
- elsif value > 10
- r -= 64; g -= 64; b -= 64
- end
- # Correction
- r = [[0,r].max, 255].min
- g = [[0,g].max, 255].min
- b = [[0,b].max, 255].min
- return Color.new(r,g,b)
- end
- end
- #==============================================================================
- # ** RGSS.Color.compare
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Adds Color Comparision methods too the color class
- #
- # Method List:
- # ------------
- # ==
- # same?
- #==============================================================================
- MACL::Loaded << 'RGSS.Color.compare'
- #==============================================================================
- # ** Color
- #==============================================================================
- class Color
- #-------------------------------------------------------------------------
- # Name : == (Equals Comparison)
- # Info : Comparision Method (checks if r, g, b, and a are equal)
- # Author : Trickster
- # Call Info : Color other color to test
- #-------------------------------------------------------------------------
- def ==(other)
- return (red == other.red && green == other.green && blue == other.blue &&
- alpha == other.alpha)
- end
- #-------------------------------------------------------------------------
- # Name : Same?
- # Info : Same Color (r, g, and b are equal)
- # Author : Trickster
- # Call Info : Color other color to test
- #-------------------------------------------------------------------------
- def same?(other)
- return (red == other.red && green == other.green && blue == other.blue)
- end
- end
- #==============================================================================
- # ** RGSS.Color.hsb
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Adds a new color space to the Color class that allows to change the hue
- # saturation and value (brightness). Also adds methods to create new colors
- # based on an Hue, Saturation, and Brightness value. The Domain and Range
- # of the three new values are Hue - [0-360), Saturation [0-100],
- # Brightness [0-100].
- # Formula is from the wikipedia.
- #
- # Method List:
- # ------------
- # Color.to_hsb
- # Color.hsb_new
- # Color.hsb_to_rgb
- # to_hsb
- # to_rgb
- # hue
- # saturation
- # brightness
- # value
- # hue=
- # saturation=
- # brightness=
- # value=
- #
- # Modified Methods:
- # -----------------
- # initialize
- # set
- # red=
- # green=
- # blue=
- #
- # Deprecated Methods from V1.5:
- # -----------------------------
- # hsb_to_rgb
- #==============================================================================
- MACL::Loaded << 'RGSS.Color.hsb'
- #==============================================================================
- # ** Color
- #==============================================================================
- class Color
- #-------------------------------------------------------------------------
- # * Alias Listings
- #-------------------------------------------------------------------------
- unless self.method_defined?(:trick_color_hsb_initialize)
- alias_method :trick_color_hsb_initialize, :initialize
- alias_method :trick_color_hsb_set, :set
- alias_method :trick_color_hsb_red=, :red=
- alias_method :trick_color_hsb_green=, :green=
- alias_method :trick_color_hsb_blue=, :blue=
- end
- #-------------------------------------------------------------------------
- # * Object Initialization
- #-------------------------------------------------------------------------
- def initialize(*args)
- trick_color_hsb_initialize(*args)
- @hue, @saturation, @brightness = to_hsb
- end
- #-------------------------------------------------------------------------
- # * Set
- #-------------------------------------------------------------------------
- def set(*args)
- trick_color_hsb_set(*args)
- @hue, @saturation, @brightness = to_hsb
- end
- #-------------------------------------------------------------------------
- # * Red
- #-------------------------------------------------------------------------
- def red=(red)
- # The Usual
- self.trick_color_hsb_red=(red)
- # Update HSB
- @hue, @saturation, @brightness = to_hsb
- end
- #-------------------------------------------------------------------------
- # * Green
- #-------------------------------------------------------------------------
- def green=(green)
- # The Usual
- self.trick_color_hsb_green=(green)
- # Update HSB
- @hue, @saturation, @brightness = to_hsb
- end
- #-------------------------------------------------------------------------
- # * Blue
- #-------------------------------------------------------------------------
- def blue=(blue)
- # The Usual
- self.trick_color_hsb_blue=(blue)
- # Update HSB
- @hue, @saturation, @brightness = to_hsb
- end
- #-------------------------------------------------------------------------
- # * Name : To HSB (Class method)
- # Info : Converts to Hue, Saturation, and Brightness
- # returns an array setup like so: [hue, sat, bright]
- # Author : Trickster
- # Call Info : One or Three Arguments
- # For One Argument - Color color Color to convert
- # For Three Arguments - Integer red, blue, green color values to
- # convert
- #-------------------------------------------------------------------------
- def self.to_hsb(r, g, b)
- # Correction if Greater than 255
- r,g,b = [r,g,b].collect! {|color| color = 255 if color > 255}
- # Get Maximum
- max = [r,g,b].max.to_f
- # Get Minimum
- min = [r,g,b].min.to_f
- # Calculate hue
- h = 60 * (g - b) / (max - min) if max == r and g >= b
- h = 60 * (g - b) / (max - min) + 360 if max == r and g < b
- h = 60 * (b - r) / (max - min) + 120 if max == g
- h = 60 * (r - g) / (max - min) + 240 if max == b
- h = 0 if max == min
- # Calculate Saturation
- s = max == 0 ? 0 : 100 * (1-min/max)
- # Calculate Brightness
- v = 100 * max / 255
- # Return Hue, Saturation, And Value
- return h,s,v
- end
- #-------------------------------------------------------------------------
- # * Name : To HSB
- # Info : Converts to Hue, Saturation, and Brightness
- # returns an array setup like so: [hue, sat, bright]
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def to_hsb
- return self.class.to_hsb(red, green, blue)
- end
- #-------------------------------------------------------------------------
- # * Name : HSB New (Class Method)
- # Info : Creates a new color based on Hue Sat and Brightness + Alpha
- # Author : Trickster
- # Call Info : Three or Four Arguements
- # Integer hue,sat,bri - Hue, Saturation, and Brightness
- # Integer Alpha - Transparency Defaults to 255
- #-------------------------------------------------------------------------
- def self.hsb_new(hue, sat, bri, alpha = 255)
- # Get Colors
- red, green, blue = Color.hsb_to_rgb(hue, sat, bri)
- # Create and Return Color
- return Color.new(red, green, blue, alpha)
- end
- #-------------------------------------------------------------------------
- # * Name : HSB To RGB
- # Info : HSB to RGB Color Conversion
- # An array setup like so [red, green, blue]
- # Author : Trickster
- # Call Info : Three Arguments.
- # Integer hue,sat,bri - Hue, Saturation, and Brightness
- #-------------------------------------------------------------------------
- def self.hsb_to_rgb(hue, sat, bri)
- # Convert All To Floats
- hue, sat, bri = hue.to_f, sat.to_f , bri.to_f
- # Ensure Hue is [0, 360)
- hue %= 360
- # Reduce to [0, 1]
- sat = sat > 100 ? 1.0 : sat / 100
- bri = bri > 100 ? 1.0 : bri / 100
- # Get Sector
- sector = (hue / 60).to_i
- f = hue / 60 - sector
- p = bri * (1 - sat)
- q = bri * (1 - f * sat)
- t = bri * (1 - (1 - f) * sat)
- # Branch By Sector and get r,g,b values
- case sector
- when 0...1
- r,g,b = bri,t,p
- when 1...2
- r,g,b = q,bri,p
- when 2...3
- r,g,b = p,bri,t
- when 3...4
- r,g,b = p,q,bri
- when 4...5
- r,g,b = t,p,bri
- when 5..6
- r,g,b = bri,p,q
- end
- # Set Color
- color = [r,g,b]
- # Convert to [0, 255] Range
- color.collect! {|value| value * 255}
- # Return Color
- return color
- end
- #-------------------------------------------------------------------------
- # * Name : To RGB
- # Info : Converts to Red, Green, Blue
- # Author : Trickster
- # Call Info : An Array setup like so [red, green, blue]
- # Comment : Not Very Useful, but included anyway.
- #-------------------------------------------------------------------------
- def to_rgb
- return red, green, blue
- end
- #-------------------------------------------------------------------------
- # * Name : Get Hue
- # Info : Gets the hue
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def hue
- # If Hue is undefined set HSB
- @hue, @saturation, @brightness = to_hsb if @hue == nil
- # Return hue
- return @hue
- end
- #-------------------------------------------------------------------------
- # * Name : Get Saturation
- # Info : Gets the Saturation
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def saturation
- # If Saturation is undefined set HSB
- @hue, @saturation, @brightness = to_hsb if @saturation == nil
- # Return Saturation
- return @saturation
- end
- #-------------------------------------------------------------------------
- # * Name : Get Brightness
- # Info : Gets the Brightness
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def brightness
- # If Brightness is undefined set HSB
- @hue, @saturation, @brightness = to_hsb if @brightness == nil
- # Return Brightness
- return @brightness
- end
- #-------------------------------------------------------------------------
- # * Name : Get Value
- # Info : Gets the Value
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def value
- return brightness
- end
- #-------------------------------------------------------------------------
- # * Name : Set Hue
- # Info : Sets the Hue, Updates RGB
- # Author : Trickster
- # Call Info : One Arguement Integer new_hue, The New Hue
- # Comment : May be used as a replacement to <bitmap>.hue_change, which
- # lags and when used many times creates graphical errors
- #-------------------------------------------------------------------------
- def hue=(new_hue)
- # Set HSB if Hue is nil
- @hue, @saturation, @brightness = to_hsb if @hue == nil
- # Ensure domain [0, 360) and set to new hue
- @hue = new_hue % 360
- # Get RGB Values
- rgb = Color.hsb_to_rgb(@hue, @saturation, @brightness)
- # Set Red Green And Blue Values by Converting to rgb
- self.red, self.green, self.blue = rgb
- end
- #-------------------------------------------------------------------------
- # * Name : Set Saturation
- # Info : Sets the Saturation, Updates RGB
- # Author : Trickster
- # Call Info : One Arguement Integer new_sat, The New Saturation
- #-------------------------------------------------------------------------
- def saturation=(new_sat)
- # Set HSB if Saturation is nil
- @hue, @saturation, @brightness = self.to_hsb if @saturation == nil
- # Set Saturation
- @saturation = new_sat
- # Get RGB Values
- rgb = Color.hsb_to_rgb(@hue, @saturation, @brightness)
- # Set Red Green And Blue Values by Converting to rgb
- self.red, self.green, self.blue = rgb
- end
- #-------------------------------------------------------------------------
- # * Name : Set Brightness
- # Info : Sets the Brightness, Updates RGB
- # Author : Trickster
- # Call Info : One Arguement Integer new_bri, The New Brightness
- #-------------------------------------------------------------------------
- def brightness=(new_bri)
- # Set HSB if Brightness is nil
- @hue, @saturation, @brightness = self.to_hsb if @brightness == nil
- # Set New Brightness
- @brightness = new_bri
- # Get RGB Values
- rgb = Color.hsb_to_rgb(@hue, @saturation, @brightness)
- # Set Red Green And Blue Values by Converting to rgb
- self.red, self.green, self.blue = rgb
- end
- #-------------------------------------------------------------------------
- # * Name : Set Value
- # Info : Sets the Value, Updates RGB
- # Author : Trickster
- # Call Info : One Arguement Integer new_val, The New Value
- # Comment : Synomym for brightness=
- #-------------------------------------------------------------------------
- def value=(val)
- # Set Brightness
- self.brightness = val
- end
- end
- #==============================================================================
- # ** RGSS.Enemy and Troop Info
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # These set of methods add observer methods to the Game_Enemy and Game_Troop
- # classes, you can get information on how weak an enemy is to a state, all
- # of the enemies resistances and weaknesses, etc.
- #
- # Method List:
- # ------------
- #
- # Game_Enemy
- # ----------
- # character_name
- # character_hue
- # element_effectiveness
- # state_effectiveness
- # skills
- # elements
- # element_test
- # weaknesses
- # resistance
- #
- # Game_Troop
- # ----------
- # strongest
- # weakest
- # existing_enemies
- # has_enemies?
- #
- # RGP::Enemy
- # ----------
- # element_test
- # weakness
- # resistance
- #
- # RPG::Troop
- # ----------
- # has_enemy?
- #==============================================================================
- MACL::Loaded << 'RGSS.Enemy and Troop Info'
- #==============================================================================
- # ** Game_Enemy
- #==============================================================================
- class Game_Enemy
- #-------------------------------------------------------------------------
- # * Name : Character Name
- # Info : Returns Character Filename (Battler Name by Default)
- # Author : SephirothSpawn
- # Call Info : None
- #-------------------------------------------------------------------------
- def character_name
- return self.battler_name
- end
- #-------------------------------------------------------------------------
- # * Name : Character Hue
- # Info : Returns Character Filename Hue (Battler Hue by Default)
- # Author : SephirothSpawn
- # Call Info : None
- #-------------------------------------------------------------------------
- def character_hue
- return self.battler_hue
- end
- #-------------------------------------------------------------------------
- # Name : Element Effectiveness
- # Info : How Effective Enemy is against an Element
- # An Integer from 0-5 (5: most effective 0: not effective at all)
- # Author : Trickster
- # Call Info : Integer Element_ID id of the element to check
- #-------------------------------------------------------------------------
- def element_effectiveness(element_id)
- # Get a numerical value corresponding to element effectiveness
- table = [0,5,4,3,2,1,0]
- effective = table[$data_enemies[@enemy_id].element_ranks[element_id]]
- # If protected by state, this element is reduced by half
- for i in @states
- if $data_states[i].guard_element_set.include?(element_id)
- effective = (effective / 2.0).ceil
- end
- end
- # End Method
- return effective
- end
- #-------------------------------------------------------------------------
- # Name : State Effectiveness
- # Info : How Effective Enemy is against a State
- # An Integer from 0-5 (5: most effective 0: ineffective)
- # Author : Trickster
- # Call Info : Integer State_ID id of the state to check
- #-------------------------------------------------------------------------
- def state_effectiveness(state_id)
- table = [0,5,4,3,2,1,0]
- effective = table[$data_enemies[@enemy_id].state_ranks[state_id]]
- return effective
- end
- #-------------------------------------------------------------------------
- # Name : Enemies Skills
- # Info : Returns all skills enemy can use
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def skills
- data = []
- actions.each {|action| data << action.skill_id if action.kind == 1}
- return data
- end
- #-------------------------------------------------------------------------
- # Name : Enemy's Elements
- # Info : Returns All Elements Enemy can use
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def elements
- elements = []
- skills.each {|skill_id| elements += $data_skills[skill_id].element_set}
- elements += element_set
- elements.uniq!
- return elements
- end
- #-------------------------------------------------------------------------
- # * Name : Element Test
- # Info : Returns Element Effiency Value
- # An Integer 1-6 representing the effiency
- # Author : Trickster
- # Call Info : One Argument Element_Id the element Id to test
- #-------------------------------------------------------------------------
- def element_test(element_id)
- # Get a numerical value corresponding to element effectiveness
- table = [0,6,5,4,3,2,1]
- result = table[$data_enemies[@enemy_id].element_ranks[element_id]]
- return result
- end
- #-------------------------------------------------------------------------
- # * Name : Weaknesses
- # Info : Returns Enemy Weaknesses
- # An Array of Element Ids for which an A or B effiency
- # Author : Trickster
- # Call Info : None
- #-------------------------------------------------------------------------
- def weaknesses
- weak = []
- MACL::Real_Elements.each {|i| weak << i if [6,5].include?(element_test(i))}
- return weak
- end
- #-------------------------------------------------------------------------
- # * Name : Resistance
- # Info : Returns Enemy Resistance
- # An Array of Element Ids for which an F or E or D effiency
- # Author : Trickster
- # Call Info : None
- #-------------------------------------------------------------------------
- def resistance
- resists = []
- MACL::Real_Elements.each {|i| resists << i if [1,2,3].include?(element_test(i))}
- return resists
- end
- end
- #==============================================================================
- # ** Game_Troop
- #==============================================================================
- class Game_Troop
- #-------------------------------------------------------------------------
- # Name : Strongest Enemy in Troop
- # Info : Gets Strongest Enemy, in terms of hp
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def strongest
- array = enemies.sort {|a,b| b.hp - a.hp}
- return array[0]
- end
- #-------------------------------------------------------------------------
- # Name : Weakest Enemy in Troop
- # Info : Gets Weakest Enemy, in terms of hp
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def weakest
- array = existing_enemies.sort! {|a,b| b.hp - a.hp}
- return array[-1]
- end
- #-------------------------------------------------------------------------
- # Name : Get Existing Enemies
- # Info : Gets All Non-Dead, Non-Hidden Enemies
- # Author : Trickster
- # Call Info : No Arguments
- #-------------------------------------------------------------------------
- def existing_enemies
- array = []
- enemies.each {|enemy| array << enemy if enemy.exist?}
- return array
- end
- #-------------------------------------------------------------------------
- # * Name : Has Enemies?
- # Info : Are These Enemy Ids in troop?
- # Author : Trickster
- # Call Info : Variable Amount Integer Enemy enemy id to check
- #-------------------------------------------------------------------------
- def has_enemies?(*enemies)
- # Setup Array
- enemy_ids = []
- # Get All Enemy IDs
- @enemies.each {|enemy| enemy_ids << enemy.id}
- # Run Through All Enemies Sent
- enemies.each_with_index do |enemy_id, index|
- # Return false if not included
- return false if not enemy_ids.include?(enemy_id)
- # Delete from Enemies
- enemies.delete_at(index)
- # Delete ONE from Enemy Ids
- enemy_ids.delete_at(enemy_ids.index(enemy_id))
- end
- # All Are Included
- return true
- end
- end
- #==============================================================================
- # ** RPG::Enemy
- #==============================================================================
- class RPG::Enemy
- #-------------------------------------------------------------------------
- # * Name : Element Test
- # Info : Returns Element Effiency Value
- # An Integer 1-6 representing the effiency
- # Author : Trickster
- # Call Info : One Argument Element_Id the element Id to test
- #-------------------------------------------------------------------------
- def element_test(element_id)
- # Get a numerical value corresponding to element effectiveness
- return [0,6,5,4,3,2,1][element_ranks[element_id]]
- end
- #-------------------------------------------------------------------------
- # * Name : Weaknesses
- # Info : Returns Enemy Weaknesses
- # An Array of Element Ids for which an A or B effiency
- # Author : Trickster
- # Call Info : None
- #-------------------------------------------------------------------------
- def weaknesses
- weak = []
- MACL::Real_Elements.each do |element_id|
- weak << element_id if [6,5].include?(element_test(element_id))
- end
- return weak
- end
- #-------------------------------------------------------------------------
- # * Name : Resistance
- # Info : Returns Enemy Resistance
- # An Array of Element Ids for which an F or E effiency
- # Author : Trickster
- # Call Info : None
- #-------------------------------------------------------------------------
- def resistance
- resists = []
- MACL::Real_Elements.each do |element_id|
- resists << element_id if [1,2].include?(self.element_test(element_id))
- end
- return resists
- end
- end
- #==============================================================================
- # ** RPG::Troop
- #==============================================================================
- class RPG::Troop
- #-------------------------------------------------------------------------
- # * Name : Has Enemy?
- # Info : Does Troop have enemy id in members
- # Author : Trickster
- # Call Info : One Argument Integer Enemy id - Enemy Id to check
- #-------------------------------------------------------------------------
- def has_enemy?(enemy_id)
- # Run through each member and return true if included
- self.members.each {|member| return true if member.enemy_id == enemy_id}
- # Not In Troop
- return false
- end
- end
- #==============================================================================
- # ** RGSS.Font
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # This sections improves the font class to allow for more font styles, such as
- # shadow and outline and strikethrough.
- #
- # Method List:
- # ------------
- # Font.default_underline=
- # Font.default_underline
- # Font.default_underline_full=
- # Font.default_underline_full
- # Font.default_strikethrough=
- # Font.default_strikethrough
- # Font.default_strikethrough_full=
- # Font.default_strikethrough_full
- # Font.default_shadow=
- # Font.default_shadow
- # Font.default_shadow_color=
- # Font.default_shadow_color
- # Font.default_outline=
- # Font.default_outline
- # Font.default_outline_color=
- # Font.default_outline_color
- # Font.default_vert_grad=
- # Font.default_vert_grad
- # Font.default_horiz_grad=
- # Font.default_horiz_grad
- # Font.default_grad_s_color=
- # Font.default_grad_s_color
- # Font.default_grad_e_color=
- # Font.default_grad_e_color
- # underline=
- # underline
- # underline_full=
- # underline_full
- # strikethrough=
- # strikethrough
- # strikethrough_full=
- # strikethrough_full
- # shadow_color=
- # shadow_color
- # outline_color=
- # outline_color
- # shadow=
- # shadow
- # outline=
- # outline
- # vert_grad=
- # vert_grad
- # horiz_grad=
- # horiz_grad
- # grad_s_color=
- # grad_s_color
- # grad_e_color=
- # grad_e_color
- # ==(other)
- #
- # Modified Methods:
- # -----------------
- # initailzie
- #==============================================================================
- MACL::Loaded << 'RGSS.Font'
- #==============================================================================
- # ** Font
- #==============================================================================
- class Font
- #--------------------------------------------------------------------------
- # * Class Variables
- #--------------------------------------------------------------------------
- class_accessor :default_underline
- class_accessor :default_underline_full
- class_accessor :default_strikethrough
- class_accessor :default_strikethrough_full
- class_accessor :default_shadow
- class_accessor :default_shadow_color
- class_accessor :default_outline
- class_accessor :default_outline_color
- class_accessor :default_vert_grad
- class_accessor :default_horiz_grad
- class_accessor :default_grad_s_color
- class_accessor :default_grad_e_color
- #--------------------------------------------------------------------------
- # * Class Variable Declaration
- #--------------------------------------------------------------------------
- Font.default_underline = Default_Underline
- Font.default_underline_full = Default_Underline_Full
- Font.default_strikethrough = Default_Strikethrough
- Font.default_strikethrough_full = Default_Strikethrough_Full
- Font.default_shadow = Default_Shadow
- Font.default_shadow_color = Default_Shadow_Color
- Font.default_outline = Default_Outline
- Font.default_outline_color = Default_Outline_Color
- Font.default_vert_grad = Default_Vert_Grad
- Font.default_horiz_grad = Default_Horiz_Grad
- Font.default_grad_s_color = Default_Grad_S_Color
- Font.default_grad_e_color = Default_Grad_E_Color
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_accessor :underline
- attr_accessor :underline_full
- attr_accessor :strikethrough
- attr_accessor :strikethrough_full
- attr_accessor :shadow_color
- attr_accessor :outline_color
- attr_reader :shadow
- attr_reader :outline
- attr_reader :vert_grad
- attr_reader :horiz_grad
- attr_accessor :grad_s_color
- attr_accessor :grad_e_color
- #--------------------------------------------------------------------------
- # * Alias Listings
- #--------------------------------------------------------------------------
- alias_method :macl_rgssfont_init, :initialize
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(*args)
- # Set font settings
- @underline = Font.default_underline
- @underline_full = Font.default_underline_full
- @strikethrough = Font.default_strikethrough
- @strikethrough_full = Font.default_strikethrough_full
- @shadow_color = Font.default_shadow_color
- @outline_color = Font.default_outline_color
- @shadow = Font.default_shadow
- @outline = Font.default_outline
- @vert_grad = Font.default_vert_grad
- @horiz_grad = Font.default_horiz_grad
- @grad_s_color = Font.default_grad_s_color
- @grad_e_color = Font.default_grad_e_color
- # Original Initialization
- macl_rgssfont_init(*args)
- end
- #-------------------------------------------------------------------------
- # * Name : Set Shadow
- # Info : Sets Shadow Flag
- # Author : Yeyinde
- # Call Info : One Argument Boolean bool flag
- #-------------------------------------------------------------------------
- def shadow=(bool)
- @shadow = bool
- @outline = false unless bool == false
- end
- #-------------------------------------------------------------------------
- # * Name : Set Outline
- # Info : Sets Outline Flag
- # Author : Yeyinde
- # Call Info : One Argument Boolean bool flag
- #-------------------------------------------------------------------------
- def outline=(bool)
- @shadow = false unless bool == false
- @outline = bool
- end
- #-------------------------------------------------------------------------
- # * Name : Set Vert Gradient
- # Info : Sets Vert Gradient Flag
- # Author : SephirothSpawn
- # Call Info : One Argument Boolean bool flag
- #-------------------------------------------------------------------------
- def vert_grad=(bool)
- @vert_grad = bool
- @horiz_grad = false unless bool == false
- end
- #-------------------------------------------------------------------------
- # * Name : Set Horiz Gradient
- # Info : Sets Horiz Gradient Flag
- # Author : SephirothSpawn
- # Call Info : One Argument Boolean bool flag
- #-------------------------------------------------------------------------
- def horiz_grad=(bool)
- @vert_grad = false unless bool == false
- @horiz_grad = bool
- end
- #-------------------------------------------------------------------------
- # Name : == (Comparision Equals)
- # Info : Compares two Fonts
- # Author : Trickster
- # Call Info : One Argument Font other, Font to Check
- #-------------------------------------------------------------------------
- def ==(other)
- attr = %w( name size color bold italic underline underline_full strikethrough
- strikethrough_full shadow_color outline_color shadow outline vert_grad
- horiz_grad grad_s_color grad_e_color)
- attr.each do |var|
- return false if method(var).call != other.method(var).call
- end
- return true
- end
- end
- #==============================================================================
- # ** RGSS.Input
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # New methods to add to the RGSS Modules
- #
- # Method List:
- # ------------
- #
- # disable_key
- # enable_key
- #==============================================================================
- MACL::Loaded << 'RGSS.Input'
- #==============================================================================
- # ** Input
- #==============================================================================
- module Input
- #------------------------------------------------------------------------
- # * Disabled Keys
- #------------------------------------------------------------------------
- @disabled_keys = []
- @disabled_timer = {}
- class << self
- #------------------------------------------------------------------------
- # * Alias Listings
- #------------------------------------------------------------------------
- unless self.method_defined?(:seph_disabledkeys_input_update)
- alias_method :seph_disabledkeys_input_update, :update
- alias_method :seph_disabledkeys_input_press?, :press?
- alias_method :seph_disabledkeys_input_trigger?, :trigger?
- alias_method :seph_disabledkeys_input_repeat?, :repeat?
- alias_method :seph_disabledkeys_input_dir4, :dir4
- alias_method :seph_disabledkeys_input_dir8, :dir8
- end
- #------------------------------------------------------------------------
- # * Name : Disable Key
- # Info : Disables Input Constant from being read
- # Author : SephirothSpawn
- # Call Info : Constant defined in Input Module to be disabled
- # Frames to be disabled (nil for infinite frames)
- #------------------------------------------------------------------------
- def disable_key(constant, frames = nil)
- # Add Key to Disabled List
- @disabled_keys << constant unless @disabled_keys.include?(constant)
- # Set Disabled Counter if non-nil
- @disabled_timer[constant] = frames unless frames.nil?
- end
- #------------------------------------------------------------------------
- # * Name : Enable Key
- # Info : Enable Input Constant
- # Author : SephirothSpawn
- # Call Info : Constant defined in Input Module to be enabled
- #------------------------------------------------------------------------
- def enable_key(constant)
- # Remove Constant From List
- @disabled_keys.delete(constant)
- # Set Nil Timer
- @disabled_timer[constant] = nil
- end
- #------------------------------------------------------------------------
- # * Frame Update
- #------------------------------------------------------------------------
- def update
- # Pass Through Timer List
- @disabled_timer.each do |key, timer|
- # Next if nil timer or key not-disabled
- next if timer.nil? || !@disabled_keys.include?(key)
- # If Greater than 0 Timer
- if timer > 0
- timer -= 1
- next
- end
- # Enable Key
- @disabled_keys.delete(key) if @disabled_keys.include?(key)
- # Set Timer to Nil
- @disabled_timer[key] = nil
- end
- # Original Update
- seph_disabledkeys_input_update
- end
- #------------------------------------------------------------------------
- # * Press? Test
- #------------------------------------------------------------------------
- def press?(constant)
- return @disabled_keys.include?(constant) ?
- false : seph_disabledkeys_input_press?(constant)
- end
- #------------------------------------------------------------------------
- # * Trigger? Test
- #------------------------------------------------------------------------
- def trigger?(constant)
- return @disabled_keys.include?(constant) ?
- false : seph_disabledkeys_input_trigger?(constant)
- end
- #------------------------------------------------------------------------
- # * Repeat? Test
- #------------------------------------------------------------------------
- def repeat?(constant)
- return @disabled_keys.include?(constant) ?
- false : seph_disabledkeys_input_repeat?(constant)
- end
- #------------------------------------------------------------------------
- # * Dir4 Test
- #------------------------------------------------------------------------
- def dir4
- # Gets Original Direction Test
- dir = seph_disabledkeys_input_dir4
- # Return 0 if Direction Disabled
- if (dir == 2 && @disabled_keys.include?(DOWN)) ||
- (dir == 4 && @disabled_keys.include?(LEFT)) ||
- (dir == 6 && @disabled_keys.include?(RIGHT)) ||
- (dir == 8 && @disabled_keys.include?(UP))
- return 0
- end
- # Return Original Dir Test
- return dir
- end
- #------------------------------------------------------------------------
- # * Dir8 Test
- #------------------------------------------------------------------------
- def dir8
- # Gets Original Direction Test
- dir = seph_disabledkeys_input_dir8
- # Return 0 if Direction Disabled
- if (dir == 2 && @disabled_keys.include?(DOWN)) ||
- (dir == 4 && @disabled_keys.include?(LEFT)) ||
- (dir == 6 && @disabled_keys.include?(RIGHT)) ||
- (dir == 8 && @disabled_keys.include?(UP)) ||
- (dir == 1 && @disabled_keys.include?(DOWN) &&
- @disabled_keys.include?(LEFT)) ||
- (dir == 3 && @disabled_keys.include?(DOWN) &&
- @disabled_keys.include?(RIGHT)) ||
- (dir == 7 && @disabled_keys.include?(UP) &&
- @disabled_keys.include?(LEFT)) ||
- (dir == 9 && @disabled_keys.include?(UP) &&
- @disabled_keys.include?(RIGHT))
- return 0
- end
- # Return Original Dir Test
- return dir
- end
- end
- end
- #==============================================================================
- # ** RGSS.Interpreter
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Miscellaneous methods for RGSS classes.
- #
- # Method List:
- # ------------
- # event
- #==============================================================================
- MACL::Loaded << 'RGSS.Interpreter'
- #==============================================================================
- # ** Interpreter
- #==============================================================================
- class Interpreter
- #--------------------------------------------------------------------------
- # * Name : Event
- # Info : Returns Interpreter Event
- # Author : Near Fantastica
- # Call Info : Nothing
- #--------------------------------------------------------------------------
- def event
- return $game_map.events[@event_id]
- end
- end
- #==============================================================================
- # ** RGSS.Map
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # These set of methods add to the map classes, game, spriteset & scene.
- #
- # Method List:
- # ------------
- #
- # Game_Map
- # --------
- # characters
- # add_event
- # delete_event
- # add_character
- # delete_character
- # event?
- # event_at
- # character?
- # character_at
- # tile_terrain
- # terrain_ids
- #
- # Spriteset_Map
- # -------------
- # add_character
- # delete_character
- #
- # Scene_Map
- # ---------
- # spriteset
- #==============================================================================
- MACL::Loaded << 'RGSS.Map'
- #==============================================================================
- # ** Game_Map
- #==============================================================================
- class Game_Map
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_reader :characters
- #--------------------------------------------------------------------------
- # * Alias Listings
- #--------------------------------------------------------------------------
- alias_method :seph_macl_gmmap_setup, :setup
- alias_method :seph_macl_gmmap_refresh, :refresh
- alias_method :seph_macl_gmmap_passbl?, :passable?
- alias_method :seph_macl_gmmap_update, :update
- #--------------------------------------------------------------------------
- # * Setup
- #--------------------------------------------------------------------------
- def setup(map_id)
- # Set map characters data
- @characters = {}
- # Original Setup
- seph_macl_gmmap_setup(map_id)
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- # Original Refresh
- seph_macl_gmmap_refresh
- # If map ID is effective
- if @map_id > 0
- # Refresh all map characters
- for character in @characters.values
- character.refresh
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Determine if Passable
- #--------------------------------------------------------------------------
- def passable?(x, y, d, self_event = nil)
- # Return false if Previous Test False
- return false unless seph_macl_gmmap_passbl?(x, y, d, self_event)
- # Change direction (0,2,4,6,8,10) to obstacle bit (0,1,2,4,8,0)
- bit = (1 << (d / 2 - 1)) & 0x0f
- # Loop in all characters
- for character in @characters.values
- # If tiles other than self are consistent with coordinates
- if character.tile_id >= 0 and character != self_event and
- character.x == x and character.y == y and not character.through
- # If obstacle bit is set
- if @passages[character.tile_id] & bit != 0
- # impassable
- return false
- # If obstacle bit is set in all directions
- elsif @passages[character.tile_id] & 0x0f == 0x0f
- # impassable
- return false
- # If priorities other than that are 0
- elsif @priorities[character.tile_id] == 0
- # passable
- return true
- end
- end
- end
- # passable
- return true
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- # Original Update
- seph_macl_gmmap_update
- # Update map characters
- for character in @characters.values
- character.update
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Add Event
- # Info : Adds Game_Event to Game_Map#events list
- # Author : SephirothSpawn
- # Call Info : RPG::Event object
- #-------------------------------------------------------------------------
- def add_event(event)
- # Change Id if Already Taken
- event.id = @events.keys.max + 1 if @events.has_key?(event.id)
- # Creates New Event
- @events[event.id] = Game_Event.new(@map_id, event)
- # Adds To Spriteset
- if $scene.is_a?(Scene_Map) && $scene.spriteset.is_a?(Spriteset_Map)
- $scene.spriteset.add_character(@events[event.id])
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Delete Event
- # Info : Deletes Game_Event to Game_Map#events list
- # Author : SephirothSpawn
- # Call Info : Event ID
- #-------------------------------------------------------------------------
- def delete_event(event_id = 1)
- # Return if event not present
- return unless @events.has_key?(event_id)
- # Removes event from spriteset
- if $scene.is_a?(Scene_Map) && $scene.spriteset.is_a?(Spriteset_Map)
- $scene.spriteset.delete_character(@events[event_id])
- end
- # Deletes event from events list
- @events.delete(event_id)
- end
- #-------------------------------------------------------------------------
- # * Name : Add Character
- # Info : Adds Game_Character to Game_Map#characters list
- # Author : SephirothSpawn
- # Call Info : Game_Character, ID of Event (Auto-corrects if taken)
- #-------------------------------------------------------------------------
- def add_character(character, id = nil)
- # If ID Already taken or nil
- if id.nil? || @characters.has_key?(id)
- id = @characters.empty? ? 1 : @characters.keys.max + 1
- end
- # Creates New Event
- @characters[id] = character
- # Adds To Spriteset
- if $scene.is_a?(Scene_Map) && $scene.spriteset.is_a?(Spriteset_Map)
- $scene.spriteset.add_character(character)
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Delete Character
- # Info : Deletes Game_Character to Game_Map#characters list
- # Author : SephirothSpawn
- # Call Info : Character ID
- #-------------------------------------------------------------------------
- def delete_character(character_id = 1)
- # Return if character not present
- return unless @characters.has_key?(character_id)
- # Removes character from spriteset
- if $scene.is_a?(Scene_Map) && $scene.spriteset.is_a?(Spriteset_Map)
- $scene.spriteset.delete_character(@characters[character_id])
- end
- # Deletes character from characters list
- @characters.delete(character_id)
- end
- #-------------------------------------------------------------------------
- # * Name : Event?
- # Info : Is there an event on x and y
- # Author : Trickster
- # Call Info : Two Arguments Integer X, Y - Position to Check
- #-------------------------------------------------------------------------
- def event?(x, y)
- @events.each_value do |event|
- return true if event.x == x and event.y == y
- end
- return false
- end
- #-------------------------------------------------------------------------
- # * Name : Event at
- # Info : Returns event at location or nil
- # Author : SephirothSpawn
- # Call Info : Two Arguments Integer X, Y - Position to Check
- #-------------------------------------------------------------------------
- def event_at(x, y)
- for event in @events.values
- return event if event.x == x && event.y == y
- end
- return nil
- end
- #-------------------------------------------------------------------------
- # * Name : Character?
- # Info : Is there an character on x and y
- # Author : SephirothSpawn
- # Call Info : Two Arguments Integer X, Y - Position to Check
- #-------------------------------------------------------------------------
- def character?(x, y)
- @characters.each_value do |character|
- return true if character.x == x and character.y == y
- end
- return false
- end
- #-------------------------------------------------------------------------
- # * Name : Character at
- # Info : Returns character at location or nil
- # Author : SephirothSpawn
- # Call Info : Two Arguments Integer X, Y - Position to Check
- #-------------------------------------------------------------------------
- def character_at(x, y)
- @characters.each_value do |character|
- return character if character.x == x and character.y == y
- end
- return nil
- end
- #-------------------------------------------------------------------------
- # * Name : Tile Terrain
- # Info : Returns tile specific terrain from given x, y and layer
- # Author : Hanmac
- # Call Info : x, y, z (Integer) Position
- #-------------------------------------------------------------------------
- def tile_terrain(x, y, z)
- tile_id = data[x, y, z]
- return tile_id.nil? ? 0 : @terrain_tags[tile_id]
- end
- #-------------------------------------------------------------------------
- # * Name : Terrain IDs
- # Info : Returns a list of terrain ids at a x y locations
- # Author : Hanmac
- # Call Info : x, y (Integer) Position
- #-------------------------------------------------------------------------
- def terrain_ids(x, y)
- return [0, 1, 2].collect {|i| tile_terrain(x, y, i)}
- end
- end
- #==============================================================================
- # ** Spriteset_Map
- #==============================================================================
- class Spriteset_Map
- #--------------------------------------------------------------------------
- # * Add Character
- #--------------------------------------------------------------------------
- def add_character(game_character)
- # Returns if Character already has sprite
- for sprite in @character_sprites
- return if sprite.character == game_character
- end
- # Adds New Sprite
- @character_sprites << Sprite_Character.new(@viewport1, game_character)
- end
- #--------------------------------------------------------------------------
- # * Delete Character
- #--------------------------------------------------------------------------
- def delete_character(game_character)
- # Pass Through Sprites
- for sprite in @character_sprites
- # If Character Matches
- if sprite.character == game_character
- # Dispose Sprite
- sprite.dispose
- # Delete from List
- @character_sprites.delete(sprite)
- break
- end
- end
- end
- end
- #==============================================================================
- # ** Scene_Map
- #==============================================================================
- class Scene_Map
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_reader :spriteset
- end
- #==============================================================================
- # ** RGSS.RPG::AudioFile
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # New methods to add to the RPG::AudioFile class
- #
- # Method List:
- # ------------
- # is_a_bgm?
- # is_a_bgm=
- # is_a_bgm
- # is_a_bgs?
- # is_a_bgs=
- # is_a_bgs
- # is_a_me?
- # is_a_me=
- # is_a_me
- # is_a_se?
- # is_a_se=
- # is_a_se
- # play
- # stop
- #==============================================================================
- MACL::Loaded << 'RGSS.RPG::AudioFile'
- #==============================================================================
- # ** RPG::AudioFile
- #==============================================================================
- class RPG::AudioFile
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_accessor :is_a_bgm
- attr_accessor :is_a_bgs
- attr_accessor :is_a_me
- attr_accessor :is_a_se
- #-------------------------------------------------------------------------
- # * Name : Is a BGM?
- # Info : Test if AudioFile is BGM (In theory)
- # Author : SephirothSpawn
- #-------------------------------------------------------------------------
- def is_a_bgm?
- return @is_a_bgm.nil? ? @name.include?('BGM/') : @is_a_bgm
- end
- #-------------------------------------------------------------------------
- # * Name : Is a BGS?
- # Info : Test if AudioFile is BGS (In theory)
- # Author : SephirothSpawn
- #-------------------------------------------------------------------------
- def is_a_bgs?
- return @is_a_bgs.nil? ? @name.include?('BGS/') : @is_a_bgs
- end
- #-------------------------------------------------------------------------
- # * Name : Is a ME?
- # Info : Test if AudioFile is ME (In theory)
- # Author : SephirothSpawn
- #-------------------------------------------------------------------------
- def is_a_me?
- return @is_a_me.nil? ? @name.include?('ME/') : @is_a_me
- end
- #-------------------------------------------------------------------------
- # * Name : Is a SE?
- # Info : Test if AudioFile is SE (In theory)
- # Author : SephirothSpawn
- #-------------------------------------------------------------------------
- def is_a_se?
- return @is_a_se.nil? ? @name.include?('SE/') : @is_a_se
- end
- #-------------------------------------------------------------------------
- # * Name : Play
- # Info : Autoplays AudioFile
- # Author : SephirothSpawn
- #-------------------------------------------------------------------------
- def play
- if is_a_bgm?
- Audio.bgm_play(@name, @volume, @pitch)
- elsif is_a_bgs?
- Audio.bgs_play(@name, @volume, @pitch)
- elsif is_a_me?
- Audio.me_play(@name, @volume, @pitch)
- elsif is_a_se?
- Audio.se_play(@name, @volume, @pitch)
- end
- end
- #-------------------------------------------------------------------------
- # * Name : Stop
- # Info : Stops AudioFile
- # Author : SephirothSpawn
- #-------------------------------------------------------------------------
- def stop
- if is_a_bgm?
- Audio.bgm_stop
- elsif is_a_bgs?
- Audio.bgs_stop
- elsif is_a_me?
- Audio.me_stop
- elsif is_a_se?
- Audio.se_stop
- end
- end
- end
- #==============================================================================
- # ** RGSS.RPG::Cache
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # These set of methods add to the RPG::Cache.
- #
- # Method List:
- # ------------
- # autotile_tile
- # gradient
- #==============================================================================
- MACL::Loaded << 'RGSS.RPG::Cache'
- #==============================================================================
- # ** RPG::Cache
- #==============================================================================
- module RPG::Cache
- #--------------------------------------------------------------------------
- # * Auto-Tiles
- #--------------------------------------------------------------------------
- Autotiles = [
- [[27, 28, 33, 34], [ 5, 28, 33, 34], [27, 6, 33, 34], [ 5, 6, 33, 34],
- [27, 28, 33, 12], [ 5, 28, 33, 12], [27, 6, 33, 12], [ 5, 6, 33, 12]],
- [[27, 28, 11, 34], [ 5, 28, 11, 34], [27, 6, 11, 34], [ 5, 6, 11, 34],
- [27, 28, 11, 12], [ 5, 28, 11, 12], [27, 6, 11, 12], [ 5, 6, 11, 12]],
- [[25, 26, 31, 32], [25, 6, 31, 32], [25, 26, 31, 12], [25, 6, 31, 12],
- [15, 16, 21, 22], [15, 16, 21, 12], [15, 16, 11, 22], [15, 16, 11, 12]],
- [[29, 30, 35, 36], [29, 30, 11, 36], [ 5, 30, 35, 36], [ 5, 30, 11, 36],
- [39, 40, 45, 46], [ 5, 40, 45, 46], [39, 6, 45, 46], [ 5, 6, 45, 46]],
- [[25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20], [13, 14, 19, 12],
- [17, 18, 23, 24], [17, 18, 11, 24], [41, 42, 47, 48], [ 5, 42, 47, 48]],
- [[37, 38, 43, 44], [37, 6, 43, 44], [13, 18, 19, 24], [13, 14, 43, 44],
- [37, 42, 43, 48], [17, 18, 47, 48], [13, 18, 43, 48], [ 1, 2, 7, 8]]
- ]
- #--------------------------------------------------------------------------
- # * Autotile Cache
- #
- # @autotile_cache = {
- # filename => { [autotile_id, frame_id, hue] => bitmap, ... },
- # ...
- # }
- #--------------------------------------------------------------------------
- @autotile_cache = {}
- #--------------------------------------------------------------------------
- # * Autotile Tile
- #--------------------------------------------------------------------------
- def self.autotile_tile(filename, tile_id, hue = 0, frame_id = nil)
- # Gets Autotile Bitmap
- autotile = self.autotile(filename)
- # Configures Frame ID if not specified
- if frame_id.nil?
- # Animated Tiles
- frames = autotile.width / 96
- # Configures Animation Offset
- fc = Graphics.frame_count / Animated_Autotiles_Frames
- frame_id = (fc) % frames * 96
- end
- # Creates list if already not created
- @autotile_cache[filename] = {} unless @autotile_cache.has_key?(filename)
- # Gets Key
- key = [tile_id, frame_id, hue]
- # If Key Not Found
- unless @autotile_cache[filename].has_key?(key)
- # Reconfigure Tile ID
- tile_id %= 48
- # Creates Bitmap
- bitmap = Bitmap.new(32, 32)
- # Collects Auto-Tile Tile Layout
- tiles = Autotiles[tile_id / 8][tile_id % 8]
- # Draws Auto-Tile Rects
- for i in 0...4
- tile_position = tiles[i] - 1
- src_rect = Rect.new(tile_position % 6 * 16 + frame_id,
- tile_position / 6 * 16, 16, 16)
- bitmap.blt(i % 2 * 16, i / 2 * 16, autotile, src_rect)
- end
- # Saves Autotile to Cache
- @autotile_cache[filename][key] = bitmap
- # Change Hue
- @autotile_cache[filename][key].hue_change(hue)
- end
- # Return Autotile
- return @autotile_cache[filename][key]
- end
- #-------------------------------------------------------------------------
- # * Name : Gradient
- # Info : Loads A Gradient Bar
- # Author : Trickster
- # Call Info : One to Two Arguments
- # String filename of Bar to load
- # Integer hue - hue displacement
- # Comment : Files are to be located in Graphics/Gradients
- #-------------------------------------------------------------------------
- def self.gradient(filename, hue = 0)
- self.load_bitmap("Graphics/Gradients/", filename, hue)
- end
- end
- #==============================================================================
- # ** RGSS.RPG::State
- #------------------------------------------------------------------------------
- # Description:
- # ------------
- # Miscellaneous New stuff for the RPG::State class.
- #
- # Method List:
- # ------------
- # RPG::State.normal_icon_name
- # RPG::State.normal_icon
- # icon_name
- # icon
- #==============================================================================
- MACL::Loaded << 'RGSS.RPG::State'
- #==============================================================================
- # ** RPG::State
- #==============================================================================
- class RPG::State
- #--------------------------------------------------------------------------
- # * Normal Icon Name
- #--------------------------------------------------------------------------
- def self.normal_icon_name
- return Normal_Icon
- end
- #--------------------------------------------------------------------------
- # * Normal Icon
- #--------------------------------------------------------------------------
- def self.normal_icon
- begin
- return RPG::Cache.icon(Normal_Icon)
- rescue
- return nil
- end
- end
- #--------------------------------------------------------------------------
- # * Icon Name
- #--------------------------------------------------------------------------
- def icon_name
- return Icon_Name[@id].nil? ? self.name : Icon_Name[@id]
- end
- #--------------------------------------------------------------------------
- # * Icon
- #--------------------------------------------------------------------------
- def icon
- begin
- return RPG::Cache.icon(icon_name)
- rescue
- return nil
- end
- end
- end
Add Comment
Please, Sign In to add comment