HumanBreak/src/plugin/utils.ts

28 lines
727 B
TypeScript
Raw Normal View History

2022-11-16 23:01:23 +08:00
import { isNil } from 'lodash';
export default function init() {
return { has, getDamageColor };
}
/**
* undefined或null
* @param value
*/
export function has<T>(value: T): value is NonNullable<T> {
return !isNil(value);
}
/**
*
* @param damage
*/
export function getDamageColor(damage: number): string {
if (typeof damage !== 'number') return '#f00';
if (damage === 0) return '#2f2';
if (damage < 0) return '#7f7';
if (damage < core.status.hero.hp / 3) return '#fff';
if (damage < (core.status.hero.hp * 2) / 3) return '#ff4';
if (damage < core.status.hero.hp) return '#f22';
return '#f00';
}