Advertisement
roninator2

Cozziekuns Earthbound-ish Battle Core - mod

Dec 7th, 2024
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.20 KB | None | 0 0
  1. #==============================================================================
  2. # ** Earthbound-Ish Battle Core
  3. #------------------------------------------------------------------------------
  4. # Version: 1.1
  5. # Author: cozziekuns
  6. # Fixed by Roninator2
  7. # Date: February 17, 2013
  8. #==============================================================================
  9. # Description:
  10. #------------------------------------------------------------------------------
  11. # This script attempts to mimic the battle system of the Earthbound/Mother
  12. # series; most notably Earthbound and Earthbound 2 (Mother 2 and 3).
  13. #==============================================================================
  14. # Instructions:
  15. #------------------------------------------------------------------------------
  16. # Paste this script into its own slot in the Script Editor, above Main but
  17. # below Materials. Edit the modules to your liking.
  18. #==============================================================================
  19.  
  20. #==============================================================================
  21. # ** Cozziekuns
  22. #==============================================================================
  23.  
  24. module Cozziekuns
  25.  
  26.   module Earthboundish
  27.    
  28.     ActorIcons ={
  29.       # Command Name => IconID
  30.       "Attack" => 116,
  31.       "Magic" => 152,
  32.       "Special" => 128,
  33.       "Guard" => 161,
  34.       "Items" => 260,
  35.       "Escape" => 474,
  36.     }
  37.    
  38.   end
  39.  
  40. end
  41.  
  42. include Cozziekuns
  43.  
  44. #==============================================================================
  45. # ** Sprite Battler
  46. #==============================================================================
  47.  
  48. class Sprite_Battler
  49.  
  50.   alias coz_ebish_spbtlr_update_effect update_effect
  51.   def update_effect(*args)
  52.     update_select_whiten if @effect_type == :select_white
  53.     if @battler.sprite_effect_type == :select_white_to_normal
  54.       revert_to_normal
  55.       @battler.sprite_effect_type = nil
  56.     end
  57.     coz_ebish_spbtlr_update_effect(*args)
  58.   end
  59.  
  60.   def update_select_whiten
  61.     self.color.set(255, 255, 255, 0)
  62.     self.color.alpha = 128
  63.   end
  64.  
  65. end
  66.  
  67. #==============================================================================
  68. # ** Window_ActorCommand
  69. #==============================================================================
  70.  
  71. class Window_ActorCommand
  72.  
  73.   def visible_line_number
  74.     return 1
  75.   end
  76.  
  77.   def col_max
  78.     return 6
  79.   end
  80.  
  81.   def contents_height
  82.     item_height
  83.   end
  84.  
  85.   def top_col
  86.     ox / (item_width + spacing)
  87.   end
  88.  
  89.   def top_col=(col)
  90.     col = 0 if col < 0
  91.     col = col_max - 1 if col > col_max - 1
  92.     self.ox = col * (item_width + spacing)
  93.   end
  94.  
  95.   def bottom_col
  96.     top_col + col_max - 1
  97.   end
  98.  
  99.   def bottom_col=(col)
  100.     self.top_col = col - (col_max - 1)
  101.   end
  102.  
  103.   def ensure_cursor_visible
  104.     self.top_col = index if index < top_col
  105.     self.bottom_col = index if index > bottom_col
  106.   end
  107.  
  108.   def item_rect(index)
  109.     rect = super
  110.     rect.x = index * (item_width + spacing)
  111.     rect.y = 0
  112.     rect
  113.   end
  114.  
  115.   def window_width
  116.     Graphics.width - 224
  117.   end
  118.  
  119.   def open
  120.     @help_window.open
  121.     super
  122.   end
  123.  
  124.   def close
  125.     @help_window.close
  126.     super
  127.   end
  128.  
  129.   def update
  130.     super
  131.     @help_window.update
  132.   end
  133.  
  134.   def draw_item(index)
  135.     rect = item_rect_for_text(index)
  136.     x = rect.x + rect.width / 2 - 12
  137.     y = item_rect_for_text(index).y
  138.     draw_icon(Earthboundish::ActorIcons[command_name(index)], x, y, command_enabled?(index))
  139.   end
  140.  
  141.   alias coz_ebish_waccmd_make_command_list make_command_list
  142.   def make_command_list(*args)
  143.     coz_ebish_waccmd_make_command_list(*args)
  144.     add_escape_command
  145.   end
  146.  
  147.   def add_escape_command
  148.     add_command(Vocab::escape, :escape, BattleManager.can_escape?)
  149.   end
  150.  
  151.   def update_help
  152.     @help_window.set_text(command_name(index))
  153.   end
  154.  
  155. end
  156.  
  157. #==============================================================================
  158. # ** Window_BattleStatus
  159. #==============================================================================
  160.  
  161. class Window_BattleStatus
  162.  
  163.   [:basic_area_rect, :gauge_area_rect].each { |method|
  164.     define_method(method) { |index|
  165.       rect = item_rect(index)
  166.       rect
  167.     }
  168.   }
  169.  
  170.   def col_max
  171.     $game_party.members.size
  172.   end
  173.  
  174.   def window_width
  175.     if $game_party.members.size == 1
  176.       Graphics.width / ( 3.5 / $game_party.members.size.to_f )
  177.     elsif $game_party.battle_members.size == 2
  178.       Graphics.width / ( 3.8 / $game_party.members.size.to_f )
  179.     elsif $game_party.battle_members.size == 3
  180.       Graphics.width / ( 4 / $game_party.members.size.to_f )
  181.     else
  182.       Graphics.width
  183.     end
  184.   end
  185. #~   def window_width
  186. #~     (Graphics.width / ( 4 / $game_party.members.size.to_f )) + 12
  187. #~   end
  188.  
  189.   def window_height
  190.     fitting_height($data_system.opt_display_tp ? 5 : 4)
  191.   end
  192.  
  193.   def item_width
  194.     (window_width - standard_padding * 2) / $game_party.members.size
  195.   end
  196.  
  197.   def item_height
  198.     (window_height - standard_padding * 2)
  199.   end
  200.  
  201.   def draw_basic_area(rect, actor)
  202.     draw_actor_name(actor, rect.x, rect.y, rect.width)
  203.     draw_actor_icons(actor, rect.x + 4, rect.y + line_height, rect.width)
  204.   end
  205.  
  206.   def draw_gauge_area_with_tp(rect, actor)
  207.     draw_gauge_area_without_tp(rect, actor)
  208.     draw_actor_tp(actor, rect.x + 4, rect.y + line_height * 4, rect.width - 8)
  209.   end
  210.  
  211.   def draw_gauge_area_without_tp(rect, actor)
  212.     draw_actor_hp(actor, rect.x + 4, rect.y + line_height * 2, rect.width - 8)
  213.     draw_actor_mp(actor, rect.x + 4, rect.y + line_height * 3, rect.width - 8)
  214.   end
  215.  
  216.   def draw_actor_name(actor, x, y, width = 112)
  217.     change_color(hp_color(actor))
  218.     draw_text(x, y, width, line_height, actor.name, 1)
  219.   end
  220.  
  221.   alias coz_ebish_wbtlsts_item_rect item_rect
  222.   def item_rect(index, *args)
  223.     rect = coz_ebish_wbtlsts_item_rect(index, *args)
  224.     rect.x = index % col_max * item_width
  225.     rect
  226.   end
  227.  
  228.   def update
  229.     super
  230.     update_position
  231.   end
  232.  
  233.   def update_position
  234.     self.x = (Graphics.width - window_width) / 2 + 128
  235.   end
  236.  
  237. end
  238.  
  239. #==============================================================================
  240. # ** Window_BattleActor
  241. #==============================================================================
  242.  
  243. class Window_BattleActor
  244.  
  245.   def update_position
  246.     self.x = (Graphics.width - window_width) / 2
  247.   end
  248.  
  249. end
  250.  
  251. #==============================================================================
  252. # ** Window_BattleEnemy
  253. #==============================================================================
  254.  
  255. class Window_BattleEnemy
  256.  
  257.   def cursor_left(wrap)
  258.     select((index - 1 + item_max) % item_max)
  259.   end
  260.  
  261.   def cursor_right(wrap)
  262.     select((index + 1) % item_max)
  263.   end
  264.  
  265.   def cursor_up(wrap)
  266.     cursor_left(true)
  267.   end
  268.  
  269.   def cursor_down(wrap)
  270.     cursor_right(true)
  271.   end
  272.  
  273.   def show
  274.     select(0)
  275.     self
  276.   end
  277.  
  278.   def update_help
  279.     @help_window.set_text(enemy.name)
  280.   end
  281.  
  282. end
  283.  
  284. #==============================================================================
  285. # ** Window_BattleSkill + Window_BattleItem
  286. #==============================================================================
  287.  
  288. [:Window_BattleSkill, :Window_BattleItem].each { |klass|
  289.   Object.const_get(klass).send(:define_method, :show) {
  290.     select_last
  291.     super()
  292.   }
  293.   Object.const_get(klass).send(:define_method, :hide) { super() }
  294. }
  295.  
  296. #==============================================================================
  297. # ** Window_ActorHelp
  298. #==============================================================================
  299.  
  300. class Window_ActorHelp < Window_Help
  301.  
  302.   def initialize
  303.     super(1)
  304.     self.openness = 0
  305.     update_position
  306.   end
  307.  
  308.   def update_position
  309.     self.x = Graphics.width - 224
  310.     self.width = 224
  311.     create_contents
  312.   end
  313.  
  314.   def refresh
  315.     contents.clear
  316.     draw_text(4, 0, 224 - standard_padding * 2, line_height, @text, 1)
  317.   end
  318.  
  319. end
  320.  
  321. #==============================================================================
  322. # ** Scene_Battle
  323. #==============================================================================
  324.  
  325. class Scene_Battle
  326.  
  327.   def start_party_command_selection
  328.     unless scene_changing?
  329.       @status_window.open
  330.       @status_window.refresh
  331.       if BattleManager.input_start
  332.         next_command
  333.         start_actor_command_selection
  334.       else
  335.         @party_command_window.deactivate
  336.         turn_start
  337.       end
  338.     end
  339.   end
  340.  
  341.   def create_actor_command_window
  342.     @actor_command_window = Window_ActorCommand.new
  343.     @actor_command_window.set_handler(:attack, method(:command_attack))
  344.     @actor_command_window.set_handler(:skill,  method(:command_skill))
  345.     @actor_command_window.set_handler(:guard,  method(:command_guard))
  346.     @actor_command_window.set_handler(:item,   method(:command_item))
  347.     @actor_command_window.set_handler(:escape, method(:command_escape))
  348.     @actor_command_window.set_handler(:cancel, method(:prior_command))
  349.     @actor_command_window.help_window = @actor_help_window = Window_ActorHelp.new
  350.   end
  351.  
  352.   def create_help_window
  353.     @help_window = Window_Help.new(1)
  354.     @help_window.visible = false
  355.   end
  356.  
  357.   alias coz_ebish_scbtl_create_enemy_window create_enemy_window
  358.   def create_enemy_window(*args)
  359.     coz_ebish_scbtl_create_enemy_window(*args)
  360.     @enemy_window.help_window = @actor_command_window.help_window
  361.   end
  362.  
  363.   alias coz_ebish_scbtl_update_basic update_basic
  364.   def update_basic(*args)
  365.     old_enemy = @enemy_window.active ? @enemy_window.enemy : nil
  366.     @old_enemy.sprite_effect_type = nil if !@old_enemy.nil? && !@enemy_window.active
  367.     @old_enemy = @enemy_window.active ? @enemy_window.enemy : nil
  368.     coz_ebish_scbtl_update_basic(*args)
  369.     update_enemy_whiten(old_enemy)
  370.   end
  371.  
  372.   def update_enemy_whiten(old_enemy)
  373.     if @old_enemy.nil?
  374.       @enemy_window.enemy.sprite_effect_type = :whiten if @enemy_window.active
  375.     elsif @enemy_window.active
  376.       @old_enemy.sprite_effect_type = nil if @old_enemy != @enemy_window.enemy
  377.       @enemy_window.enemy.sprite_effect_type = :whiten
  378.     elsif !@enemy_window.active
  379.       @old_enemy.sprite_effect_type = nil if !@old_enemy.dead?
  380.     end
  381.   end
  382.  
  383.   def update_info_viewport
  384.     move_info_viewport(128)
  385.   end
  386.  
  387. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement