From 060046a6a606c4fd0459a3b73ad2022317701554 Mon Sep 17 00:00:00 2001 From: walkpan Date: Mon, 3 Feb 2025 15:03:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=A4=E5=AE=B3=E7=B3=BB=E7=BB=9F=E6=9C=89?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E6=89=93=E7=AE=97=E6=94=BE=E5=BC=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/resources/game/skills/anm/tobig.anim | 106 +++---- .../resources/game/skills/damageText.prefab | 290 ++++++++++++++++++ .../game/skills/damageText.prefab.meta | 13 + assets/script/Main.ts | 10 +- assets/script/common.meta | 9 + assets/script/game/battle/BattleEndSystem.ts | 24 ++ assets/script/game/battle/BattleManager.ts | 7 - assets/script/game/damage/DamageComp.ts | 23 +- assets/script/game/damage/DamageShowSystem.ts | 93 +++++- .../game/damage/DamageShowSystem.ts.meta | 2 +- assets/script/game/damage/DamageSystem.ts | 24 +- assets/script/game/damage/DamageText.ts | 17 + assets/script/game/damage/DamageText.ts.meta | 9 + assets/script/game/hero/HeroViewComp.ts | 14 +- assets/script/game/map/MapView.ts.meta | 9 + assets/script/game/skill/EcsSkillSystem.ts | 6 +- assets/script/game/skill/HeroSkillSystem.ts | 1 + tsconfig.json | 4 +- 18 files changed, 549 insertions(+), 112 deletions(-) create mode 100644 assets/resources/game/skills/damageText.prefab create mode 100644 assets/resources/game/skills/damageText.prefab.meta create mode 100644 assets/script/common.meta create mode 100644 assets/script/game/battle/BattleEndSystem.ts create mode 100644 assets/script/game/damage/DamageText.ts create mode 100644 assets/script/game/damage/DamageText.ts.meta create mode 100644 assets/script/game/map/MapView.ts.meta diff --git a/assets/resources/game/skills/anm/tobig.anim b/assets/resources/game/skills/anm/tobig.anim index f1b5de2f..e5a6f9d0 100644 --- a/assets/resources/game/skills/anm/tobig.anim +++ b/assets/resources/game/skills/anm/tobig.anim @@ -95,9 +95,9 @@ "__type__": "cc.RealCurve", "_times": [ 0, - 0.16666666666666666, - 0.2777777777777778, - 0.6666666666666666 + 0.1666666716337204, + 0.2777777910232544, + 0.6666666865348816 ], "_values": [ { @@ -162,9 +162,9 @@ "__type__": "cc.RealCurve", "_times": [ 0, - 0.16666666666666666, - 0.2777777777777778, - 0.6666666666666666 + 0.1666666716337204, + 0.2777777910232544, + 0.6666666865348816 ], "_values": [ { @@ -229,9 +229,9 @@ "__type__": "cc.RealCurve", "_times": [ 0, - 0.16666666666666666, - 0.2777777777777778, - 0.6666666666666666 + 0.1666666716337204, + 0.2777777910232544, + 0.6666666865348816 ], "_values": [ { @@ -347,9 +347,9 @@ "__type__": "cc.RealCurve", "_times": [ 0, - 0.16666666666666666, - 0.2777777777777778, - 0.6666666666666666 + 0.1666666716337204, + 0.2777777910232544, + 0.6666666865348816 ], "_values": [ { @@ -414,9 +414,9 @@ "__type__": "cc.RealCurve", "_times": [ 0, - 0.16666666666666666, - 0.2777777777777778, - 0.6666666666666666 + 0.1666666716337204, + 0.2777777910232544, + 0.6666666865348816 ], "_values": [ { @@ -545,9 +545,9 @@ "__type__": "cc.RealCurve", "_times": [ 0, - 0.16666666666666666, - 0.2777777777777778, - 0.4444444444444444 + 0.1666666716337204, + 0.2777777910232544, + 0.4444444477558136 ], "_values": [ { @@ -612,9 +612,9 @@ "__type__": "cc.RealCurve", "_times": [ 0, - 0.16666666666666666, - 0.2777777777777778, - 0.4444444444444444 + 0.1666666716337204, + 0.2777777910232544, + 0.4444444477558136 ], "_values": [ { @@ -678,8 +678,8 @@ { "__type__": "cc.RealCurve", "_times": [ - 0.16666666666666666, - 0.2777777777777778 + 0.1666666716337204, + 0.2777777910232544 ], "_values": [ { @@ -771,9 +771,9 @@ "__type__": "cc.RealCurve", "_times": [ 0, - 0.16666666666666666, - 0.2777777777777778, - 0.6666666666666666 + 0.1666666716337204, + 0.2777777910232544, + 0.6666666865348816 ], "_values": [ { @@ -838,9 +838,9 @@ "__type__": "cc.RealCurve", "_times": [ 0, - 0.16666666666666666, - 0.2777777777777778, - 0.6666666666666666 + 0.1666666716337204, + 0.2777777910232544, + 0.6666666865348816 ], "_values": [ { @@ -904,9 +904,9 @@ { "__type__": "cc.RealCurve", "_times": [ - 0.16666666666666666, - 0.2777777777777778, - 0.6666666666666666 + 0.1666666716337204, + 0.2777777910232544, + 0.6666666865348816 ], "_values": [ { @@ -1010,8 +1010,8 @@ "__type__": "cc.RealCurve", "_times": [ 0, - 0.2777777777777778, - 0.5555555555555556 + 0.2777777910232544, + 0.5555555820465088 ], "_values": [ { @@ -1064,8 +1064,8 @@ "__type__": "cc.RealCurve", "_times": [ 0, - 0.2777777777777778, - 0.5555555555555556 + 0.2777777910232544, + 0.5555555820465088 ], "_values": [ { @@ -1117,7 +1117,7 @@ { "__type__": "cc.RealCurve", "_times": [ - 0.2777777777777778 + 0.2777777910232544 ], "_values": [ { @@ -1196,8 +1196,8 @@ { "__type__": "cc.RealCurve", "_times": [ - 0.2777777777777778, - 0.6666666666666666 + 0.2777777910232544, + 0.6666666865348816 ], "_values": [ { @@ -1237,8 +1237,8 @@ { "__type__": "cc.RealCurve", "_times": [ - 0.2777777777777778, - 0.6666666666666666 + 0.2777777910232544, + 0.6666666865348816 ], "_values": [ { @@ -1278,8 +1278,8 @@ { "__type__": "cc.RealCurve", "_times": [ - 0.2777777777777778, - 0.6666666666666666 + 0.2777777910232544, + 0.6666666865348816 ], "_values": [ { @@ -1370,8 +1370,8 @@ { "__type__": "cc.RealCurve", "_times": [ - 0.3333333333333333, - 0.6666666666666666 + 0.3333333432674408, + 0.6666666865348816 ], "_values": [ { @@ -1411,8 +1411,8 @@ { "__type__": "cc.RealCurve", "_times": [ - 0.3333333333333333, - 0.6666666666666666 + 0.3333333432674408, + 0.6666666865348816 ], "_values": [ { @@ -1452,8 +1452,8 @@ { "__type__": "cc.RealCurve", "_times": [ - 0.3333333333333333, - 0.6666666666666666 + 0.3333333432674408, + 0.6666666865348816 ], "_values": [ { @@ -1544,8 +1544,8 @@ { "__type__": "cc.RealCurve", "_times": [ - 0.2777777777777778, - 0.6666666666666666 + 0.2777777910232544, + 0.6666666865348816 ], "_values": [ { @@ -1585,8 +1585,8 @@ { "__type__": "cc.RealCurve", "_times": [ - 0.2777777777777778, - 0.6666666666666666 + 0.2777777910232544, + 0.6666666865348816 ], "_values": [ { diff --git a/assets/resources/game/skills/damageText.prefab b/assets/resources/game/skills/damageText.prefab new file mode 100644 index 00000000..55831ad8 --- /dev/null +++ b/assets/resources/game/skills/damageText.prefab @@ -0,0 +1,290 @@ +[ + { + "__type__": "cc.Prefab", + "_name": "damageText", + "_objFlags": 0, + "__editorExtras__": {}, + "_native": "", + "data": { + "__id__": 1 + }, + "optimizationPolicy": 0, + "persistent": false + }, + { + "__type__": "cc.Node", + "_name": "damageText", + "_objFlags": 0, + "__editorExtras__": {}, + "_parent": null, + "_children": [ + { + "__id__": 2 + } + ], + "_active": true, + "_components": [ + { + "__id__": 8 + }, + { + "__id__": 10 + } + ], + "_prefab": { + "__id__": 12 + }, + "_lpos": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_lrot": { + "__type__": "cc.Quat", + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "_lscale": { + "__type__": "cc.Vec3", + "x": 1, + "y": 1, + "z": 1 + }, + "_mobility": 0, + "_layer": 1, + "_euler": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_id": "" + }, + { + "__type__": "cc.Node", + "_name": "DamageText", + "_objFlags": 0, + "__editorExtras__": {}, + "_parent": { + "__id__": 1 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 3 + }, + { + "__id__": 5 + } + ], + "_prefab": { + "__id__": 7 + }, + "_lpos": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_lrot": { + "__type__": "cc.Quat", + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "_lscale": { + "__type__": "cc.Vec3", + "x": 1, + "y": 1, + "z": 1 + }, + "_mobility": 0, + "_layer": 1, + "_euler": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_id": "" + }, + { + "__type__": "cc.UITransform", + "_name": "", + "_objFlags": 0, + "__editorExtras__": {}, + "node": { + "__id__": 2 + }, + "_enabled": true, + "__prefab": { + "__id__": 4 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 22.61767578125, + "height": 39.8 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "b2q8sfHG5IWKdfC5g/dDbk" + }, + { + "__type__": "cc.Label", + "_name": "", + "_objFlags": 0, + "__editorExtras__": {}, + "node": { + "__id__": 2 + }, + "_enabled": true, + "__prefab": { + "__id__": 6 + }, + "_customMaterial": null, + "_srcBlendFactor": 2, + "_dstBlendFactor": 4, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 0, + "b": 0, + "a": 255 + }, + "_string": "10", + "_horizontalAlign": 1, + "_verticalAlign": 1, + "_actualFontSize": 25, + "_fontSize": 25, + "_fontFamily": "Arial", + "_lineHeight": 30, + "_overflow": 0, + "_enableWrapText": true, + "_font": { + "__uuid__": "a8f2a4a3-911f-43d3-9174-f2176554d7d4", + "__expectedType__": "cc.TTFFont" + }, + "_isSystemFontUsed": false, + "_spacingX": 0, + "_isItalic": false, + "_isBold": false, + "_isUnderline": false, + "_underlineHeight": 2, + "_cacheMode": 1, + "_enableOutline": true, + "_outlineColor": { + "__type__": "cc.Color", + "r": 0, + "g": 0, + "b": 0, + "a": 255 + }, + "_outlineWidth": 1, + "_enableShadow": false, + "_shadowColor": { + "__type__": "cc.Color", + "r": 0, + "g": 0, + "b": 0, + "a": 255 + }, + "_shadowOffset": { + "__type__": "cc.Vec2", + "x": 2, + "y": 2 + }, + "_shadowBlur": 2, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "c7azLszJlJJ4fkJyxPrZYJ" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__id__": 0 + }, + "fileId": "76Mh85YlFJNY/DWA9qkpBH", + "instance": null, + "targetOverrides": null, + "nestedPrefabInstanceRoots": null + }, + { + "__type__": "cc.UITransform", + "_name": "", + "_objFlags": 0, + "__editorExtras__": {}, + "node": { + "__id__": 1 + }, + "_enabled": true, + "__prefab": { + "__id__": 9 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 100, + "height": 100 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "2fHdG8eeBH07DW0tmYrhH9" + }, + { + "__type__": "96d16N6LftMNLYMRBRGVsYW", + "_name": "", + "_objFlags": 0, + "__editorExtras__": {}, + "node": { + "__id__": 1 + }, + "_enabled": true, + "__prefab": { + "__id__": 11 + }, + "label": { + "__id__": 5 + }, + "critEffect": null, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "8aOWJ+ZllPHKeljR7my1SB" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__id__": 0 + }, + "fileId": "c46/YsCPVOJYA4mWEpNYRx", + "instance": null, + "targetOverrides": null + } +] \ No newline at end of file diff --git a/assets/resources/game/skills/damageText.prefab.meta b/assets/resources/game/skills/damageText.prefab.meta new file mode 100644 index 00000000..0f050e35 --- /dev/null +++ b/assets/resources/game/skills/damageText.prefab.meta @@ -0,0 +1,13 @@ +{ + "ver": "1.1.50", + "importer": "prefab", + "imported": true, + "uuid": "cd550fa0-4951-4d3c-a22e-c7ad5520ade4", + "files": [ + ".json" + ], + "subMetas": {}, + "userData": { + "syncNodeName": "damageText" + } +} diff --git a/assets/script/Main.ts b/assets/script/Main.ts index 6f70d569..2d5d5cf9 100644 --- a/assets/script/Main.ts +++ b/assets/script/Main.ts @@ -8,9 +8,7 @@ import { smc } from './game/common/SingletonModuleComp'; import { Initialize } from './game/initialize/Initialize'; import { EcsPositionSystem } from './game/common/ecs/position/EcsPositionSystem'; import { EcsSkillSystem } from './game/skill/EcsSkillSystem'; -import { DamageSystem } from './game/damage/DamageSystem'; -import { DamageShowSystem } from './game/damage/DamageShowSystem'; -import { BattleEndSystem } from './game/battle/BattleEndSystem'; + const { ccclass, property } = _decorator; @@ -21,12 +19,6 @@ export class Main extends Root { protected async run() { smc.initialize = ecs.getEntity(Initialize); smc.vmAdd() - ecs.System.init( - DamageSystem, - DamageShowSystem, - BattleEndSystem, - // ...其他系统... - ); } protected initGui() { oops.gui.init(UIConfigData); diff --git a/assets/script/common.meta b/assets/script/common.meta new file mode 100644 index 00000000..4ddc7328 --- /dev/null +++ b/assets/script/common.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.2.0", + "importer": "directory", + "imported": true, + "uuid": "7df2a856-04db-4d7e-8c91-90db8e4e63e9", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/script/game/battle/BattleEndSystem.ts b/assets/script/game/battle/BattleEndSystem.ts new file mode 100644 index 00000000..a93d310c --- /dev/null +++ b/assets/script/game/battle/BattleEndSystem.ts @@ -0,0 +1,24 @@ +import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; +import { BattleState } from "./BattleStateComp"; +import { DamageResult } from "../damage/DamageComp"; + +@ecs.register('BattleEndSystem') +export class BattleEndSystem extends ecs.ComblockSystem { + filter(): ecs.IMatcher { + return ecs.allOf(BattleState); + + } + + update(e: ecs.Entity) { + const state = e.get(BattleState); + if (state.isEnded) { + // 清理所有残留伤害组件 + ecs.query(ecs.allOf(DamageResult)).forEach(entity => { + entity.remove(DamageResult); + }); + + // 重置战斗状态 + state.isEnded = false; + } + } +} \ No newline at end of file diff --git a/assets/script/game/battle/BattleManager.ts b/assets/script/game/battle/BattleManager.ts index 9998ee18..3d3c3460 100644 --- a/assets/script/game/battle/BattleManager.ts +++ b/assets/script/game/battle/BattleManager.ts @@ -3,7 +3,6 @@ import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ec import { BattleState } from "./BattleStateComp"; import { smc } from "../common/SingletonModuleComp"; import { GameEvent } from "../common/config/GameEvent"; -import { DamageResult } from "../damage/DamageComp"; @ecs.register('BattleManager') export class BattleManager extends ecs.Entity { @@ -72,12 +71,6 @@ export class BattleManagerSystem extends ecs.ComblockSystem { private onBattleEnd(entity: ecs.Entity) { // 发放奖励、保存进度等 - const state = entity.get(BattleState); // 清理所有残留伤害组件 - ecs.query(ecs.allOf(DamageResult)).forEach(entity => { - entity.remove(DamageResult); - }); - // 重置战斗状态 - state.isEnded = false; entity.destroy(); } } \ No newline at end of file diff --git a/assets/script/game/damage/DamageComp.ts b/assets/script/game/damage/DamageComp.ts index a2c8b23a..60d964b1 100644 --- a/assets/script/game/damage/DamageComp.ts +++ b/assets/script/game/damage/DamageComp.ts @@ -1,3 +1,4 @@ +import { Vec3 } from "cc"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; export enum DamageType { @@ -15,6 +16,7 @@ export class DamageRequest extends ecs.Comp { damageType: number = 1; // 伤害类型 canCrit: boolean = true; // 是否可暴击 ignoreDefense: boolean = false; // 是否忽略防御 + delay: number = 0; // 新增延迟时间属性 reset() { this.source = null!; @@ -23,19 +25,24 @@ export class DamageRequest extends ecs.Comp { this.damageType = 1; this.canCrit = true; this.ignoreDefense = false; + this.delay = 0; } } -/** 伤害结果组件 */ +/** 伤害结果组件 */ @ecs.register('DamageResult') export class DamageResult extends ecs.Comp { - finalDamage: number = 0; - isCrit: boolean = false; - isDodged: boolean = false; + value: number = 0; // 伤害数值 + isCrit: boolean = false; // 是否暴击 + isDodged: boolean = false; // 是否闪避 + delay: number = 0; // 显示延迟(秒) + position: Vec3 = new Vec3();// 显示位置 - reset(finalDamage: number = 0, isCrit: boolean = false, isDodged: boolean = false) { - this.finalDamage = finalDamage; - this.isCrit = isCrit; - this.isDodged = isDodged; + reset() { + this.value = 0; + this.isCrit = false; + this.isDodged = false; + this.delay = 0; + this.position.set(0, 0, 0); } } \ No newline at end of file diff --git a/assets/script/game/damage/DamageShowSystem.ts b/assets/script/game/damage/DamageShowSystem.ts index 6a5744e3..29cd8ea0 100644 --- a/assets/script/game/damage/DamageShowSystem.ts +++ b/assets/script/game/damage/DamageShowSystem.ts @@ -1,21 +1,96 @@ +import { _decorator, NodePool, Node, Label, Color, tween, Vec3, instantiate, Prefab, resources } from "cc"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; -import { HeroViewComp } from "../hero/HeroViewComp"; import { DamageResult } from "./DamageComp"; +import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; +import { DamageText } from "./DamageText"; @ecs.register('DamageShowSystem') -export class DamageShowSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate { +export class DamageShowSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate{ + private _pool: NodePool = new NodePool(); + private _timers: Set = new Set(); + private _prefab: Prefab | null = null; + + init() { + // 使用原生资源加载 + resources.load("game/skills/damageText", Prefab, (err, prefab) => { + if (err) { + console.error("预制体加载失败:", err); + return; + } + this._prefab = prefab; + console.log("预制体加载成功:", this._prefab); + // 初始化对象池 + for (let i = 0; i < 10; i++) { + const node = instantiate(this._prefab!); + this._pool.put(node); + } + }); + } + filter(): ecs.IMatcher { - return ecs.allOf(DamageResult, HeroViewComp); + return ecs.allOf(DamageResult); } update(e: ecs.Entity) { const res = e.get(DamageResult); - const view = e.get(HeroViewComp); - - // 显示伤害数字 - view.showDamage(res.finalDamage, res.isCrit); - - // 移除已处理的伤害结果组件 + this.scheduleShow(res); e.remove(DamageResult); } + + private scheduleShow(res: DamageResult) { + const timer = setTimeout(() => { + let node = this._pool.get(); + if (!node || !node.isValid) { + node = instantiate(this._prefab); + } + + const damageText = node.getComponent(DamageText); + + if (!damageText) { + console.error("Damage text prefab must have DamageText component!"); + return; + } + + this.setupText(node, res); + this.playAnimation(node, res.position); + + this._timers.delete(timer); + }, res.delay * 1000); + + this._timers.add(timer); + } + + private setupText(node: Node, res: DamageResult) { + const damageText = node.getComponent(DamageText)!; + const label = damageText.label; + + if (res.isDodged) { + label.string = "Miss"; + label.color = Color.GRAY; + return; + } + + label.string = Math.round(res.value).toString(); + label.color = res.isCrit ? Color.RED : Color.WHITE; + damageText.playEffect(res.isCrit); + } + + private playAnimation(node: Node, position: Vec3) { + node.setPosition(position); + tween(node) + .by(0.5, { position: new Vec3(0, 100, 0) }) + .call(() => { + if (this._pool.size() < 20) { // 控制最大缓存数量 + this._pool.put(node); + } else { + node.destroy(); + } + }) + .start(); + } + + onDestroy() { + this._timers.forEach(clearTimeout); + this._pool.clear(); + } } \ No newline at end of file diff --git a/assets/script/game/damage/DamageShowSystem.ts.meta b/assets/script/game/damage/DamageShowSystem.ts.meta index c23c498e..4bfd68fc 100644 --- a/assets/script/game/damage/DamageShowSystem.ts.meta +++ b/assets/script/game/damage/DamageShowSystem.ts.meta @@ -2,7 +2,7 @@ "ver": "4.0.23", "importer": "typescript", "imported": true, - "uuid": "a9a6c37c-d5c7-4811-bc7a-471c8ed7b022", + "uuid": "9c86e3d7-f8da-4e74-b180-76fe3f1fda90", "files": [], "subMetas": {}, "userData": {} diff --git a/assets/script/game/damage/DamageSystem.ts b/assets/script/game/damage/DamageSystem.ts index d1ba2b84..2ddd324b 100644 --- a/assets/script/game/damage/DamageSystem.ts +++ b/assets/script/game/damage/DamageSystem.ts @@ -5,15 +5,17 @@ import { DamageRequest, DamageResult } from "./DamageComp"; @ecs.register('DamageSystem') export class DamageSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate { + private _timers: { [key: string]: number } = {}; + filter(): ecs.IMatcher { return ecs.allOf(DamageRequest); } - update(entity: ecs.Entity) { - const req = entity.get(DamageRequest); + update(e: ecs.Entity) { + const req = e.get(DamageRequest); const result = this.calculateDamage(req); this.applyDamage(req.target, result); - entity.remove(DamageRequest); + e.remove(DamageRequest); } private calculateDamage(req: DamageRequest): DamageResult { @@ -24,7 +26,6 @@ export class DamageSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat // 闪避判定 if (Math.random() < targetView.dodge) { const result = new DamageResult(); - result.finalDamage = 0; result.isDodged = true; return result; } @@ -45,25 +46,28 @@ export class DamageSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat } const result = new DamageResult(); - result.finalDamage = Math.max(0, final); + result.value = Math.max(0, final); result.isCrit = isCrit; + result.position = req.target.get(HeroViewComp).node.position; + result.delay = req.delay; return result; } private applyDamage(target: ecs.Entity, result: DamageResult) { const view = target.get(HeroViewComp); - view.hp -= result.finalDamage; - + view.hp -= result.value; // 添加伤害结果组件 const comp = target.add(DamageResult); - comp.finalDamage = result.finalDamage; + comp.value = result.value; comp.isCrit = result.isCrit; + comp.position = result.position; + comp.delay = result.delay; comp.isDodged = result.isDodged; - + // 触发伤害事件 oops.message.dispatchEvent("OnDamage", { target, - damage: result.finalDamage, + damage: result.value, isCrit: result.isCrit }); } diff --git a/assets/script/game/damage/DamageText.ts b/assets/script/game/damage/DamageText.ts new file mode 100644 index 00000000..748a4c91 --- /dev/null +++ b/assets/script/game/damage/DamageText.ts @@ -0,0 +1,17 @@ +import { _decorator, Component, Label, ParticleSystem } from "cc"; +const { ccclass, property } = _decorator; + +@ccclass('DamageText') +export class DamageText extends Component { + @property(Label) + label: Label = null!; + + @property(ParticleSystem) + critEffect: ParticleSystem = null!; + + playEffect(isCrit: boolean) { + if (isCrit && this.critEffect) { + this.critEffect.play(); + } + } +} \ No newline at end of file diff --git a/assets/script/game/damage/DamageText.ts.meta b/assets/script/game/damage/DamageText.ts.meta new file mode 100644 index 00000000..9d817ed2 --- /dev/null +++ b/assets/script/game/damage/DamageText.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "96d1637a-2dfb-4c34-b60c-44144656c616", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/script/game/hero/HeroViewComp.ts b/assets/script/game/hero/HeroViewComp.ts index ca9c83be..99c56df1 100644 --- a/assets/script/game/hero/HeroViewComp.ts +++ b/assets/script/game/hero/HeroViewComp.ts @@ -193,7 +193,7 @@ export class HeroViewComp extends CCComp { } this.hp_less(l_hp,is_crit); } - hp_less(hp: number,is_crit:boolean=false){ + hp_less(hp: number,is_crit:boolean=false,delay:number=0){ if(this.is_dead) return hp=Math.floor(hp) this.hp -= hp @@ -211,17 +211,7 @@ export class HeroViewComp extends CCComp { this.is_dead = true; } } - check_less(ap:number,is_crit:boolean,crit_add:number=0){ - let d=this.def/ap - if(d > 1) d = 1 - let l_hp=ap*(1-d*GameSet.DEF_RATE) //防御最高减免伤害比率计算 - if(is_crit){ - l_hp = l_hp * (150+crit_add)/100 - } - let luck = RandomManager.instance.getRandomInt(-10,10) - l_hp=l_hp*(100+luck)/100 - return Math.ceil(l_hp) - } + /** * 检查并处理英雄受到的减益效果(debuff)。 * 根据技能的不同减益类型,执行相应的逻辑,如冰冻、燃烧等。 diff --git a/assets/script/game/map/MapView.ts.meta b/assets/script/game/map/MapView.ts.meta new file mode 100644 index 00000000..9e74688e --- /dev/null +++ b/assets/script/game/map/MapView.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "3748c53e-6b9b-479f-aba0-87fc123ce161", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/script/game/skill/EcsSkillSystem.ts b/assets/script/game/skill/EcsSkillSystem.ts index a70a0a76..39c7c42d 100644 --- a/assets/script/game/skill/EcsSkillSystem.ts +++ b/assets/script/game/skill/EcsSkillSystem.ts @@ -1,12 +1,16 @@ import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { HeroSkillSystem } from "./HeroSkillSystem"; import { DamageSystem } from "../damage/DamageSystem"; +import { BattleManagerSystem } from "../battle/BattleManager"; +import { BattleEndSystem } from "../battle/BattleEndSystem"; export class EcsSkillSystem extends ecs.System { constructor() { super(); this.add(new HeroSkillSystem()); this.add(new DamageSystem()); - + this.add(new BattleManagerSystem()); + this.add(new BattleEndSystem()); + } diff --git a/assets/script/game/skill/HeroSkillSystem.ts b/assets/script/game/skill/HeroSkillSystem.ts index 0f2c33d3..d0207cd2 100644 --- a/assets/script/game/skill/HeroSkillSystem.ts +++ b/assets/script/game/skill/HeroSkillSystem.ts @@ -206,6 +206,7 @@ export class HeroSkillSystem extends ecs.ComblockSystem implements ecs.ISystemUp req.source = caster; req.target = target; req.baseValue = caster.get(HeroViewComp).ap * (config.ap / 100); + req.delay = config.hited; // 添加命中延迟时间(秒)用于同步动画与伤害 // 播放技能特效 caster.get(HeroViewComp).playSkillEffect(config.uuid); diff --git a/tsconfig.json b/tsconfig.json index 66c3e018..02f0abad 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,7 @@ /* Add your custom configuration here. */ "compilerOptions": { "strict": false, - "target": "es2016", - "lib": ["es2016", "dom"] + "target": "es2017", + "lib": ["es2017", "dom"] } }