client
North()
if(usr.Frozen)
return 0
South()
if(usr.Frozen)
return 0
East()
if(usr.Frozen)
return 0
West()
if(usr.Frozen)
return 0
Northeast()
if(usr.Frozen)
return 0
Northwest()
if(usr.Frozen)
return 0
Southeast()
if(usr.Frozen)
return 0
Southwest()
if(usr.Frozen)
return 0
Will this work - and is there any better way to do it?
Next - this code simply looks inefficient, yet I can't put my finger on why and what I should change.
verb
Fly()
if(!Frozen)
if(!Flight)
Flight = 1
icon_state = "Flight"
var/X = 8 + FlightMod
step_size = X
Flight()
else
Flight = 0
icon_state = ""
step_size = 6
Train()
if(!Training)
if(!Frozen)
if(Flight)
Flight = 0
icon_state = null
step_size = 6
icon_state = "Training"
Training = 1
Frozen = 1
Training()
else
Training = 0
if(!EFroze)
Frozen = 0
mob
proc
Stop()
Training = 0
Flight = 0
if(!EFroze)
Frozen = 0
icon_state = null
Flight()
set background = 1
while(Flight)
var/Drain = 100 / (FlightMod * 5)
Energy -= Drain
if(Energy <= 0)
Energy = 0
usr << output("You have ran out of energy.","chat")
Stop()
return
sleep(15)
Training()
set background = 1
while(Training)
var/Drain = 25 / EnergyMod
Energy -= Drain
if(Energy <= 0)
Energy = 0
usr << output("You have ran out of energy.")
Stop()
return
var/stat = rand(1,8)
switch(stat)
if(1)
if(Strength >= (StrengthMod * Cap))
Strength = (StrengthMod * Cap)
else
Strength += (StrengthMod * (Rate * (Cap / 100)))
if(2)
if(Speed >= (SpeedMod * Cap))
Speed = (SpeedMod * Cap)
else
Speed += (SpeedMod * (Rate * (Cap / 100)))
if(3)
if(Endurance >= (EnduranceMod * Cap))
Endurance = (EnduranceMod * Cap)
else
Endurance += (EnduranceMod * (Rate * (Cap / 100)))
if(4)
if(Resistance >= (ResistanceMod * Cap))
Resistance = (ResistanceMod * Cap)
else
Resistance += (ResistanceMod * (Rate * (Cap / 100)))
if(5)
if(Offense >= (OffenseMod * Cap))
Offense = (OffenseMod * Cap)
else
Offense += (OffenseMod * (Rate * (Cap / 100)))
if(6)
if(Defense >= (DefenseMod * Cap))
Defense = (DefenseMod * Cap)
else
Defense += (DefenseMod * (Rate * (Cap / 100)))
if(7)
if(Force >= (ForceMod * Cap))
Force = (ForceMod * Cap)
else
Force += (ForceMod * (Rate * (Cap / 100)))
if(8)
if(prob(35))
if(Energy >= (EnergyMod * ECap))
Energy = (EnergyMod * ECap)
else
Energy += (EnergyMod * (ERate * (ECap / 100)))
sleep(20)
I'd recommend migrating any code that belongs to the mob into the mob. Rather than overriding 8 different movement button calls, just hook into client/Move(), then delegate to a new mob proc called canMove(), which will only be called by client-fed movements.
Also, the way you are managing states could do with a lot of refinement. This will get rid of a ton of boolean variables on the players and make creating ongoing action states much less of a headache.
The above code is going to save you a lot of time in the future. This will implement the general pattern of being in an ongoing state that prevents certain actions. Currently, states can prevent movement, be canceled by movement, and prevent starting other states. States will interrupt one another as you can only be in one state at a time. Before the next state starts, the player will immediately stop their ongoing state.
Also, I really recommend some generics for working with your stats:
So let's see what your code would look like using these three overhauls.
It may seem like quite a lot more, but the general structures are all much more robust and will allow for a much less spaghettified codebase.