Advertisement
Demintika

RPGM VX Ace - DMTK Linked Skill

Jun 10th, 2014
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.40 KB | None | 0 0
  1. #==============================================================================
  2. # *
  3. #==============================================================================
  4. =begin
  5.   Note tag:
  6.   Equipment Notetag: <linked_skill: t x>
  7.   - t: type: s for skill
  8.              i for item
  9.   - x: id: skill or item id
  10.   AN EQUIPMENT CAN ONLY LINK TO 1 SKILL / ITEM
  11.   A SKILL / ITEM CAN ONLY BE LINKED BY 1 EQUIPMENT
  12. =end
  13. #==============================================================================
  14. # * Config
  15. #==============================================================================
  16. module DMTK
  17.   module LINKED_SKILL
  18.   #--------------------------------------------------------------------------
  19.   # * Check skill's cost / requirement
  20.   #--------------------------------------------------------------------------
  21.     CHECK_CONDITION = false
  22.   #--------------------------------------------------------------------------
  23.   # * Ignore skill cost
  24.   #--------------------------------------------------------------------------
  25.     IGNORE_COST = false
  26.   #--------------------------------------------------------------------------
  27.   # * Include equip - Trust me, don't use it.
  28.   #--------------------------------------------------------------------------
  29.     INCLUDE_EQUIP = false
  30.   end
  31. end
  32.  
  33. #==============================================================================
  34. # For formal use
  35. #==============================================================================
  36. $imported = {} if $imported.nil?
  37. $imported["DMTK - Linked Skill"] = true
  38. #==============================================================================
  39. # *
  40. #==============================================================================
  41. module DataManager
  42.  
  43.   #--------------------------------------------------------------------------
  44.   # *
  45.   #--------------------------------------------------------------------------
  46.   class << self
  47.     alias dmtk_load_database_ls load_database
  48.   end
  49.  
  50.   #--------------------------------------------------------------------------
  51.   # *
  52.   #--------------------------------------------------------------------------
  53.   def self.load_database
  54.     dmtk_load_database_ls
  55.     dmtk_load_notetag_ls
  56.   end
  57.  
  58.   #--------------------------------------------------------------------------
  59.   # *
  60.   #--------------------------------------------------------------------------
  61.   def self.dmtk_load_notetag_ls
  62.     ($data_weapons + $data_armors).each {|obj|
  63.       next if obj.nil?
  64.       obj.dmtk_load_notetag_ls
  65.     }
  66.   end
  67. end
  68.  
  69. #==============================================================================
  70. # *
  71. #==============================================================================
  72. class RPG::UsableItem < RPG::BaseItem
  73.  
  74.   #--------------------------------------------------------------------------
  75.   # *
  76.   #--------------------------------------------------------------------------
  77.   attr_accessor :linked_equip
  78.   def linked?; !@linked_equip.nil?; end
  79.  
  80. end
  81.  
  82. #==============================================================================
  83. # *
  84. #==============================================================================
  85. class RPG::EquipItem < RPG::BaseItem
  86.  
  87.   #--------------------------------------------------------------------------
  88.   # *
  89.   #--------------------------------------------------------------------------
  90.   attr_reader :consumable
  91.  
  92.   #--------------------------------------------------------------------------
  93.   # *
  94.   #--------------------------------------------------------------------------
  95.   def linked?
  96.     !@linked_skill.nil?
  97.   end
  98.  
  99.   #--------------------------------------------------------------------------
  100.   # *
  101.   #--------------------------------------------------------------------------
  102.   def linked_skill
  103.     return nil unless linked?
  104.     ls = @linked_skill.to_s
  105.     case ls[0]
  106.     when /i/i
  107.       return $data_items[ls[/\d+/].to_i]
  108.     when /s/i
  109.       return $data_skills[ls[/\d+/].to_i]
  110.     end
  111.   end
  112.  
  113.   #--------------------------------------------------------------------------
  114.   # *
  115.   #--------------------------------------------------------------------------
  116.   def dmtk_load_notetag_ls
  117.     self.note.split(/[\r\n]+/).each { |line|
  118.       case line
  119.       when /<consumable>/i
  120.         @consumable = true
  121.       when /<linked[ _]skill:[ ]*(.[ ]*\d+)>/i
  122.         ls = $1
  123.         case ls[0]
  124.         when /i/i
  125.           if itm = $data_items[ls[/\d+/].to_i] && !itm.linked?
  126.             itm.linked_equip = self
  127.             @linked_skill = ls.to_sym
  128.           end
  129.         when /s/i
  130.           if itm = $data_skills[ls[/\d+/].to_i] && !itm.linked?
  131.             itm.linked_equip = self
  132.             @linked_skill = ls.to_sym
  133.           end
  134.         end
  135.       end
  136.     }
  137.   end
  138. end
  139.  
  140. #==============================================================================
  141. # *
  142. #==============================================================================
  143. class Game_BattlerBase
  144.  
  145.   #--------------------------------------------------------------------------
  146.   # * Determine Skill/Item Usability
  147.   #--------------------------------------------------------------------------
  148.   alias dmtk_linked_usable? usable?
  149.   def usable?(item)
  150.     if item.is_a?(RPG::EquipItem) && item.linked?
  151.       return dmtk_linked_usable?(item.linked_skill) if DMTK::LINKED_SKILL::CHECK_CONDITION
  152.       return usable_item_conditions_met?(item.linked_skill)
  153.     else
  154.       dmtk_linked_usable?(item)
  155.     end
  156.   end
  157.  
  158.   #--------------------------------------------------------------------------
  159.   # * Check Usability Conditions for Item
  160.   #--------------------------------------------------------------------------
  161.   alias dmtk_linked_condition? item_conditions_met?
  162.   def item_conditions_met?(item)
  163.     return true if dmtk_linked_condition?(item)
  164.     return false unless item.linked?
  165.     return false unless usable_item_conditions_met?(item)
  166.     include_equip = DMTK::LINKED_SKILL::INCLUDE_EQUIP
  167.     return $game_party.has_item?(item.linked_equip, include_equip)
  168.   end
  169.  
  170.   #--------------------------------------------------------------------------
  171.   # * Pay Cost of Using Skill
  172.   #--------------------------------------------------------------------------
  173.   alias dmtk_linked_cost pay_skill_cost
  174.   def pay_skill_cost(skill)
  175.     include_equip = DMTK::LINKED_SKILL::INCLUDE_EQUIP
  176.     if skill.linked? && $game_party.has_item?(skill.linked_equip, include_equip)
  177.       dmtk_linked_cost(skill) unless DMTK::LINKED_SKILL::IGNORE_COST
  178.       $game_party.lose_item(skill.linked_equip, 1, include_equip) if skill.linked_equip.consumable
  179.     else
  180.       dmtk_linked_cost(skill)
  181.     end
  182.   end
  183. end
  184.  
  185. #==============================================================================
  186. # *
  187. #==============================================================================
  188. class Window_ItemList < Window_Selectable
  189.  
  190.   #--------------------------------------------------------------------------
  191.   # * Get Item
  192.   #--------------------------------------------------------------------------
  193.   alias dmtk_linked_item item
  194.   def item
  195.     itm = dmtk_linked_item
  196.     return itm unless itm.is_a?(RPG::EquipItem) && itm.linked?
  197.     return itm.linked_skill
  198.   end
  199. end
  200.  
  201. #==============================================================================
  202. # *
  203. #==============================================================================
  204. class Game_Party < Game_Unit
  205.  
  206.   #--------------------------------------------------------------------------
  207.   # * Consume Items
  208.   #    If the specified object is a consumable item, the number in investory
  209.   #    will be reduced by 1.
  210.   #--------------------------------------------------------------------------
  211.   alias dmtk_linked_consume_item consume_item
  212.   def consume_item(item)
  213.     if !has_item?(item) && item.is_a?(RPG::Item) && item.linked?
  214.       unless item.linked_equip.consumable
  215.         include_equip = DMTK::LINKED_SKILL::INCLUDE_EQUIP
  216.         lose_item(item.linked_equip, 1, include_equip)
  217.       end
  218.     else
  219.       dmtk_linked_consume_item(item)
  220.     end
  221.   end
  222. end
  223.  
  224. #==============================================================================
  225. # * item.consumable
  226. #==============================================================================
  227. class Scene_ItemBase < Scene_MenuBase
  228.  
  229.   #--------------------------------------------------------------------------
  230.   # * Get Currently Selected Item
  231.   #--------------------------------------------------------------------------
  232.   alias dmtk_linked_item item
  233.   def item
  234.     itm = dmtk_linked_item
  235.     return itm unless itm.is_a?(RPG::EquipItem) && itm.linked?
  236.     return itm.linked_skill
  237.   end
  238. end
  239.  
  240. #==============================================================================
  241. # *
  242. #==============================================================================
  243. class Scene_Battle < Scene_Base
  244.  
  245.   #--------------------------------------------------------------------------
  246.   # * Item [OK]
  247.   #--------------------------------------------------------------------------
  248.   alias on_linked_item_ok on_item_ok
  249.   def on_item_ok
  250.     on_linked_item_ok
  251.     @item = @item_window.item
  252.     if @item.linked?
  253.       BattleManager.actor.input.set_skill(@item.id) if @item.is_a?(RPG::Skill)
  254.       $game_party.last_item.object = @item.linked_equip
  255.     end
  256.   end
  257. end
  258.  
  259. #==============================================================================
  260. # * END
  261. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement