Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Nov 20th, 2011  |  syntax: None  |  size: 346.43 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #===============================================================================
  2. #
  3. # Yanfly Engine Melody - Battle Engine Melody - Part V - Base Code
  4. # Last Date Updated: 2010.05.01
  5. # Level: Phantasm
  6. #
  7. # Over here is the base code used for Battle Engine Melody. The module will
  8. # contain in Melody script the base actions for each of the major and minor
  9. # actions found commonly within the battle scene. It's highly recommended that
  10. # you don't modify these unless you absolutely know what you're doing as these
  11. # values are considered the default Melody scripts for each of the major
  12. # actions used within the battle scene.
  13. #
  14. #===============================================================================
  15. # Updates
  16. # -----------------------------------------------------------------------------
  17. # o 2010.02.12 to 2010.05.01 - Started and Finished Script.
  18. #===============================================================================
  19. # Debug Shortcuts
  20. #===============================================================================
  21. # These shortcuts will only occur during $TEST and $BTEST. Otherwise, they will
  22. # not occur at all. These are only used for the sake of testing.
  23. #
  24. # F5 Button
  25. # - Fully heals the currently highlighted actor during turn selection.
  26. # - Fully heals the party during party command selection.
  27. # - Instantly kills the enemy when attacking.
  28. #
  29. # F6 Button
  30. # - Heals the highlighted actor's HP during turn selection.
  31. # - Heals the party's HP during party command selection.
  32. # - Prevents missing and evasion during calculations for actors.
  33. #
  34. # F7 Button
  35. # - Heals the highlighted actor's MP during turn selection.
  36. # - Heals the party's SP during command selection.
  37. #
  38. # F8 Button
  39. # - Damages the highlighted actor by various degrees when holding SHIFT or CTRL.
  40. # - Damages the whole party during command selection.
  41. #
  42. # F9 Button
  43. # - Enter the debug menu.
  44. #
  45. # CTRL Button
  46. # - If pressed with SHIFT held down during party selection, collapse enemies.
  47. # - If pressed with ALT held down, turn debug window appears.
  48. #===============================================================================
  49. # Editting anything past this point may potentially result in causing computer
  50. # damage, incontinence, explosion of user's head, coma, death, and/or halitosis.
  51. # Therefore, edit at your own risk.
  52. #===============================================================================
  53.  
  54. #===============================================================================
  55. # Yanfly Engine Melody
  56. #===============================================================================
  57.  
  58. module YEM
  59.   module REGEXP
  60.   module ANI
  61.    
  62.     ACTION_COPY = /<(?:ACTION_COPY|action copy):[ ](.*):[ ]*(\d+)>/i
  63.    
  64.     SETUP_ANI_ON   = /<(?:SETUP_ACTION|setup action|setup)>/i
  65.     SETUP_ANI_OFF  = /<\/(?:SETUP_ACTION|setup action|setup)>/i
  66.     WHOLE_ANI_ON   = /<(?:WHOLE_ACTION|whole action|whole)>/i
  67.     WHOLE_ANI_OFF  = /<\/(?:WHOLE_ACTION|whole action|whole)>/i
  68.     TARGET_ANI_ON  = /<(?:TARGET_ACTION|target action|target)>/i
  69.     TARGET_ANI_OFF = /<\/(?:TARGET_ACTION|target action|target)>/i
  70.     FOLLOW_ANI_ON  = /<(?:FOLLOW_ACTION|follow action|follow)>/i
  71.     FOLLOW_ANI_OFF = /<\/(?:FOLLOW_ACTION|follow action|follow)>/i
  72.     FINISH_ANI_ON  = /<(?:FINISH_ACTION|finish action|finish)>/i
  73.     FINISH_ANI_OFF = /<\/(?:FINISH_ACTION|finish action|finish)>/i
  74.    
  75.     GUARD_ANI_ON   = /<(?:GUARD_ACTION|guard action|guard)>/i
  76.     GUARD_ANI_OFF  = /<\/(?:GUARD_ACTION|guard action|guard)>/i
  77.    
  78.     ANI_TYPE_S6 = /[ ]*(.*):[ ](.*),[ ](.*),[ ](.*),[ ](.*),[ ](.*),[ ](.*)/i
  79.     ANI_TYPE_S5 = /[ ]*(.*):[ ](.*),[ ](.*),[ ](.*),[ ](.*),[ ](.*)/i
  80.     ANI_TYPE_S4 = /[ ]*(.*):[ ](.*),[ ](.*),[ ](.*),[ ](.*)/i
  81.     ANI_TYPE_S3 = /[ ]*(.*):[ ](.*),[ ](.*),[ ](.*)/i
  82.     ANI_TYPE_S2 = /[ ]*(.*):[ ](.*),[ ](.*)/i
  83.     ANI_TYPE_S1 = /[ ]*(.*):[ ](.*)/i
  84.     ANI_TYPE_S0 = /[ ]*(.*)/i
  85.    
  86.   end # ANI
  87.   module BASEITEM
  88.    
  89.     HIT_RATE   = /<(?:HIT_RATE|hit rate|hit):[ ]*(\d+)([%%])>/i
  90.    
  91.     PTB_BONUS      = /<(?:PTB_BONUS|ptb bonus):[ ]*([\+\-]\d+)>/i
  92.     PTB_MAX_CANCEL = /<(?:PTB_MAX_CANCEL|ptb max cancel):[ ]*([\+\-]\d+)>/i
  93.     PTB_MAX_REGAIN = /<(?:PTB_MAX_REGAIN|ptb max regain):[ ]*([\+\-]\d+)>/i
  94.    
  95.     ATB_CHANGE_SET = /<(?:ATB_CHANGE|atb change):[ ]*([\+\-]\d+)>/i
  96.     ATB_CHANGE_PER = /<(?:ATB_CHANGE|atb change):[ ]*([\+\-]\d+)([%%])>/i
  97.     ATB_RESET      = /<(?:ATB_RESET|atb reset):[ ]*(\d+)([%%])>/i
  98.     ATB_RESET_PLUS = /<(?:ATB_RESET|atb reset):[ ]*([\+\-]\d+)([%%])>/i
  99.    
  100.     CTB_CHANGE_SET = /<(?:CTB_CHANGE|ctb change):[ ]*([\+\-]\d+)>/i
  101.     CTB_CHANGE_PER = /<(?:CTB_CHANGE|ctb change):[ ]*([\+\-]\d+)([%%])>/i
  102.     CTB_RESET      = /<(?:CTB_RESET|ctb reset):[ ]*(\d+)([%%])>/i
  103.     CTB_RESET_PLUS = /<(?:CTB_RESET|ctb reset):[ ]*([\+\-]\d+)([%%])>/i
  104.    
  105.     DAMAGE_FORMULA = /<(?:DAMAGE|dmg):[ ](.*)>/i
  106.     TRAITS         = /<(?:TRAIT|traits):[ ](.*)>/i
  107.    
  108.     SET_ELE_RK = /<(?:ELEMENT_RANK|element rank)[ ](.*):(.*)>/i
  109.     SET_STA_RK = /<(?:STATE_RANK|state rank)[ ](.*):(.*)>/i
  110.     ADD_ELE_RK = /<(?:ELEMENT_RANK|element rank)[ ](.*):[ ]([\+\-]\d+)>/i
  111.     ADD_STA_RK = /<(?:STATE_RANK|state rank)[ ](.*):[ ]([\+\-]\d+)>/i
  112.     REV_ELE_RK = /<(?:ELEMENT_MIRROR|element mirror):[ ](\d+(?:\s*,\s*\d+)*)>/i
  113.     REV_STA_RK = /<(?:STATE_MIRROR|state mirror):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  114.    
  115.     SET_ELE_RT = /<(?:ELEMENT_RATE|element rate)[ ](.*):[ ]([\+\-]\d+)([%%])>/i
  116.     SET_STA_RT = /<(?:STATE_RATE|state rate)[ ](.*):[ ]([\+\-]\d+)([%%])>/i
  117.     PER_ELE_RT = /<(?:ELEMENT_RATE|element rate)[ ](.*):[ ](\d+)([%%])>/i
  118.     PER_STA_RT = /<(?:STATE_RATE|state rate)[ ](.*):[ ](\d+)([%%])>/i
  119.    
  120.     ATK_ELE = /<(?:ATTACK_ELEMENT|attack element):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  121.     ATK_STA = /<(?:ATTACK_STATE|attack state):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  122.    
  123.   end # BASEITEM
  124.   module USABLEITEM
  125.    
  126.     SKILL_TYPE = /<(?:SKILL_TYPE|skill type):[ ](.*)>/i
  127.     ITEM_TYPE  = /<(?:ITEM_TYPE|item type):[ ](.*)>/i
  128.    
  129.     HIDE_IN_BATTLE = /<(?:HIDE_IN_BATTLE|hide in battle)>/i
  130.    
  131.     PTB_TURN_COST = /<(?:PTB_TURN_COST|ptb turn cost):[ ]*(\d+)>/i
  132.     PTB_TURN_GAIN = /<(?:PTB_TURN_GAIN|ptb turn gain):[ ]*(\d+)>/i
  133.     PTB_TURN_LOSS = /<(?:PTB_TURN_LOSS|ptb turn loss):[ ]*(\d+)>/i
  134.    
  135.     HIT_RATE   = /<(?:HIT_RATE|hit rate|hit):[ ]*(\d+)([%%])>/i
  136.     SPEED_RATE = /<(?:SPEED|initiative):[ ]([\+\-]\d+)>/i
  137.     STAT_F     = /<(.*)(?:_F| f):[ ]*(\d+)([%%])>/i
  138.     CRIT_RATE  = /<(?:CRITICAL|critical rate|crit rate):[ ]*(\d+)([%%])>/i
  139.     CAST_ANI   = /<(?:CAST_ANIMATION|cast animation|cast ani):[ ]*(\d+)>/i
  140.     SKILL_COST = /<(?:COST|skill cost):[ ](.*)>/i
  141.     COST_ICON  = /<(?:COST_ICON|cost icon):[ ](.*)>/i
  142.     RAGE_BOOST = /<(?:RAGE_BOOST|rage boost):[ ]([\+\-]\d+)>/i
  143.     TARG_RAGE  = /<(?:TARGET_RAGE|target rage):[ ]([\+\-]\d+)>/i
  144.     COOLDOWN   = /<(?:COOLDOWN|recharge):[ ](\d+)>/i
  145.     LIMITEDUSE = /<(?:LIMITED_USE|limited use|limit use):[ ](\d+)>/i
  146.     INSTANT    = /<(?:INSTANT|instant use|instant cast)>/i
  147.    
  148.     ELE_GROW = /<(?:ELEMENT_RATE|element rate)[ ](\d+):[ ]([\+\-]\d+)([%%])>/i
  149.     STA_GROW = /<(?:STATE_RATE|state rate)[ ](\d+):[ ]([\+\-]\d+)([%%])>/i
  150.    
  151.     REQUIREMENTS = /<(?:REQ|REQUIRE)[ ](.*)[ ](.*):[ ](\d+(?:\s*,\s*\d+)*)>/i
  152.    
  153.     CHARGES       = /<(?:CHARGES|charge|item charges):[ ]*(\d+)>/i
  154.     CHANGE_VAR    = /<(?:VARIABLE|var)[ ](\d+):[ ]*([\+\-]\d+)>/i
  155.     CHANGE_SWI    = /<(?:SWITCH|sw)[ ](\d+):[ ]*(.*)>/i
  156.     PHARMA_ONLY   = /<(?:PHARMACOLOGY_ONLY|pharmacology only)>/i
  157.     RESTRICT      = /<(?:RESTRICT|forbid)[ ](.*):[ ](\d+(?:\s*,\s*\d+)*)>/i
  158.     NULLIFY       = /<(?:nullify|no effect)[ ](.*):[ ](\d+(?:\s*,\s*\d+)*)>/i
  159.     UNIQUE_EFFECT = /<(.*)[ ]*(\d+)[ ]*(?:EFFECT|ability):[ ]*(\d+)>/i
  160.     PHARMA_EFFECT = /<(?:PHARMACOLOGY_EFFECT|pharmacology effect):[ ]*(\d+)>/i
  161.    
  162.     CUSTOM_BEFORE = /<(?:BSE|before effect):[ ](.*)>/i
  163.     CUSTOM_DURING = /<(?:DSE|during effect):[ ](.*)>/i
  164.     CUSTOM_AFTER  = /<(?:ASE|after effect):[ ](.*)>/i
  165.    
  166.     TARGETS    = /<(?:TARGET|targets):[ ](.*)>/i
  167.     AOE_IMAGE  = /<(?:AREA_IMAGE|area image|aoe image):[ ](.*)>/i
  168.     AOE_BLEND  = /<(?:AREA_BLEND|area blend|aoe blend):[ ](\d+)>/i
  169.     AOE_HEIGHT = /<(?:AREA_HEIGHT|area height|aoe height):[ ](\d+)([%%])>/i
  170.     AOE_RADIUS = /<(?:AREA_RADIUS|area radius|aoe radius):[ ](\d+)>/i
  171.     RECT_IMAGE = /<(?:RECT_IMAGE|rect image):[ ](.*)>/i
  172.     RECT_BLEND = /<(?:RECT_BLEND|rect blend):[ ](\d+)>/i
  173.     RECT_COL   = /<(?:AREA_COLUMN|area column|aoe column):[ ](\d+)>/i
  174.     RECT_ROW   = /<(?:AREA_ROW|area row|aoe row):[ ](\d+)>/i
  175.     RECT_MAP   = /<(?:AREA_MAP|area map|aoe map)>/i
  176.    
  177.     TARGET_TEXT_ON  = /<(?:TARGET_TEXT|target text|target name)>/i
  178.     TARGET_TEXT_OFF = /<\/(?:TARGET_TEXT|target text|target name)>/i
  179.    
  180.   end # USABLEITEM
  181.   module ENEMY
  182.    
  183.     ATTACK_ANIMATION = /<(?:ATTACK_ANIMATION|attack animation):[ ]*(\d+)>/i
  184.     ENEMY_ICON       = /<(?:ENEMY_ICON|enemy icon):[ ]*(\d+)>/i
  185.     ENEMY_ICON_HUE   = /<(?:ENEMY_ICON_HUE|enemy icon hue):[ ]*([\+\-]\d+)>/i
  186.     EMPTYVIEW_MIRROR = /<(?:EMPTYVIEW_MIRROR|emptyview mirror)>/i
  187.     FRONTVIEW_MIRROR = /<(?:FRONTVIEW_MIRROR|frontview mirror)>/i
  188.     SIDEVIEW_MIRROR  = /<(?:SIDEVIEW_MIRROR|sideview mirror)>/i
  189.     ANGLEVIEW_MIRROR = /<(?:ANGLEVIEW_MIRROR|angleview mirror)>/i
  190.     EMPTYVIEW_ZOOM   = /<(?:EMPTYVIEW_ZOOM|emptyview zoom):[ ]*(\d+)([%%])>/i
  191.     FRONTVIEW_ZOOM   = /<(?:FRONTVIEW_ZOOM|frontview zoom):[ ]*(\d+)([%%])>/i
  192.     SIDEVIEW_ZOOM    = /<(?:SIDEVIEW_ZOOM|sideview zoom):[ ]*(\d+)([%%])>/i
  193.     ANGLEVIEW_ZOOM   = /<(?:ANGLEVIEW_ZOOM|angleview zoom):[ ]*(\d+)([%%])>/i
  194.    
  195.     PTB_TURNS      = /<(?:PTB_TURNS|ptb turns):[ ]*(\d+)>/i
  196.     PTB_MAX_CANCEL = /<(?:PTB_MAX_CANCEL|ptb max cancel):[ ]*(\d+)>/i
  197.     PTB_MAX_REGAIN = /<(?:PTB_MAX_REGAIN|ptb max regain):[ ]*(\d+)>/i
  198.    
  199.     ATB_CHANGE_SET = /<(?:ATB_CHANGE|atb change):[ ]*([\+\-]\d+)>/i
  200.     ATB_CHANGE_PER = /<(?:ATB_CHANGE|atb change):[ ]*([\+\-]\d+)([%%])>/i
  201.     ATB_RESET      = /<(?:ATB_RESET|atb reset):[ ]*(\d+)([%%])>/i
  202.    
  203.     CTB_CHANGE_SET = /<(?:CTB_CHANGE|ctb change):[ ]*([\+\-]\d+)>/i
  204.     CTB_CHANGE_PER = /<(?:CTB_CHANGE|ctb change):[ ]*([\+\-]\d+)([%%])>/i
  205.     CTB_RESET      = /<(?:CTB_RESET|ctb reset):[ ]*(\d+)([%%])>/i
  206.    
  207.     DAMAGE_FORMULA = /<(?:DAMAGE|dmg):[ ](.*)>/i
  208.     STATE_ANI_ZOOM = /<(?:STATE_ZOOM|state zoom):[ ]*(\d+)([%%])>/i
  209.     TRAITS         = /<(?:TRAIT|traits):[ ](.*)>/i
  210.    
  211.     GAUGE_WIDTH = /<(?:GAUGE_WIDTH|gauge width):[ ]*(\d+)>/i
  212.     HIDE_GAUGE  = /<(.*)[ ](.*)[ ](?:GAUGE|gauge)>/i
  213.     HP_GAUGE    = /<(?:HP_GAUGE|hp gauge):[ ]*(\d+),[ ]*(\d+)>/i
  214.     MP_GAUGE    = /<(?:MP_GAUGE|mp gauge):[ ]*(\d+),[ ]*(\d+)>/i
  215.    
  216.     ATK_ELE = /<(?:ATTACK_ELEMENT|attack element):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  217.     ATK_STA = /<(?:ATTACK_STATE|attack state):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  218.    
  219.     ANIMATION_STANCE = /<(.*)[ ](?:STANCE|stand):[ ]*(\d+)>/i
  220.     STANCE_HUE = /<(?:STANCE_HUE|stance hue|animation hue):[ ]*([\+\-]\d+)>/i
  221.    
  222.     UNMOVING = /<(?:UNMOVING|unmovable|cannot move|do not move)>/i
  223.    
  224.     CHARSET0 = /<(?:CS|charset):[ ](.*)>/i
  225.     CHARSET1 = /<(?:CS|charset):[ ](.*),[ ]*(\d+)>/i
  226.     WEAPON   = /<(?:WEAPONS|weapon):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  227.     SHIELD   = /<(?:SHIELD|shield):[ ]*(\d+)>/i
  228.    
  229.   end # ENEMY
  230.   module STATE
  231.    
  232.     POPUP_ADD = /<(?:POPUP_ADD_RULE|popup add rule|popup add):[ ](.*)>/i
  233.     POPUP_REM = /<(?:POPUP_REM_RULE|popup rem rule|popup rem):[ ](.*)>/i
  234.     POPUP_DUR = /<(?:POPUP_DUR_RULE|popup dur rule|popup dur):[ ](.*)>/i
  235.    
  236.     HIDE_ADD  = /<(?:POPUP_HIDE_ADD|popup hide add|hide add)>/i
  237.     HIDE_REM  = /<(?:POPUP_HIDE_REM|popup hide rem|hide rem)>/i
  238.     HIDE_DUR  = /<(?:POPUP_HIDE_DUR|popup hide dur|hide dur)>/i
  239.    
  240.     STATE_TYPE = /<(?:STATE_TYPE|state type):[ ](.*)>/i
  241.     STATE_ANI  = /<(?:STATE_ANIMATION|state animation|state ani):[ ]*(\d+)>/i
  242.    
  243.     DMG_TAKEN = /<(.*)[ ](?:extra|taken):[ ]*(\d+)([%%])>/i
  244.     DMG_BONUS = /<(.*)[ ](?:given|bonus):[ ]*(\d+)([%%])>/i
  245.     DMG_WALL  = /<(.*)[ ](?:WALL|guard|boost|raise):[ ]*([\+\-]\d+)>/i
  246.    
  247.     SLIP_SET = /<\s*(HP|MP)?\s*[ ]\s*(DEGEN|REGEN)?\s*:[ ]*(\d+)>/i
  248.     SLIP_PER = /<\s*(HP|MP)?\s*[ ]\s*(DEGEN|REGEN)?\s*:[ ]*(\d+)([%%])>/i
  249.    
  250.     PTB_BONUS      = /<(?:PTB_BONUS|ptb bonus):[ ]*([\+\-]\d+)>/i
  251.     PTB_MAX_CANCEL = /<(?:PTB_MAX_CANCEL|ptb max cancel):[ ]*([\+\-]\d+)>/i
  252.     PTB_MAX_REGAIN = /<(?:PTB_MAX_REGAIN|ptb max regain):[ ]*([\+\-]\d+)>/i
  253.    
  254.     ATB_RESET_PLUS = /<(?:ATB_RESET|atb reset):[ ]*([\+\-]\d+)([%%])>/i
  255.     CTB_RESET_PLUS = /<(?:CTB_RESET|ctb reset):[ ]*([\+\-]\d+)([%%])>/i
  256.    
  257.     RAGE_BOOST_PER = /<(?:RAGE_BOOST|rage boost):[ ]*(\d+)([%%])>/i
  258.     RAGE_BOOST_SET = /<(?:RAGE_BOOST|rage boost):[ ]*([\+\-]\d+)>/i
  259.    
  260.     RESTRICT_SKILL = /<(?:RESTRICT_SKILLS|restrict skills):[ ](.*)>/i
  261.     RESTRICT_ITEM  = /<(?:RESTRICT_ITEMS|restrict items):[ ](.*)>/i
  262.    
  263.     MAX_STACK = /<(?:MAX_STACK|max stack|stack):[ ]*(\d+)>/i
  264.     TRAITS    = /<(?:TRAIT|traits):[ ](.*)>/i
  265.     COST_PER  = /<(.*)[ ](?:COST|costs):[ ]*(\d+)([%%])>/i
  266.     COST_SET  = /<(.*)[ ](?:COST|costs):[ ]*([\+\-]\d+)>/i
  267.     STAT_PER  = /<(.*):[ ]*(\d+)([%%])>/i
  268.     STAT_SET  = /<(.*):[ ]*([\+\-]\d+)>/i
  269.    
  270.     CUSTOM_APPLY = /<(?:APPLY_EFFECT|apply effect):[ ](.*)>/i
  271.     CUSTOM_ERASE = /<(?:ERASE_EFFECT|erase effect):[ ](.*)>/i
  272.     CUSTOM_LEAVE = /<(?:LEAVE_EFFECT|leave effect):[ ](.*)>/i
  273.     CUSTOM_REACT = /<(?:REACT_EFFECT|react effect):[ ](.*)>/i
  274.     CUSTOM_SHOCK = /<(?:SHOCK_EFFECT|shock effect):[ ](.*)>/i
  275.     CUSTOM_BEGIN = /<(?:BEGIN_EFFECT|begin effect):[ ](.*)>/i
  276.     CUSTOM_WHILE = /<(?:WHILE_EFFECT|while effect):[ ](.*)>/i
  277.     CUSTOM_CLOSE = /<(?:CLOSE_EFFECT|close effect):[ ](.*)>/i
  278.    
  279.     SET_ELE_RK = /<(?:ELEMENT_RANK|element rank)[ ](.*):(.*)>/i
  280.     SET_STA_RK = /<(?:STATE_RANK|state rank)[ ](.*):(.*)>/i
  281.     ADD_ELE_RK = /<(?:ELEMENT_RANK|element rank)[ ](.*):[ ]([\+\-]\d+)>/i
  282.     ADD_STA_RK = /<(?:STATE_RANK|state rank)[ ](.*):[ ]([\+\-]\d+)>/i
  283.     REV_ELE_RK = /<(?:ELEMENT_MIRROR|element mirror):[ ](\d+(?:\s*,\s*\d+)*)>/i
  284.     REV_STA_RK = /<(?:STATE_MIRROR|state mirror):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  285.    
  286.     SET_ELE_RT = /<(?:ELEMENT_RATE|element rate)[ ](.*):[ ]([\+\-]\d+)([%%])>/i
  287.     SET_STA_RT = /<(?:STATE_RATE|state rate)[ ](.*):[ ]([\+\-]\d+)([%%])>/i
  288.     PER_ELE_RT = /<(?:ELEMENT_RATE|element rate)[ ](.*):[ ](\d+)([%%])>/i
  289.     PER_STA_RT = /<(?:STATE_RATE|state rate)[ ](.*):[ ](\d+)([%%])>/i
  290.    
  291.     ATK_ELE = /<(?:ATTACK_ELEMENT|attack element):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  292.     ATK_STA = /<(?:ATTACK_STATE|attack state):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  293.     WEAPON_ICON = /<(?:WEAPON_ICON|weapon icon):[ ]*(\d+)>/i
  294.     ATTACK_ANI = /<(?:ATTACK_ANIMATION|attack animation|attack ani):[ ]*(\d+)>/i
  295.    
  296.   end # STATE
  297.   end # REGEXP
  298.   module BATTLE_ENGINE
  299.     module_function
  300.     #--------------------------------------------------------------------------
  301.     # convert_integer_array
  302.     #--------------------------------------------------------------------------
  303.     def convert_integer_array(array)
  304.       result = []
  305.       array.each { |i|
  306.         case i
  307.         when Range; result |= i.to_a
  308.         when Integer; result |= [i]
  309.         end }
  310.       return result
  311.     end
  312.    
  313.     #--------------------------------------------------------------------------
  314.     # converted_contants
  315.     #--------------------------------------------------------------------------
  316.     ALLY_ELEMENTS = convert_integer_array(ALLY_ELEMENTS)
  317.     ALLY_STATES   = convert_integer_array(ALLY_STATES)
  318.    
  319.   end # BATTLE_ENGINE
  320. end # YEM
  321.  
  322. #===============================================================================
  323. # module Vocab
  324. #===============================================================================
  325.  
  326. module Vocab
  327.  
  328.   #--------------------------------------------------------------------------
  329.   # self.hit
  330.   #--------------------------------------------------------------------------
  331.   def self.hit; return YEM::BATTLE_ENGINE::STAT_VOCAB[:hit]; end
  332.  
  333.   #--------------------------------------------------------------------------
  334.   # self.eva
  335.   #--------------------------------------------------------------------------
  336.   def self.eva; return YEM::BATTLE_ENGINE::STAT_VOCAB[:eva]; end
  337.  
  338.   #--------------------------------------------------------------------------
  339.   # self.cri
  340.   #--------------------------------------------------------------------------
  341.   def self.cri; return YEM::BATTLE_ENGINE::STAT_VOCAB[:cri]; end
  342.    
  343.   #--------------------------------------------------------------------------
  344.   # self.odds
  345.   #--------------------------------------------------------------------------
  346.   def self.odds; return YEM::BATTLE_ENGINE::STAT_VOCAB[:odds]; end
  347.  
  348.   #--------------------------------------------------------------------------
  349.   # self.rage
  350.   #--------------------------------------------------------------------------
  351.   def self.rage; return YEM::BATTLE_ENGINE::SKILL_SETTINGS[:rage_vocab]; end
  352.    
  353.   #--------------------------------------------------------------------------
  354.   # self.rage_a
  355.   #--------------------------------------------------------------------------
  356.   def self.rage_a; return YEM::BATTLE_ENGINE::SKILL_SETTINGS[:rage_abbrev]; end
  357.  
  358. end # Vocab
  359.  
  360. #===============================================================================
  361. # RPG::BGM
  362. #===============================================================================
  363.  
  364. module RPG
  365. class BGM < AudioFile
  366.  
  367.   #--------------------------------------------------------------------------
  368.   # overwrite method: play
  369.   #--------------------------------------------------------------------------
  370.   def play
  371.     if @name.empty?
  372.       Audio.bgm_stop
  373.       @@last = BGM.new
  374.     else
  375.       vol = @volume
  376.       if $game_variables != nil
  377.         options = YEM::BATTLE_ENGINE::OPTIONS
  378.         vol = vol * $game_variables[options[:bgm_variable]] / 100
  379.         vol = [[vol, 0].max, 100].min
  380.         vol = 0 if $game_switches[options[:bgm_mute_sw]]
  381.       end
  382.       Audio.bgm_play("Audio/BGM/" + @name, vol, @pitch)
  383.       @@last = self
  384.     end
  385.   end
  386.  
  387. end # BGM
  388. class ME < AudioFile
  389.  
  390.   #--------------------------------------------------------------------------
  391.   # overwrite method: play
  392.   #--------------------------------------------------------------------------
  393.   def play
  394.     if @name.empty?
  395.       Audio.me_stop
  396.     else
  397.       vol = @volume
  398.       if $game_variables != nil
  399.         options = YEM::BATTLE_ENGINE::OPTIONS
  400.         vol = vol * $game_variables[options[:bgm_variable]] / 100
  401.         vol = [[vol, 0].max, 100].min
  402.         vol = 0 if $game_switches[options[:bgm_mute_sw]]
  403.       end
  404.       Audio.me_play("Audio/ME/" + @name, vol, @pitch)
  405.     end
  406.   end
  407.  
  408. end # ME
  409. class BGS < AudioFile
  410.  
  411.   #--------------------------------------------------------------------------
  412.   # overwrite method: play
  413.   #--------------------------------------------------------------------------
  414.   def play
  415.     if @name.empty?
  416.       Audio.bgs_stop
  417.       @@last = BGS.new
  418.     else
  419.       vol = @volume
  420.       if $game_variables != nil
  421.         options = YEM::BATTLE_ENGINE::OPTIONS
  422.         vol = vol * $game_variables[options[:bgs_variable]] / 100
  423.         vol = [[vol, 0].max, 100].min
  424.         vol = 0 if $game_switches[options[:bgs_mute_sw]]
  425.       end
  426.       Audio.bgs_play("Audio/BGS/" + @name, vol, @pitch)
  427.       @@last = self
  428.     end
  429.   end
  430.  
  431. end # BGS
  432. class SE < AudioFile
  433.  
  434.   #--------------------------------------------------------------------------
  435.   # overwrite method: play
  436.   #--------------------------------------------------------------------------
  437.   def play
  438.     unless @name.empty?
  439.       vol = @volume
  440.       if $game_variables != nil
  441.         options = YEM::BATTLE_ENGINE::OPTIONS
  442.         vol = vol * $game_variables[options[:sfx_variable]] / 100
  443.         vol = [[vol, 0].max, 100].min
  444.         vol = 0 if $game_switches[options[:sfx_mute_sw]]
  445.       end
  446.       Audio.se_play("Audio/SE/" + @name, vol, @pitch)
  447.     end
  448.   end
  449.  
  450. end # SE
  451. end # RPG
  452.  
  453. #===============================================================================
  454. # RPG::BaseItem
  455. #===============================================================================
  456.  
  457. class RPG::BaseItem
  458.  
  459.   #--------------------------------------------------------------------------
  460.   # public instance variables
  461.   #--------------------------------------------------------------------------
  462.   attr_accessor :attack_vocab
  463.   attr_accessor :guard_vocab
  464.   attr_accessor :setup_action_list
  465.   attr_accessor :whole_action_list
  466.   attr_accessor :target_action_list
  467.   attr_accessor :follow_action_list
  468.   attr_accessor :finish_action_list
  469.   attr_accessor :guard_action_list
  470.   attr_accessor :ptb_bonus
  471.   attr_accessor :ptb_max_cancel
  472.   attr_accessor :ptb_max_regain
  473.   attr_accessor :atb_change_set
  474.   attr_accessor :atb_change_per
  475.   attr_accessor :atb_reset
  476.   attr_accessor :atb_reset_plus
  477.   attr_accessor :ctb_change_set
  478.   attr_accessor :ctb_change_per
  479.   attr_accessor :ctb_reset
  480.   attr_accessor :ctb_reset_plus
  481.   attr_accessor :damage_formula
  482.   attr_accessor :traits
  483.   attr_accessor :element_rank
  484.   attr_accessor :state_rank
  485.   attr_accessor :attack_element
  486.   attr_accessor :attack_state
  487.   attr_accessor :element_rank_add
  488.   attr_accessor :state_rank_add
  489.   attr_accessor :element_rank_rev
  490.   attr_accessor :state_rank_rev
  491.   attr_accessor :element_rate_set
  492.   attr_accessor :state_rate_set
  493.   attr_accessor :element_rate_per
  494.   attr_accessor :state_rate_per
  495.  
  496.   #--------------------------------------------------------------------------
  497.   # new method: create_default_baseitem_values
  498.   #--------------------------------------------------------------------------
  499.   def create_default_baseitem_values
  500.     @attack_vocab = Vocab.attack
  501.     @guard_vocab = Vocab.guard
  502.     @ptb_bonus = 0
  503.     @ptb_max_cancel = 0
  504.     @ptb_max_regain = 0
  505.     @atb_change_set = 0
  506.     @atb_change_per = 0
  507.     @atb_reset = 0
  508.     @atb_reset_plus = 0
  509.     @ctb_change_set = 0
  510.     @ctb_change_per = 0
  511.     @ctb_reset = 0
  512.     @ctb_reset_plus = 0
  513.     @damage_formula = []
  514.     #---
  515.     @traits = []
  516.     if self.is_a?(RPG::Weapon)
  517.       @traits.push(:fast_attack) if self.fast_attack
  518.       @traits.push(:dual_attack) if self.dual_attack
  519.     end
  520.     if self.is_a?(RPG::Armor)
  521.       @traits.push(:prevent_critical) if self.prevent_critical
  522.       @traits.push(:half_mp_cost) if self.half_mp_cost
  523.       @traits.push(:double_exp_gain) if self.double_exp_gain
  524.       @traits.push(:auto_hp_recover) if self.auto_hp_recover
  525.     end
  526.     #---
  527.     @element_rank = {}
  528.     @state_rank = {}
  529.     @attack_element = []
  530.     @attack_state = []
  531.     @element_rank_add = {}
  532.     @state_rank_add = {}
  533.     @element_rank_rev = []
  534.     @state_rank_rev = []
  535.     @element_rate_set = {}
  536.     @state_rate_set = {}
  537.     @element_rate_per = {}
  538.     @state_rate_per = {}
  539.   end
  540.  
  541.   #--------------------------------------------------------------------------
  542.   # new method: finish_default_baseitem_values
  543.   #--------------------------------------------------------------------------
  544.   def finish_default_baseitem_values
  545.     #---
  546.     if @damage_formula == []
  547.       if self.is_a?(RPG::Weapon)
  548.         @damage_formula = ["ATK WEAPON"]
  549.       elsif self.is_a?(RPG::UsableItem)
  550.         @damage_formula = ["NORMAL"]
  551.       end
  552.     end
  553.     #---
  554.   end
  555.  
  556.   #--------------------------------------------------------------------------
  557.   # common cache: yem_cache_baseitem_bem
  558.   #--------------------------------------------------------------------------
  559.   def yem_cache_baseitem_bem
  560.     return if @cached_baseitem_bem; @cached_baseitem_bem = true
  561.     create_default_baseitem_values
  562.     self.note.split(/[\r\n]+/).each { |line|
  563.       case line
  564.       #---
  565.       when YEM::REGEXP::BASEITEM::HIT_RATE
  566.         @hit = $1.to_i
  567.       #---
  568.       when YEM::REGEXP::BASEITEM::PTB_BONUS
  569.         @ptb_bonus = $1.to_i
  570.       when YEM::REGEXP::BASEITEM::PTB_MAX_CANCEL
  571.         @ptb_max_cancel = $1.to_i
  572.       when YEM::REGEXP::BASEITEM::PTB_MAX_REGAIN
  573.         @ptb_max_regain = $1.to_i
  574.       #---
  575.       when YEM::REGEXP::BASEITEM::ATB_CHANGE_SET
  576.         @atb_change_set = $1.to_i
  577.       when YEM::REGEXP::BASEITEM::ATB_CHANGE_PER
  578.         @atb_change_per = $1.to_i
  579.       when YEM::REGEXP::BASEITEM::ATB_RESET
  580.         @atb_reset = $1.to_i
  581.       when YEM::REGEXP::BASEITEM::ATB_RESET_PLUS
  582.         @atb_reset_plus = $1.to_i
  583.       #---
  584.       when YEM::REGEXP::BASEITEM::CTB_CHANGE_SET
  585.         @ctb_change_set = $1.to_i
  586.       when YEM::REGEXP::BASEITEM::CTB_CHANGE_PER
  587.         @ctb_change_per = $1.to_i
  588.       when YEM::REGEXP::BASEITEM::CTB_RESET
  589.         @ctb_reset = $1.to_i
  590.       when YEM::REGEXP::BASEITEM::CTB_RESET_PLUS
  591.         @ctb_reset_plus = $1.to_i
  592.       #---
  593.       when YEM::REGEXP::BASEITEM::DAMAGE_FORMULA
  594.         @damage_formula.push($1.to_s.upcase)
  595.       #---
  596.       when YEM::REGEXP::BASEITEM::TRAITS
  597.         case $1.upcase
  598.         when "SUPER GUARD", "SUPER_GUARD", "SUPERGUARD"
  599.           @traits.push(:super_guard)
  600.         when "PHARMACOLOGY", "PHARMA", "ITEM BOOST", "ITEM_BOOST"
  601.           @traits.push(:pharmacology)
  602.         when "FAST ATTACK", "FAST_ATTACK", "FASTATTACK"
  603.           @traits.push(:fast_attack)
  604.         when "DUAL ATTACK", "DUALATTACK", "DUAL_ATTACK"
  605.           @traits.push(:dual_attack)
  606.         when "PREVENT_CRITICAL", "PREVENT CRITICAL", "PREVENT CRI"
  607.           @traits.push(:prevent_critical)
  608.         when "HALF MP COST", "HALF_MP_COST", "HALF MP", "HALF_MP", "HALFMP"
  609.           @traits.push(:half_mp_cost)
  610.         when "DOUBLE EXP GAIN", "DOUBLE_EXP_GAIN", "DOUBLE EXP", "DOUBLE_EXP"
  611.           @traits.push(:double_exp_gain)
  612.         when "AUTO_HP_RECOVER", "AUTO HP RECOVER", "AUTO HP", "AUTO_HP"
  613.           @traits.push(:auto_hp_recover)
  614.         when "ANTI HP REGEN", "ANTI_HP_REGEN"
  615.           @traits.push(:anti_hp_regen)
  616.         when "ANTI HP DEGEN", "ANTI_HP_DEGEN"
  617.           @traits.push(:anti_hp_degen)
  618.         when "ANTI MP REGEN", "ANTI_MP_REGEN"
  619.           @traits.push(:anti_mp_regen)
  620.         when "ANTI MP DEGEN", "ANTI_MP_DEGEN"
  621.           @traits.push(:anti_mp_degen)
  622.         else; next
  623.         end
  624.       #---
  625.       when YEM::REGEXP::BASEITEM::SET_ELE_RT
  626.         next if self.is_a?(RPG::Item)
  627.         if $1.to_i != 0
  628.           @element_rate_set[$1.to_i] = $2.to_i
  629.         elsif $1.upcase == "ALL"
  630.           for i in 1..($data_system.elements.size - 1)
  631.             @element_rate_set[i] = $2.to_i
  632.           end
  633.         end
  634.       #---
  635.       when YEM::REGEXP::BASEITEM::PER_ELE_RT
  636.         next if self.is_a?(RPG::Item)
  637.         if $1.to_i != 0
  638.           @element_rate_per[$1.to_i] = $2.to_i
  639.         elsif $1.upcase == "ALL"
  640.           for i in 1..($data_system.elements.size - 1)
  641.             @element_rate_per[i] = $2.to_i
  642.           end
  643.         end
  644.       #---
  645.       when YEM::REGEXP::BASEITEM::ADD_ELE_RK
  646.         if $1.to_i != 0
  647.           @element_rank_add[$1.to_i] = $2.to_i
  648.         elsif $1.upcase == "ALL"
  649.           for i in 1..($data_system.elements.size - 1)
  650.             @element_rank_add[i] = $2.to_i
  651.           end
  652.         end
  653.       #---
  654.       when YEM::REGEXP::BASEITEM::SET_ELE_RK
  655.         case $2.upcase
  656.         when "S", "Z"; value = 0
  657.         when "A"; value = 1
  658.         when "B"; value = 2
  659.         when "C"; value = 3
  660.         when "D"; value = 4
  661.         when "E"; value = 5
  662.         when "F"; value = 6
  663.         else; next
  664.         end
  665.         if $1.to_i != 0
  666.           @element_rank[$1.to_i] = value
  667.         elsif $1.upcase == "ALL"
  668.           for i in 1..($data_system.elements.size - 1)
  669.             @element_rank[i] = value
  670.           end
  671.         end
  672.       #---
  673.       when YEM::REGEXP::BASEITEM::SET_STA_RT
  674.         if $1.to_i != 0
  675.           @state_rate_set[$1.to_i] = $2.to_i
  676.         elsif $1.upcase == "ALL"
  677.           for i in 1..($data_states.size - 1)
  678.             @state_rate_set[i] = $2.to_i
  679.           end
  680.         end
  681.       #---
  682.       when YEM::REGEXP::BASEITEM::PER_STA_RT
  683.         if $1.to_i != 0
  684.           @state_rate_per[$1.to_i] = $2.to_i
  685.         elsif $1.upcase == "ALL"
  686.           for i in 1..($data_states.size - 1)
  687.             @state_rate_per[i] = $2.to_i
  688.           end
  689.         end
  690.       #---
  691.       when YEM::REGEXP::BASEITEM::ADD_STA_RK
  692.         if $1.to_i != 0
  693.           @state_rank_add[$1.to_i] = $2.to_i
  694.         elsif $1.upcase == "ALL"
  695.           for i in 1..($data_states.size - 1)
  696.             @state_rank_add[i] = $2.to_i
  697.           end
  698.         end
  699.       #---
  700.       when YEM::REGEXP::BASEITEM::SET_STA_RK
  701.         case $2.upcase
  702.         when "S", "Z"; value = 0
  703.         when "A"; value = 1
  704.         when "B"; value = 2
  705.         when "C"; value = 3
  706.         when "D"; value = 4
  707.         when "E"; value = 5
  708.         when "F"; value = 6
  709.         else; next
  710.         end
  711.         if $1.to_i != 0
  712.           @state_rank[$1.to_i] = value
  713.         elsif $1.upcase == "ALL"
  714.           for i in 1..($data_states.size - 1)
  715.             @state_rank[i] = value
  716.           end
  717.         end
  718.       #---
  719.       when YEM::REGEXP::BASEITEM::ATK_ELE
  720.         $1.scan(/\d+/).each { |num|
  721.         @attack_element.push(num.to_i) if num.to_i > 0 }
  722.       #---
  723.       when YEM::REGEXP::BASEITEM::ATK_STA
  724.         $1.scan(/\d+/).each { |num|
  725.         @attack_state.push(num.to_i) if num.to_i > 0 }
  726.       #---
  727.       end
  728.     } # self.note.split
  729.     finish_default_baseitem_values
  730.    
  731.     #--- Melody REGEXP ---
  732.     create_default_action_codes
  733.     self.note.split(/[\r\n]+/).each { |line|
  734.       case line
  735.       #---
  736.       when YEM::REGEXP::ANI::ACTION_COPY
  737.         case $1.upcase
  738.         when "I", "ITEM"
  739.           obj = $data_items[$2.to_i]
  740.           next if obj == nil
  741.           obj.yem_cache_baseitem_bem
  742.         when "S", "SKILL"
  743.           obj = $data_skills[$2.to_i]
  744.           next if obj == nil
  745.           obj.yem_cache_baseitem_bem
  746.         when "W", "WEAPON"
  747.           obj = $data_weapons[$2.to_i]
  748.           next if obj == nil
  749.           obj.yem_cache_baseitem_bem
  750.         when "A", "ARMOR", "ARMOUR"
  751.           obj = $data_armors[$2.to_i]
  752.           next if obj == nil
  753.           obj.yem_cache_baseitem_bem
  754.         when "E", "ENEMY"
  755.           obj = $data_enemies[$2.to_i]
  756.           next if obj == nil
  757.           obj.yem_cache_enemy_bem
  758.         else; next
  759.         end
  760.         @setup_action_list = obj.setup_action_list.clone
  761.         @whole_action_list = obj.whole_action_list.clone
  762.         @target_action_list = obj.target_action_list.clone
  763.         @follow_action_list = obj.follow_action_list.clone
  764.         @finish_action_list = obj.finish_action_list.clone
  765.         @guard_action_list = obj.guard_action_list.clone
  766.       #---
  767.       when YEM::REGEXP::ANI::SETUP_ANI_ON
  768.         @melody_line = true
  769.         @setup_action_list = []
  770.         @setup_action_flag = true
  771.       when YEM::REGEXP::ANI::SETUP_ANI_OFF
  772.         @melody_line = false
  773.         @setup_action_flag = false
  774.       when YEM::REGEXP::ANI::WHOLE_ANI_ON
  775.         @melody_line = true
  776.         @whole_action_list = []
  777.         @whole_action_flag = true
  778.       when YEM::REGEXP::ANI::WHOLE_ANI_OFF
  779.         @melody_line = false
  780.         @whole_action_flag = false
  781.       when YEM::REGEXP::ANI::TARGET_ANI_ON
  782.         @melody_line = true
  783.         @target_action_list = []
  784.         @target_action_flag = true
  785.       when YEM::REGEXP::ANI::TARGET_ANI_OFF
  786.         @melody_line = false
  787.         @target_action_flag = false
  788.       when YEM::REGEXP::ANI::FOLLOW_ANI_ON
  789.         @melody_line = true
  790.         @follow_action_list = []
  791.         @follow_action_flag = true
  792.       when YEM::REGEXP::ANI::FOLLOW_ANI_OFF
  793.         @melody_line = false
  794.         @follow_action_flag = false
  795.       when YEM::REGEXP::ANI::FINISH_ANI_ON
  796.         @melody_line = true
  797.         @finish_action_list = []
  798.         @finish_action_flag = true
  799.       when YEM::REGEXP::ANI::FINISH_ANI_OFF
  800.         @melody_line = false
  801.         @finish_action_flag = false
  802.       #---
  803.       when YEM::REGEXP::ANI::GUARD_ANI_ON
  804.         @melody_line = true
  805.         @guard_action_list = []
  806.         @guard_action_flag = true
  807.       when YEM::REGEXP::ANI::GUARD_ANI_OFF
  808.         @melody_line = false
  809.         @guard_action_flag = false
  810.       #---
  811.       else
  812.         next unless @melody_line
  813.         case line
  814.         when YEM::REGEXP::ANI::ANI_TYPE_S6
  815.           type  = $1
  816.           value = [$2, $3, $4, $5, $6, $7]
  817.         when YEM::REGEXP::ANI::ANI_TYPE_S5
  818.           type  = $1
  819.           value = [$2, $3, $4, $5, $6]
  820.         when YEM::REGEXP::ANI::ANI_TYPE_S4
  821.           type  = $1
  822.           value = [$2, $3, $4, $5]
  823.         when YEM::REGEXP::ANI::ANI_TYPE_S3
  824.           type  = $1
  825.           value = [$2, $3, $4]
  826.         when YEM::REGEXP::ANI::ANI_TYPE_S2
  827.           type  = $1
  828.           value = [$2, $3]
  829.         when YEM::REGEXP::ANI::ANI_TYPE_S1
  830.           type  = $1
  831.           value = [$2]
  832.         when YEM::REGEXP::ANI::ANI_TYPE_S0
  833.           type  = $1
  834.           value = [nil]
  835.         else; next
  836.         end
  837.         case type.upcase
  838.         when /IF[ ](.*)/i, /UNLESS[ ](.*)/i, /ELSIF[ ](.*)/i
  839.           ignore_upcase = true
  840.         when "MESSAGE", "SCRIPT", "SCRIPT CALL", "POPUP"
  841.           type = type.upcase
  842.           ignore_upcase = true
  843.         when /CHANGE[ ](?:VARIABLE|VAR)[ ](.*)/i
  844.         else
  845.           type = type.upcase
  846.           ignore_upcase = false
  847.         end
  848.         for i in 0..(value.size-1)
  849.           next if value[i] == nil
  850.           next if ignore_upcase
  851.           next if value[i] == /IF[ ](.*)/i
  852.           next if value[i] == /UNLESS[ ](.*)/i
  853.           value[i] = value[i].to_s.upcase
  854.         end
  855.         array = [type, value]
  856.         if @setup_action_flag
  857.           @setup_action_list[@setup_action_list.size] = array
  858.         elsif @whole_action_flag
  859.           @whole_action_list[@whole_action_list.size] = array
  860.         elsif @target_action_flag
  861.           @target_action_list[@target_action_list.size] = array
  862.         elsif @follow_action_flag
  863.           @follow_action_list[@follow_action_list.size] = array
  864.         elsif @finish_action_flag
  865.           @finish_action_list[@finish_action_list.size] = array
  866.         elsif @guard_action_flag
  867.           @guard_action_list[@guard_action_list.size] = array
  868.         end
  869.       end
  870.     } # self.note.split
  871.     #--- Melody REGEXP ---
  872.   end # yem_cache_baseitem_bem
  873.  
  874.   #--------------------------------------------------------------------------
  875.   # new method: create_default_action_codes
  876.   #--------------------------------------------------------------------------
  877.   def create_default_action_codes
  878.     @setup_action_list = []; @finish_action_list = []
  879.     @whole_action_list = []; @target_action_list = []
  880.     @guard_action_list = []; @follow_action_list = []
  881.     if self.is_a?(RPG::Weapon)
  882.       @setup_action_list = YEM::DEFAULT_ACTIONS::ATTACK_SETUP
  883.       @whole_action_list = YEM::DEFAULT_ACTIONS::ATTACK_WHOLE
  884.       @target_action_list = YEM::DEFAULT_ACTIONS::ATTACK_TARGET
  885.       @follow_action_list = YEM::DEFAULT_ACTIONS::ATTACK_FOLLOW
  886.       @finish_action_list = YEM::DEFAULT_ACTIONS::ATTACK_FINISH
  887.       return
  888.     end
  889.     if self.is_a?(RPG::Skill) and !self.physical_attack
  890.       @setup_action_list = YEM::DEFAULT_ACTIONS::MAGIC_SETUP
  891.       @whole_action_list = YEM::DEFAULT_ACTIONS::MAGIC_WHOLE
  892.       @target_action_list = YEM::DEFAULT_ACTIONS::MAGIC_TARGET
  893.       @follow_action_list = YEM::DEFAULT_ACTIONS::MAGIC_FOLLOW
  894.       @finish_action_list = YEM::DEFAULT_ACTIONS::MAGIC_FINISH
  895.       return
  896.     elsif self.is_a?(RPG::Skill) and self.physical_attack
  897.       @setup_action_list = YEM::DEFAULT_ACTIONS::PHYSICAL_SETUP
  898.       @whole_action_list = YEM::DEFAULT_ACTIONS::PHYSICAL_WHOLE
  899.       @target_action_list = YEM::DEFAULT_ACTIONS::PHYSICAL_TARGET
  900.       @follow_action_list = YEM::DEFAULT_ACTIONS::PHYSICAL_FOLLOW
  901.       @finish_action_list = YEM::DEFAULT_ACTIONS::PHYSICAL_FINISH
  902.       return
  903.     end
  904.     if self.is_a?(RPG::Item)
  905.       @setup_action_list = YEM::DEFAULT_ACTIONS::ITEM_SETUP
  906.       @whole_action_list = YEM::DEFAULT_ACTIONS::ITEM_WHOLE
  907.       @target_action_list = YEM::DEFAULT_ACTIONS::ITEM_TARGET
  908.       @follow_action_list = YEM::DEFAULT_ACTIONS::ITEM_FOLLOW
  909.       @finish_action_list = YEM::DEFAULT_ACTIONS::ITEM_FINISH
  910.       return
  911.     end
  912.     if self.is_a?(RPG::Armor) and self.kind == 0
  913.       @guard_action_list = YEM::DEFAULT_ACTIONS::GUARD_ACTIONS
  914.     end
  915.   end
  916.  
  917. end # RPG::BaseItem
  918.  
  919. #===============================================================================
  920. # RPG::UsableItem
  921. #===============================================================================
  922.  
  923. class RPG::UsableItem < RPG::BaseItem
  924.  
  925.   #--------------------------------------------------------------------------
  926.   # public instance variables
  927.   #--------------------------------------------------------------------------
  928.   attr_accessor :skill_type
  929.   attr_accessor :item_type
  930.   attr_accessor :hide_in_battle
  931.   attr_accessor :ptb_turn_cost
  932.   attr_accessor :ptb_turn_gain
  933.   attr_accessor :ptb_turn_loss
  934.   attr_accessor :random_targets
  935.   attr_accessor :def_f
  936.   attr_accessor :res_f
  937.   attr_accessor :dex_f
  938.   attr_accessor :agi_f
  939.   attr_accessor :cri_rate
  940.   attr_accessor :cast_ani
  941.   attr_accessor :skill_cost
  942.   attr_accessor :cost_icon
  943.   attr_accessor :rage_skill
  944.   attr_accessor :rage_boost
  945.   attr_accessor :rage_target
  946.   attr_accessor :cooldown
  947.   attr_accessor :limited_use
  948.   attr_accessor :instant
  949.   attr_accessor :requirements
  950.   attr_accessor :element_growth
  951.   attr_accessor :state_growth
  952.   attr_accessor :lunatic_effects
  953.   attr_accessor :charges
  954.   attr_accessor :change_variable
  955.   attr_accessor :change_switch
  956.   attr_accessor :pharmacology_only
  957.   attr_accessor :restrict
  958.   attr_accessor :targets
  959.   attr_accessor :target_text
  960.   attr_accessor :aoe_animation
  961.   attr_accessor :aoe_image
  962.   attr_accessor :aoe_blend
  963.   attr_accessor :aoe_height
  964.   attr_accessor :aoe_radius
  965.   attr_accessor :rect_image
  966.   attr_accessor :rect_blend
  967.   attr_accessor :rect_type
  968.   attr_accessor :rect_value
  969.   attr_accessor :for_opponent
  970.   attr_accessor :for_friend
  971.   attr_accessor :nullify
  972.   attr_accessor :unique_effect
  973.  
  974.   #--------------------------------------------------------------------------
  975.   # new method: create_default_usableitem_values
  976.   #--------------------------------------------------------------------------
  977.   def create_default_usableitem_values
  978.     @name.gsub!(/\[.*\]/) { "" }
  979.     #---
  980.     @skill_type = ["ALL"] if self.is_a?(RPG::Skill)
  981.     @item_type = ["ALL"] if self.is_a?(RPG::Item)
  982.     @hide_in_battle = false
  983.     #---
  984.     @ptb_turn_cost = 1
  985.     @ptb_turn_gain = 0
  986.     @ptb_turn_loss = 0
  987.     #---
  988.     @def_f = 0
  989.     @res_f = 0
  990.     @dex_f = 0
  991.     @agi_f = 0
  992.     #--
  993.     @cast_ani = 0
  994.     if self.is_a?(RPG::Skill) and !self.physical_attack
  995.       @cast_ani = YEM::BATTLE_ENGINE::DEFAULT_CAST_ANIMATION
  996.     end
  997.     @skill_cost = ""
  998.     @skill_cost = self.mp_cost.to_s + " MP" if self.is_a?(RPG::Skill)
  999.     @rage_skill = false
  1000.     @rage_boost = 0
  1001.     if self.is_a?(RPG::Skill) and self.physical_attack
  1002.       @rage_boost = YEM::BATTLE_ENGINE::SKILL_SETTINGS[:physical_rage_gain]
  1003.     elsif self.is_a?(RPG::Skill)
  1004.       @rage_boost = YEM::BATTLE_ENGINE::SKILL_SETTINGS[:magical_rage_gain]
  1005.     end
  1006.     @rage_target = 0
  1007.     @cooldown = 0
  1008.     @limited_use = 0
  1009.     @instant = false
  1010.     @requirements = {}
  1011.     @lunatic_effects = {}
  1012.     @element_growth = {}
  1013.     @state_growth = {}
  1014.     #---
  1015.     @charges = 1
  1016.     @change_variable = {}
  1017.     @change_switch = {}
  1018.     @pharmacology_only = false
  1019.     @restrict = {:actors => [], :classes => []}
  1020.     @nullify = {:actors => [], :classes => [], :enemies => []}
  1021.     @unique_effect = {:pharm => nil, :actor => {}, :class => {}}
  1022.     #---
  1023.     @targets = []
  1024.     @aoe_animation = false
  1025.     @aoe_image = YEM::BATTLE_ENGINE::TARGET_SETTINGS[:circ_name]
  1026.     @aoe_blend = YEM::BATTLE_ENGINE::TARGET_SETTINGS[:circ_blend]
  1027.     @aoe_height = YEM::BATTLE_ENGINE::TARGET_SETTINGS[:circ_height]
  1028.     @aoe_radius = 0
  1029.     @rect_image = YEM::BATTLE_ENGINE::TARGET_SETTINGS[:rect_name]
  1030.     @rect_blend = YEM::BATTLE_ENGINE::TARGET_SETTINGS[:rect_blend]
  1031.     @rect_type = 0
  1032.     @rect_value = 0
  1033.   end
  1034.  
  1035.   #--------------------------------------------------------------------------
  1036.   # common cache: finish_default_usableitem_values
  1037.   #--------------------------------------------------------------------------
  1038.   def finish_default_usableitem_values
  1039.     @lunatic_effects[:before] = [] if @lunatic_effects[:before] == nil
  1040.     @lunatic_effects[:before].push("COMMON BEFORE")
  1041.     @lunatic_effects[:during] = [] if @lunatic_effects[:during] == nil
  1042.     @lunatic_effects[:before].push("COMMON DURING")
  1043.     @lunatic_effects[:after] = [] if @lunatic_effects[:after] == nil
  1044.     @lunatic_effects[:before].push("COMMON AFTER")
  1045.     #---
  1046.     if @aoe_animation and $data_animations[self.animation_id] != nil
  1047.       animation = $data_animations[self.animation_id]
  1048.       @aoe_animation = false if animation.position == 3
  1049.     end
  1050.     #---
  1051.     if @targets == []
  1052.       string = "NONE"
  1053.       if self.for_opponent?
  1054.         @for_opponent = true
  1055.         @for_friend = false
  1056.         if self.for_random?
  1057.           if self.for_one?
  1058.             string = "1 RANDOM FOE"
  1059.             @random_targets = 1
  1060.           elsif self.for_two?
  1061.             string = "2 RANDOM FOES"
  1062.             @random_targets = 2
  1063.           else
  1064.             string = "3 RANDOM FOES"
  1065.             @random_targets = 3
  1066.           end
  1067.         elsif self.dual?
  1068.           string = "2 HITS FOE"
  1069.         elsif self.for_one?
  1070.           string = "1 HIT FOE"
  1071.         else
  1072.           string = "ALL FOES X1"
  1073.         end
  1074.       elsif self.for_user?
  1075.         @for_friend = true
  1076.         @for_opponent = false
  1077.         string = "USER ONLY"
  1078.       elsif self.for_dead_friend?
  1079.         @for_friend = true
  1080.         @for_opponent = false
  1081.         if self.for_one?
  1082.           string = "1 HIT DEAD ALLY"
  1083.         else
  1084.           string = "ALL DEAD ALLIES X1"
  1085.         end
  1086.       elsif self.for_friend?
  1087.         @for_friend = true
  1088.         @for_opponent = false
  1089.         if self.for_one?
  1090.           string = "1 HIT ALLY"
  1091.         else
  1092.           string = "ALL ALLIES X1"
  1093.         end
  1094.       elsif self.for_none?
  1095.         @for_friend = false
  1096.         @for_opponent = false
  1097.       end
  1098.       @targets.push(string)
  1099.     end # @targets == []
  1100.     @random_targets = 0 if @random_targets == nil
  1101.     @targets.push("COMMON TARGET")
  1102.     remodify_scope
  1103.   end
  1104.  
  1105.   #--------------------------------------------------------------------------
  1106.   # common cache: yem_cache_usableitem_bem
  1107.   #--------------------------------------------------------------------------
  1108.   def yem_cache_usableitem_bem
  1109.     return if @cached_usableitem_bem; @cached_usableitem_bem = true
  1110.     create_default_usableitem_values
  1111.     self.note.split(/[\r\n]+/).each { |line|
  1112.       case line
  1113.       #---
  1114.       when YEM::REGEXP::USABLEITEM::SKILL_TYPE
  1115.         next unless self.is_a?(RPG::Skill)
  1116.         @skill_type.push($1.upcase)
  1117.       when YEM::REGEXP::USABLEITEM::ITEM_TYPE
  1118.         next unless self.is_a?(RPG::Item)
  1119.         @item_type.push($1.upcase)
  1120.       when YEM::REGEXP::USABLEITEM::HIDE_IN_BATTLE
  1121.         @hide_in_battle = true
  1122.       #---
  1123.       when YEM::REGEXP::USABLEITEM::PTB_TURN_COST
  1124.         next if @instant
  1125.         @ptb_turn_cost = $1.to_i
  1126.       when YEM::REGEXP::USABLEITEM::PTB_TURN_GAIN
  1127.         @ptb_turn_gain = $1.to_i
  1128.       when YEM::REGEXP::USABLEITEM::PTB_TURN_LOSS
  1129.         @ptb_turn_loss = $1.to_i
  1130.       #---
  1131.       when YEM::REGEXP::USABLEITEM::ELE_GROW
  1132.         @element_growth[$1.to_i] = $2.to_i
  1133.       when YEM::REGEXP::USABLEITEM::STA_GROW
  1134.         @state_growth[$1.to_i] = $2.to_i
  1135.       #---
  1136.       when YEM::REGEXP::USABLEITEM::HIT_RATE
  1137.         next unless self.is_a?(RPG::Skill)
  1138.         @hit = $1.to_i
  1139.       when YEM::REGEXP::USABLEITEM::SPEED_RATE
  1140.         @speed = $1.to_i
  1141.       when YEM::REGEXP::USABLEITEM::STAT_F
  1142.         value = $2.to_i
  1143.         case $1.upcase
  1144.         when "ATK"; @atk_f = value
  1145.         when "DEF"; @def_f = value
  1146.         when "SPI"; @spi_f = value
  1147.         when "RES"; @res_f = value
  1148.         when "DEX"; @dex_f = value
  1149.         when "AGI"; @agi_f = value
  1150.         end
  1151.       #---
  1152.       when YEM::REGEXP::USABLEITEM::CRIT_RATE
  1153.         @cri_rate = $1.to_i
  1154.       #---
  1155.       when YEM::REGEXP::USABLEITEM::CAST_ANI
  1156.         @cast_ani = $1.to_i
  1157.       #---
  1158.       when YEM::REGEXP::USABLEITEM::SKILL_COST
  1159.         @skill_cost = $1.to_s.upcase
  1160.         case $1.upcase
  1161.         when /(\d+)[ ]RAGE/i
  1162.           @rage_skill = true
  1163.         end
  1164.       #---
  1165.       when YEM::REGEXP::USABLEITEM::COST_ICON
  1166.         @cost_icon = $1.to_i
  1167.       #---
  1168.       when YEM::REGEXP::USABLEITEM::RAGE_BOOST
  1169.         @rage_boost = $1.to_i
  1170.       when YEM::REGEXP::USABLEITEM::TARG_RAGE
  1171.         @target_rage = $1.to_i
  1172.       #---
  1173.       when YEM::REGEXP::USABLEITEM::COOLDOWN
  1174.         @cooldown = $1.to_i
  1175.       when YEM::REGEXP::USABLEITEM::LIMITEDUSE
  1176.         @limited_use = $1.to_i
  1177.       #---
  1178.       when YEM::REGEXP::USABLEITEM::INSTANT
  1179.         @instant = true
  1180.         @speed = 10 ** 10
  1181.         @ptb_turn_cost = 0
  1182.         @atb_reset = 100
  1183.         @ctb_reset = 100
  1184.       #---
  1185.       when YEM::REGEXP::USABLEITEM::REQUIREMENTS
  1186.         case $2.upcase
  1187.         when "STATE", "STATES"
  1188.           case $1.upcase
  1189.           when "ANY"; type = :any_state
  1190.           when "ALL"; type = :all_state
  1191.           end
  1192.         when "ELEMENT", "ELEMENTS", "ELE"
  1193.           case $1.upcase
  1194.           when "ANY"; type = :any_ele
  1195.           when "ALL"; type = :all_ele
  1196.           end
  1197.         when "SWITCH", "SWITCHES"
  1198.           case $1.upcase
  1199.           when "ANY"; type = :any_switch
  1200.           when "ALL"; type = :all_switch
  1201.           end
  1202.         else; next
  1203.         end
  1204.         @requirements[type] = [] if @requirements[type] == nil
  1205.         $3.scan(/\d+/).each { |num|
  1206.         @requirements[type].push(num.to_i) if num.to_i > 0 }
  1207.       #---
  1208.       when YEM::REGEXP::USABLEITEM::CUSTOM_BEFORE
  1209.         string = $1.upcase; type = :before
  1210.         @lunatic_effects[type] = [] if @lunatic_effects[type] == nil
  1211.         @lunatic_effects[type].push(string)
  1212.       when YEM::REGEXP::USABLEITEM::CUSTOM_DURING
  1213.         string = $1.upcase; type = :during
  1214.         @lunatic_effects[type] = [] if @lunatic_effects[type] == nil
  1215.         @lunatic_effects[type].push(string)
  1216.       when YEM::REGEXP::USABLEITEM::CUSTOM_AFTER
  1217.         string = $1.upcase; type = :after
  1218.         @lunatic_effects[type] = [] if @lunatic_effects[type] == nil
  1219.         @lunatic_effects[type].push(string)
  1220.       #---
  1221.       when YEM::REGEXP::USABLEITEM::CHARGES
  1222.         next unless self.is_a?(RPG::Item)
  1223.         @charges = $1.to_i
  1224.       when YEM::REGEXP::USABLEITEM::CHANGE_VAR
  1225.         next unless self.is_a?(RPG::Item)
  1226.         @change_variable[$1.to_i] = $2.to_i
  1227.       when YEM::REGEXP::USABLEITEM::CHANGE_SWI
  1228.         next unless self.is_a?(RPG::Item)
  1229.         case $2.upcase
  1230.         when "TRUE", "ON";   value = :true
  1231.         when "FALSE", "OFF"; value = :false
  1232.         when "TOGGLE";       value = :toggle
  1233.         else; next
  1234.         end
  1235.         @change_switch[$1.to_i] = value
  1236.       #---
  1237.       when YEM::REGEXP::USABLEITEM::PHARMA_ONLY
  1238.         @pharmacology_only = true
  1239.       when YEM::REGEXP::USABLEITEM::RESTRICT
  1240.         case $1.upcase
  1241.         when "ACTOR", "ACTORS";  type = :actors
  1242.         when "CLASS", "CLASSES"; type = :classes
  1243.         else; next
  1244.         end
  1245.         $2.scan(/\d+/).each { |num|
  1246.         @restrict[type].push(num.to_i) if num.to_i > 0 }
  1247.       when YEM::REGEXP::USABLEITEM::NULLIFY
  1248.         case $1.upcase
  1249.         when "ACTOR", "ACTORS";  type = :actors
  1250.         when "CLASS", "CLASSES"; type = :classes
  1251.         when "ENEMY", "ENEMIES"; type = :enemies
  1252.         else; next
  1253.         end
  1254.         $2.scan(/\d+/).each { |num|
  1255.         @nullify[type].push(num.to_i) if num.to_i > 0 }
  1256.       #---
  1257.       when YEM::REGEXP::USABLEITEM::PHARMA_EFFECT
  1258.         @unique_effect[:pharm] = $1.to_i
  1259.       when YEM::REGEXP::USABLEITEM::UNIQUE_EFFECT
  1260.         next unless self.is_a?(RPG::Item)
  1261.         case $1.upcase
  1262.         when "ACTOR"; type = :actor
  1263.         when "CLASS"; type = :class
  1264.         else; next
  1265.         end
  1266.         @unique_effect[type][$2.to_i] = $3.to_i
  1267.       #---
  1268.       when YEM::REGEXP::USABLEITEM::TARGETS
  1269.         string = $1.to_s.upcase
  1270.         @targets.push(string)
  1271.         case string
  1272.         when /DEAD/i
  1273.           @for_dead = true
  1274.         end
  1275.         #---
  1276.         case string
  1277.         when "EVERYBODY"
  1278.           @for_opponent = true
  1279.           @for_friend = true
  1280.         when "ALL BUT USER"
  1281.           @for_friend = true
  1282.           @for_opponent = false
  1283.         when /(\d+)[ ](?:RANDOM|RAND)[ ](.*)/i
  1284.           @random_targets = $1.to_i
  1285.           case $2.upcase
  1286.           when /(?:FOE|FOES)/i
  1287.             @for_opponent = true
  1288.             @for_friend = false
  1289.           when /(?:ALLY|ALLIES)/i
  1290.             @for_friend = true
  1291.             @for_opponent = false
  1292.           end
  1293.         when /(?:FOE|FOES)/i
  1294.           @for_opponent = true
  1295.           @for_friend = false
  1296.         when /(?:ALLY|ALLIES|USER|USERS)/i
  1297.           @for_friend = true
  1298.           @for_opponent = false
  1299.         end
  1300.       #---
  1301.       when YEM::REGEXP::USABLEITEM::AOE_IMAGE
  1302.         @aoe_image = $1.to_s
  1303.       when YEM::REGEXP::USABLEITEM::AOE_BLEND
  1304.         @aoe_blend = $1.to_i
  1305.       when YEM::REGEXP::USABLEITEM::AOE_HEIGHT
  1306.         @aoe_height = $1.to_i / 100.0
  1307.       when YEM::REGEXP::USABLEITEM::AOE_RADIUS
  1308.         @aoe_radius = [$1.to_i, 3].max
  1309.         @aoe_animation = true
  1310.       when YEM::REGEXP::USABLEITEM::RECT_IMAGE
  1311.         @rect_image = $1.to_s
  1312.       when YEM::REGEXP::USABLEITEM::RECT_BLEND
  1313.         @rect_blend = $1.to_i
  1314.       when YEM::REGEXP::USABLEITEM::RECT_COL
  1315.         @rect_type = 1
  1316.         @rect_value = [$1.to_i, 3].max
  1317.         @aoe_animation = true
  1318.       when YEM::REGEXP::USABLEITEM::RECT_ROW
  1319.         @rect_type = 2
  1320.         @rect_value = [$1.to_i, 3].max
  1321.         @aoe_animation = true
  1322.       when YEM::REGEXP::USABLEITEM::RECT_MAP
  1323.         @rect_type = 3
  1324.       #---
  1325.       when YEM::REGEXP::USABLEITEM::TARGET_TEXT_ON
  1326.         @target_text_enabled = true
  1327.         @target_text = ""
  1328.       when YEM::REGEXP::USABLEITEM::TARGET_TEXT_OFF
  1329.         @target_text_enabled = false
  1330.       #---
  1331.       else
  1332.         if @target_text_enabled
  1333.           @target_text += line
  1334.         end
  1335.       end
  1336.     } # self.note.split
  1337.     finish_default_usableitem_values
  1338.   end # yem_cache_usableitem_bem
  1339.  
  1340.   #--------------------------------------------------------------------------
  1341.   # overwrite method: for_opponent?
  1342.   #--------------------------------------------------------------------------
  1343.   def for_opponent?
  1344.     return @for_opponent if @for_opponent != nil
  1345.     return [1, 2, 3, 4, 5, 6].include?(@scope)
  1346.   end
  1347.    
  1348.   #--------------------------------------------------------------------------
  1349.   # overwrite method: for_friend?
  1350.   #--------------------------------------------------------------------------
  1351.   def for_friend?
  1352.     return @for_friend if @for_friend != nil
  1353.     return [7, 8, 9, 10, 11].include?(@scope)
  1354.   end
  1355.  
  1356.   #--------------------------------------------------------------------------
  1357.   # overwrite method: for_random?
  1358.   #--------------------------------------------------------------------------
  1359.   def for_random?
  1360.     return @random_targets > 0 if @random_targets != nil
  1361.     return [4, 5, 6].include?(@scope)
  1362.   end
  1363.  
  1364.   #--------------------------------------------------------------------------
  1365.   # new method: for_none?
  1366.   #--------------------------------------------------------------------------
  1367.   def for_none?; return [0].include?(@scope); end
  1368.  
  1369.   #--------------------------------------------------------------------------
  1370.   # overwrite method: for_dead_friend?
  1371.   #--------------------------------------------------------------------------
  1372.   def for_dead_friend?
  1373.     return true if @for_dead
  1374.     return [9, 10].include?(@scope)
  1375.   end
  1376.    
  1377.   #--------------------------------------------------------------------------
  1378.   # new method: can_critical?
  1379.   #--------------------------------------------------------------------------
  1380.   def can_critical?
  1381.     return true if @cri_rate != nil and @cri_rate > 0
  1382.     return YEM::BATTLE_ENGINE::CRITICAL_SKILLS[:healing] if @base_damage < 0
  1383.     return YEM::BATTLE_ENGINE::CRITICAL_SKILLS[:physical] if @physical_attack
  1384.     return YEM::BATTLE_ENGINE::CRITICAL_SKILLS[:magical]
  1385.   end
  1386.  
  1387.   #--------------------------------------------------------------------------
  1388.   # new method: remodify_scope
  1389.   #--------------------------------------------------------------------------
  1390.   def remodify_scope
  1391.     for target in targets
  1392.       #---
  1393.       case target.upcase
  1394.       when "USER ONLY"
  1395.         @scope = 11 # User Only
  1396.       when "ALL BUT USER", "EVERYBODY"
  1397.         @scope = 2 # All Enemies
  1398.       #---
  1399.       when /(?:PICK|TARGET)[ ](\d+)[ ](?:RANDOM|RAND)[ ](.*)/i,
  1400.       /(\d+)[ ](?:HIT|HITS)[ ](.*)/i
  1401.         case $2.upcase
  1402.         when "DEAD FOE", "DEAD FOES", "FOE", "FOES"
  1403.           @scope = 1 # One Enemy
  1404.         when "DEAD ALLIES", "DEAD ALLIES", "ALLY", "ALLIES"
  1405.           @scope = 7 # One Ally
  1406.         else; next
  1407.         end
  1408.       #---
  1409.       when /(?:ALL|EVERY)[ ](.*)[ ]X(\d+)/i
  1410.         case $1.upcase
  1411.         when "DEAD FOE", "DEAD FOES", "FOE", "FOES"
  1412.           @scope = 2 # All Enemies
  1413.         when "DEAD ALLIES", "DEAD ALLIES", "ALLY", "ALLIES"
  1414.           @scope = 8 # All Allies
  1415.         else; next
  1416.         end
  1417.       #---
  1418.       when /(?:RANDOM|RAND)/i
  1419.         @scope = 4
  1420.       #---
  1421.       else; next
  1422.       end
  1423.       break
  1424.     end
  1425.   end
  1426.  
  1427. end # RPG::UsableItem
  1428.  
  1429. #===============================================================================
  1430. # RPG::Enemy
  1431. #===============================================================================
  1432.  
  1433. class RPG::Enemy
  1434.  
  1435.   #--------------------------------------------------------------------------
  1436.   # public instance variables
  1437.   #--------------------------------------------------------------------------
  1438.   attr_accessor :attack_animation
  1439.   attr_accessor :enemy_icon
  1440.   attr_accessor :enemy_icon_hue
  1441.   attr_accessor :view_mirror
  1442.   attr_accessor :view_zoom
  1443.   attr_accessor :setup_action_list
  1444.   attr_accessor :whole_action_list
  1445.   attr_accessor :target_action_list
  1446.   attr_accessor :follow_action_list
  1447.   attr_accessor :finish_action_list
  1448.   attr_accessor :guard_action_list
  1449.   attr_accessor :ptb_turns
  1450.   attr_accessor :ptb_max_cancel
  1451.   attr_accessor :ptb_max_regain
  1452.   attr_accessor :atb_change_set
  1453.   attr_accessor :atb_change_per
  1454.   attr_accessor :atb_reset
  1455.   attr_accessor :ctb_change_set
  1456.   attr_accessor :ctb_change_per
  1457.   attr_accessor :ctb_reset
  1458.   attr_accessor :damage_formula
  1459.   attr_accessor :state_zoom
  1460.   attr_accessor :traits
  1461.   attr_accessor :target_offset_x
  1462.   attr_accessor :target_offset_y
  1463.   attr_accessor :quick_gauge
  1464.   attr_accessor :attack_element
  1465.   attr_accessor :attack_state
  1466.   attr_accessor :animation_stance
  1467.   attr_accessor :animation_hue
  1468.   attr_accessor :unmoving
  1469.   attr_accessor :character_name
  1470.   attr_accessor :character_index
  1471.   attr_accessor :weapons
  1472.   attr_accessor :shield
  1473.  
  1474.   #--------------------------------------------------------------------------
  1475.   # new method: create_default_enemy_values
  1476.   #--------------------------------------------------------------------------
  1477.   def create_default_enemy_values
  1478.     @attack_animation = YEM::BATTLE_ENGINE::DEFAULT_ENEMY_ATTACK
  1479.     @enemy_icon = YEM::BATTLE_ENGINE::DEFAULT_ENEMY_ICON
  1480.     @enemy_icon_hue = 0
  1481.     @view_mirror ={
  1482.       :empty => false,
  1483.       :front => false,
  1484.       :side => false,
  1485.       :angle => false, }
  1486.     @view_zoom ={
  1487.       :empty => 1.0,
  1488.       :front => 1.0,
  1489.       :side => 1.0,
  1490.       :angle => 1.0 }
  1491.     @state_zoom = 100
  1492.     @ptb_turns = YEM::BATTLE_ENGINE::PTB_RULES[:provided_turns]
  1493.     @ptb_max_cancel = YEM::BATTLE_ENGINE::PTB_RULES[:max_actor_cancel]
  1494.     @ptb_max_regain = YEM::BATTLE_ENGINE::PTB_RULES[:max_actor_regain]
  1495.     @atb_change_set = 0
  1496.     @atb_change_per = 0
  1497.     @atb_reset = 0
  1498.     @ctb_change_set = 0
  1499.     @ctb_change_per = 0
  1500.     @ctb_reset = 0
  1501.     @damage_formula = []
  1502.     @target_offset_x = YEM::BATTLE_ENGINE::TARGET_SETTINGS[:target_off_x]
  1503.     @target_offset_y = YEM::BATTLE_ENGINE::TARGET_SETTINGS[:target_off_y]
  1504.     #---
  1505.     @quick_gauge ={
  1506.       :width     => YEM::BATTLE_ENGINE::QUICK_QUERY_SETTINGS[:width] + 32,
  1507.       :states    => YEM::BATTLE_ENGINE::QUICK_QUERY_SETTINGS[:states],
  1508.       :show_hp   => YEM::BATTLE_ENGINE::QUICK_QUERY_SETTINGS[:show_hp],
  1509.       :hp_gauge1 => YEM::BATTLE_ENGINE::QUICK_QUERY_SETTINGS[:hp_gauge1],
  1510.       :hp_gauge2 => YEM::BATTLE_ENGINE::QUICK_QUERY_SETTINGS[:hp_gauge2],
  1511.       :show_mp   => YEM::BATTLE_ENGINE::QUICK_QUERY_SETTINGS[:show_mp],
  1512.       :mp_gauge1 => YEM::BATTLE_ENGINE::QUICK_QUERY_SETTINGS[:mp_gauge1],
  1513.       :mp_gauge2 => YEM::BATTLE_ENGINE::QUICK_QUERY_SETTINGS[:mp_gauge2],
  1514.     } # End Quick Gauge
  1515.     #---
  1516.     @attack_element = []
  1517.     @attack_state = []
  1518.     #---
  1519.     @animation_stance = {}
  1520.     @animation_hue = 0
  1521.     @unmoving = false
  1522.     #---
  1523.     @character_name = ""
  1524.     @character_index = 0
  1525.     @weapons = []
  1526.     @shield = nil
  1527.   end
  1528.  
  1529.   #--------------------------------------------------------------------------
  1530.   # new method: finish_default_enemy_values
  1531.   #--------------------------------------------------------------------------
  1532.   def finish_default_enemy_values
  1533.     @damage_formula = ["ATK WEAPON"] if @damage_formula == []
  1534.     if @animation_stance.include?("IDLE")
  1535.       @animation_stance["PIYORI"] = @animation_stance["CRITICAL"] if
  1536.         @animation_stance.include?("CRITICAL")
  1537.       @animation_stance["PIYORI"] = @animation_stance["IDLE"] unless
  1538.         @animation_stance.include?("PIYORI")
  1539.       @animation_stance["STASIS"] = @animation_stance["IDLE"] unless
  1540.         @animation_stance.include?("STASIS")
  1541.     end
  1542.   end
  1543.  
  1544.   #--------------------------------------------------------------------------
  1545.   # common cache: yem_cache_enemy_bem
  1546.   #--------------------------------------------------------------------------
  1547.   def yem_cache_enemy_bem
  1548.     return if @cached_enemy_bem; @cached_enemy_bem = true
  1549.     create_default_enemy_values
  1550.     self.note.split(/[\r\n]+/).each { |line|
  1551.       case line
  1552.       #---
  1553.       when YEM::REGEXP::ENEMY::CHARSET1
  1554.         @character_name = $1.to_s
  1555.         @character_index = [$2.to_i, 7].min
  1556.         @battler_name = ""
  1557.       when YEM::REGEXP::ENEMY::CHARSET0
  1558.         @character_name = $1.to_s
  1559.         @character_name
  1560.         @battler_name = ""
  1561.       when YEM::REGEXP::ENEMY::WEAPON
  1562.         $1.scan(/\d+/).each { |num|
  1563.         @weapons.push($data_weapons[num.to_i]) if num.to_i > 0 }
  1564.       when YEM::REGEXP::ENEMY::SHIELD
  1565.         @shield = $data_armors[$1.to_i]
  1566.       #---
  1567.       when YEM::REGEXP::ENEMY::ATTACK_ANIMATION
  1568.         @attack_animation = $1.to_i
  1569.       #---
  1570.       when YEM::REGEXP::ENEMY::ANIMATION_STANCE
  1571.         @animation_stance[$1.upcase] = $2.to_i
  1572.       when YEM::REGEXP::ENEMY::STANCE_HUE
  1573.         @animation_hue = $1.to_i
  1574.       #---
  1575.       when YEM::REGEXP::ENEMY::ENEMY_ICON
  1576.         @enemy_icon = $1.to_i
  1577.       when YEM::REGEXP::ENEMY::ENEMY_ICON_HUE
  1578.         @enemy_icon_hue = $1.to_i
  1579.       when YEM::REGEXP::ENEMY::STATE_ANI_ZOOM
  1580.         @state_zoom = $1.to_i
  1581.       #---
  1582.       when YEM::REGEXP::ENEMY::EMPTYVIEW_MIRROR
  1583.         @view_mirror[:empty] = true
  1584.       when YEM::REGEXP::ENEMY::FRONTVIEW_MIRROR
  1585.         @view_mirror[:front] = true
  1586.       when YEM::REGEXP::ENEMY::SIDEVIEW_MIRROR
  1587.         @view_mirror[:side] = true
  1588.       when YEM::REGEXP::ENEMY::ANGLEVIEW_MIRROR
  1589.         @view_mirror[:angle] = true
  1590.       #---
  1591.       when YEM::REGEXP::ENEMY::EMPTYVIEW_ZOOM
  1592.         @view_zoom[:empty] = $1.to_i * 0.01
  1593.       when YEM::REGEXP::ENEMY::FRONTVIEW_ZOOM
  1594.         @view_zoom[:front] = $1.to_i * 0.01
  1595.       when YEM::REGEXP::ENEMY::SIDEVIEW_ZOOM
  1596.         @view_zoom[:side] = $1.to_i * 0.01
  1597.       when YEM::REGEXP::ENEMY::ANGLEVIEW_ZOOM
  1598.         @view_zoom[:angle] = $1.to_i * 0.01
  1599.       #---
  1600.       when YEM::REGEXP::ENEMY::PTB_TURNS
  1601.         @ptb_turns = $1.to_i
  1602.       when YEM::REGEXP::ENEMY::PTB_MAX_CANCEL
  1603.         @ptb_max_cancel = $1.to_i
  1604.       when YEM::REGEXP::ENEMY::PTB_MAX_REGAIN
  1605.         @ptb_max_regain = $1.to_i
  1606.       #---
  1607.       when YEM::REGEXP::ENEMY::ATB_CHANGE_SET
  1608.         @atb_change_set = $1.to_i
  1609.       when YEM::REGEXP::ENEMY::ATB_CHANGE_PER
  1610.         @atb_change_per = $1.to_i
  1611.       when YEM::REGEXP::ENEMY::ATB_RESET
  1612.         @atb_reset = $1.to_i
  1613.       #---
  1614.       when YEM::REGEXP::ENEMY::CTB_CHANGE_SET
  1615.         @ctb_change_set = $1.to_i
  1616.       when YEM::REGEXP::ENEMY::CTB_CHANGE_PER
  1617.         @ctb_change_per = $1.to_i
  1618.       when YEM::REGEXP::ENEMY::CTB_RESET
  1619.         @ctb_reset = $1.to_i
  1620.       #---
  1621.       when YEM::REGEXP::ENEMY::DAMAGE_FORMULA
  1622.         @damage_formula.push($1.to_s.upcase)
  1623.       #---
  1624.       when YEM::REGEXP::BASEITEM::TRAITS
  1625.         case $1.upcase
  1626.         when "SUPER GUARD", "SUPER_GUARD", "SUPERGUARD"
  1627.           @traits.push(:super_guard)
  1628.         when "FAST ATTACK", "FAST_ATTACK", "FASTATTACK"
  1629.           @traits.push(:fast_attack)
  1630.         when "DUAL ATTACK", "DUALATTACK", "DUAL_ATTACK"
  1631.           @traits.push(:dual_attack)
  1632.         when "PREVENT_CRITICAL", "PREVENT CRITICAL", "PREVENT CRI"
  1633.           @traits.push(:prevent_critical)
  1634.         when "HALF MP COST", "HALF_MP_COST", "HALF MP", "HALF_MP", "HALFMP"
  1635.           @traits.push(:half_mp_cost)
  1636.         when "ANTI HP REGEN", "ANTI_HP_REGEN"
  1637.           @traits.push(:anti_hp_regen)
  1638.         when "ANTI HP DEGEN", "ANTI_HP_DEGEN"
  1639.           @traits.push(:anti_hp_degen)
  1640.         when "ANTI MP REGEN", "ANTI_MP_REGEN"
  1641.           @traits.push(:anti_mp_regen)
  1642.         when "ANTI MP DEGEN", "ANTI_MP_DEGEN"
  1643.           @traits.push(:anti_mp_degen)
  1644.         else; next
  1645.         end
  1646.       #---
  1647.       when YEM::REGEXP::ENEMY::GAUGE_WIDTH
  1648.         @quick_gauge[:width] = $1.to_i + 32
  1649.       when YEM::REGEXP::ENEMY::HIDE_GAUGE
  1650.         case $1.upcase
  1651.         when "HIDE"
  1652.           setting = false
  1653.         when "SHOW"
  1654.           setting = true
  1655.         else; next
  1656.         end
  1657.         case $2.upcase
  1658.         when "STATE", "STATES"
  1659.           @quick_gauge[:states] = setting
  1660.         when "HP"
  1661.           @quick_gauge[:show_hp] = setting
  1662.         when "MP", "SP"
  1663.           @quick_gauge[:show_mp] = setting
  1664.         else; next
  1665.         end
  1666.       when YEM::REGEXP::ENEMY::HP_GAUGE
  1667.         @quick_gauge[:hp_gauge1] = $1.to_i
  1668.         @quick_gauge[:hp_gauge2] = $2.to_i
  1669.       when YEM::REGEXP::ENEMY::MP_GAUGE
  1670.         @quick_gauge[:mp_gauge1] = $1.to_i
  1671.         @quick_gauge[:mp_gauge2] = $2.to_i
  1672.       #---
  1673.       when YEM::REGEXP::ENEMY::ATK_ELE
  1674.         $1.scan(/\d+/).each { |num|
  1675.         @attack_element.push(num.to_i) if num.to_i > 0 }
  1676.       #---
  1677.       when YEM::REGEXP::ENEMY::ATK_STA
  1678.         $1.scan(/\d+/).each { |num|
  1679.         @attack_state.push(num.to_i) if num.to_i > 0 }
  1680.       when YEM::REGEXP::ENEMY::UNMOVING
  1681.         @unmoving = true
  1682.       #---
  1683.       end
  1684.     } # self.note.split
  1685.     finish_default_enemy_values
  1686.    
  1687.     #--- Melody REGEXP ---
  1688.     create_default_action_codes
  1689.     self.note.split(/[\r\n]+/).each { |line|
  1690.       case line
  1691.       #---
  1692.       when YEM::REGEXP::ANI::ACTION_COPY
  1693.         case $1.upcase
  1694.         when "I", "ITEM"
  1695.           obj = $data_items[$2.to_i]
  1696.           next if obj == nil
  1697.           obj.yem_cache_baseitem_bem
  1698.         when "S", "SKILL"
  1699.           obj = $data_skills[$2.to_i]
  1700.           next if obj == nil
  1701.           obj.yem_cache_baseitem_bem
  1702.         when "W", "WEAPON"
  1703.           obj = $data_weapons[$2.to_i]
  1704.           next if obj == nil
  1705.           obj.yem_cache_baseitem_bem
  1706.         when "A", "ARMOR", "ARMOUR"
  1707.           obj = $data_armors[$2.to_i]
  1708.           next if obj == nil
  1709.           obj.yem_cache_baseitem_bem
  1710.         when "E", "ENEMY"
  1711.           obj = $data_enemies[$2.to_i]
  1712.           next if obj == nil
  1713.           obj.yem_cache_enemy_bem
  1714.         else; next
  1715.         end
  1716.         @setup_action_list = obj.setup_action_list.clone
  1717.         @whole_action_list = obj.whole_action_list.clone
  1718.         @target_action_list = obj.target_action_list.clone
  1719.         @follow_action_list = obj.follow_action_list.clone
  1720.         @finish_action_list = obj.finish_action_list.clone
  1721.         @guard_action_list = obj.guard_action_list.clone
  1722.       #---
  1723.       when YEM::REGEXP::ANI::SETUP_ANI_ON
  1724.         @melody_line = true
  1725.         @setup_action_list = []
  1726.         @setup_action_flag = true
  1727.       when YEM::REGEXP::ANI::SETUP_ANI_OFF
  1728.         @melody_line = false
  1729.         @setup_action_flag = false
  1730.       when YEM::REGEXP::ANI::WHOLE_ANI_ON
  1731.         @melody_line = true
  1732.         @whole_action_list = []
  1733.         @whole_action_flag = true
  1734.       when YEM::REGEXP::ANI::WHOLE_ANI_OFF
  1735.         @melody_line = false
  1736.         @whole_action_flag = false
  1737.       when YEM::REGEXP::ANI::TARGET_ANI_ON
  1738.         @melody_line = true
  1739.         @target_action_list = []
  1740.         @target_action_flag = true
  1741.       when YEM::REGEXP::ANI::TARGET_ANI_OFF
  1742.         @melody_line = false
  1743.         @target_action_flag = false
  1744.       when YEM::REGEXP::ANI::FOLLOW_ANI_ON
  1745.         @melody_line = true
  1746.         @follow_action_list = []
  1747.         @follow_action_flag = true
  1748.       when YEM::REGEXP::ANI::FOLLOW_ANI_OFF
  1749.         @melody_line = false
  1750.         @follow_action_flag = false
  1751.       when YEM::REGEXP::ANI::FINISH_ANI_ON
  1752.         @melody_line = true
  1753.         @finish_action_list = []
  1754.         @finish_action_flag = true
  1755.       when YEM::REGEXP::ANI::FINISH_ANI_OFF
  1756.         @melody_line = false
  1757.         @finish_action_flag = false
  1758.       #---
  1759.       when YEM::REGEXP::ANI::GUARD_ANI_ON
  1760.         @melody_line = true
  1761.         @guard_action_list = []
  1762.         @guard_action_flag = true
  1763.       when YEM::REGEXP::ANI::GUARD_ANI_OFF
  1764.         @melody_line = false
  1765.         @guard_action_flag = false
  1766.       #---
  1767.       else
  1768.         next unless @melody_line
  1769.         case line
  1770.         when YEM::REGEXP::ANI::ANI_TYPE_S6
  1771.           type  = $1
  1772.           value = [$2, $3, $4, $5, $6, $7]
  1773.         when YEM::REGEXP::ANI::ANI_TYPE_S5
  1774.           type  = $1
  1775.           value = [$2, $3, $4, $5, $6]
  1776.         when YEM::REGEXP::ANI::ANI_TYPE_S4
  1777.           type  = $1
  1778.           value = [$2, $3, $4, $5]
  1779.         when YEM::REGEXP::ANI::ANI_TYPE_S3
  1780.           type  = $1
  1781.           value = [$2, $3, $4]
  1782.         when YEM::REGEXP::ANI::ANI_TYPE_S2
  1783.           type  = $1
  1784.           value = [$2, $3]
  1785.         when YEM::REGEXP::ANI::ANI_TYPE_S1
  1786.           type  = $1
  1787.           value = [$2]
  1788.         when YEM::REGEXP::ANI::ANI_TYPE_S0
  1789.           type  = $1
  1790.           value = [nil]
  1791.         else; next
  1792.         end
  1793.         case type.upcase
  1794.         when /IF[ ](.*)/i, /UNLESS[ ](.*)/i, /ELSIF[ ](.*)/i
  1795.           ignore_upcase = true
  1796.         when "MESSAGE", "SCRIPT", "SCRIPT CALL", "POPUP"
  1797.           type = type.upcase
  1798.           ignore_upcase = true
  1799.         when /CHANGE[ ](?:VARIABLE|VAR)[ ](.*)/i
  1800.         else
  1801.           type = type.upcase
  1802.           ignore_upcase = false
  1803.         end
  1804.         for i in 0..(value.size-1)
  1805.           next if value[i] == nil
  1806.           next if ignore_upcase
  1807.           next if value[i] == /IF[ ](.*)/i
  1808.           next if value[i] == /UNLESS[ ](.*)/i
  1809.           value[i] = value[i].to_s.upcase
  1810.         end
  1811.         array = [type, value]
  1812.         if @setup_action_flag
  1813.           @setup_action_list[@setup_action_list.size] = array
  1814.         elsif @whole_action_flag
  1815.           @whole_action_list[@whole_action_list.size] = array
  1816.         elsif @target_action_flag
  1817.           @target_action_list[@target_action_list.size] = array
  1818.         elsif @follow_action_flag
  1819.           @follow_action_list[@follow_action_list.size] = array
  1820.         elsif @finish_action_flag
  1821.           @finish_action_list[@finish_action_list.size] = array
  1822.         elsif @guard_action_flag
  1823.           @guard_action_list[@guard_action_list.size] = array
  1824.         end
  1825.       end
  1826.     } # self.note.split
  1827.     #--- Melody REGEXP ---
  1828.   end # yem_cache_enemy_bem
  1829.  
  1830.   #--------------------------------------------------------------------------
  1831.   # new method: create_default_action_codes
  1832.   #--------------------------------------------------------------------------
  1833.   def create_default_action_codes
  1834.     @setup_action_list  = YEM::DEFAULT_ACTIONS::ATTACK_SETUP
  1835.     @whole_action_list  = YEM::DEFAULT_ACTIONS::ATTACK_WHOLE
  1836.     @target_action_list = YEM::DEFAULT_ACTIONS::ATTACK_TARGET
  1837.     @follow_action_list = YEM::DEFAULT_ACTIONS::ATTACK_FOLLOW
  1838.     @finish_action_list = YEM::DEFAULT_ACTIONS::ATTACK_FINISH
  1839.     @guard_action_list  = YEM::DEFAULT_ACTIONS::GUARD_ACTIONS
  1840.   end
  1841.  
  1842. end # RPG::Enemy
  1843.  
  1844. #===============================================================================
  1845. # RPG::State
  1846. #===============================================================================
  1847.  
  1848. class RPG::State
  1849.  
  1850.   #--------------------------------------------------------------------------
  1851.   # public instance variables
  1852.   #--------------------------------------------------------------------------
  1853.   attr_accessor :popup_rules
  1854.   attr_accessor :state_type
  1855.   attr_accessor :state_ani
  1856.   attr_accessor :restrict_skill
  1857.   attr_accessor :restrict_item
  1858.   attr_accessor :ptb_bonus
  1859.   attr_accessor :ptb_max_cancel
  1860.   attr_accessor :ptb_max_regain
  1861.   attr_accessor :atb_reset_plus
  1862.   attr_accessor :ctb_reset_plus
  1863.   attr_accessor :dmg_taken_rate
  1864.   attr_accessor :dmg_bonus_rate
  1865.   attr_accessor :dmg_wall
  1866.   attr_accessor :slip_effect
  1867.   attr_accessor :rage_boost
  1868.   attr_accessor :stack
  1869.   attr_accessor :lunatic_effects
  1870.   attr_accessor :cost_per
  1871.   attr_accessor :cost_set
  1872.   attr_accessor :maxhp_rate
  1873.   attr_accessor :maxmp_rate
  1874.   attr_accessor :hit_rate
  1875.   attr_accessor :eva_rate
  1876.   attr_accessor :cri_rate
  1877.   attr_accessor :odds_rate
  1878.   attr_accessor :maxhp_set
  1879.   attr_accessor :maxmp_set
  1880.   attr_accessor :atk_set
  1881.   attr_accessor :def_set
  1882.   attr_accessor :spi_set
  1883.   attr_accessor :agi_set
  1884.   attr_accessor :hit_set
  1885.   attr_accessor :eva_set
  1886.   attr_accessor :cri_set
  1887.   attr_accessor :odds_set
  1888.   attr_accessor :traits
  1889.   attr_accessor :element_rank
  1890.   attr_accessor :state_rank
  1891.   attr_accessor :attack_element
  1892.   attr_accessor :attack_state
  1893.   attr_accessor :element_rank_add
  1894.   attr_accessor :state_rank_add
  1895.   attr_accessor :element_rank_rev
  1896.   attr_accessor :state_rank_rev
  1897.   attr_accessor :element_rate_set
  1898.   attr_accessor :state_rate_set
  1899.   attr_accessor :element_rate_per
  1900.   attr_accessor :state_rate_per
  1901.   attr_accessor :weapon_icon
  1902.   attr_accessor :attack_animation
  1903.  
  1904.   #--------------------------------------------------------------------------
  1905.   # new method: create_default_state_values
  1906.   #--------------------------------------------------------------------------
  1907.   def create_default_state_values
  1908.     @popup_rules = {
  1909.       :add => "ADDSTATE",
  1910.       :rem => "REMSTATE",
  1911.       :dur => nil }
  1912.     #---
  1913.     @state_ani = 0
  1914.     @state_type = ["ALL"]
  1915.     @restrict_skill = []
  1916.     @restrict_item = []
  1917.     #---
  1918.     @ptb_bonus = 0
  1919.     @ptb_max_cancel = 0
  1920.     @ptb_max_regain = 0
  1921.     @atb_reset_plus = 0
  1922.     @ctb_reset_plus = 0
  1923.     #---
  1924.     @dmg_taken_rate = {}
  1925.     @dmg_bonus_rate = {}
  1926.     @dmg_wall = {}
  1927.     @rage_boost = {}
  1928.     #---
  1929.     @lunatic_effects = {}
  1930.     @slip_effect = {}
  1931.     @slip_effect[:hp_degen_per] = 10 if @slip_damage
  1932.     @stack = 1
  1933.     @maxhp_rate = 100
  1934.     @maxmp_rate = 100
  1935.     @hit_rate = 100
  1936.     @eva_rate = 100
  1937.     @cri_rate = 100
  1938.     @odds_rate = 100
  1939.     @maxhp_set = 0
  1940.     @maxmp_set = 0
  1941.     @atk_set = 0
  1942.     @def_set = 0
  1943.     @spi_set = 0
  1944.     @agi_set = 0
  1945.     @hit_set = 0
  1946.     @eva_set = 0
  1947.     @cri_set = 0
  1948.     @odds_set = 0
  1949.     @traits = []
  1950.     @cost_per = {}
  1951.     @cost_set = {}
  1952.     #---
  1953.     @element_rank = {}
  1954.     @state_rank = {}
  1955.     @attack_element = []
  1956.     @attack_state = []
  1957.     @element_rank_add = {}
  1958.     @state_rank_add = {}
  1959.     @element_rank_rev = []
  1960.     @state_rank_rev = []
  1961.     @element_rate_set = {}
  1962.     @state_rate_set = {}
  1963.     @element_rate_per = {}
  1964.     @state_rate_per = {}
  1965.     @weapon_icon = 0
  1966.     @attack_animation = 0
  1967.   end
  1968.  
  1969.   #--------------------------------------------------------------------------
  1970.   # new method: finish_default_state_values
  1971.   #--------------------------------------------------------------------------
  1972.   def finish_default_state_values
  1973.     @lunatic_effects[:apply] = [] if @lunatic_effects[:apply] == nil
  1974.     @lunatic_effects[:apply].push("COMMON APPLY")
  1975.     @lunatic_effects[:erase] = [] if @lunatic_effects[:erase] == nil
  1976.     @lunatic_effects[:erase].push("COMMON ERASE")
  1977.     @lunatic_effects[:leave] = [] if @lunatic_effects[:leave] == nil
  1978.     @lunatic_effects[:leave].push("COMMON LEAVE")
  1979.     @lunatic_effects[:react] = [] if @lunatic_effects[:react] == nil
  1980.     @lunatic_effects[:react].push("COMMON REACT")
  1981.     @lunatic_effects[:shock] = [] if @lunatic_effects[:shock] == nil
  1982.     @lunatic_effects[:shock].push("COMMON APPLY")
  1983.     @lunatic_effects[:begin] = [] if @lunatic_effects[:begin] == nil
  1984.     @lunatic_effects[:begin].push("COMMON BEGIN")
  1985.     @lunatic_effects[:while] = [] if @lunatic_effects[:while] == nil
  1986.     @lunatic_effects[:while].push("COMMON WHILE")
  1987.     @lunatic_effects[:close] = [] if @lunatic_effects[:close] == nil
  1988.     @lunatic_effects[:close].push("COMMON CLOSE")
  1989.   end
  1990.  
  1991.   #--------------------------------------------------------------------------
  1992.   # common cache: yem_cache_state_bem
  1993.   #--------------------------------------------------------------------------
  1994.   def yem_cache_state_bem
  1995.     return if @cached_state_bem; @cached_state_bem = true
  1996.     create_default_state_values
  1997.     self.note.split(/[\r\n]+/).each { |line|
  1998.       case line
  1999.       #---
  2000.       when YEM::REGEXP::STATE::POPUP_ADD
  2001.         @popup_rules[:add] = $1.to_s
  2002.       when YEM::REGEXP::STATE::POPUP_REM
  2003.         @popup_rules[:rem] = $1.to_s
  2004.       when YEM::REGEXP::STATE::POPUP_DUR
  2005.         @popup_rules[:dur] = $1.to_s
  2006.       when YEM::REGEXP::STATE::HIDE_ADD
  2007.         @popup_rules[:add] = nil
  2008.       when YEM::REGEXP::STATE::HIDE_REM
  2009.         @popup_rules[:rem] = nil
  2010.       when YEM::REGEXP::STATE::HIDE_DUR
  2011.         @popup_rules[:dur] = nil
  2012.       #---
  2013.       when YEM::REGEXP::STATE::STATE_TYPE
  2014.         @state_type.push($1.upcase) unless type?($1.upcase)
  2015.       when YEM::REGEXP::STATE::STATE_ANI
  2016.         @state_ani = $1.to_i
  2017.       when YEM::REGEXP::STATE::RESTRICT_SKILL
  2018.         type = $1.upcase
  2019.         @restrict_skill.push(type) unless @restrict_skill.include?(type)
  2020.       when YEM::REGEXP::STATE::RESTRICT_ITEM
  2021.         type = $1.upcase
  2022.         @restrict_item.push(type) unless @restrict_item.include?(type)
  2023.       #---
  2024.       when YEM::REGEXP::STATE::PTB_BONUS
  2025.         @ptb_bonus = $1.to_i
  2026.       when YEM::REGEXP::STATE::PTB_MAX_CANCEL
  2027.         @ptb_max_cancel = $1.to_i
  2028.       when YEM::REGEXP::STATE::PTB_MAX_REGAIN
  2029.         @ptb_max_regain = $1.to_i
  2030.       #---
  2031.       when YEM::REGEXP::STATE::ATB_RESET_PLUS
  2032.         @atb_reset_plus = $1.to_i
  2033.       #---
  2034.       when YEM::REGEXP::STATE::DMG_TAKEN
  2035.         case $1.upcase
  2036.         when "HP DMG", "HP DAMAGE"
  2037.           temp = :hp_dmg
  2038.         when "MP DMG", "MP DAMAGE", "SP DMG", "SP DAMAGE"
  2039.           temp = :mp_dmg
  2040.         when "HP HEAL", "HP HEALING"
  2041.           temp = :hp_heal
  2042.         when "MP HEAL", "MP HEALING", "SP HEAL", "SP HEALING"
  2043.           temp = :mp_heal
  2044.         else; next
  2045.         end
  2046.         @dmg_taken_rate[temp] = $2.to_i
  2047.       when YEM::REGEXP::STATE::DMG_BONUS
  2048.         case $1.upcase
  2049.         when "HP DMG", "HP DAMAGE"
  2050.           temp = :hp_dmg
  2051.         when "MP DMG", "MP DAMAGE", "SP DMG", "SP DAMAGE"
  2052.           temp = :mp_dmg
  2053.         when "HP HEAL", "HP HEALING"
  2054.           temp = :hp_heal
  2055.         when "MP HEAL", "MP HEALING", "SP HEAL", "SP HEALING"
  2056.           temp = :mp_heal
  2057.         else; next
  2058.         end
  2059.         @dmg_bonus_rate[temp] = $2.to_i
  2060.       when YEM::REGEXP::STATE::DMG_WALL
  2061.         case $1.upcase
  2062.         when "HP DMG", "HP DAMAGE"
  2063.           temp = :hp_dmg
  2064.         when "MP DMG", "MP DAMAGE", "SP DMG", "SP DAMAGE"
  2065.           temp = :mp_dmg
  2066.         when "HP HEAL", "HP HEALING"
  2067.           temp = :hp_heal
  2068.         when "MP HEAL", "MP HEALING", "SP HEAL", "SP HEALING"
  2069.           temp = :mp_heal
  2070.         else; next
  2071.         end
  2072.         @dmg_wall[temp] = $2.to_i
  2073.       #---
  2074.       when YEM::REGEXP::STATE::RAGE_BOOST_PER
  2075.         @rage_boost[:per] = $1.to_i
  2076.       when YEM::REGEXP::STATE::RAGE_BOOST_SET
  2077.         @rage_boost[:set] = $1.to_i
  2078.       #---
  2079.       when YEM::REGEXP::STATE::SLIP_SET
  2080.         case $1.upcase
  2081.         when "HP"
  2082.           case $2.upcase
  2083.           when "DEGEN"
  2084.             @slip_effect[:hp_degen_set] = $3.to_i
  2085.           when "REGEN"
  2086.             @slip_effect[:hp_degen_set] = -$3.to_i
  2087.           end
  2088.         when "MP"
  2089.           case $2.upcase
  2090.           when "DEGEN"
  2091.             @slip_effect[:mp_degen_set] = $3.to_i
  2092.           when "REGEN"
  2093.             @slip_effect[:mp_degen_set] = -$3.to_i
  2094.           end
  2095.         else; return
  2096.         end
  2097.         @slip_damage = true
  2098.       when YEM::REGEXP::STATE::SLIP_PER
  2099.         case $1.upcase
  2100.         when "HP"
  2101.           case $2.upcase
  2102.           when "DEGEN"
  2103.             @slip_effect[:hp_degen_per] = $3.to_i
  2104.           when "REGEN"
  2105.             @slip_effect[:hp_degen_per] = -$3.to_i
  2106.           end
  2107.         when "MP"
  2108.           case $2.upcase
  2109.           when "DEGEN"
  2110.             @slip_effect[:mp_degen_per] = $3.to_i
  2111.           when "REGEN"
  2112.             @slip_effect[:mp_degen_per] = -$3.to_i
  2113.           end
  2114.         else; return
  2115.         end
  2116.         @slip_damage = true
  2117.       #---
  2118.       when YEM::REGEXP::STATE::MAX_STACK
  2119.         @stack = [$1.to_i, 1].max
  2120.       #---
  2121.       when YEM::REGEXP::STATE::TRAITS
  2122.         case $1.upcase
  2123.         when "SUPER GUARD", "SUPER_GUARD", "SUPERGUARD"
  2124.           @traits.push(:super_guard)
  2125.         when "PHARMACOLOGY", "PHARMA", "ITEM BOOST", "ITEM_BOOST"
  2126.           @traits.push(:pharmacology)
  2127.         when "FAST ATTACK", "FAST_ATTACK", "FASTATTACK"
  2128.           @traits.push(:fast_attack)
  2129.         when "DUAL ATTACK", "DUALATTACK", "DUAL_ATTACK"
  2130.           @traits.push(:dual_attack)
  2131.         when "PREVENT_CRITICAL", "PREVENT CRITICAL", "PREVENT CRI"
  2132.           @traits.push(:prevent_critical)
  2133.         when "HALF MP COST", "HALF_MP_COST", "HALF MP", "HALF_MP", "HALFMP"
  2134.           @traits.push(:half_mp_cost)
  2135.         when "DOUBLE EXP GAIN", "DOUBLE_EXP_GAIN", "DOUBLE EXP", "DOUBLE_EXP"
  2136.           @traits.push(:double_exp_gain)
  2137.         when "AUTO_HP_RECOVER", "AUTO HP RECOVER", "AUTO HP", "AUTO_HP"
  2138.           @traits.push(:auto_hp_recover)
  2139.         when "ANTI HP REGEN", "ANTI_HP_REGEN"
  2140.           @traits.push(:anti_hp_regen)
  2141.         when "ANTI HP DEGEN", "ANTI_HP_DEGEN"
  2142.           @traits.push(:anti_hp_degen)
  2143.         when "ANTI MP REGEN", "ANTI_MP_REGEN"
  2144.           @traits.push(:anti_mp_regen)
  2145.         when "ANTI MP DEGEN", "ANTI_MP_DEGEN"
  2146.           @traits.push(:anti_mp_degen)
  2147.         else; next
  2148.         end
  2149.       #---
  2150.       when YEM::REGEXP::STATE::COST_PER
  2151.         name = $1.upcase
  2152.         case name
  2153.         when "SP"; name = "MP"
  2154.         when "LP"; name = "HP"
  2155.         end
  2156.         @cost_per[name] = $2.to_i
  2157.       when YEM::REGEXP::STATE::COST_SET
  2158.         name = $1.upcase
  2159.         case name
  2160.         when "SP"; name = "MP"
  2161.         when "LP"; name = "HP"
  2162.         end
  2163.         @cost_set[name] = $2.to_i
  2164.       #---
  2165.       when YEM::REGEXP::STATE::CUSTOM_APPLY
  2166.         string = $1.upcase; type = :apply
  2167.         @lunatic_effects[type] = [] if @lunatic_effects[type] == nil
  2168.         @lunatic_effects[type].push(string)
  2169.       when YEM::REGEXP::STATE::CUSTOM_ERASE
  2170.         string = $1.upcase; type = :erase
  2171.         @lunatic_effects[type] = [] if @lunatic_effects[type] == nil
  2172.         @lunatic_effects[type].push(string)
  2173.       when YEM::REGEXP::STATE::CUSTOM_LEAVE
  2174.         string = $1.upcase; type = :leave
  2175.         @lunatic_effects[type] = [] if @lunatic_effects[type] == nil
  2176.         @lunatic_effects[type].push(string)
  2177.       when YEM::REGEXP::STATE::CUSTOM_REACT
  2178.         string = $1.upcase; type = :react
  2179.         @lunatic_effects[type] = [] if @lunatic_effects[type] == nil
  2180.         @lunatic_effects[type].push(string)
  2181.       when YEM::REGEXP::STATE::CUSTOM_SHOCK
  2182.         string = $1.upcase; type = :shock
  2183.         @lunatic_effects[type] = [] if @lunatic_effects[type] == nil
  2184.         @lunatic_effects[type].push(string)
  2185.       when YEM::REGEXP::STATE::CUSTOM_BEGIN
  2186.         string = $1.upcase; type = :begin
  2187.         @lunatic_effects[type] = [] if @lunatic_effects[type] == nil
  2188.         @lunatic_effects[type].push(string)
  2189.       when YEM::REGEXP::STATE::CUSTOM_WHILE
  2190.         string = $1.upcase; type = :while
  2191.         @lunatic_effects[type] = [] if @lunatic_effects[type] == nil
  2192.         @lunatic_effects[type].push(string)
  2193.       when YEM::REGEXP::STATE::CUSTOM_CLOSE
  2194.         string = $1.upcase; type = :close
  2195.         @lunatic_effects[type] = [] if @lunatic_effects[type] == nil
  2196.         @lunatic_effects[type].push(string)
  2197.       #---
  2198.       when YEM::REGEXP::STATE::SET_ELE_RT
  2199.         if $1.to_i != 0
  2200.           @element_rate_set[$1.to_i] = $2.to_i
  2201.         elsif $1.upcase == "ALL"
  2202.           for i in 1..($data_system.elements.size - 1)
  2203.             @element_rate_set[i] = $2.to_i
  2204.           end
  2205.         end
  2206.       #---
  2207.       when YEM::REGEXP::STATE::PER_ELE_RT
  2208.         if $1.to_i != 0
  2209.           @element_rate_per[$1.to_i] = $2.to_i
  2210.         elsif $1.upcase == "ALL"
  2211.           for i in 1..($data_system.elements.size - 1)
  2212.             @element_rate_per[i] = $2.to_i
  2213.           end
  2214.         end
  2215.       #---
  2216.       when YEM::REGEXP::STATE::ADD_ELE_RK
  2217.         if $1.to_i != 0
  2218.           @element_rank_add[$1.to_i] = $2.to_i
  2219.         elsif $1.upcase == "ALL"
  2220.           for i in 1..($data_system.elements.size - 1)
  2221.             @element_rank_add[i] = $2.to_i
  2222.           end
  2223.         end
  2224.       #---
  2225.       when YEM::REGEXP::STATE::SET_ELE_RK
  2226.         case $2.upcase
  2227.         when "S", "Z"; value = 0
  2228.         when "A"; value = 1
  2229.         when "B"; value = 2
  2230.         when "C"; value = 3
  2231.         when "D"; value = 4
  2232.         when "E"; value = 5
  2233.         when "F"; value = 6
  2234.         else; next
  2235.         end
  2236.         if $1.to_i != 0
  2237.           @element_rank[$1.to_i] = value
  2238.         elsif $1.upcase == "ALL"
  2239.           for i in 1..($data_system.elements.size - 1)
  2240.             @element_rank[i] = value
  2241.           end
  2242.         end
  2243.       #---
  2244.       when YEM::REGEXP::STATE::SET_STA_RT
  2245.         if $1.to_i != 0
  2246.           @state_rate_set[$1.to_i] = $2.to_i
  2247.         elsif $1.upcase == "ALL"
  2248.           for i in 1..($data_states.size - 1)
  2249.             @state_rate_set[i] = $2.to_i
  2250.           end
  2251.         end
  2252.       #---
  2253.       when YEM::REGEXP::STATE::PER_STA_RT
  2254.         if $1.to_i != 0
  2255.           @state_rate_per[$1.to_i] = $2.to_i
  2256.         elsif $1.upcase == "ALL"
  2257.           for i in 1..($data_states.size - 1)
  2258.             @state_rate_per[i] = $2.to_i
  2259.           end
  2260.         end
  2261.       #---
  2262.       when YEM::REGEXP::STATE::ADD_STA_RK
  2263.         if $1.to_i != 0
  2264.           @state_rank_add[$1.to_i] = $2.to_i
  2265.         elsif $1.upcase == "ALL"
  2266.           for i in 1..($data_states.size - 1)
  2267.             @state_rank_add[i] = $2.to_i
  2268.           end
  2269.         end
  2270.       #---
  2271.       when YEM::REGEXP::STATE::SET_STA_RK
  2272.         case $2.upcase
  2273.         when "S", "Z"; value = 0
  2274.         when "A"; value = 1
  2275.         when "B"; value = 2
  2276.         when "C"; value = 3
  2277.         when "D"; value = 4
  2278.         when "E"; value = 5
  2279.         when "F"; value = 6
  2280.         else; next
  2281.         end
  2282.         if $1.to_i != 0
  2283.           @state_rank[$1.to_i] = value
  2284.         elsif $1.upcase == "ALL"
  2285.           for i in 1..($data_states.size - 1)
  2286.             @state_rank[i] = value
  2287.           end
  2288.         end
  2289.       #---
  2290.       when YEM::REGEXP::STATE::ATK_ELE
  2291.         $1.scan(/\d+/).each { |num|
  2292.         @attack_element.push(num.to_i) if num.to_i > 0 }
  2293.       when YEM::REGEXP::STATE::ATK_STA
  2294.         $1.scan(/\d+/).each { |num|
  2295.         @attack_state.push(num.to_i) if num.to_i > 0 }
  2296.       #---
  2297.       when YEM::REGEXP::STATE::WEAPON_ICON
  2298.         @weapon_icon = $1.to_i
  2299.       when YEM::REGEXP::STATE::ATTACK_ANI
  2300.         @attack_animation = $1.to_i
  2301.       #--- Make sure this remains at the bottom of the list.
  2302.       when YEM::REGEXP::STATE::STAT_PER
  2303.         case $1.upcase
  2304.         when "MAXHP"
  2305.           @maxhp_rate = $2.to_i
  2306.         when "MAXMP", "MAXSP"
  2307.           @maxmp_rate = $2.to_i
  2308.         when "ATK"
  2309.           @atk_rate = $2.to_i
  2310.         when "DEF"
  2311.           @def_rate = $2.to_i
  2312.         when "SPI", "INT"
  2313.           @spi_rate = $2.to_i
  2314.         when "AGI"
  2315.           @agi_rate = $2.to_i
  2316.         when "HIT"
  2317.           @hit_rate = $2.to_i
  2318.         when "EVA"
  2319.           @eva_rate = $2.to_i
  2320.         when "CRI"
  2321.           @cri_rate = $2.to_i
  2322.         when "ODDS", "AGR", "AGGRO"
  2323.           @odds_rate = $2.to_i
  2324.         else; next
  2325.         end
  2326.       when YEM::REGEXP::STATE::STAT_SET
  2327.         case $1.upcase
  2328.         when "MAXHP"
  2329.           @maxhp_set = $2.to_i
  2330.         when "MAXMP", "MAXSP"
  2331.           @maxmp_set = $2.to_i
  2332.         when "ATK"
  2333.           @atk_set = $2.to_i
  2334.         when "DEF"
  2335.           @def_set = $2.to_i
  2336.         when "SPI", "INT"
  2337.           @spi_set = $2.to_i
  2338.         when "AGI"
  2339.           @agi_set = $2.to_i
  2340.         when "HIT"
  2341.           @hit_set = $2.to_i
  2342.         when "EVA"
  2343.           @eva_set = $2.to_i
  2344.         when "CRI"
  2345.           @cri_set = $2.to_i
  2346.         when "ODDS", "AGR", "AGGRO"
  2347.           @odds_set = $2.to_i
  2348.         else; next
  2349.         end
  2350.       #---
  2351.       end
  2352.     } # end self.note.split
  2353.     finish_default_state_values
  2354.   end # end yem_cache_state_bem
  2355.  
  2356.   #--------------------------------------------------------------------------
  2357.   # new method: type?
  2358.   #--------------------------------------------------------------------------
  2359.   def type?(name); return @state_type.include?(name.upcase); end
  2360.  
  2361. end # RPG::State
  2362.  
  2363. #===============================================================================
  2364. # RPG::Animation
  2365. #===============================================================================
  2366.  
  2367. class RPG::Animation
  2368.  
  2369.   #--------------------------------------------------------------------------
  2370.   # public instance variables
  2371.   #--------------------------------------------------------------------------
  2372.   attr_accessor :anti_mirror
  2373.   attr_accessor :battler_looping
  2374.  
  2375.   #--------------------------------------------------------------------------
  2376.   # common cache: yem_cache_animation_bem
  2377.   #--------------------------------------------------------------------------
  2378.   def yem_cache_animation_bem
  2379.     @battler_looping = true
  2380.     @anti_mirror = false
  2381.     #---
  2382.     case name
  2383.     when /\[(?:NO_LOOP|NOLOOP|NO LOOP)\]/i
  2384.       @battler_looping = false
  2385.     when /\[(?:NO_MIRROR|NOMIRROR|NO MIRROR)\]/i
  2386.       @anti_mirror = true
  2387.     end
  2388.   end
  2389.  
  2390. end # RPG::Animation
  2391.  
  2392. #===============================================================================
  2393. # RPG::Troop
  2394. #===============================================================================
  2395.  
  2396. class RPG::Troop
  2397.  
  2398.   #--------------------------------------------------------------------------
  2399.   # public instance variables
  2400.   #--------------------------------------------------------------------------
  2401.   attr_accessor :strike_case
  2402.  
  2403.   #--------------------------------------------------------------------------
  2404.   # common cache: yem_cache_troop_bem
  2405.   #--------------------------------------------------------------------------
  2406.   def yem_cache_troop_bem
  2407.     @strike_case = 0
  2408.     #---
  2409.     case @name
  2410.     when /\[(?:NORMAL|NO SURPRISE|NO PREEMPTIVE)\]/i
  2411.       @strike_case = 1
  2412.     when /\[(?:PREEMPTIVE|PRE EMPTIVE|FIRST STRIKE)\]/i
  2413.       @strike_case = 2
  2414.     when /\[(?:SURPRISE|SURPRISED|BACK ATTACK)\]/i
  2415.       @strike_case = 3
  2416.     end
  2417.   end
  2418.  
  2419. end # RPG::Troop
  2420.  
  2421. #===============================================================================
  2422. # Scene_Title
  2423. #===============================================================================
  2424.  
  2425. class Scene_Title < Scene_Base
  2426.  
  2427.   #--------------------------------------------------------------------------
  2428.   # alias method: load_bt_database
  2429.   #--------------------------------------------------------------------------
  2430.   alias load_bt_database_bem load_bt_database unless $@
  2431.   def load_bt_database
  2432.     load_bt_database_bem
  2433.     load_bem_cache
  2434.   end
  2435.  
  2436.   #--------------------------------------------------------------------------
  2437.   # alias method: load_database
  2438.   #--------------------------------------------------------------------------
  2439.   alias load_database_bem load_database unless $@
  2440.   def load_database
  2441.     load_database_bem
  2442.     load_bem_cache
  2443.   end
  2444.  
  2445.   #--------------------------------------------------------------------------
  2446.   # new method: load_bem_cache
  2447.   #--------------------------------------------------------------------------
  2448.   def load_bem_cache
  2449.     groups = [$data_skills, $data_items, $data_weapons, $data_armors,
  2450.       $data_enemies, $data_states, $data_animations, $data_troops]
  2451.     for group in groups
  2452.       for obj in group
  2453.         next if obj == nil
  2454.         obj.yem_cache_enemy_bem if obj.is_a?(RPG::Enemy)
  2455.         obj.yem_cache_state_bem if obj.is_a?(RPG::State)
  2456.         obj.yem_cache_baseitem_bem if obj.is_a?(RPG::BaseItem)
  2457.         obj.yem_cache_usableitem_bem if obj.is_a?(RPG::UsableItem)
  2458.         obj.yem_cache_animation_bem if obj.is_a?(RPG::Animation)
  2459.         obj.yem_cache_troop_bem if obj.is_a?(RPG::Troop)
  2460.       end
  2461.     end
  2462.   end
  2463.  
  2464.   #--------------------------------------------------------------------------
  2465.   # alias method: create_game_objects
  2466.   #--------------------------------------------------------------------------
  2467.   alias create_game_objects_bem create_game_objects unless $@
  2468.   def create_game_objects
  2469.     create_game_objects_bem
  2470.     $game_system.create_battle_options
  2471.     $game_temp.atk_effects   = ["calc", "dmg", "state", "effect", "collapse"]
  2472.     $game_temp.skill_effects = ["calc", "dmg", "state", "effect", "collapse"]
  2473.     $game_temp.item_effects  = ["calc", "growth", "dmg", "state", "effect",
  2474.       "collapse"]
  2475.   end
  2476.  
  2477.   #--------------------------------------------------------------------------
  2478.   # alias method: command_new_game
  2479.   #--------------------------------------------------------------------------
  2480.   alias command_new_game_bem command_new_game unless $@
  2481.   def command_new_game
  2482.     command_new_game_bem
  2483.     $game_system.create_battle_options
  2484.   end
  2485.  
  2486. end # Scene_Title
  2487.  
  2488. #===============================================================================
  2489. # Scene_File
  2490. #===============================================================================
  2491.  
  2492. class Scene_File < Scene_Base
  2493.  
  2494.   #--------------------------------------------------------------------------
  2495.   # alias method: do_load
  2496.   #--------------------------------------------------------------------------
  2497.   alias do_load_bem do_load unless $@
  2498.   def do_load
  2499.     do_load_bem
  2500.     $game_party.battle_items_cache = nil
  2501.     $game_party.clear_caches
  2502.   end
  2503.  
  2504. end # Scene_File
  2505.  
  2506. #===============================================================================
  2507. # Game_Temp
  2508. #===============================================================================
  2509.  
  2510. class Game_Temp
  2511.  
  2512.   #--------------------------------------------------------------------------
  2513.   # public instance variables
  2514.   #--------------------------------------------------------------------------
  2515.   attr_accessor :action_elements
  2516.   attr_accessor :atk_effects
  2517.   attr_accessor :force_critical
  2518.   attr_accessor :hp_damage_inflate
  2519.   attr_accessor :iconset
  2520.   attr_accessor :item_effects
  2521.   attr_accessor :less_spacing
  2522.   attr_accessor :mp_damage_inflate
  2523.   attr_accessor :perfect_hit
  2524.   attr_accessor :skill_effects
  2525.  
  2526.   #--------------------------------------------------------------------------
  2527.   # alias method: initialize
  2528.   #--------------------------------------------------------------------------
  2529.   alias initialize_game_temp_bem initialize unless $@
  2530.   def initialize
  2531.     initialize_game_temp_bem
  2532.     @iconset = Cache.system("Iconset")
  2533.   end
  2534.  
  2535. end # Game_Temp
  2536.  
  2537. #===============================================================================
  2538. # Game_System
  2539. #===============================================================================
  2540.  
  2541. class Game_System
  2542.  
  2543.   #--------------------------------------------------------------------------
  2544.   # new method: create_battle_options
  2545.   #--------------------------------------------------------------------------
  2546.   def create_battle_options
  2547.     return if @created_battle_options
  2548.     @created_battle_options = true
  2549.     #--- View and Battle Types ---
  2550.     $game_variables[YEM::BATTLE_ENGINE::VIEW_TYPE_VARIABLE] =
  2551.       YEM::BATTLE_ENGINE::DEFAULT_VIEW
  2552.     $game_variables[YEM::BATTLE_ENGINE::BATTLE_TYPE_VARIABLE] =
  2553.       YEM::BATTLE_ENGINE::DEFAULT_TYPE
  2554.     #--- Option Commands ---
  2555.     options = YEM::BATTLE_ENGINE::OPTIONS
  2556.     atb = YEM::BATTLE_ENGINE::ATB_RULES
  2557.     $game_variables[options[:bgm_variable]] = 100
  2558.     $game_variables[options[:bgs_variable]] = 100
  2559.     $game_variables[options[:sfx_variable]] = 100
  2560.     $game_variables[options[:atb_avariable]] = atb[:default_type]
  2561.     $game_variables[options[:atb_svariable]] = atb[:default_speed]
  2562.     $game_switches[options[:bgm_mute_sw]] = false
  2563.     $game_switches[options[:bgs_mute_sw]] = false
  2564.     $game_switches[options[:sfx_mute_sw]] = false
  2565.     $game_switches[options[:animation_sw]] = true
  2566.     $game_switches[options[:autocursor_sw]] = true
  2567.     $game_switches[options[:next_actor_sw]] = true
  2568.     $game_switches[options[:skill_help_sw]] = false
  2569.   end
  2570.  
  2571. end # Game_System
  2572.  
  2573. #===============================================================================
  2574. # Game_Battler
  2575. #===============================================================================
  2576.  
  2577. class Game_Battler
  2578.  
  2579.   #--------------------------------------------------------------------------
  2580.   # public instance variable
  2581.   #--------------------------------------------------------------------------
  2582.   attr_accessor :absorbed
  2583.   attr_accessor :action
  2584.   attr_accessor :atb_speed
  2585.   attr_accessor :atb_speed_bonus
  2586.   attr_accessor :bonus_element_affinity
  2587.   attr_accessor :bonus_state_affinity
  2588.   attr_accessor :critical
  2589.   attr_accessor :ctb_cache
  2590.   attr_accessor :ctb_speed
  2591.   attr_accessor :ctb_prediction
  2592.   attr_accessor :element_max
  2593.   attr_accessor :equip_clocktick
  2594.   attr_accessor :hp_damage
  2595.   attr_accessor :make_auto_skill
  2596.   attr_accessor :mp_damage
  2597.   attr_accessor :stored_action
  2598.   attr_accessor :ptb_actions
  2599.   attr_accessor :ptb_cancel
  2600.   attr_accessor :ptb_performed
  2601.   attr_accessor :ptb_regain
  2602.   attr_accessor :rage
  2603.   attr_accessor :state_animation_id
  2604.   attr_accessor :temp_immortal
  2605.   attr_accessor :turn_count
  2606.   attr_accessor :update_maxhp
  2607.   attr_accessor :update_maxmp
  2608.   attr_accessor :update_states
  2609.   attr_accessor :update_commands
  2610.  
  2611.   #--------------------------------------------------------------------------
  2612.   # alias method: initialize
  2613.   #--------------------------------------------------------------------------
  2614.   alias initialize_game_battler_bem initialize unless $@
  2615.   def initialize
  2616.     initialize_game_battler_bem
  2617.     @rage = 0
  2618.     @state_animation_id = 0
  2619.   end
  2620.  
  2621.   #--------------------------------------------------------------------------
  2622.   # new method: enemy?
  2623.   #--------------------------------------------------------------------------
  2624.   def enemy?; return false; end
  2625.    
  2626.   #--------------------------------------------------------------------------
  2627.   # overwrite method: state?
  2628.   #--------------------------------------------------------------------------
  2629.   def state?(state_id)
  2630.     state_id = state_id.id if state_id.is_a?(RPG::State)
  2631.     return states.include?($data_states[state_id])
  2632.   end
  2633.  
  2634.   #--------------------------------------------------------------------------
  2635.   # new method: clear_battle_cache
  2636.   #--------------------------------------------------------------------------
  2637.   def clear_battle_cache
  2638.     @cache_ptb = {}
  2639.     @cache_rage = {}
  2640.     @cache_states = {}
  2641.     @cache_params = {}
  2642.     @cache_traits = nil
  2643.     @cache_skill_costs = {}
  2644.     @cache_restrict_skill = nil
  2645.     @cache_restrict_item = nil
  2646.     @cache_element_rate = {}
  2647.     @cache_state_rate = {}
  2648.     @cache_element_set = nil
  2649.     @cache_state_set = nil
  2650.     @cache_weapon_icon = {}
  2651.     @cache_atk_animation = {}
  2652.   end
  2653.  
  2654.   #--------------------------------------------------------------------------
  2655.   # alias method: clear_action_results
  2656.   #--------------------------------------------------------------------------
  2657.   alias clear_action_results_bem clear_action_results unless $@
  2658.   def clear_action_results
  2659.     clear_action_results_bem
  2660.     @element_max = 100
  2661.   end
  2662.  
  2663.   #--------------------------------------------------------------------------
  2664.   # alias method: hp=
  2665.   #--------------------------------------------------------------------------
  2666.   alias hp_equals_bem hp= unless $@
  2667.   def hp=(hp)
  2668.     hp_equals_bem(hp)
  2669.     @update_commands = true
  2670.     $scene.refresh_battle_windows if $scene.is_a?(Scene_Battle)
  2671.   end
  2672.  
  2673.   #--------------------------------------------------------------------------
  2674.   # alias method: mp=
  2675.   #--------------------------------------------------------------------------
  2676.   alias mp_equals_bem mp= unless $@
  2677.   def mp=(mp)
  2678.     mp_equals_bem(mp)
  2679.     @update_commands = true
  2680.     $scene.refresh_battle_windows if $scene.is_a?(Scene_Battle)
  2681.   end
  2682.  
  2683.   #--------------------------------------------------------------------------
  2684.   # overwrite method: make_attack_damage_value
  2685.   #--------------------------------------------------------------------------
  2686.   def make_attack_damage_value(attacker); make_damage_values(attacker); end
  2687.  
  2688.   #--------------------------------------------------------------------------
  2689.   # overwrite method: make_obj_damage_value
  2690.   #--------------------------------------------------------------------------
  2691.   def make_obj_damage_value(user, obj); make_damage_values(user, obj); end
  2692.    
  2693.   #--------------------------------------------------------------------------
  2694.   # new method: apply_max_min
  2695.   #--------------------------------------------------------------------------
  2696.   def apply_max_min(damage, type, obj = nil)
  2697.     maximum = YEM::BATTLE_ENGINE::MAXIMUM_DMG == nil ? damage :
  2698.       YEM::BATTLE_ENGINE::MAXIMUM_DMG
  2699.     minimum = YEM::BATTLE_ENGINE::MINIMUM_DMG == nil ? 0 :
  2700.       YEM::BATTLE_ENGINE::MINIMUM_DMG
  2701.     type = 0 if obj == nil
  2702.     #---
  2703.     case type
  2704.     when 0 # Normal Attack
  2705.       damage = [[damage, maximum].min, minimum].max
  2706.     when 1 # Damage Skill
  2707.       damage = [[damage, maximum].min, minimum].max
  2708.     when 2 # Heal Skill
  2709.       maximum = YEM::BATTLE_ENGINE::MAXIMUM_DMG == nil ? damage :
  2710.       -YEM::BATTLE_ENGINE::MAXIMUM_DMG
  2711.       damage = [[damage, maximum].max, minimum].min
  2712.     end
  2713.     #---
  2714.     return damage
  2715.   end
  2716.  
  2717.   #--------------------------------------------------------------------------
  2718.   # new method: apply_element_rate
  2719.   #--------------------------------------------------------------------------
  2720.   def apply_element_rate(user, damage, obj = nil)
  2721.     return damage if damage == 0
  2722.     if obj != nil
  2723.       set = obj.element_set
  2724.       if obj.physical_attack and YEM::BATTLE_ENGINE::APPLY_PHYSICAL_ELE
  2725.         set += user.element_set
  2726.       elsif YEM::BATTLE_ENGINE::APPLY_MAGICAL_ELE
  2727.         set += user.element_set
  2728.       end
  2729.     else
  2730.       set = user.element_set
  2731.     end
  2732.     set = $game_temp.action_elements if $game_temp.action_elements != nil
  2733.     damage *= elements_max_rate(set)
  2734.     damage /= 100
  2735.     return damage
  2736.   end
  2737.  
  2738.   #--------------------------------------------------------------------------
  2739.   # new method: apply_state_rates
  2740.   #--------------------------------------------------------------------------
  2741.   def apply_state_rates(value, user, stat)
  2742.     case stat
  2743.     when :hp
  2744.       temp = value > 0 ? :hp_dmg : :hp_heal
  2745.     when :mp
  2746.       temp = value > 0 ? :mp_dmg : :mp_heal
  2747.     else; return value
  2748.     end
  2749.     for state in user.states
  2750.       next unless state.dmg_bonus_rate.include?(temp)
  2751.       stack(state).times do
  2752.         value = value * state.dmg_bonus_rate[temp] / 100
  2753.       end
  2754.     end
  2755.     for state in self.states
  2756.       next unless state.dmg_taken_rate.include?(temp)
  2757.       stack(state).times do
  2758.         value = value * state.dmg_taken_rate[temp] / 100
  2759.       end
  2760.     end
  2761.     return value
  2762.   end
  2763.  
  2764.   #--------------------------------------------------------------------------
  2765.   # new method: apply_damage_wall
  2766.   #--------------------------------------------------------------------------
  2767.   def apply_damage_wall(value, stat)
  2768.     case stat
  2769.     when :hp
  2770.       temp = value > 0 ? :hp_dmg : :hp_heal
  2771.     when :mp
  2772.       temp = value > 0 ? :mp_dmg : :mp_heal
  2773.     else; return value
  2774.     end
  2775.     heal = value > 0 ? false : true
  2776.     for state in self.states
  2777.       next unless state.dmg_wall.include?(temp)
  2778.       bonus = state.dmg_wall[temp] * stack(state)
  2779.       value = [(value + bonus), 0].max if !heal
  2780.       value = [(value + bonus), 0].min if heal
  2781.     end
  2782.     return value
  2783.   end
  2784.  
  2785.   #--------------------------------------------------------------------------
  2786.   # new method: apply_state_rank
  2787.   #--------------------------------------------------------------------------
  2788.   def apply_state_rank(state_id)
  2789.     if actor?
  2790.       rank = self.class.state_ranks[state_id]
  2791.     else
  2792.       rank = enemy.state_ranks[state_id]
  2793.     end
  2794.     result = []
  2795.     #---
  2796.     if actor?
  2797.       for equip in equips.compact
  2798.         next unless equip.state_rank.include?(state_id)
  2799.         result.push(equip.state_rank[state_id])  
  2800.       end
  2801.     end
  2802.     #---
  2803.     for state in states
  2804.       next unless state.state_rank.include?(state_id)
  2805.       result.push(state.state_rank[state_id])
  2806.     end
  2807.     #---
  2808.     rank = result.min if result != []
  2809.     #---
  2810.     if actor?
  2811.       for equip in equips.compact
  2812.         next unless equip.state_rank_add.include?(state_id)
  2813.         rank += equip.state_rank_add[state_id]
  2814.       end
  2815.     end
  2816.     #---
  2817.     for state in states
  2818.       next unless state.state_rank_add.include?(state_id)
  2819.       rank += state.state_rank_add[state_id] * stack(state)
  2820.     end
  2821.     #---
  2822.     rank = [[rank, 0].max, 6].min
  2823.     for state in states
  2824.       next unless state.state_rank_rev.include?(state_id)
  2825.       case rank
  2826.       when 0; rank = 6
  2827.       when 1; rank = 5
  2828.       when 2; rank = 4
  2829.       when 4; rank = 2
  2830.       when 5; rank = 1
  2831.       when 6; rank = 0
  2832.       end
  2833.       break
  2834.     end
  2835.     return rank
  2836.   end
  2837.  
  2838.   #--------------------------------------------------------------------------
  2839.   # new method: state_probability_table
  2840.   #--------------------------------------------------------------------------
  2841.   def state_probability_table(state_id, rank)
  2842.     if YEM::BATTLE_ENGINE::STATE_RATE.include?(state_id)
  2843.       result = YEM::BATTLE_ENGINE::STATE_RATE[state_id]
  2844.     else
  2845.       result = YEM::BATTLE_ENGINE::STATE_RATE[0]
  2846.     end
  2847.     rate = result[rank]
  2848.     #---
  2849.     create_affinity_bonus
  2850.     @bonus_state_affinity[state_id] = 0 if
  2851.       @bonus_state_affinity[state_id] == nil
  2852.     rate += @bonus_state_affinity[state_id]
  2853.     #---
  2854.     if actor?
  2855.       for equip in equips.compact
  2856.         next unless equip.state_rate_per.include?(state_id)
  2857.         percent = equip.state_rate_per[state_id]
  2858.         rate = rate * percent / 100
  2859.       end
  2860.     end
  2861.     #---
  2862.     for state in states
  2863.       next unless state.state_rate_per.include?(state_id)
  2864.       stack(state).times do
  2865.         rate = rate * state.state_rate_per[state_id] / 100
  2866.       end
  2867.     end
  2868.     #---
  2869.     if actor?
  2870.       for equip in equips.compact
  2871.         next unless equip.state_rate_set.include?(state_id)
  2872.         rate += equip.state_rate_set[state_id]
  2873.       end
  2874.     end
  2875.     #---
  2876.     for state in states
  2877.       next unless state.state_rate_set.include?(state_id)
  2878.       rate += state.state_rate_set[state_id] * stack(state)
  2879.     end
  2880.     #---
  2881.     return [rate, 0].max
  2882.   end
  2883.  
  2884.   #--------------------------------------------------------------------------
  2885.   # new method: element_apply_state_rate
  2886.   #--------------------------------------------------------------------------
  2887.   def element_apply_state_rate(rate)
  2888.     return rate unless $scene.is_a?(Scene_Battle)
  2889.     return rate unless YEM::BATTLE_ENGINE::STATE_ELEMENT_APPLY
  2890.     return rate if $scene.active_battler == nil
  2891.     battler = $scene.active_battler
  2892.     if battler.action.item? or battler.action.skill?
  2893.       obj = battler.action.item if $scene.active_battler.action.item?
  2894.       obj = battler.action.skill if $scene.active_battler.action.skill?
  2895.     else
  2896.       obj = nil
  2897.     end
  2898.     rate = apply_element_rate(battler, rate, obj)
  2899.     return rate
  2900.   end
  2901.  
  2902.   #--------------------------------------------------------------------------
  2903.   # new method: attack_formulas
  2904.   #--------------------------------------------------------------------------
  2905.   def attack_formulas; return ["ATK WEAPON"]; end
  2906.  
  2907.   #--------------------------------------------------------------------------
  2908.   # new method: added_states_plus
  2909.   #--------------------------------------------------------------------------
  2910.   def added_states_plus(state_id)
  2911.     state_id = state_id.id if state_id.is_a?(RPG::State)
  2912.     if state?(state_id)
  2913.       remained_states_plus(state_id)
  2914.       return
  2915.     end
  2916.     add_state(state_id)
  2917.     return if @added_states.include?(state_id)
  2918.     @added_states.push(state_id)
  2919.     @added_states.uniq!
  2920.     @added_states.sort!
  2921.   end
  2922.  
  2923.   #--------------------------------------------------------------------------
  2924.   # new method: removed_states_plus
  2925.   #--------------------------------------------------------------------------
  2926.   def removed_states_plus(state_id)
  2927.     state_id = state_id.id if state_id.is_a?(RPG::State)
  2928.     return unless state?(state_id)
  2929.     return if @removed_states.include?(state_id)
  2930.     remove_state(state_id)
  2931.     @removed_states.push(state_id)
  2932.     @removed_states.uniq!
  2933.     @removed_states.sort!
  2934.   end
  2935.  
  2936.   #--------------------------------------------------------------------------
  2937.   # new method: remained_states_plus
  2938.   #--------------------------------------------------------------------------
  2939.   def remained_states_plus(state_id)
  2940.     state_id = state_id.id if state_id.is_a?(RPG::State)
  2941.     return unless state?(state_id)
  2942.     return if @remained_states.include?(state_id)
  2943.     @remained_states.push(state_id)
  2944.     @remained_states.uniq!
  2945.     @remained_states.sort!
  2946.   end
  2947.  
  2948.   #--------------------------------------------------------------------------
  2949.   # new method: clear_state_tags
  2950.   #--------------------------------------------------------------------------
  2951.   def clear_state_tags
  2952.     @added_states = []
  2953.     @removed_states = []
  2954.     @remained_states = []
  2955.   end
  2956.  
  2957.   #--------------------------------------------------------------------------
  2958.   # alias method: add_state
  2959.   #--------------------------------------------------------------------------
  2960.   alias add_state_bem add_state unless $@
  2961.   def add_state(state_id)
  2962.     hpdif = maxhp; mpdif = maxmp
  2963.     #---
  2964.     add_state_bem(state_id)
  2965.     increase_stack(state_id)
  2966.     #---
  2967.     @state_clockticks = {} if @state_clockticks == nil
  2968.     ctr = 32
  2969.     if $scene.is_a?(Scene_Battle)
  2970.       ctr = YEM::BATTLE_ENGINE::ATB_RULES[:turns_ctr] if $scene.atb?
  2971.       ctr = YEM::BATTLE_ENGINE::CTB_RULES[:turns_ctr] if $scene.ctb?
  2972.     end
  2973.     @state_clockticks[state_id] = ctr
  2974.     #---
  2975.     apply_state_differences(hpdif, mpdif, true)
  2976.     create_state_origin(state_id)
  2977.     reload_state_animation
  2978.     lunatic_status_effects(state_id, :apply)
  2979.     #---
  2980.     clear_battle_cache
  2981.     if $scene.is_a?(Scene_Battle)
  2982.       @update_states = true
  2983.       @update_maxhp = true
  2984.       @update_maxmp = true
  2985.       @update_commands = true
  2986.       $scene.refresh_battle_windows
  2987.     end
  2988.   end
  2989.  
  2990.   #--------------------------------------------------------------------------
  2991.   # alias method: remove_state
  2992.   #--------------------------------------------------------------------------
  2993.   alias remove_state_bem remove_state unless $@
  2994.   def remove_state(state_id)
  2995.     hpdif = maxhp; mpdif = maxmp
  2996.     #---
  2997.     remove_state_bem(state_id)
  2998.     clear_stack(state_id)
  2999.     #---
  3000.     @state_clockticks = {} if @state_clockticks == nil
  3001.     @state_clockticks.delete(state_id)
  3002.     #---
  3003.     apply_state_differences(hpdif, mpdif, false)
  3004.     clear_state_origin(state_id)
  3005.     reload_state_animation
  3006.     lunatic_status_effects(state_id, :remove)
  3007.     #---
  3008.     clear_battle_cache
  3009.     if $scene.is_a?(Scene_Battle)
  3010.       @update_states = true
  3011.       @update_maxhp = true
  3012.       @update_maxmp = true
  3013.       @update_commands = true
  3014.       spriteset.revive_character_death if state_id == 1
  3015.       $scene.refresh_battle_windows
  3016.     end
  3017.   end
  3018.  
  3019.   #--------------------------------------------------------------------------
  3020.   # alias method: remove_states_auto
  3021.   # Game Battler version
  3022.   #--------------------------------------------------------------------------
  3023.   alias remove_states_auto_bem remove_states_auto unless $@
  3024.   def remove_states_auto
  3025.     return unless exist?
  3026.     for state in states; lunatic_status_effects(state, :while); end
  3027.     for i in @state_turns.keys.clone
  3028.       next unless @state_turns[i] <= 0
  3029.       lunatic_status_effects(i, :leave)
  3030.     end
  3031.     remove_states_auto_bem
  3032.     @update_states = true
  3033.   end
  3034.  
  3035.   #--------------------------------------------------------------------------
  3036.   # new method: stack
  3037.   #--------------------------------------------------------------------------
  3038.   def stack(state_id)
  3039.     state_id = state_id.id if state_id.is_a?(RPG::State)
  3040.     state = $data_states[state_id]
  3041.     return 0 unless state?(state)
  3042.     @state_stack = {} if @state_stack == nil
  3043.     max_stack = state.stack
  3044.     return [[@state_stack[state_id].to_i, 1].max, max_stack].min
  3045.   end
  3046.  
  3047.   #--------------------------------------------------------------------------
  3048.   # new method: create_state_origin
  3049.   #--------------------------------------------------------------------------
  3050.   def create_state_origin(state_id)
  3051.     state_id = state_id.id if state_id.is_a?(RPG::State)
  3052.     @state_origin = {} if @state_origin == nil
  3053.     return unless $scene.is_a?(Scene_Battle)
  3054.     @state_origin[state_id] = $scene.active_battler
  3055.   end
  3056.  
  3057.   #--------------------------------------------------------------------------
  3058.   # new method: clear_state_origin
  3059.   #--------------------------------------------------------------------------
  3060.   def clear_state_origin(state_id)
  3061.     state_id = state_id.id if state_id.is_a?(RPG::State)
  3062.     @state_origin = {} if @state_origin == nil
  3063.     @state_origin.delete(state_id)
  3064.   end
  3065.  
  3066.   #--------------------------------------------------------------------------
  3067.   # new method: reset_state_origins
  3068.   #--------------------------------------------------------------------------
  3069.   def reset_state_origins; @state_origin = {}; end
  3070.    
  3071.   #--------------------------------------------------------------------------
  3072.   # new method: state_origin
  3073.   #--------------------------------------------------------------------------
  3074.   def state_origin(state_id)
  3075.     state_id = state_id.id if state_id.is_a?(RPG::State)
  3076.     @state_origin = {} if @state_origin == nil
  3077.     origin = @state_origin[state_id]
  3078.     origin = self if origin == nil
  3079.     return origin
  3080.   end
  3081.  
  3082.   #--------------------------------------------------------------------------
  3083.   # new method: increase_stack
  3084.   #--------------------------------------------------------------------------
  3085.   def increase_stack(state_id, value = 1)
  3086.     state_id = state_id.id if state_id.is_a?(RPG::State)
  3087.     state = $data_states[state_id]
  3088.     return unless state?(state_id)
  3089.     return if state_id == 1
  3090.     @state_stack = {} if @state_stack == nil
  3091.     @state_stack[state_id] = 0 if @state_stack[state_id] == nil
  3092.     original_stack = @state_stack[state_id]
  3093.     @state_stack[state_id] += value
  3094.     @state_stack[state_id] = [@state_stack[state_id], state.stack].min
  3095.     #---
  3096.     clear_battle_cache
  3097.     #---
  3098.     return if @state_stack[state_id] == original_stack
  3099.     @added_states.push(state_id) if !@added_states.include?(state_id)
  3100.   end
  3101.  
  3102.   #--------------------------------------------------------------------------
  3103.   # new method: decrease_stack
  3104.   #--------------------------------------------------------------------------
  3105.   def decrease_stack(state_id, value = 1)
  3106.     state_id = state_id.id if state_id.is_a?(RPG::State)
  3107.     increase_stack(state_id, -value)
  3108.     @state_stack = {} if @state_stack == nil
  3109.     @state_stack.delete(state_id) if @state_stack[state_id].to_i <= 0
  3110.   end
  3111.  
  3112.   #--------------------------------------------------------------------------
  3113.   # new method: clear_stack
  3114.   #--------------------------------------------------------------------------
  3115.   def clear_stack(state_id)
  3116.     state_id = state_id.id if state_id.is_a?(RPG::State)
  3117.     @state_stack = {} if @state_stack == nil
  3118.     @state_stack.delete(state_id)
  3119.   end
  3120.  
  3121.   #--------------------------------------------------------------------------
  3122.   # overwrite method: maxhp
  3123.   #--------------------------------------------------------------------------
  3124.   def maxhp
  3125.     clear_battle_cache if @cache_params == nil
  3126.     if $scene.is_a?(Scene_Battle)
  3127.       return @cache_params[:maxhp] if @cache_params[:maxhp] != nil
  3128.     end
  3129.     #---
  3130.     n = [base_maxhp + @maxhp_plus, 1].max
  3131.     for state in states
  3132.       stack(state).times do
  3133.         n = n * state.maxhp_rate / 100.0
  3134.       end
  3135.     end
  3136.     for state in states
  3137.       next if state.maxhp_set == 0
  3138.       n += state.maxhp_set * stack(state)
  3139.     end
  3140.     #---
  3141.     @cache_params[:maxhp] = [[Integer(n), maxhp_limit].min, 1].max
  3142.     @hp = [@cache_params[:maxhp], @hp].min
  3143.     return @cache_params[:maxhp]
  3144.   end
  3145.  
  3146.   #--------------------------------------------------------------------------
  3147.   # alias methods: maxhp=
  3148.   #--------------------------------------------------------------------------
  3149.   alias maxhp_equals_bem maxhp= unless $@
  3150.   def maxhp=(value)
  3151.     maxhp_equals_bem(value)
  3152.     clear_battle_cache
  3153.     @update_maxhp = true
  3154.     @hp = [@hp, self.maxhp].min
  3155.   end
  3156.  
  3157.   #--------------------------------------------------------------------------
  3158.   # overwrite method: maxmp
  3159.   #--------------------------------------------------------------------------
  3160.   def maxmp
  3161.     clear_battle_cache if @cache_params == nil
  3162.     if $scene.is_a?(Scene_Battle)
  3163.       return @cache_params[:maxmp] if @cache_params[:maxmp] != nil
  3164.     end
  3165.     #---
  3166.     n = [base_maxmp + @maxmp_plus, 0].max
  3167.     for state in states
  3168.       stack(state).times do
  3169.         n = n * state.maxmp_rate / 100.0
  3170.       end
  3171.     end
  3172.     for state in states
  3173.       next if state.maxmp_set == 0
  3174.       n += state.maxmp_set * stack(state)
  3175.     end
  3176.     #---
  3177.     @cache_params[:maxmp] = [[Integer(n), maxmp_limit].min, 0].max
  3178.     @mp = [@cache_params[:maxmp], @mp].min
  3179.     return @cache_params[:maxmp]
  3180.   end
  3181.  
  3182.   #--------------------------------------------------------------------------
  3183.   # alias methods: maxmp=
  3184.   #--------------------------------------------------------------------------
  3185.   alias maxmp_equals_bem maxmp= unless $@
  3186.   def maxmp=(value)
  3187.     maxmp_equals_bem(value)
  3188.     clear_battle_cache
  3189.     @update_maxmp = true
  3190.     @mp = [@mp, self.maxmp].min
  3191.   end
  3192.  
  3193.   #--------------------------------------------------------------------------
  3194.   # overwrite method: atk
  3195.   #--------------------------------------------------------------------------
  3196.   def atk
  3197.     clear_battle_cache if @cache_params == nil
  3198.     if $scene.is_a?(Scene_Battle)
  3199.       return @cache_params[:atk] if @cache_params[:atk] != nil
  3200.     end
  3201.     #---
  3202.     n = [base_atk + @atk_plus, 1].max
  3203.     for state in states
  3204.       stack(state).times do
  3205.         n = n * state.atk_rate / 100.0
  3206.       end
  3207.     end
  3208.     for state in states
  3209.       next if state.atk_set == 0
  3210.       n += state.atk_set * stack(state)
  3211.     end
  3212.     #---
  3213.     @cache_params[:atk] = [[Integer(n), parameter_limit].min, 1].max
  3214.     return @cache_params[:atk]
  3215.   end
  3216.  
  3217.   #--------------------------------------------------------------------------
  3218.   # alias methods: atk=
  3219.   #--------------------------------------------------------------------------
  3220.   alias atk_equals_bem atk= unless $@
  3221.   def atk=(value)
  3222.     atk_equals_bem(value)
  3223.     clear_battle_cache
  3224.   end
  3225.  
  3226.   #--------------------------------------------------------------------------
  3227.   # overwrite method: def
  3228.   #--------------------------------------------------------------------------
  3229.   def def
  3230.     clear_battle_cache if @cache_params == nil
  3231.     if $scene.is_a?(Scene_Battle)
  3232.       return @cache_params[:def] if @cache_params[:def] != nil
  3233.     end
  3234.     #---
  3235.     n = [base_def + @def_plus, 1].max
  3236.     for state in states
  3237.       stack(state).times do
  3238.         n = n * state.def_rate / 100.0
  3239.       end
  3240.     end
  3241.     for state in states
  3242.       next if state.def_set == 0
  3243.       n += state.def_set * stack(state)
  3244.     end
  3245.     #---
  3246.     @cache_params[:def] = [[Integer(n), parameter_limit].min, 1].max
  3247.     return @cache_params[:def]
  3248.   end
  3249.  
  3250.   #--------------------------------------------------------------------------
  3251.   # alias methods: def=
  3252.   #--------------------------------------------------------------------------
  3253.   alias def_equals_bem def= unless $@
  3254.   def def=(value)
  3255.     def_equals_bem(value)
  3256.     clear_battle_cache
  3257.   end
  3258.  
  3259.   #--------------------------------------------------------------------------
  3260.   # overwrite method: spi
  3261.   #--------------------------------------------------------------------------
  3262.   def spi
  3263.     clear_battle_cache if @cache_params == nil
  3264.     if $scene.is_a?(Scene_Battle)
  3265.       return @cache_params[:spi] if @cache_params[:spi] != nil
  3266.     end
  3267.     #---
  3268.     n = [base_spi + @spi_plus, 1].max
  3269.     for state in states
  3270.       stack(state).times do
  3271.         n = n * state.spi_rate / 100.0
  3272.       end
  3273.     end
  3274.     for state in states
  3275.       next if state.spi_set == 0
  3276.       n += state.spi_set * stack(state)
  3277.     end
  3278.     #---
  3279.     @cache_params[:spi] = [[Integer(n), parameter_limit].min, 1].max
  3280.     return @cache_params[:spi]
  3281.   end
  3282.  
  3283.   #--------------------------------------------------------------------------
  3284.   # alias methods: spi=
  3285.   #--------------------------------------------------------------------------
  3286.   alias spi_equals_bem spi= unless $@
  3287.   def spi=(value)
  3288.     spi_equals_bem(value)
  3289.     clear_battle_cache
  3290.   end
  3291.  
  3292.   #--------------------------------------------------------------------------
  3293.   # overwrite method: agi
  3294.   #--------------------------------------------------------------------------
  3295.   def agi
  3296.     clear_battle_cache if @cache_params == nil
  3297.     if $scene.is_a?(Scene_Battle)
  3298.       return @cache_params[:agi] if @cache_params[:agi] != nil
  3299.     end
  3300.     #---
  3301.     n = [base_agi + @agi_plus, 1].max
  3302.     for state in states
  3303.       stack(state).times do
  3304.         n = n * state.agi_rate / 100.0
  3305.       end
  3306.     end
  3307.     for state in states
  3308.       next if state.agi_set == 0
  3309.       n += state.agi_set * stack(state)
  3310.     end
  3311.     #---
  3312.     @cache_params[:agi] = [[Integer(n), parameter_limit].min, 1].max
  3313.     return @cache_params[:agi]
  3314.   end
  3315.  
  3316.   #--------------------------------------------------------------------------
  3317.   # alias methods: agi=
  3318.   #--------------------------------------------------------------------------
  3319.   alias agi_equals_bem agi= unless $@
  3320.   def agi=(value)
  3321.     agi_equals_bem(value)
  3322.     clear_battle_cache
  3323.   end
  3324.  
  3325.   #--------------------------------------------------------------------------
  3326.   # new method: traits
  3327.   #--------------------------------------------------------------------------
  3328.   def traits
  3329.     return @cache_traits if @cache_traits != nil
  3330.     @cache_traits = []
  3331.     for state in states; @cache_traits |= state.traits; end
  3332.     if actor?
  3333.       for equip in equips.compact; @cache_traits |= equip.traits; end
  3334.     end
  3335.     return @cache_traits
  3336.   end
  3337.  
  3338.   #--------------------------------------------------------------------------
  3339.   # new method: auto_battle
  3340.   #--------------------------------------------------------------------------
  3341.   def auto_battle; return false; end
  3342.  
  3343.   #--------------------------------------------------------------------------
  3344.   # overwrite method: super_guard
  3345.   #--------------------------------------------------------------------------
  3346.   def super_guard; return traits.include?(:super_guard); end
  3347.  
  3348.   #--------------------------------------------------------------------------
  3349.   # overwrite method: fast_attack
  3350.   #--------------------------------------------------------------------------
  3351.   def fast_attack; return traits.include?(:fast_attack); end
  3352.  
  3353.   #--------------------------------------------------------------------------
  3354.   # overwrite method: dual_attack
  3355.   #--------------------------------------------------------------------------
  3356.   def dual_attack; return traits.include?(:dual_attack); end
  3357.  
  3358.   #--------------------------------------------------------------------------
  3359.   # overwrite method: prevent_critical
  3360.   #--------------------------------------------------------------------------
  3361.   def prevent_critical; return traits.include?(:dual_attack); end
  3362.  
  3363.   #--------------------------------------------------------------------------
  3364.   # overwrite method: half_mp_cost
  3365.   #--------------------------------------------------------------------------
  3366.   def half_mp_cost; return traits.include?(:half_mp_cost); end
  3367.  
  3368.   #--------------------------------------------------------------------------
  3369.   # new method: anti_hp_regen
  3370.   #--------------------------------------------------------------------------
  3371.   def anti_hp_regen; return traits.include?(:anti_hp_regen); end
  3372.    
  3373.   #--------------------------------------------------------------------------
  3374.   # new method: anti_hp_degen
  3375.   #--------------------------------------------------------------------------
  3376.   def anti_hp_degen; return traits.include?(:anti_hp_degen); end
  3377.  
  3378.   #--------------------------------------------------------------------------
  3379.   # new method: anti_mp_regen
  3380.   #--------------------------------------------------------------------------
  3381.   def anti_mp_regen; return traits.include?(:anti_mp_regen); end
  3382.    
  3383.   #--------------------------------------------------------------------------
  3384.   # new method: anti_mp_degen
  3385.   #--------------------------------------------------------------------------
  3386.   def anti_mp_degen; return traits.include?(:anti_mp_degen); end
  3387.  
  3388.   #--------------------------------------------------------------------------
  3389.   # overwrite method: skill_can_use?
  3390.   #--------------------------------------------------------------------------
  3391.   def skill_can_use?(skill)
  3392.     return false unless skill.is_a?(RPG::Skill)
  3393.     return false unless movable?
  3394.     return false if silent? and skill.spi_f > 0
  3395.     #---
  3396.     return false if skill_restriction?(skill)
  3397.     return false if skill_limited?(skill)
  3398.     return false if cooldown(skill) > 0
  3399.     return false unless meet_obj_requirements(skill)
  3400.     #---
  3401.     return false unless custom_skill_costs(skill, :can_use)
  3402.     #---
  3403.     return ($game_temp.in_battle) ? skill.battle_ok? : skill.menu_ok?
  3404.   end
  3405.  
  3406.   #--------------------------------------------------------------------------
  3407.   # new method: meet_obj_requirements
  3408.   #--------------------------------------------------------------------------
  3409.   def meet_obj_requirements(obj)
  3410.     return false unless met_obj_state_requirements(obj)
  3411.     return false unless met_obj_element_requirements(obj)
  3412.     return false unless met_obj_switch_requirements(obj)
  3413.     return true
  3414.   end
  3415.  
  3416.   #--------------------------------------------------------------------------
  3417.   # new method: met_obj_state_requirements
  3418.   #--------------------------------------------------------------------------
  3419.   def met_obj_state_requirements(obj)
  3420.     if obj.requirements[:all_state] != nil
  3421.       for id in obj.requirements[:all_state]
  3422.         return false unless state?(id)
  3423.       end
  3424.     end
  3425.     #---
  3426.     if obj.requirements[:any_state] != nil
  3427.       for id in obj.requirements[:any_state]
  3428.         return true if state?(id)
  3429.       end
  3430.     end
  3431.     #---
  3432.     return true
  3433.   end
  3434.  
  3435.   #--------------------------------------------------------------------------
  3436.   # new method: met_obj_element_requirements
  3437.   #--------------------------------------------------------------------------
  3438.   def met_obj_element_requirements(obj)
  3439.     return true if self.enemy?
  3440.     if obj.requirements[:all_ele] != nil
  3441.       for id in obj.requirements[:all_ele]
  3442.         return false unless element_set.include?(id)
  3443.       end
  3444.     end
  3445.     #---
  3446.     if obj.requirements[:any_ele] != nil
  3447.       for id in obj.requirements[:any_ele]
  3448.         return true if element_set.include?(id)
  3449.       end
  3450.     end
  3451.     #---
  3452.     return true
  3453.   end
  3454.  
  3455.   #--------------------------------------------------------------------------
  3456.   # new method: met_obj_switch_requirements
  3457.   #--------------------------------------------------------------------------
  3458.   def met_obj_switch_requirements(obj)
  3459.     if obj.requirements[:all_switch] != nil
  3460.       for id in obj.requirements[:all_switch]
  3461.         return false unless $game_switches[id]
  3462.       end
  3463.     end
  3464.     #---
  3465.     if obj.requirements[:any_switch] != nil
  3466.       for id in obj.requirements[:any_switch]
  3467.         return true if $game_switches[id]
  3468.       end
  3469.     end
  3470.     #---
  3471.     return true
  3472.   end
  3473.  
  3474.   #--------------------------------------------------------------------------
  3475.   # new method: skill_restriction?
  3476.   #--------------------------------------------------------------------------
  3477.   def skill_restriction?(skill)
  3478.     if @cache_restrict_skill == nil
  3479.       @cache_restrict_skill = []
  3480.       for state in states
  3481.         @cache_restrict_skill += state.restrict_skill
  3482.       end
  3483.     end
  3484.     return true if (@cache_restrict_skill & skill.skill_type != [])
  3485.     return false
  3486.   end
  3487.  
  3488.   #--------------------------------------------------------------------------
  3489.   # alias method: calc_hit
  3490.   #--------------------------------------------------------------------------
  3491.   alias calc_hit_bem calc_hit unless $@
  3492.   def calc_hit(user, obj = nil)
  3493.     return 100 if $game_temp.perfect_hit
  3494.     if ($TEST or $BTEST) and Input.press?(Input::F6)
  3495.       return 100 if user.actor?
  3496.       return 0 if user.enemy?
  3497.     end
  3498.     return calc_hit_bem(user, obj)
  3499.   end
  3500.  
  3501.   #--------------------------------------------------------------------------
  3502.   # alias method: calc_eva
  3503.   #--------------------------------------------------------------------------
  3504.   alias calc_eva_bem calc_eva unless $@
  3505.   def calc_eva(user, obj = nil)
  3506.     return -1 if $game_temp.perfect_hit
  3507.     if ($TEST or $BTEST) and Input.press?(Input::F6)
  3508.       return 0 if user.actor?
  3509.       return 100 if user.enemy?
  3510.     end
  3511.     return calc_eva_bem(user, obj)
  3512.   end
  3513.  
  3514.   #--------------------------------------------------------------------------
  3515.   # overwrite method: elements_max_rate
  3516.   #--------------------------------------------------------------------------
  3517.   def elements_max_rate(element_set)
  3518.     if element_set.empty?
  3519.       @element_max = 100
  3520.       return 100
  3521.     end
  3522.     rate_list = []
  3523.     for i in element_set
  3524.       rate_list.push(element_rate(i))
  3525.     end
  3526.     #---
  3527.     case YEM::BATTLE_ENGINE::ELEMENT_RATE_CALCULATION
  3528.     when 1 # Lowest of the rates
  3529.       n = rate_list.min
  3530.     when 2 # Average of the rates without absorb, then apply absorb
  3531.       n = 0; absorb = false
  3532.       for rate in rate_list
  3533.         absorb = true if rate < 0
  3534.         n += rate.abs
  3535.       end
  3536.       n *= -1 if absorb
  3537.       n /= rate_list.size
  3538.     when 3 # Average of the rates with absorb
  3539.       n = 0
  3540.       for rate in rate_list;
  3541.         n += rate
  3542.       end
  3543.       n /= rate_list.size
  3544.     when 4 # Priority to absorb, resist, find maximum for the rest.
  3545.       result = []
  3546.       for rate in rate_list
  3547.         next if rate >= 100
  3548.         result.push(rate)
  3549.       end
  3550.       n = (result != []) ? result.min : rate_list.max
  3551.     when 5 # Priority to absorb, resist, find average for the rest.
  3552.       result = []
  3553.       n = 0
  3554.       for rate in rate_list
  3555.         result.push(rate) if rate <= 99
  3556.         n += rate
  3557.       end
  3558.       n = (result != []) ? result.min : n / rate_list.size
  3559.     when 6 # Priority to absorb, immune, find maximum for the rest.
  3560.       result = []
  3561.       for rate in rate_list
  3562.         next if rate > 0
  3563.         result.push(rate)
  3564.       end
  3565.       n = (result != []) ? result.min : rate_list.max
  3566.     when 7 # Priority to absorb, immune, find average for the rest.
  3567.       result = []
  3568.       n = 0
  3569.       for rate in rate_list
  3570.         result.push(rate) if rate <= 0
  3571.         n += rate
  3572.       end
  3573.       n = (result != []) ? result.min : n / rate_list.size
  3574.     when 8 # Multiply all of the rates together to yield a STAB multiplier.
  3575.       n = 100
  3576.       for rate in rate_list; n = n * rate / 100; end
  3577.     when 9 # Absorb and resist priority, apply multiplication for rest.
  3578.       result = []
  3579.       n = 100
  3580.       for rate in rate_list
  3581.         result.push(rate) if rate <= 99
  3582.         n = n * rate / 100
  3583.       end
  3584.       n = result.min if result != []
  3585.     when 10 # Absorb and immune priority, apply multiplication for rest.
  3586.       result = []
  3587.       n = 100
  3588.       for rate in rate_list
  3589.         result.push(rate) if rate <= 0
  3590.         n = n * rate / 100
  3591.       end
  3592.       n = result.min if result != []
  3593.     else # Default: Highest of the rates
  3594.       n = rate_list.max
  3595.     end
  3596.     #---
  3597.     @element_max = n
  3598.     return n
  3599.   end
  3600.  
  3601.   #--------------------------------------------------------------------------
  3602.   # new method: apply_element_rank
  3603.   #--------------------------------------------------------------------------
  3604.   def apply_element_rank(element_id)
  3605.     if actor?
  3606.       rank = self.class.element_ranks[element_id]
  3607.     else
  3608.       rank = enemy.element_ranks[element_id]
  3609.     end
  3610.     result = []
  3611.     #---
  3612.     if actor?
  3613.       for equip in equips.compact
  3614.         next unless equip.element_rank.include?(element_id)
  3615.         result.push(equip.element_rank[element_id])
  3616.       end
  3617.     end
  3618.     #---
  3619.     for state in states
  3620.       next unless state.element_rank.include?(element_id)
  3621.       result.push(state.element_rank[element_id])
  3622.     end
  3623.     rank = result.min if result != []
  3624.     #---
  3625.     if actor?
  3626.       for equip in equips.compact
  3627.         next unless equip.element_rank_add.include?(element_id)
  3628.         rank += equip.element_rank_add[element_id]
  3629.       end
  3630.     end
  3631.     #---
  3632.     for state in states
  3633.       next unless state.element_rank_add.include?(element_id)
  3634.       multiplier = stack(state)
  3635.       rank += state.element_rank_add[element_id] * multiplier
  3636.     end
  3637.     #---
  3638.     rank = [[rank, 0].max, 6].min
  3639.     for state in states
  3640.       next unless state.element_rank_rev.include?(element_id)
  3641.       case rank
  3642.       when 0; rank = 6
  3643.       when 1; rank = 5
  3644.       when 2; rank = 4
  3645.       when 4; rank = 2
  3646.       when 5; rank = 1
  3647.       when 6; rank = 0
  3648.       end
  3649.       break
  3650.     end
  3651.     #---
  3652.     return rank
  3653.   end
  3654.  
  3655.   #--------------------------------------------------------------------------
  3656.   # new method: element_rate_table
  3657.   #--------------------------------------------------------------------------
  3658.   def element_rate_table(element_id, rank)
  3659.     if YEM::BATTLE_ENGINE::ELEMENT_RATE.include?(element_id)
  3660.       result = YEM::BATTLE_ENGINE::ELEMENT_RATE[element_id]
  3661.     else
  3662.       result = YEM::BATTLE_ENGINE::ELEMENT_RATE[0]
  3663.     end
  3664.     rate = result[rank]
  3665.     absorb = (rate < 0)
  3666.     #---
  3667.     create_affinity_bonus
  3668.     @bonus_element_affinity[element_id] = 0 if
  3669.       @bonus_element_affinity[element_id] == nil
  3670.     rate += @bonus_element_affinity[element_id]
  3671.     #---
  3672.     if actor?
  3673.       for equip in equips.compact
  3674.         next unless equip.element_rate_per.include?(element_id)
  3675.         percent = equip.element_rate_per[element_id]
  3676.         rate = rate * percent / 100
  3677.       end
  3678.     end
  3679.     #---
  3680.     for state in states
  3681.       next unless state.element_rate_per.include?(element_id)
  3682.       stack(state).times do
  3683.         rate = rate * state.element_rate_per[element_id] - 100 / 100
  3684.       end
  3685.     end
  3686.     #---
  3687.     if actor?
  3688.       for equip in equips.compact
  3689.         next unless equip.element_rate_set.include?(element_id)
  3690.         rate += equip.element_rate_set[element_id]
  3691.       end
  3692.     end
  3693.     #---
  3694.     for state in states
  3695.       next unless state.element_rate_set.include?(element_id)
  3696.       rate += state.element_rate_set[element_id] * stack(state)
  3697.     end
  3698.     #---
  3699.     rate = absorb ? [rate, 0].min : [rate, 0].max
  3700.     rate = [rate, YEM::BATTLE_ENGINE::MAX_ELEMENT_RATE].min
  3701.     rate = [rate, YEM::BATTLE_ENGINE::MIN_ELEMENT_RATE].max
  3702.     return rate
  3703.   end
  3704.  
  3705.   #--------------------------------------------------------------------------
  3706.   # alias method: execute_damage
  3707.   #--------------------------------------------------------------------------
  3708.   alias execute_damage_bem execute_damage unless $@
  3709.   def execute_damage(user)
  3710.     for state in states; lunatic_status_effects(state, :react); end
  3711.     #--- Damage Inflate ---
  3712.     $game_temp.hp_damage_inflate = 100 if $game_temp.hp_damage_inflate == nil
  3713.     $game_temp.mp_damage_inflate = 100 if $game_temp.mp_damage_inflate == nil
  3714.     @hp_damage = @hp_damage * $game_temp.hp_damage_inflate / 100
  3715.     @mp_damage = @mp_damage * $game_temp.mp_damage_inflate / 100
  3716.     @hp_damage = apply_damage_wall(@hp_damage, :hp)
  3717.     @mp_damage = apply_damage_wall(@mp_damage, :hp)
  3718.     #--- Damage Inflate ---
  3719.     execute_damage_bem(user)
  3720.     #--- Debug Options ---
  3721.     self.hp = 0 if ($TEST or $BTEST) and Input.press?(Input::F5) and enemy?
  3722.     for state in states; lunatic_status_effects(state, :shock); end
  3723.   end
  3724.  
  3725.   #--------------------------------------------------------------------------
  3726.   # new method: maxmp_limit
  3727.   #--------------------------------------------------------------------------
  3728.   unless method_defined?(:maxmp_limit)
  3729.   def maxmp_limit; return 9999; end
  3730.   end # method_defined?(:maxmp_limit)
  3731.  
  3732.   #--------------------------------------------------------------------------
  3733.   # new method: parameter_limit
  3734.   #--------------------------------------------------------------------------
  3735.   unless method_defined?(:parameter_limit)
  3736.   def parameter_limit; return 999; end
  3737.   end # method_defined?(:parameter_limit)
  3738.  
  3739.   #--------------------------------------------------------------------------
  3740.   # new method: attack_setup_actions
  3741.   #--------------------------------------------------------------------------
  3742.   def attack_setup_actions
  3743.     return YEM::DEFAULT_ACTIONS::ATTACK_SETUP
  3744.   end
  3745.  
  3746.   #--------------------------------------------------------------------------
  3747.   # new method: attack_whole_actions
  3748.   #--------------------------------------------------------------------------
  3749.   def attack_whole_actions
  3750.     return YEM::DEFAULT_ACTIONS::ATTACK_WHOLE
  3751.   end
  3752.  
  3753.   #--------------------------------------------------------------------------
  3754.   # new method: attack_follow_actions
  3755.   #--------------------------------------------------------------------------
  3756.   def attack_follow_actions
  3757.     return YEM::DEFAULT_ACTIONS::ATTACK_FOLLOW
  3758.   end
  3759.  
  3760.   #--------------------------------------------------------------------------
  3761.   # new method: attack_target_actions
  3762.   #--------------------------------------------------------------------------
  3763.   def attack_target_actions
  3764.     return YEM::DEFAULT_ACTIONS::ATTACK_TARGET
  3765.   end
  3766.  
  3767.   #--------------------------------------------------------------------------
  3768.   # new method: attack_finish_actions
  3769.   #--------------------------------------------------------------------------
  3770.   def attack_finish_actions
  3771.     return YEM::DEFAULT_ACTIONS::ATTACK_FINISH
  3772.   end
  3773.  
  3774.   #--------------------------------------------------------------------------
  3775.   # new method: guard_actions
  3776.   #--------------------------------------------------------------------------
  3777.   def guard_actions
  3778.     return YEM::DEFAULT_ACTIONS::GUARD_ACTIONS
  3779.   end
  3780.  
  3781.   #--------------------------------------------------------------------------
  3782.   # overwrite method: apply_state_changes
  3783.   #--------------------------------------------------------------------------
  3784.   def apply_state_changes(obj)
  3785.     plus = obj.plus_state_set
  3786.     minus = obj.minus_state_set
  3787.     #---
  3788.     if obj.is_a?(RPG::UsableItem) and $scene.is_a?(Scene_Battle)
  3789.       if YEM::BATTLE_ENGINE::APPLY_PHYSICAL_STATE and obj.physical_attack
  3790.         plus += $scene.active_battler.plus_state_set
  3791.         minus += $scene.active_battler.minus_state_set
  3792.       elsif YEM::BATTLE_ENGINE::APPLY_MAGICAL_STATE
  3793.         plus += $scene.active_battler.plus_state_set
  3794.         minus += $scene.active_battler.minus_state_set
  3795.       end
  3796.     end
  3797.     #---
  3798.     for i in plus
  3799.       next if state_resist?(i)
  3800.       next if dead?
  3801.       next if i == 1 and @immortal
  3802.       if state?(i)
  3803.         remained_rules(i)
  3804.         @remained_states.push(i) unless @remained_states.include?(i)
  3805.         next
  3806.       end
  3807.       if rand(100) < state_probability(i)
  3808.         @added_states.push(i) unless @added_states.include?(i)
  3809.         add_state(i)
  3810.       end
  3811.     end
  3812.     for i in minus
  3813.       next unless state?(i)
  3814.       remove_state(i)
  3815.       @removed_states.push(i) unless @removed_states.include?(i)
  3816.     end
  3817.     for i in @added_states & @removed_states
  3818.       @added_states.delete(i)
  3819.       @removed_states.delete(i)
  3820.     end
  3821.   end
  3822.  
  3823.   #--------------------------------------------------------------------------
  3824.   # new method: remained_rules
  3825.   #--------------------------------------------------------------------------
  3826.   def remained_rules(state_id)
  3827.     state = $data_states[state_id]
  3828.     return if state == nil
  3829.     #---
  3830.     hpdif = maxhp; mpdif = maxmp
  3831.     increase_stack(state)
  3832.     #---
  3833.     case YEM::BATTLE_ENGINE::REMAINED_RULES
  3834.     when 0 # No changes
  3835.       return
  3836.     when 1 # Reset Turns
  3837.       @state_turns[state_id] = state.hold_turn
  3838.     when 2 # Add Turns
  3839.       @state_turns[state_id] = 0 if !@state_turns.include?(state_id)
  3840.       @state_turns[state_id] += state.hold_turn
  3841.     end
  3842.     #---
  3843.     apply_state_differences(hpdif, mpdif)
  3844.   end
  3845.  
  3846.   #--------------------------------------------------------------------------
  3847.   # new method: apply_state_differences
  3848.   #--------------------------------------------------------------------------
  3849.   def apply_state_differences(hpdif, mpdif, apply = true)
  3850.     return if dead?
  3851.     state_settings = YEM::BATTLE_ENGINE::STATE_SETTINGS
  3852.     hpdif = maxhp - hpdif; mpdif = maxmp - mpdif
  3853.     return if hpdif == 0 and mpdif == 0
  3854.     if apply
  3855.       self.hp += hpdif if hpdif > 0 and state_settings[:apply_heal_hp]
  3856.       self.hp += hpdif if hpdif < 0 and state_settings[:apply_dmg_hp]
  3857.       self.mp += mpdif if mpdif > 0 and state_settings[:apply_heal_mp]
  3858.       self.mp += mpdif if mpdif < 0 and state_settings[:apply_dmg_mp]
  3859.     else
  3860.       self.hp += hpdif if hpdif > 0 and state_settings[:erase_heal_hp]
  3861.       self.hp += hpdif if hpdif < 0 and state_settings[:erase_dmg_hp]
  3862.       self.mp += mpdif if mpdif > 0 and state_settings[:erase_heal_mp]
  3863.       self.mp += mpdif if mpdif < 0 and state_settings[:erase_dmg_mp]
  3864.     end
  3865.   end
  3866.  
  3867.   #--------------------------------------------------------------------------
  3868.   # overwrite method: attack_effect
  3869.   #--------------------------------------------------------------------------
  3870.   def attack_effect(attacker)
  3871.     clear_action_results if $game_temp.atk_effects.include?("calc")
  3872.     unless attack_effective?(attacker)
  3873.       @skipped = true
  3874.       return
  3875.     end
  3876.     #---
  3877.     if $game_temp.atk_effects.include?("calc")
  3878.       if rand(100) >= calc_hit(attacker)
  3879.         @missed = true
  3880.         return
  3881.       end
  3882.       if rand(100) < calc_eva(attacker)
  3883.         @evaded = true
  3884.         return
  3885.       end
  3886.     end
  3887.     #---
  3888.     if $game_temp.atk_effects.include?("effect")
  3889.       atb_change_effect(attacker, nil)
  3890.       attacker.create_atb_reset(nil)
  3891.       ctb_change_effect(attacker, nil)
  3892.       attacker.create_ctb_reset(nil)
  3893.       earn_rage(attacker, nil)
  3894.     end
  3895.     #---
  3896.     if $game_temp.atk_effects.include?("dmg")
  3897.       make_attack_damage_value(attacker)
  3898.       execute_damage(attacker)
  3899.       return if @hp_damage == 0
  3900.     end
  3901.     #---
  3902.     apply_state_changes(attacker) if $game_temp.atk_effects.include?("state")
  3903.     ##---
  3904.   end
  3905.  
  3906.   #--------------------------------------------------------------------------
  3907.   # alias method: skill_test
  3908.   #--------------------------------------------------------------------------
  3909.   alias skill_test_bem skill_test unless $@
  3910.   def skill_test(user, skill)
  3911.     for state_id in skill.plus_state_set
  3912.       state = $data_states[state_id]
  3913.       next if state == nil
  3914.       return true if state.stack > self.stack(state)
  3915.     end
  3916.     return skill_test_bem(user, skill)
  3917.   end
  3918.  
  3919.   #--------------------------------------------------------------------------
  3920.   # overwrite method: skill_effect
  3921.   #--------------------------------------------------------------------------
  3922.   def skill_effect(user, skill)
  3923.     clear_action_results if $game_temp.skill_effects.include?("calc")
  3924.     unless skill_effective?(user, skill)
  3925.       @skipped = true
  3926.       return
  3927.     end
  3928.     #---
  3929.     if $game_temp.skill_effects.include?("calc")
  3930.       if rand(100) >= calc_hit(user, skill)
  3931.         @missed = true
  3932.         return
  3933.       end
  3934.       if rand(100) < calc_eva(user, skill)
  3935.         @evaded = true
  3936.         return
  3937.       end
  3938.     end
  3939.     #---
  3940.     if $game_temp.skill_effects.include?("effect")
  3941.       ptb_obj_effect(user, skill)
  3942.       atb_change_effect(user, skill)
  3943.       user.create_atb_reset(skill)
  3944.       ctb_change_effect(user, skill)
  3945.       user.create_ctb_reset(skill)
  3946.       earn_rage(user, skill)
  3947.     end
  3948.     #---
  3949.     if $game_temp.skill_effects.include?("dmg")
  3950.       make_obj_damage_value(user, skill)
  3951.       make_obj_absorb_effect(user, skill)
  3952.       execute_damage(user)
  3953.       return if skill.physical_attack and @hp_damage == 0
  3954.     end
  3955.     #---
  3956.     apply_state_changes(skill) if $game_temp.skill_effects.include?("state")
  3957.   end
  3958.  
  3959.   #--------------------------------------------------------------------------
  3960.   # new method: perform_skill_cost
  3961.   #--------------------------------------------------------------------------
  3962.   def perform_skill_cost(skill)
  3963.     return if skill == nil or !skill.is_a?(RPG::Skill)
  3964.     custom_skill_costs(skill, :perform)
  3965.     make_cooldown(skill)
  3966.     make_limited(skill)
  3967.   end
  3968.  
  3969.   #--------------------------------------------------------------------------
  3970.   # new method: apply_skill_cost_changes
  3971.   #--------------------------------------------------------------------------
  3972.   def apply_skill_cost_changes(skill, cost, type = "MP")
  3973.     clear_battle_cache if @cache_skill_costs == nil
  3974.     return @cache_skill_costs[skill.id] if @cache_skill_costs[skill.id] != nil
  3975.     cost = apply_skill_cost_state_per(skill, cost, type)
  3976.     cost = apply_skill_cost_state_set(skill, cost, type)
  3977.     @cache_skill_costs[skill.id] = [Integer(cost), 0].max
  3978.     return @cache_skill_costs[skill.id]
  3979.   end
  3980.  
  3981.   #--------------------------------------------------------------------------
  3982.   # new method: apply_skill_cost_state_per
  3983.   #--------------------------------------------------------------------------
  3984.   def apply_skill_cost_state_per(skill, cost, type = "MP")
  3985.     for state in states
  3986.       next unless state.cost_per[type.upcase] != nil
  3987.       stack(state).times do
  3988.         cost = cost * state.cost_per[type.upcase] / 100.0
  3989.       end
  3990.     end
  3991.     return cost
  3992.   end
  3993.  
  3994.   #--------------------------------------------------------------------------
  3995.   # new method: apply_skill_cost_state_set
  3996.   #--------------------------------------------------------------------------
  3997.   def apply_skill_cost_state_set(skill, cost, type = "MP")
  3998.     for state in states
  3999.       next unless state.cost_set[type.upcase] != nil
  4000.       cost += state.cost_set[type.upcase] * stack(state)
  4001.     end
  4002.     return cost
  4003.   end
  4004.  
  4005.   #--------------------------------------------------------------------------
  4006.   # overwrite method: item_effect
  4007.   #--------------------------------------------------------------------------
  4008.   def item_effect(user, item)
  4009.     clear_action_results if $game_temp.item_effects.include?("calc")
  4010.     unless item_effective?(user, item)
  4011.       @skipped = true
  4012.       return
  4013.     end
  4014.     #---
  4015.     if $game_temp.item_effects.include?("calc")
  4016.       if rand(100) >= calc_hit(user, item)
  4017.         @missed = true
  4018.         return
  4019.       end
  4020.       if rand(100) < calc_eva(user, item)
  4021.         @evaded = true
  4022.         return
  4023.       end
  4024.     end
  4025.     #---
  4026.     item_growth_effect(user, item) if $game_temp.item_effects.include?("growth")
  4027.     #---
  4028.     if $game_temp.item_effects.include?("effect")
  4029.       ptb_obj_effect(user, item)
  4030.       atb_change_effect(user, item)
  4031.       user.create_atb_reset(item)
  4032.       ctb_change_effect(user, item)
  4033.       user.create_ctb_reset(item)
  4034.       earn_rage(user, item)
  4035.     end
  4036.     #---
  4037.     if $game_temp.item_effects.include?("dmg")
  4038.       hp_recovery = calc_hp_recovery(user, item)
  4039.       mp_recovery = calc_mp_recovery(user, item)
  4040.       make_obj_damage_value(user, item)
  4041.       @hp_damage -= hp_recovery
  4042.       @mp_damage -= mp_recovery
  4043.       make_obj_absorb_effect(user, item)
  4044.       execute_damage(user)
  4045.       return if item.physical_attack and @hp_damage == 0
  4046.     end
  4047.     #---
  4048.     apply_state_changes(item) if $game_temp.item_effects.include?("state")
  4049.   end
  4050.  
  4051.   #--------------------------------------------------------------------------
  4052.   # alias method: item_effective?
  4053.   #--------------------------------------------------------------------------
  4054.   alias item_effective_bem item_effective?
  4055.   def item_effective?(user, item)
  4056.     return false if nullify_effect?(item)
  4057.     return item_effective_bem(user, item)
  4058.   end
  4059.  
  4060.   #--------------------------------------------------------------------------
  4061.   # new method: create_affinity_bonus
  4062.   #--------------------------------------------------------------------------
  4063.   def create_affinity_bonus
  4064.     @bonus_element_affinity = {} if @bonus_element_affinity == nil
  4065.     @bonus_state_affinity = {} if @bonus_state_affinity == nil
  4066.   end
  4067.  
  4068.   #--------------------------------------------------------------------------
  4069.   # alias method: item_test
  4070.   #--------------------------------------------------------------------------
  4071.   alias item_test_bem item_test unless $@
  4072.   def item_test(user, item)
  4073.     return true if item.element_growth != {}
  4074.     return true if item.state_growth != {}
  4075.     return item_test_bem(user, item)
  4076.   end
  4077.  
  4078.   #--------------------------------------------------------------------------
  4079.   # alias method: item_growth_effect
  4080.   #--------------------------------------------------------------------------
  4081.   alias item_growth_effect_bem item_growth_effect unless $@
  4082.   def item_growth_effect(user, item)
  4083.     create_affinity_bonus
  4084.     if item.element_growth != {}
  4085.       for key in item.element_growth
  4086.         ele_id = key[0]; value = key[1]
  4087.         @bonus_element_affinity[ele_id] = 0 if
  4088.           @bonus_element_affinity[ele_id] == nil
  4089.         @bonus_element_affinity[ele_id] += value
  4090.       end
  4091.     end
  4092.     if item.state_growth != {}
  4093.       for key in item.state_growth
  4094.         state_id = key[0]; value = key[1]
  4095.         @bonus_state_affinity[state_id] = 0 if
  4096.           @bonus_state_affinity[state_id] == nil
  4097.         @bonus_state_affinity[state_id] += value
  4098.       end
  4099.     end
  4100.     item_growth_effect_bem(user, item)
  4101.   end
  4102.  
  4103.   #--------------------------------------------------------------------------
  4104.   # new method: nullify_effect?
  4105.   #--------------------------------------------------------------------------
  4106.   def nullify_effect?(item)
  4107.     return false unless item.is_a?(RPG::Item)
  4108.     if actor?
  4109.       return true if item.nullify[:actors].include?(@actor_id)
  4110.       return true if item.nullify[:classes].include?(@class_id)
  4111.     elsif enemy?
  4112.       return true if item.nullify[:enemies].include?(@enemy_id)
  4113.     end
  4114.     return false
  4115.   end
  4116.  
  4117.   #--------------------------------------------------------------------------
  4118.   # new method: consume_item
  4119.   #--------------------------------------------------------------------------
  4120.   def consume_item(item)
  4121.     return unless self.actor?
  4122.     perform_consume_item(item)
  4123.   end
  4124.  
  4125.   #--------------------------------------------------------------------------
  4126.   # new method: perform_consume_item
  4127.   #--------------------------------------------------------------------------
  4128.   def perform_consume_item(item)
  4129.     return if item == nil or !item.is_a?(RPG::Item)
  4130.     $game_party.consume_item(item)
  4131.   end
  4132.  
  4133.   #--------------------------------------------------------------------------
  4134.   # overwrite method: calc_hp_recovery
  4135.   #--------------------------------------------------------------------------
  4136.   def calc_hp_recovery(user, item)
  4137.     result = maxhp * item.hp_recovery_rate / 100 + item.hp_recovery
  4138.     rate = YEM::BATTLE_ENGINE::ITEM_SETTINGS[:hp_pharma_rate]
  4139.     result = Integer(result * rate) if user.pharmacology
  4140.     return result
  4141.   end
  4142.   #--------------------------------------------------------------------------
  4143.   # overwrite method: calc_mp_recovery
  4144.   #--------------------------------------------------------------------------
  4145.   def calc_mp_recovery(user, item)
  4146.     result = maxmp * item.mp_recovery_rate / 100 + item.mp_recovery
  4147.     rate = YEM::BATTLE_ENGINE::ITEM_SETTINGS[:hp_pharma_rate]
  4148.     result = Integer(result * rate) if user.pharmacology
  4149.     return result
  4150.   end
  4151.  
  4152.   #--------------------------------------------------------------------------
  4153.   # new method: item_can_use?
  4154.   #--------------------------------------------------------------------------
  4155.   def item_can_use?(item); return false; end
  4156.  
  4157.   #--------------------------------------------------------------------------
  4158.   # new method: item_restriction?
  4159.   #--------------------------------------------------------------------------
  4160.   def item_restriction?(item)
  4161.     if @cache_restrict_item == nil
  4162.       @cache_restrict_item = []
  4163.       for state in states
  4164.         @cache_restrict_item |= state.restrict_item
  4165.       end
  4166.     end
  4167.     return true if (@cache_restrict_item & item.item_type != [])
  4168.     return false
  4169.   end
  4170.  
  4171.   #--------------------------------------------------------------------------
  4172.   # new method: active_battler?
  4173.   #--------------------------------------------------------------------------
  4174.   def active_battler?
  4175.     return false unless $scene.is_a?(Scene_Battle)
  4176.     return self == $scene.active_battler
  4177.   end
  4178.  
  4179.   #--------------------------------------------------------------------------
  4180.   # overwrite method: slip_damage_effect
  4181.   #--------------------------------------------------------------------------
  4182.   def slip_damage_effect
  4183.     return unless slip_damage?
  4184.     for state in states; perform_slip_effect(state); end
  4185.   end
  4186.  
  4187.   #--------------------------------------------------------------------------
  4188.   # new method: perform_slip_effect
  4189.   #--------------------------------------------------------------------------
  4190.   def perform_slip_effect(state)
  4191.     return if state == nil
  4192.     return unless exist?
  4193.     return unless state.slip_damage
  4194.     hp_dmg = 0; mp_dmg = 0
  4195.     hash = state.slip_effect
  4196.     #---
  4197.     hp_dmg += maxhp * hash[:hp_degen_per] / 100 if hash [:hp_degen_per] != nil
  4198.     hp_dmg += hash[:hp_degen_set] if hash[:hp_degen_set] != nil
  4199.     hp_dmg *= stack(state) if hp_dmg != 0
  4200.     mp_dmg += maxmp * hash[:mp_degen_per] / 100 if hash [:mp_degen_per] != nil
  4201.     mp_dmg += hash[:mp_degen_set] if hash[:mp_degen_set] != nil
  4202.     mp_dmg *= stack(state) if mp_dmg != 0
  4203.     #---
  4204.     hp_dmg = [hp_dmg, @hp - 1].min
  4205.     hp_dmg = 0 if anti_hp_regen if hp_dmg < 0
  4206.     hp_dmg = 0 if anti_hp_degen if hp_dmg > 0
  4207.     mp_dmg = 0 if anti_mp_regen if mp_dmg < 0
  4208.     mp_dmg = 0 if anti_mp_degen if mp_dmg > 0
  4209.     #---
  4210.     if hp_dmg != 0
  4211.       @hp = [[@hp - hp_dmg, maxhp].min, 0].max
  4212.       if hp_dmg > 0
  4213.         rules = "HP_DMG"
  4214.         value = hp_dmg
  4215.         sprint = YEM::BATTLE_ENGINE::POPUP_SETTINGS[:hp_dmg]
  4216.       else
  4217.         rules = "HP_HEAL"
  4218.         value = -hp_dmg
  4219.         sprint = YEM::BATTLE_ENGINE::POPUP_SETTINGS[:hp_heal]
  4220.       end
  4221.       create_popup(value, rules) if $scene.is_a?(Scene_Battle)
  4222.     end
  4223.     if mp_dmg != 0
  4224.       @mp = [[@mp - mp_dmg, maxmp].min, 0].max
  4225.       if mp_dmg > 0
  4226.         rules = "MP_DMG"
  4227.         value = mp_dmg
  4228.         sprint = YEM::BATTLE_ENGINE::POPUP_SETTINGS[:mp_dmg]
  4229.       else
  4230.         rules = "MP_HEAL"
  4231.         value = -mp_dmg
  4232.         sprint = YEM::BATTLE_ENGINE::POPUP_SETTINGS[:mp_heal]
  4233.       end
  4234.       value = sprintf(sprint, value)
  4235.       create_popup(value, rules) if $scene.is_a?(Scene_Battle)
  4236.     end
  4237.   end
  4238.  
  4239.   #--------------------------------------------------------------------------
  4240.   # new method: use_rage?
  4241.   #--------------------------------------------------------------------------
  4242.   def use_rage?
  4243.     for skill in total_skills
  4244.       next if skill == nil
  4245.       return true if skill.rage_skill
  4246.     end
  4247.     return false
  4248.   end
  4249.  
  4250.   #--------------------------------------------------------------------------
  4251.   # new method: max_rage
  4252.   #--------------------------------------------------------------------------
  4253.   def max_rage; return YEM::BATTLE_ENGINE::SKILL_SETTINGS[:max_rage]; end
  4254.  
  4255.   #--------------------------------------------------------------------------
  4256.   # new method: earn_rage
  4257.   #--------------------------------------------------------------------------
  4258.   def earn_rage(user, obj = nil)
  4259.     if user.actor? != actor?
  4260.       value = YEM::BATTLE_ENGINE::SKILL_SETTINGS[:hit_rage_gain]
  4261.       value = rage_modifiers(value)
  4262.       gain_rage(value)
  4263.     end
  4264.     if obj != nil
  4265.       value = obj.rage_target
  4266.       gain_rage(value)
  4267.     end
  4268.     #---
  4269.     if obj == nil
  4270.       value = YEM::BATTLE_ENGINE::SKILL_SETTINGS[:attack_rage_gain]
  4271.     else
  4272.       value = obj.rage_boost
  4273.     end
  4274.     value = user.rage_modifiers(value)
  4275.     user.gain_rage(value)
  4276.   end
  4277.  
  4278.   #--------------------------------------------------------------------------
  4279.   # new method: rage_modifiers
  4280.   #--------------------------------------------------------------------------
  4281.   def rage_modifiers(value)
  4282.     #---
  4283.     if @cache_rage[:per] == nil
  4284.       percent = 100
  4285.       for state in states
  4286.         next if state == nil
  4287.         next if state.rage_boost[:per] == nil
  4288.         percent += state.rage_boost[:per] - 100
  4289.       end
  4290.       @cache_rage[:per] = percent
  4291.     end
  4292.     #---
  4293.     if @cache_rage[:set] == nil
  4294.       modifier = 0
  4295.       for state in states
  4296.         next if state == nil
  4297.         next if state.rage_boost[:set] == nil
  4298.         modifier += state.rage_boost[:set]
  4299.       end
  4300.       @cache_rage[:set] = modifier
  4301.     end
  4302.     #---
  4303.     value = value * @cache_rage[:per] / 100
  4304.     value += @cache_rage[:set]
  4305.     #---
  4306.     return value
  4307.   end
  4308.  
  4309.   #--------------------------------------------------------------------------
  4310.   # new method: gain_rage
  4311.   #--------------------------------------------------------------------------
  4312.   def gain_rage(value = 1)
  4313.     @rage = 0 if @rage == nil
  4314.     @rage = [@rage + value, max_rage].min
  4315.   end
  4316.  
  4317.   #--------------------------------------------------------------------------
  4318.   # new method: lose_rage
  4319.   #--------------------------------------------------------------------------
  4320.   def lose_rage(value = 1)
  4321.     @rage = 0 if @rage == nil
  4322.     @rage = [@rage - value, 0].max
  4323.   end
  4324.  
  4325.   #--------------------------------------------------------------------------
  4326.   # new method: cooldown
  4327.   #--------------------------------------------------------------------------
  4328.   def cooldown(skill_id)
  4329.     skill_id = skill_id.id if skill_id.is_a?(RPG::Skill)
  4330.     @cooldown = {} if @cooldown == nil
  4331.     return @cooldown[skill_id].to_i
  4332.   end
  4333.  
  4334.   #--------------------------------------------------------------------------
  4335.   # new method: make_cooldown
  4336.   #--------------------------------------------------------------------------
  4337.   def make_cooldown(skill_id, value = nil)
  4338.     skill_id = skill_id.id if skill_id.is_a?(RPG::Skill)
  4339.     @cooldown = {} if @cooldown == nil
  4340.     value = $data_skills[skill_id].cooldown if value == nil
  4341.     @cooldown[skill_id] = value
  4342.     #---
  4343.     @cooldown_clockticks = {} if @cooldown_clockticks == nil
  4344.     ctr = 32
  4345.     if $scene.is_a?(Scene_Battle)
  4346.       ctr = YEM::BATTLE_ENGINE::ATB_RULES[:turns_ctr] if $scene.atb?
  4347.       ctr = YEM::BATTLE_ENGINE::CTB_RULES[:turns_ctr] if $scene.ctb?
  4348.     end
  4349.     @cooldown_clockticks[skill_id] = ctr
  4350.   end
  4351.  
  4352.   #--------------------------------------------------------------------------
  4353.   # new method: clear_cooldowns
  4354.   #--------------------------------------------------------------------------
  4355.   def clear_cooldowns; @cooldown = {}; end
  4356.  
  4357.   #--------------------------------------------------------------------------
  4358.   # new method: update_all_cooldown
  4359.   #--------------------------------------------------------------------------
  4360.   def update_all_cooldown
  4361.     @cooldown = {} if @cooldown == nil
  4362.     return if @cooldown == {}
  4363.     for key in @cooldown
  4364.       skill_id = key[0]
  4365.       update_cooldown(skill_id)
  4366.     end
  4367.   end
  4368.  
  4369.   #--------------------------------------------------------------------------
  4370.   # new method: update_cooldown
  4371.   #--------------------------------------------------------------------------
  4372.   def update_cooldown(skill_id)
  4373.     @cooldown = {} if @cooldown == nil
  4374.     return if @cooldown[skill_id] == nil
  4375.     value = 1
  4376.     @cooldown[skill_id] -= value
  4377.     return unless @cooldown[skill_id] <= 0
  4378.     @cooldown.delete(skill_id)
  4379.     @cooldown_clockticks.delete(skill_id)
  4380.   end
  4381.  
  4382.   #--------------------------------------------------------------------------
  4383.   # new method: update_clocktick_cooldown
  4384.   #--------------------------------------------------------------------------
  4385.   def update_clocktick_cooldown
  4386.     return unless $scene.is_a?(Scene_Battle)
  4387.     @cooldown_clockticks = {} if @cooldown_clockticks == nil
  4388.     remove_skills = []
  4389.     ctr = YEM::BATTLE_ENGINE::ATB_RULES[:turns_ctr] if $scene.atb?
  4390.     ctr = YEM::BATTLE_ENGINE::CTB_RULES[:turns_ctr] if $scene.ctb?
  4391.     for key in @cooldown_clockticks
  4392.       skill_id = key[0]; ticks = key[1]
  4393.       if @cooldown_clockticks[skill_id] == nil
  4394.         remove_skills.push(skill_id)
  4395.         next
  4396.       end
  4397.       @cooldown_clockticks[skill_id] = ctr if
  4398.         @cooldown_clockticks[skill_id] == nil
  4399.       @cooldown_clockticks[skill_id] -= 1
  4400.       next unless @cooldown_clockticks[skill_id] <= 0
  4401.       @cooldown_clockticks[skill_id] = ctr
  4402.       update_cooldown(skill_id)
  4403.       $scene.refresh_battle_windows
  4404.       remove_skills.push(skill_id) if cooldown(skill_id) <= 0
  4405.     end
  4406.     #---
  4407.     for skill_id in remove_skills
  4408.       @cooldown_clockticks.delete(skill_id)
  4409.     end
  4410.   end
  4411.  
  4412.   #--------------------------------------------------------------------------
  4413.   # new method: skill_limited?
  4414.   #--------------------------------------------------------------------------
  4415.   def skill_limited?(skill_id)
  4416.     skill_id = skill_id.id if skill_id.is_a?(RPG::Skill)
  4417.     skill = $data_skills[skill_id]
  4418.     return false if skill.limited_use <= 0
  4419.     @limited_use = {} if @limited_use == nil
  4420.     return (@limited_use[skill_id].to_i >= skill.limited_use)
  4421.   end
  4422.  
  4423.   #--------------------------------------------------------------------------
  4424.   # new method: clear_limited_use
  4425.   #--------------------------------------------------------------------------
  4426.   def clear_limited_use; @limited_use = {}; end
  4427.  
  4428.   #--------------------------------------------------------------------------
  4429.   # new method: make_limited
  4430.   #--------------------------------------------------------------------------
  4431.   def make_limited(skill_id, value = 1)
  4432.     skill_id = skill_id.id if skill_id.is_a?(RPG::Skill)
  4433.     return if $data_skills[skill_id].limited_use <= 0
  4434.     @limited_use = {} if @limited_use == nil
  4435.     @limited_use[skill_id] = 0 if @limited_use[skill_id] == nil
  4436.     @limited_use[skill_id] += value
  4437.   end
  4438.  
  4439.   #--------------------------------------------------------------------------
  4440.   # new method: ptb_provided_turns
  4441.   #--------------------------------------------------------------------------
  4442.   def ptb_provided_turns
  4443.     return 0 unless movable?
  4444.     return @cache_ptb[:provided_turns] if @cache_ptb[:provided_turns] != nil
  4445.     result = YEM::BATTLE_ENGINE::PTB_RULES[:provided_turns]
  4446.     #---
  4447.     if self.actor?
  4448.       for equip in equips.compact; result += equip.ptb_bonus; end
  4449.     elsif self.enemy?
  4450.       result = enemy.ptb_turns
  4451.     end
  4452.     if @cache_states[:ptb_bonus] == nil
  4453.       @cache_states[:ptb_bonus] = 0
  4454.       for state in states
  4455.         @cache_states[:ptb_bonus] += state.ptb_bonus
  4456.       end
  4457.     end
  4458.     result += @cache_states[:ptb_bonus]
  4459.     #---
  4460.     @cache_ptb[:provided_turns] = result
  4461.     return @cache_ptb[:provided_turns]
  4462.   end
  4463.  
  4464.   #--------------------------------------------------------------------------
  4465.   # new method: ptb_max_cancel
  4466.   #--------------------------------------------------------------------------
  4467.   def ptb_max_cancel
  4468.     return @cache_ptb[:max_cancel] if @cache_ptb[:max_cancel] != nil
  4469.     result = YEM::BATTLE_ENGINE::PTB_RULES[:max_actor_cancel]
  4470.     #---
  4471.     if self.actor?
  4472.       for equip in equips.compact; result += equip.ptb_max_cancel; end
  4473.     elsif self.enemy?
  4474.       result = enemy.ptb_max_cancel
  4475.     end
  4476.     if @cache_states[:ptb_max_cancel] == nil
  4477.       @cache_states[:ptb_max_cancel] = 0
  4478.       for state in states
  4479.         @cache_states[:ptb_max_cancel] += state.ptb_max_cancel
  4480.       end
  4481.     end
  4482.     result += @cache_states[:ptb_max_cancel]
  4483.     #---
  4484.     @cache_ptb[:max_cancel] = result
  4485.     return @cache_ptb[:max_cancel]
  4486.   end
  4487.  
  4488.   #--------------------------------------------------------------------------
  4489.   # new method: ptb_max_regain
  4490.   #--------------------------------------------------------------------------
  4491.   def ptb_max_regain
  4492.     return @cache_ptb[:max_regain] if @cache_ptb[:max_regain] != nil
  4493.     result = YEM::BATTLE_ENGINE::PTB_RULES[:max_actor_regain]
  4494.     #---
  4495.     if self.actor?
  4496.       for equip in equips.compact; result += equip.ptb_max_regain; end
  4497.     elsif self.enemy?
  4498.       result = enemy.ptb_max_regain
  4499.     end
  4500.     if @cache_states[:ptb_max_regain] == nil
  4501.       @cache_states[:ptb_max_regain] = 0
  4502.       for state in states
  4503.         @cache_states[:ptb_max_regain] += state.ptb_max_regain
  4504.       end
  4505.     end
  4506.     result += @cache_states[:ptb_max_regain]
  4507.     #---
  4508.     @cache_ptb[:max_regain] = result
  4509.     return @cache_ptb[:max_regain]
  4510.   end
  4511.  
  4512.   #--------------------------------------------------------------------------
  4513.   # new method: ptb_obj_effect
  4514.   #--------------------------------------------------------------------------
  4515.   def ptb_obj_effect(battler, obj)
  4516.     return unless $scene.is_a?(Scene_Battle)
  4517.     return unless $scene.ptb?
  4518.     return if obj == nil
  4519.     if obj.ptb_turn_gain > 0
  4520.       battler.action.friends_unit.gain_bonus(nil, obj.ptb_turn_gain, false)
  4521.     end
  4522.     if obj.ptb_turn_loss > 0
  4523.       battler.action.friends_unit.cancel_turn(nil, obj.ptb_turn_loss, false)
  4524.     end
  4525.   end
  4526.  
  4527.   #--------------------------------------------------------------------------
  4528.   # new method: atb_position
  4529.   #--------------------------------------------------------------------------
  4530.   def atb_position
  4531.     @atb_speed = 0 if @atb_speed == nil
  4532.     value = @atb_speed * 300 / $game_troop.atb_max
  4533.     value = [[value, 0].max, 300].min
  4534.     return value
  4535.   end
  4536.  
  4537.   #--------------------------------------------------------------------------
  4538.   # new method: reset_atb_speed
  4539.   #--------------------------------------------------------------------------
  4540.   def reset_atb_speed
  4541.     @atb_speed = 0
  4542.     @atb_speed_bonus = 0
  4543.     action.clear
  4544.     action.atb_queue_down
  4545.     make_action if self.actor? and self.auto_battle
  4546.     return unless self.enemy?
  4547.     make_action
  4548.     action_bonus_speed
  4549.     @turn_count += 1
  4550.   end
  4551.  
  4552.   #--------------------------------------------------------------------------
  4553.   # new method: update_atb_speed
  4554.   #--------------------------------------------------------------------------
  4555.   def update_atb_speed
  4556.     update_clocktick_states
  4557.     update_clocktick_equip
  4558.     update_clocktick_cooldown
  4559.     return if active_battler?
  4560.     return unless movable?
  4561.     return if $game_troop.atb_ready.include?(self)
  4562.     value = self.agi
  4563.     value += @atb_speed_bonus if @atb_speed >= $game_troop.atb_threshold
  4564.     value = [value, Integer(base_agi*$game_troop.atb_min_speed)].max
  4565.     @atb_speed += value
  4566.     confirm_atb_speed
  4567.   end
  4568.  
  4569.   #--------------------------------------------------------------------------
  4570.   # new method: confirm_atb_speed
  4571.   #--------------------------------------------------------------------------
  4572.   def confirm_atb_speed
  4573.     if @atb_speed >= $game_troop.atb_threshold
  4574.       action.atb_guarding = false
  4575.     end
  4576.     return unless @atb_speed >= $game_troop.atb_max
  4577.     $game_troop.atb_ready.push(self)
  4578.   end
  4579.  
  4580.   #--------------------------------------------------------------------------
  4581.   # new method: action_bonus_speed
  4582.   #--------------------------------------------------------------------------
  4583.   def action_bonus_speed
  4584.     action.make_speed
  4585.     value = action.speed
  4586.     value -= self.agi
  4587.     @atb_speed_bonus = value
  4588.   end
  4589.  
  4590.   #--------------------------------------------------------------------------
  4591.   # new method: atb_reached_treshold?
  4592.   #--------------------------------------------------------------------------
  4593.   def atb_reached_treshold?
  4594.     return false unless @atb_speed >= $game_troop.atb_threshold
  4595.     if berserker? or confusion?
  4596.       if !action.attack?
  4597.         action.set_attack
  4598.         group = (actor? and berserker?) ? $game_troop : $game_party
  4599.         size = group.existing_members.size
  4600.         action.target_index = group.existing_members[rand(size)]
  4601.         action.atb_queue_down
  4602.       end
  4603.       return false
  4604.     end
  4605.     return true if action.wait?
  4606.     return true if action.nothing?
  4607.     return false
  4608.   end
  4609.  
  4610.   #--------------------------------------------------------------------------
  4611.   # new method: atb_change_effect
  4612.   #--------------------------------------------------------------------------
  4613.   def atb_change_effect(user, obj = nil)
  4614.     return unless $scene.is_a?(Scene_Battle)
  4615.     return unless $scene.atb?
  4616.     @atb_speed = 0 if @atb_speed == nil
  4617.     if obj == nil
  4618.       @atb_speed += user.atb_change_value
  4619.     else
  4620.       change = $game_troop.atb_max * obj.atb_change_per / 100
  4621.       change += obj.atb_change_set
  4622.       @atb_speed += change
  4623.     end
  4624.     @atb_speed = [[@atb_speed, 0].max, $game_troop.atb_max].min
  4625.     confirm_atb_speed
  4626.   end
  4627.  
  4628.   #--------------------------------------------------------------------------
  4629.   # new method: atb_change_value
  4630.   #--------------------------------------------------------------------------
  4631.   def atb_change_value; return 0; end
  4632.  
  4633.   #--------------------------------------------------------------------------
  4634.   # new method: create_atb_reset
  4635.   #--------------------------------------------------------------------------
  4636.   def create_atb_reset(obj = nil)
  4637.     return unless $scene.is_a?(Scene_Battle)
  4638.     return unless $scene.atb?
  4639.     if obj == nil
  4640.       @atb_reset_speed = 0
  4641.       return
  4642.     end
  4643.     @atb_reset_speed = $game_troop.atb_max * obj.atb_reset / 100
  4644.   end
  4645.  
  4646.   #--------------------------------------------------------------------------
  4647.   # new method: process_atb_reset
  4648.   #--------------------------------------------------------------------------
  4649.   def process_atb_reset
  4650.     @atb_reset_speed = 0 if @atb_reset_speed == nil
  4651.     if @cache_states[:atb_reset_plus] == nil
  4652.       @cache_states[:atb_reset_plus] = 0
  4653.       for state in states
  4654.         next if state == nil
  4655.         @cache_states[:atb_reset_plus] += state.atb_reset_plus
  4656.       end
  4657.     end
  4658.     @atb_reset_speed += @cache_states[:atb_reset_plus]
  4659.     return if @atb_reset_speed == 0
  4660.     speed = $game_troop.atb_max * @atb_reset_speed / 100
  4661.     @atb_speed = [[speed, $game_troop.atb_max].min, 0].max
  4662.   end
  4663.  
  4664.   #--------------------------------------------------------------------------
  4665.   # new method: ctb_active?
  4666.   #--------------------------------------------------------------------------
  4667.   def ctb_active?
  4668.     return false unless $scene.is_a?(Scene_Battle)
  4669.     return ($game_troop.ctb_ready[0] == self)
  4670.   end
  4671.  
  4672.   #--------------------------------------------------------------------------
  4673.   # new method: ctb_ctr
  4674.   #--------------------------------------------------------------------------
  4675.   def ctb_ctr
  4676.     return @ctb_cache if @ctb_cache != nil
  4677.     value = 0
  4678.     @ctb_speed = 0 if @ctb_speed == nil
  4679.     @ctb_prediction = @ctb_speed + ctb_speed_bonus
  4680.     loop do
  4681.       break if @ctb_prediction >= $game_troop.ctb_max
  4682.       value += 1
  4683.       @ctb_prediction += self.agi
  4684.     end
  4685.     @ctb_cache = value
  4686.     return @ctb_cache
  4687.   end
  4688.  
  4689.   #--------------------------------------------------------------------------
  4690.   # new method: ctb_total_speed
  4691.   #--------------------------------------------------------------------------
  4692.   def ctb_total_speed; return @ctb_speed + ctb_speed_bonus; end
  4693.  
  4694.   #--------------------------------------------------------------------------
  4695.   # new method: ctb_speed_bonus
  4696.   #--------------------------------------------------------------------------
  4697.   def ctb_speed_bonus
  4698.     case self.action.kind
  4699.     when 0 # Basic
  4700.       return 0
  4701.     when 1, 2 # Skill
  4702.       obj = self.action.skill if self.action.skill?
  4703.       obj = self.action.item if self.action.item?
  4704.       value = [obj.speed, 0].min
  4705.       value = YEM::BATTLE_ENGINE::CTB_RULES[:speed_rate] * value
  4706.       return Integer(value)
  4707.     end
  4708.     return 0
  4709.   end
  4710.  
  4711.   #--------------------------------------------------------------------------
  4712.   # new method: reset_ctb_speed
  4713.   #--------------------------------------------------------------------------
  4714.   def reset_ctb_speed
  4715.     @ctb_reset_speed = 0 if @ctb_reset_speed == nil
  4716.     @ctb_speed = 0
  4717.     if action.skill? or action.item?
  4718.       obj = action.skill if action.skill?
  4719.       obj = action.item if action.item?
  4720.       if obj.speed > 0
  4721.         multiplier = YEM::BATTLE_ENGINE::CTB_RULES[:speed_rate]
  4722.         @ctb_speed += Integer(obj.speed * multiplier)
  4723.       end
  4724.     end
  4725.     action.clear
  4726.     if @ctb_reset_speed != 0
  4727.       @ctb_speed += $game_troop.ctb_max * @ctb_reset_speed / 100
  4728.     end
  4729.     @ctb_reset_speed = nil
  4730.     return unless self.enemy?
  4731.     make_action
  4732.     @turn_count += 1
  4733.   end
  4734.  
  4735.   #--------------------------------------------------------------------------
  4736.   # new method: update_ctb_speed
  4737.   #--------------------------------------------------------------------------
  4738.   def update_ctb_speed
  4739.     return unless $scene.is_a?(Scene_Battle)
  4740.     update_clocktick_states
  4741.     update_clocktick_equip
  4742.     update_clocktick_cooldown
  4743.     return unless movable?
  4744.     @ctb_speed += self.agi
  4745.     confirm_ctb_speed
  4746.   end
  4747.  
  4748.   #--------------------------------------------------------------------------
  4749.   # new method: confirm_ctb_speed
  4750.   #--------------------------------------------------------------------------
  4751.   def confirm_ctb_speed
  4752.     return unless ctb_total_speed >= $game_troop.ctb_max
  4753.     $game_troop.ctb_ready.push(self)
  4754.     $game_troop.ctb_ready.sort! { |a,b|
  4755.       if a.ctb_ctr != b.ctb_ctr
  4756.         a.ctb_ctr <=> b.ctb_ctr
  4757.       elsif a.ctb_prediction != b.ctb_prediction
  4758.         b.ctb_prediction <=> a.ctb_prediction
  4759.       elsif a.agi != b.agi
  4760.         b.agi <=> a.agi
  4761.       else
  4762.         b.screen_x <=> a.screen_x
  4763.       end }
  4764.   end
  4765.  
  4766.   #--------------------------------------------------------------------------
  4767.   # new method: update_clocktick_states
  4768.   #--------------------------------------------------------------------------
  4769.   def update_clocktick_states
  4770.     return unless $scene.is_a?(Scene_Battle)
  4771.     @state_clockticks = {} if @state_clockticks == nil
  4772.     remove_states = []
  4773.     ctr = YEM::BATTLE_ENGINE::ATB_RULES[:turns_ctr] if $scene.atb?
  4774.     ctr = YEM::BATTLE_ENGINE::CTB_RULES[:turns_ctr] if $scene.ctb?
  4775.     for key in @state_clockticks
  4776.       state_id = key[0]; ticks = key[1]
  4777.       next if state_id == 1
  4778.       next if rand(100) >= $data_states[state_id].auto_release_prob
  4779.       if @state_clockticks[state_id] == nil
  4780.         remove_states.push(state_id)
  4781.         next
  4782.       end
  4783.       @state_clockticks[state_id] -= 1
  4784.       next unless @state_clockticks[state_id] <= 0
  4785.       perform_slip_effect($data_states[state_id])
  4786.       next if @state_turns[state_id] == nil
  4787.       @state_turns[state_id] -= 1
  4788.       @state_clockticks[state_id] = ctr
  4789.       lunatic_status_effects($data_states[state_id], :while)
  4790.       if @state_turns[state_id] < 0
  4791.         remove_state(state_id)
  4792.         @removed_states.push(state_id)
  4793.         remove_states.push(state_id)
  4794.         lunatic_status_effects(state_id, :leave)
  4795.         $scene.pause_atb(true)
  4796.         $scene.display_state_changes(self) if exist?
  4797.         clear_state_tags
  4798.         $scene.pause_atb(false)
  4799.         $scene.refresh_battle_windows
  4800.       end
  4801.       @update_states = true
  4802.     end
  4803.     #---
  4804.     for state_id in remove_states
  4805.       next if state?(state_id)
  4806.       @state_clockticks.delete(state_id)
  4807.       @update_states = true
  4808.     end
  4809.   end
  4810.  
  4811.   #--------------------------------------------------------------------------
  4812.   # new method: update_clocktick_equip
  4813.   #--------------------------------------------------------------------------
  4814.   def update_clocktick_equip
  4815.     return unless $scene.is_a?(Scene_Battle)
  4816.     return unless self.actor?
  4817.     return if @equip_clocktick == nil
  4818.     @equip_clocktick -= 1
  4819.     return unless @equip_clocktick <= 0
  4820.     @equip_cooldown -= 1
  4821.     if @equip_cooldown > 0
  4822.       @equip_clocktick = YEM::BATTLE_ENGINE::ATB_RULES[:turns_ctr]
  4823.     else
  4824.       @equip_clocktick = nil
  4825.       @update_commands = true
  4826.     end
  4827.   end
  4828.  
  4829.   #--------------------------------------------------------------------------
  4830.   # new method: ctb_change_effect
  4831.   #--------------------------------------------------------------------------
  4832.   def ctb_change_effect(user, obj = nil)
  4833.     return unless $scene.is_a?(Scene_Battle)
  4834.     return unless $scene.ctb?
  4835.     @ctb_speed = 0 if @ctb_speed == nil
  4836.     if obj == nil
  4837.       @ctb_speed += user.ctb_change_value
  4838.     else
  4839.       change = $game_troop.ctb_max * obj.ctb_change_per / 100
  4840.       change += obj.ctb_change_set
  4841.       @ctb_speed += change
  4842.     end
  4843.     @ctb_speed = [@ctb_speed, 0].max
  4844.     confirm_ctb_speed
  4845.   end
  4846.  
  4847.   #--------------------------------------------------------------------------
  4848.   # new method: ctb_change_value
  4849.   #--------------------------------------------------------------------------
  4850.   def ctb_change_value; return 0; end
  4851.  
  4852.   #--------------------------------------------------------------------------
  4853.   # new method: create_ctb_reset
  4854.   #--------------------------------------------------------------------------
  4855.   def create_ctb_reset(obj = nil)
  4856.     return unless $scene.is_a?(Scene_Battle)
  4857.     return unless $scene.ctb?
  4858.     if obj == nil
  4859.       @ctb_reset_speed = 0
  4860.       return
  4861.     end
  4862.     @ctb_reset_speed = obj.ctb_reset
  4863.   end
  4864.  
  4865.   #--------------------------------------------------------------------------
  4866.   # new method: process_ctb_reset
  4867.   #--------------------------------------------------------------------------
  4868.   def process_ctb_reset
  4869.     @ctb_reset_speed = 0 if @ctb_reset_speed == nil
  4870.     if @cache_states[:ctb_reset_plus] == nil
  4871.       @cache_states[:ctb_reset_plus] = 0
  4872.       for state in states
  4873.         next if state == nil
  4874.         @cache_states[:ctb_reset_plus] += state.ctb_reset_plus
  4875.       end
  4876.     end
  4877.     @ctb_reset_speed += @cache_states[:ctb_reset_plus]
  4878.     return if @ctb_reset_speed == 0
  4879.     speed = $game_troop.ctb_max * @ctb_reset_speed / 100
  4880.     @ctb_speed = [[speed, $game_troop.ctb_max].min, 0].max
  4881.   end
  4882.  
  4883.   #--------------------------------------------------------------------------
  4884.   # anti-crash method: dex, dex=, res, res=
  4885.   #--------------------------------------------------------------------------
  4886.   unless $imported["DEX Stat"]
  4887.     def dex; return agi; end
  4888.     def dex=(value); agi=(value); end
  4889.   end
  4890.   unless $imported["RES Stat"]
  4891.     def res; return spi; end
  4892.     def res=(value); spi=(value); end
  4893.   end
  4894.  
  4895. end # Game_Battler
  4896.  
  4897. #===============================================================================
  4898. # Game_BattleAction
  4899. #===============================================================================
  4900.  
  4901. class Game_BattleAction
  4902.  
  4903.   #--------------------------------------------------------------------------
  4904.   # public instance variables
  4905.   #--------------------------------------------------------------------------
  4906.   attr_accessor :atb_guarding
  4907.   attr_accessor :atb_queue_kind
  4908.   attr_accessor :atb_queue_basic
  4909.   attr_accessor :atb_queue_target
  4910.   attr_accessor :ctb_guarding
  4911.   attr_accessor :ctb_guarding_queue
  4912.   attr_accessor :ptb_guarding
  4913.  
  4914.   #--------------------------------------------------------------------------
  4915.   # alias method: clear
  4916.   #--------------------------------------------------------------------------
  4917.   alias clear_battleaction_bem clear unless $@
  4918.   def clear
  4919.     clear_battleaction_bem if allow_clear?
  4920.     @basic = 3
  4921.   end
  4922.  
  4923.   #--------------------------------------------------------------------------
  4924.   # new method: allow_clear?
  4925.   #--------------------------------------------------------------------------
  4926.   def allow_clear?
  4927.     if $scene.is_a?(Scene_Battle) and $scene.atb?
  4928.       battler.atb_speed = 0 if battler.atb_speed == nil
  4929.       return false if battler.atb_speed >= $game_troop.atb_threshold
  4930.       return true
  4931.     end
  4932.     return true
  4933.   end
  4934.  
  4935.   #--------------------------------------------------------------------------
  4936.   # alias method: set_attack
  4937.   #--------------------------------------------------------------------------
  4938.   alias set_attack_bem set_attack unless $@
  4939.   def set_attack
  4940.     if $scene.is_a?(Scene_Battle) and $scene.atb? and !@battler.make_auto_skill
  4941.       @atb_queue_kind = 0
  4942.       @atb_queue_basic = 0
  4943.       return
  4944.     end
  4945.     set_attack_bem
  4946.   end
  4947.  
  4948.   #--------------------------------------------------------------------------
  4949.   # alias method: set_guard
  4950.   #--------------------------------------------------------------------------
  4951.   alias set_guard_bem set_guard unless $@
  4952.   def set_guard
  4953.     if $scene.is_a?(Scene_Battle) and $scene.ptb?
  4954.       @ptb_guarding = true
  4955.       return
  4956.     elsif $scene.is_a?(Scene_Battle) and $scene.atb?
  4957.       @atb_queue_kind = 0
  4958.       @atb_queue_basic = 1
  4959.       return
  4960.     elsif $scene.is_a?(Scene_Battle) and $scene.ctb?
  4961.       @ctb_guarding_queue = true
  4962.       return
  4963.     end
  4964.     set_guard_bem
  4965.   end
  4966.  
  4967.   #--------------------------------------------------------------------------
  4968.   # alias method: guard?
  4969.   #--------------------------------------------------------------------------
  4970.   alias guard_questionmark_bem guard? unless $@
  4971.   def guard?
  4972.     return true if @ptb_guarding
  4973.     return @atb_guarding if $scene.is_a?(Scene_Battle) and $scene.atb?
  4974.     return @ctb_guarding if $scene.is_a?(Scene_Battle) and $scene.ctb?
  4975.     return guard_questionmark_bem
  4976.   end
  4977.  
  4978.   #--------------------------------------------------------------------------
  4979.   # new method: set_escape
  4980.   #--------------------------------------------------------------------------
  4981.   def set_escape
  4982.     if $scene.is_a?(Scene_Battle) and $scene.atb?
  4983.       @atb_queue_kind = 0
  4984.       @atb_queue_basic = 2
  4985.       return
  4986.     end
  4987.     @kind = 0
  4988.     @basic = 2
  4989.   end
  4990.  
  4991.   #--------------------------------------------------------------------------
  4992.   # new method: escape?
  4993.   #--------------------------------------------------------------------------
  4994.   def escape?; return (@kind == 0 and @basic == 2); end
  4995.  
  4996.   #--------------------------------------------------------------------------
  4997.   # alias method: set_skill
  4998.   #--------------------------------------------------------------------------
  4999.   alias set_skill_bem set_skill unless $@
  5000.   def set_skill(skill_id)
  5001.     if $scene.is_a?(Scene_Battle) and $scene.atb? and !@battler.make_auto_skill
  5002.       @atb_queue_kind = 1
  5003.       @atb_queue_basic = skill_id
  5004.       return
  5005.     end
  5006.     set_skill_bem(skill_id)
  5007.   end
  5008.  
  5009.   #--------------------------------------------------------------------------
  5010.   # alias method: set_item
  5011.   #--------------------------------------------------------------------------
  5012.   alias set_item_bem set_item unless $@
  5013.   def set_item(item_id)
  5014.     if $scene.is_a?(Scene_Battle) and $scene.atb?
  5015.       @atb_queue_kind = 2
  5016.       @atb_queue_basic = item_id
  5017.       return
  5018.     end
  5019.     set_item_bem(item_id)
  5020.   end
  5021.  
  5022.   #--------------------------------------------------------------------------
  5023.   # new method: wait?
  5024.   #--------------------------------------------------------------------------
  5025.   def wait?
  5026.     return true if nothing?
  5027.     return (@kind == 0 and @basic == 3)
  5028.   end
  5029.  
  5030.   #--------------------------------------------------------------------------
  5031.   # new method: atb_queue_down
  5032.   #--------------------------------------------------------------------------
  5033.   def atb_queue_down
  5034.     return unless $scene.is_a?(Scene_Battle)
  5035.     return unless $scene.atb?
  5036.     return unless wait? or battler.atb_speed <= $game_troop.atb_threshold
  5037.     @kind = @atb_queue_kind
  5038.     case @kind
  5039.     when 0
  5040.       @basic = @atb_queue_basic
  5041.     when 1
  5042.       @skill_id = @atb_queue_basic
  5043.     when 2
  5044.       @item_id = @atb_queue_basic
  5045.     end
  5046.     @target_index = @atb_queue_target
  5047.     battler.action_bonus_speed
  5048.     @atb_queue_kind = 0
  5049.     @atb_queue_basic = 3
  5050.     @atb_queue_target = 0
  5051.     if $scene.is_a?(Scene_Battle)
  5052.       return if $scene.status_window == nil
  5053.       $scene.status_window.battle_refresh_call = true
  5054.     end
  5055.   end
  5056.  
  5057.   #--------------------------------------------------------------------------
  5058.   # overwrite method: valid?
  5059.   #--------------------------------------------------------------------------
  5060.   def valid?
  5061.     return false if nothing?
  5062.     return true if @forcing
  5063.     return false unless battler.movable?
  5064.     if skill?
  5065.       return false unless battler.skill_can_use?(skill)
  5066.     elsif item?
  5067.       return false unless battler.item_can_use?(item)
  5068.     end
  5069.     return true
  5070.   end
  5071.  
  5072.   #--------------------------------------------------------------------------
  5073.   # overwrite method: make_speed
  5074.   #--------------------------------------------------------------------------
  5075.   def make_speed
  5076.     @speed = battler.agi
  5077.     @speed += skill.speed if skill?
  5078.     @speed += item.speed if item?
  5079.     @speed += guard_speed if guard?
  5080.     @speed += fast_attack_speed if battler.fast_attack
  5081.     @speed = -4444 if battler.dead?
  5082.   end
  5083.  
  5084.   #--------------------------------------------------------------------------
  5085.   # new method: guard_speed
  5086.   #--------------------------------------------------------------------------
  5087.   def guard_speed; return 2000; end
  5088.  
  5089.   #--------------------------------------------------------------------------
  5090.   # new method: fast_attack_speed
  5091.   #--------------------------------------------------------------------------
  5092.   def fast_attack_speed; return 1000; end
  5093.  
  5094.   #--------------------------------------------------------------------------
  5095.   # new method: target_index=
  5096.   #--------------------------------------------------------------------------
  5097.   def target_index=(value)
  5098.     if $scene.atb?
  5099.       @atb_queue_target = value
  5100.       return
  5101.     end
  5102.     @target_index = value
  5103.   end
  5104.  
  5105.   #--------------------------------------------------------------------------
  5106.   # overwrite method: make_obj_targets
  5107.   #--------------------------------------------------------------------------
  5108.   def make_obj_targets(obj)
  5109.     targets = custom_battle_targets(obj)
  5110.     for target in targets
  5111.       next if target == nil
  5112.       group = target.actor? ? $game_party : $game_troop
  5113.       targets += group.area_targets(target, obj)
  5114.     end
  5115.     return targets
  5116.   end
  5117.  
  5118. end # Game_BattleAction
  5119.  
  5120. #===============================================================================
  5121. # Game_Actor
  5122. #===============================================================================
  5123.  
  5124. class Game_Actor < Game_Battler
  5125.  
  5126.   #--------------------------------------------------------------------------
  5127.   # public instance variables
  5128.   #--------------------------------------------------------------------------
  5129.   attr_accessor :actor_id
  5130.   attr_accessor :battle_command_index
  5131.   attr_accessor :equip_cooldown
  5132.  
  5133.   #--------------------------------------------------------------------------
  5134.   # alias method: setup
  5135.   #--------------------------------------------------------------------------
  5136.   alias setup_game_actor_bem setup unless $@
  5137.   def setup(actor_id)
  5138.     setup_game_actor_bem(actor_id)
  5139.     @cooldown = {}
  5140.     @limited_use = {}
  5141.     @state_origin = {}
  5142.     @battle_command_index = 0
  5143.     @equip_cooldown = 0
  5144.     @bonus_element_affinity = nil
  5145.     @bonus_state_affinity = nil
  5146.     create_affinity_bonus
  5147.   end
  5148.  
  5149.   #--------------------------------------------------------------------------
  5150.   # alias method: change_equip
  5151.   #--------------------------------------------------------------------------
  5152.   alias change_equip_bem change_equip unless $@
  5153.   def change_equip(equip_type, item, test = false)
  5154.     change_equip_bem(equip_type, item, test)
  5155.     clear_battle_cache
  5156.     if $game_temp.in_battle
  5157.       @update_states = true
  5158.       @update_maxhp = true
  5159.       @update_maxmp = true
  5160.       @update_commands = true
  5161.     end
  5162.   end
  5163.  
  5164.   #--------------------------------------------------------------------------
  5165.   # overwrite method: element_rate
  5166.   #--------------------------------------------------------------------------
  5167.   def element_rate(element_id)
  5168.     if @cache_element_rate[element_id] != nil and $scene.is_a?(Scene_Battle)
  5169.       return @cache_element_rate[element_id]
  5170.     end
  5171.     rank = apply_element_rank(element_id)
  5172.     result = element_rate_table(element_id, rank)
  5173.     for armor in armors.compact
  5174.       result /= 2 if armor.element_set.include?(element_id)
  5175.     end
  5176.     for state in states
  5177.       result /= 2 if state.element_set.include?(element_id)
  5178.     end
  5179.     result
  5180.     @cache_element_rate[element_id] = result
  5181.     return @cache_element_rate[element_id]
  5182.   end
  5183.  
  5184.   #--------------------------------------------------------------------------
  5185.   # overwrite method: state_probability
  5186.   #--------------------------------------------------------------------------
  5187.   def state_probability(state_id)
  5188.     if @cache_state_rate[state_id] != nil and $scene.is_a?(Scene_Battle)
  5189.       rate = element_apply_state_rate(@cache_state_rate[state_id])
  5190.       return rate
  5191.     end
  5192.     if $data_states[state_id].nonresistance
  5193.       result = 100
  5194.     else
  5195.       rank = apply_state_rank(state_id)
  5196.       result = state_probability_table(state_id, rank)
  5197.     end
  5198.     @cache_state_rate[state_id] = result
  5199.     rate = element_apply_state_rate(@cache_state_rate[state_id])
  5200.     return rate
  5201.   end
  5202.  
  5203.   #--------------------------------------------------------------------------
  5204.   # alias method: element_set
  5205.   #--------------------------------------------------------------------------
  5206.   alias element_set_actor_esa element_set unless $@
  5207.   def element_set
  5208.     return @cache_element_set if @cache_element_set != nil
  5209.     result = element_set_actor_esa
  5210.     #---
  5211.     for equip in equips.compact
  5212.       result += equip.attack_element
  5213.     end
  5214.     #---
  5215.     for state in states
  5216.       result += state.attack_element
  5217.     end
  5218.     #---
  5219.     @cache_element_set = result.uniq
  5220.     return @cache_element_set
  5221.   end
  5222.  
  5223.   #--------------------------------------------------------------------------
  5224.   # alias method: plus_state_set
  5225.   #--------------------------------------------------------------------------
  5226.   alias plus_state_set_actor_esa plus_state_set unless $@
  5227.   def plus_state_set
  5228.     return @cache_state_set if @cache_state_set != nil
  5229.     result = plus_state_set_actor_esa
  5230.     #---
  5231.     for equip in equips.compact
  5232.       result += equip.attack_state
  5233.     end
  5234.     #---
  5235.     for state in states
  5236.       result += state.attack_state
  5237.     end
  5238.     #---
  5239.     @cache_state_set = result.uniq
  5240.     return @cache_state_set
  5241.   end
  5242.  
  5243.   #--------------------------------------------------------------------------
  5244.   # alias method: hit
  5245.   #--------------------------------------------------------------------------
  5246.   alias game_actor_hit_bem hit unless $@
  5247.   def hit
  5248.     clear_battle_cache if @cache_params == nil
  5249.     if $scene.is_a?(Scene_Battle)
  5250.       return @cache_params[:hit] if @cache_params[:hit] != nil
  5251.     end
  5252.     #---
  5253.     n = game_actor_hit_bem
  5254.     for state in states
  5255.       stack(state).times do
  5256.         n = n * state.hit_rate / 100.0
  5257.       end
  5258.     end
  5259.     for state in states
  5260.       next if state.hit_set == 0
  5261.       n += state.hit_set * stack(state)
  5262.     end
  5263.     #---
  5264.     @cache_params[:hit] = [Integer(n), 0].max
  5265.     return @cache_params[:hit]
  5266.   end
  5267.  
  5268.   #--------------------------------------------------------------------------
  5269.   # alias method: eva
  5270.   #--------------------------------------------------------------------------
  5271.   alias game_actor_eva_bem eva unless $@
  5272.   def eva
  5273.     clear_battle_cache if @cache_params == nil
  5274.     if $scene.is_a?(Scene_Battle)
  5275.       return @cache_params[:eva] if @cache_params[:eva] != nil
  5276.     end
  5277.     #---
  5278.     n = game_actor_eva_bem
  5279.     for state in states
  5280.       stack(state).times do
  5281.         n = n * state.eva_rate / 100.0
  5282.       end
  5283.     end
  5284.     for state in states
  5285.       next if state.eva_set == 0
  5286.       n += state.eva_set * stack(state)
  5287.     end
  5288.     #---
  5289.     @cache_params[:eva] = [Integer(n), 0].max
  5290.     return @cache_params[:eva]
  5291.   end
  5292.  
  5293.   #--------------------------------------------------------------------------
  5294.   # alias method: cri
  5295.   #--------------------------------------------------------------------------
  5296.   alias game_actor_cri_bem cri unless $@
  5297.   def cri
  5298.     clear_battle_cache if @cache_params == nil
  5299.     if $scene.is_a?(Scene_Battle)
  5300.       return @cache_params[:cri] if @cache_params[:cri] != nil
  5301.     end
  5302.     #---
  5303.     n = game_actor_cri_bem
  5304.     for state in states
  5305.       stack(state).times do
  5306.         n = n * state.cri_rate / 100.0
  5307.       end
  5308.     end
  5309.     for state in states
  5310.       next if state.cri_set == 0
  5311.       n += state.cri_set * stack(state)
  5312.     end
  5313.     #---
  5314.     @cache_params[:cri] = [Integer(n), 0].max
  5315.     return @cache_params[:cri]
  5316.   end
  5317.  
  5318.   #--------------------------------------------------------------------------
  5319.   # alias method: odds
  5320.   #--------------------------------------------------------------------------
  5321.   alias game_actor_odds_bem odds unless $@
  5322.   def odds
  5323.     clear_battle_cache if @cache_params == nil
  5324.     if $scene.is_a?(Scene_Battle)
  5325.       return @cache_params[:odds] if @cache_params[:odds] != nil
  5326.     end
  5327.     #---
  5328.     n = game_actor_odds_bem
  5329.     for state in states
  5330.       stack(state).times do
  5331.         n = n * state.odds_rate / 100.0
  5332.       end
  5333.     end
  5334.     for state in states
  5335.       next if state.odds_set == 0
  5336.       n += state.odds_set * stack(state)
  5337.     end
  5338.     #---
  5339.     @cache_params[:odds] = [Integer(n), 1].max
  5340.     return @cache_params[:odds]
  5341.   end
  5342.  
  5343.   #--------------------------------------------------------------------------
  5344.   # alias method: super_guard
  5345.   #--------------------------------------------------------------------------
  5346.   alias super_guard_bem super_guard unless $@
  5347.   def super_guard
  5348.     return true if traits.include?(:super_guard)
  5349.     return super_guard_bem
  5350.   end
  5351.  
  5352.   #--------------------------------------------------------------------------
  5353.   # overwrite method: pharmacology
  5354.   #--------------------------------------------------------------------------
  5355.   alias pharmacology_bem pharmacology unless $@
  5356.   def pharmacology
  5357.     return true if traits.include?(:pharmacology)
  5358.     return pharmacology_bem
  5359.   end
  5360.  
  5361.   #--------------------------------------------------------------------------
  5362.   # alias method: fast_attack
  5363.   #--------------------------------------------------------------------------
  5364.   alias fast_attack_bem fast_attack unless $@
  5365.   def fast_attack
  5366.     return true if traits.include?(:fast_attack)
  5367.     return fast_attack_bem
  5368.   end
  5369.  
  5370.   #--------------------------------------------------------------------------
  5371.   # alias method: dual_attack
  5372.   #--------------------------------------------------------------------------
  5373.   alias dual_attack_bem dual_attack unless $@
  5374.   def dual_attack
  5375.     return true if traits.include?(:dual_attack)
  5376.     return dual_attack_bem
  5377.   end
  5378.  
  5379.   #--------------------------------------------------------------------------
  5380.   # alias method: prevent_critical
  5381.   #--------------------------------------------------------------------------
  5382.   alias prevent_critical_bem prevent_critical unless $@
  5383.   def prevent_critical
  5384.     return true if traits.include?(:prevent_critical)
  5385.     return prevent_critical_bem
  5386.   end
  5387.  
  5388.   #--------------------------------------------------------------------------
  5389.   # alias method: half_mp_cost
  5390.   #--------------------------------------------------------------------------
  5391.   alias half_mp_cost_bem half_mp_cost unless $@
  5392.   def half_mp_cost
  5393.     return true if traits.include?(:half_mp_cost)
  5394.     return half_mp_cost_bem
  5395.   end
  5396.  
  5397.   #--------------------------------------------------------------------------
  5398.   # alias method: double_exp_gain
  5399.   #--------------------------------------------------------------------------
  5400.   alias double_exp_gain_bem double_exp_gain unless $@
  5401.   def double_exp_gain
  5402.     return true if traits.include?(:double_exp_gain)
  5403.     return double_exp_gain_bem
  5404.   end
  5405.  
  5406.   #--------------------------------------------------------------------------
  5407.   # alias method: auto_hp_recover
  5408.   #--------------------------------------------------------------------------
  5409.   alias auto_hp_recover_bem auto_hp_recover unless $@
  5410.   def auto_hp_recover
  5411.     return true if traits.include?(:auto_hp_recover)
  5412.     return auto_hp_recover_bem
  5413.   end
  5414.  
  5415.   #--------------------------------------------------------------------------
  5416.   # overwrite method: skill_can_use?
  5417.   #--------------------------------------------------------------------------
  5418.   def skill_can_use?(skill); return super(skill); end
  5419.  
  5420.   #--------------------------------------------------------------------------
  5421.   # new method: item_can_use?
  5422.   #--------------------------------------------------------------------------
  5423.   def item_can_use?(item)
  5424.     return false if item == nil
  5425.     return false if item.pharmacology_only and !pharmacology
  5426.     return false if item.restrict[:actors].include?(@actor_id)
  5427.     return false if item.restrict[:classes].include?(@class_id)
  5428.     return false if item_restriction?(item)
  5429.     return action.friends_unit.item_can_use?(item)
  5430.   end
  5431.  
  5432.   #--------------------------------------------------------------------------
  5433.   # alias method: make_action
  5434.   #--------------------------------------------------------------------------
  5435.   alias make_action_bem make_action unless $@
  5436.   def make_action
  5437.     @make_auto_skill = true
  5438.     make_action_bem
  5439.     @make_auto_skill = nil
  5440.     action_bonus_speed if $scene.is_a?(Scene_Battle) and $scene.atb?
  5441.   end
  5442.  
  5443.   #--------------------------------------------------------------------------
  5444.   # new method: attack_formulas
  5445.   #--------------------------------------------------------------------------
  5446.   def attack_formulas
  5447.     result = []
  5448.     for weapon in weapons.compact
  5449.       result = weapon.damage_formula
  5450.       break
  5451.     end
  5452.     result = ["ATK WEAPON"] if result == []
  5453.     return result
  5454.   end
  5455.  
  5456.   #--------------------------------------------------------------------------
  5457.   # new method: attack_vocab
  5458.   #--------------------------------------------------------------------------
  5459.   def attack_vocab
  5460.     return weapons.compact[0].attack_vocab if weapons.compact != []
  5461.     return Vocab.attack
  5462.   end
  5463.  
  5464.   #--------------------------------------------------------------------------
  5465.   # new method: attack_setup_actions
  5466.   #--------------------------------------------------------------------------
  5467.   def attack_setup_actions
  5468.     return weapons.compact[0].setup_action_list if weapons.compact != []
  5469.     return super
  5470.   end
  5471.  
  5472.   #--------------------------------------------------------------------------
  5473.   # new method: attack_whole_actions
  5474.   #--------------------------------------------------------------------------
  5475.   def attack_whole_actions
  5476.     return weapons.compact[0].whole_action_list if weapons.compact != []
  5477.     return super
  5478.   end
  5479.  
  5480.   #--------------------------------------------------------------------------
  5481.   # new method: attack_target_actions
  5482.   #--------------------------------------------------------------------------
  5483.   def attack_target_actions
  5484.     return weapons.compact[0].target_action_list if weapons.compact != []
  5485.     return super
  5486.   end
  5487.  
  5488.   #--------------------------------------------------------------------------
  5489.   # new method: attack_follow_actions
  5490.   #--------------------------------------------------------------------------
  5491.   def attack_follow_actions
  5492.     return weapons.compact[0].follow_action_list if weapons.compact != []
  5493.     return super
  5494.   end
  5495.  
  5496.   #--------------------------------------------------------------------------
  5497.   # new method: attack_finish_actions
  5498.   #--------------------------------------------------------------------------
  5499.   def attack_finish_actions
  5500.     return weapons.compact[0].finish_action_list if weapons.compact != []
  5501.     return super
  5502.   end
  5503.  
  5504.   #--------------------------------------------------------------------------
  5505.   # new method: guard_vocab
  5506.   #--------------------------------------------------------------------------
  5507.   def guard_vocab
  5508.     for armor in armors.compact
  5509.       next unless armor.kind == 0
  5510.       return armor.guard_vocab
  5511.     end
  5512.     return Vocab.guard
  5513.   end
  5514.  
  5515.   #--------------------------------------------------------------------------
  5516.   # new method: guard_actions
  5517.   #--------------------------------------------------------------------------
  5518.   def guard_actions
  5519.     for armor in armors.compact
  5520.       next unless armor.kind == 0
  5521.       return armor.guard_action_list
  5522.     end
  5523.     return super
  5524.   end
  5525.  
  5526.   #--------------------------------------------------------------------------
  5527.   # new method: skill_vocab
  5528.   #--------------------------------------------------------------------------
  5529.   def skill_vocab
  5530.     return self.class.skill_name if self.class.skill_name_valid
  5531.     return Vocab.skill
  5532.   end
  5533.  
  5534.   #--------------------------------------------------------------------------
  5535.   # new method: total_skills
  5536.   #--------------------------------------------------------------------------
  5537.   def total_skills
  5538.     result = skills
  5539.     return result
  5540.   end
  5541.  
  5542.   #--------------------------------------------------------------------------
  5543.   # new method: confirm_atb_speed
  5544.   #--------------------------------------------------------------------------
  5545.   def confirm_atb_speed
  5546.     if atb_reached_treshold?
  5547.       if auto_battle
  5548.         make_action
  5549.         action_bonus_speed
  5550.       else
  5551.         @atb_speed = $game_troop.atb_threshold
  5552.         return
  5553.       end
  5554.     end
  5555.     super
  5556.   end
  5557.  
  5558.   #--------------------------------------------------------------------------
  5559.   # new method: atb_change_value
  5560.   #--------------------------------------------------------------------------
  5561.   def atb_change_value
  5562.     result = 0
  5563.     percent = 0
  5564.     for weapon in weapons.compact
  5565.       percent += weapon.atb_change_per
  5566.       result += weapon.atb_change_set
  5567.     end
  5568.     result += $game_troop.atb_max * percent / 100
  5569.     return result
  5570.   end
  5571.  
  5572.   #--------------------------------------------------------------------------
  5573.   # new method: create_atb_reset
  5574.   #--------------------------------------------------------------------------
  5575.   def create_atb_reset(obj = nil)
  5576.     if obj == nil
  5577.       @atb_reset_speed = 0
  5578.       for weapon in weapons.compact
  5579.         @atb_reset_speed += weapon.atb_reset
  5580.       end
  5581.       return
  5582.     end
  5583.     super(obj)
  5584.   end
  5585.  
  5586.   #--------------------------------------------------------------------------
  5587.   # new method: process_atb_reset
  5588.   #--------------------------------------------------------------------------
  5589.   def process_atb_reset
  5590.     @atb_reset_speed = 0 if @atb_reset_speed == nil
  5591.     for equip in equips.compact
  5592.       @atb_reset_speed += equip.atb_reset_plus
  5593.     end
  5594.     super
  5595.   end
  5596.  
  5597.   #--------------------------------------------------------------------------
  5598.   # new method: ctb_change_value
  5599.   #--------------------------------------------------------------------------
  5600.   def ctb_change_value
  5601.     result = 0
  5602.     percent = 0
  5603.     for weapon in weapons.compact
  5604.       percent += weapon.ctb_change_per
  5605.       result += weapon.ctb_change_set
  5606.     end
  5607.     result += $game_troop.ctb_max * percent / 100
  5608.     return result
  5609.   end
  5610.  
  5611.   #--------------------------------------------------------------------------
  5612.   # new method: create_ctb_reset
  5613.   #--------------------------------------------------------------------------
  5614.   def create_ctb_reset(obj = nil)
  5615.     if obj == nil
  5616.       @ctb_reset_speed = 0
  5617.       for weapon in weapons.compact
  5618.         @ctb_reset_speed += weapon.ctb_reset
  5619.       end
  5620.       return
  5621.     end
  5622.     super(obj)
  5623.   end
  5624.  
  5625.   #--------------------------------------------------------------------------
  5626.   # new method: process_ctb_reset
  5627.   #--------------------------------------------------------------------------
  5628.   def process_ctb_reset
  5629.     @ctb_reset_speed = 0 if @ctb_reset_speed == nil
  5630.     for equip in equips.compact
  5631.       @ctb_reset_speed += equip.ctb_reset_plus
  5632.     end
  5633.     super
  5634.   end
  5635.  
  5636. end # Game_Actor
  5637.  
  5638. #===============================================================================
  5639. # Game_Enemy
  5640. #===============================================================================
  5641.  
  5642. class Game_Enemy < Game_Battler
  5643.  
  5644.   #--------------------------------------------------------------------------
  5645.   # new method: enemy?
  5646.   #--------------------------------------------------------------------------
  5647.   def enemy?; return true; end
  5648.  
  5649.   #--------------------------------------------------------------------------
  5650.   # alias method: hit
  5651.   #--------------------------------------------------------------------------
  5652.   alias game_enemy_hit_bem hit unless $@
  5653.   def hit
  5654.     clear_battle_cache if @cache_params == nil
  5655.     return @cache_params[:hit] if @cache_params[:hit] != nil
  5656.     #---
  5657.     n = game_enemy_hit_bem
  5658.     for state in states
  5659.       stack(state).times do
  5660.         n = n * state.hit_rate / 100.0
  5661.       end
  5662.     end
  5663.     for state in states
  5664.       next if state.hit_set == 0
  5665.       n += state.hit_set * stack(state)
  5666.     end
  5667.     #---
  5668.     @cache_params[:hit] = [Integer(n), 0].max
  5669.     return @cache_params[:hit]
  5670.   end
  5671.  
  5672.   #--------------------------------------------------------------------------
  5673.   # alias method: eva
  5674.   #--------------------------------------------------------------------------
  5675.   alias game_enemy_eva_bem eva unless $@
  5676.   def eva
  5677.     clear_battle_cache if @cache_params == nil
  5678.     return @cache_params[:eva] if @cache_params[:eva] != nil
  5679.     #---
  5680.     n = game_enemy_eva_bem
  5681.     for state in states
  5682.       stack(state).times do
  5683.         n = n * state.eva_rate / 100.0
  5684.       end
  5685.     end
  5686.     for state in states
  5687.       next if state.eva_set == 0
  5688.       n += state.eva_set * stack(state)
  5689.     end
  5690.     #---
  5691.     @cache_params[:eva] = [Integer(n), 0].max
  5692.     return @cache_params[:eva]
  5693.   end
  5694.  
  5695.   #--------------------------------------------------------------------------
  5696.   # alias method: cri
  5697.   #--------------------------------------------------------------------------
  5698.   alias game_enemy_cri_bem cri unless $@
  5699.   def cri
  5700.     clear_battle_cache if @cache_params == nil
  5701.     return @cache_params[:cri] if @cache_params[:cri] != nil
  5702.     #---
  5703.     n = game_enemy_cri_bem
  5704.     for state in states
  5705.       stack(state).times do
  5706.         n = n * state.cri_rate / 100.0
  5707.       end
  5708.     end
  5709.     for state in states
  5710.       next if state.cri_set == 0
  5711.       n += state.cri_set * stack(state)
  5712.     end
  5713.     #---
  5714.     @cache_params[:cri] = [Integer(n), 0].max
  5715.     return @cache_params[:cri]
  5716.   end
  5717.  
  5718.   #--------------------------------------------------------------------------
  5719.   # alias method: odds
  5720.   #--------------------------------------------------------------------------
  5721.   alias game_enemy_odds_bem odds unless $@
  5722.   def odds
  5723.     clear_battle_cache if @cache_params == nil
  5724.     return @cache_params[:odds] if @cache_params[:odds] != nil
  5725.     #---
  5726.     n = game_enemy_odds_bem
  5727.     for state in states
  5728.       stack(state).times do
  5729.         n = n * state.odds_rate / 100.0
  5730.       end
  5731.     end
  5732.     for state in states
  5733.       next if state.odds_set == 0
  5734.       n += state.odds_set * stack(state)
  5735.     end
  5736.     #---
  5737.     @cache_params[:odds] = [Integer(n), 1].max
  5738.     return @cache_params[:odds]
  5739.   end
  5740.  
  5741.   #--------------------------------------------------------------------------
  5742.   # overwrite method: element_rate
  5743.   #--------------------------------------------------------------------------
  5744.   def element_rate(element_id)
  5745.     if @cache_element_rate[element_id] != nil
  5746.       return @cache_element_rate[element_id]
  5747.     end
  5748.     rank = apply_element_rank(element_id)
  5749.     result = element_rate_table(element_id, rank)
  5750.     for state in states
  5751.       result /= 2 if state.element_set.include?(element_id)
  5752.     end
  5753.     @cache_element_rate[element_id] = result
  5754.     return @cache_element_rate[element_id]
  5755.   end
  5756.  
  5757.   #--------------------------------------------------------------------------
  5758.   # overwrite method: state_probability
  5759.   #--------------------------------------------------------------------------
  5760.   def state_probability(state_id)
  5761.     if @cache_state_rate[state_id] != nil
  5762.       rate = element_apply_state_rate(@cache_state_rate[state_id])
  5763.       return rate
  5764.     end
  5765.     if $data_states[state_id].nonresistance
  5766.       result = 100
  5767.     else
  5768.       rank = apply_state_rank(state_id)
  5769.       result = state_probability_table(state_id, rank)
  5770.     end
  5771.     @cache_state_rate[state_id] = result
  5772.     rate = element_apply_state_rate(@cache_state_rate[state_id])
  5773.     return rate
  5774.   end
  5775.  
  5776.   #--------------------------------------------------------------------------
  5777.   # new method: element_set
  5778.   #--------------------------------------------------------------------------
  5779.   def element_set
  5780.     return @cache_element_set if @cache_element_set != nil
  5781.     result = super
  5782.     result += enemy.attack_element
  5783.     for state in states
  5784.       result += state.attack_element
  5785.     end
  5786.     @cache_element_set = result.uniq
  5787.     return @cache_element_set
  5788.   end
  5789.  
  5790.   #--------------------------------------------------------------------------
  5791.   # new method: plus_state_set
  5792.   #--------------------------------------------------------------------------
  5793.   def plus_state_set
  5794.     return @cache_state_set if @cache_state_set != nil
  5795.     result = super
  5796.     result += enemy.attack_state
  5797.     for state in states
  5798.       result += state.attack_state
  5799.     end
  5800.     @cache_state_set = result.uniq
  5801.     return @cache_state_set
  5802.   end
  5803.  
  5804.   #--------------------------------------------------------------------------
  5805.   # new method: attack_formulas
  5806.   #--------------------------------------------------------------------------
  5807.   def attack_formulas; return enemy.damage_formula; end
  5808.  
  5809.   #--------------------------------------------------------------------------
  5810.   # new method: attack_setup_actions
  5811.   #--------------------------------------------------------------------------
  5812.   def attack_setup_actions; return enemy.setup_action_list; end
  5813.  
  5814.   #--------------------------------------------------------------------------
  5815.   # new method: attack_whole_actions
  5816.   #--------------------------------------------------------------------------
  5817.   def attack_whole_actions; return enemy.whole_action_list; end
  5818.  
  5819.   #--------------------------------------------------------------------------
  5820.   # new method: attack_target_actions
  5821.   #--------------------------------------------------------------------------
  5822.   def attack_target_actions; return enemy.target_action_list; end
  5823.  
  5824.   #--------------------------------------------------------------------------
  5825.   # new method: attack_follow_actions
  5826.   #--------------------------------------------------------------------------
  5827.   def attack_follow_actions; return enemy.follow_action_list; end
  5828.  
  5829.   #--------------------------------------------------------------------------
  5830.   # new method: attack_finish_actions
  5831.   #--------------------------------------------------------------------------
  5832.   def attack_finish_actions; return enemy.finish_action_list; end
  5833.  
  5834.   #--------------------------------------------------------------------------
  5835.   # new method: guard_actions
  5836.   #--------------------------------------------------------------------------
  5837.   def guard_actions; return enemy.guard_action_list; end
  5838.  
  5839.   #--------------------------------------------------------------------------
  5840.   # new method: total_skills
  5841.   #--------------------------------------------------------------------------
  5842.   def total_skills
  5843.     result = []
  5844.     for action in enemy.actions
  5845.       next unless action.kind == 1
  5846.       skill = $data_skills[action.skill_id]
  5847.       result.push(skill) unless result.include?(skill)
  5848.     end
  5849.     result.sort! { |a,b| a.id <=> b.id }
  5850.     return result.uniq
  5851.   end
  5852.  
  5853.   #--------------------------------------------------------------------------
  5854.   # overwrite method: perform_collapse
  5855.   #--------------------------------------------------------------------------
  5856.   def perform_collapse
  5857.     return unless $game_temp.in_battle
  5858.     return unless dead?
  5859.     @collapse = true
  5860.     Sound.play_enemy_collapse
  5861.     battler_animation_stance("DEAD") if use_battler_animations?
  5862.     return if $scene.target_enemy_window == nil
  5863.     $scene.target_enemy_window.refresh
  5864.   end
  5865.  
  5866.   #--------------------------------------------------------------------------
  5867.   # alias method: conditions_met?
  5868.   #--------------------------------------------------------------------------
  5869.   alias conditions_met_bem conditions_met? unless $@
  5870.   def conditions_met?(action)
  5871.     if action.condition_type == 1
  5872.       n = @turn_count
  5873.       a = action.condition_param1
  5874.       b = action.condition_param2
  5875.       return false if (b == 0 and n != a)
  5876.       return false if (b > 0 and (n < 1 or n < a or n % b != a % b))
  5877.       return true
  5878.     end
  5879.     return conditions_met_bem(action)
  5880.   end
  5881.  
  5882.   #--------------------------------------------------------------------------
  5883.   # new method: atb_change_value
  5884.   #--------------------------------------------------------------------------
  5885.   def atb_change_value
  5886.     result = 0
  5887.     result += enemy.atb_change_set
  5888.     result += $game_troop.atb_max * enemy.atb_change_per / 100
  5889.     return result
  5890.   end
  5891.  
  5892.   #--------------------------------------------------------------------------
  5893.   # new method: create_atb_reset
  5894.   #--------------------------------------------------------------------------
  5895.   def create_atb_reset(obj = nil)
  5896.     if obj == nil
  5897.       @atb_reset_speed = enemy.atb_reset
  5898.       return
  5899.     end
  5900.     super(obj)
  5901.   end
  5902.  
  5903.   #--------------------------------------------------------------------------
  5904.   # new method: ctb_change_value
  5905.   #--------------------------------------------------------------------------
  5906.   def ctb_change_value
  5907.     result = 0
  5908.     result += enemy.ctb_change_set
  5909.     result += $game_troop.ctb_max * enemy.ctb_change_per / 100
  5910.     return result
  5911.   end
  5912.  
  5913.   #--------------------------------------------------------------------------
  5914.   # new method: create_ctb_reset
  5915.   #--------------------------------------------------------------------------
  5916.   def create_ctb_reset(obj = nil)
  5917.     if obj == nil
  5918.       @ctb_reset_speed = enemy.ctb_reset
  5919.       return
  5920.     end
  5921.     super(obj)
  5922.   end
  5923.  
  5924. end # Game_Enemy
  5925.  
  5926. #===============================================================================
  5927. # Game_Unit
  5928. #===============================================================================
  5929.  
  5930. class Game_Unit
  5931.  
  5932.   #--------------------------------------------------------------------------
  5933.   # public instance variables
  5934.   #--------------------------------------------------------------------------
  5935.   attr_accessor :ptb_bonus_turns
  5936.   attr_accessor :ptb_cancel_turns
  5937.   attr_accessor :ptb_spent_turns
  5938.  
  5939.   #--------------------------------------------------------------------------
  5940.   # new method: total_agi
  5941.   #--------------------------------------------------------------------------
  5942.   def total_agi
  5943.     result = 0
  5944.     for member in members; result += member.agi; end
  5945.     return result
  5946.   end
  5947.  
  5948.   #--------------------------------------------------------------------------
  5949.   # new method: update_battle_start
  5950.   #--------------------------------------------------------------------------
  5951.   def update_battle_start
  5952.     reset_ptb_turns
  5953.     for member in members
  5954.       member.action.clear if $scene.is_a?(Scene_Battle) and !$scene.dtb?
  5955.       member.clear_battle_cache
  5956.       member.turn_count = 0
  5957.     end
  5958.   end
  5959.  
  5960.   #--------------------------------------------------------------------------
  5961.   # new method: update_turn_start
  5962.   #--------------------------------------------------------------------------
  5963.   def update_turn_start
  5964.     for member in members
  5965.       member.ptb_actions = 0
  5966.       #---
  5967.       for state in member.states
  5968.         member.lunatic_status_effects(state, :begin)
  5969.       end
  5970.     end
  5971.   end
  5972.  
  5973.   #--------------------------------------------------------------------------
  5974.   # new method: update_turn_end
  5975.   #--------------------------------------------------------------------------
  5976.   def update_turn_end
  5977.     slip_damage_effect
  5978.     for member in members
  5979.       for state in member.states
  5980.         member.lunatic_status_effects(state, :close)
  5981.       end
  5982.     end
  5983.   end
  5984.  
  5985.   #--------------------------------------------------------------------------
  5986.   # new method: update_battle_over
  5987.   #--------------------------------------------------------------------------
  5988.   def update_battle_over
  5989.     reset_ptb_turns
  5990.     skill_settings = YEM::BATTLE_ENGINE::SKILL_SETTINGS
  5991.     for member in members
  5992.       member.clear_battle_cache
  5993.       member.reset_state_origins
  5994.       member.clear_cooldowns if skill_settings[:cooldown_reset]
  5995.       member.clear_limited_use if skill_settings[:limited_reset]
  5996.       member.lose_rage(member.max_rage) if skill_settings[:rage_reset]
  5997.     end
  5998.   end
  5999.  
  6000.   #--------------------------------------------------------------------------
  6001.   # new method: ptb_total_turns
  6002.   #--------------------------------------------------------------------------
  6003.   def ptb_total_turns
  6004.     result = ptb_member_turns + @ptb_bonus_turns
  6005.     result -= @ptb_cancel_turns + @ptb_spent_turns
  6006.     return [result, 0].max
  6007.   end
  6008.  
  6009.   #--------------------------------------------------------------------------
  6010.   # new method: ptb_member_turns
  6011.   #--------------------------------------------------------------------------
  6012.   def ptb_member_turns
  6013.     result = 0
  6014.     for member in existing_members; result += member.ptb_provided_turns; end
  6015.     return result
  6016.   end
  6017.  
  6018.   #--------------------------------------------------------------------------
  6019.   # new method: reset_ptb_turns
  6020.   #--------------------------------------------------------------------------
  6021.   def reset_ptb_turns
  6022.     for member in members;
  6023.       member.action.ptb_guarding = nil
  6024.       member.ptb_performed = false
  6025.       member.ptb_actions = 0
  6026.       member.ptb_cancel = 0
  6027.       member.ptb_regain = 0
  6028.     end
  6029.     @ptb_bonus_turns = 0
  6030.     @ptb_cancel_turns = 0
  6031.     @ptb_spent_turns = 0
  6032.   end
  6033.  
  6034.   #--------------------------------------------------------------------------
  6035.   # new method: update_ptb
  6036.   #--------------------------------------------------------------------------
  6037.   def update_ptb(value = 1, ignore = false)
  6038.     return unless $scene.is_a?(Scene_Battle)
  6039.     return unless $scene.ptb?
  6040.     return if $scene.active_battler.action.forcing
  6041.     #---
  6042.     unless ignore
  6043.       if $scene.active_battler.action.skill?
  6044.         obj = $scene.active_battler.action.skill
  6045.         value = obj.ptb_turn_cost
  6046.       elsif $scene.active_battler.action.item?
  6047.         obj = $scene.active_battler.action.item
  6048.         value = obj.ptb_turn_cost
  6049.       end
  6050.     end
  6051.     #---
  6052.     value.times do
  6053.       if @ptb_bonus_turns > 0
  6054.         @ptb_bonus_turns -= 1
  6055.       else
  6056.         @ptb_spent_turns += 1
  6057.       end
  6058.     end
  6059.     #---
  6060.     $scene.active_battler.ptb_actions += 1 if $scene.active_battler != nil
  6061.   end
  6062.  
  6063.   #--------------------------------------------------------------------------
  6064.   # new method: gain_bonus
  6065.   #--------------------------------------------------------------------------
  6066.   def gain_bonus(battler = nil, value = 1, follow_rule = true)
  6067.     return unless $scene.is_a?(Scene_Battle)
  6068.     return unless $scene.ptb?
  6069.     if battler != nil and follow_rule
  6070.       battler.ptb_regain += 1
  6071.       if battler.ptb_regain <= battler.ptb_max_regain
  6072.         @ptb_bonus_turns += value
  6073.         sfx = YEM::BATTLE_ENGINE::PTB_RULES[:one_more_sfx]
  6074.         sfx.play if sfx != nil
  6075.       end
  6076.     else
  6077.       @ptb_bonus_turns += value
  6078.       sfx = YEM::BATTLE_ENGINE::PTB_RULES[:one_more_sfx]
  6079.       sfx.play if sfx != nil
  6080.     end
  6081.     $scene.ptb_updated = true
  6082.     $scene.refresh_ptb_windows
  6083.   end
  6084.  
  6085.   #--------------------------------------------------------------------------
  6086.   # new method: cancel_turn
  6087.   #--------------------------------------------------------------------------
  6088.   def cancel_turn(battler = nil, value = 1, follow_rule = true)
  6089.     return unless $scene.is_a?(Scene_Battle)
  6090.     return unless $scene.ptb?
  6091.     if battler != nil and follow_rule
  6092.       battler.ptb_cancel += 1
  6093.       if battler.ptb_cancel <= battler.ptb_max_cancel
  6094.         @ptb_cancel_turns += value
  6095.         sfx = YEM::BATTLE_ENGINE::PTB_RULES[:one_less_sfx]
  6096.         sfx.play if sfx != nil
  6097.       end
  6098.     else
  6099.       @ptb_cancel_turns += value
  6100.       sfx = YEM::BATTLE_ENGINE::PTB_RULES[:one_less_sfx]
  6101.       sfx.play if sfx != nil
  6102.     end
  6103.     $scene.ptb_updated = true
  6104.     $scene.refresh_ptb_windows
  6105.   end
  6106.  
  6107.   #--------------------------------------------------------------------------
  6108.   # new method: create_initial_atb_speeds
  6109.   #--------------------------------------------------------------------------
  6110.   def create_initial_atb_speeds
  6111.     percent1 = YEM::BATTLE_ENGINE::ATB_RULES[:initial]
  6112.     percent2 = YEM::BATTLE_ENGINE::ATB_RULES[:surprise]
  6113.     random = YEM::BATTLE_ENGINE::ATB_RULES[:random]
  6114.     value = Integer($game_troop.atb_max * percent1)
  6115.     bonus = Integer($game_troop.atb_max * percent2)
  6116.     $scene.force_preemptive_or_surprise
  6117.     for member in members
  6118.       member.turn_count = 0
  6119.       member.reset_atb_speed
  6120.       member.atb_speed = value
  6121.       member.action.atb_queue_kind = 0
  6122.       member.action.atb_queue_basic = 3
  6123.       member.action.atb_guarding = false
  6124.       random.times do; member.atb_speed += rand(member.base_agi); end
  6125.       member.atb_speed += bonus if member.actor? and $game_troop.preemptive
  6126.       member.atb_speed += bonus if member.enemy? and $game_troop.surprise
  6127.       member.atb_speed = [member.atb_speed, 0].max
  6128.       member.atb_speed = [member.atb_speed, $game_troop.atb_threshold].min
  6129.     end
  6130.   end
  6131.  
  6132.   #--------------------------------------------------------------------------
  6133.   # new method: create_initial_ctb_speeds
  6134.   #--------------------------------------------------------------------------
  6135.   def create_initial_ctb_speeds
  6136.     percent1 = YEM::BATTLE_ENGINE::CTB_RULES[:initial]
  6137.     percent2 = YEM::BATTLE_ENGINE::CTB_RULES[:surprise]
  6138.     random = YEM::BATTLE_ENGINE::CTB_RULES[:random]
  6139.     value = Integer($game_troop.ctb_max * percent1)
  6140.     bonus = Integer($game_troop.ctb_max * percent2)
  6141.     $scene.force_preemptive_or_surprise
  6142.     for member in members
  6143.       member.turn_count = 0
  6144.       member.reset_ctb_speed
  6145.       member.ctb_speed = value
  6146.       member.action.ctb_guarding = false
  6147.       member.action.ctb_guarding_queue = false
  6148.       random.times do; member.ctb_speed += rand(member.base_agi); end
  6149.       member.ctb_speed += bonus if member.actor? and $game_troop.preemptive
  6150.       member.ctb_speed += bonus if member.enemy? and $game_troop.surprise
  6151.       member.ctb_speed = [member.ctb_speed, 0].max
  6152.     end
  6153.   end
  6154.  
  6155.   #--------------------------------------------------------------------------
  6156.   # new method: update_group_cooldowns
  6157.   #--------------------------------------------------------------------------
  6158.   def update_group_cooldowns
  6159.     for member in existing_members; member.update_all_cooldown; end
  6160.   end
  6161.  
  6162.   #--------------------------------------------------------------------------
  6163.   # new method: area_targets
  6164.   #--------------------------------------------------------------------------
  6165.   def area_targets(main_target, obj = nil)
  6166.     return [] unless $scene.is_a?(Scene_Battle)
  6167.     return [] if obj == nil
  6168.     result = []
  6169.     for member in members
  6170.       next if member.dead? != obj.for_dead_friend?
  6171.       next if member.hidden
  6172.       result.push(member) if within_radius?(main_target, member, obj)
  6173.       result.push(member) if within_area?(main_target, member, obj)
  6174.     end
  6175.     return result.uniq
  6176.   end
  6177.  
  6178.   #--------------------------------------------------------------------------
  6179.   # new method: within_radius?
  6180.   #--------------------------------------------------------------------------
  6181.   def within_radius?(main_target, target, obj)
  6182.     return false if target == main_target
  6183.     return false if obj == nil
  6184.     return false if obj.aoe_radius <= 0
  6185.     radius = obj.aoe_radius + 1
  6186.     height = obj.aoe_height
  6187.     #--- Target Point Creation ---
  6188.     main_x = main_target.screen_x
  6189.     main_y = main_target.screen_y
  6190.     target_x = target.screen_x
  6191.     target_y = target.screen_y
  6192.     #--- Target Offset Buffering ---
  6193.     main_x += main_target.enemy.target_offset_x unless main_target.actor?
  6194.     main_y += main_target.enemy.target_offset_y unless main_target.actor?
  6195.     target_x += target.enemy.target_offset_x unless target.actor?
  6196.     target_y += target.enemy.target_offset_y unless target.actor?
  6197.     #--- Target Point Buffering ---
  6198.     if main_x >= target_x
  6199.       target_x += target.bitmap_width/2
  6200.     elsif main_x <= target_x
  6201.       target_x -= target.bitmap_width/2
  6202.     end
  6203.     #--- Calculations ---
  6204.     x = (target_x - main_x) * Math.cos(0) + (target_y - main_y) * Math.sin(0)
  6205.     y = -(target_x - main_x) * Math.sin(0) + (target_y - main_y) * Math.cos(0)
  6206.     a = radius; b = radius * height
  6207.     return (x**2 / a**2) + (y**2 / b**2) <= 1
  6208.   end
  6209.  
  6210.   #--------------------------------------------------------------------------
  6211.   # new method: within_area?
  6212.   #--------------------------------------------------------------------------
  6213.   def within_area?(main_target, target, obj)
  6214.     return false if target == main_target
  6215.     return false if obj == nil
  6216.     return false if obj.rect_type <= 0
  6217.     #--- Target Point Creation ---
  6218.     main_x = main_target.origin_x
  6219.     main_y = main_target.origin_y
  6220.     target_x = target.screen_x
  6221.     target_y = target.screen_y
  6222.     #--- Target Offset Buffering ---
  6223.     main_x += main_target.enemy.target_offset_x unless main_target.actor?
  6224.     main_y += main_target.enemy.target_offset_y unless main_target.actor?
  6225.     target_x += target.enemy.target_offset_x unless target.actor?
  6226.     target_y += target.enemy.target_offset_y unless target.actor?
  6227.     #--- Target Point Buffering ---
  6228.     if main_x >= target_x
  6229.       target_x += target.bitmap_width/2
  6230.     elsif main_x <= target_x
  6231.       target_x -= target.bitmap_width/2
  6232.     end
  6233.     #--- Area Creation ---
  6234.     case obj.rect_type
  6235.     when 1 # Column
  6236.       y1 = 0; y2 = Graphics.height
  6237.       x1 = main_x - obj.rect_value
  6238.       x2 = main_x + obj.rect_value
  6239.     when 2 # Row
  6240.       x1 = 0; x2 = Graphics.width
  6241.       y1 = main_y - obj.rect_value
  6242.       y2 = main_y + obj.rect_value
  6243.     when 3 # Map
  6244.       x1 = 0; x2 = Graphics.width
  6245.       y1 = 0; y2 = Graphics.height
  6246.     else; return false
  6247.     end
  6248.     #--- Calculations ---
  6249.     in_x = ((x1..x2) === target_x)
  6250.     in_y = ((y1..y2) === target_y)
  6251.     return (in_x and in_y)
  6252.   end
  6253.  
  6254. end # Game_Unit
  6255.  
  6256. #===============================================================================
  6257. # Game_Party
  6258. #===============================================================================
  6259.  
  6260. class Game_Party < Game_Unit
  6261.  
  6262.   #--------------------------------------------------------------------------
  6263.   # Public Instance Variables
  6264.   #--------------------------------------------------------------------------
  6265.   attr_accessor :battle_items_cache
  6266.   attr_accessor :item_charges
  6267.  
  6268.   #--------------------------------------------------------------------------
  6269.   # alias method: setup_starting_members
  6270.   #--------------------------------------------------------------------------
  6271.   alias setup_starting_members_bem setup_starting_members unless $@
  6272.   def setup_starting_members
  6273.     setup_starting_members_bem
  6274.     for i in 0..$data_actors.size
  6275.       actor = $game_actors[i]
  6276.       next if actor == nil
  6277.       actor.clear_battle_cache
  6278.     end
  6279.   end
  6280.  
  6281.   #--------------------------------------------------------------------------
  6282.   # overwrite method: on_player_walk
  6283.   #--------------------------------------------------------------------------
  6284.   def on_player_walk
  6285.     for actor in members
  6286.       if actor.slip_damage?
  6287.         for state in actor.states; actor.perform_slip_effect(state); end
  6288.       end
  6289.       if actor.auto_hp_recover and actor.hp > 0
  6290.         actor.hp += 1
  6291.       end
  6292.     end
  6293.     #---
  6294.     if YEM::BATTLE_ENGINE::SKILL_SETTINGS[:rage_decay] > 0
  6295.       if @steps % YEM::BATTLE_ENGINE::SKILL_SETTINGS[:rage_decay] == 0
  6296.         for member in members; member.lose_rage; end
  6297.       end
  6298.     end
  6299.     if YEM::BATTLE_ENGINE::SKILL_SETTINGS[:cooldown_decay] > 0
  6300.       if @steps % YEM::BATTLE_ENGINE::SKILL_SETTINGS[:cooldown_decay] == 0
  6301.         for member in members; member.update_all_cooldown; end
  6302.       end
  6303.     end
  6304.     #---
  6305.   end
  6306.  
  6307.   #--------------------------------------------------------------------------
  6308.   # alias method: gain_item
  6309.   # Quick Cache Data
  6310.   #--------------------------------------------------------------------------
  6311.   alias gain_item_bem gain_item unless $@
  6312.   def gain_item(item, n, include_equip = false)
  6313.     gain_item_bem(item, n, include_equip)
  6314.     @battle_items_cache = nil
  6315.   end
  6316.  
  6317.   #--------------------------------------------------------------------------
  6318.   # alias method: consume_item
  6319.   #--------------------------------------------------------------------------
  6320.   alias consume_item_bem consume_item unless $@
  6321.   def consume_item(item)
  6322.     item_variable_switch_change(item)
  6323.     if item.is_a?(RPG::Item) and item.consumable
  6324.       @item_charges = {} if @item_charges == nil
  6325.       @item_charges[item.id] = item.charges if @item_charges[item.id] == nil
  6326.       @item_charges[item.id] -= 1
  6327.       if @item_charges[item.id] <= 0
  6328.         @item_charges[item.id] = item.charges
  6329.         consume_item_bem(item)
  6330.       end
  6331.     else
  6332.       consume_item_bem(item)
  6333.     end
  6334.   end
  6335.  
  6336.   #--------------------------------------------------------------------------
  6337.   # new method: item_variable_switch_change
  6338.   #--------------------------------------------------------------------------
  6339.   def item_variable_switch_change(item)
  6340.     return unless item.is_a?(RPG::Item)
  6341.     for key in item.change_variable
  6342.       variable_id = key[0]; value = key[1]
  6343.       $game_variables[variable_id] += value
  6344.     end
  6345.     for key in item.change_switch
  6346.       switch_id = key[0]; value = key[1]
  6347.       case value
  6348.       when :true;   $game_switches[switch_id] = true
  6349.       when :false;  $game_switches[switch_id] = false
  6350.       when :toggle; $game_switches[switch_id] = !$game_switches[switch_id]
  6351.       end
  6352.     end
  6353.   end
  6354.  
  6355.   #--------------------------------------------------------------------------
  6356.   # new method: battle_item_size
  6357.   # Quick Cache Data
  6358.   #--------------------------------------------------------------------------
  6359.   def battle_item_size
  6360.     return @battle_items_cache if @battle_items_cache != nil
  6361.     @battle_items_cache = 0
  6362.     for item in items
  6363.       next unless item_can_use?(item)
  6364.       @battle_items_cache += 1
  6365.     end
  6366.     return @battle_items_cache
  6367.   end
  6368.  
  6369.   #--------------------------------------------------------------------------
  6370.   # new method: update_battle_start
  6371.   #--------------------------------------------------------------------------
  6372.   def update_battle_start
  6373.     super
  6374.     clear_caches
  6375.     for member in members
  6376.       member.turn_count = 0
  6377.     end
  6378.   end
  6379.  
  6380.   #--------------------------------------------------------------------------
  6381.   # new method: update_turn_start
  6382.   #--------------------------------------------------------------------------
  6383.   def update_turn_start
  6384.     super
  6385.     for member in members
  6386.       member.equip_cooldown = 0 if member.equip_cooldown == nil
  6387.       member.equip_cooldown = [member.equip_cooldown - 1, 0].max
  6388.     end
  6389.   end
  6390.  
  6391.   #--------------------------------------------------------------------------
  6392.   # new method: update_turn_end
  6393.   #--------------------------------------------------------------------------
  6394.   def update_turn_end
  6395.     super
  6396.     do_auto_recovery
  6397.   end
  6398.  
  6399.   #--------------------------------------------------------------------------
  6400.   # new method: update_battle_over
  6401.   #--------------------------------------------------------------------------
  6402.   def update_battle_over
  6403.     super
  6404.     remove_states_battle
  6405.     clear_caches
  6406.     for member in members
  6407.       member.equip_cooldown = 0
  6408.       member.equip_clocktick = nil
  6409.       next if $scene.is_a?(Scene_Battle) and $scene.dtb?
  6410.       member.action.clear
  6411.     end
  6412.   end
  6413.  
  6414.   #--------------------------------------------------------------------------
  6415.   # new method: clear_caches
  6416.   #--------------------------------------------------------------------------
  6417.   def clear_caches
  6418.     @battle_items_cache = nil
  6419.     for i in 0..$data_actors.size
  6420.       actor = $game_actors[i]
  6421.       next if actor == nil
  6422.       actor.clear_battle_cache
  6423.     end
  6424.   end
  6425.  
  6426. end # Game_Party
  6427.  
  6428. #===============================================================================
  6429. # Game_Troop
  6430. #===============================================================================
  6431.  
  6432. class Game_Troop < Game_Unit
  6433.  
  6434.   #--------------------------------------------------------------------------
  6435.   # public instance variables
  6436.   #--------------------------------------------------------------------------
  6437.   attr_accessor :atb_max
  6438.   attr_accessor :atb_min_speed
  6439.   attr_accessor :atb_threshold
  6440.   attr_accessor :atb_ready
  6441.   attr_accessor :ctb_max
  6442.   attr_accessor :ctb_min_speed
  6443.   attr_accessor :ctb_ready
  6444.   attr_accessor :turn_count
  6445.  
  6446.   #--------------------------------------------------------------------------
  6447.   # overwrite method: make_actions
  6448.   #--------------------------------------------------------------------------
  6449.   def make_actions
  6450.     if @preemptive and ($scene.is_a?(Scene_Battle) and !$scene.atb?)
  6451.       clear_actions
  6452.     else
  6453.       for enemy in members; enemy.make_action; end
  6454.     end
  6455.   end
  6456.  
  6457.   #--------------------------------------------------------------------------
  6458.   # new method: update_battle_start
  6459.   #--------------------------------------------------------------------------
  6460.   def update_battle_start
  6461.     super
  6462.   end
  6463.  
  6464.   #--------------------------------------------------------------------------
  6465.   # new method: update_turn_start
  6466.   #--------------------------------------------------------------------------
  6467.   def update_turn_start
  6468.     super
  6469.   end
  6470.  
  6471.   #--------------------------------------------------------------------------
  6472.   # new method: update_turn_end
  6473.   #--------------------------------------------------------------------------
  6474.   def update_turn_end
  6475.     super
  6476.   end
  6477.  
  6478.   #--------------------------------------------------------------------------
  6479.   # new method: update_battle_over
  6480.   #--------------------------------------------------------------------------
  6481.   def update_battle_over
  6482.     super
  6483.   end
  6484.  
  6485.   #--------------------------------------------------------------------------
  6486.   # overwrite method: increase_turn
  6487.   #--------------------------------------------------------------------------
  6488.   def increase_turn
  6489.     for page in troop.pages
  6490.       if page.span == 1
  6491.         @event_flags[page] = false
  6492.       end
  6493.     end
  6494.     @turn_count += 1
  6495.     return unless $scene.is_a?(Scene_Battle)
  6496.     return if $scene.atb? or $scene.ctb?
  6497.     for member in ($game_party.members + $game_troop.members)
  6498.       member.turn_count = 0 if member.turn_count == nil
  6499.       member.turn_count += 1
  6500.     end
  6501.   end
  6502.  
  6503.   #--------------------------------------------------------------------------
  6504.   # new method: create_atb_max_speed
  6505.   #--------------------------------------------------------------------------  
  6506.   def create_atb_max_speed
  6507.     array = $game_troop.members + $game_party.members
  6508.     @atb_max = 0
  6509.     @atb_min_speed = YEM::BATTLE_ENGINE::ATB_RULES[:min_speed]
  6510.     for member in array; @atb_max += member.base_agi; end
  6511.     @atb_max = Integer(@atb_max * YEM::BATTLE_ENGINE::ATB_RULES[:max_rate])
  6512.     @atb_max += YEM::BATTLE_ENGINE::ATB_RULES[:max_offset]
  6513.     @atb_max = [@atb_max, YEM::BATTLE_ENGINE::ATB_RULES[:max_low]].max
  6514.     threshold = YEM::BATTLE_ENGINE::ATB_RULES[:threshold]
  6515.     @atb_threshold = Integer(threshold * @atb_max)
  6516.     @atb_ready = []
  6517.   end
  6518.  
  6519.   #--------------------------------------------------------------------------
  6520.   # new method: create_ctb_max_speed
  6521.   #--------------------------------------------------------------------------  
  6522.   def create_ctb_max_speed
  6523.     array = $game_troop.members + $game_party.members
  6524.     @ctb_max = 0
  6525.     @ctb_min_speed = YEM::BATTLE_ENGINE::CTB_RULES[:min_speed]
  6526.     for member in array; @ctb_max += member.base_agi; end
  6527.     @ctb_max = Integer(@ctb_max * YEM::BATTLE_ENGINE::CTB_RULES[:max_rate])
  6528.     @ctb_max += YEM::BATTLE_ENGINE::CTB_RULES[:max_offset]
  6529.     @ctb_max = [@ctb_max, YEM::BATTLE_ENGINE::CTB_RULES[:max_low]].max
  6530.     @ctb_ready = []
  6531.     clear_ctb_cache
  6532.   end
  6533.  
  6534.   #--------------------------------------------------------------------------
  6535.   # new method: clear_ctb_cache
  6536.   #--------------------------------------------------------------------------
  6537.   def clear_ctb_cache
  6538.     for battler in ($game_party.members + $game_troop.members)
  6539.       battler.ctb_cache = nil
  6540.     end
  6541.   end
  6542.  
  6543. end # Game_Troop
  6544.  
  6545. #===============================================================================
  6546. # Game_Interpreter
  6547. #===============================================================================
  6548.  
  6549. class Game_Interpreter
  6550.  
  6551.   #--------------------------------------------------------------------------
  6552.   # alias method: Change Parameters
  6553.   #--------------------------------------------------------------------------
  6554.   alias command_317_bem command_317 unless $@
  6555.   def command_317
  6556.     n = command_317_bem
  6557.     actor = $game_actors[@params[0]]
  6558.     actor.clear_battle_cache
  6559.     actor.update_maxhp = true
  6560.     actor.update_maxmp = true
  6561.     return n
  6562.   end
  6563.  
  6564.   #--------------------------------------------------------------------------
  6565.   # alias method: Change Skills
  6566.   #--------------------------------------------------------------------------
  6567.   alias command_318_bem command_318 unless $@
  6568.   def command_318
  6569.     n = command_318_bem
  6570.     actor = $game_actors[@params[0]]
  6571.     if actor != nil and $scene.is_a?(Scene_Battle)
  6572.       if @params[1] != 0
  6573.         skill = $data_skills[@params[2]]
  6574.         if actor.action.skill? and actor.action.skill == skill
  6575.           actor.action.clear
  6576.         end
  6577.       end
  6578.     end
  6579.     return true
  6580.   end
  6581.  
  6582.   #--------------------------------------------------------------------------
  6583.   # overwrite method: Enemy Appear
  6584.   #--------------------------------------------------------------------------
  6585.   def command_335
  6586.     enemy = $game_troop.members[@params[0]]
  6587.     if enemy != nil and enemy.hidden
  6588.       enemy.hidden = false
  6589.       enemy.battler_animation_stance("IDLE")
  6590.       $game_troop.make_unique_names
  6591.     end
  6592.     return true
  6593.   end
  6594.  
  6595.   #--------------------------------------------------------------------------
  6596.   # alias method: Force Action
  6597.   #--------------------------------------------------------------------------
  6598.   alias command_339_bem command_339 unless $@
  6599.   def command_339
  6600.     iterate_battler(@params[0], @params[1]) do |battler|
  6601.       next unless battler.exist?
  6602.       next if battler.stored_action != nil
  6603.       battler.stored_action = battler.action.clone if battler.action != nil
  6604.     end
  6605.     n = command_339_bem
  6606.     #---
  6607.     if $scene.is_a?(Scene_Battle) and ($scene.ctb? or $scene.atb?)
  6608.       iterate_battler(@params[0], @params[1]) do |battler|
  6609.         next unless battler.exist?
  6610.         current_active_battler = $scene.active_battler
  6611.         $scene.active_battler = battler
  6612.         $scene.process_action
  6613.         $scene.active_battler = current_active_battler
  6614.       end
  6615.       $game_troop.forcing_battler = nil
  6616.     end
  6617.     return n
  6618.   end
  6619.  
  6620.   #--------------------------------------------------------------------------
  6621.   # new method: clear_limited_use
  6622.   #--------------------------------------------------------------------------
  6623.   def clear_limited_use
  6624.     for member in $game_party.members; member.clear_limited_use; end
  6625.   end
  6626.  
  6627. end # Game_Interpreter
  6628.  
  6629. #===============================================================================
  6630. # Scene_Skill
  6631. #===============================================================================
  6632.  
  6633. class Scene_Skill < Scene_Base
  6634.  
  6635.   #--------------------------------------------------------------------------
  6636.   # overwrite method: use_skill_nontarget
  6637.   #--------------------------------------------------------------------------
  6638.   def use_skill_nontarget
  6639.     Sound.play_use_skill
  6640.     @actor.perform_skill_cost(@skill)
  6641.     @status_window.refresh
  6642.     @skill_window.refresh
  6643.     @target_window.refresh
  6644.     if $game_party.all_dead?
  6645.       $scene = Scene_Gameover.new
  6646.     elsif @skill.common_event_id > 0
  6647.       $game_temp.common_event_id = @skill.common_event_id
  6648.       $scene = Scene_Map.new
  6649.     end
  6650.   end
  6651.  
  6652. end # Scene_Skill
  6653.  
  6654. #===============================================================================
  6655. # Scene_Equip
  6656. #===============================================================================
  6657.  
  6658. class Scene_Equip < Scene_Base
  6659.  
  6660.   #--------------------------------------------------------------------------
  6661.   # alias method: next_actor
  6662.   #--------------------------------------------------------------------------
  6663.   alias next_actor_scene_equip next_actor unless $@
  6664.   def next_actor
  6665.     if $game_temp.in_battle
  6666.       Sound.play_buzzer
  6667.       return
  6668.     end
  6669.     next_actor_scene_equip
  6670.   end
  6671.  
  6672.   #--------------------------------------------------------------------------
  6673.   # alias method: prev_actor
  6674.   #--------------------------------------------------------------------------
  6675.   alias prev_actor_scene_equip prev_actor unless $@
  6676.   def prev_actor
  6677.     if $game_temp.in_battle
  6678.       Sound.play_buzzer
  6679.       return
  6680.     end
  6681.     prev_actor_scene_equip
  6682.   end
  6683.  
  6684. end # Scene_Equip
  6685.  
  6686. #===============================================================================
  6687. # Scene_Battle
  6688. #===============================================================================
  6689.  
  6690. class Scene_Battle < Scene_Base
  6691.  
  6692.   #--------------------------------------------------------------------------
  6693.   # public instance variables
  6694.   #--------------------------------------------------------------------------
  6695.   attr_accessor :action_battlers
  6696.   attr_accessor :active_battler
  6697.   attr_accessor :actor_command_window
  6698.   attr_accessor :battle_type
  6699.   attr_accessor :camera_speed
  6700.   attr_accessor :camera_x
  6701.   attr_accessor :camera_y
  6702.   attr_accessor :characters
  6703.   attr_accessor :combo_hits
  6704.   attr_accessor :combo_damage
  6705.   attr_accessor :combo_update
  6706.   attr_accessor :confirm_command_window
  6707.   attr_accessor :enemychars
  6708.   attr_accessor :help_viewport
  6709.   attr_accessor :hide_battlecursor
  6710.   attr_accessor :highlighted_targets
  6711.   attr_accessor :info_viewport
  6712.   attr_accessor :message_window
  6713.   attr_accessor :mirror_ani
  6714.   attr_accessor :party_command_window
  6715.   attr_accessor :party_input_flag
  6716.   attr_accessor :performed_actors
  6717.   attr_accessor :ptb_party_window
  6718.   attr_accessor :ptb_troop_window
  6719.   attr_accessor :ptb_updated
  6720.   attr_accessor :selected_battler
  6721.   attr_accessor :spriteset
  6722.   attr_accessor :status_window
  6723.   attr_accessor :target_actor_window
  6724.   attr_accessor :target_enemy_window
  6725.   attr_accessor :target_help_window
  6726.   attr_accessor :view_type
  6727.  
  6728.   #--------------------------------------------------------------------------
  6729.   # overwrite method: start
  6730.   #--------------------------------------------------------------------------
  6731.   def start
  6732.     super
  6733.     $game_system.create_battle_options
  6734.     $game_temp.in_battle = true
  6735.     set_battle_types
  6736.     @performed_actors = []
  6737.     @action_battlers = []
  6738.     @action_values = []
  6739.     @spriteset = Spriteset_Battle.new
  6740.     @message_window = Window_BattleMessageMelody.new
  6741.     @hide_battlecursor = false
  6742.     reset_extra_calculation_modifiers
  6743.     create_info_viewport
  6744.     create_bem_windows
  6745.     update_battler_poses
  6746.     @spriteset.update
  6747.   end
  6748.  
  6749.   #--------------------------------------------------------------------------
  6750.   # new method: set_battle_types
  6751.   #--------------------------------------------------------------------------
  6752.   def set_battle_types
  6753.     @current_party = $game_party.members.clone
  6754.     @all_members = ($game_party.members + $game_troop.members).clone
  6755.     @battle_type = $game_variables[YEM::BATTLE_ENGINE::BATTLE_TYPE_VARIABLE]
  6756.     @view_type = $game_variables[YEM::BATTLE_ENGINE::VIEW_TYPE_VARIABLE]
  6757.     setup_atb if atb?
  6758.     setup_ctb if ctb?
  6759.     force_create_empty_actions
  6760.   end
  6761.  
  6762.   #--------------------------------------------------------------------------
  6763.   # new method: force_create_empty_actions
  6764.   #--------------------------------------------------------------------------
  6765.   def force_create_empty_actions
  6766.     for member in ($game_troop.members + $game_party.members)
  6767.       member.rage = 0 if member.rage == nil
  6768.       member.action = Game_BattleAction.new(member) if member.action == nil
  6769.       member.action.kind = 0 if member.action.kind == nil
  6770.       member.action.basic = 3 if member.action.basic == nil
  6771.       member.reload_state_animation
  6772.     end
  6773.   end
  6774.  
  6775.   #--------------------------------------------------------------------------
  6776.   # new method: dtb? (Default Turn Battle)
  6777.   #--------------------------------------------------------------------------
  6778.   def dtb?; return @battle_type == 0; end
  6779.  
  6780.   #--------------------------------------------------------------------------
  6781.   # new method: ptb? (Press Turn Battle)
  6782.   #--------------------------------------------------------------------------
  6783.   def ptb?; return @battle_type == 1; end
  6784.  
  6785.   #--------------------------------------------------------------------------
  6786.   # new method: atb? (Active Turn Battle)
  6787.   #--------------------------------------------------------------------------
  6788.   def atb?; return @battle_type == 2; end
  6789.  
  6790.   #--------------------------------------------------------------------------
  6791.   # new method: ctb? (Charge Turn Battle)
  6792.   #--------------------------------------------------------------------------
  6793.   def ctb?; return @battle_type == 3; end
  6794.  
  6795.   #--------------------------------------------------------------------------
  6796.   # new method: active_atb?
  6797.   #--------------------------------------------------------------------------
  6798.   def active_atb?
  6799.     return $game_variables[YEM::BATTLE_ENGINE::OPTIONS[:atb_avariable]] >= 0
  6800.   end
  6801.  
  6802.   #--------------------------------------------------------------------------
  6803.   # new method: semi_active_atb?
  6804.   #--------------------------------------------------------------------------
  6805.   def semi_active_atb?
  6806.     return $game_variables[YEM::BATTLE_ENGINE::OPTIONS[:atb_avariable]] >= 1
  6807.   end
  6808.  
  6809.   #--------------------------------------------------------------------------
  6810.   # new method: semi_wait_atb?
  6811.   #--------------------------------------------------------------------------
  6812.   def semi_wait_atb?
  6813.     return $game_variables[YEM::BATTLE_ENGINE::OPTIONS[:atb_avariable]] >= 2
  6814.   end
  6815.  
  6816.   #--------------------------------------------------------------------------
  6817.   # new method: wait_atb?
  6818.   #--------------------------------------------------------------------------
  6819.   def wait_atb?
  6820.     return $game_variables[YEM::BATTLE_ENGINE::OPTIONS[:atb_avariable]] >= 3
  6821.   end
  6822.  
  6823.   #--------------------------------------------------------------------------
  6824.   # new method: cinematic?
  6825.   #--------------------------------------------------------------------------
  6826.   def cinematic?; return false; end
  6827.  
  6828.   #--------------------------------------------------------------------------
  6829.   # new method: emptyview?
  6830.   #--------------------------------------------------------------------------
  6831.   def emptyview?; return @view_type == 0; end
  6832.  
  6833.   #--------------------------------------------------------------------------
  6834.   # new method: frontview?
  6835.   #--------------------------------------------------------------------------
  6836.   def frontview?; return @view_type == 1; end
  6837.  
  6838.   #--------------------------------------------------------------------------
  6839.   # new method: sideview?
  6840.   #--------------------------------------------------------------------------
  6841.   def sideview?; return @view_type == 2; end
  6842.  
  6843.   #--------------------------------------------------------------------------
  6844.   # new method: angleview?
  6845.   #--------------------------------------------------------------------------
  6846.   def angleview?; return @view_type == 3; end
  6847.    
  6848.   #--------------------------------------------------------------------------
  6849.   # alias method: terminate
  6850.   #--------------------------------------------------------------------------
  6851.   alias terminate_scene_battle_bem terminate unless $@
  6852.   def terminate
  6853.     terminate_scene_battle_bem
  6854.     if $disposable_melody_windows != nil
  6855.       for window in $disposable_melody_windows
  6856.         window.dispose unless window.disposed?
  6857.       end
  6858.       $disposable_melody_windows = []
  6859.     end
  6860.   end
  6861.  
  6862.   #--------------------------------------------------------------------------
  6863.   # overwrite method: create_info_viewport
  6864.   #--------------------------------------------------------------------------
  6865.   def create_info_viewport
  6866.     force_preemptive_or_surprise
  6867.     #---
  6868.     @info_viewport = Viewport.new(0, Graphics.height-128, Graphics.width, 128)
  6869.     @info_viewport.z = 100
  6870.     #---
  6871.     @status_window = Window_BattleStatus.new(true)
  6872.     @status_window.viewport = @info_viewport
  6873.     @status_window.x = 128
  6874.     @status_hp_window = Window_BattleStatusHP.new
  6875.     @status_hp_window.viewport = @info_viewport
  6876.     @status_hp_window.x = 128
  6877.     @status_mp_window = Window_BattleStatusMP.new
  6878.     @status_mp_window.viewport = @info_viewport
  6879.     @status_mp_window.x = 128
  6880.     @status_rage_window = Window_BattleStatusRage.new
  6881.     @status_rage_window.viewport = @info_viewport
  6882.     @status_rage_window.x = 128
  6883.     @status_rage_window.z = @status_mp_window.z + 1
  6884.     @status_states_window = Window_BattleStatusStates.new
  6885.     @status_states_window.viewport = @info_viewport
  6886.     @status_states_window.x = 128   # MK original value: 128
  6887.     #---
  6888.     @party_command_window = Window_PartyCommand.new
  6889.     @actor_command_window = Window_ActorCommand.new
  6890.     @party_command_window.viewport = @info_viewport
  6891.     @actor_command_window.viewport = @info_viewport
  6892.     @actor_command_window.x = Graphics.width
  6893.     @confirm_command_window = Window_ConfirmCommand.new
  6894.     @confirm_command_window.viewport = @info_viewport
  6895.     @confirm_command_window.x = Graphics.width
  6896.     #---
  6897.     @info_viewport.ox = 128
  6898.     @actor_index = 0
  6899.     @status_shortcut_index = 0
  6900.     @status_window.index = 0
  6901.     @status_window.refresh
  6902.     actor = @status_window.actor
  6903.     @actor_command_window.setup(actor)
  6904.     if $game_switches[YEM::BATTLE_ENGINE::OPTIONS[:autocursor_sw]]
  6905.       @actor_command_window.index = actor.battle_command_index.to_i
  6906.     end
  6907.     #--- Calculate PTB Initiative
  6908.     if ptb? and (rand($game_party.total_agi) < rand($game_troop.total_agi) or
  6909.     $game_troop.surprise and !$scene.atb?)
  6910.       if !(($TEST or $BTEST) and Input.press?(Input::CTRL)) and
  6911.       !$game_troop.preemptive
  6912.         @ptb_initiative = true
  6913.         @info_viewport.ox = 64
  6914.         @actor_index = -1
  6915.         @status_window.index = -1
  6916.         @status_window.refresh
  6917.         @actor_command_window.openness = 0
  6918.         @party_command_window.openness = 0
  6919.       end
  6920.     end
  6921.     if ctb?
  6922.       make_action_orders_ctb
  6923.       if @action_battlers[0].actor?
  6924.         @actor_index = @action_battlers[0].index
  6925.         @status_window.index = @action_battlers[0].index
  6926.         actor = @status_window.actor
  6927.         @actor_command_window.setup(actor)
  6928.         if $game_switches[YEM::BATTLE_ENGINE::OPTIONS[:autocursor_sw]]
  6929.           index = actor.battle_command_index.to_i
  6930.           maximum = @actor_command_window.item_max - 1
  6931.           @actor_command_window.index = [index, maximum].min
  6932.         end
  6933.       else
  6934.         @ctb_initiative = true
  6935.         @info_viewport.ox = 64
  6936.         @actor_index = -1
  6937.         @status_window.index = -1
  6938.         @actor_command_window.openness = 0
  6939.         @party_command_window.openness = 0
  6940.       end
  6941.       @status_window.refresh
  6942.     end
  6943.     #---
  6944.     @info_viewport.visible = true
  6945.   end
  6946.  
  6947.   #--------------------------------------------------------------------------
  6948.   # dispose_info_viewport
  6949.   #--------------------------------------------------------------------------
  6950.   def dispose_info_viewport
  6951.     #---
  6952.     @status_window.dispose
  6953.     @status_hp_window.dispose
  6954.     @status_mp_window.dispose
  6955.     @status_rage_window.dispose
  6956.     @status_states_window.dispose
  6957.     #---
  6958.     @party_command_window.dispose
  6959.     @actor_command_window.dispose
  6960.     @confirm_command_window.dispose
  6961.     @info_viewport.dispose
  6962.     #---
  6963.     dispose_bem_windows
  6964.   end
  6965.  
  6966.   #--------------------------------------------------------------------------
  6967.   # overwrite method: update_info_viewport
  6968.   #--------------------------------------------------------------------------
  6969.   def update_info_viewport
  6970.     return if atb?
  6971.     @party_command_window.update
  6972.     @actor_command_window.update
  6973.     @confirm_command_window.update
  6974.     update_info_viewport_windows
  6975.   end
  6976.  
  6977.   #--------------------------------------------------------------------------
  6978.   # new method: update_info_viewport_windows
  6979.   #--------------------------------------------------------------------------
  6980.   def update_info_viewport_windows
  6981.     if @party_command_window.active and @info_viewport.ox > 0
  6982.       @info_viewport.ox = [@info_viewport.ox - 16, 0].max
  6983.     elsif @actor_command_window.active and @info_viewport.ox < 128
  6984.       @info_viewport.ox = [@info_viewport.ox + 16, 128].min
  6985.     elsif @confirm_command_window.active and @info_viewport.ox < 128
  6986.       @info_viewport.ox = [@info_viewport.ox + 16, 128].min
  6987.     end
  6988.   end
  6989.  
  6990.   #--------------------------------------------------------------------------
  6991.   # new method: force_preemptive_or_surprise
  6992.   #--------------------------------------------------------------------------
  6993.   def force_preemptive_or_surprise
  6994.     case $game_troop.troop.strike_case
  6995.     when 1
  6996.       $game_troop.preemptive = false
  6997.       $game_troop.surprise = false
  6998.     when 2
  6999.       $game_troop.preemptive = true
  7000.       $game_troop.surprise = false
  7001.     when 3
  7002.       $game_troop.preemptive = false
  7003.       $game_troop.surprise = true
  7004.     else
  7005.       return
  7006.     end
  7007.   end
  7008.  
  7009.   #--------------------------------------------------------------------------
  7010.   # new method: create_bem_windows
  7011.   #--------------------------------------------------------------------------
  7012.   def create_bem_windows
  7013.     @combo_window = Window_ComboCounter.new
  7014.     @combo_window.viewport = @spriteset.viewportA
  7015.     #---
  7016.     @view_help_window = Window_Help.new
  7017.     dh = @view_help_window.height
  7018.     @help_viewport = Viewport.new(0, Graphics.height-128-dh, Graphics.width, dh)
  7019.     @help_viewport.z = 100
  7020.     @view_help_window.viewport = @help_viewport
  7021.     @view_help_window.y = dh
  7022.     #---
  7023.     @target_help_window = Window_TargetHelp.new
  7024.     dh = @target_help_window.height
  7025.     @target_viewport = Viewport.new(0, 0, Graphics.width, dh)
  7026.     @target_viewport.z = 100
  7027.     @target_help_window.viewport = @target_viewport
  7028.     @target_help_window.y = -dh
  7029.     @target_help_window.active = false
  7030.     #--- Debug Window ---
  7031.     if $TEST or $BTEST
  7032.       @debug_window = Window_BattleDebug.new
  7033.       @debug_window.viewport = @help_viewport
  7034.     end
  7035.     #--- PTB Windows ---
  7036.     if ptb?
  7037.       @ptb_party_window = Window_PressTurns.new($game_party)
  7038.       @ptb_party_window.viewport = @spriteset.viewportA
  7039.       @ptb_troop_window = Window_PressTurns.new($game_troop)
  7040.       @ptb_troop_window.viewport = @spriteset.viewportA
  7041.     end    
  7042.   end
  7043.  
  7044.   #--------------------------------------------------------------------------
  7045.   # new method: dispose_bem_windows
  7046.   #--------------------------------------------------------------------------
  7047.   def dispose_bem_windows
  7048.     @combo_window.dispose if @combo_window != nil
  7049.     @debug_window.dispose if @debug_window != nil
  7050.     #---
  7051.     @ptb_party_window.dispose if @ptb_party_window != nil
  7052.     @ptb_troop_window.dispose if @ptb_troop_window != nil
  7053.     #---
  7054.     @view_help_window.dispose if @view_help_window != nil
  7055.     @help_viewport.dispose if @help_viewport != nil
  7056.     #---
  7057.     @target_help_window.dispose if @target_help_window != nil
  7058.     @target_viewport.dispose
  7059.   end
  7060.  
  7061.   #--------------------------------------------------------------------------
  7062.   # overwrite method: update
  7063.   #--------------------------------------------------------------------------
  7064.   def update # Scene_Battle
  7065.     super
  7066.     return unless $scene.is_a?(Scene_Battle)
  7067.     update_basic(true)
  7068.     update_info_viewport
  7069.     @message_window.visible = true if $game_message.visible
  7070.     update_input_windows unless atb?
  7071.     update_scene_change
  7072.   end
  7073.  
  7074.   #--------------------------------------------------------------------------
  7075.   # new method: update_input_windows
  7076.   #--------------------------------------------------------------------------
  7077.   def update_input_windows
  7078.     return if $game_message.visible
  7079.     return if judge_win_loss
  7080.     if @target_enemy_window != nil
  7081.       update_target_enemy_selection
  7082.     elsif @target_actor_window != nil
  7083.       update_target_actor_selection
  7084.     elsif @skill_window != nil
  7085.       update_skill_selection
  7086.     elsif @item_window != nil
  7087.       update_item_selection
  7088.     elsif @actor_status_window != nil
  7089.       update_actor_status
  7090.     elsif @options_window != nil
  7091.       update_options
  7092.     elsif @party_command_window.active
  7093.       update_party_command_selection
  7094.     elsif @actor_command_window.active
  7095.       update_actor_command_selection
  7096.     elsif @confirm_command_window.active
  7097.       update_confirm_command_selection
  7098.     elsif !atb?
  7099.       process_battle_event
  7100.       process_action
  7101.       process_battle_event
  7102.     end
  7103.   end
  7104.  
  7105.   #--------------------------------------------------------------------------
  7106.   # alias method: update_basic
  7107.   #--------------------------------------------------------------------------
  7108.   alias update_basic_bem update_basic unless $@
  7109.   def update_basic(main = false)
  7110.     update_party
  7111.     #---
  7112.     update_basic_bem(main)
  7113.     #---
  7114.     update_bem_windows
  7115.     update_atb
  7116.     call_debug_menu if ($TEST or $BTEST) and Input.trigger?(Input::F9)
  7117.   end
  7118.  
  7119.   #--------------------------------------------------------------------------
  7120.   # new method: update_party
  7121.   #--------------------------------------------------------------------------
  7122.   def update_party
  7123.     return if @current_party == $game_party.members
  7124.     @current_party = $game_party.members.clone
  7125.     @all_members = ($game_party.members + $game_troop.members).clone
  7126.     @spriteset.create_actors
  7127.     @spriteset.create_order_sprites
  7128.     make_action_orders
  7129.     wait(20, true)
  7130.   end
  7131.  
  7132.   #--------------------------------------------------------------------------
  7133.   # new method: update_bem_windows
  7134.   #--------------------------------------------------------------------------
  7135.   def update_bem_windows
  7136.     @status_window.update if @status_window != nil
  7137.     @status_hp_window.update if @status_hp_window != nil
  7138.     @status_mp_window.update if @status_mp_window != nil
  7139.     @status_rage_window.update if @status_rage_window != nil
  7140.     @status_states_window.update if @status_states_window != nil
  7141.     #---
  7142.     @combo_window.update if @combo_window != nil
  7143.     @debug_window.update if @debug_window != nil
  7144.     #---
  7145.     if scroll_help_viewport? and !@judge_win_loss
  7146.       height = @view_help_window.height
  7147.       @help_viewport.oy = [@help_viewport.oy + 4, height].min
  7148.     else
  7149.       @help_viewport.oy = [@help_viewport.oy - 4, 0].max
  7150.     end
  7151.     if @target_help_window.active and !@judge_win_loss
  7152.       height = @target_help_window.height
  7153.       @target_viewport.oy = [@target_viewport.oy - 4, -height].max
  7154.     else
  7155.       @target_viewport.oy = [@target_viewport.oy + 4, 0].min
  7156.     end
  7157.     #---
  7158.     if ptb?
  7159.       @ptb_party_window.update
  7160.       @ptb_troop_window.update
  7161.     end
  7162.   end
  7163.  
  7164.   #--------------------------------------------------------------------------
  7165.   # new method: setup_atb
  7166.   #--------------------------------------------------------------------------
  7167.   def setup_atb
  7168.     $game_troop.create_atb_max_speed
  7169.     $game_troop.create_initial_atb_speeds
  7170.     $game_party.create_initial_atb_speeds
  7171.     @ctr_per_turn = YEM::BATTLE_ENGINE::ATB_RULES[:turns_ctr]
  7172.     @pause_atb = false
  7173.     @atb_counter = 0
  7174.     @clockticks = 0
  7175.   end
  7176.  
  7177.   #--------------------------------------------------------------------------
  7178.   # new method: setup_ctb
  7179.   #--------------------------------------------------------------------------
  7180.   def setup_ctb
  7181.     $game_troop.create_ctb_max_speed
  7182.     $game_troop.create_initial_ctb_speeds
  7183.     $game_party.create_initial_ctb_speeds
  7184.     @ctr_per_turn = YEM::BATTLE_ENGINE::CTB_RULES[:turns_ctr]
  7185.     @clockticks = 0
  7186.   end
  7187.  
  7188.   #--------------------------------------------------------------------------
  7189.   # new method: update_atb
  7190.   #--------------------------------------------------------------------------
  7191.   def update_atb
  7192.     return unless atb?
  7193.     update_info_viewport_windows
  7194.     return if @judge_win_loss
  7195.     @party_command_window.update
  7196.     @actor_command_window.update
  7197.     @confirm_command_window.update
  7198.     update_input_windows
  7199.     return if @pause_atb
  7200.     return if $game_troop.interpreter.running?
  7201.     if atb_action_ready?
  7202.       process_action
  7203.       return
  7204.     end
  7205.     @atb_counter += 1
  7206.     return unless @atb_counter % atb_speed == 0
  7207.     @clockticks += 1
  7208.     if @clockticks % @ctr_per_turn == 0
  7209.       $game_troop.turn_ending = true
  7210.       process_battle_event
  7211.       $game_troop.turn_ending = false
  7212.       $game_troop.increase_turn
  7213.       if YEM::BATTLE_ENGINE::ATB_COMMON_EVENTS[:turn_update] != nil
  7214.         event_id = YEM::BATTLE_ENGINE::ATB_COMMON_EVENTS[:turn_update]
  7215.         $game_temp.common_event_id = event_id
  7216.         process_battle_event
  7217.       end
  7218.       process_battle_event
  7219.     end
  7220.     for member in @all_members; member.update_atb_speed; end
  7221.     pause_atb(true) if input_atb_actor?
  7222.   end
  7223.  
  7224.   #--------------------------------------------------------------------------
  7225.   # new method: input_atb_actor?
  7226.   #--------------------------------------------------------------------------
  7227.   def input_atb_actor?
  7228.     return false unless wait_atb?
  7229.     for member in $game_party.existing_members
  7230.       next if member.atb_speed < $game_troop.atb_threshold
  7231.       if member.action.wait?
  7232.         @actor_index = member.index
  7233.         @status_window.index = @actor_index
  7234.         @selected_battler = $game_party.members[@actor_index]
  7235.         start_actor_command_selection
  7236.         YEM::BATTLE_ENGINE::ATB_WAIT_SOUND.play
  7237.         return true
  7238.       end
  7239.     end
  7240.     return false
  7241.   end
  7242.  
  7243.   #--------------------------------------------------------------------------
  7244.   # new method: atb_speed
  7245.   #--------------------------------------------------------------------------
  7246.   def atb_speed
  7247.     value = $game_variables[YEM::BATTLE_ENGINE::OPTIONS[:atb_svariable]]
  7248.     value = 20 - value * 2
  7249.     return [[value, 20].min, 1].max
  7250.   end
  7251.  
  7252.   #--------------------------------------------------------------------------
  7253.   # new method: atb_action_ready?
  7254.   #--------------------------------------------------------------------------
  7255.   def atb_action_ready?
  7256.     return false if @active_battler != nil
  7257.     return true if $game_troop.forcing_battler != nil
  7258.     return $game_troop.atb_ready != []
  7259.   end
  7260.  
  7261.   #--------------------------------------------------------------------------
  7262.   # new method: update_ctb_clockticks
  7263.   #--------------------------------------------------------------------------
  7264.   def update_ctb_clockticks
  7265.     return unless ctb?
  7266.     for member in ($game_troop.members + $game_party.members)
  7267.       $game_troop.ctb_ready.delete(member) if !member.movable?
  7268.       next if member.ctb_speed >= $game_troop.ctb_max
  7269.       $game_troop.ctb_ready.delete(member)
  7270.     end
  7271.     #---
  7272.     loop do
  7273.       break if $game_troop.ctb_ready.size > 0
  7274.       return if judge_win_loss
  7275.       @clockticks += 1
  7276.       if @clockticks % @ctr_per_turn == 0
  7277.         $game_troop.turn_ending = true
  7278.         process_battle_event
  7279.         $game_troop.turn_ending = false
  7280.         $game_troop.increase_turn
  7281.         if YEM::BATTLE_ENGINE::CTB_COMMON_EVENTS[:turn_update] != nil
  7282.           event_id = YEM::BATTLE_ENGINE::CTB_COMMON_EVENTS[:turn_update]
  7283.           $game_temp.common_event_id = event_id
  7284.           process_battle_event
  7285.         end
  7286.         process_battle_event
  7287.       end
  7288.       for member in @all_members
  7289.         if member.actor? and member.auto_battle and member.action.wait?
  7290.           member.make_action
  7291.         end
  7292.         member.update_ctb_speed
  7293.       end
  7294.     end
  7295.     #---
  7296.     @first_ctb_update = true
  7297.     @active_battler = $game_troop.ctb_ready[0]
  7298.     @active_battler.action.prepare unless @active_battler.action.forcing
  7299.     if !@active_battler.movable? and @active_battler.action.valid?
  7300.       process_action
  7301.       return
  7302.     end
  7303.     if @active_battler.actor? and (@active_battler.action.wait? or
  7304.     !@active_battler.action.valid?) and !@active_battler.auto_battle
  7305.       @selected_battler = @active_battler
  7306.       @actor_index = @selected_battler.index
  7307.       @status_window.index = @selected_battler.index
  7308.       @selected_battler.action.ctb_guarding_queue = false
  7309.       @selected_battler.action.ctb_guarding = false
  7310.       start_actor_command_selection
  7311.     elsif @active_battler.actor?
  7312.       @actor_command_window.active = false
  7313.       close_input_windows
  7314.       process_action
  7315.       return if @active_battler == nil
  7316.       @active_battler.make_action if @active_battler.auto_battle
  7317.     elsif @active_battler.enemy?
  7318.       @actor_command_window.active = false
  7319.       close_input_windows
  7320.       create_enemy_ctb_action
  7321.     end
  7322.   end
  7323.  
  7324.   #--------------------------------------------------------------------------
  7325.   # new method: create_enemy_ctb_action
  7326.   #--------------------------------------------------------------------------
  7327.   def create_enemy_ctb_action
  7328.     if @active_battler.action.wait? or @active_battler.action.nothing?
  7329.       @active_battler.make_action
  7330.       if @active_battler.action.skill? and
  7331.       @active_battler.action.skill.speed < 0
  7332.         $game_troop.ctb_ready.shift
  7333.         $game_troop.clear_ctb_cache
  7334.         make_action_orders
  7335.         return
  7336.       end
  7337.     end
  7338.     process_action
  7339.   end
  7340.  
  7341.   #--------------------------------------------------------------------------
  7342.   # new method: scroll_help_viewport?
  7343.   #--------------------------------------------------------------------------
  7344.   def scroll_help_viewport?
  7345.     if YEM::BATTLE_ENGINE::TARGET_WINDOW[:hidehelp]
  7346.       return false if @target_actor_window != nil
  7347.       return false if @target_enemy_window != nil
  7348.     end
  7349.     if @skill_window != nil
  7350.       return false if @skill_window.skill == nil
  7351.       return true
  7352.     end
  7353.     if @item_window != nil
  7354.       return false if @item_window.item == nil
  7355.       return true
  7356.     end
  7357.     return false
  7358.   end
  7359.  
  7360.   #--------------------------------------------------------------------------
  7361.   # new method: win_loss_flag
  7362.   #--------------------------------------------------------------------------
  7363.   def win_loss_flag; return @judge_win_loss; end
  7364.  
  7365.   #--------------------------------------------------------------------------
  7366.   # alias method: judge_win_loss
  7367.   #--------------------------------------------------------------------------
  7368.   alias judge_win_loss_bem judge_win_loss unless $@
  7369.   def judge_win_loss
  7370.     return false if @action_occuring
  7371.     return judge_win_loss_bem
  7372.   end
  7373.  
  7374.   #--------------------------------------------------------------------------
  7375.   # overwrite method: process_battle_start
  7376.   #--------------------------------------------------------------------------
  7377.   def process_battle_start
  7378.     @message_window.clear
  7379.     #---
  7380.     if YEM::BATTLE_ENGINE::DISPLAY_MESSAGE[:enemy_appear]
  7381.       for name in $game_troop.enemy_names
  7382.         text = sprintf(Vocab::Emerge, name)
  7383.         $game_message.texts.push(text)
  7384.       end
  7385.     end
  7386.     #---
  7387.     if YEM::BATTLE_ENGINE::DISPLAY_MESSAGE[:advantage] and !ptb?
  7388.       if $game_troop.preemptive
  7389.         text = sprintf(Vocab::Preemptive, $game_party.name)
  7390.         $game_message.texts.push(text)
  7391.         @pause_atb = true
  7392.       elsif $game_troop.surprise
  7393.         text = sprintf(Vocab::Surprise, $game_party.name)
  7394.         $game_message.texts.push(text)
  7395.         @pause_atb = true
  7396.       end
  7397.     end
  7398.     #---
  7399.     wait_for_message
  7400.     pause_atb(false)
  7401.     @message_window.clear
  7402.     @message_window.visible = false
  7403.     $game_party.update_battle_start
  7404.     $game_troop.update_battle_start
  7405.     make_escape_ratio
  7406.     $game_troop.make_actions
  7407.     make_action_orders
  7408.     if YEM::BATTLE_ENGINE::ALL_COMMON_EVENTS[:battle_start] != nil
  7409.       event_id = YEM::BATTLE_ENGINE::ALL_COMMON_EVENTS[:battle_start]
  7410.       $game_temp.common_event_id = event_id
  7411.       process_battle_event
  7412.     end
  7413.     process_battle_event
  7414.     if ctb?
  7415.       update_ctb_clockticks
  7416.       return
  7417.     end
  7418.     if enemy_initiative?
  7419.       enemy_turn_start
  7420.     else
  7421.       party_turn_start
  7422.     end
  7423.   end
  7424.  
  7425.   #--------------------------------------------------------------------------
  7426.   # new method: enemy_initiative?
  7427.   #--------------------------------------------------------------------------
  7428.   def enemy_initiative?
  7429.     return false if atb?
  7430.     return false if $game_troop.preemptive
  7431.     return true if ptb? and @ptb_initiative
  7432.     return true if ctb? and @ctb_initiative
  7433.     return $game_troop.surprise
  7434.   end
  7435.  
  7436.   #--------------------------------------------------------------------------
  7437.   # new method: party_turn_start
  7438.   #--------------------------------------------------------------------------
  7439.   def party_turn_start
  7440.     if ptb?
  7441.       ptb_remove_states_auto($game_party)
  7442.       ptb_turn_end($game_troop)
  7443.       @active_battler = nil
  7444.       $game_party.reset_ptb_turns
  7445.       $game_party.update_group_cooldowns
  7446.       @ptb_party_window.appear
  7447.       @ptb_troop_window.disappear
  7448.       ptb_party_berserk
  7449.     end
  7450.     @message_window.clear
  7451.     @message_window.visible = false
  7452.     if ptb? and YEM::BATTLE_ENGINE::PTB_COMMON_EVENTS[:party_turn] != nil
  7453.       event_id = YEM::BATTLE_ENGINE::PTB_COMMON_EVENTS[:party_turn]
  7454.       $game_temp.common_event_id = event_id
  7455.       process_battle_event
  7456.     end
  7457.     #---
  7458.     berserk_members = 0
  7459.     create_autobattler_actions unless ptb?
  7460.     for member in $game_party.existing_members
  7461.       next unless member.berserker? or member.confusion? or member.auto_battle
  7462.       berserk_members += 1
  7463.     end
  7464.     if berserk_members >= $game_party.existing_members.size
  7465.       enemy_turn_start
  7466.       return
  7467.     end
  7468.     #---
  7469.     @party_input_flag = true
  7470.     @actor_index = -1
  7471.     next_actor
  7472.   end
  7473.  
  7474.   #--------------------------------------------------------------------------
  7475.   # new method: enemy_turn_start
  7476.   #--------------------------------------------------------------------------
  7477.   def enemy_turn_start
  7478.     ptb_remove_states_auto($game_troop)
  7479.     ptb_turn_end($game_party)
  7480.     $game_troop.make_actions
  7481.     make_action_orders
  7482.     @party_input_flag = false
  7483.     $game_party.clear_actions if ptb?
  7484.     if ptb? and YEM::BATTLE_ENGINE::PTB_COMMON_EVENTS[:troop_turn] != nil
  7485.       event_id = YEM::BATTLE_ENGINE::PTB_COMMON_EVENTS[:troop_turn]
  7486.       $game_temp.common_event_id = event_id
  7487.       process_battle_event
  7488.     end
  7489.     start_main
  7490.   end
  7491.  
  7492.   #--------------------------------------------------------------------------
  7493.   # new method: create_autobattler_actions
  7494.   #--------------------------------------------------------------------------
  7495.   def create_autobattler_actions
  7496.     for member in $game_party.members
  7497.       next if member == nil
  7498.       next unless member.auto_battle
  7499.       unless member.exist?
  7500.         member.action.clear
  7501.         @status_window.draw_item(member.index)
  7502.         next
  7503.       end
  7504.       member.make_action
  7505.       @status_window.draw_item(member.index)
  7506.     end
  7507.   end
  7508.  
  7509.   #--------------------------------------------------------------------------
  7510.   # overwrite method: make_escape_ratio
  7511.   #--------------------------------------------------------------------------
  7512.   def make_escape_ratio
  7513.     actors_agi = $game_party.average_agi
  7514.     enemies_agi = $game_troop.average_agi
  7515.     @escape_ratio = 150 - 100 * enemies_agi / actors_agi
  7516.     if @action_escape and (dtb? or ptb?)
  7517.       @escape_ratio /= $game_party.members.size
  7518.     end
  7519.     @escape_ratio = 100 if ($TEST or $BTEST) and Input.press?(Input::CTRL)
  7520.   end
  7521.  
  7522.   #--------------------------------------------------------------------------
  7523.   # overwrite method: process_escape
  7524.   #--------------------------------------------------------------------------
  7525.   def process_escape
  7526.     @hide_battlecursor = true
  7527.     make_escape_ratio
  7528.     @message_window.visible = true
  7529.     text = sprintf(Vocab::EscapeStart, $game_party.name)
  7530.     $game_message.texts.push(text) unless @action_escape
  7531.     if $game_troop.preemptive
  7532.       success = true
  7533.     else
  7534.       success = (rand(100) < @escape_ratio)
  7535.     end
  7536.     Sound.play_escape unless @action_escape
  7537.     if success
  7538.       @enemy_gauge_window.visible = false if @enemy_gauge_window != nil
  7539.       $game_message.texts[0] += "\\.\\." unless @action_escape
  7540.       action_list = YEM::DEFAULT_ACTIONS::ACTOR_ESCAPE_ACTIONS
  7541.       perform_action_list(action_list, $game_party.existing_members)
  7542.       wait_for_message unless @action_escape
  7543.       battle_end(1)
  7544.     else
  7545.       if @action_escape
  7546.         @message_window.add_instant_text(Vocab::EscapeFailure)
  7547.         action_list = [["AUTOMELODY", ["RETURN ORIGIN"]]]
  7548.         battler = @selected_battler if @selected_battler != nil
  7549.         battler = @active_battler if @active_battler != nil
  7550.         perform_action_list(action_list, [battler])
  7551.       else
  7552.         $game_message.texts.push('\.' + Vocab::EscapeFailure)
  7553.         wait_for_message
  7554.         $game_party.clear_actions
  7555.         @status_window.refresh
  7556.         start_main
  7557.         @hide_battlecursor = false
  7558.       end
  7559.     end
  7560.   end
  7561.  
  7562.   #--------------------------------------------------------------------------
  7563.   # overwrite method: process_victory
  7564.   #--------------------------------------------------------------------------
  7565.   def process_victory
  7566.     @judge_win_loss = true
  7567.     pause_atb(true, true)
  7568.     @enemy_gauge_window.dispose if @enemy_gauge_window != nil
  7569.     @hide_battlecursor = true
  7570.     @party_input_flag = true
  7571.     @message_window.visible = true
  7572.     RPG::BGM.stop
  7573.     $game_system.battle_end_me.play
  7574.     unless $BTEST
  7575.       $game_temp.map_bgm.play
  7576.       $game_temp.map_bgs.play
  7577.     end
  7578.     start_victory_poses
  7579.     @spriteset.update_dtb_order
  7580.     @spriteset.update_ctb_order
  7581.     wait(45,true)
  7582.     if YEM::BATTLE_ENGINE::DEFAULT_VICTORY_MESSAGE
  7583.       @message_window.dispose
  7584.       @message_window = Window_BattleMessage.new
  7585.       @info_viewport.oy = Graphics.height * 8
  7586.     else
  7587.       close_input_windows
  7588.       wait(10)
  7589.     end
  7590.     display_exp_and_gold
  7591.     display_drop_items
  7592.     display_level_up
  7593.     battle_end(0)
  7594.   end
  7595.  
  7596.   #--------------------------------------------------------------------------
  7597.   # overwrite method: process_defeat
  7598.   #--------------------------------------------------------------------------
  7599.   def process_defeat
  7600.     @hide_battlecursor = true
  7601.     @judge_win_loss = true
  7602.     pause_atb(true, true)
  7603.     @message_window.visible = true
  7604.     text = sprintf(Vocab::Defeat, $game_party.name)
  7605.     $game_message.texts.push(text)
  7606.     wait_for_message
  7607.     battle_end(2)
  7608.   end
  7609.  
  7610.   #--------------------------------------------------------------------------
  7611.   # overwrite method: battle_end
  7612.   #--------------------------------------------------------------------------
  7613.   def battle_end(result)
  7614.     reset_extra_calculation_modifiers
  7615.     if result == 2 and not $game_troop.can_lose
  7616.       call_gameover
  7617.     else
  7618.       $game_troop.distribute_jp if result == 0 and $imported["SkillOverhaul"]
  7619.       $game_party.update_battle_over
  7620.       $game_troop.clear
  7621.       if $game_temp.battle_proc != nil
  7622.         $game_temp.battle_proc.call(result)
  7623.         $game_temp.battle_proc = nil
  7624.       end
  7625.       unless $BTEST
  7626.         $game_temp.map_bgm.play
  7627.         $game_temp.map_bgs.play
  7628.       end
  7629.       @message_window.clear
  7630.       $game_message.clear
  7631.       $scene = Scene_Map.new
  7632.       Graphics.fadeout(30)
  7633.       if YEM::BATTLE_ENGINE::ALL_COMMON_EVENTS[:battle_finish] != nil
  7634.         event_id = YEM::BATTLE_ENGINE::ALL_COMMON_EVENTS[:battle_finish]
  7635.         $game_temp.common_event_id = event_id
  7636.       end
  7637.     end
  7638.     $game_temp.in_battle = false
  7639.   end
  7640.  
  7641.   #--------------------------------------------------------------------------
  7642.   # new method: call_debug_menu
  7643.   #--------------------------------------------------------------------------
  7644.   def call_debug_menu
  7645.     return if @debug_entry_window != nil
  7646.     Sound.play_decision
  7647.     Graphics.freeze
  7648.     hide_screen_items
  7649.     snapshot_for_background
  7650.     $scene = Scene_Debug.new
  7651.     $scene.main
  7652.     $scene = self
  7653.     show_screen_items
  7654.     @actor_command_window.refresh
  7655.     @status_window.refresh
  7656.     perform_transition
  7657.   end
  7658.  
  7659.   #--------------------------------------------------------------------------
  7660.   # new method: call_equip_menu
  7661.   #--------------------------------------------------------------------------
  7662.   def call_equip_menu
  7663.     Graphics.freeze
  7664.     hide_screen_items
  7665.     snapshot_for_background
  7666.     previous_equips = @selected_battler.equips.clone
  7667.     $scene = Scene_Equip.new(@selected_battler.index)
  7668.     $scene.main
  7669.     $scene = self
  7670.     #---
  7671.     if @selected_battler.equips != previous_equips
  7672.       @selected_battler.equip_cooldown = YEM::BATTLE_ENGINE::EQUIP_COOLDOWN
  7673.       if atb?
  7674.         ctr = YEM::BATTLE_ENGINE::ATB_RULES[:turns_ctr]
  7675.         @selected_battler.equip_clocktick = ctr
  7676.       elsif ctb?
  7677.         ctr = YEM::BATTLE_ENGINE::CTB_RULES[:turns_ctr]
  7678.         @selected_battler.equip_clocktick = ctr
  7679.       end
  7680.     end
  7681.     #---
  7682.     show_screen_items
  7683.     @actor_command_window.refresh
  7684.     @status_window.refresh
  7685.     perform_transition
  7686.   end
  7687.  
  7688.   #--------------------------------------------------------------------------
  7689.   # new method: hide_screen_items
  7690.   #--------------------------------------------------------------------------
  7691.   def hide_screen_items
  7692.     @info_viewport.visible = false
  7693.     @spriteset.viewportA.visible = false
  7694.     @spriteset.viewportB.visible = false
  7695.     @spriteset.viewportC.visible = false
  7696.   end
  7697.  
  7698.   #--------------------------------------------------------------------------
  7699.   # new method: show_screen_items
  7700.   #--------------------------------------------------------------------------
  7701.   def show_screen_items
  7702.     @info_viewport.visible = true
  7703.     @spriteset.viewportA.visible = true
  7704.     @spriteset.viewportB.visible = true
  7705.     @spriteset.viewportC.visible = true
  7706.   end
  7707.  
  7708.   #--------------------------------------------------------------------------
  7709.   # overwrite method: next_actor
  7710.   #--------------------------------------------------------------------------
  7711.   def next_actor
  7712.     if @actor_index == $game_party.members.size-1
  7713.       @status_shortcut_index = $game_party.members.size-1
  7714.       start_confirm_command_selection
  7715.       return
  7716.     end
  7717.     @status_window.index = @actor_index += 1
  7718.     @selected_battler = $game_party.members[@actor_index]
  7719.     start_actor_command_selection
  7720.   end
  7721.  
  7722.   #--------------------------------------------------------------------------
  7723.   # overwrite method: prior_actor
  7724.   #--------------------------------------------------------------------------
  7725.   def prior_actor
  7726.     if @actor_index == 0
  7727.       @status_shortcut_index = 0
  7728.       start_party_command_selection
  7729.       return
  7730.     end
  7731.     @status_window.index = @actor_index -= 1
  7732.     @selected_battler = $game_party.members[@actor_index]
  7733.     start_actor_command_selection
  7734.   end
  7735.  
  7736.   #--------------------------------------------------------------------------
  7737.   # overwrite method: start_party_command_selection
  7738.   #--------------------------------------------------------------------------
  7739.   def start_party_command_selection
  7740.     return unless $game_temp.in_battle
  7741.     pause_atb(true)
  7742.     @status_window.refresh
  7743.     @status_window.index = @actor_index = -1
  7744.     @party_command_window.openness = 255
  7745.     @actor_command_window.openness = 255
  7746.     @confirm_command_window.active = false
  7747.     @selected_battler = nil
  7748.     @info_viewport.visible = true
  7749.     @message_window.visible = false unless atb?
  7750.     if !$game_switches[YEM::BATTLE_ENGINE::OPTIONS[:autocursor_sw]]
  7751.       @party_command_window.index = 0
  7752.     end
  7753.     @party_command_window.active = true
  7754.     @actor_command_window.active = false
  7755.     return if atb?
  7756.     loop do
  7757.       update_basic
  7758.       break if @info_viewport.ox == 0
  7759.       if @info_viewport.ox >= 0
  7760.         @info_viewport.ox -= [16, (0 - @info_viewport.ox).abs].min
  7761.       else
  7762.         @info_viewport.ox += [16, (0 - @info_viewport.ox).abs].min
  7763.       end
  7764.     end
  7765.   end
  7766.  
  7767.   #--------------------------------------------------------------------------
  7768.   # overwrite method: update_party_command_selection
  7769.   #--------------------------------------------------------------------------
  7770.   def update_party_command_selection
  7771.     if Input.trigger?(Input::C)
  7772.       party_command_case
  7773.     elsif Input.repeat?(Input::RIGHT)
  7774.       Sound.play_cursor
  7775.       @actor_index = -1
  7776.       next_actor
  7777.     elsif Input.trigger?(Input::L)
  7778.       Sound.play_cursor
  7779.       @actor_index = @status_shortcut_index - 1
  7780.       next_actor
  7781.     elsif Input.trigger?(Input::R)
  7782.       Sound.play_cursor
  7783.       start_confirm_command_selection
  7784.     #--- Debug Shortcuts ---
  7785.     elsif ($TEST or $BTEST) and Input.trigger?(Input::F5)
  7786.       Sound.play_recovery
  7787.       for member in $game_party.members
  7788.         member.recover_all
  7789.         member.gain_rage(member.max_rage)
  7790.       end
  7791.     elsif ($TEST or $BTEST) and Input.trigger?(Input::F6)
  7792.       Sound.play_use_item
  7793.       for member in $game_party.members
  7794.         member.hp += member.maxhp
  7795.       end
  7796.     elsif ($TEST or $BTEST) and Input.trigger?(Input::F7)
  7797.       Sound.play_use_skill
  7798.       for member in $game_party.members
  7799.         member.mp += member.maxmp
  7800.         member.gain_rage(member.max_rage)
  7801.       end
  7802.     elsif ($TEST or $BTEST) and Input.trigger?(Input::F8)
  7803.       Sound.play_actor_damage
  7804.       if Input.press?(Input::SHIFT)
  7805.         for member in $game_party.members
  7806.           member.hp -= member.maxhp/4 + 4
  7807.           member.mp -= member.maxmp/4 + 4
  7808.           member.lose_rage(member.max_rage/4)
  7809.           member.perform_collapse
  7810.         end
  7811.       else
  7812.         for member in $game_party.members
  7813.           member.hp = 1
  7814.           member.mp = 0
  7815.           member.lose_rage(member.max_rage)
  7816.         end
  7817.       end
  7818.     elsif ($TEST or $BTEST) and Input.press?(Input::CTRL) and
  7819.     Input.press?(Input::SHIFT)
  7820.       for enemy in $game_troop.existing_members
  7821.         enemy.hp = 0
  7822.         enemy.perform_collapse
  7823.       end
  7824.     end
  7825.   end
  7826.  
  7827.   #--------------------------------------------------------------------------
  7828.   # new method: party_command_case
  7829.   #--------------------------------------------------------------------------
  7830.   def party_command_case
  7831.     case @party_command_window.item
  7832.     when :fight
  7833.       Sound.play_decision
  7834.       @status_window.index = @actor_index = -1
  7835.       next_actor
  7836.     when :execute
  7837.       Sound.play_decision
  7838.       start_confirm_command_selection
  7839.     when :option
  7840.       Sound.play_decision
  7841.       start_options(@party_command_window)
  7842.     when :escape
  7843.       if $game_troop.can_escape == false
  7844.         Sound.play_buzzer
  7845.         return
  7846.       end
  7847.       Sound.play_decision
  7848.       process_escape
  7849.     #---
  7850.     when :turnskip
  7851.       Sound.play_decision
  7852.       enemy_turn_start
  7853.     #---
  7854.     when :atb_type
  7855.       Sound.play_decision
  7856.       variable = YEM::BATTLE_ENGINE::OPTIONS[:atb_avariable]
  7857.       $game_variables[variable] += 1
  7858.       $game_variables[variable] = 0 if $game_variables[variable] > 3
  7859.       @party_command_window.refresh
  7860.       @confirm_command_window.refresh
  7861.     when :atb_speed
  7862.       Sound.play_decision
  7863.       variable = YEM::BATTLE_ENGINE::OPTIONS[:atb_svariable]
  7864.       $game_variables[variable] += 1
  7865.       $game_variables[variable] = 1 if $game_variables[variable] > 10
  7866.       @party_command_window.refresh
  7867.       @confirm_command_window.refresh
  7868.     end
  7869.   end
  7870.  
  7871.   #--------------------------------------------------------------------------
  7872.   # overwrite method: start_actor_command_selection
  7873.   #--------------------------------------------------------------------------
  7874.   def start_actor_command_selection
  7875.     update_battler_poses
  7876.     @party_command_window.active = false
  7877.     @confirm_command_window.active = false
  7878.     pause_atb(false)
  7879.     @confirm_command_window.openness = 0
  7880.     @actor_command_window.openness = 255 if @actor_command_window.openness == 0
  7881.     @actor_command_window.setup(@selected_battler)
  7882.     @actor_command_window.active = true
  7883.     if $game_switches[YEM::BATTLE_ENGINE::OPTIONS[:autocursor_sw]]
  7884.       index = @selected_battler.battle_command_index.to_i
  7885.       maximum = @actor_command_window.item_max - 1
  7886.       @actor_command_window.index = [index, maximum].min
  7887.     end
  7888.     @selected_battler.battle_command_index = nil
  7889.     update_battle_cursor
  7890.   end
  7891.  
  7892.   #--------------------------------------------------------------------------
  7893.   # overwrite method: update_actor_command_selection
  7894.   #--------------------------------------------------------------------------
  7895.   def update_actor_command_selection
  7896.     if @selected_battler.battle_command_index != @actor_command_window.index
  7897.       @selected_battler.battle_command_index = @actor_command_window.index
  7898.       if (dtb? or ctb?) and !@selected_battler.auto_battle
  7899.         $game_troop.clear_ctb_cache
  7900.         last_action = @selected_battler.action.clone
  7901.         case @actor_command_window.item
  7902.         when :attack;  @selected_battler.action.set_attack
  7903.         when :guard;   @selected_battler.action.set_guard
  7904.         else
  7905.           item = @actor_command_window.item
  7906.           array = YEM::BATTLE_ENGINE::SKILL_COMMANDS[item]
  7907.           if array != nil
  7908.             skill = $data_skills[array[0]]
  7909.             @selected_battler.action.set_skill(skill.id) if skill != nil
  7910.           end
  7911.         end
  7912.         make_action_orders
  7913.         @selected_battler.action = last_action
  7914.       end
  7915.       make_action_orders if @selected_battler.auto_battle and (dtb? or ctb?)
  7916.     end
  7917.     #---
  7918.     if Input.trigger?(Input::B)
  7919.       Sound.play_cancel
  7920.       cancel_action
  7921.     elsif Input.trigger?(Input::C)
  7922.       actor_command_case
  7923. #~     elsif Input.repeat?(Input::LEFT)  # Disable selecting actors when it's not
  7924. #~       Sound.play_cursor               # their turn; comment out all this above
  7925. #~       prior_actor                     # the phrase "Debug Shortcuts"
  7926. #~     elsif Input.repeat?(Input::RIGHT)
  7927. #~       Sound.play_cursor
  7928. #~       next_actor
  7929. #~     elsif Input.trigger?(Input::L)
  7930. #~       Sound.play_cursor
  7931. #~       @status_shortcut_index = @status_window.index
  7932. #~       start_party_command_selection
  7933. #~     elsif Input.trigger?(Input::R)
  7934. #~       Sound.play_cursor
  7935. #~       @status_shortcut_index = @status_window.index
  7936. #~       start_confirm_command_selection
  7937.     #--- Debug Shortcuts ---
  7938.     elsif ($TEST or $BTEST) and Input.trigger?(Input::F5)
  7939.       Sound.play_recovery
  7940.       @selected_battler.recover_all
  7941.       @selected_battler.gain_rage(@selected_battler.max_rage)
  7942.     elsif ($TEST or $BTEST) and Input.trigger?(Input::F6)
  7943.       Sound.play_use_item
  7944.       if Input.press?(Input::SHIFT)
  7945.         @selected_battler.hp += @selected_battler.maxhp/5
  7946.       else
  7947.         @selected_battler.hp = @selected_battler.maxhp
  7948.       end
  7949.     elsif ($TEST or $BTEST) and Input.trigger?(Input::F7)
  7950.       Sound.play_use_skill
  7951.       if Input.press?(Input::SHIFT)
  7952.         @selected_battler.mp += @selected_battler.maxmp/5
  7953.         @selected_battler.gain_rage(@selected_battler.max_rage/5)
  7954.       else
  7955.         @selected_battler.mp = @selected_battler.maxmp
  7956.         @selected_battler.gain_rage(@selected_battler.max_rage)
  7957.       end
  7958.     elsif ($TEST or $BTEST) and Input.trigger?(Input::F8)
  7959.       Sound.play_actor_damage
  7960.       if Input.press?(Input::SHIFT)
  7961.         @selected_battler.hp -= @selected_battler.maxhp/4 + 4
  7962.         @selected_battler.perform_collapse
  7963.       elsif Input.press?(Input::CTRL)
  7964.         @selected_battler.mp -= @selected_battler.maxmp/4 + 4
  7965.         @selected_battler.lose_rage(@selected_battler.max_rage/4)
  7966.       else
  7967.         @selected_battler.hp = 1
  7968.         @selected_battler.mp = 0
  7969.         @selected_battler.lose_rage(@selected_battler.max_rage)
  7970.       end
  7971.     elsif ($TEST or $BTEST) and Input.press?(Input::CTRL) and
  7972.     Input.press?(Input::SHIFT)
  7973.       for enemy in $game_troop.existing_members
  7974.         enemy.hp = 0
  7975.         enemy.perform_collapse
  7976.       end
  7977.     end
  7978.   end
  7979.  
  7980.   #--------------------------------------------------------------------------
  7981.   # new method: actor_command_case
  7982.   #--------------------------------------------------------------------------
  7983.   def actor_command_case
  7984.     if !@actor_command_window.enabled?(@actor_command_window.item)
  7985.       if @selected_battler.inputable? and !@selected_battler.auto_battle
  7986.         Sound.play_buzzer
  7987.       else
  7988.         Sound.play_cursor
  7989.         if !dtb? and (@actor_index == $game_party.members.size - 1)
  7990.           @actor_index = -1
  7991.         end
  7992.         next_actor
  7993.       end
  7994.       return
  7995.     end
  7996.     #---
  7997.     case @actor_command_window.item
  7998.     when :attack
  7999.       Sound.play_decision
  8000.       @selected_battler.action.set_attack
  8001.       start_target_enemy_selection
  8002.     when :skill
  8003.       Sound.play_decision
  8004.       start_skill_selection
  8005.     when :guard
  8006.       Sound.play_decision
  8007.       @selected_battler.action.set_guard
  8008.       confirm_action
  8009.     when :item
  8010.       Sound.play_decision
  8011.       start_item_selection
  8012.     when :equip
  8013.       Sound.play_decision
  8014.       call_equip_menu
  8015.     when :escape
  8016.       Sound.play_decision
  8017.       @selected_battler.action.set_escape
  8018.       confirm_action
  8019.     else
  8020.       Sound.play_decision
  8021.       @command_action = true
  8022.       @skill = @actor_command_window.skill
  8023.       determine_skill
  8024.     end
  8025.   end
  8026.  
  8027.   #--------------------------------------------------------------------------
  8028.   # new method: cancel_action
  8029.   #--------------------------------------------------------------------------
  8030.   def cancel_action
  8031.     return if @selected_battler == @active_battler
  8032.     @selected_battler.action.clear if allow_cancel_action?
  8033.     @status_window.draw_item(@selected_battler.index)
  8034.     $game_troop.clear_ctb_cache if ctb?
  8035.     make_action_orders unless @actor_command_window.active
  8036.     if $game_switches[YEM::BATTLE_ENGINE::OPTIONS[:next_actor_sw]] and !ctb?
  8037.       prior_actor unless @actor_index == 0
  8038.     end
  8039.   end
  8040.  
  8041.   #--------------------------------------------------------------------------
  8042.   # new method: allow_cancel_action?
  8043.   #--------------------------------------------------------------------------
  8044.   def allow_cancel_action?
  8045.     return false if @selected_battler.auto_battle
  8046.     return true unless atb?
  8047.     return false if @selected_battler == @active_battler
  8048.     return false if @selected_battler.atb_speed > $game_troop.atb_threshold
  8049.     return true
  8050.   end
  8051.  
  8052.   #--------------------------------------------------------------------------
  8053.   # new method: confirm_action
  8054.   #--------------------------------------------------------------------------
  8055.   def confirm_action
  8056.     @status_window.draw_item(@selected_battler.index)
  8057.     @selected_battler.action.atb_queue_down
  8058.     make_action_orders unless ctb?
  8059.     if instant_action?
  8060.       if ctb?
  8061.         wait(20, true) if @help_viewport.oy != 0
  8062.         close_input_windows
  8063.       end
  8064.       perform_instant_action
  8065.     else
  8066.       if atb? and @actor_index == $game_party.members.size - 1 and
  8067.       $game_switches[YEM::BATTLE_ENGINE::OPTIONS[:next_actor_sw]]
  8068.         @actor_index = -1
  8069.       end
  8070.       if ctb?
  8071.         if @selected_battler.ctb_active?
  8072.           $game_troop.ctb_ready.shift
  8073.           $game_troop.clear_ctb_cache
  8074.           make_action_orders
  8075.           update_ctb_clockticks
  8076.           return
  8077.         end
  8078.         make_action_orders
  8079.         if $game_switches[YEM::BATTLE_ENGINE::OPTIONS[:next_actor_sw]]
  8080.           @actor_index = -1 if @actor_index == $game_party.members.size - 1
  8081.         end
  8082.       end
  8083.       next_actor if $game_switches[YEM::BATTLE_ENGINE::OPTIONS[:next_actor_sw]]
  8084.     end
  8085.   end
  8086.  
  8087.   #--------------------------------------------------------------------------
  8088.   # new method: instant_action?
  8089.   #--------------------------------------------------------------------------
  8090.   def instant_action?
  8091.     return true if dtb_instant?
  8092.     return true if ptb?
  8093.     return true if ctb_instant?
  8094.     return false
  8095.   end
  8096.  
  8097.   #--------------------------------------------------------------------------
  8098.   # new method: dtb_instant?
  8099.   #--------------------------------------------------------------------------
  8100.   def dtb_instant?
  8101.     return false unless dtb?
  8102.     case @selected_battler.action.kind
  8103.     when 0; return false
  8104.     when 1; return @selected_battler.action.skill.instant
  8105.     when 2; return @selected_battler.action.item.instant
  8106.     end
  8107.     return false
  8108.   end
  8109.  
  8110.   #--------------------------------------------------------------------------
  8111.   # new method: ctb_instant?
  8112.   #--------------------------------------------------------------------------
  8113.   def ctb_instant?
  8114.     return false unless ctb?
  8115.     $game_troop.clear_ctb_cache
  8116.     return false unless @selected_battler.ctb_active?
  8117.     return true if @selected_battler.action.kind == 0
  8118.     return false if @selected_battler.ctb_total_speed < $game_troop.ctb_max
  8119.     return true
  8120.   end
  8121.  
  8122.   #--------------------------------------------------------------------------
  8123.   # new method: perform_instant_action
  8124.   #--------------------------------------------------------------------------
  8125.   def perform_instant_action
  8126.     @message_window.clear
  8127.     @message_window.visible = true
  8128.     @actor_command_window.active = false
  8129.     @active_battler = @selected_battler if @selected_battler != nil
  8130.     @instant_cast = true
  8131.     #---
  8132.     case @selected_battler.action.kind
  8133.     when 1; instant_property = @selected_battler.action.skill.instant
  8134.     when 2; instant_property = @selected_battler.action.item.instant
  8135.     else; instant_property = false
  8136.     end
  8137.     #---
  8138.     process_action
  8139.     @instant_cast = false
  8140.     @active_battler = nil
  8141.     if @selected_battler != nil
  8142.       @selected_battler.action.clear
  8143.       @status_window.draw_item(@selected_battler.index)
  8144.     end
  8145.     @message_window.clear
  8146.     @message_window.visible = false
  8147.     if ptb? and @selected_battler != nil
  8148.       ptb_party_berserk(true)
  8149.       #---
  8150.       berserk_members = 0
  8151.       for member in $game_party.existing_members
  8152.         next unless member.berserker? or member.confusion?
  8153.         berserk_members += 1
  8154.       end
  8155.       if $game_party.existing_members.size <= berserk_members
  8156.         enemy_turn_start
  8157.         return
  8158.       end
  8159.       #---
  8160.       if @selected_battler.action.friends_unit.ptb_total_turns <= 0
  8161.         enemy_turn_start
  8162.         return
  8163.       end
  8164.       @actor_index = -1 if @actor_index == $game_party.members.size-1
  8165.       if !$game_switches[YEM::BATTLE_ENGINE::OPTIONS[:next_actor_sw]] or
  8166.       instant_property
  8167.         @actor_index = @selected_battler.index - 1
  8168.         next_actor
  8169.         return
  8170.       end
  8171.     end
  8172.     @actor_index = @selected_battler.index - 1 if dtb?
  8173.     return if ctb?
  8174.     next_actor if $game_switches[YEM::BATTLE_ENGINE::OPTIONS[:next_actor_sw]]
  8175.   end
  8176.  
  8177.   #--------------------------------------------------------------------------
  8178.   # new method: start_confirm_command_selection
  8179.   #--------------------------------------------------------------------------
  8180.   def start_confirm_command_selection
  8181.     @selected_battler = nil
  8182.     @status_window.index = @actor_index = -1
  8183.     @actor_command_window.openness = 0
  8184.     @actor_command_window.active = false
  8185.     @party_command_window.active = false
  8186.     if !$game_switches[YEM::BATTLE_ENGINE::OPTIONS[:autocursor_sw]]
  8187.       @confirm_command_window.index = 0
  8188.     end
  8189.     @confirm_command_window.openness = 255
  8190.     @confirm_command_window.active = true
  8191.     pause_atb(true)
  8192.     make_action_orders
  8193.   end
  8194.  
  8195.   #--------------------------------------------------------------------------
  8196.   # new method: start_confirm_command_selection
  8197.   #--------------------------------------------------------------------------
  8198.   def update_confirm_command_selection
  8199.     if Input.trigger?(Input::B) or Input.repeat?(Input::LEFT)
  8200.       Sound.play_cancel if Input.trigger?(Input::B)
  8201.       Sound.play_cursor if Input.repeat?(Input::LEFT)
  8202.       @actor_index = $game_party.members.size
  8203.       @actor_command_window.openness = 255
  8204.       @actor_command_window.active = true
  8205.       @confirm_command_window.openness = 0
  8206.       @confirm_command_window.active = false
  8207.       prior_actor
  8208.     elsif Input.trigger?(Input::C)
  8209.       confirm_command_case
  8210.     elsif Input.trigger?(Input::L)
  8211.       Sound.play_cursor
  8212.       start_party_command_selection
  8213.     elsif Input.trigger?(Input::R)
  8214.       Sound.play_cursor
  8215.       @actor_index = @status_shortcut_index + 1
  8216.       prior_actor
  8217.     #--- Debug Shortcuts ---
  8218.     elsif ($TEST or $BTEST) and Input.trigger?(Input::F5)
  8219.       Sound.play_recovery
  8220.       for member in $game_party.members
  8221.         member.recover_all
  8222.         member.gain_rage(member.max_rage)
  8223.       end
  8224.     elsif ($TEST or $BTEST) and Input.trigger?(Input::F6)
  8225.       Sound.play_use_item
  8226.       for member in $game_party.members
  8227.         member.hp += member.maxhp
  8228.       end
  8229.     elsif ($TEST or $BTEST) and Input.trigger?(Input::F7)
  8230.       Sound.play_use_skill
  8231.       for member in $game_party.members
  8232.         member.mp += member.maxmp
  8233.         member.gain_rage(member.max_rage)
  8234.       end
  8235.     elsif ($TEST or $BTEST) and Input.trigger?(Input::F8)
  8236.       Sound.play_actor_damage
  8237.       if Input.press?(Input::SHIFT)
  8238.         for member in $game_party.members
  8239.           member.hp -= member.maxhp/4 + 4
  8240.           member.mp -= member.maxmp/4 + 4
  8241.           member.perform_collapse
  8242.         end
  8243.       else
  8244.         for member in $game_party.members
  8245.           member.hp = 1
  8246.           member.mp = 0
  8247.         end
  8248.       end
  8249.     elsif ($TEST or $BTEST) and Input.press?(Input::CTRL) and
  8250.     Input.press?(Input::SHIFT)
  8251.       for enemy in $game_troop.existing_members
  8252.         enemy.hp = 0
  8253.         enemy.perform_collapse
  8254.       end
  8255.     end
  8256.   end
  8257.  
  8258.   #--------------------------------------------------------------------------
  8259.   # new method: confirm_command_case
  8260.   #--------------------------------------------------------------------------
  8261.   def confirm_command_case
  8262.     case @confirm_command_window.item
  8263.     when :confirm
  8264.       Sound.play_decision
  8265.       start_main
  8266.     when :status
  8267.       Sound.play_decision
  8268.       start_actor_status
  8269.     when :option
  8270.       Sound.play_decision
  8271.       start_options(@confirm_command_window)
  8272.     when :escape
  8273.       if !$game_troop.can_escape
  8274.         Sound.play_buzzer
  8275.         return
  8276.       end
  8277.       Sound.play_decision
  8278.       process_escape
  8279.     #---
  8280.     when :turnskip
  8281.       Sound.play_decision
  8282.       enemy_turn_start
  8283.     #---
  8284.     when :atb_type
  8285.       Sound.play_decision
  8286.       variable = YEM::BATTLE_ENGINE::OPTIONS[:atb_avariable]
  8287.       $game_variables[variable] += 1
  8288.       $game_variables[variable] = 0 if $game_variables[variable] > 3
  8289.       @party_command_window.refresh
  8290.       @confirm_command_window.refresh
  8291.     when :atb_speed
  8292.       Sound.play_decision
  8293.       variable = YEM::BATTLE_ENGINE::OPTIONS[:atb_svariable]
  8294.       $game_variables[variable] += 1
  8295.       $game_variables[variable] = 1 if $game_variables[variable] > 10
  8296.       @party_command_window.refresh
  8297.       @confirm_command_window.refresh
  8298.     end
  8299.   end
  8300.  
  8301.   #--------------------------------------------------------------------------
  8302.   # new method: start_actor_status
  8303.   #--------------------------------------------------------------------------
  8304.   def start_actor_status
  8305.     @actor_status_window = Window_BattleActor.new
  8306.     @actor_states_window = Window_BattleActorStates.new
  8307.     @actor_status_window.viewport = @spriteset.viewportC
  8308.     @actor_states_window.viewport = @spriteset.viewportC
  8309.     @confirm_command_window.active = false
  8310.     @status_window.active = true
  8311.     @status_window.index = 0
  8312.   end
  8313.  
  8314.   #--------------------------------------------------------------------------
  8315.   # new method: update_actor_status
  8316.   #--------------------------------------------------------------------------
  8317.   def update_actor_status
  8318.     @actor_states_window.update
  8319.     if @last_query_index != @status_window.index
  8320.       @last_query_index = @status_window.index
  8321.       @actor_status_window.refresh(@last_query_index)
  8322.       @actor_states_window.refresh(@status_window.actor)
  8323.     end
  8324.     if Input.trigger?(Input::B)
  8325.       Sound.play_cancel
  8326.       @status_window.active = false
  8327.       @last_query_index = nil
  8328.       @actor_status_window.dispose
  8329.       @actor_status_window = nil
  8330.       @actor_states_window.dispose
  8331.       @actor_states_window = nil
  8332.       start_confirm_command_selection
  8333.     end
  8334.   end
  8335.  
  8336.   #--------------------------------------------------------------------------
  8337.   # new method: start_options
  8338.   #--------------------------------------------------------------------------
  8339.   def start_options(host_window)
  8340.     host_window.active = false
  8341.     @options_host_window = host_window
  8342.     @help_window = Window_Help.new
  8343.     @options_window = Window_BattleOptions.new(0, @help_window.height)
  8344.     @options_window.help_window = @help_window
  8345.     @options_window.viewport = @spriteset.viewportC
  8346.     @help_window.viewport = @spriteset.viewportC
  8347.   end
  8348.  
  8349.   #--------------------------------------------------------------------------
  8350.   # new method: end_options
  8351.   #--------------------------------------------------------------------------
  8352.   def end_options
  8353.     @options_window.dispose
  8354.     @options_window = nil
  8355.     @help_window.dispose
  8356.     @help_window = nil
  8357.     @options_host_window.active = true
  8358.   end
  8359.  
  8360.   #--------------------------------------------------------------------------
  8361.   # new method: update_options
  8362.   #--------------------------------------------------------------------------
  8363.   def update_options
  8364.     @options_window.update
  8365.     if Input.trigger?(Input::B)
  8366.       Sound.play_cancel
  8367.       end_options
  8368.     end
  8369.   end
  8370.  
  8371.   #--------------------------------------------------------------------------
  8372.   # new method: create_highlighted_targets
  8373.   #--------------------------------------------------------------------------
  8374.   def create_highlighted_targets(group = nil)
  8375.     return if group == nil
  8376.     @highlighted_targets = []
  8377.     return if @selected_battler.action.attack? and !atb?
  8378.     obj = @selected_battler.action.skill if @selected_battler.action.skill?
  8379.     obj = @selected_battler.action.item if @selected_battler.action.item?
  8380.     if atb?
  8381.       case @selected_battler.action.atb_queue_kind
  8382.       when 0; return
  8383.       when 1; obj = $data_skills[@selected_battler.action.atb_queue_basic]
  8384.       when 2; obj = $data_items[@selected_battler.action.atb_queue_basic]
  8385.       else;   return
  8386.       end
  8387.     end
  8388.     if obj.for_user?
  8389.       @highlighted_targets |= [@selected_battler]
  8390.     elsif obj.for_random? or obj.for_all?
  8391.       @highlighted_targets |= group.existing_members
  8392.     end
  8393.     #---
  8394.     main_target = @target_enemy_window.enemy if @target_enemy_window != nil
  8395.     main_target = @target_actor_window.actor if @target_actor_window != nil
  8396.     return if main_target == nil
  8397.     @highlighted_targets |= group.area_targets(main_target, obj)
  8398.   end
  8399.  
  8400.   #--------------------------------------------------------------------------
  8401.   # overwrite method: start_target_enemy_selection
  8402.   #--------------------------------------------------------------------------
  8403.   def start_target_enemy_selection
  8404.     pause_atb(true) if semi_active_atb? or wait_atb?
  8405.     create_highlighted_targets($game_troop)
  8406.     @target_help_window.active = true
  8407.     @status_window.draw_item(@selected_battler.index)
  8408.     @target_enemy_window = Window_TargetEnemy.new
  8409.     @target_enemy_window.y = Graphics.height * 8
  8410.     if !left_to_right
  8411.       @target_enemy_window.index = @target_enemy_window.item_max-1
  8412.     end
  8413.     @actor_command_window.active = false
  8414.     create_aoe_indicator(@target_enemy_window)
  8415.     @enemy_gauge_window = Window_EnemyGauge.new
  8416.     @enemy_gauge_window.viewport = @spriteset.viewportB
  8417.   end
  8418.  
  8419.   #--------------------------------------------------------------------------
  8420.   # overwrite method: end_target_enemy_selection
  8421.   #--------------------------------------------------------------------------
  8422.   def end_target_enemy_selection
  8423.     @target_help_window.active = false
  8424.     @last_target_enemy = nil
  8425.     @status_window.draw_item(@selected_battler.index)
  8426.     @target_enemy_window.dispose
  8427.     @target_enemy_window = nil
  8428.     if @actor_command_window.item == :attack or @command_action
  8429.       @actor_command_window.active = true
  8430.       @command_action = false
  8431.     end
  8432.     pause_atb(false) if semi_active_atb?
  8433.     dispose_aoe_indicator
  8434.     @enemy_gauge_window.dispose if @enemy_gauge_window != nil
  8435.     @enemy_gauge_window = nil
  8436.   end
  8437.  
  8438.   #--------------------------------------------------------------------------
  8439.   # overwrite method: update_target_enemy_selection
  8440.   #--------------------------------------------------------------------------
  8441.   def update_target_enemy_selection
  8442.     @target_enemy_window.update
  8443.     if @target_enemy_window.enemy != nil
  8444.       @target_enemy_window.enemy.white_flash = true
  8445.     end
  8446.     for target in @highlighted_targets; target.white_flash = true; end
  8447.     if @last_target_enemy != @target_enemy_window.index
  8448.       @last_target_enemy = @target_enemy_window.index
  8449.       @target_help_window.refresh(@target_enemy_window.enemy, @selected_battler)
  8450.       update_battle_cursor
  8451.       @enemy_gauge_window.battler = @target_enemy_window.enemy
  8452.     end
  8453.     @enemy_gauge_window.update
  8454.     if Input.trigger?(Input::B)
  8455.       @selected_battler.action.clear
  8456.       @mini_window.refresh if @mini_window != nil
  8457.       Sound.play_cancel
  8458.       end_target_enemy_selection
  8459.       update_battle_cursor
  8460.     elsif Input.trigger?(Input::C)
  8461.       return if @target_enemy_window.enemy == nil
  8462.       Sound.play_decision
  8463.       @selected_battler.action.target_index = @target_enemy_window.enemy.index
  8464.       end_target_enemy_selection
  8465.       end_skill_selection
  8466.       end_item_selection
  8467.       confirm_action
  8468.     end
  8469.   end
  8470.  
  8471.   #--------------------------------------------------------------------------
  8472.   # overwrite method: start_target_actor_selection
  8473.   #--------------------------------------------------------------------------
  8474.   def start_target_actor_selection
  8475.     pause_atb(true) if semi_active_atb? or wait_atb?
  8476.     if @command_action
  8477.       @info_viewport.ox += @status_window.width
  8478.       @info_viewport.rect.x += @status_window.width
  8479.     end
  8480.     create_highlighted_targets($game_party)
  8481.     @target_help_window.active = true
  8482.     @target_actor_window = Window_BattleStatus.new(true)
  8483.     @target_actor_window.index = 0
  8484.     @target_actor_window.active = true
  8485.     @target_actor_window.y = @info_viewport.rect.y
  8486.     @actor_command_window.active = false
  8487.     #---
  8488.     @target_actor_hp = Window_BattleStatusHP.new
  8489.     @target_actor_mp = Window_BattleStatusMP.new
  8490.     @target_actor_states = Window_BattleStatusStates.new
  8491.     @target_actor_rage = Window_BattleStatusRage.new
  8492.     @target_actor_hp.y = @target_actor_window.y
  8493.     @target_actor_mp.y = @target_actor_window.y
  8494.     @target_actor_states.y = @target_actor_window.y
  8495.     @target_actor_rage.y = @target_actor_window.y
  8496.     #---
  8497.     if atb_target_actor_case
  8498.       obj = @selected_battler.action.skill if @selected_battler.action.skill?
  8499.       obj = @selected_battler.action.item if @selected_battler.action.item?
  8500.       if atb?
  8501.         case @selected_battler.action.atb_queue_kind
  8502.         when 1
  8503.           obj = $data_skills[@selected_battler.action.atb_queue_basic]
  8504.         when 2
  8505.           obj = $data_items[@selected_battler.action.atb_queue_basic]
  8506.         end
  8507.       end
  8508.       @target_actor_window.target_highlight = true
  8509.       @target_actor_window.highlight_all = true if obj.for_all?
  8510.       @target_actor_window.highlight_all = true if obj.for_random?
  8511.       @target_actor_window.highlight_user = true if obj.for_user?
  8512.       @target_actor_window.frozen_cursor = true if obj.for_user?
  8513.       @target_actor_window.index = @selected_battler.index if obj.for_user?
  8514.       @target_actor_window.highlight_none = true if obj.for_none?
  8515.       @target_actor_window.highlight_dead = true if obj.for_dead_friend?
  8516.       @target_actor_window.refresh
  8517.     end
  8518.     #---
  8519.     @target_help_window.refresh(@target_actor_window.actor, @selected_battler)
  8520.     hide_object_windows
  8521.     update_battle_cursor
  8522.     create_aoe_indicator(@target_actor_window)
  8523.   end
  8524.  
  8525.   #--------------------------------------------------------------------------
  8526.   # new method: atb_target_actor_case
  8527.   #--------------------------------------------------------------------------
  8528.   def atb_target_actor_case
  8529.     if atb?
  8530.       return true if [1, 2].include?(@selected_battler.action.atb_queue_kind)
  8531.       return false
  8532.     end
  8533.     return true if @selected_battler.action.skill?
  8534.     return true if @selected_battler.action.item?
  8535.     return false
  8536.   end
  8537.  
  8538.   #--------------------------------------------------------------------------
  8539.   # overwrite method: end_target_actor_selection
  8540.   #--------------------------------------------------------------------------
  8541.   def end_target_actor_selection
  8542.     @target_help_window.active = false
  8543.     @last_target_enemy = nil
  8544.     @status_window.draw_item(@selected_battler.index)
  8545.     @target_actor_window.dispose
  8546.     @target_actor_window = nil
  8547.     #---
  8548.     @target_actor_hp.dispose
  8549.     @target_actor_mp.dispose
  8550.     @target_actor_states.dispose
  8551.     @target_actor_rage.dispose
  8552.     @target_actor_hp = nil
  8553.     @target_actor_mp = nil
  8554.     @target_actor_states = nil
  8555.     @target_actor_rage = nil
  8556.     #---
  8557.     show_object_windows
  8558.     if @actor_command_window.item == :attack or @command_action
  8559.       @info_viewport.ox -= @status_window.width
  8560.       @info_viewport.rect.x -= @status_window.width
  8561.       @actor_command_window.active = true
  8562.       @command_action = false
  8563.     end
  8564.     pause_atb(false) if semi_active_atb?
  8565.     dispose_aoe_indicator
  8566.   end
  8567.  
  8568.   #--------------------------------------------------------------------------
  8569.   # overwrite method: update_target_actor_selection
  8570.   #--------------------------------------------------------------------------
  8571.   def update_target_actor_selection
  8572.     @target_actor_window.update
  8573.     if @target_actor_window.actor != nil
  8574.       @target_actor_window.actor.white_flash = true
  8575.     end
  8576.     for target in @highlighted_targets; target.white_flash = true; end
  8577.     if @last_target_actor != @target_actor_window.index
  8578.       @last_target_actor = @target_actor_window.index
  8579.       @target_help_window.refresh(@target_actor_window.actor, @selected_battler)
  8580.       update_battle_cursor
  8581.     end
  8582.     if Input.trigger?(Input::B)
  8583.       @selected_battler.action.clear
  8584.       @mini_window.refresh if @mini_window != nil
  8585.       Sound.play_cancel
  8586.       end_target_actor_selection
  8587.       update_battle_cursor
  8588.     elsif Input.trigger?(Input::C)
  8589.       if !@target_actor_window.opacity?(@target_actor_window.actor)
  8590.         Sound.play_buzzer
  8591.         return
  8592.       end
  8593.       Sound.play_decision
  8594.       @selected_battler.action.target_index = @target_actor_window.index
  8595.       end_target_actor_selection
  8596.       end_skill_selection
  8597.       end_item_selection
  8598.       confirm_action
  8599.     end
  8600.   end
  8601.  
  8602.   #--------------------------------------------------------------------------
  8603.   # new method: create_mini_window
  8604.   #--------------------------------------------------------------------------
  8605.   def create_mini_window
  8606.     $game_temp.less_spacing = nil
  8607.     @info_viewport.oy = Graphics.height * 8
  8608.     @mini_window = Window_BattleStatus_Mini.new if @mini_window == nil
  8609.   end
  8610.  
  8611.   #--------------------------------------------------------------------------
  8612.   # new method: dispose_mini_window
  8613.   #--------------------------------------------------------------------------
  8614.   def dispose_mini_window
  8615.     @info_viewport.oy = 0
  8616.     return if @mini_window == nil
  8617.     @mini_window.dispose
  8618.     @mini_window = nil
  8619.   end
  8620.  
  8621.   #--------------------------------------------------------------------------
  8622.   # new method: hide_object_windows
  8623.   #--------------------------------------------------------------------------
  8624.   def hide_object_windows
  8625.     @skill_window.y = Graphics.height * 8 if @skill_window != nil
  8626.     @item_window.y = Graphics.height * 8 if @item_window != nil
  8627.   end
  8628.  
  8629.   #--------------------------------------------------------------------------
  8630.   # new method: show_object_windows
  8631.   #--------------------------------------------------------------------------
  8632.   def show_object_windows
  8633.     @skill_window.y = @info_viewport.rect.y if @skill_window != nil
  8634.     @item_window.y = @info_viewport.rect.y if @item_window != nil
  8635.   end
  8636.  
  8637.   #--------------------------------------------------------------------------
  8638.   # overwrite method: start_skill_selection
  8639.   #--------------------------------------------------------------------------
  8640.   def start_skill_selection
  8641.     dx = 0; dy = Graphics.height-128; dw = Graphics.width - 128; dh = 128
  8642.     $game_temp.less_spacing = true
  8643.     @skill_window = Window_Skill.new(dx, dy, dw, dh, @selected_battler)
  8644.     @skill_window.help_window = @view_help_window
  8645.     @actor_command_window.active = false
  8646.     create_mini_window
  8647.     pause_atb(true) if semi_wait_atb? or wait_atb?
  8648.   end
  8649.  
  8650.   #--------------------------------------------------------------------------
  8651.   # overwrite method: end_skill_selection
  8652.   #--------------------------------------------------------------------------
  8653.   def end_skill_selection
  8654.     dispose_mini_window
  8655.     if @skill_window != nil
  8656.       @skill_window.dispose
  8657.       @skill_window = nil
  8658.     end
  8659.     @last_skill_index = nil
  8660.     $game_troop.clear_ctb_cache if ctb?
  8661.     make_action_orders
  8662.     @actor_command_window.active = true
  8663.     pause_atb(false)
  8664.   end
  8665.  
  8666.   #--------------------------------------------------------------------------
  8667.   # overwrite method: update_skill_selection
  8668.   #--------------------------------------------------------------------------
  8669.   def update_skill_selection
  8670.     @skill_window.active = true
  8671.     @skill_window.update
  8672.     #---
  8673.     if @last_skill_index != @skill_window.index
  8674.       @last_skill_index = @skill_window.index
  8675.       if dtb? or ctb?
  8676.         $game_troop.clear_ctb_cache
  8677.         skill = @skill_window.skill
  8678.         if skill != nil and @selected_battler.skill_can_use?(skill)
  8679.           last_action = @selected_battler.action.clone
  8680.           @selected_battler.action.set_skill(skill.id)
  8681.           make_action_orders
  8682.           @selected_battler.action = last_action
  8683.         end
  8684.       end
  8685.     end
  8686.     #---
  8687.     if Input.trigger?(Input::B)
  8688.       @selected_battler.action.clear
  8689.       @status_window.draw_item(@selected_battler.index)
  8690.       Sound.play_cancel
  8691.       end_skill_selection
  8692.       update_battle_cursor
  8693.     elsif Input.trigger?(Input::C)
  8694.       @skill = @skill_window.skill
  8695.       if @skill != nil
  8696.         @selected_battler.last_skill_id = @skill.id
  8697.       end
  8698.       if @selected_battler.skill_can_use?(@skill)
  8699.         Sound.play_decision
  8700.         determine_skill
  8701.       else
  8702.         Sound.play_buzzer
  8703.       end
  8704.     end
  8705.   end
  8706.  
  8707.   #--------------------------------------------------------------------------
  8708.   # overwrite method: determine_skill
  8709.   #--------------------------------------------------------------------------
  8710.   def determine_skill
  8711.     @selected_battler.action.set_skill(@skill.id)
  8712.     @mini_window.refresh if @mini_window != nil
  8713.     @skill_window.active = false if @skill_window != nil
  8714.     if @skill.for_opponent?
  8715.       start_target_enemy_selection
  8716.     else
  8717.       start_target_actor_selection
  8718.     end
  8719.   end
  8720.  
  8721.   #--------------------------------------------------------------------------
  8722.   # overwrite method: start_item_selection
  8723.   #--------------------------------------------------------------------------
  8724.   def start_item_selection
  8725.     dx = 0; dy = Graphics.height-128; dw = Graphics.width - 128; dh = 128
  8726.     $game_temp.less_spacing = true
  8727.     @item_window = Window_Item.new(dx, dy, dw, dh)
  8728.     @item_window.help_window = @view_help_window
  8729.     @actor_command_window.active = false
  8730.     create_mini_window
  8731.     pause_atb(true) if semi_wait_atb? or wait_atb?
  8732.   end
  8733.  
  8734.   #--------------------------------------------------------------------------
  8735.   # overwrite method: end_item_selection
  8736.   #--------------------------------------------------------------------------
  8737.   def end_item_selection
  8738.     dispose_mini_window
  8739.     if @item_window != nil
  8740.       @item_window.dispose
  8741.       @item_window = nil
  8742.     end
  8743.     @last_item_index = nil
  8744.     $game_troop.clear_ctb_cache if ctb?
  8745.     make_action_orders
  8746.     @actor_command_window.active = true
  8747.   end
  8748.  
  8749.   #--------------------------------------------------------------------------
  8750.   # overwrite method: update_item_selection
  8751.   #--------------------------------------------------------------------------
  8752.   def update_item_selection
  8753.     @item_window.active = true
  8754.     @item_window.update
  8755.     #---
  8756.     if @last_item_index != @item_window.index
  8757.       @last_item_index = @item_window.index
  8758.       if dtb? or ctb?
  8759.         $game_troop.clear_ctb_cache
  8760.         item = @item_window.item
  8761.         if item != nil and @selected_battler.item_can_use?(item)
  8762.           last_action = @selected_battler.action.clone
  8763.           @selected_battler.action.set_item(item.id)
  8764.           make_action_orders
  8765.           @selected_battler.action = last_action
  8766.         end
  8767.       end
  8768.     end
  8769.     #---
  8770.     if Input.trigger?(Input::B)
  8771.       @selected_battler.action.clear
  8772.       @status_window.draw_item(@selected_battler.index)
  8773.       Sound.play_cancel
  8774.       end_item_selection
  8775.       update_battle_cursor
  8776.     elsif Input.trigger?(Input::C)
  8777.       @item = @item_window.item
  8778.       if @item != nil
  8779.         $game_party.last_item_id = @item.id
  8780.       end
  8781.       if @selected_battler.item_can_use?(@item)
  8782.         Sound.play_decision
  8783.         determine_item
  8784.       else
  8785.         Sound.play_buzzer
  8786.       end
  8787.     end
  8788.   end
  8789.  
  8790.   #--------------------------------------------------------------------------
  8791.   # overwrite method: determine_item
  8792.   #--------------------------------------------------------------------------
  8793.   def determine_item
  8794.     @selected_battler.action.set_item(@item.id)
  8795.     @mini_window.refresh if @mini_window != nil
  8796.     @item_window.active = false
  8797.     if @item.for_opponent?
  8798.       start_target_enemy_selection
  8799.     else
  8800.       start_target_actor_selection
  8801.     end
  8802.   end
  8803.  
  8804.   #--------------------------------------------------------------------------
  8805.   # new method: pause_atb
  8806.   #--------------------------------------------------------------------------
  8807.   def pause_atb(value, locked = false)
  8808.     return unless atb?
  8809.     return if @locked
  8810.     @locked = locked
  8811.     if value == true
  8812.       @pause_atb = true
  8813.       return
  8814.     end
  8815.     return if @confirm_command_window.active
  8816.     return if @party_command_window.active
  8817.     return if @options_window != nil
  8818.     return if @actor_status_window != nil
  8819.     return if @active_battler != nil
  8820.     if semi_active_atb? or semi_wait_atb? or wait_atb?
  8821.       return if @target_enemy_window != nil
  8822.       return if @target_actor_window != nil
  8823.     end
  8824.     if semi_wait_atb? or wait_atb?
  8825.       return if @skill_window != nil
  8826.       return if @item_window != nil
  8827.     end
  8828.     if wait_atb?
  8829.       for member in $game_party.existing_members
  8830.         next if member.atb_speed < $game_troop.atb_threshold
  8831.         return if member.action.wait?
  8832.       end
  8833.     end
  8834.     @pause_atb = false
  8835.   end
  8836.  
  8837.   #--------------------------------------------------------------------------
  8838.   # overwrite method: start_main
  8839.   # Used as starting turns or processing actions.
  8840.   #--------------------------------------------------------------------------
  8841.   def start_main
  8842.     $game_troop.increase_turn
  8843.     #---
  8844.     start_main_dtb
  8845.     start_main_ptb
  8846.     #---
  8847.     @message_window.visible = true
  8848.     @message_window.clear
  8849.     close_input_windows unless atb?
  8850.     @selected_battler = nil
  8851.     @active_battler = nil
  8852.     @message_window.clear
  8853.     @performed_actors = []
  8854.     @party_input_flag = nil
  8855.     make_action_orders
  8856.   end
  8857.  
  8858.   #--------------------------------------------------------------------------
  8859.   # new method: close_input_windows
  8860.   #--------------------------------------------------------------------------
  8861.   def close_input_windows
  8862.     @party_command_window.active = false
  8863.     @actor_command_window.active = false
  8864.     @confirm_command_window.active = false
  8865.     @party_command_window.openness = 0
  8866.     @actor_command_window.openness = 0
  8867.     @confirm_command_window.openness = 0
  8868.     loop do
  8869.       update_basic
  8870.       break if @info_viewport.ox == 64
  8871.       if @info_viewport.ox >= 64
  8872.         @info_viewport.ox -= [16, (64 - @info_viewport.ox).abs].min
  8873.       else
  8874.         @info_viewport.ox += [16, (64 - @info_viewport.ox).abs].min
  8875.       end
  8876.     end
  8877.     @status_window.index = @actor_index = -1
  8878.   end
  8879.  
  8880.   #--------------------------------------------------------------------------
  8881.   # new method: start_main_dtb
  8882.   #--------------------------------------------------------------------------
  8883.   def start_main_dtb
  8884.     $game_party.update_turn_start
  8885.     $game_party.update_group_cooldowns
  8886.     $game_troop.update_turn_start
  8887.     $game_troop.update_group_cooldowns
  8888.     @spriteset.mark_first_time_order
  8889.     close_input_windows
  8890.     if YEM::BATTLE_ENGINE::DTB_COMMON_EVENTS[:turn_start] != nil
  8891.       event_id = YEM::BATTLE_ENGINE::DTB_COMMON_EVENTS[:turn_start]
  8892.       $game_temp.common_event_id = event_id
  8893.       process_battle_event
  8894.     end
  8895.   end
  8896.  
  8897.   #--------------------------------------------------------------------------
  8898.   # new method: start_main_ptb
  8899.   #--------------------------------------------------------------------------
  8900.   def start_main_ptb
  8901.     return unless ptb?
  8902.     $game_troop.reset_ptb_turns
  8903.     $game_troop.update_group_cooldowns
  8904.     @ptb_troop_window.appear
  8905.     @ptb_party_window.disappear
  8906.     $game_troop.update_turn_start
  8907.   end
  8908.  
  8909.   #--------------------------------------------------------------------------
  8910.   # overwrite method: make_action_orders
  8911.   #--------------------------------------------------------------------------
  8912.   def make_action_orders
  8913.     make_action_orders_dtb
  8914.     make_action_orders_ptb
  8915.     make_action_orders_ctb
  8916.   end
  8917.  
  8918.   #--------------------------------------------------------------------------
  8919.   # new method: make_action_orders_ctb
  8920.   #--------------------------------------------------------------------------
  8921.   def make_action_orders_ctb
  8922.     return unless ctb?
  8923.     @action_battlers = @all_members.clone
  8924.     @action_battlers.sort! { |a,b|
  8925.       if a.ctb_ctr != b.ctb_ctr
  8926.         a.ctb_ctr <=> b.ctb_ctr
  8927.       elsif a.ctb_prediction != b.ctb_prediction
  8928.         b.ctb_prediction <=> a.ctb_prediction
  8929.       elsif a.agi != b.agi
  8930.         b.agi <=> a.agi
  8931.       else
  8932.         b.screen_x <=> a.screen_x
  8933.       end
  8934.     }
  8935.     @spriteset.update_ctb_order if @first_ctb_update
  8936.   end
  8937.  
  8938.   #--------------------------------------------------------------------------
  8939.   # overwrite method: turn_end
  8940.   #--------------------------------------------------------------------------
  8941.   def turn_end
  8942.     remove_states_auto
  8943.     $game_troop.turn_ending = true
  8944.     $game_troop.update_turn_end
  8945.     $game_party.update_turn_end
  8946.     $game_troop.preemptive = false
  8947.     $game_troop.surprise = false
  8948.     @message_window.visible = false
  8949.     if dtb? and YEM::BATTLE_ENGINE::DTB_COMMON_EVENTS[:turn_finish] != nil
  8950.       event_id = YEM::BATTLE_ENGINE::DTB_COMMON_EVENTS[:turn_finish]
  8951.       $game_temp.common_event_id = event_id
  8952.       process_battle_event
  8953.     end
  8954.     process_battle_event
  8955.     $game_troop.turn_ending = false
  8956.     $game_troop.make_actions
  8957.     @performed_actors = []
  8958.     party_turn_start
  8959.   end
  8960.  
  8961.   #--------------------------------------------------------------------------
  8962.   # overwrite method: ptb_turn_end
  8963.   #--------------------------------------------------------------------------
  8964.   def ptb_turn_end(group)
  8965.     return unless ptb?
  8966.     $game_troop.turn_ending = true
  8967.     group.update_turn_end
  8968.     $game_troop.preemptive = false
  8969.     $game_troop.surprise = false
  8970.     process_battle_event
  8971.     $game_troop.turn_ending = false
  8972.   end
  8973.  
  8974.   #--------------------------------------------------------------------------
  8975.   # overwrite method: set_next_active_battler
  8976.   #--------------------------------------------------------------------------
  8977.   def set_next_active_battler
  8978.     @performed_actors = [] if @performed_actors == nil
  8979.     loop do
  8980.       if $game_troop.forcing_battler != nil
  8981.         @active_battler = $game_troop.forcing_battler
  8982.         @action_battlers.delete(@active_battler)
  8983.         $game_troop.forcing_battler = nil
  8984.       else
  8985.         make_action_orders
  8986.         @action_battlers -= @performed_actors
  8987.         @active_battler = @action_battlers.shift
  8988.       end
  8989.       @performed_actors.push(@active_battler) unless @active_battler == nil
  8990.       return if @active_battler == nil
  8991.       return if @active_battler.index != nil
  8992.     end
  8993.   end
  8994.  
  8995.   #--------------------------------------------------------------------------
  8996.   # new method: sort_targets
  8997.   #--------------------------------------------------------------------------
  8998.   def sort_targets(targets, obj = nil)
  8999.     if obj != nil
  9000.       return targets.compact if obj.for_random?
  9001.     end
  9002.     if left_to_right
  9003.       targets.sort! { |a,b| a.screen_x <=> b.screen_x }
  9004.     else
  9005.       targets.sort! { |a,b| b.screen_x <=> a.screen_x }
  9006.     end
  9007.     return targets.compact
  9008.   end
  9009.  
  9010.   #--------------------------------------------------------------------------
  9011.   # new method: left_to_right
  9012.   #--------------------------------------------------------------------------
  9013.   def left_to_right
  9014.     case @view_type
  9015.     when 0; type = :empty
  9016.     when 1; type = :front
  9017.     when 2; type = :side
  9018.     when 3; type = :angle
  9019.     else;   return true
  9020.     end
  9021.     return YEM::BATTLE_ENGINE::MISC_VIEW_ADJUSTMENTS[type][2]
  9022.   end
  9023.  
  9024.   #--------------------------------------------------------------------------
  9025.   # new method: status_window_refresh
  9026.   #--------------------------------------------------------------------------
  9027.   def status_window_refresh
  9028.     return unless @active_battler.actor?
  9029.     @status_window.draw_item(@active_battler.index)
  9030.   end
  9031.  
  9032.   #--------------------------------------------------------------------------
  9033.   # overwrite method: process_action
  9034.   #--------------------------------------------------------------------------
  9035.   def process_action
  9036.     return if judge_win_loss
  9037.     return if $game_temp.next_scene != nil
  9038.     @combo_damage = 0; @combo_heal = 0
  9039.     @action_occuring = true
  9040.     process_dtb_action if dtb?
  9041.     process_ptb_action if ptb?
  9042.     process_atb_action if atb?
  9043.     process_ctb_action if ctb?
  9044.     @message_window.clear
  9045.     @action_occuring = false
  9046.     update_battler_poses
  9047.     update_ctb_clockticks
  9048.   end
  9049.  
  9050.   #--------------------------------------------------------------------------
  9051.   # new method: process_dtb_action
  9052.   #--------------------------------------------------------------------------
  9053.   def process_dtb_action
  9054.     loop do
  9055.       set_next_active_battler unless @instant_cast
  9056.       if @active_battler == nil
  9057.         turn_end unless @instant_cast
  9058.         return
  9059.       end
  9060.       @status_window.refresh
  9061.       @message_window.clear
  9062.       @active_battler.action.prepare unless @active_battler.action.forcing
  9063.       if @active_battler.action.valid?
  9064.         break
  9065.       else
  9066.         @message_window.clear
  9067.         display_current_state
  9068.       end
  9069.     end
  9070.     execute_action
  9071.     update_battler_poses
  9072.     unless @active_battler.action.forcing
  9073.       @message_window.clear
  9074.       display_current_state
  9075.     end
  9076.     @active_battler = nil
  9077.   end
  9078.  
  9079.   #--------------------------------------------------------------------------
  9080.   # new method: process_ptb_action
  9081.   #--------------------------------------------------------------------------
  9082.   def process_ptb_action
  9083.     if $game_troop.forcing_battler != nil
  9084.       @active_battler = $game_troop.forcing_battler
  9085.       $game_troop.forcing_battler = nil
  9086.       process_ptb_action
  9087.       return
  9088.     elsif @active_battler == nil
  9089.       make_action_orders
  9090.       @active_battler = @action_battlers[0]
  9091.       if @active_battler != nil and @active_battler.enemy?
  9092.         @active_battler.make_action
  9093.       end
  9094.       party_turn_start if $game_troop.ptb_total_turns <= 0
  9095.       return
  9096.     end
  9097.     @status_window.refresh
  9098.     @message_window.clear
  9099.     @active_battler.action.prepare unless @active_battler.action.forcing
  9100.     return if !@active_battler.action.valid?
  9101.     execute_action
  9102.     return if @active_battler == nil
  9103.     if @active_battler.action == nil
  9104.       @active_battler = nil
  9105.       return
  9106.     end
  9107.     unless @active_battler.action.forcing
  9108.       @message_window.clear
  9109.       display_current_state
  9110.     end
  9111.     @active_battler.action.forcing = false
  9112.     @active_battler = nil
  9113.   end
  9114.  
  9115.   #--------------------------------------------------------------------------
  9116.   # new method: ptb_party_berserk
  9117.   #--------------------------------------------------------------------------
  9118.   def ptb_party_berserk(set_return = false)
  9119.     return unless ptb?
  9120.     previous_selected_battler = @selected_battler
  9121.     berserk_members = 0
  9122.     performed_action = false
  9123.     for member in $game_party.existing_members
  9124.       next unless member.berserker? or member.confusion? or member.auto_battle
  9125.       berserk_members += 1
  9126.       next if $game_party.ptb_total_turns <= 0
  9127.       next if member.ptb_performed
  9128.       member.ptb_performed = true
  9129.       member.action.set_attack
  9130.       if member.auto_battle and !member.berserker? and !member.confusion?
  9131.         member.make_action
  9132.       end
  9133.       @selected_battler = member
  9134.       @actor_command_window.setup(@selected_battler)
  9135.       @status_window.index = @selected_battler.index
  9136.       perform_instant_action
  9137.       performed_action = true
  9138.     end
  9139.     @selected_battler = previous_selected_battler
  9140.     if performed_action and !set_return and @selected_battler != nil
  9141.       @actor_command_window.setup(@selected_battler)
  9142.       @status_window.index = @selected_battler.index
  9143.     end
  9144.     return if set_return
  9145.     return if $game_party.existing_members.size > berserk_members
  9146.     enemy_turn_start
  9147.   end
  9148.  
  9149.   #--------------------------------------------------------------------------
  9150.   # new method: ptb_remove_states_auto
  9151.   #--------------------------------------------------------------------------
  9152.   def ptb_remove_states_auto(group)
  9153.     return unless ptb?
  9154.     return if $game_troop.surprise
  9155.     for member in group.members
  9156.       last_st = member.states
  9157.       member.remove_states_auto
  9158.       if member.states != last_st
  9159.         display_state_changes(member)
  9160.         @message_window.clear
  9161.       end
  9162.     end
  9163.   end
  9164.  
  9165.   #--------------------------------------------------------------------------
  9166.   # new method: process_atb_action
  9167.   #--------------------------------------------------------------------------
  9168.   def process_atb_action
  9169.     if $game_troop.forcing_battler != nil
  9170.       @active_battler = $game_troop.forcing_battler
  9171.     else
  9172.       @active_battler = $game_troop.atb_ready[0]
  9173.       $game_troop.atb_ready.delete(@active_battler)
  9174.     end
  9175.     return if @active_battler == nil
  9176.     return if !@active_battler.action.valid?
  9177.     pause_atb(true)
  9178.     @message_window.visible = true
  9179.     execute_action unless @active_battler.action.wait?
  9180.     @message_window.clear
  9181.     @message_window.visible = false
  9182.     unless $game_troop.forcing_battler
  9183.       $game_troop.atb_ready.delete(@active_battler)
  9184.       @active_battler.reset_atb_speed
  9185.       @active_battler.process_atb_reset
  9186.     end
  9187.     $game_troop.forcing_battler = nil
  9188.     @active_battler = nil
  9189.     if YEM::BATTLE_ENGINE::ATB_COMMON_EVENTS[:end_action] != nil
  9190.       event_id = YEM::BATTLE_ENGINE::ATB_COMMON_EVENTS[:end_action]
  9191.       $game_temp.common_event_id = event_id
  9192.       process_battle_event
  9193.     end
  9194.     pause_atb(false)
  9195.   end
  9196.  
  9197.   #--------------------------------------------------------------------------
  9198.   # new method: process_ctb_action
  9199.   #--------------------------------------------------------------------------
  9200.   def process_ctb_action
  9201.     return if @active_battler == nil
  9202.     @spriteset.mark_first_time_order
  9203.     $game_troop.clear_ctb_cache
  9204.     make_action_orders
  9205.     @message_window.visible = true
  9206.     @instant_action = true
  9207.     unless $game_troop.forcing_battler
  9208.       @active_battler.action.ctb_guarding = false
  9209.     end
  9210.     execute_action
  9211.     @message_window.clear
  9212.     @message_window.visible = false
  9213.     unless $game_troop.forcing_battler
  9214.       @active_battler.reset_ctb_speed
  9215.       @active_battler.process_ctb_reset
  9216.     end
  9217.     $game_troop.forcing_battler = nil
  9218.     @active_battler.action.forcing = false
  9219.     @active_battler = nil
  9220.     if YEM::BATTLE_ENGINE::CTB_COMMON_EVENTS[:end_action] != nil
  9221.       event_id = YEM::BATTLE_ENGINE::CTB_COMMON_EVENTS[:end_action]
  9222.       $game_temp.common_event_id = event_id
  9223.       process_battle_event
  9224.     end
  9225.     $game_troop.ctb_ready.shift unless @instant_ctb_action
  9226.     $game_troop.clear_ctb_cache
  9227.     make_action_orders
  9228.   end
  9229.  
  9230.   #--------------------------------------------------------------------------
  9231.   # alias method: execute_action
  9232.   #--------------------------------------------------------------------------
  9233.   alias execute_action_bem execute_action unless $@
  9234.   def execute_action
  9235.     reset_extra_calculation_modifiers
  9236.     if @active_battler != nil
  9237.       if @active_battler.action.valid? or @active_battler.action.forcing
  9238.         execute_action_bem if @active_battler.action != nil
  9239.       end
  9240.       #---
  9241.       if @active_battler.action.forcing and
  9242.       @active_battler.stored_action != nil
  9243.         @active_battler.action = @active_battler.stored_action
  9244.         @active_battler.stored_action = nil
  9245.       elsif @active_battler.action.forcing
  9246.         @active_battler.action.clear
  9247.       end
  9248.     end
  9249.     reset_extra_calculation_modifiers
  9250.   end
  9251.  
  9252.   #--------------------------------------------------------------------------
  9253.   # new method: reset_extra_calculation_modifiers
  9254.   #--------------------------------------------------------------------------
  9255.   def reset_extra_calculation_modifiers
  9256.     $game_temp.action_elements = nil
  9257.     $game_temp.force_critical = nil
  9258.     $game_temp.perfect_hit = false
  9259.     $game_temp.hp_damage_inflate = 100
  9260.     $game_temp.mp_damage_inflate = 100
  9261.     @ignore_cost = false
  9262.     @ptb_updated = false
  9263.     @combo_hits = 0
  9264.     $game_temp.atk_effects = ["calc", "dmg", "state", "effect", "collapse"]
  9265.     $game_temp.item_effects = ["calc", "growth", "dmg", "state", "effect",
  9266.       "collapse"]
  9267.     $game_temp.skill_effects = ["calc", "dmg", "state", "effect", "collapse"]
  9268.     for member in ($game_party.members + $game_troop.members)
  9269.       member.clear_action_results
  9270.     end
  9271.   end
  9272.  
  9273.   #--------------------------------------------------------------------------
  9274.   # overwrite method: execute_action_attack
  9275.   #--------------------------------------------------------------------------
  9276.   def execute_action_attack
  9277.     targets = @active_battler.action.make_targets
  9278.     targets = sort_targets(targets)
  9279.     #--- Setup ---
  9280.     action_list = @active_battler.attack_setup_actions
  9281.     perform_action_list(action_list, targets) unless @chain_action
  9282.     @active_battler.action.friends_unit.update_ptb
  9283.     lunatic_obj_effects(:before)
  9284.     #--- Whole ---
  9285.     action_list = @active_battler.attack_whole_actions
  9286.     perform_action_list(action_list, targets)
  9287.     #--- Target ---
  9288.     action_list = @active_battler.attack_target_actions
  9289.     for target in targets
  9290.       next if target.dead?
  9291.       perform_action_list(action_list, [target])
  9292.     end
  9293.     #--- Follow ---
  9294.     action_list = @active_battler.attack_follow_actions
  9295.     perform_action_list(action_list, targets)
  9296.     lunatic_obj_effects(:after)
  9297.     #--- Finish ---
  9298.     refresh_ptb_windows unless @ptb_updated
  9299.     action_list = @active_battler.attack_finish_actions
  9300.     perform_action_list(action_list, targets) unless @chain_action
  9301.     perform_earn_jp(:attack) if $imported["SkillOverhaul"]
  9302.   end
  9303.  
  9304.   #--------------------------------------------------------------------------
  9305.   # overwrite method: execute_action_guard
  9306.   #--------------------------------------------------------------------------
  9307.   def execute_action_guard
  9308.     @active_battler.action.friends_unit.update_ptb
  9309.     if atb?
  9310.       @active_battler.action.atb_guarding = true
  9311.     elsif ctb?
  9312.       @active_battler.action.ctb_guarding = true
  9313.       @active_battler.action.ctb_guarding_queue = false
  9314.     end
  9315.     refresh_ptb_windows
  9316.     action_list = @active_battler.guard_actions
  9317.     perform_action_list(action_list, [@active_battler])
  9318.     perform_earn_jp(:guard) if $imported["SkillOverhaul"]
  9319.   end
  9320.  
  9321.   #--------------------------------------------------------------------------
  9322.   # overwrite method: execute_action_escape
  9323.   #--------------------------------------------------------------------------
  9324.   def execute_action_escape
  9325.     @active_battler.action.friends_unit.update_ptb
  9326.     refresh_ptb_windows
  9327.     action_list = YEM::DEFAULT_ACTIONS::ENEMY_ESCAPE_ACTIONS
  9328.     perform_action_list(action_list, [@active_battler])
  9329.   end
  9330.  
  9331.   #--------------------------------------------------------------------------
  9332.   # overwrite method: execute_action_wait
  9333.   #--------------------------------------------------------------------------
  9334.   def execute_action_wait
  9335.     if (ptb? and @active_battler.action.guard?) or (ctb?)
  9336.       execute_action_guard
  9337.       return
  9338.     end
  9339.     @active_battler.action.friends_unit.update_ptb
  9340.     refresh_ptb_windows
  9341.     action_list = YEM::DEFAULT_ACTIONS::WAIT_ACTIONS
  9342.     perform_action_list(action_list, [@active_battler])
  9343.   end
  9344.  
  9345.   #--------------------------------------------------------------------------
  9346.   # overwrite method: execute_action_skill
  9347.   #--------------------------------------------------------------------------
  9348.   def execute_action_skill
  9349.     @copy_targets = [] if $imported["SkillEquipSystem"]
  9350.     skill = @active_battler.action.skill
  9351.     @scene_skill = skill
  9352.     perform_skill(skill)
  9353.     perform_earn_jp(:skill) if $imported["SkillOverhaul"]
  9354.     readjust_instant_properties if skill.instant
  9355.   end
  9356.  
  9357.   #--------------------------------------------------------------------------
  9358.   # overwrite method: perform_skill
  9359.   #--------------------------------------------------------------------------
  9360.   def perform_skill(skill)
  9361.     targets = @active_battler.action.make_targets
  9362.     targets = sort_targets(targets, skill)
  9363.     #--- Setup ---
  9364.     action_list = skill.setup_action_list
  9365.     perform_action_list(action_list, targets) unless @chain_action
  9366.     lunatic_obj_effects(:before, skill)
  9367.     @active_battler.perform_skill_cost(skill) unless @ignore_cost
  9368.     @active_battler.action.friends_unit.update_ptb
  9369.     status_window_refresh
  9370.     #--- Whole ---
  9371.     action_list = skill.whole_action_list
  9372.     perform_action_list(action_list, targets)
  9373.     #--- Target ---
  9374.     action_list = skill.target_action_list
  9375.     for target in targets
  9376.       next if target.dead? and !skill.for_dead_friend?
  9377.       perform_action_list(action_list, [target])
  9378.     end
  9379.     #--- Follow ---
  9380.     action_list = skill.follow_action_list
  9381.     perform_action_list(action_list, targets)
  9382.     lunatic_obj_effects(:after, skill)
  9383.     #--- Finish ---
  9384.     perform_copy_skill(skill) if $imported["SkillEquipSystem"]
  9385.     refresh_ptb_windows unless @ptb_updated
  9386.     action_list = skill.finish_action_list
  9387.     perform_action_list(action_list, targets) unless @chain_action
  9388.   end
  9389.  
  9390.   #--------------------------------------------------------------------------
  9391.   # overwrite method: execute_action_item
  9392.   #--------------------------------------------------------------------------
  9393.   def execute_action_item
  9394.     item = @active_battler.action.item
  9395.     if unique_item_effect?(item)
  9396.       perform_unique_item(item)
  9397.     else
  9398.       @scene_item = item
  9399.       perform_item(item)
  9400.     end
  9401.     perform_earn_jp(:item) if $imported["SkillOverhaul"]
  9402.     readjust_instant_properties if item.instant
  9403.   end
  9404.  
  9405.   #--------------------------------------------------------------------------
  9406.   # new method: unique_item_effect?
  9407.   #--------------------------------------------------------------------------
  9408.   def unique_item_effect?(item)
  9409.     return false unless @active_battler.actor?
  9410.     if @active_battler.pharmacology and item.unique_effect[:pharm] != nil
  9411.       return true
  9412.     elsif item.unique_effect[:actor].include?(@active_battler.actor_id)
  9413.       return true
  9414.     elsif item.unique_effect[:class].include?(@active_battler.class_id)
  9415.       return true
  9416.     end
  9417.     return false
  9418.   end
  9419.  
  9420.   #--------------------------------------------------------------------------
  9421.   # new method: perform_unique_item
  9422.   #--------------------------------------------------------------------------
  9423.   def perform_unique_item(item)
  9424.     if @active_battler.pharmacology and item.unique_effect[:pharm] != nil
  9425.       item_id = item.unique_effect[:pharm]
  9426.     elsif item.unique_effect[:actor].include?(@active_battler.actor_id)
  9427.       item_id = item.unique_effect[:actor][@active_battler.actor_id]
  9428.     elsif item.unique_effect[:class].include?(@active_battler.class_id)
  9429.       item_id = item.unique_effect[:class][@active_battler.class_id]
  9430.     end
  9431.     unique_item = $data_items[item_id]
  9432.     @active_battler.perform_consume_item(item)
  9433.     @ignore_cost = true
  9434.     perform_item(unique_item)
  9435.   end
  9436.  
  9437.   #--------------------------------------------------------------------------
  9438.   # new method: perform_item
  9439.   #--------------------------------------------------------------------------
  9440.   def perform_item(item)
  9441.     targets = @active_battler.action.make_targets
  9442.     targets = sort_targets(targets, item)
  9443.     #--- Setup ---
  9444.     action_list = item.setup_action_list
  9445.     perform_action_list(action_list, targets) unless @chain_action
  9446.     lunatic_obj_effects(:before, item)
  9447.     @active_battler.perform_consume_item(item) unless @ignore_cost
  9448.     @active_battler.action.friends_unit.update_ptb
  9449.     status_window_refresh
  9450.     #--- Whole ---
  9451.     action_list = item.whole_action_list
  9452.     perform_action_list(action_list, targets)
  9453.     #--- Target ---
  9454.     action_list = item.target_action_list
  9455.     for target in targets
  9456.       next if target.dead? and !item.for_dead_friend?
  9457.       perform_action_list(action_list, [target])
  9458.     end
  9459.     #--- Follow ---
  9460.     action_list = item.follow_action_list
  9461.     perform_action_list(action_list, targets)
  9462.     lunatic_obj_effects(:after, item)
  9463.     #--- Finish ---
  9464.     refresh_ptb_windows unless @ptb_updated
  9465.     action_list = item.finish_action_list
  9466.     perform_action_list(action_list, targets) unless @chain_action
  9467.   end
  9468.  
  9469.   #--------------------------------------------------------------------------
  9470.   # overwrite method: process_battle_event
  9471.   #--------------------------------------------------------------------------
  9472.   def process_battle_event
  9473.     @message_window.clear
  9474.     @message_window.visible = true
  9475.     loop do
  9476.       return if judge_win_loss
  9477.       return if $game_temp.next_scene != nil
  9478.       $game_troop.interpreter.update
  9479.       $game_troop.setup_battle_event
  9480.       wait_for_message
  9481.       process_action if $game_troop.forcing_battler != nil
  9482.       return unless $game_troop.interpreter.running?
  9483.       update_basic
  9484.     end
  9485.     @message_window.clear
  9486.     $game_message.clear
  9487.   end
  9488.  
  9489.   #--------------------------------------------------------------------------
  9490.   # new method: process_complete_battle_event
  9491.   #--------------------------------------------------------------------------
  9492.   def process_complete_battle_event
  9493.     @message_window.clear
  9494.     @message_window.visible = true
  9495.     loop do
  9496.       $game_troop.interpreter.update
  9497.       $game_troop.setup_battle_event
  9498.       wait_for_message
  9499.       process_action if $game_troop.forcing_battler != nil
  9500.       return unless $game_troop.interpreter.running?
  9501.       update_basic
  9502.     end
  9503.     @message_window.clear
  9504.     $game_message.clear
  9505.   end
  9506.  
  9507.   #--------------------------------------------------------------------------
  9508.   # new method: readjust_instant_properties
  9509.   #--------------------------------------------------------------------------
  9510.   def readjust_instant_properties
  9511.     @performed_actors.delete(@active_battler)
  9512.     if @active_battler.enemy?
  9513.       @active_battler.make_action
  9514.       @instant_ctb_action = true if ctb?
  9515.     elsif @active_battler.actor? and @active_battler.auto_battle
  9516.       @active_battler.make_action
  9517.     end
  9518.   end
  9519.  
  9520.   #--------------------------------------------------------------------------
  9521.   # new method: target_mirror?
  9522.   #--------------------------------------------------------------------------
  9523.   def target_mirror?(mirror, target)
  9524.     case @view_type
  9525.     when 0; view = :empty
  9526.     when 1; view = :front
  9527.     when 2; view = :side
  9528.     when 3; view = :angle
  9529.     else; return mirror
  9530.     end
  9531.     index = target.actor? ? 0 : 1
  9532.     mirror = !mirror if YEM::BATTLE_ENGINE::MISC_VIEW_ADJUSTMENTS[view][index]
  9533.     return mirror
  9534.   end
  9535.  
  9536.   #--------------------------------------------------------------------------
  9537.   # new method: show_animation?
  9538.   #--------------------------------------------------------------------------
  9539.   def show_animation?
  9540.     return true if cinematic?
  9541.     return $game_switches[YEM::BATTLE_ENGINE::OPTIONS[:animation_sw]]
  9542.   end
  9543.  
  9544.   #--------------------------------------------------------------------------
  9545.   # overwrite method: remove_states_auto
  9546.   # Scene Battle Version
  9547.   #--------------------------------------------------------------------------
  9548.   def remove_states_auto
  9549.     for member in $game_troop.members + $game_party.members
  9550.       next if member == nil
  9551.       @message_window.clear
  9552.       member.remove_states_auto
  9553.       display_state_changes(member)
  9554.     end
  9555.     @message_window.clear
  9556.   end
  9557.  
  9558.   #--------------------------------------------------------------------------
  9559.   # alias method: display_current_state
  9560.   #--------------------------------------------------------------------------
  9561.   alias display_current_state_bem display_current_state unless $@
  9562.   def display_current_state
  9563.     return unless YEM::BATTLE_ENGINE::DISPLAY_MESSAGE[:currentstate]
  9564.     display_current_state_bem
  9565.   end
  9566.  
  9567.   #--------------------------------------------------------------------------
  9568.   # display_action_effects
  9569.   #--------------------------------------------------------------------------
  9570.   def display_action_effects(target, obj = nil)
  9571.     return if target.skipped
  9572.     line_number = @message_window.line_number
  9573.     display_critical(target, obj)
  9574.     display_damage(target, obj)
  9575.     display_state_changes(target, obj)
  9576.     lunatic_obj_effects(:during, obj, target)
  9577.     @message_window.back_to(line_number)
  9578.   end
  9579.  
  9580.   #--------------------------------------------------------------------------
  9581.   # overwrite method: display_critical
  9582.   #--------------------------------------------------------------------------
  9583.   def display_critical(target, obj = nil)
  9584.     return unless target.critical
  9585.     action_list = YEM::DEFAULT_ACTIONS::CRITICAL_ACTIONS
  9586.     perform_action_list(action_list, [target])
  9587.   end
  9588.  
  9589.   #--------------------------------------------------------------------------
  9590.   # overwrite method: display_miss
  9591.   #--------------------------------------------------------------------------
  9592.   def display_miss(target, obj = nil)
  9593.     if obj == nil or obj.physical_attack
  9594.       action_list = YEM::DEFAULT_ACTIONS::MISS_ACTIONS
  9595.       perform_action_list(action_list, [target])
  9596.     else
  9597.       display_failure(target, obj)
  9598.     end
  9599.   end
  9600.  
  9601.   #--------------------------------------------------------------------------
  9602.   # overwrite method: display_evasion
  9603.   #--------------------------------------------------------------------------
  9604.   def display_evasion(target, obj = nil)
  9605.     action_list = YEM::DEFAULT_ACTIONS::EVADE_ACTIONS
  9606.     perform_action_list(action_list, [target])
  9607.   end
  9608.  
  9609.   #--------------------------------------------------------------------------
  9610.   # overwrite method: display_failure
  9611.   #--------------------------------------------------------------------------
  9612.   def display_failure(target, obj = nil)
  9613.     action_list = YEM::DEFAULT_ACTIONS::FAIL_ACTIONS
  9614.     perform_action_list(action_list, [target])
  9615.   end
  9616.  
  9617.   #--------------------------------------------------------------------------
  9618.   # overwrite method: display_hp_damage
  9619.   #--------------------------------------------------------------------------
  9620.   def display_hp_damage(target, obj = nil)
  9621.     if target.hp_damage == 0
  9622.       return if obj != nil and obj.damage_to_mp
  9623.       return if obj != nil and obj.base_damage == 0
  9624.       @combo_hits += 1
  9625.       action_list = YEM::DEFAULT_ACTIONS::HP_DAMAGE_NONE
  9626.       perform_action_list(action_list, [target])
  9627.     elsif target.hp_damage > 0
  9628.       @combo_hits += 1
  9629.       @combo_damage += target.hp_damage
  9630.       @combo_update = true
  9631.       action_list = YEM::DEFAULT_ACTIONS::HP_DAMAGE_DMG
  9632.       perform_action_list(action_list, [target])
  9633.     else
  9634.       @combo_hits += 1
  9635.       @combo_damage += target.hp_damage
  9636.       @combo_update = true
  9637.       action_list = YEM::DEFAULT_ACTIONS::HP_DAMAGE_HEAL
  9638.       perform_action_list(action_list, [target])
  9639.     end
  9640.   end
  9641.  
  9642.   #--------------------------------------------------------------------------
  9643.   # overwrite method: display_mp_damage
  9644.   #--------------------------------------------------------------------------
  9645.   def display_mp_damage(target, obj = nil)
  9646.     return if target.dead?
  9647.     return if target.mp_damage == 0
  9648.     if target.mp_damage > 0
  9649.       action_list = YEM::DEFAULT_ACTIONS::MP_DAMAGE_DMG
  9650.       perform_action_list(action_list, [target])
  9651.     else
  9652.       action_list = YEM::DEFAULT_ACTIONS::MP_DAMAGE_HEAL
  9653.       perform_action_list(action_list, [target])
  9654.     end
  9655.   end
  9656.  
  9657.   #--------------------------------------------------------------------------
  9658.   # overwrite method: display_state_changes
  9659.   #--------------------------------------------------------------------------
  9660.   def display_state_changes(target, obj = nil)
  9661.     return if target.missed or target.evaded
  9662.     return unless target.states_active?
  9663.     if @message_window.line_number < 4 and
  9664.     YEM::BATTLE_ENGINE::DISPLAY_MESSAGE[:state_change]
  9665.       @message_window.add_instant_text("")
  9666.     end
  9667.     display_added_states(target, obj)
  9668.     display_removed_states(target, obj)
  9669.     display_remained_states(target, obj)
  9670.     if YEM::BATTLE_ENGINE::DISPLAY_MESSAGE[:state_change] and
  9671.     @message_window.last_instant_text.empty?
  9672.       @message_window.back_one
  9673.     end
  9674.   end
  9675.  
  9676.   #--------------------------------------------------------------------------
  9677.   # overwrite method: display_added_states
  9678.   #--------------------------------------------------------------------------
  9679.   def display_added_states(target, obj = nil)
  9680.     action_list = YEM::DEFAULT_ACTIONS::ADD_STATE
  9681.     @state_number = 0 if @state_number == nil
  9682.     for state in target.added_states
  9683.       perform_action_list(action_list, [target])
  9684.       @state_number += 1
  9685.     end
  9686.     @state_number = nil
  9687.   end
  9688.  
  9689.   #--------------------------------------------------------------------------
  9690.   # overwrite method: display_removed_states
  9691.   #--------------------------------------------------------------------------
  9692.   def display_removed_states(target, obj = nil)
  9693.     action_list = YEM::DEFAULT_ACTIONS::REM_STATE
  9694.     @state_number = 0 if @state_number == nil
  9695.     for state in target.removed_states
  9696.       perform_action_list(action_list, [target])
  9697.       @state_number += 1
  9698.     end
  9699.     @state_number = nil
  9700.   end
  9701.  
  9702.   #--------------------------------------------------------------------------
  9703.   # overwrite method: display_remained_states
  9704.   #--------------------------------------------------------------------------
  9705.   def display_remained_states(target, obj = nil)
  9706.     action_list = YEM::DEFAULT_ACTIONS::DUR_STATE
  9707.     @state_number = 0 if @state_number == nil
  9708.     for state in target.remained_states
  9709.       perform_action_list(action_list, [target])
  9710.       @state_number += 1
  9711.     end
  9712.     @state_number = nil
  9713.   end
  9714.  
  9715. end # Scene_Battle
  9716.  
  9717. #===============================================================================
  9718. #
  9719. # END OF FILE
  9720. #
  9721. #===============================================================================
  9722.