You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
177 lines
6.7 KiB
177 lines
6.7 KiB
import { _decorator, Component, find, Label, Node, Prefab, sp, Tween, tween, v3, Vec3 } from 'cc';
|
|
import { GBundle, UIID } from '../../game/ConfigRes';
|
|
import { BattleType } from '../../manager/ChapterDataManager';
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('DiamondTreasure')
|
|
export class DiamondTreasure extends Component {
|
|
Sk: sp.Skeleton = null;
|
|
isCanClick: boolean = true;
|
|
|
|
boxNumLabel: Label = null;
|
|
|
|
lableTip: Node = null;
|
|
|
|
protected onLoad(): void {
|
|
this.boxNumLabel = this.node.getChildByName('boxNum').getComponent(Label);
|
|
this.Sk = this.node.getChildByName('宝箱').getComponent(sp.Skeleton);
|
|
|
|
}
|
|
protected onEnable(): void {
|
|
this.node.on(Node.EventType.TOUCH_START, this.onClickTreasure, this);
|
|
// 节点再次启用/复用时,确保可点击状态被恢复(避免上一次中途打断导致 isCanClick 卡死)
|
|
this.isCanClick = true;
|
|
}
|
|
protected onDisable(): void {
|
|
this.node.off(Node.EventType.TOUCH_START, this.onClickTreasure, this);
|
|
}
|
|
public playSpine(name: string, callback: Function = null, timeScale = 1, loop = true) {
|
|
this.Sk = this.node.getChildByName('宝箱').getComponent(sp.Skeleton);
|
|
this.Sk.setCompleteListener(() => {
|
|
this.Sk.setCompleteListener(null);
|
|
if (callback) callback();
|
|
});
|
|
this.Sk.timeScale = timeScale * 1
|
|
this.Sk.setAnimation(0, name, loop);
|
|
}
|
|
|
|
/**
|
|
* 打开宝物动画
|
|
*/
|
|
public openTreasure() {
|
|
this.boxNumLabel = this.node.getChildByName('boxNum').getComponent(Label);
|
|
this.Sk = this.node.getChildByName('宝箱').getComponent(sp.Skeleton);
|
|
|
|
if (!this.isCanClick) {
|
|
console.log('[SkillSelectTrace]', JSON.stringify({ step: 'click_ignored', reason: 'isCanClick_false' }));
|
|
return
|
|
}
|
|
console.log("打开宝物动画");
|
|
gg.audio.playEffect({ name: "钻石宝箱打开音效" });
|
|
if (gg.game.playerWeaponIdArray.length > 0 || gg.game.playerSkillIdArray.length > 0 || gg.game.setPlayerSkillGroupIdArray || gg.game.setPlayerWeaponGroupIdArray) {
|
|
//
|
|
console.log("GM有武器或技能,不开启转盘");
|
|
|
|
this.node.active = false
|
|
this.isCanClick = true
|
|
return
|
|
}
|
|
|
|
this.isCanClick = false
|
|
let curWaveNum = gg.game.CurentBattle.CurentWaveNum
|
|
gg.sdk.reportDY("inLevel", `章节${gg.game.CurentBattle.getReportDYChapterId()}_${curWaveNum}-点击掉落宝箱`)
|
|
|
|
let index = gg.game.CurentBattle.IsOpenSkillSelectTimes;
|
|
if (index >= gg.game.CurentBattle.OpenSkillSelectCoinArr.length) {
|
|
index = gg.game.CurentBattle.OpenSkillSelectCoinArr.length - 1;
|
|
}
|
|
let coinNum = gg.game.CurentBattle.OpenSkillSelectCoinArr[index] ?? 0;
|
|
const shouldChargeCoin = gg.game.CurentBattle.BattleType != BattleType.OrangeWeaponMode_Dian;
|
|
|
|
gg.ui.popSkillSelectFromTreasure({
|
|
onSkillSelectOpenSuccess: () => {
|
|
this.onSkillSelectOpened(coinNum, shouldChargeCoin);
|
|
},
|
|
onSkillSelectOpenFail: (reason, detail, context) => {
|
|
this.onSkillSelectOpenFailed(reason, detail, context);
|
|
},
|
|
});
|
|
}
|
|
|
|
/** SkillSelect 确认打开后再扣银币并播放开箱动画 */
|
|
private onSkillSelectOpened(coinNum: number, shouldChargeCoin: boolean) {
|
|
if (shouldChargeCoin && coinNum > 0) {
|
|
gg.game.CurentBattle.subCoinNum(coinNum);
|
|
}
|
|
this.playSpine('play', () => {
|
|
gg.game.CurentBattle.tetriSaveBoxNum--
|
|
this.refreshBoxNum()
|
|
if (gg.game.CurentBattle.tetriSaveBoxNum == 0) {
|
|
this.playSpine('idle')
|
|
this.isCanClick = true
|
|
this.node.active = false
|
|
} else {
|
|
this.playSpine('idle')
|
|
this.isCanClick = true
|
|
this.node.active = true
|
|
}
|
|
}, 1.5, false)
|
|
}
|
|
|
|
/** SkillSelect 打开失败:回滚可点击状态,不扣银币、不减宝箱计数 */
|
|
private onSkillSelectOpenFailed(reason: string, detail?: string, context?: Record<string, unknown>) {
|
|
const battle = gg.game?.CurentBattle;
|
|
console.error('[SkillSelectFail]', JSON.stringify({
|
|
source: 'treasure',
|
|
reason,
|
|
detail: detail ?? '',
|
|
wave: battle?.CurentWaveNum,
|
|
chapter: battle?.ChapterId,
|
|
openTimes: battle?.IsOpenSkillSelectTimes,
|
|
saveBoxNum: battle?.tetriSaveBoxNum,
|
|
panelType: context?.panelType ?? 'unknown',
|
|
pickSkillIds: context?.pickSkillIds ?? [],
|
|
pickWeaponIds: context?.pickWeaponIds ?? [],
|
|
curWeaponIds: context?.curWeaponIds ?? [],
|
|
curSkillIds: context?.curSkillIds ?? [],
|
|
}));
|
|
this.isCanClick = true;
|
|
gg.ui.showToast('技能选择界面打开失败,请重试', false);
|
|
}
|
|
|
|
refreshBoxNum() {
|
|
this.boxNumLabel = this.node.getChildByName('boxNum').getComponent(Label);
|
|
if (gg.game.CurentBattle.tetriSaveBoxNum <= 1) {
|
|
this.boxNumLabel.node.active = false
|
|
} else {
|
|
this.boxNumLabel.node.active = false
|
|
this.boxNumLabel.string = 'x' + gg.game.CurentBattle.tetriSaveBoxNum.toString()
|
|
}
|
|
|
|
}
|
|
|
|
|
|
onClickTreasure() {
|
|
console.log('[SkillSelectTrace]', JSON.stringify({
|
|
step: 'click',
|
|
wave: gg.game.CurentBattle?.CurentWaveNum,
|
|
saveBoxNum: gg.game.CurentBattle?.tetriSaveBoxNum,
|
|
openTimes: gg.game.CurentBattle?.IsOpenSkillSelectTimes,
|
|
coin: gg.game.CurentBattle?.CurentCoinNum,
|
|
}));
|
|
let index = gg.game.CurentBattle.IsOpenSkillSelectTimes;
|
|
if (index >= gg.game.CurentBattle.OpenSkillSelectCoinArr.length) {
|
|
index = gg.game.CurentBattle.OpenSkillSelectCoinArr.length - 1;
|
|
}
|
|
let num = gg.game.CurentBattle.OpenSkillSelectCoinArr[index];
|
|
|
|
if(gg.game.CurentBattle.BattleType == BattleType.OrangeWeaponMode_Dian){
|
|
|
|
}else{
|
|
if (gg.game.CurentBattle.CurentCoinNum < num) {
|
|
gg.ui.showToast('银币不足')
|
|
return
|
|
}
|
|
}
|
|
|
|
if (this.lableTip)
|
|
this.lableTip.active = false;
|
|
|
|
let paopao = this.node.getChildByName('paopao')
|
|
if (paopao?.isValid && paopao.active) {
|
|
Tween.stopAllByTarget(paopao);
|
|
|
|
tween(paopao)
|
|
.to(0.5, { scale:Vec3.ZERO }, { easing: 'quadInOut' })
|
|
.call(() => {
|
|
paopao.active = false;
|
|
})
|
|
.start();
|
|
}
|
|
|
|
this.openTreasure()
|
|
}
|
|
}
|
|
|
|
|
|
|