Advertisement
Guest User

Quasi VXA

a guest
Sep 24th, 2014
3
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.86 KB | None | 0 0
  1. #==============================================================================
  2. # ** Quasi v0.1
  3. #==============================================================================
  4. #  Adds new methods to VXA's default classes and modules.
  5. # These methods will be used in other scripts create by Quasi, so instead of
  6. # making them over and over, they will be placed here.
  7. #==============================================================================
  8. # * New method list
  9. #------------------------------------------------------------------------------
  10. #  class Game_Event
  11. #    def grab_comment(regex, default)
  12. #      * This def grabs comments from the event, if no default is set
  13. #      it will return true or false if the regex was found.
  14. #
  15. #  class Game_Party
  16. #    def lowest_level
  17. #      * Returns the lowest lvl in party
  18. #
  19. #    def who_level(value)
  20. #      * Returns the actor/s whose level is equal to the set value
  21. #      - If multiple actors, it returns an array
  22. #
  23. #    def avg_level
  24. #      *Grabs the average level of party
  25. #
  26. #    def lowest_param(param)
  27. #      *Returns lowest param value from party
  28. #
  29. #    def highest_param(param)
  30. #      * Returns highest param value from party
  31. #
  32. #    def avg_param(param)
  33. #      *Grabs the average value of param of party
  34. #
  35. #    def who_param(value,param)
  36. #      * Returns the actor/s whose param is equal to the set value
  37. #      - If multiple actors, it returns an array
  38. #
  39. #  class Game_Map
  40. #    def clone_event(x,y,mapid,eventid)
  41. #      * Copies event from the mapid to the current map at x,y
  42. #
  43. #  class Scene_Base
  44. #    def wait(duration)
  45. #      * Waits duration time before continuing
  46. #
  47. #  class Sprite_Base
  48. #    alias start_animation
  49. #    alias animation_set_sprites
  50. #      * New feature that allows animations to appear different sizes each time.
  51. #        To use:  In animation name include a range in < numbers > ex:
  52. #                   002:Hit Fire <-50..50>
  53. #                 Animation will play at a random size between -50% to 50%
  54. #
  55. #  module Kernel
  56. #    def qrand(max)
  57. #      * Created my own rand.  A range can be used ex: qrand(-20..20)  
  58. #        It stores previous 3 randoms and if the current random is equal
  59. #        to any of those 3 it will run again.
  60. #
  61. #  module Math
  62. #    def self.angle(point1, point2)
  63. #      * Returns the angle of line made by point1 and point2
  64. #
  65. #    def self.circle(cx,cy,radius,angle)
  66. #      * Gets the x,y position on a circle from the given values
  67. #        cx and cy are center x/y
  68. #        radius is the radius of the circle
  69. #        angle is the angle you want the new points at.
  70. #
  71. #  class String
  72. #    def to_range
  73. #      * Converts string to a range.  Needs to be written as a range
  74. #        "0..10" or "0...10"
  75. #
  76. #  RPG::Animation
  77. #    def zoom_range
  78. #      * Used to grab the random animation zoom range from the name.  If regex
  79. #        is not found it defaults to 0 which means no change in size.
  80. #
  81. #  RPG::SE | RPG::BGM | RPG::ME | RPG::BGS
  82. #    def play
  83. #      * Added a master volume control.  Value set on line 94
  84. #==============================================================================
  85. # Change Log
  86. #------------------------------------------------------------------------------
  87. # v0.1 - Pre-Released for movement script
  88. #==============================================================================
  89. module Quasi
  90.   #--------------------------------------------------------------------------
  91.   # * Master volume control.  VXA default sounds are too loud on my pc
  92.   #   so I have it set at -70 when testing scripts.
  93.   #--------------------------------------------------------------------------
  94.   VOLUME = 0
  95. end
  96. $imported = {} if $imported.nil?
  97. $imported["Quasi"] = 0.1
  98. #==============================================================================
  99. # ** Game_Event
  100. #------------------------------------------------------------------------------
  101. #  This class handles events. Functions include event page switching via
  102. # condition determinants and running parallel process events. Used within the
  103. # Game_Map class.
  104. #==============================================================================
  105.  
  106. class Game_Event < Game_Character
  107.   #--------------------------------------------------------------------------
  108.   # * Grabs comment from event
  109.   #--------------------------------------------------------------------------
  110.   def grab_comment(regex,default=false)
  111.     return unless @list
  112.     reg = nil
  113.     @list.each do |cmd|
  114.       next if cmd.code != 108
  115.       comment = cmd.parameters[0]
  116.       next unless comment =~ regex
  117.       if !default.nil?
  118.         reg = $1
  119.       else
  120.         reg = true
  121.       end
  122.     end
  123.     return default if reg.nil?
  124.     return reg
  125.   end
  126. end
  127.  
  128. #==============================================================================
  129. # ** Game_Party
  130. #------------------------------------------------------------------------------
  131. #  This class handles parties. Information such as gold and items is included.
  132. # Instances of this class are referenced by $game_party.
  133. #==============================================================================
  134.  
  135. class Game_Party < Game_Unit
  136.   #--------------------------------------------------------------------------
  137.   # * Get Lowest Level of Party Members
  138.   #--------------------------------------------------------------------------
  139.   def lowest_level
  140.     lvl = members.collect {|actor| actor.level }.min
  141.     return lvl
  142.   end
  143.   #--------------------------------------------------------------------------
  144.   # * Get Who the Level belongs too
  145.   # ** If multiple have the same level, it returns an array with both
  146.   #--------------------------------------------------------------------------
  147.   def who_level(value)
  148.     who = []
  149.     members.each do |mem|
  150.       next unless mem.level == value
  151.       who.push(mem.name)
  152.     end
  153.     return if who.empty?
  154.     return who[0] if who.size == 1
  155.     return who
  156.   end
  157.   #--------------------------------------------------------------------------
  158.   # * Get Average Level of Party Members
  159.   #--------------------------------------------------------------------------
  160.   def avg_level
  161.     avg = 0
  162.     members.each {|actor| avg += actor.level}
  163.     avg /= members.size
  164.     return avg
  165.   end
  166.   #--------------------------------------------------------------------------
  167.   # * Get Lowest Value of param of Party Members
  168.   #--------------------------------------------------------------------------
  169.   def lowest_param(x)
  170.     param = members.collect {|actor| actor.param(x) }.min
  171.     return param
  172.   end
  173.   #--------------------------------------------------------------------------
  174.   # * Get Highest Value of param of Party Members
  175.   #--------------------------------------------------------------------------
  176.   def highest_param(x)
  177.     param = members.collect {|actor| actor.param(x) }.max
  178.     return param
  179.   end
  180.   #--------------------------------------------------------------------------
  181.   # * Get Average Value of param of Party Members
  182.   #--------------------------------------------------------------------------
  183.   def avg_param(x)
  184.     avg = 0
  185.     members.each {|actor| avg += actor.param(x)}
  186.     avg /= members.size
  187.     return avg
  188.   end
  189.   #--------------------------------------------------------------------------
  190.   # * Get Who the param belongs too
  191.   #--------------------------------------------------------------------------
  192.   def who_param(value, x)
  193.     who = []
  194.     members.each do |mem|
  195.       next unless mem.param(x) == value
  196.       who.push(mem.name)
  197.     end
  198.     return if who.empty?
  199.     return who[0] if who.size == 1
  200.     return who
  201.   end
  202. end
  203.  
  204. #==============================================================================
  205. # ** Game_Map
  206. #------------------------------------------------------------------------------
  207. #  This class handles maps. It includes scrolling and passage determination
  208. # functions. The instance of this class is referenced by $game_map.
  209. #==============================================================================
  210.  
  211. class Game_Map
  212.   #--------------------------------------------------------------------------
  213.   # * Clone event from any map to x,y pos
  214.   #--------------------------------------------------------------------------
  215.   def clone_event(x,y,mapid,eventid)
  216.     cmap = load_data(sprintf("Data/Map%03d.rvdata2", mapid))
  217.     return if cmap.events[eventid].nil?
  218.     cmap.events[eventid].x = x
  219.     cmap.events[eventid].y = y
  220.     @events[@events.length+1] = Game_Event.new(mapid, cmap.events[eventid])
  221.     SceneManager.scene.spriteset_refresh
  222.     refresh
  223.   end
  224. end
  225.  
  226. #==============================================================================
  227. # ** Sprite_Base
  228. #------------------------------------------------------------------------------
  229. #  A sprite class with animation display processing added.
  230. #==============================================================================
  231.  
  232. class Sprite_Base < Sprite
  233.   alias quasi_start_animation start_animation
  234.   alias quasi_animation_set animation_set_sprites
  235.   #--------------------------------------------------------------------------
  236.   # * Start Animation
  237.   #--------------------------------------------------------------------------
  238.   def start_animation(animation, mirror = false)
  239.     quasi_start_animation(animation, mirror)
  240.     if @animation
  241.       @rand = qrand(@animation.zoom_range)
  242.     end
  243.   end
  244.   #--------------------------------------------------------------------------
  245.   # * Set Animation Sprite
  246.   #     frame : Frame data (RPG::Animation::Frame)
  247.   #--------------------------------------------------------------------------
  248.   def animation_set_sprites(frame)
  249.     quasi_animation_set(frame)
  250.     return if @rand == 0
  251.     cell_data = frame.cell_data
  252.     @ani_sprites.each_with_index do |sprite, i|
  253.       next unless sprite
  254.       pattern = cell_data[i, 0]
  255.       next if !pattern || pattern < 0
  256.       sprite.zoom_x += @rand/100.0
  257.       sprite.zoom_y += @rand/100.0
  258.     end
  259.   end
  260. end
  261.  
  262. #==============================================================================
  263. # ** Scene_Base
  264. #------------------------------------------------------------------------------
  265. #  This is a super class of all scenes within the game.
  266. #==============================================================================
  267.  
  268. class Scene_Base
  269.   #--------------------------------------------------------------------------
  270.   # * Wait
  271.   #--------------------------------------------------------------------------
  272.   def wait(duration)
  273.     duration.times {|i| update_basic if i < duration }
  274.   end
  275. end
  276.  
  277. #==============================================================================
  278. # ** Kernel
  279. #==============================================================================
  280.  
  281. module Kernel
  282.   def qrand(max)
  283.     max = 1 if max == 0
  284.     @prand = [] if @prand.nil?
  285.     v = Random.new.rand(max)
  286.     v = Random.new.rand(max) if @prand.include?(v)
  287.     @prand << v
  288.     @prand.shift if @prand.length > 3
  289.     return v
  290.   end
  291. end
  292.  
  293. #==============================================================================
  294. # ** Math
  295. #==============================================================================
  296.  
  297. module Math
  298.   #--------------------------------------------------------------------------
  299.   # * Calculate angle between 2 points
  300.   #--------------------------------------------------------------------------
  301.   def self.angle(point1,point2)
  302.     x = point1[0] - point1[0]
  303.     y = point2[1] - point1[1]
  304.     radian = atan2(y,x)
  305.     angle = (radian/PI) * 180
  306.     return angle
  307.   end
  308.   #--------------------------------------------------------------------------
  309.   # * Calculate pos on a circle
  310.   #--------------------------------------------------------------------------
  311.   def self.circle(cx, cy, radius, angle)
  312.     x = cx + Math.sin(angle)*radius
  313.     y = cy + Math.cos(angle)*radius
  314.     return [x, y]
  315.   end
  316. end
  317.  
  318. #==============================================================================
  319. # ** String
  320. #==============================================================================
  321.  
  322. class String
  323.   def to_range
  324.     return unless self.include? ".."
  325.     literal = (self.include?"...") ? literal = "..." : literal = ".."
  326.     range = self.split(literal).map {|x| x.to_i}
  327.     return range[0]..range[1] if literal == ".."
  328.     return range[0]...range[1]
  329.   end
  330. end
  331.  
  332. #==============================================================================
  333. # ** RPG::Animation
  334. #==============================================================================
  335.  
  336. class RPG::Animation
  337.   def zoom_range
  338.     if @zoom_range.nil?
  339.       @zoom_range = @name =~ /<(.*)>/i ? $1.to_range : 0
  340.     end
  341.     return @zoom_range
  342.   end
  343. end
  344.  
  345. #==============================================================================
  346. # ** RPG::SE | RPG::BGM | RPG::ME | RPG::BGS
  347. #==============================================================================
  348.  
  349. class RPG::SE < RPG::AudioFile
  350.   def play
  351.     unless @name.empty?
  352.       volume = @volume + Quasi::VOLUME
  353.       volume = 0 if volume < 0
  354.       Audio.se_play('Audio/SE/' + @name, volume, @pitch)
  355.     end
  356.   end
  357. end
  358. class RPG::BGM < RPG::AudioFile
  359.   def play(pos = 0)
  360.     if @name.empty?
  361.       Audio.bgm_stop
  362.       @@last = RPG::BGM.new
  363.     else
  364.       volume = @volume + Quasi::VOLUME
  365.       volume = 0 if volume < 0
  366.       Audio.bgm_play('Audio/BGM/' + @name, volume, @pitch, pos)
  367.       @@last = self.clone
  368.     end
  369.   end
  370. end
  371. class RPG::ME < RPG::AudioFile
  372.   def play
  373.     if @name.empty?
  374.       Audio.me_stop
  375.     else
  376.       volume = @volume + Quasi::VOLUME
  377.       volume = 0 if volume < 0
  378.       Audio.me_play('Audio/ME/' + @name, volume, @pitch)
  379.     end
  380.   end
  381. end
  382. class RPG::BGS < RPG::AudioFile
  383.   def play(pos = 0)
  384.     if @name.empty?
  385.       Audio.bgs_stop
  386.       @@last = RPG::BGS.new
  387.     else
  388.       volume = @volume + Quasi::VOLUME
  389.       volume = 0 if volume < 0
  390.       Audio.bgs_play('Audio/BGS/' + @name, volume, @pitch, pos)
  391.       @@last = self.clone
  392.     end
  393.   end
  394. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement