Action RPG Framework

by Forum_account
Action RPG Framework
A framework for developing action RPGs.
ID:842983
 
This is a basic script to enable health and mana regeneration. You can configure the % of max that it should restore, as well as how often it restores. It's currently set to restore 1% health and 2% mana per second.

I also included two Conditions that you can apply, Wounded and Sapped, that will prevent health and mana regen respectively.

Constants
var
const
REGEN_HEALTH_PERCENT = 1
REGEN_MANA_PERCENT = 2

REGEN_TICK_LENGTH = 10

// Regen only on players, or monsters too?
REGEN_ONLY_PLAYERS = 1

world
New()
..()
spawn() tick_regen()

proc

tick_regen()
spawn(Constants.REGEN_TICK_LENGTH)
tick_regen()

var/regen

for(var/mob/M in world)
if(Constants.REGEN_ONLY_PLAYERS && !M.key)
continue

regen = max(1, round(M.max_health * Constants.REGEN_HEALTH_PERCENT / 100))
if(M.has_condition(/Condition/Wounded))
regen = 0

M.gain_health(regen)

regen = max(1, round(M.max_mana * Constants.REGEN_MANA_PERCENT / 100))
if(M.has_condition(/Condition/Sapped))
regen = 0

M.gain_mana(regen)


Condition

Wounded
tick_count = 4
tick_rate = 40

icon_state = "wounded"

tick()
target.effect("wounded")

Sapped
tick_count = 4
tick_rate = 40

icon_state = "sapped"

tick()
target.effect("sapped")

Thanks! I might put some of it in the framework since health and mana are defined there, it'd make sense to include support for regen. I'd probably make mob.health_regen() and mana_regen() procs that you can use to implement regen however you'd like. The sapped and wounded conditions would be in the sample game, to show how you can easily override the regen procs to add those effects.

There are a few things I'd change here. I don't like the idea of checking for a condition by type because you might want to have other conditions that also apply the effect. I'm not sure what the best way to handle this is but for now I'd probably make it work like the "slowed" condition. I'd also call the regen from the mob's movement() or action() proc - those procs are automatically called every tick for every active mob. That way you're using a loop that already exists and you're not bothering to check the regen for mobs on maps that aren't being used.