pigu_6

Yanfly| Class Unlock Level

Nov 24th, 2012
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.16 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # ▼ Yanfly Engine Ace - Class System Add-On: Class Unlock Level v1.00
  4. # -- Last Updated: 2011.12.20
  5. # -- Level: Normal
  6. # -- Requires: YEA - Class System v1.01+
  7. #
  8. #==============================================================================
  9.  
  10. $imported = {} if $imported.nil?
  11. $imported["YEA-ClassUnlockLevel"] = true
  12.  
  13. #==============================================================================
  14. # ▼ Updates
  15. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  16. # 2011.12.20 - Started Script and Finished.
  17. #
  18. #==============================================================================
  19. # ▼ Introduction
  20. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  21. # This script allows for classes to be unlocked after a class reaches a certain
  22. # level. Note that this script is made for the Class System script and not
  23. # using the MAINTAIN_LEVELS feature. Requirements for unlocking a class can be
  24. # multiple level requirements as well.
  25. #
  26. #==============================================================================
  27. # ▼ Instructions
  28. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  29. # To install this script, open up your script editor and copy/paste this script
  30. # to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.
  31. #
  32. # -----------------------------------------------------------------------------
  33. # Class Notetags - These notetags go in the class notebox in the database.
  34. # -----------------------------------------------------------------------------
  35. # <level unlock requirements>
  36. # class x: level y
  37. # class x: level y
  38. # </level unlock requirements>
  39. # Sets the requirements for unlocking that particular class. The unlocking of
  40. # the class will require classes x to be at level y. Insert multiple of the
  41. # strings in between the two opening and closing notetags to require all of the
  42. # class levels to be met.
  43. #
  44. #==============================================================================
  45. # ▼ Compatibility
  46. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  47. # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
  48. # it will run with RPG Maker VX without adjusting.
  49. #
  50. # This script requires Yanfly Engine Ace - Class System v1.01+.
  51. #
  52. #==============================================================================
  53. # ▼ Editting anything past this point may potentially result in causing
  54. # computer damage, incontinence, explosion of user's head, coma, death, and/or
  55. # halitosis so edit at your own risk.
  56. #==============================================================================
  57.  
  58. if $imported["YEA-ClassSystem"] && !YEA::CLASS_SYSTEM::MAINTAIN_LEVELS
  59.  
  60. module YEA
  61. module REGEXP
  62. module CLASS
  63.  
  64. LV_UNLOCK_ON =
  65. /<(?:LEVEL_UNLOCK_REQUIREMENTS|level unlock requirements)>/i
  66. LV_UNLOCK_OFF =
  67. /<\/(?:LEVEL_UNLOCK_REQUIREMENTS|level unlock requirements)>/i
  68. LV_UNLOCK_STR = /CLASS[ ](\d+): LEVEL[ ](\d+)/i
  69.  
  70. end # CLASS
  71. end # REGEXP
  72. end # YEA
  73.  
  74. #==============================================================================
  75. # ■ DataManager
  76. #==============================================================================
  77.  
  78. module DataManager
  79.  
  80. #--------------------------------------------------------------------------
  81. # alias method: load_database
  82. #--------------------------------------------------------------------------
  83. class <<self; alias load_database_cul load_database; end
  84. def self.load_database
  85. load_database_cul
  86. load_notetags_cul
  87. end
  88.  
  89. #--------------------------------------------------------------------------
  90. # new method: load_notetags_cul
  91. #--------------------------------------------------------------------------
  92. def self.load_notetags_cul
  93. for obj in $data_classes
  94. next if obj.nil?
  95. obj.load_notetags_cul
  96. end
  97. end
  98.  
  99. end # DataManager
  100.  
  101. #==============================================================================
  102. # ■ RPG::Class
  103. #==============================================================================
  104.  
  105. class RPG::Class < RPG::BaseItem
  106.  
  107. #--------------------------------------------------------------------------
  108. # public instance variables
  109. #--------------------------------------------------------------------------
  110. attr_accessor :level_unlock
  111.  
  112. #--------------------------------------------------------------------------
  113. # common cache: load_notetags_cul
  114. #--------------------------------------------------------------------------
  115. def load_notetags_cul
  116. @level_unlock = {}
  117. @level_unlock_on = false
  118. #---
  119. self.note.split(/[\r\n]+/).each { |line|
  120. case line
  121. #---
  122. when YEA::REGEXP::CLASS::LV_UNLOCK_ON
  123. @level_unlock_on = true
  124. when YEA::REGEXP::CLASS::LV_UNLOCK_OFF
  125. @level_unlock_on = false
  126. when YEA::REGEXP::CLASS::LV_UNLOCK_STR
  127. next unless @level_unlock_on
  128. @level_unlock[$1.to_i] = $2.to_i
  129. end
  130. } # self.note.split
  131. #---
  132. end
  133.  
  134. end # RPG::Class
  135.  
  136. #==============================================================================
  137. # ■ Game_Actor
  138. #==============================================================================
  139.  
  140. class Game_Actor < Game_Battler
  141.  
  142. #--------------------------------------------------------------------------
  143. # check_level_unlocked_classes
  144. #--------------------------------------------------------------------------
  145. def check_level_unlocked_classes
  146. for item in $data_classes
  147. next if item.nil?
  148. next if unlocked_classes.include?(item.id)
  149. next if item.level_unlock == {}
  150. next unless class_unlock_level_requirements_met?(item)
  151. unlock_class(item.id)
  152. end
  153. end
  154.  
  155. #--------------------------------------------------------------------------
  156. # class_unlock_level_requirements_met?
  157. #--------------------------------------------------------------------------
  158. def class_unlock_level_requirements_met?(item)
  159. for key in item.level_unlock
  160. class_id = key[0]
  161. level_req = key[1]
  162. return false if class_level(class_id) < level_req
  163. end
  164. return true
  165. end
  166.  
  167. end # Game_Actor
  168.  
  169. #==============================================================================
  170. # ■ Window_ClassList
  171. #==============================================================================
  172.  
  173. class Window_ClassList < Window_Selectable
  174.  
  175. #--------------------------------------------------------------------------
  176. # alias method: actor=
  177. #--------------------------------------------------------------------------
  178. alias window_classlist_actor_equals_cul actor=
  179. def actor=(actor)
  180. return if @actor == actor
  181. actor.check_level_unlocked_classes
  182. window_classlist_actor_equals_cul(actor)
  183. end
  184.  
  185. end # Window_ClassList
  186.  
  187. end # $imported["YEA-ClassSystem"] && !YEA::CLASS_SYSTEM::MAINTAIN_LEVELS
  188.  
  189. #==============================================================================
  190. #
  191. # ▼ End of File
  192. #
  193. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment