namespace GOTHIC_ENGINE {
// Add your code here . . .
#define playerIsDead player->attribute[NPC_ATR_HITPOINTS] <= 0
#define infoFinished oCInformationManager::GetInformationManager().HasFinished()
static Timer mainTimer;
const int MANA_TIMER = 1;
const int HP_TIMER = 2;
int manaRegenSeconds;
float manaRegenPercent;
int hpRegenSeconds;
float hpRegenPercent;
bool needRegenMana;
bool needRegenHP;
bool needRegenInBattle;
void manaRegenGameInit() {
manaRegenPercent = min(zoptions->ReadInt("SIMPLE_REGEN", "manapercent", 2), 20);
manaRegenPercent /= 100;
manaRegenSeconds = (zoptions->ReadInt("SIMPLE_REGEN", "manaseconds", 1)) * 1000;
hpRegenPercent = min(zoptions->ReadInt("SIMPLE_REGEN", "hppercent", 2), 20);
hpRegenPercent /= 100;
hpRegenSeconds = (zoptions->ReadInt("SIMPLE_REGEN", "hpseconds", 1)) * 1000;
needRegenMana = zoptions->ReadBool("SIMPLE_REGEN", "needRegenMana", True);
needRegenHP = zoptions->ReadBool("SIMPLE_REGEN", "needRegenHP", True);
needRegenInBattle = zoptions->ReadBool("SIMPLE_REGEN", "needRegenInBattle", False);
}
void manaRegenGameLoop() {
if (!ogame || !player || playerIsDead || !infoFinished || ogame->pause_screen || ogame->singleStep)
return;
if (player->fmode && !needRegenInBattle) {
return;
}
if (needRegenMana && manaRegenSeconds > 0 && mainTimer[MANA_TIMER].Await(manaRegenSeconds)) {
int currenMana = player->GetAttribute(NPC_ATR_MANA);
int maxMana = player->GetAttribute(NPC_ATR_MANAMAX);
if (currenMana < maxMana) {
player->SetAttribute(NPC_ATR_MANA, min(ceil(currenMana + ((float)maxMana * manaRegenPercent)), maxMana));
}
}
if (needRegenHP && hpRegenSeconds > 0 && mainTimer[HP_TIMER].Await(hpRegenSeconds)) {
int currenHP = player->GetAttribute(NPC_ATR_HITPOINTS);
int maxHP = player->GetAttribute(NPC_ATR_HITPOINTSMAX);
if (currenHP < maxHP) {
player->SetAttribute(NPC_ATR_HITPOINTS, min(ceil(currenHP + ((float)maxHP * hpRegenPercent)), maxHP));
}
}
}
}