#====================================================================== # Scan Skill v2 by mjshi (edits by Trihan) #---------------------------------------------------------------------- # Place images into Graphics/System. #---------------------------------------------------------------------- # Usage: Set a skill ID to be the scan skill, then, in that skill's # effects, call a common event. # The common event should look like this: # Script command: SceneManager.scene.run_scan_skill #---------------------------------------------------------------------- module ScanSkill #-------------------------------------------------------------------- # Config # ID of the scan skill SkillID = [ 45, 163, 364, 384, 468, 553 ] # Order to draw elements in (by type id) ElementOrder = [ 2, 3, 4, 5, 6, 7, 8 ] # Mini element images, grabbed off the icon sheet ElementIcons = { #--------------------------- # Format: # ElementId => IconIndex # 1 => 313, 2 => 306, 3 => 307, 4 => 308, 5 => 309, 6 => 310, 7 => 311, 8 => 312, #--------------------------- } # Images associated with each id ElementImages = { #--------------------------- # Format: # ElementId => "icon image", # 2 => "Bone", 3 => "Flesh", 4 => "Blood", 5 => "Nature", 6 => "Lightning", 7 => "Ectoplasm", 8 => "Sugar", #--------------------------- } WeakText = "Wk" StrongText = "Res" NormalText = "--" NullText = "Null" # Text that precedes the state icons. Leave blank for none. StatusText = { # Set this to "" for no text :text => "Status", :x => 325, :y => 0, } # If damage taken is 150% normal or higher, consider weak WeakPercent = 1.5 # If damage taken is 50% normal or lower, consider strong StrongPercent = 0.5 # If damage taken is 0%, consider null NullPercent = 0 NameWindow = { :x => 0, :y => 22, :width => 544, :height => 48, :name_x => 0, :name_y => 0, :icon_x => 5, :icon_y => 0, :state_x => 415, :state_y => 0, } ElementWindow = { :x => 0, :y => 70, :width => 544, :height => 120, :image_x => 4, :image_y => 8, :text_x => 0, :text_y => 70, } DescriptionWindow = { :x => 0, :y => 190, :width => 544, :height => 120 } DescriptionOn = //i DescriptionOff = /<\/description>/i # End Config #-------------------------------------------------------------------- end #---------------------------------------------------------------------- # Scene_Battle # class Scene_Battle def wait_for_scan @scan_status_window.update update_for_wait while @scan_status_window.visible end alias mjshi_scan_create_all_windows create_all_windows def create_all_windows mjshi_scan_create_all_windows create_scan_window end def create_scan_window @scan_status_window = Window_ScanStatus.new @scan_resist_window = Window_Resistances.new @scan_description_window = Window_ScanDescription.new end alias mjshi_scan_on_enemy_ok on_enemy_ok def on_enemy_ok if (@should_scan) @should_scan = false @enemy_to_scan = $game_troop.members[@enemy_window.enemy.index] end mjshi_scan_on_enemy_ok end alias mjshi_scan_on_skill_ok on_skill_ok def on_skill_ok @should_scan = true if (ScanSkill::SkillID.include?(@skill_window.item.id)) mjshi_scan_on_skill_ok end def run_scan_skill return if ($game_troop.all_dead?) if (!$game_troop.alive_members.include?(@enemy_to_scan)) @enemy_to_scan = $game_troop.alive_members[0] end RPG::SE.new("ScanWindow Open", 100, 100).play @log_window.hide @scan_status_window.set_enemy(@enemy_to_scan) @scan_resist_window.set_enemy(@enemy_to_scan) @scan_description_window.set_enemy(@enemy_to_scan) @scan_status_window.show @scan_resist_window.show @scan_description_window.show wait_for_scan end def stop_scan_skill RPG::SE.new("ScanWindow Close", 100, 100).play @scan_status_window.hide @scan_resist_window.hide @scan_description_window.hide @log_window.show end end #---------------------------------------------------------------------- # Window_Resistances # class Window_ScanStatus < Window_Selectable # icons = (actor.state_icons + actor.buff_icons)[0, width / 24] # icons.each_with_index {|n, i| draw_icon(n, x + 24 * i, y) } def initialize super(ScanSkill::NameWindow[:x], ScanSkill::NameWindow[:y], window_width, window_height) self.visible = false end def visible_line_number return 1 end def col_max return 1 end def window_width ScanSkill::NameWindow[:width] end def window_height ScanSkill::NameWindow[:height] end def set_enemy(enemy) @enemy = enemy refresh end def draw_all_items rect = item_rect_for_text(0) change_color(normal_color) draw_text_ex(rect.x + ScanSkill::NameWindow[:name_x], rect.y + ScanSkill::NameWindow[:name_y], @enemy.original_name) name_stripped = @enemy.original_name.sub(/^\\C\[\d+\]/i, '').sub(/\\C\[\d+\]$/i, '') icon_x = text_size(name_stripped).width # cache end x draw_text(rect.x + ScanSkill::StatusText[:x], rect.y + ScanSkill::StatusText[:y], rect.width, rect.height, ScanSkill::StatusText[:text]) # attack element if !@enemy.atk_elements.empty? && ScanSkill::ElementIcons.include?(@enemy.atk_elements[0]) draw_icon(ScanSkill::ElementIcons[@enemy.atk_elements[0]], icon_x + ScanSkill::NameWindow[:icon_x], ScanSkill::NameWindow[:icon_y]) end # states draw_actor_icons(@enemy, ScanSkill::NameWindow[:state_x], ScanSkill::NameWindow[:state_y]) reset_font_settings end def update super return if (!self.visible) if Input.trigger?(:B) || Input.trigger?(:C) SceneManager.scene.stop_scan_skill end end end #---------------------------------------------------------------------- # Window_Resistances # class Window_Resistances < Window_Selectable def initialize super(ScanSkill::ElementWindow[:x], ScanSkill::ElementWindow[:y], window_width, window_height) self.visible = false end def visible_line_number return 1 end def col_max return ScanSkill::ElementOrder.size end def window_width ScanSkill::ElementWindow[:width] end def window_height ScanSkill::ElementWindow[:height] end def item_max return col_max end def set_enemy(enemy) @enemy = enemy refresh end def draw_image(file, index, x, y, enabled = true) bitmap = Cache.system(file) rect = Rect.new(0, 0, bitmap.width, bitmap.height) contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha) end def spacing return 5 end def draw_item(index) elementID = ScanSkill::ElementOrder[index] rect = item_rect_for_text(index) text = ScanSkill::NormalText text = ScanSkill::WeakText if @enemy.element_rate(elementID) >= ScanSkill::WeakPercent text = ScanSkill::StrongText if @enemy.element_rate(elementID) <= ScanSkill::StrongPercent text = ScanSkill::NullText if @enemy.element_rate(elementID) == ScanSkill::NullPercent draw_image(ScanSkill::ElementImages[elementID], index, rect.x + ScanSkill::ElementWindow[:image_x], rect.y + ScanSkill::ElementWindow[:image_y]) rect.x += ScanSkill::ElementWindow[:text_x] rect.y += ScanSkill::ElementWindow[:text_y] change_color(normal_color) draw_text(rect, text, 1) reset_font_settings end end #---------------------------------------------------------------------- # Window_ScanDescription # class Window_ScanDescription < Window_Base def initialize super(ScanSkill::DescriptionWindow[:x], ScanSkill::DescriptionWindow[:y], window_width, window_height) self.visible = false @description_on = false @description = "" end def visible_line_number return 3 end def window_width ScanSkill::DescriptionWindow[:width] end def window_height ScanSkill::DescriptionWindow[:height] end def set_enemy(enemy) @enemy = enemy refresh end def refresh if @enemy @enemy.note.split(/[\r\n]+/).each { |line| case line when ScanSkill::DescriptionOn @description_on = true when ScanSkill::DescriptionOff @description_on = false else @description += line.to_s + "\n" if @description_on end } process_all_text end end def process_all_text text = convert_escape_characters(@description) col = contents.width / text_size("W").width text.gsub!(/\e([ic])\[(\d+)\]/," \\1\\2 ") text = wrap_text(text, col) lines = text.split("\n") output = [] lines.each_with_index { |line, index| loop do if lines[index+1] next_line = lines[index+1] if next_line == "" lines.delete(next_line) next end words = next_line.split(" ") word = words[0] break unless word line_width = text_size(line).width word_width = text_size(" " + word).width if line_width + word_width < contents.width line << (line == "" ? "" : " ") + word next_line.slice!(0, (word + " ").length) else break end else break end end output << line } text = output.join("\n") text.gsub!(/ ?([ic])(\d+) ?/,"\e\\1\[\\2\]") pos = {} new_page(text, pos) process_character(text.slice!(0, 1), text, pos) until text.empty? end def wrap_text(txt, col = 80) txt.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}}(?: ?[ic]?\d+? )?)/,"\\1\\3\n") end def new_page(text, pos) contents.clear reset_font_settings pos[:x] = new_line_x pos[:y] = 0 pos[:new_x] = new_line_x pos[:height] = calc_line_height(text) end def new_line_x 0 end end class Window_BattleLog < Window_Selectable alias mjshi_scan_display_failure display_failure def display_failure(target, item) return if item.is_a?(RPG::Skill) && ScanSkill::SkillID.include?(item.id) mjshi_scan_display_failure(target, item) end end