Code:
AttackLock()
if(Lock == 1)
world<<"You're not in a battle..."
return
else
TypeCheck() //battle takes place for base dmg and
//weapon special
OffensivePlayerElementCheck()//weapon element
CriticalCheck()//critical check
DeathCheck()//damage occurs. all is what im showing.
The Above is what everything will proc first as a verb so might as well make it what's used immediately after relevant variables are created and/or set/checked.
The below is how we typecheck not only the weapon special, not crit like it says, but how we also typecheck between the three 'builds' of damage. (Hybrids possible) Melee, Magic, Ranged.
TypeCheck()
Crit = WSC //32% with 15% wep at max level which gives around 2x bonus to all damage.
Crit += Intellect/50 //using 'floating' reusable crit variable to calculate weapon special %
Crit += Dexterity + Strength/90 //added to by stats
Crit += Luck/35
Crit += Charisma + Endurance /220
if(WSP == "Yes") //Not all weapons have specials.
switch(rand(100)) //out of 100
if(0 to Crit) //using our chance
world<<"[WText]" //weapon effect txt
if(WTYPE == "Magic") //type check
MagicDamage() //next step
FDamage = FDamage * WSM //<<
if(WTYPE == "Melee")//multiplier^^^^
MeleeDamage() //mult VVVV
FDamage = FDamage * WSM //<<
if(WTYPE == "Ranged") // mult^^^^
DexDamage()//from weapon..
FDamage = FDamage * WSM //ok
else //if no roll favor
if(WTYPE == "Magic") //same with no
MagicDamage()// mult from
if(WTYPE == "Melee")//weapon special
MeleeDamage()
if(WTYPE == "Ranged")
DexDamage()
else //if no mult at all..
if(WTYPE == "Magic") //type check
MagicDamage() //damage
if(WTYPE == "Melee") //e.t.c.
MeleeDamage()
if(WTYPE == "Ranged")
DexDamage()
Sorry for all the bad notation, WSM and stuff have to do with weapon's attributes, aiding in the creativity of their creation through offering alternatives, soon to add statuses.
Below is the damage formula, will example with strength.
MeleeDamage()
FDamage = WepDamage + (Strength + Strength)
FDamage += 1 + (Level * 2.3) * ((1 * Luck/25) / 8.8)
FDamage += 1 + (Dexterity/1.9)
FDamage = (FDamage / 100) * (((Strength / 2.5) - Emeleedef) + 101) //max is 250 //% resist up to 100, but can be overcome with training in melee combat via strength. Min of 1% damage.)
FDamage = FDamage * DamMod (Damage Modifier for skills.)
txt = "Melee" (Test and for a later composite text part.)
Above is one example of damage, intellect relies less on other stats, only really itself, luck and endurance.
Below is OffensivePlayerElementCheck()
This is how I check element which is granted by weapon.
OffensivePlayerElementCheck()
if(WELE == "Fire")
FDamage = (FDamage / 100) * EFIR
if(WELE == "Water")
FDamage = (FDamage / 100) * EWAT
if(WELE == "Earth")
FDamage = (FDamage / 100) * EEAR
if(WELE == "Air")
FDamage = (FDamage / 100) * EWIN
if(WELE == "Thunder")
FDamage = (FDamage / 100) * ETHU
if(WELE == "Ice")
FDamage = (FDamage / 100) * EICE
if(WELE == "Light")
FDamage = (FDamage / 100) * ELIG
if(WELE == "Darkness")
FDamage = (FDamage / 100) * EDAR
else
return
//fire water earth wind thunder ice light darkness
Above is for % resistance check, which you get from equipment, buffs, classes, e.t.c.
Below is for a critical check, also pretty standard, but could I be doing this faster? REINDENTED TO BE READABLE EASIER Not like this is my script
CriticalCheck()
Crit = WepCrit
Crit = Luck/33
Crit += Dexterity/75
Crit += Strength/100
Crit += Charisma/125
switch(rand(100))
if(0 to Crit)
FDamage = FDamage * (1 + (Luck / 320) + ((Strength + Intellect + Dexterity) / 800) + (Charisma / 600))
switch(rand(6))
if(1)
FDamage = FDamage * (1 + (Luck / 1250) + (Strength / 2000))
world<<"An Astonishing blow!"
if(2)
FDamage = FDamage * (1 + (Luck / 1250) + (Intellect / 1925))
world<<"A Precise assault!"
if(3)
FDamage = FDamage * (1 + (Luck / 1250) + (Dexterity / 1850))
world<<"A Flanking attack!"
if(4)
FDamage = FDamage * 1.4
world<<"A Critical strike!"
if(5)
FDamage = FDamage * (1 + ((Strength + Dexterity + Intellect + Charisma + Luck + Endurance) / 10000))
world<<"An Awesome strik!"
if(6)
FDamage = FDamage * 1.6
world<<"A Perfect Attack!"
else
return
else
return //build special the same way, clear cast, e.t.c.)
Up there we check for critical and type of critical.
Below we check for death. Going to do a new exp system and stuff based off of overkill. Placeholder numbers for now.
DeathCheck()
if(EHP <= 0)
world<<"The enemy is dead!"
else
EHP -= FDamage
world<<"You dealt [FDamage] [txt] [WELE] Damage!"
if(EHP<=0)
world<<"The enemy is slain! You gain [MonEXP] as Experience!"
EXP += MonEXP
Lock=1
</dm
<b>Problem description:</b>
It's just taking a bit and dunno if I'm doing things well.
Your TypeCheck() can also be rearranged to reduce code duplication. Multiplying by WSM always happens after all WTYPE checks, if at all, so you can make that clearer:
A common alternative to switch() in general is polymorphism. It's the more object-oriented approach. In your case, each weapon type and each weapon element can be represented by different objects that provide their own damage calculations and elemental modifiers. What they all have in common goes in the parent type, and how they differ goes in overrides of the child types:
To use this, your attacker's WTYPE and WELE vars would be replaced with instances of the appropriate /weapon_type and /weapon_element. Then, you would call the proc, and the appropriate calculation is done automatically, no type checks required. Something like this:
More information about this particular code conversion here:
https://refactoring.guru/ replace-conditional-with-polymorphism