Advertisement
DrDhoom

[RGSS3] Monster Catalogue Addon

Jan 11th, 2015
949
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 16.61 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # • modern algebra Monster Catalogue v1.4 Add-on:
  4. #   • Kill Counts, Elements and States Resistance,
  5. #     Drop Items (including Extra Drops from Yanfly),
  6. #     and Stealable Items from Yanfly Script
  7. # by : DrDhoom
  8. # -- Last Updated: 2018.01.09
  9. # -- Level: Easy, Normal
  10. # -- Requires: modern algebra Monster Catalogue v1.1
  11. #
  12. #
  13. # Aditional Credit :
  14. #   - joeyjoejoe (Commission requester)
  15. #
  16. #==============================================================================
  17.  
  18. module Dhoom
  19.   module MonsterCatalogueAddon    
  20.   #    :always    - The value to be shown will always be shown
  21.   #    :encounter - The value to be shown will be shown once the monster has
  22.   #                been encountered. You can either manually encounter an enemy
  23.   #                through a call script, or it will automatically happen the
  24.   #                first time the party fights that kind of enemy.
  25.   #    :analyze   - The value to be shown will be shown once the monster has
  26.   #                been analyzed. You can set either manually analyze an enemy
  27.   #                through a call script, or you can do it by setting items and
  28.   #                skills to be \analyze items that, when used, will analyze
  29.   #                a monster and show data on it. By default, I do not use this
  30.   #                option for anything.
  31.     ENABLE_DATA_WHEN = :always
  32.    
  33.   # %d is where the digit would be
  34.     KILL_TEXT = "Total Killed: %d"  
  35.    
  36.     ELEMENT_LABEL = "Elements"
  37.     ELEMENT_LABEL_Y = 38
  38.     ELEMENT_FONT_SIZE = 14
  39.     ELEMENT_EACH_ROW = 7
  40.     ELEMENT_SPACING = 2
  41.     ELEMENT_WIDTH = 54    
  42.     ELEMENT_ID = [3,4,5,6,7,8,9,10,11,12,13,14,15,16]
  43.     DEFAULT_ELEMENT_ICON = 16
  44.    
  45.     ELEMENT_ICONS = []
  46.     ELEMENT_ICONS[3] = 17
  47.     ELEMENT_ICONS[4] = 18
  48.    
  49.     STATE_LABEL = "States"
  50.     STATE_LABEL_Y = 184
  51.     STATE_FONT_SIZE = 14
  52.     STATE_EACH_ROW = 5
  53.     STATE_SPACING = 2
  54.     STATE_WIDTH = 54
  55.     STATE_ID = [2,3,4,5,6,7,8,9,10,11]
  56.    
  57.     SKILL_LABEL = "Skills"
  58.     SKILL_MANIPULATE_LABEL = "Control Skill"
  59.     SKILL_LABEL_Y = 38
  60.     SKILL_FONT_SIZE = 24
  61.     SKILL_EACH_ROW = 1
  62.     SKILL_SPACING = 6
  63.     SKILL_WIDTH = 280
  64.     DISABLE_SKILLS = false
  65.     DISABLE_MANIPULATE_SKILLS = false
  66.    
  67.     DROP_LABEL = "Drops"
  68.     DROP_FONT_SIZE = 21
  69.     DROP_EACH_ROW = 1
  70.     DROP_SPACING = 6
  71.     DROP_WIDTH = 280
  72.    
  73.     STEALABLE_LABEL = "Stealables"
  74.     STEALABLE_FONT_SIZE = 21
  75.     STEALABLE_EACH_ROW = 1
  76.     STEALABLE_SPACING = 6
  77.     STEALABLE_WIDTH = 280
  78.     STEALABLE_GOLD_ICON = 361
  79.   end
  80. end
  81.  
  82. class Game_System
  83.   attr_accessor :enemy_killed
  84.  
  85.   alias dhoom_mcadon_gmsystem_initialize initialize
  86.   def initialize
  87.     dhoom_mcadon_gmsystem_initialize
  88.     @enemy_killed = []
  89.   end
  90. end
  91.  
  92. module BattleManager
  93.   class <<self; alias dhoom_mcadon_batman_battle_end battle_end; end
  94.   def self.battle_end(result)
  95.     $game_troop.dead_members.each do |enemy|
  96.       $game_system.enemy_killed[enemy.enemy_id] ||= 0
  97.       $game_system.enemy_killed[enemy.enemy_id] += 1
  98.     end
  99.     dhoom_mcadon_batman_battle_end(result)    
  100.   end
  101. end
  102.  
  103. class Window_MonsterCard < Window_Selectable
  104.   include Dhoom::MonsterCatalogueAddon
  105.  
  106.   alias dhoom_mcadon_wndmcard_refresh refresh  
  107.   def refresh(monster_id = @monster_id, index = 0)
  108.     @tindex = index
  109.     if @tindex == 0
  110.       monster_id = 0 if monster_id == nil      
  111.       if monster_id.is_a?(Game_Enemy)        
  112.         @monster = monster_id        
  113.         @monster_id = @monster.enemy_id  
  114.       elsif @monster.nil? || @monster.enemy_id != monster_id
  115.         @monster_id = monster_id
  116.         @monster = monster_id > 0 ? Game_Enemy.new(0, @monster_id) : nil
  117.       end
  118.       if @monster.is_a?(Game_Enemy)
  119.         dhoom_mcadon_wndmcard_refresh(@monster)
  120.       else
  121.         dhoom_mcadon_wndmcard_refresh(monster_id)
  122.       end      
  123.       w = MAMC_CONFIG[:frame_width]
  124.       draw_total_killed(6 + w*2, 2 + w*2) if @monster
  125.     elsif @tindex == 1
  126.       contents.clear
  127.       reset_font_settings
  128.       w = MAMC_CONFIG[:frame_width]
  129.       draw_frame
  130.       draw_name(6 + w*2, 2 + w*2) if @monster
  131.       draw_total_killed(6 + w*2, 2 + w*2) if @monster
  132.       draw_label(ELEMENT_LABEL_Y, ELEMENT_LABEL)
  133.       draw_label(STATE_LABEL_Y, STATE_LABEL)
  134.       enabled = $game_system.mamc_data_conditions_met?(ENABLE_DATA_WHEN, @monster_id)
  135.       draw_elements(enabled)
  136.       draw_states(enabled)
  137.     elsif @tindex == 2
  138.       contents.clear
  139.       reset_font_settings
  140.       w = MAMC_CONFIG[:frame_width]
  141.       draw_frame
  142.       draw_name(6 + w*2, 2 + w*2) if @monster
  143.       draw_total_killed(6 + w*2, 2 + w*2) if @monster
  144.       enabled = $game_system.mamc_data_conditions_met?(ENABLE_DATA_WHEN, @monster_id)
  145.       unless DISABLE_SKILLS
  146.         draw_label(SKILL_LABEL_Y, SKILL_LABEL)
  147.         draw_skills(enabled)
  148.       else
  149.         @mskill_label = SKILL_LABEL_Y
  150.       end
  151.       reset_font_settings
  152.       if $imported && $imported["DHManipulate"] && !monster.enemy.control_skill.empty? && !DISABLE_MANIPULATE_SKILLS
  153.         draw_label(@mskill_label, SKILL_MANIPULATE_LABEL)
  154.         draw_manipulate_skills(enabled)
  155.       else
  156.         @drop_label = @mskill_label
  157.       end
  158.       items = monster.enemy.drop_items
  159.       items += monster.enemy.extra_drops if $imported && $imported["YEA-ExtraDrops"]
  160.       unless items.empty?
  161.         reset_font_settings
  162.         draw_label(@drop_label, DROP_LABEL)
  163.         draw_drops(enabled)      
  164.       end
  165.     elsif @tindex == 3
  166.       contents.clear
  167.       reset_font_settings
  168.       w = MAMC_CONFIG[:frame_width]
  169.       draw_frame
  170.       draw_name(6 + w*2, 2 + w*2) if @monster
  171.       draw_total_killed(6 + w*2, 2 + w*2) if @monster
  172.       enabled = $game_system.mamc_data_conditions_met?(ENABLE_DATA_WHEN, @monster_id)
  173.       if $imported && $imported["YEA-StealItems"]
  174.         reset_font_settings
  175.         draw_label(SKILL_LABEL_Y, STEALABLE_LABEL)
  176.         draw_stealables(enabled)
  177.       end
  178.     end
  179.     update_help
  180.   end
  181.   alias monster_id= refresh
  182.   alias monster= refresh
  183.      
  184.   def draw_total_killed(x, y)
  185.     change_color(system_color)
  186.     $game_system.enemy_killed ||= []
  187.     $game_system.enemy_killed[@monster_id] ||= 0
  188.     text = sprintf(KILL_TEXT, $game_system.enemy_killed[@monster_id])
  189.     draw_text(x, y, contents_width - 2*x, line_height, text, 2)
  190.   end  
  191.  
  192.   def draw_label(ay, text)
  193.     w = MAMC_CONFIG[:frame_width]
  194.     contents.font.bold = true
  195.     stw = text_size(text).width + 8
  196.     lx = 34
  197.     y = ay + (line_height / 2)
  198.     draw_stat_divider(1 + w, y + w, contents_width - 2 - 3*w, lx, stw, text_color(MAMC_CONFIG[:frame_shadow_colour]))
  199.     draw_stat_divider(1, y, contents_width - 2 - w, lx, stw, text_color(MAMC_CONFIG[:frame_colour]))
  200.     change_color(text_color(MAMC_CONFIG[:frame_colour]))
  201.     draw_text(lx, ay, stw, line_height, text, 1)
  202.     reset_font_settings
  203.   end
  204.      
  205.   def draw_elements(enabled)
  206.     contents.font.size = ELEMENT_FONT_SIZE
  207.     x = (contents.width-(ELEMENT_WIDTH+ELEMENT_SPACING)*ELEMENT_EACH_ROW)/2    
  208.     y = ELEMENT_LABEL_Y+28
  209.     ELEMENT_ID.each_with_index do |id, i|  
  210.       change_color(system_color)
  211.       draw_text(x, y, ELEMENT_WIDTH, ELEMENT_FONT_SIZE, $data_system.elements[id], 1)
  212.       if ELEMENT_ICONS[id]
  213.         draw_icon(ELEMENT_ICONS[id], x+(ELEMENT_WIDTH-24)/2, y+ELEMENT_FONT_SIZE)
  214.       else
  215.         draw_icon(DEFAULT_ELEMENT_ICON, x+(ELEMENT_WIDTH-24)/2, y+ELEMENT_FONT_SIZE)
  216.       end
  217.       change_color(normal_color)
  218.       if enabled
  219.         text = "#{(monster.element_rate(id)*100).to_i}%"
  220.       else
  221.         text = "????"
  222.       end
  223.       draw_text(x, y+ELEMENT_FONT_SIZE+28, ELEMENT_WIDTH, ELEMENT_FONT_SIZE, text, 1)
  224.       x += ELEMENT_WIDTH+ELEMENT_SPACING
  225.       if (i+1) % ELEMENT_EACH_ROW == 0
  226.         y += ELEMENT_FONT_SIZE*2+28+ELEMENT_SPACING
  227.         w = ELEMENT_ID.size-(i+1) > ELEMENT_EACH_ROW ? ELEMENT_EACH_ROW : ELEMENT_ID.size-(i+1)
  228.         x = (contents.width-(ELEMENT_WIDTH+ELEMENT_SPACING)*w)/2
  229.       end
  230.     end
  231.   end
  232.  
  233.   def draw_states(enabled)
  234.     contents.font.size = STATE_FONT_SIZE
  235.     x = (contents.width-(STATE_WIDTH+STATE_SPACING)*STATE_EACH_ROW)/2    
  236.     y = STATE_LABEL_Y+28
  237.     states = []
  238.     $data_states.compact.each do |state|
  239.       states.push(state) if STATE_ID.include?(state.id)
  240.     end
  241.     states.each_with_index do |state, i|
  242.       change_color(system_color)
  243.       draw_text(x, y, STATE_WIDTH, STATE_FONT_SIZE, state.name, 1)
  244.       draw_icon(state.icon_index, x+(STATE_WIDTH-24)/2, y+STATE_FONT_SIZE)
  245.       change_color(normal_color)
  246.       if enabled
  247.         text = "#{(monster.state_rate(state.id)*100).to_i}%"
  248.       else
  249.         text = "????"
  250.       end
  251.       draw_text(x, y+STATE_FONT_SIZE+28, STATE_WIDTH, STATE_FONT_SIZE, text, 1)
  252.       x += STATE_WIDTH+STATE_SPACING
  253.       if (i+1) % STATE_EACH_ROW == 0
  254.         y += STATE_FONT_SIZE*2+28+STATE_SPACING
  255.         w = states.size-(i+1) > STATE_EACH_ROW ? STATE_EACH_ROW : states.size-(i+1)
  256.         x = (contents.width-(STATE_WIDTH+STATE_SPACING)*w)/2
  257.       end
  258.     end    
  259.   end
  260.  
  261.   def draw_skills(enabled)
  262.     contents.font.size = SKILL_FONT_SIZE
  263.     x = (contents.width-(SKILL_WIDTH+SKILL_SPACING)*SKILL_EACH_ROW)/2    
  264.     y = SKILL_LABEL_Y+28
  265.     skills = []
  266.     monster.enemy.actions.each do |action|
  267.       skills.push(action.skill_id) unless skills.include?(action.skill_id)
  268.     end
  269.     skills.each_with_index do |id, i|
  270.       change_color(normal_color)
  271.       draw_icon($data_skills[id].icon_index, x, y+(SKILL_FONT_SIZE-24)/2) if enabled
  272.       text = enabled ? $data_skills[id].name : $data_skills[id].name.gsub(/./,"?")
  273.       draw_text(x+28, y, SKILL_WIDTH-28, SKILL_FONT_SIZE, text)
  274.       x += SKILL_WIDTH+SKILL_SPACING
  275.       if (i+1) % SKILL_EACH_ROW == 0
  276.         y += SKILL_FONT_SIZE+SKILL_SPACING
  277.         x = (contents.width-(SKILL_WIDTH+SKILL_SPACING)*SKILL_EACH_ROW)/2
  278.         @mskill_label = y
  279.       else
  280.         @mskill_label = y+SKILL_FONT_SIZE+SKILL_SPACING
  281.       end
  282.     end
  283.   end
  284.  
  285.   def draw_manipulate_skills(enabled)
  286.     contents.font.size = SKILL_FONT_SIZE
  287.     x = (contents.width-(SKILL_WIDTH+SKILL_SPACING)*SKILL_EACH_ROW)/2    
  288.     y = @mskill_label+28
  289.     if monster.enemy.control_skill.empty?
  290.       change_color(normal_color)
  291.       draw_text(x, y, SKILL_WIDTH, SKILL_FONT_SIZE, "None")
  292.       @drop_label = y+SKILL_FONT_SIZE+SKILL_SPACING
  293.     else
  294.       monster.enemy.control_skill.each_with_index do |skill, i|
  295.         change_color(normal_color)
  296.         draw_icon(skill.icon_index, x, y+(SKILL_FONT_SIZE-24)/2) if enabled
  297.         text = enabled ? skill.name : skill.name.gsub(/./,"?")
  298.         draw_text(x+28, y, SKILL_WIDTH-28, SKILL_FONT_SIZE, text)
  299.         x += SKILL_WIDTH+SKILL_SPACING
  300.         if (i+1) % SKILL_EACH_ROW == 0
  301.           y += SKILL_FONT_SIZE+SKILL_SPACING
  302.           x = (contents.width-(SKILL_WIDTH+SKILL_SPACING)*SKILL_EACH_ROW)/2
  303.           @drop_label = y
  304.         else
  305.           @drop_label = y+SKILL_FONT_SIZE+SKILL_SPACING
  306.         end
  307.       end
  308.     end
  309.   end
  310.  
  311.   def draw_drops(enabled)
  312.     contents.font.size = DROP_FONT_SIZE
  313.     x = (contents.width-(DROP_WIDTH+DROP_SPACING)*DROP_EACH_ROW)/2    
  314.     y = @drop_label+28
  315.     items = monster.enemy.drop_items
  316.     items += monster.enemy.extra_drops if $imported && $imported["YEA-ExtraDrops"]
  317.     items.select{|v| v.kind != 0}.each_with_index do |drop, i|
  318.       change_color(normal_color)
  319.       case drop.kind
  320.       when 1
  321.         item = $data_items[drop.data_id]
  322.       when 2
  323.         item = $data_weapons[drop.data_id]
  324.       when 3
  325.         item = $data_armors[drop.data_id]
  326.       end
  327.       draw_icon(item.icon_index, x, y+(DROP_FONT_SIZE-24)/2) if enabled
  328.       text = enabled ? item.name : item.name.gsub(/./,"?")
  329.       if $imported && $imported["YEA-ExtraDrops"] && drop.drop_rate > 0
  330.         percent = "#{(drop.drop_rate * 100).to_i}%"
  331.       else
  332.         percent = "#{(1.0/drop.denominator*100).to_i}%"
  333.       end
  334.       amount = enabled ? percent : percent.gsub(/./,"?")
  335.       draw_text(x+28, y, DROP_WIDTH-28-DROP_FONT_SIZE*2, DROP_FONT_SIZE, text)
  336.       draw_text(x, y, DROP_WIDTH, DROP_FONT_SIZE, amount, 2)
  337.       x += DROP_WIDTH+DROP_SPACING
  338.       if (i+1) % DROP_EACH_ROW == 0
  339.         y += DROP_FONT_SIZE+DROP_SPACING
  340.         x = (contents.width-(DROP_WIDTH+DROP_SPACING)*DROP_EACH_ROW)/2
  341.         @stealable_label = y
  342.       else
  343.         @stealable_label = y+DROP_FONT_SIZE+DROP_SPACING
  344.       end
  345.     end
  346.   end
  347.  
  348.   def draw_stealables(enabled)
  349.     contents.font.size = STEALABLE_FONT_SIZE
  350.     x = (contents.width-(STEALABLE_WIDTH+STEALABLE_SPACING)*STEALABLE_EACH_ROW)/2    
  351.     y = SKILL_LABEL_Y+28
  352.     monster.enemy.stealable_items.each_with_index do |drop, i|
  353.       change_color(normal_color)      
  354.       case drop.kind
  355.       when 1
  356.         item = $data_items[drop.data_id]
  357.       when 2
  358.         item = $data_weapons[drop.data_id]
  359.       when 3
  360.         item = $data_armors[drop.data_id]
  361.       when 4
  362.         item = 'gold'
  363.       end
  364.       icon = item === 'gold' ? STEALABLE_GOLD_ICON : item.icon_index
  365.       draw_icon(icon, x, y+(STEALABLE_FONT_SIZE-24)/2) if enabled
  366.       name = item === 'gold' ? Vocab.currency_unit : item.name
  367.       text = enabled ? name : name.gsub(/./,"?")
  368.       percent = "#{(drop.rate*100).to_i}%"
  369.       amount = enabled ? percent : percent.to_s.gsub(/./,"?")
  370.       draw_text(x+28, y, STEALABLE_WIDTH-28-STEALABLE_FONT_SIZE*2, STEALABLE_FONT_SIZE, text)
  371.       draw_text(x, y, STEALABLE_WIDTH, STEALABLE_FONT_SIZE, amount, 2)
  372.       x += STEALABLE_WIDTH+STEALABLE_SPACING
  373.       if (i+1) % STEALABLE_EACH_ROW == 0
  374.         y += STEALABLE_FONT_SIZE+STEALABLE_SPACING
  375.         x = (contents.width-(STEALABLE_WIDTH+STEALABLE_SPACING)*STEALABLE_EACH_ROW)/2
  376.       end
  377.     end
  378.   end
  379.    
  380.   def update
  381.     super
  382.     return unless self.active && self.visible
  383.     if Input.trigger?(:LEFT)
  384.       Sound.play_cursor
  385.       @tindex -= 1
  386.       @tindex = $imported && $imported["YEA-StealItems"] ? 3 : 2 if @tindex == -1
  387.     elsif Input.trigger?(:RIGHT)
  388.       Sound.play_cursor
  389.       @tindex += 1
  390.       max = $imported && $imported["YEA-StealItems"] ? 4 : 3
  391.       @tindex = 0 if @tindex == max
  392.     end
  393.     if @temp_index != @tindex
  394.       @temp_index = @tindex
  395.       refresh(@monster_id, @tindex)
  396.     end
  397.   end
  398. end
  399.  
  400. class Scene_MonsterCatalogue < Scene_MenuBase
  401.   alias dhoom_mcadon_scmcat_create_category_window create_category_window
  402.   def create_category_window
  403.     dhoom_mcadon_scmcat_create_category_window
  404.     if @category_window
  405.       @category_window.set_handler(:ok,       method(:activate_monstercard_window))
  406.     end
  407.   end
  408.  
  409.   alias dhoom_mcadon_scmcat_create_monsterlist_window create_monsterlist_window
  410.   def create_monsterlist_window
  411.     dhoom_mcadon_scmcat_create_monsterlist_window
  412.     @monsterlist_window.set_handler(:ok,       method(:activate_monstercard_window))
  413.     @monsterlist_window.set_handler(:cancel,   method(:return_scene))
  414.   end
  415.  
  416.   alias dhoom_mcadon_scmcat_create_monstercard_window create_monstercard_window
  417.   def create_monstercard_window
  418.     dhoom_mcadon_scmcat_create_monstercard_window
  419.     @monstercard_window.set_handler(:cancel,   method(:deactivate_monstercard_window))
  420.     @monstercard_window.deactivate
  421.   end
  422.  
  423.   def activate_monstercard_window
  424.     @monstercard_window.activate
  425.     @monsterlist_window.deactivate
  426.     @category_window.deactivate if @category_window
  427.   end
  428.  
  429.   def deactivate_monstercard_window
  430.     @monstercard_window.deactivate
  431.     @monsterlist_window.activate
  432.     @category_window.activate if @category_window
  433.   end
  434. end
  435.  
  436. class Scene_Battle
  437.   def create_monstercard_window
  438.     x = (Graphics.width - @status_window.width) / 2
  439.     @monstercard_window = Window_MonsterCard.new(x, 0, @status_window.width, Graphics.height)
  440.     @monstercard_window.z = [@log_window.z + 1, 200].max
  441.     @monstercard_window.openness = 0
  442.     # Include the BattleMonsterCard module in the singleton class
  443.     @monstercard_window.send(:extend, MAMC_BattleMonsterCard)
  444.     @monstercard_window.set_handler(:cancel, lambda { close_monster_card_window })
  445.     @monstercard_window.set_handler(:ok, lambda { close_monster_card_window })
  446.   end
  447.  
  448.   alias dhoom_mcadon_scbat_mamc_analyze_monster mamc_analyze_monster
  449.   def mamc_analyze_monster(target)
  450.     dhoom_mcadon_scbat_mamc_analyze_monster(target)
  451.     @status_window.hide
  452.     @actor_command_openned = @actor_command_window.open?
  453.     @actor_command_window.openness = 0
  454.   end
  455.  
  456.   alias dhoom_mcadon_scbat_close_monster_card_window close_monster_card_window
  457.   def close_monster_card_window
  458.     dhoom_mcadon_scbat_close_monster_card_window
  459.     @status_window.show
  460.     @actor_command_window.openness = 255 if @actor_command_openned
  461.   end  
  462. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement