Files
heros/assets/script/game/skills/SkillCom.ts
2025-01-09 16:45:45 +08:00

109 lines
3.8 KiB
TypeScript

import { _decorator,Collider2D ,Contact2DType,v3,IPhysics2DContact,Vec3, tween, math} 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 { BoxSet } from "../common/config/BoxSet";
import { smc } from "../common/SingletonModuleComp";
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
import { HeroViewComp } from "../hero/HeroViewComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { GameEvent } from "../common/config/GameEvent";
import { SkillSet } from "../common/config/SkillSet";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@ccclass('SkillCom')
@ecs.register('SkillView', false)
export class SkillCom extends CCComp {
s_uuid:number = 0;
s_name:string = "";
speed:number = 200;
scale:number = 1;
ap:number = 10;
cd:number = 1;
debuff:number = 0;
debtime:number = 0;
depb:number = 0;
derate:number = 0;
atk_count:number = 0;
is_crit:boolean = false;
crit_add: number = 0;//暴击伤害加成
angle:number = 0;
t_pos:Vec3 = v3(0,0,0); // 目标增量
is_destroy:boolean = false;
box_group:number = 0;
box_tag:number=0;
type:number = 1;
run:number = 0;
tg:number = 3;
in_time:number = 0.3; // 不动技能持续时间
enemys:any = [];
start() {
oops.message.on(GameEvent.MissionEnd, this.doDestroy, this);
this.node.active=true
let collider = this.getComponent(Collider2D);
collider.group = this.box_group;
collider.tag = this.box_tag;
collider.sensor = true;
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 (seCol: Collider2D, otCol: Collider2D, contact: IPhysics2DContact | null) {
if(otCol.group != seCol.group&&otCol.tag ==0){
this.atk_count+=1
if(this.run==1 ){
this.is_destroy=true
}
}
if(otCol.group == seCol.group&&otCol.tag ==0&&(this.tg==2||this.tg==0)){
this.to_console("skill onBeginContact 是对自己人的buff",seCol,otCol)
this.do_buff(otCol.node.getComponent(HeroViewComp))
}
}
to_console(value:any,value2:any=null,value3:any=null){
console.log("["+this.s_name+this.s_uuid+"]:",value,value2,value3)
}
do_buff(hero:any){
this.to_console(" do_buff hero: ",hero)
if(SkillSet[this.s_uuid].hp > 0){ //buff加血
let increase_hp=Math.floor(SkillSet[this.s_uuid].hp*this.ap/(this.in_time/this.cd))
hero.add_hp(increase_hp)
}
if(SkillSet[this.s_uuid].apup > 0){ //buff加攻击
let increase_atk=Math.floor(SkillSet[this.s_uuid].apup*this.ap/(this.in_time/this.cd))
hero.add_ap(increase_atk)
}
if(SkillSet[this.s_uuid].shield > 0){ //buff护盾
console.log("do_buff shield: ",SkillSet[this.s_uuid].shield*this.ap/(this.in_time/this.cd))
hero.add_shield(SkillSet[this.s_uuid].shield)
}
}
update(deltaTime: number) {
if(smc.mission.pause) return
this.toDestroy()
}
toDestroy() {
if(this.is_destroy){
this.ent.destroy()
}
}
doDestroy(){
this.is_destroy=true
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.is_destroy=false
this.node.destroy();
}
}