复活完成

This commit is contained in:
2025-06-17 10:58:13 +08:00
parent 5af0a314a6
commit d02482a591
12 changed files with 205 additions and 114 deletions

View File

@@ -1,26 +1,23 @@
import { oops } from "db://oops-framework/core/Oops";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { VM } from "../../../../extensions/oops-plugin-framework/assets/libs/model-view/ViewModel";
import { GameEvent } from "../common/config/GameEvent";
/** 数据层对象 */
@ecs.register('FriendModel')
export class FriendModelComp extends ecs.Comp {
/** 提供 MVVM 组件使用的数据 */
private vm: any = {};
/** 显示数据添加到 MVVM 框架中监视 */
vmAdd() {
VM.add(this.vm, "FriendModel");
onLoad(){
oops.message.on(GameEvent.ChangeATK_EQUIP_SPECIAL_ATTR,this.change_equip_special_attr,this)
}
/** 显示数据从 MVVM 框架中移除 */
vmRemove() {
VM.remove("FriendModel");
change_equip_special_attr(e:GameEvent,data:any){
console.log("[FriendModel]:change_equip_special_attr",data)
}
/** 数据层组件移除时,重置所有数据为默认值 */
reset() {
for (var key in this.vm) {
delete this.vm[key];
}
}
}

View File

@@ -5,10 +5,9 @@ import { smc } from "../common/SingletonModuleComp";
import { HeroModelComp } from "./HeroModelComp";
import { HeroViewComp } from "./HeroViewComp";
import { BoxSet, FacSet } from "../common/config/BoxSet";
import { HeroInfo } from "../common/config/heroSet";
import { HeroInfo, HeroPos } from "../common/config/heroSet";
import { BattleMoveComp } from "../common/ecs/position/BattleMoveComp";
import { SkillConComp } from "./SkillConComp";
import { FriendModelComp } from "./FriendModel";
/** 角色实体 */
@ecs.register(`Hero`)
@@ -37,7 +36,7 @@ export class Hero extends ecs.Entity {
var node = instantiate(prefab);
var scene = smc.map.MapView.scene;
node.parent = scene.entityLayer!.node!
let pos=v3(-277,0,0)
let pos=HeroPos[0].pos
node.setPosition(pos)
var hv = node.getComponent(HeroViewComp)!;
let hero= HeroInfo[uuid] // 共用英雄数据
@@ -62,7 +61,7 @@ export class Hero extends ecs.Entity {
this.add(hv);
}
/** 加载角色 */
load(pos: Vec3 = Vec3.ZERO,scale:number = 1,uuid:number=1001,info:any={ap:0,hp:0},fight_pos:number=0) {
load(pos: Vec3 = Vec3.ZERO,scale:number = 1,uuid:number=1001,info:any={ap:0,hp:0},fight_pos:number=1) {
// console.log("英雄加载:",uuid,pos,scale,info)
scale = 1
let box_group=BoxSet.HERO
@@ -73,7 +72,6 @@ export class Hero extends ecs.Entity {
node.parent = scene.entityLayer!.node!
node.setPosition(pos)
// console.log("hero load",pos)
this.addComponents<ecs.Comp>(FriendModelComp);
var hv = node.getComponent(HeroViewComp)!;
let hero= HeroInfo[uuid] // 共用英雄数据
hv.scale = scale;

View File

@@ -2,7 +2,7 @@ import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label ,Node,Prefab,insta
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { HeroSpine } from "./HeroSpine";
import { BoxSet } from "../common/config/BoxSet";
import { BoxSet, FacSet } from "../common/config/BoxSet";
import { smc } from "../common/SingletonModuleComp";
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
import { SkillSet, TargetGroup, TargetType } from "../common/config/SkillSet";
@@ -76,7 +76,8 @@ export class HeroViewComp extends CCComp {
dir_y:number = 0;
speek_time:number = 0;
is_stop_temp:boolean = false;i
Friend_alive_cd:Timer=new Timer(10)
private damageQueue: Array<{
damage: number,
isCrit: boolean,
@@ -92,28 +93,10 @@ export class HeroViewComp extends CCComp {
this.FIGHTCON=this.node.parent.getComponent(FightConComp);
console.log("hero view comp ",this.FIGHTCON)
this.on(GameEvent.ChangeATK,this.change_atk,this)
this.on(GameEvent.ChangeATK_EQUIP_SPECIAL_ATTR,this.change_equip_special_attr,this)
// let anm = this.node.getChildByName("anm")
// anm.setScale(anm.scale.x*0.8,anm.scale.y*0.8);
// 注册单个碰撞体的回调函数
// let collider = this.getComponent(Collider2D);
// collider.group = this.box_group;
// // console.log("hero collider ",this.scale,collider);
// 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);
// }
}
// onBeginContact (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 () {
this.as.idle()
@@ -127,7 +110,7 @@ export class HeroViewComp extends CCComp {
}
/* 显示角色血量 */
this.node.getChildByName("top").getChildByName("hp").active = true;
// console.log("hero parent",this.node.parent)
this.Friend_alive_cd=new Timer(FightSet.FRIEND_LIVE_CD)
}
update(dt: number){
if(!smc.mission.play||smc.mission.pause) return
@@ -135,6 +118,12 @@ export class HeroViewComp extends CCComp {
// this.ent.destroy();
// return
// }
if(this.is_dead) {
if(this.Friend_alive_cd.update(dt)){
console.log("alive friend")
this.to_alive()
}
}
if(this.timer.update(dt)){
// this.add_ap(10)
};
@@ -149,7 +138,17 @@ export class HeroViewComp extends CCComp {
this.in_stop(dt);
// 处理伤害队列
this.processDamageQueue();
}
}
change_equip_special_attr(e:GameEvent,data:any){
console.log("change_equip_special_attr",data)
this.up_friend_alive_cd(data.friend_live_cd_less)
}
up_friend_alive_cd(less:number){
this.Friend_alive_cd=new Timer(FightSet.FRIEND_LIVE_CD-less)
}
change_atk(e:GameEvent,data:any){
switch(data){
case EquipSpecialAttr.ICE:
@@ -296,10 +295,17 @@ export class HeroViewComp extends CCComp {
this.hp -= remainingDamage;
if(this.hp <= 0) {
if(this == null) return;
this.is_dead=true
this.BUFFCOMP.dead()
this.do_dead()
console.log("[HeroViewComp]:dead,fac => "+(this.fac==FacSet.HERO?"hero":"monster"))
if(this.ent == null) return;
this.ent.destroy();
if(this.fac ==FacSet.HERO){
this.to_grave()
}else{
this.ent.destroy();
}
}
this.BUFFCOMP.update_info_hp()
this.showDamage(remainingDamage, true);
@@ -309,10 +315,21 @@ export class HeroViewComp extends CCComp {
this.BUFFCOMP.dead()
this.to_drop()
}
to_grave(){
tween(this.node).to(0.5, { position:v3(-900,this.node.position.y+300,0)},{
onComplete: (target?: object) => {
this.node.setPosition(-900,this.node.position.y-300,0)
}
}
).start()
}
to_alive(){
this.is_dead=false
this.node.setPosition(HeroPos[0].pos)
this.hp=this.hp_max
this.BUFFCOMP.update_info_hp()
this.node.setPosition(HeroPos[this.fight_pos].pos)
this.BUFFCOMP.heathed()
}
//掉落物品
to_drop(){

View File

@@ -0,0 +1,25 @@
import { _decorator, Component, Node } from 'cc';
import { GameEvent } from '../common/config/GameEvent';
import { oops } from 'db://oops-framework/core/Oops';
import { ecs } from 'db://oops-framework/libs/ecs/ECS';
const { ccclass, property } = _decorator;
@ecs.register('MasterModel')
export class MasterModelComp extends ecs.Comp {
onLoad(){
oops.message.on(GameEvent.ChangeATK_EQUIP_SPECIAL_ATTR,this.change_equip_special_attr,this)
}
change_equip_special_attr(e:GameEvent,data:any){
console.log("[MasterModel]:change_equip_special_attr",data)
}
update(deltaTime: number) {
}
reset(): void {
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "70abe143-ca41-4c22-b645-63a6035aba95",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -42,6 +42,7 @@ export class SkillConComp extends CCComp {
if(count<1) count=1
// console.log(this.HeroView.hero_name+(this.HeroView.is_master?"[主]":"[从] 准备释放")+SkillSet[this.HeroView.atk_skill].name+"=>"+"=>cd:"+cd+"=> count:"+count)
if (this.HeroView.is_atking &&(this.HeroView.at > cd)) {
if(this.HeroView.is_dead) return
const config = SkillSet[this.HeroView.atk_skill];
if (!config) return;
// console.log(this.HeroView.hero_name+(this.HeroView.is_master?"[主]":"[从] 释放")+"=>"+config.name+"=>"+count)