Advertisement
KhegayIV

[RGSS3] L'James Skill Traits

Oct 1st, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.23 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. #
  4. #                           L'James Skill Traits
  5. #
  6. #
  7. # Requires L'James Notetag System
  8. #==============================================================================
  9. #                                Description
  10. #==============================================================================
  11. # Script allows to assign special traits to skills and items and then choose
  12. # behaviour in reaction to them, namely:
  13. #
  14. # * Set damage rate recieved from skills/items with specified trait
  15. # * Set damage rate dealt by skills/items with specified trait
  16. # * Allow states to be removed in reaction to skills/items with specified
  17. #   traits, like FFX Nul-spells
  18. # * Restrict usage of skills/items with specified traits
  19. #
  20. #==============================================================================
  21. #                                Instruction
  22. #==============================================================================
  23. # Insert this script between L'J Notetag System and Main
  24. # Set list of traits
  25. module LJ
  26.   module SKILL_TRAITS
  27.     TRAITS = [
  28.       :physical,
  29.       :magical,
  30.       :fire,
  31.       :ice,
  32.       :lightning,
  33.       :heal,
  34.     ]    
  35.   end
  36. end
  37. # Use notetags to change game behaviour
  38. #
  39. # Note:
  40. # some tags have multiple versions that can be written like
  41. #     <tag arg1, arg2, arg3>
  42. # or
  43. #     <tag>
  44. #       arg1
  45. #       arg2
  46. #       arg3
  47. #     </tag>
  48. #
  49. #------------------------------------------------------------------------------
  50. #                         Skill and Item notetags  
  51. #------------------------------------------------------------------------------
  52. # These notetags go in the skill or item notebox in the database.
  53. #
  54. # * <<x>> assigns trait x to skill/item. E.g. <<fire>>
  55. #
  56. # * <take x> assigns trait x to skill/item but only if user of this skill/item
  57. #     has feature <give x>. Also: <take x1, x2...>
  58. #
  59. # * <<take all>> same as <take x> but applied for all traits
  60. #
  61. #------------------------------------------------------------------------------
  62. #                             State notetags  
  63. #------------------------------------------------------------------------------
  64. # This notetag go in the state notebox in the database.
  65. #
  66. # * <removed by x> - state with this tag will be removed when skill/item with
  67. #     trait x is applied to character with this state. Also <removed by x1, x2>
  68. # * <added by x> - state with this tag will be added when skill/item with
  69. #     trait x is applied to character with this state. Also <added by x1, x2>
  70. #------------------------------------------------------------------------------
  71. #                             Feature notetags
  72. #------------------------------------------------------------------------------
  73. # These notetag go in the actor, class, equipment, enemy or state notebox in
  74. # the database. The behave like features of RPG Maker VXA
  75. #
  76. # * <give x> - assigns trait x to skills/items which take trait x.
  77.  
  78. # * <power x y%> - battler with this tag will deal y% damage when using
  79. #     skills/items with trait x. y may be negative. Also <power x1 y1%, x2 y2%>
  80. #
  81. # * <damage x y%> - battler with this tag will receive y% damage from
  82. #     skills/items with trait x. y may be negative. Also <damage x1 y1%, x2 y2%>
  83. #
  84. # * <ignore x> - battler with this tag will not be affected by skills/items
  85. #     with trait x. Different from <damage x 0%> in that battler also ignores
  86. #     state modifications, not only damage
  87. #
  88. # * <seal x> - battler can't use skills/items with trait x
  89. #==============================================================================
  90. #                                Terms of use
  91. #==============================================================================
  92. # Free to use in commercial and non-commercial projects as long as you give
  93. # credit to L'James
  94. #==============================================================================
  95. #                             Notetag editing
  96. #==============================================================================
  97. # Here you can rename notetags if you prefer other names or these names
  98. # are used in other scripts
  99. module LJ
  100.   module SKILL_TRAITS
  101.  
  102.     # Skills:
  103.     # Parameter that takes selected given traits
  104.     TAKE = :take
  105.     # Parameter that takes all possible given traits
  106.     TAKE_ALL = :take_all
  107.    
  108.  
  109.     # States:
  110.     # List of traits that remove this state
  111.     REMOVED_BY = :removed_by
  112.    
  113.     # List of traits that add this state
  114.     ADDED_BY = :added_by
  115.    
  116.    
  117.     # Features:
  118.     # List of traits that will be applied on skills/items with TAKE
  119.     GIVE = :give
  120.    
  121.     # Damage multiplier for attacker
  122.     POWER = :power
  123.    
  124.     # Damage multiplier for defender
  125.     DAMAGE = :damage
  126.    
  127.     # List of traits that will make skills/items have no effect
  128.     IGNORE = :ignore
  129.    
  130.     # List of traits that will make skills/items unusable
  131.     SEAL = :seal
  132.      
  133.   end
  134. end
  135. module LJ
  136.   module SKILL_TRAITS
  137.     LJ::NOTETAGS.extension do
  138.       # Here you can specify extension styling if you know how
  139.  
  140.      
  141. #==============================================================================
  142. #                  Don't touch unless you really want it
  143. #==============================================================================
  144.  
  145.       declare_usableitem do
  146.         TRAITS.each do |t|
  147.           register t, trait
  148.         end
  149.         register TAKE, array(:sym).set_limit(*TRAITS)
  150.         register TAKE_ALL, trait
  151.       end
  152.      
  153.       declare_state do
  154.         register REMOVED_BY, array(:sym).set_limit(*TRAITS)
  155.         register ADDED_BY, array(:sym).set_limit(*TRAITS)
  156.       end
  157.      
  158.       declare_features do
  159.         register GIVE, array(:sym).set_limit(*TRAITS)
  160.         register SEAL, array(:sym).set_limit(*TRAITS)
  161.         register IGNORE, array(:sym).set_limit(*TRAITS)
  162.         register POWER, hash(:percent).set_key_limit(*TRAITS)
  163.         register DAMAGE, hash(:percent).set_key_limit(*TRAITS)
  164.       end
  165.     end
  166.   end
  167. end
  168.  
  169. class RPG::UsableItem::Damage
  170.   attr_writer :multiplier
  171.  
  172.   alias eval_ljskilltraits eval
  173.   def eval(a,b,v)
  174.     @multiplier ||= 1
  175.     res = @multiplier*eval_ljskilltraits(a,b,v)
  176.     @multiplier = 1
  177.     res
  178.   end
  179. end
  180.  
  181. class RPG::UsableItem < RPG::BaseItem
  182.   def get_all_skill_traits(user)
  183.     res = LJ::SKILL_TRAITS::TRAITS.select {|tr| get_param(tr)}
  184.     if get_param(LJ::SKILL_TRAITS::TAKE_ALL)
  185.       res += user.get_feature(LJ::SKILL_TRAITS::GIVE)
  186.     else
  187.       res += user.get_feature(LJ::SKILL_TRAITS::GIVE) &
  188.         get_param(LJ::SKILL_TRAITS::TAKE)
  189.     end
  190.     res          
  191.   end
  192. end
  193.  
  194. class Game_Battler < Game_BattlerBase
  195.  
  196.   alias make_damage_value_ljskilltraits make_damage_value
  197.   def make_damage_value(user, item)
  198.     item.damage.multiplier = item.get_all_skill_traits(user).inject(1) do
  199.       |acc, tr|
  200.       acc * user.get_feature(LJ::SKILL_TRAITS::POWER)[tr]
  201.     end
  202.     make_damage_value_ljskilltraits(user, item)
  203.   end
  204.  
  205.   alias item_element_rate_ljskilltraits item_element_rate
  206.   def item_element_rate(user, item)
  207.     res = item_element_rate_ljskilltraits(user,item) *
  208.       item.get_all_skill_traits(user).inject(1) do
  209.         |acc, tr|
  210.         acc * get_feature(LJ::SKILL_TRAITS::DAMAGE)[tr]
  211.       end
  212.   end
  213.    
  214.   alias item_test_ljskilltraits item_test
  215.   def item_test(user, item)
  216.     return false unless (item.get_all_skill_traits(user) &
  217.       get_feature(LJ::SKILL_TRAITS::IGNORE)).empty?
  218.     item_test_ljskilltraits(user, item)
  219.   end
  220.  
  221.   alias item_apply_ljskilltraits item_apply
  222.   def item_apply(user, item)
  223.     item_apply_ljskilltraits(user, item)
  224.     if @result.hit?
  225.       traits = item.get_all_skill_traits(user)
  226.       states.each do
  227.         |state|
  228.         remove_state(state.id) unless
  229.           (state.get_param(LJ::SKILL_TRAITS::REMOVED_BY) & traits).empty?
  230.       end
  231.       $data_states.each do |state|
  232.         add_state(state.id) unless state.nil? ||
  233.           (state.get_param(LJ::SKILL_TRAITS::ADDED_BY) & traits).empty?
  234.      
  235.       end
  236.     end
  237.   end
  238.  
  239.   #overload
  240.   def usable?(item)
  241.     return false if item.is_a?(RPG::UsableItem) &&
  242.     !(item.get_all_skill_traits(self) &
  243.       get_feature(LJ::SKILL_TRAITS::SEAL)).empty?
  244.     super(item)
  245.   end
  246.  
  247. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement