Advertisement
mrbubble

Gender Requirements

Jan 7th, 2012
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.81 KB | None | 0 0
  1. #==============================================================================
  2. # ++ Gender Requirements ++                                      v1.0 (1/07/12)
  3. #==============================================================================
  4. # Script by:
  5. #     Mr. Bubble ( http://mrbubblewand.wordpress.com/ )
  6. # Thanks:
  7. #     Yanfly, script and design references, suggesting to make this script
  8. #--------------------------------------------------------------------------
  9. # This is an add-on script for Gender Functions which allows developers to
  10. # define gender requirements for equipment, skills, and items.
  11. #
  12. # Built-in support for Yanfly Engine Ace - Class System is included.
  13. #--------------------------------------------------------------------------
  14. # ++ Changelog ++
  15. #--------------------------------------------------------------------------
  16. # v1.0 : Initial release. (1/06/2012)
  17. #--------------------------------------------------------------------------
  18. # ++ Installation ++
  19. #--------------------------------------------------------------------------
  20. # Install this script in the Materials section in your project's
  21. # script editor. This script requires that Gender Functions is also
  22. # installed in your project.
  23. #
  24. # Place this script below YEA - Class System in your script editor list
  25. # if you have that script installed as well.
  26. #--------------------------------------------------------------------------
  27. # ++ Gender Requirement Notetags ++
  28. #--------------------------------------------------------------------------
  29. # The following notetags are for Classes, Skills, Items, Weapons,
  30. # and Armors:
  31. #
  32. # <gender req: genderless>
  33. # <gender requirement: genderless>
  34. #   Requires that the actor be genderless in order to use/equip the skill,
  35. #   item, weapon, or armor. Each tag listed above has the same effect.
  36. #   Simply choose whichever one you prefer to type.
  37. #  
  38. # <gender req: m>
  39. # <gender req: male>
  40. # <gender requirement: male>
  41. #   Requires that the actor be male in order to use/equip the skill,
  42. #   item, weapon, or armor. Each tag listed above has the same effect.
  43. #   Simply choose whichever one you prefer to type.
  44. #  
  45. # <gender req: f>
  46. # <gender req: female>
  47. # <gender requirement: female>
  48. #   Requires that the actor be female in order to use/equip the skill,
  49. #   item, weapon, or armor. Each tag listed above has the same effect.
  50. #   Simply choose whichever one you prefer to type.
  51. #
  52. # Multiple gender requirement tags may be added to the same notebox.
  53. #
  54. # Class gender requirements are currently only for YEA - Class System.
  55. # Gender requirements for classes do not affect the "Change Class..."
  56. # event command.
  57. #--------------------------------------------------------------------------
  58. # The following notetags are for Actors, Classes, and Enemies:
  59. #
  60. # <gender req: ignore>
  61. # <gender requirement: ignore>
  62. #   Allows the actor, class, or enemy to ignore any imposed gender
  63. #   requirements for classes, skills, items, weapons, and armors. Each
  64. #   tag listed above has the same effect. Simply choose whichever one
  65. #   you prefer to type.
  66. #
  67. # If you need very specifc exceptions made regarding gender requirements,
  68. # it is recommended that you create your own Armor Type(s) in your
  69. # Database and define equip permissions through that.
  70. #--------------------------------------------------------------------------
  71. # ++ Compatibility ++
  72. #--------------------------------------------------------------------------
  73. # This script does not overwrite any default VXA methods. All default
  74. # methods modified in this script are aliased.
  75. #
  76. # This script has built-in compatibility with the following scripts:
  77. #     - Yanfly Engine Ace - Class System
  78. #
  79. # Requests for compatibility with other scripts are welcome.
  80. #--------------------------------------------------------------------------
  81. # ++ Terms and Conditions ++
  82. #--------------------------------------------------------------------------
  83. # Please do not repost this script elsewhere without permission. Newest
  84. # versions of this script can be found at http://mrbubblewand.wordpress.com/
  85. #==========================================================================
  86.  
  87. $imported = {} if $imported.nil?
  88. $imported["BubsGenderRequirements"] = true
  89.  
  90. #==========================================================================
  91. # ++ THIS SCRIPT CONTAINS NO USER CUSTOMIZATION MODULE ++
  92. #==========================================================================
  93.  
  94. if $imported["BubsGenderFunctions"]
  95. #==========================================================================
  96. # ++ Bubs::Regexp
  97. #==========================================================================
  98. module Bubs
  99.   module Regexp
  100.     module BaseItem
  101.       GENDER_REQUIREMENTS =
  102.         /<GENDER[_\s](?:REQUIREMENT[S]?|req):\s*(\w*)>/i
  103.     end # module BaseItem
  104.   end # module Regexp
  105. end # module Bubs
  106.  
  107.  
  108. #==========================================================================
  109. # ++ DataManager
  110. #==========================================================================
  111. module DataManager
  112.  
  113.   #--------------------------------------------------------------------------
  114.   # alias : load_database
  115.   #--------------------------------------------------------------------------
  116.   class << self; alias load_database_bubs_gender_requirements load_database; end
  117.   def self.load_database
  118.     load_database_bubs_gender_requirements # alias
  119.     load_notetags_bubs_gender_requirements
  120.   end
  121.  
  122.   #--------------------------------------------------------------------------
  123.   # new method : load_notetags_bubs_gender_requirements
  124.   #--------------------------------------------------------------------------
  125.   def self.load_notetags_bubs_gender_requirements
  126.     groups = [$data_actors, $data_classes, $data_skills, $data_items,
  127.       $data_weapons, $data_armors, $data_enemies]
  128.     for group in groups
  129.       for obj in group
  130.         next if obj.nil?
  131.         obj.load_notetags_bubs_gender_requirements
  132.       end
  133.     end
  134.   end
  135.  
  136. end # module DataManager
  137.  
  138.  
  139. #==========================================================================
  140. # ++ RPG::BaseItem
  141. #==========================================================================
  142. class RPG::BaseItem
  143.   #--------------------------------------------------------------------------
  144.   # public instance variables
  145.   #--------------------------------------------------------------------------
  146.   attr_accessor :gender_requirements
  147.   attr_accessor :ignore_gender_requirements
  148.  
  149.   #--------------------------------------------------------------------------
  150.   # common cache : load_notetags_bubs_gender_requirements
  151.   #--------------------------------------------------------------------------
  152.   def load_notetags_bubs_gender_requirements
  153.     @gender_requirements = []
  154.     @ignore_gender_requirements = false
  155.    
  156.     self.note.split(/[\r\n]+/).each { |line|
  157.       case line
  158.       when Bubs::Regexp::BaseItem::GENDER_REQUIREMENTS
  159.         case $1.upcase
  160.         when "IGNORE"
  161.           next unless self.is_a?(RPG::Actor) ||
  162.             self.is_a?(RPG::Class) ||
  163.             self.is_a?(RPG::Enemy)
  164.           @ignore_gender_requirements = true
  165.          
  166.         when "GENDERLESS", "NONE"
  167.           next if self.is_a?(RPG::Actor) || self.is_a?(RPG::Enemy)
  168.           @gender_requirements.push(0) unless @gender_requirements.include?(0)
  169.        
  170.         when "MALE", "M"
  171.           next if self.is_a?(RPG::Actor) || self.is_a?(RPG::Enemy)
  172.           @gender_requirements.push(1) unless @gender_requirements.include?(1)
  173.          
  174.         when "FEMALE", "F"
  175.           next if self.is_a?(RPG::Actor) || self.is_a?(RPG::Enemy)
  176.           @gender_requirements.push(2) unless @gender_requirements.include?(2)
  177.  
  178.         end # case
  179.       end # case
  180.     } # self.note.split
  181.    
  182.   end # def
  183. end # class RPG::BaseItem
  184.  
  185.  
  186. #==============================================================================
  187. # ++ Game_BattlerBase
  188. #==============================================================================
  189. class Game_BattlerBase
  190.   #--------------------------------------------------------------------------
  191.   # new method : gender_conditions_met?
  192.   #--------------------------------------------------------------------------
  193.   def gender_conditions_met?(item)
  194.     return true if item.gender_requirements.empty?
  195.     if actor?
  196.       return true if self.actor.ignore_gender_requirements
  197.       # ensures being a class does not allow ignoring class gender reqs
  198.       unless item.is_a?(RPG::Class)
  199.         return true if self.class.ignore_gender_requirements
  200.       end
  201.       return true if item.gender_requirements.include?(self.actor.gender)
  202.     else
  203.       return true if self.enemy.ignore_gender_requirements
  204.       return true if item.gender_requirements.include?(self.enemy.gender)
  205.     end
  206.     return false
  207.   end
  208.  
  209.   #--------------------------------------------------------------------------
  210.   # alias : equippable?
  211.   #--------------------------------------------------------------------------
  212.   alias equippable_bubs_gender_requirements equippable?
  213.   def equippable?(item)
  214.     return false unless equippable_bubs_gender_requirements(item) # alias
  215.     return false unless gender_conditions_met?(item)
  216.     return true
  217.   end
  218.  
  219.   #--------------------------------------------------------------------------
  220.   # alias : skill_conditions_met?
  221.   #--------------------------------------------------------------------------
  222.   alias skill_conditions_met_bubs_gender_requirements skill_conditions_met?
  223.   def skill_conditions_met?(skill)
  224.     return false unless gender_conditions_met?(skill)
  225.     return skill_conditions_met_bubs_gender_requirements(skill) # alias
  226.   end
  227.  
  228.   #--------------------------------------------------------------------------
  229.   # alias : item_conditions_met?
  230.   #--------------------------------------------------------------------------
  231.   alias item_conditions_met_bubs_gender_requirements item_conditions_met?
  232.   def item_conditions_met?(item)
  233.     return false unless gender_conditions_met?(item)
  234.     return item_conditions_met_bubs_gender_requirements(item) # alias
  235.   end
  236.  
  237. end # class Game_BattlerBase
  238.  
  239.  
  240. #==============================================================================
  241. # ++ Window_ClassList
  242. #==============================================================================
  243. if $imported["YEA-ClassSystem"]
  244.  
  245. class Window_ClassList < Window_Selectable
  246.   #--------------------------------------------------------------------------
  247.   # alias : include?
  248.   #--------------------------------------------------------------------------
  249.   alias include_bubs_gender_requirements include?
  250.   def include?(item)
  251.     return false unless @actor.gender_conditions_met?(item)
  252.     return include_bubs_gender_requirements(item) # alias
  253.   end
  254.  
  255. end # class Window_ClassList
  256.  
  257. end # if $imported["YEA-ClassSystem"]
  258.  
  259. end # if $imported["BubsGenderFunctions"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement