
import { LQCollide } from "../../../lq_collide_system/lq_collide";
import { LQCollideBase } from "../../../lq_collide_system/lq_collide_base";
import { LQCollideInfoList } from "../../../lq_collide_system/lq_collide_config";
import { MonsterModel } from "../monster/monsterModel";
import { EffectMgr } from "../nest/effectMgr";



const {ccclass, property, requireComponent} = cc._decorator;
@ccclass
@requireComponent(LQCollideBase)
export default class bullet extends LQCollide {

    atk:number = 10;

    /*===========================自动绑定组件开始===========================*/
	/*自动生成*/
    @property({type:dragonBones.ArmatureDisplay, displayName:""})
    private $dragon_bone:dragonBones.ArmatureDisplay = null;

	/*===========================自动绑定组件结束===========================*/

    /*===========================自动生成按钮事件开始==========================*/

	/*===========================自动生成按钮事件结束==========================*/

    protected onLoad(): void {
        this.$dragon_bone.playAnimation('appear', 1);
        this.$dragon_bone.addEventListener('complete', ()=>{
            this.$dragon_bone.playAnimation('bullet_1', 0);
        });
    }

    public on_enter(collide: LQCollide): void {
        // cc.log(collide);
        
        if(collide.collide_group_index == LQCollideInfoList.enemy) {
            // cc.log('@@ -- ', collide.node.name);
            let worldPos = this.node.convertToWorldSpaceAR(cc.Vec2.ZERO);
            EffectMgr.inst.createHarmNum(worldPos, this.atk);

            let model = collide.node.getComponent(MonsterModel);
            model.beAttacked(this.atk);
            if(model.isOver()){
                collide.node.destroy();
            }
        }
        this.node.destroy();
    }

    setDirction(dir: cc.Vec2){
        let angle = cc.v2(0,1).signAngle(dir) / Math.PI * 180;
        this.node.angle = angle;
    }
}