/* * @Author: dgflash * @Date: 2021-11-18 17:42:59 * @LastEditors: dgflash * @LastEditTime: 2022-08-17 12:36:18 */ import { Vec3, _decorator ,v3,Collider2D,Contact2DType,IPhysics2DContact,Prefab,instantiate} from "cc"; import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { CCComp } from "../../../../../extensions/oops-plugin-framework/assets/module/common/CCComp"; import { RoleSpine } from "./RoleSpine"; import { BoxSet } from "../../common/config/BoxSet"; import { smc } from "../../common/SingletonModuleComp"; import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops"; import { Timer } from "../../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer"; import { SkillCom } from "../../skills/SkillCom"; import { Skill } from "../../skills/Skill"; const { ccclass, property } = _decorator; /** 角色显示组件 */ @ccclass('RoleViewComp') // 定义为 Cocos Creator 组件 @ecs.register('RoleView', false) // 定义为 ECS 组件 export class RoleViewComp extends CCComp { as: RoleSpine = null!; hero_uuid:string = 'h001'; hero_name : string = "hero"; level:number =1; state: number = 1; /** 状态 1:move ,2: act 3: stop */ hp: number = 100; /** 血量 */ hp_max: number = 100; /** 最大血量 */ hp_speed: number = 0; //回复速度 power: number = 0; /**能量**/ power_max: number = 100; /** 能量最大值 */ power_speed: number = 1; //能量回复速度每0.1秒回复量 skill_name: string = "base"; //技能名称 max_skill_name: string = "base"; //大技能名称 atk: number = 10; /**攻击力 */ // atk_speed: number = 1; atk_cd: number = 2; /**攻击速度 攻击间隔 */ atk_time: number = 0; /** 冷却时间 */ stop_cd: number = 0; /*停止倒计时*/ is_dead:boolean = false; //是否摧毁 shield:number = 0; //护盾量 shield_time:number = 0; //护盾持续时间 private timer:Timer = new Timer(0.1); //计时器 onLoad() { this.as = this.getComponent(RoleSpine); } protected start(): void { let collider = this.getComponent(Collider2D); if (collider) { collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this); collider.on(Contact2DType.END_CONTACT, this.onEndContact, this); collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this); } } onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) { } onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) { // 只在两个碰撞体结束接触时被调用一次 } onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) { if(otherCollider.group== BoxSet.HERO_SKILL || otherCollider.group== BoxSet.MONSTER_SKILL){ let skill = otherCollider.node.getComponent(SkillCom)!; // console.log('onPostSolve',skill); this.in_atked(); // this.hp_change(skill.atk); } } update(dt: number){ if (this.timer.update(dt)) { } this.in_act(dt); } in_act(dt: number) { if(this.atk_time >= this.atk_cd){ this.atk_time = 0; // console.log("atk_cd:"+this.atk_cd); this.as.atk(); this.load_skill(this.skill_name); } this.atk_time += dt; } load_skill(skill_name:string){ let skill = ecs.getEntity(Skill); let pos = v3(30,30) let speed =400 let scale = 1 let range = 720 skill.load(pos,speed,range,scale,this.node,skill_name,this.atk); } in_atked() { var path = "game/skills/atked"; var prefab: Prefab = oops.res.get(path, Prefab)!; var node = instantiate(prefab); let pos = v3(0,30) node.setPosition(pos) node.parent = this.node; } reset() { this.node.destroy(); } }