nathmatt

Battle Dome(2) Version: 1.25

May 22nd, 2011
300
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  2. # Battle Dome by Nathmatt
  3. # Version: 1.25
  4. # Type: Add On
  5. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  6. #
  7. #                                    PART 2
  8. #
  9. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  10. #  
  11. #  This work is protected by the following license:
  12. # #-----------------------------------------------------------------------------
  13. # #  
  14. # #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
  15. # #  ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
  16. # #  
  17. # #  You are free:
  18. # #  
  19. # #  to Share - to copy, distribute and transmit the work
  20. # #  to Remix - to adapt the work
  21. # #  
  22. # #  Under the following conditions:
  23. # #  
  24. # #  Attribution. You must attribute the work in the manner specified by the
  25. # #  author or licensor (but not in any way that suggests that they endorse you
  26. # #  or your use of the work).
  27. # #  
  28. # #  Noncommercial. You may not use this work for commercial purposes.
  29. # #  
  30. # #  Share alike. If you alter, transform, or build upon this work, you may
  31. # #  distribute the resulting work only under the same or similar license to
  32. # #  this one.
  33. # #  
  34. # #  - For any reuse or distribution, you must make clear to others the license
  35. # #    terms of this work. The best way to do this is with a link to this web
  36. # #    page.
  37. # #  
  38. # #  - Any of the above conditions can be waived if you get permission from the
  39. # #    copyright holder.
  40. # #  
  41. # #  - Nothing in this license impairs or restricts the author's moral rights.
  42. # #  
  43. # #-----------------------------------------------------------------------------
  44. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  45. #
  46. #  This is the part of the script that runs everything.
  47. #
  48. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  49. module Battle_Dome
  50.  
  51.   # version of Battle_Dome
  52.   Version = 1.23
  53.   Enemy_Data = Struct.new(:id,:character_name,:character_hue)
  54.  
  55.   #============================================================================
  56.   # Battle_Dome::Processor
  57.   #----------------------------------------------------------------------------
  58.   #  This class provides methods for Battle Dome's handling.
  59.   #============================================================================
  60.   class Processor
  61.    
  62.     # setting all accessible variables
  63.     attr_accessor :escape_time,:exp,:gold,:items,:list
  64.     attr_reader   :in_battle,:result,:returns
  65.     #--------------------------------------------------------------------------
  66.     # Initialization
  67.     #--------------------------------------------------------------------------
  68.     def initialize
  69.       @result = nil
  70.       reset
  71.     end
  72.     #--------------------------------------------------------------------------
  73.     # reset
  74.     #  resets all my variables.
  75.     #--------------------------------------------------------------------------
  76.     def reset
  77.       @exp,@gold,@items,@in_battle,@result,@bar_opacity,@enemies_called,@escape_bar,
  78.       @escape_time,@phase = 0,0,[],false,false,255,false,nil,Config::Escape_Time,0
  79.       @evented = RPG::Event.new(0, 0)
  80.     end
  81.     #--------------------------------------------------------------------------
  82.     # Call_Battle
  83.     #  Calls the battle map and sets a few necessary variables
  84.     #--------------------------------------------------------------------------
  85.     def Call_Battle
  86.       @in_battle,@escaped,$game_temp.battle_calling,$game_temp.menu_calling,
  87.       $game_temp.menu_beep,$game_temp.map_bgm = true,false,false,false,false,
  88.       $game_system.playing_bgm
  89.       $game_player.make_encounter_count
  90.       $game_system.bgm_stop
  91.       $game_system.se_play($data_system.battle_start_se)
  92.       $game_system.bgm_play($game_system.battle_bgm)
  93.       @returns = [$game_map.map_id,$game_player.x,$game_player.y,$game_player.direction]
  94.       @data     = []
  95.       @troop_id = $game_temp.battle_troop_id
  96.       @t_Name   = $data_troops[@troop_id].name
  97.       $game_troop.setup(@troop_id)
  98.       (0...$game_troop.enemies.size).each {|e|
  99.       id             = $data_troops[@troop_id].members[e].enemy_id
  100.       character_name = $game_troop.enemies[e].battler_name
  101.       character_hue  = $game_troop.enemies[e].battler_hue
  102.       @data[e] = Enemy_Data.new(id,character_name,character_hue)}
  103.       teleport = check_terrain
  104.       if teleport == nil
  105.         raise 'No map was Dectected please use the config to create a terrain for this map'
  106.       end
  107.       Transfer(true,teleport)
  108.       @phase = 1
  109.     end
  110.     #--------------------------------------------------------------------------
  111.     # check_terrain
  112.     #  returns the terrain id from the current map id
  113.     #--------------------------------------------------------------------------
  114.     def check_terrain
  115.       (1...Terrains::Terrain.size).each {|i|
  116.       return Terrains::Terrain[i] if Terrain_Maps.Terrains(i).include?(@returns[0])}
  117.       return nil
  118.     end
  119.     #--------------------------------------------------------------------------
  120.     # Transfer
  121.     #  Teleports the player to the difined location
  122.     #--------------------------------------------------------------------------
  123.     def Transfer(battle=false,array=[])
  124.       $game_temp.player_new_map_id    = (battle ? array[0]:@returns[0])
  125.       $game_temp.player_new_x         = (battle ? array[1]:@returns[1])
  126.       $game_temp.player_new_y         = (battle ? array[2]:@returns[2])
  127.       $game_temp.player_new_direction = (battle ? array[3]:@returns[3])
  128.       (battle ? $scene.transfer_battle : $scene.transfer_player)
  129.     end
  130.     #--------------------------------------------------------------------------
  131.     # delay
  132.     #  delays all actions for the defined secounds
  133.     #--------------------------------------------------------------------------
  134.     def delay(frames)
  135.       wait = 0
  136.       while frames * 40 > wait; wait += 1; Graphics.update; Input.update; end
  137.     end
  138.     #--------------------------------------------------------------------------
  139.     # create_event
  140.     #  Creates an event with the defined graphic
  141.     #--------------------------------------------------------------------------
  142.     def create_event(data)
  143.       @evented.pages[0].graphic.character_name = data.character_name
  144.       @evented.pages[0].graphic.character_hue  = data.character_hue
  145.       id = $BlizzABS.create_event(0, 0, "\\e[#{data.id}]",@evented.pages)
  146.       x, y = $BlizzABS.get_respawn_coordinates($game_map.events[id])
  147.       $game_map.events[id].moveto(x,y)
  148.     end
  149.     #--------------------------------------------------------------------------
  150.     # can_escape
  151.     #  This checks to see if you can escape
  152.     #--------------------------------------------------------------------------
  153.     def can_escape?
  154.       enemies_agi = actors_agi = 0
  155.       enemies = $game_map.battlers_group(BlizzABS::Alignments::ENEMY_GROUP)
  156.       actors  = ($game_party.actors.find_all {|a| !a.dead?})
  157.       en = enemies.size
  158.       an = actors.size
  159.       enemies.each{|battler|enemies_agi += battler.enemy.agi}
  160.       enemies_agi /= en if en > 0
  161.       actors.each{|actor|actors_agi += actor.agi}
  162.       actors_agi /= actors.size if actors.size > 0
  163.       return rand(100) < 50 * actors_agi / enemies_agi
  164.     end
  165.     #--------------------------------------------------------------------------
  166.     # update
  167.     #  Updates Battle Dome's processes.
  168.     #--------------------------------------------------------------------------
  169.     def update
  170.       reset if $game_temp.gameover
  171.       case @phase; when 1; create_enemies; when 2; battle_check; when 3;
  172.       escape; when 4; finish;
  173.       end
  174.     end
  175.     #--------------------------------------------------------------------------
  176.     # create_enemies
  177.     #  Creates the enemies on the map.
  178.     #--------------------------------------------------------------------------
  179.     def create_enemies
  180.       return if $game_map.map_id == @map_id
  181.       (0...$game_troop.enemies.size).each {|e| create_event(@data[e])}
  182.       @phase = 2
  183.     end
  184.     #--------------------------------------------------------------------------
  185.     # battle_check
  186.     #  Checks whether you win or escape the battle.
  187.     #--------------------------------------------------------------------------
  188.     def battle_check
  189.       if Input.trigger?(Input::Escape)
  190.         @escape_bar = Window_Escape_Bar.new
  191.         @phase = 3
  192.       end
  193.       @phase = 4 if $game_map.battlers_group(BlizzABS::Alignments::ENEMY_GROUP).size == 0
  194.     end
  195.     #--------------------------------------------------------------------------
  196.     # escape
  197.     #  Runs the escape proccesing.
  198.     #--------------------------------------------------------------------------
  199.     def escape
  200.       @escape_bar.update
  201.       @escape_time -= 1
  202.       return if @escape_time != 0
  203.       @escape_time = Config::Escape_Time
  204.       @escape_bar.dispose
  205.       @escape_bar = nil
  206.       @phase = 2
  207.       return if !can_escape?
  208.       $game_system.se_play($data_system.escape_se)
  209.       $game_system.bgm_play($game_temp.map_bgm)
  210.       @result = 2
  211.       reset
  212.       Transfer()
  213.       @phase = 0
  214.     end
  215.     #--------------------------------------------------------------------------
  216.     # finish
  217.     #  Runs the win proccesing.
  218.     #--------------------------------------------------------------------------
  219.     def finish
  220.       $game_system.me_play($game_system.battle_end_me)
  221.       treasures = @items
  222.       $game_party.gain_gold(@gold)
  223.       @escape_time = Battle_Dome::Config::Escape_Time
  224.       $game_party.actors.each {|actor|
  225.       actor.exp += @exp if !actor.cant_get_exp?}
  226.       treasures = treasures[0..5]
  227.       treasures.each {|item|
  228.       case item
  229.       when RPG::Item
  230.         $game_party.gain_item(item.id, 1)
  231.       when RPG::Weapon
  232.         $game_party.gain_weapon(item.id, 1)
  233.       when RPG::Armor
  234.         $game_party.gain_armor(item.id, 1)
  235.       end}
  236.       @result_window = Window_BattleResult.new(@exp, @gold, treasures)
  237.       @result_window.y += 50
  238.       @result_window.visible = true
  239.       delay(Config::Wait_Time)
  240.       @result_window.dispose
  241.       @result_window = nil
  242.       @result = 0
  243.       Transfer()
  244.       $game_system.bgm_play($game_temp.map_bgm)
  245.       reset
  246.     end
  247.      
  248.   end
  249.  
  250. end
  251. # load Battle Dome's Processor
  252. $Battle_Dome = Battle_Dome::Processor.new
  253. #============================================================================
  254. # Scene Map
  255. #============================================================================
  256. class Scene_Map
  257.   # Calls the battle scene
  258.   def call_battle; $Battle_Dome.Call_Battle; end
  259.  
  260.   # updates the battle proccessing
  261.   alias battle_dome_update update
  262.   def update
  263.     $Battle_Dome.update if $Battle_Dome.in_battle
  264.     if !$Battle_Dome.in_battle && $Battle_Dome.list != nil
  265.     end
  266.     battle_dome_update
  267.   end
  268.   # adds the ability to refresh spriteset
  269.   def sprite_refresh; @spriteset = Spriteset_Map.new; end
  270.   # disables menu during battle
  271.   alias battle_dome_call_menu call_menu
  272.   def call_menu
  273.     if $Battle_Dome.in_battle && Battle_Dome::Config::Disable_menu
  274.       $game_temp.menu_calling = false
  275.       if Battle_Dome::Config::Menu != false
  276.         eval("$scene = #{Battle_Dome::Config::Menu}.new")
  277.       end
  278.     else
  279.       battle_dome_call_menu
  280.     end
  281.   end
  282.  
  283.   def transfer_battle
  284.     Graphics.freeze
  285.     t = Battle_Dome::Transition_Pack
  286.     $scene = Transition.new($scene,t::Type , t::Args) if t::Using
  287.     if $game_map.map_id != $game_temp.player_new_map_id
  288.       $game_map.setup($game_temp.player_new_map_id)
  289.     end
  290.     $game_player.moveto($game_temp.player_new_x, $game_temp.player_new_y)
  291.     case $game_temp.player_new_direction
  292.     when 2  # down
  293.       $game_player.turn_down
  294.     when 4  # left
  295.       $game_player.turn_left
  296.     when 6  # right
  297.       $game_player.turn_right
  298.     when 8  # up
  299.       $game_player.turn_up
  300.     end
  301.     $game_player.straighten
  302.     $game_map.update
  303.     @spriteset.dispose
  304.     @spriteset = Spriteset_Map.new
  305.     if !t::Using
  306.       Graphics.transition(40, "Graphics/Transitions/" +
  307.         $data_system.battle_transition,100)
  308.     end
  309.     $game_map.autoplay
  310.     Graphics.frame_reset
  311.     Input.update
  312.   end
  313.  
  314. end
  315. #============================================================================
  316. # Scene Gameover
  317. #============================================================================
  318. class Scene_Gameover
  319.   alias battle_dome_main main
  320.   def main
  321.     $Battle_Dome.reset
  322.     battle_dome_main
  323.   end
  324. end
  325. #============================================================================
  326. # Map_Enemy
  327. #----------------------------------------------------------------------------
  328. # Get enemy id
  329. #============================================================================
  330. class Map_Enemy < Map_Battler; attr_reader   :enemy; end
  331. #============================================================================
  332. # BlizzABS::Processor
  333. #----------------------------------------------------------------------------
  334. #  This edits the part of bliz'z script that controls
  335. #  how you get exp, gold, and items so you get it after battle.
  336. #============================================================================
  337. class BlizzABS::Processor
  338.  
  339.   #--------------------------------------------------------------------------
  340.   # drop_items
  341.   #  enemy - the killed enemy event
  342.   #  Returns array of items that will be dropped.
  343.   #--------------------------------------------------------------------------
  344.   def drop_items(enemy)
  345.     # initialize array
  346.     items = []
  347.     if $tons_version != nil && $tons_version >= 5.98 &&
  348.         TONS_OF_ADDONS::MULTI_DROP
  349.       $Battle_Dome.items += BlizzCFG.dropped_items(enemy.battler)
  350.     elsif rand(100) < enemy.battler.treasure_prob
  351.       if enemy.battler.item_id > 0
  352.         $Battle_Dome.items.push($data_items[enemy.battler.item_id])
  353.       elsif enemy.battler.weapon_id > 0
  354.         $Battle_Dome.items.push($data_weapons[enemy.battler.weapon_id])
  355.       elsif enemy.battler.armor_id > 0
  356.         $Battle_Dome.items.push($data_armors[enemy.battler.armor_id])
  357.       end
  358.     end
  359.     return items
  360.   end
  361.   #--------------------------------------------------------------------------
  362.   # exp_result
  363.   #  enemy - the killed enemy event
  364.   #  Processes EXP gain after the death of an enemy.
  365.   #--------------------------------------------------------------------------
  366.   def exp_result(enemy)
  367.     return 0 if enemy.exp == 0
  368.     exp = enemy.exp
  369.     if $tons_version != nil
  370.       if $tons_version >= 6.4 && TONS_OF_ADDONS::DIFFICULTY
  371.         exp = exp * $game_system.exp_rate / 100
  372.       end
  373.     end
  374.     $Battle_Dome.exp += exp
  375.     exp = 0
  376.     return exp
  377.   end
  378.   #--------------------------------------------------------------------------
  379.   # gold_result
  380.   #  enemy - the killed enemy event
  381.   #  Processes gold gain after the death of an enemy.
  382.   #--------------------------------------------------------------------------
  383.   def gold_result(enemy)
  384.     return 0 if enemy.gold == 0
  385.     gold = enemy.gold
  386.     if $tons_version != nil
  387.       if $tons_version >= 6.4 && TONS_OF_ADDONS::DIFFICULTY
  388.         gold = gold * $game_system.gold_rate / 100
  389.       end
  390.     end
  391.     $Battle_Dome.gold += gold
  392.     return gold
  393.   end
  394.  
  395.   alias battle_dome_create_event_page create_event_page
  396.   def create_event_page(data)
  397.     if data.is_a?(RPG::Event::Page)
  398.       return data
  399.     end
  400.     return battle_dome_create_event_page
  401.   end
  402.    
  403. end
  404. #============================================================================
  405. # BlizzABS::Cache
  406. #----------------------------------------------------------------------------
  407. #  This class was enhanced to support the yellow escpae bar
  408. #============================================================================
  409. class BlizzABS::Cache
  410.  
  411.   alias battle_dome_initialize initialize
  412.   def initialize
  413.     battle_dome_initialize
  414.     # add image
  415.     @data['empty_hud_yellow_bar'] = @data['empty_hud_green_bar'].clone
  416.     @data['empty_hud_yellow_bar'].hue_change(-60)
  417.     # prevent "Script is hanging" error
  418.     Graphics.update
  419.     # add image
  420.     @data['hud_yellow_bar'] = @data['hud_green_bar'].clone
  421.     @data['hud_yellow_bar'].hue_change(-60)
  422.     # prevent "Script is hanging" error
  423.     Graphics.update
  424.   end
  425. end
  426. # load Blizz-ABS Processor
  427. $BlizzABS = BlizzABS::Processor.new
  428. #==============================================================================
  429. # Window_Escape_Bar
  430. #==============================================================================
  431. class Window_Escape_Bar < Sprite
  432.  
  433.   #--------------------------------------------------------------------------
  434.   # * Object Initialization
  435.   #--------------------------------------------------------------------------
  436.   def initialize
  437.     super
  438.     # create bitmap
  439.     self.bitmap = Bitmap.new(206, 96)
  440.     self.x, self.y = 200, 0
  441.     self.z = 1000
  442.     update
  443.   end
  444.   #--------------------------------------------------------------------------
  445.   # * Refresh
  446.   #--------------------------------------------------------------------------
  447.   def update
  448.    rate = (Battle_Dome::Config::Escape_Time > 0 ? $Battle_Dome.escape_time.to_f /
  449.    Battle_Dome::Config::Escape_Time : 0)
  450.     if rate > 0.6
  451.       color1 = Color.new(80 - 150 * (rate-0.6), 80, 50 * (rate-0.6), 192)
  452.       color2 = Color.new(240 - 450 * (rate-0.6), 240, 150 * (rate-0.6), 192)
  453.     elsif rate > 0.2 && rate <= 0.6
  454.       color1 = Color.new(80, 200 * (rate-0.2), 0, 192)
  455.       color2 = Color.new(240, 600 * (rate-0.2), 0, 192)
  456.     elsif rate <= 0.2
  457.       color1 = Color.new(400 * rate, 0, 0, 192)
  458.       color2 = Color.new(240, 0, 0, 192)
  459.     end
  460.     color3 = Color.new(0, 80, 0, 192)
  461.     self.bitmap.font.color = normal_color
  462.     if Battle_Dome::Config::Use_Tons &&  $tons_version != nil
  463.       self.bitmap.gradient_bar(55,10,114, color1, color2, color3, rate)
  464.     else
  465.       self.bitmap.gradient_bar_hud(55, 32, 114, rate, 'hud_yellow_bar')
  466.     end
  467.     self.bitmap.draw_text_full(65,-6,100,32,Battle_Dome::Config::Escape_Text.to_s)
  468.   end
  469. end
  470. #==============================================================================
  471. # Input
  472. #==============================================================================
  473. module Input ; Escape =  [Key[Battle_Dome::Control::Escape]]; end
  474. #==============================================================================
  475. # Interpreter
  476. #==============================================================================
  477. class Interpreter
  478.   attr_accessor :branch
  479.   alias battle_dome_command_301 command_301
  480.   def command_301
  481.     list = @list[@index+1..@list.size]
  482.     $Battle_Dome.list = list
  483.     battle_dome_command_301
  484.   end
  485.    
  486. end
RAW Paste Data