Heartbreak61

HBK Basic v0.60

Jan 31st, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.31 KB | None | 0 0
  1. =begin
  2. HBK Basic v0.60
  3. created 2013.01.31
  4.  
  5. class Integer
  6. <Integer>.factorial
  7.   Will return the factorial value of self.
  8.   Example:
  9.   5.factorial
  10.   will return 5 * 4 * 3 * 2 * 1 #=> 120
  11.  
  12. <Integer>.sum_to(target)
  13.   Will return the sum value of self increased or decreased by 1 until self
  14.   reach target.
  15.   Example:
  16.   3.sum_to(5)
  17.   will return 3 + 4 + 5 #=> 12
  18.  
  19. <Integer>.sum_down
  20.   Will return the sum value of self increased or decreased by 1 until self
  21.   reach 0.
  22.   Example:
  23.   -3.sumdown
  24.   will return (-3) + (-2) + (-1) + 0 #=> - 6
  25.  
  26. class Array
  27. <Array>.random
  28. <Array>.random!
  29.   Will result on random member. random! will remove the returned value from
  30.   Array.
  31.  
  32. <Array>.sum
  33.   Returns the sum of all numeric values.
  34.  
  35. <Array>.average(float = false)
  36. float : float flag
  37.   Returns the average of all numeric values, if float is true, the value
  38.   returned is a float, otherwise it's a integer.
  39.  
  40. class Game_Unit
  41. New method: lowest(method_name)
  42. New method: highest(method_name)
  43.   Will return the member with lowest/highest value of (method_name)
  44.   Method name could be on symbol or string. For example :hp or "hp" will be
  45.   considered as valid argument.
  46.   Example:
  47.   $game_troop.lowest(:hp)
  48.   will return alive member with lowest HP
  49.  
  50. New method: lowest_by_index(method_name)
  51. New method: highest_by_index(method_name)
  52.   Will return the index of member which has lowest/highest attribute declared
  53.   on method name.
  54.   Method name could be on symbol or string. For example :hp or "hp" will be
  55.   considered as valid argument.
  56.  
  57. class Game_Battler
  58. New method: lowest?(method_name)
  59.   Method name could be on symbol or string. For example :hp or "hp" will be
  60.   considered as valid argument.
  61.   Example:
  62.   $game_actors[1].lowest?(:hp)
  63.   will return true if he/she is alive &  has lowest HP on party.
  64.  
  65. *Credits (from me)
  66. - Victor Sant
  67. - Tsukihime
  68.  
  69. *Note:
  70. I found that some of the method here were already written on Victor's Basic
  71. Module. But since it just modify the basic objects like Array and Integer,
  72. I think it's okay to copy it on my basic module. Please give credit to him
  73. if you feel like to.
  74. =end
  75.  
  76. #===============================================================================
  77. # ■ Skip Title
  78. #==============================================================================
  79. module SkipTitle
  80.   Skip = true # <= Set to false if you don't want to skip intro
  81.   Width = 544
  82.   Height = 416
  83.   Framerate = 60
  84. end
  85.  
  86. #===============================================================================
  87. # ■ Array
  88. #===============================================================================
  89. class Array
  90.   def sum
  91.     return self.inject(0) {|r, n| r += (n.is_a?(Numeric) ? n : 0)}
  92.   end
  93.  
  94.   def random
  95.     return self[rand(size)]
  96.   end
  97.  
  98.   def random!
  99.     return self.delete_at(rand(size))
  100.   end
  101.  
  102.   def average(float = false)
  103.     return self.sum / [(float ? size.to_f : size.to_i), 1].max
  104.   end
  105. end
  106.  
  107. #===============================================================================
  108. # ■ Integer
  109. #===============================================================================
  110. class Integer
  111.   #--------------------------------------------------------------------------
  112.   # * New method: factorial
  113.   #--------------------------------------------------------------------------
  114.   def factorial
  115.     return if self <= 0
  116.     return (1..self).inject(1) {|r,n| r *= n}
  117.   end
  118.  
  119.   #--------------------------------------------------------------------------
  120.   # * New method: sum_to
  121.   #--------------------------------------------------------------------------
  122.   def sum_to(v)
  123.     if v > self
  124.       (self..v).inject(0) {|r,n| r += n}
  125.     elsif v < self
  126.       (v..self).inject(0) {|r,n| r += n}
  127.     else
  128.       self
  129.     end
  130.   end
  131.  
  132.   #--------------------------------------------------------------------------
  133.   # * New method: sum_down
  134.   #--------------------------------------------------------------------------
  135.   def sum_down
  136.     sum_to(0)
  137.   end
  138. end
  139.  
  140. #===============================================================================
  141. # ■ SceneManager
  142. #==============================================================================
  143. module SceneManager
  144.   class << self
  145.     alias skiptitle_run run
  146.   end
  147.  
  148.   def self.run
  149.     DataManager.init
  150.     Graphics.frame_rate = SkipTitle::Framerate
  151.     Graphics.resize_screen(SkipTitle::Width, SkipTitle::Height)
  152.     Audio.setup_midi if use_midi?
  153.     if SkipTitle::Skip
  154.       if $BTEST
  155.         SceneManager.goto(Scene_Battle)
  156.       elsif not DataManager.save_file_exists?
  157.         DataManager.setup_new_game    
  158.         $game_map.autoplay            
  159.         SceneManager.goto(Scene_Map)
  160.       else                            
  161.         @scene = first_scene_class.new
  162.       end                              
  163.       @scene.main while @scene
  164.     else
  165.       skiptitle_run
  166.     end
  167.   end
  168. end
  169.  
  170. #==============================================================================
  171. # ■ Game_Unit
  172. #==============================================================================
  173. class Game_Unit
  174.   # Just for compatibility reason for Game_Troop
  175.   def battle_members
  176.     return members
  177.   end
  178.  
  179.   def lowest(name)
  180.     m = alive_members.min_by{|member|
  181.     member.send(name)
  182.     }
  183.     return m
  184.   end
  185.  
  186.   def highest(name)
  187.     m = alive_members.max_by{|member|
  188.     member.send(name)
  189.     }
  190.     return m
  191.   end
  192.  
  193.   def lowest_by_index(name)
  194.     return members.index(lowest(name))
  195.   end
  196.  
  197.   def highest_by_index(name)
  198.     return members.index(highest(name))
  199.   end
  200. end
  201.  
  202. #==============================================================================
  203. # ■ Game_BattlerBase
  204. #==============================================================================
  205. class Game_BattlerBase
  206.   # TP Rate fix, in case you modified max_tp
  207.   def tp_rate
  208.     @tp.to_f / max_tp
  209.   end
  210. end
  211.  
  212. #==============================================================================
  213. # ■ Game_Battler
  214. #==============================================================================
  215. class Game_Battler < Game_BattlerBase
  216.   def lowest?(name)
  217.     return self == friends_unit.lowest(name)
  218.     return false
  219.   end
  220.  
  221.   def highest?(name)
  222.     return self == friends_unit.highest(name)
  223.     return false
  224.   end
  225. end
  226.  
  227. $imported = {} if $imported.nil?
  228. $imported["HBK Basic"] = 0.60
Advertisement
Add Comment
Please, Sign In to add comment