feat(任务): 增加准备阶段与战斗阶段的切换逻辑
- 在准备阶段显示卡牌面板和开始战斗按钮,并发放金币奖励 - 进入战斗阶段时隐藏卡牌面板并禁用按钮 - 根据波数动态计算准备阶段金币奖励 - 修复金币同步和初始化问题
This commit is contained in:
@@ -3,7 +3,7 @@ import { _decorator, instantiate, Label, Node, NodeEventType, Prefab, SpriteAtla
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||
import { GameEvent } from "../common/config/GameEvent";
|
||||
import { CARD_POOL_INIT_LEVEL, CARD_POOL_MAX_LEVEL, CardConfig, CardInitCoins, CardsUpSet, getCardsByLv } from "../common/config/CardSet";
|
||||
import { CARD_POOL_INIT_LEVEL, CARD_POOL_MAX_LEVEL, CardConfig, CardsUpSet, getCardsByLv } from "../common/config/CardSet";
|
||||
import { CardComp } from "./CardComp";
|
||||
import { oops } from "db://oops-framework/core/Oops";
|
||||
import { HeroAttrsComp } from "../hero/HeroAttrsComp";
|
||||
@@ -25,6 +25,10 @@ export class MissionCardComp extends CCComp {
|
||||
/** 四个插卡槽位(固定顺序分发:1~4) */
|
||||
@property(Node)
|
||||
cards_node:Node = null!
|
||||
@property({ tooltip: "战斗阶段卡牌面板下移隐藏距离" })
|
||||
cardsBattleHideOffsetY: number = 1280;
|
||||
@property({ tooltip: "卡牌面板位移动画时长" })
|
||||
cardsPanelMoveDuration: number = 0.2;
|
||||
@property(Node)
|
||||
card1:Node = null!
|
||||
@property(Node)
|
||||
@@ -55,6 +59,9 @@ export class MissionCardComp extends CCComp {
|
||||
private poolLv: number = CARD_POOL_INIT_LEVEL;
|
||||
private readonly heroInfoItemGap: number = 86;
|
||||
private heroInfoSyncTimer: number = 0;
|
||||
private cardsShowPos: Vec3 = new Vec3();
|
||||
private cardsHidePos: Vec3 = new Vec3();
|
||||
private cardsPosReady: boolean = false;
|
||||
private heroInfoItems: Map<number, {
|
||||
node: Node,
|
||||
model: HeroAttrsComp,
|
||||
@@ -65,6 +72,7 @@ export class MissionCardComp extends CCComp {
|
||||
this.bindEvents();
|
||||
this.cacheCardComps();
|
||||
this.layoutCardSlots();
|
||||
this.initCardsPanelPos();
|
||||
this.onMissionStart();
|
||||
mLogger.log(this.debugMode, "MissionCardComp", "onLoad init", {
|
||||
slots: this.cardComps.length,
|
||||
@@ -82,10 +90,11 @@ export class MissionCardComp extends CCComp {
|
||||
|
||||
/** 任务开始时:重置卡池等级、清空4槽、显示面板 刷新一次卡池*/
|
||||
onMissionStart() {
|
||||
this.enterPreparePhase();
|
||||
this.poolLv = CARD_POOL_INIT_LEVEL;
|
||||
const missionData = this.getMissionData();
|
||||
if (missionData) {
|
||||
missionData.coin = CardInitCoins;
|
||||
missionData.coin = Math.max(0, Math.floor(missionData.coin ?? 0));
|
||||
missionData.hero_num = 0;
|
||||
missionData.hero_max_num = 5;
|
||||
missionData.hero_extend_max_num = 6;
|
||||
@@ -136,6 +145,7 @@ export class MissionCardComp extends CCComp {
|
||||
/** 生命周期事件 */
|
||||
this.on(GameEvent.MissionStart, this.onMissionStart, this);
|
||||
this.on(GameEvent.MissionEnd, this.onMissionEnd, this);
|
||||
this.on(GameEvent.FightStart, this.onFightStart, this);
|
||||
this.on(GameEvent.CoinAdd, this.onCoinAdd, this);
|
||||
oops.message.on(GameEvent.MasterCalled, this.onMasterCalled, this);
|
||||
oops.message.on(GameEvent.HeroDead, this.onHeroDead, this);
|
||||
@@ -150,12 +160,21 @@ export class MissionCardComp extends CCComp {
|
||||
this.cards_up?.on(NodeEventType.TOUCH_CANCEL, this.onUpgradeTouchCancel, this);
|
||||
}
|
||||
private onCoinAdd(args:any){
|
||||
if (args?.syncOnly) {
|
||||
this.updatePoolLvUI();
|
||||
this.playCoinChangeAnim((args?.delta ?? 0) > 0);
|
||||
return;
|
||||
}
|
||||
const v = typeof args === 'number' ? args : (args?.delta ?? args?.value ?? 0);
|
||||
if (v === 0) return;
|
||||
this.setMissionCoin(this.getMissionCoin() + v);
|
||||
this.updatePoolLvUI();
|
||||
this.playCoinChangeAnim(v > 0);
|
||||
}
|
||||
|
||||
private onFightStart() {
|
||||
this.enterBattlePhase();
|
||||
}
|
||||
|
||||
/** 解除按钮监听,避免节点销毁后回调泄漏 */
|
||||
private unbindEvents() {
|
||||
@@ -271,6 +290,34 @@ export class MissionCardComp extends CCComp {
|
||||
});
|
||||
}
|
||||
|
||||
private initCardsPanelPos() {
|
||||
if (!this.cards_node || !this.cards_node.isValid || this.cardsPosReady) return;
|
||||
const pos = this.cards_node.position;
|
||||
this.cardsShowPos = new Vec3(pos.x, pos.y, pos.z);
|
||||
this.cardsHidePos = new Vec3(pos.x, pos.y - Math.abs(this.cardsBattleHideOffsetY), pos.z);
|
||||
this.cardsPosReady = true;
|
||||
}
|
||||
|
||||
private enterPreparePhase() {
|
||||
if (!this.cards_node || !this.cards_node.isValid) return;
|
||||
this.initCardsPanelPos();
|
||||
this.cards_node.active = true;
|
||||
Tween.stopAllByTarget(this.cards_node);
|
||||
this.cards_node.setPosition(this.cardsShowPos);
|
||||
}
|
||||
|
||||
private enterBattlePhase() {
|
||||
if (!this.cards_node || !this.cards_node.isValid) return;
|
||||
this.initCardsPanelPos();
|
||||
this.cards_node.active = true;
|
||||
Tween.stopAllByTarget(this.cards_node);
|
||||
tween(this.cards_node)
|
||||
.to(this.cardsPanelMoveDuration, {
|
||||
position: this.cardsHidePos
|
||||
})
|
||||
.start();
|
||||
}
|
||||
|
||||
/** 构建本次抽卡结果,保证最终可分发4条数据 */
|
||||
private buildDrawCards(): CardConfig[] {
|
||||
const cards = getCardsByLv(this.poolLv);
|
||||
|
||||
Reference in New Issue
Block a user