Advertisement
Guest User

Sideview 2 Flash

a guest
Jul 6th, 2011
582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 121.19 KB | None | 0 0
  1. #==============================================================================
  2. # Sideview Battle System Version 2.2xp
  3. #==============================================================================
  4. #==============================================================================
  5. # ■ Atoa Module
  6. #==============================================================================
  7. $atoa_script = {} if $atoa_script.nil?
  8. $atoa_script["SBS Tankentai"] = true
  9.  
  10. #==============================================================================
  11. # ■ Scene_Battle
  12. #==============================================================================
  13. class Scene_Battle
  14.   #--------------------------------------------------------------------------
  15.   include N01
  16.   #--------------------------------------------------------------------------
  17.   attr_accessor :spriteset
  18.   #--------------------------------------------------------------------------
  19.   def main
  20.     fix_weapon_init
  21.     start
  22.     create_viewport
  23.     process_transition
  24.     update_battle
  25.     terminate
  26.     fix_weapon_end
  27.   end
  28.   #--------------------------------------------------------------------------
  29.   def start
  30.     @battle_start = true
  31.     $game_temp.in_battle = true
  32.     $game_temp.battle_turn = 0
  33.     $game_temp.battle_event_flags.clear
  34.     $game_temp.battle_abort = false
  35.     $game_temp.battle_main_phase = false
  36.     $game_temp.battleback_name = $game_map.battleback_name
  37.     $game_temp.forcing_battler = nil
  38.     $game_system.battle_interpreter.setup(nil, 0)
  39.     @troop_id = $game_temp.battle_troop_id
  40.     $game_troop.setup(@troop_id)
  41.     for enemy in $game_troop.enemies
  42.       enemy.true_immortal = enemy.immortal
  43.     end
  44.   end
  45.   #--------------------------------------------------------------------------
  46.   def create_viewport
  47.     s1 = $data_system.words.attack
  48.     s2 = $data_system.words.skill
  49.     s3 = $data_system.words.guard
  50.     s4 = $data_system.words.item
  51.     @actor_command_window = Window_Command.new(160, [s1, s2, s3, s4])
  52.     @actor_command_window.y = 160
  53.     @actor_command_window.back_opacity = 160
  54.     @actor_command_window.active = false
  55.     @actor_command_window.visible = false
  56.     @party_command_window = Window_PartyCommand.new
  57.     @help_window = Window_Help.new
  58.     @help_window.back_opacity = 160
  59.     @help_window.visible = false
  60.     @active_battler_window = Window_NameCommand.new(@active_battler, 240, 64)
  61.     @active_battler_window.visible = false
  62.     @status_window = Window_BattleStatus.new
  63.     @message_window = Window_Message.new
  64.     @spriteset = Spriteset_Battle.new
  65. #=======================================================================
  66. #=====================Flash Bbacks (lol)================================
  67. #=======================================================================
  68. # Use a different variable Value for differents flashs
  69. # Lights Effects Can be done aswell, just use images
  70.       @archivo_flash = $game_map.map_id
  71.       @variable_del_fondo = Sprite.new
  72.       @variable_del_fondo.bitmap = Bitmap.new("Graphics/Pictures/#{$game_map.map_id}")
  73.       @variable_del_fondo.z = 400
  74.       @asdf = RMFlash.load(@archivo_flash, 640, 480)
  75.       #@asdf.loop = 1
  76.     @wait_count, @escape_ratio = 0, 50
  77.   end
  78.   #--------------------------------------------------------------------------
  79.   def process_transition
  80.     if $data_system.battle_transition == ""
  81.       Graphics.transition(20)
  82.     else
  83.       Graphics.transition(40, "Graphics/Transitions/" + $data_system.battle_transition)
  84.     end
  85.     start_phase1
  86.   end
  87.   #--------------------------------------------------------------------------
  88.   def update_battle
  89.     loop do
  90.       Graphics.update
  91.       Input.update
  92.       @asdf.update
  93.       update
  94.       break if $scene != self
  95.     end
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   def terminate
  99.     $game_map.refresh
  100.     Graphics.freeze
  101.     @actor_command_window.dispose
  102.     @party_command_window.dispose
  103.     @help_window.dispose
  104.     @status_window.dispose
  105.     @message_window.dispose
  106.     @skill_window.dispose if @skill_window != nil
  107.     @item_window.dispose if @item_window != nil
  108.     @result_window.dispose if @result_window != nil
  109.     @spriteset.dispose
  110.     @asdf.dispose
  111.     @variable_del_fondo.dispose
  112.     if $scene.is_a?(Scene_Title)
  113.       Graphics.transition
  114.       Graphics.freeze
  115.     end
  116.     $scene = nil if $BTEST and not $scene.is_a?(Scene_Gameover)
  117.   end
  118.   #--------------------------------------------------------------------------
  119.   def fix_weapon_init
  120.     for member in $game_party.actors
  121.       if member.weapons[0] == nil and member.weapons[1] != nil
  122.         weapon_to_equip = member.armor1_id
  123.         member.equip(1, 0)
  124.         member.equip(0, weapon_to_equip)
  125.         member.two_swords_change = true
  126.       end
  127.     end  
  128.   end
  129.   #--------------------------------------------------------------------------
  130.   def fix_weapon_end
  131.     for member in $game_party.actors
  132.       if member.two_swords_change
  133.         weapon_to_re_equip = member.weapon_id
  134.         member.equip(0, 0)
  135.         member.equip(1, weapon_to_re_equip)
  136.         member.two_swords_change = false
  137.       end  
  138.     end
  139.   end
  140.   #--------------------------------------------------------------------------
  141.   def update_basic
  142.     Graphics.update
  143.     Input.update
  144.     $game_system.update
  145.     $game_screen.update
  146.     @spriteset.update
  147.     @asdf.update
  148.   end  
  149.   #--------------------------------------------------------------------------
  150.   def update_effects
  151.     for battler in $game_party.actors + $game_troop.enemies
  152.       if battler.exist?
  153.         battler_sprite = @spriteset.actor_sprites[battler.index] if battler.actor?
  154.         battler_sprite = @spriteset.enemy_sprites[battler.index] if battler.is_a?(Game_Enemy)
  155.         battler_sprite.effects_update
  156.       end
  157.     end
  158.   end
  159.   #--------------------------------------------------------------------------
  160.   def wait(duration)
  161.     for i in 0...duration
  162.       update_basic
  163.     end
  164.   end
  165.   #--------------------------------------------------------------------------
  166.   def pop_help(obj)
  167.     @help_window.set_text(obj, 1)
  168.     loop do
  169.       update_basic
  170.       break @help_window.visible = false if Input.trigger?(Input::C)
  171.     end
  172.   end
  173.   #--------------------------------------------------------------------------
  174.   alias start_phase1_n01 start_phase1
  175.   def start_phase1
  176.     for member in $game_party.actors + $game_troop.enemies
  177.       member.dead_anim = member.dead? ? true : false
  178.       @spriteset.set_stand_by_action(member.actor?, member.index) unless member.dead_anim
  179.     end
  180.     start_phase1_n01
  181.     $clear_enemies_actions = false
  182.     if $preemptive
  183.       pop_help(PREEMPTIVE_ALERT)
  184.       $clear_enemies_actions = true
  185.     end
  186.     @battle_start = false unless $back_attack
  187.     return unless $back_attack
  188.     pop_help(BACK_ATTACK_ALERT)
  189.     @battle_start = false
  190.     $game_party.clear_actions
  191.     start_phase4
  192.   end
  193.   #--------------------------------------------------------------------------
  194.   alias start_phase4_n01 start_phase4
  195.   def start_phase4
  196.     start_phase4_n01
  197.     @active_battler_window.visible = false
  198.     if $clear_enemies_actions
  199.       $clear_enemies_actions = false
  200.       $game_troop.clear_actions
  201.     end
  202.   end
  203.   #--------------------------------------------------------------------------
  204.   def judge
  205.     if $game_party.all_dead? or $game_party.actors.size == 0
  206.       if $game_temp.battle_can_lose
  207.         $game_system.bgm_play($game_temp.map_bgm)
  208.         battle_end(2)
  209.         return true
  210.       end
  211.       $game_temp.gameover = true
  212.       return true
  213.     end
  214.     for enemy in $game_troop.enemies
  215.       return false if enemy.exist?
  216.     end
  217.     process_victory
  218.     return true
  219.   end
  220.   #--------------------------------------------------------------------------
  221.   def update_phase2_escape
  222.     enemies_agi = enemies_number = 0
  223.     for enemy in $game_troop.enemies
  224.       if enemy.exist?
  225.         enemies_agi += enemy.agi
  226.         enemies_number += 1
  227.       end
  228.     end
  229.     enemies_agi /= [enemies_number, 1].max
  230.     actors_agi = actors_number = 0
  231.     for actor in $game_party.actors
  232.       if actor.exist?
  233.         actors_agi += actor.agi
  234.         actors_number += 1
  235.       end
  236.     end
  237.     actors_agi /= [actors_number, 1].max
  238.     @success = rand(100) < @escape_ratio * actors_agi / enemies_agi
  239.     @party_command_window.visible = false
  240.     @party_command_window.active = false
  241.     wait(2)
  242.     if @success
  243.       $game_system.se_play($data_system.escape_se)
  244.       for actor in $game_party.actors
  245.         unless actor.dead?
  246.           @spriteset.set_action(true, actor.index, actor.run_success)
  247.         end
  248.       end
  249.       pop_help(ESCAPE_SUCCESS)
  250.       $game_system.bgm_play($game_temp.map_bgm)
  251.       battle_end(1)
  252.     else
  253.       @escape_ratio += 5
  254.       $game_party.clear_actions
  255.       $game_system.se_play($data_system.escape_se)
  256.       for actor in $game_party.actors
  257.         unless actor.dead?
  258.           @spriteset.set_action(true, actor.index,actor.run_ng)
  259.         end
  260.       end
  261.       pop_help(ESCAPE_FAIL)
  262.       start_phase4
  263.     end
  264.   end
  265.   #--------------------------------------------------------------------------
  266.   def process_victory
  267.     for enemy in $game_troop.enemies
  268.       break boss_wait = true if enemy.collapse_type == 3
  269.     end
  270.     wait(440) if boss_wait
  271.     wait(WIN_WAIT) unless boss_wait
  272.     for actor in $game_party.actors
  273.       unless actor.restriction == 4
  274.         @spriteset.set_action(true, actor.index,actor.win)
  275.       end
  276.     end
  277.     start_phase5
  278.   end
  279.   #--------------------------------------------------------------------------
  280.   def start_phase5
  281.     @phase = 5
  282.     $game_system.me_play($game_system.battle_end_me)
  283.     $game_system.bgm_play($game_temp.map_bgm)
  284.     treasures = []
  285.     for enemy in $game_troop.enemies
  286.       gold = gold.nil? ? enemy.gold : gold + enemy.gold
  287.       treasures << treasure_drop(enemy) unless enemy.hidden
  288.     end
  289.     exp = gain_exp
  290.     treasures = treasures.compact
  291.     $game_party.gain_gold(gold)
  292.     for item in treasures
  293.       case item
  294.       when RPG::Item
  295.         $game_party.gain_item(item.id, 1)
  296.       when RPG::Weapon
  297.         $game_party.gain_weapon(item.id, 1)
  298.       when RPG::Armor
  299.         $game_party.gain_armor(item.id, 1)
  300.       end
  301.     end
  302.     @result_window = Window_BattleResult.new(exp, gold, treasures)
  303.     @result_window.add_multi_drops if $atoa_script['Multi Drop']
  304.     @phase5_wait_count = 100
  305.   end
  306.   #--------------------------------------------------------------------------
  307.   def treasure_drop(enemy)
  308.     if rand(100) < enemy.treasure_prob
  309.       treasure = $data_items[enemy.item_id] if enemy.item_id > 0
  310.       treasure = $data_weapons[enemy.weapon_id] if enemy.weapon_id > 0
  311.       treasure = $data_armors[enemy.armor_id] if enemy.armor_id > 0
  312.     end
  313.     return treasure
  314.   end
  315.   #--------------------------------------------------------------------------
  316.   def gain_exp
  317.     exp = exp_gained
  318.     for i in 0...$game_party.actors.size
  319.       actor = $game_party.actors[i]
  320.       if actor.cant_get_exp? == false
  321.         last_level = actor.level
  322.         actor.exp += exp
  323.         if actor.level > last_level
  324.           @status_window.level_up(i)
  325.         end
  326.       end
  327.     end
  328.     return exp
  329.   end
  330.   #--------------------------------------------------------------------------
  331.   def exp_gained
  332.     for enemy in $game_troop.enemies
  333.       exp = exp.nil? ? enemy.exp : exp + enemy.exp
  334.     end
  335.     if EXP_SHARE
  336.       actor_number = 0
  337.       for actor in $game_party.actors
  338.         actor_number += 1 unless actor.cant_get_exp?
  339.       end
  340.       exp = exp / [actor_number, 1].max
  341.     end
  342.     return exp
  343.   end
  344.   #--------------------------------------------------------------------------
  345.   alias acbs_update_phase5 update_phase5
  346.   def update_phase5
  347.     @result_window.update
  348.     acbs_update_phase5
  349.   end
  350.   #--------------------------------------------------------------------------
  351.   alias phase3_next_actor_n01 phase3_next_actor
  352.   def phase3_next_actor
  353.     if @active_battler != nil && @active_battler.inputable?
  354.       @spriteset.set_action(true, @actor_index, @active_battler.command_a)
  355.     end
  356.     @wait_count = 32 if @actor_index == $game_party.actors.size-1
  357.     phase3_next_actor_n01
  358.     if @active_battler != nil && @active_battler.inputable?
  359.       @spriteset.set_action(true, @actor_index,@active_battler.command_b)
  360.     end  
  361.   end  
  362.   #--------------------------------------------------------------------------
  363.   alias phase3_prior_actor_n01 phase3_prior_actor
  364.   def phase3_prior_actor
  365.     if @active_battler != nil && @active_battler.inputable?
  366.       @active_battler.current_action.clear
  367.       @spriteset.set_action(true, @actor_index,@active_battler.command_a)
  368.     end
  369.     phase3_prior_actor_n01
  370.     if @active_battler != nil && @active_battler.inputable?
  371.       @active_battler.current_action.clear
  372.       @spriteset.set_action(true, @actor_index,@active_battler.command_b)
  373.     end
  374.   end
  375.   #--------------------------------------------------------------------------
  376.   alias start_phase2_n01 start_phase2
  377.   def start_phase2
  378.     @active_battler_window.visible = false
  379.     start_phase2_n01
  380.   end
  381.   #--------------------------------------------------------------------------
  382.   alias phase3_setup_command_window_n01 phase3_setup_command_window
  383.   def phase3_setup_command_window
  384.     phase3_setup_command_window_n01
  385.     @actor_command_window.x = COMMAND_WINDOW_POSITION[0]
  386.     @actor_command_window.y = COMMAND_WINDOW_POSITION[1]
  387.     @actor_command_window.z = 2000
  388.     @actor_command_window.index = 0
  389.     @actor_command_window.back_opacity = COMMAND_OPACITY
  390.     @active_battler_window.refresh(@active_battler)
  391.     @active_battler_window.visible = true if BATTLER_NAME_WINDOW
  392.   end
  393.   #--------------------------------------------------------------------------
  394.   alias acbs_update_phase3_basic_command_scenebattle update_phase3_basic_command
  395.   def update_phase3_basic_command
  396.     if Input.trigger?(Input::C)
  397.       case @actor_command_window.commands[@actor_command_window.index]
  398.       when $data_system.words.attack
  399.         $game_system.se_play($data_system.decision_se)
  400.         @active_battler.current_action.kind = 0
  401.         @active_battler.current_action.basic = 0
  402.         @actor_command_window.active = false
  403.         @actor_command_window.visible = false
  404.         start_enemy_select
  405.         return
  406.       when $data_system.words.item
  407.         $game_system.se_play($data_system.decision_se)
  408.         @active_battler.current_action.kind = 2
  409.         start_item_select
  410.         return
  411.       when $data_system.words.guard
  412.         $game_system.se_play($data_system.decision_se)
  413.         @active_battler.current_action.kind = 0
  414.         @active_battler.current_action.basic = 1
  415.         phase3_next_actor
  416.         return
  417.       end
  418.     end
  419.     acbs_update_phase3_basic_command_scenebattle
  420.   end
  421.   #--------------------------------------------------------------------------
  422.   def now_action(battler = @active_battler)
  423.     return if battler.nil?
  424.     @now_action = nil
  425.     case battler.current_action.kind
  426.     when 0
  427.       @now_action = $data_weapons[battler.weapon_id] if battler.current_action.basic == 0
  428.     when 1
  429.       @now_action = $data_skills[battler.current_action.skill_id]
  430.     when 2
  431.       @now_action = $data_items[battler.current_action.item_id]
  432.     end
  433.   end
  434.   #--------------------------------------------------------------------------
  435.   def start_enemy_select
  436.     now_action
  437.     @enemy_arrow = Arrow_Enemy.new(@spriteset.viewport2)
  438.     @enemy_arrow.help_window = @help_window
  439.     @actor_command_window.active = false
  440.     @actor_command_window.visible = false
  441.     @active_battler_window.visible = false
  442.     @status_window.visible = true
  443.   end
  444.   #--------------------------------------------------------------------------
  445.   alias start_actor_select_n01 start_actor_select
  446.   def start_actor_select
  447.     now_action
  448.     start_actor_select_n01
  449.     @status_window.visible = true
  450.     @active_battler_window.visible = false
  451.     @actor_arrow.input_right if @now_action.extension.include?("OTHERS")
  452.   end
  453.   #--------------------------------------------------------------------------
  454.   alias update_phase3_actor_select_n01 update_phase3_actor_select
  455.   def update_phase3_actor_select
  456.     @actor_arrow.input_update_target if @now_action.extension.include?("OTHERS") and @actor_arrow.index == @active_battler.index
  457.     update_phase3_actor_select_n01
  458.   end
  459.   #--------------------------------------------------------------------------
  460.   alias update_phase3_n01 update_phase3
  461.   def update_phase3
  462.     if @enemy_arrow_all != nil
  463.       update_phase3_select_all_enemies
  464.       return
  465.     elsif @actor_arrow_all != nil
  466.       update_phase3_select_all_actors
  467.       return
  468.     elsif @battler_arrow_all != nil
  469.       update_phase3_select_all_battlers
  470.       return
  471.     end
  472.     update_phase3_n01
  473.   end
  474.   #--------------------------------------------------------------------------
  475.   alias update_phase3_skill_select_n01 update_phase3_skill_select
  476.   def update_phase3_skill_select
  477.     @status_window.visible = false  if HIDE_WINDOW
  478.     if Input.trigger?(Input::C)
  479.       @skill = @skill_window.skill
  480.       if @skill == nil or not @active_battler.skill_can_use?(@skill.id)
  481.         $game_system.se_play($data_system.buzzer_se)
  482.         return
  483.       end
  484.       @active_battler.current_action.skill_id = @skill.id
  485.       @skill_window.visible = false
  486.       if @skill.extension.include?("TARGETALL")
  487.         $game_system.se_play($data_system.decision_se)
  488.         start_select_all_battlers
  489.         return
  490.       end
  491.       if (@skill.extension.include?("RANDOMTARGET") and @skill.scope <= 2) or @skill.scope == 2
  492.         $game_system.se_play($data_system.decision_se)
  493.         start_select_all_enemies
  494.         return
  495.       end
  496.       if (@skill.extension.include?("RANDOMTARGET") and @skill.scope > 2) or @skill.scope == 4
  497.         $game_system.se_play($data_system.decision_se)
  498.         start_select_all_actors
  499.         return
  500.       end
  501.     end
  502.     update_phase3_skill_select_n01
  503.   end
  504.   #--------------------------------------------------------------------------
  505.   alias update_phase3_item_select_n01 update_phase3_item_select
  506.   def update_phase3_item_select
  507.     @status_window.visible = false if HIDE_WINDOW
  508.     if Input.trigger?(Input::C)
  509.       @item = @item_window.item
  510.       if @item == nil or not $game_party.item_can_use?(@item.id)
  511.         $game_system.se_play($data_system.buzzer_se)
  512.         return
  513.       end
  514.       @active_battler.current_action.item_id = @item.id
  515.       @item_window.visible = false
  516.       if @item.extension.include?("TARGETALL")
  517.         $game_system.se_play($data_system.decision_se)
  518.         start_select_all_battlers
  519.         return
  520.       end
  521.       if @item.extension.include?("RANDOMTARGET") and @item.scope <= 2 or @item.scope == 2
  522.         $game_system.se_play($data_system.decision_se)
  523.         start_select_all_enemies
  524.         return
  525.       end
  526.       if (@item.extension.include?("RANDOMTARGET") and @item.scope > 2) or @item.scope == 4
  527.         $game_system.se_play($data_system.decision_se)
  528.         start_select_all_actors
  529.         return
  530.       end
  531.     end
  532.     update_phase3_item_select_n01
  533.   end
  534.   #--------------------------------------------------------------------------
  535.   def update_phase3_select_all_enemies
  536.     @enemy_arrow_all.update_multi_arrow
  537.     if Input.trigger?(Input::B)
  538.       $game_system.se_play($data_system.cancel_se)
  539.       end_select_all_enemies
  540.       return
  541.     end
  542.     if Input.trigger?(Input::C)
  543.       $game_system.se_play($data_system.decision_se)
  544.       if @skill_window != nil
  545.         end_skill_select
  546.       end
  547.       if @item_window != nil
  548.         end_item_select
  549.       end
  550.       end_select_all_enemies
  551.       phase3_next_actor
  552.       return
  553.     end
  554.   end
  555.   #--------------------------------------------------------------------------
  556.   def update_phase3_select_all_actors
  557.     @actor_arrow_all.update_multi_arrow
  558.     if Input.trigger?(Input::B)
  559.       $game_system.se_play($data_system.cancel_se)
  560.       end_select_all_actors
  561.       return
  562.     end
  563.     if Input.trigger?(Input::C)
  564.       $game_system.se_play($data_system.decision_se)
  565.       if @skill_window != nil
  566.         end_skill_select
  567.       end
  568.       if @item_window != nil
  569.         end_item_select
  570.       end
  571.       end_select_all_actors
  572.       phase3_next_actor
  573.       return
  574.     end
  575.   end      
  576.   #--------------------------------------------------------------------------
  577.   def update_phase3_select_all_battlers
  578.     @battler_arrow_all.update_multi_arrow
  579.     if Input.trigger?(Input::B)
  580.       $game_system.se_play($data_system.cancel_se)
  581.       end_select_all_battlers
  582.       return
  583.     end
  584.     if Input.trigger?(Input::C)
  585.       $game_system.se_play($data_system.decision_se)
  586.       if @skill_window != nil
  587.         end_skill_select
  588.       end
  589.       if @item_window != nil
  590.         end_item_select
  591.       end
  592.       end_select_all_battlers
  593.       phase3_next_actor
  594.       return
  595.     end
  596.   end      
  597.   #--------------------------------------------------------------------------
  598.   def start_select_all_enemies
  599.     now_action
  600.     @status_window.visible = true
  601.     @active_battler_window.visible = false
  602.     @enemy_arrow_all = Arrow_Enemy_All.new(@spriteset.viewport2)
  603.   end
  604.   #--------------------------------------------------------------------------
  605.   def start_select_all_actors
  606.     now_action
  607.     @status_window.visible = true
  608.     @active_battler_window.visible = false
  609.     @actor_arrow_all = Arrow_Actor_All.new(@spriteset.viewport2)
  610.   end
  611.   #--------------------------------------------------------------------------
  612.   def start_select_all_battlers
  613.     now_action
  614.     @status_window.visible = true
  615.     @active_battler_window.visible = false
  616.     @battler_arrow_all = Arrow_Battler_All.new(@spriteset.viewport2)
  617.   end
  618.   #--------------------------------------------------------------------------
  619.   def end_select_all_actors
  620.     @actor_arrow_all.dispose_multi_arrow
  621.     @actor_arrow_all = nil
  622.     @active_battler_window.visible = true if @actor_command_window.index == 0 and BATTLER_NAME_WINDOW
  623.   end
  624.   #--------------------------------------------------------------------------
  625.   def end_select_all_enemies
  626.     @enemy_arrow_all.dispose_multi_arrow
  627.     @enemy_arrow_all = nil
  628.     @active_battler_window.visible = true if @actor_command_window.index == 0 and BATTLER_NAME_WINDOW
  629.   end
  630.   #--------------------------------------------------------------------------
  631.   def end_select_all_battlers
  632.     @battler_arrow_all.dispose_multi_arrow
  633.     @battler_arrow_all = nil
  634.     @active_battler_window.visible = true if @actor_command_window.index == 0 and BATTLER_NAME_WINDOW
  635.   end
  636.   #--------------------------------------------------------------------------
  637.   alias end_enemy_select_n01 end_enemy_select
  638.   def end_enemy_select
  639.     end_enemy_select_n01
  640.     @active_battler_window.visible = true if @actor_command_window.index == 0 and BATTLER_NAME_WINDOW
  641.   end
  642.   #--------------------------------------------------------------------------
  643.   alias start_skill_select_n01 start_skill_select
  644.   def start_skill_select
  645.     start_skill_select_n01
  646.     @status_window.visible = false if HIDE_WINDOW
  647.     @active_battler_window.visible = false
  648.   end
  649.   #--------------------------------------------------------------------------
  650.   alias end_skill_select_n01 end_skill_select
  651.   def end_skill_select
  652.     end_skill_select_n01
  653.     @status_window.visible = true
  654.     @active_battler_window.visible = true if BATTLER_NAME_WINDOW
  655.   end
  656.   #--------------------------------------------------------------------------
  657.   alias start_item_select_n01 start_item_select
  658.   def start_item_select
  659.     start_item_select_n01
  660.     @status_window.visible = false if HIDE_WINDOW
  661.     @active_battler_window.visible = false
  662.   end
  663.   #--------------------------------------------------------------------------
  664.   alias end_item_select_n01 end_item_select
  665.   def end_item_select
  666.     end_item_select_n01
  667.     @status_window.visible = true
  668.     @active_battler_window.visible = true if BATTLER_NAME_WINDOW
  669.   end
  670.   #--------------------------------------------------------------------------
  671.   alias make_action_orders_n01 make_action_orders
  672.   def make_action_orders
  673.     make_action_orders_n01
  674.     for battler in @action_battlers
  675.       skill_id = battler.current_action.skill_id
  676.       item_id = battler.current_action.item_id
  677.       next if battler.current_action.kind == 0
  678.       extension = $data_skills[skill_id].extension if skill_id != 0
  679.       extension = $data_items[item_id].extension if item_id != 0
  680.       battler.current_action.speed = 9999 if extension.include?("FAST")
  681.       battler.current_action.speed = -1 if extension.include?("SLOW")
  682.     end
  683.     @action_battlers.sort! {|a,b|
  684.       b.current_action.speed - a.current_action.speed }
  685.     for enemy in $game_troop.enemies
  686.       if enemy.action_time[0] != 1
  687.         action_time = 0
  688.         for i in 1...enemy.action_time[0]
  689.           action_time += 1 if rand(100) < enemy.action_time[1]
  690.         end
  691.         enemy.act_time = action_time
  692.         action_time.times do
  693.           enemy_order_time(enemy)
  694.           action_time -= 1
  695.           break if action_time == 0
  696.         end  
  697.         enemy.adj_speed = nil
  698.       end
  699.     end
  700.   end
  701.   #--------------------------------------------------------------------------
  702.   def enemy_order_time(enemy)
  703.     enemy.make_action_speed2(enemy.action_time[2])
  704.     select_time = 0
  705.     for member in @action_battlers
  706.       select_time += 1
  707.       break @action_battlers.push(enemy) if member.current_action.speed < enemy.adj_speed
  708.       break @action_battlers.push(enemy) if select_time == @action_battlers.size
  709.     end
  710.   end  
  711.   #--------------------------------------------------------------------------
  712.   def update_phase4_step1
  713.     return if @spriteset.effect?
  714.     return @wait_count -= 1 if @wait_count > 0
  715.     @help_window.visible = false
  716.     return if judge
  717.     if $game_temp.forcing_battler == nil
  718.       setup_battle_event
  719.        return if $game_system.battle_interpreter.running?
  720.     end
  721.     if $game_temp.forcing_battler != nil
  722.       @action_battlers.delete($game_temp.forcing_battler)
  723.       @action_battlers.unshift($game_temp.forcing_battler)
  724.     end
  725.     if @action_battlers.size == 0
  726.       turn_ending
  727.       start_phase2
  728.       return
  729.     end
  730.     @animation1_id = 0
  731.     @animation2_id = 0
  732.     @common_event_id = 0
  733.     @active_battler = @action_battlers.shift
  734.     return if @active_battler.index == nil
  735.     @active_battler.remove_states_auto
  736.     @status_window.refresh
  737.     @phase4_step = 2
  738.   end
  739.   #--------------------------------------------------------------------------
  740.   def turn_ending
  741.     for member in $game_party.actors + $game_troop.enemies
  742.       member.current_action.clear
  743.       next unless member.exist?
  744.       member.slip_damage = false
  745.       actor = member.actor?
  746.       for state in member.battler_states
  747.         member.remove_state(state.id) if state.extension.include?("ZEROTURNLIFT")
  748.       end
  749.       damage = 0
  750.       for state in member.battler_states
  751.         next unless state.extension.include?("SLIPDAMAGE")
  752.         for ext in state.slip_extension
  753.           if ext[0] == "hp"
  754.             base_damage = ext[1] + member.maxhp * ext[2] / 100
  755.             damage += base_damage + base_damage * (rand(5) - rand(5)) / 100
  756.             slip_pop = ext[3]
  757.             slip_dead = ext[4]
  758.             slip_damage_flug = true
  759.             member.slip_damage = true
  760.           end
  761.         end  
  762.       end
  763.       if member.slip_damage && member.exist? && !slip_damage_flug
  764.         damage += member.apply_variance(member.maxhp / 10, 10)
  765.         slip_dead = false
  766.         slip_pop = true
  767.         slip_damage_flug = true
  768.         member.slip_damage = true
  769.       end
  770.       damage = member.hp - 1 if damage >= member.hp && slip_dead = false
  771.       member.hp -= damage
  772.       member.damage = damage if damage > 0
  773.       member.perform_collapse if member.dead? && member.slip_damage
  774.       @spriteset.set_damage_pop(actor, member.index, damage) if slip_pop
  775.       @spriteset.set_stand_by_action(actor, member.index) if member.hp <= 0 and not member.dead_anim
  776.       member.dead_anim = member.dead? ? true : false
  777.     end
  778.     @status_window.refresh
  779.     wait(DMG_DURATION / 2) if slip_damage_flug
  780.     slip_damage_flug = false
  781.     for member in $game_party.actors + $game_troop.enemies
  782.       next unless member.exist?
  783.       actor = member.actor?
  784.       damage = 0
  785.       for state in member.battler_states
  786.         next unless state.extension.include?("SLIPDAMAGE")
  787.         for ext in state.slip_extension
  788.           if ext[0] == "mp"
  789.             base_damage = ext[1] + member.maxsp * ext[2] / 100
  790.             damage += base_damage + base_damage * (rand(5) - rand(5)) / 100
  791.             slip_pop = ext[3]
  792.             slip_damage_flug = true
  793.           end
  794.         end
  795.         member.sp_damage = true
  796.         member.sp -= damage
  797.         member.damage = damage if damage > 0
  798.         @spriteset.set_damage_pop(actor, member.index, damage) if slip_pop
  799.       end
  800.     end
  801.     @status_window.refresh
  802.     wait(DMG_DURATION / 2) if slip_damage_flug
  803.     for member in $game_party.actors + $game_troop.enemies
  804.       next unless member.exist?
  805.       actor = member.actor?
  806.       damage = 0
  807.       for state in member.battler_states
  808.         next unless state.extension.include?("REGENERATION")
  809.         for ext in state.slip_extension
  810.           if ext[0] == "hp"
  811.             base_damage = ext[1] + member.maxhp * ext[2] / 100
  812.             damage += base_damage + base_damage * (rand(5) - rand(5)) / 100
  813.             slip_pop = ext[3]
  814.             slip_damage_flug = true
  815.           end
  816.         end
  817.         member.hp -= damage
  818.         member.damage = damage if damage < 0
  819.         @spriteset.set_damage_pop(actor, member.index, damage) if slip_pop
  820.       end  
  821.     end
  822.     @status_window.refresh
  823.     wait(DMG_DURATION / 2) if slip_damage_flug
  824.     for member in $game_party.actors + $game_troop.enemies
  825.       next unless member.exist?
  826.       actor = member.actor?
  827.       damage = 0
  828.       for state in member.battler_states
  829.         next unless state.extension.include?("REGENERATION")
  830.         for ext in state.slip_extension
  831.           if ext[0] == "mp"
  832.             base_damage = ext[1] + member.maxhp * ext[2] / 100
  833.             damage += base_damage + base_damage * (rand(5) - rand(5)) / 100
  834.             slip_pop = ext[3]
  835.             slip_damage_flug = true
  836.           end
  837.         end
  838.         member.sp_damage = true
  839.         member.sp -= damage  
  840.         member.damage = damage if damage < 0
  841.         @spriteset.set_damage_pop(actor, member.index, damage) if slip_pop
  842.       end
  843.     end
  844.     @status_window.refresh
  845.     wait(DMG_DURATION / 2) if slip_damage_flug
  846.   end
  847.   #--------------------------------------------------------------------------
  848.   alias update_phase4_step2_n01 update_phase4_step2
  849.   def update_phase4_step2
  850.     for member in $game_party.actors + $game_troop.enemies
  851.       member.dead_anim = member.dead? ? true : false
  852.     end
  853.     if @active_battler.current_action.kind != 0
  854.       obj = $data_skills[@active_battler.current_action.skill_id] if @active_battler.current_action.kind == 1
  855.       obj = $data_items[@active_battler.current_action.item_id] if @active_battler.current_action.kind == 2
  856.       @active_battler.white_flash = false if obj != nil &&obj.extension.include?("NOFLASH")
  857.     end
  858.     @active_battler.active = true
  859.     update_phase4_step2_n01
  860.     if @active_battler != nil && @active_battler.derivation != 0
  861.       @active_battler.current_action.kind = 1
  862.       @active_battler.current_action.skill_id = @active_battler.derivation
  863.       @action_battlers.unshift(@active_battler)
  864.     end
  865.     if @active_battler != nil && !@active_battler.actor? && @active_battler.act_time != 0
  866.       @active_battler.make_action
  867.       @active_battler.act_time -= 1
  868.     end
  869.     update_phase4_step6
  870.   end
  871.   #--------------------------------------------------------------------------
  872.   alias update_phase4_step6_n01 update_phase4_step6
  873.   def update_phase4_step6
  874.     update_phase4_step6_n01
  875.     @active_battler.active = false if @active_battler != nil
  876.   end
  877.   #--------------------------------------------------------------------------
  878.   def make_basic_action_result
  879.     if @active_battler.current_action.basic == 0
  880.       execute_action_attack
  881.       return
  882.     end
  883.     if @active_battler.current_action.basic == 1
  884.       @help_window.set_text("#{@active_battler.name} defends", 1)
  885.       @help_window.visible = true
  886.       @active_battler.active = false
  887.       @active_battler.defense_pose = true
  888.       @spriteset.set_stand_by_action(@active_battler.actor?, @active_battler.index)
  889.       wait(45)
  890.       @help_window.visible = false
  891.       return
  892.     end
  893.     if @active_battler.is_a?(Game_Enemy) and @active_battler.current_action.basic == 2
  894.       @spriteset.set_action(false, @active_battler.index, @active_battler.run_success)
  895.       $game_system.se_play($data_system.escape_se)
  896.       @active_battler.escape
  897.       pop_help("#{@active_battler.name} escaped...")
  898.       return
  899.     end
  900.     if @active_battler.current_action.basic == 3
  901.       @active_battler.active = false
  902.       $game_temp.forcing_battler = nil
  903.       @phase4_step = 1
  904.       return
  905.     end
  906.   end
  907.   #--------------------------------------------------------------------------
  908.   def execute_action_attack
  909.     if @active_battler.actor?
  910.       if @active_battler.weapon_id == 0
  911.         action = @active_battler.non_weapon
  912.         immortaling
  913.       else  
  914.         action = $data_weapons[@active_battler.weapon_id].base_action
  915.         if $data_weapons[@active_battler.weapon_id].plus_state_set.include?(1)
  916.           for member in $game_party.actors + $game_troop.enemies
  917.             next if member.immortal
  918.             next if member.dead?
  919.             member.dying = true
  920.           end
  921.         else
  922.           immortaling
  923.         end
  924.       end  
  925.     else
  926.       if @active_battler.weapon == 0
  927.         action = @active_battler.base_action
  928.         immortaling
  929.       else
  930.         action = $data_weapons[@active_battler.weapon].base_action
  931.         if $data_weapons[@active_battler.weapon].plus_state_set.include?(1)
  932.           for member in $game_party.actors + $game_troop.enemies
  933.             next if member.immortal
  934.             next if member.dead?
  935.             member.dying = true
  936.           end
  937.         else
  938.           immortaling
  939.         end
  940.       end  
  941.     end
  942.     target_decision
  943.     @spriteset.set_action(@active_battler.actor?, @active_battler.index, action)
  944.     playing_action
  945.   end
  946.   #--------------------------------------------------------------------------
  947.   def make_attack_targets
  948.     @target_battlers = []
  949.     if @active_battler.is_a?(Game_Enemy)
  950.       if @active_battler.restriction == 3
  951.         target = $game_troop.random_target_enemy
  952.       elsif @active_battler.restriction == 2
  953.         target = $game_party.random_target_actor
  954.       else
  955.         index = @active_battler.current_action.target_index
  956.         target = $game_party.smooth_target_actor(index)
  957.       end
  958.     end
  959.     if @active_battler.actor?
  960.       if @active_battler.restriction == 3
  961.         target = $game_party.random_target_actor
  962.       elsif @active_battler.restriction == 2
  963.         target = $game_troop.random_target_enemy
  964.       else
  965.         index = @active_battler.current_action.target_index
  966.         target = $game_troop.smooth_target_enemy(index)
  967.       end
  968.     end
  969.     @target_battlers = [target]
  970.     return @target_battlers
  971.   end
  972.   #--------------------------------------------------------------------------
  973.   def make_skill_action_result
  974.     skill = $data_skills[@active_battler.current_action.skill_id]
  975.     if skill.plus_state_set.include?(1)
  976.       for member in $game_party.actors + $game_troop.enemies
  977.         next if member.immortal
  978.         next if member.dead?
  979.         member.dying = true
  980.       end
  981.     else
  982.       immortaling
  983.     end
  984.     return unless @active_battler.skill_can_use?(skill.id)
  985.     target_decision(skill)
  986.     @active_battler.consum_skill_cost(skill)
  987.     @status_window.refresh
  988.     @spriteset.set_action(@active_battler.actor?, @active_battler.index, skill.base_action)
  989.     @help_window.set_text(skill.name, 1) unless skill.extension.include?("HELPHIDE")
  990.     playing_action
  991.     @common_event_id = skill.common_event_id
  992.   end
  993.   #--------------------------------------------------------------------------
  994.   def make_item_action_result
  995.     item = $data_items[@active_battler.current_action.item_id]
  996.     unless $game_party.item_can_use?(item.id)
  997.       @phase4_step = 1
  998.       return
  999.     end
  1000.     if @item.consumable
  1001.       $game_party.lose_item(item.id, 1)
  1002.     end
  1003.     immortaling
  1004.     target_decision(item)
  1005.     @spriteset.set_action(@active_battler.actor?, @active_battler.index, item.base_action)
  1006.     @help_window.set_text(item.name, 1) unless item.extension.include?("HELPHIDE")
  1007.     playing_action
  1008.     @common_event_id = item.common_event_id
  1009.   end
  1010.   #--------------------------------------------------------------------------
  1011.   def target_decision(obj = nil)
  1012.     if obj != nil
  1013.       set_target_battlers(obj.scope)
  1014.       if obj.extension.include?("TARGETALL")
  1015.         @target_battlers = []
  1016.         if obj.scope != 5 or obj.scope != 6
  1017.           for target in $game_troop.enemies + $game_party.actors
  1018.             @target_battlers.push(target) if target.exist?
  1019.           end
  1020.         else
  1021.           for target in $game_troop.enemies + $game_party.actors
  1022.             @target_battlers.push(target) if target != nil && target.hp0?
  1023.           end
  1024.         end
  1025.       end
  1026.       @target_battlers.delete(@active_battler) if obj.extension.include?("OTHERS")
  1027.       if obj.extension.include?("RANDOMTARGET")
  1028.         randum_targets = @target_battlers.dup
  1029.         @target_battlers = [randum_targets[rand(randum_targets.size)]]
  1030.       end
  1031.     else
  1032.       @target_battlers = make_attack_targets
  1033.     end
  1034.     if @target_battlers.size == 0
  1035.       action = @active_battler.recover_action
  1036.       @spriteset.set_action(@active_battler.actor?, @active_battler.index, action)
  1037.     end
  1038.     @spriteset.set_target(@active_battler.actor?, @active_battler.index, @target_battlers)
  1039.   end  
  1040.   #--------------------------------------------------------------------------
  1041.   def playing_action
  1042.     loop do
  1043.       update_basic
  1044.       update_effects
  1045.       action = @active_battler.play
  1046.       next if action == 0
  1047.       @active_battler.play = 0
  1048.       if action[0] == "Individual"
  1049.         individual
  1050.       elsif action == "Can Collapse"
  1051.         unimmortaling
  1052.       elsif action == "Cancel Action"
  1053.         break action_end
  1054.       elsif action == "End"
  1055.         break action_end
  1056.       elsif action[0] == "OBJ_ANIM"
  1057.         damage_action(action[1])
  1058.       end
  1059.     end
  1060.   end
  1061.   #--------------------------------------------------------------------------
  1062.   def individual
  1063.     @individual_target = @target_battlers
  1064.     @stand_by_target = @target_battlers.dup
  1065.   end
  1066.   #--------------------------------------------------------------------------
  1067.   def immortaling
  1068.     for member in $game_party.actors + $game_troop.enemies
  1069.       member.immortal = true unless member.dead?
  1070.     end  
  1071.   end  
  1072.   #--------------------------------------------------------------------------
  1073.   def unimmortaling
  1074.     return if @active_battler.individual
  1075.     for member in $game_party.actors + $game_troop.enemies
  1076.       member.immortal = false
  1077.       member.add_state(1) if member.dead?
  1078.       if member.dead? and not member.dead_anim
  1079.         member.perform_collapse
  1080.         @spriteset.set_stand_by_action(member.actor?, member.index)
  1081.       end
  1082.       member.dead_anim = member.dead? ? true : false
  1083.       next unless member.dead?
  1084.       resurrection(member)
  1085.     end
  1086.     update_basic
  1087.     @status_window.refresh
  1088.   end
  1089.   #--------------------------------------------------------------------------
  1090.   def resurrection(target)
  1091.     for state in target.battler_states
  1092.       for ext in state.extension
  1093.         name = ext.split('')
  1094.         next unless name[0] == "A"
  1095.         wait(25)
  1096.         name = name.join
  1097.         name.slice!("AUTOLIFE/")
  1098.         target.hp = target.maxhp * name.to_i / 100
  1099.         target.remove_state(1)
  1100.         target.remove_state(state.id)
  1101.         target.animation_id = RESURRECTION
  1102.         target.animation_hit = true
  1103.         target.anime_mirror = true if $back_attack
  1104.         @status_window.refresh
  1105.         wait($data_animations[RESURRECTION].frame_max * 2)
  1106.       end  
  1107.     end
  1108.   end
  1109.   #--------------------------------------------------------------------------
  1110.   def magic_reflection(target, obj)
  1111.     return if obj != nil and $data_skills[@active_battler.current_action.skill_id].int_f == 0
  1112.     for state in target.battler_states
  1113.       for ext in state.extension
  1114.         name = ext.split('')
  1115.         next unless name[0] == "M"
  1116.         if name[3] == "R"
  1117.           name = name.join
  1118.           name.slice!("MAGREFLECT/")
  1119.           target.animation_id = name.to_i
  1120.           target.animation_hit = true
  1121.           target.anime_mirror = true if $back_attack
  1122.           @reflection = true
  1123.         else
  1124.           name = name.join
  1125.           name.slice!("MAGNULL/")
  1126.           target.animation_id = name.to_i
  1127.           target.animation_hit = true
  1128.           target.anime_mirror = true if $back_attack
  1129.           @invalid = true
  1130.         end  
  1131.       end  
  1132.     end
  1133.   end
  1134.   #--------------------------------------------------------------------------
  1135.   def physics_reflection(target, obj)
  1136.     return if obj != nil && $data_skills[@active_battler.current_action.skill_id].str_f == 0
  1137.     for state in target.battler_states
  1138.       for ext in state.extension
  1139.         name = ext.split('')
  1140.         next unless name[0] == "P"
  1141.         if name[3] == "R"
  1142.           name = name.join
  1143.           name.slice!("PHYREFLECT/")
  1144.           target.animation_id = name.to_i
  1145.           target.animation_hit = true
  1146.           target.anime_mirror = true if $back_attack
  1147.           @reflection = true
  1148.         else
  1149.           name = name.join
  1150.           name.slice!("PHYNULL/")
  1151.           target.animation_id = name.to_i
  1152.           target.animation_hit = true
  1153.           target.anime_mirror = true if $back_attack
  1154.           @invalid = true
  1155.         end
  1156.       end  
  1157.     end
  1158.   end
  1159.   #--------------------------------------------------------------------------
  1160.   def absorb_cost(target, obj)
  1161.     for state in target.battler_states
  1162.       if state.extension.include?("COSTABSORB")
  1163.         cost = @active_battler.calc_sp_cost(@active_battler, obj)
  1164.         return target.hp += cost if obj.extension.include?("HPCONSUME")
  1165.         return target.mp += cost
  1166.       end  
  1167.     end
  1168.   end
  1169.   #--------------------------------------------------------------------------
  1170.   def absorb_attack(obj, target, index, actor)
  1171.     for ext in obj.extension
  1172.       return if target.evaded or target.missed or target.damage == 0 or target.damage == nil
  1173.       name = ext.split('')
  1174.       next unless name[3] == "G" and name[1] == "D"
  1175.       name = name.join
  1176.       name.slice!("%DMGABSORB/")
  1177.       kind = "hp" unless target.sp_damage
  1178.       kind = "sp" if target.sp_damage
  1179.       absorb = target.damage * name.to_i / 100
  1180.       @wide_attack = true if obj.scope == 2 or obj.scope == 4 or obj.scope == 6 or obj.extension.include?("TARGETALL")
  1181.       if @wide_attack && @absorb == nil && @target_battlers.size != 1
  1182.         @absorb = absorb
  1183.         @absorb_target_size = @target_battlers.size - 2
  1184.       elsif @absorb != nil && @absorb_target_size > 0
  1185.         @absorb += absorb
  1186.         @absorb_target_size -= 1
  1187.       elsif @absorb != nil
  1188.         @absorb += absorb
  1189.         absorb_action = ["absorb", nil, kind, @absorb]
  1190.         @spriteset.set_damage_action(actor, index, absorb_action)
  1191.         @absorb = nil
  1192.         @absorb_target_size = nil
  1193.         @active_battler.perform_collapse
  1194.       else
  1195.         absorb_action = ["absorb", nil, kind, absorb]
  1196.         @spriteset.set_damage_action(actor, index, absorb_action)
  1197.         @active_battler.perform_collapse
  1198.       end  
  1199.     end
  1200.   end  
  1201.   #--------------------------------------------------------------------------
  1202.   def action_end
  1203.     @individual_target = nil
  1204.     @help_window.visible = false if @help_window != nil && @help_window.visible
  1205.     @active_battler.active = false
  1206.     unimmortaling
  1207.     for member in $game_troop.enemies
  1208.       member.non_dead = false if member.non_dead
  1209.     end
  1210.     if @active_battler.reflex != nil
  1211.       if @active_battler.current_action.kind == 1
  1212.         obj = $data_skills[@active_battler.current_action.skill_id]
  1213.         @active_battler.perfect_skill_effect(@active_battler, obj)
  1214.       elsif @active_battler.current_action.kind == 2
  1215.         obj = $data_items[@active_battler.current_action.item_id]
  1216.         @active_battler.item_effect(@active_battler, obj)
  1217.       else
  1218.         @active_battler.perfect_attack_effect(@active_battler)
  1219.       end
  1220.       pop_damage(@active_battler, obj, @active_battler.reflex)
  1221.       @active_battler.perform_collapse
  1222.       @active_battler.reflex = nil
  1223.       wait(COLLAPSE_WAIT)
  1224.     end
  1225.     if @active_battler.derivation != 0
  1226.       @active_battler.current_action.skill_id = @active_battler.derivation
  1227.       @active_battler.current_action.kind = 1
  1228.       @active_battler.derivation = 0
  1229.       @action_battlers.unshift(@active_battler)
  1230.     else
  1231.       @spriteset.set_stand_by_action(@active_battler.actor?, @active_battler.index)
  1232.       wait(ACTION_WAIT + 20)
  1233.     end
  1234.   end  
  1235.   #--------------------------------------------------------------------------
  1236.   def damage_action(action)
  1237.     @target_battlers = [@individual_target.shift] if @active_battler.individual
  1238.     if @active_battler.current_action.kind == 1
  1239.       obj = $data_skills[@active_battler.current_action.skill_id]
  1240.       for target in @target_battlers
  1241.         return if target == nil
  1242.         if obj.scope == 5 or obj.scope == 6
  1243.           return unless target.dead?
  1244.         else
  1245.           return if target.dead?
  1246.         end
  1247.         if target.hp == 0 && obj.scope != 5 && obj.scope != 6
  1248.           target.perfect_skill_effect(@active_battler, obj)
  1249.         elsif obj.extension.include?("NOEVADE")
  1250.           target.perfect_skill_effect(@active_battler, obj)
  1251.         else
  1252.           magic_reflection(target, obj) unless obj.extension.include?("IGNOREREFLECT")
  1253.           physics_reflection(target, obj) unless obj.extension.include?("IGNOREREFLECT")
  1254.           target.skill_effect(@active_battler, obj) unless @reflection or @invalid
  1255.         end
  1256.         pop_damage(target, obj, action) unless @reflection or @invalid
  1257.         absorb_cost(target, obj)
  1258.         @active_battler.reflex = action if @reflection
  1259.         @reflection = false
  1260.         @invalid = false
  1261.       end
  1262.     elsif @active_battler.current_action.kind == 2
  1263.       obj = $data_items[@active_battler.current_action.item_id]
  1264.       for target in @target_battlers
  1265.         return if target == nil
  1266.         if obj.scope == 5 or obj.scope == 6
  1267.           return unless target.dead?
  1268.         else
  1269.           return if target.dead?
  1270.         end
  1271.         target.revival = true if obj.scope == 5 or obj.scope == 6
  1272.         target.item_effect(obj)
  1273.         pop_damage(target, obj, action)
  1274.       end
  1275.     else
  1276.       for target in @target_battlers
  1277.         return if target == nil or target.dead?
  1278.         physics_reflection(target, nil)
  1279.         target.perfect_attack_effect(@active_battler) if target.hp <= 0
  1280.         target.attack_effect(@active_battler) unless target.hp <= 0 unless @reflection or @invalid
  1281.         pop_damage(target, obj, action) unless @reflection or @invalid
  1282.         @active_battler.reflex = action if @reflection
  1283.         @reflection = false
  1284.         @invalid = false
  1285.       end
  1286.     end
  1287.     return if obj == nil
  1288.     target_decision(obj) if obj.extension.include?("RANDOMTARGET")
  1289.   end
  1290.   #--------------------------------------------------------------------------
  1291.   def pop_damage(target, obj, action)
  1292.     index = @active_battler.index
  1293.     actor = @active_battler.actor?
  1294.     if obj != nil && obj.extension.size != 0
  1295.       absorb_attack(obj, target, index, actor)
  1296.       action[2] = false if obj.extension.include?("NOOVERKILL")
  1297.     end
  1298.     @spriteset.set_damage_action(target.actor?, target.index, action)
  1299.     @status_window.refresh
  1300.   end
  1301. end  
  1302.  
  1303. #==============================================================================
  1304. # ■ Scene_Map
  1305. #==============================================================================
  1306. class Scene_Map
  1307.   #--------------------------------------------------------------------------
  1308.   include N01
  1309.   #--------------------------------------------------------------------------
  1310.   alias call_battle_n01 call_battle
  1311.   #--------------------------------------------------------------------------
  1312.   def call_battle
  1313.     $back_attack = $preemptive = false
  1314.     preemptive_or_back_attack
  1315.     call_battle_n01
  1316.   end
  1317.   #--------------------------------------------------------------------------
  1318.   def preemptive_or_back_attack  
  1319.     enemies_agi = 0
  1320.     for enemy in $game_troop.enemies
  1321.       enemies_agi += enemy.agi
  1322.     end
  1323.     enemies_agi /= [$game_troop.enemies.size, 1].max
  1324.     actors_agi = 0
  1325.     for actor in $game_party.actors
  1326.       actors_agi += actor.agi
  1327.     end
  1328.     actors_agi /= [$game_party.actors.size, 1].max
  1329.     preemptive_plus
  1330.     if actors_agi >= enemies_agi
  1331.       percent_preemptive = PREEMPTIVE_RATE * ($preemptive_plus ? 3 : 1)
  1332.       percent_back_attack = BACK_ATTACK_RATE / 2
  1333.     else
  1334.       percent_preemptive = (PREEMPTIVE_RATE / 2) * ($preemptive_plus ? 3 : 1)
  1335.       percent_back_attack = BACK_ATTACK_RATE
  1336.     end
  1337.     if rand(100) < percent_preemptive
  1338.       $preemptive = true
  1339.     elsif rand(100) < percent_back_attack
  1340.       $back_attack = true
  1341.     end
  1342.     special_back_attack_conditions
  1343.     special_preemptive_conditions
  1344.     $preemptive = false if $back_attack or !PREEMPTIVE
  1345.     $back_attack = false if !BACK_ATTACK
  1346.   end
  1347.   #--------------------------------------------------------------------------
  1348.   def special_back_attack_conditions
  1349.     for i in 0...BACK_ATTACK_SWITCH.size
  1350.       return $back_attack = true if $game_switches[BACK_ATTACK_SWITCH[i]]
  1351.     end
  1352.     for i in 0...NO_BACK_ATTACK_SWITCH.size
  1353.       return $back_attack = false if $game_switches[NON_BACK_ATTACK_SWITCH[i]]
  1354.     end
  1355.     for actor in $game_party.actors
  1356.       return $back_attack = false if NON_BACK_ATTACK_WEAPONS.include?(actor.weapon_id)
  1357.       return $back_attack = false if NON_BACK_ATTACK_ARMOR1.include?(actor.armor1_id)
  1358.       return $back_attack = false if NON_BACK_ATTACK_ARMOR2.include?(actor.armor2_id)
  1359.       return $back_attack = false if NON_BACK_ATTACK_ARMOR3.include?(actor.armor3_id)
  1360.       return $back_attack = false if NON_BACK_ATTACK_ARMOR4.include?(actor.armor4_id)
  1361.       for i in 0...NON_BACK_ATTACK_SKILLS.size
  1362.         return $back_attack = false if actor.skill_id_learn?(NON_BACK_ATTACK_SKILLS[i])
  1363.       end  
  1364.     end
  1365.   end
  1366.   #--------------------------------------------------------------------------
  1367.   def special_preemptive_conditions
  1368.     for i in 0...PREEMPTIVE_SWITCH.size
  1369.       return $preemptive = true if $game_switches[PREEMPTIVE_SWITCH[i]]
  1370.     end
  1371.     for i in 0...NO_PREEMPTIVE_SWITCH.size
  1372.       return $preemptive = false if $game_switches[NON_PREEMPTIVE_SWITCH[i]]
  1373.     end
  1374.   end
  1375.   #--------------------------------------------------------------------------
  1376.   def preemptive_plus
  1377.     $preemptive_plus = false
  1378.     for actor in $game_party.actors
  1379.      return $preemptive_plus = true if PREEMPTIVE_WEAPONS.include?(actor.weapon_id)
  1380.      return $preemptive_plus = true if PREEMPTIVE_ARMOR1.include?(actor.armor1_id)
  1381.      return $preemptive_plus = true if PREEMPTIVE_ARMOR2.include?(actor.armor2_id)
  1382.      return $preemptive_plus = true if PREEMPTIVE_ARMOR3.include?(actor.armor3_id)
  1383.      return $preemptive_plus = true if PREEMPTIVE_ARMOR4.include?(actor.armor4_id)
  1384.       for i in 0...PREEMPTIVE_SKILLS.size
  1385.         return $preemptive_plus = true if actor.skill_id_learn?(PREEMPTIVE_SKILLS[i])
  1386.       end  
  1387.     end
  1388.   end
  1389. end
  1390.  
  1391. #==============================================================================
  1392. # ■ Spriteset_Battle
  1393. #==============================================================================
  1394. class Spriteset_Battle
  1395.   #--------------------------------------------------------------------------
  1396.   attr_reader   :viewport1                
  1397.   attr_reader   :viewport2              
  1398.   attr_accessor :actor_sprites
  1399.   attr_accessor :enemy_sprites
  1400.   #--------------------------------------------------------------------------
  1401.   include N01
  1402.   #--------------------------------------------------------------------------
  1403.   def initialize
  1404.     @viewport1 = Viewport.new(0, 0, 640, 480)
  1405.     @viewport2 = Viewport.new(0, 0, 640, 480)
  1406.     @viewport3 = Viewport.new(0, 0, 640, 480)
  1407.     @viewport4 = Viewport.new(0, 0, 640, 480)
  1408.     @viewport2.z = 101
  1409.     @viewport3.z = 200
  1410.     @viewport4.z = 5000
  1411.     @battleback_sprite = Sprite.new(@viewport1)
  1412.     @battleback_sprite.mirror = true if $back_attack && BACK_ATTACK_BATTLE_BACK_MIRROR
  1413.     @enemy_sprites = []
  1414.     for enemy in $game_troop.enemies
  1415.       @enemy_sprites.push(Sprite_Battler.new(@viewport2, enemy))
  1416.     end
  1417.     @actor_sprites = []
  1418.     for i in 0...$game_party.actors.size
  1419.       @actor_sprites.push(Sprite_Battler.new(@viewport2, $game_party.actors[i]))
  1420.     end
  1421.     @weather = RPG::Weather.new(@viewport1)
  1422.     @picture_sprites = []
  1423.     for i in 51..100
  1424.       @picture_sprites.push(Sprite_Picture.new(@viewport3, $game_screen.pictures[i]))
  1425.     end
  1426.     @timer_sprite = Sprite_Timer.new
  1427.     update
  1428.   end
  1429.   #--------------------------------------------------------------------------
  1430.   def update
  1431.     if $game_party.actors.size > @actor_sprites.size
  1432.       for i in @actor_sprites.size...$game_party.actors.size
  1433.         @actor_sprites.push(Sprite_Battler.new(@viewport2, $game_party.actors[i]))
  1434.       end
  1435.     elsif @actor_sprites.size > $game_party.actors.size
  1436.       for i in 0...@actor_sprites.size
  1437.         @actor_sprites[i].dispose
  1438.       end
  1439.       @actor_sprites = []
  1440.       for i in 0...$game_party.actors.size
  1441.         @actor_sprites.push(Sprite_Battler.new(@viewport2, $game_party.actors[i]))
  1442.       end
  1443.     end
  1444.     for i in 0...$game_party.actors.size
  1445.       @actor_sprites[i].battler = $game_party.actors[i]
  1446.     end
  1447.     if @battleback_name != $game_temp.battleback_name
  1448.       @battleback_name = $game_temp.battleback_name
  1449.       if @battleback_sprite.bitmap != nil
  1450.         @battleback_sprite.bitmap.dispose
  1451.       end
  1452.       @battleback_sprite.bitmap = RPG::Cache.battleback(@battleback_name)
  1453.       @battleback_sprite.src_rect.set(0, 0, 640, 480)
  1454.     end
  1455.     for sprite in @enemy_sprites + @actor_sprites
  1456.       sprite.update
  1457.     end
  1458.     @weather.type = $game_screen.weather_type
  1459.     @weather.max = $game_screen.weather_max
  1460.     @weather.update
  1461.     for sprite in @picture_sprites
  1462.       sprite.update
  1463.     end
  1464.     @timer_sprite.update
  1465.     @viewport1.tone = $game_screen.tone
  1466.     @viewport1.ox = $game_screen.shake
  1467.     @viewport2.tone = $game_screen.tone
  1468.     @viewport2.ox = $game_screen.shake
  1469.     @viewport4.color = $game_screen.flash_color
  1470.     @viewport1.update
  1471.     @viewport2.update
  1472.     @viewport4.update
  1473.   end
  1474.   #--------------------------------------------------------------------------
  1475.   def set_damage_action(actor, index, action)
  1476.     return if index.nil?
  1477.     @actor_sprites[index].damage_action(action) if actor
  1478.     @enemy_sprites[index].damage_action(action) unless actor
  1479.   end
  1480.   #--------------------------------------------------------------------------
  1481.   def set_damage_pop(actor, index, damage)
  1482.     return if index.nil?
  1483.     @actor_sprites[index].damage_pop if actor
  1484.     @enemy_sprites[index].damage_pop unless actor
  1485.   end
  1486.   #--------------------------------------------------------------------------
  1487.   def set_target(actor, index, target)
  1488.     return if index.nil?
  1489.     @actor_sprites[index].get_target(target) if actor
  1490.     @enemy_sprites[index].get_target(target) unless actor
  1491.   end
  1492.   #--------------------------------------------------------------------------
  1493.   def set_action(actor, index, kind)
  1494.     return if index.nil?
  1495.     @actor_sprites[index].start_action(kind) if actor
  1496.     @enemy_sprites[index].start_action(kind) unless actor
  1497.   end  
  1498.   #--------------------------------------------------------------------------
  1499.   def set_stand_by_action(actor, index)
  1500.     return if index.nil?
  1501.     @actor_sprites[index].push_stand_by if actor
  1502.     @enemy_sprites[index].push_stand_by unless actor
  1503.   end
  1504. end
  1505.  
  1506. #==============================================================================
  1507. # ■ Sprite_MoveAnime
  1508. #==============================================================================
  1509. class Sprite_MoveAnime < RPG::Sprite
  1510.   #--------------------------------------------------------------------------
  1511.   attr_accessor :battler
  1512.   attr_accessor :base_x
  1513.   attr_accessor :base_y
  1514.   #--------------------------------------------------------------------------
  1515.   def initialize(viewport,battler = nil)
  1516.     super(viewport)
  1517.     @battler = battler
  1518.     self.visible = false
  1519.     @base_x = 0
  1520.     @base_y = 0
  1521.     @move_x = 0
  1522.     @move_y = 0
  1523.     @moving_x = 0
  1524.     @moving_y = 0
  1525.     @orbit = 0
  1526.     @orbit_plus = 0
  1527.     @orbit_time = 0
  1528.     @through = false
  1529.     @finish = false
  1530.     @time = 0
  1531.     @angle = 0
  1532.     @angling = 0
  1533.   end
  1534.   #--------------------------------------------------------------------------
  1535.   def anime_action(id,mirror,distanse_x,distanse_y,type,speed,orbit,weapon,icon_index,icon_weapon)
  1536.     @time = speed
  1537.     @moving_x = distanse_x / speed
  1538.     @moving_y = distanse_y / speed
  1539.     @through = true if type == 1
  1540.     @orbit_plus = orbit
  1541.     @orbit_time = @time
  1542.     if weapon != ""
  1543.       action = ANIME[weapon].dup
  1544.       @angle = action[0]
  1545.       end_angle = action[1]
  1546.       time = action[2]
  1547.       @angling = (end_angle - @angle)/ time
  1548.       self.angle = @angle
  1549.       self.mirror = mirror
  1550.       if icon_weapon
  1551.         self.bitmap = RPG::Cache.icon(icon_index)
  1552.         self.ox = 12
  1553.         self.oy = 12
  1554.       else
  1555.         self.bitmap = RPG::Cache.character(icon_index, 0)
  1556.         self.ox = self.bitmap.width / 2
  1557.         self.oy = self.bitmap.height / 2
  1558.       end  
  1559.       self.visible = true
  1560.       self.z = 1000
  1561.     end  
  1562.     self.x = @base_x + @move_x
  1563.     self.y = @base_y + @move_y + @orbit
  1564.     if id != 0 && !icon_weapon
  1565.       animation($data_animations[id],true)
  1566.     elsif id != 0 && icon_weapon
  1567.       loop_animation($data_animations[id])
  1568.     end
  1569.   end  
  1570.   #--------------------------------------------------------------------------  
  1571.   def action_reset
  1572.     @moving_x = @moving_y = @move_x = @move_y = @base_x = @base_y = @orbit = 0
  1573.     @orbit_time = @angling = @angle = 0    
  1574.     @through = self.visible = @finish = false
  1575.     dispose_animation
  1576.   end  
  1577.   #--------------------------------------------------------------------------
  1578.   def finish?
  1579.     return @finish
  1580.   end
  1581.   #--------------------------------------------------------------------------
  1582.   def update
  1583.     super
  1584.     @time -= 1
  1585.     if @time >= 0
  1586.       @move_x += @moving_x
  1587.       @move_y += @moving_y
  1588.       if @time < @orbit_time / 2
  1589.         @orbit_plus = @orbit_plus * 5 / 4
  1590.       elsif @time == @orbit_time / 2
  1591.         @orbit_plus *= -1
  1592.       else
  1593.         @orbit_plus = @orbit_plus * 2 / 3
  1594.       end  
  1595.       @orbit += @orbit_plus
  1596.     end    
  1597.     @time = 100 if @time < 0 && @through
  1598.     @finish = true if @time < 0 && !@through
  1599.     self.x = @base_x + @move_x
  1600.     self.y = @base_y + @move_y + @orbit
  1601.     if self.x < -200 or self.x > 840 or self.y < -200 or self.y > 680
  1602.       @finish = true
  1603.     end
  1604.     if self.visible
  1605.       @angle += @angling
  1606.       self.angle = @angle
  1607.     end  
  1608.   end
  1609. end
  1610.  
  1611. #==============================================================================
  1612. # ■ Sprite_Weapon
  1613. #==============================================================================
  1614. class Sprite_Weapon < RPG::Sprite
  1615.   #--------------------------------------------------------------------------
  1616.   include N01
  1617.   #--------------------------------------------------------------------------
  1618.   attr_accessor :battler
  1619.   #--------------------------------------------------------------------------
  1620.   def initialize(viewport,battler = nil)
  1621.     super(viewport)
  1622.     @battler = battler
  1623.     @action = []
  1624.     @move_x = 0
  1625.     @move_y = 0
  1626.     @move_z = 0
  1627.     @plus_x = 0
  1628.     @plus_y = 0
  1629.     @angle = 0
  1630.     @zoom_x = 1
  1631.     @zoom_y = 1
  1632.     @moving_x = 0
  1633.     @moving_y = 0
  1634.     @angling = 0
  1635.     @zooming_x = 1
  1636.     @zooming_y = 1
  1637.     @freeze = -1
  1638.     @mirroring = false
  1639.     @time = ANIME_PATTERN + 1
  1640.     weapon_graphics
  1641.   end
  1642.   #--------------------------------------------------------------------------
  1643.   def dispose
  1644.     self.bitmap.dispose if self.bitmap != nil
  1645.     super
  1646.   end
  1647.   #--------------------------------------------------------------------------
  1648.   def weapon_graphics(left = false)
  1649.     if @battler.actor?
  1650.       weapon = @battler.weapons[0] unless left
  1651.       weapon = @battler.weapons[1] if left
  1652.     else
  1653.       weapon = $data_weapons[@battler.weapon]
  1654.       @mirroring = true if @battler.action_mirror
  1655.     end
  1656.     return if weapon == nil
  1657.     if weapon.graphic == ""
  1658.       self.bitmap = RPG::Cache.icon(weapon.icon_name)
  1659.       @weapon_width = @weapon_height = 24
  1660.     else
  1661.       self.bitmap = RPG::Cache.icon(weapon.graphic)
  1662.       @weapon_width = self.bitmap.width
  1663.       @weapon_height = self.bitmap.height
  1664.     end
  1665.   end
  1666.   #--------------------------------------------------------------------------
  1667.   def freeze(action)
  1668.     @freeze = action
  1669.   end
  1670.   #--------------------------------------------------------------------------
  1671.   def weapon_action(action,loop)
  1672.     if action == ""
  1673.       self.visible = false
  1674.     elsif @weapon_id == 0
  1675.       self.visible = false
  1676.     else
  1677.       @action = ANIME[action]
  1678.       act0 = @action[0]
  1679.       act1 = @action[1]
  1680.       act2 = @action[2]
  1681.       act3 = @action[3]
  1682.       act4 = @action[4]
  1683.       act5 = @action[5]
  1684.       act6 = @action[6]
  1685.       act7 = @action[7]
  1686.       act8 = @action[8]
  1687.       act9 = @action[9]
  1688.       act10 = @action[10]
  1689.       if @mirroring
  1690.         act0 *= -1
  1691.         act3 *= -1
  1692.         act4 *= -1
  1693.         act9 *= -1
  1694.       end
  1695.       if $back_attack && BACK_ATTACK
  1696.         act0 *= -1
  1697.         act3 *= -1
  1698.         act4 *= -1
  1699.         act9 *= -1
  1700.       end
  1701.       time = ANIME_PATTERN
  1702.       if act2
  1703.         self.z = @battler.position_z + 1
  1704.       else
  1705.         self.z = @battler.position_z - 1
  1706.       end
  1707.       if act6
  1708.         if self.mirror
  1709.           self.mirror = false
  1710.         else
  1711.           self.mirror = true
  1712.         end
  1713.       end
  1714.       if @mirroring
  1715.         if self.mirror
  1716.           self.mirror = false
  1717.         else
  1718.           self.mirror = true
  1719.         end
  1720.       end
  1721.       if $back_attack && BACK_ATTACK
  1722.         if self.mirror
  1723.           self.mirror = false
  1724.         else
  1725.           self.mirror = true
  1726.         end
  1727.       end  
  1728.       @moving_x = act0 / time
  1729.       @moving_y = act1 / time
  1730.       @angle = act3
  1731.       self.angle = @angle
  1732.       @angling = (act4 - act3)/ time
  1733.       @angle += (act4 - act3) % time
  1734.       @zooming_x = (1 - act7) / time
  1735.       @zooming_y = (1 - act8) / time
  1736.       if self.mirror
  1737.         case act5
  1738.         when 1
  1739.           act5 = 2
  1740.         when 2
  1741.           act5 = 1
  1742.         when 3
  1743.           act5 = 4
  1744.         when 4
  1745.           act5 = 3
  1746.         end  
  1747.       end    
  1748.       case act5
  1749.       when 0
  1750.         self.ox = @weapon_width / 2
  1751.         self.oy = @weapon_height / 2
  1752.       when 1
  1753.         self.ox = 0
  1754.         self.oy = 0
  1755.       when 2
  1756.         self.ox = @weapon_width
  1757.         self.oy = 0
  1758.       when 3
  1759.         self.ox = 0
  1760.         self.oy = @weapon_height
  1761.       when 4
  1762.         self.ox = @weapon_width
  1763.         self.oy = @weapon_height
  1764.       end  
  1765.       @plus_x = act9
  1766.       @plus_y = act10
  1767.       @loop = true if loop == 0
  1768.       @angle -= @angling
  1769.       @zoom_x -= @zooming_x
  1770.       @zoom_y -= @zooming_y
  1771.       @move_x -= @moving_x
  1772.       @move_y -= @moving_y
  1773.       @move_z = 1000 if act2
  1774.       if @freeze != -1
  1775.         for i in 0..@freeze + 1
  1776.           @angle += @angling
  1777.           @zoom_x += @zooming_x
  1778.           @zoom_y += @zooming_y
  1779.           @move_x += @moving_x
  1780.           @move_y += @moving_y
  1781.         end
  1782.         @angling = 0
  1783.         @zooming_x = 0
  1784.         @zooming_y = 0
  1785.         @moving_x = 0
  1786.         @moving_y = 0
  1787.       end
  1788.       self.visible = true
  1789.     end
  1790.   end  
  1791.   #--------------------------------------------------------------------------
  1792.   def action_reset
  1793.     @moving_x = @moving_y = @move_x = @move_y = @plus_x = @plus_y = 0
  1794.     @angling = @zooming_x = @zooming_y = @angle = self.angle = @move_z = 0
  1795.     @zoom_x = @zoom_y = self.zoom_x = self.zoom_y = 1
  1796.     self.mirror = self.visible = @loop = false
  1797.     @freeze = -1
  1798.     @action = []
  1799.     @time = ANIME_PATTERN + 1
  1800.   end
  1801.   #--------------------------------------------------------------------------
  1802.   def action_loop
  1803.     @angling *= -1
  1804.     @zooming_x *= -1
  1805.     @zooming_y *= -1
  1806.     @moving_x *= -1
  1807.     @moving_y *= -1
  1808.   end  
  1809.   #--------------------------------------------------------------------------
  1810.   def mirroring
  1811.     return @mirroring = false if @mirroring
  1812.     @mirroring = true
  1813.   end  
  1814.   #--------------------------------------------------------------------------
  1815.   def action
  1816.     return if @time <= 0
  1817.     @time -= 1
  1818.     @angle += @angling
  1819.     @zoom_x += @zooming_x
  1820.     @zoom_y += @zooming_y
  1821.     @move_x += @moving_x
  1822.     @move_y += @moving_y
  1823.     if @loop && @time == 0
  1824.       @time = ANIME_PATTERN + 1
  1825.       action_loop
  1826.     end
  1827.   end  
  1828.   #--------------------------------------------------------------------------
  1829.   def update
  1830.     super
  1831.     self.angle = @angle
  1832.     self.zoom_x = @zoom_x
  1833.     self.zoom_y = @zoom_y
  1834.     self.x = @battler.position_x + @move_x + @plus_x
  1835.     self.y = @battler.position_y + @move_y + @plus_y
  1836.     self.z = @battler.position_z + @move_z - 1
  1837.   end
  1838. end
  1839.  
  1840. #==============================================================================
  1841. # Game_Party
  1842. #==============================================================================
  1843. class Game_Party
  1844.   #--------------------------------------------------------------------------
  1845.   include N01
  1846.   #--------------------------------------------------------------------------
  1847.   def add_actor(actor_id)
  1848.     actor = $game_actors[actor_id]
  1849.     if @actors.size < MAX_MEMBER and not @actors.include?(actor)
  1850.       @actors.push(actor)
  1851.       $game_player.refresh
  1852.     end
  1853.   end
  1854. end
  1855.  
  1856. #==============================================================================
  1857. # ■ RPG::Weapon
  1858. #==============================================================================
  1859. class RPG::Weapon
  1860.   #--------------------------------------------------------------------------
  1861.   def magic?
  1862.     return false
  1863.   end
  1864. end
  1865.  
  1866. #==============================================================================
  1867. # ■ RPG::Skill
  1868. #==============================================================================
  1869. class RPG::Skill
  1870.   #--------------------------------------------------------------------------
  1871.   def magic?
  1872.     return @atk_f == 0 ? true : false
  1873.   end
  1874. end
  1875.  
  1876. #==============================================================================
  1877. # ■ RPG::Item
  1878. #==============================================================================
  1879. class RPG::Item
  1880.   #--------------------------------------------------------------------------
  1881.   def magic?
  1882.     return false
  1883.   end
  1884. end
  1885.  
  1886. #==============================================================================
  1887. # ■ RPG::Cache
  1888. #==============================================================================
  1889. module RPG::Cache
  1890.   def self.faces(filename, hue = 0)
  1891.     self.load_bitmap('Graphics/Faces/', filename, hue)
  1892.   end
  1893. end
  1894.  
  1895. #==============================================================================
  1896. # ■ Game_Battler
  1897. #==============================================================================
  1898. class Game_Battler
  1899.   #--------------------------------------------------------------------------
  1900.   include N01
  1901.   #--------------------------------------------------------------------------
  1902.   attr_accessor :sp_damage
  1903.   attr_accessor :collapse
  1904.   attr_accessor :move_x
  1905.   attr_accessor :move_y
  1906.   attr_accessor :move_z
  1907.   attr_accessor :jump
  1908.   attr_accessor :active
  1909.   attr_accessor :non_dead
  1910.   attr_accessor :slip_damage
  1911.   attr_accessor :derivation
  1912.   attr_accessor :individual
  1913.   attr_accessor :play
  1914.   attr_accessor :force_action
  1915.   attr_accessor :force_target
  1916.   attr_accessor :revival
  1917.   attr_accessor :reflex
  1918.   attr_accessor :absorb
  1919.   attr_accessor :anime_mirror
  1920.   attr_accessor :dying
  1921.   attr_accessor :state_animation_id
  1922.   attr_accessor :dead_anim
  1923.   attr_accessor :missed
  1924.   attr_accessor :evaded
  1925.   attr_accessor :true_immortal
  1926.   attr_accessor :defense_pose
  1927.   attr_reader   :base_position_x
  1928.   attr_reader   :base_position_y  
  1929.   attr_reader   :base_height  
  1930.   #--------------------------------------------------------------------------
  1931.   alias initialize_n01 initialize
  1932.   def initialize
  1933.     initialize_n01
  1934.     @move_x = @move_y = @move_z = @plus_y = @jump = @derivation = @act_time = 0
  1935.     @force_action = @force_target = @base_position_x = @base_position_y = 0
  1936.     @absorb = @play = @now_state = @state_frame = @state_animation_id = 0
  1937.     @active = @non_dead = @individual = @slip_damage = @revival = false
  1938.     @collapse = @sp_damage = @anime_mirror = @dying = false
  1939.     @evaded = @missed = false
  1940.     @anim_states = []
  1941.   end
  1942.   #--------------------------------------------------------------------------
  1943.   def state_id
  1944.     return @states[@states.size - 1]
  1945.   end
  1946.   #--------------------------------------------------------------------------
  1947.   def in_danger
  1948.     return @hp <= self.maxhp / 4
  1949.   end
  1950.   #--------------------------------------------------------------------------
  1951.   def battler_states
  1952.     bat_states = []
  1953.     for i in self.states
  1954.       bat_states.push($data_states[i])
  1955.     end
  1956.     return bat_states
  1957.   end
  1958.   #--------------------------------------------------------------------------
  1959.   def apply_variance(damage, variance)
  1960.     if damage != 0
  1961.       amp = [damage.abs * variance / 100, 0].max
  1962.       damage += rand(amp+1) + rand(amp+1) - amp
  1963.     end
  1964.     return damage
  1965.   end
  1966.   #--------------------------------------------------------------------------
  1967.   def state_animation_id
  1968.     return 0 if @states.empty?
  1969.     return 0 if @states.include?(1)
  1970.     @state_frame -= 1 if @state_frame > 0
  1971.     return @state_animation_id if @state_frame > 0
  1972.     if @anim_states.empty?
  1973.       for state in @states
  1974.         @anim_states << state if $data_states[state].animation_id > 0
  1975.       end
  1976.     end
  1977.     now_state = @anim_states.shift
  1978.     return 0 if now_state.nil?
  1979.     @state_animation_id = $data_states[now_state].animation_id
  1980.     return 0 if $data_animations[@state_animation_id].nil?
  1981.     @state_frame = $data_animations[@state_animation_id].frame_max * STATE_CYCLE_TIME * 2
  1982.     return @state_animation_id
  1983.   end
  1984.   #--------------------------------------------------------------------------
  1985.   def skill_can_use?(skill_id)
  1986.     skill = $data_skills[skill_id]
  1987.     if skill.extension.include?("CONSUMEHP")
  1988.       return false if calc_sp_cost(self, skill) >= self.hp
  1989.     else  
  1990.       return false if calc_sp_cost(self, skill) > self.sp
  1991.     end
  1992.     return false if dead?
  1993.     return false if skill.atk_f == 0 and self.restriction == 1
  1994.     occasion = skill.occasion
  1995.     return (occasion == 0 or occasion == 1) if $game_temp.in_battle
  1996.     return (occasion == 0 or occasion == 2)
  1997.   end  
  1998.   #--------------------------------------------------------------------------
  1999.   def calc_sp_cost(user, skill)
  2000.     cost = skill.sp_cost
  2001.     if skill.extension.include?("%COSTMAX")
  2002.       return user.maxhp * cost / 100 if skill.extension.include?("CONSUMEHP")
  2003.       return user.maxsp * cost / 100
  2004.     elsif skill.extension.include?("%COSTNOW")
  2005.       return user.hp * cost / 100 if skill.extension.include?("CONSUMEHP")
  2006.       return user.sp * cost / 100
  2007.     end
  2008.     return cost
  2009.   end
  2010.   #--------------------------------------------------------------------------
  2011.   def consum_skill_cost(skill)
  2012.     return false unless skill_can_use?(skill.id)
  2013.     cost = calc_sp_cost(self, skill)
  2014.     return self.hp -= cost if skill.extension.include?("CONSUMEHP")
  2015.     return self.sp -= cost
  2016.   end
  2017.   #--------------------------------------------------------------------------
  2018.   def attack_effect(attacker)
  2019.     self.critical = @evaded = @missed = false
  2020.     hit_result = (rand(100) < attacker.hit)
  2021.     set_attack_result(attacker) if hit_result
  2022.     weapon = attacker.actor? ? $data_weapons[attacker.weapon_id] : nil
  2023.     if hit_result
  2024.       set_attack_state_change(attacker)
  2025.     else
  2026.       self.critical = false
  2027.       @missed = true
  2028.     end
  2029.     self.damage = POP_EVA if @evaded
  2030.     self.damage = POP_MISS if @missed
  2031.     return true
  2032.   end
  2033.   #--------------------------------------------------------------------------
  2034.   def perfect_attack_effect(attacker)
  2035.     self.critical = @evaded = @missed = false
  2036.     set_attack_result(attacker)
  2037.     weapon = attacker.actor? ? $data_weapons[attacker.weapon_id] : nil
  2038.     set_attack_state_change(attacker)
  2039.     return true
  2040.   end
  2041.   #--------------------------------------------------------------------------
  2042.   def set_attack_result(attacker)
  2043.     set_attack_damage_value(attacker)
  2044.     if self.damage > 0
  2045.       self.damage /= 2 if self.guarding?
  2046.       set_attack_critical(attacker)
  2047.       set_critical_damage(attacker) if self.critical
  2048.     end
  2049.     apply_variance(15) if self.damage.abs > 0
  2050.     set_attack_hit_value(attacker)
  2051.   end
  2052.   #--------------------------------------------------------------------------
  2053.   def set_attack_damage_value(attacker)
  2054.     case DAMAGE_ALGORITHM_TYPE
  2055.     when 0
  2056.       atk = [attacker.atk - (self.pdef / 2), 0].max
  2057.       str = [20 + attacker.str, 0].max
  2058.     when 1
  2059.       atk = [attacker.atk - ((attacker.atk * self.pdef) / 1000), 0].max
  2060.       str = [20 + attacker.str, 0].max
  2061.     when 2
  2062.       atk = 20
  2063.       str = [(attacker.str * 4) - (self.dex * 2) , 0].max
  2064.     when 3
  2065.       atk = [(10 + attacker.atk) - (self.pdef / 2), 0].max
  2066.       str = [(20 + attacker.str) - (self.dex / 2), 0].max
  2067.     end
  2068.     self.damage = atk * str / 20
  2069.     self.damage = 1 if self.damage == 0 and (rand(100) > 40)
  2070.     self.damage *= elements_correct(attacker.element_set)
  2071.     self.damage /= 100
  2072.   end
  2073.   #--------------------------------------------------------------------------
  2074.   def apply_variance(variance)
  2075.     amp = [self.damage.abs * variance / 100, 1].max
  2076.     self.damage += rand(amp + 1) + rand(amp + 1) - amp
  2077.   end
  2078.   #--------------------------------------------------------------------------
  2079.   def set_attack_hit_value(attacker)
  2080.     atk_hit = DAMAGE_ALGORITHM_TYPE > 1 ? attacker.agi : attacker.dex
  2081.     eva = (8 * self.agi / atk_hit) + self.eva
  2082.     hit = self.damage < 0 ? 100 : 100 - eva
  2083.     hit = self.cant_evade? ? 100 : hit
  2084.     hit_result = (rand(100) < hit)
  2085.     @evaded = true unless hit_result
  2086.   end
  2087.   #--------------------------------------------------------------------------
  2088.   def set_attack_critical(attacker)
  2089.     atk_crt = DAMAGE_ALGORITHM_TYPE > 1 ? attacker.agi : attacker.dex
  2090.     self.critical = rand(100) < 5 * atk_crt / self.agi
  2091.   end
  2092.   #--------------------------------------------------------------------------
  2093.   def set_critical_damage(attacker)
  2094.     self.damage += self.damage
  2095.   end
  2096.   #--------------------------------------------------------------------------
  2097.   def set_attack_state_change(attacker)
  2098.     remove_states_shock
  2099.     effective = apply_damage(attacker)
  2100.     @state_changed = false
  2101.     states_plus(attacker.plus_state_set)
  2102.     states_minus(attacker.minus_state_set)
  2103.     return effective
  2104.   end
  2105.   #--------------------------------------------------------------------------
  2106.   def skill_effect(user, skill)
  2107.     self.critical = @evaded = @missed = false
  2108.     if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
  2109.        ((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
  2110.       return false
  2111.     end
  2112.     effective = false
  2113.     effective |= skill.common_event_id > 0
  2114.     hit = skill.hit
  2115.     hit *= set_skill_hit(user, skill)
  2116.     hit_result = (rand(100) < hit)
  2117.     effective |= hit < 100
  2118.     effective |= set_skill_result(user, skill, effective) if hit_result
  2119.     if hit_result
  2120.       effective |= set_skill_state_change(user, skill, effective)
  2121.     else
  2122.       @missed = true unless @evaded
  2123.     end
  2124.     self.damage = nil unless $game_temp.in_battle
  2125.     self.damage = POP_EVA if @evaded
  2126.     self.damage = POP_MISS if @missed
  2127.     return effective
  2128.   end
  2129.   #--------------------------------------------------------------------------
  2130.   def perfect_skill_effect(user, skill)
  2131.     self.critical = @evaded = @missed = false
  2132.     if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
  2133.        ((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
  2134.       return false
  2135.     end
  2136.     effective = false
  2137.     effective |= skill.common_event_id > 0
  2138.     effective |= set_skill_result(user, skill, effective)
  2139.     effective |= set_skill_state_change(user, skill, effective)
  2140.     self.damage = nil unless $game_temp.in_battle
  2141.     return effective
  2142.   end
  2143.   #--------------------------------------------------------------------------
  2144.   def set_skill_hit(user, skill)
  2145.     if skill.magic?
  2146.       return 1
  2147.     else
  2148.       return user.hit / 100
  2149.     end
  2150.   end
  2151.   #--------------------------------------------------------------------------
  2152.   def set_skill_result(user, skill, effective)
  2153.     set_skill_damage_value(user, skill)
  2154.     if self.damage > 0
  2155.       self.damage /= 2 if self.guarding?
  2156.     end
  2157.     apply_variance(skill.variance) if skill.variance > 0 and self.damage.abs > 0
  2158.     effective |= set_skill_hit_value(user, skill, effective)
  2159.     return effective
  2160.   end
  2161.   #--------------------------------------------------------------------------
  2162.   def set_skill_damage_value(user, skill)
  2163.     power = set_skill_power(user, skill)
  2164.     if power > 0
  2165.       case DAMAGE_ALGORITHM_TYPE
  2166.       when 0,3
  2167.         power -= (self.pdef * skill.pdef_f) / 200
  2168.         power -= (self.mdef * skill.mdef_f) / 200
  2169.       when 1
  2170.         power -= (power * (self.pdef * skill.pdef_f)) / 100000
  2171.         power -= (power * (self.mdef * skill.mdef_f)) / 100000
  2172.       when 2
  2173.         power -= ((self.dex * 2 * skill.pdef_f) / 100)
  2174.         power -= ((self.int * 1 * skill.mdef_f) / 100)
  2175.       end
  2176.       power = [power, 0].max
  2177.     end
  2178.     rate = set_skill_rate(user, skill) unless DAMAGE_ALGORITHM_TYPE == 2
  2179.     rate = [rate, 0].max
  2180.     self.damage = power * rate / 20
  2181.     self.damage *= elements_correct(skill.element_set)
  2182.     self.damage /= 100
  2183.   end
  2184.   #--------------------------------------------------------------------------
  2185.   def set_skill_power(user, skill)
  2186.     case DAMAGE_ALGORITHM_TYPE
  2187.     when 0,1,3
  2188.       power = skill.power + ((user.atk * skill.atk_f) / 100)
  2189.     when 2
  2190.       user_str = (user.str * 4 * skill.str_f / 100)
  2191.       user_int = (user.int * 2 * skill.int_f / 100)
  2192.       if skill.power > 0
  2193.         power = skill.power + user_str + user_int
  2194.       else
  2195.         power = skill.power - user_str - user_int
  2196.       end
  2197.     end
  2198.     return power
  2199.   end
  2200.   #--------------------------------------------------------------------------
  2201.   def set_skill_rate(user, skill)
  2202.     case DAMAGE_ALGORITHM_TYPE
  2203.     when 0,1,2
  2204.       rate = 20
  2205.     when 3
  2206.       rate = 40
  2207.       rate -= (self.dex / 2 * skill.pdef_f / 200)
  2208.       rate -= ((self.dex + self.int)/ 4 * skill.mdef_f / 200)
  2209.     end
  2210.     rate += (user.str * skill.str_f / 100)
  2211.     rate += (user.dex * skill.dex_f / 100)
  2212.     rate += (user.agi * skill.agi_f / 100)
  2213.     rate += (user.int * skill.int_f / 100)
  2214.     return rate
  2215.   end
  2216.   #--------------------------------------------------------------------------
  2217.   def set_skill_hit_value(user, skill, effective)
  2218.     atk_hit = DAMAGE_ALGORITHM_TYPE > 1 ? user.agi : user.dex
  2219.     eva = 8 * self.agi / atk_hit + self.eva
  2220.     hit = self.damage < 0 ? 100 : 100 - eva * skill.eva_f / 100
  2221.     hit = self.cant_evade? ? 100 : hit
  2222.     hit_result = (rand(100) < hit)
  2223.     @evaded = true unless hit_result
  2224.     effective |= hit < 100
  2225.     return effective
  2226.   end
  2227.   #--------------------------------------------------------------------------
  2228.   def set_skill_state_change(user, skill, effective = false)
  2229.     if skill.power != 0 and not skill.magic?
  2230.       remove_states_shock
  2231.       effective = true
  2232.     end
  2233.     effective |= apply_damage(user)
  2234.     @state_changed = false
  2235.     effective |= states_plus(skill.plus_state_set)
  2236.     effective |= states_minus(skill.minus_state_set)
  2237.     if skill.power == 0
  2238.       self.damage = ""
  2239.       @missed = true unless @state_changed
  2240.     end
  2241.     return effective
  2242.   end
  2243.   #--------------------------------------------------------------------------
  2244.   def apply_damage(user)
  2245.     return true if @evaded or @missed or not self.damage.is_a?(Numeric)
  2246.     if self.sp_damage
  2247.       last_sp = self.sp
  2248.       self.sp -= self.damage
  2249.       effective = self.sp != last_sp
  2250.     else
  2251.       last_hp = self.hp
  2252.       self.hp -= self.damage
  2253.       effective = self.hp != last_hp
  2254.     end
  2255.     return effective
  2256.   end
  2257.   #--------------------------------------------------------------------------
  2258.   def item_effect(item)
  2259.     self.critical = @evaded = @missed = false
  2260.     if ((item.scope == 3 or item.scope == 4) and self.hp == 0) or
  2261.        ((item.scope == 5 or item.scope == 6) and self.hp >= 1)
  2262.       return false
  2263.     end
  2264.     effective = false
  2265.     effective |= item.common_event_id > 0
  2266.     hit_result = (rand(100) < item.hit)
  2267.     @missed = true unless hit_result
  2268.     effective |= item.hit < 100
  2269.     if hit_result == true
  2270.       effective |= make_item_damage_value(item)
  2271.     else
  2272.       @missed = true
  2273.     end
  2274.     self.damage = nil unless $game_temp.in_battle
  2275.     self.damage = POP_MISS if @missed
  2276.     return effective
  2277.   end
  2278.   #--------------------------------------------------------------------------
  2279.   def perfect_item_effect(item)
  2280.     self.critical = @evaded = @missed = false
  2281.     if ((item.scope == 3 or item.scope == 4) and self.hp == 0) or
  2282.        ((item.scope == 5 or item.scope == 6) and self.hp >= 1)
  2283.       return false
  2284.     end
  2285.     effective = false
  2286.     effective |= item.common_event_id > 0
  2287.     effective |= item.hit < 100
  2288.     effective |= make_item_damage_value(item)
  2289.     self.damage = nil unless $game_temp.in_battle
  2290.     self.damage = POP_MISS if @missed
  2291.     return effective
  2292.   end
  2293.   #--------------------------------------------------------------------------
  2294.   def make_item_damage_value(item)
  2295.     recover_hp = maxhp * item.recover_hp_rate / 100 + item.recover_hp
  2296.     recover_sp = maxsp * item.recover_sp_rate / 100 + item.recover_sp
  2297.     if recover_hp < 0
  2298.       recover_hp += self.pdef * item.pdef_f / 20
  2299.       recover_hp += self.mdef * item.mdef_f / 20
  2300.       recover_hp = [recover_hp, 0].min
  2301.     end
  2302.     recover_hp *= elements_correct(item.element_set)
  2303.     recover_hp /= 100
  2304.     recover_sp *= elements_correct(item.element_set)
  2305.     recover_sp /= 100
  2306.     if item.variance > 0 and recover_hp.abs > 0
  2307.       amp = [recover_hp.abs * item.variance / 100, 1].max
  2308.       recover_hp += rand(amp+1) + rand(amp+1) - amp
  2309.     end
  2310.     if item.variance > 0 and recover_sp.abs > 0
  2311.       amp = [recover_sp.abs * item.variance / 100, 1].max
  2312.       recover_sp += rand(amp+1) + rand(amp+1) - amp
  2313.     end
  2314.     recover_hp /= 2 if recover_hp < 0 and self.guarding?
  2315.     self.damage = -recover_hp
  2316.     last_hp = self.hp
  2317.     last_sp = self.sp
  2318.     self.hp += recover_hp
  2319.     self.sp += recover_sp
  2320.     effective |= self.hp != last_hp
  2321.     effective |= self.sp != last_sp
  2322.     @state_changed = false
  2323.     effective |= states_plus(item.plus_state_set)
  2324.     effective |= states_minus(item.minus_state_set)
  2325.     if item.parameter_type > 0 and item.parameter_points != 0
  2326.       case item.parameter_type
  2327.       when 1
  2328.         @maxhp_plus += item.parameter_points
  2329.       when 2
  2330.         @maxsp_plus += item.parameter_points
  2331.       when 3
  2332.         @str_plus += item.parameter_points
  2333.       when 4
  2334.         @dex_plus += item.parameter_points
  2335.       when 5
  2336.         @agi_plus += item.parameter_points
  2337.       when 6
  2338.         @int_plus += item.parameter_points
  2339.       end
  2340.       effective = true
  2341.     end
  2342.     if item.recover_hp_rate == 0 and item.recover_hp == 0
  2343.       self.damage = ""
  2344.       if item.recover_sp_rate == 0 and item.recover_sp == 0 and
  2345.          (item.parameter_type == 0 or item.parameter_points == 0)
  2346.         unless @state_changed
  2347.           @missed = true
  2348.         end
  2349.       end
  2350.     end
  2351.     return effective
  2352.   end
  2353.   #--------------------------------------------------------------------------
  2354.   alias skill_effect_n01 skill_effect
  2355.   def skill_effect(user, skill)
  2356.     now_hp = self.hp
  2357.     if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
  2358.        ((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
  2359.       return false
  2360.     end
  2361.     effective = skill_effect_n01(user, skill)
  2362.     return if effective == false
  2363.     check_extension(skill)
  2364.     if @ratio_maxdamage != nil
  2365.       self.damage = self.maxhp * @ratio_maxdamage / 100 unless @sp_damage
  2366.       self.damage = self.maxsp * @ratio_maxdamage / 100 if @sp_damage
  2367.     end
  2368.     if @ratio_nowdamage != nil
  2369.       self.damage = self.hp * @ratio_nowdamage / 100 unless @sp_damage
  2370.       self.damage = self.sp * @ratio_nowdamage / 100 if @sp_damage
  2371.     end
  2372.     if @cost_damage
  2373.       cost = calc_sp_cost(user, skill)
  2374.       if skill.extension.include?("CONSUMEHP")
  2375.         self.damage = self.damage * cost / user.maxhp
  2376.       else
  2377.         self.damage = self.damage * cost / user.maxsp
  2378.       end  
  2379.     end
  2380.     self.damage = self.damage * user.hp / user.maxhp if @nowhp_damage
  2381.     self.damage = self.damage * user.sp / user.maxsp if @nowsp_damage
  2382.     if @sp_damage
  2383.       self.hp = now_hp
  2384.       self.sp -= self.damage
  2385.     elsif @extension
  2386.       self.hp = now_hp
  2387.       self.hp -= self.damage
  2388.     end
  2389.     return true
  2390.   end
  2391.   #--------------------------------------------------------------------------
  2392.   alias perfect_skill_effect_n01 perfect_skill_effect
  2393.   def perfect_skill_effect(user, skill)
  2394.     now_hp = self.hp
  2395.     if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
  2396.        ((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
  2397.       return false
  2398.     end
  2399.     effective = perfect_skill_effect_n01(user, skill)
  2400.     return if effective == false
  2401.     check_extension(skill)
  2402.     if @ratio_maxdamage != nil
  2403.       self.damage = self.maxhp * @ratio_maxdamage / 100 unless @sp_damage
  2404.       self.damage = self.maxsp * @ratio_maxdamage / 100 if @sp_damage
  2405.     end
  2406.     if @ratio_nowdamage != nil
  2407.       self.damage = self.hp * @ratio_nowdamage / 100 unless @sp_damage
  2408.       self.damage = self.sp * @ratio_nowdamage / 100 if @sp_damage
  2409.     end
  2410.     if @cost_damage
  2411.       cost = calc_sp_cost(user, skill)
  2412.       if skill.extension.include?("CONSUMEHP")
  2413.         self.damage = self.damage * cost / user.maxhp
  2414.       else
  2415.         self.damage = self.damage * cost / user.maxsp
  2416.       end  
  2417.     end
  2418.     self.damage = self.damage * user.hp / user.maxhp if @nowhp_damage
  2419.     self.damage = self.damage * user.sp / user.maxsp if @nowsp_damage
  2420.     if @sp_damage
  2421.       self.hp = now_hp
  2422.       self.sp -= self.damage
  2423.     elsif @extension
  2424.       self.hp = now_hp
  2425.       self.hp -= self.damage
  2426.     end
  2427.     return true
  2428.   end
  2429.   #--------------------------------------------------------------------------
  2430.   def check_extension(skill)
  2431.     @extension = false
  2432.     @sp_damage = false
  2433.     @cost_damage = false
  2434.     @nowhp_damage = false
  2435.     @nowsp_damage = false
  2436.     @ratio_maxdamage = nil
  2437.     @ratio_nowdamage = nil
  2438.     for ext in skill.extension
  2439.       break if self.damage == "Errou!" or self.damage == "" or self.damage == 0
  2440.       if ext == "SPDAMAGE"
  2441.         next @sp_damage = true
  2442.       elsif ext == "COSTPOWER"  
  2443.         @extension = true
  2444.         next @cost_damage = true
  2445.       elsif ext == "HPNOWPOWER"
  2446.         @extension = true
  2447.         next @nowhp_damage = true
  2448.       elsif ext == "MPNOWPOWER"
  2449.         @extension = true
  2450.         next @nowsp_damage = true
  2451.       else
  2452.         name = ext.split('')
  2453.         if name[7] == "M"
  2454.           name = name.join
  2455.           name.slice!("%DAMAGEMAX/")
  2456.           @extension = true
  2457.           next @ratio_maxdamage = name.to_i
  2458.         elsif name[7] == "N"
  2459.           name = name.join
  2460.           name.slice!("%DAMAGENOW/")
  2461.           @extension = true
  2462.           next @ratio_nowdamage = name.to_i
  2463.         end  
  2464.       end
  2465.     end  
  2466.   end
  2467.   #--------------------------------------------------------------------------
  2468.   def change_base_position(x, y)
  2469.     @base_position_x = x
  2470.     @base_position_y = y
  2471.   end
  2472.   #--------------------------------------------------------------------------
  2473.   def reset_coordinate
  2474.     @move_x = @move_y = @move_z = @jump = @derivation = 0
  2475.     @active = @non_dead = @individual = false    
  2476.   end
  2477. end  
  2478.  
  2479. #==============================================================================
  2480. # ■ Game_Actor
  2481. #==============================================================================
  2482. class Game_Actor < Game_Battler
  2483.   #--------------------------------------------------------------------------
  2484.   attr_reader   :armor5_id
  2485.   attr_reader   :armor6_id
  2486.   attr_reader   :armor7_id
  2487.   attr_accessor :actor_height
  2488.   attr_accessor :two_swords_change
  2489.   #--------------------------------------------------------------------------
  2490.   include N01
  2491.   #--------------------------------------------------------------------------
  2492.   def actor?
  2493.     return true
  2494.   end
  2495.   #--------------------------------------------------------------------------
  2496.   def weapons
  2497.     return [$data_weapons[@weapon_id]]
  2498.   end
  2499.   #--------------------------------------------------------------------------
  2500.   def armors
  2501.     result = []
  2502.     result << $data_armors[@armor1_id]
  2503.     result << $data_armors[@armor2_id]
  2504.     result << $data_armors[@armor3_id]
  2505.     result << $data_armors[@armor4_id]
  2506.     return result
  2507.   end
  2508.   #--------------------------------------------------------------------------
  2509.   def equips
  2510.     return weapons + armors
  2511.   end
  2512.   #--------------------------------------------------------------------------
  2513.   def skill_id_learn?(skill_id)
  2514.     return @skills.include?(skill_id)
  2515.   end
  2516.   #--------------------------------------------------------------------------
  2517.   def exp=(exp)
  2518.     @exp = [exp, 0].max
  2519.     while @exp >= @exp_list[@level+1] and @exp_list[@level+1] > 0
  2520.       @level += 1
  2521.       for j in $data_classes[@class_id].learnings
  2522.         if j.level == @level
  2523.           learn_skill(j.skill_id)
  2524.         end
  2525.       end
  2526.     end
  2527.     while @exp < @exp_list[@level]
  2528.       @level -= 1
  2529.     end
  2530.     @hp = [@hp, self.maxhp].min
  2531.     @sp = [@sp, self.maxsp].min
  2532.   end
  2533.   #--------------------------------------------------------------------------
  2534.   def base_atk
  2535.     n = 0
  2536.     for item in weapons.compact do n += item.atk end
  2537.     n = UNARMED_ATTACK if weapons[0] == nil and weapons[1] == nil
  2538.     return n
  2539.   end
  2540.   #--------------------------------------------------------------------------
  2541.   def base_pdef
  2542.     n = 0
  2543.     for item in equips.compact do n += item.pdef end
  2544.     return n
  2545.   end
  2546.   #--------------------------------------------------------------------------
  2547.   def base_mdef
  2548.     n = 0
  2549.     for item in equips.compact do n += item.mdef end
  2550.     return n
  2551.   end
  2552.   #--------------------------------------------------------------------------
  2553.   def base_eva
  2554.     n = 0
  2555.     for item in armors.compact do n += item.eva end
  2556.     return n
  2557.   end
  2558.   #--------------------------------------------------------------------------
  2559.   def graphic_change(character_name)
  2560.     @character_name = character_name
  2561.   end
  2562.   #--------------------------------------------------------------------------
  2563.   def perform_collapse
  2564.     $game_system.se_play($data_system.actor_collapse_se) if $game_temp.in_battle and dead?
  2565.   end
  2566.   #--------------------------------------------------------------------------
  2567.   def base_position
  2568.     base = ACTOR_POSITION[self.index]
  2569.     @base_position_x = base[0]
  2570.     @base_position_y = base[1]
  2571.     @base_position_x = 640 - base[0] if $back_attack and BACK_ATTACK_MIRROR
  2572.   end
  2573.   #--------------------------------------------------------------------------
  2574.   def actor_height
  2575.     @base_height = 0 if CURSOR_TYPE != 1
  2576.     @base_height = 72 if CURSOR_TYPE == 1
  2577.     return @base_height
  2578.   end
  2579.   #--------------------------------------------------------------------------
  2580.   def position_x
  2581.     return 0 if self.index == nil
  2582.     return @base_position_x + @move_x
  2583.   end
  2584.   #--------------------------------------------------------------------------
  2585.   def position_y
  2586.     return 0 if self.index == nil
  2587.     return @base_position_y + @move_y + @jump
  2588.   end
  2589.   #--------------------------------------------------------------------------
  2590.   def position_z
  2591.     return 0 if self.index == nil
  2592.     return position_y + @move_z - @jump + 200
  2593.   end  
  2594. end
  2595.  
  2596. #==============================================================================
  2597. # ■ Game_Enemy
  2598. #==============================================================================
  2599. class Game_Enemy < Game_Battler
  2600.   #--------------------------------------------------------------------------
  2601.   include N01
  2602.   #--------------------------------------------------------------------------
  2603.   attr_accessor :adj_speed
  2604.   attr_accessor :act_time
  2605.   #--------------------------------------------------------------------------
  2606.   def actor?
  2607.     return false
  2608.   end
  2609.   #--------------------------------------------------------------------------
  2610.   def make_action_speed2(adj)
  2611.     @adj_speed = @current_action.speed if @adj_speed == nil
  2612.     @adj_speed = @adj_speed * adj / 100
  2613.   end
  2614.   #--------------------------------------------------------------------------
  2615.   def perform_collapse
  2616.     @force_action = ["N01collapse"] if $game_temp.in_battle and dead?
  2617.   end
  2618.   #--------------------------------------------------------------------------
  2619.   def element_set2
  2620.     return []
  2621.   end
  2622.   #--------------------------------------------------------------------------
  2623.   def base_position
  2624.     return if self.index == nil
  2625.     bitmap = Bitmap.new("Graphics/Battlers/" + @battler_name) if !self.anime_on
  2626.     bitmap = Bitmap.new("Graphics/Characters/" + @battler_name) if self.anime_on && WALK_ANIME
  2627.     bitmap = Bitmap.new("Graphics/Characters/" + @battler_name + "_1") if self.anime_on && !WALK_ANIME
  2628.     height = bitmap.height
  2629.     @base_position_x = self.screen_x + self.position_plus[0]
  2630.     @base_position_y = self.screen_y + self.position_plus[1] - height / 3 + 32
  2631.     @base_position_x = 640 - self.screen_x - self.position_plus[0] if $back_attack and BACK_ATTACK_MIRROR
  2632.     @base_height = 0 if CURSOR_TYPE == 0
  2633.     @base_height = height / 3 + 64 if CURSOR_TYPE == 1 if !self.anime_on
  2634.     @base_height = height /12 + 64 if CURSOR_TYPE == 1 if self.anime_on
  2635.     @base_height = -(height / 3) if CURSOR_TYPE == 2 if !self.anime_on
  2636.     @base_height = -(height /12) if CURSOR_TYPE == 2 if self.anime_on
  2637.     bitmap.dispose
  2638.   end
  2639.   #--------------------------------------------------------------------------
  2640.   def enemy_height
  2641.     return @base_height
  2642.   end
  2643.   #--------------------------------------------------------------------------
  2644.   def position_x
  2645.     return @base_position_x - @move_x
  2646.   end
  2647.   #--------------------------------------------------------------------------
  2648.   def position_y
  2649.     return @base_position_y + @move_y + @jump
  2650.   end
  2651.   #--------------------------------------------------------------------------
  2652.   def position_z
  2653.     return position_y + @move_z - @jump + 200
  2654.   end
  2655. end
  2656.  
  2657. #==============================================================================
  2658. # Arrow_Base
  2659. #==============================================================================
  2660. class Arrow_Base < Sprite
  2661.   #--------------------------------------------------------------------------
  2662.   include N01
  2663.   #--------------------------------------------------------------------------
  2664.   def update_multi_arrow
  2665.     return if @arrows == nil or @arrows == []
  2666.     for i in 0...@arrows.size
  2667.       @blink_count = (@blink_count + 1) % 40
  2668.       if @blink_count < 20
  2669.         @arrows[i].src_rect.set(128, 96, 32, 32) if @arrows[i] != nil
  2670.       else
  2671.         @arrows[i].src_rect.set(160, 96, 32, 32) if @arrows[i] != nil
  2672.       end
  2673.     end
  2674.   end
  2675.   #--------------------------------------------------------------------------
  2676.   def dispose_multi_arrow
  2677.     for i in 0...@arrows.size
  2678.       @arrows[i].dispose if @arrows[i] != nil
  2679.     end
  2680.   end
  2681. end
  2682.  
  2683. #==============================================================================
  2684. # Arrow_Enemy_All
  2685. #==============================================================================
  2686. class Arrow_Enemy_All < Arrow_Base
  2687.   #--------------------------------------------------------------------------
  2688.   def initialize(viewport)
  2689.     super(viewport)
  2690.     @arrows = []
  2691.     for battler in $game_troop.enemies
  2692.       if battler.exist?
  2693.         @arrows[battler.index] = Arrow_Enemy.new(viewport)
  2694.         @arrows[battler.index].index = battler.index
  2695.       end
  2696.     end
  2697.   end
  2698.   #--------------------------------------------------------------------------
  2699.   def update_multi_arrow
  2700.     super
  2701.     for i in 0...@arrows.size
  2702.       enemy = $game_troop.enemies[i]
  2703.       if enemy  != nil && @arrows[i] != nil && @arrows[i].enemy != nil
  2704.         @arrows[i].x = @arrows[i].enemy.position_x + CURSOR_POSITION[0]
  2705.         @arrows[i].y = @arrows[i].enemy.position_y + CURSOR_POSITION[1] + enemy.enemy_height
  2706.       end
  2707.     end
  2708.   end
  2709. end
  2710.  
  2711. #==============================================================================
  2712. # Arrow_Actor_All
  2713. #==============================================================================
  2714. class Arrow_Actor_All < Arrow_Base
  2715.   #--------------------------------------------------------------------------
  2716.   def initialize(viewport)
  2717.     super(viewport)
  2718.     @arrows = []
  2719.     for battler in $game_party.actors
  2720.       if battler.exist?
  2721.         @arrows[battler.index] = Arrow_Actor.new(viewport)
  2722.         @arrows[battler.index].index = battler.index
  2723.       end
  2724.     end
  2725.   end
  2726.   #--------------------------------------------------------------------------
  2727.   def update_multi_arrow
  2728.     super
  2729.     for i in 0...@arrows.size
  2730.       actor = $game_party.actors[i]
  2731.       if actor  != nil && @arrows[i] != nil && @arrows[i].actor != nil
  2732.         @arrows[i].x = @arrows[i].actor.position_x + CURSOR_POSITION[0]
  2733.         @arrows[i].y = @arrows[i].actor.position_y + CURSOR_POSITION[1] + actor.actor_height
  2734.       end
  2735.     end
  2736.   end
  2737. end
  2738.  
  2739. #==============================================================================
  2740. # Arrow_Battler_All
  2741. #==============================================================================
  2742. class Arrow_Battler_All < Arrow_Base
  2743.   #--------------------------------------------------------------------------
  2744.   def initialize(viewport)
  2745.     super(viewport)
  2746.     @arrows = []
  2747.     s = 0
  2748.     for battler in $game_party.actors + $game_troop.enemies
  2749.       @arrows[s] = Arrow_Actor.new(viewport) if battler.actor?
  2750.       @arrows[s] = Arrow_Enemy.new(viewport) if battler.is_a?(Game_Enemy)
  2751.       @arrows[s].index = battler.index
  2752.       s += 1
  2753.     end
  2754.   end
  2755.   #--------------------------------------------------------------------------
  2756.   def update_multi_arrow
  2757.     super
  2758.     s = 0
  2759.     for i in 0...@arrows.size
  2760.       if @arrows[i].is_a?(Arrow_Actor)
  2761.         actor = $game_party.actors[i]
  2762.         if @arrows[i].actor != nil
  2763.           @arrows[i].x = @arrows[i].actor.position_x + CURSOR_POSITION[0]
  2764.           @arrows[i].y = @arrows[i].actor.position_y + CURSOR_POSITION[1] + actor.actor_height
  2765.           s += 1
  2766.         end
  2767.       elsif @arrows[i].is_a?(Arrow_Enemy)
  2768.         enemy = $game_troop.enemies[i - s]
  2769.         if @arrows[i].enemy != nil or @arrows[i] != nil
  2770.           @arrows[i].x = @arrows[i].enemy.position_x + CURSOR_POSITION[0]
  2771.           @arrows[i].y = @arrows[i].enemy.position_y + CURSOR_POSITION[1] + enemy.enemy_height
  2772.         end
  2773.       end
  2774.     end
  2775.   end
  2776. end
  2777.  
  2778. #==============================================================================
  2779. # ■ Arrow_Enemy
  2780. #==============================================================================
  2781. class Arrow_Enemy < Arrow_Base
  2782.   #--------------------------------------------------------------------------
  2783.   def update
  2784.     super
  2785.     $game_troop.enemies.size.times do
  2786.       break if self.enemy.exist?
  2787.       @index += 1
  2788.       @index %= $game_troop.enemies.size
  2789.     end
  2790.     if Input.repeat?(Input::RIGHT)
  2791.       cursor_up if $back_attack
  2792.       cursor_down unless $back_attack
  2793.     end
  2794.     if Input.repeat?(Input::LEFT)
  2795.       cursor_up unless $back_attack
  2796.       cursor_down if $back_attack
  2797.     end
  2798.     if Input.repeat?(Input::UP)
  2799.       cursor_down
  2800.     end
  2801.     if Input.repeat?(Input::DOWN)
  2802.       cursor_up
  2803.     end
  2804.     if self.enemy != nil
  2805.       self.x = self.enemy.position_x + CURSOR_POSITION[0]
  2806.       self.y = self.enemy.position_y + CURSOR_POSITION[1] + enemy.enemy_height
  2807.     end
  2808.   end
  2809.   #--------------------------------------------------------------------------
  2810.   def cursor_up
  2811.     $game_system.se_play($data_system.cursor_se)
  2812.     $game_troop.enemies.size.times do
  2813.       @index += $game_troop.enemies.size - 1
  2814.       @index %= $game_troop.enemies.size
  2815.       break if self.enemy.exist?
  2816.     end
  2817.   end
  2818.   #--------------------------------------------------------------------------
  2819.   def cursor_down
  2820.     $game_system.se_play($data_system.cursor_se)
  2821.     $game_troop.enemies.size.times do
  2822.       @index += 1
  2823.       @index %= $game_troop.enemies.size
  2824.       break if self.enemy.exist?
  2825.     end
  2826.   end
  2827. end
  2828.  
  2829. #==============================================================================
  2830. # ■ Arrow_Actor
  2831. #==============================================================================
  2832. class Arrow_Actor < Arrow_Base
  2833.   #--------------------------------------------------------------------------
  2834.   def update
  2835.     super
  2836.     if Input.repeat?(Input::RIGHT)
  2837.       cursor_up if $back_attack
  2838.       cursor_down unless $back_attack
  2839.     end
  2840.     if Input.repeat?(Input::LEFT)
  2841.       cursor_up unless $back_attack
  2842.       cursor_down if $back_attack
  2843.     end
  2844.     if Input.repeat?(Input::UP)
  2845.       cursor_up
  2846.     end
  2847.     if Input.repeat?(Input::DOWN)
  2848.       cursor_down
  2849.     end
  2850.     if self.actor != nil
  2851.       self.x = self.actor.position_x + CURSOR_POSITION[0]
  2852.       self.y = self.actor.position_y + CURSOR_POSITION[1] + actor.actor_height
  2853.     end
  2854.   end
  2855.   #--------------------------------------------------------------------------
  2856.   def cursor_up
  2857.     $game_system.se_play($data_system.cursor_se)
  2858.     @index += $game_party.actors.size - 1
  2859.     @index %= $game_party.actors.size
  2860.   end
  2861.   #--------------------------------------------------------------------------
  2862.   def cursor_down
  2863.     $game_system.se_play($data_system.cursor_se)
  2864.     @index += 1
  2865.     @index %= $game_party.actors.size
  2866.   end
  2867.   #--------------------------------------------------------------------------
  2868.   def input_right
  2869.     @index += 1
  2870.     @index %= $game_party.actors.size
  2871.   end
  2872.   #--------------------------------------------------------------------------
  2873.   def input_update_target
  2874.     if Input.repeat?(Input::RIGHT)
  2875.       if @index == self.actor.index    
  2876.         cursor_up if $back_attack
  2877.         cursor_down unless $back_attack
  2878.       end
  2879.     end
  2880.     if Input.repeat?(Input::LEFT)
  2881.       if @index == self.actor.index
  2882.         cursor_up unless $back_attack
  2883.         cursor_down if $back_attack
  2884.       end
  2885.     end
  2886.     if Input.repeat?(Input::UP)
  2887.       cursor_up if @index == self.actor.index
  2888.     end
  2889.     if Input.repeat?(Input::DOWN)
  2890.       cursor_down if @index == self.actor.index
  2891.     end
  2892.     if self.actor != nil
  2893.       self.x = self.actor.screen_x
  2894.       self.y = self.actor.screen_y
  2895.     end
  2896.   end
  2897. end
  2898.  
  2899. #==============================================================================
  2900. # ■ Game_Troop
  2901. #==============================================================================
  2902. class Game_Troop
  2903.   def clear_actions
  2904.     for enemies in @enemies
  2905.       enemies.current_action.clear
  2906.     end
  2907.   end
  2908. end
  2909.  
  2910. #==============================================================================
  2911. # ■ Window_Command
  2912. #==============================================================================
  2913. class Window_Command < Window_Selectable
  2914.   #--------------------------------------------------------------------------
  2915.   attr_accessor :commands
  2916. end
  2917.  
  2918. #==============================================================================
  2919. # ■ Window_Base
  2920. #==============================================================================
  2921. class Window_Base < Window
  2922.   #--------------------------------------------------------------------------
  2923.   include N01
  2924.   #--------------------------------------------------------------------------
  2925.   def draw_actor_state(actor, x, y, width = 0)
  2926.     status_icon = []
  2927.     for i in actor.states
  2928.       if $data_states[i].rating >= 1
  2929.         begin
  2930.           status_icon.push(RPG::Cache.icon($data_states[i].name + "_st"))
  2931.           break if status_icon.size > (Icon_max - 1)
  2932.         rescue
  2933.         end
  2934.       end
  2935.     end
  2936.     for icon in status_icon
  2937.       self.contents.blt(x + X_Adjust, y + Y_Adjust + 4, icon, Rect.new(0, 0, Icon_X, Icon_Y), 255)
  2938.       x += Icon_X + 2
  2939.     end
  2940.   end
  2941.   #--------------------------------------------------------------------------
  2942.   def draw_actor_parameter(actor, x, y, type)
  2943.     case type
  2944.     when 0
  2945.       parameter_name = $data_system.words.atk
  2946.       parameter_value = actor.atk
  2947.     when 1
  2948.       parameter_name = $data_system.words.pdef
  2949.       parameter_value = actor.pdef
  2950.     when 2
  2951.       parameter_name = $data_system.words.mdef
  2952.       parameter_value = actor.mdef
  2953.     when 3
  2954.       parameter_name = $data_system.words.str
  2955.       parameter_value = actor.str
  2956.     when 4
  2957.       parameter_name = (DAMAGE_ALGORITHM_TYPE == 0 ? STAT_VIT : $data_system.words.dex)
  2958.       parameter_value = actor.dex
  2959.     when 5
  2960.       parameter_name = $data_system.words.agi
  2961.       parameter_value = actor.agi
  2962.     when 6
  2963.       parameter_name = $data_system.words.int
  2964.       parameter_value = actor.int
  2965.     when 7
  2966.       parameter_name = STAT_EVA
  2967.       parameter_value = actor.eva
  2968.     end
  2969.     self.contents.font.color = system_color
  2970.     self.contents.draw_text(x, y, 120, 32, parameter_name)
  2971.     self.contents.font.color = normal_color
  2972.     self.contents.draw_text(x + 120, y, 36, 32, parameter_value.to_s, 2)
  2973.   end
  2974. end
  2975.  
  2976. #==============================================================================
  2977. # ■ Window_Help
  2978. #==============================================================================
  2979. class Window_Help < Window_Base
  2980.   #--------------------------------------------------------------------------
  2981.   def initialize
  2982.     super(0, 0, 640, 64)
  2983.     self.contents = Bitmap.new(width - 32, height - 32)
  2984.     self.z = 2000 if $game_temp.in_battle
  2985.     self.back_opacity = HELP_OPACITY if $game_temp.in_battle
  2986.   end
  2987.   #--------------------------------------------------------------------------
  2988.   def set_text_update(text, align = 0)
  2989.     self.contents.clear
  2990.     self.contents.font.color = normal_color
  2991.     self.contents.draw_text(4, 0, self.width - 40, 32, text, align)
  2992.     @text = text
  2993.     @align = align
  2994.     @actor = nil
  2995.     self.visible = true
  2996.   end
  2997.   #--------------------------------------------------------------------------
  2998.   def set_enemy(enemy)
  2999.     text = enemy.name
  3000.     set_text_update(text, 1)
  3001.     text_width = self.contents.text_size(text).width
  3002.     x = (text_width + self.width)/2
  3003.     status_icon = []
  3004.     for i in enemy.states
  3005.       if $data_states[i].rating >= 1
  3006.         begin
  3007.           status_icon.push(RPG::Cache.icon($data_states[i].name + "_st"))
  3008.           break if status_icon.size > (Icon_max - 1)
  3009.         rescue
  3010.         end
  3011.       end
  3012.     end
  3013.     for icon in status_icon
  3014.       self.contents.blt(x + X_Adjust, y + Y_Adjust + 4, icon, Rect.new(0, 0, Icon_X, Icon_Y), 255)
  3015.       x += Icon_X + 2
  3016.     end
  3017.   end
  3018. end
  3019.  
  3020. #==============================================================================
  3021. # ■ Window_Skill
  3022. #==============================================================================
  3023. class Window_Skill < Window_Selectable
  3024.   #--------------------------------------------------------------------------
  3025.   def initialize(actor)
  3026.     super(0, 128, 640, 352)
  3027.     @actor = actor
  3028.     @column_max = 2
  3029.     refresh
  3030.     self.index = 0
  3031.     if $game_temp.in_battle
  3032.       self.y = 320
  3033.       self.height = 160
  3034.       self.z = 2100
  3035.       self.back_opacity = MENU_OPACITY
  3036.     end
  3037.   end
  3038.   #--------------------------------------------------------------------------
  3039.   def draw_item(index)
  3040.     skill = @data[index]
  3041.     if @actor.skill_can_use?(skill.id)
  3042.       self.contents.font.color = normal_color
  3043.     else
  3044.       self.contents.font.color = disabled_color
  3045.     end
  3046.     x = 4 + index % 2 * (288 + 32)
  3047.     y = index / 2 * 32
  3048.     rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  3049.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  3050.     bitmap = RPG::Cache.icon(skill.icon_name)
  3051.     opacity = self.contents.font.color == normal_color ? 255 : 128
  3052.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  3053.     self.contents.draw_text(x + 28, y, 204, 32, skill.name, 0)
  3054.     cost = @actor.calc_sp_cost(@actor, skill)
  3055.     self.contents.draw_text(x + 232, y, 48, 32, cost.to_s, 2)
  3056.   end
  3057. end
  3058.  
  3059. #==============================================================================
  3060. # ■ Window_Item
  3061. #==============================================================================
  3062. class Window_Item < Window_Selectable
  3063.   #--------------------------------------------------------------------------
  3064.   def initialize
  3065.     super(0, 64, 640, 416)
  3066.     @column_max = 2
  3067.     refresh
  3068.     self.index = 0
  3069.     if $game_temp.in_battle
  3070.       self.y = 320
  3071.       self.height = 160
  3072.       self.z = 2100
  3073.       self.back_opacity = MENU_OPACITY
  3074.     end
  3075.   end
  3076. end
  3077.  
  3078. #==============================================================================
  3079. # ■ Window_PartyCommand
  3080. #==============================================================================
  3081. class Window_PartyCommand < Window_Selectable
  3082.   #--------------------------------------------------------------------------
  3083.   alias initialize_n01 initialize
  3084.   #--------------------------------------------------------------------------
  3085.   def initialize
  3086.     initialize_n01
  3087.     self.z = 2000
  3088.   end
  3089. end
  3090.  
  3091. #==============================================================================
  3092. # ■ Window_BattleStatus
  3093. #==============================================================================
  3094. class Window_BattleStatus < Window_Base
  3095.   #--------------------------------------------------------------------------
  3096.   def initialize
  3097.     super(0, 320, 640, 160)
  3098.     self.contents = Bitmap.new(width - 32, height - 32)
  3099.     @level_up_flags = []
  3100.     for i in 0...$game_party.actors.size
  3101.       @level_up_flags.push(false)
  3102.     end
  3103.     self.z = 2000
  3104.     self.opacity = STATUS_OPACITY
  3105.     refresh
  3106.   end
  3107.   #--------------------------------------------------------------------------
  3108.   def update
  3109.     super
  3110.   end
  3111. end
  3112.  
  3113. #==============================================================================
  3114. # ■ Window_NameCommand
  3115. #==============================================================================
  3116. class Window_BattleResult < Window_Base
  3117.   #--------------------------------------------------------------------------
  3118.   def initialize(exp, gold, treasures)
  3119.     @exp = exp
  3120.     @gold = gold
  3121.     @treasures = treasures
  3122.     super(160, 0, 320, @treasures.size * 32 + 64)
  3123.     self.contents = Bitmap.new(width - 32, height - 32)
  3124.     self.y = 160 - height / 2
  3125.     self.back_opacity = 160
  3126.     self.z = 2000
  3127.     self.visible = false
  3128.     refresh
  3129.   end
  3130. end
  3131.  
  3132. #==============================================================================
  3133. # ■ Window_NameCommand
  3134. #==============================================================================
  3135. class Window_NameCommand < Window_Base
  3136.   #--------------------------------------------------------------------------
  3137.   def initialize(actor, x, y)
  3138.     super(x, y, 160, 64)
  3139.     self.contents = Bitmap.new(width - 32, height - 32)
  3140.     self.contents.font.name = Font.default_name
  3141.     self.z = 2000
  3142.     self.back_opacity = COMMAND_OPACITY
  3143.     refresh(actor)
  3144.   end
  3145.   #--------------------------------------------------------------------------
  3146.   def refresh(actor)
  3147.     self.contents.clear
  3148.     self.contents.font.color = normal_color
  3149.     self.contents.draw_text(0, 0, 128, 32, actor.name, 1) if actor != nil
  3150.   end
  3151. end
  3152.  
  3153. #==============================================================================
  3154. # ■ RPG::Sprite
  3155. #==============================================================================
  3156. class RPG::Sprite < ::Sprite
  3157.   #--------------------------------------------------------------------------
  3158.   include N01
  3159.   #--------------------------------------------------------------------------
  3160.   def initialize(viewport = nil)
  3161.     super(viewport)
  3162.     @_whiten_duration = 0
  3163.     @_appear_duration = 0
  3164.     @_escape_duration = 0
  3165.     @_collapse_duration = 0
  3166.     @_damage_duration = 0
  3167.     @_animation_duration = 0
  3168.     @_blink = false
  3169.     @_damage_durations = []
  3170.     @time = 0
  3171.   end
  3172.   #--------------------------------------------------------------------------
  3173.   def appear
  3174.   end
  3175.   #--------------------------------------------------------------------------
  3176.   def escape
  3177.   end
  3178.   #--------------------------------------------------------------------------
  3179.   def collapse
  3180.   end
  3181.   #--------------------------------------------------------------------------
  3182.   def damage(value, critical, sp_damage = nil)
  3183.     dispose_damage(0...@_damage_durations.size)
  3184.     @_damage_sprites = []
  3185.     if value.is_a?(Numeric)
  3186.       damage_string = value.abs.to_s
  3187.     else
  3188.       damage_string = value.to_s
  3189.     end
  3190.     @damage_size = 1 if !MULTI_POP
  3191.     @damage_size = damage_string.size if MULTI_POP
  3192.     for i in 0...@damage_size
  3193.       letter = damage_string[i..i] if MULTI_POP
  3194.       letter = damage_string if !MULTI_POP
  3195.       bitmap = Bitmap.new(160, 48)
  3196.       bitmap.font.name = DAMAGE_FONT
  3197.       bitmap.font.size = DMG_F_SIZE
  3198.       bitmap.font.color.set(0, 0, 0)
  3199.       bitmap.draw_text(-1, 12-1,160, 36, letter, 1)
  3200.       bitmap.draw_text(+1, 12-1,160, 36, letter, 1)
  3201.       bitmap.draw_text(-1, 12+1,160, 36, letter, 1)
  3202.       bitmap.draw_text(+1, 12+1,160, 36, letter, 1)
  3203.       if value.is_a?(Numeric) and value < 0
  3204.         bitmap.font.color.set(HP_REC_COLOR[0],HP_REC_COLOR[1],HP_REC_COLOR[2]) if !sp_damage
  3205.         bitmap.font.color.set(SP_REC_COLOR[0],SP_REC_COLOR[1],SP_REC_COLOR[2]) if sp_damage
  3206.       else
  3207.         bitmap.font.color.set(HP_DMG_COLOR[0],HP_DMG_COLOR[1],HP_DMG_COLOR[2]) if !sp_damage
  3208.         bitmap.font.color.set(SP_DMG_COLOR[0],SP_DMG_COLOR[1],SP_DMG_COLOR[2]) if sp_damage
  3209.         bitmap.font.color.set(CRT_DMG_COLOR[0],CRT_DMG_COLOR[1],CRT_DMG_COLOR[2]) if critical
  3210.       end
  3211.       bitmap.draw_text(0, 12,160, 36, letter, 1)
  3212.       if critical and CRITIC_TEXT and i == 0
  3213.         x_pop = (MULTI_POP ? (damage_string.size - 1) * (DMG_SPACE / 2) : 0)
  3214.         bitmap.font.size = ((DMG_F_SIZE * 2) / 3).to_i
  3215.         bitmap.font.color.set(0, 0, 0)
  3216.         bitmap.draw_text(-1 + x_pop, -1, 160, 20, POP_CRI, 1)
  3217.         bitmap.draw_text(+1 + x_pop, -1, 160, 20, POP_CRI, 1)
  3218.         bitmap.draw_text(-1 + x_pop, +1, 160, 20, POP_CRI, 1)
  3219.         bitmap.draw_text(+1 + x_pop, +1, 160, 20, POP_CRI, 1)
  3220.         bitmap.font.color.set(CRT_TXT_COLOR[0],CRT_TXT_COLOR[1],CRT_TXT_COLOR[2]) if critical
  3221.         bitmap.draw_text(0 + x_pop, 0, 160, 20, POP_CRI, 1)
  3222.       end
  3223.       if critical and CRITIC_FLASH
  3224.         $game_screen.start_flash(Color.new(255, 255, 255, 255),10)
  3225.       end
  3226.       @_damage_sprites[i] = ::Sprite.new(self.viewport)
  3227.       @_damage_sprites[i].bitmap = bitmap
  3228.       @_damage_sprites[i].ox = 80
  3229.       @_damage_sprites[i].oy = 20
  3230.       @_damage_sprites[i].x = self.x + i * DMG_SPACE
  3231.       @_damage_sprites[i].y = self.y - self.oy / 2
  3232.       @_damage_sprites[i].z = DMG_DURATION + 3000 + i * 2
  3233.     end
  3234.   end
  3235.   #--------------------------------------------------------------------------
  3236.   def dispose
  3237.     dispose_damage(0...@_damage_durations.size)
  3238.     dispose_animation
  3239.     dispose_loop_animation
  3240.     if @damage_sprites != nil
  3241.       for damage_sprite in @damage_sprites
  3242.         damage_sprite.dispose
  3243.       end
  3244.     end
  3245.     super
  3246.   end
  3247.   #--------------------------------------------------------------------------
  3248.   def update
  3249.     super
  3250.     @damage_sprites   = [] if @damage_sprites.nil?
  3251.     @damage_durations = [] if @damage_durations.nil?
  3252.     if @_damage_sprites != nil
  3253.       for sprite in @_damage_sprites
  3254.         if sprite != nil and sprite.visible
  3255.           x = DMG_X_MOVE
  3256.           y = DMG_Y_MOVE
  3257.           d = sprite.z - 3000
  3258.           m = self.mirror
  3259.           @damage_sprites.push(Sprite_Damage.new(sprite, x, y, d, m))
  3260.           sprite.visible = false
  3261.         end
  3262.       end
  3263.     end
  3264.     for damage_sprite in @damage_sprites
  3265.       damage_sprite.update
  3266.     end
  3267.     for i in 0...@damage_sprites.size
  3268.       @damage_sprites[i] = nil if @damage_sprites[i].disposed?
  3269.     end
  3270.     @damage_sprites.compact!
  3271.     if @_whiten_duration > 0
  3272.       @_whiten_duration -= 1
  3273.       self.color.alpha = 128 - (16 - @_whiten_duration) * 10
  3274.     end
  3275.     if @_animation != nil and (Graphics.frame_count % 2 == 0)
  3276.       @_animation_duration -= 1
  3277.       update_animation
  3278.     end
  3279.     if @_loop_animation != nil and (Graphics.frame_count % 2 == 0)
  3280.       update_loop_animation
  3281.       @_loop_animation_index += 1
  3282.       @_loop_animation_index %= @_loop_animation.frame_max
  3283.     end
  3284.     if @_blink
  3285.       @_blink_count = (@_blink_count + 1) % 32
  3286.       if @_blink_count < 16
  3287.         alpha = (16 - @_blink_count) * 6
  3288.       else
  3289.         alpha = (@_blink_count - 16) * 6
  3290.       end
  3291.       self.color.set(255, 255, 255, alpha)
  3292.     end
  3293.     @@_animations.clear
  3294.   end
  3295.   #--------------------------------------------------------------------------
  3296.   def dispose_damage(index)
  3297.     return if @_damage_sprites == nil
  3298.     if @_damage_sprites[index].is_a?(::Sprite) and @_damage_sprites[index].bitmap != nil
  3299.       @_damage_sprites[index].bitmap.dispose
  3300.       @_damage_sprites[index].dispose
  3301.       @_damage_durations[index] = 0
  3302.     end
  3303.   end
  3304.   #--------------------------------------------------------------------------
  3305.   def dispose_animation
  3306.     if @_animation_sprites != nil
  3307.       sprite = @_animation_sprites[0]
  3308.       if sprite != nil
  3309.         @@_reference_count[sprite.bitmap] -= 1
  3310.         if @@_reference_count[sprite.bitmap] == 0
  3311.           sprite.bitmap.dispose
  3312.         end
  3313.       end
  3314.       for sprite in @_animation_sprites
  3315.         sprite.dispose
  3316.       end
  3317.       @_animation_sprites = nil
  3318.       @_animation = nil
  3319.     end
  3320.     @mirror = false
  3321.   end
  3322.   #--------------------------------------------------------------------------
  3323.   def animation_mirror(mirror_effect)
  3324.     @mirror = mirror_effect
  3325.   end
  3326.   #--------------------------------------------------------------------------
  3327.   def animation_set_sprites(sprites, cell_data, position)
  3328.     for i in 0..15
  3329.       sprite = sprites[i]
  3330.       pattern = cell_data[i, 0]
  3331.       if sprite == nil or pattern == nil or pattern == -1
  3332.         sprite.visible = false if sprite != nil
  3333.         next
  3334.       end
  3335.       sprite.visible = true
  3336.       sprite.src_rect.set(pattern % 5 * 192, pattern / 5 * 192, 192, 192)
  3337.       if position == 3
  3338.         if self.viewport != nil
  3339.           sprite.x = self.viewport.rect.width / 2
  3340.           sprite.y = self.viewport.rect.height - 160
  3341.         else
  3342.           sprite.x = 320
  3343.           sprite.y = 240
  3344.         end
  3345.       else
  3346.         sprite.x = self.x - self.ox + self.src_rect.width / 2
  3347.         sprite.y = self.y - self.oy + self.src_rect.height / 2
  3348.         sprite.y -= self.src_rect.height / 4 if position == 0
  3349.         sprite.y += self.src_rect.height / 4 if position == 2
  3350.       end
  3351.       sprite.x += cell_data[i, 1]
  3352.       sprite.y += cell_data[i, 2]
  3353.       sprite.z = 2000
  3354.       if @mirror
  3355.         sprite.ox = 88
  3356.       else
  3357.         sprite.ox = 104
  3358.       end
  3359.       sprite.oy = 96
  3360.       sprite.zoom_x = cell_data[i, 3] / 100.0
  3361.       sprite.zoom_y = cell_data[i, 3] / 100.0
  3362.       sprite.angle = cell_data[i, 4]
  3363.       sprite.mirror = (cell_data[i, 5] == 1)
  3364.       if @mirror
  3365.         if sprite.mirror
  3366.           sprite.mirror = false
  3367.         else  
  3368.           sprite.mirror = true
  3369.         end
  3370.       end
  3371.       sprite.opacity = cell_data[i, 6] * self.opacity / 255.0
  3372.       sprite.blend_type = cell_data[i, 7]
  3373.     end
  3374.   end
  3375. end
  3376.  
  3377. #==============================================================================
  3378. # ■ Sprite_Damage
  3379. #==============================================================================
  3380. class Sprite_Damage < Sprite
  3381.   #--------------------------------------------------------------------------
  3382.   include N01
  3383.   #--------------------------------------------------------------------------
  3384.   def initialize(sprite, init_x_speed, init_y_speed, duration, mirror)
  3385.     super(nil)
  3386.     self.bitmap = sprite.bitmap.dup unless sprite.bitmap.nil?
  3387.     self.opacity = 255
  3388.     self.x = sprite.x
  3389.     self.y = sprite.y
  3390.     self.z = 3000
  3391.     self.ox = sprite.ox
  3392.     self.oy = sprite.oy
  3393.     @damage_mirror = mirror
  3394.     @now_x_speed = init_x_speed
  3395.     @now_y_speed = init_y_speed
  3396.     @potential_x_energy = 0.0
  3397.     @potential_y_energy = 0.0
  3398.     @duration = duration
  3399.   end
  3400.   #--------------------------------------------------------------------------
  3401.   def update
  3402.     @duration -= 1
  3403.     return unless @duration <= DMG_DURATION
  3404.     super
  3405.     n = self.oy + @now_y_speed
  3406.     if n <= 0
  3407.       @now_y_speed *= -1
  3408.       @now_y_speed /=  2
  3409.       @now_x_speed /=  2
  3410.     end
  3411.     self.oy  = [n, 0].max
  3412.     @potential_y_energy += DMG_GRAVITY
  3413.     speed = @potential_y_energy.floor
  3414.     @now_y_speed        -= speed
  3415.     @potential_y_energy -= speed
  3416.     @potential_x_energy += @now_x_speed if @damage_mirror if POP_MOVE
  3417.     @potential_x_energy -= @now_x_speed if !@damage_mirror if POP_MOVE
  3418.     speed = @potential_x_energy.floor
  3419.     self.ox             += speed
  3420.     @potential_x_energy -= speed
  3421.     case @duration
  3422.     when 1..10
  3423.       self.opacity -= 25
  3424.     when 0
  3425.       self.dispose
  3426.     end
  3427.   end
  3428. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement