Advertisement
ezmash

Dynamic Features (VX Ace)

Nov 4th, 2013
1,583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.85 KB | None | 0 0
  1. #============================================================================
  2. # DYNAMIC FEATURES
  3. # v1.00 by Shaz
  4. #----------------------------------------------------------------------------
  5. # This script allows you to add and delete features for Actors, Classes,
  6. # Weapons, Armors and States, dynamically, without requiring custom states
  7. # set up for the sole purpose of granting or changing features.
  8. # Skills and Items also have features due to inheritance, but they're not
  9. # used by Ace, so while the script will allow you to set them up, there's
  10. # really not much of a point in doing it.
  11. #----------------------------------------------------------------------------
  12. # To Install:
  13. # Copy and paste into a new slot in materials, below all other scripts
  14. #----------------------------------------------------------------------------
  15. # To Use:
  16. # Enter one of the following as a Call Script event command
  17. #
  18. # add_feature(class, id, feature_code, data_id[, value])
  19. # remove_feature(class, id, feature_code, data_id[, value])
  20. # get_feature(class, id, feature_code, data_id)
  21. #
  22. # Parameters:
  23. # class - this is a symbol, and should be one of :actor, :class, :skill, :item,
  24. #         :weapon, :armor, :state
  25. # id    - this is the id of the object you want to change (an actor id, or a
  26. #         weapon id, for example)
  27. # feature_code - this is a code to indicate what feature to change.  It is a
  28. #                symbol, and should be one of :element_rate, :debuff_rate,
  29. #                :state_rate, :state_resist, :param, :xparam, :sparam,
  30. #                :atk_element, :atk_state, :atk_speed, :atk_times, :stype_add,
  31. #                :stype_seal, :skill_add, :skill_seal, :equip_wtype,
  32. #                :equip_atype, :equip_fix, :equip_seal, :slot_type,
  33. #                :action_plus, :special_flag, :collapse_type, :party_ability
  34. # data_id - this id refers to the drop-down list when adding features.  When
  35. #           adjusting something represented in the database (actors, weapons,
  36. #           etc, including elements and types in the Terms tab), it is the id
  37. #           of that item.  When it is not something in the database (like the
  38. #           selections on the Other tab in features), it is the number of the
  39. #           item in the drop-down list, starting at 0 for the top item (so the
  40. #           Party Ability for Gold Double has a data id of 4)
  41. # value - this is only necessary for features where you set a numeric value.
  42. #         Percentages should be sent as a decimal (so 75% is 0.75, not 75).
  43. #         This is optional for the remove_feature call, and when left out, ANY
  44. #         features for that code and data id will be removed.
  45. #
  46. # get_feature will return nil if a value is not found for that feature.
  47. #----------------------------------------------------------------------------
  48. # Terms:
  49. # Use in free and commercial games
  50. # Credit Shaz
  51. #============================================================================
  52.  
  53. module DataManager
  54.   class << self;
  55.     alias shaz_dynamic_features_create_game_objects create_game_objects
  56.     alias shaz_dynamic_features_make_save_contents make_save_contents
  57.     alias shaz_dynamic_features_extract_save_contents extract_save_contents
  58.   end
  59.   #--------------------------------------------------------------------------
  60.   # * Create Game Objects
  61.   #--------------------------------------------------------------------------
  62.   def self.create_game_objects
  63.     shaz_dynamic_features_create_game_objects
  64.     $game_features      = {}
  65.   end
  66.   #--------------------------------------------------------------------------
  67.   # * Create Save Contents
  68.   #--------------------------------------------------------------------------
  69.   def self.make_save_contents
  70.     contents = shaz_dynamic_features_make_save_contents
  71.     contents[:features]      = $game_features ? $game_features : {}
  72.     contents
  73.   end
  74.   #--------------------------------------------------------------------------
  75.   # * Extract Save Contents
  76.   #--------------------------------------------------------------------------
  77.   def self.extract_save_contents(contents)
  78.     shaz_dynamic_features_extract_save_contents(contents)
  79.     $game_features      = contents[:features] ? contents[:features] : {}
  80.   end
  81. end
  82.  
  83. class RPG::BaseItem
  84.   @@feature_code = {
  85.     :element_rate  => 11,              # Element Rate
  86.     :debuff_rate   => 12,              # Debuff Rate
  87.     :state_rate    => 13,              # State Rate
  88.     :state_resist  => 14,              # State Resist
  89.     :param         => 21,              # Parameter
  90.     :xparam        => 22,              # Ex-Parameter
  91.     :sparam        => 23,              # Sp-Parameter
  92.     :atk_element   => 31,              # Atk Element
  93.     :atk_state     => 32,              # Atk State
  94.     :atk_speed     => 33,              # Atk Speed
  95.     :atk_times     => 34,              # Atk Times+
  96.     :stype_add     => 41,              # Add Skill Type
  97.     :stype_seal    => 42,              # Disable Skill Type
  98.     :skill_add     => 43,              # Add Skill
  99.     :skill_seal    => 44,              # Disable Skill
  100.     :equip_wtype   => 51,              # Equip Weapon
  101.     :equip_atype   => 52,              # Equip Armor
  102.     :equip_fix     => 53,              # Lock Equip
  103.     :equip_seal    => 54,              # Seal Equip
  104.     :slot_type     => 55,              # Slot Type
  105.     :action_plus   => 61,              # Action Times+
  106.     :special_flag  => 62,              # Special Flag
  107.     :collapse_type => 63,              # Collapse Effect
  108.     :party_ability => 64,              # Party Ability
  109.   }
  110.  
  111.   def features
  112.     if $game_features && $game_features[class_symbol] &&
  113.         $game_features[class_symbol][@id]
  114.       $game_features[class_symbol][@id]
  115.     else
  116.       @features
  117.     end
  118.   end
  119.  
  120.   def clone_features
  121.     $game_features = {} if !$game_features
  122.     $game_features[class_symbol] = {} if !$game_features[class_symbol]
  123.     $game_features[class_symbol][@id] = @features.dup if
  124.       !$game_features[class_symbol][@id]
  125.   end
  126.  
  127.   def add_feature(code, data_id, value)
  128.     clone_features
  129.     $game_features[class_symbol][@id].push(RPG::BaseItem::Feature.new(
  130.       @@feature_code[code], data_id, value))
  131.   end
  132.  
  133.   def remove_feature(code, data_id, value)
  134.     clone_features
  135.     i = $game_features[class_symbol][@id].length - 1
  136.     while i >= 0
  137.       f = $game_features[class_symbol][@id][i]
  138.       $game_features[class_symbol][@id].delete_at(i) if
  139.         f.code == @@feature_code[code] && f.data_id == data_id &&
  140.           (f.value == value || value.nil?)
  141.       i -= 1
  142.     end
  143.   end
  144.  
  145.   def get_feature(code, data_id)
  146.     features.each { |feature|
  147.       return feature.value if feature.code == @@feature_code[code] &&
  148.         feature.data_id == data_id
  149.     }
  150.     return nil
  151.   end
  152.  
  153.   def class_symbol
  154.     case self.class.to_s
  155.       when /Actor/i;  :actor
  156.       when /Class/i;  :class
  157.       when /Skill/i;  :skill
  158.       when /Item/i;   :item
  159.       when /Weapon/i; :weapon
  160.       when /Armor/i;  :armor
  161.       when /State/i;  :state
  162.     end
  163.   end
  164. end
  165.  
  166. class Game_Interpreter
  167.   def get_class_object(cls, id)
  168.     obj = nil
  169.     case cls
  170.       when :actor;  obj = $data_actors[id]
  171.       when :class;  obj = $data_classes[id]
  172.       when :skill;  obj = $data_skills[id]
  173.       when :item;   obj = $data_items[id]
  174.       when :weapon; obj = $data_weapons[id]
  175.       when :armor;  obj = $data_armors[id]
  176.       when :state;  obj = $data_states[id]
  177.     end
  178.     obj
  179.   end
  180.    
  181.   def add_feature(cls, id, feature_code, data_id, value = 0)
  182.     get_class_object(cls, id).add_feature(feature_code, data_id, value)
  183.   end
  184.  
  185.   def remove_feature(cls, id, feature_code, data_id, value = nil)
  186.     get_class_object(cls, id).remove_feature(feature_code, data_id, value)
  187.   end
  188.  
  189.   def get_feature(cls, id, feature_code, data_id)
  190.     get_class_object(cls, id).get_feature(feature_code, data_id)
  191.   end
  192. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement