[XP] Alternate Attack Algorithms

Started by Xelias, November 07, 2009, 12:12:37 pm

Previous topic - Next topic

Xelias

November 07, 2009, 12:12:37 pm Last Edit: November 08, 2009, 12:11:36 pm by Xelias
Alternate Attack Algorithms
Authors: Xelias
Version: 1.00
Type: Battle Add-On
Key Term: Battle Add-on



Introduction

This script allows selected weapons to have special damage formulas. Think Final Fantasy's Ultima Weapon for this one. Effects are better described in the script


Features


  • Weapons inflict damage based on current HP
  • Weapons inflict damage based on HP difference
  • Weapons inflict damage based on current SP
  • Weapons inflict damage based on current Level
  • Weapons inflict damage based on enemy's HP
  • Weapons inflict damage ignoring Defense
  • Weapons inflict damage based on Intelligence
  • Weapons inflict damage based on Agility
  • Weapons drain a selected percent of damage inflicted
  • Weapons inflict damage to opponent's SP
  • Weapons inflict damage ignoring Guard State
  • Weapons increase Critical Hit Ratio
  • Weapons increase Critical Hit Power



Screenshots

No screens. I wonder why we would need some


Demo

No demo. However, I will put one if required.


Script

Put this above main.
Spoiler: ShowHide

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Alternative Attack Algorithms  by Xelias
# Version: 1.00
# Type: Battle Add-ON
# Date v1.00:   7.11.2009
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#  
#  This work is protected by the following license:
# #----------------------------------------------------------------------------
# #  
# #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
# #  ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
# #  
# #  You are free:
# #  
# #  to Share - to copy, distribute and transmit the work
# #  to Remix - to adapt the work
# #  
# #  Under the following conditions:
# #  
# #  Attribution. You must attribute the work in the manner specified by the
# #  author or licensor (but not in any way that suggests that they endorse you
# #  or your use of the work).
# #  
# #  Noncommercial. You may not use this work for commercial purposes.
# #  
# #  Share alike. If you alter, transform, or build upon this work, you may
# #  distribute the resulting work only under the same or similar license to
# #  this one.
# #  
# #  - For any reuse or distribution, you must make clear to others the license
# #    terms of this work. The best way to do this is with a link to this web
# #    page.
# #  
# #  - Any of the above conditions can be waived if you get permission from the
# #    copyright holder.
# #  
# #  - Nothing in this license impairs or restricts the author's moral rights.
# #  
# #----------------------------------------------------------------------------
#   How to use this script :
# This allows your weapons to follow different damage algorithms. Before that, you
# MUST place your weapons following a normal algorithm in the
# NORMAL_WEAPONS_IDS, or else... It wouldn't be good for your game.
# Also place all weapons ID except SP damaging and absorbing ones, into the
# "ALL_WEAPONS_IDS", because if you don't, a nasty bug will prevent you from
# dealing damage with normal attack. Cool, huh ?
#
# ATMA_WEAPON_IDS = [X,X...] : A weapon with an ID equal to X will inflict
# more damage depending on the user's HP. If HP are full, attack power is doubled.
# If HP are at minimum, attack power is normal. If HP are equal to half, attack power
# is equal to 1,5 of the normal Attack power, and so on...
# VALIANT_KNIFE_IDS = [X, X...] : The opposite effect of Atma Weapon.
# If HP are at minimum, attack power is doubled, and so on...
# LIMITED_MOON_IDS = [X, X...] : Follows the same formula than Atma Weapon
# but works with SP
# CONFORMER_IDS = [X, X...] : Deals damage based on user's Level.
#At Level 1, attack power is normal. At Level 99, attack power is doubled. You get
# the idea
# MASAMUNE_IDS = [X, X...] : Deals more damage the weaker the enemy is
# For an enemy with 100% HP, attack power is normal. For an enemy with 1 HP,
# attack power is doubled (which is pretty useless). For an enemy with half HP,
# attack power is equal to 1,5 of the normal attack power, and so on...
# PROJECTILE_IDS = [X, X...] : Ignores the opponent's defense in the damage
# calculation. However, the Attack power is halved, preventing an attack to inflict
# max damage at an opponent with max defense. Otherwise, it wouldn't be fair.
# FFXII_KATANA_IDS = [X, X...] : Acts like a Final Fantasy XII Katana, which
# means it inflicts damage based on user's Intelligence instead of Strength
# FFXII_NINJA_SWORDS_IDS = [X, X...] : Acts like a Final Fantasy XII Ninja Sword,
# which means it inflicts damage based on user's Agility instead of Strength
# MIND_BLASTER_IDS = [X, X...] : Damage is inflicted to SP. Damage
# relies also on the opponent's Magic Defense and your Intelligence
# BLOOD_SWORD_IDS = [X, X...] & PERCENT_DRAINED = X :  
# some damage is absorbed from the attack. How many? PERCENT_DRAINED %
# GUARD_BREAKER_IDS = [X, X...] : Damage ignores if enemy is defending.  
# As simple as that.
# GENJI_WEAPON_IDS = [X, X...] : Critical Hit Ratio is doubled.
# KIKU_ICHIMONJI_IDS = [X, X...] : Critical Hit power is doubled.
#
#
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
 OTHER_WEAPONS_IDS = [11]
 ALL_WEAPONS_IDS = [10,12,13,14,15,16,17,18,21,22,23,24]

 ATMA_WEAPON_IDS = [10]
 VALIANT_KNIFE_IDS = [12]
 LIMITED_MOON_IDS = [13]
 CONFORMER_IDS = [14]
 MASAMUNE_IDS = [15]
 PROJECTILE_IDS = [16]
 FFXII_KATANA_IDS = [17]
 FFXII_NINJA_SWORDS_IDS = [18]
 MIND_BLASTER_IDS = [19]
 BLOOD_SWORD_IDS = [20]
 PERCENT_DRAINED = 50
 GUARD_BREAKER_IDS = [21]
 GENJI_WEAPON_IDS = [23]
 KIKU_ICHIMONJI_IDS = [24]
 
class Game_Battler

def attack_effect(attacker)
   # Clear critical flag
   self.critical = false
   # First hit detection
   hit_result = (rand(100) < attacker.hit)
   # If hit occurs
   if hit_result == true
     # Calculate basic damage
         if attacker.is_a?(Game_Actor)
   if OTHER_WEAPONS_IDS.include?(attacker.weapon_id)
   atk = [attacker.atk - self.pdef / 2, 0].max
    self.damage = atk * (20 + attacker.str) / 20
  end
  if ATMA_WEAPON_IDS.include?(attacker.weapon_id)
    atk = [attacker.atk - self.pdef / 2,0].max
    atk2 = atk * (20 + attacker.str) / 20
   self.damage = atk2 + ((atk2*((attacker.hp*100)/attacker.maxhp))/100)
   end
      if VALIANT_KNIFE_IDS.include?(attacker.weapon_id)
    atk = [attacker.atk - self.pdef / 2,0].max
    atk2 = atk * (20 + attacker.str) / 20
    minushp = attacker.maxhp - attacker.hp
   self.damage = atk2 + ((atk2*((minushp*100)/attacker.maxhp))/100)
   end
    if LIMITED_MOON_IDS.include?(attacker.weapon_id)
    atk = [attacker.atk - self.pdef / 2,0].max
    atk2 = atk * (20 + attacker.str) / 20
   self.damage = atk2 + ((atk2*((attacker.sp*100)/attacker.maxsp))/100)
 end
      if CONFORMER_IDS.include?(attacker.weapon_id)
    atk = [attacker.atk - self.pdef / 2,0].max
    atk2 = atk * (20 + attacker.str) / 20
   self.damage = atk2 + (atk2*(((attacker.level*100) / 99)/100))
 end
     if MASAMUNE_IDS.include?(attacker.weapon_id)
    atk = [attacker.atk - self.pdef / 2,0].max
    atk2 = atk * (20 + attacker.str) / 20
    minushp = self.maxhp - self.hp
   self.damage = atk2 + ((atk2*((minushp*100)/self.maxhp))/100)
 end
       if PROJECTILE_IDS.include?(attacker.weapon_id)
    atk = [attacker.atk,0].max
    self.damage = atk * (20 + attacker.str) / 20
  end
     if FFXII_KATANA_IDS.include?(attacker.weapon_id)
   atk = [attacker.atk - self.pdef / 2, 0].max
    self.damage = atk * (20 + attacker.int) / 20
  end
     if FFXII_NINJA_SWORDS_IDS.include?(attacker.weapon_id)
   atk = [attacker.atk - self.pdef / 2, 0].max
    self.damage = atk * (20 + attacker.agi) / 20
  end
     if BLOOD_SWORD_IDS.include?(attacker.weapon_id)
   atk = [attacker.atk - self.pdef / 2, 0].max
    self.damage = atk * (20 + attacker.str) / 20
  end
     if MIND_BLASTER_IDS.include?(attacker.weapon_id)
   atk = [attacker.atk - ((self.pdef+self.mdef)) / 4, 0].max
    self.damage = atk * (20 + ((attacker.str + attacker.int)/2)) / 20
  end
     if GUARD_BREAKER_IDS.include?(attacker.weapon_id)
   atk = [attacker.atk - self.pdef / 2, 0].max
    self.damage = atk * (20 + attacker.str) / 20
  end
     if GENJI_WEAPON_IDS.include?(attacker.weapon_id)
   atk = [attacker.atk - self.pdef / 2, 0].max
    self.damage = atk * (20 + attacker.str) / 20
  end
     if KIKU_ICHIMONJI_IDS.include?(attacker.weapon_id)
   atk = [attacker.atk - self.pdef / 2, 0].max
    self.damage = atk * (20 + attacker.str) / 20
  end
     end
  if attacker.is_a?(Game_Enemy)
     atk = [attacker.atk - self.pdef / 2, 0].max
    self.damage = atk * (20 + attacker.str) / 20
  end
     # Element correction
   self.damage *= elements_correct(attacker.element_set)
     self.damage /= 100
     # If damage value is strictly positive
     if self.damage > 0
       # Critical correction
       if attacker.is_a?(Game_Actor)
   if GENJI_WEAPON_IDS.include?(attacker.weapon_id)
       if rand(100) < 8 * attacker.dex / self.agi
         self.damage *= 2
         self.critical = true
       end
       end
     if KIKU_ICHIMONJI_IDS.include?(attacker.weapon_id)
       if rand(100) < 4 * attacker.dex / self.agi
         self.damage *= 4
         self.critical = true
       end
     end
   elsif rand(100) < 4 * attacker.dex / self.agi
         self.damage *= 2
         self.critical = true
       end
       # Guard correction
       if self.guarding?
       if GUARD_BREAKER_IDS.include?(attacker.weapon_id)
      self.damage /=1
         end
    else
      self.damage /=2
    end
     # Dispersion
  if self.damage.abs > 0
       amp = [self.damage.abs * 15 / 100, 1].max
       self.damage += rand(amp+1) + rand(amp+1) - amp
     end
     # Second hit detection
     eva = 8 * self.agi / attacker.dex + self.eva
     hit = self.damage < 0 ? 100 : 100 - eva
     hit = self.cant_evade? ? 100 : hit
     hit_result = (rand(100) < hit)
   end
    # If hit occurs
   if hit_result == true
     # State Removed by Shock
     remove_states_shock
     # Substract damage from HP
      if attacker.is_a?(Game_Actor)
     if MIND_BLASTER_IDS.include?(attacker.weapon_id)
       self.sp -= self.damage
       self.damage = sprintf('%+d %s', -self.damage, $data_system.words.sp)
       end
     if BLOOD_SWORD_IDS.include?(attacker.weapon_id)
      healing = (self.damage*PERCENT_DRAINED)/100
       self.hp -= self.damage
       attacker.hp += healing
     end
     if ALL_WEAPONS_IDS.include?(attacker.weapon_id)
       self.hp -= self.damage
   end
   else self.hp -= self.damage
 end
 end
     # 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
end








Instructions

Just set up the weapons' ID at the beginning of the script. And enjoy.


Compatibility

May cause compatibility problem with CBS... maybe ?


Credits and Thanks


  • Xelias, for making this script
  • Game_Guy and Ryexander for helping me with a bug that, well... bugged me.



Author's Notes

If you have ideas for new formulas, just send them. I'll do them... if I can.
On another note : special effects do not stack ! If you want to have two effects (Ex : Blood Sword Ultima Weapon), ask it and I'll make it.  


My sprites
Kuja Tales of the World style :

Blizzard

Quote from: Xelias on November 07, 2009, 12:12:37 pm
On another note : special effects do not stack !


Maybe you should make it change so they do. :)
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Xelias

I tried, but I got more bugs than a swarm of locusts !
But remember, I will merge 'almost' any of those if you ask it. Because some effects are polar opposites (Valiant Knife and Ultima Weapon) and cannot be merged.


My sprites
Kuja Tales of the World style :

Aqua

I fixed a tiny tile error for you.

This looks good :D
It's nice to have some weapons that are a little different than the rest XD.

Xelias

Thanks. Where was the error ? I'd like to know it.


My sprites
Kuja Tales of the World style :

Aqua

[XP] Alternate Attack Algorithms vs. Alternate Attack Algorithms [XP]

Xelias

Phew ! I thought you were talking about a scripting error   :D


My sprites
Kuja Tales of the World style :

Azuriyuu

Hm, it's been a while... and I'm not all that much a scripter, but I'm modifying it to suit my needs(Making the script check weapon elements rather than IDs).

Would it be impolite to post such a thing here?  What's the ettiquette for this sort of thing?

Jragyn

Hey, do it yo, I'm interested if anything :D
A bright light can either illuminate or blind, but how will you know which until you open your eyes?