Advertisement
EduAlves

Galv's Actor Duel

Nov 9th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 46.13 KB | None | 0 0
  1. #-------------------------------------------------------------------------------
  2. #  Galv's Actor Duel Mini Game
  3. #-------------------------------------------------------------------------------
  4. #  For: RPGMAKER VX ACE
  5. #  Version 1.5
  6. #-------------------------------------------------------------------------------
  7. #  2013-09-11 - Version 1.5 - fixed <fse: > tag for skills. Ooops!
  8. #  2013-07-13 - Version 1.4 - fixed a bug with changing music script call
  9. #  2013-07-11 - Version 1.3 - added compatibility with victor's animated battler
  10. #                           - added tag for actor to play victory pose once
  11. #  2013-07-11 - Version 1.2 - fixed (hopefully) a crash with AI battle. Updated
  12. #                             AI to use skills more often.
  13. #  2013-07-10 - Version 1.1 - added state icons, button combo moves, working
  14. #                           - regen, poisons, buffs, projectile attacks.
  15. #  2013-07-08 - Version 1.0 - release
  16. #-------------------------------------------------------------------------------
  17. #  Holder's animated battler spritesheets can be found here:
  18. #  http://animatedbattlers.wordpress.com/
  19. #-------------------------------------------------------------------------------
  20. #  This script adds a scene where you can face two actors against each other in
  21. #  a mini-game duel that plays similar to a fighting game.
  22. #  You can do Player1 VS AI or Player1 VS Player2 (on same computer)
  23. #
  24. #  The actors use their statistics and hp in the duel. They can move, jump,
  25. #  block, attack and use button combo skills that you create using notetags
  26. #  on skills. Normal attack damage formula is taken from skill 1 by default.
  27. #
  28. #  Actors have stamina that regenerates during the fight. Each attack uses a
  29. #  certain amount of stamina and the fighter cannot attack or use a skill if he
  30. #  doesn't have enough left.
  31. #
  32. #  Fighters can be affected by buffs and states, however a few things have no
  33. #  effect in an actor duel such as blinds or stuns. Poisons, regen, parameter
  34. #  boosting stats do work.
  35. #
  36. #-------------------------------------------------------------------------------
  37. #  BASIC INSTRUCTIONS
  38. #-------------------------------------------------------------------------------
  39. #  1. Get holder style battlers (http://animatedbattlers.wordpress.com/)
  40. #  2. Import battlers into /Graphics/Battlers folder
  41. #  3. Copy /Graphics/Battlers/FightSkills.png from the demo into your project
  42. #  4. Copy /Graphics/System/kombat_bar.png from the demo into your project
  43. #  5. Put this script below Materials and above main.
  44. #  6. Read all instructions and settings
  45. #  7. Remember to start a NEW GAME instead of loading a save file that was made
  46. #     prior to adding this script
  47. #-------------------------------------------------------------------------------
  48.  
  49. #-------------------------------------------------------------------------------
  50. #  SCRIPT CALLS
  51. #-------------------------------------------------------------------------------
  52. #
  53. #  set_fighters(id1,id2)         # Starts a kombat between actors with id1 & id2
  54. #
  55. #  set_fbacks("back1","back2")   # Change battlebacks for next kombat. "back1"
  56. #                                # is from /Graphics/Battlebacks1/ and "back2"
  57. #                                # is from /Graphics/Battlebacks2/
  58. #
  59. #  set_fmusic("MusicName")       # Change the kombat music
  60. #
  61. #  set_fmode(x)                  # 0 = P1 vs AI      1 = P1 vs P2    (Default 0)
  62. #
  63. #  add_fskill(a_id,s_id,[btns])  # a_id = actor id... s_id = skill id
  64. #                                # [btns] is the button combo array which can
  65. #                                # include:   :l   :r   :u   :d
  66. #                                # (See explanation below)
  67. #
  68. #-------------------------------------------------------------------------------
  69. #  btn       info
  70. #  -----------------------------
  71. #  :l        Left key for whomever is on the left. 'away from enemy' key.
  72. #  :r        Right key for whomever is on the left. 'toward the enemy' key.
  73. #  :u        Up key
  74. #  :d        Down key
  75. #
  76. #  EXAMPLE OF SCRIPT CALL TO ADD A SKILL:
  77. #  add_fskill(1,80,[:l,:l,:r])     # This will give actor 1 a button combo:
  78. #                                  # Left, Left, Right, Attack (while on left)
  79. #                                  # (Right, Right, Left, Attack while on right)
  80. #                                  # Which will activate skill 80
  81. #
  82. #-------------------------------------------------------------------------------
  83.  
  84. #-------------------------------------------------------------------------------
  85. #  Note tag for ACTORS required
  86. #-------------------------------------------------------------------------------
  87. #
  88. #  <fimage: imagename>       # The name of the holder-style spritesheet
  89. #                            # image from /Graphics/Battlers/
  90. #
  91. #-------------------------------------------------------------------------------
  92. #  Note tag for ACTORS to override Defaults
  93. #-------------------------------------------------------------------------------
  94. #
  95. #  <fatks: x,x,x,x>          # The rows in the spritesheet to use for the
  96. #                            # actor's normal attacks. Default is COMBO below
  97. #
  98. #  <fse miss: sename>        # SE to use for attacking and missing
  99. #
  100. #  <fhit: x>                 # Animation played when hitting enemy with attack
  101. #
  102. #  <frange: x>               # How close need to be to make contact with attack
  103. #
  104. #  <fviconeanim>             # This notetag will mean the actor's victory pose
  105. #                            # will only play once instead of repeat.
  106. #
  107. #-------------------------------------------------------------------------------
  108.  
  109. #-------------------------------------------------------------------------------
  110. #  Note tag for SKILLS
  111. #-------------------------------------------------------------------------------
  112. #
  113. #  <fpose: x>            # The pose row used for actor when using this skill.
  114. #                        # Will default to row 7 if no tag added.
  115. #
  116. #  <fcost: x>            # Stamina required to use skill
  117. #
  118. #  <fse: sename>         # SE that plays when using the skill
  119. #
  120. #  <fp: p,s,a,t,r>       # Use this tag if the skill will be a projectile.
  121. #                        # p = pose row of SKILLIMAGE spritesheet
  122. #                        # s = speed projectile travels
  123. #                        # a = animation_id when projectile is created
  124. #                        # t = time before projectile disappears (60 per second)
  125. #                        # r = How close projectile needs to be to make contact
  126. #                        # Skill's 'scope' must be set to enemy for this to work
  127. #                        
  128. #
  129. #
  130. #-------------------------------------------------------------------------------
  131. #  BUTTON COMBO NOTE
  132. #  If a skill has scope of ally, the animation in the database skill is played
  133. #  on the user. If not, the animation is played when the skill hits the enemy.
  134. #-------------------------------------------------------------------------------
  135.  
  136. #-------------------------------------------------------------------------------
  137. #  DEFAULT SPRITESHEET POSES (HOLDER SETUP)
  138. #-------------------------------------------------------------------------------
  139. #  ROW     POSE                     USED IN DEFAULT SCRIPT
  140. #
  141. #   0      Idle                     Yes
  142. #   1      Guard                    Yes
  143. #   2      Poor Status              Yes
  144. #   3      Get hit                  Yes
  145. #   4      Normal Attack            Yes
  146. #   5      Use Item
  147. #   6      Use Skill
  148. #   7      Use Magic                Yes
  149. #   8      Move toward              Yes
  150. #   9      Move back                Yes
  151. #   10     Victory                  Yes
  152. #   11     Battle Start
  153. #   12     Dead                     Yes
  154. #   13     Spritesheet Info
  155. #-------------------------------------------------------------------------------
  156.  
  157. ($imported ||= {})["Galv_ActorDuel"] = true
  158. module GALVFIGHT
  159.  
  160. #-------------------------------------------------------------------------------
  161. #
  162. #  ** SETTINGS
  163. #
  164. #-------------------------------------------------------------------------------
  165.  
  166.   FONT = "Arial"  # Font used in script
  167.   VICTOR_VAR = 1  # Variable used to store the winner's ID in. 0 if nobody wins.
  168.  
  169.   QUIT_SWITCH = 1 # Turn this swith ON to disable the quit menu. OFF to enable
  170.  
  171.   CMD_QUIT = "Encerrar a luta"  # To quit the fight
  172.   CMD_CANCEL = "Voltar à luta"    # When cancelling the quit menu
  173.  
  174.   # Spritesheet
  175.  
  176.   COLS = 16        # Number of animation columns in spritesheet
  177.   ROWS = 28       # Number of rows in spritesheet
  178.   SIZE = 1.8        # Size of the battlers (2 = 2x zoom. 1 = normal)
  179.  
  180.   SKILLIMAGE = "FightSkills2"  # name of skill spritesheet in /Graphics/Battlers/
  181.   SKILLCOLS = 8   # Number of animation columns in skill spritesheet
  182.   SKILLROWS = 28  # Number of rows in skill spritesheet
  183.  
  184.  
  185.   # Actor Defaults
  186.  
  187.   COMBO = [8]           # Array of spritesheet rows that cycle with attacks
  188.                         # eg. [4,5,6] will cycle rows 4,5 and 6 when attacking
  189.   MISS_SE = "Wind7"     # "SE_Name" for missing and attack sound
  190.   HIT_ANIM = 115        # Animation played when hitting enemy.
  191.   GUARD_ANIM = 116      # Animation played when guarded a hit
  192.   RANGE = 45            # Distance from opponent before attack makes contact
  193.  
  194.   JUMP_POSE = 5         # Pose used when jumping
  195.  
  196.   SKILLSE = "Wind7"     # "SE_Name" played when using a skill
  197.  
  198.  
  199.   # Level Defaults
  200.  
  201.   MUSIC = "Battle6"        # Default battle BGM
  202.   VICTORY_ME = "victory"  # Default victory ME
  203.  
  204.   BATTLEBACK1 = "res1"  # Default battleback 1 from /Graphics/Battlebacks1/
  205.   BATTLEBACK2 = "res1"  # Default battleback 2 from /Graphics/Battlebacks2/
  206.   BATTLEBACK3 = "Kekkai2"
  207.  
  208.   P1_X = 100            # Starting X position of player 1
  209.   P2_X = 455            # Starting X position of player 2
  210.   Y = 370               # Grounded Y position
  211.  
  212.  
  213.   # Fighting
  214.  
  215.   MAX_STAMINA = 1000      # Stamina each fighter has
  216.   STAMINA_COST = 100     # Amount of stamina out of 1000 that attacking uses
  217.   REGEN_RATE = 1.3       # Speed that stamina regenerates
  218.  
  219.   GUARD_DAMAGE = 0.2    # Normal damage is multiplied by this when guarding.
  220.  
  221.   ATTACK_SKILL = 1       # Skill to use for basic attacks
  222.  
  223.   TURNTIMER = 150        # Number of frames before it counts as a new turn for
  224.                          # buffs and states
  225.  
  226.  
  227.   # Text
  228.  
  229.   START1 = "Prontos?"      # Text that appears at the start
  230.   START2 = "LUTEM"
  231.  
  232.   NOWINNER = "DESISTÊNCIA"   # Message when player quits from the match
  233.   WINS = " VENCEU!"            # Message that comes after winner's name
  234.  
  235.  
  236.  
  237. #-------------------------------------------------------------------------------
  238. #  CONTROLS - PLAYER 1
  239. #-------------------------------------------------------------------------------
  240.   P1_UP =     :UP        # Jump
  241.   P1_DOWN =   :DOWN      # Block
  242.   P1_LEFT =   :LEFT      # Move left
  243.   P1_RIGHT =  :RIGHT     # Move right
  244.   P1_ACTION = :C         # (Spacebar key) Attack
  245.  
  246. #-------------------------------------------------------------------------------
  247. #  CONTROLS - PLAYER 2
  248. #-------------------------------------------------------------------------------
  249.   P2_UP =     :R         # (W key) Jump
  250.   P2_DOWN =   :Y         # (S key) Block
  251.   P2_LEFT =   :X         # (A key) Move Left
  252.   P2_RIGHT =  :Z         # (D key) Move Right
  253.   P2_ACTION = :CTRL      # Attack
  254.  
  255. #-------------------------------------------------------------------------------
  256.  
  257. end
  258.  
  259. #-------------------------------------------------------------------------------
  260. #
  261. #  ** END SETTINGS
  262. #
  263. #-------------------------------------------------------------------------------
  264.  
  265.  
  266.     #---------------#
  267. #---|   GFIGHT_AI   |-----------------------------------------------------------
  268.     #---------------#
  269.  
  270. module GFIGHT_AI
  271.   def update_f2_ai
  272.     update_ai_random
  273.     update_ai_decision
  274.     update_ai_action
  275.     update_timer
  276.     update_victorcheck
  277.   end
  278.  
  279.   def p1; @f1; end
  280.   def ai; @f2; end
  281.    
  282.   def update_ai_random
  283.     if !ai_timer_running?
  284.       @chance = (rand(10) + 1).to_i
  285.       @schance = (rand(10) + 1).to_i
  286.     end
  287.   end
  288.  
  289.   def update_ai_decision
  290.     if ai.in_range_x
  291.       update_ai_in_range
  292.     else
  293.       update_ai_out_of_range
  294.     end
  295.   end
  296.  
  297.   def update_ai_in_range
  298.     if p1.attacking?
  299.       # IF PLAYER IS ATTACKING
  300.       if ai.getting_hit? && @chance > 2
  301.         @ai_move = :down
  302.         @ai_action = false
  303.         @ai_timer = rand(50) + 10 if !ai_timer_running?
  304.       else
  305.         if @chance > 5
  306.           @ai_move = :down
  307.           @ai_action = false
  308.           @ai_timer = rand(50) + 10 if !ai_timer_running?
  309.         elsif @chance > 2
  310.           ai_melee_action
  311.           @ai_timer = rand(20) + 5 if !ai_timer_running?
  312.         else
  313.           @ai_move = random_move_in_range
  314.           @ai_timer = rand(50) + 10 if !ai_timer_running?
  315.         end
  316.       end
  317.     else
  318.       # IF PLAYER IS NOT ATTACKING
  319.       if @chance > 4
  320.         ai_melee_action
  321.         @ai_timer = rand(20) + 10 if !ai_timer_running?
  322.       elsif @chance > 2
  323.         @ai_move = :down
  324.         @ai_action = false
  325.         @ai_timer = rand(40) + 20 if !ai_timer_running?
  326.       else
  327.         @ai_move = random_move_in_range
  328.         @ai_timer = rand(40) + 20 if !ai_timer_running?
  329.       end
  330.     end
  331.   end
  332.  
  333.   def update_ai_out_of_range
  334.     @ai_move = random_move_out_of_range
  335.     @ai_action = false
  336.     @ai_raction = true
  337.   end
  338.  
  339.   def ai_jump
  340.     if ai.fjumping?
  341.       @ai_move = :none
  342.     else
  343.       @ai_move = :up
  344.       ai.fight_pose = 0
  345.     end
  346.   end
  347.  
  348.   def random_move_in_range
  349.     if ai.fight_x <= 20 + 10
  350.       return @chance > 7 ? :right : :none
  351.     elsif ai.fight_x >= Graphics.width - 20 - 10
  352.       return @chance > 7 ? :left : :none
  353.     elsif @chance >= 8
  354.       return :right
  355.     elsif @chance >= 5
  356.       return :left
  357.     elsif @chance == 1
  358.       return ai.fjumping? ? :left : :up
  359.     elsif @chance == 2
  360.       return ai.fjumping? ? :right : :up
  361.     else
  362.       return :none
  363.     end
  364.   end
  365.  
  366.   def random_move_out_of_range
  367.     if ai.fight_x <= 20 + 10
  368.       @ai_timer = rand(30) + 10 if !ai_timer_running?
  369.       return @chance > 4 ? :right : :none
  370.     elsif ai.fight_x >= Graphics.width - 20 - 10
  371.       @ai_timer = rand(30) + 10 if !ai_timer_running?
  372.       return @chance > 4 ? :left : :none
  373.     elsif @chance >= 7
  374.       @ai_timer = rand(40) + 10 if !ai_timer_running?
  375.       return ai_advance
  376.     elsif @chance >= 4
  377.       @ai_timer = rand(40) + 10 if !ai_timer_running?
  378.       return ai_retreat
  379.     else
  380.       @ai_timer = rand(30) + 10 if !ai_timer_running?
  381.       return :none
  382.     end
  383.   end
  384.  
  385.   def ai_timer_running?
  386.     @ai_timer > 0
  387.   end
  388.  
  389.   def update_ai_action
  390.     ai.fight_move(@ai_move)
  391.     ai_melee_action if @ai_action
  392.     ai_range_action if @ai_raction
  393.   end
  394.  
  395.   def ai_melee_action
  396.     if @schance <= 2
  397.       bcs = get_ai_random_skill
  398.       ai.fight_combo_skill(bcs) if bcs > 0
  399.     else
  400.       ai.fight_action
  401.     end
  402.   end
  403.  
  404.   def ai_range_action
  405.     if @schance <= 3
  406.       bcs = get_ai_projectile_skill
  407.       ai.fight_combo_skill(bcs) if bcs > 0
  408.     end
  409.   end
  410.  
  411.   def get_ai_projectile_skill
  412.     ai.combo_skills.each { |combo|
  413.       return combo[1] if $data_skills[combo[1]].fproj
  414.     }
  415.     return 0
  416.   end
  417.  
  418.   def get_ai_random_skill
  419.     cskills = ai.combo_skills.to_a
  420.     rskill = cskills.sample
  421.     @ai_raction = false
  422.     return 0 if rskill.nil?
  423.     return rskill[1] <= 0 ? 0 : rskill[1]
  424.   end
  425.  
  426.   def ai_make_attack
  427.     if ai.fstamina < GALVFIGHT::STAMINA_COST
  428.       @ai_move = :down
  429.     else
  430.       @ai_action = true
  431.       @ai_move = random_move_in_range
  432.     end
  433.   end
  434.  
  435.   def ai_retreat
  436.     return ai.fight_x > p1.fight_x ? :right : :left
  437.   end
  438.  
  439.   def ai_advance
  440.     return ai.fight_x < p1.fight_x ? :right : :left
  441.   end
  442.  
  443.   def update_timer
  444.     @ai_timer -= 1
  445.   end
  446.  
  447.   def update_victorcheck
  448.     if p1.dead?
  449.       @phase = 2
  450.       @victor = ai
  451.     end
  452.   end
  453. end # GFIGHT_AI
  454.  
  455.  
  456.     #----------------------#
  457. #---|   GAME_INTERPRETER   |----------------------------------------------------
  458.     #----------------------#
  459.  
  460. class Game_Interpreter
  461.   def set_fighters(player1,player2)
  462.     $game_system.save_bgm
  463.     command_221
  464.     a = $game_actors[player1]
  465.     b = $game_actors[player2]
  466.     $game_system.fighters = [a,b]
  467.     SceneManager.call(Scene_ActorDuel)
  468.     wait(1)
  469.     command_222
  470.     $game_system.replay_bgm
  471.   end
  472.  
  473.   def set_fbacks(back1,back2,back3)
  474.     $game_system.fbacks = [back1,back2,back3]
  475.   end
  476.  
  477.   def set_fmusic(music)
  478.     $game_system.fmusic[0] = music
  479.   end
  480.  
  481.   def set_fmode(mode)
  482.     $game_system.fmode = mode
  483.   end
  484.  
  485.   def add_skill(a_id,s_id,btns)
  486.     $game_actors[a_id].combo_skills[btns] = s_id
  487.   end
  488. end
  489.  
  490.  
  491.     #------------------#
  492. #---|   RPG BASEITEM   |--------------------------------------------------------
  493.     #------------------#
  494.  
  495. class RPG::BaseItem
  496.   def f_atks
  497.     if @f_atks.nil?
  498.       if @note =~ /<fatks:[ ](.*)>/i
  499.         @f_atks = $1.to_s.split(",").map {|i| i.to_i}
  500.       else
  501.         @f_atks = GALVFIGHT::COMBO
  502.       end
  503.     end
  504.     @f_atks
  505.   end
  506. end # RPG::Item
  507.  
  508. class RPG::Skill
  509.   def fpose
  510.     if @fpose.nil?
  511.       if @note =~ /<fpose:[ ](.*)>/i
  512.         @fpose = $1.to_i
  513.       else
  514.         @fpose = 7
  515.       end
  516.     end
  517.     @fpose
  518.   end
  519.   def fcost
  520.     if @fcost.nil?
  521.       if @note =~ /<fcost:[ ](.*)>/i
  522.         @fcost = $1.to_i
  523.       else
  524.         @fcost = GALVFIGHT::STAMINA_COST
  525.       end
  526.     end
  527.     @fcost
  528.   end
  529.   def fproj
  530.     if @fproj.nil?
  531.       if @note =~ /<fp:[ ](.*)>/i
  532.         @fproj = $1.to_s.split(",").map {|i| i.to_i}
  533.       else
  534.         @fproj = nil
  535.       end
  536.     end
  537.     @fproj
  538.   end
  539.   def fse
  540.     if @fse.nil?
  541.       if @note =~ /<fse:[ ](.*)>/i
  542.         @fse = $1.to_s
  543.       else
  544.         @fse = GALVFIGHT::SKILLSE
  545.       end
  546.     end
  547.     @fse
  548.   end
  549. end # RPG::Skill
  550.  
  551.  
  552.     #----------------#
  553. #---|   GAME_ACTOR   |----------------------------------------------------------
  554.     #----------------#
  555.  
  556. class Game_Actor < Game_Battler
  557.   attr_reader :fhit_anim
  558.   attr_reader :frange
  559.   attr_accessor :fight_x
  560.   attr_accessor :fight_y
  561.   attr_accessor :fight_pose
  562.   attr_accessor :fight_sprite
  563.   attr_accessor :fight_speed
  564.   attr_accessor :fight_mspeed
  565.   attr_accessor :fstamina
  566.   attr_accessor :combo_skills
  567.   attr_accessor :fprojectiles
  568.   attr_accessor :fvicpose
  569.  
  570.   alias galv_fight_gagb_setup setup
  571.   def setup(actor_id)
  572.     galv_fight_gagb_setup(actor_id)
  573.     init_fight_vars
  574.     @fight_sprite = actor.note =~ /<fimage: (.*)>/i ? $1 : ""
  575.     @combo = actor.f_atks
  576.     @combo_skills = {}
  577.     @fse_miss = actor.note =~ /<fse miss: (.*)>/i ? $1 : GALVFIGHT::MISS_SE
  578.     @fhit_anim = actor.note =~ /<fhit: (.*)>/i ? $1.to_i : GALVFIGHT::HIT_ANIM
  579.     @frange = actor.note =~ /<frange: (.*)>/i ? $1.to_i : GALVFIGHT::RANGE
  580.     @fvicpose = actor.note =~ /<fviconeanim>/i ? true : false # true = one play
  581.   end
  582.  
  583.   def init_fight_vars
  584.     @fight_x = 0
  585.     @fight_y = GALVFIGHT::Y
  586.     @fight_pose = 0
  587.     @fight_speed = 0.to_f
  588.     @fight_mspeed = 4
  589.     @attack_timer = 0
  590.     @skill_timer = 0
  591.     @takehit_timer = 0
  592.     @jump = 0
  593.     @fstamina = GALVFIGHT::MAX_STAMINA
  594.     @btn_combo = []
  595.     @btn_timer = 0
  596.     @fprojectiles = []
  597.   end
  598.  
  599.   def fight_move(direction)
  600.     case direction
  601.     when :up
  602.       fight_jump
  603.       fight_slowing
  604.     when :down
  605.       fight_guard
  606.       fight_slowing
  607.     when :left
  608.       if !attacking?
  609.         if @fight_x < fight_target.fight_x
  610.           @fight_pose = 9
  611.         else
  612.           @fight_pose = 8
  613.         end
  614.       end
  615.       return @fight_speed = 0 if fight_left_limit
  616.       @fight_speed -= 0.4
  617.       @fight_speed = -@fight_mspeed if @fight_speed <= -@fight_mspeed
  618.     when :right
  619.       if !attacking?
  620.         if @fight_x < fight_target.fight_x
  621.           @fight_pose = 8
  622.         else
  623.           @fight_pose = 9
  624.         end
  625.       end
  626.       return @fight_speed = 0 if fight_right_limit
  627.       @fight_speed += 0.4
  628.       @fight_speed = @fight_mspeed if @fight_speed >= @fight_mspeed
  629.     when :none
  630.       if !attacking?
  631.         @fight_pose = fjumping? ? GALVFIGHT::JUMP_POSE : fight_idle_pose
  632.       end
  633.       fight_slowing
  634.     end
  635.   end
  636.  
  637.   def fight_right_limit; @fight_x >= Graphics.width - 20; end
  638.   def fight_left_limit; @fight_x <= 20; end
  639.  
  640.   def fight_idle_pose
  641.     hp < mhp * 0.25 ? 2 : 0
  642.   end
  643.  
  644.   def fight_slowing
  645.     if moving_right?
  646.       return @fight_speed = 0 if @fight_x >= Graphics.width - 20
  647.       @fight_speed -= [0 + @fight_speed,0.3].min
  648.     elsif moving_left?
  649.       return @fight_speed = 0 if @fight_x <= 20
  650.       @fight_speed += [0 - @fight_speed,0.3].min
  651.     end
  652.   end
  653.  
  654.   def fight_action
  655.     return if attacking? || guarding? || getting_hit?
  656.     bcs = get_combo_skill
  657.     if bcs.nil?
  658.       fight_normal_attack
  659.     else
  660.       fight_combo_skill(bcs)
  661.     end
  662.   end
  663.  
  664.   def get_combo_skill
  665.     @combo_skills.each { |combo|
  666.       if @btn_combo.reverse[0..(combo[0].size - 1)] == combo[0].reverse
  667.         return combo[1]
  668.       end
  669.     }
  670.     return nil
  671.   end
  672.  
  673.   def fight_normal_attack
  674.     return if @fstamina < GALVFIGHT::STAMINA_COST
  675.     @fskill_used = nil
  676.     @fstamina -= GALVFIGHT::STAMINA_COST
  677.     se = @fse_miss
  678.     vol = 80 + rand(20)
  679.     pit = 100 + rand(50)
  680.     RPG::SE.new(se,vol,pit).play
  681.     @combo = @combo.rotate
  682.     @fight_pose = @combo[0]
  683.     @attack_timer = 22
  684.   end
  685.  
  686.   def fight_combo_skill(skill)
  687.     sk = $data_skills[skill]
  688.     return if @fstamina < sk.fcost #fight_normal_attack if @fstamina < sk.fcost
  689.     return if attacking?
  690.     @fstamina -= sk.fcost
  691.     se = sk.fse
  692.     vol = 80 + rand(20)
  693.     pit = 100 + rand(50)
  694.     RPG::SE.new(se,vol,pit).play
  695.     if sk.fproj
  696.       # Create Projectile Here
  697.       @fprojectiles << FightProjectile.new(sk,self)
  698.       self.animation_id = sk.fproj[2]
  699.       @skill_timer = 22
  700.     elsif sk.scope >= 7
  701.       self.animation_id = sk.animation_id
  702.       self.fight_item_apply(self, sk)
  703.       @skill_timer = 22
  704.     else
  705.       @fskill_used = sk
  706.       @attack_timer = 22
  707.     end
  708.     @fight_pose = sk.fpose
  709.   end
  710.  
  711.   def fight_item_apply(user, item)
  712.     @result.clear
  713.     @result.used = item_test(user, item)
  714.     @result.missed = (@result.used && rand >= item_hit(user, item))
  715.     @result.evaded = (!@result.missed && rand < item_eva(user, item))
  716.     if @result.hit?
  717.       @result.critical = (rand < item_cri(user, item))
  718.       damage = fight_damage_value(self, $data_skills[item.id])
  719.       fight_target.do_damage(guarding?,item.id,damage)
  720.       item.effects.each {|effect| item_effect_apply(user, item, effect) }
  721.       item_user_effect(user, item)
  722.     end
  723.   end
  724.  
  725.   def fight_guard
  726.     return if attacking?
  727.     @fight_pose = 1
  728.   end
  729.  
  730.   def fight_jump
  731.     return if fjumping? || in_air?
  732.     @jump = -10 - GALVFIGHT::SIZE / 2
  733.   end
  734.  
  735.   def fjumping?; @jump < 0; end
  736.   def in_air?; @fight_y < GALVFIGHT::Y; end
  737.   def attacking?; @attack_timer > 0 || @skill_timer > 0; end
  738.   def guarding?; @fight_pose == 1; end
  739.   def getting_hit?; @takehit_timer > 0; end
  740.   def moving_right?; @fight_speed > 0; end
  741.   def moving_left?; @fight_speed < 0; end
  742.   def away(amount)
  743.     if fight_x < fight_target.fight_x
  744.       return amount
  745.     else
  746.       return -amount
  747.     end
  748.   end
  749.  
  750.   def move_pose(direction)
  751.     return 1 if @fight_x < fight_target.fight_x
  752.   end
  753.  
  754.   def update_fight
  755.     @takehit_timer -= 1
  756.     update_fight_movement
  757.     update_gravity
  758.     return @fight_pose = 12 if dead?
  759.     return @fight_pose = 3 if getting_hit? && !guarding?
  760.     update_btn_combo
  761.     update_stamina
  762.     update_hit
  763.     @attack_timer -= 1
  764.     @skill_timer -= 1
  765.   end
  766.  
  767.   def update_stamina
  768.     @fstamina += GALVFIGHT::REGEN_RATE if @fstamina < GALVFIGHT::MAX_STAMINA
  769.   end
  770.  
  771.   def update_fight_movement
  772.     if moving_right?
  773.       @fight_x += [@fight_speed,@fight_mspeed].min
  774.     elsif moving_left?
  775.       @fight_x += [@fight_speed,-@fight_mspeed].max
  776.     end
  777.   end
  778.  
  779.   def update_gravity
  780.     if fjumping? || in_air?
  781.       @fight_y += @jump + $game_system.gravity
  782.       @jump += 0.2
  783.     else
  784.       @fight_y = GALVFIGHT::Y
  785.       @jump = 0
  786.     end
  787.   end
  788.  
  789.   def fight_target
  790.     if $game_system.fighters[0].id == @actor_id
  791.       return $game_system.fighters[1]
  792.     else
  793.       return $game_system.fighters[0]
  794.     end
  795.   end
  796.  
  797.   def update_hit
  798.     if @attack_timer == 8
  799.       if make_contact?
  800.         if fight_target.guarding?
  801.           fight_target.animation_id = GALVFIGHT::GUARD_ANIM
  802.           s = @fskill_used ? @fskill_used : $data_skills[GALVFIGHT::ATTACK_SKILL]
  803.           damage = fight_damage_value(self,s)
  804.           do_damage(true,s.id,damage)
  805.           @fskill_used = nil
  806.         else
  807.           if @fskill_used
  808.             anim = @fskill_used.animation_id
  809.             s = @fskill_used
  810.           else
  811.             anim = @fhit_anim
  812.             s = $data_skills[GALVFIGHT::ATTACK_SKILL]
  813.           end
  814.           fight_target.animation_id = anim
  815.           damage = fight_damage_value(self,s)
  816.           do_damage(false,GALVFIGHT::ATTACK_SKILL,damage)
  817.           @fskill_used = nil
  818.         end
  819.       end
  820.     end
  821.   end
  822.  
  823.   def proj_hit(skill)
  824.     if fight_target.guarding?
  825.       fight_target.animation_id = GALVFIGHT::GUARD_ANIM
  826.     else
  827.       fight_target.animation_id = skill.animation_id
  828.     end
  829.     fight_target.fight_item_apply(self,skill)
  830.   end
  831.  
  832.   def do_damage(guard,s_id,damage,proj = false)
  833.     if guard
  834.       damage *= GALVFIGHT::GUARD_DAMAGE
  835.       if damage > 0
  836.         fight_target.fight_speed += away(2) * GALVFIGHT::SIZE
  837.         @fight_speed += fight_target.away(2) * GALVFIGHT::SIZE if proj
  838.       end
  839.     else
  840.       fight_target.fight_speed += away(4) * GALVFIGHT::SIZE if damage > 0
  841.     end
  842.     fight_target.fight_damage(damage)
  843.   end
  844.  
  845.   def fight_damage_value(user, item)
  846.     value = item.damage.eval(user, self, $game_variables)
  847.     value *= item_element_rate(user, item)
  848.     value *= pdr if item.physical?
  849.     value *= mdr if item.magical?
  850.     value *= rec if item.damage.recover?
  851.     value = apply_variance(value, item.damage.variance)
  852.     return value
  853.   end
  854.  
  855.   def fight_damage(damage)
  856.     change_hp(-damage.to_i,true) if SceneManager.scene.phase == 1
  857.     @attack_timer = 0
  858.     @skill_timer = 0
  859.     if damage > 0
  860.       @takehit_timer = 18
  861.       remove_states_by_damage
  862.     end
  863.   end
  864.  
  865.   def reach; @frange * GALVFIGHT::SIZE; end
  866.   def range; (fight_target.fight_x - @fight_x).abs; end
  867.   def in_range_x; (fight_target.fight_x - @fight_x).abs < reach; end
  868.   def in_range_y; ((fight_target.fight_y - @fight_y).abs) * 1.2 < reach ;end
  869.   def near_range_x; ((fight_target.fight_x - @fight_x).abs) / 1.5 < reach; end
  870.  
  871.   def make_contact?
  872.     return true if in_range_x && in_range_y
  873.   end
  874.  
  875.   def reset_fight
  876.     erase_state(death_state_id)
  877.     @hp = 1 if @hp <= 0
  878.     init_fight_vars
  879.   end
  880.  
  881.   def end_match
  882.     @fight_pose = 0 if !dead?
  883.   end
  884.  
  885.   def sta_rate
  886.     @fstamina.to_f / GALVFIGHT::MAX_STAMINA
  887.   end
  888.  
  889.   def update_btn_combo
  890.     @btn_combo = [] if @btn_timer == 0
  891.     @btn_timer -= 1
  892.   end
  893.  
  894.   def add_combo(direction)
  895.     @btn_timer = 20
  896.     @btn_combo << direction
  897.   end
  898. end # Game_Actor < Game_Battler
  899.  
  900.  
  901.     #-----------------#
  902. #---|   GAME_SYSTEM   |---------------------------------------------------------
  903.     #-----------------#
  904.  
  905. class Game_System
  906.   attr_accessor :fighters
  907.   attr_accessor :fmode
  908.   attr_accessor :gravity
  909.   attr_accessor :fbacks
  910.   attr_accessor :fmusic
  911.  
  912.   alias galv_fight_gs_initialize initialize
  913.   def initialize
  914.     galv_fight_gs_initialize
  915.     @gravity = 5
  916.     @fbacks = [GALVFIGHT::BATTLEBACK1,GALVFIGHT::BATTLEBACK2]
  917.     @fmusic = [GALVFIGHT::MUSIC,GALVFIGHT::VICTORY_ME]
  918.     @fmode = 0 #  0 is Player vs AI   1 is Player vs Player
  919.   end
  920. end # Game_System
  921.  
  922.  
  923.     #---------------------#
  924. #---|   SCENE_ACTORDUEL   |-----------------------------------------------------
  925.     #---------------------#
  926.  
  927. class Scene_ActorDuel < Scene_Base
  928.   attr_accessor :spriteset
  929.   attr_reader :phase
  930.   include GFIGHT_AI
  931.  
  932.   def start
  933.     super
  934.     init_fvariables
  935.     determine_fighters
  936.     create_spriteset
  937.     create_windows
  938.   end
  939.  
  940.   def init_fvariables
  941.     $game_variables[GALVFIGHT::VICTOR_VAR] = 0
  942.     @phase = 0
  943.     @ai_move = :none
  944.     @ai_action = false
  945.     @ai_timer = 0
  946.     @bufftimer = 0
  947.     RPG::BGM.new($game_system.fmusic[0],100,100).play
  948.   end
  949.  
  950.   def determine_fighters
  951.     @f1,@f2 = $game_system.fighters
  952.     @f1.fight_x = GALVFIGHT::P1_X
  953.     @f2.fight_x = GALVFIGHT::P2_X
  954.   end
  955.  
  956.   def create_spriteset
  957.     @spriteset = Spriteset_ActorDuel.new
  958.   end
  959.  
  960.   def create_windows
  961.     @hp_window = Window_FightHealth.new
  962.     @info_window = Window_Fight.new
  963.     @command_window = Window_FightCommand.new
  964.     @command_window.deactivate.hide
  965.     @command_window.set_handler(:ok,     method(:on_ok))
  966.     @command_window.set_handler(:cancel, method(:on_cancel))
  967.   end
  968.  
  969.   def on_ok
  970.     @phase = 2
  971.     @command_window.hide.deactivate
  972.     @f1.end_match
  973.     @f2.end_match
  974.   end
  975.  
  976.   def on_cancel
  977.     @command_window.hide.deactivate
  978.   end
  979.  
  980. #--------|  UPDATE
  981.  
  982.   def update
  983.     super
  984.     update_graphics
  985.     case @phase
  986.     when 0
  987.       update_begin
  988.     when 1
  989.       return if @command_window.active
  990.       update_fighter1
  991.       update_fighter2
  992.       update_other
  993.     when 2
  994.       update_common(@f2)
  995.       update_common(@f1)
  996.       @f1.fight_speed = 0
  997.       @f2.fight_speed = 0
  998.       update_end
  999.     end
  1000.   end
  1001.  
  1002.   def update_begin
  1003.     return while @info_window.active
  1004.     @phase = 1
  1005.   end
  1006.  
  1007.   def update_end
  1008.     RPG::ME.new($game_system.fmusic[1],100,100).play if !@end_timer
  1009.     @end_timer ||= 60
  1010.     @victor.fight_pose = 10 if @victor
  1011.     @end_timer -= 1
  1012.     return if @end_timer > 0
  1013.     @info_window.victory(@victor) if @end_timer == 0
  1014.     return while @info_window.active
  1015.     $game_system.fighters.each { |actor| actor.reset_fight }
  1016.     $game_variables[GALVFIGHT::VICTOR_VAR] = @victor ? @victor.id : 0
  1017.     SceneManager.return
  1018.   end
  1019.  
  1020.   def update_graphics
  1021.     @spriteset.update
  1022.   end
  1023.  
  1024.   def update_other
  1025.     if Input.trigger?(:B) && !$game_switches[GALVFIGHT::QUIT_SWITCH]
  1026.       @command_window.show.activate
  1027.     end
  1028.     if @bufftimer >= GALVFIGHT::TURNTIMER
  1029.       @f1.on_turn_end
  1030.       @f2.on_turn_end
  1031.       @f1.remove_buffs_auto
  1032.       @f2.remove_buffs_auto
  1033.       @bufftimer = 0
  1034.     end
  1035.     @bufftimer += 1
  1036.   end
  1037.  
  1038.   def update_fighter1
  1039.     update_f1_movement
  1040.     update_f1_action
  1041.     update_common(@f1)
  1042.   end
  1043.  
  1044.   def update_f1_movement
  1045.     if Input.press?(GALVFIGHT::P1_DOWN)
  1046.       @f1.fight_move(:down)
  1047.       @f1.add_combo(:d) if Input.trigger?(GALVFIGHT::P1_DOWN)
  1048.     elsif Input.trigger?(GALVFIGHT::P1_UP)
  1049.       @f1.fight_move(:up)
  1050.       @f1.add_combo(:u)
  1051.     elsif Input.press?(GALVFIGHT::P1_LEFT)
  1052.       @f1.fight_move(:left)
  1053.       @f1.add_combo(get_back_dir(@f1)) if Input.trigger?(GALVFIGHT::P1_LEFT)
  1054.     elsif Input.press?(GALVFIGHT::P1_RIGHT)
  1055.       @f1.fight_move(:right)
  1056.       @f1.add_combo(get_forward_dir(@f1)) if Input.trigger?(GALVFIGHT::P1_RIGHT)
  1057.     else
  1058.       @f1.fight_move(:none)
  1059.     end
  1060.   end
  1061.  
  1062.   def get_back_dir(player)
  1063.     return player.fight_x < player.fight_target.fight_x ? :l : :r
  1064.   end
  1065.  
  1066.   def get_forward_dir(player)
  1067.     return player.fight_x < player.fight_target.fight_x ? :r : :l
  1068.   end
  1069.  
  1070.   def update_f1_action
  1071.     @f1.fight_action if Input.trigger?(GALVFIGHT::P1_ACTION) &&
  1072.       !@f1.attacking? && !@f1.guarding?
  1073.     if @f2.dead?
  1074.       @phase = 2
  1075.       @victor = @f1
  1076.     end
  1077.   end
  1078.  
  1079.   def update_fighter2
  1080.     if $game_system.fmode == 1
  1081.       update_f2_movement
  1082.       update_f2_action
  1083.     else
  1084.       update_f2_ai
  1085.     end
  1086.     update_common(@f2)
  1087.   end
  1088.  
  1089.   def update_f2_movement
  1090.     if Input.press?(GALVFIGHT::P2_DOWN)
  1091.       @f2.fight_move(:down)
  1092.       @f2.add_combo(:d) if Input.trigger?(GALVFIGHT::P2_DOWN)
  1093.     elsif Input.trigger?(GALVFIGHT::P2_UP)
  1094.       @f2.fight_move(:up)
  1095.       @f2.add_combo(:u)
  1096.     elsif Input.press?(GALVFIGHT::P2_LEFT)
  1097.       @f2.fight_move(:left)
  1098.       @f2.add_combo(get_back_dir(@f2)) if Input.trigger?(GALVFIGHT::P2_LEFT)
  1099.     elsif Input.press?(GALVFIGHT::P2_RIGHT)
  1100.       @f2.fight_move(:right)
  1101.       @f2.add_combo(get_forward_dir(@f2)) if Input.trigger?(GALVFIGHT::P2_RIGHT)
  1102.     else
  1103.       @f2.fight_move(:none)
  1104.     end
  1105.   end
  1106.  
  1107.   def update_f2_action
  1108.     @f2.fight_action if Input.trigger?(GALVFIGHT::P2_ACTION) && !@f2.attacking? && !@f2.guarding?
  1109.     if @f1.dead?
  1110.       @phase = 2
  1111.       @victor = @f2
  1112.     end
  1113.   end
  1114.  
  1115.   def update_common(fighter)
  1116.     fighter.update_fight
  1117.   end
  1118.  
  1119. #--------|  DESTROY
  1120.  
  1121.   def dispose_spriteset
  1122.     @spriteset.dispose
  1123.   end
  1124.  
  1125.   def terminate
  1126.     super
  1127.     dispose_spriteset
  1128.     @f1.on_battle_end
  1129.     @f2.on_battle_end
  1130.   end
  1131. end # Scene_Kombat < Scene_Base
  1132.  
  1133.  
  1134.     #-------------------------#
  1135. #---|   SPRITESET_ACTORDUEL   |-------------------------------------------------
  1136.     #-------------------------#
  1137.  
  1138. class Spriteset_ActorDuel
  1139.   attr_accessor :viewport3
  1140.  
  1141.   def initialize
  1142.     create_viewports
  1143.     create_battleback1
  1144.     create_battleback2
  1145.     create_battleback3
  1146.     create_fighters
  1147.     create_face1
  1148.     create_face2
  1149.     create_bars
  1150.     update
  1151.   end
  1152.  
  1153. #-------- |  CREATE STUFF
  1154.  
  1155.   def create_viewports
  1156.     @viewport1 = Viewport.new
  1157.     @viewport2 = Viewport.new
  1158.     @viewport3 = Viewport.new
  1159.     @viewport4 = Viewport.new
  1160.     @viewport1.z = 20
  1161.     @viewport2.z = 50
  1162.     @viewport3.z = 250
  1163.     @viewport4.z = 25
  1164.   end
  1165.  
  1166.   def create_battleback1
  1167.     return if !$game_system.fbacks[0]
  1168.     @back1_sprite = Sprite.new(@viewport1)
  1169.     @back1_sprite.bitmap = Cache.battleback1($game_system.fbacks[0])
  1170.     @back1_sprite.z = 1
  1171.     center_sprite(@back1_sprite)
  1172.   end
  1173.  
  1174.   def create_battleback2
  1175.     return if !$game_system.fbacks[1]
  1176.     @back2_sprite = Sprite.new(@viewport4)
  1177.     @back2_sprite.bitmap = Cache.battleback2($game_system.fbacks[1])
  1178.     @back2_sprite.z = 2
  1179.     center_sprite(@back2_sprite)
  1180.   end
  1181.  
  1182.   def create_battleback3
  1183.     return if !$game_system.fbacks[1]
  1184.     @back3_sprite = Sprite.new(@viewport4)
  1185.     @back3_sprite.bitmap = Cache.battleback2($game_system.fbacks[2])
  1186.     @back3_sprite.z = 1
  1187.     center_sprite(@back3_sprite)
  1188.   end
  1189.  
  1190.  
  1191.   def create_fighters
  1192.     @fighters = []
  1193.     @shadows = []
  1194.     $game_system.fighters.each { |f|
  1195.       @shadows << Sprite_FightShadow.new(@viewport2,f)
  1196.       @fighters << Sprite_Fighter.new(@viewport2,f)
  1197.     }
  1198.   end
  1199.  
  1200.   def create_face1
  1201.     face_index = $game_system.fighters[0].face_index
  1202.     @face1 = Sprite.new(@viewport2)
  1203.     @face1.bitmap = Cache.face($game_system.fighters[0].face_name)
  1204.     rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96)
  1205.     @face1.src_rect.set(rect)
  1206.   end
  1207.  
  1208.   def create_face2
  1209.     face_index = $game_system.fighters[1].face_index
  1210.     @face2 = Sprite.new(@viewport2)
  1211.     @face2.bitmap = Cache.face($game_system.fighters[1].face_name)
  1212.     rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96)
  1213.     @face2.src_rect.set(rect)
  1214.     @face2.x = Graphics.width - 96
  1215.     @face2.mirror = false
  1216.   end
  1217.  
  1218.   def create_bars
  1219.     @bar1 = Sprite.new(@viewport3)
  1220.     @bar1.bitmap = Cache.system("kombat_bar") rescue Cache.system("")
  1221.     @bar2 = Sprite.new(@viewport3)
  1222.     @bar2.bitmap = Cache.system("kombat_bar") rescue Cache.system("")
  1223.     @bar2.x = Graphics.width - @bar2.bitmap.width
  1224.     @bar2.mirror = true
  1225.   end
  1226.  
  1227. #-------- |  UPDATE STUFF
  1228.  
  1229.   def update
  1230.     @fighters.each { |s| s.update }
  1231.     @shadows.each { |s| s.update }
  1232.     @viewport1.update
  1233.     @viewport2.update
  1234.     @viewport3.update
  1235.     @viewport4.update
  1236.     update_projectiles
  1237.   end
  1238.  
  1239.   def update_projectiles
  1240.     $game_system.fighters.each { |f|
  1241.       f.fprojectiles.each_with_index { |p,i|
  1242.         if p.finished?
  1243.           p.dispose if !p.nil?
  1244.           p = nil
  1245.         else
  1246.           p.update
  1247.         end
  1248.       }
  1249.       f.fprojectiles.compact!
  1250.     }
  1251.   end
  1252.  
  1253. #-------- |  DESTROY STUFF
  1254.  
  1255.   def dispose
  1256.     dispose_viewports
  1257.     dispose_fighters
  1258.     dispose_background
  1259.     dispose_faces
  1260.     dispose_projectiles
  1261.   end
  1262.  
  1263.   def dispose_viewports
  1264.     @viewport1.dispose
  1265.     @viewport2.dispose
  1266.     @viewport3.dispose
  1267.     @viewport4.dispose
  1268.   end
  1269.  
  1270.   def dispose_fighters
  1271.     @fighters.each { |s| s.dispose }
  1272.     @shadows.each { |s| s.dispose }
  1273.     @bar1.dispose
  1274.     @bar2.dispose
  1275.   end
  1276.  
  1277.   def dispose_background
  1278.     @back1_sprite.dispose if @back1_sprite
  1279.     @back2_sprite.dispose if @back2_sprite
  1280.     @back3_sprite.dispose if @back3_sprite
  1281.   end
  1282.  
  1283.   def dispose_faces
  1284.     @face1.dispose
  1285.     @face2.dispose
  1286.   end
  1287.  
  1288.   def dispose_projectiles
  1289.     $game_system.fighters.each { |f|
  1290.       f.fprojectiles.each { |p| p.dispose }
  1291.     }
  1292.   end
  1293.  
  1294.   def center_sprite(sprite)
  1295.     sprite.ox = sprite.bitmap.width / 2
  1296.     sprite.oy = sprite.bitmap.height / 2
  1297.     sprite.x = Graphics.width / 2
  1298.     sprite.y = Graphics.height / 2
  1299.   end
  1300. end # Spriteset_ActorDuel
  1301.  
  1302.  
  1303.     #-------------------#
  1304. #---|   SPRITE_FIGHTER  |-------------------------------------------------------
  1305.     #-------------------#
  1306.  
  1307. class Sprite_Fighter < Sprite_Battler
  1308.   def initialize(viewport, battler = nil)
  1309.     super(viewport,battler)
  1310.     init_fvariables
  1311.   end
  1312.  
  1313.   def init_fvariables
  1314.     @pattern = 0
  1315.     @speed_timer = 0
  1316.     @pose = 0
  1317.     if $game_system.fighters[0].id == @battler.id
  1318.       player = 0; opponent = 1
  1319.     else
  1320.       player = 1; opponent = 0
  1321.     end
  1322.     @player = $game_system.fighters[player]
  1323.     @opponent = $game_system.fighters[opponent]
  1324.   end
  1325.  
  1326.   def update
  1327.     if @battler.fight_sprite
  1328.       update_bitmap
  1329.       update_pose
  1330.       update_src_rect
  1331.       update_anim
  1332.       update_position
  1333.       update_facing
  1334.     end
  1335.     super
  1336.   end
  1337.  
  1338.   def update_bitmap
  1339.     new_bitmap = Cache.battler(@battler.fight_sprite,
  1340.       @battler.battler_hue)
  1341.     if bitmap != new_bitmap
  1342.       self.bitmap = new_bitmap
  1343.       spritesheet_normal
  1344.       init_visibility
  1345.       self.zoom_x = GALVFIGHT::SIZE
  1346.       self.zoom_y = GALVFIGHT::SIZE
  1347.     end
  1348.   end
  1349.  
  1350.   def spritesheet_normal
  1351.     @cw = bitmap.width / GALVFIGHT::COLS
  1352.     @ch = bitmap.height / GALVFIGHT::ROWS
  1353.     self.ox = @cw / 2
  1354.     self.oy = @ch
  1355.   end
  1356.  
  1357.   def update_pose
  1358.     if @pose != @battler.fight_pose
  1359.       @pattern = 0
  1360.       @pose = @battler.fight_pose
  1361.     end
  1362.   end
  1363.  
  1364.   def update_src_rect
  1365.     if @pattern >= GALVFIGHT::COLS
  1366.       if @battler.fight_pose == 10 && @battler.fvicpose
  1367.         @pattern = GALVFIGHT::COLS - 1
  1368.       else
  1369.         @pattern = 0
  1370.       end
  1371.     end
  1372.     sx = @pattern * @cw
  1373.     sy = @battler.fight_pose * @ch
  1374.     self.src_rect.set(sx, sy, @cw, @ch)
  1375.   end
  1376.  
  1377.   def update_origin;end
  1378.  
  1379.   def update_anim
  1380.     @speed_timer += 1
  1381.     if @speed_timer > 6
  1382.       @pattern += 1
  1383.       @speed_timer = 0
  1384.     end
  1385.   end
  1386.  
  1387.   def update_facing
  1388.     self.mirror = @player.fight_x > @opponent.fight_x ? false : true
  1389.   end
  1390.  
  1391.   def update_position
  1392.     self.x = @battler.fight_x
  1393.     self.y = @battler.fight_y
  1394.   end
  1395.  
  1396.   def make_animation_sprites
  1397.     @ani_sprites = []
  1398.     if !@@ani_spr_checker.include?(@animation)
  1399.       16.times do
  1400.         sprite = ::Sprite.new(viewport)
  1401.         sprite.visible = false
  1402.         @ani_sprites.push(sprite)
  1403.       end
  1404.       if @animation.position == 3
  1405.         @@ani_spr_checker.push(@animation)
  1406.       end
  1407.     end
  1408.     @ani_duplicated = @@ani_checker.include?(@animation)
  1409.     if !@ani_duplicated && @animation.position == 3
  1410.       @@ani_checker.push(@animation)
  1411.     end
  1412.   end
  1413. end # Sprite_Fighter < Sprite_Battler
  1414.  
  1415.  
  1416.     #------------------#
  1417. #---|   SPRITE_SHADOW  |--------------------------------------------------------
  1418.     #------------------#
  1419.  
  1420. class Sprite_FightShadow < Sprite
  1421.   def initialize(viewport, player)
  1422.     super(viewport)
  1423.     @player = player
  1424.     create_shadow
  1425.   end
  1426.  
  1427.   def dispose
  1428.     bitmap.dispose if bitmap
  1429.     super
  1430.   end
  1431.  
  1432.   def update
  1433.     super
  1434.     update_position
  1435.   end
  1436.  
  1437.   def create_shadow
  1438.     self.bitmap = Cache.system("Shadow")
  1439.     self.ox = self.bitmap.width / 2
  1440.     self.oy = self.bitmap.height
  1441.     self.z = 0
  1442.     self.zoom_x = GALVFIGHT::SIZE
  1443.     self.zoom_y = GALVFIGHT::SIZE
  1444.   end
  1445.  
  1446.   def update_position
  1447.     self.x = @player.fight_x
  1448.     self.y = GALVFIGHT::Y
  1449.   end
  1450. end # Sprite_FightShadow < Sprite
  1451.  
  1452.  
  1453.     #-----------------------#
  1454. #---|   WINDOW_FIGHTHEALTH  |---------------------------------------------------
  1455.     #-----------------------#
  1456.  
  1457. class Window_FightHealth < Window_Base
  1458.   def initialize
  1459.     super(0, 0, Graphics.width, 140)
  1460.     self.opacity = 0
  1461.     refresh
  1462.   end
  1463.  
  1464.   def player; $game_system.fighters; end
  1465.    
  1466.   def update
  1467.     super
  1468.     refresh
  1469.   end
  1470.  
  1471.   def refresh
  1472.     contents.clear
  1473.     contents.font.name = GALVFIGHT::FONT
  1474.     draw_player1
  1475.     draw_player2
  1476.   end
  1477.  
  1478.   def draw_player1
  1479.     pl = player[0]
  1480.     draw_hp(pl, 100, 15, false)
  1481.     draw_stamina(pl, 100, 40, false)
  1482.     draw_text(100,0,100,line_height,pl.name,0)
  1483.     draw_actor_icons(pl, 100, 65, 240)
  1484.   end
  1485.  
  1486.   def draw_player2
  1487.     pl = player[1]
  1488.     draw_hp(pl, contents.width - 224, 15, true)
  1489.     draw_stamina(pl, contents.width - 224, 40, true)
  1490.     draw_text(contents.width - 200,0,100,line_height,pl.name,2)
  1491.     draw_actor_icons(pl, contents.width - 224, 65, 240)
  1492.   end
  1493.  
  1494.   def draw_hp(actor, x, y, r)
  1495.     draw_gauge(x, y, 124, actor.hp_rate, hp_gauge_color1, hp_gauge_color2, r, 12)
  1496.   end
  1497.  
  1498.   def draw_stamina(actor, x, y, r)
  1499.     draw_gauge(x, y, 124, actor.sta_rate, sta_gauge_color1, sta_gauge_color2, r, 6)
  1500.   end
  1501.  
  1502.   def draw_gauge(x, y, width, rate, color1, color2, reverse, height)
  1503.     fill_w = (width * rate).to_i
  1504.     gauge_y = y + line_height - 8
  1505.     contents.fill_rect(x, gauge_y, width, height, gauge_back_color)
  1506.     if reverse
  1507.       contents.gradient_fill_rect(x + width - fill_w, gauge_y, fill_w, height,
  1508.         color1, color2)
  1509.     else
  1510.       contents.gradient_fill_rect(x, gauge_y, fill_w, height, color1, color2)
  1511.     end
  1512.   end
  1513. end # Window_FightHealth < Window_Base
  1514.  
  1515.  
  1516.     #-----------------#
  1517. #---|   WINDOW_FIGHT  |---------------------------------------------------------
  1518.     #-----------------#
  1519.  
  1520. class Window_Fight < Window_Base
  1521.   attr_accessor :phase
  1522.   attr_accessor :victor
  1523.  
  1524.   def initialize
  1525.     super(0, 0, Graphics.width, Graphics.height)
  1526.     self.opacity = 0
  1527.     @phase = 0
  1528.     @timer = 0
  1529.   end
  1530.  
  1531.   def update
  1532.     case @phase
  1533.     when 0
  1534.       contents.clear
  1535.       contents.font.name = GALVFIGHT::FONT
  1536.       contents.font.size += 1
  1537.       draw_text(0,0,width,height,GALVFIGHT::START1,1)
  1538.     when 2
  1539.       contents.clear
  1540.       contents.font.name = GALVFIGHT::FONT
  1541.       contents.font.size = 80
  1542.       draw_text(0,0,width,height,GALVFIGHT::START2,1)
  1543.     when 3
  1544.       contents.clear
  1545.       deactivate
  1546.     when 4
  1547.       contents.clear
  1548.       contents.font.size = 60
  1549.       if @victor
  1550.         contents.font.name = GALVFIGHT::FONT
  1551.         txt = @victor.name.upcase + GALVFIGHT::WINS
  1552.         draw_text(0,0,width,height,txt,1)
  1553.       else
  1554.         contents.font.name = GALVFIGHT::FONT
  1555.         draw_text(0,0,width,height,GALVFIGHT::NOWINNER,1)
  1556.       end
  1557.     when 5
  1558.       contents.clear
  1559.       deactivate
  1560.     end
  1561.     @timer += 1
  1562.     @phase = 1 if @timer == 40
  1563.     @phase = 2 if @timer == 100
  1564.     @phase = 3 if @timer == 130
  1565.     @phase = 5 if @timer == 300
  1566.   end
  1567.  
  1568.   def victory(victor)
  1569.     @victor = victor
  1570.     @phase = 4
  1571.     @timer = 150
  1572.     activate
  1573.   end
  1574. end # Window_Fight < Window_Base
  1575.  
  1576.  
  1577.     #------------------------#
  1578. #---|   WINDOW_FIGHTCOMMAND  |--------------------------------------------------
  1579.     #------------------------#
  1580.  
  1581. class Window_FightCommand < Window_Command
  1582.   def initialize
  1583.     super(Graphics.width / 2 - window_width / 2, Graphics.height / 2 - 80)
  1584.   end
  1585.  
  1586.   def window_width; return 160; end
  1587.   def visible_line_number; return 2; end
  1588.  
  1589.   def make_command_list
  1590.     add_command(GALVFIGHT::CMD_QUIT, :quit, true)
  1591.     add_command(GALVFIGHT::CMD_CANCEL, :cancel, true)
  1592.   end
  1593.  
  1594.   def update; super; end
  1595.   def select_last; select(0); end
  1596. end # Window_FightCommand < Window_Command
  1597.  
  1598.  
  1599.     #---------------------------#
  1600. #---|   SPRITE_FIGHTPROJECTILE  |-----------------------------------------------
  1601.     #---------------------------#
  1602.  
  1603. class FightProjectile < Sprite_Base
  1604.   attr_accessor :skill
  1605.   def initialize(skill, owner)
  1606.     @owner = owner
  1607.     @target = owner.fight_target
  1608.     @skill = skill
  1609.     super(SceneManager.scene.spriteset.viewport3)
  1610.     init_fvariables
  1611.     create_bitmap
  1612.   end
  1613.  
  1614.   def init_fvariables
  1615.     self.x = @owner.fight_x
  1616.     self.y = @owner.fight_y
  1617.     self.opacity = 0
  1618.     @pattern = 0
  1619.     @pose = @skill.fproj[0]
  1620.     @speed_timer = 0
  1621.     @range_limit = @skill.fproj[3]
  1622.     @range = 0
  1623.     @reach = @skill.fproj[4]
  1624.   end
  1625.  
  1626.   def update
  1627.     update_src_rect
  1628.     update_anim
  1629.     update_position
  1630.     update_hit
  1631.     super
  1632.   end
  1633.  
  1634.   def create_bitmap
  1635.     self.bitmap = Cache.battler(GALVFIGHT::SKILLIMAGE, 0)
  1636.     @cw = bitmap.width / GALVFIGHT::SKILLCOLS
  1637.     @ch = bitmap.height / GALVFIGHT::SKILLROWS
  1638.     self.ox = @cw / 2
  1639.     self.oy = @ch
  1640.     self.mirror = @owner.fight_x > @target.fight_x ? false : true
  1641.   end
  1642.  
  1643.   def update_src_rect
  1644.     if @pattern >= GALVFIGHT::SKILLCOLS
  1645.       @pattern = 0
  1646.     end
  1647.     sx = @pattern * @cw
  1648.     sy = @pose * @ch
  1649.     self.src_rect.set(sx, sy, @cw, @ch)
  1650.   end
  1651.  
  1652.   def update_anim
  1653.     @speed_timer += 1
  1654.     if @speed_timer > 6
  1655.       @pattern += 1
  1656.       @speed_timer = 0
  1657.     end
  1658.   end
  1659.  
  1660.   def update_position
  1661.     self.x += self.mirror ? @skill.fproj[1] : -@skill.fproj[1]
  1662.     self.opacity += 20
  1663.     @range += 1
  1664.   end
  1665.  
  1666.   def make_animation_sprites
  1667.     @ani_sprites = []
  1668.     if !@@ani_spr_checker.include?(@animation)
  1669.       16.times do
  1670.         sprite = ::Sprite.new(viewport)
  1671.         sprite.visible = false
  1672.         @ani_sprites.push(sprite)
  1673.       end
  1674.       if @animation.position == 3
  1675.         @@ani_spr_checker.push(@animation)
  1676.       end
  1677.     end
  1678.     @ani_duplicated = @@ani_checker.include?(@animation)
  1679.     if !@ani_duplicated && @animation.position == 3
  1680.       @@ani_checker.push(@animation)
  1681.     end
  1682.   end
  1683.  
  1684.   def dispose; super; end
  1685.  
  1686.   def finished?; @range >= @range_limit; end
  1687.  
  1688.   def in_range_x; (@target.fight_x - self.x).abs < @reach; end
  1689.   def in_range_y; (@target.fight_y - self.y).abs < @reach + 60; end
  1690.  
  1691.   def make_contact?; return true if in_range_x && in_range_y; end
  1692.    
  1693.   def update_hit
  1694.     if make_contact?
  1695.       @owner.proj_hit(@skill)
  1696.       @range = @range_limit
  1697.     end
  1698.   end
  1699. end # FightProjectile < Sprite_Base
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement