UserSkillBase.ts 1.09 KB
import { SaveDataManager } from "../../../component/SaveDataManager";
import { SoundManager } from "../../../component/SoundManager";
import { SoundName } from "../../../Global";
import { Battle } from "../Battle";
import { BattleEvent, UserSkill } from "../BattleConst";
import { BattleManager } from "../BattleManager";

export class UserSkillBase {

    protected _battle: Battle;
    private _skillId: UserSkill = UserSkill.NONE;

    constructor(battle: Battle, skillId: UserSkill) {
        this._battle = battle;
        this._skillId = skillId;
    }

    start(free: boolean = false): boolean {

        //解锁与否完全由关卡控制

        let num = SaveDataManager.ins.getUserSkillNum(this._skillId);

        if (num > 0 || free) {
            !free && SaveDataManager.ins.setUserSkillNumDelta(this._skillId, -1);
            this.dispatchEvent();

            SoundManager.ins.playEffect(SoundName.USE_ITEM);
            return true;
        }

        return false;
    }

    protected dispatchEvent() {
        BattleManager.ins.eventNode.emit(BattleEvent.SKILL_START, this._skillId);
    }
}