#=begin #============================================================================== ** Magic Units Author: Tsukihime Date: May 28, 2012 ------------------------------------------------------------------------------ ** Change log May 28 - initial release ------------------------------------------------------------------------------ This script converts skill types to "units". In the default engine, skill use consumes MP or TP. A "unit of magic" is treated like an item; in order to use the magic, you must have one, and each time you use it, you consume as many units as required. You can determine how many units of each skill you can have using For some integer n You can also determine which skill types should be treated as units by specifying it in the configuration. You can add/remove magic units by using script calls add_units(skill_id, amount, scope_id, scope) lose_units(skill_id, amount, scope_id, scope) scope is either "actor" or "party". If the scope is "party", then the scope_id is the number representing the position of an actor in your party. 1 will be the first person, 2 will be the second person, etc If the scope is actor, then the scope_id is the actor_id. By default, the scope is "party" #============================================================================== =end $imported = {} if $imported.nil? $imported["Tsuki_MagicUnits"] = true #============================================================================== # ** Configuration #============================================================================== module Tsuki module Magic_Units # skill types that this script applies to Applied_Types = [2] # default maximum number of units you can have for a skill Max_Units = 99 # Default_Scope = "party" #============================================================================== # ** Rest of the script #============================================================================== # regex Max_Unit_Regex = //i end end module RPG class Skill < UsableItem def max_units return @max_units unless @max_units.nil? return @max_units = load_notetag_max_units end def load_notetag_max_units matches = Tsuki::Magic_Units::Max_Unit_Regex.match(self.note) return matches ? matches[1].to_i : Tsuki::Magic_Units::Max_Units end end end # stores a battler's skill units class Game_MagicStore def initialize @units = {} end def all_magic @units.keys.collect {|id| $data_skills[id]} end def skill(skill_id) $data_skills[skill_id] end def add_unit(skill_id, amount) @units[skill_id] = 0 if @units[skill_id].nil? @units[skill_id] = [@units[skill_id] + amount, skill(skill_id).max_units].min end def remove_unit(skill_id, amount) return if @units[skill_id].nil? @units[skill_id] -= amount @units.delete(skill_id) if @units[skill_id] <= 0 end def get_units(skill_id) @units[skill_id] || 0 end end class Game_BattlerBase alias :th_magic_units_init_bbase :initialize def initialize th_magic_units_init_bbase clear_magic_store end def clear_magic_store @magic_store = Game_MagicStore.new end alias :th_magic_units_pay_cost :pay_skill_cost def pay_skill_cost(skill) magic_unit_type?(skill.id) ? pay_unit_cost(skill) : th_magic_units_pay_cost(skill) end alias :th_magic_units_skill_payable? :skill_cost_payable? def skill_cost_payable?(skill) magic_unit_type?(skill.id) ? has_magic_units?(skill.id) : th_magic_units_skill_payable?(skill) end # ignore added skills if they're unit types alias :th_magic_units_added_skills :added_skills def added_skills th_magic_units_added_skills.select {|id| !magic_unit_type?(id)} end def pay_unit_cost(skill) lose_magic_units(skill.id, magic_unit_cost(skill)) end def magic_unit_cost(skill) 1 end def magic_unit_type?(skill_id) return if skill_id == 0 Tsuki::Magic_Units::Applied_Types.include?($data_skills[skill_id].stype_id) end def has_magic_units?(skill_id) @magic_store.get_units(skill_id) > 0 end def add_magic_units(skill_id, units) @magic_store.add_unit(skill_id, units) if magic_unit_type?(skill_id) end def lose_magic_units(skill_id, units) @magic_store.remove_unit(skill_id, units) if magic_unit_type?(skill_id) end def get_magic_units(skill_id) @magic_store.get_units(skill_id) if magic_unit_type?(skill_id) end def get_all_magic @magic_store.all_magic end end class Game_Actor < Game_Battler alias :th_magic_units_learn_skill :learn_skill def learn_skill(skill_id) return if magic_unit_type?(skill_id) th_magic_units_learn_skill(skill_id) end alias :th_magic_units_skills :skills def skills th_magic_units_skills.concat(get_all_magic) end end class Game_Interpreter def get_actor(scope, scope_id) scope == "party" ? $game_party.all_members[scope_id-1] : $game_actors[scope_id] end def add_units(id, amount, scope_id=1, scope=Tsuki::Magic_Units::Default_Scope) actor = get_actor(scope.downcase, scope_id) return unless actor actor.add_magic_units(id, amount) end def lose_units(id, amount, scope_id=1, scope=Tsuki::Magic_Units::Default_Scope) actor = get_actor(scope.downcase, scope_id) return unless actor actor.lose_magic_units(id, amount) end end #============================================================================== # ** update skill list window to display units of magic #============================================================================== class Window_SkillList < Window_Selectable def draw_item(index) skill = @data[index] if skill rect = item_rect(index) rect.width -= 4 draw_item_name(skill, rect.x, rect.y, enable?(skill)) if Tsuki::Magic_Units::Applied_Types.include?(skill.stype_id) draw_total_units(rect, skill) else draw_skill_cost(rect, skill) end end end def draw_total_units(rect, skill) draw_text(rect, @actor.get_magic_units(skill.id), 2) end end