Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # ** Quasi v0.2
- #==============================================================================
- # Adds new methods to VXA's default classes and modules.
- # These methods will be used in other scripts create by Quasi, so instead of
- # making them over and over, they will be placed here.
- #==============================================================================
- # Change Log
- #------------------------------------------------------------------------------
- # v0.2 - Changed followers to be made when there are party members instead of
- # already being made.
- # - Fix to angle, had a typo.
- # --
- # v0.1 - Pre-Released for movement script
- #==============================================================================
- # * New method list
- #------------------------------------------------------------------------------
- # class Game_Event
- # def grab_comment(regex, default)
- # * This def grabs comments from the event, if no default is set
- # it will return true or false if the regex was found.
- #
- # class Game_Party
- # def add_actor & def remove_actor
- # * Recreates followers
- #
- # def lowest_level
- # * Returns the lowest lvl in party
- #
- # def who_level(value)
- # * Returns the actor/s whose level is equal to the set value
- # - If multiple actors, it returns an array
- #
- # def avg_level
- # *Grabs the average level of party
- #
- # def lowest_param(param)
- # *Returns lowest param value from party
- #
- # def highest_param(param)
- # * Returns highest param value from party
- #
- # def avg_param(param)
- # *Grabs the average value of param of party
- #
- # def who_param(value,param)
- # * Returns the actor/s whose param is equal to the set value
- # - If multiple actors, it returns an array
- #
- # class Game_Map
- # def clone_event(x,y,mapid,eventid)
- # * Copies event from the mapid to the current map at x,y
- #
- # class Game_Follower & Game_Followers
- # def initialize
- # * Doesn't make all the followers at start anymore.
- #
- # def recreate
- # * Used to create followers when they are added to party.
- #
- # class Scene_Base
- # def wait(duration)
- # * Waits duration time before continuing
- #
- # class Sprite_Base
- # alias start_animation
- # alias animation_set_sprites
- # * New feature that allows animations to appear different sizes each time.
- # To use: In animation name include a range in < numbers > ex:
- # 002:Hit Fire <-50..50>
- # Animation will play at a random size between -50% to 50%
- #
- # module Kernel
- # def qrand(max)
- # * Created my own rand. A range can be used ex: qrand(-20..20)
- # It stores previous 3 randoms and if the current random is equal
- # to any of those 3 it will run again.
- #
- # module Math
- # def self.angle(point1, point2)
- # * Returns the angle of line made by point1 and point2
- #
- # def self.circle(cx,cy,radius,angle)
- # * Gets the x,y position on a circle from the given values
- # cx and cy are center x/y
- # radius is the radius of the circle
- # angle is the angle you want the new points at.
- #
- # class String
- # def to_range
- # * Converts string to a range. Needs to be written as a range
- # "0..10" or "0...10"
- #
- # RPG::Animation
- # def zoom_range
- # * Used to grab the random animation zoom range from the name. If regex
- # is not found it defaults to 0 which means no change in size.
- #
- # RPG::SE | RPG::BGM | RPG::ME | RPG::BGS
- # def play
- # * Added a master volume control. Value set on line 94
- #==============================================================================
- module Quasi
- #--------------------------------------------------------------------------
- # * Master volume control. VXA default sounds are too loud on my pc
- # so I have it set at -70 when testing scripts.
- #--------------------------------------------------------------------------
- VOLUME = -70
- end
- $imported = {} if $imported.nil?
- $imported["Quasi"] = 0.2
- #==============================================================================
- # ** Game_Event
- #------------------------------------------------------------------------------
- # This class handles events. Functions include event page switching via
- # condition determinants and running parallel process events. Used within the
- # Game_Map class.
- #==============================================================================
- class Game_Event < Game_Character
- #--------------------------------------------------------------------------
- # * Grabs comment from event
- #--------------------------------------------------------------------------
- def grab_comment(regex,default=nil)
- return unless @list
- reg = []
- @list.each do |cmd|
- next if cmd.code != 108
- comment = cmd.parameters[0]
- next unless comment =~ regex
- if !default.nil?
- reg << $1
- else
- reg = [true]
- end
- end
- return default if reg.empty?
- return reg if reg.length > 1
- return reg[0]
- end
- end
- #==============================================================================
- # ** Game_Party
- #------------------------------------------------------------------------------
- # This class handles parties. Information such as gold and items is included.
- # Instances of this class are referenced by $game_party.
- #==============================================================================
- class Game_Party < Game_Unit
- #--------------------------------------------------------------------------
- # * Add an Actor
- #--------------------------------------------------------------------------
- def add_actor(actor_id)
- if !@actors.include?(actor_id)
- @actors.push(actor_id)
- $game_player.followers.recreate
- SceneManager.scene.spriteset_refresh if SceneManager.scene_is?(Scene_Map)
- end
- $game_player.refresh
- $game_map.need_refresh = true
- end
- #--------------------------------------------------------------------------
- # * Remove Actor
- #--------------------------------------------------------------------------
- def remove_actor(actor_id)
- @actors.delete(actor_id)
- $game_player.followers.recreate
- SceneManager.scene.spriteset_refresh if SceneManager.scene_is?(Scene_Map)
- $game_player.refresh
- $game_map.need_refresh = true
- end
- #--------------------------------------------------------------------------
- # * Get Lowest Level of Party Members
- #--------------------------------------------------------------------------
- def lowest_level
- lvl = members.collect {|actor| actor.level }.min
- return lvl
- end
- #--------------------------------------------------------------------------
- # * Get Who the Level belongs too
- # ** If multiple have the same level, it returns an array with both
- #--------------------------------------------------------------------------
- def who_level(value)
- who = []
- members.each do |mem|
- next unless mem.level == value
- who.push(mem.name)
- end
- return if who.empty?
- return who[0] if who.size == 1
- return who
- end
- #--------------------------------------------------------------------------
- # * Get Average Level of Party Members
- #--------------------------------------------------------------------------
- def avg_level
- avg = 0
- members.each {|actor| avg += actor.level}
- avg /= members.size
- return avg
- end
- #--------------------------------------------------------------------------
- # * Get Lowest Value of param of Party Members
- #--------------------------------------------------------------------------
- def lowest_param(x)
- param = members.collect {|actor| actor.param(x) }.min
- return param
- end
- #--------------------------------------------------------------------------
- # * Get Highest Value of param of Party Members
- #--------------------------------------------------------------------------
- def highest_param(x)
- param = members.collect {|actor| actor.param(x) }.max
- return param
- end
- #--------------------------------------------------------------------------
- # * Get Average Value of param of Party Members
- #--------------------------------------------------------------------------
- def avg_param(x)
- avg = 0
- members.each {|actor| avg += actor.param(x)}
- avg /= members.size
- return avg
- end
- #--------------------------------------------------------------------------
- # * Get Who the param belongs too
- #--------------------------------------------------------------------------
- def who_param(value, x)
- who = []
- members.each do |mem|
- next unless mem.param(x) == value
- who.push(mem.name)
- end
- return if who.empty?
- return who[0] if who.size == 1
- return who
- end
- end
- #==============================================================================
- # ** Game_Map
- #------------------------------------------------------------------------------
- # This class handles maps. It includes scrolling and passage determination
- # functions. The instance of this class is referenced by $game_map.
- #==============================================================================
- class Game_Map
- #--------------------------------------------------------------------------
- # * Clone event from any map to x,y pos
- #--------------------------------------------------------------------------
- def clone_event(x,y,mapid,eventid)
- cmap = load_data(sprintf("Data/Map%03d.rvdata2", mapid))
- return if cmap.events[eventid].nil?
- cmap.events[eventid].x = x
- cmap.events[eventid].y = y
- @events[@events.length+1] = Game_Event.new(mapid, cmap.events[eventid])
- SceneManager.scene.spriteset_refresh
- refresh
- end
- end
- #==============================================================================
- # ** Game_Follower
- #------------------------------------------------------------------------------
- # This class handles followers. A follower is an allied character, other than
- # the front character, displayed in the party. It is referenced within the
- # Game_Followers class.
- #==============================================================================
- class Game_Follower < Game_Character
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(member_index, preceding_character)
- super()
- @member_index = member_index
- @preceding_character = !preceding_character ? $game_player : preceding_character
- @transparent = $data_system.opt_transparent
- @through = true
- end
- end
- #==============================================================================
- # ** Game_Followers
- #------------------------------------------------------------------------------
- # This is a wrapper for a follower array. This class is used internally for
- # the Game_Player class.
- #==============================================================================
- class Game_Followers
- #--------------------------------------------------------------------------
- # * Object Initialization
- # leader: Lead character
- #--------------------------------------------------------------------------
- def initialize(leader)
- @visible = $data_system.opt_followers
- @gathering = false # Gathering processing underway flag
- @data = []
- $data_system.party_members.each_index do |index|
- next if index == 0
- prec = index == 1 ? leader : @data[-1]
- @data.push(Game_Follower.new(index, prec))
- end
- end
- #--------------------------------------------------------------------------
- # * Recreate
- #--------------------------------------------------------------------------
- def recreate
- @data = []
- $game_party.battle_members.each_index do |index|
- next if index == 0
- prec = index == 1 ? $game_player : @data[-1]
- @data.push(Game_Follower.new(index, prec))
- end
- synchronize($game_player.x, $game_player.y, $game_player.direction)
- end
- end
- #==============================================================================
- # ** Sprite_Base
- #------------------------------------------------------------------------------
- # A sprite class with animation display processing added.
- #==============================================================================
- class Sprite_Base < Sprite
- alias quasi_start_animation start_animation
- alias quasi_animation_set animation_set_sprites
- #--------------------------------------------------------------------------
- # * Start Animation
- #--------------------------------------------------------------------------
- def start_animation(animation, mirror = false)
- quasi_start_animation(animation, mirror)
- if @animation
- @rand = qrand(@animation.zoom_range)
- end
- end
- #--------------------------------------------------------------------------
- # * Set Animation Sprite
- # frame : Frame data (RPG::Animation::Frame)
- #--------------------------------------------------------------------------
- def animation_set_sprites(frame)
- quasi_animation_set(frame)
- return if @rand == 0
- cell_data = frame.cell_data
- @ani_sprites.each_with_index do |sprite, i|
- next unless sprite
- pattern = cell_data[i, 0]
- next if !pattern || pattern < 0
- sprite.zoom_x += @rand/100.0
- sprite.zoom_y += @rand/100.0
- end
- end
- end
- #==============================================================================
- # ** Scene_Base
- #------------------------------------------------------------------------------
- # This is a super class of all scenes within the game.
- #==============================================================================
- class Scene_Base
- #--------------------------------------------------------------------------
- # * Wait
- #--------------------------------------------------------------------------
- def wait(duration)
- duration.times {|i| update_basic if i < duration }
- end
- end
- #==============================================================================
- # ** Scene_Map
- #------------------------------------------------------------------------------
- # This class performs the map screen processing.
- #==============================================================================
- class Scene_Map < Scene_Base
- #--------------------------------------------------------------------------
- # * Refresh spriteset
- #--------------------------------------------------------------------------
- def spriteset_refresh
- @spriteset.refresh_characters
- end
- end
- #==============================================================================
- # ** Kernel
- #==============================================================================
- module Kernel
- def qrand(max)
- max = 1 if max == 0
- @prand = [] if @prand.nil?
- v = Random.new.rand(max)
- v = Random.new.rand(max) if @prand.include?(v)
- @prand << v
- @prand.shift if @prand.length > 3
- return v
- end
- end
- #==============================================================================
- # ** Math
- #==============================================================================
- module Math
- #--------------------------------------------------------------------------
- # * Calculate angle between 2 points
- #--------------------------------------------------------------------------
- def self.angle(point1,point2)
- x = point2[0] - point1[0]
- y = point2[1] - point1[1]
- radian = atan2(y,x)
- angle = (radian/PI) * 180
- return angle
- end
- #--------------------------------------------------------------------------
- # * Calculate pos on a circle
- #--------------------------------------------------------------------------
- def self.circle(cx, cy, radius, angle)
- x = cx + Math.sin(angle)*radius
- y = cy + Math.cos(angle)*radius
- return [x, y]
- end
- end
- #==============================================================================
- # ** String
- #==============================================================================
- class String
- def to_range
- return unless self.include? ".."
- literal = (self.include?"...") ? literal = "..." : literal = ".."
- range = self.split(literal).map {|x| x.to_i}
- return range[0]..range[1] if literal == ".."
- return range[0]...range[1]
- end
- end
- #==============================================================================
- # ** RPG::Animation
- #==============================================================================
- class RPG::Animation
- def zoom_range
- if @zoom_range.nil?
- @zoom_range = @name =~ /<(.*)>/i ? $1.to_range : 0
- end
- return @zoom_range
- end
- end
- #==============================================================================
- # ** RPG::SE | RPG::BGM | RPG::ME | RPG::BGS
- #==============================================================================
- class RPG::SE < RPG::AudioFile
- def play
- unless @name.empty?
- volume = @volume + Quasi::VOLUME
- volume = 0 if volume < 0
- Audio.se_play('Audio/SE/' + @name, volume, @pitch)
- end
- end
- end
- class RPG::BGM < RPG::AudioFile
- def play(pos = 0)
- if @name.empty?
- Audio.bgm_stop
- @@last = RPG::BGM.new
- else
- volume = @volume + Quasi::VOLUME
- volume = 0 if volume < 0
- Audio.bgm_play('Audio/BGM/' + @name, volume, @pitch, pos)
- @@last = self.clone
- end
- end
- end
- class RPG::ME < RPG::AudioFile
- def play
- if @name.empty?
- Audio.me_stop
- else
- volume = @volume + Quasi::VOLUME
- volume = 0 if volume < 0
- Audio.me_play('Audio/ME/' + @name, volume, @pitch)
- end
- end
- end
- class RPG::BGS < RPG::AudioFile
- def play(pos = 0)
- if @name.empty?
- Audio.bgs_stop
- @@last = RPG::BGS.new
- else
- volume = @volume + Quasi::VOLUME
- volume = 0 if volume < 0
- Audio.bgs_play('Audio/BGS/' + @name, volume, @pitch, pos)
- @@last = self.clone
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement