From 5686adc79d82391ea8f251727547cc0eee98f625 Mon Sep 17 00:00:00 2001 From: walkpan Date: Thu, 2 Apr 2026 08:11:36 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BB=BB=E5=8A=A1=E5=8D=A1):=20=E5=85=81?= =?UTF-8?q?=E8=AE=B8=E5=9C=A8=E8=8B=B1=E9=9B=84=E6=BB=A1=E5=91=98=E6=97=B6?= =?UTF-8?q?=E9=80=9A=E8=BF=87=E5=90=88=E5=B9=B6=E8=A7=84=E5=88=99=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E8=8B=B1=E9=9B=84=E5=8D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当英雄数量达到上限时,检查新英雄卡是否符合合并规则。如果满足相同英雄和等级的数量要求,则允许使用该卡进行合并升级,避免因上限限制而无法使用英雄卡。 --- assets/script/game/map/MissionCardComp.ts | 41 +++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/assets/script/game/map/MissionCardComp.ts b/assets/script/game/map/MissionCardComp.ts index 41b099e1..6e6e7ab8 100644 --- a/assets/script/game/map/MissionCardComp.ts +++ b/assets/script/game/map/MissionCardComp.ts @@ -13,6 +13,7 @@ import { HeroInfo, HType } from "../common/config/heroSet"; import { HeroViewComp } from "../hero/HeroViewComp"; import { FacSet } from "../common/config/GameSet"; import { MoveComp } from "../hero/MoveComp"; +import { MissionHeroCompComp } from "./MissionHeroComp"; const { ccclass, property } = _decorator; @@ -231,6 +232,13 @@ export class MissionCardComp extends CCComp { this.syncMissionHeroData(current); const heroMax = this.getMissionHeroMaxNum(); if (current >= heroMax) { + const heroUuid = Number(payload?.uuid ?? 0); + const heroLv = Math.max(1, Math.floor(Number(payload?.hero_lv ?? 1))); + if (this.canUseHeroCardByMerge(heroUuid, heroLv)) { + payload.cancel = false; + payload.reason = ""; + return; + } payload.cancel = true; payload.reason = "hero_limit"; oops.gui.toast(`英雄已满 (${current}/${heroMax})`); @@ -238,6 +246,39 @@ export class MissionCardComp extends CCComp { } } + private canUseHeroCardByMerge(heroUuid: number, heroLv: number): boolean { + if (!heroUuid) return false; + const mergeRule = this.getMergeRule(); + if (heroLv >= mergeRule.maxLv) return false; + const sameCount = this.countAliveHeroesByUuidAndLv(heroUuid, heroLv); + return sameCount + 1 >= mergeRule.needCount; + } + + private countAliveHeroesByUuidAndLv(heroUuid: number, heroLv: number): number { + let count = 0; + const actors = this.queryAliveHeroActors(); + for (let i = 0; i < actors.length; i++) { + const model = actors[i].model; + if (!model) continue; + if (model.hero_uuid !== heroUuid) continue; + if (model.lv !== heroLv) continue; + count += 1; + } + return count; + } + + private getMergeRule(): { needCount: number, maxLv: number } { + let needCount = 2; + let maxLv = 3; + ecs.query(ecs.allOf(MissionHeroCompComp)).forEach((entity: ecs.Entity) => { + const comp = entity.get(MissionHeroCompComp); + if (!comp) return; + needCount = comp.merge_need_count === 2 ? 2 : 3; + maxLv = Math.max(1, Math.floor(comp.merge_max_lv ?? 3)); + }); + return { needCount, maxLv }; + } + private onUseSpecialCard(event: string, args: any) { const payload = args ?? event; const uuid = Number(payload?.uuid ?? 0);