So, I have this damage code for a small game I was working on awhile ago(it won't bear fruit, so I just tinker with the codes now) and I recently got a problem with it.
If(PlayerGetAttack){
If(ArmorThickness > ProjPen){
ImpDmg = (ProjImpDmg/ShieldStr);
PenDmg = (ProjPenDmg/(ShieldStr*4));
SlashDmg = (ProjSlashDmg/(ShieldStr*6)) ;
PlayerHP = OldPlayerHP - (ImpDmg+PenDmg+SlashDmg);
ArmorHP = OldArmorHP - ((ImpDmg+PenDmg+SlashDmg)/2);
OldPlayerHP = PlayerHP;
OldArmorHP = ArmorHP;
} //What you saw above this comment is if the projectile is not powerful enough to penetrate the armor, the player will take very limited damage, as the armor took it up for him. Below is the codes for if the projectile goes THROUGH the armor.
If(ArmorThickness < ProjPen){
ImpDmg = (ProjImpDmg/ShieldStr);
PenDmg = (ProjPenDmg/(ShieldStr/3));
SlashDmg = (ProjSlashDmg/(ShieldStr/2)) ;
PlayerHP = OldPlayerHP - (ImpDmg+PenDmg+SlashDmg);
ArmorHP = OldArmorHP - ((ImpDmg+PenDmg+SlashDmg)*3);
OldPlayerHP = PlayerHP;
OldArmorHP = ArmorHP;
}
}
/*I recently added a new form of protection, shielding as we all know it. It takes up all damage, and Shields v1.0 took Impact damage the most, while Shields v2.0 introduced the shield types Positron, Gravaton, and Molecular, the latter being the closest to the original shield concept. Shields v2.0 also introduced three new damage types, Thermal against Molecular, Magnetic against Positron, and a third damage type I never gave a name to for Gravaton. Only problem is that instead of having six damage types, I now have 15 damage types and the majority of them do masses of damage to their respective shield. I seem to have lost the Shields v2.0 code, pity.
Anyway, take a look at the simple code overhead, and judge it for yourself. */
EDIT A:A request from one of my friends have yeilded a slightly different code, focused on small % reductions and a flat dmg reduction, meaning if you have '10' armor and you take 25 damage, the armor takes up ten of the 25 and then a percentage of the remaining 15, and you take the rest. ArmorHP may or may not be a factor in this matter.
If(PlayerGetAttack){
DMG = (AttackDMG/ArmorDMG) - ArmorSTR; //a single number, or we multiply it by a percentage, should he resuest otherwise. ArmorDMG will represent % reduction and ArmorSTR will represent flat reduction.
PlayerHP = OldPlayerHP - DMG;
OldPlayerHP = PlayerHP;
}
Now, without the complex Pen/Slash/Imp damages, we get a smaller code overall. It isnt as pleasing to code in, due to the lack of complexity(somehow I feel that the more conplex the code the more fun it is. Strange right?)
I'm curious as to how you're doing this in some sort of static sense. (Though I guess it's not full code anyways, so you don't have any way of calling each unique ship)
I reccomend not doing everything all at once like that. Calculate the damage in a different function, and set certain values based on what the function yields. That way you'll be able to handle more types of damage types, rather than just saying 'if you are hit, take damage'
//If the damage type is..
if(type == <INSERT TYPE>){
//Do your damage calculation
<Blahblahblah>
//Return the modified damage based on if the type conflicted or not. Was it critical? Was it not?
return currentHP - damage;
}
//Do another damage type
else if(type == <ANOTHER TYPE>){
//Do the same thing as above, and return the damage
So really you just need a way to feed in what type of damage you were just hit with, and how much whenever your 'GetAttack' boolean triggers.
Or.. something.
Edit: Better yet, instead of feeding it a string for the damage type, create a struct for each of the types. Or some other method of holding subvalues such as modifiers.
Edit Edit: C#? The Unity Engine i'm assuming? I like Unity. I've done some creation with that engine for fun.
(08-26-2016, 02:04 AM)King Boo Wrote: Edit Edit: C#? The Unity Engine i'm assuming? I like Unity. I've done some creation with that engine for fun.
The Unity Engine indeed. I started code in Visual Studio and went to Unity, so I may be merging alot of concepts without real attention(I haven't been able to send these strips of code through a compiler in two years)
(08-26-2016, 02:04 AM)King Boo Wrote: That way you'll be able to handle more types of damage types, rather than just saying 'if you are hit, take damage'
I would assume you are referring to the first example. That fragment is about as flawed as I can get it before it stops resembling code. The original 1.0 version of it is lost somewhere within my laptop(which no longer functions.)
As for the second, shorter example of code, it was designed for an example of a project my friend wants me to develop. He specified one damage type, so that the players of the game would not have to make complex decisions regarding weapons and armor.
As for doing it all together...I'll work on phrasing it another way. I haven't really been working on my code in a long time(thanks, higher education) and that felt the easiest way was as such.
(08-26-2016, 02:04 AM)King Boo Wrote: (Though I guess it's not full code anyways, so you don't have any way of calling each unique ship)
I was thinking of linking the variables to JavaScript that would be attached/unique to every weapon/ship that had their own stats. I am unsure what I am typing now. I blame...the Zoners. *Inferno retreats to his corner and slams the dolphin door shut. The door accepts PayPal, but not MasterCard. Taco. Edit A: Alright, I reread the if DamageType code block you provided, Boo, and I can understand why you are confused.
The damage types represented above are like the damage concept in Warframe, not Discovery. Instead of one weapon type per weapon, most weapons have differences on certain values of all three, but they all have the same three values. For example, if a shrapnel shotgun was fired, it would be high amounts of slash damage for the shards, and medium penetration values, and very low Impact, as if they didn't cut or punctured the target, they just... bounce off.
Right now I am looking into alternate code phrasing. I will one day get a full script to this thread, with floats, booleans and even variable values. 90% chance it will be Unity-based scripting..