Advertisement
QuasiXi

Module Quasi

Oct 1st, 2014
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 18.12 KB | None | 0 0
  1. #==============================================================================
  2. # ** Quasi v0.2
  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. # Change Log
  9. #------------------------------------------------------------------------------
  10. # v0.2 - Changed followers to be made when there are party members instead of
  11. #        already being made.
  12. #      - Fix to angle, had a typo.
  13. # --
  14. # v0.1 - Pre-Released for movement script
  15. #==============================================================================
  16. # * New method list
  17. #------------------------------------------------------------------------------
  18. #  class Game_Event
  19. #    def grab_comment(regex, default)
  20. #      * This def grabs comments from the event, if no default is set
  21. #      it will return true or false if the regex was found.
  22. #
  23. #  class Game_Party
  24. #    def add_actor & def remove_actor
  25. #      * Recreates followers
  26. #
  27. #    def lowest_level
  28. #      * Returns the lowest lvl in party
  29. #
  30. #    def who_level(value)
  31. #      * Returns the actor/s whose level is equal to the set value
  32. #      - If multiple actors, it returns an array
  33. #
  34. #    def avg_level
  35. #      *Grabs the average level of party
  36. #
  37. #    def lowest_param(param)
  38. #      *Returns lowest param value from party
  39. #
  40. #    def highest_param(param)
  41. #      * Returns highest param value from party
  42. #
  43. #    def avg_param(param)
  44. #      *Grabs the average value of param of party
  45. #
  46. #    def who_param(value,param)
  47. #      * Returns the actor/s whose param is equal to the set value
  48. #      - If multiple actors, it returns an array
  49. #
  50. #  class Game_Map
  51. #    def clone_event(x,y,mapid,eventid)
  52. #      * Copies event from the mapid to the current map at x,y
  53. #
  54. #  class Game_Follower & Game_Followers
  55. #   def initialize
  56. #      * Doesn't make all the followers at start anymore.
  57. #
  58. #   def recreate
  59. #      * Used to create followers when they are added to party.
  60. #
  61. #  class Scene_Base
  62. #    def wait(duration)
  63. #      * Waits duration time before continuing
  64. #
  65. #  class Sprite_Base
  66. #    alias start_animation
  67. #    alias animation_set_sprites
  68. #      * New feature that allows animations to appear different sizes each time.
  69. #        To use:  In animation name include a range in < numbers > ex:
  70. #                   002:Hit Fire <-50..50>
  71. #                 Animation will play at a random size between -50% to 50%
  72. #
  73. #  module Kernel
  74. #    def qrand(max)
  75. #      * Created my own rand.  A range can be used ex: qrand(-20..20)  
  76. #        It stores previous 3 randoms and if the current random is equal
  77. #        to any of those 3 it will run again.
  78. #
  79. #  module Math
  80. #    def self.angle(point1, point2)
  81. #      * Returns the angle of line made by point1 and point2
  82. #
  83. #    def self.circle(cx,cy,radius,angle)
  84. #      * Gets the x,y position on a circle from the given values
  85. #        cx and cy are center x/y
  86. #        radius is the radius of the circle
  87. #        angle is the angle you want the new points at.
  88. #
  89. #  class String
  90. #    def to_range
  91. #      * Converts string to a range.  Needs to be written as a range
  92. #        "0..10" or "0...10"
  93. #
  94. #  RPG::Animation
  95. #    def zoom_range
  96. #      * Used to grab the random animation zoom range from the name.  If regex
  97. #        is not found it defaults to 0 which means no change in size.
  98. #
  99. #  RPG::SE | RPG::BGM | RPG::ME | RPG::BGS
  100. #    def play
  101. #      * Added a master volume control.  Value set on line 94
  102. #==============================================================================
  103. module Quasi
  104.   #--------------------------------------------------------------------------
  105.   # * Master volume control.  VXA default sounds are too loud on my pc
  106.   #   so I have it set at -70 when testing scripts.
  107.   #--------------------------------------------------------------------------
  108.   VOLUME = -70
  109. end
  110. $imported = {} if $imported.nil?
  111. $imported["Quasi"] = 0.2
  112. #==============================================================================
  113. # ** Game_Event
  114. #------------------------------------------------------------------------------
  115. #  This class handles events. Functions include event page switching via
  116. # condition determinants and running parallel process events. Used within the
  117. # Game_Map class.
  118. #==============================================================================
  119.  
  120. class Game_Event < Game_Character
  121.   #--------------------------------------------------------------------------
  122.   # * Grabs comment from event
  123.   #--------------------------------------------------------------------------
  124.   def grab_comment(regex,default=nil)
  125.     return unless @list
  126.     reg = []
  127.     @list.each do |cmd|
  128.       next if cmd.code != 108
  129.       comment = cmd.parameters[0]
  130.       next unless comment =~ regex
  131.       if !default.nil?
  132.         reg << $1
  133.       else
  134.         reg = [true]
  135.       end
  136.     end
  137.     return default if reg.empty?
  138.     return reg if reg.length > 1
  139.     return reg[0]
  140.   end
  141. end
  142.  
  143. #==============================================================================
  144. # ** Game_Party
  145. #------------------------------------------------------------------------------
  146. #  This class handles parties. Information such as gold and items is included.
  147. # Instances of this class are referenced by $game_party.
  148. #==============================================================================
  149.  
  150. class Game_Party < Game_Unit
  151.   #--------------------------------------------------------------------------
  152.   # * Add an Actor
  153.   #--------------------------------------------------------------------------
  154.   def add_actor(actor_id)
  155.     if !@actors.include?(actor_id)
  156.       @actors.push(actor_id)
  157.       $game_player.followers.recreate
  158.       SceneManager.scene.spriteset_refresh if SceneManager.scene_is?(Scene_Map)
  159.     end
  160.     $game_player.refresh
  161.     $game_map.need_refresh = true
  162.   end
  163.   #--------------------------------------------------------------------------
  164.   # * Remove Actor
  165.   #--------------------------------------------------------------------------
  166.   def remove_actor(actor_id)
  167.     @actors.delete(actor_id)
  168.     $game_player.followers.recreate
  169.     SceneManager.scene.spriteset_refresh if SceneManager.scene_is?(Scene_Map)
  170.     $game_player.refresh
  171.     $game_map.need_refresh = true
  172.   end
  173.   #--------------------------------------------------------------------------
  174.   # * Get Lowest Level of Party Members
  175.   #--------------------------------------------------------------------------
  176.   def lowest_level
  177.     lvl = members.collect {|actor| actor.level }.min
  178.     return lvl
  179.   end
  180.   #--------------------------------------------------------------------------
  181.   # * Get Who the Level belongs too
  182.   # ** If multiple have the same level, it returns an array with both
  183.   #--------------------------------------------------------------------------
  184.   def who_level(value)
  185.     who = []
  186.     members.each do |mem|
  187.       next unless mem.level == value
  188.       who.push(mem.name)
  189.     end
  190.     return if who.empty?
  191.     return who[0] if who.size == 1
  192.     return who
  193.   end
  194.   #--------------------------------------------------------------------------
  195.   # * Get Average Level of Party Members
  196.   #--------------------------------------------------------------------------
  197.   def avg_level
  198.     avg = 0
  199.     members.each {|actor| avg += actor.level}
  200.     avg /= members.size
  201.     return avg
  202.   end
  203.   #--------------------------------------------------------------------------
  204.   # * Get Lowest Value of param of Party Members
  205.   #--------------------------------------------------------------------------
  206.   def lowest_param(x)
  207.     param = members.collect {|actor| actor.param(x) }.min
  208.     return param
  209.   end
  210.   #--------------------------------------------------------------------------
  211.   # * Get Highest Value of param of Party Members
  212.   #--------------------------------------------------------------------------
  213.   def highest_param(x)
  214.     param = members.collect {|actor| actor.param(x) }.max
  215.     return param
  216.   end
  217.   #--------------------------------------------------------------------------
  218.   # * Get Average Value of param of Party Members
  219.   #--------------------------------------------------------------------------
  220.   def avg_param(x)
  221.     avg = 0
  222.     members.each {|actor| avg += actor.param(x)}
  223.     avg /= members.size
  224.     return avg
  225.   end
  226.   #--------------------------------------------------------------------------
  227.   # * Get Who the param belongs too
  228.   #--------------------------------------------------------------------------
  229.   def who_param(value, x)
  230.     who = []
  231.     members.each do |mem|
  232.       next unless mem.param(x) == value
  233.       who.push(mem.name)
  234.     end
  235.     return if who.empty?
  236.     return who[0] if who.size == 1
  237.     return who
  238.   end
  239. end
  240.  
  241. #==============================================================================
  242. # ** Game_Map
  243. #------------------------------------------------------------------------------
  244. #  This class handles maps. It includes scrolling and passage determination
  245. # functions. The instance of this class is referenced by $game_map.
  246. #==============================================================================
  247.  
  248. class Game_Map
  249.   #--------------------------------------------------------------------------
  250.   # * Clone event from any map to x,y pos
  251.   #--------------------------------------------------------------------------
  252.   def clone_event(x,y,mapid,eventid)
  253.     cmap = load_data(sprintf("Data/Map%03d.rvdata2", mapid))
  254.     return if cmap.events[eventid].nil?
  255.     cmap.events[eventid].x = x
  256.     cmap.events[eventid].y = y
  257.     @events[@events.length+1] = Game_Event.new(mapid, cmap.events[eventid])
  258.     SceneManager.scene.spriteset_refresh
  259.     refresh
  260.   end
  261. end
  262.  
  263. #==============================================================================
  264. # ** Game_Follower
  265. #------------------------------------------------------------------------------
  266. #  This class handles followers. A follower is an allied character, other than
  267. # the front character, displayed in the party. It is referenced within the
  268. # Game_Followers class.
  269. #==============================================================================
  270.  
  271. class Game_Follower < Game_Character
  272.   #--------------------------------------------------------------------------
  273.   # * Object Initialization
  274.   #--------------------------------------------------------------------------
  275.   def initialize(member_index, preceding_character)
  276.     super()
  277.     @member_index = member_index
  278.     @preceding_character = !preceding_character ? $game_player : preceding_character
  279.     @transparent = $data_system.opt_transparent
  280.     @through = true
  281.   end
  282. end
  283.  
  284. #==============================================================================
  285. # ** Game_Followers
  286. #------------------------------------------------------------------------------
  287. #  This is a wrapper for a follower array. This class is used internally for
  288. # the Game_Player class.
  289. #==============================================================================
  290.  
  291. class Game_Followers
  292.   #--------------------------------------------------------------------------
  293.   # * Object Initialization
  294.   #     leader:  Lead character
  295.   #--------------------------------------------------------------------------
  296.   def initialize(leader)
  297.     @visible = $data_system.opt_followers
  298.     @gathering = false                    # Gathering processing underway flag
  299.     @data = []
  300.     $data_system.party_members.each_index do |index|
  301.       next if index == 0
  302.       prec = index == 1 ? leader : @data[-1]
  303.       @data.push(Game_Follower.new(index, prec))
  304.     end
  305.   end
  306.   #--------------------------------------------------------------------------
  307.   # * Recreate
  308.   #--------------------------------------------------------------------------
  309.   def recreate
  310.     @data = []
  311.     $game_party.battle_members.each_index do |index|
  312.       next if index == 0
  313.       prec = index == 1 ? $game_player : @data[-1]
  314.       @data.push(Game_Follower.new(index, prec))
  315.     end
  316.     synchronize($game_player.x, $game_player.y, $game_player.direction)
  317.   end
  318. end
  319.  
  320. #==============================================================================
  321. # ** Sprite_Base
  322. #------------------------------------------------------------------------------
  323. #  A sprite class with animation display processing added.
  324. #==============================================================================
  325.  
  326. class Sprite_Base < Sprite
  327.   alias quasi_start_animation start_animation
  328.   alias quasi_animation_set animation_set_sprites
  329.   #--------------------------------------------------------------------------
  330.   # * Start Animation
  331.   #--------------------------------------------------------------------------
  332.   def start_animation(animation, mirror = false)
  333.     quasi_start_animation(animation, mirror)
  334.     if @animation
  335.       @rand = qrand(@animation.zoom_range)
  336.     end
  337.   end
  338.   #--------------------------------------------------------------------------
  339.   # * Set Animation Sprite
  340.   #     frame : Frame data (RPG::Animation::Frame)
  341.   #--------------------------------------------------------------------------
  342.   def animation_set_sprites(frame)
  343.     quasi_animation_set(frame)
  344.     return if @rand == 0
  345.     cell_data = frame.cell_data
  346.     @ani_sprites.each_with_index do |sprite, i|
  347.       next unless sprite
  348.       pattern = cell_data[i, 0]
  349.       next if !pattern || pattern < 0
  350.       sprite.zoom_x += @rand/100.0
  351.       sprite.zoom_y += @rand/100.0
  352.     end
  353.   end
  354. end
  355.  
  356. #==============================================================================
  357. # ** Scene_Base
  358. #------------------------------------------------------------------------------
  359. #  This is a super class of all scenes within the game.
  360. #==============================================================================
  361.  
  362. class Scene_Base
  363.   #--------------------------------------------------------------------------
  364.   # * Wait
  365.   #--------------------------------------------------------------------------
  366.   def wait(duration)
  367.     duration.times {|i| update_basic if i < duration }
  368.   end
  369. end
  370.  
  371. #==============================================================================
  372. # ** Scene_Map
  373. #------------------------------------------------------------------------------
  374. #  This class performs the map screen processing.
  375. #==============================================================================
  376.  
  377. class Scene_Map < Scene_Base
  378.   #--------------------------------------------------------------------------
  379.   # * Refresh spriteset
  380.   #--------------------------------------------------------------------------
  381.   def spriteset_refresh
  382.     @spriteset.refresh_characters
  383.   end
  384. end
  385.  
  386. #==============================================================================
  387. # ** Kernel
  388. #==============================================================================
  389.  
  390. module Kernel
  391.   def qrand(max)
  392.     max = 1 if max == 0
  393.     @prand = [] if @prand.nil?
  394.     v = Random.new.rand(max)
  395.     v = Random.new.rand(max) if @prand.include?(v)
  396.     @prand << v
  397.     @prand.shift if @prand.length > 3
  398.     return v
  399.   end
  400. end
  401.  
  402. #==============================================================================
  403. # ** Math
  404. #==============================================================================
  405.  
  406. module Math
  407.   #--------------------------------------------------------------------------
  408.   # * Calculate angle between 2 points
  409.   #--------------------------------------------------------------------------
  410.   def self.angle(point1,point2)
  411.     x = point2[0] - point1[0]
  412.     y = point2[1] - point1[1]
  413.     radian = atan2(y,x)
  414.     angle = (radian/PI) * 180
  415.     return angle
  416.   end
  417.   #--------------------------------------------------------------------------
  418.   # * Calculate pos on a circle
  419.   #--------------------------------------------------------------------------
  420.   def self.circle(cx, cy, radius, angle)
  421.     x = cx + Math.sin(angle)*radius
  422.     y = cy + Math.cos(angle)*radius
  423.     return [x, y]
  424.   end
  425. end
  426.  
  427. #==============================================================================
  428. # ** String
  429. #==============================================================================
  430.  
  431. class String
  432.   def to_range
  433.     return unless self.include? ".."
  434.     literal = (self.include?"...") ? literal = "..." : literal = ".."
  435.     range = self.split(literal).map {|x| x.to_i}
  436.     return range[0]..range[1] if literal == ".."
  437.     return range[0]...range[1]
  438.   end
  439. end
  440.  
  441. #==============================================================================
  442. # ** RPG::Animation
  443. #==============================================================================
  444.  
  445. class RPG::Animation
  446.   def zoom_range
  447.     if @zoom_range.nil?
  448.       @zoom_range = @name =~ /<(.*)>/i ? $1.to_range : 0
  449.     end
  450.     return @zoom_range
  451.   end
  452. end
  453.  
  454. #==============================================================================
  455. # ** RPG::SE | RPG::BGM | RPG::ME | RPG::BGS
  456. #==============================================================================
  457.  
  458. class RPG::SE < RPG::AudioFile
  459.   def play
  460.     unless @name.empty?
  461.       volume = @volume + Quasi::VOLUME
  462.       volume = 0 if volume < 0
  463.       Audio.se_play('Audio/SE/' + @name, volume, @pitch)
  464.     end
  465.   end
  466. end
  467. class RPG::BGM < RPG::AudioFile
  468.   def play(pos = 0)
  469.     if @name.empty?
  470.       Audio.bgm_stop
  471.       @@last = RPG::BGM.new
  472.     else
  473.       volume = @volume + Quasi::VOLUME
  474.       volume = 0 if volume < 0
  475.       Audio.bgm_play('Audio/BGM/' + @name, volume, @pitch, pos)
  476.       @@last = self.clone
  477.     end
  478.   end
  479. end
  480. class RPG::ME < RPG::AudioFile
  481.   def play
  482.     if @name.empty?
  483.       Audio.me_stop
  484.     else
  485.       volume = @volume + Quasi::VOLUME
  486.       volume = 0 if volume < 0
  487.       Audio.me_play('Audio/ME/' + @name, volume, @pitch)
  488.     end
  489.   end
  490. end
  491. class RPG::BGS < RPG::AudioFile
  492.   def play(pos = 0)
  493.     if @name.empty?
  494.       Audio.bgs_stop
  495.       @@last = RPG::BGS.new
  496.     else
  497.       volume = @volume + Quasi::VOLUME
  498.       volume = 0 if volume < 0
  499.       Audio.bgs_play('Audio/BGS/' + @name, volume, @pitch, pos)
  500.       @@last = self.clone
  501.     end
  502.   end
  503. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement