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);