KK20

8 hero party

Jan 11th, 2019
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 19.33 KB | None | 0 0
  1. #==============================================================================
  2. # ** 8_Hero_Party - by cockroach
  3. #------------------------------------------------------------------------------
  4. #  This script is meant to permit 8 heroes in the party.
  5. #  The heroes will appear in every instance of the game and show up properly,
  6. #  but in many cases it may look crowded. (Specially in the default Battle System)
  7. #  This is why this goes best with another type of battle system.
  8. #  If anyone wants to use even more than 8 heroes, all necessary changes are in
  9. #  this script, and it is a very easy thing to alter.
  10. #
  11. #  All you need to do is adding heroes to the party normally, no custom script
  12. #  call is necessary.
  13. #
  14. #  (This very simple script is free for usage and edition, in any type of game.)
  15. #==============================================================================
  16. #==============================================================================
  17. # Alterations in Game_Actor
  18. #==============================================================================
  19. class Game_Actor
  20.   def screen_x
  21.     return 0 if self.index.nil?
  22.     # Return after calculating x-coordinate by order of members in party
  23.     p_size = [$game_party.actors.size, 4].max
  24.     self.index * (640 / p_size) + (320 / p_size)  
  25.   end
  26. end
  27. #==============================================================================
  28. # Alterations in Game_Party
  29. #==============================================================================
  30. class Game_Party  
  31.   #--------------------------------------------------------------------------  
  32.   # * Add an Actor  
  33.   # actor_id : actor ID  
  34.   #--------------------------------------------------------------------------
  35.   def add_actor(actor_id)
  36.     # Get actor
  37.     actor = $game_actors[actor_id]
  38.     # If the party has less than 8 members and this actor is not in the party
  39.     if @actors.size < 8 && !@actors.include?(actor)
  40.       # Add actor
  41.       @actors.push(actor)
  42.       # Refresh player
  43.       $game_player.refresh
  44.     end
  45.   end
  46.   #--------------------------------------------------------------------------  
  47.   # * Random Selection of Target Actor  
  48.   # hp0 : limited to actors with 0 HP  
  49.   #--------------------------------------------------------------------------
  50.   def random_target_actor(hp0 = false)
  51.     # Initialize roulette
  52.     roulette = []
  53.     # Loop
  54.     for actor in @actors
  55.       # If it fits the conditions
  56.       if (!hp0 && actor.exist?) || (hp0 && actor.hp0?)
  57.         # Get actor class [position]
  58.         position = $data_classes[actor.class_id].position / 2
  59.         # Front guard: n = 4; Mid guard: n = 3; Rear guard: n = 2
  60.         n = 4 - position
  61.         n = 1 if n == 0
  62.         # Add actor to roulette n times
  63.         n.times { roulette.push(actor) }
  64.       end
  65.     end
  66.     # If roulette size is 0
  67.     return nil if roulette.size == 0
  68.     # Spin the roulette, choose an actor
  69.     roulette[rand(roulette.size)]  
  70.   end
  71. end
  72. #==============================================================================
  73. # Alterations in Window_MenuStatus
  74. #==============================================================================
  75. class Window_MenuStatus < Window_Selectable  
  76.   #--------------------------------------------------------------------------  
  77.   # * Refresh  
  78.   #--------------------------------------------------------------------------
  79.   def refresh
  80.     self.contents.clear
  81.     @item_max = $game_party.actors.size
  82.     for i in 0...$game_party.actors.size
  83.       x = 64
  84.       if @item_max > 5
  85.         y = i * (455 / @item_max)
  86.       else
  87.         y = i * 76.5
  88.       end
  89.       actor = $game_party.actors[i]
  90.       draw_actor_graphic(actor, x - 40, y + 47)
  91.       draw_actor_name(actor, x, y - 9)
  92.       draw_actor_class(actor, x + 144, y - 9)
  93.       draw_actor_level(actor, x, y + 7)
  94.       draw_actor_state(actor, x + 90, y + 7)
  95.       draw_actor_exp(actor, x, y + 23)
  96.       draw_actor_hp(actor, x + 236, y + 7)
  97.       draw_actor_sp(actor, x + 236, y + 23)
  98.     end  
  99.   end  
  100.   #--------------------------------------------------------------------------  
  101.   # * Cursor Rectangle Update  
  102.   #--------------------------------------------------------------------------
  103.   def update_cursor_rect
  104.     if @index < 0
  105.       self.cursor_rect.empty
  106.     else
  107.       if @item_max > 5
  108.         y = @index * (455 / @item_max) - 3
  109.       else
  110.         y = @index * 76.5 - 3
  111.       end
  112.       self.cursor_rect.set(0, y, self.width - 32, 52)
  113.     end  
  114.   end
  115. end
  116. #==============================================================================
  117. # Alterations in Window_Target
  118. #==============================================================================
  119. class Window_Target < Window_Selectable  
  120.   #--------------------------------------------------------------------------  
  121.   # * Refresh  
  122.   #--------------------------------------------------------------------------  
  123.   def refresh
  124.     self.contents.clear
  125.     for i in 0...$game_party.actors.size
  126.       x = 4
  127.       y = i * 55
  128.       actor = $game_party.actors[i]
  129.       draw_actor_name(actor, x, y)
  130.       draw_actor_class(actor, x + 144, y)
  131.       draw_actor_level(actor, x + 8, y + 16)
  132.       draw_actor_state(actor, x + 8, y + 32)
  133.       draw_actor_hp(actor, x + 152, y + 16)
  134.       draw_actor_sp(actor, x + 152, y + 32)
  135.     end
  136.   end  
  137.   #--------------------------------------------------------------------------  
  138.   # * Cursor Rectangle Update  
  139.   #--------------------------------------------------------------------------  
  140.   def update_cursor_rect
  141.     # Cursor position -1 = all choices, -2 or lower = independent choice
  142.     # (meaning the user's own choice)
  143.     if @index <= -2
  144.       self.cursor_rect.set(0, (@index + 10) * 55 + 6, self.width - 32, 48)
  145.     elsif @index == -1
  146.       self.cursor_rect.set(0, 0, self.width - 32 + 6, @item_max * 58 - 20)
  147.     else
  148.       self.cursor_rect.set(0, @index * 55 + 6, self.width - 32, 52)
  149.     end  
  150.   end
  151. end
  152. #==============================================================================
  153. # Alterations in Window_SaveFile
  154. #==============================================================================
  155. class Window_SaveFile < Window_Base  
  156.   #--------------------------------------------------------------------------  
  157.   # * Refresh  
  158.   #--------------------------------------------------------------------------  
  159.   def refresh
  160.     self.contents.clear
  161.     # Draw file number
  162.     self.contents.font.color = normal_color
  163.     name = "File#{@file_index + 1}"
  164.     self.contents.draw_text(4, 0, 600, 32, name)
  165.     @name_width = contents.text_size(name).width
  166.     # If save file exists
  167.     if @file_exist
  168.       # Draw character
  169.       for i in 0...@characters.size
  170.         bitmap = RPG::Cache.character(@characters[i][0], @characters[i][1])
  171.         cw = bitmap.rect.width / 4
  172.         ch = bitmap.rect.height / 4
  173.         src_rect = Rect.new(0, 0, cw, ch)
  174.         x = 275 - @characters.size * 24 + i * 48 - cw / 2
  175.         self.contents.blt(x, 68 - ch, bitmap, src_rect)
  176.       end
  177.       # Draw play time
  178.       hour = @total_sec / 60 / 60
  179.       min = @total_sec / 60 % 60
  180.       sec = @total_sec % 60
  181.       time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
  182.       self.contents.font.color = normal_color
  183.       self.contents.draw_text(4, 8, 600, 32, time_string, 2)
  184.       # Draw timestamp
  185.       self.contents.font.color = normal_color
  186.       time_string = @time_stamp.strftime("%Y/%m/%d %H:%M")
  187.       self.contents.draw_text(4, 40, 600, 32, time_string, 2)
  188.     end
  189.   end
  190. end
  191. #==============================================================================
  192. # Alterations in Window_ShopStatus
  193. #==============================================================================
  194. class Window_ShopStatus < Window_Base  
  195.   #--------------------------------------------------------------------------  
  196.   # * Refresh  
  197.   #--------------------------------------------------------------------------  
  198.   def refresh
  199.     self.contents.clear
  200.     return if @item.nil?
  201.     number = case @item
  202.       when RPG::Item then $game_party.item_number(@item.id)
  203.       when RPG::Weapon then $game_party.weapon_number(@item.id)
  204.       when RPG::Armor then $game_party.armor_number(@item.id)
  205.     end
  206.     self.contents.font.color = system_color
  207.     self.contents.draw_text(4, 0, 200, 24, "number in possession")
  208.     self.contents.font.color = normal_color
  209.     self.contents.draw_text(204, 0, 32, 24, number.to_s, 2)
  210.     return if @item.is_a?(RPG::Item)
  211.     # Equipment adding information
  212.     for i in 0...$game_party.actors.size
  213.       # Get actor
  214.       actor = $game_party.actors[i]
  215.       p_size = $game_party.actors.size
  216.       # If equippable, then set to normal text color. If not, set to
  217.       # invalid text color.
  218.       if actor.equippable?(@item)
  219.         self.contents.font.color = normal_color
  220.       else
  221.         self.contents.font.color = disabled_color
  222.       end
  223.       # Draw actor's name
  224.       if p_size > 5
  225.         y1 = i * (288 / p_size)
  226.       else
  227.         y1 = i * 48
  228.       end
  229.       self.contents.draw_text(4, 24 + y1, 120, 24, actor.name)
  230.       # Get current equipment
  231.       if @item.is_a?(RPG::Weapon)
  232.         item1 = $data_weapons[actor.weapon_id]
  233.       elsif @item.kind == 0
  234.         item1 = $data_armors[actor.armor1_id]
  235.       elsif @item.kind == 1
  236.         item1 = $data_armors[actor.armor2_id]
  237.       elsif @item.kind == 2
  238.         item1 = $data_armors[actor.armor3_id]
  239.       else
  240.         item1 = $data_armors[actor.armor4_id]
  241.       end
  242.       # If equippable
  243.       if actor.equippable?(@item)
  244.         # If weapon
  245.         if @item.is_a?(RPG::Weapon)
  246.           atk1 = item1 != nil ? item1.atk : 0
  247.           atk2 = @item != nil ? @item.atk : 0
  248.           change = atk2 - atk1
  249.         end
  250.         # If armor
  251.         if @item.is_a?(RPG::Armor)
  252.           pdef1 = item1 != nil ? item1.pdef : 0
  253.           mdef1 = item1 != nil ? item1.mdef : 0
  254.           pdef2 = @item != nil ? @item.pdef : 0
  255.           mdef2 = @item != nil ? @item.mdef : 0
  256.           change = pdef2 - pdef1 + mdef2 - mdef1
  257.         end
  258.         # Draw parameter change values
  259.         self.contents.draw_text(124, 24 + y1, 112, 24, sprintf("%+d", change), 2)
  260.       end
  261.       # Draw item
  262.       if item1.nil?
  263.         x = 4
  264.         y = 8 + y1 + 32
  265.         bitmap = RPG::Cache.icon(item1.icon_name)
  266.         opacity = self.contents.font.color == normal_color ? 255 : 128
  267.         self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  268.         self.contents.draw_text(x + 28, y, 212, 24, item1.name)
  269.       end
  270.     end
  271.   end
  272. end
  273. class Spriteset_Battle  
  274.   #--------------------------------------------------------------------------  
  275.   # * Object Initialization  
  276.   #--------------------------------------------------------------------------  
  277.   def initialize
  278.     # Make viewports
  279.     @viewport1 = Viewport.new(0, 0, 640, 320)
  280.     @viewport2 = Viewport.new(0, 0, 640, 480)
  281.     @viewport3 = Viewport.new(0, 0, 640, 480)
  282.     @viewport4 = Viewport.new(0, 0, 640, 480)
  283.     @viewport2.z = 101
  284.     @viewport3.z = 200
  285.     @viewport4.z = 5000
  286.     # Make battleback sprite
  287.     @battleback_sprite = Sprite.new(@viewport1)
  288.     # Make enemy sprites
  289.     @enemy_sprites = []
  290.     for enemy in $game_troop.enemies.reverse
  291.       @enemy_sprites.push(Sprite_Battler.new(@viewport1, enemy))
  292.     end
  293.     # Make actor sprites
  294.     @actor_sprites = []
  295.     8.times { @actor_sprites.push(Sprite_Battler.new(@viewport2)) }
  296.     # Make weather
  297.     @weather = RPG::Weather.new(@viewport1)
  298.     # Make picture sprites
  299.     @picture_sprites = []
  300.     for i in 51..100
  301.       @picture_sprites.push(Sprite_Picture.new(@viewport3, $game_screen.pictures[i]))
  302.     end
  303.     # Make timer sprite
  304.     @timer_sprite = Sprite_Timer.new
  305.     # Frame update
  306.     update
  307.   end
  308.  
  309.   def update
  310.     # Update actor sprite contents (corresponds with actor switching)
  311.     8.times do |i|
  312.       @actor_sprites[i].battler = $game_party.actors[i]
  313.     end
  314.     # If battleback file name is different from current one
  315.     if @battleback_name != $game_temp.battleback_name
  316.       @battleback_name = $game_temp.battleback_name
  317.       @battleback_sprite.bitmap.dispose unless @battleback_sprite.bitmap.nil?
  318.       @battleback_sprite.bitmap = RPG::Cache.battleback(@battleback_name)
  319.       @battleback_sprite.src_rect.set(0, 0, 640, 320)
  320.     end
  321.     # Update battler sprites
  322.     for sprite in @enemy_sprites + @actor_sprites
  323.       sprite.update
  324.     end
  325.     # Update weather graphic
  326.     @weather.type = $game_screen.weather_type
  327.     @weather.max = $game_screen.weather_max
  328.     @weather.update
  329.     # Update picture sprites
  330.     for sprite in @picture_sprites
  331.       sprite.update
  332.     end
  333.     # Update timer sprite
  334.     @timer_sprite.update
  335.     # Set screen color tone and shake position
  336.     @viewport1.tone = $game_screen.tone
  337.     @viewport1.ox = $game_screen.shake
  338.     # Set screen flash color
  339.     @viewport4.color = $game_screen.flash_color
  340.     # Update viewports
  341.     @viewport1.update
  342.     @viewport2.update
  343.     @viewport4.update
  344.   end
  345. end
  346. #==============================================================================
  347. # ** Window_BattleStatus
  348. #------------------------------------------------------------------------------
  349. #  This window displays the status of all party members on the battle screen.
  350. #==============================================================================
  351. class Window_Base < Window
  352.   def shadow_color
  353.     Color.new(0, 0, 0)
  354.   end  
  355.   #--------------------------------------------------------------------------  
  356.   # * Draw Name  
  357.   #actor : actor  
  358.   #x: draw spot x-coordinate  
  359.   #y: draw spot y-coordinate  
  360.   #--------------------------------------------------------------------------  
  361.   def draw_actor_name(actor, x, y, shadow = false)
  362.     self.contents.font.color = shadow ? shadow_color : normal_color
  363.     self.contents.draw_text(x, y, 120, 32, actor.name)
  364.   end  
  365.   #--------------------------------------------------------------------------  
  366.   # * Draw State  
  367.   #actor : actor  
  368.   #x: draw spot x-coordinate  
  369.   #y: draw spot y-coordinate  
  370.   #width : draw spot width  
  371.   #--------------------------------------------------------------------------  
  372.   def draw_actor_state(actor, x, y, width = 120, shadow = false)
  373.     text = make_battler_state_text(actor, width, true)
  374.     self.contents.font.color = shadow ? shadow_color : (actor.hp == 0 ? knockout_color : normal_color)
  375.     self.contents.draw_text(x, y, width, 32, text)
  376.   end  
  377.   #--------------------------------------------------------------------------  
  378.   # * Draw HP  
  379.   #actor : actor  
  380.   #x: draw spot x-coordinate  
  381.   # y : draw spot y-coordinate  
  382.   # width : draw spot width  
  383.   #--------------------------------------------------------------------------  
  384.   def draw_actor_hp(actor, x, y, width = 144, height = 32, shadow = false)
  385.     # Draw "HP" text string
  386.     self.contents.font.color = shadow ? shadow_color : system_color
  387.     self.contents.draw_text(x, y, 32, height, $data_system.words.hp)
  388.     # Calculate if there is draw space for MaxHP
  389.     if width - 32 >= 108
  390.       hp_x = x + width - 108
  391.       flag = true
  392.     elsif width - 32 >= 28
  393.       hp_x = x + width - 48
  394.       flag = false
  395.     end
  396.     # Draw HP
  397.     self.contents.font.color = shadow ? shadow_color : (actor.hp == 0 ? knockout_color : (actor.hp <= actor.maxhp / 4 ? crisis_color : normal_color))
  398.     self.contents.draw_text(hp_x, y, 48, height, actor.hp.to_s, 2)
  399.     # Draw MaxHP
  400.     if flag
  401.       self.contents.font.color = shadow ? shadow_color : normal_color
  402.       self.contents.draw_text(hp_x + 48, y, 12, height, "/", 1)
  403.       self.contents.draw_text(hp_x + 60, y, 48, height, actor.maxhp.to_s)
  404.     end
  405.   end  
  406.   #--------------------------------------------------------------------------  
  407.   # * Draw SP  
  408.   # actor : actor  
  409.   # x : draw spot x-coordinate  
  410.   # y : draw spot y-coordinate  
  411.   # width : draw spot width  
  412.   #--------------------------------------------------------------------------  
  413.   def draw_actor_sp(actor, x, y, width = 144, height = 32, shadow = false)
  414.     # Draw "SP" text string
  415.     self.contents.font.color = shadow ? shadow_color : system_color
  416.     self.contents.draw_text(x, y, 32, height, $data_system.words.sp)
  417.     # Calculate if there is draw space for MaxHP
  418.     if width - 32 >= 108
  419.       sp_x = x + width - 108
  420.       flag = true
  421.     elsif width - 32 >= 28
  422.       sp_x = x + width - 48
  423.       flag = false
  424.     end
  425.     # Draw SP
  426.     self.contents.font.color = shadow ? shadow_color : (actor.sp == 0 ? knockout_color : (actor.sp <= actor.maxsp / 4 ? crisis_color : normal_color))
  427.     self.contents.draw_text(sp_x, y, 48, height, actor.sp.to_s, 2)
  428.     # Draw MaxSP
  429.     if flag
  430.       self.contents.font.color = shadow ? shadow_color : normal_color
  431.       self.contents.draw_text(sp_x + 48, y, 12, height, "/", 1)
  432.       self.contents.draw_text(sp_x + 60, y, 48, height, actor.maxsp.to_s)
  433.     end  
  434.   end
  435. end
  436.  
  437. class Window_BattleStatus < Window_Base  
  438.   #--------------------------------------------------------------------------  
  439.   # * Refresh  
  440.   #--------------------------------------------------------------------------  
  441.   def refresh
  442.     self.contents.clear
  443.     @item_max = $game_party.actors.size
  444.     if @item_max > 7
  445.       self.contents.font.size = 16
  446.       self.contents.font.bold = true
  447.     elsif @item_max > 6
  448.       self.contents.font.size = 18
  449.       self.contents.font.bold = true
  450.     elsif @item_max > 4
  451.       self.contents.font.size = 20
  452.       self.contents.font.bold = true
  453.     else
  454.       self.contents.font.size = 22
  455.     end
  456.     for i in 0...$game_party.actors.size
  457.       actor = $game_party.actors[i]
  458.       if @item_max > 6
  459.         actor_x = i * 610/@item_max + 0
  460.         text_x = 75
  461.         t_height = 32
  462.       elsif @item_max > 4
  463.         actor_x = i * 612/@item_max + 4
  464.         text_x = 95
  465.         t_height = 32
  466.       else
  467.         actor_x = i * 160 + 4
  468.         text_x = 120
  469.         t_height = 32
  470.       end
  471.       # Draw shade
  472.       actor_x -= 2
  473.       draw_actor_name(actor, actor_x, 2, true)
  474.       draw_actor_hp(actor, actor_x, 34, text_x, t_height, true)
  475.       draw_actor_sp(actor, actor_x, 66, text_x, t_height, true)
  476.       if @level_up_flags[i]
  477.         self.contents.font.color = Color.new(0, 0, 0)
  478.         self.contents.draw_text(actor_x, 98, 120, t_height, "LEVEL UP!")
  479.       else
  480.         draw_actor_state(actor, actor_x, 98, 120, true)
  481.       end
  482.       actor_x += 2
  483.       draw_actor_name(actor, actor_x, 0)
  484.       draw_actor_hp(actor, actor_x, 32, text_x, t_height)
  485.       draw_actor_sp(actor, actor_x, 64, text_x, t_height)
  486.       if @level_up_flags[i]
  487.         self.contents.font.color = normal_color
  488.         self.contents.draw_text(actor_x, 96, 120, t_height, "LEVEL UP!")
  489.       else
  490.         draw_actor_state(actor, actor_x, 96)
  491.       end
  492.     end
  493.   end
  494. end
  495.  
  496. class Scene_Battle
  497.   def phase3_setup_command_window
  498.     # Disable party command window
  499.     @party_command_window.active = false
  500.     @party_command_window.visible = false
  501.     # Enable actor command window
  502.     @actor_command_window.active = true
  503.     @actor_command_window.visible = true
  504.     p_size = $game_party.actors.size - 1
  505.     step_x = 480 / p_size
  506.     step = 160 if step_x > 160
  507.     window_x = @actor_index * step_x
  508.     if @actor_index == $game_party.actors.size - 1
  509.       window_x = 480
  510.     end
  511.     # Set actor command window position
  512.     @actor_command_window.x = window_x
  513.     # Set index to 0
  514.     @actor_command_window.index = 0  
  515.   end
  516. end
Advertisement
Add Comment
Please, Sign In to add comment