Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Summong

By: a guest on Oct 3rd, 2012  |  syntax: Ruby  |  size: 25.42 KB  |  hits: 133  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. =begin
  2. ==============================================================================
  3.  ** Battle Summons
  4.  Author: Tsukihime
  5.  Date: Jul 10, 2012
  6. ------------------------------------------------------------------------------
  7.  ** Change log
  8.  Jul 10
  9.    -added summon_only_battle to game system as a flag
  10.  Jun 24
  11.    -fixed enemy summoning: only refresh newly summoned sprites
  12.  Jun 12
  13.    -assign specific summons to items/skills
  14.    -summon ID is now the same as the actor ID
  15.    -added remove summon functionality.
  16.  May 30
  17.    -summon limits and type limits added
  18.    -summons recover all after battle
  19.    -summon implemented as a skill
  20.    -added Command Setup compatibility
  21.    -added enemy summons
  22.    -summon equip menu added
  23.  May 20
  24.    -option to remove all actors when summon appears
  25.    -actors will return when the summon disappears
  26.  May 19
  27.    -Created summon scene/window
  28.    -added summon command
  29.    -summons are now treated as actors and level accordingly
  30.  May 18
  31.    -Initial release
  32. ------------------------------------------------------------------------------
  33.  Summon battlers to fight for you!
  34.  
  35.  In the configuration, designate skills that should be treated as
  36.  "summon skills". Then set up the skill in the database.
  37.  
  38.  Enemies can also be set up to use the summon skill.
  39.  They will need a list of enemy ID's to choose from.
  40.  Tag enemies with the enemy ID's they should summon
  41.  
  42.     <summons: 1,2,3>
  43.    
  44.  Then give them the summon skill in their action list
  45.  
  46.  To add a summon to your party, use the script call
  47.  
  48.     $game_party.add_summon(summon_id)
  49.    
  50.  To remove a summon from your party,
  51.  
  52.     $game_party.remove_summon(summon_id)
  53.    
  54.  To force summon a party to battle, use the call
  55.  
  56.     $game_summons.summon(id)
  57. ==============================================================================
  58. =end
  59. $imported = {} if $imported.nil?
  60. $imported["Tsuki_BattleSummon"] = true
  61. #==============================================================================
  62. # ** Configuration.
  63. #==============================================================================
  64. module Tsuki
  65.   module Battle_Summon
  66.    
  67.     # Skill IDs that are treated as summon skills
  68.     Summon_Skill = [3, 4, 17,18]
  69.     Summon_Item = []
  70.     Summon_Constraints =
  71.       {[:skill, 3] => [3], [:skill, 4] => [4], [:skill, 17] => [5], [:skill, 18] => [6]}
  72.      
  73.     # variable used to determine the number of turns summoned
  74.     Default_Summon_Turns = 99
  75.     Summon_Turn_Variable = 1
  76.        
  77.     Summon_Limit = 2      # How many summons you can have in battle
  78.     Summon_Type_Limit = 2 # How many different summons you can have in battle
  79.    
  80.     # Messages to display on successful summon in battle
  81.     # format [user name], [summon name]
  82.     Summon_Message = "%s has called %s to battle!"
  83.    
  84.     # Should the summon command be shown in battle?
  85.     Enable_Summon_Command = false
  86.    
  87.     # party members leave when a summon appears
  88.     Summon_Only_Battle = false
  89.    
  90.     # Monster Hunter add-on requires that script. It adds all captured monsters
  91.     # to your summon list rather than the party list.
  92.     Monster_Hunter_Addon = false
  93.  
  94.   #==============================================================================
  95.   # ** Rest of the Script
  96.   #==============================================================================
  97.     def self.summon_effect?(item)
  98.       return Summon_Skill.include?(item.id) if item.is_a?(RPG::Skill)
  99.       return Summon_Item.include?(item.id) if item.is_a?(RPG::Item)
  100.       return false
  101.     end
  102.    
  103.     Enemy_Summon_Regex = /<summons:?\s*(.*)\s*>/i
  104.     Summon_Limit_Regex = /<summon-max:?\s*(\d+)\s*>/i
  105.     Summon_ID_Regex = /<summon:?\s*(\d+)\s*>/i
  106.   end
  107. end
  108.  
  109. module RPG
  110.  
  111.   class Actor < BaseItem
  112.    
  113.     def summon_limit
  114.       return @summon_limit unless @summon_limit.nil?
  115.       res = Tsuki::Battle_Summon::Summon_Limit_Regex.match(self.note)
  116.       return @summon_limit = res ? res[1].to_i : 99
  117.     end
  118.   end
  119.  
  120.   class Enemy < BaseItem
  121.    
  122.     def enemy_summons
  123.       return @enemy_summon unless @enemy_summon.nil?
  124.       return @enemy_summon = load_notetags_enemy_summons
  125.     end
  126.  
  127.     def load_notetags_enemy_summons
  128.       summons = []
  129.       self.note.split(/[\r\n]+/).each do |line|
  130.         case line
  131.         when Tsuki::Battle_Summon::Enemy_Summon_Regex
  132.           $1.scan(/\d+/).each {|id| summons << id.to_i}
  133.         end
  134.       end
  135.       return summons
  136.     end
  137.   end
  138.  
  139.   class UsableItem < BaseItem
  140.    
  141.     def summon_id
  142.       return @summon_id unless @summon_id.nil?
  143.       res = Tsuki::Battle_Summon::Summon_ID_Regex.match(self.note)
  144.       return @summon_id = res ? res[1].to_i : 0
  145.     end
  146.   end
  147. end
  148.  
  149. module DataManager
  150.  
  151.   class << self
  152.     alias :tsuki_battle_summon_create_objects :create_game_objects
  153.     alias :tsuki_battle_summon_make_save_contents :make_save_contents
  154.     alias :tsuki_battle_summon_extract_save_contents :extract_save_contents
  155.   end
  156.  
  157.   def self.create_game_objects
  158.     tsuki_battle_summon_create_objects
  159.     $game_summons = Game_Summons.new
  160.   end
  161.  
  162.   def self.make_save_contents
  163.     contents = tsuki_battle_summon_make_save_contents
  164.     contents[:summons]        = $game_summons
  165.     contents
  166.   end
  167.  
  168.   def self.extract_save_contents(contents)
  169.     tsuki_battle_summon_extract_save_contents(contents)
  170.     $game_summons = contents[:summons]
  171.   end
  172. end
  173.  
  174. module BattleManager
  175.   class << self
  176.     alias :tsuki_battle_summon_turn_end :turn_end
  177.     alias :tsuki_battle_summon_gain_exp :gain_exp
  178.     alias :tsuki_battle_summon_battle_end :battle_end
  179.   end
  180.  
  181.   def self.turn_end
  182.     tsuki_battle_summon_turn_end
  183.     $game_summons.update_summons
  184.   end
  185.  
  186.   def self.gain_exp
  187.     tsuki_battle_summon_gain_exp
  188.     $game_summons.battle_members.each do |summon|
  189.       summon.gain_exp($game_troop.exp_total)
  190.     end
  191.     wait_for_message
  192.   end
  193.  
  194.   def self.battle_end(result)
  195.     tsuki_battle_summon_battle_end(result)
  196.     $game_summons.on_battle_end
  197.   end
  198. end
  199.  
  200. class Spriteset_Battle
  201.   def refresh_enemies
  202.     new_enemies = $game_troop.members.reverse.collect do |enemy|
  203.       @enemy_sprites << Sprite_Battler.new(@viewport1, enemy)  if enemy.summoned?
  204.     end
  205.   end
  206. end
  207.  
  208. class Game_System
  209.  
  210.   attr_accessor :summon_only_battle
  211.  
  212.   alias :th_battle_summon_init_system :initialize
  213.   def initialize
  214.     th_battle_summon_init_system
  215.     @summon_only_battle = Tsuki::Battle_Summon::Summon_Only_Battle
  216.   end
  217. end
  218.  
  219. class Game_Action
  220.  
  221.   attr_accessor :summon_id #id of summon to call
  222.  
  223.   alias :th_battle_summon_clear_action :clear
  224.   def clear
  225.     th_battle_summon_clear_action
  226.     @summon_id = 0
  227.   end
  228. end
  229.  
  230. class Game_ActionResult
  231.    
  232.     attr_accessor :called_summon
  233.    
  234.     alias :th_battle_summon_clear_results :clear
  235.     def clear
  236.       th_battle_summon_clear_results
  237.       clear_summon_result
  238.     end
  239.    
  240.     def clear_summon_result
  241.       @called_summon = nil
  242.     end
  243.    
  244.     def called_summon_text
  245.       if @called_summon
  246.         fmt = Tsuki::Battle_Summon::Summon_Message
  247.         sprintf(fmt, @battler.name, @called_summon.name)
  248.       else
  249.         ""
  250.       end
  251.     end
  252.   end
  253.  
  254. class Game_Battler < Game_BattlerBase
  255.  
  256.   def is_summon_action?(item)
  257.     return false unless item
  258.     Tsuki::Battle_Summon.summon_effect?(item)
  259.   end
  260.  
  261.   alias :th_summon_battler_item_apply :item_apply
  262.   def item_apply(user, item)
  263.     th_summon_battler_item_apply(user, item)
  264.     summon_battler(user, item) if is_summon_action?(item)
  265.   end
  266.  
  267.   def summon_battler(user, item)
  268.     called_summon = user.friends_unit.summon_battler(user.actions[0].summon_id)
  269.     if called_summon
  270.       @result.success = true
  271.       @result.called_summon = called_summon
  272.     end
  273.   end
  274. end
  275.  
  276. class Game_Enemy < Game_Battler
  277.    
  278.   attr_accessor :just_summoned
  279.   alias :th_battle_summon_init_enemy :initialize
  280.   def initialize(index, enemy_id)
  281.     th_battle_summon_init_enemy(index, enemy_id)
  282.     @just_summoned = false
  283.     init_summons
  284.   end
  285.  
  286.   def summoned?
  287.     if @just_summoned
  288.       @just_summoned = false
  289.       return true
  290.     end
  291.     return false
  292.   end
  293.  
  294.   def init_summons
  295.     @summons = enemy.enemy_summons
  296.   end
  297.  
  298.   alias :th_battle_summon_make_enemy_actions :make_actions
  299.   def make_actions
  300.     th_battle_summon_make_enemy_actions
  301.     @actions.each do |action|
  302.       make_summon_action(action) if is_summon_action?(action.item)
  303.     end
  304.   end
  305.  
  306.   # pick a random target to draw a random magic from
  307.   def make_summon_action(action)
  308.     action.summon_id = @summons.sample
  309.   end
  310. end
  311.  
  312. class Game_Summon < Game_Actor
  313.  
  314.   attr_reader :summon_id
  315.   attr_accessor :summon_turns
  316.   attr_accessor :summon_index
  317.   def initialize(actor_id)
  318.     super(actor_id)
  319.     @summon_id = actor_id
  320.     @summon_turns = 0
  321.     @summon_index = 0 # 0 if not summoned
  322.     @dupe = false
  323.   end
  324.  
  325.   def can_dupe?
  326.     @dupe
  327.   end
  328.  
  329.   def update_summon
  330. #~     @summon_turns -= 1
  331. #~     if @summon_turns <= 0 || @mp <= 0
  332. #~       $game_summons.unsummon(@summon_id)
  333.     if @mp == 0; add_state(2)
  334.     end
  335.   end
  336.  
  337.   def die
  338.     $game_summons.unsummon(@summon_id)
  339.     super
  340.   end
  341.  
  342.   def index
  343.     $game_summons.members.index(self)
  344.   end
  345. end
  346.  
  347. class Game_Summons < Game_Unit
  348.   include Tsuki::Battle_Summon
  349.  
  350.   def initialize
  351.     @data = [nil]
  352.     @ids = [nil]
  353.     @dispatched = []
  354.     @summon_count = 0 #how many summons are on the field
  355.     @limit = Summon_Limit
  356.     @type_limit = Summon_Type_Limit
  357.     @menu_actor_id = 0
  358.   end
  359.  
  360.   def [](summon_id)
  361.     @data[summon_id] ||= Game_Summon.new(summon_id)
  362.   end
  363.  
  364.   def members
  365.     in_battle ? battle_members : all_summons
  366.   end
  367.  
  368.   def all_summons
  369.     @data.select {|summon| !summon.nil?}
  370.   end
  371.  
  372.   # summons that are currently in battle
  373.   def battle_members
  374.     @dispatched.collect {|id| @data[id]}
  375.   end
  376.    
  377.   def summon_actor(id)
  378.     return if @ids.include?(id)
  379.     summon = Game_Summon.new(id)
  380.     @data[id] = summon
  381.     @ids << id
  382.   end
  383.  
  384.   def unsummon(id)
  385.     return unless @dispatched.include?(id)
  386.     @dispatched.delete_at(@data[id].summon_index - 1)
  387.     @data[id].summon_index = 0
  388.     @summon_count -= 1
  389.   end
  390.  
  391.   def summon(id)
  392.     return 0 unless @data[id]
  393.     @data[id].summon_turns = [Default_Summon_Turns, $game_variables[Summon_Turn_Variable]].max
  394.     @data[id].make_actions
  395.     @summon_count += 1
  396.     @data[id].summon_index = @summon_count
  397.     @dispatched << id
  398.     return id
  399.   end
  400.  
  401.   def can_summon?(summon_id)
  402.     return false if @data[summon_id].nil?
  403.     return false if @summon_count >= @limit
  404.     return false if @dispatched.include?(summon_id) && !@data[summon_id].can_dupe?
  405.     return true
  406.   end
  407.  
  408.   def update_summons
  409.     members.each {|summon| summon.update_summon}
  410.   end
  411.  
  412.   def on_battle_end
  413.     alive_members.each {|summon| summon.remove_state(2) }
  414.     @dispatched = []
  415.     @summon_count = 0
  416.   end
  417.  
  418.   def menu_actor
  419.     @data[@menu_actor_id] || members[0]
  420.   end
  421.  
  422.   def menu_actor=(summon)
  423.     return unless summon
  424.     @menu_actor_id = summon.summon_id
  425.   end
  426.  
  427.   def menu_actor_next
  428.     index = members.index(menu_actor) || -1
  429.     index = (index + 1) % members.size
  430.     self.menu_actor = members[index]
  431.   end
  432.  
  433.   def menu_actor_prev
  434.     index = members.index(menu_actor) || 1
  435.     index = (index + members.size - 1) % members.size
  436.     self.menu_actor = members[index]
  437.   end
  438. end
  439.  
  440. class Game_Party < Game_Unit
  441.   include Tsuki::Battle_Summon
  442.  
  443.   alias tsuki_battle_summon_initialize_party initialize
  444.   def initialize
  445.     tsuki_battle_summon_initialize_party
  446.     @summons = []
  447.   end
  448.  
  449.   alias tsuki_battle_summon_battle_members battle_members
  450.   def battle_members
  451.     summons = $game_summons.battle_members
  452.     if $game_system.summon_only_battle
  453.       summons.empty? ? tsuki_battle_summon_battle_members : summons
  454.     else
  455.       members = tsuki_battle_summon_battle_members
  456.       members.concat(summons)
  457.     end
  458.   end
  459.  
  460.   def summons
  461.     @summons.collect {|id| $game_summons[id]}
  462.   end
  463.  
  464.   # try to call a summon, return summoned_id if successful
  465.   def summon_battler(id)
  466.     return unless $game_summons.can_summon?(id)
  467.     summoned_id = $game_summons.summon(id)
  468.     return $game_summons[summoned_id]
  469.   end
  470.  
  471.   def add_summon(summon_id)
  472.     $game_summons.summon_actor(summon_id)
  473.     @summons.push(summon_id) unless @summons.include?(summon_id)
  474.   end
  475.  
  476.   def remove_summon(summon_id)
  477.     @summons.delete(summon_id)
  478.   end
  479.  
  480.   def clear_summons
  481.     @summons = []
  482.   end
  483.  
  484. end
  485.  
  486. class Game_Troop < Game_Unit
  487.  
  488.   # create a new enemy on the spot
  489.   def summon_battler(enemy_id)
  490.     return unless $data_enemies[enemy_id]
  491.     new_enemy = Game_Enemy.new(@enemies.size, enemy_id)
  492.     new_enemy.just_summoned = true
  493.     new_enemy.screen_x = rand(Graphics.width / 2) + 100
  494.     new_enemy.screen_y = rand(Graphics.height / 2) + 100
  495.     @enemies.push(new_enemy)
  496.     SceneManager.scene.refresh_enemies
  497.     return new_enemy
  498.   end
  499. end
  500.  
  501. class Game_Interpreter
  502.  
  503.   def add_actor_summon(actor_id)
  504.     $game_party.add_summon(actor_id)
  505.   end
  506.    
  507.   def summon_battler(summon_id)
  508.     $game_party.summon_battler(summon_id)
  509.   end
  510. end
  511.  
  512. #==============================================================================
  513. # ** Menu windows and scenes
  514. #==============================================================================
  515.  
  516. class Window_SummonList < Window_Selectable
  517.   #--------------------------------------------------------------------------
  518.   # * Object Initialization
  519.   #--------------------------------------------------------------------------
  520.   def initialize(x, y, width, height)
  521.     super
  522.     @actor = nil
  523.     @data = []
  524.     refresh
  525.   end
  526.   #--------------------------------------------------------------------------
  527.   # * Set Category
  528.   #--------------------------------------------------------------------------
  529.   def actor=(actor)
  530.     return if @actor == actor
  531.     @actor = actor
  532.     refresh
  533.     self.oy = 0
  534.   end
  535.   #--------------------------------------------------------------------------
  536.   # * Get Digit Count
  537.   #--------------------------------------------------------------------------
  538.   def col_max
  539.     return 2
  540.   end
  541.  
  542.   def item_height
  543.     104
  544.   end
  545.   #--------------------------------------------------------------------------
  546.   # * Get Number of Items
  547.   #--------------------------------------------------------------------------
  548.   def item_max
  549.     @data ? @data.size : 1
  550.   end
  551.   #--------------------------------------------------------------------------
  552.   # * Get Item
  553.   #--------------------------------------------------------------------------
  554.   def item
  555.     @data && index >= 0 ? @data[index] : nil
  556.   end
  557.   #--------------------------------------------------------------------------
  558.   # * Get Activation State of Selection Item
  559.   #--------------------------------------------------------------------------
  560.   def current_item_enabled?
  561.     enable?(@data[index])
  562.   end
  563.  
  564.   def enable?(summon)
  565.     summon && !$game_summons.battle_members.include?(summon) && summon.mp > 0
  566.   end
  567.  
  568.   def select_last
  569.     select(0)
  570.   end
  571.  
  572.   def make_item_list(constraint=nil)
  573.     @data = $game_party.summons
  574.     if constraint
  575.       valid_summons = Tsuki::Battle_Summon::Summon_Constraints[constraint] || []
  576.       @data = @data.select {|s| valid_summons.include?(s.summon_id) }
  577.     end
  578.   end
  579.      
  580.   def draw_item(index)
  581.     summon = @data[index]
  582.     if summon
  583.       rect = item_rect(index)
  584.       rect.width -= 4
  585.       draw_summon_basic(summon, rect.x + 4, rect.y, enable?(summon))
  586.       draw_actor_face(summon, rect.x + rect.width - 96, rect.y)
  587.     end
  588.   end
  589.  
  590.   def draw_summon_name(summon, x, y, enabled, width = 112)
  591.     change_color(normal_color, enabled)
  592.     draw_text(x, y, width, line_height, summon.name)
  593.   end
  594.  
  595.   def draw_summon_basic(summon, x, y, enabled=true, width=172)
  596.     return unless summon
  597.     text_width = text_size(summon.name).width
  598.     draw_summon_name(summon, x, y + line_height*0, enabled)
  599.     draw_actor_level(summon, x, y + line_height*1)
  600.     draw_actor_hp(summon, x, y + line_height*2)
  601.     draw_actor_mp(summon, x, y + line_height*3)
  602.   end
  603.  
  604.   def update_help
  605.     @help_window.set_item(item)
  606.   end
  607.  
  608.   def refresh(constraint=nil)
  609.     make_item_list(constraint)
  610.     create_contents
  611.     draw_all_items
  612.   end
  613. end
  614.  
  615. class Window_SummonCommand < Window_HorzCommand
  616.  
  617.   def window_width
  618.     Graphics.width
  619.   end
  620.  
  621.   def make_command_list
  622.     add_command("Equip", :equip)
  623.     add_command("Skill", :skill)
  624.     add_command("Status", :status)
  625.   end
  626. end
  627.  
  628. class Scene_Summons  < Scene_MenuBase
  629.  
  630.   def start
  631.     super
  632.     create_summon_command
  633.     create_summon_window
  634.   end
  635.  
  636.   def create_summon_command
  637.     @summon_command = Window_SummonCommand.new(0, 0)
  638.     @summon_command.set_handler(:cancel, method(:return_scene))
  639.     @summon_command.set_handler(:equip, method(:command_personal))
  640.     @summon_command.set_handler(:skill, method(:command_personal))
  641.     @summon_command.set_handler(:status, method(:command_personal))
  642.   end
  643.  
  644.   def create_summon_window
  645.     wy = @summon_command.height
  646.     width = Graphics.width
  647.     height = Graphics.height - wy
  648.     @summon_window = Window_SummonList.new(0, wy, width, height)
  649.   end
  650.  
  651.   def command_personal
  652.     @summon_window.select_last
  653.     @summon_window.activate
  654.     @summon_window.set_handler(:ok,     method(:on_personal_ok))
  655.     @summon_window.set_handler(:cancel, method(:on_personal_cancel))
  656.   end
  657.  
  658.   def on_personal_ok
  659.     $game_summons.menu_actor = @summon_window.item
  660.     case @summon_command.current_symbol
  661.     when :equip
  662.       SceneManager.call(Scene_SummonEquip)
  663.     when :skill
  664.       SceneManager.call(Scene_SummonSkill)
  665.     when :status
  666.       SceneManager.call(Scene_SummonStatus)
  667.     end
  668.   end
  669.  
  670.   def on_personal_cancel
  671.     @summon_window.unselect
  672.     @summon_command.activate
  673.   end
  674. end
  675.  
  676. class Scene_SummonSkill < Scene_Skill
  677.  
  678.   def start
  679.     super
  680.     @actor = $game_summons.menu_actor
  681.     on_actor_change
  682.   end
  683.  
  684.   def next_actor
  685.     @actor = $game_summons.menu_actor_next
  686.     on_actor_change
  687.   end
  688.  
  689.   def prev_actor
  690.     @actor = $game_summons.menu_actor_prev
  691.     on_actor_change
  692.   end
  693. end
  694.  
  695. class Scene_SummonEquip < Scene_Equip
  696.  
  697.   def start
  698.     super
  699.     @actor = $game_summons.menu_actor
  700.     on_actor_change
  701.   end
  702.  
  703.   def next_actor
  704.     @actor = $game_summons.menu_actor_next
  705.     on_actor_change
  706.   end
  707.  
  708.   def prev_actor
  709.     @actor = $game_summons.menu_actor_prev
  710.     on_actor_change
  711.   end
  712. end
  713.  
  714. class Scene_SummonStatus < Scene_Status
  715.  
  716.   def start
  717.     super
  718.     @actor = $game_summons.menu_actor
  719.     on_actor_change
  720.   end
  721.  
  722.   def next_actor
  723.     @actor = $game_summons.menu_actor_next
  724.     on_actor_change
  725.   end
  726.  
  727.   def prev_actor
  728.     @actor = $game_summons.menu_actor_prev
  729.     on_actor_change
  730.   end
  731. end
  732.  
  733. #==============================================================================
  734. # ** Battle windows and scenes
  735. #==============================================================================
  736.  
  737. class Window_BattleSummon < Window_SummonList
  738.  
  739.   def initialize(help_window, info_viewport)
  740.     y = 0
  741.     super(0, y, Graphics.width, info_viewport.rect.y - y)
  742.     self.visible = false
  743.     @help_window = help_window
  744.     @info_viewport = info_viewport
  745.     select(0)
  746.   end
  747.  
  748.   def enable?(summon)
  749.     summon && $game_summons.can_summon?(summon.summon_id) && summon.mp > 0
  750.   end
  751. end
  752.  
  753. class Window_BattleStatus < Window_Selectable
  754.  
  755.   def content_height
  756.     $game_party.battle_members.size * line_height - standard_padding * 2
  757.   end
  758.  
  759.   alias tsuki_battle_summon_status_refresh refresh
  760.   def refresh
  761.     create_contents
  762.     tsuki_battle_summon_status_refresh
  763.   end
  764. end
  765.  
  766. class Scene_Battle < Scene_Base
  767.  
  768.   def refresh_enemies
  769.     @spriteset.refresh_enemies
  770.   end
  771.  
  772.   alias :battle_summon_create_battle_windows :create_all_windows
  773.   def create_all_windows
  774.     battle_summon_create_battle_windows
  775.     create_summon_window
  776.   end
  777.  
  778.   def create_summon_window
  779.     @summon_window = Window_BattleSummon.new(@help_window, @info_viewport)
  780.     @summon_window.set_handler(:ok,     method(:on_summon_ok))
  781.     @summon_window.set_handler(:cancel, method(:on_summon_cancel))
  782.   end
  783.  
  784.   alias :th_battle_summon_on_skill_ok :on_skill_ok
  785.   def on_skill_ok
  786.     @skill = @skill_window.item
  787.     if Tsuki::Battle_Summon.summon_effect?(@skill)
  788.       BattleManager.actor.input.set_skill(@skill.id)
  789.       BattleManager.actor.last_skill.object = @skill
  790.       @skill_window.hide
  791.       if @skill.summon_id > 0
  792.         BattleManager.actor.input.summon_id = @skill.summon_id
  793.         next_command
  794.       else
  795.         activate_summon_window([:skill, @skill.id])
  796.       end
  797.     else
  798.       th_battle_summon_on_skill_ok
  799.     end
  800.   end
  801.  
  802.   alias :th_battle_summon_on_item_ok :on_item_ok
  803.   def on_item_ok
  804.     @item = @item_window.item
  805.     if Tsuki::Battle_Summon.summon_effect?(@item)
  806.       BattleManager.actor.input.set_item(@item.id)
  807.       $game_party.last_item.object = @item
  808.       @item_window.hide
  809.       if @item.summon_id > 0
  810.         BattleManager.actor.input.summon_id = @skill.summon_id
  811.         next_command
  812.       else
  813.         activate_summon_window([:item, @item.id])
  814.       end
  815.     else
  816.       th_battle_summon_on_item_ok
  817.     end
  818.   end
  819.  
  820.   def command_summon
  821.     activate_summon_window
  822.   end
  823.  
  824.   def on_summon_ok
  825.     BattleManager.actor.input.summon_id = @summon_window.item.summon_id
  826.     @summon_window.hide
  827.     next_command
  828.   end
  829.  
  830.   def on_summon_cancel
  831.     @summon_window.hide
  832.     @skill_window.show.activate if @skill
  833.     @item_window.show.activate if @item
  834.   end
  835.  
  836.   def activate_summon_window(constraint=nil)
  837.     @summon_window.refresh(constraint)
  838.     @summon_window.show.activate
  839.   end
  840. end
  841.  
  842. class Window_BattleLog < Window_Selectable
  843.    
  844.   alias :th_battle_summon_display_damage :display_damage
  845.   def display_damage(target, item)
  846.     th_battle_summon_display_damage(target, item)
  847.     display_summon_results(target, item)
  848.   end
  849.  
  850.   def display_summon_results(target, item)
  851.     return unless target.result.called_summon && Tsuki::Battle_Summon.summon_effect?(item)
  852.     add_text(target.result.called_summon_text)
  853.     wait
  854.   end
  855. end
  856.  
  857. #==============================================================================
  858. # ** Update menu scene to add option
  859. #==============================================================================
  860.  
  861. class Window_MenuCommand < Window_Command
  862.   #--------------------------------------------------------------------------
  863.   # * Add arena command to List
  864.   #--------------------------------------------------------------------------
  865.   alias tsuki_summons_commands add_main_commands
  866.   def add_main_commands
  867.     tsuki_summons_commands
  868.     add_command("Summons", :summons)
  869.   end
  870. end
  871.  
  872. class Scene_Menu < Scene_MenuBase
  873.   #--------------------------------------------------------------------------
  874.   # * Add arena handler
  875.   #--------------------------------------------------------------------------
  876.   alias tsuki_summons_command_window create_command_window
  877.   def create_command_window
  878.     tsuki_summons_command_window
  879.     @command_window.set_handler(:summons, method(:command_summons))
  880.   end
  881.  
  882.   def command_summons
  883.     SceneManager.call(Scene_Summons)
  884.   end
  885. end
  886.  
  887. #==============================================================================
  888. # ** Compatibility mods
  889. #==============================================================================
  890. if $imported["FP_InventoryPlus"]
  891.  
  892.   class Scene_Battle < Scene_Base
  893.    
  894.     # directly use item from inventory
  895.     def on_item_ok      
  896.       @item = @item_window.item
  897.       if Tsuki::Battle_Summon.summon_effect?(@item)
  898.         BattleManager.actor.input.set_item(@item)
  899.         $game_party.last_item.object = @item
  900.         @item_window.hide
  901.         if @item.summon_id > 0
  902.           BattleManager.actor.input.summon_id = @item.summon_id
  903.           next_command
  904.         else
  905.           activate_summon_window([:item, @item.id])
  906.         end
  907.       else
  908.         th_battle_summon_on_item_ok
  909.       end
  910.     end
  911.   end
  912. end
  913.  
  914. if $imported["Tsuki_CommandSetup"]
  915.  
  916.   class Scene_Battle < Scene_Base
  917.     alias :th_battle_summon_command_use_skill :command_use_skill
  918.     def command_use_skill
  919.       @skill = $data_skills[@actor_command_window.current_data[:ext]]
  920.       if Tsuki::Battle_Summon.summon_effect?(@skill)
  921.         BattleManager.actor.input.set_skill(@skill.id)
  922.         BattleManager.actor.last_skill.object = @skill
  923.         @skill_window.hide
  924.         if @skill.summon_id > 0
  925.           BattleManager.actor.input.summon_id = @skill.summon_id
  926.           next_command
  927.         else
  928.           activate_summon_window([:skill, @skill.id])
  929.         end
  930.       else
  931.         th_battle_summon_command_use_skill
  932.       end
  933.     end      
  934.    
  935.     def on_summon_cancel
  936.       @enemy_draw_window.hide
  937.       if @skill == $data_skills[@actor_command_window.current_data[:ext]]
  938.         @actor_command_window.activate
  939.       else
  940.         @summon_window.hide
  941.         @skill_window.show.activate
  942.       end
  943.     end
  944.   end
  945. end
  946. #==============================================================================
  947. # ** Add-ons
  948. #==============================================================================
  949. if Tsuki::Battle_Summon::Monster_Hunter_Addon
  950.   if $imported["Tsuki_MonsterHunter"]
  951.     module Monster_Hunter
  952.       def self.create_game_actor(actor_id)
  953.         return if $BTEST
  954.         $game_summons.summon_actor(actor_id)
  955.       end
  956.     end
  957.   else
  958.     msgbox("Monster Hunter must placed above this script")
  959.   end
  960. end