khanhdu

Battle Summons

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