DaFuWeng/assets/Script/DialogNode/LuckyCoinsNode.ts

185 lines
3.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* @Author: WoNiu
* @Date: 2024-03-26 11:44:58
* @LastEditTime: 2024-03-26 15:41:01
* @LastEditors: WoNiu
* @Description: 幸运硬币效果类型
*/
import {
_decorator,
Sprite,
Director,
director,
Node,
tween,
UITransform,
v2,
Color,
} from "cc";
import { AnimationNode } from "../../GlobalScript/Animation/AnimationNode";
import { BaseSprite } from "../../GlobalScript/CommonComponent/BaseSprite";
import { NpkImage } from "../../Tool/NPKImage";
import { CloseButtonNode } from "../Common/CloseButtonNode";
import { GameRootSingleton } from "../GameRootController";
import { ShowNodeBorder } from "../../GlobalScript/CommonComponent/ShowNodeBorder";
const { ccclass, property } = _decorator;
/**
* @description: 幸运硬币效果类型
*/
export enum LuckyType {
// 前进三格
GoThree = 0,
// 移动到月光酒馆
YeGuangJiuGuan,
// 移动到决斗场
JueDouChang,
// 移动到海上列车
HaiShangLieChe,
// 我要双倍点数x2
Double,
// 这是我的钱,点数减半
Halve,
// 骑士马战 ,点数+2w
HorseCombat,
// 装备修理, 点数-2w
Servicing,
// 收取费用,夺取其他人 2w 点数
Charge,
}
@ccclass("LuckyCoinsNode")
export class LuckyCoinsNode extends Node {
luckyType: LuckyType;
// 幸运硬币的结果
resultNode: Node;
static show(type: LuckyType) {
const node = new LuckyCoinsNode(type);
GameRootSingleton.getInstance().DialogRootNode.addChild(node);
}
constructor(type: LuckyType) {
super();
this.luckyType = type;
this.addComponent(UITransform).anchorPoint = v2(0, 1);
this.addComponent(ShowNodeBorder);
this.initResultNode();
this.initLuckyAni();
this.delayShowResult();
}
initActionButton() {
const node = new CloseButtonNode(() => {
this.initLuckyAni();
});
this.addChild(node);
}
initResultNode() {
const node = new Node();
this.addChild(node);
node.setPosition(443, -200);
this.resultNode = node;
node.active = false;
const bs = node.addComponent(BaseSprite);
bs.updateSpriteFrame(NpkImage.luckycoin, this.luckyType);
}
initLuckyAni() {
const lucky = new AnimationNode("ani/luckycoin01.ani", () => {
/// 这一帧结束之后调用
director.once(Director.EVENT_END_FRAME, () => {
// 销毁,销毁节点只能在当前帧结束后
lucky.destroy();
});
});
lucky.setPosition(318.5, -107.5);
this.addChild(lucky);
}
// 延迟显示结果
delayShowResult() {
setTimeout(() => {
this.resultNode.active = true;
setTimeout(() => {
this.resultTweenDestroy();
}, 1000);
}, 1600);
}
// 缓动消失
resultTweenDestroy() {
let obj = { x: 255 };
tween(obj)
.to(0.5, { x: 1 }, { onUpdate: () => {
const spr = this.resultNode.getComponent(Sprite);
spr.color = new Color(255,255,255,obj.x);
console.log(spr.color.a + ' - ' + obj.x);
}, onComplete: () => {
this.resultNode.active = false;
},easing:'linear'})
.start();
}
close(){
}
}
/**
* @description: 幸运硬币事件
*/
export class LuckyAction {
// 前进三格
static GoThreeAction(){
}
// 移动到月光酒馆
YeGuangJiuGuanAction(){
}
// 移动到决斗场
JueDouChangAction(){
}
// 移动到海上列车
HaiShangLieCheAction(){
}
// 我要双倍点数x2
DoubleAction(){
}
// 这是我的钱,点数减半
HalveAction(){
}
// 骑士马战 ,点数+2w
HorseCombatAction(){
}
// 装备修理, 点数-2w
ServicingAction(){
}
// 收取费用,夺取其他人 2w 点数
ChargeAction(){
}
}