Save-Point

Full Version: Save-Point
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Board Message
Sorry, you do not have permission to access this resource.
Save-Point - Atoa ACBS Regeneration while defend

Save-Point

Full Version: Atoa ACBS Regeneration while defend
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Im using RPG XP and the battle system of Atoa (Link below) For those who dont know what kind of battle system it is: Its a side view battle system.
I want the players to recover 2% of the maximal HP and SP back when they defend. I found no addon on the actual script that has that kind of script. Thats why Im asking here.
I hope you got my point :))) If you defend in the Battlesystem you only get 1/2 of the damage, but there's no recovering of HP or SP.
I was able to make HP recovery work fine after his turn, even when using the ATB or CTB scripts.
But oddly, SP recovery was a bit ... muffled. Pops wouldn't show and it was extremely... haphazard.
So here's HP recovery.
Code:
#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
#  This class deals with battlers. It's used as a superclass for the Game_Actor
#  and Game_Enemy classes.
#==============================================================================

class Game_Battler
  #--------------------------------------------------------------------------
  # * Applying Recovery HP Effects
  #     attacker : battler
  #--------------------------------------------------------------------------
  def recover_effect_hp
    # Calculate recovery
    recovery = (self.maxhp / 50).to_i
    # Erase recovery if HP already maxed
    recovery = 0 if (recovery+ self.hp) > self.maxhp
    # Set damage sprite to negative damage (aka reovery)
    self.damage = -recovery
    # If recovery value is positive
    if recovery > 0
      # Substract damage from HP
      self.hp += recovery
    # When missing
    else
      # Set damage to nil
      self.damage = nil
    end
    # End Method
    return true
  end
end



#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#==============================================================================

class Scene_Battle
  #--------------------------------------------------------------------------
  # * Update battler phase 5 (part 4)
  #     battler : active battler
  #--------------------------------------------------------------------------
  alias recover_step5_part4 step5_part4
  def step5_part4(battler)
    recover_step5_part4(battler)
    recover_hpsp_system(battler)
  end
  #--------------------------------------------------------------------------
  # * Update HP and SP Recovery
  #     battler : active battler
  #--------------------------------------------------------------------------
  def recover_hpsp_system(battler)
    return unless battler.current_action.kind  == 0   # Exit unless Normal
    return unless battler.current_action.basic == 1   # Exit unless Defend
    battler.recover_effect_hp                         # Recover HP
    battler.damage_pop = true                         # Force Pop
  end
end
Before you ask, duplicating the 'recover_effect_hp' method and changing it for SP didn't do the trick. Something a bit weird there.
Thank you very much so far. Do I just need to put this above main?

And btw. there's a little bug. If someone defends, it should exactly add 2% of the maxium HP but it adds twice as 2% while on the battlescreen it is shown as 2%.

For example: a player has 9999 HP. if he defends it should add 199. In the battlescreen the HP got by defending is shown as 199 while it is calculated as twice as much.
Sorry for the delay. I had a bit of studying to perform on this, seeing some methods rewritten which I was previously familiar.

Did you know that the original RPG::Sprite.damage method did not actively alter your battler's HP (or SP) when it was called? Probably... yes. Did you know that Atoa changed the system so just performing the RPG::Sprite damage pop now ACTIVELY changed your HP (or SP) now? Probably... nope! That's why there was double damage inflicted using basic routines that erased from self.hp while later applying self.damage. Way to go.... :P

Meanwhile, you cannot have HP and SP damage pops from occurring simultaneously. It's because one damage pop would override the other. So I had to make HP recovery 'pop' in one section of the battlesystem while the SP recovery would 'pop' in another.

Oh, and there are some minor adjustment values you may like. Particularly, if you wanted to make HP do 2% recovery and SP just 1% Grinning

Code:
#==============================================================================
# Atoa HP/SP Defending Recovery
# based on the works by Atoa / Victor Sant
# system suggested by Djigit of Save-Point.org
#
#------------------------------------------------------------------------------
#    by DerVVulfman
#    version 1.1
#    12-11-2014
#    RGSS / RMXP - Involves Rewrite of Atoa's RPG::Sprite.damage method
#    Requires:  Atoa's Custom Battle System
#
#------------------------------------------------------------------------------
#
#  INTRODUCTION:
#
#  This system lets battlers recover health after a turn if they so chose
#  to defend rather than perform  an attack or valid action.   Percentage
#  values and SP damage pop location can be adjusted in the below module.
#
#==============================================================================


module Atoa  
  
  # HANDLING OF CUSTOM PERCENTAGES
  #
    HP_Defend_Recovery_Adjust = 2     # Percentage of MaxHP recovered
    SP_Defend_Recovery_Adjust = 1     # Percentage of MaxSP recovered
  
  # ADJUSTING SP DAMAGE POPS
  #
    Dmg_SP_X_Adjust           = 48    # X Position adjust for SP damage pops
    
end
  
  
  
#==============================================================================
# ** RPG::Sprite
#------------------------------------------------------------------------------
# Class that manages Sprites exhibition
#==============================================================================

class RPG::Sprite < ::Sprite
  #--------------------------------------------------------------------------
  # * Include Settings Module
  #--------------------------------------------------------------------------
  include Atoa  
  #--------------------------------------------------------------------------
  # * Set Damage Pop
  #     value     : Damage value
  #     critical  : Critical flag
  #     sp_damage : SP Damage flag
  #--------------------------------------------------------------------------
  def damage(value, critical, sp_damage = nil)
    dispose_damage(0...@_damage_durations.size)
    @_damage_sprites = []
    damage_string = value.numeric? ? value.abs.to_s : value.to_s
    @battler.apply_damage(value, sp_damage)
    for i in 0...damage_string.size
      letter = damage_string[i..i]
      if Damage_Sprite
        if value.numeric? and value < 0
          extension = Hp_Rec_String
          extension = Sp_Rec_String if sp_damage
        else
          extension = Sp_Dmg_String  if sp_damage
          extension = Crt_Dmg_String if critical
          extension = Mss_Txt_String if damage_string == Miss_Message
        end
        begin
          bitmap = RPG::Cache.digits(letter + extension)
        rescue
          bitmap = RPG::Cache.digits(letter)
        end
      else
        if value.numeric? and value < 0
          @_damage_color = [Hp_Rec_Color[0],Hp_Rec_Color[1],Hp_Rec_Color[2]]
          @_damage_color = [Sp_Rec_Color[0],Sp_Rec_Color[1],Sp_Rec_Color[2]] if sp_damage
        else
          @_damage_color = [Hp_Dmg_Color[0],Hp_Dmg_Color[1],Hp_Dmg_Color[2]]
          @_damage_color = [Sp_Dmg_Color[0],Sp_Dmg_Color[1],Sp_Dmg_Color[2]] if sp_damage
          @_damage_color = [Crt_Dmg_Color[0],Crt_Dmg_Color[1],Crt_Dmg_Color[2]] if critical
          @_damage_color = [Mss_Txt_Color[0],Mss_Txt_Color[1],Mss_Txt_Color[2]] if damage_string == Miss_Message
        end
        bitmap = Bitmap.new(160, 48)
        bitmap.font.name = Damage_Font
        bitmap.font.size = Dmg_Font_Size
        bitmap.font.color.set(0, 0, 0)
        bitmap.draw_text(-1, 12-1,160, 36, letter, 1)
        bitmap.draw_text(+1, 12-1,160, 36, letter, 1)
        bitmap.draw_text(-1, 12+1,160, 36, letter, 1)
        bitmap.draw_text(+1, 12+1,160, 36, letter, 1)
        bitmap.font.color.set(*@_damage_color)
        bitmap.draw_text(0, 12,160, 36, letter, 1)
        if critical and Critic_Text and i == 0
          x_pop = (damage_string.size - 1) * (Dmg_Space / 2)
          bitmap.font.size = ((Dmg_Font_Size * 2) / 3).to_i
          bitmap.font.color.set(0, 0, 0)
          bitmap.draw_text(-1 + x_pop, -1, 160, 20, Crt_Message, 1)
          bitmap.draw_text(+1 + x_pop, -1, 160, 20, Crt_Message, 1)
          bitmap.draw_text(-1 + x_pop, +1, 160, 20, Crt_Message, 1)
          bitmap.draw_text(+1 + x_pop, +1, 160, 20, Crt_Message, 1)
          color = [Crt_Txt_Color[0],Crt_Txt_Color[1],Crt_Txt_Color[2]] if critical
          bitmap.font.color.set(*color) if critical
          bitmap.draw_text(0 + x_pop, 0, 160, 20, Crt_Message, 1)
        end
      end
      if critical and Critic_Flash and value.numeric?
        $game_screen.start_flash(Color.new(255, 255, 255, 255),10)
      end
      dmg_delay = Multi_Pop ? i : 1
      dmg_adjust = Damage_Sprite ? 32 : 96
      @_damage_sprites[i] = ::Sprite.new(self.viewport)
      @_damage_sprites[i].bitmap = bitmap
      @_damage_sprites[i].ox = dmg_adjust
      @_damage_sprites[i].oy = 20
      @_damage_sprites[i].x = self.x + 32 + Dmg_X_Adjust + i * Dmg_Space - (damage_string.size * 8)
      @_damage_sprites[i].x += Dmg_SP_X_Adjust if sp_damage == true
      @_damage_sprites[i].y = self.y + Dmg_Y_Adjust - self.oy / 3
      @_damage_sprites[i].z = Dmg_Duration + 3000 + dmg_delay * 2
      @_damage_sprites[i].opacity = 0
    end
  end
end



#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
#  This class deals with battlers. It's used as a superclass for the Game_Actor
#  and Game_Enemy classes.
#==============================================================================

class Game_Battler
  #--------------------------------------------------------------------------
  # * Include Settings Module
  #--------------------------------------------------------------------------
  include Atoa  
  #--------------------------------------------------------------------------
  # * Remove/Clear Flags
  #--------------------------------------------------------------------------
  def recover_effect_clear
    self.damage     = nil
    self.critical   = false
    self.sp_damage  = false
    self.damage_pop = nil
  end  
  #--------------------------------------------------------------------------
  # * Applying Recovery HP Effects
  #     attacker : battler
  #--------------------------------------------------------------------------
  def recover_effect_hp
    return if HP_Defend_Recovery_Adjust.nil?            # End if nil config
    return if HP_Defend_Recovery_Adjust <= 0            # End if invalid config
    recover_effect_clear                                # Clear Data
    adjust    = 100/HP_Defend_Recovery_Adjust           # Calculate Adjustment
    adjust    = 1 if adjust < 1                         # Ensure no div/0
    recovery  = (self.maxhp / adjust).to_i              # Calculate Recovery
    recovery  = 0 if (recovery + self.hp) > self.maxhp  # Erase if Maxed Out
    self.damage = (recovery > 0) ? -recovery : nil      # Set Damage Sprite
    self.damage_pop = true if recovery > 0              # Set Pop if Valid
    return true                                         # End Method
  end
  #--------------------------------------------------------------------------
  # * Applying Recovery HP Effects
  #     attacker : battler
  #--------------------------------------------------------------------------
  def recover_effect_sp
    return if SP_Defend_Recovery_Adjust.nil?            # End if nil config
    return if SP_Defend_Recovery_Adjust <= 0            # End if invalid config
    recover_effect_clear                                # Clear Data
    adjust    = 100/SP_Defend_Recovery_Adjust           # Calculate Adjustment
    adjust    = 1 if adjust < 1                         # Ensure no div/0
    recovery  = (self.maxsp / adjust).to_i              # Calculate Recovery
    recovery  = 0 if (recovery + self.sp) > self.maxsp  # Erase if Maxed Out
    self.damage = (recovery > 0) ? -recovery : nil      # Set Damage Sprite
    self.sp_damage  = true                              # Set as SP damage
    self.damage_pop = true if recovery > 0              # Set Pop if Valid
    return true                                         # End Method
  end
end


#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#==============================================================================

class Scene_Battle
  #--------------------------------------------------------------------------
  # * Update battler phase 5 (part 1)
  #     battler : active battler
  #--------------------------------------------------------------------------
  alias recover_step5_part1 step5_part1
  def step5_part1(battler)
    recover_hp_system(battler)                        # Perform HP Recovery
    recover_step5_part1(battler)                      # Perform Original Call
  end
  #--------------------------------------------------------------------------
  # * Update battler phase 5 (part 4)
  #     battler : active battler
  #--------------------------------------------------------------------------
  alias recover_step5_part4 step5_part4
  def step5_part4(battler)
    recover_sp_system(battler)                        # Perform SP Recovery
    @status_window.refresh                            # Refresh Status
    recover_step5_part4(battler)                      # Perform Original Call
  end  
  #--------------------------------------------------------------------------
  # * Update HP Recovery
  #     battler : active battler
  #--------------------------------------------------------------------------
  def recover_hp_system(battler)
    return unless battler.current_action.kind  == 0   # Exit unless Normal
    return unless battler.current_action.basic == 1   # Exit unless Defend
    battler.recover_effect_hp                         # Recover HP
  end
  #--------------------------------------------------------------------------
  # * Update SP Recovery
  #     battler : active battler
  #--------------------------------------------------------------------------
  def recover_sp_system(battler)
    return unless battler.current_action.kind  == 0   # Exit unless Normal
    return unless battler.current_action.basic == 1   # Exit unless Defend
    battler.recover_effect_sp                         # Recover SP
  end  
end

EDIT: Oops. Forgot to add that it was suggested by Djigit of Save-Point.org. Fixed in the header. Winking