技能系统还要,伤害逻辑交给碰撞系统处理

This commit is contained in:
2025-03-26 13:49:11 +08:00
parent ae30a865c7
commit 4335a8500b
4 changed files with 35 additions and 121 deletions

View File

@@ -55,22 +55,10 @@ export class Hero extends ecs.Entity {
hv.hero_name= hero.name; hv.hero_name= hero.name;
hv.speed =hv.ospeed = hero.speed; hv.speed =hv.ospeed = hero.speed;
hv.dis = hero.dis; hv.dis = hero.dis;
hv.pw = hero.pw;
hv.pwm= hero.pwm;
hv.pws= hero.pws
hv.apw=hero.apw;
hv.uapw=hero.uapw;
hv.cpw=hero.cpw;
hv.dpw=hero.dpw;
hv.dopw=hero.dopw;
let slv= Math.floor(( hv.lv) / 5);
hv.hp= hv.hp_max =hero.hp; hv.hp= hv.hp_max =hero.hp;
hv.ap = hero.ap; hv.ap = hero.ap;
hv.def= hero.def;
hv.cd = hero.a_cd hv.cd = hero.a_cd
hv.crit = hero.crit; //暴击率 hv.atk_skill=hero.skills[0]
hv.crit_add = hero.crit_add;//暴击伤害加成
hv.dodge = hero.dodge; //闪避率
this.add(hv); this.add(hv);
// 初始化多个技能组件 // 初始化多个技能组件

View File

@@ -52,44 +52,16 @@ export class HeroViewComp extends CCComp {
hp_max: number = 100; /** 最大血量 */ hp_max: number = 100; /** 最大血量 */
hp_speed: number = 0; //每秒回复量 hp_speed: number = 0; //每秒回复量
pw: number = 0; // 当前能量值
pwm: number = 100; // 最大能量值
pws: number = 1; //能量回复速度每0.1秒回复量
apw:number=0;
uapw:number=0;
cpw:number=0;
dopw:number=0;
dpw:number=0;
pwt:Timer = new Timer(1); //计时器 pwt:Timer = new Timer(1); //计时器
akr:number=0; //攻击触发机率
uar:number=0; //受伤触发机率
dgr:number=0; //闪避触发机率
crr:number=0; //暴击触发机率
akc:number=0; //攻击次数触发
uac:number=0; //受伤次数触发
dgc:number=0; //闪避次数触发
crc:number=0; //暴击次数触发
aexp:number=0; //攻击经验
uaexp:number=0; //受伤经验
cexp:number=0; //暴击经验 */
doexp:number=0; //闪避经验 */
dexp:number=0; //死亡经验 */
ap: number = 10; /**攻击力 */ ap: number = 10; /**攻击力 */
ap_buff: number = 0;
ap_buffs:any = [];
// atk_speed: number = 1; // atk_speed: number = 1;
cd: number = 1.3; /**攻击速度 攻击间隔 */ cd: number = 1.3; /**攻击速度 攻击间隔 */
dis: number = 80; dis: number = 80;
at: number = 0; /** 冷却时间 */ at: number = 0; /** 冷却时间 */
atk_skill:number=0;
def: number = 0; //防御 def: number = 0; //防御
vun: number = 0; //易伤 vun: number = 0; //易伤
crit: number = 0; //暴击率
crit_add: number = 0;//暴击伤害加成
dodge: number = 10; //闪避率 dodge: number = 10; //闪避率
@@ -99,9 +71,6 @@ export class HeroViewComp extends CCComp {
atk_count: number = 0; atk_count: number = 0;
atked_count: number = 0; atked_count: number = 0;
dodge_count: number = 0;
crit_count: number = 0;
stop_cd: number = 0; /*停止倒计时*/ stop_cd: number = 0; /*停止倒计时*/
yun_cd: number = 0; //眩晕倒计时 yun_cd: number = 0; //眩晕倒计时
@@ -139,18 +108,12 @@ export class HeroViewComp extends CCComp {
} }
onBeginContact (seCol: Collider2D, oCol: Collider2D) { onBeginContact (seCol: Collider2D, oCol: Collider2D) {
console.log("碰撞开始 ",this.scale,seCol,oCol); console.log("碰撞开始 ",this.scale,seCol,oCol);
}
onEndContact (seCol: Collider2D, oCol: Collider2D) {
console.log("碰撞结束 ",this.scale,seCol,oCol);
}
onPreSolve (seCol: Collider2D, oCol: Collider2D) {
console.log("碰撞预处理 ",this.scale,seCol,oCol);
}
onPostSolve (seCol: Collider2D, oCol: Collider2D) {
console.log("碰撞后处理 ",this.scale,seCol,oCol);
} }
onEndContact (seCol: Collider2D, oCol: Collider2D) { console.log("碰撞结束 ",this.scale,seCol,oCol);}
onPreSolve (seCol: Collider2D, oCol: Collider2D) {console.log("碰撞预处理 ",this.scale,seCol,oCol);}
onPostSolve (seCol: Collider2D, oCol: Collider2D) {console.log("碰撞后处理 ",this.scale,seCol,oCol); }
/** 视图层逻辑代码分离演示 */ /** 视图层逻辑代码分离演示 */
start () { start () {
@@ -172,9 +135,6 @@ export class HeroViewComp extends CCComp {
if(!this.in_grave()) this.to_grave() if(!this.in_grave()) this.to_grave()
return return
} }
if (this.pwt.update(dt)) {
this.pw+=this.pws
}
this.hp_show() this.hp_show()
if(this.ice_cd > 0){ if(this.ice_cd > 0){
this.ice_cd -=dt; this.ice_cd -=dt;
@@ -240,27 +200,6 @@ export class HeroViewComp extends CCComp {
this.ap -= Math.floor(ap); this.ap -= Math.floor(ap);
this.BUFFCOMP.buff_get("deap") this.BUFFCOMP.buff_get("deap")
} }
add_def(def: number){
this.def += Math.floor(def);
this.BUFFCOMP.buff_get("def")
}
de_def(def: number){
this.def -= Math.floor(def);
this.BUFFCOMP.buff_get("dedef")
}
/**
* 增加英雄的暴击率。
* @param crit 要增加的暴击率。
*/
add_crit(critRate: number) {
this.crit += Math.floor(critRate);
this.BUFFCOMP.buff_get("crit");
}
de_crit(critRate: number) {
this.crit += Math.floor(critRate);
this.BUFFCOMP.buff_get("decrit");
}
/** /**
* 增加英雄的闪避率。 * 增加英雄的闪避率。
* @param dodge 要增加的闪避率。 * @param dodge 要增加的闪避率。
@@ -294,7 +233,6 @@ export class HeroViewComp extends CCComp {
this.hp += Math.floor(hprate/100*this.hp_max) ; this.hp += Math.floor(hprate/100*this.hp_max) ;
} }
/** 静止时间 */ /** 静止时间 */
in_stop (dt: number) { in_stop (dt: number) {
if(this.stop_cd > 0){ if(this.stop_cd > 0){
@@ -315,9 +253,6 @@ export class HeroViewComp extends CCComp {
let Drops = getMonsterDrops(1, MonsterType.Normal, 1.2); let Drops = getMonsterDrops(1, MonsterType.Normal, 1.2);
if(this.is_boss) Drops =getMonsterDrops(1, MonsterType.Elite, 1.2); if(this.is_boss) Drops =getMonsterDrops(1, MonsterType.Elite, 1.2);
if(this.is_big_boss) Drops =getMonsterDrops(1, MonsterType.Boss, 1.2); if(this.is_big_boss) Drops =getMonsterDrops(1, MonsterType.Boss, 1.2);
} }
//进入墓地 //进入墓地
to_grave(){ to_grave(){
@@ -329,13 +264,11 @@ export class HeroViewComp extends CCComp {
in_grave(){ in_grave(){
return this.node.position.y <= -900; return this.node.position.y <= -900;
} }
to_alive(){ to_alive(){
let pos =v3(HeroSet.StartPos[this.type],this.node.position.y,this.node.position.z) let pos =v3(HeroSet.StartPos[this.type],this.node.position.y,this.node.position.z)
this.node.setPosition(pos) this.node.setPosition(pos)
this.revive() this.revive()
} }
to_console(value:any,value2:any=null,value3:any=null){ to_console(value:any,value2:any=null,value3:any=null){
console.log("["+this.scale+this.hero_name+']'+value,value2,value3) console.log("["+this.scale+this.hero_name+']'+value,value2,value3)
} }
@@ -343,7 +276,6 @@ export class HeroViewComp extends CCComp {
this.is_dead = false; this.is_dead = false;
this.node.destroy(); this.node.destroy();
} }
playSkillEffect(skill_id:number) { playSkillEffect(skill_id:number) {
let skill = SkillSet[skill_id] let skill = SkillSet[skill_id]
switch(skill.act){ switch(skill.act){
@@ -357,7 +289,6 @@ export class HeroViewComp extends CCComp {
break break
} }
} }
public revive() { public revive() {
this.hp = this.hp_max; this.hp = this.hp_max;
const skills = this.ent.get(HeroSkillsComp); const skills = this.ent.get(HeroSkillsComp);

View File

@@ -28,7 +28,7 @@ export class HeroSkillSystem extends ecs.ComblockSystem implements ecs.ISystemUp
update(e: ecs.Entity) { update(e: ecs.Entity) {
return false //return false
// 处理伤害队列 // 处理伤害队列
this.processDamageQueue(); this.processDamageQueue();
const view = e.get(HeroViewComp); const view = e.get(HeroViewComp);

View File

@@ -1,4 +1,4 @@
import { _decorator,Collider2D ,Contact2DType,v3,IPhysics2DContact,Vec3, tween, math} from "cc"; import { _decorator,Collider2D ,Contact2DType,v3,IPhysics2DContact,Vec3, tween, math, RigidBody2D} from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp"; import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { smc } from "../common/SingletonModuleComp"; import { smc } from "../common/SingletonModuleComp";
@@ -29,36 +29,31 @@ export class SkillCom extends CCComp {
targetPos: Vec3 = v3(); // 目标位置 targetPos: Vec3 = v3(); // 目标位置
duration: number = 0; // 技能持续时间 duration: number = 0; // 技能持续时间
prefabName: string = ""; // 预制体名称 prefabName: string = ""; // 预制体名称
animName: string = "";
group:number = 0; //阵营 group:number = 0; //阵营
animName: string = ""; // 动画名称 rigid:RigidBody2D=null!; // 动画名称
box_group:number = 0; //碰撞组
protected onLoad(): void { protected onLoad(): void {
let collider = this.getComponent(Collider2D);
collider.group = this.group;
let collider = this.getComponent(Collider2D); // console.log("hero collider ",this.scale,collider);
collider.group = this.box_group; if (collider) {
// console.log("hero collider ",this.scale,collider); collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
if (collider) { // collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this); collider.on(Contact2DType.PRE_SOLVE, this.onPreSolve, this);
// collider.on(Contact2DType.END_CONTACT, this.onEndContact, this); // collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
collider.on(Contact2DType.PRE_SOLVE, this.onPreSolve, this); }
// collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this); this.rigid = this.getComponent(RigidBody2D);
} if(this.rigid.sleep){
console.log("hero rigid sleep ",this.scale,this.rigid);
} this.rigid.wakeUp();
onBeginContact (seCol: Collider2D, oCol: Collider2D) { }
}
} onBeginContact (seCol: Collider2D, oCol: Collider2D) {
console.log("碰撞开始 ",this.scale,seCol,oCol);
onEndContact (seCol: Collider2D, oCol: Collider2D) { }
onEndContact (seCol: Collider2D, oCol: Collider2D) { console.log("碰撞结束 ",this.scale,seCol,oCol);}
} onPreSolve (seCol: Collider2D, oCol: Collider2D) {console.log("碰撞预处理 ",this.scale,seCol,oCol);}
onPreSolve (seCol: Collider2D, oCol: Collider2D) { onPostSolve (seCol: Collider2D, oCol: Collider2D) {console.log("碰撞后处理 ",this.scale,seCol,oCol); }
}
onPostSolve (seCol: Collider2D, oCol: Collider2D) {
}
start() { start() {
oops.message.on(GameEvent.MissionEnd, this.doDestroy, this); oops.message.on(GameEvent.MissionEnd, this.doDestroy, this);