修复 buff 逻辑处理 bug : 预制体不能设置全局监听oops.message.on,会一直执行
This commit is contained in:
@@ -44,7 +44,7 @@ export class CSkill extends ecs.Entity {
|
||||
const url = 'game/heros/skill';
|
||||
resources.load(url, SpriteAtlas, (err: any, atlas) => {
|
||||
const sprite = node.getChildByName("skill").getComponent(Sprite);
|
||||
sprite.spriteFrame = atlas.getSpriteFrame(SkillSet[uuid].path);
|
||||
sprite.spriteFrame = atlas.getSpriteFrame(smc.skills[uuid].path);
|
||||
});
|
||||
this.skill_init(uuid,node,pos)
|
||||
oops.message.dispatchEvent("cskill_load",this)
|
||||
@@ -67,7 +67,7 @@ export class CSkill extends ecs.Entity {
|
||||
var mv = node.getComponent(CSkillComp)
|
||||
mv.scale = 1;
|
||||
mv.skill_uuid = uuid;
|
||||
mv.atk=SkillSet[uuid].atk;
|
||||
mv.atk=smc.skills[uuid].atk;
|
||||
this.add(mv);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ import { MonsterModelComp } from "./MonsterModelComp";
|
||||
import { MonsterViewComp } from "./MonsterViewComp";
|
||||
import { BoxSet } from "../common/config/BoxSet";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
import { HeroModelComp } from "./HeroModelComp";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 视图层对象 */
|
||||
@@ -29,9 +31,9 @@ export class CSkillComp extends CCComp {
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
start() {
|
||||
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
|
||||
this.sd =new Timer(SkillSet[this.skill_uuid].sd)
|
||||
this.cd = new Timer(SkillSet[this.skill_uuid].cd)
|
||||
this.time =SkillSet[this.skill_uuid].sd
|
||||
this.sd =new Timer(smc.skills[this.skill_uuid].sd)
|
||||
this.cd = new Timer(smc.skills[this.skill_uuid].cd)
|
||||
this.time =smc.skills[this.skill_uuid].sd
|
||||
this.node.getChildByName("time").getComponent(Label).string = this.time.toString()
|
||||
|
||||
}
|
||||
@@ -45,7 +47,13 @@ export class CSkillComp extends CCComp {
|
||||
if (this.cd.update(dt)) {
|
||||
this.time -=1
|
||||
this.node.getChildByName("time").getComponent(Label).string = this.time.toString()
|
||||
this.shoot()
|
||||
if(smc.skills[this.skill_uuid].type == 1){
|
||||
this.shoot()
|
||||
}
|
||||
if(smc.skills[this.skill_uuid].type == 9){
|
||||
this.add_buff()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
shoot() {
|
||||
@@ -72,11 +80,24 @@ export class CSkillComp extends CCComp {
|
||||
angle = randian * (180 / Math.PI);
|
||||
// console.log("angle",angle);
|
||||
let scale = this.scale
|
||||
let dis = SkillSet[this.skill_uuid].dis+this.dis;
|
||||
let atk = SkillSet[this.skill_uuid].atk+this.atk;
|
||||
let speed = SkillSet[this.skill_uuid].speed+this.speed;
|
||||
let dis = smc.skills[this.skill_uuid].dis+this.dis;
|
||||
let atk = smc.skills[this.skill_uuid].atk+this.atk;
|
||||
let speed = smc.skills[this.skill_uuid].speed+this.speed;
|
||||
skill.load(pos,speed,dis,scale,this.node,this.skill_uuid,atk,angle,t_pos);
|
||||
}
|
||||
add_buff(){
|
||||
let uuid= this.skill_uuid;
|
||||
let eid = 0
|
||||
let group = BoxSet.HERO;
|
||||
let heros:any = ecs.query(ecs.allOf(HeroModelComp));
|
||||
if (heros.length > 0) {
|
||||
for (let i = 0; i < heros.length; i++) {
|
||||
let hero = heros[i];
|
||||
hero.MonsterBuff.add_buff(uuid,eid,group);
|
||||
}
|
||||
}
|
||||
// oops.message.dispatchEvent("add_buff",{uuid:this.skill_uuid,eid:0,group:BoxSet.HERO})
|
||||
}
|
||||
/** 全局消息逻辑处理 */
|
||||
// private onHandler(event: string, args: any) {
|
||||
// switch (event) {
|
||||
@@ -106,7 +127,6 @@ export class CSkillComp extends CCComp {
|
||||
reset() {
|
||||
this.sd.reset()
|
||||
this.cd.reset()
|
||||
|
||||
this.node.destroy();
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import { MonsterViewComp } from "./MonsterViewComp";
|
||||
import {HeroModelComp} from "./HeroModelComp";
|
||||
import { CardSet } from "../common/config/CardSet";
|
||||
import { BoxSet } from "../common/config/BoxSet";
|
||||
import { MonsterBuffComp } from "./MonsterBuffComp";
|
||||
/** 角色实体 */
|
||||
@ecs.register(`Hero`)
|
||||
export class Hero extends ecs.Entity {
|
||||
@@ -31,7 +32,8 @@ export class Hero extends ecs.Entity {
|
||||
|
||||
destroy(): void {
|
||||
this.remove(MonsterViewComp);
|
||||
this.remove(MonsterModelComp);
|
||||
this.remove(HeroModelComp);
|
||||
this.remove(MonsterBuffComp);
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
@@ -83,10 +85,11 @@ export class Hero extends ecs.Entity {
|
||||
}
|
||||
hero_init(uuid:number=1001,node:Node,pos:Vec3=v3(0,0,0)){
|
||||
var mv = node.getComponent(MonsterViewComp)!;
|
||||
var buff =node.getComponent(MonsterBuffComp)!;
|
||||
mv.hero_uuid=uuid;
|
||||
mv.speed =mv.ospeed = smc.heros[uuid].speed;
|
||||
mv.hero_name= smc.heros[uuid].name;
|
||||
mv.box_group= BoxSet.HERO;
|
||||
buff.group= mv.box_group= BoxSet.HERO;
|
||||
mv.hp= mv.hp_max = smc.heros[uuid].hp;
|
||||
mv.level = smc.heros[uuid].level;
|
||||
mv.atk = smc.heros[uuid].atk;
|
||||
@@ -99,6 +102,7 @@ export class Hero extends ecs.Entity {
|
||||
mv.scale = 1;
|
||||
// mv.change_name(smc.heros[uuid].name,1)
|
||||
this.add(mv);
|
||||
this.add(buff);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ export class HeroCard extends ecs.Entity {
|
||||
case 2:
|
||||
path = "game/heros/skill_card";
|
||||
url = "game/heros/skill";
|
||||
({ path: pathName, name, level } = SkillSet[uuid]);
|
||||
({ path: pathName, name, level } = smc.skills[uuid]);
|
||||
break;
|
||||
case 3:
|
||||
default:
|
||||
@@ -74,7 +74,6 @@ export class HeroCard extends ecs.Entity {
|
||||
hcv.card_type=type
|
||||
hcv.card_level=level
|
||||
this.add(hcv);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,13 +28,11 @@ export class Monster extends ecs.Entity {
|
||||
MonsterBuff!: MonsterBuffComp; // 移动
|
||||
|
||||
protected init() {
|
||||
this.addComponents<ecs.Comp>(
|
||||
MonsterModelComp);
|
||||
|
||||
this.addComponents<ecs.Comp>( MonsterModelComp);
|
||||
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
|
||||
this.remove(MonsterViewComp);
|
||||
this.remove(MonsterBuffComp);
|
||||
super.destroy();
|
||||
@@ -84,10 +82,10 @@ export class Monster extends ecs.Entity {
|
||||
}
|
||||
hero_init(uuid:number=1001,node:Node,pos:Vec3=v3(0,0,0)){
|
||||
var mv = node.getComponent(MonsterViewComp)!;
|
||||
var buff = node.getComponent(MonsterBuffComp)!;
|
||||
var buff =node.getComponent(MonsterBuffComp)!;
|
||||
mv.speed =mv.ospeed = smc.heros[uuid].speed;
|
||||
mv.hero_name= smc.heros[uuid].name;
|
||||
mv.box_group= BoxSet.MONSTER;
|
||||
buff.group=mv.box_group= BoxSet.MONSTER;
|
||||
mv.hp= mv.hp_max = smc.heros[uuid].hp;
|
||||
mv.level = smc.heros[uuid].level;
|
||||
mv.atk = smc.heros[uuid].atk;
|
||||
@@ -99,7 +97,6 @@ export class Monster extends ecs.Entity {
|
||||
mv.scale = -1;
|
||||
mv.Tpos = v3(0,0,0);
|
||||
this.add(mv);
|
||||
this.add(buff)
|
||||
|
||||
this.add(buff);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
* @LastEditTime: 2022-08-17 12:36:18
|
||||
*/
|
||||
|
||||
import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite} from "cc";
|
||||
import { _decorator} 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 { MonsterSpine } from "./MonsterSpine";
|
||||
@@ -18,9 +18,8 @@ import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/O
|
||||
import { Skill } from "../skills/Skill";
|
||||
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
|
||||
import { SkillCom } from "../skills/SkillCom";
|
||||
import { SkillSet } from "../common/config/SkillSet";
|
||||
import { BoxRangComp } from "./BoxRangComp";
|
||||
import { Tooltip } from "../skills/Tooltip";
|
||||
import { Tooltip } from "../skills/Tooltip";
|
||||
import { MonsterViewComp } from "./MonsterViewComp";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@@ -33,64 +32,49 @@ export class MonsterBuffComp extends CCComp {
|
||||
mv!: MonsterViewComp;
|
||||
|
||||
timer:Timer = new Timer(0.1);
|
||||
buffs:Array<number>=[];
|
||||
buffs_arr:any=[];
|
||||
buffs:any=[];
|
||||
group:number=0;
|
||||
/**
|
||||
skill_uuid:number=0;
|
||||
atk:number=0;
|
||||
hp:number=0;
|
||||
shield:number=0;
|
||||
time:number=0;
|
||||
|
||||
|
||||
**/
|
||||
|
||||
|
||||
onLoad() {
|
||||
this.as = this.node.getComponent(MonsterSpine);
|
||||
this.mv= this.getComponent(MonsterViewComp);
|
||||
|
||||
} /** 视图层逻辑代码分离演示 */
|
||||
start () {
|
||||
// 注册单个碰撞体的回调函数
|
||||
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.PRE_SOLVE, this.onPreSolve, this);
|
||||
collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
|
||||
}
|
||||
// this.node.getChildByName("level").getChildByName("level").getComponent(Label).string = this.level.toString();
|
||||
|
||||
|
||||
}
|
||||
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D) {
|
||||
if(otherCollider.tag==BoxSet.SKILL_TAG &&selfCollider.tag!=BoxSet.SKILL_TAG){
|
||||
if(selfCollider.group != otherCollider.group){
|
||||
|
||||
add_buff(uuid:number=0,eid:number=0,group:number=0){
|
||||
// console.log("add_buff",event,args,smc.skills[uuid]);
|
||||
|
||||
let new_buff={
|
||||
skill_uuid:uuid,
|
||||
skill_name:smc.skills[uuid].name,
|
||||
atk:smc.skills[uuid].atk,
|
||||
hp:smc.skills[uuid].hp,
|
||||
shield:smc.skills[uuid].shield,
|
||||
time:smc.skills[uuid].bsd,
|
||||
bcd:smc.skills[uuid].bcd,
|
||||
sk_uuid:smc.skills[uuid].uuid,
|
||||
}
|
||||
if(eid !=0 && group ==0 ){
|
||||
if(this.mv.ent.eid == eid){
|
||||
this.buff_add(new_buff);
|
||||
}
|
||||
}
|
||||
}
|
||||
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D) { }
|
||||
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
|
||||
|
||||
}
|
||||
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
|
||||
if(selfCollider.group == otherCollider.group&&otherCollider.tag == 0&&selfCollider.tag == 0){
|
||||
let self_pos=selfCollider.node.getPosition();
|
||||
let other_pos=otherCollider.node.getPosition();
|
||||
// console.log('monster view group 相同');
|
||||
switch (selfCollider.group) {
|
||||
case BoxSet.HERO:
|
||||
|
||||
break;
|
||||
case BoxSet.MONSTER:
|
||||
|
||||
break
|
||||
}
|
||||
if(eid ==0 && group == this.group){
|
||||
this.buff_add(new_buff);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
update(dt: number){
|
||||
if (this.timer.update(dt)) {
|
||||
this.buff_update()
|
||||
@@ -102,21 +86,45 @@ export class MonsterBuffComp extends CCComp {
|
||||
this.node.destroy();
|
||||
}
|
||||
|
||||
buff_add(time:number,atk:number){
|
||||
|
||||
buff_add(buff:any){
|
||||
// console.log("buff add:",this.buffs);
|
||||
if(!this.node.isValid){ return }
|
||||
let i = 0
|
||||
if(this.buffs.length >=0){
|
||||
this.buffs.forEach((b:any,index:number)=>{
|
||||
if(b.skill_uuid==buff.skill_uuid){
|
||||
b.time=buff.time;
|
||||
this.mv.atk+=(buff.atk-b.atk);
|
||||
this.mv.hp+=(buff.hp-b.hp);
|
||||
this.mv.hp_max+=(buff.hp-b.hp);
|
||||
this.mv.shield=buff.shield-b.shield;
|
||||
i=index
|
||||
}
|
||||
})
|
||||
}
|
||||
if (i==0||this.buffs.length==0) {
|
||||
this.buffs.push(buff);
|
||||
this.mv.atk+=buff.atk;
|
||||
this.mv.hp+=buff.hp;
|
||||
this.mv.hp_max+=buff.hp;
|
||||
this.mv.shield+=buff.shield;
|
||||
}
|
||||
// console.log("buff add:"+this.mv.ent.eid,this.node);
|
||||
}
|
||||
buff_remove(index:number){
|
||||
this.mv.atk=this.mv.atk-this.buffs_arr[index].atk;
|
||||
this.mv.hp=this.mv.hp-this.buffs_arr[index].hp;
|
||||
this.mv.shield=this.mv.shield-this.buffs_arr[index].shield;
|
||||
this.mv.atk=this.mv.atk-this.buffs[index].atk;
|
||||
this.mv.hp_max=this.mv.hp_max-this.buffs[index].hp;
|
||||
this.mv.shield=this.mv.shield-this.buffs[index].shield;
|
||||
// console.log("buff remove:"+this.mv.ent.eid,this.node)
|
||||
}
|
||||
buff_update(){
|
||||
this.buffs_arr.forEach((buff:any,index:number)=>{
|
||||
this.buffs.forEach((buff:any,index:number)=>{
|
||||
buff.time -= 0.1;
|
||||
if(buff.time <= 0){
|
||||
this.buff_remove(index);
|
||||
}
|
||||
})
|
||||
this.buffs_arr = this.buffs_arr.filter((buff:any) => buff.time > 0);
|
||||
this.buffs = this.buffs.filter((buff:any) => buff.time > 0);
|
||||
// console.log(this.buffs,this.buffs);
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import { SkillCom } from "../skills/SkillCom";
|
||||
import { SkillSet } from "../common/config/SkillSet";
|
||||
import { BoxRangComp } from "./BoxRangComp";
|
||||
import { Tooltip } from "../skills/Tooltip";
|
||||
import { MonsterBuffComp } from "./MonsterBuffComp";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 角色显示组件 */
|
||||
@@ -34,6 +35,9 @@ export class MonsterViewComp extends CCComp {
|
||||
|
||||
@property(Node)
|
||||
BoxRang:Node =null!
|
||||
|
||||
buff:MonsterBuffComp =null!
|
||||
|
||||
/** 角色动画 */
|
||||
as: MonsterSpine = null!;
|
||||
hero_uuid:number = 1001;
|
||||
@@ -66,6 +70,7 @@ export class MonsterViewComp extends CCComp {
|
||||
stop_cd: number = 0.5; /*停止倒计时*/
|
||||
|
||||
shield:number = 0; //护盾量
|
||||
shield_max:number = 0;
|
||||
shield_time:number = 0; //护盾持续时间
|
||||
|
||||
box_group:number = 2;
|
||||
@@ -77,18 +82,18 @@ export class MonsterViewComp extends CCComp {
|
||||
|
||||
onLoad() {
|
||||
this.as = this.getComponent(MonsterSpine);
|
||||
|
||||
this.buff=this.node.getComponent(MonsterBuffComp);
|
||||
this.BoxRang = this.node.getChildByName("range_box");
|
||||
} /** 视图层逻辑代码分离演示 */
|
||||
start () {
|
||||
this.sprite = this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
|
||||
this.orginalFlashMaterial = this.sprite.getRenderMaterial(0);
|
||||
|
||||
|
||||
this.BoxRang = this.node.getChildByName("range_box");
|
||||
this.BoxRang.getComponent(BoxRangComp).box_group = this.box_group;
|
||||
this.BoxRang.getComponent(BoxRangComp).offset_x = this.scale*SkillSet[this.skill_uuid].dis;
|
||||
this.BoxRang.getComponent(BoxRangComp).offset_x = this.scale*smc.skills[this.skill_uuid].dis;
|
||||
// console.log("monseter ",this.BoxRang);
|
||||
|
||||
this.buff.group=this.box_group
|
||||
// 注册单个碰撞体的回调函数
|
||||
let collider = this.getComponent(Collider2D);
|
||||
collider.group = this.box_group;
|
||||
@@ -182,11 +187,11 @@ export class MonsterViewComp extends CCComp {
|
||||
let x=32
|
||||
let pos = v3(35*this.scale,40)
|
||||
let scale = this.scale
|
||||
let speed =SkillSet[skill_uuid].speed;
|
||||
let dis = SkillSet[skill_uuid].dis;
|
||||
let atk = SkillSet[skill_uuid].atk+this.atk;
|
||||
let speed =smc.skills[skill_uuid].speed;
|
||||
let dis = smc.skills[skill_uuid].dis;
|
||||
let atk = smc.skills[skill_uuid].atk+this.atk;
|
||||
skill.load(pos,speed,dis,scale,this.node,skill_uuid,atk);
|
||||
// this.tooltip(3,SkillSet[skill_uuid].name,this.skill_uuid);
|
||||
// this.tooltip(3,smc.skills[skill_uuid].name,this.skill_uuid);
|
||||
}
|
||||
//使用max_skill
|
||||
do_max_skill(){
|
||||
@@ -194,11 +199,11 @@ export class MonsterViewComp extends CCComp {
|
||||
let x=32
|
||||
let pos = v3(35*this.scale,40)
|
||||
let scale = this.scale
|
||||
let speed =SkillSet[this.max_skill_uuid].speed;
|
||||
let dis = SkillSet[this.max_skill_uuid].dis;
|
||||
let atk = SkillSet[this.max_skill_uuid].atk+this.atk;
|
||||
let speed =smc.skills[this.max_skill_uuid].speed;
|
||||
let dis = smc.skills[this.max_skill_uuid].dis;
|
||||
let atk = smc.skills[this.max_skill_uuid].atk+this.atk;
|
||||
skill.load(pos,speed,dis,scale,this.node,this.max_skill_uuid,atk);
|
||||
this.tooltip(3,SkillSet[this.max_skill_uuid].name,this.max_skill_uuid);
|
||||
this.tooltip(3,smc.skills[this.max_skill_uuid].name,this.max_skill_uuid);
|
||||
}
|
||||
in_act(dt: number) {
|
||||
|
||||
@@ -219,7 +224,11 @@ export class MonsterViewComp extends CCComp {
|
||||
if(this.is_dead){
|
||||
return;
|
||||
}
|
||||
this.hp -= hp;
|
||||
let lhp=this.shield_change(hp);
|
||||
if(lhp == 0){
|
||||
return;
|
||||
}
|
||||
this.hp += lhp;
|
||||
this.tooltip(1,hp.toString());
|
||||
if(this.hp > this.hp_max){
|
||||
this.hp = this.hp_max;
|
||||
@@ -234,6 +243,18 @@ export class MonsterViewComp extends CCComp {
|
||||
}, 15);
|
||||
}
|
||||
}
|
||||
shield_change(hp: number){
|
||||
let ls=this.shield - hp;
|
||||
if(ls <= 0){
|
||||
this.shield = 0;
|
||||
return ls;
|
||||
}else{
|
||||
this.shield = ls;
|
||||
return 0;
|
||||
}
|
||||
// let shield_progress= this.shield/this.shield_max;
|
||||
// this.node.getChildByName("shield").getComponent(ProgressBar)!.progress = shield_progress;
|
||||
}
|
||||
tooltip(type:number=1,value:string="",s_uuid:number=1001){
|
||||
// console.log("tooltip",type);
|
||||
let tip =ecs.getEntity<Tooltip>(Tooltip);
|
||||
|
||||
Reference in New Issue
Block a user