So, Revision 9 introduced a new file: Battle.lua
This file manages the most important things about the combat system: Damage Calculation, how damage is dealt to platoons and how the A.I. behaves.
This is a request for help, actually, I would like to hear YOUR opinion on things, how would you do those calculations and why mine are wrong (or what I can do to improve them).
I'll explain everything after the break.
...
Damage Calculation is probably the easiest part so I'll be quick and I think that if you did something like that it'll probably be similar to how I did it.
function CalculateDamage (aATK,aDEX,dDEF,dDEX)
Damage = aATK
EnemyDef = 2*dDEF
Damage = aATK
CriticalPos = aDEX/5
DodgePos = dDEX/10
-- Base multiplier (None)
Multiplier = 1
if CriticalPos > math.random(100) then
Multiplier = 1.5
end
if DodgePos > math.random(100) then
Multiplier = 0
end
-- This is how the enemy DEF affects the whole thing
-- This is also why I will kill you if you set DEF to 0.
DefEffect = Damage/EnemyDef
Damage = Damage * Multiplier * DefEffect
return Damage
end
If you are a programmer, it's likely that you can understand most of it (if not everything) without having to read here, but I'll explain it anyway, but before, some info:
That said, here's how damage is calculated:
That's it, simple and straight-forward. Still, I'm not really happy how the Defender's DEF actually influences it, but I'll stick to it until I'll need to change it for balancing reasons.
Let's move to the next argument of this article.
This is the big deal or it could appear to be so.
There's really no big strategy in a J-RPG combat system, so it's not really complicated to do the A.I. code.
Still, I think that the actual code I wrote it's too simple and I'll appreciate every single suggestion about how could I improve it.
Here's the code:
function AI_Attack (_atkPow,_EnemyPlatoons,_pCount,_type)
if _pCount < 1 then
return 0
end
MaxAtk = Platoon.getStat(_EnemyPlatoons[0],"ATK",_type)
MaxID = 0
for i=1,_pCount-1 do
TempAtk = Platoon.getStat(_EnemyPlatoons[i],"ATK",_type)
if TempAtk > MaxAtk then
MaxAtk = TempAtk
MaxID = i
end
end
return MaxID
end
So, what does it do?
As I said, it's really simple:
Stop, it can't get simpler than that.
Brief explanation why I kept it so simple:
The attack of a platoon depends on how many units are alive, so three weak platoons do less damage than if they were two with full health.
So the most logical thing is to attack the strongest enemies, so they do less damage to you when it's their turn.
You're tired, aren't you?
Well, good news is that I won't post the code because it doesn't work yet.
So, problem is:
When someone attacks, it attacks a Platoon, not single units, so how I distribute this damage to units?
The method I used is pretty simple and it should work fine.
The explanation is pretty simple too, just like the other ones:
About this, I still don't know if it will ever work, and I think I'll probably stick to a less random-based approach.
So again, let me know your opinion about AI, about Damage Calculation... about everything!
I'll be happy to reply!
See you~
PS: Grammar Nazis are welcome, so I can blame my co-worker for being a bad Spellchecker.