Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Custom Battle Algorithm

In my project, my characters will have low stats (5-20), and I need to customize the battle algorithms in order to be able to have this. Now, I played around with attack_effect so far, and I've come up with this:
Code:
  def attack_effect(attacker)
    # Clear critical flag
    self.critical = false
    # First hit detection
    hit_result = (rand(50) < attacker.hit)
    # If hit occurs
    if hit_result == true
      # Calculate basic damage
      atk = [attacker.atk + 50, 0].max
      self.damage = atk * (attacker.str)
      # Element correction
      self.damage *= elements_correct(attacker.element_set)
      # If damage value is strictly positive
      if self.damage > 0
        # Critical correction
        if rand(100) < 4 * attacker.agi / self.agi + critical_bonus(attacker)
          self.damage += (((attacker.atk + 30) * (attacker.str + 30) * self.pdef) / ((self.pdef + 70) * (self.pdef + 50)))
          self.damage *= 9 / 7
          self.critical = true
        end
        # Guard correction
        if self.guarding?
          self.damage = guard_effect(self.damage)
        end
      end
      # Second hit detection
      hit_result = (rand(50) < rand(attacker.agi))
    end
    # If hit occurs
    if hit_result == true
      # State Removed by Shock
      remove_states_shock
      # Substract damage from HP
      self.hp -= self.damage
      # State change
      @state_changed = false
      states_plus(attacker.plus_state_set)
      states_minus(attacker.minus_state_set)
    # When missing
    else
      # Set damage to "Miss"
      self.damage = "Miss"
      # Clear critical flag
      self.critical = false
    end
    # End Method
    return true
  end
The problem is that the damage I get is too high. Can anyone tell me what's wrong and how I would fix this?

Thanks in advance.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top