战斗系统 重构继续
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label ,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite, math, clamp, Game, tween, Color, BoxCollider2D} from "cc";
|
||||
import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label ,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite, math, clamp, Game, tween, Color, BoxCollider2D, UITransform} 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 { HeroSpine } from "./HeroSpine";
|
||||
@@ -6,7 +6,6 @@ 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,BuffConf,} from "../common/config/SkillSet";
|
||||
import { BuffComp } from "./BuffComp";
|
||||
import { oops } from "db://oops-framework/core/Oops";
|
||||
import { GameEvent } from "../common/config/GameEvent";
|
||||
import { FightSet, TooltipTypes } from "../common/config/Mission";
|
||||
@@ -14,7 +13,12 @@ import { RandomManager } from "db://oops-framework/core/common/random/RandomMana
|
||||
import { AttrSet, HeroInfo, HeroUpSet } from "../common/config/heroSet";
|
||||
import { Attrs, AttrsType, BType, NeAttrs } from "../common/config/HeroAttrs";
|
||||
import { TalComp } from "./TalComp";
|
||||
import { HeroModelComp, HeroBattleSystem } from "./HeroModelComp";
|
||||
import { HeroAttrsComp } from "./HeroAttrsComp";
|
||||
import { EBusComp } from "./EBusComp";
|
||||
import { HeroAtkSystem } from "./HeroAtk";
|
||||
import { Tooltip } from "../skill/Tooltip";
|
||||
import { timedCom } from "../skill/timedCom";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 角色显示组件 */
|
||||
@@ -27,18 +31,18 @@ export interface BuffInfo {
|
||||
@ecs.register('HeroView', false) // 定义ECS 组件
|
||||
export class HeroViewComp extends CCComp {
|
||||
// ==================== View 层属性(表现相关)====================
|
||||
BUFFCOMP:BuffComp=null!
|
||||
TALCOMP:any=null!
|
||||
EBus:any=null!
|
||||
as: HeroSpine = null!
|
||||
status:String = "idle"
|
||||
scale: number = 1; // 显示方向
|
||||
box_group:number = BoxSet.HERO; // 碰撞组
|
||||
is_stop:boolean = false;
|
||||
is_atking:boolean = false;
|
||||
|
||||
// ==================== UI 节点引用 ====================
|
||||
private top_node: Node = null!;
|
||||
|
||||
// ==================== 直接访问 HeroModelComp ====================
|
||||
// ==================== 直接访问 HeroAttrsComp ====================
|
||||
private get model() {
|
||||
return this.ent.get(HeroModelComp);
|
||||
return this.ent.get(HeroAttrsComp);
|
||||
}
|
||||
|
||||
private damageQueue: Array<{
|
||||
@@ -51,6 +55,7 @@ export class HeroViewComp extends CCComp {
|
||||
private damageInterval: number = 0.01; // 伤害数字显示间隔
|
||||
onLoad() {
|
||||
this.as = this.getComponent(HeroSpine);
|
||||
this.EBus=this.ent.get(EBusComp);
|
||||
//console.log("[HeroViewComp]:hero view comp ",this.FIGHTCON)
|
||||
this.on(GameEvent.FightEnd,this.do_fight_end,this)
|
||||
const collider = this.node.getComponent(BoxCollider2D);
|
||||
@@ -63,91 +68,30 @@ export class HeroViewComp extends CCComp {
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
start () {
|
||||
this.as.idle()
|
||||
this.BUFFCOMP=this.node.getComponent(BuffComp);
|
||||
this.TALCOMP=this.ent.get(TalComp);
|
||||
// console.log("[HeroViewComp]:heroview"+this.hero_name,this.Attrs)
|
||||
|
||||
// 初始化 UI 节点
|
||||
this.initUINodes();
|
||||
|
||||
/** 方向 */
|
||||
this.node.setScale(this.scale,1);
|
||||
this.node.getChildByName("top").setScale(this.scale,1);
|
||||
if(this.is_boss){
|
||||
this.node.getChildByName("top").position=v3(this.node.position.x,this.node.position.y+100,0)
|
||||
this.top_node.setScale(this.scale,1);
|
||||
if(this.model.is_boss){
|
||||
this.top_node.position=v3(this.node.position.x,this.node.position.y+100,0)
|
||||
}
|
||||
/* 显示角色血*/
|
||||
this.node.getChildByName("top").getChildByName("hp").active = true;
|
||||
this.node.getChildByName("top").getChildByName("pow").active = true;
|
||||
this.top_node.getChildByName("hp").active = true;
|
||||
this.top_node.getChildByName("pow").active = true;
|
||||
}
|
||||
|
||||
/** 初始化 UI 节点引用 */
|
||||
private initUINodes() {
|
||||
this.top_node = this.node.getChildByName("top");
|
||||
let hp_y = this.node.getComponent(UITransform).height;
|
||||
this.top_node.setPosition(0, hp_y, 0);
|
||||
}
|
||||
|
||||
// ==================== BUFF 系统方法直接调用 ====================
|
||||
/**
|
||||
* 初始化角色的 buff debuff(直接调用 Model)
|
||||
*/
|
||||
initAttrs() {
|
||||
if (this.model) {
|
||||
this.model.initAttrs();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加 buff 效果(直接调用 Model)
|
||||
*/
|
||||
addBuff(buffConf: BuffConf) {
|
||||
if (this.model) {
|
||||
this.model.addBuff(buffConf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 属性计算方法已迁移到 Model,这里不再需要
|
||||
|
||||
/**
|
||||
* 更新临时 buff/debuff(直接调用 Model)
|
||||
*/
|
||||
updateTemporaryBuffsDebuffs(dt: number) {
|
||||
if (this.model) {
|
||||
this.model.updateTemporaryBuffsDebuffs(dt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空buff(直接调用 Model)
|
||||
*/
|
||||
clearBuffs(attrIndex?: number, isBuff: boolean = true): void {
|
||||
if (this.model) {
|
||||
this.model.clearBuffs(attrIndex, isBuff);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理单个NeAttr(直接调用 Model)
|
||||
*/
|
||||
clearNeAttr(neAttrIndex: number): void {
|
||||
if (this.model) {
|
||||
this.model.clearNeAttr(neAttrIndex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理所有NeAttrs(直接调用 Model)
|
||||
*/
|
||||
clearAllNeAttrs(): void {
|
||||
if (this.model) {
|
||||
this.model.clearAllNeAttrs();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否眩晕(直接调用 Model)
|
||||
*/
|
||||
public isStun(): boolean {
|
||||
return this.model?.isStun() ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否冰冻(直接调用 Model)
|
||||
*/
|
||||
public isFrost(): boolean {
|
||||
return this.model?.isFrost() ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* View 层每帧更新
|
||||
@@ -161,9 +105,132 @@ export class HeroViewComp extends CCComp {
|
||||
this.processDamageQueue(); // 伤害数字显示队列
|
||||
|
||||
// ✅ 更新显示(数据由 HeroAttrSystem 更新)
|
||||
this.BUFFCOMP.hp_show(this.hp, this.Attrs[Attrs.HP_MAX]);
|
||||
this.BUFFCOMP.mp_show(this.mp, this.Attrs[Attrs.MP_MAX]);
|
||||
this.BUFFCOMP.show_shield(this.shield, this.Attrs[Attrs.SHIELD_MAX]);
|
||||
this.hp_show(this.model.hp, this.model.Attrs[Attrs.HP_MAX]);
|
||||
this.mp_show(this.model.mp, this.model.Attrs[Attrs.MP_MAX]);
|
||||
this.show_shield(this.model.shield, this.model.Attrs[Attrs.SHIELD_MAX]);
|
||||
}
|
||||
|
||||
|
||||
/** 显示护盾 */
|
||||
private show_shield(shield: number = 0, shield_max: number = 0) {
|
||||
let shield_progress = shield / shield_max;
|
||||
this.node.getChildByName("shielded").active = shield > 0;
|
||||
this.top_node.getChildByName("shield").active = shield > 0;
|
||||
this.top_node.getChildByName("shield").getComponent(ProgressBar).progress = shield_progress;
|
||||
this.scheduleOnce(() => {
|
||||
this.top_node.getChildByName("shield").getChildByName("pb").getComponent(ProgressBar).progress = shield_progress;
|
||||
}, 0.15);
|
||||
}
|
||||
|
||||
/** 显示血量 */
|
||||
private hp_show(hp: number, hp_max: number) {
|
||||
let hp_progress = hp / hp_max;
|
||||
this.top_node.getChildByName("hp").getComponent(ProgressBar).progress = hp_progress;
|
||||
this.scheduleOnce(() => {
|
||||
this.top_node.getChildByName("hp").getChildByName("hpb").getComponent(ProgressBar).progress = hp_progress;
|
||||
}, 0.15);
|
||||
}
|
||||
|
||||
/** 显示魔法值 */
|
||||
private mp_show(mp: number, mp_max: number) {
|
||||
this.top_node.getChildByName("pow").getComponent(ProgressBar).progress = mp / mp_max;
|
||||
this.scheduleOnce(() => {
|
||||
this.top_node.getChildByName("pow").getChildByName("mpb").getComponent(ProgressBar).progress = mp / mp_max;
|
||||
}, 0.15);
|
||||
}
|
||||
|
||||
/** 升级特效 */
|
||||
private lv_up() {
|
||||
var path = "game/skill/buff/buff_lvup";
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
node.parent = this.node;
|
||||
}
|
||||
|
||||
/** 攻击力提升特效 */
|
||||
private ap_up() {
|
||||
var path = "game/skill/buff/buff_apup";
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
node.parent = this.node;
|
||||
}
|
||||
|
||||
/** 显示 Buff 特效 */
|
||||
private show_do_buff(name: string) {
|
||||
var path = "game/skill/buff/" + name;
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
let pos = v3(this.node.position.x, this.node.position.y + 20, this.node.position.z);
|
||||
node.parent = this.node.parent;
|
||||
node.setPosition(pos);
|
||||
}
|
||||
|
||||
/** 死亡特效 */
|
||||
private dead() {
|
||||
var path = "game/skill/buff/dead";
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
node.parent = this.node.parent;
|
||||
node.setScale(node.scale.x * 0.5, node.scale.y * 0.5);
|
||||
let pos = v3(this.node.position.x, this.node.position.y + 30, this.node.position.z);
|
||||
node.setPosition(pos);
|
||||
}
|
||||
|
||||
/** 受击特效 */
|
||||
private in_atked(anm: string = "atked", scale: number = 1) {
|
||||
var path = "game/skill/boom/" + anm;
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
node.setScale(node.scale.x * scale, node.scale.y);
|
||||
node.setPosition(this.node.position.x, this.node.position.y + 30, this.node.position.z);
|
||||
node.parent = this.node.parent;
|
||||
}
|
||||
|
||||
/** 冰冻特效 */
|
||||
private in_iced(t: number = 1, ap: number = 0) {
|
||||
var path = "game/skill/buff/buff_iced";
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
node.getComponent(timedCom).time = t;
|
||||
node.getComponent(timedCom).ap = ap;
|
||||
node.parent = this.node;
|
||||
}
|
||||
|
||||
/** 眩晕特效 */
|
||||
private in_yun(t: number = 1, ap: number = 0) {
|
||||
var path = "game/skill/buff/buff_yun";
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
let height = this.node.getComponent(UITransform).height;
|
||||
node.setPosition(v3(0, height));
|
||||
node.getComponent(timedCom).time = t;
|
||||
node.getComponent(timedCom).ap = ap;
|
||||
node.parent = this.node;
|
||||
}
|
||||
|
||||
/** 技能提示 */
|
||||
private tooltip(type: number = 1, value: string = "", s_uuid: number = 1001, y: number = 90) {
|
||||
let tip = ecs.getEntity<Tooltip>(Tooltip);
|
||||
let pos = v3(0, 10);
|
||||
pos.y = pos.y + y;
|
||||
tip.load(pos, type, value, s_uuid, this.node);
|
||||
}
|
||||
|
||||
/** 血量提示(伤害数字) */
|
||||
private hp_tip(type: number = 1, value: string = "", s_uuid: number = 1001, y: number = 90) {
|
||||
let tip = ecs.getEntity<Tooltip>(Tooltip);
|
||||
let x = this.node.position.x;
|
||||
let ny = this.node.getComponent(UITransform).height + 20;
|
||||
let pos = v3(x, ny, 0);
|
||||
tip.load(pos, type, value, s_uuid, this.node.parent);
|
||||
}
|
||||
|
||||
/** 治疗特效 */
|
||||
private heathed() {
|
||||
var path = "game/skill/buff/heathed";
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
node.parent = this.node;
|
||||
}
|
||||
|
||||
// 注意:BaseUp 逻辑已移到 HeroAttrSystem.update()
|
||||
@@ -188,13 +255,13 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
add_shield(shield:number){
|
||||
// 护盾数据更新由 Model 层处理,这里只负责视图表现
|
||||
if(this.shield>0) this.BUFFCOMP.show_shield(this.shield,this.Attrs[Attrs.SHIELD_MAX])
|
||||
if(this.model.shield>0) this.show_shield(this.model.shield, this.model.Attrs[Attrs.SHIELD_MAX]);
|
||||
}
|
||||
|
||||
health(hp: number = 0,is_num:boolean=true) {
|
||||
health(hp: number = 0, is_num:boolean=true) {
|
||||
// 生命值更新由 Model 层处理,这里只负责视图表现
|
||||
this.BUFFCOMP.heathed();
|
||||
this.BUFFCOMP.show_heal(hp);
|
||||
this.heathed();
|
||||
this.hp_show(hp, this.model.Attrs[Attrs.HP_MAX]);
|
||||
}
|
||||
|
||||
|
||||
@@ -202,25 +269,21 @@ export class HeroViewComp extends CCComp {
|
||||
in_stop (dt: number) {
|
||||
|
||||
}
|
||||
count_atk_count(){ //主将攻击
|
||||
if(this.fac==FacSet.MON) return
|
||||
this.atk_count+=1
|
||||
}
|
||||
|
||||
|
||||
do_dead(){
|
||||
// 死亡逻辑主要由 HeroBattleSystem 处理
|
||||
// 这里只保留视图层的表现逻辑
|
||||
if(this.is_count_dead) return
|
||||
this.is_count_dead=true
|
||||
if(this.model.is_count_dead) return
|
||||
|
||||
if(this.fac==FacSet.MON){
|
||||
if(this.model.fac==FacSet.MON){
|
||||
this.scheduleOnce(()=>{
|
||||
this.do_drop()
|
||||
},0.1)
|
||||
}
|
||||
if(this.fac==FacSet.HERO){
|
||||
if(this.model.fac==FacSet.HERO){
|
||||
this.scheduleOnce(()=>{
|
||||
oops.message.dispatchEvent(GameEvent.HeroDead,{hero_uuid:this.hero_uuid})
|
||||
oops.message.dispatchEvent(GameEvent.HeroDead,{hero_uuid:this.model.hero_uuid})
|
||||
},0.1)
|
||||
}
|
||||
}
|
||||
@@ -230,7 +293,6 @@ export class HeroViewComp extends CCComp {
|
||||
|
||||
do_atked(remainingDamage:number,CAttrs:any,s_uuid:number){
|
||||
// 使用战斗系统处理攻击逻辑
|
||||
const battleSystem = this.ent.ecs.getSystem(HeroBattleSystem);
|
||||
if (!battleSystem) {
|
||||
console.error("[HeroViewComp] HeroBattleSystem 未找到");
|
||||
return;
|
||||
@@ -246,12 +308,12 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
//后退
|
||||
back(){
|
||||
if(this.fac==FacSet.MON) {
|
||||
if(this.model.fac==FacSet.MON) {
|
||||
let tx=this.node.position.x+5
|
||||
if(tx > 320) tx=320
|
||||
tween(this.node).to(0.1, { position:v3(tx,this.node.position.y,0)}).start()
|
||||
}
|
||||
if(this.fac==FacSet.HERO) {
|
||||
if(this.model.fac==FacSet.HERO) {
|
||||
let tx=this.node.position.x-5
|
||||
if(tx < -320) tx=-320
|
||||
tween(this.node).to(0.1, { position:v3(tx,this.node.position.y,0)}).start()
|
||||
@@ -260,11 +322,11 @@ export class HeroViewComp extends CCComp {
|
||||
// 伤害计算和战斗逻辑已迁移到 HeroBattleSystem
|
||||
|
||||
do_dead_trigger(){ //死亡特殊处理
|
||||
if(this.is_dead||this.fac==FacSet.MON) return
|
||||
if(this.model.is_dead||this.model.fac==FacSet.MON) return
|
||||
|
||||
}
|
||||
do_atked_trigger(){ //受伤特殊处理
|
||||
if(this.is_dead||this.fac==FacSet.MON) return
|
||||
if(this.model.is_dead||this.model.fac==FacSet.MON) return
|
||||
|
||||
}
|
||||
|
||||
@@ -275,24 +337,18 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
}).start()
|
||||
}
|
||||
// to_alive(){
|
||||
// this.is_dead=false
|
||||
// this.currentHp=this.currentHpMax*(100+this.hp_buff)/100
|
||||
// this.BUFFCOMP.vmdata_update(true)
|
||||
// this.node.setPosition(HeroPos[this.fight_pos].pos)
|
||||
// this.BUFFCOMP.heathed()
|
||||
// }
|
||||
|
||||
|
||||
to_console(value:any,value2:any=null,value3:any=null){
|
||||
//console.log("["+this.scale+this.hero_name+']'+value,value2,value3)
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.is_dead = false;
|
||||
this.model.is_dead = false;
|
||||
const collider = this.getComponent(Collider2D);
|
||||
if (collider) {
|
||||
collider.off(Contact2DType.BEGIN_CONTACT);
|
||||
}
|
||||
}
|
||||
this.scheduleOnce(() => {
|
||||
this.node.destroy();
|
||||
}, 0.1);
|
||||
@@ -303,7 +359,7 @@ export class HeroViewComp extends CCComp {
|
||||
switch(skill.act){
|
||||
case "max":
|
||||
this.as.max()
|
||||
this.BUFFCOMP.tooltip(TooltipTypes.skill,skill.name,skill_id)
|
||||
this.tooltip(TooltipTypes.skill, skill.name, skill_id)
|
||||
break
|
||||
case "atk":
|
||||
this.as.atk()
|
||||
@@ -339,16 +395,13 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
|
||||
/** 立即显示伤害效果 */
|
||||
private showDamageImmediate(damage: number, isCrit: boolean,anm:string="atked") {
|
||||
this.BUFFCOMP.hp_show(this.hp,this.Attrs[Attrs.HP_MAX])
|
||||
this.BUFFCOMP.in_atked(anm,this.fac==FacSet.HERO?1:-1)
|
||||
this.atked_count++;
|
||||
private showDamageImmediate(damage: number, isCrit: boolean, anm:string="atked") {
|
||||
this.hp_show(this.model.hp, this.model.Attrs[Attrs.HP_MAX]);
|
||||
this.in_atked(anm, this.model.fac==FacSet.HERO?1:-1);
|
||||
if (isCrit) {
|
||||
this.BUFFCOMP.hp_tip(TooltipTypes.crit, damage.toFixed(0), damage);
|
||||
// //console.log("暴击伤害 + damage);
|
||||
this.hp_tip(TooltipTypes.crit, damage.toFixed(0), damage);
|
||||
} else {
|
||||
this.BUFFCOMP.hp_tip(TooltipTypes.life, damage.toFixed(0), damage);
|
||||
// //console.log("普通伤害:" + damage);
|
||||
this.hp_tip(TooltipTypes.life, damage.toFixed(0), damage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user