Advertisement
Jragyn

[XP] BlizzABS -p3

Apr 11th, 2017
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 361.70 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  2. # Blizz-ABS by Blizzard and winkio
  3. # Version: 2.87
  4. # Type: Advanced Action Battle System
  5. # Date v1.00: 19.04.2007
  6. # Date v1.01: 30.04.2007
  7. # Date v1.02: 17.07.2007
  8. # Date v1.04: 25.07.2007
  9. # Date v1.09: 25.07.2007
  10. # Date v1.20: 29.07.2007
  11. # Date v1.23: 30.07.2007
  12. # Date v1.24:  5.08.2007
  13. # Date v1.60:  5.09.2007
  14. # Date v1.61:  6.09.2007
  15. # Date v1.62:  7.09.2007
  16. # Date v1.63: 11.09.2007
  17. # Date v1.64: 11.09.2007
  18. # Date v1.65: 12.09.2007
  19. # Date v1.66: 10.10.2007
  20. # Date v1.67: 16.10.2007
  21. # Date v1.69: 31.10.2007
  22. # Date v1.70: 13.11.2007
  23. # Date v1.71: 22.11.2007
  24. # Date v1.72: 10.12.2007
  25. # Date v1.73: 11.12.2007
  26. # Date v1.80: 18.12.2007
  27. # Date v1.89: 13.01.2008
  28. # Date v1.95: 29.02.2008
  29. # Date v1.96:  5.03.2008
  30. # Date v1.97: 28.03.2008
  31. # Date v1.98:  5.04.2008
  32. # Date v1.99:  4.08.2008
  33. # Date v2.00:  1.12.2008
  34. # Date v2.01:  1.12.2008
  35. # Date v2.02:  2.12.2008
  36. # Date v2.03:  3.12.2008
  37. # Date v2.10:  4.12.2008
  38. # Date v2.11:  5.12.2008
  39. # Date v2.12:  5.12.2008
  40. # Date v2.13:  6.12.2008
  41. # Date v2.14:  7.12.2008
  42. # Date v2.15:  8.12.2008
  43. # Date v2.20: 13.12.2008
  44. # Date v2.21: 19.12.2008
  45. # Date v2.22: 08.01.2009
  46. # Date v2.23: 25.01.2009
  47. # Date v2.30:  8.04.2009
  48. # Date v2.31:  8.04.2009
  49. # Date v2.50: 20.04.2009
  50. # Date v2.51: 20.04.2009
  51. # Date v2.52: 20.04.2009
  52. # Date v2.53:  2.05.2009
  53. # Date v2.54: 23.05.2009
  54. # Date v2.55: 28.06.2009
  55. # Date v2.56: 29.07.2009
  56. # Date v2.57: 19.08.2009
  57. # Date v2.60: 27.11.2009
  58. # Date v2.70: 28.11.2009
  59. # Date v2.71:  12.5.2010
  60. # Date v2.74:  16.5.2010
  61. # Date v2.79:  20.5.2010
  62. # Date v2.80:   4.6.2010
  63. # Date v2.81:   6.1.2011
  64. # Date v2.82:   7.1.2011
  65. # Date v2.83:  19.1.2011
  66. # Date v2.84:  23.1.2011
  67. # Date v2.85:  16.5.2013
  68. # Date v2.86:  28.2.2014
  69. # Date v2.87: 24.10.2014
  70. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  71. #
  72. #                                    PART 3
  73. #
  74. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  75. #  
  76. #  This work is protected by the following license:
  77. # #----------------------------------------------------------------------------
  78. # #  
  79. # #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
  80. # #  ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
  81. # #  
  82. # #  You are free:
  83. # #  
  84. # #  to Share - to copy, distribute and transmit the work
  85. # #  to Remix - to adapt the work
  86. # #  
  87. # #  Under the following conditions:
  88. # #  
  89. # #  Attribution. You must attribute the work in the manner specified by the
  90. # #  author or licensor (but not in any way that suggests that they endorse you
  91. # #  or your use of the work).
  92. # #  
  93. # #  Noncommercial. You may not use this work for commercial purposes.
  94. # #  
  95. # #  Share alike. If you alter, transform, or build upon this work, you may
  96. # #  distribute the resulting work only under the same or similar license to
  97. # #  this one.
  98. # #  
  99. # #  - For any reuse or distribution, you must make clear to others the license
  100. # #    terms of this work. The best way to do this is with a link to this web
  101. # #    page.
  102. # #  
  103. # #  - Any of the above conditions can be waived if you get permission from the
  104. # #    copyright holder.
  105. # #  
  106. # #  - Nothing in this license impairs or restricts the author's moral rights.
  107. # #  
  108. # #----------------------------------------------------------------------------
  109. #
  110. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  111. #
  112. # Information:
  113. #
  114. #   This script will allow you to create games with an Action Battle System
  115. #   (ABS) (i.e. Zelda). Action Battle System means real time battle on the map.
  116. #
  117. #   If you don't read the Manual, you will not be able to use many of the great
  118. #   features this ABS supports.
  119. #
  120. #   You DID NOT get the documentation with Blizz-ABS? Please contact me under
  121. #   the URL provided below.
  122. #
  123. #
  124. # If you find any bugs, please report them here:
  125. # http://forum.chaos-project.com
  126. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  127.  
  128. #==============================================================================
  129. # Map_Battler
  130. #------------------------------------------------------------------------------
  131. #  This class serves as superclass for characters that fight on the map and
  132. #  can use pixel movement.
  133. #==============================================================================
  134.  
  135. class Map_Battler < Game_Character
  136.  
  137.   # setting all accessible variables
  138.   attr_accessor :in_action
  139.   attr_accessor :s_count
  140.   attr_accessor :current_sprite
  141.   attr_accessor :new_combo_sprite
  142.   attr_accessor :weapon_sprite
  143.   attr_accessor :fade_out
  144.   attr_accessor :blend_type
  145.   attr_accessor :opacity
  146.   attr_accessor :battler
  147.   attr_accessor :force_move
  148.   attr_accessor :normal_speed
  149.   attr_accessor :move_speed
  150.   attr_accessor :character_name_org
  151.   attr_accessor :character_name
  152.   attr_accessor :combo
  153.   attr_accessor :always_on_top
  154.   attr_accessor :through
  155.   attr_accessor :direction_fix
  156.   attr_accessor :direction
  157.   attr_accessor :tile_id
  158.   attr_accessor :last_attackers
  159.   attr_accessor :last_slip_attackers
  160.   attr_accessor :last_targets
  161.   attr_accessor :path_target_x
  162.   attr_accessor :path_target_y
  163.   attr_accessor :battler
  164.   attr_accessor :body
  165.   attr_writer   :freeze_action
  166.   attr_writer   :idle_allowed
  167.   attr_reader   :ai
  168.   attr_reader   :direction_fix
  169.   attr_reader   :attacked
  170.   attr_reader   :precondition
  171.   #----------------------------------------------------------------------------
  172.   # Initialization
  173.   #----------------------------------------------------------------------------
  174.   def initialize
  175.     # call superclass method
  176.     super
  177.     # sprite animation name add-on and weapon sprite animation name add-on
  178.     @current_sprite = @weapon_sprite = ''
  179.     # flag for combo sprite
  180.     @new_combo_sprite = false
  181.     # sprite animation counter, penalty counter and action penalty counter
  182.     @attacked, @in_action = 0, 0
  183.     # action freezing flag
  184.     @freeze_action = false
  185.     # pixel rate setting
  186.     @pixel_rate = $game_system.pixel_rate
  187.     # set original character name
  188.     @character_name_org = @character_name
  189.     # create array of moving commands
  190.     @force_move = []
  191.     # precondition
  192.     @precondition = true
  193.     # sprite animation frame data
  194.     reset_sprites
  195.     # don't allow idle animation
  196.     @idle_allowed = false
  197.     # reset last attackers
  198.     @last_attackers = []
  199.     # reset last slip damage attackers
  200.     @last_slip_attackers = []
  201.     # reset last targets
  202.     @last_targets = []
  203.     # path target
  204.     @path_target_x, @path_target_y = nil, nil
  205.     # hitbox size
  206.     @hitbox_width, @hitbox_height = 32, 32
  207.   end
  208.   #----------------------------------------------------------------------------
  209.   # update
  210.   #  Checks if everything is ok with the pixel rate.
  211.   #----------------------------------------------------------------------------
  212.   def update
  213.     # store old attacker and target lists
  214.     if (@battler != nil)
  215.       @last_targets = @battler.last_targets
  216.       @battler.last_targets = []
  217.       @last_attackers = @battler.last_attackers
  218.       @battler.last_attackers = []
  219.       @last_slip_attackers = @battler.last_slip_attackers
  220.       @battler.last_slip_attackers = []
  221.       @last_action = @battler.last_action
  222.     end
  223.     # update pixel movement rate
  224.     update_pixel_rate
  225.     # if charging up
  226.     if charging?
  227.       # decrease charge counter
  228.       @charge.time -= 1
  229.       # if charged up and not trigger type
  230.       if charged? && !charging?(BlizzABS::CHARGETrigger)
  231.         # execute charged action
  232.         case @charge.action
  233.         when BlizzABS::CHARGEAttack then use_attack
  234.         when BlizzABS::CHARGESkill then use_skill($data_skills[@charge.id])
  235.         when BlizzABS::CHARGEItem then use_item($data_items[@charge.id])
  236.         end
  237.         # reset action
  238.         self.reset_action
  239.       end
  240.     end
  241.     # if performing a combo
  242.     if @combo != nil
  243.       # update the combo
  244.       @combo.update
  245.       # dispose if combo has ended
  246.       if @combo.ended
  247.         @new_combo_sprite = false
  248.         @combo = nil
  249.       end
  250.     end
  251.     # restore lists if needed
  252.     if (@battler != nil)
  253.       @battler.last_targets = @last_targets if @battler.last_targets == []
  254.       @battler.last_attackers = @last_attackers if @battler.last_attackers == []
  255.       @battler.last_slip_attackers = @last_slip_attackers if @battler.last_slip_attackers == []
  256.     end
  257.     # call superclass method
  258.     super
  259.   end
  260.   #----------------------------------------------------------------------------
  261.   # update_combomove
  262.   #  move - the move to execute
  263.   #  Updates movement.
  264.   #----------------------------------------------------------------------------
  265.   def update_combomove(move = nil)
  266.     # if moving commands exist
  267.     move = @combo.moves[0] if move == nil && @combo.moves.size > 0
  268.     # stop if no move
  269.     return if move == nil
  270.     # move
  271.     case move[0]
  272.     when 1 # walk
  273.       case move[1]
  274.       when 1 then move_lower_left
  275.       when 2 then move_down(move[1])
  276.       when 3 then move_lower_right
  277.       when 4 then move_left(move[1])
  278.       when 6 then move_right(move[1])
  279.       when 7 then move_upper_left
  280.       when 8 then move_up(move[1])
  281.       when 9 then move_upper_right
  282.       when false
  283.         # remove from caterpillar
  284.         remove_from_caterpillar if @cindex != nil
  285.         # reset force counter
  286.         @force_movement = 0
  287.       end
  288.     when 2 # turn
  289.       @direction = move[1]
  290.       @stop_count = move[2]
  291.     when 3 # jump
  292.       # get difference between current speed and normal speed
  293.       dplus = @move_speed - @normal_speed
  294.       # set jumping direction
  295.       x, y = BlizzABS::Cache::DirOffsets[move[1]]
  296.       range = move[2]
  297.       # jump into direction with considering running/sneaking
  298.       jump(x*range + x*dplus, y*range + y*dplus, move[1])
  299.     end
  300.   end
  301.   #----------------------------------------------------------------------------
  302.   # update_pixel_rate
  303.   #  Updates the pixel movement rate if necessary.
  304.   #----------------------------------------------------------------------------
  305.   def update_pixel_rate
  306.     # if pixel movement rate different than the stored one
  307.     if @pixel_rate != $game_system.pixel_rate
  308.       # updating factor
  309.       factor = 2.0 ** ($game_system.pixel_rate - @pixel_rate)
  310.       # store new pixel movement rate
  311.       @pixel_rate = $game_system.pixel_rate
  312.       # refresh coordinates
  313.       @x, @y = (@x * factor).to_i, (@y * factor).to_i
  314.       # update memorized coordinates
  315.       @ai.memory.values.each {|a| a.x, a.y = (a.x * factor).to_i, (a.y * factor).to_i}
  316.     end
  317.   end
  318.   #----------------------------------------------------------------------------
  319.   # update_states
  320.   #  Updates status effects in Blizz-ABS.
  321.   #----------------------------------------------------------------------------
  322.   def update_states
  323.     # if battler exists
  324.     if battler != nil
  325.       # check status effect timers
  326.       check_states
  327.       # change status effect timers
  328.       count_states
  329.       # apply additional status effects
  330.       additional_states
  331.     end
  332.   end
  333.   #----------------------------------------------------------------------------
  334.   # check_states
  335.   #  Checks the time counters for the status effects.
  336.   #----------------------------------------------------------------------------
  337.   def check_states
  338.     # remove all counters from states that are gone
  339.     (battler.state_time.keys - battler.states).each {|id|
  340.         battler.state_time.delete(id)}
  341.     # add all counters from new states
  342.     (battler.states - battler.state_time.keys).each {|id|
  343.         battler.state_time[id] = $data_states[id].hold_turn * 40 + 1}
  344.   end
  345.   #----------------------------------------------------------------------------
  346.   # count_states
  347.   #  Changes the state time counters.
  348.   #----------------------------------------------------------------------------
  349.   def count_states
  350.     # check each state
  351.     battler.state_time.keys.each {|id|
  352.         # decrease counter if fading state
  353.         battler.state_time[id] -= 1 if $data_states[id].battle_only
  354.         # if 1 second has passed and probability that the state gets removed
  355.         if battler.state_time[id] <= 0 && battler.state_time[id] % 40 == 0 &&
  356.             rand(100) < $data_states[id].auto_release_prob
  357.           # remove state and counter
  358.           battler.remove_state(id)
  359.           battler.state_time.delete(id)
  360.         end}
  361.   end
  362.   #----------------------------------------------------------------------------
  363.   # additional_states
  364.   #  Handles poison and paralyze effects as well as additional status effects.
  365.   #----------------------------------------------------------------------------
  366.   def additional_states
  367.     # temporary variable
  368.     slip_damage = battler.slip_damage?
  369.     # if Tons of Add-ons is there and using Regen Status
  370.     if $tons_version != nil && $tons_version >= 5.98 &&
  371.         $game_system.REGEN_STATUS
  372.       # modify slip damage flag
  373.       slip_damage |= (HP_REGEN_IDS + SP_REGEN_IDS + SP_POISON_IDS).any? {|i|
  374.           battler.states.include?(i)}
  375.     end
  376.     # if not dead, getting slip damage and every second
  377.     if valid? && slip_damage && Graphics.frame_count % 40 == 0
  378.       # apply the slip damage
  379.       slip_damage_effect
  380.     end
  381.     # if old direction fix was stored
  382.     if @old_direction_fix != nil
  383.       # if able to move again
  384.       if self.restriction < 4
  385.         # reset everything
  386.         @direction_fix, @old_direction_fix = @old_direction_fix, nil
  387.       end
  388.     # if paralyzed
  389.     elsif self.restriction == 4
  390.       # store old direction fix and set new direction fix
  391.       @direction_fix, @old_direction_fix = true, @direction_fix
  392.       # reset movement
  393.       @force_move = []
  394.       # reset action if valid and not charging
  395.       self.reset_action if self.valid? && !self.charging?(BlizzABS::CHARGEFreeze)
  396.     end
  397.   end
  398.   #----------------------------------------------------------------------------
  399.   # last_hit_by
  400.   #  Returns the last battler that hit this one for hp or sp damage.
  401.   #----------------------------------------------------------------------------
  402.   def last_hit_by
  403.     return (@battler == nil ? nil : @battler.last_hit_by)
  404.   end
  405.   #----------------------------------------------------------------------------
  406.   # last_action
  407.   #  Returns the last action by this battler.
  408.   #----------------------------------------------------------------------------
  409.   def last_action
  410.     return (@battler == nil ? ["none", false] : @battler.last_action)
  411.   end
  412.   #----------------------------------------------------------------------------
  413.   # slip_damage_effect
  414.   #  Applies slip damage effect.
  415.   #----------------------------------------------------------------------------
  416.   def slip_damage_effect
  417.     # store hpdamage and spdamage
  418.     hpdamage, spdamage = battler.hpdamage, battler.spdamage
  419.     # store current hp and sp
  420.     old_hp, old_sp = battler.hp, battler.sp
  421.     # if Tons of Add-ons is there and using Regen Status
  422.     if $tons_version != nil && $tons_version >= 5.98 &&
  423.         $game_system.REGEN_STATUS
  424.       # calculate HP damage
  425.       damage_hp = battler.maxhp / 50
  426.       damage_hp = 1 if damage_hp < 1
  427.       # if HP damaging state
  428.       if !(HP_REGEN_IDS.any? {|i| battler.states.include?(i)}) &&
  429.           battler.slip_damage?
  430.         # decrease HP by 2%
  431.         battler.hp -= damage_hp
  432.       # if HP regenarating state
  433.       elsif HP_REGEN_IDS.any? {|i| battler.states.include?(i)} &&
  434.           !battler.slip_damage?
  435.         # increase HP by 2%
  436.         battler.hp += damage_hp
  437.       end
  438.       # calculate SP damage
  439.       damage_sp = battler.maxsp / 50
  440.       damage_sp = 1 if damage_sp < 1
  441.       # if SP damaging state
  442.       if SP_POISON_IDS.any? {|i| battler.states.include?(i)}
  443.         # decrease SP by 2%
  444.         battler.sp -= damage_sp
  445.       end
  446.       # if SP regenarating state
  447.       if SP_REGEN_IDS.any? {|i| battler.states.include?(i)}
  448.         # increase SP by 2%
  449.         battler.sp += damage_sp
  450.       end
  451.     else
  452.       # decrease HP by 2%
  453.       dam = battler.maxhp / 50
  454.       dam = 1 if dam < 1
  455.       battler.hp -= dam
  456.       # set attacker and target data
  457.     end
  458.     # set last hit by
  459.     if (@battler.hp < old_hp || @battler.sp < old_sp)
  460.       slip_atk_size = @battler.last_slip_attackers.size
  461.        slip_atk_size > 0
  462.       @battler.last_hit_by = @battler.last_slip_attackers[slip_atk_size - 1]
  463.     end
  464.     # restore hpdamage and spdamage
  465.     battler.hpdamage, battler.spdamage = hpdamage, spdamage
  466.   end
  467.   #----------------------------------------------------------------------------
  468.   # can_act?
  469.   #  Tests if the battler is able to act in any way.
  470.   #----------------------------------------------------------------------------
  471.   def can_act?
  472.     # "can act" if knockback state
  473.     return true if @ai.state == BlizzABS::AI::Knockback
  474.     # can't act if abort state
  475.     return false if @ai.state == BlizzABS::AI::Abort
  476.     # can act if not defending
  477.     return true unless @ai.act.defend?
  478.     # turn toward reference target if it exists
  479.     turn_toward(@ai.target) if @ai.target != nil
  480.     # can't act
  481.     return false
  482.   end
  483.   #----------------------------------------------------------------------------
  484.   # update_behavior
  485.   #  Updates AI controlled behavior. The deriving classes implement the
  486.   #  methods called in this method and they call this method.
  487.   #----------------------------------------------------------------------------
  488.   def update_behavior
  489.     # if not paralyzed
  490.     if self.restriction < 4
  491.       # update AI
  492.       update_ai
  493.       # update action
  494.       update_action
  495.     end
  496.     # set up any force movement
  497.     setup_move
  498.   end
  499.   #----------------------------------------------------------------------------
  500.   # reset_action
  501.   #  Deletes action data.
  502.   #----------------------------------------------------------------------------
  503.   def reset_action
  504.     return if @ai.act.defend? && !@ai.act.ready?
  505.     @ai.state, @ai.target, @charge = BlizzABS::AI::Return, nil, nil
  506.     @ai.act.set
  507.   end
  508.   #----------------------------------------------------------------------------
  509.   # freeze_action
  510.   #  Overriding method to support paralyzed status effect
  511.   #----------------------------------------------------------------------------
  512.   def freeze_action
  513.     return (self.restriction == 4 || @freeze_action || charging? && !charged?)
  514.   end
  515.   #----------------------------------------------------------------------------
  516.   # restriction
  517.   #  Overriding method for easier reference.
  518.   #----------------------------------------------------------------------------
  519.   def restriction
  520.     return 0 if !valid? || battler.dead?
  521.     return 4 if charging?(BlizzABS::CHARGEFreeze)
  522.     return @battler.restriction
  523.   end
  524.   #----------------------------------------------------------------------------
  525.   # battler_id
  526.   #  Overriding method for easier reference.
  527.   #----------------------------------------------------------------------------
  528.   def battler_id
  529.     return (@battler == nil ? 0 : @battler.id)
  530.   end
  531.   #----------------------------------------------------------------------------
  532.   # states
  533.   #  Overriding method for easier reference.
  534.   #----------------------------------------------------------------------------
  535.   def states
  536.     return (@battler == nil ? [] : @battler.states)
  537.   end
  538.   #----------------------------------------------------------------------------
  539.   # set_action
  540.   #  rate - penalty rate in seconds
  541.   #  Set frame penalty counter.
  542.   #----------------------------------------------------------------------------
  543.   def set_action(rate)
  544.     @in_action = rate
  545.   end
  546.   #----------------------------------------------------------------------------
  547.   # attack_can_use?
  548.   #  Determines whether an attack can be used, serves for extension purposes.
  549.   #  It automatically recognizes HP/SP Crush from Tons of Add-ons.
  550.   #----------------------------------------------------------------------------
  551.   def attack_can_use?
  552.     # cant use if no battler
  553.     if (@battler == nil)
  554.       return false
  555.     end
  556.     # if Tons is there and using HP/SP Crush and actor
  557.     if $tons_version != nil && $tons_version >= 6.4 &&
  558.         $game_system.HP_SP_CRUSH && self.is_a?(Map_Actor)
  559.       # can it be used
  560.       return @battler.attack_can_use?
  561.     end
  562.     # can be used
  563.     return true
  564.   end
  565.   #----------------------------------------------------------------------------
  566.   # skill_can_use?
  567.   #  id - skill ID
  568.   #  forced - whether this is a forced action
  569.   #  Determines whether a skill can be used, serves for extendable purposes.
  570.   #----------------------------------------------------------------------------
  571.   def skill_can_use?(id, forced = false)
  572.     # cant use if no battler
  573.     if (@battler == nil)
  574.       return false
  575.     end
  576.     if (forced)
  577.       # If low SP, incapacitated, or silent and non-physical, can't use
  578.       return $data_skills[id].sp_cost <= @battler.sp && !@battler.dead? &&
  579.          ($data_skills[id].atk_f != 0 || @battler.restriction != 1)
  580.     end
  581.     return @battler.skill_can_use?(id)
  582.   end
  583.   #----------------------------------------------------------------------------
  584.   # item_can_use?
  585.   #  id - item ID
  586.   #  forced - whether this is a forced action
  587.   #  Determines whether an item can be used, serves for extendable purposes.
  588.   #----------------------------------------------------------------------------
  589.   def item_can_use?(id, forced = false)
  590.     # cant use if no battler
  591.     if (@battler == nil)
  592.       return false
  593.     end
  594.     if (forced)
  595.       # Unusable If item quantity is 0
  596.       return $game_party.item_number(id) != 0
  597.     end
  598.     return $game_party.item_can_use?(id)
  599.   end
  600.   #----------------------------------------------------------------------------
  601.   # use_defend
  602.   #  Processes using a defending action.
  603.   #----------------------------------------------------------------------------
  604.   def use_defend
  605.     setup_sprites(BlizzABS::SPRDefend)
  606.     # action truth value
  607.     truthval = @battler.last_action[0] == "defend" && @battler.last_action[1]
  608.     # set last action
  609.     @battler.last_action = ["defend", truthval]
  610.   end
  611.   #----------------------------------------------------------------------------
  612.   # use_attack
  613.   #  Processes using an attack.
  614.   #----------------------------------------------------------------------------
  615.   def use_attack
  616.     # remove last hpdamage and spdamage values
  617.     @battler.hpdamage = @battler.spdamage = 0
  618.     # if battler can use attack and attack was processed with success
  619.     if attack_can_use?
  620.       # default combo id
  621.       combo_id = 0
  622.       # get combo id based on whether the character is an actor or enemy
  623.       if self.is_a?(Map_Enemy)
  624.         combo_id = BlizzABS::Enemies.combo(self.battler.id)
  625.       elsif self.is_a?(Map_Actor)
  626.         combo_id = BlizzABS::Weapons.combo(self.battler.weapon_id)
  627.       end
  628.       # if combo id is valid and not currently in a combo
  629.       if combo_id != 0 && @combo == nil
  630.         # create combo
  631.         @combo = BlizzABS::Combo.new(combo_id, self)
  632.         # return used
  633.         return true
  634.       end
  635.       # set last action
  636.       @battler.last_action = ["attack", false]
  637.       # execute attack
  638.       result = $BlizzABS.attack_process(self)
  639.       # if used and not charging up
  640.       if result
  641.         # sets everything up for attack sprites
  642.         setup_sprites(BlizzABS::SPRAttack)
  643.         # set frame penalty
  644.         set_action(self.attack_penalty)
  645.         # attack consumption effect
  646.         attack_consumption
  647.         # set usage animation
  648.         set_usage_animation(battler)
  649.         # set up user damage display if necessary
  650.         user_damage_display
  651.         # reset action if attack executed
  652.         self.reset_action
  653.       end
  654.       # used or charging
  655.       return (result || charging?)
  656.     end
  657.     # not used
  658.     return false
  659.   end
  660.   #----------------------------------------------------------------------------
  661.   # use_skill
  662.   #  skill - the skill to be used
  663.   #  forced - whether this is a forced action
  664.   #  Processes using a skill.
  665.   #----------------------------------------------------------------------------
  666.   def use_skill(skill, forced = false)
  667.     # remove last hpdamage and spdamage values
  668.     @battler.hpdamage = @battler.spdamage = 0
  669.     # if can use the skill
  670.     if skill_can_use?(skill.id, forced)
  671.       # get combo id
  672.       combo_id = BlizzABS::Skills.combo(skill.id)
  673.       # if combo id is valid and not currently in a combo
  674.       if combo_id != 0 && @combo == nil
  675.         # create combo
  676.         @combo = BlizzABS::Combo.new(combo_id, self)
  677.         # return used
  678.         return true
  679.       end
  680.       # set last action
  681.       @battler.last_action = ["skill", false]
  682.       # execute skill
  683.       result = $BlizzABS.skillitem_process(self, skill)
  684.       # effectiveness
  685.       effective = (result || charging? && !charged?)
  686.       # if used or charging up and about to discharge
  687.       if result
  688.         # set frame penalty
  689.         set_action(self.skill_penalty(skill.id))
  690.         # skill consumption effect
  691.         skill_consumption(skill)
  692.         # call common event
  693.         common_event_call(skill)
  694.         # set usage animation
  695.         set_usage_animation(skill)
  696.         # set sprite animation
  697.         set_sprite_animation(BlizzABS::SPRSkill, skill_sprites?, skill)
  698.         # set up user damage display if necessary
  699.         user_damage_display
  700.         # reset action
  701.         self.reset_action
  702.       # if discharged
  703.       elsif charging? && charged?
  704.         # reset action
  705.         self.reset_action
  706.       end
  707.       # effective
  708.       return effective
  709.     end
  710.     # not used
  711.     return false
  712.   end
  713.   #----------------------------------------------------------------------------
  714.   # use_item
  715.   #  item - the item to be used
  716.   #  forced - whether this is a forced action
  717.   #  Processes using an item.
  718.   #----------------------------------------------------------------------------
  719.   def use_item(item, forced = false)
  720.     # remove last hpdamage and spdamage values
  721.     @battler.hpdamage = @battler.spdamage = 0
  722.     # if can use the item
  723.     if item_can_use?(item.id, forced)
  724.       # get combo id
  725.       combo_id = BlizzABS::Items.combo(item.id)
  726.       # if combo id is valid and not currently in a combo
  727.       if combo_id != 0 && @combo == nil
  728.         # create combo
  729.         @combo = BlizzABS::Combo.new(combo_id, self)
  730.         # return used
  731.         return true
  732.       end
  733.       # execute item
  734.       result = $BlizzABS.skillitem_process(self, item)
  735.       # effectiveness
  736.       effective = (result || charging? && !charged?)
  737.       # set last action
  738.       @battler.last_action = ["item", false]
  739.       # if used or charging up and about to discharge
  740.       if result
  741.         # set frame penalty
  742.         set_action(self.item_penalty(item.id))
  743.         # skill consumption effect
  744.         item_consumption(item)
  745.         # call common event
  746.         common_event_call(item)
  747.         # set usage animation
  748.         set_usage_animation(item)
  749.         # set sprite animation
  750.         set_sprite_animation(BlizzABS::SPRItem, item_sprites?, item)
  751.         # set up user damage display if necessary
  752.         user_damage_display
  753.         # reset action
  754.         self.reset_action
  755.       # if discharged
  756.       elsif charging? && charged?
  757.         # reset action
  758.         self.reset_action
  759.       end
  760.       # effective
  761.       return effective
  762.     end
  763.     # not used
  764.     return false
  765.   end
  766.   #----------------------------------------------------------------------------
  767.   # attack_consumption
  768.   #  Processes aftermath of using an attack. Serves for extension purposes.
  769.   #  It automatically recognizes HP/SP Crush from Tons of Add-ons.
  770.   #----------------------------------------------------------------------------
  771.   def attack_consumption
  772.     # if Tons is there and using HP/SP Crush and actor
  773.     if $tons_version != nil && $tons_version >= 6.4 &&
  774.         $game_system.HP_SP_CRUSH && self.is_a?(Map_Actor)
  775.       # store hpdamage and spdamage
  776.       hpdamage, spdamage = @battler.hpdamage, @battler.spdamage
  777.       # get requirements
  778.       reqs = BlizzCFG.hpsp_crush(@battler.weapon_id)
  779.       # HP consumption
  780.       @battler.hp -= reqs[0]
  781.       # SP consumption
  782.       @battler.sp -= reqs[1]
  783.       # restore hpdamage and spdamage
  784.       @battler.hpdamage, @battler.spdamage = hpdamage, spdamage
  785.     end
  786.   end
  787.   #----------------------------------------------------------------------------
  788.   # skill_consumption
  789.   #  skill - the skill that was used
  790.   #  Processes aftermath of using a skill.
  791.   #----------------------------------------------------------------------------
  792.   def skill_consumption(skill)
  793.     # store spdamage
  794.     spdamage = @battler.spdamage
  795.     # SP consumption
  796.     @battler.sp -= @battler.spdamage + skill.sp_cost
  797.     # restore spdamage
  798.     @battler.spdamage = spdamage
  799.     # if using Tons of Add-ons and HP Consuming Skills
  800.     if $tons_version != nil && $tons_version >= 7.2 && $game_system.HP_SKILL
  801.       # store hpdamage
  802.       hpdamage = @battler.hpdamage
  803.       # HP consumption
  804.       @battler.hp -= @battler.hpdamage + skill.hp_cost
  805.       # restore hpdamage
  806.       @battler.hpdamage = hpdamage
  807.     end
  808.   end
  809.   #----------------------------------------------------------------------------
  810.   # item_consumption
  811.   #  item - the item that was used
  812.   #  Processes aftermath of using an item.
  813.   #----------------------------------------------------------------------------
  814.   def item_consumption(item)
  815.     # item consumption if item can be consumed
  816.     $game_party.lose_item(item.id, 1) if item.consumable
  817.   end
  818.   #----------------------------------------------------------------------------
  819.   # common_event_call
  820.   #  object - the skill of item
  821.   #  Runs a common event if supported by the object.
  822.   #----------------------------------------------------------------------------
  823.   def common_event_call(object)
  824.     # if object calls common event
  825.     if object.common_event_id > 0
  826.       # temporary variable
  827.       common_event = $data_common_events[object.common_event_id]
  828.       # setup common event execution
  829.       $game_system.map_interpreter.setup(common_event.list, 0)
  830.     end
  831.   end
  832.   #----------------------------------------------------------------------------
  833.   # attack_effect
  834.   #  character - the character that holds attack data (can be projectile)
  835.   #  _battler  - the attacking battler
  836.   #  Executes attack upon a map character.
  837.   #----------------------------------------------------------------------------
  838.   def attack_effect(character, _battler)
  839.     # stop attack if no battler assigned or still invincible
  840.     return false if @battler == nil || @blinking != nil && @blinking > 0
  841.     # stop attack if pressing CTRL in debug mode
  842.     return false if $DEBUG && @ai.group != 0 && Input.press?(Input::CTRL)
  843.     # damage sprite character
  844.     dmgchar = (@body == nil ? self : @body)
  845.     # if full defending
  846.     if BlizzABS::Config::FULL_DEFEND && @ai.act.defend?
  847.       # set attacked counter
  848.       self.attacked = $BlizzABS.pixel
  849.       # request damage sprite
  850.       $BlizzABS.util.request_damage_sprite(dmgchar, BlizzABS::Cache::TXTDefend)
  851.       # not executed
  852.       return false
  853.     end
  854.     # if defending set action data
  855.     if @ai.act.defend? && @battler.last_action[0] == "defend"
  856.       @battler.last_action[1] = true
  857.     end
  858.     # needed for defend emulation
  859.     @battler.current_action.kind = 0
  860.     # set own battler's action as defend action if necessary
  861.     @battler.current_action.basic = (@ai.act.defend? ? 1 : 0)
  862.     # reset hpdamage and spdamage
  863.     @battler.hpdamage, @battler.spdamage = 0, 0
  864.     # get result
  865.     result = @battler.attack_effect(_battler)
  866.     # if effect processing was executed
  867.     if result || self.damage_display?
  868.       # apply basic effects
  869.       action_effect(_battler)
  870.       # apply weapon knockback
  871.       if _battler.is_a?(Game_Actor)
  872.         self.attacked *= BlizzABS::Weapons.knockback(_battler.weapon_id)
  873.       # apply enemy knockback
  874.       else
  875.         self.attacked *= BlizzABS::Enemies.knockback(_battler.id)
  876.       end
  877.       # face attacker
  878.       turn_toward(character) if BlizzABS::Config::KNOCKBACK_MODE == 2
  879.       # apply action effect if any actual damage done
  880.       alignment_effect(character.ai.group) if self.damage_done?
  881.       # request damage sprite
  882.       $BlizzABS.util.request_damage_sprite(dmgchar)
  883.       # set last hit by
  884.       if @battler.hpdamage > 0 || @battler.spdamage > 0
  885.         @battler.last_hit_by = _battler
  886.       end
  887.       # reset hpdamage and spdamage
  888.       @battler.hpdamage, @battler.spdamage = 0, 0
  889.       # attack was executed
  890.       result = true
  891.       # set attacker and target data
  892.       @battler.last_attackers.push(_battler)
  893.       _battler.last_targets.push(@battler)
  894.       # if attack set action data
  895.       _battler.last_action[1] = true if _battler.last_action[0] == "attack"
  896.       # check slip damage state
  897.       if _battler.plus_state_set.any? {|s| $data_states[s].slip_damage}
  898.         @battler.last_slip_attackers.push(_battler)
  899.       end
  900.     end
  901.     # send data to obeserver if attacked by actor
  902.     $BlizzABS.AI.observe(_battler, @battler.damage) if _battler.is_a?(Game_Actor)
  903.     # delete own charge data if executed
  904.     @charge = nil if result
  905.     # return result
  906.     return result
  907.   end
  908.   #----------------------------------------------------------------------------
  909.   # skill_effect
  910.   #  character - the character that holds skill use (can be projectile)
  911.   #  _battler  - the skill using battler
  912.   #  skill     - the skill
  913.   #  Executes skill use upon a map character.
  914.   #----------------------------------------------------------------------------
  915.   def skill_effect(character, _battler, skill)
  916.     # stop skill if no battler assigned
  917.     return false if @battler == nil
  918.     # stop skill if pressing CTRL in debug mode
  919.     return false if $DEBUG && @ai.group != 0 && Input.press?(Input::CTRL)
  920.     # if defending set action data
  921.     if @ai.act.defend? && @battler.last_action[0] == "defend"
  922.       @battler.last_action[1] = true
  923.     end
  924.     # reset own battler's action
  925.     @battler.current_action.kind = @battler.current_action.basic = 0
  926.     # reset hpdamage and spdamage
  927.     @battler.hpdamage, @battler.spdamage = 0, 0
  928.     # get slip damage state
  929.     slip_dmg = (@battler.slip_damage? ? true : false)
  930.     # get result
  931.     result = @battler.skill_effect(_battler, skill)
  932.     # if effect processing was executed
  933.     if result || self.damage_display?
  934.       # apply basic effects
  935.       action_effect(skill)
  936.       # apply knockback
  937.       self.attacked *= BlizzABS::Skills.knockback(skill.id)
  938.       # face attacker
  939.       turn_toward(character) if BlizzABS::Config::KNOCKBACK_MODE == 2
  940.       # apply action effect if any actual damage done
  941.       alignment_effect(character.ai.group) if self.damage_done?
  942.       # request damage sprite
  943.       $BlizzABS.util.request_damage_sprite(@body == nil ? self : @body)
  944.       # set last hit by
  945.       if @battler.hpdamage > 0 || @battler.spdamage > 0
  946.         @battler.last_hit_by = _battler
  947.       end
  948.       # reset hpdamage and spdamage
  949.       @battler.hpdamage, @battler.spdamage = 0, 0
  950.       # attack was executed
  951.       result = true
  952.       # set attacker and target data
  953.       @battler.last_attackers.push(_battler)
  954.       _battler.last_targets.push(@battler)
  955.       # if skill set action data
  956.       _battler.last_action[1] = true if _battler.last_action[0] == "skill"
  957.       # check slip damage state
  958.       if skill.plus_state_set.any? {|s| $data_states[s].slip_damage}
  959.         @battler.last_slip_attackers.push(_battler)
  960.       end
  961.     end
  962.     # send data to obeserver if attacked by actor
  963.     $BlizzABS.AI.observe(_battler, @battler.damage) if _battler.is_a?(Game_Actor)
  964.     # delete own charge data if executed
  965.     @charge = nil if result
  966.     # return result
  967.     return result
  968.   end
  969.   #----------------------------------------------------------------------------
  970.   # item_effect
  971.   #  character - the character that holds item use (can be projectile)
  972.   #  item      - the item
  973.   #  Executes item use upon a map character.
  974.   #----------------------------------------------------------------------------
  975.   def item_effect(character, _battler, item)
  976.     # stop item if no battler assigned
  977.     return false if @battler == nil
  978.     # stop item if pressing CTRL in debug mode
  979.     return false if $DEBUG && @ai.group != 0 && Input.press?(Input::CTRL)
  980.     # if defending set action data
  981.     if @ai.act.defend? && @battler.last_action[0] == "defend"
  982.       @battler.last_action[1] = true
  983.     end
  984.     # reset own battler's action
  985.     @battler.current_action.kind = @battler.current_action.basic = 0
  986.     # reset hpdamage and spdamage
  987.     @battler.hpdamage, @battler.spdamage = 0, 0
  988.     # get result
  989.     result = @battler.item_effect(item)
  990.     # if effect processing was executed
  991.     if result || self.damage_display?
  992.       # apply basic effects
  993.       action_effect(item)
  994.       # apply knockback
  995.       self.attacked *= BlizzABS::Items.knockback(item.id)
  996.       # face attacker
  997.       turn_toward(character) if BlizzABS::Config::KNOCKBACK_MODE == 2
  998.       # apply action effect if any actual damage done
  999.       alignment_effect(character.ai.group) if self.damage_done?
  1000.       # request damage sprite
  1001.       $BlizzABS.util.request_damage_sprite(@body == nil ? self : @body)
  1002.       # set last hit by
  1003.       if @battler.hpdamage > 0 || @battler.spdamage > 0
  1004.         @battler.last_hit_by = _battler
  1005.       end
  1006.       # reset hpdamage and spdamage
  1007.       @battler.hpdamage, @battler.spdamage = 0, 0
  1008.       # attack was executed
  1009.       result = true
  1010.       # set attacker and target data
  1011.       @battler.last_attackers.push(_battler)
  1012.       _battler.last_targets.push(@battler)
  1013.       # if item set action data
  1014.       _battler.last_action[1] = true if _battler.last_action[0] == "item"
  1015.       # check slip damage state
  1016.       if item.plus_state_set.any? {|s| $data_states[s].slip_damage}
  1017.         @battler.last_slip_attackers.push(_battler)
  1018.       end
  1019.     end
  1020.     # delete own charge data if executed
  1021.     @charge = nil if result
  1022.     # return result
  1023.     return result
  1024.   end
  1025.   #----------------------------------------------------------------------------
  1026.   # alignment_effect
  1027.   #  group - the group to which the character belongs to
  1028.   #  Applies alignment changes.
  1029.   #----------------------------------------------------------------------------
  1030.   def alignment_effect(group)
  1031.     # if not already negatively aligned
  1032.     if !(@ai.negative + @ai.neutral).include?(group)
  1033.       # add negative group
  1034.       @ai.negative.push(group)
  1035.       # mark this battler with altered alignment
  1036.       @ai.altered_alignment = true
  1037.     end
  1038.   end
  1039.   #----------------------------------------------------------------------------
  1040.   # damage_display?
  1041.   #  Checks if there is any damage to display.
  1042.   #----------------------------------------------------------------------------
  1043.   def damage_display?
  1044.     return (@battler.hpdamage != 0 || @battler.spdamage != 0 ||
  1045.         @battler.damage.is_a?(Numeric))
  1046.   end
  1047.   #----------------------------------------------------------------------------
  1048.   # damage_done?
  1049.   #  Checks if there is any actual damage to display.
  1050.   #----------------------------------------------------------------------------
  1051.   def damage_done?
  1052.     return (@battler.hpdamage > 0 || @battler.spdamage > 0 ||
  1053.         @battler.damage.is_a?(Numeric) && @battler.damage >= 0)
  1054.   end
  1055.   #----------------------------------------------------------------------------
  1056.   # user_damage_display
  1057.   #  Sets up damage display for the user if HP or SP have changed.
  1058.   #----------------------------------------------------------------------------
  1059.   def user_damage_display
  1060.     # if any HP or SP change
  1061.     if @battler.hpdamage != 0 || @battler.spdamage != 0
  1062.       # request damage sprite
  1063.       $BlizzABS.util.request_damage_sprite(@body == nil ? self : @body)
  1064.     end
  1065.     # reset hpdamage and spdamage
  1066.     @battler.hpdamage, @battler.spdamage = 0, 0
  1067.   end
  1068.   #----------------------------------------------------------------------------
  1069.   # charging?
  1070.   #  type - charge type
  1071.   #  Checks whether charging up.
  1072.   #----------------------------------------------------------------------------
  1073.   def charging?(type = nil)
  1074.     return (@charge != nil && (type == nil || type == @charge.type))
  1075.   end
  1076.   #----------------------------------------------------------------------------
  1077.   # charged?
  1078.   #  Checks whether charged up.
  1079.   #----------------------------------------------------------------------------
  1080.   def charged?
  1081.     return @charge.charged?
  1082.   end
  1083.   #----------------------------------------------------------------------------
  1084.   # setup_charge
  1085.   #  object - battler (for attack), skill or item
  1086.   #  charge - charge data
  1087.   #  Sets up the appropriate data for charging.
  1088.   #----------------------------------------------------------------------------
  1089.   def setup_charge(object, charge)
  1090.     # get data depending on action to be executed
  1091.     case object
  1092.     when Map_Battler then action, id = BlizzABS::CHARGEAttack, 0
  1093.     when RPG::Skill then action, id = BlizzABS::CHARGESkill, object.id
  1094.     when RPG::Item then action, id = BlizzABS::CHARGEItem, object.id
  1095.     end
  1096.     # setup charge data
  1097.     @charge = BlizzABS::ChargeData.new(charge[0], charge[1], action, id)
  1098.   end
  1099.   #----------------------------------------------------------------------------
  1100.   # set_usage_animation
  1101.   #  object - the battler, skill or item
  1102.   #  Sets usage animation
  1103.   #----------------------------------------------------------------------------
  1104.   def set_usage_animation(object)
  1105.     # set usage animation ID if ANIMATIONS is turned on
  1106.     @animation_id = object.animation1_id if BlizzABS::Config::ANIMATIONS
  1107.   end
  1108.   #----------------------------------------------------------------------------
  1109.   # set_sprite_animation
  1110.   #  name     - spriteset base name
  1111.   #  extended - flag to determine whether to add or not the object.id
  1112.   #  object   - the skill or item
  1113.   #  Processes using a skill.
  1114.   #----------------------------------------------------------------------------
  1115.   def set_sprite_animation(name, extended, object)
  1116.     # setup sprite extension
  1117.     setup_sprites(extended ? name + object.id.to_s : name)
  1118.   end
  1119.   #----------------------------------------------------------------------------
  1120.   # action_effect
  1121.   #  object - the battler, skill or item
  1122.   #  Applies some basic action effects.
  1123.   #----------------------------------------------------------------------------
  1124.   def action_effect(object)
  1125.     # set attacked counter
  1126.     self.attacked = $BlizzABS.pixel if BlizzABS::Config::KNOCKBACK_MODE > 0
  1127.     # set attacked enemy animation ID if ANIMATIONS is turned on
  1128.     @animation_id = object.animation2_id if BlizzABS::Config::ANIMATIONS
  1129.   end
  1130.   #----------------------------------------------------------------------------
  1131.   # valid?
  1132.   #  Checks if the assigned battler exists.
  1133.   #----------------------------------------------------------------------------
  1134.   def valid?
  1135.     return (self.battler != nil)
  1136.   end
  1137.   #----------------------------------------------------------------------------
  1138.   # pattern
  1139.   #  Overriding method for accessing the pattern number of the spriteset.
  1140.   #----------------------------------------------------------------------------
  1141.   def pattern
  1142.     # if not in action and jumping and turned on JUMPING_SPRITES
  1143.     if self.in_action == 0 && jumping? && jumping_sprites?
  1144.       # pattern 1 if jumping up, 3 if falling down again else 2
  1145.       return (@jump_count > @jump_peak + 1 ? 1 :
  1146.           (@jump_count < @jump_peak - 1 ? 3 : 2))
  1147.     end
  1148.     # if animating and either in action and not defending or charging
  1149.     if (in_action > 0 && !@ai.act.defend? || charging?) &&
  1150.         @sindex < @sframes.size && @sframes[@sindex] > 0
  1151.       # return sprite animation modified pattern
  1152.       return @sindex
  1153.     end
  1154.     # return normal pattern if not in action
  1155.     return @pattern
  1156.   end
  1157.   #----------------------------------------------------------------------------
  1158.   # pattern_size
  1159.   #  Gets the altered pattern_size
  1160.   #----------------------------------------------------------------------------
  1161.   def pattern_size
  1162.     # if in action or charging and animating
  1163.     if (in_action > 0 || charging?) && @sindex < @sframes.size &&
  1164.         @sframes[@sindex] > 0
  1165.       # return sprite animation modified pattern
  1166.       return @sframes.size
  1167.     end
  1168.     # return normal pattern if not in action
  1169.     return @pattern_size
  1170.   end
  1171.   #----------------------------------------------------------------------------
  1172.   # attack_penalty
  1173.   #  Returns the penalty for the attack.
  1174.   #----------------------------------------------------------------------------
  1175.   def attack_penalty
  1176.     return 0
  1177.   end
  1178.   #----------------------------------------------------------------------------
  1179.   # skill_penalty
  1180.   #  id - skill ID
  1181.   #  Returns the penalty for the skill.
  1182.   #----------------------------------------------------------------------------
  1183.   def skill_penalty(id)
  1184.     # get skill penalty
  1185.     penalty = BlizzABS::Skills.penalty(id)
  1186.     # limit is sum of all animation frames if using action sprites
  1187.     limit = (action_sprites? ? BlizzABS::Skills.frames(id).sum : 0)
  1188.     # limit penalty
  1189.     return (penalty < limit ? limit : penalty)
  1190.   end
  1191.   #----------------------------------------------------------------------------
  1192.   # item_penalty
  1193.   #  id - item ID
  1194.   #  Returns the penalty for the item.
  1195.   #----------------------------------------------------------------------------
  1196.   def item_penalty(id)
  1197.     # get item penalty
  1198.     penalty = BlizzABS::Items.penalty(id)
  1199.     # limit is sum of all animation frames if using action sprites
  1200.     limit = (action_sprites? ? BlizzABS::Items.frames(id).sum : 0)
  1201.     # limit penalty
  1202.     return (penalty < limit ? limit : penalty)
  1203.   end
  1204.   #----------------------------------------------------------------------------
  1205.   # sprite_animation_setup
  1206.   #  Processes the sprite-animation timing.
  1207.   #----------------------------------------------------------------------------
  1208.   def sprite_animation_setup
  1209.     # if not Scene_Map, spriteset doesn't exist, not valid or no action sprites
  1210.     if !$scene.is_a?(Scene_Map) || $scene.spriteset == nil || !valid? ||
  1211.         !action_sprites?
  1212.       # stop
  1213.       return
  1214.     end
  1215.     # if defending
  1216.     if @ai.act.defend?
  1217.       # set spriteset name add-ons
  1218.       @current_sprite, @weapon_sprite = BlizzABS::SPRDefend, ''
  1219.       # set spriteset name
  1220.       @character_name = @character_name_org + @current_sprite
  1221.     # spriteset name add-on exists
  1222.     elsif @current_sprite != '' && @character_name_org != ''
  1223.       # decrease frame timer
  1224.       @sframes[@sindex] -= 1
  1225.       # increase frame index if this frame is over
  1226.       @sindex += 1 if @sframes[@sindex] <= 0
  1227.       # if animation expired
  1228.       if @sindex >= @sframes.size
  1229.         # reset sprites
  1230.         reset_sprites
  1231.         # set the index back
  1232.         @sindex = 0
  1233.       else
  1234.         # set spriteset name
  1235.         @character_name = @character_name_org + @current_sprite
  1236.       end
  1237.     else
  1238.       # reset sprites
  1239.       reset_sprites
  1240.     end
  1241.     # if sprite extension doesn't exist already
  1242.     if @current_sprite == '' && @character_name_org != ''
  1243.       # set up movement sprite handling
  1244.       sprite_movement_animation_setup
  1245.     end
  1246.   end
  1247.   #----------------------------------------------------------------------------
  1248.   # sprite_movement_animation_setup
  1249.   #  Sets up movement sprite handling.
  1250.   #----------------------------------------------------------------------------
  1251.   def sprite_movement_animation_setup
  1252.     # if jumping and turned on JUMPING_SPRTES
  1253.     if jumping_sprites? && self.jumping?
  1254.       # set spriteset name
  1255.       @current_sprite = BlizzABS::SPRJumping
  1256.       @character_name = @character_name_org + @current_sprite
  1257.     # if running and turned on RUNNING_SPRTES
  1258.     elsif running_sprites? && #self.moving? && edit 123
  1259.         self.running? && self.attacked <= 0
  1260.       # set spriteset name
  1261.       @current_sprite = BlizzABS::SPRRunning
  1262.       @character_name = @character_name_org + @current_sprite
  1263.     # if sneaking and turned on SNEAKING_SPRTES
  1264.     elsif sneaking_sprites? && (self.moving? || Input.dir8 != 0) &&
  1265.         self.sneaking? && self.attacked <= 0
  1266.       # set spriteset name
  1267.       @current_sprite = BlizzABS::SPRSneaking
  1268.       @character_name = @character_name_org + @current_sprite
  1269.     # if idle and using idle sprites
  1270.     elsif self.idle? && idle_sprites?
  1271.       # set spriteset name
  1272.       @current_sprite = BlizzABS::SPRIdle
  1273.       @character_name = @character_name_org + @current_sprite
  1274.     # if charging
  1275.     elsif self.charging? && charge_sprites?
  1276.       # setup charge sprites
  1277.       setup_charge_sprites
  1278.     end
  1279.   end
  1280.   #----------------------------------------------------------------------------
  1281.   # action_sprites?
  1282.   #  Checks if action sprites can be used.
  1283.   #----------------------------------------------------------------------------
  1284.   def action_sprites?
  1285.     return false
  1286.   end
  1287.   #----------------------------------------------------------------------------
  1288.   # weapon_sprites?
  1289.   #  Checks if weapon sprites can be used.
  1290.   #----------------------------------------------------------------------------
  1291.   def weapon_sprites?
  1292.     return false
  1293.   end
  1294.   #----------------------------------------------------------------------------
  1295.   # skill_sprites?
  1296.   #  Checks if skill sprites can be used.
  1297.   #----------------------------------------------------------------------------
  1298.   def skill_sprites?
  1299.     return false
  1300.   end
  1301.   #----------------------------------------------------------------------------
  1302.   # item_sprites?
  1303.   #  Checks if item sprites can be used.
  1304.   #----------------------------------------------------------------------------
  1305.   def item_sprites?
  1306.     return false
  1307.   end
  1308.   #----------------------------------------------------------------------------
  1309.   # jumping_sprites?
  1310.   #  Checks if jumping sprites can be used.
  1311.   #----------------------------------------------------------------------------
  1312.   def jumping_sprites?
  1313.     return false
  1314.   end
  1315.   #----------------------------------------------------------------------------
  1316.   # running_sprites?
  1317.   #  Checks if running sprites can be used.
  1318.   #----------------------------------------------------------------------------
  1319.   def running_sprites?
  1320.     return false
  1321.   end
  1322.   #----------------------------------------------------------------------------
  1323.   # sneaking_sprites?
  1324.   #  Checks if sneaking sprites can be used.
  1325.   #----------------------------------------------------------------------------
  1326.   def sneaking_sprites?
  1327.     return false
  1328.   end
  1329.   #----------------------------------------------------------------------------
  1330.   # idle_sprites?
  1331.   #  Checks if idle sprites can be used.
  1332.   #----------------------------------------------------------------------------
  1333.   def idle_sprites?
  1334.     return false
  1335.   end
  1336.   #----------------------------------------------------------------------------
  1337.   # charge_sprites?
  1338.   #  Checks if charge sprites can be used.
  1339.   #----------------------------------------------------------------------------
  1340.   def charge_sprites?
  1341.     return false
  1342.   end
  1343.   #----------------------------------------------------------------------------
  1344.   # charge_weapon_sprites?
  1345.   #  Checks if charge weapon sprites can be used.
  1346.   #----------------------------------------------------------------------------
  1347.   def charge_weapon_sprites?
  1348.     return false
  1349.   end
  1350.   #----------------------------------------------------------------------------
  1351.   # charge_skill_sprites?
  1352.   #  Checks if charge skill sprites can be used.
  1353.   #----------------------------------------------------------------------------
  1354.   def charge_skill_sprites?
  1355.     return false
  1356.   end
  1357.   #----------------------------------------------------------------------------
  1358.   # charge_item_sprites?
  1359.   #  Checks if charge item sprites can be used.
  1360.   #----------------------------------------------------------------------------
  1361.   def charge_item_sprites?
  1362.     return false
  1363.   end
  1364.   #----------------------------------------------------------------------------
  1365.   # setup_sprites
  1366.   #  type - the spriteset extension
  1367.   #  Sets up everything used for sprite combination.
  1368.   #----------------------------------------------------------------------------
  1369.   def setup_sprites(type)
  1370.     # stop if animations are not active
  1371.     return unless action_sprites?
  1372.     # set current sprite extension
  1373.     @current_sprite = type
  1374.     # default animation frames
  1375.     data = BlizzABS::Cache::FramesDefault.clone
  1376.     # if attack sprites
  1377.     if type == BlizzABS::SPRAttack
  1378.       # set up attack sprites
  1379.       data = setup_attack_sprites
  1380.     # if skill sprites
  1381.     elsif type[0, 4] == BlizzABS::SPRSkill
  1382.       # get frame animation data
  1383.       data = BlizzABS::Skills.frames(type[4, type.size - 4].to_i)
  1384.     # if item sprites
  1385.     elsif type[0, 4] == BlizzABS::SPRItem
  1386.       # get frame animation data
  1387.       data = BlizzABS::Items.frames(type[4, type.size - 4].to_i)
  1388.     end
  1389.     # set spriteset name
  1390.     @character_name = @character_name_org + @current_sprite
  1391.     # setup frames
  1392.     setup_frames(data)
  1393.   end
  1394.   #----------------------------------------------------------------------------
  1395.   # setup_charge_sprites
  1396.   #  type - the spriteset extension
  1397.   #  Sets up everything used for sprite combination.
  1398.   #----------------------------------------------------------------------------
  1399.   def setup_charge_sprites
  1400.     # spriteset name add-on
  1401.     @current_sprite = BlizzABS::SPRCharge
  1402.     # default animation frames
  1403.     data = BlizzABS::Cache::FramesDefault.clone
  1404.     # if charging attack and charge attack active
  1405.     if @charge.action == BlizzABS::CHARGEAttack && charge_weapon_sprites?
  1406.       # set up charge attack sprites
  1407.       data = setup_charge_attack_sprites
  1408.     # if charging skill and skill charge active
  1409.     elsif @charge.action == BlizzABS::CHARGESkill && charge_skill_sprites?
  1410.       # spriteset name add-on
  1411.       @current_sprite = BlizzABS::SPRSkill + BlizzABS::SPRCharge +
  1412.           @charge.id.to_s
  1413.       # get frame animation data
  1414.       data = BlizzABS::Skills.charge_frames(@charge.id)
  1415.     # if charging item and item charge active
  1416.     elsif @charge.action == BlizzABS::CHARGEItem && charge_item_sprites?
  1417.       # spriteset name add-on
  1418.       @current_sprite = BlizzABS::SPRItem + BlizzABS::SPRCharge +
  1419.           @charge.id.to_s
  1420.       # get frame animation data
  1421.       data = BlizzABS::Items.charge_frames(@charge.id)
  1422.     end
  1423.     # set spriteset name
  1424.     @character_name = @character_name_org + @current_sprite
  1425.     # setup frames
  1426.     setup_frames(data)
  1427.   end
  1428.   #----------------------------------------------------------------------------
  1429.   # reset_sprites
  1430.   #  Resets sprite combination names.
  1431.   #----------------------------------------------------------------------------
  1432.   def reset_sprites
  1433.     # reset spriteset name
  1434.     @character_name = @character_name_org
  1435.     # reset spriteset name add-on
  1436.     @current_sprite = @weapon_sprite = ''
  1437.     # reset frane data
  1438.     setup_frames(BlizzABS::Cache::FramesDefault.clone)
  1439.   end
  1440.   #----------------------------------------------------------------------------
  1441.   # setup_frames
  1442.   #  data - frame animation timer data
  1443.   #  Sets up the basics used for charge sprite animation.
  1444.   #----------------------------------------------------------------------------
  1445.   def setup_frames(data)
  1446.     @sindex, @stime, @sframes = 0, data.sum, data
  1447.   end
  1448.   #----------------------------------------------------------------------------
  1449.   # attacked=
  1450.   #  val - number
  1451.   #  Sets the attacked counter and resets all sprites.
  1452.   #----------------------------------------------------------------------------
  1453.   def attacked=(val)
  1454.     # reset sprites
  1455.     @current_sprite = @weapon_sprite = ''
  1456.     # set attacked counter and reset sprite counter
  1457.     @attacked, @sindex = val, 0xFFFF
  1458.   end
  1459.   #----------------------------------------------------------------------------
  1460.   # moving?
  1461.   #  Determines if the character is moving.
  1462.   #----------------------------------------------------------------------------
  1463.   def moving?
  1464.     # get pixel movement rate
  1465.     pix = $BlizzABS.pixel
  1466.     # return if player is moving
  1467.     return (@real_x != @x * 128 / pix || @real_y != @y * 128 / pix)
  1468.   end
  1469.   #----------------------------------------------------------------------------
  1470.   # moveto
  1471.   #  x - x-coordinate
  1472.   #  y - y-coordinate
  1473.   #  Instant moving.
  1474.   #----------------------------------------------------------------------------
  1475.   def moveto(x, y)
  1476.     # get pixel movement rate
  1477.     pix = $BlizzABS.pixel
  1478.     # calculate new coordinates
  1479.     @x = (x * pix) % ($game_map.width * pix)
  1480.     @y = (y * pix) % ($game_map.height * pix)
  1481.     @real_x, @real_y = @x * 128 / pix, @y * 128 / pix
  1482.     # reset pre-lock direction
  1483.     @prelock_direction = 0
  1484.     return true
  1485.   end
  1486.   #--------------------------------------------------------------------------
  1487.   # move_direction
  1488.   #  d - direction
  1489.   #  Moves into x or y direction. (pixel movement)
  1490.   #--------------------------------------------------------------------------
  1491.   def move_direction(d)
  1492.     # x and y offsets depending on direction
  1493.     ox, oy = BlizzABS::Cache::DirOffsets[d]
  1494.     # if passable
  1495.     if passable?(@x, @y, d)
  1496.       # set new coordinates
  1497.       @x += ox
  1498.       @y += oy
  1499.       # increase steps
  1500.       increase_steps
  1501.       # moved
  1502.       return true
  1503.     end
  1504.     # check touched events
  1505.     check_event_trigger_touch(@x + ox, @y + oy)
  1506.     # not moved
  1507.     return false
  1508.   end
  1509.   #----------------------------------------------------------------------------
  1510.   # jump_passable?
  1511.   #  x  - x-coordinate
  1512.   #  y  - y-coordinate
  1513.   #  nx - new x-coordinate
  1514.   #  ny - new y-coordinate
  1515.   #  Checks if there is a tile with NO_JUMP_TAGS tag so jumping isn't possible.
  1516.   #----------------------------------------------------------------------------
  1517.   def jump_passable?(x, y, d)
  1518.     # impassable if new coordinates not valid
  1519.     return false unless $game_map.self_valid?(x, y)
  1520.     # passable if landing tile passable
  1521.     return ($game_map.self_passable?(x, y, 0, self))
  1522.   end
  1523.   #--------------------------------------------------------------------------
  1524.   # move_down
  1525.   #  turn_enabled - flag that determines whether to turn in moving direction
  1526.   #  Moves. (pixel movement)
  1527.   #--------------------------------------------------------------------------
  1528.   def move_down(turn_enabled = true)
  1529.     # turn if turn enabled
  1530.     turn_down if turn_enabled
  1531.     # move into direction
  1532.     return move_direction(2)
  1533.   end
  1534.   #--------------------------------------------------------------------------
  1535.   # move_left
  1536.   #  turn_enabled - flag that determines whether to turn in moving direction
  1537.   #  Moves. (pixel movement)
  1538.   #--------------------------------------------------------------------------
  1539.   def move_left(turn_enabled = true)
  1540.     # turn if turn enabled
  1541.     turn_left if turn_enabled
  1542.     # move into direction
  1543.     return move_direction(4)
  1544.   end
  1545.   #--------------------------------------------------------------------------
  1546.   # move_right
  1547.   #  turn_enabled - flag that determines whether to turn in moving direction
  1548.   #  Moves. (pixel movement)
  1549.   #--------------------------------------------------------------------------
  1550.   def move_right(turn_enabled = true)
  1551.     # turn if turn enabled
  1552.     turn_right if turn_enabled
  1553.     # move into direction
  1554.     return move_direction(6)
  1555.   end
  1556.   #--------------------------------------------------------------------------
  1557.   # move_up
  1558.   #  turn_enabled - flag that determines whether to turn in moving direction
  1559.   #  Moves. (pixel movement)
  1560.   #--------------------------------------------------------------------------
  1561.   def move_up(turn_enabled = true)
  1562.     # turn if turn enabled
  1563.     turn_up if turn_enabled
  1564.     # move into direction
  1565.     return move_direction(8)
  1566.   end
  1567.   #----------------------------------------------------------------------------
  1568.   # get_diagonal_movement_data
  1569.   #  dx - direction on x-axis
  1570.   #  dy - direction on y-axis
  1571.   #  Calculates whether diagional movement can be executed or not. If it can't
  1572.   #  be executed, an alternative traditional movement is calculated.
  1573.   #----------------------------------------------------------------------------
  1574.   def get_diagonal_movement_data(dx, dy)
  1575.     # get pixel movement and offsets depending on directions
  1576.     pix, ox, oy = $BlizzABS.pixel, (dx == 4 ? -1 : 1), (dy == 2 ? 1 : -1)
  1577.     # initialize and test first y direction
  1578.     move, x_move, y_move = false, false, passable?(@x, @y, dy)
  1579.     # if first y direction works
  1580.     if y_move
  1581.       # test second x direction
  1582.       other_x_move = passable?(@x, @y + oy, dx)
  1583.       # if pixel movement and second x direction works
  1584.       if pix > 1 && other_x_move
  1585.         # moving diagonally
  1586.         move = true
  1587.       # if pixel movement XOR second x direction
  1588.       elsif (pix > 1) != other_x_move
  1589.         # test first x direction
  1590.         x_move = passable?(@x, @y, dx)
  1591.         # if first x direction works
  1592.         if x_move
  1593.           # if second y direction works
  1594.           if passable?(@x + ox, @y, dy)
  1595.             # moving diagonally
  1596.             move = true
  1597.           else
  1598.             # moving into facing direction
  1599.             case @direction
  1600.             when dx, 10 - dx then x_move = false
  1601.             when dy, 10 - dy then y_move = false
  1602.             end
  1603.           end
  1604.         end
  1605.       # if facing in x direction
  1606.       elsif @direction != dx && @direction != 10 - dx
  1607.         # test x direction
  1608.         x_move = passable?(@x, @y, dx)
  1609.         # moving in x direction if x direction works
  1610.         y_move = false if x_move
  1611.       end
  1612.     else
  1613.       # test x direction
  1614.       x_move = passable?(@x, @y, dx)
  1615.       # moving diagonally if pixel movement and other direction works
  1616.       move = true if pix > 1 && x_move && passable?(@x + ox, @y, dy)
  1617.     end
  1618.     # result
  1619.     return [move, x_move, y_move]
  1620.   end
  1621.   #----------------------------------------------------------------------------
  1622.   # move_diagonal
  1623.   #  dx - x direction
  1624.   #  dy - y direction
  1625.   #  Moves diagonally, this method is generic. (pixel movement)
  1626.   #----------------------------------------------------------------------------
  1627.   def move_diagonal(dx, dy)
  1628.     # get offsets depending on directions
  1629.     ox, oy = (dx == 4 ? -1 : 1), (dy == 2 ? 1 : -1)
  1630.     # get flags for movement
  1631.     move, x_move, y_move = get_diagonal_movement_data(dx, dy)
  1632.     # if not direction fixed
  1633.     unless @direction_fix
  1634.       # if moving diagonal
  1635.       if move
  1636.         # set direction
  1637.         @direction = (@direction == 10 - dx ? dx : @direction == 10 - dy ? dy :
  1638.             @direction)
  1639.       # if moving left
  1640.       elsif x_move
  1641.         # set direction
  1642.         @direction = dx
  1643.       # if moving down
  1644.       elsif y_move
  1645.         # set direction
  1646.         @direction = dy
  1647.       end
  1648.     end
  1649.     # if any movement applies
  1650.     if move || x_move || y_move
  1651.       # set new coordinates if appropriate movement
  1652.       @x += ox if move || x_move
  1653.       @y += oy if move || y_move
  1654.       # increase steps
  1655.       increase_steps
  1656.       # moved
  1657.       return true
  1658.     end
  1659.     # check touched events
  1660.     check_event_trigger_touch(@x + ox, @y + oy)
  1661.     # not moved
  1662.     return false
  1663.   end
  1664.   #----------------------------------------------------------------------------
  1665.   # move_lower_left
  1666.   #  Moves. (pixel movement)
  1667.   #----------------------------------------------------------------------------
  1668.   def move_lower_left
  1669.     return move_diagonal(4, 2)
  1670.   end
  1671.   #----------------------------------------------------------------------------
  1672.   # move_lower_right
  1673.   #  Moves. (pixel movement)
  1674.   #----------------------------------------------------------------------------
  1675.   def move_lower_right
  1676.     return move_diagonal(6, 2)
  1677.   end
  1678.   #----------------------------------------------------------------------------
  1679.   # move_upper_left
  1680.   #  Moves. (pixel movement)
  1681.   #----------------------------------------------------------------------------
  1682.   def move_upper_left
  1683.     return move_diagonal(4, 8)
  1684.   end
  1685.   #----------------------------------------------------------------------------
  1686.   # move_upper_right
  1687.   #  Moves. (pixel movement)
  1688.   #----------------------------------------------------------------------------
  1689.   def move_upper_right
  1690.     return move_diagonal(6, 8)
  1691.   end
  1692.   #----------------------------------------------------------------------------
  1693.   # move_toward
  1694.   #  character    - the character
  1695.   #  turn_enabled - whether the character should turn or not
  1696.   #  Moves towards a character. (pixel movement)
  1697.   #----------------------------------------------------------------------------
  1698.   def move_toward(character, turn_enabled = true)
  1699.     # set movement route depending on the x and y differences
  1700.     dir = $BlizzABS.util.get_direction(@x - character.x, @y - character.y)
  1701.     # if not on top of target add move command
  1702.     if dir != 0
  1703.       @force_move.push((turn_enabled ? BlizzABS::Cache::TDirs :
  1704.           BlizzABS::Cache::FDirs)[dir])
  1705.     end
  1706.   end
  1707.   #----------------------------------------------------------------------------
  1708.   # move_away_from
  1709.   #  character    - the character
  1710.   #  turn_enabled - whether the character should turn or not
  1711.   #  Moves away from a character. (pixel movement)
  1712.   #----------------------------------------------------------------------------
  1713.   def move_away_from(character, turn_enabled = true)
  1714.     # set movement route depending on the x and y differences
  1715.     dir = $BlizzABS.util.get_direction(@x - character.x, @y - character.y)
  1716.     # if not on top of target add move command
  1717.     if dir != 0
  1718.       @force_move.push((turn_enabled ? BlizzABS::Cache::TDirs :
  1719.           BlizzABS::Cache::FDirs)[10 - dir])
  1720.     end
  1721.   end
  1722.   #----------------------------------------------------------------------------
  1723.   # move_away_random
  1724.   #  character    - the character
  1725.   #  turn_enabled - whether the character should turn or not
  1726.   #  distance     - distance
  1727.   #  Moves away from a character randomly. (pixel movement)
  1728.   #----------------------------------------------------------------------------
  1729.   def move_away_random(character, turn_enabled = true, distance = 1)
  1730.     # calculate differences in x and y
  1731.     dx, dy = @real_x - character.real_x, @real_y - character.real_y
  1732.     # array of directions
  1733.     dir = ($game_system._8_way ? BlizzABS::Cache::Dir8 : BlizzABS::Cache::Dir4)
  1734.     # determines where can't move according to the x and y differences
  1735.     if dx > 0 && dy > 0 # character is up left
  1736.       dir = dir - BlizzABS::Cache::NoDirsUpLeft
  1737.     elsif dx > 0 && dy < 0 # character is down left
  1738.       dir = dir - BlizzABS::Cache::NoDirsDownLeft
  1739.     elsif dx < 0 && dy > 0 # character is up right
  1740.       dir = dir - BlizzABS::Cache::NoDirsUpRight
  1741.     elsif dx < 0 && dy < 0 # character is down right
  1742.       dir = dir - BlizzABS::Cache::NoDirsDownRight
  1743.     elsif dx < 0 && dy == 0 # character is right
  1744.       dir = dir - BlizzABS::Cache::NoDirsRight
  1745.     elsif dx > 0 && dy == 0 # character is left
  1746.       dir = dir - BlizzABS::Cache::NoDirsLeft
  1747.     elsif dx == 0 && dy < 0 # character is down
  1748.       dir = dir - BlizzABS::Cache::NoDirsDown
  1749.     elsif dx == 0 && dy > 0 # character is up
  1750.       dir = dir - BlizzABS::Cache::NoDirsUp
  1751.     end
  1752.     # get necessary data
  1753.     pix, dir = $BlizzABS.pixel, dir[rand(dir.size)]
  1754.     distance *= pix
  1755.     # if turn enabled
  1756.     if turn_enabled
  1757.       # add to movement commands
  1758.       distance.to_i.times {@force_move.push(BlizzABS::Cache::TDirs[dir])}
  1759.     else
  1760.       # add to movement commands
  1761.       distance.to_i.times {@force_move.push(BlizzABS::Cache::FDirs[dir])}
  1762.     end
  1763.   end
  1764.   #----------------------------------------------------------------------------
  1765.   # overriding move_type_custom
  1766.   #----------------------------------------------------------------------------
  1767.   alias move_type_custom_blizzabs_later move_type_custom
  1768.   def move_type_custom
  1769.     # store current index and list
  1770.     index, list = @move_route_index, @move_route.list.clone
  1771.     # call original method
  1772.     move_type_custom_blizzabs_later
  1773.     # abort if not move route defined
  1774.     return if @move_route == nil && list.size == 0
  1775.     # create execution range
  1776.     if @move_route_index < index && @move_route_index < list.size-1
  1777.       range = index..@move_route_index
  1778.     else
  1779.       range = index..(list.size-1)
  1780.     end
  1781.     # set new normal speed if speed changing command
  1782.     @normal_speed = @move_speed if range.any? {|i| list[i] != nil && list[i].code == 29}
  1783.     # if enemy
  1784.     if self.is_a?(Map_Enemy)
  1785.       # if spriteset changing command
  1786.       @character_name_org = @character_name if range.any? {|i| list[i].code == 41}
  1787.       # exit method if jumping or moving
  1788.       return if jumping? || moving?
  1789.       # if move route exists, basic movement, not skippable and same index
  1790.       if index == @move_route_index && index < list.size &&
  1791.           list[index].code <= 14 && !@move_route.skippable
  1792.         # increase move_route_index
  1793.         @move_route_index += 1
  1794.       end
  1795.     end
  1796.   end
  1797.   #----------------------------------------------------------------------------
  1798.   # update_move
  1799.   #  Processes moving progress. (pixel movement)
  1800.   #----------------------------------------------------------------------------
  1801.   def update_move
  1802.     # get pixel movement rate and moving distance
  1803.     pix, distance = $BlizzABS.pixel, 2 ** @move_speed
  1804.     fx, fy = @x * 128 / pix, @y * 128 / pix
  1805.     # set new coordinates
  1806.     if fx < @real_x
  1807.       rx = @real_x - distance
  1808.       @real_x = (rx > fx ? rx : fx)
  1809.     elsif fx > @real_x
  1810.       rx = @real_x + distance
  1811.       @real_x = (rx < fx ? rx : fx)
  1812.     end
  1813.     if fy < @real_y
  1814.       ry = @real_y - distance
  1815.       @real_y = (ry > fy ? ry : fy)
  1816.     elsif fy > @real_y
  1817.       ry = @real_y + distance
  1818.       @real_y = (ry < fy ? ry : fy)
  1819.     end
  1820.     # if walking
  1821.     if @walk_anime
  1822.       # increase anime_count
  1823.       @anime_count += 1.5
  1824.     # if standing
  1825.     elsif @step_anime
  1826.       # increase anime_count
  1827.       @anime_count += 1
  1828.     end
  1829.   end
  1830.   #----------------------------------------------------------------------------
  1831.   # update_jump
  1832.   #  Processes jumping progress. (pixel movement)
  1833.   #----------------------------------------------------------------------------
  1834.   def update_jump
  1835.     # get pixel movement rate
  1836.     pix = $BlizzABS.pixel
  1837.     # decrease jump count
  1838.     @jump_count -= 1
  1839.     # set new coordinates
  1840.     @real_x = (@real_x * @jump_count + @x * 128 / pix) / (@jump_count + 1)
  1841.     @real_y = (@real_y * @jump_count + @y * 128 / pix) / (@jump_count + 1)
  1842.   end
  1843.   #----------------------------------------------------------------------------
  1844.   # ignored_jump_coordinates
  1845.   #  Returns the correct real_x and real_y without the jumping offset. It is
  1846.   #  being used to ignore jumping distance between allies to prevent separation
  1847.   #  from the caterpillar.
  1848.   #----------------------------------------------------------------------------
  1849.   def ignored_jump_coordinates
  1850.     # get pixel movement rate
  1851.     pix = $BlizzABS.pixel
  1852.     # calculate coordinates back
  1853.     real_x = (@real_x * (@jump_count + 1) - @x * 128 / pix) / @jump_count
  1854.     real_y = (@real_y * (@jump_count + 1) - @y * 128 / pix) / @jump_count
  1855.     # return the result
  1856.     return [real_x, real_y]
  1857.   end
  1858.   #----------------------------------------------------------------------------
  1859.   # jump
  1860.   #  x - x-coordinate
  1861.   #  y - y-coordinate
  1862.   #  Jumps. (pixel movement)
  1863.   #----------------------------------------------------------------------------
  1864.   def jump(x_plus, y_plus, d = nil)
  1865.     # get pixel movement rate
  1866.     pix = $BlizzABS.pixel
  1867.     # if jumping onto another tile
  1868.     if x_plus != 0 or y_plus != 0
  1869.       # if horizontal distance is longer
  1870.       if x_plus.abs > y_plus.abs
  1871.         # turn left or right
  1872.         x_plus < 0 ? turn_left : turn_right
  1873.       else
  1874.         # turn up or down
  1875.         y_plus < 0 ? turn_up : turn_down
  1876.       end
  1877.     end
  1878.     # if direction unknown
  1879.     if d == nil
  1880.       # determine direction depending plus values
  1881.       if x_plus > 0 && y_plus > 0 # jumping down right
  1882.         d = 3
  1883.       elsif x_plus > 0 && y_plus < 0 # jumping up left
  1884.         d = 9
  1885.       elsif x_plus < 0 && y_plus > 0 # jumping down right
  1886.         d = 1
  1887.       elsif x_plus < 0 && y_plus < 0 # jumping up left
  1888.         d = 7
  1889.       elsif x_plus < 0 && y_plus == 0 # jumping left
  1890.         d = 4
  1891.       elsif x_plus > 0 && y_plus == 0 # jumping right
  1892.         d = 6
  1893.       elsif x_plus == 0 && y_plus < 0 # jumping up
  1894.         d = 8
  1895.       elsif x_plus == 0 && y_plus > 0 # jumping down
  1896.         d = 2
  1897.       end
  1898.     end
  1899.     # straighten
  1900.     straighten
  1901.     # find new coordinates
  1902.     nx, ny = @x + x_plus * pix, @y + y_plus * pix
  1903.     # if can't jump to new location
  1904.     if jump_passable?(nx, ny, d) && $game_map.jump_passable?(@x, @y, nx, ny)
  1905.       # set new coordinates
  1906.       @x, @y = nx, ny
  1907.     else
  1908.       # reset coordinates
  1909.       x_plus = y_plus = 0
  1910.     end
  1911.     # set jump peak
  1912.     @jump_peak = 10 + Math.hypot(x_plus, y_plus).round - @move_speed
  1913.     # set jump count and stop count
  1914.     @jump_count, @stop_count = @jump_peak * 2, 0
  1915.     # jumped if x and y plus are 0
  1916.     return (x_plus != 0 || y_plus != 0)
  1917.   end
  1918.   #----------------------------------------------------------------------------
  1919.   # passable?
  1920.   #  x - x-coordinate
  1921.   #  y - y-coordinate
  1922.   #  d - direction
  1923.   #  Checks the passability. (pixel movement)
  1924.   #----------------------------------------------------------------------------
  1925.   def passable?(x, y, d)
  1926.     # calculate new coordinates
  1927.     nx = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  1928.     ny = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  1929.     # impassable if standing on impassable tile
  1930.     return false unless $game_map.self_passable?(x, y, d, self)
  1931.     # get pixel movement rate
  1932.     pix = $BlizzABS.pixel
  1933.     # if impassable in all directions
  1934.     unless $game_map.direction_passable?(nx, ny, 10 - d) &&
  1935.         $game_map.direction_passable?(nx, ny+pix-1, 10 - d) &&
  1936.         $game_map.direction_passable?(nx+pix-1, ny, 10 - d) &&
  1937.         $game_map.direction_passable?(nx+pix-1, ny+pix-1, 10 - d)
  1938.       # impassable
  1939.       return false
  1940.     end
  1941.     # new real coordinates
  1942.     rx, ry = nx * 128 / pix, ny * 128 / pix
  1943.     # get all events
  1944.     events = $game_map.events_only
  1945.     # rectangle
  1946.     rect = Rect.new(nx, ny, pix, pix)
  1947.     # if any event in the way
  1948.     if events.any? {|event|
  1949.         !event.through && event.character_name != '' &&
  1950.         $BlizzABS.util.rect_intersection(rect, event.phitbox)}
  1951.             #Rect.new(event.x * pix, event.y * pix, pix, pix))}
  1952.       # impassable
  1953.       return false
  1954.     end
  1955.     # if any battler that is not self or an event in the way
  1956.     if ($game_map.events.values - [self] - events).any? {|battler|
  1957.         !battler.through && battler.character_name != '' &&
  1958.         $BlizzABS.util.rect_intersection(rect, battler.phitbox)}
  1959.             #Rect.new(battler.x, battler.y, pix, pix))}
  1960.       # impassable
  1961.       return false
  1962.     end
  1963.     # passable so far
  1964.     return true
  1965.   end
  1966.   #----------------------------------------------------------------------------
  1967.   # bush_depth
  1968.   #  Checks the bush depth. (pixel movement)
  1969.   #----------------------------------------------------------------------------
  1970.   def bush_depth
  1971.     # if no tile and not jumping and not bush and not always on top
  1972.     if @jump_count == 0 && $game_map.pixel_bush?(@x, @y) &&
  1973.         @tile_id == 0 && !@always_on_top
  1974.       # return bush depth
  1975.       return 12
  1976.     end
  1977.     # no depth
  1978.     return 0
  1979.   end
  1980.   #----------------------------------------------------------------------------
  1981.   # terrain_tag
  1982.   #  Checks the terrain tag. (pixel movement)
  1983.   #----------------------------------------------------------------------------
  1984.   def terrain_tag
  1985.     # no terrain tag if in mid-air
  1986.     return 0 if jumping?
  1987.     # return terrain tag at the character's center
  1988.     return $game_map.terrain_tag((@real_x + 64) / 128, (@real_y + 64) / 128)
  1989.   end
  1990.   #----------------------------------------------------------------------------
  1991.   # in_action
  1992.   #  Overriding method needed for sprite animation.
  1993.   #----------------------------------------------------------------------------
  1994.   def in_action
  1995.     # if not in action and either sprite add-on or path requested
  1996.     if @in_action < 1 && ((@current_sprite != '' && !charging? &&
  1997.       !BlizzABS::SPRNoAction.include?(@current_sprite)) ||
  1998.       $BlizzABS.AI.path_requesting?(self))
  1999.       # in action
  2000.       return 1
  2001.     end
  2002.     # real in action
  2003.     return @in_action
  2004.   end
  2005.   #----------------------------------------------------------------------------
  2006.   # in_screen?
  2007.   #  Checks whether a battler is within the screen.
  2008.   #----------------------------------------------------------------------------
  2009.   def in_screen?
  2010.     return (((@real_x - $game_map.display_x - 64) / 4).between?(0, 640) &&
  2011.             ((@real_y - $game_map.display_y - 64) / 4).between?(0, 480))
  2012.   end
  2013.   #----------------------------------------------------------------------------
  2014.   # running?
  2015.   #  Dummy method.
  2016.   #----------------------------------------------------------------------------
  2017.   def running?
  2018.     return false
  2019.   end
  2020.   #----------------------------------------------------------------------------
  2021.   # sneaking?
  2022.   #  Dummy method.
  2023.   #----------------------------------------------------------------------------
  2024.   def sneaking?
  2025.     return false
  2026.   end
  2027.   #----------------------------------------------------------------------------
  2028.   # idle?
  2029.   #  Checks whether the character is idle on the map.
  2030.   #----------------------------------------------------------------------------
  2031.   def idle?
  2032.     return (@current_sprite == '' && !moving? && !jumping? && self.valid? &&
  2033.         self.in_action == 0 && self.restriction < 3 && !charging? &&
  2034.         !freeze_action && (@step_anime || self.pattern == @original_pattern))
  2035.   end
  2036.  
  2037. end
  2038.  
  2039. #==============================================================================
  2040. # Map_Actor
  2041. #------------------------------------------------------------------------------
  2042. #  This class serves as character class for any actor on the map.
  2043. #  Controller controls that instance of this class which has the first party
  2044. #  member as battler.
  2045. #==============================================================================
  2046.  
  2047. class Map_Actor < Map_Battler
  2048.  
  2049.   # setting all accessible variables
  2050.   attr_accessor :cindex
  2051.   attr_accessor :buffer
  2052.   attr_accessor :move_speed
  2053.   attr_reader   :blinking
  2054.   #----------------------------------------------------------------------------
  2055.   # Initialization
  2056.   #----------------------------------------------------------------------------
  2057.   def initialize(index)
  2058.     # call superclass method
  2059.     super()
  2060.     # store battler
  2061.     @battler = $game_party.actors[index]
  2062.     # set blinking counter
  2063.     @blinking = 0
  2064.     # save index in caterpillar
  2065.     @cindex = index
  2066.     # enforce the next force_movement from the buffer
  2067.     @force_movement = 0
  2068.     # create actor AI data pack
  2069.     @ai = BlizzABS::AI::Data_Actor.new(self)
  2070.     # set initial normal speed
  2071.     @normal_speed = BlizzABS::Config::NORMAL_SPEED
  2072.   end
  2073.   #----------------------------------------------------------------------------
  2074.   # update?
  2075.   #  Checks if caterpillar is active.
  2076.   #----------------------------------------------------------------------------
  2077.   def update?
  2078.     return ($game_system.caterpillar_active || in_abseal_range?)
  2079.   end
  2080.   #----------------------------------------------------------------------------
  2081.   # update
  2082.   #  Processes all the data.
  2083.   #----------------------------------------------------------------------------
  2084.   def update
  2085.     # check special state effects
  2086.     update_states
  2087.     # if this character is being controlled by the player
  2088.     if self == $game_player
  2089.       # always reset alignment group if the alignment was altered for player
  2090.       @ai.setup_group(@ai.group) if @ai.altered_alignment
  2091.       # determine if path requesting
  2092.       if @path_target_x == nil
  2093.         # no force move like the other battlers
  2094.         @force_move = []
  2095.         # always idle AI state
  2096.         @ai.state = BlizzABS::AI::Return
  2097.       else
  2098.         # if no current move route
  2099.         if @force_move == []
  2100.           # request path to target
  2101.           $BlizzABS.AI.request_path(self, @path_target_x, @path_target_y)
  2102.         end
  2103.         # set waiting state
  2104.         @ai.state = BlizzABS::AI::Request
  2105.         # update forcemove
  2106.         update_forcemove if !moving?
  2107.         # stop if reached target
  2108.         if [x, y] == $BlizzABS.AI.path_requesting_parameters(@path_target_x,
  2109.            @path_target_y) || $BlizzABS.player.cancel_path_request?
  2110.            @path_target_x = nil
  2111.            @path_target_y = nil
  2112.            @force_move = []
  2113.            @ai.state = BlizzABS::AI::Return
  2114.         end
  2115.       end
  2116.       # update player control over this character
  2117.       result = $BlizzABS.player.update_control
  2118.       # update stop animation display
  2119.       update_step_anime
  2120.       # call superclass method
  2121.       super
  2122.       # call post update process
  2123.       $BlizzABS.player.update_moving(result)
  2124.       # if battler valid and dead
  2125.       if self.valid? && battler.dead?
  2126.         # set blendtype to "ghost"
  2127.         @blend_type = 1
  2128.         # make a ghost animation using opacity
  2129.         @opacity = 64 + 192 * (Graphics.frame_count % 4 / 2).abs
  2130.         # unfreeze action
  2131.         @freeze_action = false
  2132.         # reset action data
  2133.         self.reset_action
  2134.         # not attacked and not in action
  2135.         @attacked = @in_action = 0
  2136.       else
  2137.         # set blendtype to normal
  2138.         @blend_type = 0
  2139.       end
  2140.       # exit method
  2141.       return
  2142.     end
  2143.     # update pixel movement rate
  2144.     update_pixel_rate
  2145.     # stop if no update necessary
  2146.     return if !update?
  2147.     # reset spriteset name
  2148.     @character_name = @character_name_org
  2149.     # update spriteset animation
  2150.     sprite_animation_setup
  2151.     # if battler exists
  2152.     if valid?
  2153.       # if battler is dead
  2154.       if battler.dead?
  2155.         # stop if summoned
  2156.         return if $BlizzABS.summoned?(self)
  2157.         # make a ghost animation using opacity
  2158.         @opacity = 64 + 192 * (Graphics.frame_count % 4 / 2).abs
  2159.         # unfreeze action
  2160.         @freeze_action = false
  2161.         # reset action data
  2162.         self.reset_action
  2163.         # not attacked and not in action
  2164.         @attacked = @in_action = 0
  2165.       end
  2166.       # updates any attack action
  2167.       update_attacked
  2168.     end
  2169.     # transparent flag inheritance from player
  2170.     @transparent = $game_player.transparent
  2171.     # through flag inheritance from player
  2172.     @through = $game_player.through
  2173.     # set blendtype to "ghost" if dead, otherwise to normal
  2174.     @blend_type = (valid? && battler.dead? ? 1 : 0)
  2175.     # if battler is not valid or dead or ABS disabled
  2176.     if !valid? || battler.dead? || !$game_temp.in_battle
  2177.       # if not in caterpillar
  2178.       if @cindex == nil
  2179.         # set to return state
  2180.         @ai.state = BlizzABS::AI::Return
  2181.       else
  2182.         # set to idle state
  2183.         @ai.state = BlizzABS::AI::Idle
  2184.       end
  2185.       # check state and decide further processing
  2186.       case @ai.state
  2187.       when BlizzABS::AI::Idle then update_in_caterpillar
  2188.       when BlizzABS::AI::Return then update_out_caterpillar
  2189.       end
  2190.       # call superclass method
  2191.       super
  2192.       # update stop animation display
  2193.       update_step_anime
  2194.       # exit method
  2195.       return
  2196.     end
  2197.     # if event is being executed
  2198.     if $game_system.map_interpreter.running?
  2199.       # check state and decide further processing
  2200.       case @ai.state
  2201.       when BlizzABS::AI::Idle then update_in_caterpillar
  2202.       when BlizzABS::AI::Return then update_out_caterpillar
  2203.       else
  2204.         # move normally if not already moving
  2205.         update_forcemove if !moving?
  2206.       end
  2207.       # update the event with the superclass method
  2208.       super
  2209.       # update stop animation display
  2210.       update_step_anime
  2211.       # exit method
  2212.       return
  2213.     end
  2214.     # AI update phase 1 (pre-phase)
  2215.     $BlizzABS.AI.prepare(self)
  2216.     # if can't act now
  2217.     if !can_act?
  2218.       # update action
  2219.       update_action
  2220.       # call superclass method
  2221.       super
  2222.       # update stop animation display
  2223.       update_step_anime
  2224.       # exit method
  2225.       return
  2226.     end
  2227.     # update AI controlled behavior
  2228.     update_behavior
  2229.     # get pixel move rate
  2230.     pix = $BlizzABS.pixel
  2231.     # if battler doesn't exist or dead
  2232.     if @ai.target != nil && (!@ai.target.valid? || !@ai.target.in_screen? ||
  2233.         Math.hypot(self.x / pix - @ai.target.x / pix,
  2234.             self.y / pix - @ai.target.y / pix) >
  2235.                 $BlizzABS.util.get_player_radius * @ai.aggressive / 15)
  2236.       # reset movement
  2237.       @force_move = []
  2238.       # reset action
  2239.       self.reset_action
  2240.       # if not in catepillar already
  2241.       if @cindex == nil
  2242.         # return to caterpillar
  2243.         @ai.state = BlizzABS::AI::Return
  2244.       else
  2245.         # idle state
  2246.         @ai.state = BlizzABS::AI::Idle
  2247.       end
  2248.     end
  2249.     # set to return if abort requested
  2250.     return if @ai.state == BlizzABS::AI::Abort
  2251.     # check state and decide further processing
  2252.     case @ai.state
  2253.     when BlizzABS::AI::Idle then update_in_caterpillar
  2254.     when BlizzABS::AI::Return then update_out_caterpillar
  2255.     else
  2256.       #p 2
  2257.       # move normally if not already moving
  2258.       update_forcemove if !moving?
  2259.     end
  2260.     # call superclass method
  2261.     super
  2262.   end
  2263.   #----------------------------------------------------------------------------
  2264.   # update_step_anime
  2265.   #  Updates stop animation display.
  2266.   #----------------------------------------------------------------------------
  2267.   def update_step_anime
  2268.     # if player's character is animated
  2269.     if BlizzABS::Config::ANIMATED_IDS.include?(battler_id)
  2270.       # set stopped animation flag
  2271.       @step_anime = true
  2272.     else
  2273.       # set stopped animation flag to defending
  2274.       @step_anime = @ai.act.defend?
  2275.     end
  2276.   end
  2277.   #----------------------------------------------------------------------------
  2278.   # update_ai
  2279.   #  Updates AI specific behavior.
  2280.   #----------------------------------------------------------------------------
  2281.   def update_ai
  2282.     # AI update phase 2 (perception)
  2283.     $BlizzABS.AI.perception(self, (@force_move.size == 0))
  2284.     # if doing nothing, not force-moving and no target exists
  2285.     if self.in_action == 0 && @ai.state != BlizzABS::AI::Knockback &&
  2286.         (@ai.target == nil || !@ai.target.valid?)
  2287.       # AI update phase 3 (decide action)
  2288.       $BlizzABS.AI.decide_action(self)
  2289.     end
  2290.   end
  2291.   #----------------------------------------------------------------------------
  2292.   # update_action
  2293.   #  Updates the action to be executed.
  2294.   #----------------------------------------------------------------------------
  2295.   def update_action
  2296.     # decrease AI delay count
  2297.     @ai.act.delay -= 1
  2298.     # stop if no action exists
  2299.     return if !@ai.act.valid?
  2300.     # if not controller by player
  2301.     if self != $game_player
  2302.       # if in caterpillar
  2303.       if @cindex != nil
  2304.         # remove from caterpillar
  2305.         remove_from_caterpillar
  2306.         # set state to be ready
  2307.         @ai.state = BlizzABS::AI::Ready
  2308.       end
  2309.       # projectile evasion processing if defensive enough
  2310.       $BlizzABS.AI.evade_projectiles(self) if rand(200) < 10 - @ai.offensive
  2311.     end
  2312.     # if defending and counter expired
  2313.     if @ai.act.defend? && @ai.act.ready?
  2314.       # reset action
  2315.       self.reset_action
  2316.       # reset sprites
  2317.       self.reset_sprites
  2318.     end
  2319.   end
  2320.   #----------------------------------------------------------------------------
  2321.   # setup_move
  2322.   #  Sets up the forced movement if it is needed.
  2323.   #----------------------------------------------------------------------------
  2324.   def setup_move
  2325.     # if allowed to change speed
  2326.     if @ai.state != BlizzABS::AI::MoveOnly
  2327.       # if return state and in caterpillar
  2328.       if @ai.state == BlizzABS::AI::Return && @cindex != nil
  2329.         # set to idle state
  2330.         @ai.state = BlizzABS::AI::Idle
  2331.       end
  2332.       # reset moving speed
  2333.       @move_speed = @normal_speed
  2334.       # increase moving speed if knockback
  2335.       @move_speed += 1 if @ai.state == BlizzABS::AI::Knockback
  2336.     # if in caterpillar
  2337.     elsif @cindex != nil
  2338.       # set to idle state
  2339.       @ai.state = BlizzABS::AI::Idle
  2340.     end
  2341.   end
  2342.   #----------------------------------------------------------------------------
  2343.   # update_forcemove
  2344.   #  move - the move to execute
  2345.   #  Updates movement.
  2346.   #----------------------------------------------------------------------------
  2347.   def update_forcemove(move = nil)
  2348.     # if moving commands exist
  2349.     move = @force_move.shift if move == nil && @force_move.size > 0
  2350.     # stop if no move
  2351.     return if move == nil
  2352.     # move
  2353.     case move[0]
  2354.     when 1 then move_lower_left
  2355.     when 2 then move_down(move[1])
  2356.     when 3 then move_lower_right
  2357.     when 4 then move_left(move[1])
  2358.     when 6 then move_right(move[1])
  2359.     when 7 then move_upper_left
  2360.     when 8 then move_up(move[1])
  2361.     when 9 then move_upper_right
  2362.     when false
  2363.       # remove from caterpillar
  2364.       remove_from_caterpillar if @cindex != nil
  2365.       # reset force counter
  2366.       @force_movement = 0
  2367.     end
  2368.   end
  2369.   #----------------------------------------------------------------------------
  2370.   # update_pixel_rate
  2371.   #  Updates the pixel movement rate if necessary.
  2372.   #----------------------------------------------------------------------------
  2373.   def update_pixel_rate
  2374.     # stop if pixel movement rate is not different than the stored one
  2375.     return if @pixel_rate == $game_system.pixel_rate
  2376.     # store old buffer and clear buffer
  2377.     tmp, @force_move = @force_move, []
  2378.     # while there is still data in the old buffer
  2379.     while tmp.size > 0
  2380.       # if normal command
  2381.       if tmp[0][1] == true || tmp[0][1] == false
  2382.         # get current command
  2383.         move = tmp.shift
  2384.         # remove the rest of the commands depending on old pixel movement
  2385.         (2 ** @pixel_rate - 1).times {tmp.shift}
  2386.         # add into new buffer depending on new pixel movement
  2387.         (2 ** $game_system.pixel_rate).times {@force_move.push(move)}
  2388.       else
  2389.         # directly add into new buffer
  2390.         @force_move.push(tmp.shift)
  2391.       end
  2392.     end
  2393.   end
  2394.   #----------------------------------------------------------------------------
  2395.   # update_in_caterpillar
  2396.   #  Updates movement within caterpillar.
  2397.   #----------------------------------------------------------------------------
  2398.   def update_in_caterpillar
  2399.     # reset alignment group if the alignment was altered
  2400.     @ai.setup_group(@ai.group) if @ai.altered_alignment
  2401.     # get poxel movement
  2402.     pix = $BlizzABS.pixel
  2403.     # if far enough from the player or relative position doesn't fit movement
  2404.     if Math.hypot(@real_x - $game_player.real_x,
  2405.         @real_y - $game_player.real_y) > (@cindex + 2) * 128 ||
  2406.         @force_move.size < calc_movement.size && @force_movement == 0
  2407.       # remove from caterpillar
  2408.       remove_from_caterpillar
  2409.     else
  2410.       # set speed to the player's move speed
  2411.       @move_speed = $game_player.move_speed
  2412.       # if not moving and buffer not empty and either forced or buffer full
  2413.       if !moving? && @force_move.size > 0 &&
  2414.           (@force_move.size > @cindex * pix || @force_movement > 0)
  2415.         # get next command
  2416.         move = @force_move.shift
  2417.         # if normal movement command
  2418.         if move[1] == true || move[1] == false
  2419.           # execute movement command
  2420.           update_forcemove(move)
  2421.         else
  2422.           # check command and decide jump direction
  2423.           x, y = BlizzABS::Cache::DirOffsets[move[0]]
  2424.           # get jumping range
  2425.           range = BlizzABS::Config::JUMPING
  2426.           # jump into direction with considering running/sneaking
  2427.           jump(x*range + x*move[1], y*range + y*move[1], move[0])
  2428.         end
  2429.         # decrease counter if counter is active
  2430.         @force_movement -= 1 if @force_movement > 0
  2431.       end
  2432.     end
  2433.   end
  2434.   #----------------------------------------------------------------------------
  2435.   # update_out_caterpillar
  2436.   #  Updates movement when separated from caterpillar.
  2437.   #----------------------------------------------------------------------------
  2438.   def update_out_caterpillar
  2439.     # get pixel movement and current index
  2440.     pix, ind, battlers = $BlizzABS.pixel, self.index, $BlizzABS.battlers
  2441.     # decrease ind for every an actor that is missing in the caterpillar
  2442.     (1...ind).each {|i| ind -= 1 if battlers[i].cindex == nil}
  2443.     # if not at correct position depending on player
  2444.     if (@x - $game_player.x).abs <= ind * pix &&
  2445.         (@y - $game_player.y).abs <= ind * pix
  2446.       # return to caterpillar if caterpillar is active
  2447.       return_to_caterpillar if $game_system.caterpillar_active
  2448.     # if still movement commands exist
  2449.     elsif @force_move.size > 0
  2450.       # execute movement command if not already moving
  2451.       update_forcemove if !moving?
  2452.     # if caterpillas is active
  2453.     elsif $game_system.caterpillar_active
  2454.       # request path to party leader
  2455.       $BlizzABS.AI.request_path(self, $game_player)
  2456.       # set waiting state
  2457.       @ai.state = BlizzABS::AI::Request
  2458.     end
  2459.   end
  2460.   #----------------------------------------------------------------------------
  2461.   # calc_movement
  2462.   #  Calculates a movement pattern to the player's current position when
  2463.   #  integrating back into the caterpillar, so this characeter doesn't need to
  2464.   #  go to the player's position or a reserved position, but can stay as far as
  2465.   #  possible to give a more natural feeling.
  2466.   #----------------------------------------------------------------------------
  2467.   def calc_movement
  2468.     # initialize result
  2469.     result = []
  2470.     # get differences
  2471.     dx, dy = @x - $game_player.x, @y - $game_player.y
  2472.     # while differences exist
  2473.     while dx.abs > 0 || dy.abs > 0
  2474.       # add move command into direction to player
  2475.       if dx > 0 && dy > 0 # up left
  2476.         result.push(BlizzABS::Cache::TDirs[7])
  2477.       elsif dx > 0 && dy < 0 # down right
  2478.         result.push(BlizzABS::Cache::TDirs[1])
  2479.       elsif dx < 0 && dy > 0 # up right
  2480.         result.push(BlizzABS::Cache::TDirs[9])
  2481.       elsif dx < 0 && dy < 0 # down left
  2482.         result.push(BlizzABS::Cache::TDirs[3])
  2483.       elsif dx < 0 && dy == 0 # right
  2484.         result.push(BlizzABS::Cache::TDirs[6])
  2485.       elsif dx > 0 && dy == 0 # left
  2486.         result.push(BlizzABS::Cache::TDirs[4])
  2487.       elsif dx == 0 && dy < 0 # down
  2488.         result.push(BlizzABS::Cache::TDirs[2])
  2489.       elsif dx == 0 && dy > 0 # up
  2490.         result.push(BlizzABS::Cache::TDirs[8])
  2491.       end
  2492.       # decrease difference if there are differences
  2493.       dx -= dx.sgn if dx != 0
  2494.       dy -= dy.sgn if dy != 0
  2495.     end
  2496.     # return result
  2497.     return result
  2498.   end
  2499.   #----------------------------------------------------------------------------
  2500.   # battler
  2501.   #  override - allows obtaining the real battler value
  2502.   #  Allows disabling of the character if caterpillar is turned off.
  2503.   #----------------------------------------------------------------------------
  2504.   def battler(override = false)
  2505.     return (($game_system.caterpillar || self == $game_player || override) ?
  2506.         @battler : nil)
  2507.   end
  2508.   #----------------------------------------------------------------------------
  2509.   # skill_hotkeys
  2510.   #  Allows access of the item hotkeys.
  2511.   #----------------------------------------------------------------------------
  2512.   def skill_hotkeys
  2513.     return (battler == nil ? BlizzABS::Cache::HotKeys : battler.skill_hotkeys)
  2514.   end
  2515.   #----------------------------------------------------------------------------
  2516.   # item_hotkeys
  2517.   #  Allows access of the item hotkeys.
  2518.   #----------------------------------------------------------------------------
  2519.   def item_hotkeys
  2520.     return (battler == nil ? BlizzABS::Cache::HotKeys : battler.item_hotkeys)
  2521.   end
  2522.   #----------------------------------------------------------------------------
  2523.   # encounter_count
  2524.   #  Reroutes the battle-encounter countdown from the controller if being
  2525.   #  controlled by the player.
  2526.   #----------------------------------------------------------------------------
  2527.   def encounter_count
  2528.     return (self == $game_player ? $BlizzABS.player.encounter_count : 1)
  2529.   end
  2530.   #----------------------------------------------------------------------------
  2531.   # make_encounter_count
  2532.   #  Reroutes the battle-encounter countdown setup.
  2533.   #----------------------------------------------------------------------------
  2534.   def make_encounter_count
  2535.     # stop if map doesn't exist
  2536.     return if $game_map.map_id == 0
  2537.     # temporary variable
  2538.     n = $game_map.encounter_step * (2 ** (5 - $game_system.pixel_rate))
  2539.     # 2 hyperdices rolling
  2540.     $BlizzABS.player.encounter_count = (rand(n) + rand(n) + 1) *
  2541.         2 ** (5 - $game_system.pixel_rate)
  2542.   end
  2543.   #----------------------------------------------------------------------------
  2544.   # remove_from_caterpillar
  2545.   #  Procedure used at a couple of places in the script. To shorten the code
  2546.   #  the procedure was embedded into one method.
  2547.   #----------------------------------------------------------------------------
  2548.   def remove_from_caterpillar
  2549.     # disintegrate from caterpillar
  2550.     update_ci(nil)
  2551.     # empty movement buffer, set to return state
  2552.     @force_move, @ai.state = [], BlizzABS::AI::Return
  2553.     # if too slow
  2554.     if @move_speed < $game_player.normal_speed
  2555.       # set normal moving speed
  2556.       @move_speed = $game_player.normal_speed
  2557.     end
  2558.   end
  2559.   #----------------------------------------------------------------------------
  2560.   # return_to_caterpillar
  2561.   #  Integrates the map actor back into the caterpillar.
  2562.   #----------------------------------------------------------------------------
  2563.   def return_to_caterpillar
  2564.     # integrate back into caterpillar
  2565.     update_ci(self.index)
  2566.     # reset action
  2567.     self.reset_action
  2568.     # calculate movement buffer commands
  2569.     @force_move = calc_movement
  2570.     # reset force movement counter
  2571.     @force_movement = 0
  2572.     # idle state
  2573.     @ai.state = BlizzABS::AI::Idle
  2574.   end
  2575.   #----------------------------------------------------------------------------
  2576.   # update_ci
  2577.   #  index - new caterpillar index
  2578.   #  Integrates back into the caterpillar by setting up @cindex.
  2579.   #----------------------------------------------------------------------------
  2580.   def update_ci(ind = (@cindex == nil ? nil : self.index))
  2581.     # set new cindex
  2582.     @cindex = ind
  2583.     # get all battlers
  2584.     battlers = $BlizzABS.battlers
  2585.     # if index isn't removing from caterpillar
  2586.     if ind != nil
  2587.       # iterate through all actors in front of self
  2588.       (1...self.index).each {|i|
  2589.           # decrease cindex if missing in the caterpillar or no battler
  2590.           @cindex -= 1 if battlers[i].cindex == nil || battlers[i].battler == nil}
  2591.     end
  2592.     # update the @cindex of the actor behind if he exists
  2593.     battlers[self.index + 1].update_ci if battlers[self.index + 1] != nil
  2594.   end
  2595.   #----------------------------------------------------------------------------
  2596.   # update_buffer
  2597.   #  move - new command added into the buffer
  2598.   #  Handles the movement command delay system for caterpillar movement.
  2599.   #----------------------------------------------------------------------------
  2600.   def update_buffer(move)
  2601.     # exit if removed from caterpillar
  2602.     return if @cindex == nil
  2603.     # if enforce emptying buffer command
  2604.     if move == nil
  2605.       # set enforcement to the current buffer size
  2606.       @force_movement = @force_move.size
  2607.     # reintegrate into caterpillar
  2608.     elsif move == false
  2609.       # calculate movement buffer commands
  2610.       @force_move += calc_movement
  2611.     else
  2612.       # add new command into buffer
  2613.       @force_move.push(move)
  2614.       # if forced execution or command is jumping
  2615.       unless move[1] == true || move[1] == false
  2616.         # set enforcement to the current buffer size
  2617.         @force_movement = @force_move.size
  2618.       end
  2619.     end
  2620.   end
  2621.   #----------------------------------------------------------------------------
  2622.   # attack_penalty
  2623.   #  Returns the penalty for the weapon.
  2624.   #----------------------------------------------------------------------------
  2625.   def attack_penalty
  2626.     # get weapon penalty
  2627.     penalty = BlizzABS::Weapons.penalty(@battler.weapon_id)
  2628.     # limit is sum of all animation frames if using action sprites
  2629.     limit = (action_sprites? ? BlizzABS::Weapons.frames(@battler.weapon_id).sum : 0)
  2630.     # limit penalty
  2631.     return (penalty < limit ? limit : penalty)
  2632.   end
  2633.   #----------------------------------------------------------------------------
  2634.   # update_attacked
  2635.   #  Processes being attacked and blinking animation.
  2636.   #----------------------------------------------------------------------------
  2637.   def update_attacked
  2638.     # if blinking
  2639.     if @blinking > 0
  2640.       # set blink opacity
  2641.       @opacity = 128 + 128 * ((@blinking + 2) % 4 / 2).abs
  2642.       # decrease blinking counter
  2643.       @blinking -= 1
  2644.     # if not dead
  2645.     elsif valid? && !battler.dead?
  2646.       # full opacity
  2647.       @opacity = 255
  2648.     end
  2649.     # stop if not attacked
  2650.     return if @attacked == 0
  2651.     # decrease attacked counter
  2652.     @attacked -= 1
  2653.     # get thrown back
  2654.     move_backward
  2655.   end
  2656.   #----------------------------------------------------------------------------
  2657.   # action_sprites?
  2658.   #  Checks if action sprites can be used.
  2659.   #----------------------------------------------------------------------------
  2660.   def action_sprites?
  2661.     return BlizzABS::Config::A_ACTION_SPRITES
  2662.   end
  2663.   #----------------------------------------------------------------------------
  2664.   # weapon_sprites?
  2665.   #  Checks if weapon sprites can be used.
  2666.   #----------------------------------------------------------------------------
  2667.   def weapon_sprites?
  2668.     return BlizzABS::Config::A_WEAPON_SPRITES
  2669.   end
  2670.   #----------------------------------------------------------------------------
  2671.   # skill_sprites?
  2672.   #  Checks if skill sprites can be used.
  2673.   #----------------------------------------------------------------------------
  2674.   def skill_sprites?
  2675.     return BlizzABS::Config::A_SKILL_SPRITES
  2676.   end
  2677.   #----------------------------------------------------------------------------
  2678.   # item_sprites?
  2679.   #  Checks if item sprites can be used.
  2680.   #----------------------------------------------------------------------------
  2681.   def item_sprites?
  2682.     return BlizzABS::Config::A_ITEM_SPRITES
  2683.   end
  2684.   #----------------------------------------------------------------------------
  2685.   # jumping_sprites?
  2686.   #  Checks if jumping sprites can be used.
  2687.   #----------------------------------------------------------------------------
  2688.   def jumping_sprites?
  2689.     return BlizzABS::Config::JUMPING_SPRITES
  2690.   end
  2691.   #----------------------------------------------------------------------------
  2692.   # running_sprites?
  2693.   #  Checks if running sprites can be used.
  2694.   #----------------------------------------------------------------------------
  2695.   def running_sprites?
  2696.     return BlizzABS::Config::RUNNING_SPRITES
  2697.   end
  2698.   #----------------------------------------------------------------------------
  2699.   # sneaking_sprites?
  2700.   #  Checks if sneaking sprites can be used.
  2701.   #----------------------------------------------------------------------------
  2702.   def sneaking_sprites?
  2703.     return BlizzABS::Config::SNEAKING_SPRITES
  2704.   end
  2705.   #----------------------------------------------------------------------------
  2706.   # idle_sprites?
  2707.   #  Checks if idle sprites can be used.
  2708.   #----------------------------------------------------------------------------
  2709.   def idle_sprites?
  2710.     return BlizzABS::Config::A_IDLE_SPRITES
  2711.   end
  2712.   #----------------------------------------------------------------------------
  2713.   # charge_sprites?
  2714.   #  Checks if charge sprites can be used.
  2715.   #----------------------------------------------------------------------------
  2716.   def charge_sprites?
  2717.     return BlizzABS::Config::A_CHARGE_SPRITES
  2718.   end
  2719.   #----------------------------------------------------------------------------
  2720.   # charge_weapon_sprites?
  2721.   #  Checks if charge weapon sprites can be used.
  2722.   #----------------------------------------------------------------------------
  2723.   def charge_weapon_sprites?
  2724.     return BlizzABS::Config::A_CHARGE_WEAPON_SPRITES
  2725.   end
  2726.   #----------------------------------------------------------------------------
  2727.   # charge_skill_sprites?
  2728.   #  Checks if charge skill sprites can be used.
  2729.   #----------------------------------------------------------------------------
  2730.   def charge_skill_sprites?
  2731.     return BlizzABS::Config::A_CHARGE_SKILL_SPRITES
  2732.   end
  2733.   #----------------------------------------------------------------------------
  2734.   # charge_item_sprites?
  2735.   #  Checks if charge item sprites can be used.
  2736.   #----------------------------------------------------------------------------
  2737.   def charge_item_sprites?
  2738.     return BlizzABS::Config::A_CHARGE_ITEM_SPRITES
  2739.   end
  2740.   #----------------------------------------------------------------------------
  2741.   # setup_attack_sprites
  2742.   #  Sets up attack sprites and returns the frame animation data necessary.
  2743.   #----------------------------------------------------------------------------
  2744.   def setup_attack_sprites
  2745.     # get weapon type number
  2746.     type = BlizzABS::Weapons.type(self.battler.weapon_id)
  2747.     # add weapon type number to sprite extension
  2748.     @current_sprite += type.to_s
  2749.     # if weapon exists
  2750.     if self.battler.weapon_id > 0
  2751.       # if weapon sprites active
  2752.       if weapon_sprites?
  2753.         # set advanced weapon sprite name
  2754.         @weapon_sprite = BlizzABS::SPRWeaponID + self.battler.weapon_id.to_s
  2755.       else
  2756.         # set generic weapon sprite
  2757.         @weapon_sprite = BlizzABS::SPRWeapon + type.to_s
  2758.       end
  2759.     end
  2760.     # return frame animation data
  2761.     return BlizzABS::Weapons.frames(self.battler.weapon_id)
  2762.   end
  2763.   #----------------------------------------------------------------------------
  2764.   # setup_charge_attack_sprites
  2765.   #  Sets up charge attack sprites and returns the frame animation data
  2766.   #  necessary.
  2767.   #----------------------------------------------------------------------------
  2768.   def setup_charge_attack_sprites
  2769.     # spriteset name add-on
  2770.     @current_sprite = BlizzABS::SPRAttack + BlizzABS::SPRCharge +
  2771.         self.battler.weapon_id.to_s
  2772.     # return frame animation data
  2773.     return BlizzABS::Weapons.charge_frames(self.battler.weapon_id)
  2774.   end
  2775.   #----------------------------------------------------------------------------
  2776.   # use_defend
  2777.   #  Processes using a defending action.
  2778.   #----------------------------------------------------------------------------
  2779.   def use_defend
  2780.     # if defend sprites is active
  2781.     if BlizzABS::Config::A_DEFEND_SPRITES
  2782.       # setup special defend sprite
  2783.       setup_sprites(BlizzABS::SPRDefend + battler.armor1_id.to_s)
  2784.     else
  2785.       # call super class method
  2786.       super
  2787.     end
  2788.   end
  2789.   #----------------------------------------------------------------------------
  2790.   # refresh
  2791.   #  Refreshes the character.
  2792.   #----------------------------------------------------------------------------
  2793.   def refresh(flag = false)
  2794.     # refresh all actors if self is controlled by player and not calling again
  2795.     $BlizzABS.player.refresh if !flag && self == $game_player
  2796.     # if not valid
  2797.     if !valid?
  2798.       # set spriteset name
  2799.       @character_name_org = @character_name = ''
  2800.       # set spriteset hue
  2801.       @character_hue = 0
  2802.     else
  2803.       # set spriteset name
  2804.       @character_name_org = @character_name = battler.character_name
  2805.       # set spriteset hue
  2806.       @character_hue = battler.character_hue
  2807.       # set opacity to full and blend type to normal
  2808.       @opacity, @blend_type = 255, 0
  2809.     end
  2810.   end
  2811.   #----------------------------------------------------------------------------
  2812.   # jump_passable?
  2813.   #  x  - x-coordinate
  2814.   #  y  - y-coordinate
  2815.   #  nx - new x-coordinate
  2816.   #  ny - new y-coordinate
  2817.   #  Checks if there is a tile with NO_JUMP_TAGS tag so jumping isn't possible.
  2818.   #----------------------------------------------------------------------------
  2819.   def jump_passable?(x, y, d)
  2820.     # impassable if new coordinates not valid
  2821.     return false unless $game_map.self_valid?(x, y)
  2822.     # passable through or pressing CTRL in DEBUG mode
  2823.     return true if $DEBUG && Input.press?(Input::CTRL) || @through
  2824.     # passable if landing tile passable
  2825.     return ($game_map.self_passable?(x, y, 0, self))
  2826.   end
  2827.   #----------------------------------------------------------------------------
  2828.   # move_down
  2829.   #  turn_enabled - turning flag
  2830.   #  Moves. (pixel movement)
  2831.   #----------------------------------------------------------------------------
  2832.   def move_down(turn_enabled = true)
  2833.     # call superclass method and store result
  2834.     result = super
  2835.     # if self is controlled by player
  2836.     if self == $game_player && result
  2837.       # if turn enabled
  2838.       if turn_enabled
  2839.         # update buffer
  2840.         $BlizzABS.player.update_buffer(BlizzABS::Cache::TDirs[2])
  2841.       else
  2842.         # update buffer
  2843.         $BlizzABS.player.update_buffer(BlizzABS::Cache::FDirs[2])
  2844.       end
  2845.     end
  2846.     # return result
  2847.     return result
  2848.   end
  2849.   #----------------------------------------------------------------------------
  2850.   # move_left
  2851.   #  turn_enabled - turning flag
  2852.   #  Moves. (pixel movement)
  2853.   #----------------------------------------------------------------------------
  2854.   def move_left(turn_enabled = true)
  2855.     # call superclass method and store result
  2856.     result = super
  2857.     # if self is controlled by player
  2858.     if self == $game_player && result
  2859.       # if turn enabled
  2860.       if turn_enabled
  2861.         # update buffer
  2862.         $BlizzABS.player.update_buffer(BlizzABS::Cache::TDirs[4])
  2863.       else
  2864.         # update buffer
  2865.         $BlizzABS.player.update_buffer(BlizzABS::Cache::FDirs[4])
  2866.       end
  2867.     end
  2868.     # return result
  2869.     return result
  2870.   end
  2871.   #----------------------------------------------------------------------------
  2872.   # move_right
  2873.   #  turn_enabled - turning flag
  2874.   #  Moves. (pixel movement)
  2875.   #----------------------------------------------------------------------------
  2876.   def move_right(turn_enabled = true)
  2877.     # call superclass method and store result
  2878.     result = super
  2879.     # if self is controlled by player
  2880.     if self == $game_player && result
  2881.       # if turn enabled
  2882.       if turn_enabled
  2883.         # update buffer
  2884.         $BlizzABS.player.update_buffer(BlizzABS::Cache::TDirs[6])
  2885.       else
  2886.         # update buffer
  2887.         $BlizzABS.player.update_buffer(BlizzABS::Cache::FDirs[6])
  2888.       end
  2889.     end
  2890.     # return result
  2891.     return result
  2892.   end
  2893.   #----------------------------------------------------------------------------
  2894.   # move_up
  2895.   #  turn_enabled - turning flag
  2896.   #  Moves. (pixel movement)
  2897.   #----------------------------------------------------------------------------
  2898.   def move_up(turn_enabled = true)
  2899.     # call superclass method and store result
  2900.     result = super
  2901.     # if self is controlled by player
  2902.     if self == $game_player && result
  2903.       # if turn enabled
  2904.       if turn_enabled
  2905.         # update buffer
  2906.         $BlizzABS.player.update_buffer(BlizzABS::Cache::TDirs[8])
  2907.       else
  2908.         # update buffer
  2909.         $BlizzABS.player.update_buffer(BlizzABS::Cache::FDirs[8])
  2910.       end
  2911.     end
  2912.     # return result
  2913.     return result
  2914.   end
  2915.   #----------------------------------------------------------------------------
  2916.   # move_lower_left
  2917.   #  Moves. (pixel movement)
  2918.   #----------------------------------------------------------------------------
  2919.   def move_lower_left
  2920.     # call superclass method and store result
  2921.     result = super
  2922.     # if self is controlled by player
  2923.     if self == $game_player && result
  2924.       # update buffer
  2925.       $BlizzABS.player.update_buffer(BlizzABS::Cache::TDirs[1])
  2926.     end
  2927.     # return result
  2928.     return result
  2929.   end
  2930.   #----------------------------------------------------------------------------
  2931.   # move_lower_right
  2932.   #  Moves. (pixel movement)
  2933.   #----------------------------------------------------------------------------
  2934.   def move_lower_right
  2935.     # call superclass method and store result
  2936.     result = super
  2937.     # if self is controlled by player
  2938.     if self == $game_player && result
  2939.       # update buffer
  2940.       $BlizzABS.player.update_buffer(BlizzABS::Cache::TDirs[3])
  2941.     end
  2942.     # return result
  2943.     return result
  2944.   end
  2945.   #----------------------------------------------------------------------------
  2946.   # move_upper_left
  2947.   #  Moves. (pixel movement)
  2948.   #----------------------------------------------------------------------------
  2949.   def move_upper_left
  2950.     # call superclass method and store result
  2951.     result = super
  2952.     # if self is controlled by player
  2953.     if self == $game_player && result
  2954.       # update buffer
  2955.       $BlizzABS.player.update_buffer(BlizzABS::Cache::TDirs[7])
  2956.     end
  2957.     # return result
  2958.     return result
  2959.   end
  2960.   #----------------------------------------------------------------------------
  2961.   # move_upper_right
  2962.   #  Moves. (pixel movement)
  2963.   #----------------------------------------------------------------------------
  2964.   def move_upper_right
  2965.     # call superclass method and store result
  2966.     result = super
  2967.     # if self is controlled by player
  2968.     if self == $game_player && result
  2969.       # update buffer
  2970.       $BlizzABS.player.update_buffer(BlizzABS::Cache::TDirs[9])
  2971.     end
  2972.     # return result
  2973.     return result
  2974.   end
  2975.   #----------------------------------------------------------------------------
  2976.   # passable?
  2977.   #  x - x-coordinate
  2978.   #  y - y-coordinate
  2979.   #  d - direction
  2980.   #  Checks the passability. (pixel movement)
  2981.   #----------------------------------------------------------------------------
  2982.   def passable?(x, y, d)
  2983.     # calculate new coordinates
  2984.     nx = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  2985.     ny = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  2986.     # impassable if new coordinates not valid
  2987.     return false unless $game_map.self_valid?(nx, ny)
  2988.     # impassable if paralyzed
  2989.     return false if self.restriction == 4
  2990.     # passable if actor and pressing CTRL in DEBUG mode
  2991.     return true if $DEBUG && Input.press?(Input::CTRL) || @through
  2992.     # passability depends on basic testing
  2993.     return super
  2994.   end
  2995.   #----------------------------------------------------------------------------
  2996.   # jump
  2997.   #  x - x-coordinate
  2998.   #  y - y-coordinate
  2999.   #  Jumps. (pixel movement)
  3000.   #----------------------------------------------------------------------------
  3001.   def jump(x_plus, y_plus, d = nil)
  3002.     # if direction is unknown
  3003.     if d == nil
  3004.       # determines direction
  3005.       if x_plus > 0 && y_plus > 0 # jumping down right
  3006.         d = 3
  3007.       elsif x_plus > 0 && y_plus < 0 # jumping up left
  3008.         d = 9
  3009.       elsif x_plus < 0 && y_plus > 0 # jumping down right
  3010.         d = 1
  3011.       elsif x_plus < 0 && y_plus < 0 # jumping up left
  3012.         d = 7
  3013.       elsif x_plus < 0 && y_plus == 0 # jumping left
  3014.         d = 4
  3015.       elsif x_plus > 0 && y_plus == 0 # jumping right
  3016.         d = 6
  3017.       elsif x_plus == 0 && y_plus < 0 # jumping up
  3018.         d = 8
  3019.       elsif x_plus == 0 && y_plus > 0 # jumping down
  3020.         d = 2
  3021.       end
  3022.     end
  3023.     # if jumped
  3024.     if super
  3025.       # if self is controlled by player
  3026.       if self == $game_player
  3027.         # update buffer
  3028.         $BlizzABS.player.update_buffer([d, @move_speed - $game_player.normal_speed])
  3029.       end
  3030.       # jumped
  3031.       return true
  3032.     end
  3033.     # not jumped
  3034.     return false
  3035.   end
  3036.   #----------------------------------------------------------------------------
  3037.   # moveto
  3038.   #  x - x-coordinate
  3039.   #  y - y-coordinate
  3040.   #  Moves the player instantly to a postion, moves all actors and centers the
  3041.   #  screen upon the player.
  3042.   #----------------------------------------------------------------------------
  3043.   def moveto(x, y)
  3044.     # call superclass method
  3045.     super
  3046.     # call controller method if self is controlled by player
  3047.     $BlizzABS.player.moveto(x, y) if self == $game_player
  3048.   end
  3049.   #----------------------------------------------------------------------------
  3050.   # center
  3051.   #  x - x-coordinate
  3052.   #  y - y-coordinate
  3053.   #  Centers the screen upon the player's character if the character is
  3054.   #  controlled by the player.
  3055.   #----------------------------------------------------------------------------
  3056.   def center(x, y)
  3057.     $BlizzABS.player.center(x, y) if self == $game_player
  3058.   end
  3059.   #----------------------------------------------------------------------------
  3060.   # attacked=
  3061.   #  val - number
  3062.   #  Sets the attacked counter and blinking value.
  3063.   #----------------------------------------------------------------------------
  3064.   def attacked=(val)
  3065.     # call superclass method
  3066.     super
  3067.     # if controlled by player
  3068.     if self == $game_player
  3069.       # dismantle entire caterpillar
  3070.       ($BlizzABS.battlers - [self]).each {|b| b.remove_from_caterpillar}
  3071.     else
  3072.       # remove from caterpillar
  3073.       remove_from_caterpillar
  3074.     end
  3075.     # set blinking counter if not defending
  3076.     @blinking = val * 8 unless BlizzABS::Config::FULL_DEFEND && @ai.act.defend?
  3077.   end
  3078.   #----------------------------------------------------------------------------
  3079.   # check_event_trigger_touch
  3080.   #  x - x-coordinate
  3081.   #  y - y-coordinate
  3082.   #  Checks event touching if self is controlled by player.
  3083.   #----------------------------------------------------------------------------
  3084.   def check_event_trigger_touch(x, y)
  3085.     $BlizzABS.player.check_event_trigger_touch(x, y) if self == $game_player
  3086.   end
  3087.   #----------------------------------------------------------------------------
  3088.   # index
  3089.   #  Returns own position in battlers array composed of actors, summoned pets
  3090.   #  and summoned monsters.
  3091.   #----------------------------------------------------------------------------
  3092.   def index
  3093.     return $BlizzABS.battlers.index(self)
  3094.   end
  3095.   #----------------------------------------------------------------------------
  3096.   # running?
  3097.   #  Checks if the player is running.
  3098.   #----------------------------------------------------------------------------
  3099.   def running?
  3100.     return (BlizzABS::Config::RUN_SPEED == @move_speed)
  3101.   end
  3102.   #----------------------------------------------------------------------------
  3103.   # sneaking?
  3104.   #  Checks if the player is sneaking.
  3105.   #----------------------------------------------------------------------------
  3106.   def sneaking?
  3107.     return (BlizzABS::Config::SNEAK_SPEED == @move_speed)
  3108.   end
  3109.   #----------------------------------------------------------------------------
  3110.   # idle?
  3111.   #  Checks whether the character is idle on the map.
  3112.   #----------------------------------------------------------------------------
  3113.   def idle?
  3114.     return (super && (self == $game_player ? !moving? && @idle_allowed :
  3115.         @cindex != nil && @force_move.size <= $BlizzABS.pixel * @cindex))
  3116.   end
  3117.   #----------------------------------------------------------------------------
  3118.   # screen_z
  3119.   #  height - height on the screen
  3120.   #  Gets character's z-coordinate.
  3121.   #----------------------------------------------------------------------------
  3122.   def screen_z(height = 0)
  3123.     return (super - (index == nil ? BlizzABS::Config::MAX_PARTY : index))
  3124.   end
  3125.  
  3126. end
  3127.  
  3128. #==============================================================================
  3129. # Game_Player
  3130. #------------------------------------------------------------------------------
  3131. #  This class serves as override, so a Map_Actor class is loaded as current
  3132. #  player.
  3133. #==============================================================================
  3134.  
  3135. class Game_Player < Map_Actor
  3136.  
  3137.   #----------------------------------------------------------------------------
  3138.   # Initialization
  3139.   #----------------------------------------------------------------------------
  3140.   def initialize
  3141.     # call superclass method for first actor
  3142.     super(0)
  3143.   end
  3144.  
  3145. end
  3146.  
  3147. #==============================================================================
  3148. # Map_Enemy
  3149. #------------------------------------------------------------------------------
  3150. #  This class handles a map enemy character. It supports pixel movement,
  3151. #  complete AI handling, advanced sprite handling and battle handling.
  3152. #==============================================================================
  3153.  
  3154. class Map_Enemy < Map_Battler
  3155.  
  3156.   # setting all accessible variables
  3157.   attr_accessor :respawn_point
  3158.   attr_accessor :hide_health
  3159.   attr_reader   :event
  3160.   attr_reader   :trigger
  3161.   attr_reader   :list
  3162.   attr_reader   :page
  3163.   attr_reader   :starting
  3164.   attr_reader   :execute
  3165.   attr_reader   :immortal
  3166.   attr_reader   :full_passable
  3167.   attr_reader   :move_flag
  3168.   #----------------------------------------------------------------------------
  3169.   # Initialization
  3170.   #----------------------------------------------------------------------------
  3171.   def initialize(map_id, event, id = 0, group = 0, attributes = 0x00,
  3172.                  move = false, immortal = false, full_passable = false,
  3173.                  custom = false, delay = 40, view = 5, hear = 40, nojump = false)
  3174.     # if respawning system active
  3175.     if event.is_a?(Map_Enemy)
  3176.       # get AI attributes
  3177.       attributes = event.ai.attributes
  3178.       # get event ID of earlier enemy
  3179.       id = event.battler_id
  3180.       # get moving flag
  3181.       move = !event.move_flag
  3182.       # get immortal flag
  3183.       immortal = event.immortal
  3184.       # get full passability flag
  3185.       full_passable = event.full_passable
  3186.       # get health bar visibility
  3187.       @hide_health = event.hide_health
  3188.       # get custom AI flag
  3189.       custom = event.ai.custom
  3190.       # get alignmend group
  3191.       group = event.ai.group
  3192.       # get AI Delay Time
  3193.       delay = event.ai.delay_time
  3194.       # get view range
  3195.       view = event.ai.view_range
  3196.       # get hearing range ratio
  3197.       hear = event.ai.hearing_range_ratio
  3198.       # get event of earlier enemy
  3199.       event = event.event
  3200.     end
  3201.     # give the enemy all attributes of a normal character
  3202.     super()
  3203.     # set map ID and store @event (needed for respawn)
  3204.     @map_id, @event = map_id, event
  3205.     # move to starting position
  3206.     moveto(@event.x, @event.y)
  3207.     # set erased flag, starting flag, execute flag, precondition and object flag
  3208.     @erased = @starting = @execute = @precondition = false
  3209.     # set character spriteset name
  3210.     @character_name_org = @character_name = ''
  3211.     # empty custom triggers
  3212.     @custom_triggers = []
  3213.     # refresh
  3214.     refresh
  3215.     # the database enemy or actor
  3216.     @enemy = $data_enemies[id]
  3217.     # the battler
  3218.     @battler = Game_Enemy.new(@enemy)
  3219.     # set immortal flag
  3220.     @immortal = @battler.immortal = immortal
  3221.     # set full passability flag
  3222.     @full_passable = full_passable
  3223.     # set no jump flag
  3224.     @no_jump = no_jump
  3225.     # create AI Data
  3226.     @ai = BlizzABS::AI::Data_Enemy.new(self, group, attributes, custom, delay,
  3227.         view, hear)
  3228.     # own ID and own event ID
  3229.     @SELF = @id = event.id
  3230.     # set moving flag
  3231.     @move_flag = !move
  3232.   end
  3233.   #----------------------------------------------------------------------------
  3234.   # transform
  3235.   #  id - new enemy's ID in the database
  3236.   #  Transforms an enemy battler into another one.
  3237.   #----------------------------------------------------------------------------
  3238.   def transform(id)
  3239.     # set new enemy ID, own ID and database enemy
  3240.     @battler.enemy_id, @enemy = id, $data_enemies[id]
  3241.     # set HP if over maximum and remove last hpdamage value
  3242.     @battler.hp = @battler.hp
  3243.     # set SP if over maximum and remove last spdamage value
  3244.     @battler.sp = @battler.sp
  3245.     # get AI data setup
  3246.     attr, delay, view, hear = $BlizzABS.setup_enemy_ai(id)
  3247.     # get AI attributes if custom
  3248.     attr = @ai.attributes if @ai.custom
  3249.     # recreate data pack for new enemy
  3250.     @ai = BlizzABS::AI::Data_Enemy.new(self, @ai.group, attr, @ai.custom,
  3251.         delay, view, hear)
  3252.   end
  3253.   #----------------------------------------------------------------------------
  3254.   # override lock
  3255.   #----------------------------------------------------------------------------
  3256.   alias lock_blizzabs_later lock
  3257.   def lock
  3258.     # store direction fix
  3259.     fix, @direction_fix = @direction_fix, true
  3260.     # call original method
  3261.     lock_blizzabs_later
  3262.     # restore direction fix
  3263.     @direction_fix = fix
  3264.   end
  3265.   #----------------------------------------------------------------------------
  3266.   # clear_starting
  3267.   #  Clears the starting flag.
  3268.   #----------------------------------------------------------------------------
  3269.   def clear_starting
  3270.     @starting = false
  3271.   end
  3272.   #----------------------------------------------------------------------------
  3273.   # start
  3274.   #  Setups the starting event code.
  3275.   #----------------------------------------------------------------------------
  3276.   def start
  3277.     # if event code exists
  3278.     return if @list.size <= 1
  3279.     # set starting and execution flag
  3280.     @starting = @execute = true
  3281.   end
  3282.   #----------------------------------------------------------------------------
  3283.   # erase
  3284.   #  Dummy method.
  3285.   #----------------------------------------------------------------------------
  3286.   def erase
  3287.     @terminate = @erased = true
  3288.   end
  3289.   #----------------------------------------------------------------------------
  3290.   # over_trigger?
  3291.   #  Dummy method.
  3292.   #----------------------------------------------------------------------------
  3293.   def over_trigger?
  3294.     return false
  3295.   end
  3296.   #--------------------------------------------------------------------------
  3297.   # refresh
  3298.   #  Refreshes the character.
  3299.   #--------------------------------------------------------------------------
  3300.   def refresh
  3301.     # initialize
  3302.     new_page = nil
  3303.     # if not erased
  3304.     unless @erased
  3305.       # iterate through all pages in reverse order
  3306.       @event.pages.reverse.each {|page|
  3307.           # temporary variable
  3308.           c = page.condition
  3309.           # switch 1 condition test
  3310.           next if c.switch1_valid && !$game_switches[c.switch1_id]
  3311.           # switch 2 condition test
  3312.           next if c.switch2_valid && !$game_switches[c.switch2_id]
  3313.           # variable condition test
  3314.           if c.variable_valid
  3315.             # next page if condition not fulfilled
  3316.             next if $game_variables[c.variable_id] < c.variable_value
  3317.           end
  3318.           # self switch condition test
  3319.           if c.self_switch_valid
  3320.             # temporary variable
  3321.             key = [@map_id, @event.id, c.self_switch_ch]
  3322.             # next page if condition not fulfilled
  3323.             next unless $game_self_switches[key]
  3324.           end
  3325.           # set local variable
  3326.           new_page = page
  3327.           # stop looping
  3328.           break}
  3329.     end
  3330.     # setup event page if event page is not the same as last time
  3331.     setup_event_page(new_page) if new_page != @page
  3332.   end
  3333.   #----------------------------------------------------------------------------
  3334.   # setup_event_page
  3335.   #  new_page - the event page
  3336.   #  Set up the defined event page.
  3337.   #----------------------------------------------------------------------------
  3338.   def setup_event_page(new_page)
  3339.     # set as current event page
  3340.     @page = new_page
  3341.     # if no page fulfills conditions
  3342.     if @page == nil
  3343.       # set up variables
  3344.       @character_name_org = @character_name = ''
  3345.       @tile_id = @character_hue = @move_type = 0
  3346.       @trigger = @list = nil
  3347.       @through, @precondition = true, false
  3348.       # exit method
  3349.       return
  3350.     end
  3351.     # set up variables
  3352.     @tile_id = @page.graphic.tile_id
  3353.     @character_name_org = @character_name = @page.graphic.character_name
  3354.     @character_hue = @page.graphic.character_hue
  3355.     # if direction is different
  3356.     if @original_direction != @page.graphic.direction
  3357.       @direction = @page.graphic.direction
  3358.       @original_direction = @direction
  3359.       @prelock_direction = 0
  3360.     end
  3361.     # if pattern is different
  3362.     if @original_pattern != @page.graphic.pattern
  3363.       @pattern = @page.graphic.pattern
  3364.       @original_pattern = @pattern
  3365.     end
  3366.     @opacity = @page.graphic.opacity
  3367.     @blend_type = @page.graphic.blend_type
  3368.     @move_type = @page.move_type
  3369.     @normal_speed = @move_speed = @page.move_speed
  3370.     @move_frequency = @page.move_frequency
  3371.     @move_route = @page.move_route
  3372.     @move_route_index = 0
  3373.     @move_route_forcing = false
  3374.     @walk_anime = @page.walk_anime
  3375.     @step_anime = @page.step_anime
  3376.     @direction_fix = @page.direction_fix
  3377.     @through = (@page.through || @full_passable)
  3378.     @always_on_top = @page.always_on_top
  3379.     triggers = $BlizzABS.util.get_triggers(@page.list)
  3380.     @trigger = triggers.shift
  3381.     @custom_triggers = triggers.shift
  3382.     @list = @page.list
  3383.     # set precondtion flag
  3384.     @precondition = true
  3385.   end
  3386.   #----------------------------------------------------------------------------
  3387.   # update
  3388.   #  Executes the enemy behavior according to the AI.
  3389.   #----------------------------------------------------------------------------
  3390.   def update
  3391.     # if outside of ABSEAL range and actually existing
  3392.     if !self.update? || !@precondition
  3393.       # reset memory and moving route
  3394.       @ai.memory, @force_move = {}, []
  3395.       # stop updating
  3396.       return
  3397.     end
  3398.     # check special state effects
  3399.     update_states
  3400.     # reset loop animation
  3401.     @loop_animation_id = 0
  3402.     # reset spriteset name
  3403.     @character_name = @character_name_org
  3404.     # update spriteset
  3405.     sprite_animation_setup
  3406.     # if executing an event code
  3407.     if event_execution?
  3408.       # call superclass method
  3409.       super
  3410.       # abort update
  3411.       return
  3412.     end
  3413.     # return if page doesn't exist
  3414.     return if @page == nil
  3415.     # if event code is being executed or lifeless object or not in battle
  3416.     if $game_system.map_interpreter.running? || @ai.lifeless? ||
  3417.         !$game_temp.in_battle
  3418.       # update movement
  3419.       update_forcemove
  3420.       # update the event with the superclass method
  3421.       super
  3422.       # exit method
  3423.       return
  3424.     end
  3425.     # AI update phase 1 (pre-phase)
  3426.     $BlizzABS.AI.prepare(self)
  3427.     # if can't act now
  3428.     if !can_act?
  3429.       # update action
  3430.       update_action
  3431.       # call superclass method
  3432.       super
  3433.       # exit method
  3434.       return
  3435.     end
  3436.     # update AI controlled behavior
  3437.     update_behavior
  3438.     # stop execution if abort requested
  3439.     return if @ai.state == BlizzABS::AI::Abort
  3440.     # update idle
  3441.     update_idle
  3442.     # update movement
  3443.     update_forcemove
  3444.     # call superclass method
  3445.     super
  3446.   end
  3447.   #----------------------------------------------------------------------------
  3448.   # event_execution?
  3449.   #  Tests if the enemy died and is executing an event now.
  3450.   #----------------------------------------------------------------------------
  3451.   def event_execution?
  3452.     # stop if not executing
  3453.     return false if !@execute
  3454.     # if about to start or running already
  3455.     if @starting || $game_system.map_interpreter.running?
  3456.       # reset blending type
  3457.       @blend_type = 0 if @starting
  3458.       # reset moving route
  3459.       @force_move = []
  3460.       # executing event
  3461.       return true
  3462.     end
  3463.     # if enemy revived with event command
  3464.     if valid? && !battler.dead?
  3465.       # reset opacity
  3466.       @opacity = 255
  3467.       # reset blending type
  3468.       @blend_type = 0
  3469.       # reset execute flag
  3470.       @execute = false
  3471.       # recreate data pack for new enemy
  3472.       @ai = BlizzABS::AI::Data_Enemy.new(self, @ai.group, @ai.attributes,
  3473.           @ai.custom, @ai.delay_time, @ai.view_range, @ai.hearing_range_ratio)
  3474.       # reset moving route
  3475.       @force_move = []
  3476.     # if opacity is 0
  3477.     elsif !valid?
  3478.       # set execute flag and erased flag
  3479.       @execute, @erased = false, true
  3480.       # refresh
  3481.       refresh
  3482.     end
  3483.     # not executing event
  3484.     return false
  3485.   end
  3486.   #----------------------------------------------------------------------------
  3487.   # update_ai
  3488.   #  Updates AI specific behavior.
  3489.   #----------------------------------------------------------------------------
  3490.   def update_ai
  3491.     # stop if force moving knockback
  3492.     return if @ai.state == BlizzABS::AI::Knockback
  3493.     # if not aggressive
  3494.     if !@ai.aggressive
  3495.       # light update
  3496.       update_priority = BlizzABS::UPDLight
  3497.     # if moving
  3498.     elsif moving?
  3499.       # medium update
  3500.       update_priority = BlizzABS::UPDMedium
  3501.     # if trying to move
  3502.     elsif @force_move.size > 0
  3503.       # heavy update
  3504.       update_priority = BlizzABS::UPDHeavy
  3505.     else
  3506.       # full update
  3507.       update_priority = BlizzABS::UPDFull
  3508.     end
  3509.     # AI update phase 2 (perception)
  3510.     in_range = $BlizzABS.AI.perception(self, update_priority)
  3511.     # if doing nothing, aggressive and no target exists
  3512.     if self.in_action == 0 && @ai.aggressive &&
  3513.         (@ai.target == nil || !@ai.target.valid?)
  3514.       # AI update phase 3 (decide action)
  3515.       $BlizzABS.AI.decide_action(self)
  3516.     end
  3517.     # update leader related data
  3518.     $BlizzABS.AI.leader_update(self)
  3519.     # override timer if using "full power" attribute and not running away
  3520.     @ai.act.delay = 0 if @ai.full_power && !@ai.act.ready? && !@ai.act.escape?
  3521.   end
  3522.   #----------------------------------------------------------------------------
  3523.   # update_action
  3524.   #  Updates the action to be executed.
  3525.   #----------------------------------------------------------------------------
  3526.   def update_action
  3527.     # stop if force moving knockback or action doesn't exist
  3528.     return if @ai.state == BlizzABS::AI::Knockback || !@ai.act.valid?
  3529.     # decrease delay timer
  3530.     @ai.act.delay -= 1
  3531.     # if leader and counter expired and only sometimes
  3532.     if @ai.leader && @ai.act.ready? && rand(100) < 10
  3533.       # all minions
  3534.       @ai.minions.each {|b|
  3535.           # 50% chance if they have an action pending
  3536.           if b.ai.act.valid? && rand(2) == 0
  3537.             # force into action
  3538.             b.ai.act.delay = 0
  3539.             # 50% chance for same target
  3540.             b.ai.target = @ai.target if rand(2) == 0
  3541.           end}
  3542.     end
  3543.     # projectile evasion processing if attribute "defensive" is active
  3544.     $BlizzABS.AI.evade_projectiles(self) if @ai.defensive && @move_type != 3
  3545.     # if counter expired and either running away or defending
  3546.     if @ai.act.ready? && (@ai.act.escape? || @ai.act.defend?)
  3547.       # reset action
  3548.       self.reset_action
  3549.       # reset sprites
  3550.       self.reset_sprites
  3551.     end
  3552.   end
  3553.   #----------------------------------------------------------------------------
  3554.   # setup_move
  3555.   #  Sets up the forced movement if it is needed.
  3556.   #----------------------------------------------------------------------------
  3557.   def setup_move
  3558.     # stop if not allowed to change speed
  3559.     return if @ai.state == BlizzABS::AI::MoveOnly
  3560.     # set to idle state if return state
  3561.     @ai.state = BlizzABS::AI::Idle if @ai.state == BlizzABS::AI::Return
  3562.     # reset moving speed
  3563.     @move_speed = @normal_speed
  3564.     # increase moving speed if knockback
  3565.     @move_speed += 1 if @ai.state == BlizzABS::AI::Knockback
  3566.   end
  3567.   #----------------------------------------------------------------------------
  3568.   # update_idle
  3569.   #  Updates idle action.
  3570.   #----------------------------------------------------------------------------
  3571.   def update_idle
  3572.     # if idle, update time expired and not forced to move
  3573.     if @ai.state == BlizzABS::AI::Idle &&
  3574.         Graphics.frame_count % 20 == rand(30) && @move_type != 3
  3575.       # get pixel movement rate
  3576.       pix = $BlizzABS.pixel
  3577.       # get possible directions
  3578.       dir = ($game_system._8_way ? BlizzABS::Cache::Dir8 : BlizzABS::Cache::Dir4)
  3579.       # get one direction
  3580.       dir = dir[rand(dir.size)]
  3581.       # move randomly
  3582.       (pix/2 + rand(pix+1)).times {@force_move.push(BlizzABS::Cache::TDirs[dir])}
  3583.       # set idle moving speed
  3584.       @move_speed = @normal_speed - 1
  3585.     end
  3586.   end
  3587.   #----------------------------------------------------------------------------
  3588.   # update_forcemove
  3589.   #  Updates movement.
  3590.   #----------------------------------------------------------------------------
  3591.   def update_forcemove
  3592.     # stop if no moving commands exist
  3593.     return if @force_move.size == 0
  3594.     # get next moving command
  3595.     move = @force_move.shift
  3596.     # stop if moving not allowed
  3597.     return if !@move_flag
  3598.     # execute movement command
  3599.     case move[0]
  3600.     when 1 then move_lower_left(11)
  3601.     when 2 then move_down(11, move[1])
  3602.     when 3 then move_lower_right(11)
  3603.     when 4 then move_left(11, move[1])
  3604.     when 6 then move_right(11, move[1])
  3605.     when 7 then move_upper_left(11)
  3606.     when 8 then move_up(11, move[1])
  3607.     when 9 then move_upper_right(11)
  3608.     end
  3609.   end
  3610.   #----------------------------------------------------------------------------
  3611.   # attack_effect
  3612.   #  character - the character that holds attack data (can be projectile)
  3613.   #  _battler  - the attacking battler
  3614.   #  Executes attack upon a map character.
  3615.   #----------------------------------------------------------------------------
  3616.   def attack_effect(character, _battler)
  3617.     # call superclass method
  3618.     result = super
  3619.     # if actor
  3620.     if _battler.is_a?(Game_Actor)
  3621.       # get weapon ID and custom event trigger type
  3622.       id, cet = _battler.weapon_id, BlizzABS::CETWeapon
  3623.     # if enemy
  3624.     elsif _battler.is_a?(Game_Enemy)
  3625.       # get weapon ID and custom event trigger type
  3626.       id, cet = _battler.id, BlizzABS::CETEnemy
  3627.     end
  3628.     # if can be activated by this weapon / enemy
  3629.     if result && @custom_triggers.has_key?(cet) &&
  3630.         (@custom_triggers[cet].size == 0 ||
  3631.         @custom_triggers[cet].include?(id))
  3632.       # run this enemy as event
  3633.       self.start
  3634.     end
  3635.     # return result
  3636.     return result
  3637.   end
  3638.   #----------------------------------------------------------------------------
  3639.   # skill_effect
  3640.   #  character - the character that holds skill use (can be projectile)
  3641.   #  _battler  - the skill using battler
  3642.   #  skill     - the skill
  3643.   #  Executes skill use upon a map character.
  3644.   #----------------------------------------------------------------------------
  3645.   def skill_effect(character, _battler, skill)
  3646.     # call superclass method
  3647.     result = super
  3648.     # if can be activated by this skill
  3649.     if result && @custom_triggers.has_key?(BlizzABS::CETSkill) &&
  3650.         (@custom_triggers[BlizzABS::CETSkill].size == 0 ||
  3651.         @custom_triggers[BlizzABS::CETSkill].include?(skill.id))
  3652.       # run this enemy as event
  3653.       self.start
  3654.     end
  3655.     # return result
  3656.     return result
  3657.   end
  3658.   #----------------------------------------------------------------------------
  3659.   # item_effect
  3660.   #  character - the character that holds item use (can be projectile)
  3661.   #  item      - the item
  3662.   #  Executes item use upon a map character.
  3663.   #----------------------------------------------------------------------------
  3664.   def item_effect(character, _battler, item)
  3665.     # call superclass method
  3666.     result = super
  3667.     # if can be activated by this item
  3668.     if result && @custom_triggers.has_key?(BlizzABS::CETItem) &&
  3669.         (@custom_triggers[BlizzABS::CETItem].size == 0 ||
  3670.         @custom_triggers[BlizzABS::CETItem].include?(item.id))
  3671.       # run this enemy as event
  3672.       self.start
  3673.     end
  3674.     # return result
  3675.     return result
  3676.   end
  3677.   #----------------------------------------------------------------------------
  3678.   # alignment_effect
  3679.   #  group - the group to which the character belongs to
  3680.   #  first - first to get the executed action
  3681.   #  Applies alignment changes.
  3682.   #----------------------------------------------------------------------------
  3683.   def alignment_effect(group, first = true)
  3684.     # set to aggressive
  3685.     @ai.aggressive = true
  3686.     # call superclass method
  3687.     super(group)
  3688.     # stop if not first to get action executed upon
  3689.     return unless first
  3690.     # for each battler
  3691.     $game_map.battlers.each {|b|
  3692.         # if this is an ally and can be seen
  3693.         if b.ai.positive.include?(@ai.group) && b.ai.sight.include?(self)
  3694.           # make action effect
  3695.           b.alignment_effect(group, false)
  3696.         end}
  3697.     # stop if not linked group
  3698.     return if !@ai.linked?
  3699.     # for each battler
  3700.     $game_map.battlers_group(@ai.group).each {|b|
  3701.         # make action effect
  3702.         b.alignment_effect(group, false)}
  3703.     # stop if not permanently linked
  3704.     return if !@ai.permanent?
  3705.     # for each alignment group setup
  3706.     $game_system.alignments.values.each {|a|
  3707.         # make character group to enemy if this group is an ally
  3708.         a.enemies.push(group) if a.ally?(@ai.group)}
  3709.   end
  3710.   #----------------------------------------------------------------------------
  3711.   # attack_penalty
  3712.   #  Returns the penalty for the enemy.
  3713.   #----------------------------------------------------------------------------
  3714.   def attack_penalty
  3715.     # get weapon penalty
  3716.     penalty = BlizzABS::Enemies.penalty(@battler.id)
  3717.     # limit is sum of all animation frames if using action sprites
  3718.     limit = (action_sprites? ? BlizzABS::Enemies.frames(@battler.id).sum : 0)
  3719.     # limit penalty
  3720.     return (penalty < limit ? limit : penalty)
  3721.   end
  3722.   #----------------------------------------------------------------------------
  3723.   # action_sprites?
  3724.   #  Checks if action sprites can be used.
  3725.   #----------------------------------------------------------------------------
  3726.   def action_sprites?
  3727.     return BlizzABS::Config::E_ACTION_SPRITES
  3728.   end
  3729.   #----------------------------------------------------------------------------
  3730.   # skill_sprites?
  3731.   #  Checks if skill sprites can be used.
  3732.   #----------------------------------------------------------------------------
  3733.   def skill_sprites?
  3734.     return BlizzABS::Config::E_SKILL_SPRITES
  3735.   end
  3736.   #----------------------------------------------------------------------------
  3737.   # idle_sprites?
  3738.   #  Checks if idle sprites can be used.
  3739.   #----------------------------------------------------------------------------
  3740.   def idle_sprites?
  3741.     return BlizzABS::Config::E_IDLE_SPRITES
  3742.   end
  3743.   #----------------------------------------------------------------------------
  3744.   # charge_sprites?
  3745.   #  Checks if charge sprites can be used.
  3746.   #----------------------------------------------------------------------------
  3747.   def charge_sprites?
  3748.     return BlizzABS::Config::E_CHARGE_SPRITES
  3749.   end
  3750.   #----------------------------------------------------------------------------
  3751.   # charge_weapon_sprites?
  3752.   #  Checks if charge weapon sprites can be used.
  3753.   #----------------------------------------------------------------------------
  3754.   def charge_weapon_sprites?
  3755.     return BlizzABS::Config::E_CHARGE_SPRITES
  3756.   end
  3757.   #----------------------------------------------------------------------------
  3758.   # charge_skill_sprites?
  3759.   #  Checks if charge skill sprites can be used.
  3760.   #----------------------------------------------------------------------------
  3761.   def charge_skill_sprites?
  3762.     return BlizzABS::Config::E_CHARGE_SKILL_SPRITES
  3763.   end
  3764.   #----------------------------------------------------------------------------
  3765.   # setup_attack_sprites
  3766.   #  Sets up attack sprites and returns the frame animation data necessary.
  3767.   #----------------------------------------------------------------------------
  3768.   def setup_attack_sprites
  3769.     # set normal weapon sprite
  3770.     @weapon_sprite = BlizzABS::SPRWeapon
  3771.     # return frame animation data
  3772.     return BlizzABS::Enemies.frames(self.battler_id)
  3773.   end
  3774.   #----------------------------------------------------------------------------
  3775.   # setup_charge_attack_sprites
  3776.   #  Sets up charge attack sprites and returns the frame animation data
  3777.   #  necessary.
  3778.   #----------------------------------------------------------------------------
  3779.   def setup_charge_attack_sprites
  3780.     return BlizzABS::Enemies.charge_frames(self.battler_id)
  3781.   end
  3782.   #----------------------------------------------------------------------------
  3783.   # battler
  3784.   #  Allows disabling of the character if the event is does not exist due to
  3785.   #  preconditions.
  3786.   #----------------------------------------------------------------------------
  3787.   def battler
  3788.     return (@precondition ? @battler : nil)
  3789.   end
  3790.   #----------------------------------------------------------------------------
  3791.   # valid?
  3792.   #  Checks if the assigned battler exists and is not dead.
  3793.   #----------------------------------------------------------------------------
  3794.   def valid?
  3795.     return (super && !(self.battler.dead? && @opacity == 0))
  3796.   end
  3797.   #----------------------------------------------------------------------------
  3798.   # exp
  3799.   #  Returns the experience.
  3800.   #----------------------------------------------------------------------------
  3801.   def exp
  3802.     return @battler.exp
  3803.   end
  3804.   #----------------------------------------------------------------------------
  3805.   # gold
  3806.   #  Returns the gold.
  3807.   #----------------------------------------------------------------------------
  3808.   def gold
  3809.     return @battler.gold
  3810.   end
  3811.   #----------------------------------------------------------------------------
  3812.   # move_random
  3813.   #  Moves into a random direction. (8-way)
  3814.   #----------------------------------------------------------------------------
  3815.   def move_random(number = 1)
  3816.     case rand(8)
  3817.     when 0 then number.times {move_down(0)}
  3818.     when 1 then number.times {move_left(0)}
  3819.     when 2 then number.times {move_right(0)}
  3820.     when 3 then number.times {move_up(0)}
  3821.     when 4 then number.times {move_lower_left}
  3822.     when 5 then number.times {move_upper_left}
  3823.     when 6 then number.times {move_lower_right}
  3824.     when 7 then number.times {move_upper_right}
  3825.     end
  3826.   end
  3827.   #----------------------------------------------------------------------------
  3828.   # move_generic
  3829.   #  mode  - flag for overriding
  3830.   #  check - turning flag
  3831.   #  dir   - direction
  3832.   #  Moves with considering the overrides. (pixel movement)
  3833.   #----------------------------------------------------------------------------
  3834.   def move_generic(mode, check, dir)
  3835.     # get pixel movement rate
  3836.     pix = $BlizzABS.pixel
  3837.     # if override type of moving
  3838.     if mode == 0
  3839.       # override and set moving route
  3840.       rand(pix*2).times{@force_move.push(BlizzABS::Cache::FDirs[dir])}
  3841.     # re-routing the method
  3842.     elsif mode
  3843.       # set moving route
  3844.       pix.times{@force_move.push(BlizzABS::Cache::TDirs[dir])}
  3845.     else
  3846.       # set moving route
  3847.       pix.times{@force_move.push(BlizzABS::Cache::FDirs[dir])}
  3848.     end
  3849.   end
  3850.   #----------------------------------------------------------------------------
  3851.   # move_down
  3852.   #  mode  - flag for overriding
  3853.   #  check - turning flag
  3854.   #  Moves. (pixel movement)
  3855.   #----------------------------------------------------------------------------
  3856.   def move_down(mode = true, check = true)
  3857.     mode == 0 ? move_generic(mode, check, 2) : super(check)
  3858.   end
  3859.   #----------------------------------------------------------------------------
  3860.   # move_left
  3861.   #  mode  - flag for overriding
  3862.   #  check - turning flag
  3863.   #  Moves. (pixel movement)
  3864.   #----------------------------------------------------------------------------
  3865.   def move_left(mode = true, check = true)
  3866.     mode == 0 ? move_generic(mode, check, 4) : super(check)
  3867.   end
  3868.   #----------------------------------------------------------------------------
  3869.   # move_right
  3870.   #  mode  - flag for overriding
  3871.   #  check - turning flag
  3872.   #  Moves. (pixel movement)
  3873.   #----------------------------------------------------------------------------
  3874.   def move_right(mode = true, check = true)
  3875.     mode == 0 ? move_generic(mode, check, 6) : super(check)
  3876.   end
  3877.   #----------------------------------------------------------------------------
  3878.   # move_up
  3879.   #  mode  - flag for overriding
  3880.   #  check - turning flag
  3881.   #  Moves. (pixel movement)
  3882.   #----------------------------------------------------------------------------
  3883.   def move_up(mode = true, check = false)
  3884.     mode == 0 ? move_generic(mode, check, 8) : super(check)
  3885.   end
  3886.   #----------------------------------------------------------------------------
  3887.   # move_lower_left
  3888.   #  mode - overriding flag
  3889.   #  Moves diagonal. (pixel movement)
  3890.   #----------------------------------------------------------------------------
  3891.   def move_lower_left(mode = 0)
  3892.     mode == 0 ? move_generic(mode, true, 1) : super()
  3893.   end
  3894.   #----------------------------------------------------------------------------
  3895.   # move_lower_right
  3896.   #  mode - overriding flag
  3897.   #  Moves diagonal. (pixel movement)
  3898.   #----------------------------------------------------------------------------
  3899.   def move_lower_right(mode = 0)
  3900.     mode == 0 ? move_generic(mode, true, 3) : super()
  3901.   end
  3902.   #----------------------------------------------------------------------------
  3903.   # move_upper_left
  3904.   #  mode - overriding flag
  3905.   #  Moves diagonal. (pixel movement)
  3906.   #----------------------------------------------------------------------------
  3907.   def move_upper_left(mode = 0)
  3908.     mode == 0 ? move_generic(mode, true, 7) : super()
  3909.   end
  3910.   #----------------------------------------------------------------------------
  3911.   # move_upper_right
  3912.   #  mode - overriding flag
  3913.   #  Moves diagonal. (pixel movement)
  3914.   #----------------------------------------------------------------------------
  3915.   def move_upper_right(mode = 0)
  3916.     mode == 0 ? move_generic(mode, true, 9) : super()
  3917.   end
  3918.   #----------------------------------------------------------------------------
  3919.   # passable?
  3920.   #  x - x-coordinate
  3921.   #  y - y-coordinate
  3922.   #  d - direction
  3923.   #  Checks the passability. (pixel movement)
  3924.   #----------------------------------------------------------------------------
  3925.   def passable?(x, y, d)
  3926.     # calculate new coordinates
  3927.     nx = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  3928.     ny = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  3929.     # impassable if new coordinates not valid
  3930.     return false unless $game_map.self_valid?(nx, ny)
  3931.     # impassable if paralyzed
  3932.     return false if self.restriction == 4
  3933.     # passable if full passability
  3934.     return true if @full_passable
  3935.     # pixel movement rate
  3936.     pix = $BlizzABS.pixel
  3937.     # rectangle
  3938.     rect = Rect.new(nx, ny, pix, pix)
  3939.     # if an actor is in the way
  3940.     if $BlizzABS.battlers.any? {|actor|
  3941.         !actor.through && actor.character_name != '' &&
  3942.         $BlizzABS.util.rect_intersection(rect, actor.phitbox)}
  3943.             #Rect.new(actor.x, actor.y, pix, pix))}
  3944.       # impassable
  3945.       return false
  3946.     end
  3947.     # passability depends on basic testing
  3948.     return super
  3949.   end
  3950.   #----------------------------------------------------------------------------
  3951.   # idle?
  3952.   #  Checks whether the character is idle on the map.
  3953.   #----------------------------------------------------------------------------
  3954.   def idle?
  3955.     return (super && @force_move.size == 0)
  3956.   end
  3957.   #----------------------------------------------------------------------------
  3958.   # check_event_trigger_touch
  3959.   #  x - x-coordinate
  3960.   #  y - y-coordinate
  3961.   #  Checks event touching.
  3962.   #----------------------------------------------------------------------------
  3963.   def check_event_trigger_touch(x, y)
  3964.     # get pixel movement rate
  3965.     pix = $BlizzABS.pixel
  3966.     # stop if an event is being executed already
  3967.     return false if $game_system.map_interpreter.running?
  3968.     # if any battler in the way
  3969.     if @trigger == BlizzABS::CETEventTouch && !jumping? && !over_trigger? &&
  3970.         !$game_player.through && $game_player.character_name != '' &&
  3971.         $BlizzABS.util.rect_intersection(Rect.new(x, y, pix, pix),
  3972.             Rect.new($game_player.x, $game_player.y, pix, pix))
  3973.       # start
  3974.       start
  3975.       # started
  3976.       return true
  3977.     end
  3978.     # not started
  3979.     return false
  3980.   end
  3981.   #----------------------------------------------------------------------------
  3982.   # check_event_trigger_at
  3983.   #  x - x-coordinate
  3984.   #  y - y-coordinate
  3985.   #  Check event if it was triggered at a specific position. (pixel movement)
  3986.   #----------------------------------------------------------------------------
  3987.   def check_event_trigger_at(x, y)
  3988.     # get pixel movement rate
  3989.     pix = $BlizzABS.pixel
  3990.     # if player touched this event and not jumping and not over_trigger
  3991.     if !jumping? && !over_trigger? && $BlizzABS.util.rect_intersection(
  3992.         Rect.new(@x, @y, pix, pix), Rect.new(x, y, pix, pix))
  3993.       # start
  3994.       start
  3995.       # started
  3996.       return true
  3997.     end
  3998.     # not started
  3999.     return false
  4000.   end
  4001.  
  4002. end
  4003.  
  4004. #==============================================================================
  4005. # Map_Remote
  4006. #------------------------------------------------------------------------------
  4007. #  This class handles remotes used in battle such as traps and projectiles. It
  4008. #  supports pixel movement and deals attack/skill/item according to the
  4009. #  battler's state when the remote was created.
  4010. #==============================================================================
  4011.  
  4012. class Map_Remote < Map_Battler
  4013.  
  4014.   # setting all accessible variables
  4015.   attr_reader :type
  4016.   attr_reader :group
  4017.   #----------------------------------------------------------------------------
  4018.   # Initialization
  4019.   #  character_name - spriteset file name
  4020.   #  creator        - character that created the projectile or item
  4021.   #  id             - skill id
  4022.   #  type           - which specific type of projectile
  4023.   #  target_group   - which battler groups to target
  4024.   #  dead_type      - dead or non-dead targets
  4025.   #  explode        - exploding or not
  4026.   #----------------------------------------------------------------------------
  4027.   def initialize(character_name, creator, id, type, target_group, dead_type,
  4028.                  explode)
  4029.     # call superclass method without arguments
  4030.     super()
  4031.     # id of weapon/skill/item
  4032.     @id = id
  4033.     # if exploding
  4034.     if explode != nil
  4035.       # exploding range and animation ID
  4036.       @explode_type, @explode_range, @explode_id = explode
  4037.     else
  4038.       # no explosion
  4039.       @explode_type = @explode_range = @explode_id = nil
  4040.     end
  4041.     # set type
  4042.     @type = type
  4043.     # target group
  4044.     @group = target_group
  4045.     # targeting dead or alive targets
  4046.     @dead_type = dead_type
  4047.     # set character_name
  4048.     @character_name = character_name
  4049.     # set coordinates to the same a the creator
  4050.     @real_x, @real_y = creator.real_x, creator.real_y
  4051.     # pixel movement
  4052.     pix = $BlizzABS.pixel
  4053.     # set map coordinates to real coordinates, taking pixel movement into account
  4054.     @x, @y = @real_x * pix / 128, @real_y * pix / 128
  4055.     # a number of projectiles appear instantly while other need a moment
  4056.     @request_time = (BlizzABS::REMRequest.include?(type) ? 4 : 10)
  4057.     # create array of already hit targets
  4058.     @hit = []
  4059.     # set opacity
  4060.     @opacity = 255
  4061.     # create a copy of the battler
  4062.     @battler_copy = creator.battler.clone
  4063.     # store the creator
  4064.     @creator = creator
  4065.     # set direction to the same as the creator's
  4066.     @direction = creator.direction
  4067.     # animate and goes through anything
  4068.     @walk_anime = @step_anime = @through = true
  4069.     # only create once to prevent lag
  4070.     @created = false
  4071.   end
  4072.   #----------------------------------------------------------------------------
  4073.   # battler
  4074.   #  Safe method that returns the battler who shot the projectile.
  4075.   #----------------------------------------------------------------------------
  4076.   def battler
  4077.     return @battler_copy
  4078.   end
  4079.   #----------------------------------------------------------------------------
  4080.   # create
  4081.   #  After creation time delay expires, the sprite is being created.
  4082.   #----------------------------------------------------------------------------
  4083.   def create
  4084.     if (!@created)
  4085.       # create own sprite
  4086.       sprite = Sprite_Character.new($scene.spriteset.viewport1, self)
  4087.       # update sprite once
  4088.       sprite.update
  4089.       # add to spriteset
  4090.       $scene.spriteset.character_sprites.push(sprite)
  4091.       # set created flag
  4092.       @created = true
  4093.     end
  4094.   end
  4095.   #----------------------------------------------------------------------------
  4096.   # execute
  4097.   #  Executes the projectile's effect.
  4098.   #----------------------------------------------------------------------------
  4099.   def execute(target = @target)
  4100.     # if skill
  4101.     if BlizzABS::REMSkills.include?(@type)
  4102.       # execute skill
  4103.       target.skill_effect(@creator, @battler_copy, $data_skills[@id])
  4104.       # check special skill effects
  4105.       $BlizzABS.check_special_skills(@creator, [target], $data_skills[@id])
  4106.     # if item
  4107.     elsif BlizzABS::REMItems.include?(@type)
  4108.       # execute item
  4109.       target.item_effect(@creator, @battler_copy, $data_items[@id])
  4110.     else
  4111.       # execute attack
  4112.       target.attack_effect(@creator, @battler_copy)
  4113.       # if shot item
  4114.       if @type == BlizzABS::REMShotItem
  4115.         # store damage
  4116.         dmg = target.battler.damage
  4117.         # execute item
  4118.         target.item_effect(@creator, @battler_copy, $data_items[@id])
  4119.         # if damage is a number and any damage done
  4120.         if target.battler.damage.is_a?(Numeric) &&
  4121.           (target.battler.hpdamage > 0 || target.battler.spdamage > 0)
  4122.           # add attack damage if attack damage was a number
  4123.           target.battler.damage += dmg if dmg.is_a?(Numeric)
  4124.         # if no damage done with item
  4125.         elsif target.battler.hpdamage == 0 && target.battler.spdamage == 0
  4126.           # set back to attack damage
  4127.           target.battler.damage = dmg
  4128.         end
  4129.       end
  4130.     end
  4131.     # clear damage displays
  4132.     target.battler.damage, target.battler.damage_pop = nil, false
  4133.     # add to already hit targets
  4134.     @hit.push(target)
  4135.     # sets flag for self-termination if necessary
  4136.     @terminate = true unless BlizzABS::REMPersistent.include?(@type)
  4137.   end
  4138.   #--------------------------------------------------------------------------
  4139.   # update
  4140.   #  Processes projectile movement.
  4141.   #--------------------------------------------------------------------------
  4142.   def update
  4143.     # update execution
  4144.     update_execution
  4145.     # call superclass method
  4146.     super
  4147.   end
  4148.   #--------------------------------------------------------------------------
  4149.   # requesting?
  4150.   #  Checks if the sprite can be updated already.
  4151.   #--------------------------------------------------------------------------
  4152.   def requesting?
  4153.     # decrease counter
  4154.     @request_time -= 1
  4155.     # abort method if creation request has not expired yet
  4156.     return false if @request_time > 0
  4157.     # create if scene is Scene_Map and spriteset exists
  4158.     create if $scene.is_a?(Scene_Map) && $scene.spriteset != nil
  4159.     # can update
  4160.     return true
  4161.   end
  4162.   #----------------------------------------------------------------------------
  4163.   # update_execution
  4164.   #  consider_all - considers if remote targets all enemies
  4165.   #  Updates the execution.
  4166.   #----------------------------------------------------------------------------
  4167.   def update_execution(consider_all = false)
  4168.     # get pixel movement rate
  4169.     pix = $BlizzABS.pixel
  4170.     # if considering all targets
  4171.     if consider_all
  4172.       # if skill
  4173.       if BlizzABS::REMSkills.include?(@type)
  4174.         # get skill
  4175.         object = $data_skills[@id]
  4176.       else
  4177.         # get item
  4178.         object = $data_items[@id]
  4179.       end
  4180.       # new value from scope data
  4181.       consider_all = $BlizzABS.util.get_scope_data(object.scope)[2]
  4182.     end
  4183.     return if !(@fade_out || @explode_type != BlizzABS::EXPLEnd)
  4184.     # iterate through all battlers
  4185.     ($game_map.battlers + $BlizzABS.battlers).each {|battler|
  4186.         # if battler can be hit and battler and projectile intersect
  4187.         if battler.battler != nil && @group.include?(battler.ai.group) &&
  4188.             @dead_type == battler.battler.dead? &&
  4189.             $BlizzABS.util.intersection(effect_area, battler.hitbox)
  4190.           # execute action unless already hit
  4191.           execute(battler) unless @hit.include?(battler)
  4192.           # check explosion if exploding skill/item
  4193.           check_explosion(battler) if @explode_id
  4194.           # stop iteration if not considering all targets
  4195.           break if !consider_all
  4196.         end}
  4197.   end
  4198.   #----------------------------------------------------------------------------
  4199.   # check_explosion
  4200.   #  battler - the map battler around which the skill explodes
  4201.   #  Checks and executes exploding skills/items.
  4202.   #----------------------------------------------------------------------------
  4203.   def check_explosion(battler = @target)
  4204.     # iterate through all map battlers
  4205.     ($game_map.battlers + $BlizzABS.battlers).each {|ch|
  4206.         # get differences in coordinates
  4207.         dx, dy = ch.real_x-battler.real_x, ch.real_y-battler.real_y
  4208.         # create affection area shape
  4209.         area = Circle.new(battler.real_x / 4 + 16, battler.real_y / 4 + 16,
  4210.             @explode_range * 32, 0)
  4211.         # create target position rectangle
  4212.         rect = ch.hitbox
  4213.         # if target can be hit and not already hit
  4214.         if ch.battler != nil && @group.include?(ch.ai.group) &&
  4215.             @dead_type == ch.battler.dead? &&
  4216.             $BlizzABS.util.intersection(area, rect) && !@hit.include?(ch)
  4217.           # execute action unless already hit
  4218.           execute(ch)
  4219.           # override with explosion animation if using animations
  4220.           ch.animation_id = @explode_id if BlizzABS::Config::ANIMATIONS
  4221.         end}
  4222.   end
  4223.   #----------------------------------------------------------------------------
  4224.   # turn_toward_target
  4225.   #  Same as turn_towards_player, but turning toward the destination.
  4226.   #----------------------------------------------------------------------------
  4227.   def turn_toward_target
  4228.     # get pixel movement rate
  4229.     pix = $BlizzABS.pixel
  4230.     # calculate the differences
  4231.     dx, dy = @real_x*pix/128-@x, @real_y*pix/128-@y
  4232.     # check the differences
  4233.     if dx < 0 && dx.abs >= dy.abs # target is right
  4234.       turn_right
  4235.     elsif dx > 0 && dx.abs >= dy.abs # target is left
  4236.       turn_left
  4237.     elsif dy < 0 # target is down
  4238.       turn_down
  4239.     elsif dy > 0 # target is up
  4240.       turn_up
  4241.     end
  4242.   end
  4243.   #----------------------------------------------------------------------------
  4244.   # out_of_screen?
  4245.   #  add - how much extra out of the screen is allowed.
  4246.   #  Quick test if the projectile is out of the visible screen.
  4247.   #----------------------------------------------------------------------------
  4248.   def out_of_screen?(add = 0)
  4249.     return (self.real_x - $game_map.display_x + add < 0 ||
  4250.             self.real_x - $game_map.display_x + add > 2560 ||
  4251.             self.real_y - $game_map.display_y + add < 0 ||
  4252.             self.real_y - $game_map.display_y + add > 1920)
  4253.   end
  4254.  
  4255. end
  4256.  
  4257. #==============================================================================
  4258. # Map_Projectile
  4259. #------------------------------------------------------------------------------
  4260. #  This class handles projectiles used in battle. It is based on the remote
  4261. #  system.
  4262. #==============================================================================
  4263.  
  4264. class Map_Projectile < Map_Remote
  4265.  
  4266.   # setting all accessible variables
  4267.   attr_reader :type
  4268.   attr_reader :group
  4269.   #----------------------------------------------------------------------------
  4270.   # Initialization
  4271.   #  character_name - spriteset file name
  4272.   #  creator        - character that created the projectile or item
  4273.   #  id             - skill id
  4274.   #  distance       - how far can it go
  4275.   #  speed          - moving speed of the projectile
  4276.   #  type           - which specific type of projectile
  4277.   #  target_group   - which battler groups to target
  4278.   #  dead_type      - dead or non-dead targets
  4279.   #  explode        - exploding or not
  4280.   #----------------------------------------------------------------------------
  4281.   def initialize(character_name, creator, id, distance, speed, type,
  4282.                  target_group, dead_type = false, explode = nil)
  4283.     # call superclass method without arguments
  4284.     super(character_name, creator, id, type, target_group, dead_type, explode)
  4285.     # move in creator's facing direction slightly
  4286.     case creator.direction
  4287.     when 2 then @real_y += 64
  4288.     when 4 then @real_x -= 64
  4289.     when 6 then @real_x += 64
  4290.     when 8 then @real_y -= 64
  4291.     end
  4292.     # normal moving speed
  4293.     @normal_speed = speed
  4294.     # if distance is a fixed target
  4295.     if distance.is_a?(Game_Character)
  4296.       # set target and speed
  4297.       @target, @move_speed = distance, @normal_speed - 2
  4298.       # set projectile range
  4299.       d = ($BlizzABS.pixel == 1 ? 1 : 2)
  4300.     else
  4301.       # set target and speed
  4302.       @target, @move_speed = nil, @normal_speed
  4303.       # set projectile range
  4304.       d = ((distance - 1) * $BlizzABS.pixel).to_i
  4305.     end
  4306.     @move_speed = 1 if @move_speed < 1
  4307.     # set up final position depending on creator's facing direction
  4308.     case creator.direction
  4309.     when 2 then @y += d
  4310.     when 4 then @x -= d
  4311.     when 6 then @x += d
  4312.     when 8 then @y -= d
  4313.     end
  4314.     # create array of caught items
  4315.     @items = []
  4316.     # freeze player's action in case of returning projectile
  4317.     @creator.freeze_action = (@type == BlizzABS::REMReturning)
  4318.     # helping variable
  4319.     @accelerate = 0
  4320.   end
  4321.   #--------------------------------------------------------------------------
  4322.   # update
  4323.   #  Processes projectile movement.
  4324.   #--------------------------------------------------------------------------
  4325.   def update
  4326.     # abort if still requesting to be created
  4327.     return unless requesting?
  4328.     # update speed
  4329.     update_speed
  4330.     # update target related data
  4331.     update_target
  4332.     # turn toward the target position
  4333.     turn_toward_target
  4334.     # update projectile behavior
  4335.     update_projectile
  4336.     # call superclass method
  4337.     super
  4338.   end
  4339.   #----------------------------------------------------------------------------
  4340.   # update_speed
  4341.   #  Updates speed additions.
  4342.   #----------------------------------------------------------------------------
  4343.   def update_speed
  4344.     # if accelerating counter
  4345.     if @accelerate > 0
  4346.       # decrease accelerating counter
  4347.       @accelerate -= 1
  4348.       # accelerate if accelerating counter expired
  4349.       @move_speed = @normal_speed if @accelerate == 0
  4350.     end
  4351.     # additional stop animation updates depending on speed
  4352.     number = @move_speed - 2
  4353.     number = 1 if number < 1
  4354.     (number < 3 ? number : 3).times {update_stop}
  4355.   end
  4356.   #----------------------------------------------------------------------------
  4357.   # update_target
  4358.   #  Updates target related data.
  4359.   #----------------------------------------------------------------------------
  4360.   def update_target
  4361.     # get pixel movement rate
  4362.     pix = $BlizzABS.pixel
  4363.     # find target or return to creator depending on the type
  4364.     case @type
  4365.     when BlizzABS::REMOnReturn then @x, @y = @creator.x, @creator.y
  4366.     when BlizzABS::REMHomingSkill, BlizzABS::REMHomingItem
  4367.       @x, @y = @target.x, @target.y
  4368.     end
  4369.     # if special type and very close to target
  4370.     if (@type == BlizzABS::REMOnReturn || @type == BlizzABS::REMHomingSkill ||
  4371.         @type == BlizzABS::REMHomingItem) &&
  4372.         Math.hypot(@x * 32 / pix - @real_x / 4, @y * 32 / pix - @real_y / 4) <= 8
  4373.       # set to target's position
  4374.       moveto(@x / pix, @y / pix)
  4375.     end
  4376.   end
  4377.   #----------------------------------------------------------------------------
  4378.   # update_projectile
  4379.   #  Updates additional projectile behavior.
  4380.   #----------------------------------------------------------------------------
  4381.   def update_projectile
  4382.     # if not moving or out of screen or non-homing projectile hitting a wall
  4383.     if !moving? || out_of_screen?(128) ||
  4384.         !BlizzABS::REMHomingBase.include?(@type) &&
  4385.         BlizzABS::Config::WALL_TAGS.include?(self.terrain_tag)
  4386.       # which internal type of projectile
  4387.       case @type
  4388.       when BlizzABS::REMReturning
  4389.         # returning projectile returns now
  4390.         @type = BlizzABS::REMOnReturn
  4391.         # set coordinates to creator's
  4392.         @x, @y = @creator.x, @creator.y
  4393.         # slow down and set acceleration count
  4394.         @move_speed, @accelerate = @normal_speed - 1, 5
  4395.       # homing skill projectile ready for pursuit
  4396.       when BlizzABS::REMInitSkill
  4397.         @type, @move_speed = BlizzABS::REMHomingSkill, @normal_speed - 1
  4398.         @accelerate = 9
  4399.       # homing item projectile ready for pursuit
  4400.       when BlizzABS::REMInitItem
  4401.         @type, @move_speed = BlizzABS::REMHomingItem, @normal_speed - 1
  4402.         @accelerate = 9
  4403.       # homing projectile hit the target
  4404.       when BlizzABS::REMHomingSkill, BlizzABS::REMHomingItem
  4405.         # execute skill/item
  4406.         execute if !@hit.include?(@target)
  4407.         # check explosion if exploding skill/item
  4408.         check_explosion(self) if @explode_id
  4409.       else
  4410.         # check explosion if exploding skill/item and hit a wall
  4411.         if (@explode_id && BlizzABS::Config::WALL_TAGS.include?(self.terrain_tag))
  4412.           check_explosion(self)
  4413.         end
  4414.         # set termination flag
  4415.         @terminate = true
  4416.         # set all caught items' new position
  4417.         @items.each {|i| i.moveto((@real_x + 64) / 128, (@real_y + 64) / 128)}
  4418.         # unfreeze creator action
  4419.         @creator.freeze_action = false
  4420.         # check drop item
  4421.         check_drop
  4422.       end
  4423.       # correct moving speed
  4424.       @move_speed = 1 if @move_speed < 1
  4425.     end
  4426.   end
  4427.   #----------------------------------------------------------------------------
  4428.   # update_execution
  4429.   #  Updates the execution.
  4430.   #----------------------------------------------------------------------------
  4431.   def update_execution
  4432.     # if homing projetile that is pursuing a target
  4433.     if BlizzABS::REMHomingBase.include?(@type)
  4434.       # if target's and projectile's rectangles intersect
  4435.       if @target.valid? && $BlizzABS.util.intersection(effect_area,
  4436.           @target.hitbox)
  4437.         # execute action
  4438.         execute if !@hit.include?(@target)
  4439.         # check explosion if exploding skill/item
  4440.         check_explosion if @explode_id
  4441.       end
  4442.     # if not out of screen at all
  4443.     elsif !out_of_screen?
  4444.       # update skill fading
  4445.       update_skill_fade
  4446.       # update items that are being returned
  4447.       update_returning_items
  4448.       # call superclass method
  4449.       super
  4450.     end
  4451.   end
  4452.   #----------------------------------------------------------------------------
  4453.   # update_skill_fade
  4454.   #  Updates fading away effect for expiring skills.
  4455.   #----------------------------------------------------------------------------
  4456.   def update_skill_fade
  4457.     # get pixel movement rate
  4458.     pix = $BlizzABS.pixel
  4459.     # if moving and not returning projectile and close to final position
  4460.     if moving? && !BlizzABS::REMHomingExtend.include?(@type) &&
  4461.        (@real_x - @x * 128 / pix).abs < 128 && (@real_y - @y * 128 / pix).abs < 128
  4462.       # slow down
  4463.       @move_speed = @normal_speed - 1
  4464.       # correct moving speed
  4465.       @move_speed = 1 if @move_speed < 1
  4466.       # if skill
  4467.       if @type == BlizzABS::REMNormalSkill || @type == BlizzABS::REMBreakSkill
  4468.         # start fade out
  4469.         @fade_out = true
  4470.       end
  4471.     end
  4472.     # if exploding and set to explode at end of path
  4473.     if @fade_out && @explode_id && @explode_type != BlizzABS::EXPLTarget
  4474.       # explode
  4475.       check_explosion(self)
  4476.     end
  4477.   end
  4478.   #----------------------------------------------------------------------------
  4479.   # update_returning_items
  4480.   #  Updates items that are being move by returning projectiles.
  4481.   #----------------------------------------------------------------------------
  4482.   def update_returning_items
  4483.     # if not using corpses and not terminated returning projectile
  4484.     if !BlizzABS::Config::CORPSES && @type == BlizzABS::REMOnReturn &&
  4485.         !@terminate
  4486.       # iterate through all events without added items
  4487.       ($game_map.events_only - @items).each {|event|
  4488.           # if caught dropped item
  4489.           if event.dropped? && @creator == $game_player &&
  4490.               $BlizzABS.util.intersection(effect_area, event.hitbox)#Rect.new(event.real_x/4,
  4491.               #event.real_y / 4, 32, 32))
  4492.             # add item into caught items array
  4493.             @items.push(event)
  4494.           end}
  4495.       # set all caught items' new position
  4496.       @items.each {|i| i.set_real_position(@real_x, @real_y)}
  4497.     end
  4498.   end
  4499.   #----------------------------------------------------------------------------
  4500.   # check_drop
  4501.   #  Checks if the projectile needs to leave a dropped item.
  4502.   #----------------------------------------------------------------------------
  4503.   def check_drop
  4504.     # get pixel movement rate
  4505.     pix = $BlizzABS.pixel
  4506.     # if dropping ammo active and floor beneath
  4507.     if BlizzABS::Config::DROP_AMMO &&
  4508.         !BlizzABS::Config::NO_FLOOR_TAGS.include?(
  4509.         $game_map.terrain_tag(@x / pix, @y / pix))
  4510.       # depending on type, drop a weapon/item
  4511.       case @type
  4512.       when BlizzABS::REMShotItem, BlizzABS::REMNormalItem,
  4513.            BlizzABS::REMBreakItem
  4514.         $BlizzABS.drop_event([$data_items[@id]], @real_x + 64, @real_y + 64)
  4515.       when BlizzABS::REMShotWeapon
  4516.         $BlizzABS.drop_event([$data_weapons[@id]], @real_x + 64, @real_y + 64)
  4517.       end
  4518.     end
  4519.   end
  4520.   #----------------------------------------------------------------------------
  4521.   # effect_area
  4522.   #  Creates own effect area for convenience.
  4523.   #----------------------------------------------------------------------------
  4524.   def effect_area
  4525.     return Rect.new(@real_x / 4 + 8, @real_y / 4 + 8, 16, 16)
  4526.   end
  4527.   #----------------------------------------------------------------------------
  4528.   # update?
  4529.   #  Overrides ABSEAL. Projectiles get terminated as soon as the get out of the
  4530.   #  screen and traps stay on the map like dropped objects.
  4531.   #----------------------------------------------------------------------------
  4532.   def update?
  4533.     return true
  4534.   end
  4535.  
  4536. end
  4537.  
  4538. #==============================================================================
  4539. # Map_Trap
  4540. #------------------------------------------------------------------------------
  4541. #  This class handles traps used in battle. It is based on the remote system.
  4542. #==============================================================================
  4543.  
  4544. class Map_Trap < Map_Remote
  4545.  
  4546.   # setting all accessible variables
  4547.   attr_reader :type
  4548.   attr_reader :group
  4549.   #----------------------------------------------------------------------------
  4550.   # Initialization
  4551.   #  character_name - spriteset file name
  4552.   #  creator        - character that created the projectile or item
  4553.   #  id             - skill id
  4554.   #  distance       - how far can it go
  4555.   #  time           - how long it stays on the map
  4556.   #  type           - which specific type of projectile
  4557.   #  target_group   - which battler groups to target
  4558.   #  dead_type      - dead or non-dead targets
  4559.   #  explode        - exploding or not
  4560.   #----------------------------------------------------------------------------
  4561.   def initialize(character_name, creator, id, distance, time, type,
  4562.                  target_group, dead_type = false, explode = nil)
  4563.     # call superclass method without arguments
  4564.     super(character_name, creator, id, type, target_group, dead_type, explode)
  4565.     # set distance and time in frames
  4566.     @distance, @time = distance, time * 40
  4567.     # store affection area
  4568.     @area = Circle.new(@real_x/4 + 16, @real_y/4 + 16, @distance * 32, 0)
  4569.   end
  4570.   #--------------------------------------------------------------------------
  4571.   # update
  4572.   #  Processes projectile movement.
  4573.   #--------------------------------------------------------------------------
  4574.   def update
  4575.     # abort if still requesting to be created
  4576.     return if !requesting? || !update?
  4577.     # set termination flag if trap expired
  4578.     @terminate = true if @time <= 0
  4579.     # decrease timer
  4580.     @time -= 1
  4581.     # call superclass method
  4582.     super
  4583.   end
  4584.   #----------------------------------------------------------------------------
  4585.   # effect_area
  4586.   #  Creates own effect area for convenience.
  4587.   #----------------------------------------------------------------------------
  4588.   def effect_area
  4589.     return @area
  4590.   end
  4591.  
  4592. end
  4593.  
  4594. #==============================================================================
  4595. # Map_Timed
  4596. #------------------------------------------------------------------------------
  4597. #  This class handles timed traps used in battle. It is based on normal traps.
  4598. #==============================================================================
  4599.  
  4600. class Map_Timed < Map_Trap
  4601.  
  4602.   #--------------------------------------------------------------------------
  4603.   # update
  4604.   #  Processes projectile movement.
  4605.   #--------------------------------------------------------------------------
  4606.   def update
  4607.     # abort if still requesting to be created
  4608.     return if !requesting? || !update?
  4609.     # if trap expired
  4610.     if @time <= 0
  4611.       # execute the timed trap
  4612.       update_execution(true)
  4613.       # execute upon self for animation
  4614.       execute(self)
  4615.       # set termination flag
  4616.       @terminate = true
  4617.     end
  4618.     # decrease timer
  4619.     @time -= 1
  4620.     # call superclass method
  4621.     super
  4622.   end
  4623.   #----------------------------------------------------------------------------
  4624.   # update_execution
  4625.   #  override - the override flag
  4626.   #  Updates the execution.
  4627.   #----------------------------------------------------------------------------
  4628.   def update_execution(override = false)
  4629.     # update only if overriding
  4630.     super(true) if override
  4631.   end
  4632.  
  4633. end
  4634.  
  4635. #==============================================================================
  4636. # Bitmap
  4637. #------------------------------------------------------------------------------
  4638. #  This class was enhanced with methods to support the drawing of gradient bars
  4639. #  and outlined text.
  4640. #==============================================================================
  4641.  
  4642. class Bitmap
  4643.  
  4644.   #----------------------------------------------------------------------------
  4645.   # gradient_bar_hud
  4646.   #  x          - x-coordinate
  4647.   #  y          - y-coordinate
  4648.   #  w          - width
  4649.   #  rate       - fill rate
  4650.   #  image_key  - image key for image used for drawing or two images
  4651.   #  change_hue - changing hue on changing fill rate
  4652.   #  Draws the HUD gradient bar.
  4653.   #----------------------------------------------------------------------------
  4654.   def gradient_bar_hud(x, y, w, rate, image_key, change_hue = 0)
  4655.     # if own bitmaps used
  4656.     if image_key.is_a?(Array)
  4657.       # set HUD bitmap
  4658.       bitmap = image_key[1]
  4659.       # draw stretched bitmap onto HUD
  4660.       stretch_blt(Rect.new(x+1, y+1, w, 12), bitmap, Rect.new(0, 0, 1, 12))
  4661.       # set HUD bitmap
  4662.       bitmap = image_key[0]
  4663.     else
  4664.       # get empty HUD bitmap
  4665.       bitmap = $BlizzABS.cache.image('empty_' + image_key)
  4666.       # draw stretched bitmap onto HUD
  4667.       stretch_blt(Rect.new(x+1, y+1, w, 12), bitmap, Rect.new(0, 0, 1, 12))
  4668.       # get HUD bitmap
  4669.       bitmap = $BlizzABS.cache.image(image_key)
  4670.     end
  4671.     # if requested hue changing bar
  4672.     if change_hue > 0
  4673.       # change hue of bitmap according to fill rate
  4674.       bitmap.hue_change((change_hue - 1.5).sgn * (1.25 - rate / 0.8) * 120 /
  4675.           (change_hue ** 2))
  4676.     end
  4677.     # draw stretched bitmap onto HUD
  4678.     stretch_blt(Rect.new(x+1, y+1, w*rate, 12), bitmap, Rect.new(0, 0, 1, 12))
  4679.   end
  4680.   #----------------------------------------------------------------------------
  4681.   # draw_circle
  4682.   #  x     - x-coordinate
  4683.   #  y     - y-coordinate
  4684.   #  rad   - radius of the circle
  4685.   #  color - fill color
  4686.   #  Draws a circle.
  4687.   #----------------------------------------------------------------------------
  4688.   def draw_circle(x, y, rad, color)
  4689.     # iterate from center to right border
  4690.     (0...rad).each {|r|
  4691.         # calculate y-coordinate from x-coordinate via trigonometric functions
  4692.         h = (rad * Math.sin(Math.acos(r/rad.to_f))).to_i
  4693.         # draw vertical bar
  4694.         fill_rect(x+rad-r-1, y+rad-h, 1, h*2+1, color)
  4695.         # draw identical vertical bar on the left side
  4696.         fill_rect(x+rad+r, y+rad-h, 1, h*2+1, color)}
  4697.   end
  4698.   #----------------------------------------------------------------------------
  4699.   # draw_text_full
  4700.   # x2    - x-coordinate
  4701.   # y2    - y-coordinate
  4702.   # w2    - width
  4703.   # h2    - height
  4704.   # text2 - text
  4705.   # a2    - align
  4706.   #  Uses an aliased version of draw_text to draw outlined text.
  4707.   #----------------------------------------------------------------------------
  4708.   # if method not aliased already
  4709.   if $tons_version == nil || $tons_version < 1.6
  4710.     # alias original method
  4711.     alias draw_text_shaded_later draw_text
  4712.   end
  4713.   def draw_text_full(x2, y2, w2 = 0, h2 = 0, text2 = '', a2 = 0)
  4714.     # if x2 is a rectangle
  4715.     if x2.is_a?(Rect)
  4716.       # set temporary variables
  4717.       x, y, w, h, text, a = x2.x, x2.y, x2.width, x2.height, y2, w2
  4718.     else
  4719.       # set temporary variables
  4720.       x, y, w, h, text, a = x2, y2, w2, h2, text2, a2
  4721.     end
  4722.     # save old font color
  4723.     save_color = self.font.color.clone
  4724.     # set new font color (black)
  4725.     self.font.color = Color.new(0, 0, 0)
  4726.     # draw text with offsets in all directions
  4727.     [x-1, x+1].each {|xx| [y-1, y+1].each {|yy|
  4728.             draw_text_shaded_later(xx, yy, w, h, text, a)}}
  4729.     # restore original color
  4730.     self.font.color = save_color
  4731.     # drw text at normal postion
  4732.     draw_text_shaded_later(x, y, w, h, text, a)
  4733.   end
  4734.  
  4735. end
  4736.  
  4737. #==============================================================================
  4738. # RPG::Sprite
  4739. #------------------------------------------------------------------------------
  4740. #  This class was modified so the loop animation ID can be read.
  4741. #==============================================================================
  4742.  
  4743. class RPG::Sprite
  4744.  
  4745.   attr_reader :loop_animation_id
  4746.  
  4747. end
  4748.  
  4749. #==============================================================================
  4750. # Sprite_Character
  4751. #------------------------------------------------------------------------------
  4752. #  This class was modified to support loop animations and custom frame numbers.
  4753. #==============================================================================
  4754.  
  4755. class Sprite_Character
  4756.  
  4757.   #----------------------------------------------------------------------------
  4758.   # override update
  4759.   #----------------------------------------------------------------------------
  4760.   alias upd_player_blizzabs_later update
  4761.   def update
  4762.     # check if there will be a change
  4763.     change = (@tile_id != @character.tile_id ||
  4764.         @character_name != @character.character_name ||
  4765.         @character_hue != @character.character_hue)
  4766.     # call original method
  4767.     upd_player_blizzabs_later
  4768.     # if changed and valid bitmap and valid character
  4769.     if change && self.bitmap != nil && @character != nil && @tile_id < 384
  4770.       # if graphic is an icon
  4771.       if @icon
  4772.         # use whole image
  4773.         @cw, @ch = self.bitmap.width, self.bitmap.height
  4774.         # zero offset
  4775.         self.ox, self.oy = 0, 0
  4776.         # change source rectangle position
  4777.         self.src_rect.x, self.src_rect.y = 0, 0
  4778.         # change source rectangle dimensions
  4779.         self.src_rect.width, self.src_rect.height = @cw, @ch
  4780.       # if graphic is not an icon
  4781.       else
  4782.         # change frame width
  4783.         @cw = self.bitmap.width / @character.pattern_size
  4784.         # change offset
  4785.         self.ox = @cw / 2
  4786.         # center sprite
  4787.         self.oy = @ch / 2 + 16 if @character.center_sprite
  4788.         # change source rectangle x
  4789.         self.src_rect.x = @character.pattern * @cw
  4790.         # change source rectangle width
  4791.         self.src_rect.width = @cw
  4792.       end
  4793.     end
  4794.     # if animation ID is different than current one
  4795.     if @character.loop_animation_id != @loop_animation_id
  4796.       # store new ID
  4797.       @loop_animation_id = @character.loop_animation_id
  4798.       # show animation loop
  4799.       loop_animation($data_animations[@loop_animation_id])
  4800.     end
  4801.   end
  4802.  
  4803. end
  4804.  
  4805. #==============================================================================
  4806. # Sprite_CharacterDrop
  4807. #------------------------------------------------------------------------------
  4808. #  This class was modified to support animation sprites and dropped item icon
  4809. #  display.
  4810. #==============================================================================
  4811.  
  4812. class Sprite_CharacterDrop < RPG::Sprite
  4813.  
  4814.   # setting all accessible variables
  4815.   attr_accessor :character
  4816.   #----------------------------------------------------------------------------
  4817.   # Initialization
  4818.   #----------------------------------------------------------------------------
  4819.   def initialize(viewport, character)
  4820.     # call original method
  4821.     super(viewport)
  4822.     # set the character
  4823.     @character = character
  4824.     # cache new icon bitmap
  4825.     self.bitmap = RPG::Cache.icon(@character.character_name)
  4826.     # set x and y position offset
  4827.     self.ox, self.oy = self.bitmap.width / 2, self.bitmap.height
  4828.   end
  4829.   #--------------------------------------------------------------------------
  4830.   # * Frame Update
  4831.   #--------------------------------------------------------------------------
  4832.   def update
  4833.     # call superclass method
  4834.     super
  4835.     # set x and y position
  4836.     self.x, self.y = @character.screen_x, @character.screen_y
  4837.     # set z position
  4838.     self.z = @character.screen_z(self.bitmap.height / 4) + 31
  4839.   end
  4840.  
  4841. end
  4842.  
  4843. #==============================================================================
  4844. # Sprite_CharacterCombo
  4845. #------------------------------------------------------------------------------
  4846. #  This class additionally displays the combo sprite and animation
  4847. #==============================================================================
  4848.  
  4849. class Sprite_CharacterCombo < RPG::Sprite
  4850.  
  4851.   # setting all accessible variables
  4852.   attr_accessor :character
  4853.   attr_accessor :combo_sprite
  4854.   #----------------------------------------------------------------------------
  4855.   # Initialization
  4856.   #----------------------------------------------------------------------------
  4857.   def initialize(viewport, character)
  4858.     # call original method
  4859.     super(viewport)
  4860.     # set the character
  4861.     @character = character
  4862.     # setup the sprite
  4863.     setup
  4864.     # update
  4865.     update
  4866.   end
  4867.   #--------------------------------------------------------------------------
  4868.   # setup
  4869.   #  Sets up the sprite.
  4870.   #--------------------------------------------------------------------------
  4871.   def setup
  4872.     # get the sprite file name
  4873.     @combo_sprite = ''
  4874.     @combo_sprite = @character.character_name_org if @character.combo.extension
  4875.     @combo_sprite += @character.combo.sprite
  4876.     # get the animation id
  4877.     @loop_animation_id = @character.combo.animation
  4878.     # if sprite
  4879.     if @combo_sprite != ''
  4880.       # load bitmap
  4881.       self.bitmap = RPG::Cache.character(@combo_sprite, 0)
  4882.     # no sprite
  4883.     else
  4884.       # dummy bitmap
  4885.       self.bitmap = Bitmap.new(1, 1)
  4886.     end
  4887.     # get dimesions
  4888.     @cw = bitmap.width / @character.combo.animation_frames.size
  4889.     @ch = bitmap.height / 4
  4890.     # set offsets accordingly
  4891.     self.ox = @cw / 2
  4892.     self.oy = @ch / 2 + 16
  4893.     # set source rectangle
  4894.     self.src_rect.set(0, 0, @cw, @ch)
  4895.   end
  4896.   #--------------------------------------------------------------------------
  4897.   # update
  4898.   #  Updates the sprite.
  4899.   #--------------------------------------------------------------------------
  4900.   def update
  4901.     # call superclass method
  4902.     super
  4903.     # set visible
  4904.     self.visible = (not @character.transparent)
  4905.     # set next source rectangle
  4906.     sx = @character.pattern * @cw
  4907.     sy = (@character.direction - 2) / 2 * @ch
  4908.     self.src_rect.set(sx, sy, @cw, @ch)
  4909.     # set sprite coordinates
  4910.     self.x = @character.screen_x
  4911.     self.y = @character.screen_y
  4912.     self.z = @character.screen_z(@ch) + 1
  4913.     # set opacity level
  4914.     self.opacity = @character.opacity
  4915.     # set blend method
  4916.     self.blend_type = @character.blend_type
  4917.     # set bush depth
  4918.     self.bush_depth = @character.bush_depth
  4919.     # if animation
  4920.     if @loop_animation_id != 0
  4921.       # play animation
  4922.       animation($data_animations[@loop_animation_id], true)
  4923.       # reset animation
  4924.       @loop_animation_id = 0
  4925.     end
  4926.   end
  4927.  
  4928. end
  4929.  
  4930. #==============================================================================
  4931. # Sprite_CharacterWeapon
  4932. #------------------------------------------------------------------------------
  4933. #  This class additionally displays the weapon sprite
  4934. #==============================================================================
  4935.  
  4936. class Sprite_CharacterWeapon < RPG::Sprite
  4937.  
  4938.   # setting all accessible variables
  4939.   attr_accessor :character
  4940.   #----------------------------------------------------------------------------
  4941.   # Initialization
  4942.   #----------------------------------------------------------------------------
  4943.   def initialize(viewport, character)
  4944.     # call original method
  4945.     super(viewport)
  4946.     # set the character
  4947.     @character = character
  4948.     # get the sprite file name
  4949.     weapon_sprite = @character.character_name_org + @character.weapon_sprite
  4950.     # load bitmap
  4951.     self.bitmap = RPG::Cache.character(weapon_sprite, 0)
  4952.     # get dimesions
  4953.     @cw = bitmap.width / @character.pattern_size
  4954.     @ch = bitmap.height / 4
  4955.     # set offsets accordingly
  4956.     self.ox = @cw / 2
  4957.     self.oy = @ch / 2 + 16
  4958.     # set source rectangle
  4959.     self.src_rect.set(0, 0, @cw, @ch)
  4960.     # upadte
  4961.     update
  4962.   end
  4963.   #--------------------------------------------------------------------------
  4964.   # update
  4965.   #  Updates the sprite.
  4966.   #--------------------------------------------------------------------------
  4967.   def update
  4968.     # call superclass method
  4969.     super
  4970.     # set visible
  4971.     self.visible = (not @character.transparent)
  4972.     # set next source rectangle
  4973.     sx = @character.pattern * @cw
  4974.     sy = (@character.direction - 2) / 2 * @ch
  4975.     self.src_rect.set(sx, sy, @cw, @ch)
  4976.     # set sprite coordinates
  4977.     self.x = @character.screen_x
  4978.     self.y = @character.screen_y
  4979.     self.z = @character.screen_z(@ch)
  4980.     # set opacity level
  4981.     self.opacity = @character.opacity
  4982.     # set blend method
  4983.     self.blend_type = @character.blend_type
  4984.     # set bush depth
  4985.     self.bush_depth = @character.bush_depth
  4986.   end
  4987.  
  4988. end
  4989.  
  4990. #==============================================================================
  4991. # Sprite_Damage
  4992. #------------------------------------------------------------------------------
  4993. #  This class provides damage sprite display in Blizz-ABS.
  4994. #==============================================================================
  4995.  
  4996. class Sprite_Damage < Sprite
  4997.  
  4998.   #----------------------------------------------------------------------------
  4999.   # Initialization
  5000.   #----------------------------------------------------------------------------
  5001.   def initialize(request, viewport = nil)
  5002.     # call superclass method
  5003.     super(viewport)
  5004.     # draw the damage
  5005.     draw_damage(request)
  5006.     # set map offsets
  5007.     @map_x, @map_y = request.x, request.y
  5008.     # set position right
  5009.     self.z = 1
  5010.     # radians of direction vector
  5011.     rad = rand(360) * Math::PI / 180
  5012.     # vector length
  5013.     @vx, @vy = -Math.cos(rad) * 3, Math.sin(rad) * 2
  5014.     # display counter
  5015.     @counter = Math::PI
  5016.     # updatet the sprite
  5017.     update
  5018.   end
  5019.   #----------------------------------------------------------------------------
  5020.   # update
  5021.   #  Updates the sprite's movement over the screen.
  5022.   #----------------------------------------------------------------------------
  5023.   def update
  5024.     # calculate offset if map display position has changed
  5025.     self.x = @map_x - self.bitmap.width / 2 - $game_map.display_x / 4
  5026.     self.y = @map_y - self.bitmap.height / 2 - $game_map.display_y / 4
  5027.     # set new offsets
  5028.     self.ox, self.oy = @vx * (@counter - Math::PI), @vy * (@counter - Math::PI)
  5029.     # increased counter
  5030.     @counter += 1
  5031.     # if using bouncing damage display
  5032.     if BlizzABS::Config::BOUNCING_DAMAGE
  5033.       # sinc function
  5034.       self.oy += (Math.sin((@counter - Math::PI) / 5.0) * 800 / (@counter)).abs
  5035.       # decrease opacity if counter high enough
  5036.       self.opacity -= 15 if @counter > 35
  5037.     else
  5038.       # wider sinc function
  5039.       self.oy += (Math.sin((@counter - Math::PI) / 10.0) * 1200 / (@counter)).abs
  5040.       # decrease opacity if counter high enough
  5041.       self.opacity -= 15 if @counter > 15
  5042.     end
  5043.     # if critical and each second frame
  5044.     if @critical && Graphics.frame_count % 2 == 0
  5045.       # make hue change animation
  5046.       self.bitmap.hue_change(60)
  5047.     end
  5048.   end
  5049.   #----------------------------------------------------------------------------
  5050.   # damage
  5051.   #  request - the damage sprite request
  5052.   #  Creates a damage text bitmap.
  5053.   #----------------------------------------------------------------------------
  5054.   def draw_damage(request)
  5055.     # get request data
  5056.     w, h = request.width, request.height
  5057.     # increase width a bit if italic text
  5058.     w += BlizzABS::Cache::FontSizeDamage / 6 if BlizzABS::Cache::FontItalicDamage
  5059.     # increase width a bit if bold text
  5060.     w += BlizzABS::Cache::FontSizeDamage / 6 if BlizzABS::Cache::FontBoldDamage
  5061.     # create real bitmap
  5062.     self.bitmap = Bitmap.new(w, h)
  5063.     # set font
  5064.     self.bitmap.font.name = BlizzABS::Cache::FontNameDamage
  5065.     # set font size
  5066.     self.bitmap.font.size = BlizzABS::Cache::FontSizeDamage
  5067.     # set font color
  5068.     self.bitmap.font.color = BlizzABS::Cache::DMGColors['Shadow']
  5069.     # set font italic
  5070.     self.bitmap.font.italic = BlizzABS::Cache::FontItalicDamage
  5071.     # set font bold
  5072.     self.bitmap.font.bold = BlizzABS::Cache::FontBoldDamage
  5073.     # draw text with offsets in all directions
  5074.     self.bitmap.draw_text_shaded_later(-1, -1, w, h, request.damage, 1)
  5075.     self.bitmap.draw_text_shaded_later(2, 2, w, h, request.damage, 1)
  5076.     self.bitmap.draw_text_shaded_later(2, -1, w, h, request.damage, 1)
  5077.     self.bitmap.draw_text_shaded_later(-1, 2, w, h, request.damage, 1)
  5078.     # get damage color
  5079.     self.bitmap.font.color = request.color
  5080.     # draw damage string
  5081.     self.bitmap.draw_text_shaded_later(0, 0, w, h, request.damage, 1)
  5082.     # set critical flag
  5083.     @critical = request.critical
  5084.   end
  5085.  
  5086. end
  5087.  
  5088. #==============================================================================
  5089. # Control_Sprite_Character
  5090. #------------------------------------------------------------------------------
  5091. #  This class is an interception class for Sprite_Character. It substitutes its
  5092. #  instances everywhere and handles them. It provides ABSEAL limitation
  5093. #  control, damage sprite control and enemy fade_in/dying animations.
  5094. #  It disposes sprites out of the ABSEAL range immediately.
  5095. #==============================================================================
  5096.  
  5097. class Control_Sprite_Character
  5098.  
  5099.   # setting all accessible variables
  5100.   attr_accessor :fade_in
  5101.   attr_accessor :dying
  5102.   attr_accessor :respawning
  5103.   attr_accessor :fade_out
  5104.   attr_accessor :select
  5105.   attr_reader   :character
  5106.   attr_reader   :damage
  5107.   #----------------------------------------------------------------------------
  5108.   # Initialization
  5109.   #  viewport  - a viewport
  5110.   #  character - the character to observe and display
  5111.   #----------------------------------------------------------------------------
  5112.   def initialize(viewport, character = nil)
  5113.     # set all flags
  5114.     @fade_in = @dying = @fade_out = @respawning = false
  5115.     # set select animation mode and health bar width
  5116.     @select = 0
  5117.     # store character
  5118.     self.character = character
  5119.     # store viewport
  5120.     @viewport = viewport
  5121.   end
  5122.   #----------------------------------------------------------------------------
  5123.   # character=
  5124.   #  char - the new character to observe and display
  5125.   #  Gives the character to the sprite as well if it exists.
  5126.   #----------------------------------------------------------------------------
  5127.   def character=(char)
  5128.     # store character
  5129.     @character = char
  5130.     # give character to sprite if sprite exists
  5131.     @sprite.character = char if @sprite != nil
  5132.     # set battler ID
  5133.     @battler_id = (@character.is_a?(Map_Battler) ? @character.battler_id : nil)
  5134.   end
  5135.   #----------------------------------------------------------------------------
  5136.   # update
  5137.   #  Processes sprite update if the sprite exists. If not, it tests if the
  5138.   #  character is within ABSEAL range and creates a sprite. Every sprite
  5139.   #  which's character is outside of ABSEAL gets disposed.
  5140.   #----------------------------------------------------------------------------
  5141.   def update
  5142.     # if character within ABSEAL range or special character
  5143.     if self.character_valid?
  5144.       # if sprite doesn't exists yet
  5145.       if @sprite == nil || @sprite.disposed?
  5146.         # if dropped item needs an icon spriteset
  5147.         if @character.icondrop
  5148.           # create a drop sprite
  5149.           @sprite = Sprite_CharacterDrop.new(@viewport, @character)
  5150.         else
  5151.           # create a sprite
  5152.           @sprite = Sprite_Character_ABSEAL_ed.new(@viewport, @character)
  5153.         end
  5154.         # create health sprite
  5155.         create_health_sprite
  5156.         # update health bar if health bar exists
  5157.         update_health if @health != nil
  5158.       else
  5159.         # if destruction sprite exists
  5160.         if @destruct != nil
  5161.           # update it
  5162.           @destruct.update
  5163.         # if respawning sprite exists
  5164.         elsif @respawn != nil
  5165.           # update it
  5166.           @respawn.update
  5167.         # if map battler
  5168.         elsif @character.is_a?(Map_Battler) && !@character.is_a?(Map_Remote)
  5169.           # if character needs new combo sprite
  5170.           if @character.new_combo_sprite
  5171.             # dispose old sprite if it exists
  5172.             @combo.dispose if @combo != nil
  5173.             # create combo sprite
  5174.             @combo = Sprite_CharacterCombo.new(@viewport, @character)
  5175.             # reset flag
  5176.             @character.new_combo_sprite = false
  5177.           # if still using combo sprite
  5178.           elsif @character.combo != nil && @combo != nil
  5179.             # update combo sprite
  5180.             @combo.update
  5181.           elsif @combo != nil
  5182.             # delete combo sprite
  5183.             @combo.dispose
  5184.             @combo = nil
  5185.           end
  5186.           # if weapon sprite doesn't exist
  5187.           if @weapon == nil
  5188.             # if character using weapon
  5189.             if @character.weapon_sprite != ''
  5190.               # create weapon sprite
  5191.               @weapon = Sprite_CharacterWeapon.new(@viewport, @character)
  5192.             end
  5193.           # if still using weapon sprite
  5194.           elsif @character.weapon_sprite != ''
  5195.             # update weapon sprite
  5196.             @weapon.update
  5197.           else
  5198.             # delete weapon sprite
  5199.             @weapon.dispose
  5200.             @weapon = nil
  5201.           end
  5202.           if @character.ai.act.defend?
  5203.             # show running away animation
  5204.             @character.loop_animation_id = BlizzABS::Config::DEFEND_ANIMATION_ID
  5205.           # if running away
  5206.           elsif @character.ai.act.escape?
  5207.             # show running away animation
  5208.             @character.loop_animation_id = BlizzABS::Config::FLEE_ANIMATION_ID
  5209.           else
  5210.             # set state animation if battler exists
  5211.             @character.loop_animation_id = (@character.battler == nil ? 0 :
  5212.                 @character.battler.state_animation_id)
  5213.           end
  5214.         else
  5215.           # no animation
  5216.           @character.loop_animation_id = 0
  5217.         end
  5218.         # update the sprite itself
  5219.         @sprite.update
  5220.         # update selection animation
  5221.         update_select
  5222.         # if battler exists and not dead
  5223.         if @character.is_a?(Map_Battler) && @character.valid?
  5224.           # create health sprite if health sprite doesn't exist yet
  5225.           create_health_sprite if @health == nil
  5226.           # if Tons of Add-ons is there and using Doom Status with timer
  5227.           if $tons_version != nil && $tons_version >= 6.2 &&
  5228.               $game_system.DOOM_STATUS && DOOM_TIMER_VISIBLE
  5229.             # update doom sprites
  5230.             update_doom_sprites
  5231.           end
  5232.         end
  5233.         # update health bar if health bar exists and character is not dead
  5234.         update_health if @health != nil && !@character.battler.dead?
  5235.       end
  5236.     # if sprite exists
  5237.     elsif @sprite != nil
  5238.       # delete sprite if it exists and not freed yet
  5239.       @sprite.dispose unless @sprite.disposed?
  5240.       # delete health sprite if it exists and not freed yet
  5241.       @health.dispose unless @health == nil || @health.disposed?
  5242.       # delete weapon sprite if it exists and not freed yet
  5243.       @weapon.dispose unless @weapon == nil || @weapon.disposed?
  5244.       # delete doom counter sprite if it exists and not freed yet
  5245.       @doom.dispose unless @doom == nil || @doom.disposed?
  5246.       # remove sprite from memory
  5247.       @sprite = @health = @hp = @weapon = @doom = nil
  5248.     end
  5249.   end
  5250.   #----------------------------------------------------------------------------
  5251.   # character_valid?
  5252.   #  Checks if this sprite should be displayed and updated.
  5253.   #----------------------------------------------------------------------------
  5254.   def character_valid?
  5255.     return (@character.is_a?(Game_Event) || @character.is_a?(Map_Enemy) &&
  5256.         @character.precondition || @character.is_a?(Map_Remote) ||
  5257.         @character.dropped?) && @character.update? ||
  5258.         !@character.is_a?(Map_Enemy) && !@character.is_a?(Map_Remote) &&
  5259.         @character.is_a?(Map_Battler)
  5260.   end
  5261.   #----------------------------------------------------------------------------
  5262.   # update_select
  5263.   #  Updates the animation when selecting a map battler.
  5264.   #----------------------------------------------------------------------------
  5265.   def update_select
  5266.     # stop if the enemy is invisible/has not sprite
  5267.     return if @sprite == nil
  5268.     # if normal blink should be processed
  5269.     if @select == 2
  5270.       # set blink
  5271.       @sprite.blink_on
  5272.     # if selected right now
  5273.     elsif @select == 1
  5274.       # set color with new alpha
  5275.       @sprite.color.set(0, 255, 0, (8 - Graphics.frame_count % 16).abs * 24)
  5276.     else
  5277.       # set to no color
  5278.       @sprite.color.set(0, 0, 0, 0)
  5279.     end
  5280.   end
  5281.   #----------------------------------------------------------------------------
  5282.   # update_doom_sprites
  5283.   #  Updates a counter sprites for the Doom Status Effect.
  5284.   #----------------------------------------------------------------------------
  5285.   def update_doom_sprites
  5286.     # get all doom status effects
  5287.     dooms = @character.battler.states.find_all {|i| DOOM_IDS.include?(i)}
  5288.     # if at least one exists
  5289.     if dooms.size > 0
  5290.       # if sprite doesn't exist yet
  5291.       if @doom == nil
  5292.         # create sprite
  5293.         @doom = Sprite.new
  5294.         # create bitmap
  5295.         @doom.bitmap = Bitmap.new(48, 48)
  5296.         # setup font
  5297.         @doom.bitmap.font.name = DOOM_FONT
  5298.         @doom.bitmap.font.size = DOOM_SIZE
  5299.       end
  5300.       # setup timer coordinates
  5301.       @doom.x, @doom.y = @sprite.x, @sprite.y
  5302.       @doom.ox, @doom.oy = 24, 24
  5303.       @doom.z = @sprite.z + 100
  5304.       # additional coordinate setup
  5305.       case DOOM_TIMER_POSITION
  5306.       when 1 then @doom.y -= @sprite.bitmap.height/4
  5307.       when 2 then @doom.oy /= 2
  5308.       end
  5309.       # if time counter exists and changed
  5310.       if @character.battler.state_time[dooms[0]] != nil &&
  5311.           @time_left != (@character.battler.state_time[dooms[0]]+38) / 40
  5312.         # update timer counter
  5313.         @time_left = (@character.battler.state_time[dooms[0]]+38) / 40
  5314.         # delete display
  5315.         @doom.bitmap.clear
  5316.         # if last turn
  5317.         if @time_left == 0
  5318.           # kill self
  5319.           @character.battler.hp = 0
  5320.         else
  5321.           # draw new timer count
  5322.           @doom.bitmap.draw_text_full(0, 0, 48, 32, @time_left.to_s, 1)
  5323.         end
  5324.       end
  5325.     # if doom sprite exists
  5326.     elsif @doom != nil
  5327.       # delete it
  5328.       @doom.dispose
  5329.       @doom = nil
  5330.     end
  5331.   end
  5332.   #----------------------------------------------------------------------------
  5333.   # create_health_sprite
  5334.   #  Creates a health sprite.
  5335.   #----------------------------------------------------------------------------
  5336.   def create_health_sprite
  5337.     # if health bars active and observing enemy
  5338.     if BlizzABS::Config::ENEMY_HEALTH_BARS > 0 &&
  5339.         @character.is_a?(Map_Enemy) && !@character.hide_health &&
  5340.         @character.opacity > 0
  5341.       # create a sprite
  5342.       @health = Sprite.new(@viewport)
  5343.       # whether ENEMY_HEALTH_BARS_MATCH_WIDTH is active and tile graphic
  5344.       if @character.tile_id < 384 &&
  5345.           BlizzABS::Config::ENEMY_HEALTH_BARS_MATCH_WIDTH
  5346.         # set the width
  5347.         width = @sprite.bitmap.width / 4
  5348.       else
  5349.         # set the width to default
  5350.         width = 32
  5351.       end
  5352.       # x offset
  5353.       @health.ox = width / 2
  5354.       # create bitmap
  5355.       @health.bitmap = Bitmap.new(width, 6)
  5356.       # fill bitmap background for better display
  5357.       @health.bitmap.fill_rect(0, 0, width, 6, Color.new(0, 26, 0))
  5358.       # set health bar z coordinate
  5359.       @health.z = 1
  5360.       # set health bar opacity
  5361.       @health.opacity = BlizzABS::Config::ENEMY_HEALTH_BARS
  5362.     end
  5363.   end
  5364.   #----------------------------------------------------------------------------
  5365.   # update_health
  5366.   #  Handles health sprite updating.
  5367.   #----------------------------------------------------------------------------
  5368.   def update_health
  5369.     # move health sprite along with sprite
  5370.     @health.x = @sprite.x
  5371.     @health.y = @sprite.y - @sprite.oy - 6
  5372.     @health.z = @sprite.z + 1
  5373.     # if enemy HP have changed
  5374.     if @hp != @character.battler.hp || @battler_id != @character.battler_id
  5375.       # rate of filling
  5376.       rate = @character.battler.hp.to_f / @character.battler.maxhp
  5377.       # get empty bar bitmap
  5378.       bitmaps = [$BlizzABS.cache.image('empty_enemy_bar'),
  5379.           $BlizzABS.cache.image('enemy_bar')]
  5380.       # change hue of bar bitmap
  5381.       bitmaps[1].hue_change((rate / 0.8 - 1.25) * 120)
  5382.       # temporary variable
  5383.       width = @health.bitmap.width - 2
  5384.       # draw empty bar bitmap
  5385.       @health.bitmap.stretch_blt(Rect.new(1, 0, width, 6), bitmaps[0],
  5386.           Rect.new(0, 0, 1, 6))
  5387.       # draw bar bitmap
  5388.       @health.bitmap.stretch_blt(Rect.new(1, 0, rate * width, 6), bitmaps[1],
  5389.           Rect.new(0, 0, 1, 6))
  5390.       # store new values
  5391.       @hp, @battler_id = @character.battler.hp, @character.battler_id
  5392.     end
  5393.   end
  5394.   #----------------------------------------------------------------------------
  5395.   # in_screen?
  5396.   #  Tests the sprite if inside the screen if it exists.
  5397.   #----------------------------------------------------------------------------
  5398.   def in_screen?
  5399.     return (@sprite != nil && @sprite.in_screen?)
  5400.   end
  5401.   #----------------------------------------------------------------------------
  5402.   # x
  5403.   #  Returns the sprite's x-coordinate.
  5404.   #----------------------------------------------------------------------------
  5405.   def x
  5406.     return (@sprite != nil ? @sprite.x : 0)
  5407.   end
  5408.   #----------------------------------------------------------------------------
  5409.   # y
  5410.   #  Returns the sprite's y-coordinate.
  5411.   #----------------------------------------------------------------------------
  5412.   def y
  5413.     return (@sprite != nil ? @sprite.y : 0)
  5414.   end
  5415.   #----------------------------------------------------------------------------
  5416.   # z
  5417.   #  Returns the sprite's z-coordinate.
  5418.   #----------------------------------------------------------------------------
  5419.   def z
  5420.     return (@sprite != nil ? @sprite.z : 0)
  5421.   end
  5422.   #----------------------------------------------------------------------------
  5423.   # z=
  5424.   #  Sets the sprite's z-coordinate.
  5425.   #----------------------------------------------------------------------------
  5426.   def z=(val)
  5427.     @sprite.z = val if @sprite != nil
  5428.   end
  5429.   #----------------------------------------------------------------------------
  5430.   # update_die
  5431.   #  Emulates a destruction engine using animation for maximum performance and
  5432.   #  processes a special 18-frame fading out animation that is used to display
  5433.   #  dying enemies if destruction engine isn't being used for a specific enemy.
  5434.   #----------------------------------------------------------------------------
  5435.   def update_die
  5436.     # if summoned
  5437.     if $BlizzABS.summoned?(@character)
  5438.       # get unsummon ID
  5439.       id = BlizzABS::Config::UNSUMMON_ANIMATION_ID
  5440.     else
  5441.       # get animation ID for destruction engine emulator
  5442.       id = BlizzABS::Enemies.destruct(@character.battler_id)
  5443.     end
  5444.     # if actually existing and dead or already dying
  5445.     if @character.battler != nil && @character.battler.dead? &&
  5446.         ($BlizzABS.summoned?(@character) || @character.is_a?(Map_Enemy) &&
  5447.         !@character.starting) || @destruct != nil
  5448.       # remove respawning flag
  5449.       @respawning = false
  5450.       # if no animation specified, Blizz-ABS default is being used
  5451.       if id == 0 || @destruct != nil && @destruct.effect? ||
  5452.           $BlizzABS.summoned?(@character)
  5453.         # set character loop animation ID to 0
  5454.         @character.loop_animation_id = 0
  5455.         # if normal blending
  5456.         if @character.blend_type == 0 && @character.precondition
  5457.           # set blending to positive
  5458.           @character.blend_type = 1
  5459.           # if health sprite exists and not freed yet
  5460.           unless @health == nil || @health.disposed?
  5461.             # delete health sprite and data
  5462.             @health.dispose
  5463.             @health = @hp = nil
  5464.           end
  5465.           # if not actor
  5466.           unless @character.is_a?(Map_Actor)
  5467.             # play collapse sound effect
  5468.             $game_system.se_play($data_system.enemy_collapse_se)
  5469.           end
  5470.         end
  5471.         # if still fading out
  5472.         if @character.opacity > 0
  5473.           # decrease opacity
  5474.           @character.opacity -= 15
  5475.         else
  5476.           # set blend type to normal
  5477.           @character.blend_type = 0
  5478.           # set termination flag
  5479.           @character.terminate = true
  5480.         end
  5481.       # if sprite exists and no animation is being played upon
  5482.       elsif @sprite != nil && (@destruct == nil || !@destruct.effect?)
  5483.         # if blend flag set
  5484.         if @character.blend_type == 1
  5485.           # set termination flag
  5486.           @character.terminate = true
  5487.         else
  5488.           # delete health sprite if it exists and not freed yet
  5489.           @health.dispose unless @health == nil || @health.disposed?
  5490.           @health = @hp = nil
  5491.           # set character loop animation ID to 0
  5492.           @character.loop_animation_id = 0
  5493.           # create a new sprite
  5494.           @destruct = Sprite_Character_ABSEAL_ed.new(nil, @character)
  5495.           # set new animation ID
  5496.           @character.animation_id = id
  5497.           # reset action sprite
  5498.           @character.character_name = @character.character_name_org
  5499.           # reset spriteset extension and weapon sprite
  5500.           @character.current_sprite = @character.weapon_sprite = ''
  5501.           # set blending type as flag
  5502.           @character.blend_type = 1
  5503.           # decrease opacity
  5504.           @character.opacity -= 15
  5505.           # update all sprites
  5506.           [@destruct, @weapon, @sprite].each {|s| s.update if s != nil}
  5507.           # get source rectangle
  5508.           rect = @sprite.src_rect.clone
  5509.           # use new bitmap for destruction engine
  5510.           @destruct.bitmap = @sprite.bitmap =
  5511.               RPG::Cache.character(@character.character_name, 0).clone
  5512.           # clear bitmap
  5513.           @sprite.bitmap.clear
  5514.           # restore source rectangle
  5515.           @destruct.src_rect = @sprite.src_rect = rect
  5516.         end
  5517.       end
  5518.     end
  5519.   end
  5520.   #----------------------------------------------------------------------------
  5521.   # update_respawn
  5522.   #  Emulates a destruction engine using animation for maximum performance and
  5523.   #  processes a special 18-frame fading out animation that is used to display
  5524.   #  dying enemies if destruction engine isn't being used for a specific enemy.
  5525.   #----------------------------------------------------------------------------
  5526.   def update_respawn
  5527.     # get animation ID for destruction engine emulator
  5528.     id = BlizzABS::Enemies.respawn(@character.battler_id)
  5529.     # if no animation specified
  5530.     if id == 0
  5531.       # set fade in flag and reset respawning flag
  5532.       @fade_in, @respawning = true, false
  5533.     # if sprite exists
  5534.     elsif @sprite != nil
  5535.       # if respawning sprite doesn't exist
  5536.       if @respawn == nil
  5537.         # reset opacity
  5538.         @character.opacity = 255
  5539.         # create a new sprite
  5540.         @respawn = Sprite_Character_ABSEAL_ed.new(nil, @character)
  5541.         # set new animation ID
  5542.         @character.animation_id = id
  5543.         # update all sprites
  5544.         [@respawn, @weapon, @sprite].each {|s| s.update if s != nil}
  5545.         # use new bitmap for respawning animation
  5546.         @respawn.bitmap = @sprite.bitmap.clone
  5547.         # clear bitmap
  5548.         @respawn.bitmap.clear
  5549.         # set source rectangle
  5550.         @respawn.src_rect = @sprite.src_rect.clone
  5551.       # if no animation is being played
  5552.       elsif !@respawn.effect?
  5553.         # reset respawning flag
  5554.         @respawning = false
  5555.         # delete sprite
  5556.         @respawn.dispose
  5557.         @respawn = nil
  5558.       end
  5559.     end
  5560.   end
  5561.   #----------------------------------------------------------------------------
  5562.   # update_fade_in
  5563.   #  Processes an 18-frame fading in animation.
  5564.   #----------------------------------------------------------------------------
  5565.   def update_fade_in
  5566.     # if still fading in
  5567.     if @character.opacity < 255
  5568.       # increase opacity
  5569.       @character.opacity += 15
  5570.     # if opacity is 255
  5571.     elsif @character.opacity == 255
  5572.       # set fade_in flag
  5573.       @fade_in = false
  5574.     end
  5575.   end
  5576.   #----------------------------------------------------------------------------
  5577.   # update_fade_out
  5578.   #  Processes a 5-frame fading out animation.
  5579.   #----------------------------------------------------------------------------
  5580.   def update_fade_out
  5581.     # if still fading out
  5582.     if @character.opacity > 0
  5583.       # decrease opacity
  5584.       @character.opacity -= 64
  5585.     else
  5586.       # reset fade_out flag
  5587.       @character.fade_out = false
  5588.     end
  5589.   end
  5590.   #----------------------------------------------------------------------------
  5591.   # dispose
  5592.   #  Deletes and removes sprite from memory.
  5593.   #----------------------------------------------------------------------------
  5594.   def dispose
  5595.     # delete sprite if it and not freed yet
  5596.     @sprite.dispose unless @sprite == nil || @sprite.disposed?
  5597.     # delete destruction sprite if it exists and not freed yet
  5598.     @destruct.dispose unless @destruct == nil || @destruct.disposed?
  5599.     # delete respawning sprite if it exists and not freed yet
  5600.     @respawn.dispose unless @respawn == nil || @respawn.disposed?
  5601.     # delete health sprite if it exists and not freed yet
  5602.     @health.dispose unless @health == nil || @health.disposed?
  5603.     # delete weapon sprite if it exists and not freed yet
  5604.     @weapon.dispose unless @weapon == nil || @weapon.disposed?
  5605.     # delete doom counter sprite if it exists and not freed yet
  5606.     @doom.dispose unless @doom == nil || @doom.disposed?
  5607.     # remove them all
  5608.     @sprite = @destruct = @respawn = @health = @hp = @weapon = @doom = nil
  5609.   end
  5610.  
  5611. end
  5612.  
  5613. Sprite_Character_ABSEAL_ed = Sprite_Character
  5614. Sprite_Character = Control_Sprite_Character
  5615.  
  5616. #==============================================================================
  5617. # Hud
  5618. #------------------------------------------------------------------------------
  5619. #  This class was modified to support SR display and modify the number of
  5620. #  skills left to use.
  5621. #==============================================================================
  5622.  
  5623. class Hud < Sprite
  5624.  
  5625.   #----------------------------------------------------------------------------
  5626.   # Initialization
  5627.   #  viewport - the viewport for the sprite
  5628.   #----------------------------------------------------------------------------
  5629.   def initialize(viewport = nil)
  5630.     # call superclass method
  5631.     super
  5632.     # create positions
  5633.     create_positions
  5634.     # get height
  5635.     h = BlizzABS::Config::DIRECT_HOTKEYS ? @hud_height - 28 : @hud_height
  5636.     # create bitmap
  5637.     self.bitmap = Bitmap.new(@hud_width, h)
  5638.     # set font
  5639.     self.bitmap.font.name = 'Arial'
  5640.     # set font size
  5641.     self.bitmap.font.size = 16
  5642.     # set font to bold
  5643.     self.bitmap.font.bold = true
  5644.     # set x, y position depending on which HUD mode
  5645.     case BlizzABS::Config::HUD_POSITION
  5646.     when 0 then self.x, self.y = 4, 4
  5647.     when 1 then self.x, self.y = 640 - self.bitmap.width - 4, 4
  5648.     when 2 then self.x, self.y = 4, 364
  5649.     end
  5650.     # set z coordinate
  5651.     self.z = 1000
  5652.     # draw basic HUD
  5653.     draw_basic
  5654.     # update
  5655.     update
  5656.   end
  5657.   #----------------------------------------------------------------------------
  5658.   # create_positions
  5659.   #  Sets drawing positions. Can be aliased and the positions modified to
  5660.   #  create a different HUD.
  5661.   #----------------------------------------------------------------------------
  5662.   def create_positions
  5663.     @original_width = @hud_width = 156
  5664.     @original_height = @hud_height = 81
  5665.     @name_x, @name_y, @level_x, @level_y = 4, 1, 112, 1
  5666.     @hp_x, @hp_y, @sp_x, @sp_y = 4, 17, 4, 33
  5667.     @hot_x, @hot_y, @left_x, @left_y = 4, 49, 8, 63
  5668.   end
  5669.   #----------------------------------------------------------------------------
  5670.   # draw_basic
  5671.   #  Draws the HUD template.
  5672.   #----------------------------------------------------------------------------
  5673.   def draw_basic
  5674.     # fill with grey rectangle
  5675.     self.bitmap.fill_rect(0, 0, self.bitmap.width, self.bitmap.height,
  5676.         Color.new(0, 0, 0, 128))
  5677.     # determine color depending on HUD style
  5678.     color = case BlizzABS::Config::HUD_TYPE
  5679.     when 0 then Color.new(255, 255, 255, 192)
  5680.     when 1 then Color.new(0, 0, 0, 0)
  5681.     end
  5682.     # if color exists
  5683.     if color.is_a?(Color)
  5684.       # draw outline in color
  5685.       self.bitmap.fill_rect(@hp_x+32, @hp_y+3, 116, 14, color)
  5686.       # draw outline in color
  5687.       self.bitmap.fill_rect(@sp_x+32, @sp_y+3, 116, 14, color)
  5688.     end
  5689.     # set font color
  5690.     self.bitmap.font.color = system_color
  5691.     # draw "LV"
  5692.     self.bitmap.draw_text_full(@level_x, @level_y, 20, 20, 'LV')
  5693.     # if direct hotkey option is turned off
  5694.     unless BlizzABS::Config::DIRECT_HOTKEYS
  5695.       # draw "Skill:"
  5696.       self.bitmap.draw_text_full(@hot_x, @hot_y, 48, 20, 'Skill:')
  5697.       # draw "Item:"
  5698.       self.bitmap.draw_text_full(@hot_x+76, @hot_y, 48, 20, 'Item:')
  5699.     end
  5700.     # draw "HP"
  5701.     self.bitmap.draw_text_full(@hp_x, @hp_y, 32, 20, $data_system.words.hp)
  5702.     # draw "SP"
  5703.     self.bitmap.draw_text_full(@sp_x, @sp_y, 32, 20, $data_system.words.sp)
  5704.   end
  5705.   #----------------------------------------------------------------------------
  5706.   # draw_empty
  5707.   #  Draws the HP and SP display when actor doesn't exist.
  5708.   #----------------------------------------------------------------------------
  5709.   def draw_empty
  5710.     # draw empty bars
  5711.     self.bitmap.gradient_bar_hud(@hp_x + 32, @hp_y + 3, 114, 0, 'hud_green_bar', 1)
  5712.     # draw empty bars
  5713.     self.bitmap.gradient_bar_hud(@sp_x + 32, @sp_y + 3, 114, 0, 'hud_blue_bar', 2)
  5714.     # set font color
  5715.     self.bitmap.font.color = disabled_color
  5716.     # draw empty HP
  5717.     self.bitmap.draw_text_full(@hp_x + 38, @hp_y, 48, 20, '0', 2)
  5718.     self.bitmap.draw_text_full(@hp_x + 86, @hp_y, 12, 20, '/', 1)
  5719.     self.bitmap.draw_text_full(@hp_x + 98, @hp_y, 48, 20, '0')
  5720.     # draw empty SP
  5721.     self.bitmap.draw_text_full(@sp_x + 38, @sp_y, 48, 20, '0', 2)
  5722.     self.bitmap.draw_text_full(@sp_x + 86, @sp_y, 12, 20, '/', 1)
  5723.     self.bitmap.draw_text_full(@sp_x + 98, @sp_y, 48, 20, '0')
  5724.     # reset all flag variables
  5725.     @name = @level = @hp = @sp = @maxhp = @maxsp = @exp = @states = @skill =
  5726.         @skills_left = @item = @items_left = @gold = nil
  5727.   end
  5728.   #----------------------------------------------------------------------------
  5729.   # draw_name
  5730.   #  Draws the name display.
  5731.   #----------------------------------------------------------------------------
  5732.   def draw_name
  5733.     # set current variable
  5734.     @name = actor.name
  5735.     # remove old display
  5736.     self.bitmap.fill_rect(@name_x, @name_y, 104, 19, Color.new(0, 0, 0, 128))
  5737.     # set font color
  5738.     self.bitmap.font.color = Color.new(0, 255, 0)
  5739.     # draw actor's name
  5740.     self.bitmap.draw_text_full(@name_x, @name_y, 104, 20, @name)
  5741.   end
  5742.   #----------------------------------------------------------------------------
  5743.   # draw_level
  5744.   #  Draws the level display.
  5745.   #----------------------------------------------------------------------------
  5746.   def draw_level
  5747.     # set current variable
  5748.     @level = actor.level
  5749.     # remove old display
  5750.     self.bitmap.fill_rect(@level_x+20, @level_y, 20, 19, Color.new(0, 0, 0, 128))
  5751.     # set font color
  5752.     self.bitmap.font.color = normal_color
  5753.     # draw actor's level
  5754.     self.bitmap.draw_text_full(@level_x+20, @level_y, 20, 20, @level.to_s, 2)
  5755.   end
  5756.   #----------------------------------------------------------------------------
  5757.   # draw_hp
  5758.   #  Draws the HP display.
  5759.   #----------------------------------------------------------------------------
  5760.   def draw_hp
  5761.     # set current variables
  5762.     @hp, @maxhp = actor.hp, actor.maxhp
  5763.     # set fill rate
  5764.     rate = (@maxhp > 0 ? @hp.to_f / @maxhp : 0)
  5765.     # draw gradient bar
  5766.     self.bitmap.gradient_bar_hud(@hp_x+32, @hp_y+3, 114, rate, 'hud_green_bar', 1)
  5767.     # set font color depending on how many HP left
  5768.     self.bitmap.font.color = @hp == 0 ? knockout_color :
  5769.         @hp <= @maxhp / 4 ? crisis_color : normal_color
  5770.     # draw HP
  5771.     self.bitmap.draw_text_full(@hp_x+38, @hp_y, 48, 20, @hp.to_s, 2)
  5772.     # set color
  5773.     self.bitmap.font.color = normal_color
  5774.     # draw "/"
  5775.     self.bitmap.draw_text_full(@hp_x+86, @hp_y, 12, 20, '/', 1)
  5776.     # draw max HP
  5777.     self.bitmap.draw_text_full(@hp_x+98, @hp_y, 48, 20, @maxhp.to_s)
  5778.   end
  5779.   #----------------------------------------------------------------------------
  5780.   # draw_sp
  5781.   #  Draws the SP display.
  5782.   #----------------------------------------------------------------------------
  5783.   def draw_sp
  5784.     # set current variables
  5785.     @sp, @maxsp = actor.sp, actor.maxsp
  5786.     # set fill rate
  5787.     rate = (@maxsp > 0 ? @sp.to_f / @maxsp : 0)
  5788.     # draw gradient bar
  5789.     self.bitmap.gradient_bar_hud(@sp_x+32, @sp_y+3, 114, rate, 'hud_blue_bar', 2)
  5790.     # set font color depending on how many SP left
  5791.     self.bitmap.font.color = @sp == 0 ? knockout_color :
  5792.         @sp <= @maxsp / 4 ? crisis_color : normal_color
  5793.     # draw SP
  5794.     self.bitmap.draw_text_full(@sp_x+38, @sp_y, 48, 20, @sp.to_s, 2)
  5795.     # set font color
  5796.     self.bitmap.font.color = normal_color
  5797.     # draw "/"
  5798.     self.bitmap.draw_text_full(@sp_x+86, @sp_y, 12, 20, '/', 1)
  5799.     # draw max SP
  5800.     self.bitmap.draw_text_full(@sp_x+98, @sp_y, 48, 20, @maxsp.to_s)
  5801.   end
  5802.   #----------------------------------------------------------------------------
  5803.   # draw_hskill
  5804.   #  Draws the hot skill display.
  5805.   #----------------------------------------------------------------------------
  5806.   def draw_hskill
  5807.     # set current variable
  5808.     @skill = actor.skill
  5809.     # remove old display
  5810.     self.bitmap.fill_rect(@hot_x+48, @hot_y+4, 24, 24, Color.new(0, 0, 0, 128))
  5811.     # if skill hot skill exists
  5812.     if @skill != 0
  5813.       # load bitmap
  5814.       bitmap = RPG::Cache.icon($data_skills[@skill].icon_name)
  5815.       # draw bitmap
  5816.       self.bitmap.blt(@hot_x+48, @hot_y+4, bitmap, Rect.new(0, 0, 24, 24))
  5817.     end
  5818.     # removes skills left to use display
  5819.     draw_lskill
  5820.   end
  5821.   #----------------------------------------------------------------------------
  5822.   # draw_lskill
  5823.   #  Draws the skills left to use display.
  5824.   #----------------------------------------------------------------------------
  5825.   def draw_lskill
  5826.     # remove old display
  5827.     self.bitmap.fill_rect(@left_x, @left_y+4, 24, 16, Color.new(0, 0, 0, 128))
  5828.     # get the number of skills left
  5829.     @skills_left = get_skills_left
  5830.     # if hot skill exists
  5831.     if @skill != nil && @skill > 0
  5832.       # if normal SP cost
  5833.       if @skills_left >= 0
  5834.         # if not enough sp to use
  5835.         if @skills_left == 0
  5836.           # set font color
  5837.           self.bitmap.font.color = Color.new(255, 0, 0)
  5838.         # if enough SP for 5 or less skill uses
  5839.         elsif @skills_left <= 5
  5840.           # set font color
  5841.           self.bitmap.font.color = Color.new(255, 255, 0)
  5842.         else
  5843.           # set font color
  5844.           self.bitmap.font.color = normal_color
  5845.         end
  5846.         # decrease font color
  5847.         self.bitmap.font.size -= 2
  5848.         # draw number how many skills left to use
  5849.         self.bitmap.draw_text_full(@left_x, @left_y, 24, 20, @skills_left.to_s, 1)
  5850.         # increase font size
  5851.         self.bitmap.font.size += 2
  5852.       # if infinite skills left
  5853.       elsif @skills_left == -1
  5854.         # set font color
  5855.         self.bitmap.font.color = Color.new(0, 255, 0)
  5856.         # increase font size
  5857.         self.bitmap.font.size += 4
  5858.         # draw "∞" skill uses left
  5859.         self.bitmap.draw_text_full(@left_x, @left_y, 24, 20, '∞', 1)
  5860.         # decrease font size
  5861.         self.bitmap.font.size -= 4
  5862.       end
  5863.     end
  5864.   end
  5865.   #----------------------------------------------------------------------------
  5866.   # get_skills_left
  5867.   #  Gets the number of skill usages left.
  5868.   #----------------------------------------------------------------------------
  5869.   def get_skills_left
  5870.     # flat if skill is not hot skill or does not exist
  5871.     return -2 if @skill == nil || @skill == 0
  5872.     # infinite usages if SP cost is zero
  5873.     return -1 if $data_skills[@skill].sp_cost == 0
  5874.     # get basic SP cost
  5875.     sp_cost = $data_skills[@skill].sp_cost
  5876.     # if using SP Cost Mod Status
  5877.     if $tons_version != nil && $tons_version >= 6.54 &&
  5878.         $game_system.SP_COST_MOD
  5879.       # get modified cost
  5880.       sp_cost = BlizzCFG.get_cost_mod(actor.states, sp_cost)
  5881.     end
  5882.     # infinite
  5883.     return -1 if sp_cost == 0
  5884.     # calculate skills left to use
  5885.     return (@sp / sp_cost)
  5886.   end
  5887.   #----------------------------------------------------------------------------
  5888.   # draw_hitem
  5889.   #  Draws the hot item display.
  5890.   #----------------------------------------------------------------------------
  5891.   def draw_hitem
  5892.     # set current variable
  5893.     @item = actor.item
  5894.     # remove old display
  5895.     self.bitmap.fill_rect(@hot_x+124, @hot_y+4, 24, 24, Color.new(0, 0, 0, 128))
  5896.     # if hot item exists
  5897.     if @item != 0
  5898.       # load bitmap
  5899.       bitmap = RPG::Cache.icon($data_items[@item].icon_name)
  5900.       # draw bitmap
  5901.       self.bitmap.blt(@hot_x+124, @hot_y+4, bitmap, Rect.new(0, 0, 24, 24))
  5902.     end
  5903.     # removes items left to use display
  5904.     draw_litem
  5905.   end
  5906.   #----------------------------------------------------------------------------
  5907.   # draw_litem
  5908.   #  Draws the items left to use display.
  5909.   #----------------------------------------------------------------------------
  5910.   def draw_litem
  5911.     # set current variable
  5912.     @items_left = $game_party.item_number(@item)
  5913.     # remove old display
  5914.     self.bitmap.fill_rect(@left_x+76, @left_y+4, 24, 16, Color.new(0, 0, 0, 128))
  5915.     # if hot item exists
  5916.     if @item != nil && @item > 0
  5917.       # if item exists and cannot be consumed
  5918.       if $data_items[@item] != nil && !$data_items[@item].consumable
  5919.         # set font color
  5920.         self.bitmap.font.color = Color.new(0, 255, 0)
  5921.         # increase font size
  5922.         self.bitmap.font.size += 4
  5923.         # draw "∞" items left
  5924.         self.bitmap.draw_text_full(@left_x+76, @left_y, 24, 20, '∞', 1)
  5925.         # decrease font size
  5926.         self.bitmap.font.size -= 4
  5927.       else
  5928.         # if no items left
  5929.         if @items_left == 0
  5930.           # set font color
  5931.           self.bitmap.font.color = Color.new(255, 0, 0)
  5932.         # if equal or less items left
  5933.         elsif @items_left <= 10
  5934.           # set font color
  5935.           self.bitmap.font.color = Color.new(255, 255, 0)
  5936.         else
  5937.           # set font color
  5938.           self.bitmap.font.color = normal_color
  5939.         end
  5940.         # decrease font color
  5941.         self.bitmap.font.size -= 2
  5942.         # draw number how many items left to use
  5943.         self.bitmap.draw_text_full(@left_x+76, @left_y, 24, 20, @items_left.to_s, 1)
  5944.         # increase font size
  5945.         self.bitmap.font.size += 2
  5946.       end
  5947.     end
  5948.   end
  5949.   #----------------------------------------------------------------------------
  5950.   # update
  5951.   #  Checks if HUD needs refreshing.
  5952.   #----------------------------------------------------------------------------
  5953.   def update
  5954.     # if actor doesn't exist
  5955.     if actor == nil
  5956.       # unless already drawn empty HUD
  5957.       unless @empty_hud_drawn
  5958.         # draw HUD template
  5959.         draw_basic
  5960.         # draw empty HP, SP and EXP bars
  5961.         draw_empty
  5962.         # empty HUD was drawn
  5963.         @empty_hud_drawn = true
  5964.       end
  5965.     else
  5966.       # if HUD needs refresh
  5967.       if $game_temp.hud_refresh
  5968.         # draw all data about actor
  5969.         draw_name
  5970.         draw_level
  5971.         draw_hp
  5972.         draw_sp
  5973.         unless BlizzABS::Config::DIRECT_HOTKEYS
  5974.           draw_hskill
  5975.           draw_lskill
  5976.           draw_hitem
  5977.           draw_litem
  5978.         end
  5979.         # remove flag
  5980.         $game_temp.hud_refresh = nil
  5981.       else
  5982.         # draw data that needs to ve updated
  5983.         test_name
  5984.         test_level
  5985.         test_hp
  5986.         test_sp
  5987.         unless BlizzABS::Config::DIRECT_HOTKEYS
  5988.           test_hskill
  5989.           test_lskill
  5990.           test_hitem
  5991.           test_litem
  5992.         end
  5993.       end
  5994.       # empty HUD wasn't drawn
  5995.       @empty_hud_drawn = false
  5996.     end
  5997.   end
  5998.   #----------------------------------------------------------------------------
  5999.   # test_name
  6000.   #  Tests and draws the name.
  6001.   #----------------------------------------------------------------------------
  6002.   def test_name
  6003.     # draw new name if name has changed
  6004.     draw_name if actor.name != @name
  6005.   end
  6006.   #----------------------------------------------------------------------------
  6007.   # test_level
  6008.   #  Tests and draws the level.
  6009.   #----------------------------------------------------------------------------
  6010.   def test_level
  6011.     # draw new level if level has changed
  6012.     draw_level if actor.level != @level
  6013.   end
  6014.   #----------------------------------------------------------------------------
  6015.   # test_hp
  6016.   #  Tests and draws the HP.
  6017.   #----------------------------------------------------------------------------
  6018.   def test_hp
  6019.     # draw new HP if HP or max HP have changed
  6020.     draw_hp if actor.hp != @hp || actor.maxhp != @maxhp
  6021.   end
  6022.   #----------------------------------------------------------------------------
  6023.   # test_sp
  6024.   #  Tests and draws the SP.
  6025.   #----------------------------------------------------------------------------
  6026.   def test_sp
  6027.     # draw new SP if SP or max SP have changed
  6028.     draw_sp if actor.sp != @sp || actor.maxsp != @maxsp
  6029.   end
  6030.   #----------------------------------------------------------------------------
  6031.   # test_hskill
  6032.   #  Tests and draws the hskill.
  6033.   #----------------------------------------------------------------------------
  6034.   def test_hskill
  6035.     # draw new skill icon if assigned skill has changed
  6036.     draw_hskill if actor.skill != @skill
  6037.   end
  6038.   #----------------------------------------------------------------------------
  6039.   # test_lskill
  6040.   #  Tests and draws the lskill.
  6041.   #----------------------------------------------------------------------------
  6042.   def test_lskill
  6043.     # draw how many skills left to use if this number has changed
  6044.     draw_lskill if get_skills_left != @skills_left
  6045.   end
  6046.   #----------------------------------------------------------------------------
  6047.   # test_hitem
  6048.   #  Tests and draws the hitem.
  6049.   #----------------------------------------------------------------------------
  6050.   def test_hitem
  6051.     # draw new item icon if assigned item has changed
  6052.     draw_hitem if actor.item != @item
  6053.   end
  6054.   #----------------------------------------------------------------------------
  6055.   # test_litem
  6056.   #  Tests and draws the litem.
  6057.   #----------------------------------------------------------------------------
  6058.   def test_litem
  6059.     # draw how many items left to use if this number has changed
  6060.     draw_litem if $game_party.item_number(@item) != @items_left
  6061.   end
  6062.   #----------------------------------------------------------------------------
  6063.   # actor
  6064.   #  Returns the party leader's battler for easier reference.
  6065.   #----------------------------------------------------------------------------
  6066.   def actor
  6067.     return $game_player.battler
  6068.   end
  6069.  
  6070. end
  6071.  
  6072. #==============================================================================
  6073. # Hotkey_Assignment
  6074. #------------------------------------------------------------------------------
  6075. #  This class creates and display currently assigned hotkeys and is more
  6076. #  effiecient than the Window class.
  6077. #==============================================================================
  6078.  
  6079. class Hotkey_Assignment < Sprite
  6080.  
  6081.   #----------------------------------------------------------------------------
  6082.   # Initialization
  6083.   #  viewport - the viewport for the sprite
  6084.   #----------------------------------------------------------------------------
  6085.   def initialize(viewport = nil)
  6086.     # call superclass
  6087.     super
  6088.     # create bitmap
  6089.     self.bitmap = Bitmap.new(320, 32)
  6090.     # set font to bold
  6091.     self.bitmap.font.bold = true
  6092.     # decrease font size
  6093.     self.bitmap.font.size -= 8
  6094.     # set font color
  6095.     self.bitmap.font.color = system_color
  6096.     # set x and y position
  6097.     self.x, self.y, self.z = 160, 0, 1100
  6098.     # skill IDs on hotkeys
  6099.     @skills = BlizzABS::Cache::EmptyKeys
  6100.     # item IDs on hotkeys
  6101.     @items = BlizzABS::Cache::EmptyKeys
  6102.     # update display
  6103.     update
  6104.   end
  6105.   #----------------------------------------------------------------------------
  6106.   # draw
  6107.   #  Draws the hotkey display.
  6108.   #----------------------------------------------------------------------------
  6109.   def draw(index = nil)
  6110.     # iterate through all hotkeys
  6111.     (index == nil ? BlizzABS::Cache::HotkeyRange : [index]).each {|i|
  6112.         # if hotkey is skill hotkey
  6113.         if $game_player.skill_hotkeys[i%10] != 0
  6114.           # temporary object
  6115.           object = $data_skills[$game_player.skill_hotkeys[i%10]]
  6116.         # if hotkey is item hotkey
  6117.         elsif $game_player.item_hotkeys[i%10] != 0
  6118.           # temporary object
  6119.           object = $data_items[$game_player.item_hotkeys[i%10]]
  6120.         end
  6121.         # if any change applied (10 is used for 0)
  6122.         if @items[i%10] != $game_player.item_hotkeys[i%10] ||
  6123.             @skills[i%10] != $game_player.skill_hotkeys[i%10]
  6124.           # remove this icon
  6125.           self.bitmap.fill_rect(32*(i-1), 0, 32, 32, Color.new(0, 0, 0, 0))
  6126.           # fill icon bachground
  6127.           self.bitmap.fill_rect(32*(i-1)+4, 4, 24, 24, Color.new(0, 0, 0, 128))
  6128.           # if object exists
  6129.           if object != nil
  6130.             # load bitmap
  6131.             bitmap = RPG::Cache.icon(object.icon_name)
  6132.             # draw bitmap
  6133.             self.bitmap.blt(32*(i-1)+4, 4, bitmap, Rect.new(0, 0, 24, 24))
  6134.           end
  6135.           # draw hotkey number
  6136.           self.bitmap.draw_text_full(32*(i-1), 10, 30, 32, (i%10).to_s, 2)
  6137.         end}
  6138.     # set new items
  6139.     @items = $game_player.item_hotkeys.clone
  6140.     # set new skills
  6141.     @skills = $game_player.skill_hotkeys.clone
  6142.   end
  6143.   #----------------------------------------------------------------------------
  6144.   # update
  6145.   #  Updates the hotkey display.
  6146.   #----------------------------------------------------------------------------
  6147.   def update
  6148.     # call superclass method
  6149.     super
  6150.     # if actor or item hotkeys or skill hotkeys have changed
  6151.     if @actor != $game_player.battler || @items != $game_player.item_hotkeys ||
  6152.         @skills != $game_player.skill_hotkeys
  6153.       # set new actor
  6154.       @actor = $game_player.battler
  6155.       # redraw
  6156.       draw
  6157.     end
  6158.   end
  6159.  
  6160. end
  6161.  
  6162. #==============================================================================
  6163. # Minimap
  6164. #------------------------------------------------------------------------------
  6165. #  This class creates and handels the minimap/fullscreen map display and is
  6166. #  more efficient than the Window class.
  6167. #==============================================================================
  6168.  
  6169. class Minimap < Sprite
  6170.  
  6171.   # setting all accessible variables
  6172.   attr_reader :map_id
  6173.   #----------------------------------------------------------------------------
  6174.   # Initialization
  6175.   #----------------------------------------------------------------------------
  6176.   def initialize
  6177.     # call superclass method
  6178.     super(Viewport.new(476, 356, 160, 120))
  6179.     # get autotile image from Blizz-ABS Cache
  6180.     @autotile = $BlizzABS.cache.image('minimap_autotile')
  6181.     # creates the passable floor map
  6182.     create_passable_floor
  6183.     # set x and y position
  6184.     self.x = self.y = 0
  6185.     # set z position
  6186.     viewport.z = 5000
  6187.     # store events
  6188.     @events, @names = check_events
  6189.     # create sprites for events
  6190.     create_sevents
  6191.     # set all sprites visible
  6192.     self.visible = true
  6193.     # update
  6194.     update
  6195.   end
  6196.   #----------------------------------------------------------------------------
  6197.   # create_passable_floor
  6198.   #  Creates the passable floor map on the bitmap.
  6199.   #----------------------------------------------------------------------------
  6200.   def create_passable_floor
  6201.     # delete bitmap if bitmap exists
  6202.     self.bitmap.dispose if self.bitmap != nil
  6203.     # store new map ID
  6204.     @map_id = $game_map.map_id
  6205.     # temporary width and height
  6206.     w, h = $game_map.width, $game_map.height
  6207.     # create bitmap
  6208.     self.bitmap = Bitmap.new(8*w, 8*h)
  6209.     # fill rectangle
  6210.     self.bitmap.fill_rect(0, 0, 8*w, 8*h, Color.new(0, 0, 0, 128))
  6211.     # get passability data
  6212.     v_map = $game_map.virtual_passability
  6213.     # iterate through all tiles
  6214.     (0...v_map.xsize).each {|x| (0...v_map.ysize).each {|y|
  6215.         # depending on passable direction, draw the path using the autotile
  6216.         case v_map[x, y]
  6217.         when 0x01 #    D
  6218.           self.bitmap.blt(x*8, y*8+4, @autotile, Rect.new(0, 0, 8, 4), 128)
  6219.         when 0x02 #   L
  6220.           self.bitmap.blt(x*8, y*8, @autotile, Rect.new(4, 0, 4, 8), 128)
  6221.         when 0x03 #   LD
  6222.           self.bitmap.blt(x*8, y*8, @autotile, Rect.new(16, 8, 8, 8), 128)
  6223.         when 0x04 #  R
  6224.           self.bitmap.blt(x*8+4, y*8, @autotile, Rect.new(0, 0, 4, 8), 128)
  6225.         when 0x05 #  R D
  6226.           self.bitmap.blt(x*8, y*8, @autotile, Rect.new(0, 8, 8, 8), 128)
  6227.         when 0x06 #  RL
  6228.           self.bitmap.blt(x*8, y*8, @autotile, Rect.new(8, 8, 8, 4), 128)
  6229.           self.bitmap.blt(x*8, y*8+4, @autotile, Rect.new(8, 28, 8, 4), 128)
  6230.         when 0x07 #  RLD
  6231.           self.bitmap.blt(x*8, y*8, @autotile, Rect.new(8, 8, 8, 8), 128)
  6232.         when 0x08 # U
  6233.           self.bitmap.blt(x*8, y*8, @autotile, Rect.new(0, 4, 8, 4), 128)
  6234.         when 0x09 # U  D
  6235.           self.bitmap.blt(x*8, y*8, @autotile, Rect.new(0, 16, 4, 8), 128)
  6236.           self.bitmap.blt(x*8+4, y*8, @autotile, Rect.new(20, 16, 4, 8), 128)
  6237.         when 0x0A # U L
  6238.           self.bitmap.blt(x*8, y*8, @autotile, Rect.new(16, 24, 8, 8), 128)
  6239.         when 0x0B # U LD
  6240.           self.bitmap.blt(x*8, y*8, @autotile, Rect.new(16, 16, 8, 8), 128)
  6241.         when 0x0C # UR
  6242.           self.bitmap.blt(x*8, y*8, @autotile, Rect.new(0, 24, 8, 8), 128)
  6243.         when 0x0D # UR D
  6244.           self.bitmap.blt(x*8, y*8, @autotile, Rect.new(0, 16, 8, 8), 128)
  6245.         when 0x0E # URL
  6246.           self.bitmap.blt(x*8, y*8, @autotile, Rect.new(8, 24, 8, 8), 128)
  6247.         when 0x0F # URLD
  6248.           self.bitmap.blt(x*8, y*8, @autotile, Rect.new(8, 16, 8, 8), 128)
  6249.         end}}
  6250.   end
  6251.   #----------------------------------------------------------------------------
  6252.   # update
  6253.   #  Updates the minimap and sprite movement on the minimap.
  6254.   #----------------------------------------------------------------------------
  6255.   def update(override = false)
  6256.     # creates the passable floor map if new map entered
  6257.     create_passable_floor if @map_id != $game_map.map_id
  6258.     # get events
  6259.     ev = check_events
  6260.     # if events or names changed
  6261.     if @events != ev[0] || @names != ev[1]
  6262.       # store new events and names
  6263.       @events, @names = ev
  6264.       # delete sprites of events
  6265.       destroy_sevents
  6266.       # create sprites of events
  6267.       create_sevents
  6268.     end
  6269.     # if minimap not in fullscreen mode
  6270.     if $game_system.minimap < 2
  6271.       # set offset display
  6272.       self.ox, self.oy = $game_map.display_x / 16, $game_map.display_y / 16
  6273.     # if not pressed the turn button to scroll map around
  6274.     elsif !($game_system.turn_button && Input.press?(Input::Turn)) || override
  6275.       # if map can be scrolled horizontally
  6276.       if self.bitmap.width > 640
  6277.         # coordinate
  6278.         border = $game_player.real_x/16 - 320
  6279.         # get right border
  6280.         border_x = self.bitmap.width - 640
  6281.         # set offset
  6282.         if border < 0
  6283.           self.ox = 0
  6284.         elsif border > border_x
  6285.           self.ox = border_x
  6286.         else
  6287.           self.ox = border
  6288.         end
  6289.       else
  6290.         # center map display horizontally
  6291.         self.ox = self.bitmap.width/2 - 320
  6292.       end
  6293.       # if map can be scrolled vertically
  6294.       if self.bitmap.height > 480
  6295.         # coordinate
  6296.         border = $game_player.real_y/16 - 240
  6297.         # get lower border
  6298.         border_y = self.bitmap.height - 480
  6299.         # set offset
  6300.         if border < 0
  6301.           self.oy = 0
  6302.         elsif border > border_y
  6303.           self.oy = border_y
  6304.         else
  6305.           self.oy = border
  6306.         end
  6307.       else
  6308.         # center map display vertically
  6309.         self.oy = self.bitmap.height/2 - 240
  6310.       end
  6311.     end
  6312.     # iterate through all sprites
  6313.     @sevents.each_index {|i|
  6314.         # if minimap is not in fullscreen mode and within the range of ABSEAL
  6315.         if $game_system.minimap == 2 || @events[i].update?
  6316.           # set new coordinates
  6317.           @sevents[i].x = self.x + @events[i].real_x / 16
  6318.           @sevents[i].y = self.y + @events[i].real_y / 16
  6319.           # set offsets
  6320.           @sevents[i].ox, @sevents[i].oy = self.ox, self.oy
  6321.           # if event has a spriteset
  6322.           if @names[i] != '' && !@events[i].dropped? &&
  6323.               (@events[i].is_a?(Map_Actor) ||
  6324.               !@events[i].name.clone.gsub!('\box') {''})
  6325.             # depending on the facing direction of the event
  6326.             @sevents[i].src_rect.set((@events[i].direction - 2) * 7, 0, 14, 14)
  6327.             # change offsets
  6328.             @sevents[i].ox += 3
  6329.             @sevents[i].oy += 3
  6330.           end
  6331.         end}
  6332.   end
  6333.   #----------------------------------------------------------------------------
  6334.   # check_events
  6335.   #  Checks all events.
  6336.   #----------------------------------------------------------------------------
  6337.   def check_events
  6338.     # events and names arrays
  6339.     events, names = [], []
  6340.     # iterate through all actors
  6341.     $BlizzABS.battlers.each {|actor|
  6342.         # if valid actor
  6343.         if actor.valid?
  6344.           # add event and spriteset name
  6345.           events.push(actor)
  6346.           names.push(actor.character_name)
  6347.         end}
  6348.     # iterate through all events
  6349.     $game_map.events.values.each {|event|
  6350.         # skip if defined to skip
  6351.         next if event.name.clone.gsub!('\nomap') {''}
  6352.         # if should be displayed
  6353.         if defined?(event.valid?) && event.valid? ||
  6354.             event.is_a?(Game_Event) && !event.erased && (event.teleport ||
  6355.             event.dropped? || event.name.clone.gsub!('\spc') {''})
  6356.           # add enemy and spriteset name
  6357.           events.push(event)
  6358.           names.push(event.character_name)
  6359.         end}
  6360.     # return result
  6361.     return events, names
  6362.   end
  6363.   #----------------------------------------------------------------------------
  6364.   # create_sevents
  6365.   #  Creates for each event on the map a sprite on the minimap.
  6366.   #----------------------------------------------------------------------------
  6367.   def create_sevents
  6368.     # set empty array
  6369.     @sevents = []
  6370.     # ierate through all events on the minimap
  6371.     @events.each_index {|i|
  6372.         # create sprite
  6373.         sprite = Sprite.new(viewport)
  6374.         # temporary variable
  6375.         rect = Rect.new(0, 0, 56, 14)
  6376.         # if event is player
  6377.         if @events[i] == $game_player
  6378.           # if player has spriteset
  6379.           if @names[i] != ''
  6380.             # create bitmap
  6381.             sprite.bitmap = Bitmap.new(56, 14)
  6382.             # get green arrow
  6383.             sprite.bitmap.blt(0, 0, $BlizzABS.cache.image('green_arrow'), rect, 128)
  6384.           end
  6385.           # highest sprite
  6386.           sprite.z = 100
  6387.         # if event is actor
  6388.         elsif @events[i].is_a?(Map_Actor)
  6389.           # if actor has spriteset
  6390.           if @names[i] != ''
  6391.             # create bitmap
  6392.             sprite.bitmap = Bitmap.new(56, 14)
  6393.             # get blue arrow
  6394.             sprite.bitmap.blt(0, 0, $BlizzABS.cache.image('blue_arrow'), rect, 128)
  6395.           end
  6396.           # 2nd highest sprite
  6397.           sprite.z = 80
  6398.         # if event is enemy
  6399.         elsif @events[i].class == Map_Enemy &&
  6400.             @events[i].ai.group == BlizzABS::Alignments::ENEMY_GROUP
  6401.           # if event without spriteset or "boxdraw" enforcing
  6402.           if @names[i] == '' || @events[i].name.clone.gsub!('\box') {''}
  6403.             # create bitmap
  6404.             sprite.bitmap = Bitmap.new(8, 8)
  6405.             # fill rectangle with black color
  6406.             sprite.bitmap.fill_rect(0, 0, 8, 8, Color.new(0, 0, 0, 128))
  6407.             # fill rectangle with red color
  6408.             sprite.bitmap.fill_rect(1, 1, 6, 6, Color.new(255, 0, 0, 128))
  6409.           else
  6410.             # create bitmap
  6411.             sprite.bitmap = Bitmap.new(56, 14)
  6412.             # get red arrow
  6413.             sprite.bitmap.blt(0, 0, $BlizzABS.cache.image('red_arrow'), rect, 128)
  6414.           end
  6415.           # 5th highest sprite
  6416.           sprite.z = 50
  6417.         # if event is dropped item
  6418.         elsif @events[i].dropped?
  6419.           # create bitmap
  6420.           sprite.bitmap = Bitmap.new(8, 8)
  6421.           # fill rectangle with black color
  6422.           sprite.bitmap.fill_rect(0, 0, 8, 8, Color.new(0, 0, 0, 128))
  6423.           # fill rectangle with cyan color
  6424.           sprite.bitmap.fill_rect(1, 1, 6, 6, Color.new(0, 255, 255, 128))
  6425.           # 3rd highest sprite
  6426.           sprite.z = 70
  6427.         # if event is normal event
  6428.         elsif @events[i].class == Game_Event
  6429.           # if event has spc command
  6430.           if @events[i].name.clone.gsub!('\spc') {''}
  6431.             # temporary variables, 4th highest sprite
  6432.             color, arrow, sprite.z = Color.new(255, 255, 0, 128), 'yellow_arrow', 60
  6433.           # if event code exists and te
  6434.           elsif @events[i].teleport
  6435.             # temporary variables, 6th highest sprite
  6436.             color, arrow, sprite.z = Color.new(128, 0, 255, 128), 'violet_arrow', 40
  6437.           end
  6438.           # if event without spriteset or "boxdraw" enforcing
  6439.           if @names[i] == '' || @events[i].name.clone.gsub!('\box') {''}
  6440.             # create bitmap
  6441.             sprite.bitmap = Bitmap.new(8, 8)
  6442.             # fill rectangle with black color
  6443.             sprite.bitmap.fill_rect(0, 0, 8, 8, Color.new(0, 0, 0, 128))
  6444.             # fill rectangle with yellow color
  6445.             sprite.bitmap.fill_rect(1, 1, 6, 6, color)
  6446.           else
  6447.             # create bitmap
  6448.             sprite.bitmap = Bitmap.new(56, 14)
  6449.             # get yellow or violet arrow
  6450.             sprite.bitmap.blt(0, 0, $BlizzABS.cache.image(arrow), rect, 128)
  6451.           end
  6452.         # if event without spriteset or "boxdraw" enforcing
  6453.         elsif @names[i] == '' || @events[i].name.clone.gsub!('\box') {''}
  6454.           # create bitmap
  6455.           sprite.bitmap = Bitmap.new(8, 8)
  6456.           # fill rectangle with black color
  6457.           sprite.bitmap.fill_rect(0, 0, 8, 8, Color.new(0, 0, 0, 128))
  6458.           # fill rectangle with default white color
  6459.           sprite.bitmap.fill_rect(1, 1, 6, 6, Color.new(255, 255, 255, 128))
  6460.         else
  6461.           # create bitmap
  6462.           sprite.bitmap = Bitmap.new(56, 14)
  6463.           # get white arrow
  6464.           sprite.bitmap.blt(0, 0, $BlizzABS.cache.image('white_arrow'), Rect.new(0, 0, 56, 14), 128)
  6465.         end
  6466.         # create a little dummy bitmap in case no bitmap was created before
  6467.         sprite.bitmap = Bitmap.new(1, 1) if sprite.bitmap == nil
  6468.         # get sprite out of map screen so ABSEAL can work correctly
  6469.         sprite.ox = sprite.oy = 64
  6470.         # if event has a spriteset
  6471.         if sprite.bitmap.width != 8
  6472.           # depending on the facing direction of the event
  6473.           sprite.src_rect.set((@events[i].direction-2)*7, 0, 14, 14)
  6474.         end
  6475.         # add sprite to array
  6476.         @sevents.push(sprite)}
  6477.   end
  6478.   #----------------------------------------------------------------------------
  6479.   # destroy_sevents
  6480.   #  Deletes all sprites.
  6481.   #----------------------------------------------------------------------------
  6482.   def destroy_sevents
  6483.     # if sprites exist
  6484.     if @sevents != nil
  6485.       # delete them
  6486.       @sevents.each {|i| i.dispose}
  6487.       @sevents = nil
  6488.     end
  6489.   end
  6490.   #----------------------------------------------------------------------------
  6491.   # visible=
  6492.   #  expr - true or false
  6493.   #  Overriding the original method so the events sprites also get affected.
  6494.   #----------------------------------------------------------------------------
  6495.   def visible=(expr)
  6496.     # call superclass method
  6497.     super
  6498.     # set each sprite's visiblity
  6499.     @sevents.each {|sprite| sprite.visible = expr}
  6500.   end
  6501.   #----------------------------------------------------------------------------
  6502.   # dispose
  6503.   #  Removes Minimap from screen and memory.
  6504.   #----------------------------------------------------------------------------
  6505.   def dispose
  6506.     # delete sprites
  6507.     destroy_sevents
  6508.     # call superclass method
  6509.     super
  6510.   end
  6511.  
  6512. end
  6513.  
  6514. #==============================================================================
  6515. # Spriteset_Map
  6516. #------------------------------------------------------------------------------
  6517. #  This class was enhanced to create and handle caterpillar characters and to
  6518. #  take over and handle damage sprites upon their host's termination.
  6519. #==============================================================================
  6520.  
  6521. class Spriteset_Map
  6522.  
  6523.   # setting all accessible variables
  6524.   attr_accessor :viewport1
  6525.   attr_accessor :character_sprites
  6526.   #----------------------------------------------------------------------------
  6527.   # override Initialization
  6528.   #----------------------------------------------------------------------------
  6529.   alias init_blizzabs_later initialize
  6530.   def initialize
  6531.     # call original method
  6532.     init_blizzabs_later
  6533.     # iterate through all active remotes, beams and all actors except player
  6534.     ($BlizzABS.cache.remotes + $BlizzABS.cache.beams +
  6535.         $BlizzABS.battlers - [$game_player]).each {|character|
  6536.         # if it's really a character
  6537.         if character.is_a?(Game_Character)
  6538.           # create sprite
  6539.           sprite = Sprite_Character.new(@viewport1, character)
  6540.           # update sprite
  6541.           sprite.update
  6542.           # add sprite to character_sprites
  6543.           @character_sprites.push(sprite)
  6544.         end}
  6545.     # set damage update flag
  6546.     @dmg_update = ($scene.is_a?(Scene_Map))
  6547.   end
  6548.   #----------------------------------------------------------------------------
  6549.   # override update
  6550.   #----------------------------------------------------------------------------
  6551.   alias upd_blizzabs_later update
  6552.   def update
  6553.     # iterate through all damage sprites
  6554.     $BlizzABS.cache.damages.each_index {|i|
  6555.         # if request
  6556.         if $BlizzABS.cache.damages[i].is_a?(BlizzABS::DamageRequest)
  6557.           # create sprite based upon request
  6558.           $BlizzABS.cache.damages[i] =
  6559.               Sprite_Damage.new($BlizzABS.cache.damages[i])
  6560.         # if damage sprite opacity is 0
  6561.         elsif $BlizzABS.cache.damages[i].opacity == 0
  6562.           # delete damage sprite
  6563.           $BlizzABS.cache.damages[i].dispose
  6564.           # remove deleted damage sprite
  6565.           $BlizzABS.cache.damages[i] = nil
  6566.         end}
  6567.     # iterate through all beam sprites
  6568.     $BlizzABS.cache.beams.each_index {|i|
  6569.         # if damage sprite opacity is 0
  6570.         if $BlizzABS.cache.beams[i][0].disposed?
  6571.           # remove deleted damage sprite
  6572.           $BlizzABS.cache.beams[i] = nil
  6573.         elsif $BlizzABS.cache.beams[i][0].opacity == 0
  6574.           # delete damage sprite
  6575.           $BlizzABS.cache.beams[i][0].dispose
  6576.           # remove deleted damage sprite
  6577.           $BlizzABS.cache.beams[i] = nil
  6578.         end}
  6579.     # remove nil values from both arrays
  6580.     $BlizzABS.cache.damages.compact!
  6581.     $BlizzABS.cache.beams.compact!
  6582.     # if damage sprites allowed to be updated
  6583.     if @dmg_update
  6584.       # update damage sprites
  6585.       $BlizzABS.cache.damages.each {|dmg| dmg.update}
  6586.       # iterate through all beam sprites
  6587.       $BlizzABS.cache.beams.each {|beam|
  6588.           # decrease counter
  6589.           beam[1] -= 1
  6590.           # set new opacity
  6591.           beam[0].opacity = beam[1] * 15}
  6592.     end
  6593.     # call original method
  6594.     upd_blizzabs_later
  6595.     # update character sprites additionally
  6596.     update_blizzabs_character_sprites
  6597.   end
  6598.   #----------------------------------------------------------------------------
  6599.   # update_blizzabs_character_sprites
  6600.   #  Updates the character sprites additionally.
  6601.   #----------------------------------------------------------------------------
  6602.   def update_blizzabs_character_sprites
  6603.     # iterate through all character sprites
  6604.     @character_sprites.each_index {|i|
  6605.         # temporary variables
  6606.         sprite = @character_sprites[i]
  6607.         character = sprite.character
  6608.         # if character is a dead enemy or an unsummoning pet or monster
  6609.         if (character.is_a?(Map_Enemy) || character.is_a?(Map_Actor) &&
  6610.             $BlizzABS.summoned?(character)) && character.battler != nil &&
  6611.             character.battler.dead?
  6612.           # set dying flag
  6613.           sprite.dying = true
  6614.         # if character which the sprite observes is a projectile
  6615.         elsif character.is_a?(Map_Projectile) && character.fade_out
  6616.           # set fade out flag
  6617.           sprite.fade_out = true
  6618.         end
  6619.         # if dying
  6620.         if sprite.dying
  6621.           # update die
  6622.           sprite.update_die
  6623.         # if respawning
  6624.         elsif sprite.respawning
  6625.           # update die
  6626.           sprite.update_respawn
  6627.         # if fading in
  6628.         elsif sprite.fade_in
  6629.           # update fade in
  6630.           sprite.update_fade_in
  6631.         # if fading out
  6632.         elsif sprite.fade_out
  6633.           # update fading out
  6634.           sprite.update_fade_out
  6635.         end
  6636.         # if sprite died and ready for deletion or expired character
  6637.         if character.terminate
  6638.           # if character is remote and remote expired
  6639.           if character.is_a?(Map_Remote)
  6640.             # remove projectile from active remotes
  6641.             $BlizzABS.cache.remotes.delete(character)
  6642.           # if character which the sprite observes is enemy
  6643.           elsif character.is_a?(Map_Enemy)
  6644.             # find all Respawn Points for this enemy
  6645.             tmp = $game_map.respawns.find_all {|event|
  6646.                 !event.erased && event.respawn_ids != nil &&
  6647.                 event.respawn_ids.include?(character.battler_id)}
  6648.             # if none exists
  6649.             if tmp.size == 0
  6650.               # normal respawn setting
  6651.               time = $game_system.respawn_time
  6652.             else
  6653.               # get a random Respawn Point and let this enemy know where it is
  6654.               character.respawn_point = tmp[rand(tmp.size)]
  6655.               # set the Respawn Points respawn time
  6656.               time = character.respawn_point.respawn_time
  6657.             end
  6658.             # add respawn counter for character
  6659.             $game_system.killed[character] = time * 40
  6660.           end
  6661.           # dispose sprite
  6662.           sprite.dispose
  6663.           # remove sprite from spriteset
  6664.           @character_sprites[i] = nil
  6665.         end}
  6666.     # remove nil values
  6667.     @character_sprites.compact!
  6668.   end
  6669.  
  6670. end
  6671.  
  6672. #==============================================================================
  6673. # Window_Message
  6674. #------------------------------------------------------------------------------
  6675. #  This class was modified to override Blizz-ABS battle handling for correct
  6676. #  window position display.
  6677. #==============================================================================
  6678.  
  6679. class Window_Message
  6680.  
  6681.   #----------------------------------------------------------------------------
  6682.   # override reset_window
  6683.   #----------------------------------------------------------------------------
  6684.   alias reset_window_blizzabs_later reset_window
  6685.   def reset_window(change_opacity = true)
  6686.     # store old in_battle flag and set new in_battle flag
  6687.     tmp, $game_temp.in_battle = $game_temp.in_battle, false
  6688.     # if ccoa's UMS is being used
  6689.     if $game_system.ums_mode != nil
  6690.       # call original method with parameter
  6691.       reset_window_blizzabs_later(change_opacity)
  6692.     else
  6693.       # call original method
  6694.       reset_window_blizzabs_later
  6695.     end
  6696.     # restore in_battle flag
  6697.     $game_temp.in_battle = tmp
  6698.   end
  6699.  
  6700. end
  6701.  
  6702. #==============================================================================
  6703. # Scene_Title
  6704. #------------------------------------------------------------------------------
  6705. #  This class was enhanced to size down the animations upon loading.
  6706. #==============================================================================
  6707.  
  6708. class Scene_Title
  6709.  
  6710.   #----------------------------------------------------------------------------
  6711.   # override main
  6712.   #----------------------------------------------------------------------------
  6713.   alias main_blizzabs_later main
  6714.   def main
  6715.     # call original method
  6716.     main_blizzabs_later
  6717.     # if SMALL_ANIMATIONS is turned on and scene exists
  6718.     if BlizzABS::Config::SMALL_ANIMATIONS && $scene != nil
  6719.       # size down animations
  6720.       $BlizzABS.util.animations_size_down
  6721.     end
  6722.   end
  6723.  
  6724. end
  6725.  
  6726. #==============================================================================
  6727. # Scene_Map
  6728. #------------------------------------------------------------------------------
  6729. #  This class was enhanced to support HUD control and creation system and
  6730. #  Blizz-ABS battle handling and level up text display.
  6731. #==============================================================================
  6732.  
  6733. class Scene_Map
  6734.  
  6735.   # setting all accessible variables
  6736.   attr_accessor :spriteset
  6737.   #----------------------------------------------------------------------------
  6738.   # override main
  6739.   #----------------------------------------------------------------------------
  6740.   alias main_blizzabs_later main
  6741.   def main
  6742.     # create HUD if HUD is turned on and HUD active
  6743.     @hud = Hud.new if BlizzABS::Config::HUD_ENABLED && $game_system.hud
  6744.     # if HOTKEYS is turned on and assignment display active
  6745.     if BlizzABS::Config::HOTKEYS && $game_system.hotkeys
  6746.       # create assignment display
  6747.       @hotkeys = Hotkey_Assignment.new
  6748.     end
  6749.     # if MINIMAP is turned on and minimap active
  6750.     if BlizzABS::Config::MINIMAP && $game_system.minimap > 0
  6751.       # create HUD
  6752.       @minimap = Minimap.new
  6753.     end
  6754.     # tests and sets the in_battle flag
  6755.     test_in_battle
  6756.     # call original method
  6757.     main_blizzabs_later
  6758.     # set in_battle flag
  6759.     $game_temp.in_battle = false
  6760.     # delete HUD elements that exist
  6761.     [@hud, @hotkeys, @minimap].each {|s| s.dispose if s != nil}
  6762.   end
  6763.   #----------------------------------------------------------------------------
  6764.   # override transfer_player
  6765.   #----------------------------------------------------------------------------
  6766.   alias transfer_player_blizzabs_later transfer_player
  6767.   def transfer_player
  6768.     # call original method
  6769.     transfer_player_blizzabs_later
  6770.     # test and set the in_battle flag
  6771.     test_in_battle
  6772.   end
  6773.   #----------------------------------------------------------------------------
  6774.   # test_in_battle
  6775.   #  Sets the in_battle flag to control game flow.
  6776.   #----------------------------------------------------------------------------
  6777.   def test_in_battle
  6778.     # if master override is being used
  6779.     if $game_system.blizzabs != nil
  6780.       # enforce user's setting
  6781.       $game_temp.in_battle = $game_system.blizzabs
  6782.     # if event code is being executed or message window is being displayed
  6783.     elsif $game_system.map_interpreter.running? || $game_temp.message_window_showing
  6784.       # disable Blizz-ABS controls
  6785.       $game_temp.in_battle = false
  6786.     else
  6787.       # depending on chosen DISABLE_ABS_MODE in battle or not in battle
  6788.       $game_temp.in_battle = case BlizzABS::Config::DISABLE_ABS_MODE
  6789.       when 0 then true
  6790.       when 1 then ($game_system.battlers_number > 0)
  6791.       when 2 then ($game_map.battlers.size > 0)
  6792.       when 3 then ($game_map.battlers_in_range.size > 0)
  6793.       end
  6794.     end
  6795.   end
  6796.   #----------------------------------------------------------------------------
  6797.   # judge
  6798.   #  Checks whether Game Over should be initiated.
  6799.   #----------------------------------------------------------------------------
  6800.   def judge
  6801.     return $game_party.all_dead?
  6802.   end
  6803.   #----------------------------------------------------------------------------
  6804.   # setup_gameover
  6805.   #  Processes the Game Over.
  6806.   #----------------------------------------------------------------------------
  6807.   def setup_gameover
  6808.     # set game over
  6809.     $game_temp.gameover = judge
  6810.     # if game over
  6811.     if $game_temp.gameover
  6812.       # play collapse sound effect
  6813.       $game_system.se_play($data_system.actor_collapse_se)
  6814.       # call original method
  6815.       upd_blizzabs_later
  6816.       # reset remotes and damage sprites
  6817.       $BlizzABS.cache.clean
  6818.       # update the HUD
  6819.       hud_update
  6820.       # confirm game over
  6821.       return true
  6822.     end
  6823.     # no game over
  6824.     return false
  6825.   end
  6826.   #----------------------------------------------------------------------------
  6827.   # override update
  6828.   #----------------------------------------------------------------------------
  6829.   alias upd_blizzabs_later update
  6830.   def update
  6831.     # update path finder
  6832.     $BlizzABS.AI.update
  6833.     # if temporary character selection exists
  6834.     if $game_temp.select_data != nil
  6835.       # call selection update
  6836.       update_selection
  6837.       # abort rest of the scene
  6838.       return
  6839.     end
  6840.     # test and set the in_battle flag
  6841.     test_in_battle
  6842.     # needed to prevent a glitch
  6843.     $game_temp.battle_turn = 1
  6844.     # abort if game over process confirms it
  6845.     return if $game_system.auto_gameover && setup_gameover
  6846.     # update level ups
  6847.     update_lvlup
  6848.     # call original method
  6849.     upd_blizzabs_later
  6850.     # update the HUD
  6851.     hud_update
  6852.   end
  6853.   #----------------------------------------------------------------------------
  6854.   # update_lvlup
  6855.   #  Updates level up displays.
  6856.   #----------------------------------------------------------------------------
  6857.   def update_lvlup
  6858.     # iterate through all map actors and pets
  6859.     ($BlizzABS.actors + $BlizzABS.pets).each {|actor|
  6860.         # if leveled up
  6861.         if actor.valid? && actor.battler != nil && actor.battler.level_up?
  6862.           # recover if RECOVER_ON_LEVEL_UP is turned on
  6863.           actor.battler.recover_all if BlizzABS::Config::RECOVER_ON_LEVEL_UP
  6864.           # if DISPLAY_LEVEL_UP is turned on
  6865.           if BlizzABS::Config::DISPLAY_LEVEL_UP
  6866.             # create level up display
  6867.             $BlizzABS.util.display_levelup(actor)
  6868.           end
  6869.           # if ANIMATIONS is turned on
  6870.           if BlizzABS::Config::ANIMATIONS
  6871.             # if first actor
  6872.             if actor.battler.index == 0
  6873.               # set animation ID if LEVEL_UP_ANIMATION_ID is turned on
  6874.               $game_player.animation_id = BlizzABS::Config::LEVEL_UP_ANIMATION_ID
  6875.             # if caterpillar is turned on
  6876.             elsif $game_system.caterpillar
  6877.               # set animation ID
  6878.               $BlizzABS.battlers[actor.index].animation_id =
  6879.                     BlizzABS::Config::LEVEL_UP_ANIMATION_ID
  6880.             end
  6881.           end
  6882.         end}
  6883.   end
  6884.   #----------------------------------------------------------------------------
  6885.   # hud_update
  6886.   #  Contains a couple of routine calls to handle with the HUD.
  6887.   #----------------------------------------------------------------------------
  6888.   def hud_update
  6889.     # check activation of HUD parts
  6890.     check_huds
  6891.     # update minimap
  6892.     update_minimap
  6893.     # update hotkey assignment display
  6894.     update_hotkeys
  6895.     # iterate through all the HUD sprites
  6896.     [@hud, @minimap, @hotkeys].each {|s|
  6897.         # if sprite exists
  6898.         if s != nil
  6899.           # update sprite
  6900.           s.update
  6901.           # if player is on the same position as one of the sprites on the screen
  6902.           if $game_player.screen_x < s.vx + s.vw + 16 &&
  6903.               $game_player.screen_y < s.vy + s.vh + 48 &&
  6904.               $game_player.screen_x > s.vx && $game_player.screen_y > s.vy &&
  6905.               (s != @minimap || $game_system.minimap < 2)
  6906.             # decrease opacity quickly if critical opacity not reached
  6907.             s.opacity -= 25 if s.opacity > 80
  6908.           # if not full opacity
  6909.           elsif s.opacity <= 255
  6910.             # increase opacity quickly if critical opacity not reached
  6911.             s.opacity += 25
  6912.           end
  6913.         end}
  6914.   end
  6915.   #----------------------------------------------------------------------------
  6916.   # check_huds
  6917.   #  Handles enabling and disabling the HUD parts on the map.
  6918.   #----------------------------------------------------------------------------
  6919.   def check_huds
  6920.     # if minimap button is enabled and pressed
  6921.     if $game_system.minimap_button && Input.trigger?(Input::Minimap)
  6922.       # trigger minimap active
  6923.       $game_system.minimap = ($game_system.minimap + 1) % 3
  6924.     end
  6925.     # if hotkey display button is enabled and pressed
  6926.     if $game_system.hotkey_button && Input.trigger?(Input::Hotkey)
  6927.       # trigger hotkey display active
  6928.       $game_system.hotkeys = (!$game_system.hotkeys)
  6929.     end
  6930.     # if HUD button is enabled and pressed
  6931.     if $game_system.hud_button && Input.trigger?(Input::Hud)
  6932.       # trigger it active
  6933.       $game_system.hud = (!$game_system.hud)
  6934.     end
  6935.     # if minimap not active and minimap exists
  6936.     if $game_system.minimap == 0 && @minimap != nil
  6937.       # delete it
  6938.       @minimap.dispose
  6939.       @minimap = nil
  6940.     # if minimap is turned on and active and doesn't exist
  6941.     elsif BlizzABS::Config::MINIMAP && $game_system.minimap > 0
  6942.       # create it
  6943.       @minimap = Minimap.new if @minimap == nil
  6944.     end
  6945.     # if assignment display not active and exists
  6946.     if !$game_system.hotkeys && @hotkeys != nil
  6947.       # delete it
  6948.       @hotkeys.dispose
  6949.       @hotkeys = nil
  6950.     # if HOTKEYS is turned on and active and doesn't exist
  6951.     elsif BlizzABS::Config::HOTKEYS && $game_system.hotkeys
  6952.       # create it
  6953.       @hotkeys = Hotkey_Assignment.new if @hotkeys == nil
  6954.     end
  6955.     # if HUD not active and HUD exists
  6956.     if !$game_system.hud && @hud != nil
  6957.       # delete it
  6958.       @hud.dispose
  6959.       @hud = nil
  6960.     # if HUD is turned on and HUD active and HUD doesn't exist
  6961.     elsif BlizzABS::Config::HUD_ENABLED && $game_system.hud
  6962.       # create it
  6963.       @hud = Hud.new if @hud == nil
  6964.     end
  6965.   end
  6966.   #----------------------------------------------------------------------------
  6967.   # update_minimap
  6968.   #  Updates the minimap.
  6969.   #----------------------------------------------------------------------------
  6970.   def update_minimap
  6971.     # stop if minimap doesn't exist or not in fullscreen mode
  6972.     return if @minimap == nil
  6973.     # if not in fullscreen mode
  6974.     if $game_system.minimap < 2
  6975.       # update the minimap
  6976.       @minimap.update
  6977.       # stop
  6978.       return
  6979.     end
  6980.     # unless fullscreen already initialized and no new map
  6981.     unless @minimap.viewport.rect.width == 640 &&
  6982.         @minimap.map_id == $game_map.map_id
  6983.       # set display rectangle
  6984.       @minimap.viewport.rect.set(0, 0, 640, 480)
  6985.       # update the offset
  6986.       @minimap.update(true)
  6987.     else
  6988.       # update the minimap
  6989.       @minimap.update
  6990.     end
  6991.     # if pressed turning button
  6992.     if $game_system.turn_button && Input.press?(Input::Turn) &&
  6993.         !$game_system.map_interpreter.running? && !@move_route_forcing &&
  6994.         !$game_temp.message_window_showing
  6995.       # if map width out of screen width
  6996.       if @minimap.bitmap.width > 640
  6997.         # if holding right
  6998.         if Input.repeat?(Input::RIGHT)
  6999.           # if map not out of screen yet
  7000.           if @minimap.ox + 640 < @minimap.bitmap.width
  7001.             # play cursor sound
  7002.             $game_system.se_play($data_system.cursor_se)
  7003.             # move minimap
  7004.             @minimap.ox += 32
  7005.             # move minimap
  7006.           else
  7007.             # play buzzer sound
  7008.             $game_system.se_play($data_system.buzzer_se)
  7009.           end
  7010.         elsif Input.repeat?(Input::LEFT)
  7011.           if @minimap.ox > 0
  7012.             # play cursor sound
  7013.             $game_system.se_play($data_system.cursor_se)
  7014.             # move minimap
  7015.             @minimap.ox -= 32
  7016.           else
  7017.             # play buzzer sound
  7018.             $game_system.se_play($data_system.buzzer_se)
  7019.           end
  7020.         end
  7021.       end
  7022.       if @minimap.bitmap.height > 480
  7023.         if Input.repeat?(Input::DOWN)
  7024.           if @minimap.oy + 480 < @minimap.bitmap.height
  7025.             # play cursor sound
  7026.             $game_system.se_play($data_system.cursor_se)
  7027.             # move minimap
  7028.             @minimap.oy += 32
  7029.           else
  7030.             # play buzzer sound
  7031.             $game_system.se_play($data_system.buzzer_se)
  7032.           end
  7033.         elsif Input.repeat?(Input::UP)
  7034.           if @minimap.oy > 0
  7035.             # play cursor sound
  7036.             $game_system.se_play($data_system.cursor_se)
  7037.             # move minimap
  7038.             @minimap.oy -= 32
  7039.           else
  7040.             # play buzzer sound
  7041.             $game_system.se_play($data_system.buzzer_se)
  7042.           end
  7043.         end
  7044.       end
  7045.     end
  7046.   end
  7047.   #----------------------------------------------------------------------------
  7048.   # update_hotkeys
  7049.   #  Updates hotkey assignment display.
  7050.   #----------------------------------------------------------------------------
  7051.   def update_hotkeys
  7052.     # update hotkey assignment display if existing
  7053.     @hotkeys.update if @hotkeys != nil
  7054.     # no hotkey linking if direct keys are being used
  7055.     return if BlizzABS::Config::DIRECT_HOTKEYS
  7056.     # iterate through all number keys
  7057.     BlizzABS::Cache::Keys.each {|i|
  7058.         # if number key i was triggered
  7059.         if Input.trigger?(Input::Key[i.to_s])
  7060.           # if hotkey is valid for this skill
  7061.           if $game_player.skill_hotkeys[i] != 0
  7062.             # set this skill as the hot skill
  7063.             $game_player.battler.skill = $game_player.skill_hotkeys[i]
  7064.           # if hotkey is valid for this item
  7065.           elsif $game_player.item_hotkeys[i] != 0
  7066.             # set this item as hot item
  7067.             $game_player.battler.item = $game_player.item_hotkeys[i]
  7068.           else
  7069.             # reset hot skill and hot item
  7070.             $game_player.battler.skill = $game_player.battler.item = 0
  7071.           end
  7072.         end}
  7073.   end
  7074.   #----------------------------------------------------------------------------
  7075.   # update_selection
  7076.   #  Overrides everything else in the map scene to allow the player to select
  7077.   #  an opponent to be attacked.
  7078.   #----------------------------------------------------------------------------
  7079.   def update_selection
  7080.     # initialize select interruption if not initialized
  7081.     initialize_selection if @index == nil
  7082.     # update selection input
  7083.     targets = process_selection
  7084.     # execute selection if target exists or cancelled
  7085.     execute_selection(targets) if targets != nil
  7086.   end
  7087.   #----------------------------------------------------------------------------
  7088.   # initialize_selection
  7089.   #  Sets up everything used in the selection override.
  7090.   #----------------------------------------------------------------------------
  7091.   def initialize_selection
  7092.     # temporary variables
  7093.     object, r, type, sprites = $game_temp.select_data
  7094.     # check scope and determine target alignment, dead flag and all flag
  7095.     enemy, dead, all = $BlizzABS.util.get_scope_data(object.scope)
  7096.     # if Tons is there and targeting all
  7097.     if $tons_version != nil && object.is_a?(RPG::Skill) &&
  7098.         ($tons_version >= 6.02 && $game_system.TARGET_EM_ALL &&
  7099.         FULL_TARGET_IDS.include?(object.id))
  7100.       # forces all flag
  7101.       target_all = all = true
  7102.     end
  7103.     # increase z coordinate of all targets
  7104.     sprites.each {|sprite| sprite.z += 1000000}
  7105.     # initialized select interruption
  7106.     @index = 0
  7107.     # freeze screen display
  7108.     Graphics.freeze
  7109.     # temporary variable
  7110.     tone = $game_screen.tone
  7111.     # make screen slightly darker
  7112.     @spriteset.viewport1.tone = Tone.new(tone.red - 32, tone.green - 32,
  7113.         tone.blue - 32, tone.gray)
  7114.     # play decision sound
  7115.     $game_system.se_play($data_system.decision_se)
  7116.     # create help window
  7117.     @win = Window_Help.new
  7118.     # make partially transparent and set z coordinate
  7119.     @win.z, @win.opacity = 10000, 192
  7120.     # create 2 sprites
  7121.     @ranges = [Sprite.new(@spriteset.viewport1),
  7122.                Sprite.new(@spriteset.viewport1)]
  7123.     # set z coordinate
  7124.     @ranges[0].z = @ranges[1].z = 950000
  7125.     # color for selection rectangle
  7126.     color = (target_all ? Color.new(255, 255, 255, 96) : enemy ?
  7127.         Color.new(255, 0, 0, 96) : Color.new(0, 128, 255, 96))
  7128.     # if fullscreen skill
  7129.     if type == BlizzABS::BEAM && all
  7130.       # create 2 bitmaps for the sprites
  7131.       @ranges[0].bitmap = Bitmap.new(640, 480)
  7132.       @ranges[1].bitmap = Bitmap.new(638, 478)
  7133.       # draw big yellow rectangle
  7134.       @ranges[0].bitmap.fill_rect(0, 0, 640, 480, Color.new(255, 255, 0, 160))
  7135.       # remove inner rectangle area
  7136.       @ranges[0].bitmap.fill_rect(1, 1, 638, 478, Color.new(0, 0, 0, 0))
  7137.       # set x, y position
  7138.       @ranges[1].x = @ranges[1].y = 1
  7139.       # draw slightly smaller rectangle
  7140.       @ranges[1].bitmap.fill_rect(0, 0, 638, 478, color)
  7141.     else
  7142.       # create 2 bitmaps for the sprites
  7143.       @ranges[0].bitmap = Bitmap.new(r * 2 + 32, r * 2 + 32)
  7144.       @ranges[1].bitmap = Bitmap.new(r * 2 + 32, r * 2 + 32)
  7145.       # set sprite position
  7146.       @ranges[0].x, @ranges[0].y = $game_player.screen_x, $game_player.screen_y
  7147.       @ranges[1].x, @ranges[1].y = $game_player.screen_x, $game_player.screen_y
  7148.       # set sprite position offset
  7149.       @ranges[0].ox, @ranges[0].oy = r + 16, r + 32
  7150.       @ranges[1].ox, @ranges[1].oy = r + 16, r + 32
  7151.       # draw big yellow circle
  7152.       @ranges[0].bitmap.draw_circle(0, 0, r.to_i + 16, Color.new(255, 255, 0, 160))
  7153.       # remove area that is smaller by radius of 1
  7154.       @ranges[0].bitmap.draw_circle(1, 1, r.to_i + 15, Color.new(0, 0, 0, 0))
  7155.       # draw slightly smaller circle
  7156.       @ranges[1].bitmap.draw_circle(1, 1, r.to_i + 15, color)
  7157.     end
  7158.     # if targeting all targets
  7159.     if all
  7160.       # all targets are selected
  7161.       sprites.each {|sprite| sprite.select = 1}
  7162.       # display "All" in help window
  7163.       @win.set_text(BlizzABS::Cache::WORDAll, 1)
  7164.     else
  7165.       # first target is selected
  7166.       sprites[0].select = 1
  7167.       # display target's name in help window
  7168.       @win.set_text(sprites[0].character.battler.name, 1)
  7169.     end
  7170.     # set current yellow blinking of sprite
  7171.     @ranges[1].color.set(255, 255, 0, (16 - Graphics.frame_count % 32).abs * 8)
  7172.     # make screen transition
  7173.     Graphics.transition
  7174.   end
  7175.   #----------------------------------------------------------------------------
  7176.   # process_selection
  7177.   #  Updates the input during the selection interruption.
  7178.   #----------------------------------------------------------------------------
  7179.   def process_selection
  7180.     # temporary variables
  7181.     object, r, type, sprites = $game_temp.select_data
  7182.     # if Tons is there and targeting all
  7183.     if $tons_version != nil && object.is_a?(RPG::Skill) &&
  7184.         ($tons_version >= 6.02 && $game_system.TARGET_EM_ALL &&
  7185.         FULL_TARGET_IDS.include?(object.id))
  7186.       # forces all flag
  7187.       all = true
  7188.     else
  7189.       # check scope and determine all flag
  7190.       all = $BlizzABS.util.get_scope_data(object.scope)[2]
  7191.     end
  7192.     # animate yellow blinking of sprite
  7193.     @ranges[1].color.set(255, 255, 0, (16 - Graphics.frame_count % 32).abs * 8)
  7194.     # update select animation for all selectable sprites
  7195.     sprites.each {|sprite| sprite.update_select}
  7196.     # if not targeting all enemies
  7197.     if !all
  7198.       # display target's name in help window
  7199.       @win.set_text(sprites[@index].character.battler.name, 1)
  7200.       # if pressed left or up
  7201.       if Input.repeat?(Input::LEFT) || Input.repeat?(Input::UP)
  7202.         # play cursor sound
  7203.         $game_system.se_play($data_system.cursor_se)
  7204.         # deselect currently selected sprite
  7205.         sprites[@index].select = 0
  7206.         # change selection index
  7207.         @index = (@index + 1) % sprites.size
  7208.         # select currently selected sprite
  7209.         sprites[@index].select = 1
  7210.       # if pressed right or down
  7211.       elsif Input.repeat?(Input::RIGHT) || Input.repeat?(Input::DOWN)
  7212.         # play cursor sound
  7213.         $game_system.se_play($data_system.cursor_se)
  7214.         # deselect currently selected sprite
  7215.         sprites[@index].select = 0
  7216.         # change selection index
  7217.         @index = (@index + sprites.size - 1) % sprites.size
  7218.         # select currently selected sprite
  7219.         sprites[@index].select = 1
  7220.       end
  7221.     end
  7222.     # if cancel button pressed
  7223.     if Input.repeat?(Input::B)
  7224.       # play cancel sound
  7225.       $game_system.se_play($data_system.cancel_se)
  7226.       # cancelled
  7227.       targets = false
  7228.     # if confirm button pressed
  7229.     elsif Input.repeat?(Input::C)
  7230.       # play decision sound
  7231.       $game_system.se_play($data_system.decision_se)
  7232.       # if targeting all enemies
  7233.       if all
  7234.         # initialize array
  7235.         targets = []
  7236.         # add all targets
  7237.         sprites.each {|sprite| targets.push(sprite.character)}
  7238.       else
  7239.         # decided target
  7240.         targets = [sprites[@index].character]
  7241.       end
  7242.     end
  7243.     # result
  7244.     return targets
  7245.   end
  7246.   #----------------------------------------------------------------------------
  7247.   # execute_selection
  7248.   #  Executes the selection.
  7249.   #----------------------------------------------------------------------------
  7250.   def execute_selection(targets)
  7251.     # freeze screen display
  7252.     Graphics.freeze
  7253.     # iterate through all target sprites
  7254.     $game_temp.select_data[3].each {|sprite|
  7255.         # deselect sprite
  7256.         sprite.select = 0
  7257.         # remove selection animation completely
  7258.         sprite.update_select
  7259.         # reset z coordinate
  7260.         sprite.z -= 1000000}
  7261.     # reset screen tint
  7262.     @spriteset.viewport1.tone = $game_screen.tone
  7263.     # if not cancelled
  7264.     if targets != false
  7265.       # set the target
  7266.       $game_player.ai.target = targets[0]
  7267.       # use skill or item
  7268.       case $game_temp.select_data[0]
  7269.       when RPG::Skill then $game_player.use_skill($game_temp.select_data[0], true)
  7270.       when RPG::Item then $game_player.use_item($game_temp.select_data[0], true)
  7271.       end
  7272.     end
  7273.     # delete range sprites and help window
  7274.     (@ranges + [@win]).each {|object| object.dispose}
  7275.     # remove all temporary select interuption data from memory
  7276.     @ranges = @index = @tone = @win = $game_temp.select_data = nil
  7277.     # make screen transition
  7278.     Graphics.transition
  7279.   end
  7280.   #----------------------------------------------------------------------------
  7281.   # override call_menu
  7282.   #----------------------------------------------------------------------------
  7283.   alias call_menu_blizzabs_later call_menu
  7284.   def call_menu
  7285.     # call original method if player is idle
  7286.     call_menu_blizzabs_later if $game_player.idle?
  7287.   end
  7288.  
  7289. end
  7290.  
  7291. #==============================================================================
  7292. # Scene_Menu
  7293. #------------------------------------------------------------------------------
  7294. #  This class was modified to infilitrate the real menu with the Blizz-ABS
  7295. #  Pre-Menu.
  7296. #==============================================================================
  7297.  
  7298. class Scene_Menu
  7299.  
  7300.   #----------------------------------------------------------------------------
  7301.   # override Initialization
  7302.   #  index - the cursor index
  7303.   #----------------------------------------------------------------------------
  7304.   alias init_blizzabs_later initialize
  7305.   def initialize(index = nil)
  7306.     # set index flag
  7307.     @index_flag = index
  7308.     # call original method with either 0 or the current index
  7309.     init_blizzabs_later(index == nil ? 0 : index)
  7310.   end
  7311.   #----------------------------------------------------------------------------
  7312.   # override main
  7313.   #----------------------------------------------------------------------------
  7314.   alias main_blizzabs_later main
  7315.   def main
  7316.     # if index flag does not exist
  7317.     if @index_flag == nil
  7318.       # set in_battle flag
  7319.       $game_temp.in_battle = true
  7320.       # create HUD if HUD is turned on and HUD active
  7321.       @hud = Hud.new if BlizzABS::Config::HUD_ENABLED && $game_system.hud
  7322.       # if ASSIGNMENT is turned on and assignment display active
  7323.       if BlizzABS::Config::HOTKEYS && $game_system.hotkeys
  7324.         # create assignment display
  7325.         @hotkeys = Hotkey_Assignment.new
  7326.       end
  7327.       # if MINIMAP is turned on and minimap active
  7328.       if BlizzABS::Config::MINIMAP && $game_system.minimap > 0
  7329.         # create HUD
  7330.         @minimap = Minimap.new
  7331.         # create HUD
  7332.         @minimap.update
  7333.       end
  7334.       # create options window
  7335.       @window = Window_Command.new(192, BlizzABS::Cache::CommandsPreMenu)
  7336.       # if no actors in the party
  7337.       if $game_party.actors.size == 0
  7338.         # disable options
  7339.         @window.disable_item(1)
  7340.         @window.disable_item(2)
  7341.         @window.disable_item(3)
  7342.       end
  7343.       # set x and y position
  7344.       @window.x, @window.y = 320 - @window.width/2, 240 - @window.height/2
  7345.       # set z position
  7346.       @window.z = 21000
  7347.       # set back opacity
  7348.       @window.back_opacity = 160
  7349.       # create spriteset
  7350.       @spriteset = Spriteset_Map.new
  7351.       # create viewport
  7352.       @view = Viewport.new(0, 0, 640, 480)
  7353.       # if using a fixed tint
  7354.       if BlizzABS::Config::MENU_COLOR_TINT > 0
  7355.         # get tint
  7356.         tint = BlizzABS::Config::MENU_COLOR_TINT
  7357.       else
  7358.         # randomize tint
  7359.         tint = rand(8) + 1
  7360.       end
  7361.       # tint viewport
  7362.       case tint
  7363.       # black-white tint
  7364.       when 1 then @view.tone = Tone.new(-40, -40, -40, 255)
  7365.       # blue tint
  7366.       when 2 then @view.tone = Tone.new(-255, -255, 0, 255)
  7367.       # green tint
  7368.       when 3 then @view.tone = Tone.new(-255, 0, -255, 255)
  7369.       # red tint
  7370.       when 4 then @view.tone = Tone.new(0, -255, -255, 255)
  7371.       # yellow tint
  7372.       when 5 then @view.tone = Tone.new(0, 0, -255, 255)
  7373.       # mangenta tint
  7374.       when 6 then @view.tone = Tone.new(0, -255, 0, 255)
  7375.       # cyan tint
  7376.       when 7 then @view.tone = Tone.new(-255, 0, 0, 255)
  7377.       # darker tint
  7378.       when 8 then @view.tone = Tone.new(-60, -60, -60, 0)
  7379.       end
  7380.       # transition
  7381.       Graphics.transition
  7382.       # loop
  7383.       loop do
  7384.         # update game screen
  7385.         Graphics.update
  7386.         # update input
  7387.         Input.update
  7388.         # stop if frame update
  7389.         break if update_before_main
  7390.       end
  7391.       # freeze screen
  7392.       Graphics.freeze
  7393.       # delete HUD elements that exist
  7394.       [@hud, @hotkeys, @minimap].each {|s| s.dispose if s != nil}
  7395.       # delete window
  7396.       @window.dispose
  7397.       @window = nil
  7398.       # delete spriteset
  7399.       @spriteset.dispose
  7400.       @spriteset = nil
  7401.       # delete viewport (screen tint) if new scene is still the menu or map
  7402.       @view.dispose if $scene.is_a?(Scene_Menu) || $scene.is_a?(Scene_Map)
  7403.       @view = nil
  7404.     end
  7405.     # call original method if scene is still the menu
  7406.     main_blizzabs_later if $scene.is_a?(Scene_Menu)
  7407.   end
  7408.   #----------------------------------------------------------------------------
  7409.   # update_before_main
  7410.   #  Processes the pre-menu.
  7411.   #----------------------------------------------------------------------------
  7412.   def update_before_main
  7413.     # updates path finder
  7414.     $BlizzABS.AI.update
  7415.     # update window
  7416.     @window.update
  7417.     # if window is active
  7418.     if @window.active
  7419.       # if B is pressed
  7420.       if Input.trigger?(Input::B)
  7421.         # play cancel sound
  7422.         $game_system.se_play($data_system.cancel_se)
  7423.         # create map scene
  7424.         $scene = Scene_Map.new
  7425.         # exit this scene
  7426.         return true
  7427.       # if C is pressed
  7428.       elsif Input.trigger?(Input::C)
  7429.         # which option
  7430.         case @window.index
  7431.         when 0
  7432.           # play sound
  7433.           $game_system.se_play($data_system.decision_se)
  7434.           # set in_battle flag
  7435.           $game_temp.in_battle = false
  7436.         when 1
  7437.           # if not actors in the party
  7438.           if $game_party.actors.size == 0
  7439.             # play buzzer sound effect
  7440.             $game_system.se_play($data_system.buzzer_se)
  7441.             # exit method
  7442.             return
  7443.           end
  7444.           # play sound
  7445.           $game_system.se_play($data_system.decision_se)
  7446.           # create hotkey assignment scene with the current screen tint
  7447.           $scene = Scene_Hotkeys.new(@view.tone)
  7448.         when 2
  7449.           # if not actors in the party
  7450.           if $game_party.actors.size == 0
  7451.             # play buzzer sound effect
  7452.             $game_system.se_play($data_system.buzzer_se)
  7453.             # exit method
  7454.             return
  7455.           end
  7456.           # play sound
  7457.           $game_system.se_play($data_system.decision_se)
  7458.           # create AI setup scene with the current screen tint
  7459.           $scene = Scene_AI_Behavior.new(@view.tone)
  7460.         when 3
  7461.           # if not actors in the party
  7462.           if $game_party.actors.size == 0
  7463.             # play buzzer sound effect
  7464.             $game_system.se_play($data_system.buzzer_se)
  7465.             # exit method
  7466.             return
  7467.           end
  7468.           # play sound
  7469.           $game_system.se_play($data_system.decision_se)
  7470.           # create AI setup scene with the current screen tint
  7471.           $scene = Scene_AI_Triggers.new(@view.tone)
  7472.         when 4
  7473.           # play sound
  7474.           $game_system.se_play($data_system.decision_se)
  7475.           # create map scene
  7476.           $scene = Scene_Map.new
  7477.         end
  7478.         # exit this scene
  7479.         return true
  7480.       end
  7481.     end
  7482.     # don't exit this scene
  7483.     return false
  7484.   end
  7485.  
  7486. end
  7487.  
  7488. #==============================================================================
  7489. # Window_Base
  7490. #------------------------------------------------------------------------------
  7491. #  This window was enhanced with utility methods for drawing triggers.
  7492. #==============================================================================
  7493.  
  7494. class Window_Base
  7495.  
  7496.   #----------------------------------------------------------------------------
  7497.   # draw_trigger
  7498.   #  trigger - the trigger
  7499.   #  i       - index of offset
  7500.   #  Draws one trigger.
  7501.   #----------------------------------------------------------------------------
  7502.   def draw_trigger(trigger, i = nil)
  7503.     # if index is a number
  7504.     if i.is_a?(Numeric)
  7505.       # clear field
  7506.       self.contents.fill_rect(0, i * 64, 448, 64, Color.new(0, 0, 0, 0))
  7507.       # draw index
  7508.       self.contents.draw_text(4, i * 64, 36, 32, "#{i+1}.", 2)
  7509.     else
  7510.       # index is 0
  7511.       i = 0
  7512.       # clear field
  7513.       self.contents.fill_rect(0, i * 64, 448, 64, Color.new(0, 0, 0, 0))
  7514.     end
  7515.     # get condition target name
  7516.     target = BlizzABS::Cache::TRGActivators[trigger.activator]
  7517.     # draw condition target name
  7518.     self.contents.draw_text(48, i * 64, 128, 32, target + ':')
  7519.     # if not probability activator
  7520.     if trigger.activator != BlizzABS::TRGProbability
  7521.       # get condition name
  7522.       condition = case trigger.condition
  7523.       when BlizzABS::TRGHP then $data_system.words.hp
  7524.       when BlizzABS::TRGSP then $data_system.words.sp
  7525.       when BlizzABS::TRGState then BlizzABS::Cache::WORDState
  7526.       when BlizzABS::TRGLocation then BlizzABS::Cache::WORDLocation
  7527.       end
  7528.       # draw condition name
  7529.       self.contents.draw_text(224, i * 64, 96, 32, "[#{condition}")
  7530.       # get comparison sign
  7531.       comparator = BlizzABS::Cache::TRGComparators[trigger.comparator]
  7532.       # draw comparison sign
  7533.       self.contents.draw_text(320, i * 64, 32, 32, comparator, 1)
  7534.       # if state condition
  7535.       if trigger.condition == BlizzABS::TRGState
  7536.         # if no state
  7537.         if $data_states[trigger.value] == nil
  7538.           # get normal state name
  7539.           value = BlizzABS::Cache::WORDNormalState
  7540.         else
  7541.           # get state name
  7542.           value = $data_states[trigger.value].name
  7543.         end
  7544.       # if location condition
  7545.       elsif trigger.condition == BlizzABS::TRGLocation
  7546.         # get condition value
  7547.         value = BlizzABS::Cache::TRGLocations[trigger.value]
  7548.       else
  7549.         # get condition value
  7550.         value = "#{trigger.value}%"
  7551.       end
  7552.       # draw condition value
  7553.       self.contents.draw_text(352, i * 64, 128, 32, "#{value}]")
  7554.     else
  7555.       # draw condition value
  7556.       self.contents.draw_text(224, i * 64, 64, 32, "[#{trigger.value}%]")
  7557.     end
  7558.     # draw target word
  7559.     self.contents.draw_text(48, i * 64 + 32, 80, 32, "#{BlizzABS::Cache::WORDTarget}:")
  7560.     # get action target
  7561.     text = BlizzABS::Cache::TRGTargets[trigger.target]
  7562.     # draw action target
  7563.     self.contents.draw_text(128, i * 64 + 32, 88, 32, text)
  7564.     # get action name
  7565.     name = case trigger.action_type
  7566.     when BlizzABS::TRGAttack then $data_system.words.attack
  7567.     when BlizzABS::TRGDefend then $data_system.words.guard
  7568.     when BlizzABS::TRGSkill then $data_skills[trigger.action_data].name
  7569.     when BlizzABS::TRGItem then $data_items[trigger.action_data].name
  7570.     else
  7571.       ''
  7572.     end
  7573.     # draw action name if it exists
  7574.     self.contents.draw_text(224, i * 64 + 32, 220, 32, "- #{name}") if name != ''
  7575.   end
  7576.  
  7577. end
  7578.  
  7579. #==============================================================================
  7580. # Window_Skill_Hotkey
  7581. #------------------------------------------------------------------------------
  7582. #  This class serves as display for skills that can be hotkeyed.
  7583. #==============================================================================
  7584.  
  7585. class Window_Skill_Hotkey < Window_Skill
  7586.  
  7587.   # setting all accessible variables
  7588.   attr_reader :item_max
  7589.   #----------------------------------------------------------------------------
  7590.   # Initialization
  7591.   #  actor - actor
  7592.   #----------------------------------------------------------------------------
  7593.   def initialize(actor)
  7594.     # call superclass method
  7595.     super
  7596.     # set max column number
  7597.     @column_max = 1
  7598.     # set width and height
  7599.     self.width, self.height = 320, 416
  7600.     # set y and z position
  7601.     self.y, self.z = 64, 21000
  7602.     # remove cursor display
  7603.     self.cursor_rect.empty
  7604.     # set to not active
  7605.     self.active = false
  7606.     # refresh display
  7607.     refresh
  7608.   end
  7609.   #----------------------------------------------------------------------------
  7610.   # update
  7611.   #  Updates only if window is active.
  7612.   #----------------------------------------------------------------------------
  7613.   def update
  7614.     super if self.active
  7615.   end
  7616.   #----------------------------------------------------------------------------
  7617.   # switch_actor
  7618.   #  Switch to next actor.
  7619.   #----------------------------------------------------------------------------
  7620.   def switch_actor
  7621.     # get next actor in line
  7622.     @actor = $game_party.actors[(@actor.index + 1) % $game_party.actors.size]
  7623.     # refresh display
  7624.     refresh
  7625.     # if previous actor had more skills than the current one
  7626.     if @index >= @item_max
  7627.       # set cursor to last skill
  7628.       @index = @item_max - 1
  7629.       # update cursor
  7630.       update_cursor_rect
  7631.     end
  7632.   end
  7633.   #----------------------------------------------------------------------------
  7634.   # refresh
  7635.   #  Draws the data on the window.
  7636.   #----------------------------------------------------------------------------
  7637.   def refresh
  7638.     # if bitmap exists
  7639.     if self.contents != nil
  7640.       # delete bitmap
  7641.       self.contents.dispose
  7642.       self.contents = nil
  7643.     end
  7644.     # set up all skills for display
  7645.     setup_skills
  7646.     # create bitmap
  7647.     self.contents = Bitmap.new(width - 32, @item_max * 32)
  7648.     # if using Dyna Edition scripts
  7649.     if $fontface != nil
  7650.       # set font name and size
  7651.       self.contents.font.name = $fontface
  7652.       self.contents.font.size = $fontsize
  7653.     # if using PK Edition 2
  7654.     elsif $defaultfonttype != nil
  7655.       # set font name and size
  7656.       self.contents.font.name = $defaultfonttype
  7657.       self.contents.font.size = $defaultfontsize
  7658.     end
  7659.     # draw all skills
  7660.     draw_skills
  7661.   end
  7662.   #----------------------------------------------------------------------------
  7663.   # setup_skills
  7664.   #  Sets up all skills displayed.
  7665.   #----------------------------------------------------------------------------
  7666.   def setup_skills
  7667.     # empty data
  7668.     @data = []
  7669.     # add all learned skills
  7670.     @actor.skills.each {|id| @data.push($data_skills[id])}
  7671.     # add nil
  7672.     @data.push(nil)
  7673.     # set size
  7674.     @item_max = @data.size
  7675.   end
  7676.   #----------------------------------------------------------------------------
  7677.   # setup_skills
  7678.   #  Draws all skills.
  7679.   #----------------------------------------------------------------------------
  7680.   def draw_skills
  7681.     # draw each skill
  7682.     (0...@item_max).each {|i| draw_item(i)}
  7683.   end  
  7684.   #----------------------------------------------------------------------------
  7685.   # draw_item
  7686.   #  i - skill index
  7687.   #  Draws one complete skill.
  7688.   #----------------------------------------------------------------------------
  7689.   def draw_item(i)
  7690.     # if skill is nil
  7691.     if @data[i] == nil
  7692.       # set font color
  7693.       self.contents.font.color = normal_color
  7694.       # draw "<Remove>"
  7695.       self.contents.draw_text(32, i*32, 204, 32, '<Remove>')
  7696.     else
  7697.       # if skill can be used
  7698.       if @actor.skill_can_use?(@data[i].id)
  7699.         # set font color
  7700.         self.contents.font.color = normal_color
  7701.       else
  7702.         # set font color
  7703.         self.contents.font.color = disabled_color
  7704.       end
  7705.       # clean this display
  7706.       self.contents.fill_rect(Rect.new(4, i*32, 288, 32), Color.new(0, 0, 0, 0))
  7707.       # get icon bitmap
  7708.       bitmap = RPG::Cache.icon(@data[i].icon_name)
  7709.       # get opacity
  7710.       opacity = self.contents.font.color == normal_color ? 255 : 128
  7711.       # draw icon bitmap
  7712.       self.contents.blt(4, 4+i*32, bitmap, Rect.new(0, 0, 24, 24), opacity)
  7713.       # skill name
  7714.       text = @data[i].name
  7715.       # if normal skill, using Tons of Add-ons and EQUAP Skills with AP display
  7716.       if @actor.skills.include?(@data[i].id) &&
  7717.           $tons_version != nil && $tons_version >= 7.32 &&
  7718.           TONS_OF_ADDONS::EQUAP_SKILLS && DISPLAY_AP_REQ
  7719.         # get AP for this skill
  7720.         aps = BlizzCFG.maxap(@data[i].id)
  7721.         # add to text if skill has AP
  7722.         text = "#{text} (#{@actor.ap(@data[i].id)}/#{aps})" if aps != 0
  7723.       end
  7724.       # draw text with name
  7725.       self.contents.draw_text(32, i*32, 204, 32, text)
  7726.       # get basic SP cost
  7727.       sp_cost = @data[i].sp_cost
  7728.       # if using Tons of Add-ons and SP Cost Mod Status
  7729.       if $tons_version != nil && $tons_version >= 6.54 &&
  7730.           $game_system.SP_COST_MOD
  7731.         # get cost modified cost
  7732.         sp_cost = BlizzCFG.get_cost_mod(@actor.states, sp_cost)
  7733.       end
  7734.       # draw skill SP cost
  7735.       self.contents.draw_text(236, i*32, 48, 32, sp_cost.to_s, 2)
  7736.     end
  7737.   end
  7738.  
  7739. end
  7740.  
  7741. #==============================================================================
  7742. # Window_Item_Hotkey
  7743. #------------------------------------------------------------------------------
  7744. #  This class serves as display for items that can be hotkeyed.
  7745. #==============================================================================
  7746.  
  7747. class Window_Item_Hotkey < Window_Item
  7748.  
  7749.   # setting all accessible variables
  7750.   attr_reader :item_max
  7751.   #----------------------------------------------------------------------------
  7752.   # Initialization
  7753.   #  actor - actor
  7754.   #----------------------------------------------------------------------------
  7755.   def initialize
  7756.     # call superclass method
  7757.     super
  7758.     # set max column number
  7759.     @column_max = 1
  7760.     # set width and height
  7761.     self.width, self.height = 320, 416
  7762.     # set x, y and z position
  7763.     self.x, self.y, self.z = 320, 64, 21000
  7764.     # remove cursor display
  7765.     self.cursor_rect.empty
  7766.     # set to not active
  7767.     self.active = false
  7768.     # refresh display
  7769.     refresh
  7770.   end
  7771.   #----------------------------------------------------------------------------
  7772.   # update
  7773.   #  Updates only if window is active
  7774.   #----------------------------------------------------------------------------
  7775.   def update
  7776.     # update only if actove
  7777.     super if self.active
  7778.   end
  7779.   #----------------------------------------------------------------------------
  7780.   # refresh
  7781.   #  Draws the data on the window.
  7782.   #----------------------------------------------------------------------------
  7783.   def refresh
  7784.     # if bitmap exists
  7785.     if self.contents != nil
  7786.       # delete bitmap
  7787.       self.contents.dispose
  7788.       self.contents = nil
  7789.     end
  7790.     # set up all items for display
  7791.     setup_items
  7792.     # create bitmap
  7793.     self.contents = Bitmap.new(width - 32, @item_max * 32)
  7794.     # if using Dyna Edition scripts
  7795.     if $fontface != nil
  7796.       # set font name and size
  7797.       self.contents.font.name = $fontface
  7798.       self.contents.font.size = $fontsize
  7799.     # if using PK Edition 2
  7800.     elsif $defaultfonttype != nil
  7801.       # set font name and size
  7802.       self.contents.font.name = $defaultfonttype
  7803.       self.contents.font.size = $defaultfontsize
  7804.     end
  7805.     # draws all items
  7806.     draw_items
  7807.   end
  7808.   #----------------------------------------------------------------------------
  7809.   # setup_items
  7810.   #  Sets up all items displayed.
  7811.   #----------------------------------------------------------------------------
  7812.   def setup_items
  7813.     # empty data
  7814.     @data = []
  7815.     # iterate through all items
  7816.     (1...$data_items.size).each {|i|
  7817.         # add item if number of items in possesion greater than 0
  7818.         @data.push($data_items[i]) if $game_party.item_number(i) > 0}
  7819.     # add nil
  7820.     @data.push(nil)
  7821.     # set size
  7822.     @item_max = @data.size
  7823.   end
  7824.   #----------------------------------------------------------------------------
  7825.   # setup_items
  7826.   #  Draws all items.
  7827.   #----------------------------------------------------------------------------
  7828.   def draw_items
  7829.     # draw each item
  7830.     (0...@item_max).each {|i| draw_item(i)}
  7831.   end  
  7832.   #----------------------------------------------------------------------------
  7833.   # draw_item
  7834.   #  i - item index
  7835.   #  Draws one complete item.
  7836.   #----------------------------------------------------------------------------
  7837.   def draw_item(i)
  7838.     # if item is nil
  7839.     if @data[i] == nil
  7840.       # set font color
  7841.       self.contents.font.color = normal_color
  7842.       # draw "<Remove>"
  7843.       self.contents.draw_text(32, i*32, 212, 32, '<Remove>')
  7844.     else
  7845.       # get number of items
  7846.       number = $game_party.item_number(@data[i].id)
  7847.       # if item can be used
  7848.       if $game_party.item_can_use?(@data[i].id)
  7849.         # set font color
  7850.         self.contents.font.color = normal_color
  7851.       else
  7852.         # set font color
  7853.         self.contents.font.color = disabled_color
  7854.       end
  7855.       # clean this display
  7856.       self.contents.fill_rect(Rect.new(4, i*32, 288, 32), Color.new(0, 0, 0, 0))
  7857.       # get icon bitmap
  7858.       bitmap = RPG::Cache.icon(@data[i].icon_name)
  7859.       # get opacity
  7860.       opacity = self.contents.font.color == normal_color ? 255 : 128
  7861.       # draw icon bitmap
  7862.       self.contents.blt(4, 4+i*32, bitmap, Rect.new(0, 0, 24, 24), opacity)
  7863.       # draw item name
  7864.       self.contents.draw_text(32, i*32, 212, 32, @data[i].name)
  7865.       # draw ":"
  7866.       self.contents.draw_text(244, i*32, 16, 32, ':', 1)
  7867.       # draw number of items left
  7868.       self.contents.draw_text(260, i*32, 24, 32, number.to_s, 2)
  7869.     end
  7870.   end
  7871.  
  7872. end
  7873.  
  7874. #==============================================================================
  7875. # Window_Behavior
  7876. #------------------------------------------------------------------------------
  7877. #  This window displays an aggressive - offensive grid for AI setup.
  7878. #==============================================================================
  7879.  
  7880. class Window_Behavior < Window_Base
  7881.  
  7882.   #----------------------------------------------------------------------------
  7883.   # Initialization
  7884.   #  actor - the actor
  7885.   #----------------------------------------------------------------------------
  7886.   def initialize(actor, map_actor)
  7887.     # call superclass method
  7888.     super(0, 0, 480, 480)
  7889.     # create bitmap
  7890.     self.contents = Bitmap.new(width - 32, height - 32)
  7891.     # if using Dyna Edition scripts
  7892.     if $fontface != nil
  7893.       # set font name and size
  7894.       self.contents.font.name = $fontface
  7895.       self.contents.font.size = $fontsize
  7896.     # if using PK Edition 2
  7897.     elsif $defaultfonttype != nil
  7898.       # set font name and size
  7899.       self.contents.font.name = $defaultfonttype
  7900.       self.contents.font.size = $defaultfontsize
  7901.     end
  7902.     # store variables
  7903.     @actor = actor
  7904.     # create cursor sprite
  7905.     @actor_sprite = RPG::Sprite.new
  7906.     # get bitmap
  7907.     @actor_sprite.bitmap = RPG::Cache.character(actor.character_name,
  7908.         actor.character_hue)
  7909.     # set sprite z coordinate
  7910.     @actor_sprite.z = 1000
  7911.     # set bitmap source rectangle
  7912.     @actor_sprite.src_rect.set(0, 0, @actor_sprite.bitmap.width / 4,
  7913.         @actor_sprite.bitmap.height / 4)
  7914.     # set coordinate offsets
  7915.     @actor_sprite.ox = @actor_sprite.bitmap.width / 8
  7916.     @actor_sprite.oy = @actor_sprite.bitmap.height / 4
  7917.     # set indices
  7918.     @aggressive, @offensive = 15 - @actor.aggressive, @actor.offensive - 1
  7919.     # not active
  7920.     self.active = false
  7921.     # refresh display
  7922.     refresh
  7923.     # update sprite position
  7924.     update_sprite
  7925.   end
  7926.   #----------------------------------------------------------------------------
  7927.   # override visible=
  7928.   #----------------------------------------------------------------------------
  7929.   alias visible_is_later= visible=
  7930.   def visible=(val)
  7931.     # process value to sprite
  7932.     @actor_sprite.visible = val
  7933.     # call original method
  7934.     visible_is_later=(val)
  7935.   end
  7936.   #----------------------------------------------------------------------------
  7937.   # override active=
  7938.   #----------------------------------------------------------------------------
  7939.   alias active_is_later= active=
  7940.   def active=(val)
  7941.     # if setting to active
  7942.     if val
  7943.       # restore settings
  7944.       @aggressive, @offensive = 15 - @actor.aggressive, @actor.offensive - 1
  7945.       # update sprite position
  7946.       update_sprite
  7947.       # start sprite blinking
  7948.       @actor_sprite.blink_on
  7949.     else
  7950.       # save settings
  7951.       @actor.aggressive, @actor.offensive = 15 - @aggressive, @offensive + 1
  7952.       # stop sprite blinking
  7953.       @actor_sprite.blink_off
  7954.     end
  7955.     # call original method
  7956.     active_is_later=(val)
  7957.   end
  7958.   #----------------------------------------------------------------------------
  7959.   # refresh
  7960.   #  Refreshes the display.
  7961.   #----------------------------------------------------------------------------
  7962.   def refresh
  7963.     # delete old display
  7964.     self.contents.clear
  7965.     # draw actor name
  7966.     self.contents.draw_text(4, 0, 160, 32, @actor.name)
  7967.     # get grid image
  7968.     bitmap = $BlizzABS.cache.image('grid')
  7969.     # put grid on background
  7970.     self.contents.blt(44, 44, bitmap, Rect.new(0, 0, 360, 360))
  7971.     # draw normal text indicators on grid
  7972.     self.contents.draw_text(0, 12, 448, 32, BlizzABS::Cache::WORDAggressive, 1)
  7973.     self.contents.draw_text(0, 404, 448, 32, BlizzABS::Cache::WORDPassive, 1)
  7974.     # create new bitmap
  7975.     b = Bitmap.new(128, 32)
  7976.     # set font name and size from window
  7977.     b.font.name = self.contents.font.name
  7978.     b.font.size = self.contents.font.size
  7979.     # draw text on bitmap
  7980.     b.draw_text(0, 0, 128, 32, BlizzABS::Cache::WORDOffensive, 1)
  7981.     # draw rotated text indicator on grid
  7982.     self.contents.blt(404, 160, $BlizzABS.util.rotate(b), Rect.new(0, 0, 32, 128))
  7983.     # clear bitmap
  7984.     b.clear
  7985.     # draw text on bitmap
  7986.     b.draw_text(0, 0, 128, 32, BlizzABS::Cache::WORDDefensive, 1)
  7987.     # draw rotated text indicator on grid
  7988.     self.contents.blt(12, 160, $BlizzABS.util.rotate(b), Rect.new(0, 0, 32, 128))
  7989.   end
  7990.   #----------------------------------------------------------------------------
  7991.   # update_sprite
  7992.   #  Sets the position of the sprite on the grid
  7993.   #----------------------------------------------------------------------------
  7994.   def update_sprite
  7995.     @actor_sprite.x = self.x + 72 + @offensive * 24
  7996.     @actor_sprite.y = self.y + 76 + @aggressive * 24
  7997.   end
  7998.   #----------------------------------------------------------------------------
  7999.   # update
  8000.   #  Updates the window's behavior
  8001.   #----------------------------------------------------------------------------
  8002.   def update
  8003.     # update the blinking animation
  8004.     @actor_sprite.update
  8005.     # if pressed cancel
  8006.     if Input.trigger?(Input::B)
  8007.       # reset settings
  8008.       @aggressive, @offensive = 15 - @actor.aggressive, @actor.offensive - 1
  8009.       # abort update
  8010.       return
  8011.     end
  8012.     # if pressed right
  8013.     if Input.repeat?(Input::RIGHT)
  8014.       # if actor forced offensive
  8015.       if @actor.force_offensive > 0
  8016.         # play buzzer sound
  8017.         $game_system.se_play($data_system.buzzer_se)
  8018.       else
  8019.         # play cursor sound
  8020.         $game_system.se_play($data_system.cursor_se)
  8021.         # change setting
  8022.         @offensive = (@offensive + 1) % 15
  8023.         # update sprite position
  8024.         update_sprite
  8025.       end
  8026.     # if pressed rleft
  8027.     elsif Input.repeat?(Input::LEFT)
  8028.       # if actor forced offensive
  8029.       if @actor.force_offensive > 0
  8030.         # play buzzer sound
  8031.         $game_system.se_play($data_system.buzzer_se)
  8032.       else
  8033.         # play cursor sound
  8034.         $game_system.se_play($data_system.cursor_se)
  8035.         # change setting
  8036.         @offensive = (@offensive + 14) % 15
  8037.         # update sprite position
  8038.         update_sprite
  8039.       end
  8040.     end
  8041.     # if pressed up
  8042.     if Input.repeat?(Input::UP)
  8043.       # if actor forced aggressive
  8044.       if @actor.force_aggressive > 0
  8045.         # play buzzer sound
  8046.         $game_system.se_play($data_system.buzzer_se)
  8047.       else
  8048.         # play cursor sound
  8049.         $game_system.se_play($data_system.cursor_se)
  8050.         # change setting
  8051.         @aggressive = (@aggressive + 14) % 15
  8052.         # update sprite position
  8053.         update_sprite
  8054.       end
  8055.     # if pressed down
  8056.     elsif Input.repeat?(Input::DOWN)
  8057.       # if actor forced aggressive
  8058.       if @actor.force_aggressive > 0
  8059.         # play buzzer sound
  8060.         $game_system.se_play($data_system.buzzer_se)
  8061.       else
  8062.         # play cursor sound
  8063.         $game_system.se_play($data_system.cursor_se)
  8064.         # change setting
  8065.         @aggressive = (@aggressive + 1) % 15
  8066.         # update sprite position
  8067.         update_sprite
  8068.       end
  8069.     end
  8070.   end
  8071.   #----------------------------------------------------------------------------
  8072.   # dispose
  8073.   #  Enhanced to remove the actor sprite as well.
  8074.   #----------------------------------------------------------------------------
  8075.   def dispose
  8076.     @actor_sprite.dispose if @actor_sprite != nil && !@actor_sprite.disposed?
  8077.     super
  8078.   end
  8079.  
  8080. end
  8081.  
  8082. #==============================================================================
  8083. # Window_EditTrigger
  8084. #------------------------------------------------------------------------------
  8085. #  This window displays a Trigger editing window.
  8086. #==============================================================================
  8087.  
  8088. class Window_EditTrigger < Window_Base
  8089.  
  8090.   # setting all accessible variables
  8091.   attr_reader :trigger
  8092.   #----------------------------------------------------------------------------
  8093.   # Initialization
  8094.   #  actor - the actor
  8095.   #----------------------------------------------------------------------------
  8096.   def initialize(trigger = BlizzABS::Trigger.new)
  8097.     # call superclass method
  8098.     super(0, 0, 480, 96)
  8099.     # create bitmap
  8100.     self.contents = Bitmap.new(width - 32, height - 32)
  8101.     # if using Dyna Edition scripts
  8102.     if $fontface != nil
  8103.       # set font name and size
  8104.       self.contents.font.name = $fontface
  8105.       self.contents.font.size = $fontsize
  8106.     # if using PK Edition 2
  8107.     elsif $defaultfonttype != nil
  8108.       # set font name and size
  8109.       self.contents.font.name = $defaultfonttype
  8110.       self.contents.font.size = $defaultfontsize
  8111.     end
  8112.     # set y-coordinate
  8113.     self.y = 240 - self.height / 2
  8114.     # change z coordinate
  8115.     self.z += 100
  8116.     # the trigger to edit
  8117.     @trigger = trigger
  8118.     # refresh display
  8119.     refresh
  8120.   end
  8121.   #----------------------------------------------------------------------------
  8122.   # refresh
  8123.   #  Refreshes the display.
  8124.   #----------------------------------------------------------------------------
  8125.   def refresh
  8126.     draw_trigger(@trigger)
  8127.   end
  8128.  
  8129. end
  8130.  
  8131. #==============================================================================
  8132. # Window_Triggers
  8133. #------------------------------------------------------------------------------
  8134. #  This window displays the Trigger AI setup.
  8135. #==============================================================================
  8136.  
  8137. class Window_Triggers < Window_Selectable
  8138.  
  8139.   #----------------------------------------------------------------------------
  8140.   # Initialization
  8141.   #  actor - the actor
  8142.   #----------------------------------------------------------------------------
  8143.   def initialize(actor)
  8144.     # call superclass method
  8145.     super(0, 0, 480, 480)
  8146.     # store variables
  8147.     @actor = actor
  8148.     # not active
  8149.     self.active = false
  8150.     # refresh display
  8151.     refresh
  8152.   end
  8153.   #----------------------------------------------------------------------------
  8154.   # refresh
  8155.   #  Refreshes the display.
  8156.   #----------------------------------------------------------------------------
  8157.   def refresh
  8158.     # delete old display
  8159.     if self.contents != nil
  8160.       self.contents.dispose
  8161.       self.contents = nil
  8162.     end
  8163.     # set max number of items
  8164.     @item_max = @actor.triggers.size
  8165.     # if any items exist
  8166.     if @item_max > 0
  8167.       # create bitmap
  8168.       self.contents = Bitmap.new(width - 32, row_max * 64)
  8169.       # if using Dyna Edition scripts
  8170.       if $fontface != nil
  8171.         # set font name and size
  8172.         self.contents.font.name = $fontface
  8173.         self.contents.font.size = $fontsize
  8174.       # if using PK Edition 2
  8175.       elsif $defaultfonttype != nil
  8176.         # set font name and size
  8177.         self.contents.font.name = $defaultfonttype
  8178.         self.contents.font.size = $defaultfontsize
  8179.       end
  8180.       # draw the items
  8181.       (0...@item_max).each {|i| draw_item(i)}
  8182.     end
  8183.   end
  8184.   #----------------------------------------------------------------------------
  8185.   # draw_item
  8186.   #  i - index
  8187.   #  Refreshes the display.
  8188.   #----------------------------------------------------------------------------
  8189.   def draw_item(i)
  8190.     draw_trigger(@actor.triggers[i], i)
  8191.   end
  8192.   #--------------------------------------------------------------------------
  8193.   # top_row
  8194.   #  Gets top row.
  8195.   #--------------------------------------------------------------------------
  8196.   def top_row
  8197.     return self.oy / 64
  8198.   end
  8199.   #--------------------------------------------------------------------------
  8200.   # top_row=
  8201.   #  row - the row
  8202.   #  Sets the row shown on top.
  8203.   #--------------------------------------------------------------------------
  8204.   def top_row=(row)
  8205.     # if row is less than 0
  8206.     if row < 0
  8207.       # change it to 0
  8208.       row = 0
  8209.     # if row exceeds row_max - 1
  8210.     elsif row > row_max - 1
  8211.       # change it to row_max - 1
  8212.       row = row_max - 1
  8213.     end
  8214.     # row height offset
  8215.     self.oy = row * 64
  8216.   end
  8217.   #--------------------------------------------------------------------------
  8218.   # page_row_max
  8219.   #  Gets number of rows displayable on one page.
  8220.   #--------------------------------------------------------------------------
  8221.   def page_row_max
  8222.     return (self.height - 32) / 64
  8223.   end
  8224.   #----------------------------------------------------------------------------
  8225.   # update_cursor_rect
  8226.   #  Updates the window's cursor.
  8227.   #----------------------------------------------------------------------------
  8228.   def update_cursor_rect
  8229.     # if cursor position is less than 0
  8230.     if @index < 0
  8231.       self.cursor_rect.empty
  8232.       return
  8233.     end
  8234.     # get current row
  8235.     row = @index / @column_max
  8236.     # scroll so current row becomes top row if current row is before top row
  8237.     self.top_row = row if row < self.top_row
  8238.     # if current row is more to back than back row
  8239.     if row > self.top_row + (self.page_row_max - 1)
  8240.       # scroll so that current row becomes back row
  8241.       self.top_row = row - (self.page_row_max - 1)
  8242.     end
  8243.     # calculate cursor width
  8244.     cursor_width = self.width / @column_max - 32
  8245.     # calculate cursor coordinates
  8246.     x = @index % @column_max * (cursor_width + 32)
  8247.     y = @index / @column_max * 64 - self.oy
  8248.     # update cursor rectangle
  8249.     self.cursor_rect.set(x, y, cursor_width, 64)
  8250.   end
  8251.  
  8252. end
  8253.  
  8254. #==============================================================================
  8255. # Window_TriggerValue
  8256. #------------------------------------------------------------------------------
  8257. #  This class serves for a number input for the trigger value.
  8258. #==============================================================================
  8259.  
  8260. class Window_TriggerValue < Window_Base
  8261.  
  8262.   # setting all accessible variables
  8263.   attr_reader :number
  8264.   #----------------------------------------------------------------------------
  8265.   # Initialization
  8266.   #  min_val - minimum value
  8267.   #  max_val - maximum value
  8268.   #  current - current value
  8269.   #----------------------------------------------------------------------------
  8270.   def initialize(min_val, max_val, current)
  8271.     # call superclass method
  8272.     super(0, 0, 108, 64)
  8273.     # set position
  8274.     self.x, self.y, self.z = 320 - self.width / 2, 240 - self.height / 2, 2000
  8275.     # create bitmap
  8276.     self.contents = Bitmap.new(width - 32, height - 32)
  8277.     # if using Dyna Edition scripts
  8278.     if $fontface != nil
  8279.       # set font name and size
  8280.       self.contents.font.name = $fontface
  8281.       self.contents.font.size = $fontsize
  8282.     # if using PK Edition 2
  8283.     elsif $defaultfonttype != nil
  8284.       # set font name and size
  8285.       self.contents.font.name = $defaultfonttype
  8286.       self.contents.font.size = $defaultfontsize
  8287.     end
  8288.     # store variables
  8289.     @number, @min_val, @max_val = current, min_val, max_val
  8290.     # display cursor
  8291.     self.cursor_rect.set(0, 0, 48, 32)
  8292.     # refresh display
  8293.     refresh
  8294.   end
  8295.   #----------------------------------------------------------------------------
  8296.   # Refresh
  8297.   #  Refreshes the display.
  8298.   #----------------------------------------------------------------------------
  8299.   def refresh
  8300.     # clear bitmap
  8301.     self.contents.clear
  8302.     # set to system color
  8303.     self.contents.font.color = system_color
  8304.     # draw "%"
  8305.     self.contents.draw_text(48, 0, 24, 32, '%')
  8306.     # draw the value
  8307.     draw_value
  8308.   end
  8309.   #----------------------------------------------------------------------------
  8310.   # draw_value
  8311.   #  Draws the current value.
  8312.   #----------------------------------------------------------------------------
  8313.   def draw_value
  8314.     # set to normal font color
  8315.     self.contents.font.color = normal_color
  8316.     # clear field
  8317.     self.contents.fill_rect(4, 0, 40, 32, Color.new(0, 0, 0, 0))
  8318.     # draw the number
  8319.     self.contents.draw_text(4, 0, 40, 32, @number.to_s, 2)
  8320.   end
  8321.   #----------------------------------------------------------------------------
  8322.   # Refresh
  8323.   #  Updates the input.
  8324.   #----------------------------------------------------------------------------
  8325.   def update
  8326.     # call superclass method
  8327.     super
  8328.     # stop if not active
  8329.     return unless self.active
  8330.     # if pressed right
  8331.     if Input.repeat?(Input::RIGHT)
  8332.       # if not maximum
  8333.       if @number < @max_val
  8334.         # play cursor sound
  8335.         $game_system.se_play($data_system.cursor_se)
  8336.         # increase value
  8337.         @number += 1
  8338.         # redraw value
  8339.         draw_value
  8340.       else
  8341.         # play buzzer sound
  8342.         $game_system.se_play($data_system.buzzer_se)
  8343.       end
  8344.     # if pressed left
  8345.     elsif Input.repeat?(Input::LEFT)
  8346.       # if not minimum
  8347.       if @number > @min_val
  8348.         # play cursor sound
  8349.         $game_system.se_play($data_system.cursor_se)
  8350.         # decrease value
  8351.         @number -= 1
  8352.         # redraw value
  8353.         draw_value
  8354.       else
  8355.         # play buzzer sound
  8356.         $game_system.se_play($data_system.buzzer_se)
  8357.       end
  8358.     # if pressed up
  8359.     elsif Input.repeat?(Input::UP)
  8360.       # if not maximum
  8361.       if @number < @max_val
  8362.         # play cursor sound
  8363.         $game_system.se_play($data_system.cursor_se)
  8364.         # increase value by 10
  8365.         @number += 10
  8366.         # limit to upper border
  8367.         @number = @max_val if @number > @max_val
  8368.         # redraw value
  8369.         draw_value
  8370.       else
  8371.         # play buzzer sound
  8372.         $game_system.se_play($data_system.buzzer_se)
  8373.       end
  8374.     # if pressed down
  8375.     elsif Input.repeat?(Input::DOWN)
  8376.       # if not minimum
  8377.       if @number > @min_val
  8378.         # play cursor sound
  8379.         $game_system.se_play($data_system.cursor_se)
  8380.         # decrease value by 10
  8381.         @number -= 10
  8382.         # limit to lower border
  8383.         @number = @min_val if @number < @min_val
  8384.         # redraw value
  8385.         draw_value
  8386.       else
  8387.         # play buzzer sound
  8388.         $game_system.se_play($data_system.buzzer_se)
  8389.       end
  8390.     end
  8391.   end
  8392.  
  8393. end
  8394.  
  8395. #==============================================================================
  8396. # Scene_Hotkeys
  8397. #------------------------------------------------------------------------------
  8398. #  This class handles the skill/item hotkey processing.
  8399. #==============================================================================
  8400.  
  8401. class Scene_Hotkeys
  8402.  
  8403.   #----------------------------------------------------------------------------
  8404.   # Initialization
  8405.   #  tone - screen background tone
  8406.   #----------------------------------------------------------------------------
  8407.   def initialize(tone = Tone.new(0, 0, 0, 0), index = 0)
  8408.     # store current screen tint
  8409.     @tone = tone
  8410.     # store current party leader
  8411.     @party_leader = $game_party.actors[index]
  8412.   end
  8413.   #----------------------------------------------------------------------------
  8414.   # main
  8415.   #  The main processing method.
  8416.   #----------------------------------------------------------------------------
  8417.   def main
  8418.     # create spriteset
  8419.     @spriteset = Spriteset_Map.new
  8420.     # create viewport
  8421.     @view = Viewport.new(0, 0, 640, 480)
  8422.     # set tone to current screen tone
  8423.     @view.tone = @tone.clone
  8424.     # create HUD if HUD is turned on and HUD active
  8425.     @hud = Hud.new if BlizzABS::Config::HUD_ENABLED && $game_system.hud
  8426.     # if ASSIGNMENT is turned
  8427.     if BlizzABS::Config::HOTKEYS
  8428.       # create assignment display
  8429.       @hotkeys = Hotkey_Assignment.new
  8430.       # set z position
  8431.       @hotkeys.z = 5000
  8432.     end
  8433.     # if MINIMAP is turned on and minimap active
  8434.     if BlizzABS::Config::MINIMAP && $game_system.minimap > 0
  8435.       # create minimap
  8436.       @minimap = Minimap.new
  8437.     end
  8438.     # create sprite
  8439.     @choice = Sprite.new
  8440.     # create bitmap
  8441.     @choice.bitmap = $BlizzABS.cache.image('menu_arrow')
  8442.     # set x, y and z positions
  8443.     @choice.x, @choice.y, @choice.z, @choice.opacity = 160, 40, 500, 128
  8444.     # set x position offset
  8445.     @choice.ox = -8
  8446.     # set active flag
  8447.     @active = true
  8448.     # set index
  8449.     @index = 0
  8450.     # set up mode flag
  8451.     @up_mode = true
  8452.     # create modified skill window
  8453.     @skill_window = Window_Skill_Hotkey.new($game_player.battler)
  8454.     # create modified item window
  8455.     @item_window = Window_Item_Hotkey.new
  8456.     # set last active
  8457.     @last_active = true
  8458.     # transtition
  8459.     Graphics.transition
  8460.     # loop
  8461.     loop do
  8462.       # update game screen
  8463.       Graphics.update
  8464.       # update input
  8465.       Input.update
  8466.       # frame update
  8467.       update
  8468.       # stop if chosen an option
  8469.       break if $scene != self
  8470.     end
  8471.     # freeze screen
  8472.     Graphics.freeze
  8473.     # delete spriteset
  8474.     @spriteset.dispose
  8475.     # delete HUD elements that exist
  8476.     [@hud, @hotkeys, @minimap].each {|s| s.dispose if s != nil}
  8477.     # delete choice sprite
  8478.     @choice.dispose
  8479.     # delete skill window
  8480.     @skill_window.dispose
  8481.     # delete item window
  8482.     @item_window.dispose
  8483.     # delete viewport
  8484.     @view.dispose
  8485.     # while real leader is not first actor in party
  8486.     while @party_leader != $game_party.actors[0]
  8487.       # switch to next actor
  8488.       $BlizzABS.player.switch_leader
  8489.     end
  8490.   end
  8491.   #----------------------------------------------------------------------------
  8492.   # update
  8493.   #  The update processing method.
  8494.   #----------------------------------------------------------------------------
  8495.   def update
  8496.     # update choice sprite
  8497.     @choice.update
  8498.     # update skill window
  8499.     @skill_window.update
  8500.     # update item window
  8501.     @item_window.update
  8502.     # update hotkey assignment display if existing
  8503.     @hotkeys.update if @hotkeys != nil
  8504.     # move by 2 or 1 whether active in direction depending on @up_mode
  8505.     @choice.oy += (@up_mode ? (@active ? 2 : 1) : (@active ? -2 : -1))
  8506.     # set new @up_mode if necesseray depending on @up_mode
  8507.     @up_mode = (@up_mode ? (@choice.oy < 8) : (@choice.oy <= -8))
  8508.     # if select button pressed
  8509.     if $game_system.select_button && Input.trigger?(Input::Select)
  8510.       # play sound
  8511.       $game_system.se_play($data_system.cursor_se)
  8512.       # switch to next actor
  8513.       $BlizzABS.player.switch_leader
  8514.       # switch to next actor
  8515.       @skill_window.switch_actor
  8516.       # update HUD if existing
  8517.       @hud.update if @hud != nil
  8518.       # update hotkey assignment display if existing
  8519.       @hotkeys.update if @hotkeys != nil
  8520.     # if active
  8521.     elsif @active
  8522.       # set choice offset always to a number divisable with 2
  8523.       @choice.oy = @choice.oy / 2 * 2
  8524.       # update hotkey selection
  8525.       update_choice
  8526.     # if skill window is active
  8527.     elsif @skill_window.active
  8528.       # update skill selection
  8529.       update_skill
  8530.     # if item window is active
  8531.     elsif @item_window.active
  8532.       # update item selection
  8533.       update_item
  8534.     end
  8535.   end
  8536.   #----------------------------------------------------------------------------
  8537.   # update_choice
  8538.   #  Updates input during the hotkey selection.
  8539.   #----------------------------------------------------------------------------
  8540.   def update_choice
  8541.     # set x position
  8542.     @choice.x = 160 + @index * 32
  8543.     # if pressed B
  8544.     if Input.trigger?(Input::B)
  8545.       # play cancel sound
  8546.       $game_system.se_play($data_system.cancel_se)
  8547.       # create map scene
  8548.       $scene = Scene_Map.new
  8549.     # if C is pressed
  8550.     elsif Input.trigger?(Input::C)
  8551.       # play sound
  8552.       $game_system.se_play($data_system.decision_se)
  8553.       # not active
  8554.       @active = false
  8555.       # the one that was active the last time is now active
  8556.       @skill_window.active = @last_active
  8557.       @item_window.active = (!@last_active)
  8558.     # if RIGHT is being pressed
  8559.     elsif Input.repeat?(Input::RIGHT)
  8560.       # if RIGHT is pressed or index is less than 9
  8561.       if Input.trigger?(Input::RIGHT) || @index < 9
  8562.         # play sound
  8563.         $game_system.se_play($data_system.cursor_se)
  8564.         # set new index
  8565.         @index = (@index + 1) % 10
  8566.       end
  8567.     # if LEFT is being pressed
  8568.     elsif Input.repeat?(Input::LEFT)
  8569.       # if LEFT is pressed or index is equal or greater than 1
  8570.       if Input.trigger?(Input::LEFT) || @index >= 1
  8571.         # play sound
  8572.         $game_system.se_play($data_system.cursor_se)
  8573.         # set new index
  8574.         @index = (@index + 9) % 10
  8575.       end
  8576.     end
  8577.   end
  8578.   #----------------------------------------------------------------------------
  8579.   # update_skill
  8580.   #  Updates input during the skill selection.
  8581.   #----------------------------------------------------------------------------
  8582.   def update_skill
  8583.     # set last active
  8584.     @last_active = true
  8585.     # if B is pressed
  8586.     if Input.trigger?(Input::B)
  8587.       # play cancel sound
  8588.       $game_system.se_play($data_system.cancel_se)
  8589.       # set active
  8590.       @active = true
  8591.       # skill window is not active
  8592.       @skill_window.active = false
  8593.       # delete cursor
  8594.       @skill_window.cursor_rect.empty
  8595.     # if C is pressd
  8596.     elsif Input.trigger?(Input::C)
  8597.       # play sound
  8598.       $game_system.se_play($data_system.decision_se)
  8599.       # if last position
  8600.       if @skill_window.index == @skill_window.item_max - 1
  8601.         # remove hotkey assigmnent from skill
  8602.         $game_player.skill_hotkeys[(@index+1)%10] = 0
  8603.       else
  8604.         # set skill to hotkey
  8605.         $game_player.skill_hotkeys[(@index+1)%10] = @skill_window.skill.id
  8606.       end
  8607.       # remove hotkey assigmnent from item
  8608.       $game_player.item_hotkeys[(@index+1)%10] = 0
  8609.       # draw hotkey display if hotkey display exists
  8610.       @hotkeys.draw(@index+1) if @hotkeys != nil
  8611.       # set active
  8612.       @active = true
  8613.       # skill window is not active
  8614.       @skill_window.active = false
  8615.       # delete cursor
  8616.       @skill_window.cursor_rect.empty
  8617.     # if RIGHT or LEFT is pressed
  8618.     elsif Input.trigger?(Input::RIGHT) || Input.trigger?(Input::LEFT)
  8619.       # play sound
  8620.       $game_system.se_play($data_system.cursor_se)
  8621.       # item window is active
  8622.       @item_window.active = true
  8623.       # skill window is not active
  8624.       @skill_window.active = false
  8625.       # delete cursor
  8626.       @skill_window.cursor_rect.empty
  8627.     end
  8628.   end
  8629.   #----------------------------------------------------------------------------
  8630.   # update_item
  8631.   #  Updates input during the item selection.
  8632.   #----------------------------------------------------------------------------
  8633.   def update_item
  8634.     # set last active
  8635.     @last_active = false
  8636.     # if B is pressed
  8637.     if Input.trigger?(Input::B)
  8638.       # play cancel sound
  8639.       $game_system.se_play($data_system.cancel_se)
  8640.       # set active
  8641.       @active = true
  8642.       # item window is not active
  8643.       @item_window.active = false
  8644.       # delete cursor
  8645.       @item_window.cursor_rect.empty
  8646.     # if C is pressed
  8647.     elsif Input.trigger?(Input::C)
  8648.       # play sound
  8649.       $game_system.se_play($data_system.decision_se)
  8650.       # if last position
  8651.       if @item_window.index == @item_window.item_max - 1
  8652.         # remove hotkey assigmnent from item
  8653.         $game_player.item_hotkeys[(@index+1)%10] = 0
  8654.       else
  8655.         # set item to hotkey
  8656.         $game_player.item_hotkeys[(@index+1)%10] = @item_window.item.id
  8657.       end
  8658.       # remove hotkey assigmnent from skill
  8659.       $game_player.skill_hotkeys[(@index+1)%10] = 0
  8660.       # draw hotkey display if hotkey display exists
  8661.       @hotkeys.draw(@index+1) if @hotkeys != nil
  8662.       # set active
  8663.       @active = true
  8664.       # item window is not active
  8665.       @item_window.active = false
  8666.       # delete cursor
  8667.       @item_window.cursor_rect.empty
  8668.     # if RIGHT or LEFT is pressed
  8669.     elsif Input.trigger?(Input::RIGHT) || Input.trigger?(Input::LEFT)
  8670.       # play sound
  8671.       $game_system.se_play($data_system.cursor_se)
  8672.       # skill window is active
  8673.       @skill_window.active = true
  8674.       # item window is not active
  8675.       @item_window.active = false
  8676.       # delete cursor
  8677.       @item_window.cursor_rect.empty
  8678.     end
  8679.   end
  8680.  
  8681. end
  8682.  
  8683. #==============================================================================
  8684. # Scene_AI_Behavior
  8685. #------------------------------------------------------------------------------
  8686. #  This class processes handling of the scene where ally behavior can be set
  8687. #  up which is used by the Ally Combat AI.
  8688. #==============================================================================
  8689.  
  8690. class Scene_AI_Behavior
  8691.  
  8692.   #----------------------------------------------------------------------------
  8693.   # Initialization
  8694.   #  tone  - screen background tone
  8695.   #  index - actor party index
  8696.   #----------------------------------------------------------------------------
  8697.   def initialize(tone = Tone.new(0, 0, 0, 0), index = 0, command_index = 0)
  8698.     # base data
  8699.     @tone, @index = tone, index
  8700.     # get battler
  8701.     @actor = $BlizzABS.battlers[index].battler
  8702.     # command window index
  8703.     @command_index = command_index
  8704.   end
  8705.   #----------------------------------------------------------------------------
  8706.   # main
  8707.   #  The main processing method.
  8708.   #----------------------------------------------------------------------------
  8709.   def main
  8710.     # create spriteset
  8711.     @spriteset = Spriteset_Map.new
  8712.     # create viewport
  8713.     @view = Viewport.new(0, 0, 640, 480)
  8714.     # set screen tint
  8715.     @view.tone = @tone
  8716.     # create command window
  8717.     @command_window = Window_Command.new(160, BlizzABS::Cache::CommandsAIBehavior)
  8718.     # command window coordinates
  8719.     @command_window.x = 480
  8720.     # command window initial index
  8721.     @command_window.index = @command_index
  8722.     # get map actor
  8723.     map_actor = $BlizzABS.battlers[@index]
  8724.     # create behavior window
  8725.     @behavior_window = Window_Behavior.new(@actor, map_actor)
  8726.     # transition
  8727.     Graphics.transition
  8728.     # loop
  8729.     loop do
  8730.       # update game screen
  8731.       Graphics.update
  8732.       # update input
  8733.       Input.update
  8734.       # update the scene
  8735.       update
  8736.       # stop if frame update
  8737.       break if $scene != self
  8738.     end
  8739.     # freeze screen
  8740.     Graphics.freeze
  8741.     # delete command window
  8742.     @command_window.dispose
  8743.     # delete behavior window
  8744.     @behavior_window.dispose
  8745.     # delete spriteset
  8746.     @spriteset.dispose
  8747.     # delete viewport
  8748.     @view.dispose
  8749.   end
  8750.   #----------------------------------------------------------------------------
  8751.   # update
  8752.   #  The update processing method.
  8753.   #----------------------------------------------------------------------------
  8754.   def update
  8755.     # updates path finder
  8756.     $BlizzABS.AI.update
  8757.     # if command window is active
  8758.     if @command_window.active
  8759.       # update command
  8760.       update_command
  8761.     # if behavior window is active
  8762.     elsif @behavior_window.active
  8763.       # update behavior
  8764.       update_behavior
  8765.     end
  8766.   end
  8767.   #----------------------------------------------------------------------------
  8768.   # update_command
  8769.   #  The command window update processing method.
  8770.   #----------------------------------------------------------------------------
  8771.   def update_command
  8772.     # update command window
  8773.     @command_window.update
  8774.     # if B is pressed
  8775.     if Input.trigger?(Input::B)
  8776.       # play cancel sound
  8777.       $game_system.se_play($data_system.cancel_se)
  8778.       # create map scene
  8779.       $scene = Scene_Map.new
  8780.     # if C is pressed
  8781.     elsif Input.trigger?(Input::C)
  8782.       # which option
  8783.       case @command_window.index
  8784.       when 0
  8785.         # play sound
  8786.         $game_system.se_play($data_system.decision_se)
  8787.         # deactivate command window
  8788.         @command_window.active = false
  8789.         # activate behavior window
  8790.         @behavior_window.active = true
  8791.       when 1
  8792.         # play sound
  8793.         $game_system.se_play($data_system.decision_se)
  8794.         # get all AI actors
  8795.         battlers = $BlizzABS.battlers
  8796.         # set next index
  8797.         @index = (@index + 1) % battlers.size
  8798.         # if battler not valid
  8799.         while battlers[@index].battler == nil
  8800.           # try to find one that is
  8801.           @index = (@index + 1) % battlers.size
  8802.         end
  8803.         # create hotkey assignment scene with the current screen tint
  8804.         $scene = Scene_AI_Behavior.new(@view.tone, @index, @command_window.index)
  8805.       when 2
  8806.         # play sound
  8807.         $game_system.se_play($data_system.decision_se)
  8808.         # get all AI actors
  8809.         battlers = $BlizzABS.battlers
  8810.         # set previous index
  8811.         @index = (@index + battlers.size - 1) % battlers.size
  8812.         # if battler not valid
  8813.         while battlers[@index].battler == nil
  8814.           # try to find one that is
  8815.           @index = (@index + battlers.size - 1) % battlers.size
  8816.         end
  8817.         # create hotkey assignment scene with the current screen tint
  8818.         $scene = Scene_AI_Behavior.new(@view.tone, @index, @command_window.index)
  8819.       when 3
  8820.         # play sound
  8821.         $game_system.se_play($data_system.decision_se)
  8822.         # create map scene
  8823.         $scene = Scene_Map.new
  8824.       end
  8825.     # if R is pressed
  8826.     elsif Input.trigger?(Input::R)
  8827.       # play sound
  8828.       $game_system.se_play($data_system.decision_se)
  8829.       # get all AI actors
  8830.       battlers = $BlizzABS.battlers
  8831.       # set next index
  8832.       @index = (@index + 1) % battlers.size
  8833.       # if battler not valid
  8834.       while battlers[@index].battler == nil
  8835.         # try to find one that is
  8836.         @index = (@index + 1) % battlers.size
  8837.       end
  8838.       # create hotkey assignment scene with the current screen tint
  8839.       $scene = Scene_AI_Behavior.new(@view.tone, @index, @command_window.index)
  8840.     # if L is pressed
  8841.     elsif Input.trigger?(Input::L)
  8842.       # play sound
  8843.       $game_system.se_play($data_system.decision_se)
  8844.       # get all AI actors
  8845.       battlers = $BlizzABS.battlers
  8846.       # set previous index
  8847.       @index = (@index + battlers.size - 1) % battlers.size
  8848.       # if battler not valid
  8849.       while battlers[@index].battler == nil
  8850.         # try to find one that is
  8851.         @index = (@index + battlers.size - 1) % battlers.size
  8852.       end
  8853.       # create hotkey assignment scene with the current screen tint
  8854.       $scene = Scene_AI_Behavior.new(@view.tone, @index, @command_window.index)
  8855.     end
  8856.   end
  8857.   #----------------------------------------------------------------------------
  8858.   # update_behavior
  8859.   #  The bahavior window update processing method.
  8860.   #----------------------------------------------------------------------------
  8861.   def update_behavior
  8862.     # update behavior window
  8863.     @behavior_window.update
  8864.     # if B is pressed
  8865.     if Input.trigger?(Input::B)
  8866.       # play cancel sound
  8867.       $game_system.se_play($data_system.cancel_se)
  8868.       # deactivate behavior window
  8869.       @behavior_window.active = false
  8870.       # activate command window
  8871.       @command_window.active = true
  8872.     # if C is pressed
  8873.     elsif Input.trigger?(Input::C)
  8874.       # play sound
  8875.       $game_system.se_play($data_system.decision_se)
  8876.       # deactivate behavior window
  8877.       @behavior_window.active = false
  8878.       # activate command window
  8879.       @command_window.active = true
  8880.     end
  8881.   end
  8882.  
  8883. end
  8884.  
  8885. #==============================================================================
  8886. # Scene_AI_Triggers
  8887. #------------------------------------------------------------------------------
  8888. #  This class processes handling of the scene where ally action triggers can be
  8889. #  set up which is used by the Ally Trigger AI.
  8890. #==============================================================================
  8891.  
  8892. class Scene_AI_Triggers
  8893.  
  8894.   #----------------------------------------------------------------------------
  8895.   # Initialization
  8896.   #  tone  - screen background tone
  8897.   #  index - actor party index
  8898.   #----------------------------------------------------------------------------
  8899.   def initialize(tone = Tone.new(0, 0, 0, 0), index = 0, command_index = 0)
  8900.     # data
  8901.     @tone, @index, @actor = tone, index, $BlizzABS.battlers[index].battler
  8902.     # command window index
  8903.     @command_index = command_index
  8904.     # status effect names
  8905.     @states = [BlizzABS::Cache::WORDNormalState]
  8906.     (1...$data_states.size).each {|id| @states.push($data_states[id].name)}
  8907.   end
  8908.   #----------------------------------------------------------------------------
  8909.   # main
  8910.   #  The main processing method.
  8911.   #----------------------------------------------------------------------------
  8912.   def main
  8913.     # create spriteset
  8914.     @spriteset = Spriteset_Map.new
  8915.     # create viewport
  8916.     @view = Viewport.new(0, 0, 640, 480)
  8917.     # set screen tint
  8918.     @view.tone = @tone
  8919.     # create command window
  8920.     @command_window = Window_Command.new(160, BlizzABS::Cache::CommandsAITrigger)
  8921.     # command window coordinates
  8922.     @command_window.x = 480
  8923.     # command window initial index
  8924.     @command_window.index = @command_index
  8925.     # create trigger command window
  8926.     @tcommand_window = Window_Command.new(160, BlizzABS::Cache::CommandsTrigger)
  8927.     # trigger command window coordinates
  8928.     @tcommand_window.x = 480
  8929.     @tcommand_window.y = @command_window.height
  8930.     # trigger command window no cursor
  8931.     @tcommand_window.index = -1
  8932.     # trigger command window not active
  8933.     @tcommand_window.active = false
  8934.     # create name window
  8935.     @name_window = Window_Base.new(480, 416, 160, 64)
  8936.     # create bitmap
  8937.     @name_window.contents = Bitmap.new(@name_window.width - 32,
  8938.         @name_window.height - 32)
  8939.     # if using Dyna Edition scripts
  8940.     if $fontface != nil
  8941.       # set font name and size
  8942.       @name_window.contents.font.name = $fontface
  8943.       @name_window.contents.font.size = $fontsize
  8944.     # if using PK Edition 2
  8945.     elsif $defaultfonttype != nil
  8946.       # set font name and size
  8947.       @name_window.contents.font.name = $defaultfonttype
  8948.       @name_window.contents.font.size = $defaultfontsize
  8949.     end
  8950.     # draw actor name
  8951.     @name_window.draw_actor_name(@actor, 4, 0)
  8952.     # update trigger command display
  8953.     check_triggers
  8954.     # creat triggers window
  8955.     @triggers_window = Window_Triggers.new(@actor)
  8956.     # transition
  8957.     Graphics.transition
  8958.     # loop
  8959.     loop do
  8960.       # update game screen
  8961.       Graphics.update
  8962.       # update input
  8963.       Input.update
  8964.       # update the scene
  8965.       update
  8966.       # stop if frame update
  8967.       break if $scene != self
  8968.     end
  8969.     # freeze screen
  8970.     Graphics.freeze
  8971.     # delete command window
  8972.     @command_window.dispose
  8973.     # delete trigger command window
  8974.     @tcommand_window.dispose
  8975.     # delete triggers window
  8976.     @triggers_window.dispose
  8977.     # delete name window
  8978.     @name_window.dispose
  8979.     # delete spriteset
  8980.     @spriteset.dispose
  8981.     # delete viewport
  8982.     @view.dispose
  8983.   end
  8984.   #----------------------------------------------------------------------------
  8985.   # check_triggers
  8986.   #  Checks unusable commands in the trigger command window.
  8987.   #----------------------------------------------------------------------------
  8988.   def check_triggers
  8989.     # refresh commands
  8990.     @tcommand_window.refresh
  8991.     # if ordering cannot be done
  8992.     if @actor.triggers.size < 2
  8993.       # disable ordering commands
  8994.       @tcommand_window.disable_item(4)
  8995.       @tcommand_window.disable_item(5)
  8996.       # if no triggers
  8997.       if @actor.triggers.size == 0
  8998.         # disable edit and delete
  8999.         @tcommand_window.disable_item(0)
  9000.         @tcommand_window.disable_item(2)
  9001.         @tcommand_window.disable_item(3)
  9002.       end
  9003.     end
  9004.   end
  9005.   #----------------------------------------------------------------------------
  9006.   # check_edits
  9007.   #  Checks unusable commands in the edit trigger command window.
  9008.   #----------------------------------------------------------------------------
  9009.   def check_edits
  9010.     # refresh commands
  9011.     @ecommand_window.refresh
  9012.     # if ordering cannot be done
  9013.     if @edit_window.trigger.action_type != BlizzABS::TRGSkill &&
  9014.         @edit_window.trigger.action_type != BlizzABS::TRGItem
  9015.       # disable skill/item selection command
  9016.       @ecommand_window.disable_item(5)
  9017.     end
  9018.     # if probability activator
  9019.     if @edit_window.trigger.activator == BlizzABS::TRGProbability
  9020.       # disable condition selection command
  9021.       @ecommand_window.disable_item(1)
  9022.       # disable comparison operator selection command
  9023.       @ecommand_window.disable_item(2)
  9024.       # disable target selection command
  9025.       @ecommand_window.disable_item(6)
  9026.     end
  9027.     # if state condition or location condition
  9028.     if @edit_window.trigger.condition == BlizzABS::TRGState ||
  9029.         @edit_window.trigger.condition == BlizzABS::TRGLocation
  9030.       # disable comparison operator selection command
  9031.       @ecommand_window.disable_item(2)
  9032.     end
  9033.   end
  9034.   #----------------------------------------------------------------------------
  9035.   # update
  9036.   #  The update processing method.
  9037.   #----------------------------------------------------------------------------
  9038.   def update
  9039.     # updates path finder
  9040.     $BlizzABS.AI.update
  9041.     # if command window is active
  9042.     if @command_window.active
  9043.       # update command
  9044.       update_command
  9045.     # if trigger command window is active
  9046.     elsif @tcommand_window.active
  9047.       # update trigger command
  9048.       update_trigger_command
  9049.     # if triggers window is active
  9050.     elsif @triggers_window.active
  9051.       # update triggers
  9052.       update_triggers
  9053.     # if edit command window exists
  9054.     elsif @edit_trigger_window != nil
  9055.       # update edit trigger
  9056.       update_edit_trigger
  9057.     # if edit command window exists
  9058.     elsif @ecommand_window != nil
  9059.       # update edit command
  9060.       update_edit_command
  9061.     end
  9062.   end
  9063.   #----------------------------------------------------------------------------
  9064.   # update_command
  9065.   #  The command window update processing method.
  9066.   #----------------------------------------------------------------------------
  9067.   def update_command
  9068.     # update command window
  9069.     @command_window.update
  9070.     # if B is pressed
  9071.     if Input.trigger?(Input::B)
  9072.       # play cancel sound
  9073.       $game_system.se_play($data_system.cancel_se)
  9074.       # create map scene
  9075.       $scene = Scene_Map.new
  9076.     # if C is pressed
  9077.     elsif Input.trigger?(Input::C)
  9078.       # which option
  9079.       case @command_window.index
  9080.       when 0
  9081.         # play sound
  9082.         $game_system.se_play($data_system.decision_se)
  9083.         # deactivate command window
  9084.         @command_window.active = false
  9085.         # activate trigger command window
  9086.         @tcommand_window.active = true
  9087.         # set cursor
  9088.         @tcommand_window.index = 0
  9089.       when 1
  9090.         # play sound
  9091.         $game_system.se_play($data_system.decision_se)
  9092.         # get all AI actors
  9093.         battlers = $BlizzABS.battlers
  9094.         # set next index
  9095.         @index = (@index + 1) % battlers.size
  9096.         # if battler not valid
  9097.         while battlers[@index].battler == nil
  9098.           # try to find one that is
  9099.           @index = (@index + 1) % battlers.size
  9100.         end
  9101.         # create hotkey assignment scene with the current screen tint
  9102.         $scene = Scene_AI_Triggers.new(@view.tone, @index, @command_window.index)
  9103.       when 2
  9104.         # play sound
  9105.         $game_system.se_play($data_system.decision_se)
  9106.         # get all AI actors
  9107.         battlers = $BlizzABS.battlers
  9108.         # set next index
  9109.         @index = (@index + battlers.size - 1) % battlers.size
  9110.         # if battler not valid
  9111.         while battlers[@index].battler == nil
  9112.           # try to find one that is
  9113.           @index = (@index + battlers.size - 1) % battlers.size
  9114.         end
  9115.         # create hotkey assignment scene with the current screen tint
  9116.         $scene = Scene_AI_Triggers.new(@view.tone, @index, @command_window.index)
  9117.       when 3
  9118.         # play sound
  9119.         $game_system.se_play($data_system.decision_se)
  9120.         # create map scene
  9121.         $scene = Scene_Map.new
  9122.       end
  9123.     # if R is pressed
  9124.     elsif Input.trigger?(Input::R)
  9125.       # play sound
  9126.       $game_system.se_play($data_system.decision_se)
  9127.       # get all AI actors
  9128.       battlers = $BlizzABS.battlers
  9129.       # set next index
  9130.       @index = (@index + 1) % battlers.size
  9131.       # if battler not valid
  9132.       while battlers[@index].battler == nil
  9133.         # try to find one that is
  9134.         @index = (@index + 1) % battlers.size
  9135.       end
  9136.       # create hotkey assignment scene with the current screen tint
  9137.       $scene = Scene_AI_Triggers.new(@view.tone, @index, @command_window.index)
  9138.     # if L is pressed
  9139.     elsif Input.trigger?(Input::L)
  9140.       # play sound
  9141.       $game_system.se_play($data_system.decision_se)
  9142.       # get all AI actors
  9143.       battlers = $BlizzABS.battlers
  9144.       # set next index
  9145.       @index = (@index + battlers.size - 1) % battlers.size
  9146.       # if battler not valid
  9147.       while battlers[@index].battler == nil
  9148.         # try to find one that is
  9149.         @index = (@index + battlers.size - 1) % battlers.size
  9150.       end
  9151.       # create hotkey assignment scene with the current screen tint
  9152.       $scene = Scene_AI_Triggers.new(@view.tone, @index, @command_window.index)
  9153.     end
  9154.   end
  9155.   #----------------------------------------------------------------------------
  9156.   # update_trigger_command
  9157.   #  The trigger command window update processing method.
  9158.   #----------------------------------------------------------------------------
  9159.   def update_trigger_command
  9160.     # update command window
  9161.     @tcommand_window.update
  9162.     # if B is pressed
  9163.     if Input.trigger?(Input::B)
  9164.       # play cancel sound
  9165.       $game_system.se_play($data_system.cancel_se)
  9166.       # deactivate command window
  9167.       @command_window.active = true
  9168.       # activate behavior window
  9169.       @tcommand_window.active = false
  9170.       # set triggers index
  9171.       @tcommand_window.index = -1
  9172.     # if C is pressed
  9173.     elsif Input.trigger?(Input::C)
  9174.       # which option
  9175.       case @tcommand_window.index
  9176.       when 0, 2, 3
  9177.         # if no triggers
  9178.         if @actor.triggers.size == 0
  9179.           # play buzzer sound
  9180.           $game_system.se_play($data_system.buzzer_se)
  9181.           # exit method
  9182.           return
  9183.         end
  9184.         # play sound
  9185.         $game_system.se_play($data_system.decision_se)
  9186.         # deactivate trigger command window
  9187.         @tcommand_window.active = false
  9188.         # activate triggers window
  9189.         @triggers_window.active = true
  9190.         # set cursor
  9191.         @triggers_window.index = 0
  9192.       when 1
  9193.         # play sound
  9194.         $game_system.se_play($data_system.decision_se)
  9195.         # deactivate trigger command window
  9196.         @tcommand_window.active = false
  9197.         # create edit command window
  9198.         @ecommand_window = Window_Command.new(160, BlizzABS::Cache::CommandsEdit)
  9199.         # set coordinates
  9200.         @ecommand_window.x = @tcommand_window.x
  9201.         @ecommand_window.y = @tcommand_window.y
  9202.         @ecommand_window.z += 100
  9203.         # set cursor
  9204.         @ecommand_window.index = 0
  9205.         # set active
  9206.         @ecommand_window.active = true
  9207.         # create editing window
  9208.         @edit_window = Window_EditTrigger.new
  9209.         # check edit window display
  9210.         check_edits
  9211.       when 4, 5
  9212.         # if not enough triggers for ordering
  9213.         if @actor.triggers.size < 2
  9214.           # play buzzer sound
  9215.           $game_system.se_play($data_system.buzzer_se)
  9216.           # exit method
  9217.           return
  9218.         end
  9219.         # play sound
  9220.         $game_system.se_play($data_system.decision_se)
  9221.         # deactivate trigger command window
  9222.         @tcommand_window.active = false
  9223.         # activate triggers window
  9224.         @triggers_window.active = true
  9225.         # set cursor
  9226.         @triggers_window.index = 0
  9227.       when 6
  9228.         # play sound
  9229.         $game_system.se_play($data_system.decision_se)
  9230.         # deactivate trigger command window
  9231.         @tcommand_window.active = false
  9232.         # activate command window
  9233.         @command_window.active = true
  9234.         # set triggers index
  9235.         @tcommand_window.index = -1
  9236.       end
  9237.     end
  9238.   end
  9239.   #----------------------------------------------------------------------------
  9240.   # update_triggers
  9241.   #  The triggers window update processing method.
  9242.   #----------------------------------------------------------------------------
  9243.   def update_triggers
  9244.     # update triggers window
  9245.     @triggers_window.update
  9246.     # if B is pressed
  9247.     if Input.trigger?(Input::B)
  9248.       # play cancel sound
  9249.       $game_system.se_play($data_system.cancel_se)
  9250.       # activate trigger command window
  9251.       @tcommand_window.active = true
  9252.       # deactivate triggers window
  9253.       @triggers_window.active = false
  9254.       # remove cursor
  9255.       @triggers_window.index = -1
  9256.     # if C is pressed
  9257.     elsif Input.trigger?(Input::C)
  9258.       # update specific action
  9259.       case @tcommand_window.index
  9260.       when 0
  9261.         # play sound
  9262.         $game_system.se_play($data_system.decision_se)
  9263.         # deactivate trigger command window
  9264.         @triggers_window.active = false
  9265.         # create edit command window
  9266.         @ecommand_window = Window_Command.new(160, BlizzABS::Cache::CommandsEdit)
  9267.         # set coordinates
  9268.         @ecommand_window.x = @tcommand_window.x
  9269.         @ecommand_window.y = @tcommand_window.y
  9270.         @ecommand_window.z = @tcommand_window.z + 100
  9271.         # set cursor
  9272.         @ecommand_window.index = 0
  9273.         # set active
  9274.         @ecommand_window.active = true
  9275.         # create editing window
  9276.         @edit_window = Window_EditTrigger.new(
  9277.             @actor.triggers[@triggers_window.index].clone)
  9278.         # check edit window display
  9279.         check_edits
  9280.       when 2
  9281.         # play sound
  9282.         $game_system.se_play($data_system.decision_se)
  9283.         # delete that trigger
  9284.         @actor.triggers.delete_at(@triggers_window.index)
  9285.         # refresh the display
  9286.         @triggers_window.refresh
  9287.         # refresh trigger command window display
  9288.         check_triggers
  9289.         # if no more triggers
  9290.         if @actor.triggers.size == 0
  9291.           # activate trigger command window
  9292.           @tcommand_window.active = true
  9293.           # deactivate triggers window
  9294.           @triggers_window.active = false
  9295.           # set cursor
  9296.           @triggers_window.index = -1
  9297.         # if last item in the list was deleted
  9298.         elsif @triggers_window.index == @actor.triggers.size
  9299.           # set to new last item
  9300.           @triggers_window.index -= 1
  9301.         end
  9302.       when 3
  9303.         # play sound
  9304.         $game_system.se_play($data_system.decision_se)
  9305.         # copy that trigger
  9306.         @actor.triggers.insert(@triggers_window.index,
  9307.             @actor.triggers[@triggers_window.index])
  9308.         # refresh the display
  9309.         @triggers_window.refresh
  9310.         # refresh trigger command window display
  9311.         check_triggers
  9312.       when 4
  9313.         # if first item selected
  9314.         if @triggers_window.index == 0
  9315.           # play buzzer sound
  9316.           $game_system.se_play($data_system.buzzer_se)
  9317.         else
  9318.           # play sound
  9319.           $game_system.se_play($data_system.decision_se)
  9320.           # swap those triggers
  9321.           @actor.triggers[@triggers_window.index],
  9322.               @actor.triggers[@triggers_window.index - 1] =
  9323.               @actor.triggers[@triggers_window.index - 1],
  9324.               @actor.triggers[@triggers_window.index]
  9325.           # refresh display
  9326.           @triggers_window.draw_item(@triggers_window.index)
  9327.           @triggers_window.index -= 1
  9328.           @triggers_window.draw_item(@triggers_window.index)
  9329.         end
  9330.       when 5
  9331.         # if last item selected
  9332.         if @triggers_window.index == @actor.triggers.size - 1
  9333.           # play buzzer sound
  9334.           $game_system.se_play($data_system.buzzer_se)
  9335.         else
  9336.           # play sound
  9337.           $game_system.se_play($data_system.decision_se)
  9338.           # swap those triggers
  9339.           @actor.triggers[@triggers_window.index],
  9340.               @actor.triggers[@triggers_window.index + 1] =
  9341.               @actor.triggers[@triggers_window.index + 1],
  9342.               @actor.triggers[@triggers_window.index]
  9343.           # refresh display
  9344.           @triggers_window.draw_item(@triggers_window.index)
  9345.           @triggers_window.index += 1
  9346.           @triggers_window.draw_item(@triggers_window.index)
  9347.         end
  9348.       end
  9349.     end
  9350.   end
  9351.   #----------------------------------------------------------------------------
  9352.   # update_edit_command
  9353.   #  The edit command window update processing method.
  9354.   #----------------------------------------------------------------------------
  9355.   def update_edit_command
  9356.     # update triggers window
  9357.     @ecommand_window.update
  9358.     # if B is pressed
  9359.     if Input.trigger?(Input::B)
  9360.       # play cancel sound
  9361.       $game_system.se_play($data_system.cancel_se)
  9362.       # if adding a new trigger
  9363.       if @tcommand_window.index == 1
  9364.         # activate trigger command window
  9365.         @tcommand_window.active = true
  9366.       else
  9367.         # activate triggers window
  9368.         @triggers_window.active = true
  9369.       end
  9370.       # delete edit command window
  9371.       @ecommand_window.dispose
  9372.       # delete edit window
  9373.       @edit_window.dispose
  9374.       # clear variables
  9375.       @ecommand_window = @edit_window = nil
  9376.     # if C is pressed
  9377.     elsif Input.trigger?(Input::C)
  9378.       # update specific action
  9379.       case @ecommand_window.index
  9380.       when 0
  9381.         # play sound
  9382.         $game_system.se_play($data_system.decision_se)
  9383.         # create edit trigger window
  9384.         create_edit_trigger_window(BlizzABS::Cache::TRGActivators,
  9385.             @edit_window.trigger.activator)
  9386.       when 1
  9387.         # if probability activator
  9388.         if @edit_window.trigger.activator == BlizzABS::TRGProbability
  9389.           # play sound
  9390.           $game_system.se_play($data_system.buzzer_se)
  9391.           # exit method
  9392.           return
  9393.         end
  9394.         # possible commands
  9395.         commands = [$data_system.words.hp, $data_system.words.sp,
  9396.             BlizzABS::Cache::WORDState]
  9397.         # if not activated by party leader
  9398.         if @edit_window.trigger.activator != BlizzABS::TRGLeader
  9399.           # add location
  9400.           commands.push(BlizzABS::Cache::WORDLocation)
  9401.         end
  9402.         # play sound
  9403.         $game_system.se_play($data_system.decision_se)
  9404.         # create edit trigger window
  9405.         create_edit_trigger_window(commands,
  9406.             @edit_window.trigger.condition)
  9407.       when 2
  9408.         # if probability activator or state condition or location condition
  9409.         if @edit_window.trigger.activator == BlizzABS::TRGProbability ||
  9410.             @edit_window.trigger.condition == BlizzABS::TRGState ||
  9411.             @edit_window.trigger.condition == BlizzABS::TRGLocation
  9412.           # play sound
  9413.           $game_system.se_play($data_system.buzzer_se)
  9414.           # exit method
  9415.           return
  9416.         end
  9417.         # play sound
  9418.         $game_system.se_play($data_system.decision_se)
  9419.         # create edit trigger window
  9420.         create_edit_trigger_window(BlizzABS::Cache::TRGComparators,
  9421.             @edit_window.trigger.comparator)
  9422.       when 3
  9423.         # play sound
  9424.         $game_system.se_play($data_system.decision_se)
  9425.         # if condition is state
  9426.         if @edit_window.trigger.condition == BlizzABS::TRGState
  9427.           # create edit trigger window
  9428.           create_edit_trigger_window(@states, @edit_window.trigger.value)
  9429.         # if location condition
  9430.         elsif @edit_window.trigger.condition == BlizzABS::TRGLocation
  9431.           # create edit trigger window
  9432.           create_edit_trigger_window(BlizzABS::Cache::TRGLocations,
  9433.               @edit_window.trigger.value)
  9434.         else
  9435.           # create a list of states
  9436.           @edit_trigger_window = Window_TriggerValue.new(0, 100,
  9437.               @edit_window.trigger.value)
  9438.         end
  9439.       when 4
  9440.         # attack and defend commands by default
  9441.         commands = [$data_system.words.attack, $data_system.words.guard]
  9442.         # get all skill possible IDs
  9443.         @skills = $BlizzABS.util.get_actor_skills(@actor)
  9444.         # add skill command if any skills available
  9445.         commands.push($data_system.words.skill) if @skills.size > 0
  9446.         # get all items possible IDs
  9447.         @items = (1...$data_items.size).find_all {|id|
  9448.             $game_party.item_number(id) > 0 && $data_items[id].occasion < 2}
  9449.         # add item command if any items available
  9450.         commands.push($data_system.words.item) if @items.size > 0
  9451.         # play sound
  9452.         $game_system.se_play($data_system.decision_se)
  9453.         # create edit trigger window
  9454.         create_edit_trigger_window(commands,
  9455.             @edit_window.trigger.action_type)
  9456.       when 5
  9457.         commands = []
  9458.         # if skill action
  9459.         if @edit_window.trigger.action_type == BlizzABS::TRGSkill
  9460.           # get all skill possible IDs
  9461.           @skills = $BlizzABS.util.get_actor_skills(@actor)
  9462.           # get all skill names
  9463.           @skills.each {|id| commands.push($data_skills[id].name)}
  9464.           # index for selection
  9465.           index = @skills.index(@edit_window.trigger.action_data)
  9466.         # if item action
  9467.         elsif @edit_window.trigger.action_type == BlizzABS::TRGItem
  9468.           # get all items possible IDs
  9469.           @items = (1...$data_items.size).find_all {|id|
  9470.               $game_party.item_number(id) > 0 && $data_items[id].occasion < 2}
  9471.           # get all item names
  9472.           @items.each {|id| commands.push($data_items[id].name)}
  9473.           # index for selection
  9474.           index = @items.index(@edit_window.trigger.action_data)
  9475.         else
  9476.           # play sound
  9477.           $game_system.se_play($data_system.buzzer_se)
  9478.           # exit method
  9479.           return
  9480.         end
  9481.         # play sound
  9482.         $game_system.se_play($data_system.decision_se)
  9483.         # create edit trigger window
  9484.         create_edit_trigger_window(commands, index)
  9485.       when 6
  9486.         # if probability activator
  9487.         if @edit_window.trigger.activator == BlizzABS::TRGProbability
  9488.           # play sound
  9489.           $game_system.se_play($data_system.buzzer_se)
  9490.           # exit method
  9491.           return
  9492.         end
  9493.         # play sound
  9494.         $game_system.se_play($data_system.decision_se)
  9495.         # create edit trigger window
  9496.         create_edit_trigger_window(BlizzABS::Cache::TRGTargets,
  9497.             @edit_window.trigger.target)
  9498.       when 7
  9499.         # play sound
  9500.         $game_system.se_play($data_system.decision_se)
  9501.         # if adding new trigger
  9502.         if @tcommand_window.index == 1
  9503.           # add new trigger
  9504.           @actor.triggers.push(@edit_window.trigger)
  9505.           # refresh display
  9506.           @triggers_window.refresh
  9507.           # set index to last position
  9508.           @triggers_window.index = @actor.triggers.size - 1
  9509.           # set mode to edit
  9510.           @tcommand_window.index = 0
  9511.           # refresh triggers command window
  9512.           check_triggers
  9513.         else
  9514.           # replace old trigger
  9515.           @actor.triggers[@triggers_window.index] = @edit_window.trigger
  9516.           # redraw display
  9517.           @triggers_window.draw_item(@triggers_window.index)
  9518.         end
  9519.         # set triggers window active
  9520.         @triggers_window.active = true
  9521.         # delete edit command window
  9522.         @ecommand_window.dispose
  9523.         # delete edit window
  9524.         @edit_window.dispose
  9525.         # clear variables
  9526.         @ecommand_window = @edit_window = nil
  9527.       when 8
  9528.         # play sound
  9529.         $game_system.se_play($data_system.decision_se)
  9530.         # if adding a new trigger
  9531.         if @tcommand_window.index == 1
  9532.           # activate trigger command window
  9533.           @tcommand_window.active = true
  9534.         else
  9535.           # activate triggers window
  9536.           @triggers_window.active = true
  9537.         end
  9538.         # delete edit command window
  9539.         @ecommand_window.dispose
  9540.         # delete edit window
  9541.         @edit_window.dispose
  9542.         # clear variables
  9543.         @ecommand_window = @edit_window = nil
  9544.       end
  9545.     end
  9546.   end
  9547.   #----------------------------------------------------------------------------
  9548.   # create_edit_trigger_window
  9549.   #  commands - window command list
  9550.   #  index    - selection index
  9551.   #  Creates and sets up an edit trigger window.
  9552.   #----------------------------------------------------------------------------
  9553.   def create_edit_trigger_window(commands, index = 0)
  9554.     # deactivate trigger command window
  9555.     @ecommand_window.active = false
  9556.     # create edit trigger window
  9557.     @edit_trigger_window = Window_Command.new(320, commands)
  9558.     # set edit trigger coordinates
  9559.     @edit_trigger_window.height = 480 if @edit_trigger_window.height > 480
  9560.     @edit_trigger_window.x = 160
  9561.     @edit_trigger_window.y = 240 - @edit_trigger_window.height / 2
  9562.     @edit_trigger_window.z = @ecommand_window.z + 100
  9563.     # set edit trigger window active
  9564.     @edit_trigger_window.active = true
  9565.     # set edit trigger window cursor
  9566.     @edit_trigger_window.index = index
  9567.   end
  9568.   #----------------------------------------------------------------------------
  9569.   # update_edit_trigger
  9570.   #  The edit trigger window update processing method.
  9571.   #----------------------------------------------------------------------------
  9572.   def update_edit_trigger
  9573.     # update triggers window
  9574.     @edit_trigger_window.update
  9575.     # if B is pressed
  9576.     if Input.trigger?(Input::B)
  9577.       # play cancel sound
  9578.       $game_system.se_play($data_system.cancel_se)
  9579.       # return to edit command window
  9580.       return_to_edit_command_window
  9581.     # if C is pressed
  9582.     elsif Input.trigger?(Input::C)
  9583.       # update specific action
  9584.       case @ecommand_window.index
  9585.       when 0
  9586.         # play sound
  9587.         $game_system.se_play($data_system.decision_se)
  9588.         # store old activator value
  9589.         old = @edit_window.trigger.activator
  9590.         # set new value for activator
  9591.         @edit_window.trigger.activator = @edit_trigger_window.index
  9592.         # refresh trigger display
  9593.         @edit_window.refresh
  9594.         # if probability activator
  9595.         if @edit_window.trigger.activator == BlizzABS::TRGProbability
  9596.           # set condition to HP
  9597.           @edit_window.trigger.condition = BlizzABS::TRGHP
  9598.           # set comparison operator to equal
  9599.           @edit_window.trigger.comparator = BlizzABS::TRGEqual
  9600.           # set target to default
  9601.           @edit_window.trigger.target = BlizzABS::TRGTargetDefault
  9602.         # if party leader activator and location condition
  9603.         elsif @edit_window.trigger.activator == BlizzABS::TRGLeader &&
  9604.             @edit_window.trigger.condition == BlizzABS::TRGLocation
  9605.           # set condition to HP
  9606.           @edit_window.trigger.condition = BlizzABS::TRGHP
  9607.         end
  9608.         # return to edit command window
  9609.         return_to_edit_command_window
  9610.       when 1
  9611.         # if state condition
  9612.         if @edit_window.trigger.condition == BlizzABS::TRGState
  9613.           # set comparison operator to equal
  9614.           @edit_window.trigger.comparator = BlizzABS::TRGEqual
  9615.           # set state to normal
  9616.           @edit_window.trigger.value = 0
  9617.         # if location condition
  9618.         elsif @edit_window.trigger.condition == BlizzABS::TRGLocation
  9619.           # set comparison operator to equal
  9620.           @edit_window.trigger.comparator = BlizzABS::TRGEqual
  9621.         end
  9622.         # play sound
  9623.         $game_system.se_play($data_system.decision_se)
  9624.         # set new value for trigger
  9625.         @edit_window.trigger.condition = @edit_trigger_window.index
  9626.         # refresh trigger display
  9627.         @edit_window.refresh
  9628.         # return to edit command window
  9629.         return_to_edit_command_window
  9630.       when 2
  9631.         # play sound
  9632.         $game_system.se_play($data_system.decision_se)
  9633.         # set new value for trigger
  9634.         @edit_window.trigger.comparator = @edit_trigger_window.index
  9635.         # refresh trigger display
  9636.         @edit_window.refresh
  9637.         # return to edit command window
  9638.         return_to_edit_command_window
  9639.       when 3
  9640.         # play sound
  9641.         $game_system.se_play($data_system.decision_se)
  9642.         # if condition is state or location
  9643.         if @edit_window.trigger.condition == BlizzABS::TRGState ||
  9644.             @edit_window.trigger.condition == BlizzABS::TRGLocation
  9645.           # set to index
  9646.           @edit_window.trigger.value = @edit_trigger_window.index
  9647.         else
  9648.           # set to selected value
  9649.           @edit_window.trigger.value = @edit_trigger_window.number
  9650.         end
  9651.         # refresh trigger display
  9652.         @edit_window.refresh
  9653.         # return to edit command window
  9654.         return_to_edit_command_window
  9655.       when 4
  9656.         # play sound
  9657.         $game_system.se_play($data_system.decision_se)
  9658.         # temporary variables
  9659.         old, new = @edit_window.trigger.action_type, @edit_trigger_window.index
  9660.         # if not skills availabled and selected skill action type
  9661.         if @skills.size == 0 && new == BlizzABS::TRGSkill
  9662.           # it is actually item action type
  9663.           new == BlizzABS::TRGItem
  9664.         end
  9665.         # if wasn't skill action type until now
  9666.         if old != BlizzABS::TRGSkill && new == BlizzABS::TRGSkill
  9667.           # set first available skill
  9668.           @edit_window.trigger.action_data = @skills[0]
  9669.         # if wasn't item action type until now
  9670.         elsif old != BlizzABS::TRGItem && new == BlizzABS::TRGItem
  9671.           # set first available item
  9672.           @edit_window.trigger.action_data = @items[0]
  9673.         end
  9674.         # set new value for trigger
  9675.         @edit_window.trigger.action_type = @edit_trigger_window.index
  9676.         # refresh trigger display
  9677.         @edit_window.refresh
  9678.         # return to edit command window
  9679.         return_to_edit_command_window
  9680.       when 6
  9681.         # play sound
  9682.         $game_system.se_play($data_system.decision_se)
  9683.         # set new value for trigger
  9684.         @edit_window.trigger.target = @edit_trigger_window.index
  9685.         # refresh trigger display
  9686.         @edit_window.refresh
  9687.         # return to edit command window
  9688.         return_to_edit_command_window
  9689.       when 5
  9690.         # play sound
  9691.         $game_system.se_play($data_system.decision_se)
  9692.         # if skill action type
  9693.         if @edit_window.trigger.action_type == BlizzABS::TRGSkill
  9694.           # set skill ID
  9695.           @edit_window.trigger.action_data = @skills[@edit_trigger_window.index]
  9696.         # if item action type
  9697.         elsif @edit_window.trigger.action_type == BlizzABS::TRGItem
  9698.           # set item ID
  9699.           @edit_window.trigger.action_data = @items[@edit_trigger_window.index]
  9700.         end
  9701.         # refresh trigger display
  9702.         @edit_window.refresh
  9703.         # return to edit command window
  9704.         return_to_edit_command_window
  9705.       end
  9706.     end
  9707.   end
  9708.   #----------------------------------------------------------------------------
  9709.   # return_to_edit_command_window
  9710.   #  Sets everything up so the edit command window is active again.
  9711.   #----------------------------------------------------------------------------
  9712.   def return_to_edit_command_window
  9713.     # activate trigger command window
  9714.     @ecommand_window.active = true
  9715.     # delete edit trigger window
  9716.     @edit_trigger_window.dispose
  9717.     # clear variables
  9718.     @edit_trigger_window = nil
  9719.     # check edit window display
  9720.     check_edits
  9721.   end
  9722.  
  9723. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement