Advertisement
Archeia

Yanfly Engine Ace - Area of Effect v1.02

Mar 30th, 2014
898
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 34.70 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # ▼ Yanfly Engine Ace - Area of Effect v1.02
  4. # -- Last Updated: 2012.07.23
  5. # -- Level: Hard
  6. # -- Requires: YEA - Target Manager v1.02
  7. #
  8. #==============================================================================
  9.  
  10. $imported = {} if $imported.nil?
  11. $imported["YEA-AreaofEffect"] = true
  12.  
  13. #==============================================================================
  14. # ▼ Updates
  15. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  16. # 2012.07.23 - Bug Fixed: AoE picking targets.
  17. # 2012.01.13 - Bug Fixed: AoE removing targets.
  18. # 2012.01.04 - Started Script and Finished.
  19. #
  20. #==============================================================================
  21. # ▼ Introduction
  22. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  23. # Sometimes, targeting one foe isn't enough and targeting all foes is too much.
  24. # The right mix in between would be area of effects to target only a certain
  25. # area of foes. This script enables area of effect targeting to come in the
  26. # forms of circular areas, column areas, row areas, and even the whole map. For
  27. # those who worry about how enemies may get hit, this script also includes the
  28. # ability to adjust an enemy's hitbox allowing them to be targeted properly
  29. # with area of effect skills and items.
  30. #
  31. #==============================================================================
  32. # ▼ Instructions
  33. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  34. # To install this script, open up your script editor and copy/paste this script
  35. # to an open slot below ▼ Materials/'f材 but above ▼ Main. Remember to save.
  36. #
  37. # -----------------------------------------------------------------------------
  38. # Skill Notetags - These notetags go in the skills notebox in the database.
  39. # -----------------------------------------------------------------------------
  40. # <aoe radius: x>
  41. # Sets the radius of a circular Area of Effect to x. This effect is required to
  42. # mark a skill or item as having an Area of Effect.
  43. #
  44. # <aoe image: string>
  45. # Changes the image used for the circular Area of Effect marker to "string". If
  46. # this tag is not used, the Area of Effect will use the DEFAULT_CIRCLE image.
  47. #
  48. # <aoe blend: x>
  49. # Changes the blend effect of the image to 0 - Normal, 1 - Additive, or
  50. # 2 - Subtractive. If this tag is not used, the area of effect blend type will
  51. # use the CIRCULAR_BLEND effect.
  52. #
  53. # <aoe height: x%>
  54. # Changes the height of the Area of Effect range to x%. If this tag is not
  55. # used, the Area of Effect height will be the DEFAULT_HEIGHT percentage.
  56. #
  57. # <aoe column: x>
  58. # This will cause the skill or item to have an Area of Effect with a width of x
  59. # pixels wide. This effect is required to mark a skill or item as having a
  60. # rectangular Area of Effect. Use this or <aoe row: x> or <aoe map>.
  61. #
  62. # <aoe row: x>
  63. # This will cause the skill or item to have an Area of Effect with a height of
  64. # x pixels tall. This effect is required to mark a skill or item as having a
  65. # rectangular Area of Effect. Use this or <aoe column: x> or <aoe map>.
  66. #
  67. # <aoe map>
  68. # This will cause the skill or item to have an Area of Effect that spans the
  69. # entire screen. This effect is required to mark a skill or item as having a
  70. # rectangular Area of Effect. Use this or <aoe row: x> or <aoe column: x>.
  71. #
  72. # <rect image: string>
  73. # Changes the image used for the rectangular Area of Effect marker to "string".
  74. # If this tag is not used, the Area of Effect will use the DEFAULT_SQUARE image.
  75. #
  76. # <rect blend: x>
  77. # Changes the blend effect of the image to 0 - Normal, 1 - Additive, or
  78. # 2 - Subtractive. If this tag is not used, the area of effect blend type will
  79. # use the SQUARISH_BLEND effect.
  80. #
  81. # -----------------------------------------------------------------------------
  82. # Item Notetags - These notetags go in the items notebox in the database.
  83. # -----------------------------------------------------------------------------
  84. # <aoe radius: x>
  85. # Sets the radius of a circular Area of Effect to x. This effect is required to
  86. # mark a skill or item as having an Area of Effect.
  87. #
  88. # <aoe image: string>
  89. # Changes the image used for the circular Area of Effect marker to "string". If
  90. # this tag is not used, the Area of Effect will use the DEFAULT_CIRCLE image.
  91. #
  92. # <aoe blend: x>
  93. # Changes the blend effect of the image to 0 - Normal, 1 - Additive, or
  94. # 2 - Subtractive. If this tag is not used, the area of effect blend type will
  95. # use the CIRCULAR_BLEND effect.
  96. #
  97. # <aoe height: x%>
  98. # Changes the height of the Area of Effect range to x%. If this tag is not
  99. # used, the Area of Effect height will be the DEFAULT_HEIGHT percentage.
  100. #
  101. # <aoe column: x>
  102. # This will cause the skill or item to have an Area of Effect with a width of x
  103. # pixels wide. This effect is required to mark a skill or item as having a
  104. # rectangular Area of Effect. Use this or <aoe row: x> or <aoe map>.
  105. #
  106. # <aoe row: x>
  107. # This will cause the skill or item to have an Area of Effect with a height of
  108. # x pixels tall. This effect is required to mark a skill or item as having a
  109. # rectangular Area of Effect. Use this or <aoe column: x> or <aoe map>.
  110. #
  111. # <aoe map>
  112. # This will cause the skill or item to have an Area of Effect that spans the
  113. # entire screen. This effect is required to mark a skill or item as having a
  114. # rectangular Area of Effect. Use this or <aoe row: x> or <aoe column: x>.
  115. #
  116. # <rect image: string>
  117. # Changes the image used for the rectangular Area of Effect marker to "string".
  118. # If this tag is not used, the Area of Effect will use the DEFAULT_SQUARE image.
  119. #
  120. # <rect blend: x>
  121. # Changes the blend effect of the image to 0 - Normal, 1 - Additive, or
  122. # 2 - Subtractive. If this tag is not used, the area of effect blend type will
  123. # use the SQUARISH_BLEND effect.
  124. #
  125. # -----------------------------------------------------------------------------
  126. # Enemy Notetags - These notetags go in the enemies notebox in the database.
  127. # -----------------------------------------------------------------------------
  128. # <hitbox width: x>
  129. # Changes the hitbox for the enemy to x pixels wide. The wider an enemy, the
  130. # more likely it is to be hit by an Area of Effect.
  131. #
  132. # <hitbox height: x>
  133. # Changes the hitbox for the enemy to x pixels tall. The taller an enemy, the
  134. # more likely it is to be hit by an Area of Effect.
  135. #
  136. # <offset x: -x>
  137. # <offset x: +x>
  138. # Changes the positioning of an enemy's horizontal origin by x amount. By
  139. # default, all enemies have a horizontal origin set at the center.
  140. #
  141. # <offset y: -x>
  142. # <offset y: +x>
  143. # Changes the positioning of an enemy's vertical origin by y amount. By
  144. # default, all enemies have a horizontal origin set at their feet.
  145. #
  146. #==============================================================================
  147. # ▼ Compatibility
  148. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  149. # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
  150. # it will run with RPG Maker VX without adjusting.
  151. #
  152. # This script requires Yanfly Engine Ace - Target Manager v1.02+ to work. Place
  153. # this script under Yanfly Engine Ace - Target Manager in the script list.
  154. #
  155. #==============================================================================
  156.  
  157. module YEA
  158.   module AOE
  159.    
  160.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  161.     # - Circular AoE Settings -
  162.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  163.     # The following sets the default settings used for AoE visual effects.
  164.     # There must be an image within your game's Graphics\Pictures\ folder
  165.     # matching the default filename below.
  166.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  167.     DEFAULT_CIRCLE = "AoE_CircleFull"    # Default circular AoE Image.
  168.     CIRCULAR_BLEND = 1     # 0 - Normal; 1 - Additive; 2 - Subtractive
  169.    
  170.     # This is how much smaller (or larger) the selection height is in
  171.     # comparison to the default width of selection area. The offset is how
  172.     # much higher the circle should be than normal.
  173.     DEFAULT_HEIGHT = 0.33
  174.    
  175.     # This is the default offset coordinate offsets for enemies on screen.
  176.     # Made to center the circles properly.
  177.     DEFAULT_ENEMY_OFFSET_X =  0
  178.     DEFAULT_ENEMY_OFFSET_Y = -8
  179.    
  180.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  181.     # - Rectangular AoE Settings -
  182.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  183.     # The following sets the default settings used for AoE visual effects.
  184.     # There must be an image within your game's Graphics\Pictures\ folder
  185.     # matching the default filename below.
  186.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  187.     DEFAULT_SQUARE = "AoE_SquareFull"    # Default square AoE Image.
  188.     SQUARISH_BLEND = 1     # 0 - Normal; 1 - Additive; 2 - Subtractive
  189.    
  190.   end # AOE
  191. end # YEA
  192.  
  193. #==============================================================================
  194. # ▼ Editting anything past this point may potentially result in causing
  195. # computer damage, incontinence, explosion of user's head, coma, death, and/or
  196. # halitosis so edit at your own risk.
  197. #==============================================================================
  198.  
  199. module YEA
  200.   module REGEXP
  201.   module USABLEITEM
  202.    
  203.     AOE_IMAGE  = /<(?:AOE_IMAGE|aoe image):[ ](.*)>/i
  204.     AOE_BLEND  = /<(?:AOE_BLEND|aoe blend):[ ](\d+)>/i
  205.     AOE_HEIGHT = /<(?:AOE_HEIGHT|aoe height):[ ](\d+)([%])>/i
  206.     AOE_RADIUS = /<(?:AOE_RADIUS|aoe radius):[ ](\d+)>/i
  207.    
  208.     RECT_IMAGE = /<(?:RECT_IMAGE|rect image):[ ](.*)>/i
  209.     RECT_BLEND = /<(?:RECT_BLEND|rect blend):[ ](\d+)>/i
  210.     RECT_COL   = /<(?:AOE_COLUMN|aoe column):[ ](\d+)>/i
  211.     RECT_ROW   = /<(?:AOE_ROW|aoe row):[ ](\d+)>/i
  212.     RECT_MAP   = /<(?:AOE_MAP|aoe map)>/i
  213.    
  214.   end # USABLEITEM
  215.   module ENEMY
  216.    
  217.     OFFSET_X = /<(?:OFFSET_X|offset x):[ ]([\+\-]\d+)>/i
  218.     OFFSET_Y = /<(?:OFFSET_Y|offset y):[ ]([\+\-]\d+)>/i
  219.     HITBOX_W = /<(?:HITBOX_WIDTH|hitbox width):[ ](\d+)>/i
  220.     HITBOX_H = /<(?:HITBOX_HEIGHT|hitbox height):[ ](\d+)>/i
  221.    
  222.   end # ENEMY
  223.   end # REGEXP
  224. end # YEA
  225.  
  226.  
  227. #==============================================================================
  228. # ■ DataManager
  229. #==============================================================================
  230.  
  231. module DataManager
  232.  
  233.   #--------------------------------------------------------------------------
  234.   # alias method: load_database
  235.   #--------------------------------------------------------------------------
  236.   class <<self; alias load_database_aoe load_database; end
  237.   def self.load_database
  238.     load_database_aoe
  239.     load_notetags_aoe
  240.   end
  241.  
  242.   #--------------------------------------------------------------------------
  243.   # new method: load_notetags_aoe
  244.   #--------------------------------------------------------------------------
  245.   def self.load_notetags_aoe
  246.     groups = [$data_skills, $data_items, $data_enemies]
  247.     for group in groups
  248.       for obj in group
  249.         next if obj.nil?
  250.         obj.load_notetags_aoe
  251.       end
  252.     end
  253.   end
  254.  
  255. end # DataManager
  256.  
  257. #==============================================================================
  258. # ■ RPG::UsableItem
  259. #==============================================================================
  260.  
  261. class RPG::UsableItem < RPG::BaseItem
  262.  
  263.   #--------------------------------------------------------------------------
  264.   # public instance variables
  265.   #--------------------------------------------------------------------------
  266.   attr_accessor :aoe_image
  267.   attr_accessor :aoe_blend
  268.   attr_accessor :aoe_height
  269.   attr_accessor :aoe_radius
  270.   attr_accessor :rect_image
  271.   attr_accessor :rect_blend
  272.   attr_accessor :rect_value
  273.   attr_accessor :rect_type
  274.  
  275.   #--------------------------------------------------------------------------
  276.   # common cache: load_notetags_aoe
  277.   #--------------------------------------------------------------------------
  278.   def load_notetags_aoe
  279.     @aoe_image = YEA::AOE::DEFAULT_CIRCLE
  280.     @aoe_blend = YEA::AOE::CIRCULAR_BLEND
  281.     @aoe_height = YEA::AOE::DEFAULT_HEIGHT
  282.     @aoe_radius = 0
  283.     @rect_image = YEA::AOE::DEFAULT_SQUARE
  284.     @rect_blend = YEA::AOE::SQUARISH_BLEND
  285.     @rect_value = 0
  286.     @rect_type = 0
  287.     #---
  288.     self.note.split(/[\r\n]+/).each { |line|
  289.       case line
  290.       #---
  291.       when YEA::REGEXP::USABLEITEM::AOE_IMAGE
  292.         @aoe_image = $1.to_s
  293.       when YEA::REGEXP::USABLEITEM::AOE_BLEND
  294.         @aoe_blend = [[$1.to_i, 0].max, 2].min
  295.       when YEA::REGEXP::USABLEITEM::AOE_HEIGHT
  296.         @aoe_height = [$1.to_i * 0.01, 0.1].max
  297.       when YEA::REGEXP::USABLEITEM::AOE_RADIUS
  298.         @aoe_radius = [$1.to_i, 3].max
  299.       #---
  300.       when YEA::REGEXP::USABLEITEM::RECT_IMAGE
  301.         @rect_image = $1.to_s
  302.       when YEA::REGEXP::USABLEITEM::RECT_BLEND
  303.         @rect_blend = $1.to_i
  304.       when YEA::REGEXP::USABLEITEM::RECT_COL
  305.         @rect_type = 1
  306.         @rect_value = [$1.to_i, 3].max
  307.       when YEA::REGEXP::USABLEITEM::RECT_ROW
  308.         @rect_type = 2
  309.         @rect_value = [$1.to_i, 3].max
  310.       when YEA::REGEXP::USABLEITEM::RECT_MAP
  311.         @rect_type = 3
  312.       #---
  313.       end
  314.     } # self.note.split
  315.     #---
  316.   end
  317.  
  318. end # class RPG::UsableItem
  319.  
  320. #==============================================================================
  321. # ■ RPG::Enemy
  322. #==============================================================================
  323.  
  324. class RPG::Enemy < RPG::BaseItem
  325.  
  326.   #--------------------------------------------------------------------------
  327.   # public instance variables
  328.   #--------------------------------------------------------------------------
  329.   attr_accessor :offset_x
  330.   attr_accessor :offset_y
  331.   attr_accessor :hitbox_w
  332.   attr_accessor :hitbox_h
  333.  
  334.   #--------------------------------------------------------------------------
  335.   # common cache: load_notetags_aoe
  336.   #--------------------------------------------------------------------------
  337.   def load_notetags_aoe
  338.     @offset_x = YEA::AOE::DEFAULT_ENEMY_OFFSET_X
  339.     @offset_y = YEA::AOE::DEFAULT_ENEMY_OFFSET_Y
  340.     #---
  341.     self.note.split(/[\r\n]+/).each { |line|
  342.       case line
  343.       #---
  344.       when YEA::REGEXP::ENEMY::OFFSET_X
  345.         @offset_x = $1.to_i
  346.       when YEA::REGEXP::ENEMY::OFFSET_Y
  347.         @offset_y = $1.to_i
  348.       when YEA::REGEXP::ENEMY::HITBOX_W
  349.         @hitbox_w = [$1.to_i, 1].max
  350.       when YEA::REGEXP::ENEMY::HITBOX_H
  351.         @hitbox_h = [$1.to_i, 1].max
  352.       #---
  353.       end
  354.     } # self.note.split
  355.     #---
  356.   end
  357.  
  358. end # RPG::Enemy
  359.  
  360. #==============================================================================
  361. # ■ Sprite_AoE_Circle
  362. #==============================================================================
  363.  
  364. class Sprite_AoE_Circle < Sprite_Base
  365.  
  366.   #--------------------------------------------------------------------------
  367.   # initialize
  368.   #--------------------------------------------------------------------------
  369.   def initialize(viewport)
  370.     super(viewport)
  371.     create_bitmap
  372.     @glow_rate = -8
  373.   end
  374.  
  375.   #--------------------------------------------------------------------------
  376.   # dispose
  377.   #--------------------------------------------------------------------------
  378.   def dispose
  379.     self.bitmap.dispose unless self.bitmap.nil?
  380.     super
  381.   end
  382.  
  383.   #--------------------------------------------------------------------------
  384.   # create_bitmap
  385.   #--------------------------------------------------------------------------
  386.   def create_bitmap(item = nil)
  387.     return if @item == item
  388.     @item = item
  389.     return if @item.nil?
  390.     return if no_aoe?
  391.     #---
  392.     self.bitmap = Cache.picture(@item.aoe_image)
  393.     self.blend_type = @item.aoe_blend
  394.     diameter = @item.aoe_radius * 2 + 1
  395.     self.zoom_x = diameter * 1.125 / self.width
  396.     self.zoom_y = self.zoom_x * @item.aoe_height
  397.     self.ox = self.width / 2
  398.     self.oy = self.height / 2
  399.     self.z = 2
  400.     self.visible = update_visible
  401.   end
  402.  
  403.   #--------------------------------------------------------------------------
  404.   # update
  405.   #--------------------------------------------------------------------------
  406.   def update
  407.     super
  408.     return unless SceneManager.scene_is?(Scene_Battle)
  409.     set_current_item
  410.     self.visible = update_visible
  411.     update_position
  412.     update_glow
  413.   end
  414.  
  415.   #--------------------------------------------------------------------------
  416.   # set_current_item
  417.   #--------------------------------------------------------------------------
  418.   def set_current_item
  419.     return if SceneManager.scene.enemy_window.nil?
  420.     if SceneManager.scene.enemy_window.visible
  421.       create_bitmap(BattleManager.actor.input.item)
  422.     elsif SceneManager.scene.actor_window.visible
  423.       create_bitmap(BattleManager.actor.input.item)
  424.     end
  425.   end
  426.  
  427.   #--------------------------------------------------------------------------
  428.   # no_aoe?
  429.   #--------------------------------------------------------------------------
  430.   def no_aoe?
  431.     return @item.aoe_radius <= 0
  432.   end
  433.  
  434.   #--------------------------------------------------------------------------
  435.   # update_visible
  436.   #--------------------------------------------------------------------------
  437.   def update_visible
  438.     return false if @item.nil?
  439.     return false if no_aoe?
  440.     return false if SceneManager.scene.enemy_window.nil?
  441.     return true if SceneManager.scene.enemy_window.visible
  442.     return true if SceneManager.scene.actor_window.visible
  443.     return false
  444.   end
  445.  
  446.   #--------------------------------------------------------------------------
  447.   # update_position
  448.   #--------------------------------------------------------------------------
  449.   def update_position
  450.     return if @item.nil?
  451.     return if no_aoe?
  452.     self.x = target_x
  453.     self.y = target_y
  454.   end
  455.  
  456.   #--------------------------------------------------------------------------
  457.   # target_x
  458.   #--------------------------------------------------------------------------
  459.   def target_x
  460.     n = 0
  461.     if SceneManager.scene.enemy_window.visible
  462.       n = SceneManager.scene.enemy_window.enemy.screen_x
  463.       n += SceneManager.scene.enemy_window.enemy.hitbox_x_offset
  464.     elsif SceneManager.scene.actor_window.visible
  465.       actor = $game_party.battle_members[SceneManager.scene.actor_window.index]
  466.       n = actor.screen_x
  467.       n += actor.hitbox_x_offset
  468.     end
  469.     return n
  470.   end
  471.  
  472.   #--------------------------------------------------------------------------
  473.   # target_y
  474.   #--------------------------------------------------------------------------
  475.   def target_y
  476.     n = 0
  477.     if SceneManager.scene.enemy_window.visible
  478.       n = SceneManager.scene.enemy_window.enemy.screen_y
  479.       n += SceneManager.scene.enemy_window.enemy.hitbox_y_offset
  480.     elsif SceneManager.scene.actor_window.visible
  481.       actor = $game_party.battle_members[SceneManager.scene.actor_window.index]
  482.       n = actor.screen_y
  483.       n += actor.hitbox_y_offset
  484.     end
  485.     return n
  486.   end
  487.  
  488.   #--------------------------------------------------------------------------
  489.   # update_glow
  490.   #--------------------------------------------------------------------------
  491.   def update_glow
  492.     return unless self.visible
  493.     self.opacity += @glow_rate
  494.     @glow_rate *= -1 if self.opacity <= 0 || self.opacity >= 255
  495.   end
  496.  
  497. end # Sprite_AoE_Circle
  498.  
  499. #==============================================================================
  500. # ■ Sprite_AoE_Square
  501. #==============================================================================
  502.  
  503. class Sprite_AoE_Square < Sprite_AoE_Circle
  504.  
  505.   #--------------------------------------------------------------------------
  506.   # create_bitmap
  507.   #--------------------------------------------------------------------------
  508.   def create_bitmap(item = nil)
  509.     return if @item == item
  510.     @item = item
  511.     return if @item.nil?
  512.     return if no_aoe?
  513.     #---
  514.     self.bitmap = Cache.picture(@item.rect_image)
  515.     self.blend_type = @item.rect_blend
  516.     case @item.rect_type
  517.     when 1 # Column
  518.       self.zoom_x = @item.rect_value.to_f / self.width
  519.       self.zoom_y = Graphics.height.to_f / self.height
  520.     when 2 # Row
  521.       self.zoom_x = Graphics.width.to_f / self.width
  522.       self.zoom_y = @item.rect_value.to_f / self.height
  523.     else # Map
  524.       self.zoom_x = Graphics.width.to_f / self.width
  525.       self.zoom_y = Graphics.height.to_f / self.height
  526.     end
  527.     self.ox = self.width / 2
  528.     self.oy = self.height / 2
  529.     self.z = 1
  530.     self.visible = update_visible
  531.   end
  532.  
  533.   #--------------------------------------------------------------------------
  534.   # no_aoe?
  535.   #--------------------------------------------------------------------------
  536.   def no_aoe?
  537.     return @item.rect_type <= 0
  538.   end
  539.  
  540.   #--------------------------------------------------------------------------
  541.   # target_x
  542.   #--------------------------------------------------------------------------
  543.   def target_x
  544.     return Graphics.width / 2 if [2, 3].include?(@item.rect_type)
  545.     return super
  546.   end
  547.  
  548.   #--------------------------------------------------------------------------
  549.   # target_y
  550.   #--------------------------------------------------------------------------
  551.   def target_y
  552.     return Graphics.height / 2 if [1, 3].include?(@item.rect_type)
  553.     return super
  554.   end
  555.  
  556. end # Sprite_AoE_Square
  557.  
  558. #==============================================================================
  559. # ■ Spriteset_Battle
  560. #==============================================================================
  561.  
  562. class Spriteset_Battle
  563.  
  564.   #--------------------------------------------------------------------------
  565.   # public instance variables
  566.   #--------------------------------------------------------------------------
  567.   attr_accessor :actor_sprites
  568.   attr_accessor :enemy_sprites
  569.  
  570.   #--------------------------------------------------------------------------
  571.   # alias method: initialize
  572.   #--------------------------------------------------------------------------
  573.   alias spriteset_battle_initialize_aoe initialize
  574.   def initialize
  575.     spriteset_battle_initialize_aoe
  576.     create_aoe_sprites
  577.   end
  578.  
  579.   #--------------------------------------------------------------------------
  580.   # new method: create_aoe_sprites
  581.   #--------------------------------------------------------------------------
  582.   def create_aoe_sprites
  583.     @aoe_circle_sprite = Sprite_AoE_Circle.new(@viewport1)
  584.     @aoe_square_sprite = Sprite_AoE_Square.new(@viewport1)
  585.   end
  586.  
  587.   #--------------------------------------------------------------------------
  588.   # alias method: dispose
  589.   #--------------------------------------------------------------------------
  590.   alias spriteset_battle_dispose_aoe dispose
  591.   def dispose
  592.     dispose_aoe_sprites
  593.     spriteset_battle_dispose_aoe
  594.   end
  595.  
  596.   #--------------------------------------------------------------------------
  597.   # new method: dispose_aoe_sprites
  598.   #--------------------------------------------------------------------------
  599.   def dispose_aoe_sprites
  600.     @aoe_circle_sprite.dispose unless @aoe_circle_sprite.nil?
  601.     @aoe_square_sprite.dispose unless @aoe_square_sprite.nil?
  602.   end
  603.  
  604.   #--------------------------------------------------------------------------
  605.   # alias method: update
  606.   #--------------------------------------------------------------------------
  607.   alias spriteset_battle_update_aoe update
  608.   def update
  609.     spriteset_battle_update_aoe
  610.     update_aoe_sprites
  611.   end
  612.  
  613.   #--------------------------------------------------------------------------
  614.   # new method: update_aoe_sprites
  615.   #--------------------------------------------------------------------------
  616.   def update_aoe_sprites
  617.     @aoe_circle_sprite.update unless @aoe_circle_sprite.nil?
  618.     @aoe_square_sprite.update unless @aoe_square_sprite.nil?
  619.   end
  620.  
  621. end # Spriteset_Battle
  622.  
  623. #==============================================================================
  624. # ■ Game_Action
  625. #==============================================================================
  626.  
  627. class Game_Action
  628.  
  629.   #--------------------------------------------------------------------------
  630.   # new method: aoe_targets
  631.   #--------------------------------------------------------------------------
  632.   def aoe_targets(targets)
  633.     result = aoe_circle_targets
  634.     result |= aoe_square_targets
  635.     for member in result
  636.       next if targets.include?(member)
  637.       targets.push(member)
  638.     end
  639.     return targets
  640.   end
  641.  
  642.   #--------------------------------------------------------------------------
  643.   # new method: aoe_circle_targets
  644.   #--------------------------------------------------------------------------
  645.   def aoe_circle_targets
  646.     targets = []
  647.     return targets if item.nil? or item.aoe_radius <= 0
  648.     group = item.for_friend? ? friends_unit : opponents_unit
  649.     main = opponents_unit.smooth_target(@target_index)
  650.     for target in group.alive_members
  651.       targets.push(target) if inside_aoe_circle?(main, target)
  652.     end
  653.     return targets
  654.   end
  655.  
  656.   #--------------------------------------------------------------------------
  657.   # new method: inside_aoe_circle?
  658.   #--------------------------------------------------------------------------
  659.   def inside_aoe_circle?(main, target)
  660.     radius = item.aoe_radius + 1
  661.     height = item.aoe_height
  662.     main_x = main.screen_x + main.hitbox_x_offset
  663.     main_y = main.screen_y + main.hitbox_y_offset
  664.     target_x = target.screen_x
  665.     target_y = target.screen_y
  666.     if main_x > target.screen_x
  667.       target_x = [target.hitbox.x + target.hitbox.width, main_x].min
  668.     elsif main_x < target.screen_x
  669.       target_x = [target.hitbox.x, main_x].max
  670.     end
  671.     if main_y > target.screen_y
  672.       target_y = [target.hitbox.y + target.hitbox.height, main_y].min
  673.     elsif main_y < target.screen_y
  674.       target_y = [target.hitbox.y, main_y].max
  675.     end
  676.     x =  (target_x - main_x) * Math.cos(0) + (target_y - main_y) * Math.sin(0)
  677.     y = -(target_x - main_x) * Math.sin(0) + (target_y - main_y) * Math.cos(0)
  678.     a = radius * 1.125; b = radius * (height + 0.01)
  679.     return (x**2 / a**2) + (y**2 / b**2) <= 1
  680.   end
  681.  
  682.   #--------------------------------------------------------------------------
  683.   # new method: aoe_square_targets
  684.   #--------------------------------------------------------------------------
  685.   def aoe_square_targets
  686.     targets = []
  687.     return targets if item.nil? or item.rect_type <= 0
  688.     group = item.for_friend? ? friends_unit : opponents_unit
  689.     main = opponents_unit.smooth_target(@target_index)
  690.     for target in group.alive_members
  691.       targets.push(target) if inside_aoe_square?(main, target)
  692.     end
  693.     puts targets.size
  694.     return targets
  695.   end
  696.  
  697.   #--------------------------------------------------------------------------
  698.   # new method: inside_aoe_square?
  699.   #--------------------------------------------------------------------------
  700.   def inside_aoe_square?(main, target)
  701.     main_x = main.screen_x + main.hitbox_x_offset
  702.     main_y = main.screen_y + main.hitbox_y_offset
  703.     target_x = target.screen_x
  704.     target_y = target.screen_y
  705.     if main_x > target.screen_x
  706.       target_x = [target.hitbox.x + target.hitbox.width, main_x].min
  707.     elsif main_x < target.screen_x
  708.       target_x = [target.hitbox.x, main_x].max
  709.     end
  710.     if main_y > target.screen_y
  711.       target_y = [target.hitbox.y + target.hitbox.height, main_y].min
  712.     elsif main_y < target.screen_y
  713.       target_y = [target.hitbox.y, main_y].max
  714.     end
  715.     case item.rect_type
  716.     when 1 # Column
  717.       y1 = 0; y2 = Graphics.height
  718.       x1 = main_x - item.rect_value / 2
  719.       x2 = main_x + item.rect_value / 2
  720.     when 2 # Row
  721.       x1 = 0; x2 = Graphics.width
  722.       y1 = main_y - item.rect_value / 2
  723.       y2 = main_y + item.rect_value / 2
  724.     else # Map
  725.       x1 = 0; x2 = Graphics.width
  726.       y1 = 0; y2 = Graphics.height
  727.     end
  728.     in_x = ((x1..x2) === target_x)
  729.     in_y = ((y1..y2) === target_y)
  730.     return (in_x && in_y)
  731.   end
  732.  
  733. end # Game_Action
  734.  
  735. #==============================================================================
  736. # ■ Game_Battler
  737. #==============================================================================
  738.  
  739. class Game_Battler < Game_BattlerBase
  740.  
  741.   #--------------------------------------------------------------------------
  742.   # new method: hitbox
  743.   #--------------------------------------------------------------------------
  744.   def hitbox
  745.     rect = Rect.new(0, 0, 32, 32)
  746.     rect.x = screen_x - hitbox_width/2 + hitbox_x_offset
  747.     rect.y = screen_y - hitbox_height + hitbox_y_offset
  748.     rect.width = hitbox_width
  749.     rect.height = hitbox_height
  750.     return rect
  751.   end
  752.  
  753.   #--------------------------------------------------------------------------
  754.   # new method: hitbox_x_offset
  755.   #--------------------------------------------------------------------------
  756.   def hitbox_x_offset
  757.     return 0
  758.   end
  759.  
  760.   #--------------------------------------------------------------------------
  761.   # new method: hitbox_y_offset
  762.   #--------------------------------------------------------------------------
  763.   def hitbox_y_offset
  764.     return 0
  765.   end
  766.  
  767.   #--------------------------------------------------------------------------
  768.   # new method: hitbox_width
  769.   #--------------------------------------------------------------------------
  770.   def hitbox_width
  771.     return sprite.width
  772.   end
  773.  
  774.   #--------------------------------------------------------------------------
  775.   # new method: hitbox_height
  776.   #--------------------------------------------------------------------------
  777.   def hitbox_height
  778.     return sprite.height
  779.   end
  780.  
  781. end # Game_Battler
  782.  
  783. #==============================================================================
  784. # ■ Game_Actor
  785. #==============================================================================
  786.  
  787. class Game_Actor < Game_Battler
  788.  
  789.   #--------------------------------------------------------------------------
  790.   # anti-crash method: screen_x
  791.   #--------------------------------------------------------------------------
  792.   unless method_defined?(:screen_x)
  793.   def screen_x
  794.     dw = Graphics.width / $game_party.max_battle_members
  795.     return index * dw + dw / 2
  796.   end
  797.   end # method_defined?(:screen_x)
  798.  
  799.   #--------------------------------------------------------------------------
  800.   # anti-crash method: screen_y
  801.   #--------------------------------------------------------------------------
  802.   unless method_defined?(:screen_y)
  803.   def screen_y
  804.     return Graphics.height - 120
  805.   end
  806.   end # method_defined?(:screen_x)
  807.  
  808.   #--------------------------------------------------------------------------
  809.   # new method: sprite
  810.   #--------------------------------------------------------------------------
  811.   unless method_defined?(:sprite)
  812.   def sprite
  813.     index = $game_party.battle_members.index(self)
  814.     return SceneManager.scene.spriteset.actor_sprites[index]
  815.   end
  816.   end # method_defined?(:sprite)
  817.  
  818.   #--------------------------------------------------------------------------
  819.   # new method: hitbox_y_offset
  820.   #--------------------------------------------------------------------------
  821.   def hitbox_y_offset
  822.     return -4
  823.   end
  824.  
  825. end # Game_Actor
  826.  
  827. #==============================================================================
  828. # ■ Game_Enemy
  829. #==============================================================================
  830.  
  831. class Game_Enemy < Game_Battler
  832.  
  833.   #--------------------------------------------------------------------------
  834.   # new method: sprite
  835.   #--------------------------------------------------------------------------
  836.   def sprite
  837.     return SceneManager.scene.spriteset.enemy_sprites.reverse[self.index]
  838.   end
  839.  
  840.   #--------------------------------------------------------------------------
  841.   # new method: hitbox_x_offset
  842.   #--------------------------------------------------------------------------
  843.   def hitbox_x_offset
  844.     return enemy.offset_x unless enemy.offset_x.nil?
  845.     return super
  846.   end
  847.  
  848.   #--------------------------------------------------------------------------
  849.   # new method: hitbox_y_offset
  850.   #--------------------------------------------------------------------------
  851.   def hitbox_y_offset
  852.     return enemy.offset_y unless enemy.offset_y.nil?
  853.     return super
  854.   end
  855.  
  856.   #--------------------------------------------------------------------------
  857.   # new method: hitbox_width
  858.   #--------------------------------------------------------------------------
  859.   def hitbox_width
  860.     return enemy.hitbox_w unless enemy.hitbox_w.nil?
  861.     return super
  862.   end
  863.  
  864.   #--------------------------------------------------------------------------
  865.   # new method: hitbox_height
  866.   #--------------------------------------------------------------------------
  867.   def hitbox_height
  868.     return enemy.hitbox_h unless enemy.hitbox_h.nil?
  869.     return super
  870.   end
  871.  
  872. end # Game_Enemy
  873.  
  874. #==============================================================================
  875. # ■ Window_BattleEnemy
  876. #==============================================================================
  877.  
  878. class Window_BattleEnemy < Window_Selectable
  879.  
  880.   #--------------------------------------------------------------------------
  881.   # alias method: update
  882.   #--------------------------------------------------------------------------
  883.   alias window_battlenemy_update_aoe update
  884.   if $imported["YEA-BattleEngine"]
  885.   def update
  886.     window_battlenemy_update_aoe
  887.     return unless active
  888.     return if BattleManager.actor.input.item.nil?
  889.     for enemy in $game_troop.alive_members
  890.       next unless hightlight_aoe?(enemy)
  891.       enemy.sprite_effect_type = :whiten
  892.     end
  893.   end
  894.   end # $imported["YEA-BattleEngine"]
  895.  
  896.   #--------------------------------------------------------------------------
  897.   # new method: hightlight_aoe?
  898.   #--------------------------------------------------------------------------
  899.   def hightlight_aoe?(enemy)
  900.     target = @data[index]
  901.     if BattleManager.actor.input.item.aoe_radius > 0
  902.       return true if BattleManager.actor.input.inside_aoe_circle?(target, enemy)
  903.     end
  904.     if BattleManager.actor.input.item.rect_type > 0
  905.       return true if BattleManager.actor.input.inside_aoe_square?(target, enemy)
  906.     end
  907.     return false
  908.   end
  909.  
  910. end # Window_BattleEnemy
  911.  
  912. #==============================================================================
  913. # ■ Scene_Battle
  914. #==============================================================================
  915.  
  916. class Scene_Battle < Scene_Base
  917.  
  918.   #--------------------------------------------------------------------------
  919.   # public instance variables
  920.   #--------------------------------------------------------------------------
  921.   attr_accessor :enemy_window
  922.   attr_accessor :actor_window
  923.   attr_accessor :spriteset
  924.  
  925. end # Scene_Battle
  926.  
  927. #==============================================================================
  928. #
  929. # ▼ End of File
  930. #
  931. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement