DBS Formula Edits

Hey guys, I just finished ironing out the bugs after doing some edits to the default damage formulas and whatnot. I'm definitely no scripter, but after some digging, I found the lines I needed, and made the necessary adjustments until things were working how I wanted them.

Overall, it expands your skill options a bit, and definitely makes things easier to calculate.

Notes:
  • This is meant for the Default Battle System in RMXP.
  • Some of the script work might be a bit ugly. Me not being a scripter is fully to blame. Feel free to criticize (:
  • Magic Defense reductions have not been fully tested. After testing PDef, I presumed MDef would work as well.
  • No credit is needed, as this is just a small edit done by a non-scripter.


All right, so here's what I've done:

Standard Attack
For standard attacks, the Attack stat is the base damage, so a sword with 10 Atk would give you 10 damage. Strength affects your base damage by adding it to itself for every 100 Str. So, 100 Str would double your base damage, 200 would triple, 300 would quadruple, etc. Standard stats go up to 999, and 900 Str would increase your base damage by 10x.

Physical Defense of the target reduces damage dealt linearly after all calculations, but before Critical Hits and Guarding. So, a 10 Atk sword with 100 Str against a target with 5 PDef would do the following:

Base Damage = Attack * (100 + Strength) / 100
Base Damage = 10 * (100 + 100) / 100
Base Damage = 10 * 200 / 100
Base Damage = 2000 / 100
Base Damage = 20

Damage = Base Damage - Physical Defense
Damage = 20 - 5
Damage = 15

Critical Hits and Guarding were moved to the end of the calculations, so you take the final damage to be dealt, THEN adjust, giving you as close to doubling and halving as possible.

Skills
This was a bit trickier, but I believe it adds a lot more options to making different skill types and whatnot. Originally, you had to set a base power for the skill and work off of that. Now, if you set the Attack-F (Atk influence) to 0, skills still work normally. But if you set the Atk-F to anything else (1-100) you get skills that base their damage off of your actual Attack stat, ignoring the skill power completely.

You might be asking yourself how this helps at all. Its best use is to make skills that are based off of only the Attack stat, and not the skill power. So if you wanted a skill that always did around double of whatever a standard attack would do, now you can. This makes long-term balancing of skills vs. attacks so much easier, since your Attack stat would always be increasing, but the skill power was always constant.

I've set the Attack-F to influence damage in a certain way, but it is very easily modifiable.

*checks to see if Attack-F is over 0*
Skill Power = Attack * Skill Attack-F / 10

So, if Attack-F is set to 10, the skill power equals your Attack stat (which equals a standard attack). If set to 5 for example, the skill's damage will be equal to 50% of a standard attack. Setting to 20 gives you double, 50 gives you 5x, etc.

The script then checks for the standard rates, so if Strength-F is 100, it will influence the base damage the same way it would for a standard attack. The same applies for the other stats. It then checks to see if either the PDefense-F or the MDefense-F are above 0. If one is set to 100, it reduces linearly like it would for standard attacks. Setting to 50 would reduce by 1 for every 2 in the respective stat, 25 would be 1 for every 4, etc.

The drawback of setting up the rates this way is that having a skill affected by more than one stat, and both defenses makes things messy, so it's ideal for single type, single stat-based skills.

I think that about covers it, sorry for the essay, here's the script. Just replace Game_Battler 3 entirely with this:
  1. #==============================================================================
  2. # ** Game_Battler (part 3)
  3. #------------------------------------------------------------------------------
  4. #  This class deals with battlers. It's used as a superclass for the Game_Actor
  5. #  and Game_Enemy classes.
  6. #==============================================================================
  7.  
  8. class Game_Battler
  9.   #--------------------------------------------------------------------------
  10.   # * Determine Usable Skills
  11.   #     skill_id : skill ID
  12.   #--------------------------------------------------------------------------
  13.   def skill_can_use?(skill_id)
  14.     # If there's not enough SP, the skill cannot be used.
  15.     if $data_skills[skill_id].sp_cost > self.sp
  16.       return false
  17.     end
  18.     # Unusable if incapacitated
  19.     if dead?
  20.       return false
  21.     end
  22.     # If silent, only physical skills can be used
  23.     if $data_skills[skill_id].atk_f == 0 and self.restriction == 1
  24.       return false
  25.     end
  26.     # Get usable time
  27.     occasion = $data_skills[skill_id].occasion
  28.     # If in battle
  29.     if $game_temp.in_battle
  30.       # Usable with [Normal] and [Only Battle]
  31.       return (occasion == 0 or occasion == 1)
  32.     # If not in battle
  33.     else
  34.       # Usable with [Normal] and [Only Menu]
  35.       return (occasion == 0 or occasion == 2)
  36.     end
  37.   end
  38.   #--------------------------------------------------------------------------
  39.   # * Applying Normal Attack Effects
  40.   #     attacker : battler
  41.   #--------------------------------------------------------------------------
  42.   def attack_effect(attacker)
  43.     # Clear critical flag
  44.     self.critical = false
  45.     # First hit detection
  46.     hit_result = (rand(100) < attacker.hit)
  47.     # If hit occurs
  48.     if hit_result == true
  49.       # Calculate basic damage
  50.       self.damage = attacker.atk * (100 + attacker.str) / 100
  51.       # Element correction
  52.       self.damage *= elements_correct(attacker.element_set)
  53.       self.damage /= 100
  54.       # If damage value is strictly positive
  55.       if self.damage > 0
  56.         self.damage -= self.pdef
  57.         # Critical correction
  58.         if rand(100) < 4 * attacker.dex / self.agi
  59.           self.damage *= 2
  60.           self.critical = true
  61.         end
  62.         # Guard correction
  63.         if self.guarding?
  64.           self.damage /= 2
  65.         end
  66.       end
  67.       # Dispersion
  68.       if self.damage.abs > 0
  69.         amp = [self.damage.abs * 10 / 100, 1].max
  70.         self.damage += rand(amp+1) + rand(amp+1) - amp
  71.       end
  72.       # Second hit detection
  73.       eva = 8 * self.agi / attacker.dex + self.eva
  74.       hit = self.damage < 0 ? 100 : 100 - eva
  75.       hit = self.cant_evade? ? 100 : hit
  76.       hit_result = (rand(100) < hit)
  77.     end
  78.     # If hit occurs
  79.     if hit_result == true
  80.       # State Removed by Shock
  81.       remove_states_shock
  82.       # Substract damage from HP
  83.       self.hp -= self.damage
  84.       # State change
  85.       @state_changed = false
  86.       states_plus(attacker.plus_state_set)
  87.       states_minus(attacker.minus_state_set)
  88.     # When missing
  89.     else
  90.       # Set damage to "Miss"
  91.       self.damage = "Miss"
  92.       # Clear critical flag
  93.       self.critical = false
  94.     end
  95.     # End Method
  96.     return true
  97.   end
  98.   #--------------------------------------------------------------------------
  99.   # * Apply Skill Effects
  100.   #     user  : the one using skills (battler)
  101.   #     skill : skill
  102.   #--------------------------------------------------------------------------
  103.   def skill_effect(user, skill)
  104.     # Clear critical flag
  105.     self.critical = false
  106.     # If skill scope is for ally with 1 or more HP, and your own HP = 0,
  107.     # or skill scope is for ally with 0, and your own HP = 1 or more
  108.     if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
  109.        ((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
  110.       # End Method
  111.       return false
  112.     end
  113.     # Clear effective flag
  114.     effective = false
  115.     # Set effective flag if common ID is effective
  116.     effective |= skill.common_event_id > 0
  117.     # First hit detection
  118.     hit = skill.hit
  119.     if skill.atk_f > 0
  120.       hit *= user.hit / 100
  121.     end
  122.     hit_result = (rand(100) < hit)
  123.     # Set effective flag if skill is uncertain
  124.     effective |= hit < 100
  125.     # If hit occurs
  126.     if hit_result == true
  127.       # Attack Influence Multipliers
  128.       #  1 = 10%  |  2 = 20%  | (...) |  9 = 90%  |  10 = 100%
  129.       # 11 = 1.1x | 12 = 1.2x | (...) | 19 = 1.9x |  20 = 2x
  130.       # 21 = 2.1x | 22 = 2.2x | (...) | 99 = 9.9x | 100 = 10x
  131.       if skill.atk_f > 0
  132.         skill.power = user.atk * skill.atk_f / 10
  133.       end
  134.       # Calculate rate
  135.       rate = 100
  136.       rate += (user.str * skill.str_f / 100)
  137.       rate += (user.dex * skill.dex_f / 100)
  138.       rate += (user.agi * skill.agi_f / 100)
  139.       rate += (user.int * skill.int_f / 100)
  140.       # Calculate basic damage
  141.       self.damage = skill.power * rate / 100
  142.       # Element correction
  143.       self.damage *= elements_correct(skill.element_set)
  144.       self.damage /= 100
  145.       if skill.pdef_f > 0
  146.         self.damage -= (self.pdef * skill.pdef_f / 100)
  147.       end
  148.       if skill.mdef_f > 0
  149.         self.damage -= (self.mdef * skill.mdef_f / 100)
  150.       end
  151.       if self.damage <= 0
  152.         self.damage == 0
  153.       end
  154.       # If damage value is strictly positive
  155.       if self.damage > 0
  156.         # Guard correction
  157.         if self.guarding?
  158.           self.damage /= 2
  159.         end
  160.       end
  161.       # Dispersion
  162.       if skill.variance > 0 and self.damage.abs > 0
  163.         amp = [self.damage.abs * skill.variance / 100, 1].max
  164.         self.damage += rand(amp+1) + rand(amp+1) - amp
  165.       end
  166.       # Second hit detection
  167.       eva = 8 * self.agi / user.dex + self.eva
  168.       hit = self.damage < 0 ? 100 : 100 - eva * skill.eva_f / 100
  169.       hit = self.cant_evade? ? 100 : hit
  170.       hit_result = (rand(100) < hit)
  171.       # Set effective flag if skill is uncertain
  172.       effective |= hit < 100
  173.     end
  174.     # If hit occurs
  175.     if hit_result == true
  176.       # If physical attack has power other than 0
  177.       if skill.power != 0 and skill.atk_f > 0
  178.         # State Removed by Shock
  179.         remove_states_shock
  180.         # Set to effective flag
  181.         effective = true
  182.       end
  183.       # Substract damage from HP
  184.       last_hp = self.hp
  185.       self.hp -= self.damage
  186.       effective |= self.hp != last_hp
  187.       # State change
  188.       @state_changed = false
  189.       effective |= states_plus(skill.plus_state_set)
  190.       effective |= states_minus(skill.minus_state_set)
  191.       # If power is 0
  192.       if skill.power == 0
  193.         # Set damage to an empty string
  194.         self.damage = ""
  195.         # If state is unchanged
  196.         unless @state_changed
  197.           # Set damage to "Miss"
  198.           self.damage = "Miss"
  199.         end
  200.       end
  201.     # If miss occurs
  202.     else
  203.       # Set damage to "Miss"
  204.       self.damage = "Miss"
  205.     end
  206.     # If not in battle
  207.     unless $game_temp.in_battle
  208.       # Set damage to nil
  209.       self.damage = nil
  210.     end
  211.     # End Method
  212.     return effective
  213.   end
  214.   #--------------------------------------------------------------------------
  215.   # * Application of Item Effects
  216.   #     item : item
  217.   #--------------------------------------------------------------------------
  218.   def item_effect(item)
  219.     # Clear critical flag
  220.     self.critical = false
  221.     # If item scope is for ally with 1 or more HP, and your own HP = 0,
  222.     # or item scope is for ally with 0 HP, and your own HP = 1 or more
  223.     if ((item.scope == 3 or item.scope == 4) and self.hp == 0) or
  224.        ((item.scope == 5 or item.scope == 6) and self.hp >= 1)
  225.       # End Method
  226.       return false
  227.     end
  228.     # Clear effective flag
  229.     effective = false
  230.     # Set effective flag if common ID is effective
  231.     effective |= item.common_event_id > 0
  232.     # Determine hit
  233.     hit_result = (rand(100) < item.hit)
  234.     # Set effective flag is skill is uncertain
  235.     effective |= item.hit < 100
  236.     # If hit occurs
  237.     if hit_result == true
  238.       # Calculate amount of recovery
  239.       recover_hp = maxhp * item.recover_hp_rate / 100 + item.recover_hp
  240.       recover_sp = maxsp * item.recover_sp_rate / 100 + item.recover_sp
  241.       if recover_hp < 0
  242.         recover_hp += self.pdef * item.pdef_f / 20
  243.         recover_hp += self.mdef * item.mdef_f / 20
  244.         recover_hp = [recover_hp, 0].min
  245.       end
  246.       # Element correction
  247.       recover_hp *= elements_correct(item.element_set)
  248.       recover_hp /= 100
  249.       recover_sp *= elements_correct(item.element_set)
  250.       recover_sp /= 100
  251.       # Dispersion
  252.       if item.variance > 0 and recover_hp.abs > 0
  253.         amp = [recover_hp.abs * item.variance / 100, 1].max
  254.         recover_hp += rand(amp+1) + rand(amp+1) - amp
  255.       end
  256.       if item.variance > 0 and recover_sp.abs > 0
  257.         amp = [recover_sp.abs * item.variance / 100, 1].max
  258.         recover_sp += rand(amp+1) + rand(amp+1) - amp
  259.       end
  260.       # If recovery code is negative
  261.       if recover_hp < 0
  262.         # Guard correction
  263.         if self.guarding?
  264.           recover_hp /= 2
  265.         end
  266.       end
  267.       # Set damage value and reverse HP recovery amount
  268.       self.damage = -recover_hp
  269.       # HP and SP recovery
  270.       last_hp = self.hp
  271.       last_sp = self.sp
  272.       self.hp += recover_hp
  273.       self.sp += recover_sp
  274.       effective |= self.hp != last_hp
  275.       effective |= self.sp != last_sp
  276.       # State change
  277.       @state_changed = false
  278.       effective |= states_plus(item.plus_state_set)
  279.       effective |= states_minus(item.minus_state_set)
  280.       # If parameter value increase is effective
  281.       if item.parameter_type > 0 and item.parameter_points != 0
  282.         # Branch by parameter
  283.         case item.parameter_type
  284.         when 1  # Max HP
  285.           @maxhp_plus += item.parameter_points
  286.         when 2  # Max SP
  287.           @maxsp_plus += item.parameter_points
  288.         when 3  # Strength
  289.           @str_plus += item.parameter_points
  290.         when 4  # Dexterity
  291.           @dex_plus += item.parameter_points
  292.         when 5  # Agility
  293.           @agi_plus += item.parameter_points
  294.         when 6  # Intelligence
  295.           @int_plus += item.parameter_points
  296.         end
  297.         # Set to effective flag
  298.         effective = true
  299.       end
  300.       # If HP recovery rate and recovery amount are 0
  301.       if item.recover_hp_rate == 0 and item.recover_hp == 0
  302.         # Set damage to empty string
  303.         self.damage = ""
  304.         # If SP recovery rate / recovery amount are 0, and parameter increase
  305.         # value is ineffective.
  306.         if item.recover_sp_rate == 0 and item.recover_sp == 0 and
  307.            (item.parameter_type == 0 or item.parameter_points == 0)
  308.           # If state is unchanged
  309.           unless @state_changed
  310.             # Set damage to "Miss"
  311.             self.damage = "Miss"
  312.           end
  313.         end
  314.       end
  315.     # If miss occurs
  316.     else
  317.       # Set damage to "Miss"
  318.       self.damage = "Miss"
  319.     end
  320.     # If not in battle
  321.     unless $game_temp.in_battle
  322.       # Set damage to nil
  323.       self.damage = nil
  324.     end
  325.     # End Method
  326.     return effective
  327.   end
  328.   #--------------------------------------------------------------------------
  329.   # * Application of Slip Damage Effects
  330.   #--------------------------------------------------------------------------
  331.   def slip_damage_effect
  332.     # Set damage
  333.     self.damage = self.maxhp / 5
  334.     # Dispersion
  335.     if self.damage.abs > 0
  336.       amp = [self.damage.abs * 15 / 100, 1].max
  337.       self.damage += rand(amp+1) + rand(amp+1) - amp
  338.     end
  339.     # Subtract damage from HP
  340.     self.hp -= self.damage
  341.     # End Method
  342.     return true
  343.   end
  344.   #--------------------------------------------------------------------------
  345.   # * Calculating Element Correction
  346.   #     element_set : element
  347.   #--------------------------------------------------------------------------
  348.   def elements_correct(element_set)
  349.     # If not an element
  350.     if element_set == []
  351.       # Return 100
  352.       return 100
  353.     end
  354.     # Return the weakest object among the elements given
  355.     # * "element_rate" method is defined by Game_Actor and Game_Enemy classes,
  356.     #    which inherit from this class.
  357.     weakest = -100
  358.     for i in element_set
  359.       weakest = [weakest, self.element_rate(i)].max
  360.     end
  361.     return weakest
  362.   end
  363. end
Expand to see the code.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=74059