mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2025-03-22 02:02:30 +01:00
26 lines
595 B
TypeScript
26 lines
595 B
TypeScript
import { CONSTANTS } from "../Constants";
|
|
import { IPlayer } from "../PersonObjects/IPlayer";
|
|
|
|
export function getHospitalizationCost(p: IPlayer): number {
|
|
let money;
|
|
if (typeof p.money === "number") {
|
|
money = p.money;
|
|
} else {
|
|
money = p.money.toNumber();
|
|
}
|
|
|
|
if (money < 0) {
|
|
return 0;
|
|
}
|
|
|
|
return Math.min(money * 0.1, (p.max_hp - p.hp) * CONSTANTS.HospitalCostPerHp);
|
|
}
|
|
|
|
export function calculateHospitalizationCost(p: IPlayer, damage: number): number {
|
|
const oldhp = p.hp;
|
|
p.hp -= damage;
|
|
const cost = getHospitalizationCost(p);
|
|
p.hp = oldhp;
|
|
return cost;
|
|
}
|