103 lines
3.4 KiB
TypeScript
103 lines
3.4 KiB
TypeScript
|
import { Sprite } from 'cc';
|
||
|
import { _decorator, Component, Node } from 'cc';
|
||
|
import { GameGlobalData } from '../../global/GameGlobalData';
|
||
|
import { UmClientEvent } from '../../../../cc-common/cc-util/UmOneToMultiListener';
|
||
|
import { GameDefine } from '../../config/GameDefine';
|
||
|
import { UmLog } from '../../../../cc-common/cc-util/UmLog';
|
||
|
import { SkillActiveManagerUI } from '../skill-active/SkillActiveManagerUI';
|
||
|
const { ccclass, property } = _decorator;
|
||
|
|
||
|
@ccclass('HeroMana')
|
||
|
export class HeroMana extends Component {
|
||
|
@property(Sprite) manaProgress: Sprite = null!;
|
||
|
@property(SkillActiveManagerUI) skillActive: SkillActiveManagerUI = null!;
|
||
|
|
||
|
manaRecoveryTime: number = 10;
|
||
|
countTime: number = 0;
|
||
|
_tween: any;
|
||
|
isTurnOn = false;
|
||
|
isUsingSkill = false;
|
||
|
|
||
|
protected start(): void {
|
||
|
UmClientEvent.on(GameDefine.EVENT_END_JOYSTICK, this.onCheckCastActiveSkill.bind(this));
|
||
|
UmClientEvent.on(GameDefine.EVENT_START_USE_ACTIVE_SKILL, this.onStartUseActiveSkill.bind(this));
|
||
|
UmClientEvent.on(GameDefine.EVENT_END_USE_ACTIVE_SKILL, this.onEndUseActiveSkill.bind(this));
|
||
|
// UmClientEvent.on(GameDefine.EVENT_START_USE_SPECIAL_SKILL, this.onStartUseSkillSpecial.bind(this));
|
||
|
|
||
|
this.setManaRecoveryTime(GameGlobalData.Instance.heroData.heroDataInfo.manaRecoveryTime);
|
||
|
}
|
||
|
|
||
|
protected onDestroy(): void {
|
||
|
UmClientEvent.off(GameDefine.EVENT_END_JOYSTICK, this.onCheckCastActiveSkill.bind(this));
|
||
|
UmClientEvent.off(GameDefine.EVENT_START_USE_ACTIVE_SKILL, this.onStartUseActiveSkill.bind(this));
|
||
|
UmClientEvent.off(GameDefine.EVENT_END_USE_ACTIVE_SKILL, this.onEndUseActiveSkill.bind(this));
|
||
|
// UmClientEvent.off(GameDefine.EVENT_START_USE_SPECIAL_SKILL, this.onStartUseSkillSpecial.bind(this));
|
||
|
}
|
||
|
|
||
|
// onStartUseSkillSpecial()
|
||
|
// {
|
||
|
// this.resetManaTime();
|
||
|
// }
|
||
|
|
||
|
setManaRecoveryTime(time: number)
|
||
|
{
|
||
|
this.manaRecoveryTime = time;
|
||
|
}
|
||
|
|
||
|
resetManaTime()
|
||
|
{
|
||
|
this.countTime = 0;
|
||
|
this.isTurnOn = false;
|
||
|
GameGlobalData.Instance.isHeroManaReady = false;
|
||
|
}
|
||
|
|
||
|
protected update(dt: number): void {
|
||
|
if (!GameGlobalData.Instance.isStatePlay()) return;
|
||
|
|
||
|
if (this.countTime >= this.manaRecoveryTime) {
|
||
|
if (this.isTurnOn) return;
|
||
|
this.isTurnOn = true;
|
||
|
this.turnOnSpecialSkillAvailable();
|
||
|
|
||
|
return;
|
||
|
};
|
||
|
|
||
|
this.countTime += dt;
|
||
|
this.updateProgress(this.countTime / this.manaRecoveryTime);
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
updateProgress(progress: number)
|
||
|
{
|
||
|
this.manaProgress.fillRange = progress;
|
||
|
}
|
||
|
|
||
|
turnOnSpecialSkillAvailable()
|
||
|
{
|
||
|
UmLog.log("MANA FULL => READY");
|
||
|
// GameGlobalData.Instance.isHeroManaReady = true;
|
||
|
// UmClientEvent.dispatchEvent(GameDefine.EVENT_MANA_READY, true);
|
||
|
}
|
||
|
|
||
|
onCheckCastActiveSkill() {
|
||
|
var mana = GameGlobalData.Instance.timeToMana(this.countTime);
|
||
|
this.skillActive?.checkCastSkill(mana);
|
||
|
}
|
||
|
|
||
|
onStartUseActiveSkill(tag: number, manaUsed: number) {
|
||
|
this.isUsingSkill = true;
|
||
|
var mana = GameGlobalData.Instance.timeToMana(this.countTime);
|
||
|
mana -= manaUsed;
|
||
|
mana = Math.max(0, mana);
|
||
|
this.countTime = GameGlobalData.Instance.manaToTime(mana);
|
||
|
this.updateProgress(this.countTime / this.manaRecoveryTime);
|
||
|
}
|
||
|
|
||
|
onEndUseActiveSkill(tag: number, manaUsed: number) {
|
||
|
this.isUsingSkill = false;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|