ID:271439
 
I have a pretty detailed attack system in my game now, but what good is it if people just have to spam a macro to use it? This is what I want and I can't quite foreplan a solution;

I have just implemented a targetting system that is mouse based, you can click on npc's monster npc's and playable characters. I also implemented a verb that alternates between a 'war mode' being on and off. My hope is to create a continuous proc that will check for war mode and - if the users weapon delay has elapsed - will check the range, then attack the target if it is within range, I am sure is is simple but having background protocols is something that makes me nervous as I don't want to slow down the game. any input would be greatly appreciated.

also time based regeneration, how would I go about accomplishing this as a looping proc, and would implementing procs like this put a strain on the server?
Perilous Knight wrote:
I have a pretty detailed attack system in my game now, but what good is it if people just have to spam a macro to use it? This is what I want and I can't quite foreplan a solution;

I have just implemented a targetting system that is mouse based, you can click on npc's monster npc's and playable characters. I also implemented a verb that alternates between a 'war mode' being on and off. My hope is to create a continuous proc that will check for war mode and - if the users weapon delay has elapsed - will check the range, then attack the target if it is within range, I am sure is is simple but having background protocols is something that makes me nervous as I don't want to slow down the game. any input would be greatly appreciated.

also time based regeneration, how would I go about accomplishing this as a looping proc, and would implementing procs like this put a strain on the server?

I used both concepts in a game/test world that I created last year. Accomplishing the combat loop can be a bit of a pain - you 'definitely' (That's for you Lummox) don't want to have the loop running all the time in the background. Only while they're in combat mode. Basically what you want is something that looks like this:

mob/var
in_combat = FALSE
mob/target = null

mob/Bump(mob/M)
..()
if(istype(M, /mob))
if(M.alignment != src.alignment)
src.Engage(M)

mob/proc/Engage(mob/M, delay=0)
spawn(delay)
if(M)
src.target = M
if(!src.in_combat)
src.CombatLoop()
return

mob/proc/CombatLoop()
src.in_combat = TRUE
while((get_dist(src, src.target) <= 1) && !(src.flags & DEAD))
if(src.target)
src.Attack(src.target)
sleep(max(src.attk_spd, 6))
src.target = null
src.in_combat = FALSE
return


Mind you that's taken from my game so you'll have to modify it to fit your own. But its just a general idea.

Regeneration loops are similar. You can either have them running all the time if they're slow updates that give a decent amount of health (if you get 10% of your health back every 60 seconds, for example). Or if you have it so you get 1 hit points back every second, then you'll probably not want it running in the background all the time. Best to check to see if they need to start regenerating when they're attacked, and if they do, start a loop that continues until they don't need to regenerate anymore.

mob/var/regenerating = FALSE

mob/proc/Regenerate()
// If the mob already has full health or has already
// started its regeneration loop, don't start another loop.
if(src.hp >= src.maxhp || src.regenerating)
return

src.regenerating = TRUE

while(src.hp < src.maxhp)
src.hp++
sleep(10)

src.regenerating = FALSE


And if I may say, I do think that combat loop system works much better than any click/macro/repeat-bumping attack systems.
In response to Foomer
Thanks Foomer,

The reason I am choosing not to have a macro based attack system is for continuity. My archery system would be difficult if people had to select from a list of people every time they wanted to attack, so I decided to allow my present combat proc serve for both. And using range a person can select a target and shoot it even if it is running around the screen. The same goes for melee combat. I have seen in other games where people can indefinitely dodge melee attacks by thumping arrows. This way if the person is in the square next to you for any time at all, they will have the combat proc called on them. Also it will most likely extend the life of the 'A' button on many peoples keyboards.
In response to Perilous Knight
Here's my own take on this system.

mob
var
attackspeed = 10
damage = 0
range = 1
health = 10
tmp/nextattack = 0 //important that this is a tmp variable
tmp/mob/target //also this
proc
attackLoop()
//while we have a target and they're close enough to see (ignoring LOS)
while(target && get_dist(src,target) < world.view)
//make sure that it's time to make a new attack: it may be changed by outside sources
if(world.time > nextattack)
//attempt to take a swing at them
attack(target)
//sleep until our next attack, ensuring we have at least SOME delay
var/t = max(nextattack - world.time, 1)
sleep(t)

attack(var/mob/M)
//if M is in range
if(get_dist(src,M) <= range)
//take a swing at them
var/damage = src.damage //obviously a real formula would go here
oview(src) << "[src] hits [M] for [damage]"
M.hurt(src, damage)
//reset our swing timer, regardless of whether we made an attack or not
nextattack = world.time + attackspeed

hurt(var/mob/hurter, var/damage)
health -= damage
if(health < 0)
die(hurter)

die(var/mob/murderer)
if(murderer)
oview(src) << "[src] was killed by [murderer]"
else
oview(src) << "[src] has died"
del(src)