IceDragon200

IEX - TraitSystem

Jul 24th, 2011
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 16.18 KB | None | 0 0
  1. #==============================================================================#
  2. # ** IEX(Icy Engine Xelion) - Trait System
  3. #------------------------------------------------------------------------------#
  4. # ** Created by    : IceDragon (http://www.rpgmakervx.net/)
  5. # ** Script-Status : Addon (Actors)
  6. # ** Script Type   : State Modifier
  7. # ** Date Created  : 11/??/2010 (DD/MM/YYYY)
  8. # ** Date Modified : 01/08/2011 (DD/MM/YYYY)
  9. # ** Script Tag    : IEX - Traits System
  10. # ** Difficulty    : Hard, Lunatic
  11. # ** Version       : 1.0a
  12. #------------------------------------------------------------------------------#
  13. #==============================================================================#
  14. # ** INTRODUCTION
  15. #------------------------------------------------------------------------------#
  16. # This was a very old idea I had when using GTBS, but due to some problems
  17. # I lost it.
  18. # What this script does is allows states to be applied temporarily to an actor
  19. # using custom conditions.
  20. # If you have the IEX - Emblem System, or BEM Passives and your wondering whats
  21. # the difference between all of them.
  22. # Passives - Are always active, the player chooses which passives to use.
  23. # Traits   - Uses a condition in order to be active, they are PRESET
  24. #            They become inactive wheb the condition isn't met.
  25. # Emblems  - Uses a condition in order to activate it self, once activated
  26. #            it stays on PERMANENTLY, unless negated.
  27. # All of these use states.
  28. #
  29. #------------------------------------------------------------------------------#
  30. #==============================================================================#
  31. # ** HOW TO USE
  32. #------------------------------------------------------------------------------#
  33. # V1.0 - Notetags - States
  34. #------------------------------------------------------------------------------#
  35. # <trt id: eid>
  36. #  Not really used, and isn't neccessary.
  37. #
  38. # <trt condition: phrase>
  39. #  This is the name of the traits condition. Replace phrase
  40. #  You can stack as many conditions as you like
  41. #
  42. # <trt states: id, id, id>
  43. #  In addition to itself, the trait, you can have as many other states, but note
  44. #  If the state is already applied the new ones will be ignored.
  45. #
  46. # <trt noself>
  47. #  The trait will not be included with states
  48. #
  49. # <trt description> </trt description>
  50. #  Everything between these tags will go towards the traits description
  51. #  Currently not used.
  52. #
  53. #------------------------------------------------------------------------------#
  54. #==============================================================================#
  55. # ** COMPATABLITIES
  56. #------------------------------------------------------------------------------#
  57. #
  58. # BEM, Yggdrasil, Probably Takentai not sure about GTBS
  59. #
  60. #------------------------------------------------------------------------------#
  61. #==============================================================================#
  62. # ** INSTALLATION
  63. #------------------------------------------------------------------------------#
  64. #
  65. # Below
  66. #  Materials
  67. #
  68. # Above
  69. #   Main
  70. #
  71. #------------------------------------------------------------------------------#
  72. #==============================================================================#
  73. # ** CHANGES
  74. #------------------------------------------------------------------------------#
  75. # Classes
  76. #   RPG::State
  77. #     new-method :iex_trt_cache
  78. #     new-method :trt_states
  79. #     new-method :trt_id
  80. #     new-method :trt_condition
  81. #     new-method :trt_description
  82. #   RPG::Enemy
  83. #     new-method :iex_trt_en_cache
  84. #     new-method :atraits
  85. #   Game_Battler
  86. #     alias      :initialize
  87. #     alias      :states
  88. #     new-method :iex_trait_check_condition
  89. #     new-method :atraits
  90. #     new-method :active_atraits
  91. #     new-method :atrait_states
  92. #   Game_Enemy
  93. #     alias      :initialize
  94. #   Game_Actor
  95. #     alias      :setup
  96. #     new-method :class_traits
  97. #     new-method :emblems
  98. #     new-method :emblem_states
  99. #     new-method :check_emblem_conditions
  100. #   Scene_Title
  101. #     alias      :load_database
  102. #     new-method :load_trait_database
  103. #
  104. #------------------------------------------------------------------------------#
  105. #==============================================================================#
  106. # ** CHANGE LOG
  107. #------------------------------------------------------------------------------#
  108. # (DD/MM/YYYY)
  109. #  11/??/2010 - V1.0  Finished Script
  110. #  01/08/2011 - V1.0a Small Changes
  111. #
  112. #------------------------------------------------------------------------------#
  113. #==============================================================================#
  114. # ** KNOWN ISSUES
  115. #------------------------------------------------------------------------------#
  116. #  Non at the moment.
  117. #
  118. #------------------------------------------------------------------------------#
  119. $imported = {} if $imported == nil
  120. $imported["IEX_TraitsSystem"] = true
  121.  
  122. #==============================================================================
  123. # ** IEX::TRAITS_SYSTEM
  124. #------------------------------------------------------------------------------
  125. #==============================================================================
  126. module IEX
  127.   module TRAITS_SYSTEM
  128. #==============================================================================
  129. #                           Start Primary Customization
  130. #------------------------------------------------------------------------------
  131. #==============================================================================    
  132.   #--------------------------------------------------------------------------#
  133.   # * ACTOR_TRAITS
  134.   #--------------------------------------------------------------------------#
  135.   # actor_id => [state_id, state_id, state_id],
  136.   #--------------------------------------------------------------------------#
  137.     ACTOR_TRAITS = {
  138.       0 => [],
  139.       1 => [121, 124],
  140.       2 => [123, 130],
  141.       3 => [120, 125],
  142.       4 => [127, 128],
  143.       5 => [126, 135],
  144.       6 => [122, 133],
  145.       7 => [129, 132],
  146.       8 => [131, 134],
  147.     } # Do Not Remove
  148.   #--------------------------------------------------------------------------#
  149.   # * CLASS_TRAITS
  150.   #--------------------------------------------------------------------------#
  151.   # class_id => [state_id, state_id, state_id],
  152.   #--------------------------------------------------------------------------#    
  153.     CLASS_TRAITS = {    
  154.       0 => [],
  155.     }
  156. #==============================================================================
  157. #                           End Primary Customization
  158. #------------------------------------------------------------------------------
  159. #==============================================================================    
  160.   end
  161. end
  162.  
  163. #==============================================================================
  164. # ** Game_Battler - Lunatic
  165. #------------------------------------------------------------------------------
  166. #==============================================================================
  167. class Game_Battler
  168.  
  169.   def iex_trait_check_condition(cond_name)
  170.     active = false
  171.     case cond_name.to_s.upcase
  172.     when "ALWAYS_TRUE", "ALWAYSTRUE", "ALWAYS TRUE"
  173.       active = true
  174.     when "ALWAYS_FALSE", "ALWAYSFALSE", "ALWAYS FALSE"  
  175.       active = false
  176.     when /(?:PARTYWORTHX|PARTY_WORTHX|PARTY WORTHX):?[ ]*(\d+)/i
  177.       wor = 0
  178.       for mem in $game_party.members
  179.         wor += mem.level * $1.to_i
  180.       end  
  181.       active = $game_party.gold > wor.to_i  
  182.     when /(\w+):?[ ]*(\d+)([%%])/i  
  183.       val = $2.to_i
  184.       case $1.to_s.upcase
  185.       when "HP"
  186.         active = (@hp > 0) && (@hp <= IEX::IMath.cal_percent(val, maxhp))
  187.       when "MP"  
  188.         active = @mp <= IEX::MATH.cal_percent(val, maxmp)
  189.       end  
  190.     when "DAWN"
  191.       active = $game_switches[ICY::ITS::DAWN_SWITCH]
  192.     when "DAY"  
  193.       active = $game_switches[ICY::ITS::DAY_SWITCH]
  194.     when "DUSK"  
  195.       active = $game_switches[ICY::ITS::DUSK_SWITCH]
  196.     when "NIGHT"  
  197.       active = $game_switches[ICY::ITS::NIGHT_SWITCH]
  198.     end  
  199.     return active
  200.   end
  201.  
  202. end
  203.  
  204. #==============================================================================
  205. # ** IEX
  206. #------------------------------------------------------------------------------
  207. #==============================================================================
  208. module IEX
  209.   #==============================================================================
  210.   # ** IMath
  211.   #------------------------------------------------------------------------------
  212.   #==============================================================================
  213.   module IMath
  214.    
  215.     def self.cal_percent(perc, val)
  216.       ans = val.to_i
  217.       ans *= 100.0
  218.       ans = ans * (perc.to_i / 100.0)
  219.       ans /= 100.0
  220.       return Integer(ans)
  221.     end  
  222.    
  223.   end
  224.   #==============================================================================
  225.   # ** TRAITS_SYSTEM
  226.   #------------------------------------------------------------------------------
  227.   #==============================================================================
  228.   module TRAITS_SYSTEM
  229.     # Credit to Yanfly for the range to array method
  230.     module_function
  231.     #--------------------------------------------------------------------------
  232.     # convert_integer_array
  233.     #--------------------------------------------------------------------------
  234.     def convert_integer_array(array)
  235.       result = []
  236.       array.each { |i|
  237.         case i
  238.         when Range; result |= i.to_a
  239.         when Integer; result |= [i]
  240.         end }
  241.       return result
  242.     end
  243.  
  244.     #--------------------------------------------------------------------------
  245.     # converted_contants
  246.     #--------------------------------------------------------------------------
  247.     for key in ACTOR_TRAITS.keys
  248.       ACTOR_TRAITS[key] = convert_integer_array(ACTOR_TRAITS[key])
  249.     end
  250.    
  251.     for key in CLASS_TRAITS.keys
  252.       CLASS_TRAITS[key] = convert_integer_array(CLASS_TRAITS[key])
  253.     end
  254.    
  255.   end  
  256. end
  257.  
  258. #==============================================================================
  259. # ** RPG::State
  260. #------------------------------------------------------------------------------
  261. #==============================================================================
  262. class RPG::State
  263.    
  264.   def iex_trt_cache
  265.     @trt_cache_complete = false
  266.     @trt_states = []
  267.     @trt_id = 0
  268.     @trt_conditions = []
  269.     @trt_description = ''
  270.     trt_des_on = false
  271.     self.note.split(/[\r\n]+/).each { |line|
  272.     case line
  273.     when /<(?:TRAIT_|trait |TRT_|trt )(?:STATE)s?:[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  274.       $1.scan(/\d+/).each { |sid|
  275.       @trt_states.push(sid.to_i) }
  276.     when /<(?:TRAIT_ID|trait id|TRT_ID|trt id):[ ]*(\d+)>/i
  277.       @trt_id = $1.to_i
  278.     when /<(?:TRT_|TRAIT_|trt |trait )(?:CONDITION|cond):[ ]*(.*)>/i
  279.       @trt_conditions << $1.to_s  
  280.     when /<(?:TRT_|TRAIT_|trt |trait )(?:DESCRIPTION|des)>/i
  281.       trt_des_on = true
  282.     when /<\/(?:TRT_|TRAIT_|trt |trait )(?:DESCRIPTION|des)>/i
  283.       trt_des_on = false
  284.     else
  285.       @trt_description += line.to_s if trt_des_on
  286.     end  }
  287.     @trt_conditions << "AlwaysTrue" if @trt_conditions.empty?
  288.     @trt_cache_complete = true
  289.     trt_des_on = false
  290.   end
  291.  
  292.   def trt_states
  293.     iex_trt_cache unless @trt_cache_complete
  294.     return @trt_states
  295.   end
  296.  
  297.   def trt_id
  298.     iex_trt_cache unless @trt_cache_complete
  299.     return @trt_id
  300.   end
  301.  
  302.   def trt_conditions
  303.     iex_trt_cache unless @trt_cache_complete
  304.     return @trt_conditions
  305.   end
  306.  
  307.   def trt_description
  308.     iex_trt_cache unless @trt_cache_complete
  309.     return @trt_description
  310.   end
  311.  
  312. end
  313.  
  314. #==============================================================================
  315. # ** RPG::Enemy
  316. #------------------------------------------------------------------------------
  317. #==============================================================================
  318. class RPG::Enemy
  319.  
  320.   def iex_trt_en_cache
  321.     @trt_trait_ids = []
  322.     @trt_trait_cache_complete = false
  323.     self.note.split(/[\r\n]+/).each { |line|
  324.     case line
  325.     when /<(?:TRAIT_ID|trait id|TRT_ID|trt id)s?:[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  326.       $1.scan(/\d+/).each { |sid|
  327.       @trt_trait_ids.push(sid.to_i) }
  328.     end
  329.     }
  330.     @trt_trait_cache_complete = true
  331.   end
  332.  
  333.   def atraits
  334.     iex_trt_en_cache unless @trt_trait_cache_complete
  335.     return @trt_trait_ids
  336.   end
  337.  
  338. end
  339.  
  340. #==============================================================================
  341. # ** Scene_Title
  342. #------------------------------------------------------------------------------
  343. #==============================================================================
  344. class Scene_Title < Scene_Base
  345.  
  346.   #--------------------------------------------------------------------------#
  347.   # * alias load_database
  348.   #--------------------------------------------------------------------------#
  349.   alias iex_trt_load_database load_database unless $@
  350.   def load_database
  351.     iex_trt_load_database
  352.     load_trait_database
  353.   end
  354.  
  355.   #--------------------------------------------------------------------------#
  356.   # * load_trait_database
  357.   #--------------------------------------------------------------------------#
  358.   # This loads all the trait caches so it doesn't have to during runtime
  359.   #--------------------------------------------------------------------------#
  360.   def load_trait_database
  361.     for st in $data_states
  362.       next if st == nil
  363.       st.iex_trt_cache
  364.     end
  365.     for en in $data_enemies
  366.       next if en == nil
  367.       en.iex_trt_en_cache
  368.     end
  369.   end
  370.  
  371. end
  372. #==============================================================================
  373. # ** Game_Battler
  374. #------------------------------------------------------------------------------
  375. #==============================================================================
  376. class Game_Battler
  377.  
  378.   alias iex_trat_initialize initialize unless $@
  379.   def initialize
  380.     iex_trat_initialize
  381.     @current_trait_checking = false
  382.   end
  383.  
  384.   def class_traits
  385.     return []
  386.   end
  387.  
  388.   def atraits
  389.     tra_lst = []
  390.     @ttrait_ids = [] if @ttrait_ids == nil
  391.     for sid in @ttrait_ids + class_traits
  392.       sta = $data_states[sid]
  393.       next if sta == nil
  394.       tra_lst(sta)
  395.     end
  396.     return tra_lst
  397.   end
  398.  
  399.   def active_atraits
  400.     @current_trait_checking = true
  401.     tra_lst = []
  402.     @ttrait_ids = [] if @ttrait_ids == nil
  403.     for sid in @ttrait_ids
  404.       sta = $data_states[sid]
  405.       next if sta == nil
  406.       failed = false
  407.       sta.trt_conditions.each { |cond|
  408.         failed = false
  409.         unless iex_trait_check_condition(cond)
  410.           failed = true
  411.           break
  412.         end
  413.       }
  414.       tra_lst.push(sta) unless failed
  415.     end
  416.     @current_trait_checking = false
  417.     return tra_lst
  418.   end
  419.  
  420.   def atrait_states
  421.     return active_atraits
  422.   end
  423.  
  424.   alias iex_trait_sstates states unless $@
  425.   def states
  426.     result = iex_trait_sstates
  427.     result |= atrait_states unless @current_trait_checking
  428.     return result
  429.   end
  430.  
  431. end
  432.  
  433. #==============================================================================
  434. # ** Game_Enemy
  435. #------------------------------------------------------------------------------
  436. #==============================================================================
  437. class Game_Enemy < Game_Battler
  438.  
  439.   alias iex_traits_initialize initialize unless $@
  440.   def initialize(*args)
  441.     @ttrait_ids = []
  442.     iex_traits_initialize(*args)
  443.     @ttrait_ids = enemy.atraits
  444.   end
  445.  
  446. end
  447.  
  448. #==============================================================================
  449. # ** Game_Actor
  450. #------------------------------------------------------------------------------
  451. #==============================================================================
  452. class Game_Actor < Game_Battler
  453.  
  454.   alias iex_traits_setup setup unless $@
  455.   def setup(*args)
  456.     @ttrait_ids = []
  457.     iex_traits_setup(*args)
  458.     if IEX::TRAITS_SYSTEM::ACTOR_TRAITS.has_key?(@actor_id)
  459.       @ttrait_ids = IEX::TRAITS_SYSTEM::ACTOR_TRAITS[@actor_id].clone
  460.     else  
  461.       @ttrait_ids = IEX::TRAITS_SYSTEM::ACTOR_TRAITS[0].clone
  462.     end
  463.   end
  464.  
  465.   def class_traits
  466.     if IEX::TRAITS_SYSTEM::CLASS_TRAITS.has_key?(@class_id)
  467.       return IEX::TRAITS_SYSTEM::CLASS_TRAITS[@class_id].clone
  468.     else  
  469.       return IEX::TRAITS_SYSTEM::CLASS_TRAITS[0].clone
  470.     end
  471.   end
  472.  
  473. end
Advertisement
Add Comment
Please, Sign In to add comment