eugene222

Class Change Armor

Jul 22nd, 2014
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.37 KB | None | 0 0
  1. #===============================================================================
  2. # ***Class Change Equipment***
  3. #
  4. # Author:     Evgenij (eugene222)
  5. # Version:    1.2
  6. # Date:       11.07.2014
  7. # Requires:   ---
  8. #===============================================================================
  9. # Changelog:
  10. #
  11. #   11.07.2014 - V. 1.0 - script created
  12. #   16.09.2014 - V. 1.1 - added armors
  13. #   16.09.2014 - V. 1.2 - fixed some bugs, changed how script works
  14. #
  15. #===============================================================================
  16. # Terms of Use:
  17. #   You can use this script for free and commercial projects as long as you give
  18. #   credits.
  19. #===============================================================================
  20. # Description:
  21. #   With this Script you can define weapons or armors which will force a class change on
  22. #   equip. You need to take care, that the new class can carry the equip type
  23. #   or you will equip yourself with the item change the class and the item
  24. #   will be unequipped again, because the class cant handle the type.
  25. #  
  26. #   Weapon Notetag:
  27. #   <classchange: class_id>
  28. #
  29. #   Armor Notetag:
  30. #   <classchange: class_id>
  31. #
  32. #===============================================================================
  33. module EVG
  34.   module EquipClassChange
  35.     #---------------------------------------------------------------------------
  36.     # Keep EXP on Class Change?
  37.     #---------------------------------------------------------------------------
  38.     KEEP_EXP = true
  39.  
  40.     #---------------------------------------------------------------------------
  41.     # Should the actor recover when he changes to a new class?
  42.     #---------------------------------------------------------------------------
  43.     HEAL_ON_CLASS_CHANGE = false
  44.     #---------------------------------------------------------------------------
  45.     # Define the slot which will have class change items
  46.     # 0 = Righthand
  47.     # 1 = Lefthand / Shield
  48.     # 2 = Head
  49.     # 3 = Body
  50.     # 4 = Accessory
  51.     #---------------------------------------------------------------------------
  52.     CLASS_CHANGE_SLOT = 3
  53.  
  54.     #---------------------------------------------------------------------------   
  55.     # Change to this class if actor unequips a class item
  56.     #---------------------------------------------------------------------------
  57.     DEFAULT_CLASS_ID = 1
  58.  
  59.     #---------------------------------------------------------------------------
  60.   end
  61. end
  62. #===============================================================================
  63. class << DataManager
  64.   #---------------------------------------------------------------------------
  65.   alias :evg_dm_ld_wc     :load_database
  66.   #---------------------------------------------------------------------------
  67.   def load_database
  68.     evg_dm_ld_wc
  69.     $data_weapons.compact.each(&:load_wc_notetags)
  70.     $data_armors.compact.each(&:load_wc_notetags)
  71.   end
  72.   #---------------------------------------------------------------------------
  73. end
  74. #===============================================================================
  75. class RPG::EquipItem
  76.   #---------------------------------------------------------------------------
  77.   def load_wc_notetags
  78.     @class_change_item = false
  79.     @class_change_id     = 0
  80.     info = /<classchange:\s*(?<id>\d+)\s*>/i.match(@note)
  81.     return unless info
  82.     @class_change_item = true
  83.     @class_change_id = info[:id].to_i
  84.   end
  85.   #---------------------------------------------------------------------------
  86.   def class_change_item?
  87.     return @class_change_item
  88.   end
  89.   #---------------------------------------------------------------------------
  90.   def class_change_id
  91.     return @class_change_id
  92.   end
  93.   #---------------------------------------------------------------------------
  94. end
  95. #===============================================================================
  96. class Game_Actor
  97.   #---------------------------------------------------------------------------
  98.   alias :evg_ga_ce_wc               :change_equip
  99.   #---------------------------------------------------------------------------
  100.   def change_equip(slot_id, item)
  101.     evg_ga_ce_wc(slot_id, item)
  102.     process_class_change(item, slot_id)
  103.   end
  104.   #---------------------------------------------------------------------------
  105.   alias :evg_ga_fce_wc              :force_change_equip
  106.   #---------------------------------------------------------------------------
  107.   def force_change_equip(slot_id, item)
  108.     evg_ga_fce_wc(slot_id, item)
  109.     process_class_change(item, slot_id)
  110.   end
  111.   #---------------------------------------------------------------------------
  112.   def process_class_change(item, slot_id)
  113.     return if slot_id != EVG::EquipClassChange::CLASS_CHANGE_SLOT
  114.     if class_change_item?(item)
  115.       return if item.class_change_id == self.class_id
  116.       self.change_class(item.class_change_id, EVG::EquipClassChange::KEEP_EXP)
  117.     else
  118.       self.change_class(EVG::EquipClassChange::DEFAULT_CLASS_ID, EVG::EquipClassChange::KEEP_EXP)
  119.     end
  120.     recover_all if EVG::EquipClassChange::HEAL_ON_CLASS_CHANGE
  121.   end
  122.   #---------------------------------------------------------------------------
  123.   def class_change_item?(item)
  124.     return false if item.nil?
  125.     return item.class_change_item?
  126.   end
  127.   #---------------------------------------------------------------------------
  128. end
  129. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment