game/js/hpregen.js

100 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

let timerHP = 0;
let lasttimeHP = 0;
let tt1 = '';
function startHpRegen(f, id, hpnow, hpmax, mpnow, mpmax, sec_h, sec_m, speed_hp, speed_mp, news, tmr) {
let d = document;
if (news !== 0) {
lasttimeHP++;
tmr = lasttimeHP;
timerHP = tmr;
}
if (news === 1 && tt1 !== undefined) {
clearTimeout(tt1);
}
if (lasttimeHP !== tmr) {
return;
}
if (f === 'top') d = top.document;
else if (f === 'main') d = top.frames['main'].document;
if (d !== undefined && lafstReg[id]) {
//здоровье
const h1 = d.getElementById(`vhp${id}`);
const m1 = d.getElementById(`vmp${id}`);
const widb1 = h1 ? parseInt(h1.style.width) : 0;
if (h1) {
const h2 = d.getElementById(`lhp${id}`);
if (h2) {
//Восстанавливаем НР
let newHP = sec_h * speed_hp;
function newHP_work(ifTrue) {
if (ifTrue) hpnow += newHP;
if (hpnow < 0) hpnow = 0;
if (hpnow > hpmax) hpnow = hpmax;
const formuleNewHP = Math.floor(hpnow / hpmax * widb1);
h1.innerHTML = ' ' + Math.floor(hpnow) + '/' + hpmax + '';
switch (true) {
case (formuleNewHP < 1):
h2.className = 'hp_none';
case (formuleNewHP > 0):
h2.className = 'hp_1';
case (formuleNewHP > 32):
h2.className = 'hp_2';
case (formuleNewHP > 65):
h2.className = 'hp_3';
case (formuleNewHP <= widb1):
h2.style.width = `${formuleNewHP}px`;
break
}
}
if (newHP !== 0) newHP_work(true)
else newHP_work(false)
}
}
//мана
if (m1) {
const m2 = d.getElementById(`lmp${id}`);
if (m2) {
//Восстанавливаем MP
let newMP = sec_m * speed_mp;
function newMP_work(ifTrue) {
if (ifTrue) mpnow += newMP;
if (mpnow < 0) mpnow = 0;
if (mpnow > mpmax) mpnow = mpmax;
const formuleNewMP = Math.floor(mpnow / mpmax * widb1);
m1.innerHTML = ' ' + Math.floor(mpnow) + '/' + mpmax + '';
switch (true) {
case (formuleNewMP < 1):
m2.className = 'hp_none';
case (formuleNewMP !== 1):
m2.className = 'hp_mp';
case (formuleNewMP <= widb1):
m2.style.width = `${formuleNewMP}px`;
break
}
}
if (newMP !== 0) newMP_work(true)
else newMP_work(false)
}
}
lafstReg[id] = 0 + lafstReg[id] + 1;
tt1 = setTimeout(`top.startHpRegen("${f}", ${id}, ${hpnow}, ${hpmax}, ${mpnow}, ${mpmax}, 1, 1, ${speed_hp}, ${speed_mp}, 0, ${timerHP});`, 1000);
}
if (!lafstReg[id]) {
lafstReg[id] = 0 + lafstReg[id] + 1;
tt1 = setTimeout(`top.startHpRegen("${f}", ${id}, ${hpnow}, ${hpmax}, ${mpnow}, ${mpmax}, 1, 1, ${speed_hp}, ${speed_mp}, 0, ${timerHP});`, 1000);
}
}