import { _decorator, Component, Node } from 'cc'; import { GameGlobalData } from '../../global/GameGlobalData'; import { LayoutManager } from '../LayoutManager'; import { HPBar } from '../../game_ui/HPBar'; import { GameDefine } from '../../config/GameDefine'; import { UmLog } from '../../../../cc-common/cc-util/UmLog'; const { ccclass, property } = _decorator; @ccclass('HeroHPHeal') export class HeroHPHeal extends Component { hpHeal = 2; countTime = 0; setStartHPHeal(hpHeal: number) { this.countTime = 0; this.setHPHealValue(hpHeal); } setHPHealValue(value: number) { this.hpHeal = value; } get hpBar(): HPBar { return LayoutManager.instance.GameUI.getHeroHPBar(); } protected update(dt: number): void { if (!GameGlobalData.Instance.isStatePlay()) return; this.countTime += dt; var hpCollect = this.timeToHP(this.countTime); if (hpCollect >= 1) { this.hpBar.increaseHP(1); hpCollect -= 1; this.countTime = this.hpToTime(hpCollect); } } timeToHP(time: number): number { return time * GameDefine.HPHEAL_UNIT * this.hpHeal; } hpToTime(hp: number) { return hp / GameDefine.HPHEAL_UNIT; } }