feat(任务卡): 允许在英雄满员时通过合并规则使用英雄卡
当英雄数量达到上限时,检查新英雄卡是否符合合并规则。如果满足相同英雄和等级的数量要求,则允许使用该卡进行合并升级,避免因上限限制而无法使用英雄卡。
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user