game/js/hpregen.js

100 lines
2.6 KiB
JavaScript
Raw Normal View History

let timerHP = 0;
let lasttimeHP = 0;
let tt1 = '';
2022-06-06 21:30:34 +00:00
function startHpRegen(f, id, hpnow, hpmax, mpnow, mpmax, sec_h, sec_m, speed_hp, speed_mp, news, tmr) {
let d = document;
2022-06-06 21:30:34 +00:00
if (news !== 0) {
2022-06-06 21:30:34 +00:00
lasttimeHP++;
tmr = lasttimeHP;
timerHP = tmr;
}
if (news === 1 && tt1 !== undefined) {
2022-06-06 21:30:34 +00:00
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;
2022-06-06 21:30:34 +00:00
if (h1) {
const h2 = d.getElementById(`lhp${id}`);
if (h2) {
2022-06-06 21:30:34 +00:00
//Восстанавливаем НР
let newHP = sec_h * speed_hp;
2022-06-06 21:30:34 +00:00
function newHP_work(ifTrue) {
if (ifTrue) hpnow += newHP;
if (hpnow < 0) hpnow = 0;
if (hpnow > hpmax) hpnow = hpmax;
2022-06-06 21:30:34 +00:00
const formuleNewHP = Math.floor(hpnow / hpmax * widb1);
h1.innerHTML = ' ' + Math.floor(hpnow) + '/' + hpmax + '';
2022-06-06 21:30:34 +00:00
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
2022-06-06 21:30:34 +00:00
}
}
if (newHP !== 0) newHP_work(true)
else newHP_work(false)
2022-06-06 21:30:34 +00:00
}
}
//мана
if (m1) {
const m2 = d.getElementById(`lmp${id}`);
if (m2) {
//Восстанавливаем MP
let newMP = sec_m * speed_mp;
2022-06-06 21:30:34 +00:00
function newMP_work(ifTrue) {
if (ifTrue) mpnow += newMP;
if (mpnow < 0) mpnow = 0;
if (mpnow > mpmax) mpnow = mpmax;
2022-06-06 21:30:34 +00:00
const formuleNewMP = Math.floor(mpnow / mpmax * widb1);
m1.innerHTML = ' ' + Math.floor(mpnow) + '/' + mpmax + '';
2022-06-06 21:30:34 +00:00
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
}
2022-06-06 21:30:34 +00:00
}
if (newMP !== 0) newMP_work(true)
else newMP_work(false)
2022-06-06 21:30:34 +00:00
}
}
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);
2022-06-06 21:30:34 +00:00
}
}