=begin #============================================================================== ** Draw Magic Author: Hime Date: May 28, 2012 ------------------------------------------------------------------------------ ** Change log May 28 - implemented "Command Setup" add-on - initial release ------------------------------------------------------------------------------ ** Requirements This script requires "Magic Units" ------------------------------------------------------------------------------ This script allows you to designate skills that should be treated as "draw skills". Draw skills allow you to steal magic units from the enemy. In the configuration, just type in the skill ID's that should be draw skills. Tag enemies that should have magic units with the desired skill ID's Note that they must be magic unit skill types. If you are using "Command setup", you may choose to set the Draw skill as a command #============================================================================== =end $imported = {} if $imported.nil? $imported["Tsuki_DrawMagic"] = true #============================================================================== # ** Configuration #============================================================================== if !$imported["Tsuki_MagicUnits"] msgbox("`Draw Magic` requires `Magic Units` to be placed above this script") else module Tsuki module Draw_Magic # skills that draw magic Draw_Skill = [128] # formula used to determine how much is drawn # a is user, b is target Draw_Formula = "rand(10) + rand(a.mat / 10) - rand(b.mat / 10)+1" # Message to display when magic is drawn # Format: [battler name], [number], [magic name] ActorDraw = "%s %s was drawn from %s!" # Format: [number], [magic name], [battler name] EnemyDraw = "Drew %s %s from %s!" #============================================================================== # ** Rest of the script #============================================================================== Draws_Regex = //i end end module RPG class Enemy < BaseItem def enemy_draws return @draws unless @draws.nil? return @draws = load_notetags_enemy_draws end def load_notetags_enemy_draws draws = [] self.note.split(/[\r\n]+/).each do |line| case line when Tsuki::Draw_Magic::Draws_Regex $1.scan(/\d+/).each {|id| draws << id.to_i} end end return draws end end end class Game_Action attr_accessor :draw_id #id of magic to draw alias :th_draw_magic_clear_action :clear def clear th_draw_magic_clear_action @draw_id = 0 end end class Game_ActionResult attr_accessor :draw_amount attr_accessor :draw_magic_name alias :th_draw_magic_clear_results :clear def clear th_draw_magic_clear_results clear_draw_amount end def clear_draw_amount @draw_amount = 0 end def draw_amount_text if @draw_amount > 0 fmt = @battler.actor? ? Tsuki::Draw_Magic::EnemyDraw : Tsuki::Draw_Magic::ActorDraw sprintf(fmt, @draw_amount, @draw_magic_name, @battler.name) else "" end end end class Game_Battler < Game_BattlerBase def is_draw_action?(item) return false unless item Tsuki::Draw_Magic::Draw_Skill.include?(item.id) end alias :th_draw_magic_item_apply :item_apply def item_apply(user, item) th_draw_magic_item_apply(user, item) draw_magic(user, item) if is_draw_action?(item) end def draw_magic(user, item) skill_id = user.actions[0].draw_id return if skill_id == 0 avail = get_magic_units(skill_id) drawn = calculate_draw_amount(user, self) amount = [[drawn, avail].min, 0].max if amount > 0 user.add_magic_units(skill_id, amount) lose_magic_units(skill_id, amount) @result.draw_amount = amount @result.draw_magic_name = $data_skills[skill_id].name @result.success = true end end def calculate_draw_amount(a, b) eval(Tsuki::Draw_Magic::Draw_Formula).to_i rescue 0 end end class Game_Enemy < Game_Battler alias :th_draw_magic_init_enemy :initialize def initialize(index, enemy_id) th_draw_magic_init_enemy(index, enemy_id) init_draws end def init_draws enemy.enemy_draws.each {|skill_id| add_magic_units(skill_id, 99)} end alias :th_draw_magic_make_enemy_actions :make_actions def make_actions th_draw_magic_make_enemy_actions @actions.each do |action| make_draw_action(action) if is_draw_action?(action.item) end end # pick a random target to draw a random magic from def make_draw_action(action) target_index = rand(action.opponents_unit.members.size) action.target_index = target_index battler_magic = action.opponents_unit.members[target_index].get_all_magic draw_target = battler_magic[rand(battler_magic.size)] action.draw_id = draw_target ? draw_target.id : 0 end end class Scene_Battle < Scene_Base alias :th_draw_magic_create_windows :create_all_windows def create_all_windows th_draw_magic_create_windows create_draw_window create_enemy_draw_window end def create_draw_window wy = @skill_window.y height = @skill_window.height @draws_window = Window_BattleDrawList.new(0, wy, Graphics.width, height, @help_window) @draws_window.set_handler(:ok, method(:on_draw_ok)) @draws_window.set_handler(:cancel, method(:on_draw_cancel)) end def create_enemy_draw_window @enemy_draw_window = Window_BattleEnemy.new(@info_viewport) @enemy_draw_window.set_handler(:ok, method(:on_enemy_draw_ok)) @enemy_draw_window.set_handler(:cancel, method(:on_enemy_draw_cancel)) end alias :th_draw_magic_on_skill_ok :on_skill_ok def on_skill_ok @skill = @skill_window.item if Tsuki::Draw_Magic::Draw_Skill.include?(@skill.id) BattleManager.actor.input.set_skill(@skill.id) BattleManager.actor.last_skill.object = @skill select_enemy_draw_selection else th_draw_magic_on_skill_ok end end def select_enemy_draw_selection @enemy_draw_window.refresh @enemy_draw_window.show.activate end def on_enemy_draw_ok @skill_window.hide @draws_window.battler = @enemy_draw_window.enemy @draws_window.show.activate @draws_window.select_last end def on_enemy_draw_cancel @enemy_draw_window.hide @skill_window.refresh @skill_window.show.activate end def on_draw_ok @draws_window.hide BattleManager.actor.input.target_index = @enemy_draw_window.enemy.index BattleManager.actor.input.draw_id = @draws_window.item.id @enemy_draw_window.hide @skill_window.hide @item_window.hide next_command end def on_draw_cancel @draws_window.hide @skill_window.show @enemy_draw_window.refresh @enemy_draw_window.activate end end class Window_BattleLog < Window_Selectable alias :th_draw_magic_display_damage :display_damage def display_damage(target, item) th_draw_magic_display_damage(target, item) display_draw_results(target, item) end def display_draw_results(target, item) return if target.result.draw_amount == 0 && item && !Tsuki::Draw_Magic::Draw_Skill.include?(item.id) add_text(target.result.draw_amount_text) wait end end class Window_BattleDrawList < Window_SkillList def initialize(x, y, width, height, help_window) super(x, y, width, height) self.visible = false @help_window = help_window @battler = nil @data = [] end def battler=(battler) @battler = battler if @battler != battler refresh self.oy = 0 end def enable?(item) !item.nil? end def make_item_list @data = @battler ? @battler.get_all_magic : [] end def draw_total_units(rect, skill) draw_text(rect, @battler.get_magic_units(skill.id), 2) end def show select_last @help_window.show super end def hide @help_window.hide super end def select_last select(0) end end #============================================================================== # ** Compatibility and add-ons #============================================================================== # Command setup add-on: allows you to set "draw" command if $imported["Tsuki_CommandSetup"] class Scene_Battle < Scene_Base alias :th_draw_magic_command_use_skill :command_use_skill def command_use_skill @skill = $data_skills[@actor_command_window.current_data[:ext]] BattleManager.actor.input.set_skill(@skill.id) BattleManager.actor.last_skill.object = @skill if Tsuki::Draw_Magic::Draw_Skill.include?(@skill.id) select_enemy_draw_selection else th_draw_magic_command_use_skill end end def on_enemy_draw_cancel @enemy_draw_window.hide if @skill == $data_skills[@actor_command_window.current_data[:ext]] @actor_command_window.activate else @skill_window.refresh @skill_window.show.activate end end end end end o