fix(map): 修复抽卡重复英雄和英雄站位偏移问题
1. 新增英雄卡UUID去重逻辑,避免单次抽卡出现重复英雄 2. 调整英雄初始站位坐标,修正布局偏移问题 3. 统一代码格式,修复缩进和类型注解不规范问题
This commit is contained in:
@@ -49,8 +49,8 @@ export class MissionHeroComp extends CCComp {
|
||||
|
||||
/** 硬编码的6个英雄占位点 */
|
||||
public static readonly HERO_POSITIONS: Vec3[] = [
|
||||
v3(-180, BoxSet.GAME_LINE, 0), // index 0 (node_index 1): Top Front 第二
|
||||
v3(-80, BoxSet.GAME_LINE, 0), // index 1 (node_index 2): Mid Front 第一
|
||||
v3(-200, BoxSet.GAME_LINE, 0), // index 0 (node_index 1): Top Front 第二
|
||||
v3(-120, BoxSet.GAME_LINE, 0), // index 1 (node_index 2): Mid Front 第一
|
||||
v3(-280, BoxSet.GAME_LINE, 0), // index 2 (node_index 3): Bot Front 第三
|
||||
// v3(-280, BoxSet.GAME_LINE + 100, 0), // index 3 (node_index 4): Top Back
|
||||
// v3(-280, BoxSet.GAME_LINE, 0), // index 4 (node_index 5): Mid Back
|
||||
@@ -63,37 +63,37 @@ export class MissionHeroComp extends CCComp {
|
||||
// ======================== 运行时属性 ========================
|
||||
|
||||
/** 预留计时器 */
|
||||
timer:Timer=new Timer(2)
|
||||
timer: Timer = new Timer(2)
|
||||
/** 预留状态:友方是否全部死亡 */
|
||||
Friend_is_dead:boolean=false
|
||||
Friend_is_dead: boolean = false
|
||||
/** 当前处理的英雄 uuid */
|
||||
current_hero_uuid:number=0
|
||||
current_hero_uuid: number = 0
|
||||
/** 当前英雄数量缓存 */
|
||||
current_hero_num:number=-1
|
||||
current_hero_num: number = -1
|
||||
/** 是否正在消费召唤队列(防止并发) */
|
||||
is_processing_queue:boolean=false
|
||||
is_processing_queue: boolean = false
|
||||
/** 召唤请求队列:保证召唤按顺序串行执行 */
|
||||
summon_queue:{ uuid: number; hero_lv: number; pool_lv: number }[]=[]
|
||||
summon_queue: { uuid: number; hero_lv: number; pool_lv: number }[] = []
|
||||
/** 预留英雄列表 */
|
||||
heros:any=[]
|
||||
heros: any = []
|
||||
|
||||
// ======================== 生命周期 ========================
|
||||
|
||||
onLoad(){
|
||||
onLoad() {
|
||||
// 注册节点级事件
|
||||
this.on(GameEvent.FightReady,this.fight_ready,this)
|
||||
this.on(GameEvent.Zhaohuan,this.zhao_huan,this)
|
||||
this.on(GameEvent.MissionEnd,this.clear_heros,this)
|
||||
this.on(GameEvent.FightReady, this.fight_ready, this)
|
||||
this.on(GameEvent.Zhaohuan, this.zhao_huan, this)
|
||||
this.on(GameEvent.MissionEnd, this.clear_heros, this)
|
||||
// 注册全局消息
|
||||
oops.message.on(GameEvent.CallHero,this.call_hero,this)
|
||||
oops.message.on("PhasePrepareStart",this.fight_ready,this)
|
||||
oops.message.on(GameEvent.CallHero, this.call_hero, this)
|
||||
oops.message.on("PhasePrepareStart", this.fight_ready, this)
|
||||
}
|
||||
|
||||
onDestroy(){
|
||||
onDestroy() {
|
||||
super.onDestroy();
|
||||
// 清理全部监听
|
||||
oops.message.off(GameEvent.CallHero,this.call_hero,this)
|
||||
oops.message.off("PhasePrepareStart",this.fight_ready,this)
|
||||
oops.message.off(GameEvent.CallHero, this.call_hero, this)
|
||||
oops.message.off("PhasePrepareStart", this.fight_ready, this)
|
||||
}
|
||||
|
||||
start() {
|
||||
@@ -102,7 +102,7 @@ export class MissionHeroComp extends CCComp {
|
||||
// ======================== 事件处理 ========================
|
||||
|
||||
/** 关卡结束时清理全部英雄 ECS 实体 */
|
||||
clear_heros(){
|
||||
clear_heros() {
|
||||
const heroes = this.getAllHeroes();
|
||||
for (let i = 0; i < heroes.length; i++) {
|
||||
heroes[i].destroy();
|
||||
@@ -110,7 +110,7 @@ export class MissionHeroComp extends CCComp {
|
||||
}
|
||||
|
||||
/** 战斗准备阶段:重置出战英雄计数,恢复满血重新登场 */
|
||||
fight_ready(){
|
||||
fight_ready() {
|
||||
const heroes = this.getAllHeroes();
|
||||
smc.vmdata.mission_data.hero_num = heroes.length;
|
||||
for (let i = 0; i < heroes.length; i++) {
|
||||
@@ -135,7 +135,7 @@ export class MissionHeroComp extends CCComp {
|
||||
}
|
||||
|
||||
/** 预留:召唤事件扩展入口 */
|
||||
private zhao_huan(event: string, args: any){
|
||||
private zhao_huan(event: string, args: any) {
|
||||
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ export class MissionHeroComp extends CCComp {
|
||||
* @param event 事件名
|
||||
* @param args { uuid, hero_lv, pool_lv }
|
||||
*/
|
||||
private async call_hero(event: string, args: any){
|
||||
private async call_hero(event: string, args: any) {
|
||||
const payload = args ?? event;
|
||||
const uuid = Number(payload?.uuid ?? 1001);
|
||||
const hero_lv = Math.max(1, Number(payload?.hero_lv ?? 1));
|
||||
@@ -196,7 +196,7 @@ export class MissionHeroComp extends CCComp {
|
||||
const m = h.get(HeroAttrsComp);
|
||||
if (m && m.posIndex >= 0) occupied.add(m.posIndex);
|
||||
}
|
||||
|
||||
|
||||
// 优先中前(1) -> 上前(0) -> 下前(2) -> 中后(4) -> 上后(3) -> 下后(5)
|
||||
const slotPriority = [1, 0, 2, 4, 3, 5];
|
||||
for (const idx of slotPriority) {
|
||||
@@ -204,7 +204,7 @@ export class MissionHeroComp extends CCComp {
|
||||
return idx;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 溢出:默认中前
|
||||
return 1;
|
||||
}
|
||||
@@ -219,14 +219,14 @@ export class MissionHeroComp extends CCComp {
|
||||
* @param pool_lv 卡池等级(历史遗留,新机制下不再使用)
|
||||
* @returns 创建的 Hero 实体
|
||||
*/
|
||||
private addHero(uuid:number=1001,hero_lv:number=1, pool_lv:number=1) {
|
||||
private addHero(uuid: number = 1001, hero_lv: number = 1, pool_lv: number = 1) {
|
||||
let hero = ecs.getEntity<Hero>(Hero);
|
||||
let scale = 1
|
||||
const posIndex = this.pickPositionIndexForHero();
|
||||
const landingPos = MissionHeroComp.HERO_POSITIONS[posIndex];
|
||||
let spawnPos:Vec3 = v3(landingPos.x, landingPos.y + MissionHeroComp.HERO_DROP_HEIGHT, 0);
|
||||
hero.load(spawnPos,scale,uuid,landingPos.y,hero_lv,pool_lv,posIndex);
|
||||
|
||||
let spawnPos: Vec3 = v3(landingPos.x, landingPos.y + MissionHeroComp.HERO_DROP_HEIGHT, 0);
|
||||
hero.load(spawnPos, scale, uuid, landingPos.y, hero_lv, pool_lv, posIndex);
|
||||
|
||||
// 召唤完成后,派发事件以更新英雄面板
|
||||
const model = hero.get(HeroAttrsComp);
|
||||
if (model) {
|
||||
@@ -235,7 +235,7 @@ export class MissionHeroComp extends CCComp {
|
||||
model: model
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return hero;
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ export class MissionHeroComp extends CCComp {
|
||||
this.addHero(uuid, hero_lv, pool_lv);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** ECS 组件移除时触发(当前不销毁节点,保留引用) */
|
||||
reset() {
|
||||
// this.node.destroy();
|
||||
|
||||
Reference in New Issue
Block a user