Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # *
- #==============================================================================
- =begin
- Note tag:
- Equipment Notetag: <linked_skill: t x>
- - t: type: s for skill
- i for item
- - x: id: skill or item id
- AN EQUIPMENT CAN ONLY LINK TO 1 SKILL / ITEM
- A SKILL / ITEM CAN ONLY BE LINKED BY 1 EQUIPMENT
- =end
- #==============================================================================
- # * Config
- #==============================================================================
- module DMTK
- module LINKED_SKILL
- #--------------------------------------------------------------------------
- # * Check skill's cost / requirement
- #--------------------------------------------------------------------------
- CHECK_CONDITION = false
- #--------------------------------------------------------------------------
- # * Ignore skill cost
- #--------------------------------------------------------------------------
- IGNORE_COST = false
- #--------------------------------------------------------------------------
- # * Include equip - Trust me, don't use it.
- #--------------------------------------------------------------------------
- INCLUDE_EQUIP = false
- end
- end
- #==============================================================================
- # For formal use
- #==============================================================================
- $imported = {} if $imported.nil?
- $imported["DMTK - Linked Skill"] = true
- #==============================================================================
- # *
- #==============================================================================
- module DataManager
- #--------------------------------------------------------------------------
- # *
- #--------------------------------------------------------------------------
- class << self
- alias dmtk_load_database_ls load_database
- end
- #--------------------------------------------------------------------------
- # *
- #--------------------------------------------------------------------------
- def self.load_database
- dmtk_load_database_ls
- dmtk_load_notetag_ls
- end
- #--------------------------------------------------------------------------
- # *
- #--------------------------------------------------------------------------
- def self.dmtk_load_notetag_ls
- ($data_weapons + $data_armors).each {|obj|
- next if obj.nil?
- obj.dmtk_load_notetag_ls
- }
- end
- end
- #==============================================================================
- # *
- #==============================================================================
- class RPG::UsableItem < RPG::BaseItem
- #--------------------------------------------------------------------------
- # *
- #--------------------------------------------------------------------------
- attr_accessor :linked_equip
- def linked?; !@linked_equip.nil?; end
- end
- #==============================================================================
- # *
- #==============================================================================
- class RPG::EquipItem < RPG::BaseItem
- #--------------------------------------------------------------------------
- # *
- #--------------------------------------------------------------------------
- attr_reader :consumable
- #--------------------------------------------------------------------------
- # *
- #--------------------------------------------------------------------------
- def linked?
- !@linked_skill.nil?
- end
- #--------------------------------------------------------------------------
- # *
- #--------------------------------------------------------------------------
- def linked_skill
- return nil unless linked?
- ls = @linked_skill.to_s
- case ls[0]
- when /i/i
- return $data_items[ls[/\d+/].to_i]
- when /s/i
- return $data_skills[ls[/\d+/].to_i]
- end
- end
- #--------------------------------------------------------------------------
- # *
- #--------------------------------------------------------------------------
- def dmtk_load_notetag_ls
- self.note.split(/[\r\n]+/).each { |line|
- case line
- when /<consumable>/i
- @consumable = true
- when /<linked[ _]skill:[ ]*(.[ ]*\d+)>/i
- ls = $1
- case ls[0]
- when /i/i
- if itm = $data_items[ls[/\d+/].to_i] && !itm.linked?
- itm.linked_equip = self
- @linked_skill = ls.to_sym
- end
- when /s/i
- if itm = $data_skills[ls[/\d+/].to_i] && !itm.linked?
- itm.linked_equip = self
- @linked_skill = ls.to_sym
- end
- end
- end
- }
- end
- end
- #==============================================================================
- # *
- #==============================================================================
- class Game_BattlerBase
- #--------------------------------------------------------------------------
- # * Determine Skill/Item Usability
- #--------------------------------------------------------------------------
- alias dmtk_linked_usable? usable?
- def usable?(item)
- if item.is_a?(RPG::EquipItem) && item.linked?
- return dmtk_linked_usable?(item.linked_skill) if DMTK::LINKED_SKILL::CHECK_CONDITION
- return usable_item_conditions_met?(item.linked_skill)
- else
- dmtk_linked_usable?(item)
- end
- end
- #--------------------------------------------------------------------------
- # * Check Usability Conditions for Item
- #--------------------------------------------------------------------------
- alias dmtk_linked_condition? item_conditions_met?
- def item_conditions_met?(item)
- return true if dmtk_linked_condition?(item)
- return false unless item.linked?
- return false unless usable_item_conditions_met?(item)
- include_equip = DMTK::LINKED_SKILL::INCLUDE_EQUIP
- return $game_party.has_item?(item.linked_equip, include_equip)
- end
- #--------------------------------------------------------------------------
- # * Pay Cost of Using Skill
- #--------------------------------------------------------------------------
- alias dmtk_linked_cost pay_skill_cost
- def pay_skill_cost(skill)
- include_equip = DMTK::LINKED_SKILL::INCLUDE_EQUIP
- if skill.linked? && $game_party.has_item?(skill.linked_equip, include_equip)
- dmtk_linked_cost(skill) unless DMTK::LINKED_SKILL::IGNORE_COST
- $game_party.lose_item(skill.linked_equip, 1, include_equip) if skill.linked_equip.consumable
- else
- dmtk_linked_cost(skill)
- end
- end
- end
- #==============================================================================
- # *
- #==============================================================================
- class Window_ItemList < Window_Selectable
- #--------------------------------------------------------------------------
- # * Get Item
- #--------------------------------------------------------------------------
- alias dmtk_linked_item item
- def item
- itm = dmtk_linked_item
- return itm unless itm.is_a?(RPG::EquipItem) && itm.linked?
- return itm.linked_skill
- end
- end
- #==============================================================================
- # *
- #==============================================================================
- class Game_Party < Game_Unit
- #--------------------------------------------------------------------------
- # * Consume Items
- # If the specified object is a consumable item, the number in investory
- # will be reduced by 1.
- #--------------------------------------------------------------------------
- alias dmtk_linked_consume_item consume_item
- def consume_item(item)
- if !has_item?(item) && item.is_a?(RPG::Item) && item.linked?
- unless item.linked_equip.consumable
- include_equip = DMTK::LINKED_SKILL::INCLUDE_EQUIP
- lose_item(item.linked_equip, 1, include_equip)
- end
- else
- dmtk_linked_consume_item(item)
- end
- end
- end
- #==============================================================================
- # * item.consumable
- #==============================================================================
- class Scene_ItemBase < Scene_MenuBase
- #--------------------------------------------------------------------------
- # * Get Currently Selected Item
- #--------------------------------------------------------------------------
- alias dmtk_linked_item item
- def item
- itm = dmtk_linked_item
- return itm unless itm.is_a?(RPG::EquipItem) && itm.linked?
- return itm.linked_skill
- end
- end
- #==============================================================================
- # *
- #==============================================================================
- class Scene_Battle < Scene_Base
- #--------------------------------------------------------------------------
- # * Item [OK]
- #--------------------------------------------------------------------------
- alias on_linked_item_ok on_item_ok
- def on_item_ok
- on_linked_item_ok
- @item = @item_window.item
- if @item.linked?
- BattleManager.actor.input.set_skill(@item.id) if @item.is_a?(RPG::Skill)
- $game_party.last_item.object = @item.linked_equip
- end
- end
- end
- #==============================================================================
- # * END
- #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement