Advertisement
Vlue

Pets and Summons Compat

Jun 6th, 2014
7,256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 14.01 KB | None | 0 0
  1. #Pets and Summons (Compatibility) v1.6a
  2. #----------#
  3. #Features: Allows you to set skills that summons pets (actors) into battle, which
  4. #           can last for the duration of the battle, until dead, or by timer.
  5. #
  6. #Usage:    Plug and play, Customize as needed
  7. #           Skill/Item Notetag:
  8. #            <SUMMON actor_id, timer, level_bonus (optional)>
  9. #           Set timer to 0 to not use it.
  10. #           level_bonus is change in pet level from the actor
  11. #
  12. #            <BIG_SUMMON actor_id, timer, level_bonus>
  13. #           Same as above, but replaces party for duration
  14. #            <MED_SUMMON actor_id, timer, level_bonus>
  15. #           Same as above, but replaces actor for duration
  16. #
  17. #            <DISMISS>
  18. #           Dismisses the user of the command, only works on pets/summons
  19. #
  20. #----------#
  21. #-- Script by: V.M of D.T
  22. #
  23. #- Questions or comments can be:
  24. #    given by email: sumptuaryspade@live.ca
  25. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  26. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  27. #
  28. #--- Free to use in any project, commercial or non-commercial, with credit given
  29. # - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  30.  
  31. #Maximum number of pets one actor can have:
  32. MAX_PETS = 3
  33.  
  34. #Script overides max number of actors in battle, reset here:
  35. MAX_BATTLE_MEMBERS = 4
  36.  
  37. #Message played when certain pet is summoned:
  38. # actor_id => "message"
  39. SUMMON_MESSAGES = {
  40.   2 => "A large wolf joins the fray!",
  41.   7 => "Transformed into a dragon!!!"
  42. }
  43. #Message played when pets timer runs out:
  44. RETREAT_MESSAGES = {
  45.   2 => "A large wolf retreats into the shadows.",
  46.   7 => "A large wolf retreats into the shadows."
  47. }
  48. #Message played when pet dies:
  49. DEATH_MESSAGES = {
  50.   2 => "A large wolf has died!",
  51.   7 => "A large wolf has died!"
  52. }
  53.  
  54. $imported = {} if $imported.nil?
  55. class Game_Battler < Game_BattlerBase
  56.   attr_accessor  :pets
  57.   alias pet_init initialize
  58.   alias pet_iue item_user_effect
  59.   alias pet_obe on_battle_end
  60.   def initialize(*args)
  61.     pet_init(*args)
  62.     @hp = 1
  63.     @pets = []
  64.   end
  65.   def add_pet(actor_id, timer = -1, level = 0)
  66.   end
  67.   def remove_pet(index)
  68.     @pets[index] = nil
  69.     @pets.compact!
  70.   end
  71.   def remove_pets_by_state
  72.     iter = 0
  73.     @pets.each do |pet|
  74.       if pet.hp <= 0
  75.         remove = true
  76.         if DEATH_MESSAGES[pet.actor_id]
  77.           SceneManager.scene.log_window.add_text(DEATH_MESSAGES[pet.actor_id])
  78.           SceneManager.scene.log_window.wait
  79.           SceneManager.scene.status_window.refresh
  80.         end
  81.       elsif pet.timer == 0 || self.hp <= 0
  82.         remove = true
  83.         if RETREAT_MESSAGES[pet.actor_id]
  84.           SceneManager.scene.log_window.add_text(RETREAT_MESSAGES[pet.actor_id])
  85.           SceneManager.scene.log_window.wait
  86.           SceneManager.scene.status_window.refresh
  87.         end
  88.       end
  89.       @pets[iter] = nil if remove
  90.       iter += 1
  91.     end
  92.     SceneManager.scene.reset_actor_sprites
  93.     SceneManager.scene.log_window.wait_and_clear
  94.     @pets.compact!
  95.   end
  96.   def item_user_effect(user, item)
  97.     pet_iue(user, item)
  98.     if item.big_summons
  99.       temp_replace_party(item.big_summons)
  100.       @result.success = true
  101.       SceneManager.scene.log_window.wait
  102.       SceneManager.scene.log_window.wait_and_clear
  103.     elsif item.med_summons
  104.       temp_replace_actor(item.med_summons[0])
  105.       @result.success = true
  106.       SceneManager.scene.log_window.wait
  107.       SceneManager.scene.log_window.wait_and_clear
  108.     elsif item.summons
  109.       item.summons.each do |array|
  110.         if self.pets.size >= MAX_PETS
  111.             remove_pet(0)
  112.         end
  113.         add_pet(array[0],array[1],array[2])
  114.         @result.success = true
  115.       end
  116.       SceneManager.scene.log_window.wait
  117.       SceneManager.scene.log_window.wait_and_clear
  118.     elsif item.dismiss && self.is_a?(Game_Pet)
  119.       @timer = 0
  120.       return if $game_party.restore_party
  121.       return if restore_actor
  122.       $game_actors[@ori_actor].remove_pets_by_state
  123.     end
  124.   end
  125.   def on_battle_end
  126.     @pets = []
  127.     pet_obe
  128.   end
  129.   def temp_replace_actor(array)
  130.   end
  131.   def temp_replace_party(array)
  132.   end
  133.   def summon_pet(array)
  134.   end
  135. end
  136.  
  137. class Game_Actors
  138.   def [](actor_id)
  139.     actor_id = 1 if actor_id.nil?
  140.     return nil unless $data_actors[actor_id]
  141.     @data[actor_id] ||= Game_Actor.new(actor_id)
  142.   end
  143. end
  144.  
  145. class Game_Actor < Game_Battler
  146.   attr_accessor  :actor_id
  147.   attr_accessor  :origin_x
  148.   attr_accessor  :origin_y
  149.   def add_pet(actor_id, timer = -1, level = 0)
  150.     if level
  151.       @pets.push(Game_Pet.new(actor_id,timer,@level + level))
  152.     else
  153.       @pets.push(Game_Pet.new(actor_id,timer,false))
  154.     end
  155.     @pets[-1].set_ori(@actor_id)
  156.     @pets[-1].set_position(@pets.size)
  157.     return unless SceneManager.scene.is_a?(Scene_Battle)
  158.     if SUMMON_MESSAGES[actor_id]
  159.       SceneManager.scene.log_window.add_text(SUMMON_MESSAGES[actor_id])
  160.       SceneManager.scene.log_window.wait
  161.       SceneManager.scene.status_window.refresh
  162.     end
  163.     SceneManager.scene.reset_actor_sprites
  164.   end
  165.   def temp_replace_actor(array)
  166.     $game_party.temp_replace_actor(self, array)
  167.   end
  168.   def temp_replace_party(array)
  169.     $game_party.temp_replace_party(self, array)
  170.   end
  171.   def summon_pet(array)
  172.     $game_party.summon_pet(self, array)
  173.   end
  174.   def restore_actor
  175.     return false
  176.   end
  177.   alias pets_on_battle_end on_battle_end
  178.   def on_battle_end
  179.     restore_actor
  180.     pets_on_battle_end
  181.   end
  182. end
  183.  
  184. class Game_Pet < Game_Actor
  185.   attr_accessor  :timer
  186.   attr_accessor  :actor_id
  187.   attr_accessor  :former_actor
  188.   def initialize(actor_id, timer, level_bonus, former_actor = nil)
  189.     super(actor_id)
  190.     @timer = timer
  191.     @timer -= 1 if @timer == 0
  192.     if level_bonus
  193.       @level = [[@level + level_bonus,1].max,99].min
  194.     end
  195.     @former_actor = former_actor
  196.     if @former_actor && @formation_slot
  197.       @formation_slot = $game_actors[@former_actor].formation_slot
  198.     end
  199.     @ori_actor = nil
  200.     init_skills
  201.     recover_all
  202.     clear_actions
  203.   end
  204.   def set_ori(id)
  205.     @ori_actor = id
  206.   end
  207.   def sprite
  208.     @sprite = Sprite_Battler.new(nil) if @sprite.nil?
  209.     @sprite
  210.   end
  211.   def on_turn_end
  212.     super
  213.     @timer -= 1
  214.     if @former_actor
  215.       if @hp <= 0 || @timer == 0
  216.         return if $game_party.restore_party
  217.         $game_party.restore_actor(self, former_actor)
  218.       end
  219.     end
  220.   end
  221.   def restore_actor
  222.     return false unless @former_actor
  223.     $game_party.restore_actor(self, former_actor)
  224.     return true
  225.   end
  226.   def screen_x
  227.     return super if $imported["YES-BattleSymphony"]
  228.     return super unless @ori_actor
  229.     $game_actors[@ori_actor].screen_x + 12
  230.   end
  231.   def screen_y
  232.     return super if $imported["YES-BattleSymphony"]
  233.     return super unless @ori_actor
  234.     $game_actors[@ori_actor].screen_y + 12
  235.   end
  236.   def use_sprite?
  237.     true
  238.   end
  239.   def correct_origin_position
  240.     return if @origin_x && @origin_y
  241.     @origin_x = @screen_x = $game_actors[@ori_actor].origin_x + position_offset[0]
  242.     @origin_y = @screen_y = $game_actors[@ori_actor].origin_y + position_offset[1]
  243.     return unless emptyview?
  244.     @origin_x = @screen_x = @destination_x = self.screen_x
  245.     @origin_y = @screen_y = @destination_y = self.screen_y
  246.   end
  247.   def set_position(id)
  248.     @position = id
  249.   end
  250.   def position_offset
  251.     offset = [0,0]
  252.     return offset unless @position
  253.     @position < 3 ? offset[0] = 12 : offset[0] = -12
  254.     @position % 2 == 0 ? offset[1] = -12 : offset[1] = 12
  255.     offset
  256.   end
  257. end
  258.  
  259. class RPG::UsableItem
  260.   def summons
  261.     return false unless self.note.index("<SUMMON")
  262.     notes = self.note.clone
  263.     summon_array = []
  264.     while notes =~ /<SUMMON (\d+), ((\d+)|(\d+), ((\d+)|(-\d+)))>/
  265.       if $2.include?(",")
  266.         array = [$1.to_i] + $2.split(",").map {|s| s.to_i}
  267.       else
  268.         array = [$1.to_i,$2.to_i,false]
  269.       end
  270.       summon_array.push(array)
  271.       notes[notes.index("SUMMON")] = "N"
  272.     end
  273.     summon_array
  274.   end
  275.   def med_summons
  276.     return false unless self.note.index("<MED_SUMMON")
  277.     notes = self.note.clone
  278.     summon_array = []
  279.     while notes =~ /<MED_SUMMON (\d+), (\d+), (\d+)>/
  280.       summon_array.push([$1.to_i,$2.to_i,$3.to_i])
  281.       notes[notes.index("MED_SUMMON")] = "N"
  282.     end
  283.     summon_array
  284.   end
  285.   def big_summons
  286.     return false unless self.note.index("<BIG_SUMMON")
  287.     notes = self.note.clone
  288.     summon_array = []
  289.     while notes =~ /<BIG_SUMMON (\d+), (\d+), (\d+)>/
  290.       summon_array.push([$1.to_i,$2.to_i,$3.to_i])
  291.       notes[notes.index("BIG_SUMMON")] = "N"
  292.     end
  293.     summon_array
  294.   end
  295.   def dismiss
  296.     self.note.index("<DISMISS>")
  297.   end
  298. end
  299.  
  300. class Scene_Battle
  301.   attr_accessor  :log_window
  302.   attr_accessor  :status_window
  303.   def turn_start
  304.     @party_command_window.close
  305.     @actor_command_window.close
  306.     @status_window.unselect
  307.     @subject =  nil
  308.     BattleManager.turn_start
  309.     @log_window.wait
  310.     @log_window.clear
  311.   end
  312.   def turn_end
  313.     all_battle_members.each do |battler|
  314.       battler.on_turn_end
  315.       refresh_status
  316.       @log_window.display_auto_affected_status(battler)
  317.       @log_window.wait_and_clear
  318.       battler.remove_pets_by_state
  319.     end
  320.     BattleManager.turn_end
  321.     process_event
  322.     start_party_command_selection
  323.     return unless $imported["YEA-BattleEngine"]
  324.     return unless YEA::BATTLE::SKIP_PARTY_COMMAND
  325.     if BattleManager.input_start
  326.       @party_command_window.deactivate
  327.       command_fight
  328.     else
  329.       @party_command_window.deactivate
  330.       turn_start
  331.     end
  332.   end
  333.   def reset_actor_sprites
  334.     @spriteset.dispose_actors
  335.     @spriteset.create_actors
  336.   end
  337.   def prompt_ftb_action?(actor)
  338.     return false unless $imported["YEA-BattleEngine"]
  339.     return false unless $imported["YEA-BattleSystem-FTB"]
  340.     return false unless BattleManager.btype?(:ftb)
  341.     return false unless actor.current_action
  342.     return actor.current_action.valid?
  343.   end
  344. end
  345.  
  346. class Scene_Base
  347.   def reset_actor_sprites
  348.   end
  349. end
  350.  
  351. class Game_Party
  352.   def pets
  353.     pet = []
  354.     self.pets_battle_members.each do |actor|
  355.       pet += actor.pets
  356.     end
  357.     pet.compact
  358.   end
  359.   def pets_nr
  360.     pet = []
  361.     all_members.each do |actor|
  362.       next unless actor && actor.pets
  363.       pet += actor.pets
  364.     end
  365.     pet.compact
  366.   end
  367.   alias pets_battle_members battle_members
  368.   def battle_members
  369.     pets_battle_members + pets
  370.   end
  371.   def temp_replace_actor(actor, array)
  372.     if SUMMON_MESSAGES[array[0]]
  373.       SceneManager.scene.log_window.add_text(SUMMON_MESSAGES[array[0]])
  374.       SceneManager.scene.log_window.wait
  375.       SceneManager.scene.status_window.refresh
  376.     end
  377.     $game_actors.set_pet(array[0],Game_Pet.new(array[0],array[1],actor.level + array[2],actor.actor_id))
  378.     @actors[actor.index] = array[0]
  379.     SceneManager.scene.reset_actor_sprites
  380.   end
  381.   def restore_actor(pet, actor_id)
  382.     @actors[pet.index] = actor_id
  383.     SceneManager.scene.reset_actor_sprites
  384.   end
  385.   def temp_replace_party(actor, arrays)
  386.     @actors_sideline = @actors.clone
  387.     @actors = []
  388.     arrays.each do |array|
  389.       $game_actors.set_pet(array[0],Game_Pet.new(array[0],array[1],actor.level + array[2],actor.actor_id))
  390.       add_actor(array[0])
  391.     end
  392.     SceneManager.scene.reset_actor_sprites
  393.   end
  394.   def restore_party
  395.     return false unless @actors_sideline
  396.     @actors = @actors_sideline.clone
  397.     @actors_sideline = nil
  398.     SceneManager.scene.reset_actor_sprites
  399.     $game_player.refresh
  400.     return true
  401.   end
  402.   def on_battle_end
  403.     restore_party_end
  404.     super
  405.   end
  406.   def restore_party_end
  407.     members.each do |pet|
  408.       pet.restore_actor
  409.       MAX_PETS.times do |i|
  410.         pet.remove_pet(0)
  411.       end
  412.     end
  413.     SceneManager.scene.reset_actor_sprites
  414.   end
  415.   def max_battle_members
  416.     return MAX_BATTLE_MEMBERS + pets_nr.size
  417.   end
  418. end
  419.  
  420. class Game_Actors
  421.   def set_pet(id, pet)
  422.     @data[id] = pet
  423.   end
  424. end
  425.  
  426. class Window_BattleStatus < Window_Selectable
  427.   alias pets_yan_refresh refresh
  428.   alias pets_yan_draw_item draw_item
  429.   def refresh
  430.     return pets_yan_refresh if !$imported["YEA-BattleEngine"].nil?
  431.     contents.dispose
  432.     self.contents = Bitmap.new(self.width-24,line_height*item_max)
  433.     contents.clear
  434.     draw_all_items
  435.   end
  436.   def item_max
  437.     $game_party.members.size
  438.   end
  439.   def battle_members; return $game_party.members; end
  440.   def draw_item(index)
  441.     return pets_yan_draw_item(index) if !$imported["YEA-BattleEngine"].nil?
  442.     return unless index
  443.     actor = $game_party.members[index]
  444.     draw_basic_area(basic_area_rect(index), actor)
  445.     draw_gauge_area(gauge_area_rect(index), actor)
  446.   end
  447. end
  448.  
  449. module BattleManager
  450.   class << self
  451.     alias pets_process_victory process_victory
  452.   end
  453.   def self.process_defeat
  454.     return false if $game_party.restore_party
  455.     $game_party.members.each do |actor|
  456.       return false if actor.restore_actor
  457.     end
  458.     $game_message.add(sprintf(Vocab::Defeat, $game_party.name))
  459.     wait_for_message
  460.     if @can_lose
  461.       revive_battle_members
  462.       replay_bgm_and_bgs
  463.       SceneManager.return
  464.     else
  465.       SceneManager.goto(Scene_Gameover)
  466.     end
  467.     battle_end(2)
  468.     return true
  469.   end
  470.   def self.process_victory
  471.     $game_party.restore_party
  472.     $game_party.restore_party_end
  473.     pets_process_victory
  474.   end
  475. end
  476.  
  477. if $imported["DoubleX RMVXA Unison Item"]
  478. class Game_Actors
  479.  
  480.   #----------------------------------------------------------------------------|
  481.   #  Rewrite method: []                                                        |
  482.   #----------------------------------------------------------------------------|
  483.   def [](actor_id)
  484.     return nil unless $data_actors[actor_id]
  485.     # This part is added by this snippet to return game pets instead of game actors
  486.     if !@data[actor_id] && SceneManager.scene_is?(Scene_Battle) && $game_party && $game_party.pets
  487.       $game_party.pets.each { |pet| return pet if pet.id == actor_id }
  488.     end
  489.     #
  490.     @data[actor_id] ||= Game_Actor.new(actor_id)
  491.   end # []
  492.  
  493. end # Game_Actors
  494. end # $imported["DoubleX RMVXA Unison Item"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement