一个全随机的刷装备小游戏
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
5.3 KiB

2 weeks ago
export const strengthenValue = (value, strengthenLv) => {
if (strengthenLv <= 0) {
return value;
}
const factor = 1.055 ** (strengthenLv ** 1.1);
return Math.round(factor * value);
};
/**
*
* @param playerAttribute
* @param rA
*/
export const callPlayerAttribute = (playerAttribute: any, rA: any) => {
const equips = [playerAttribute.weapon, playerAttribute.armor, playerAttribute.neck, playerAttribute.ring];
const curHp = playerAttribute.attribute.curHp,
hp = playerAttribute.attribute.hp;
const hpP = hp > 0 ? curHp / hp : 1;
const attribute = {
curHp: 0,
hp: 200 + rA.hp,
hpPercent: 0,
atk: rA.atk,
atkPercent: 0,
def: rA.def,
defPercent: 0,
reducPercent: 0,
bloc: rA.bloc,
blocPercent: 0,
eva: 0,
crit: rA.crit,
critDmg: 150 + rA.critDmg, // 初始暴击伤害150%
dps: 0,
};
const entry = new Array();
equips.forEach((equip) => {
equip && Array.prototype.push.apply(entry, equip.extraEntry);
equip && Array.prototype.push.apply(entry, strengthenEntry(equip));
});
entry.forEach((item) => {
const key = item.type;
attribute[key] += item.value;
});
// 暴击率最多100%
if (attribute.crit > 100) {
attribute.crit = 100;
}
//计算最终属性
attribute.hp = Math.ceil(attribute.hp * (1 + attribute.hpPercent / 100));
attribute.curHp = Math.ceil(attribute.hp * hpP);
attribute.atk = Math.ceil(attribute.atk * (1 + attribute.atkPercent / 100));
attribute.def = Math.ceil(attribute.def * (1 + attribute.defPercent / 100));
attribute.bloc = Math.ceil(attribute.bloc * (1 + attribute.blocPercent / 100));
const arr = ['hp', 'curHp', 'atk', 'def', 'bloc', 'eva'];
arr.forEach((key) => {
attribute[key] = Math.round(attribute[key]);
});
//计算秒伤
const atk = attribute.atk,
crit = attribute.crit / 100,
critdmg = attribute.critDmg / 100;
attribute.dps = Math.ceil((1 - crit + crit * critdmg) * atk);
//计算减伤比例
// attribute.def = 500;
2 weeks ago
attribute.reducPercent = (0.5 * attribute.def) / (35 + 0.55 * attribute.def) + (0.09 * attribute.def) / (attribute.def + 200);
// attribute.reducPercent = (0.5 * attribute.def) / (200 + 0.502 * attribute.def);
2 weeks ago
return attribute;
};
const strengthenEntry = (equip) => {
const temp = deepCopy(equip.base.entry);
temp.forEach((item) => {
item.value = strengthenValue(item.value, equip.strengthenLv);
});
return temp;
};
export const deepCopy = (src) => {
if (!src) {
return null;
}
return JSON.parse(JSON.stringify(src));
};
/**
*
* @param equip
* @returns
*/
export const conisOfBuy = (equip) => {
if (!equip) {
return 0;
}
return Math.round(equip.lv * equip.quality.qualityCoefficient * (250 + 20 * equip.lv));
};
/**
*
* @param equip
* @returns
*/
export const conisOfsell = (equip) => {
if (!equip) {
return 0;
}
return Math.round(equip.lv * equip.quality.qualityCoefficient * 30);
};
export const getPointsOfReborn = (playerAttribute) => {
const lv = playerAttribute.lv;
let points = lv >= 20 ? Math.floor((lv - 20) ** 1.1 / 2.1) : 0;
const euqips = [playerAttribute.weapon, playerAttribute.armor, playerAttribute.neck, playerAttribute.ring];
euqips.forEach((equip) => {
if (!equip) {
return;
}
const wlv = equip.lv;
const elv = equip.enchantlvl || 0;
const q = equip.quality.qualityCoefficient;
if (wlv >= 20) {
points += Math.floor((((wlv - 20) / 10) ** 1.1 * (0.1 * elv ** 1.5 + 1) * q) / 3.5);
}
});
return Math.round(points * 1.2);
};
export const callBattleResult = (player, monster) => {
const tmp = player.curHp,
crit = player.crit / 100,
critdmg = player.critDmg / 100,
atk = player.atk;
let monsterDmg = Math.ceil(monster.atk * (1 - player.reducPercent) - player.bloc);
monsterDmg < 1 && (monsterDmg = 1);
let curHp = player.curHp,
mHp = monster.hp;
const bouts: any = [];
while (true) {
const bout: any = {};
bouts.push(bout);
if (Math.random() < crit) {
bout.crit = true;
bout.dmg = Math.ceil(atk * critdmg);
} else {
bout.dmg = atk;
}
mHp -= bout.dmg;
if (mHp < 0) break;
bout.takeDmg = monsterDmg;
curHp -= monsterDmg;
if (curHp < 0) break;
}
return { win: curHp > 0, bouts: bouts, takeDmg: tmp - curHp };
};
export const callEuqipTipsLocation = (e, mobile) => {
const x = e.pageX,
y = e.pageY,
maxH = window.innerHeight,
maxW = window.innerWidth,
tipsStyle: any = {},
tipsStyle2: any = {};
if (mobile) {
tipsStyle.left = '0.3rem';
tipsStyle2.left = '13.9rem';
const num = 10;
if (y < maxH / 2) {
tipsStyle.top = y + num + 'px';
tipsStyle2.top = y + num + 'px';
} else {
tipsStyle.bottom = maxH - y - num + 'px';
tipsStyle2.bottom = maxH - y - num + 'px';
}
} else {
if (x < maxW / 2) {
tipsStyle.left = x + 'px';
tipsStyle2.left = 'calc(' + x + 'px + 21rem)';
} else {
tipsStyle.right = maxW - x + 'px';
tipsStyle.right2 = 'calc(' + tipsStyle.righ + ' - 21rem)';
}
if (y < maxH / 2) {
tipsStyle.top = y + 'px';
tipsStyle2.top = y + 'px';
} else {
tipsStyle.bottom = maxH - y + 'px';
tipsStyle2.bottom = maxH - y + 'px';
}
}
return [tipsStyle, tipsStyle2];
};