fix: booster gacha not inactive

feature/ads-smart-display
tiendat3699 2024-06-11 13:38:06 +07:00
parent 77e1e74333
commit ff838f52a0
13 changed files with 336 additions and 182 deletions

View File

@ -1133,6 +1133,9 @@
"_animation": {
"__id__": 82
},
"sprite": {
"__id__": 73
},
"displayName": "CHEESE",
"time": 10,
"_id": ""

View File

@ -1133,8 +1133,11 @@
"_animation": {
"__id__": 82
},
"sprite": {
"__id__": 73
},
"displayName": "SECRET BOX",
"time": 0,
"duration": 1,
"gachaType": 2,
"_id": ""
},

View File

@ -1133,8 +1133,11 @@
"_animation": {
"__id__": 82
},
"sprite": {
"__id__": 73
},
"displayName": "SECRET BOX",
"time": 0,
"duration": 1,
"gachaType": 0,
"_id": ""
},

View File

@ -1133,8 +1133,11 @@
"_animation": {
"__id__": 82
},
"sprite": {
"__id__": 73
},
"displayName": "SECRET BOX",
"time": 0,
"duration": 1,
"gachaType": 2,
"_id": ""
},

View File

@ -1133,8 +1133,11 @@
"_animation": {
"__id__": 82
},
"sprite": {
"__id__": 73
},
"displayName": "SECRET BOX",
"time": 0,
"duration": 1,
"gachaType": 1,
"_id": ""
},

View File

@ -24,18 +24,18 @@
],
"_active": true,
"_components": [
{
"__id__": 31
},
{
"__id__": 33
},
{
"__id__": 35
},
{
"__id__": 37
},
{
"__id__": 39
}
],
"_prefab": {
"__id__": 37
"__id__": 41
},
"_lpos": {
"__type__": "cc.Vec3",
@ -84,18 +84,18 @@
],
"_active": true,
"_components": [
{
"__id__": 24
},
{
"__id__": 26
},
{
"__id__": 28
},
{
"__id__": 30
},
{
"__id__": 32
}
],
"_prefab": {
"__id__": 30
"__id__": 34
},
"_lpos": {
"__type__": "cc.Vec3",
@ -298,19 +298,22 @@
"_children": [
{
"__id__": 11
},
{
"__id__": 17
}
],
"_active": true,
"_components": [
{
"__id__": 19
"__id__": 23
},
{
"__id__": 21
"__id__": 25
}
],
"_prefab": {
"__id__": 23
"__id__": 27
},
"_lpos": {
"__type__": "cc.Vec3",
@ -357,17 +360,14 @@
},
{
"__id__": 14
},
{
"__id__": 16
}
],
"_prefab": {
"__id__": 18
"__id__": 16
},
"_lpos": {
"__type__": "cc.Vec3",
"x": -231.45703125,
"x": -125.884765625,
"y": 0,
"z": 0
},
@ -420,7 +420,7 @@
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "33YwxJiIZFx52T+GuIPANS"
"fileId": "18zn0tVhhFMpybcPN2M0FU"
},
{
"__type__": "cc.Label",
@ -445,7 +445,7 @@
"a": 255
},
"_string": "100",
"_horizontalAlign": 2,
"_horizontalAlign": 1,
"_verticalAlign": 1,
"_actualFontSize": 100,
"_fontSize": 100,
@ -491,43 +491,7 @@
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "abqDTVc0pLFJAI+MKxq3eQ"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 11
},
"_enabled": true,
"__prefab": {
"__id__": 17
},
"_alignFlags": 10,
"_target": null,
"_left": -161.572265625,
"_right": 0,
"_top": 0,
"_bottom": 0,
"_horizontalCenter": 0,
"_verticalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 0,
"_originalHeight": 0,
"_alignMode": 2,
"_lockFlags": 0,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "a0YsiditVM1JgTlUtoFyOX"
"fileId": "f0DWlVpChH9b/FpF1x9GMP"
},
{
"__type__": "cc.PrefabInfo",
@ -537,27 +501,77 @@
"asset": {
"__id__": 0
},
"fileId": "c6lHFE6oBJM6bTulGiWcBC",
"fileId": "2au8tDWs9GiJ0Z29DO/vrO",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": null
},
{
"__type__": "cc.Node",
"_name": "Sprite",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 10
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 18
},
{
"__id__": 20
}
],
"_prefab": {
"__id__": 22
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 58.23046875,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 10
"__id__": 17
},
"_enabled": true,
"__prefab": {
"__id__": 20
"__id__": 19
},
"_contentSize": {
"__type__": "cc.Size",
"width": 288,
"height": 281
"width": 200,
"height": 200
},
"_anchorPoint": {
"__type__": "cc.Vec2",
@ -568,7 +582,7 @@
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "00TALsq4ZHl6Ld0LVWiUr7"
"fileId": "eeSLyxaSdA14MnU1JhQE8L"
},
{
"__type__": "cc.Sprite",
@ -576,11 +590,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 10
"__id__": 17
},
"_enabled": true,
"__prefab": {
"__id__": 22
"__id__": 21
},
"_customMaterial": null,
"_srcBlendFactor": 2,
@ -592,7 +606,10 @@
"b": 255,
"a": 255
},
"_spriteFrame": null,
"_spriteFrame": {
"__uuid__": "5b5a3073-f986-4350-9ef0-e1fddb56a494@f9941",
"__expectedType__": "cc.SpriteFrame"
},
"_type": 0,
"_fillType": 0,
"_sizeMode": 0,
@ -610,7 +627,86 @@
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "6dTw63zDlHr4d6fvs5Jqp2"
"fileId": "ecbp9qmr5AsK8U3oG22/LR"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "01q2I1EmNPXr4APxBvWUXg",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": null
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 10
},
"_enabled": true,
"__prefab": {
"__id__": 24
},
"_contentSize": {
"__type__": "cc.Size",
"width": 400,
"height": 100
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "00TALsq4ZHl6Ld0LVWiUr7"
},
{
"__type__": "cc.Layout",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 10
},
"_enabled": true,
"__prefab": {
"__id__": 26
},
"_resizeMode": 0,
"_layoutType": 1,
"_cellSize": {
"__type__": "cc.Size",
"width": 40,
"height": 40
},
"_startAxis": 0,
"_paddingLeft": 0,
"_paddingRight": 0,
"_paddingTop": 0,
"_paddingBottom": 0,
"_spacingX": 10,
"_spacingY": 0,
"_verticalDirection": 1,
"_horizontalDirection": 0,
"_constraint": 0,
"_constraintNum": 2,
"_affectedByScale": false,
"_isAlign": true,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "289shnSS9OzLTNRZIo1ZaP"
},
{
"__type__": "cc.PrefabInfo",
@ -635,7 +731,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 25
"__id__": 29
},
"_contentSize": {
"__type__": "cc.Size",
@ -663,7 +759,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 27
"__id__": 31
},
"_customMaterial": null,
"_srcBlendFactor": 2,
@ -708,7 +804,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 29
"__id__": 33
},
"ignoreTimeScale": true,
"_id": ""
@ -740,7 +836,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 32
"__id__": 36
},
"_contentSize": {
"__type__": "cc.Size",
@ -768,10 +864,10 @@
},
"_enabled": true,
"__prefab": {
"__id__": 34
"__id__": 38
},
"skeleton": {
"__id__": 26
"__id__": 30
},
"_flipX": false,
"_flipY": false,
@ -791,16 +887,19 @@
},
"_enabled": true,
"__prefab": {
"__id__": 36
"__id__": 40
},
"animationHandler": {
"__id__": 33
"__id__": 37
},
"spineRoot": {
"__id__": 2
},
"rewardRoot": {
"__id__": 10
},
"rewardSprite": {
"__id__": 21
"__id__": 20
},
"rewardLabel": {
"__id__": 14

View File

@ -34389,7 +34389,7 @@
},
"_enabled": true,
"__prefab": null,
"_colliderDebug": false,
"_colliderDebug": true,
"_floatingScoreFactory": {
"__id__": 6
},

View File

@ -1,7 +1,21 @@
import { _decorator, Animation, AudioClip, CCFloat, CCString, Collider2D, Component, Contact2DType } from 'cc';
import {
_decorator,
Animation,
AudioClip,
CCFloat,
CCString,
Collider2D,
Component,
Contact2DType,
Node,
Sprite,
Vec3,
} from 'cc';
import BoosterType from '../Enum/BoosterType';
import GameEvent from '../Events/GameEvent';
import AudioManager from '../Manager/AudioManager';
import { EventManger } from '../Manager/EventManger';
import { GameManager } from '../Manager/GameManager';
import IPoolable from '../Pool/IPoolable';
import ObjectPool from '../Pool/ObjectPool';
import Utils from '../Utilities';
@ -15,35 +29,73 @@ export class BoosterBase extends Component implements IPoolable {
protected _collectSound: AudioClip;
@property({ type: Animation, visible: true })
private _animation: Animation;
@property(Sprite)
private sprite: Sprite;
@property(CCString)
public readonly displayName: string = 'CHEESE';
@property(CCFloat)
protected time: number = 10;
protected duration: number = 10;
private active: boolean = true;
public readonly type: BoosterType;
private _timer: number = 0;
private _activeCollider: boolean = true;
private _active: boolean = false;
public get active() {
return this._active;
}
protected onLoad(): void {
this._collider.on(Contact2DType.BEGIN_CONTACT, this.onContactBegin, this);
this.active = false;
this._activeCollider = false;
}
private onContactBegin(self: Collider2D, other: Collider2D) {
if (!this.active) return;
this.boosterActive();
this.active = false;
if (!this._activeCollider) return;
this._activeCollider = false;
AudioManager.playSfx(this._collectSound);
EventManger.instance.emit(GameEvent.ObjectRelease, this.node);
ObjectPool.release(this.node);
GameManager.instance.addBooster(this);
}
protected boosterActive() {}
public tick(dt: number) {
if (!this._active) return;
this.node.setPosition(Vec3.ZERO);
this._timer += dt;
if (this._timer >= this.duration) {
this._active = false;
}
}
public resetTime() {
this._timer = 0;
}
public collect(collector: Node) {
this._active = true;
this._timer = 0;
this.sprite.setNodeActive(false);
this.node.setParent(collector);
}
public end() {
if (!this.node.releaseToPool()) {
this.node.destroy();
}
}
public dispose() {
if (!this.node.releaseToPool()) {
this.node.destroy();
}
}
async onGet() {
this._animation.play();
await Utils.delay(this._animation.defaultClip.duration);
this.active = true;
this._activeCollider = true;
this.sprite.setNodeActive(true);
}
onRelease() {
this.active = false;
this._activeCollider = false;
}
}

View File

@ -1,12 +1,20 @@
import { _decorator, Component, Node } from 'cc';
import { BoosterBase } from './BoosterBase';
import { GameManager } from '../Manager/GameManager';
import BoosterType from '../Enum/BoosterType';
import AudioManager from '../Manager/AudioManager';
import { BoosterBase } from './BoosterBase';
const { ccclass, property } = _decorator;
@ccclass('CumulativeBooster')
export class CumulativeBooster extends BoosterBase {
protected boosterActive(): void {
GameManager.instance.ActiveBooster(BoosterType.CumulativeBar, this.time, this.displayName);
public readonly type: BoosterType = BoosterType.CumulativeBar;
public collect(collector: Node): void {
super.collect(collector);
AudioManager.setPlayRateBGM(1.5);
}
public end(): void {
super.end();
AudioManager.setPlayRateBGM(1);
}
}

View File

@ -1,18 +1,24 @@
import { _decorator, Component, Node } from 'cc';
import { _decorator, Component, game, Node, TweenSystem } from 'cc';
import BoosterType from '../Enum/BoosterType';
import GachaManager, { GachaType } from '../Manager/GachaManager';
import { GameManager } from '../Manager/GameManager';
import { BoosterBase } from './BoosterBase';
const { ccclass, property } = _decorator;
@ccclass('SecretBoxBooster')
export default class SecretBoxBooster extends BoosterBase {
public readonly type: BoosterType = BoosterType.Gacha;
@property({ type: GachaType })
private gachaType: GachaType;
protected boosterActive() {
GameManager.instance.ActiveBooster(BoosterType.Gacha, this.time, this.displayName);
public collect(collector: Node) {
super.collect(collector);
GachaManager.instance.show(this.gachaType, 1.5);
}
public tick(dt: number): void {
super.tick(dt);
TweenSystem.instance.update(game.deltaTime);
}
}

View File

@ -12,6 +12,8 @@ export default class FreeReward extends GachaBase {
private animationHandler: SpineAnimationHandler;
@property(Node)
private spineRoot: Node;
@property(Node)
private rewardRoot: Node;
@property(Sprite)
private rewardSprite: Sprite;
@property(Label)
@ -24,7 +26,7 @@ export default class FreeReward extends GachaBase {
protected onEnable(): void {
this.spineRoot.setActive(false);
this.rewardSprite.setNodeActive(false);
this.rewardRoot.setActive(false);
this._opened = false;
}
@ -32,18 +34,13 @@ export default class FreeReward extends GachaBase {
if (this._startShowReward) {
let k = clamp01(this._timer / 0.3);
k = easing.quintInOut(k);
const targetScale = Vec3.lerp(this.rewardSprite.node.scale, Vec3.ZERO, Vec3.ONE, k);
const targetPosition = Vec3.lerp(this.rewardSprite.node.position, new Vec3(0, 150), new Vec3(0, 700), k);
this.rewardSprite.node.setScale(targetScale);
this.rewardSprite.node.setPosition(targetPosition);
const targetScale = Vec3.lerp(this.rewardRoot.scale, Vec3.ZERO, Vec3.ONE, k);
const targetPosition = Vec3.lerp(this.rewardRoot.position, new Vec3(0, 150), new Vec3(0, 700), k);
this.rewardRoot.setScale(targetScale);
this.rewardRoot.setPosition(targetPosition);
this._timer += game.deltaTime;
if (k === 1) {
this._startShowReward = false;
GachaManager.instance.showFloatingText(
this._reward.quantity.toString(),
this.rewardSprite.node.worldPosition,
this._reward.icon,
);
GachaManager.instance.gachaDone();
}
}
@ -65,7 +62,7 @@ export default class FreeReward extends GachaBase {
this.rewardSprite.spriteFrame = this._reward.icon;
this.rewardLabel.string = this._reward.quantity.toString();
await Utils.delay(1);
this.rewardSprite.setNodeActive(true);
this.rewardRoot.setActive(true);
this._startShowReward = true;
return;
}

View File

@ -15,6 +15,7 @@ import {
} from 'cc';
import BEConnector from '../API/BEConnector';
import Timer, { TimerType } from '../Base/Timer';
import { BoosterBase } from '../Booster/BoosterBase';
import BoosterType from '../Enum/BoosterType';
import GameState from '../Enum/GameState';
import ScoreType from '../Enum/ScoreType';
@ -42,17 +43,6 @@ window.addEventListener('message', (data) => {
}
});
class Booster {
public type: BoosterType;
public time: number;
public runningTime: number = 0;
constructor(type: BoosterType, time: number) {
this.type = type;
this.time = time;
}
}
@ccclass('GameManager')
export class GameManager extends Singleton<GameManager>() {
@property({ visible: true })
@ -82,7 +72,7 @@ export class GameManager extends Singleton<GameManager>() {
private _gameState: GameState;
private _timer: Timer = new Timer(TimerType.countDown);
private _boostersActive: Booster[] = [];
private _activeBoosters: Map<BoosterType, BoosterBase> = new Map();
private _score = 0;
private isReplayed = false;
@ -124,17 +114,7 @@ export class GameManager extends Singleton<GameManager>() {
protected update(dt: number): void {
this._timer.update(dt);
if (this._gameState != GameState.Playing) return;
for (let i = 0; i < this._boostersActive.length; i++) {
const booster = this._boostersActive[i];
booster.runningTime += dt;
if (booster.runningTime >= booster.time) {
this._boostersActive.splice(i, 1);
if (this._boostersActive.length == 0) {
AudioManager.setPlayRateBGM(1);
}
EventManger.instance.emit(GameEvent.BoosterDisable, booster.type);
}
}
this.runBooster(dt);
}
private async changeGameState(state: GameState) {
@ -237,7 +217,7 @@ export class GameManager extends Singleton<GameManager>() {
if (playStartSound) AudioManager.playSfx(this._startSound);
this.setCurrentBallInGame(1);
const ball = BallFactory.instance.create(this._ballHolder);
ball.init(this._boostersActive.length > 0);
ball.init(this._activeBoosters.size > 0);
ball.node.setRotation(Quat.IDENTITY);
ball.node.setPosition(this._ballSpawnPosition);
if (!throwBall) return ball;
@ -255,7 +235,7 @@ export class GameManager extends Singleton<GameManager>() {
if (this._currentBallInGame <= 0) {
EventManger.instance.emit(GameEvent.BallOut, null);
AudioManager.playSfx(this._ballOutSound);
this.DisableAllBooster();
this.cleanBooster();
await Utils.delay(TimeConfig.DelayPLay);
this.spawnBall(true);
}
@ -303,7 +283,7 @@ export class GameManager extends Singleton<GameManager>() {
public async gameOver() {
BallFactory.instance.releaseAll();
this.DisableAllBooster();
this.cleanBooster();
AudioManager.playBGM(this._gameOverMusic);
StickerManager.instance.showLabel('TIME UP!!!', { color: new Color('#ed3a18'), outLineColor: Color.WHITE });
BEConnector.gameScore = this.score;
@ -344,23 +324,46 @@ export class GameManager extends Singleton<GameManager>() {
this.spawnBall(true);
}
private DisableAllBooster() {
for (let i = 0; i < this._boostersActive.length; i++) {
const booster = this._boostersActive[i];
EventManger.instance.emit(GameEvent.BoosterDisable, booster.type);
public addBooster(booster: BoosterBase) {
let activeBooster = this._activeBoosters.get(booster.type);
if (activeBooster) {
booster.dispose();
activeBooster.resetTime();
return;
} else {
activeBooster = booster;
}
this._boostersActive = [];
AudioManager.setPlayRateBGM(1);
activeBooster.collect(this.node);
console.log(booster.displayName + ' active');
this._activeBoosters.set(booster.type, booster);
EventManger.instance.emit(GameEvent.BoosterActive, [booster.type, booster.displayName]);
}
public async ActiveBooster(type: BoosterType, time: number, displayName: string) {
//check booster already active
for (let i = 0; i < this._boostersActive.length; i++) {
const booster = this._boostersActive[i];
if (booster.type == type) return;
private cleanBooster() {
this._activeBoosters.forEach((booster) => {
booster.end();
EventManger.instance.emit(GameEvent.BoosterDisable, booster.type);
});
this._activeBoosters.clear();
}
private runBooster(dt: number) {
if (this._activeBoosters.size > 0) {
const boosterToRemove: BoosterBase[] = [];
this._activeBoosters.forEach((booster) => {
booster.tick(dt);
if (!booster.active) {
boosterToRemove.push(booster);
}
});
console.log(boosterToRemove.length);
boosterToRemove.forEach((booster) => {
booster.end();
EventManger.instance.emit(GameEvent.BoosterDisable, booster.type);
this._activeBoosters.delete(booster.type);
console.log(booster.displayName + ' inactive');
});
}
this._boostersActive.push(new Booster(type, time));
EventManger.instance.emit(GameEvent.BoosterActive, [type, displayName]);
AudioManager.setPlayRateBGM(1.25);
}
}

View File

@ -1,18 +1,4 @@
import {
_decorator,
CCString,
Color,
Component,
game,
Label,
Node,
Sprite,
SpriteFrame,
Tween,
tween,
TweenSystem,
Vec3,
} from 'cc';
import { _decorator, CCString, Color, Label, Node, Sprite, SpriteFrame, Tween, tween, Vec3 } from 'cc';
import Singleton from '../Singleton';
const { ccclass, property } = _decorator;
@ -33,21 +19,12 @@ export class StickerManager extends Singleton<StickerManager>() {
@property({ type: Sticker, visible: true })
private _stickers: Sticker[] = [];
private _showing: boolean = false;
protected start(): void {
this._popup.setScale(Vec3.ZERO);
this._label.string = '';
}
protected update(dt: number): void {
if (this._showing && game.timeScale == 0) {
TweenSystem.instance.ActionManager.update(game.deltaTime);
}
}
public Show(stickerName: string, position: Vec3 = Vec3.ZERO) {
this._showing = true;
let sticker = this._stickers.find((s) => s.Name == stickerName);
this._popup.setPosition(position);
this._popup.getComponent(Sprite).spriteFrame = sticker.SpriteFrame;
@ -56,12 +33,10 @@ export class StickerManager extends Singleton<StickerManager>() {
.to(0.3, { scale: Vec3.ONE }, { easing: 'backOut' })
.delay(0.5)
.to(0.2, { scale: Vec3.ZERO }, { easing: 'backIn' })
.call(() => (this._showing = false))
.start();
}
public showLabel(string: string, opts?: { color?: Color; outLineColor?: Color; position?: Vec3 }) {
this._showing = true;
this._label.string = string;
this._label.color = opts?.color || new Color('#FFFF00');
this._label.node.setPosition(opts?.position || Vec3.ZERO);
@ -82,7 +57,6 @@ export class StickerManager extends Singleton<StickerManager>() {
easing: 'backIn',
},
)
.call(() => (this._showing = false))
.start();
}
}