import { getAtkTarget } from "../atkTarget";
import { getSkillConf, randNumber } from "../fightFun";
import { EmitDataType } from "../fightType";
import { PassiveSkillBase } from "./passiveSkillBase";

export class PassiveSkill_runskill extends PassiveSkillBase {
    start() {
        /** 后续 扩展被动触发*/
        super.start();
    }

    doAtk(emitData: EmitDataType) {
        super.doAtk(emitData);
        let skills = this.skillConf.v.runskill;
        let role = this.skillInfo.toRole;

        skills.forEach((_skillId: string, k) => {
            let askillConf = getSkillConf(_skillId);
            if (!askillConf) return console.error('####没有技能id-->', _skillId);
            askillConf = JSON.parse(JSON.stringify(askillConf));
            askillConf.skillid = _skillId;
            let gailv = askillConf.randnum;
            if (!gailv || randNumber() > gailv) return;

            let targets;
            if(askillConf.side == '6'){
                // 主动技能通过doatk，可能触发N个随机的目标，这里的fromRole是指每一个被主动技能选中的目标
                targets = [emitData.fromRole];
            }else{
                targets = getAtkTarget(role.fightControl, role, askillConf);
            }

            targets.forEach(_target => {
                _target.runAfterSkill({
                    fromRole: role,
                    toRole: _target,
                    fromSkill: null,
                    skillConf: askillConf,
                    targetCount: targets.length,
                    emitData: emitData
                }, 'PassiveSkill_runskill');
            });


        });

    }
}