øAslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&topic=329.msg2719e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/index3be7.htmlslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&topic=329.0e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/index3be7.html.zxç¡g^ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÈ0P.ÍNOKtext/htmlISO-8859-1gzip0|ÖÍNÿÿÿÿÿÿÿÿTue, 10 Mar 2020 14:35:41 GMT0ó°° ®0®P®€§²ð®æ¡g^ÿÿÿÿÿÿÿÿÿ,ÍN The Holy Grail - Magic Algorithm

Author Topic: The Holy Grail - Magic Algorithm  (Read 15622 times)

Deathlike2

  • Moderator
  • *
  • Posts: 3,538
  • I'm looking at you, bitch!
    • View Profile
The Holy Grail - Magic Algorithm
« on: February 22, 2008, 03:56:38 AM »
For those that care, I believe I've figured out the basic magic damage algorithm. Remember to truncate where applicable.

For reference:

Split Damage Modifier:
Spell Targets Only All Enemies or All Allies = 1
Every Other Spell = 1/number of targets
List of spells that ignore split damage can be found here: http://slickproductions.org/forum/index.php?topic=359.0

Undead Modifier:
Drain Elemental (Osmose/Psych and Drain) vs Undead = -1
Unapplicable = 1

Note: Sylph works against Undead w/o this penalty for its "special" Drain attack.

Absorb Modifier:
Target Absorbs vs Element = -1
Unapplicable = 1

Note: If the target reacts to any of the elemental attacks, continue using the multiplier during an uninterrupted attack such as one given by Zeromus EG from FF4A. Stop using the multiplier when the uninterrupted attack ends. Elemental multipliers do not stack.

Appendix: Refer to this for how the game deals with elemental magic attacks - http://slickproductions.org/forum/index.php?topic=426.0

Healing Modifier:
Target is Ally = -1
Target is Undead = 1
Unapplicable = 1

Magic Defense:

Base Magic Defense (character) = sum of all armor magic defense values
Note: Unequipped sections have a magic defense of 0.
Base Magic Defense (monster) = Whatever is listed by the game

Magic Defense Modifier:
Healing Spell Targeted On Ally = 0
Unapplicable = 1

Note: If Magic Defense > 255 in your equipment, Magic Defense = 255. This is here just so you know.

Magic Defense = Base Magic Defense * Magic Defense Modifier

Magic Evade:

Base Magic Evade (character) =  (Wisdom (Intelligence) + Will (Spirit))/8 + all the armor magic evade values
Base Magic Evade (monster) = 0

Magic Evade Modifier:
Target is Monster and its Magic Defense is 255 sets Base Magic Evade = 99
Target is Blind = 1/2
Unapplicable = 1
Note: The Monster has 99 Magic Evade, regardless of Blind status...

If Base Magic Evade > 99, Base Magic Evade = 99.

Magic Evade = Base Magic Evade * Magic Evade Modifier

Note: When Monster Magic Defense is naturally at 255 (with no help from Shell), they are intentionally "invincible" to magic.

Magic Defense Multiplier:

Base Magic Defense Multiplier (character) = Agility/32 + (Wisdom (Intelligence) + Will (Spirit))/32
Base Magic Defense Multiplier (monster) = irrelevent

Note: Since monster magic evade = 0, it doesn't matter what the magic evade value is, except when monster magic defense = 255.

Magic Defense Multiplier Modifer:
Target is Monster and its Magic Defense is 255 sets Magic Defense Multiplier = 99
Target has Toad status sets Magic Defense Multiplier = 0
Unapplicable = Magic Defense Multiplier = Base Magic Defense
Note: When Monster Magic Defense is naturally at 255 (with no help from Shell), they are intentionally "invincible" to magic.

Spell Hit Rate:

Base Spell Hit Rate = Whatever is stored internally
If Base Spell Hit Rate > 128, Base Spell Hit Rate -= 128.
List of spells affected by the 128 point difference can be found here: http://slickproductions.org/forum/index.php?topic=360.0

Spell Hit Rate Modifier:
Weapon Used As Item Magic sets Spell Hit Rate = 100
Caster is Blind = 1/2
**Caster is in Slot 1 (the Middle position) = 5/4
Unapplicable = 1

Note: Spells cast by a weapon used as an item have a 100% hit rate, regardless of blind status or the original spell's hit rate.

Spell Hit Rate = (Base Spell Hit Rate + (Wisdom (Intelligence) or Will (Spirit) or Monster''s Magic Stat)/2) * Spell Hit Rate Modifier

Spell Power:

Base Spell Power (for most spells) = Whatever is listed internally for that spell * 4
Base Spell Power (Summon spells) = Whatever is listed internally for that spell * 8

Elemental Power Multiplier:
Weak vs Element and Weak+ = 4
Weak vs Element = 2
Resist vs Element = 1/2
Immune vs Element = 0
Unapplicable = 1

Note: If the target reacts to any of the elemental attacks, continue using the multiplier during an uninterrupted attack such as one given by Zeromus EG from FF4A. Stop using the multiplier when the uninterrupted attack ends. Elemental multipliers do not stack.

Appendix: Refer to this for how the game deals with elemental magic attacks - http://slickproductions.org/forum/index.php?topic=426.0

Spell Power = Base Spell Power * Elemental Power Multiplier * (rand (100, 150)/100) - Target's Magic Defense
If Spell Power < 0, Spell Power = 0

Or... you could also say:

Spell Power = Base Spell Power * Elemental Power Multiplier * (rand (100, 150)/100)
If Spell Power < Target's Magic Defense, then Spell Power = 0.
Else Spell Power -= Target's Magic Defense.

Note: You only need to randomize once for the algo to work properly.

Spell Power Multiplier:

Spell Power Multiplier (White) = Will (Spirit) /4 + 1
Spell Power Multiplier (Black) = Wisdom (Intelligence) /4 + 1
Spell Power Multiplier (Ninja) = Wisdom (Intelligence) /4 + 1
Spell Power Multiplier (Summon) = Wisdom (Intelligence) /4 + 1
Spell Power Multiplier (Monster) = Whatever their magic stat says /4 + 1
Spell Power Multiplier (Weapon Magic) = Whatever that value is listed
**Spell Power Multiplier (Status Effects) = 1

Note: Blind status does not hurt the weapon magic's spell multiplier.

**Refer to this thread for status effect spells that manipulate this value: http://slickproductions.org/forum/index.php?topic=370.0

Code: [Select]
//Multiplier Madness! - These checks redo the spell power multiplier based on spell hit rate and target's magic evasion.

New Spell Power Multiplier = Caster's Spell Power Multiplier; // initial

while (Caster's Spell Power Multiplier > 0)
{
 if (rand (0, 99) <= Spell's Hit Rate) // check if individual spell hit is successful due to spell hit rate
 {
  while (Target's Magic Defense Multiplier > 0)
  // consider the Magic Defense Multiplier the number of chances to evade magic hits
  // we try again on failure and stop when there is no more
  {
   Target's Magic Defense Multiplier--;
   if (rand (0,99) < Target's Magic Evade) // see if the target evades the magic hit
   {
    New Spell Power Multiplier--;
    break; // exit this loop since target has evaded successfully
   }
 }
 else // executed when individual spell hit fails to hit target and ignores magic evade - think of Tellah's suckage
 {
  New Spell Power Multiplier--;
 }
 Caster's Spell Power Mulitplier--;
}

Here we go!

Damage = New Spell Power Multiplier * Spell Power * Split Damage Modifier * Undead Modifer * Absorb Modifier * Healing Modifier;

If Damage = 0, then Damage = 1;

It is worth pointing out that monster magic evade = 0. Attack magic generally has a hit rate of 100%, although Venom/Poison is "the exception",
since it does both inflict a status and "deal damage".

HP based damage algo can be found here - http://slickproductions.org/forum/index.php?topic=448.0

Feel free to comment, question or mock my algo. If you mock it,  :banonsmash:
« Last Edit: March 30, 2008, 07:39:50 PM by Deathlike2 »
Working on the next Yet To Be Named FF4 "Hardtype" Hack Download Latest: v1.48

Video Demos: #1 #2 #3

Entroper

  • FF4 Hacker
  • *
  • Posts: 235
  • Gender: Male
    • View Profile
Re: The Holy Grail - Magic Algorithm
« Reply #1 on: February 22, 2008, 04:37:58 AM »
Most of that looks spot-on.  I have but one question: From where are you getting the rand(100, 150)/100 part?  It's in the logical place in the formula, and it seems reasonable.  But does the 1-1.5 number come from somewhere in the code, or from testing, or what exactly?

Deathlike2

  • Moderator
  • *
  • Posts: 3,538
  • I'm looking at you, bitch!
    • View Profile
Re: The Holy Grail - Magic Algorithm
« Reply #2 on: February 22, 2008, 04:54:10 AM »
Most of that looks spot-on.  I have but one question: From where are you getting the rand(100, 150)/100 part?  It's in the logical place in the formula, and it seems reasonable.  But does the 1-1.5 number come from somewhere in the code, or from testing, or what exactly?

It's the randomness factor. It is the same factor when you deal physical damage.

Test Cure1 while at 99 Spirit/Will in battle. The range of the healing is 400-600. You will then see why it is randomized.

I'm still tweaking the formula, so stay tuned.
« Last Edit: February 22, 2008, 05:00:15 AM by Deathlike2 »
Working on the next Yet To Be Named FF4 "Hardtype" Hack Download Latest: v1.48

Video Demos: #1 #2 #3

Deathlike2

  • Moderator
  • *
  • Posts: 3,538
  • I'm looking at you, bitch!
    • View Profile
Re: The Holy Grail - Magic Algorithm
« Reply #3 on: February 22, 2008, 04:38:34 PM »
Non-Damage Magic Algo (for most, if not all other spells, generally applicable to status changing magic)

Target Count:
Single = 1
All Targets = number of targets

Level based spell reference: http://slickproductions.org/forum/index.php?topic=358.0
Spells (ones that apply status effects) affected by spell multiplier manipulation: http://slickproductions.org/forum/index.php?topic=370.0

SNES version:

Success =

Code: [Select]
while (Target Count > 0)
{
  reset Spell Type Multiplier();
  Succesful Hit = false;
  while (Spell Type Multiplier > 0)
  {
   if ((rand(0, 99) <= Spell Hit Rate) || ((Level Check == true) && (rand(0, Target's Level) <= rand(0, Caster's Level)))
   {
     Successful Hit = true;
     break;
   }
   Spell Type Multiplier--;
  }
  if(Successful Hit == false)
  {
   return false;
  }
  Target Count--;
}
return true;

If Success = true, then apply status afflication to target(s) unless immune/resistant to status.

GBA Version:

Code: [Select]
while (Target Count > 0)
{
  if((attack type == status effect)&&(!target.isresistant(status effect))
  {
   reset Spell Type Multiplier();
   while (Spell Type Multiplier > 0)
   {
    if ((rand(0, 99) <= Spell Hit Rate) || ((Level Check == true) && (rand(0, Target's Level) <= rand(0, Caster's Level)))
    {
     apply status effect(); // if immune/resistant, silently fail? probably won't matter
     break; // success
    }
    Spell Type Multiplier--;
   }
  }
  Target Count--;
}
« Last Edit: March 20, 2008, 09:08:05 AM by Deathlike2 »
Working on the next Yet To Be Named FF4 "Hardtype" Hack Download Latest: v1.48

Video Demos: #1 #2 #3

Lenophis

  • Forum Overlord
  • *
  • Posts: 1,688
  • Gender: Male
  • I sad
    • View Profile
    • Slick Productions
Re: The Holy Grail - Magic Algorithm
« Reply #4 on: February 23, 2008, 01:52:37 AM »
Would a code tag help with that organization at all?

119 bugs fixed and counting.

Deathlike2

  • Moderator
  • *
  • Posts: 3,538
  • I'm looking at you, bitch!
    • View Profile
Re: The Holy Grail - Magic Algorithm
« Reply #5 on: February 23, 2008, 01:55:43 AM »
Would a code tag help with that organization at all?

Laziness ftw?  :tongue:
Working on the next Yet To Be Named FF4 "Hardtype" Hack Download Latest: v1.48

Video Demos: #1 #2 #3

Lenophis

  • Forum Overlord
  • *
  • Posts: 1,688
  • Gender: Male
  • I sad
    • View Profile
    • Slick Productions
Re: The Holy Grail - Magic Algorithm
« Reply #6 on: February 23, 2008, 02:13:27 AM »
Laziness ftw?  :tongue:
:omghax: Looks like a nice programming-esque representation of how they play out. This could translate to easily makable (yes, that's spelled correctly, even though it doesn't look like it) assembly code...

119 bugs fixed and counting.

Deathlike2

  • Moderator
  • *
  • Posts: 3,538
  • I'm looking at you, bitch!
    • View Profile
Re: The Holy Grail - Magic Algorithm
« Reply #7 on: February 23, 2008, 02:16:52 AM »
Laziness ftw?  :tongue:
:omghax: Looks like a nice programming-esque representation of how they play out. This could translate to easily makable (yes, that's spelled correctly, even though it doesn't look like it) assembly code...

Probably, but it won't be calculated in that order for a number of reasons...

1) 2x hits can still deal 1 damage total to the same character. (Though that's for physical attacks).

2) Multi-hits (consective uninterruptable attacks... magic and otherwise) involving elementals and absorption accumulate healing instead of damage.
Working on the next Yet To Be Named FF4 "Hardtype" Hack Download Latest: v1.48

Video Demos: #1 #2 #3

Deathlike2

  • Moderator
  • *
  • Posts: 3,538
  • I'm looking at you, bitch!
    • View Profile
Re: The Holy Grail - Magic Algorithm
« Reply #8 on: February 28, 2008, 12:20:02 AM »
Most of that looks spot-on.  I have but one question: From where are you getting the rand(100, 150)/100 part?  It's in the logical place in the formula, and it seems reasonable.  But does the 1-1.5 number come from somewhere in the code, or from testing, or what exactly?

Btw, BSiron's FAQ mentions 3/2 in the damage range calculations, which is where the number comes from if you think about it.
Working on the next Yet To Be Named FF4 "Hardtype" Hack Download Latest: v1.48

Video Demos: #1 #2 #3

Deathlike2

  • Moderator
  • *
  • Posts: 3,538
  • I'm looking at you, bitch!
    • View Profile
Re: The Holy Grail - Magic Algorithm
« Reply #9 on: March 01, 2008, 03:13:45 PM »
Fixed the magic algo like I did with the attack algo. Attack magic is always applied against magic defense.
The Magic Defense Multiplier's significance is beneficial for Magic Evade to reduce the damage intake
similar to what the Defense Multiplier does for Evade.
Working on the next Yet To Be Named FF4 "Hardtype" Hack Download Latest: v1.48

Video Demos: #1 #2 #3

Deathlike2

  • Moderator
  • *
  • Posts: 3,538
  • I'm looking at you, bitch!
    • View Profile
Re: The Holy Grail - Magic Algorithm
« Reply #10 on: March 02, 2008, 01:47:48 AM »
Fixed a huge logical and mathematical error. The magic evade is not supposed to be tested against the spell hit rate, but that out of 100%.  :tongue:
Working on the next Yet To Be Named FF4 "Hardtype" Hack Download Latest: v1.48

Video Demos: #1 #2 #3

Imzogelmo

  • Ogopogo Aficianado
  • *
  • Posts: 241
  • Gender: Male
  • Ask me about my other job.
    • View Profile
    • NEPROMR
Re: The Holy Grail - Magic Algorithm
« Reply #11 on: March 02, 2008, 02:34:59 AM »
Any chance of a comprehensive Algorithm FAQ like we've long had with FFVI?
Something that can factor in the chance to hit and amount of damage for physical and magical attacks, with either monster or characters attacking?
And if there are any exceptions to the rules for such (special commands, things that skip certain steps, etc.)?

Not to mention other algos, like when an attack occurs, ATB timers, etc.?

Something verbose enough to translate into an Excel spreadsheet (or the sheet itself :tongue:).

Reason I ask is that I'd like to be able to write a general enough set of functions that could handle FFIV-FFVI with some switches for different rule sets, of course.
5/31/16 - I have an assembly of the battle portion of C2, relocated to the F0 bank, which has both vanilla and patch code in my dropbox. I'll be updating it with additional patches as I have time. I will *not* be releasing it publicly, but ask me for the link and I'll share.

Deathlike2

  • Moderator
  • *
  • Posts: 3,538
  • I'm looking at you, bitch!
    • View Profile
Re: The Holy Grail - Magic Algorithm
« Reply #12 on: March 02, 2008, 03:00:42 AM »
Any chance of a comprehensive Algorithm FAQ like we've long had with FFVI?
Something that can factor in the chance to hit and amount of damage for physical and magical attacks, with either monster or characters attacking?
And if there are any exceptions to the rules for such (special commands, things that skip certain steps, etc.)?

Not to mention other algos, like when an attack occurs, ATB timers, etc.?

Something verbose enough to translate into an Excel spreadsheet (or the sheet itself :tongue:).

Reason I ask is that I'd like to be able to write a general enough set of functions that could handle FFIV-FFVI with some switches for different rule sets, of course.

I was thinking of that - http://slickproductions.org/forum/index.php?topic=190.0

The issue though is that noone seems to have dumped any code relating to the ATB system to verify any of the algos. I haven't even touched the ATB system because it is still relatively foreign to me (I mean, until FF4A, there was no ATB bar that I could even think of referencing against).

However, the bits and pieces of info about stuff are lingering all around this forum, so you are welcome to test/verify and contribute if you can. I'm bored to death thinking of stuff to be testing... the next commands worth a damn looking at is Throw and Steal at this point...
« Last Edit: March 02, 2008, 03:22:23 AM by Deathlike2 »
Working on the next Yet To Be Named FF4 "Hardtype" Hack Download Latest: v1.48

Video Demos: #1 #2 #3

Deathlike2

  • Moderator
  • *
  • Posts: 3,538
  • I'm looking at you, bitch!
    • View Profile
Re: The Holy Grail - Magic Algorithm
« Reply #13 on: March 02, 2008, 06:28:36 PM »
Finding this tidbit... http://s-endo.skr.jp/ff4magparam.txt , I am adjusting the formulas accordingly.

Most notably, I didn't know that Piggy had a atrocious 10% hit rate.

Other changes include the Summon multiplier... the multiplier is doubled naturally.
The spell power of the summon is consistant through since it doesn't deal 9999 against Behemoths...
which implies that the spell multiplier is simply doubled.
« Last Edit: March 02, 2008, 07:52:02 PM by Deathlike2 »
Working on the next Yet To Be Named FF4 "Hardtype" Hack Download Latest: v1.48

Video Demos: #1 #2 #3

Deathlike2

  • Moderator
  • *
  • Posts: 3,538
  • I'm looking at you, bitch!
    • View Profile
Re: The Holy Grail - Magic Algorithm
« Reply #14 on: March 03, 2008, 01:18:46 AM »
Updated spell algo to include updated Sylph info and level check info.
Working on the next Yet To Be Named FF4 "Hardtype" Hack Download Latest: v1.48

Video Demos: #1 #2 #3