From e8fc5a1ec9911a1bde005e33fc987202a3af2170 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 19 Dec 2022 12:00:55 +0100 Subject: [PATCH] Test values --- assets/Scenes/Game.scene | 2 ++ assets/Scripts/Game/Data/GameSettings.ts | 10 +++++-- assets/Scripts/Game/Game.ts | 15 +++++++++- assets/Scripts/Game/TestGameRunner.ts | 30 +++++++++++++++++-- .../Game/Unit/Player/PlayerUI/PlayerUI.ts | 2 +- assets/Scripts/Game/Unit/UnitLevel.ts | 2 ++ 6 files changed, 54 insertions(+), 7 deletions(-) diff --git a/assets/Scenes/Game.scene b/assets/Scenes/Game.scene index 85b9eb6..af96334 100644 --- a/assets/Scenes/Game.scene +++ b/assets/Scenes/Game.scene @@ -195,6 +195,8 @@ }, "_enabled": true, "__prefab": null, + "startTime": 500, + "startXP": 10, "maxHpLevel": 0, "bonusDamageLevel": 0, "projectilePiercingLevel": 0, diff --git a/assets/Scripts/Game/Data/GameSettings.ts b/assets/Scripts/Game/Data/GameSettings.ts index bc419cb..cfcbf40 100644 --- a/assets/Scripts/Game/Data/GameSettings.ts +++ b/assets/Scripts/Game/Data/GameSettings.ts @@ -78,20 +78,24 @@ export class GeneralEnemySpawnerSettings { public cooldown = 0; } -export class WaveEnemySpawnerSettings { +export class WaveEnemySpawnerSettings implements ISpawner { public common = new GeneralEnemySpawnerSettings(); public enemiesToSpawn = 0; } -export class CircularEnemySpawnerSettings { +export class CircularEnemySpawnerSettings implements ISpawner { public common = new GeneralEnemySpawnerSettings(); public enemiesToSpawn = 0; } -export class IndividualEnemySpawnerSettings { +export class IndividualEnemySpawnerSettings implements ISpawner { public common = new GeneralEnemySpawnerSettings(); } +export interface ISpawner { + common: GeneralEnemySpawnerSettings; +} + export class EnemySettings { public id = ""; public moveType = ""; diff --git a/assets/Scripts/Game/Game.ts b/assets/Scripts/Game/Game.ts index 39c0a60..81ca628 100644 --- a/assets/Scripts/Game/Game.ts +++ b/assets/Scripts/Game/Game.ts @@ -1,4 +1,5 @@ import { Camera, Component, JsonAsset, KeyCode, Vec2, _decorator } from "cc"; +import { runInThisContext } from "vm"; import { ModalWindowManager } from "../Services/ModalWindowSystem/ModalWindowManager"; import { delay } from "../Services/Utils/AsyncUtils"; import { Background } from "./Background/Background"; @@ -13,6 +14,7 @@ import { MultiInput } from "./Input/MultiInput"; import { VirtualJoystic } from "./Input/VirtualJoystic"; import { GameModalLauncher } from "./ModalWIndows/GameModalLauncher"; import { Pauser } from "./Pauser"; +import { TestValues } from "./TestGameRunner"; import { GameUI } from "./UI/GameUI"; import { EnemyManager } from "./Unit/Enemy/EnemyManager"; import { MetaUpgrades } from "./Unit/MetaUpgrades/MetaUpgrades"; @@ -57,7 +59,12 @@ export class Game extends Component { this.gamePauser.pause(); } - public async playGame(userData: UserData, settings: GameSettings, translationData: TranslationData): Promise { + public async playGame( + userData: UserData, + settings: GameSettings, + translationData: TranslationData, + testValues?: TestValues + ): Promise { const metaUpgrades = new MetaUpgrades(userData.game.metaUpgrades, settings.metaUpgrades); this.virtualJoystic.init(); @@ -113,6 +120,12 @@ export class Game extends Component { this.gameUI.init(this.player); this.background.init(this.player.node); + + if (testValues) { + this.timeAlive += testValues.startTime; + this.player.Level.addXp(testValues.startXP); + } + this.gamePauser.resume(); // while not dead diff --git a/assets/Scripts/Game/TestGameRunner.ts b/assets/Scripts/Game/TestGameRunner.ts index f47a7f9..8ed7560 100644 --- a/assets/Scripts/Game/TestGameRunner.ts +++ b/assets/Scripts/Game/TestGameRunner.ts @@ -1,13 +1,17 @@ -import { approx, CCInteger, Component, _decorator } from "cc"; +import { CCInteger, Component, _decorator } from "cc"; import { AppRoot } from "../AppRoot/AppRoot"; import { GameRunner } from "../Menu/GameRunner"; import { delay } from "../Services/Utils/AsyncUtils"; +import { GameSettings, ISpawner } from "./Data/GameSettings"; import { UserData } from "./Data/UserData"; import { Game } from "./Game"; const { ccclass, property } = _decorator; @ccclass("TestGameRunner") export class TestGameRunner extends Component { + @property(CCInteger) private startTime = 0; + @property(CCInteger) private startXP = 0; + @property(CCInteger) private maxHpLevel = 0; @property(CCInteger) private bonusDamageLevel = 0; @property(CCInteger) private projectilePiercingLevel = 0; @@ -30,6 +34,28 @@ export class TestGameRunner extends Component { testUserData.game.metaUpgrades.movementSpeedLevel = this.movementSpeedLevel; testUserData.game.metaUpgrades.xpGathererLevel = this.xpGathererLevel; testUserData.game.metaUpgrades.goldGathererLevel = this.goldGathererLevel; - Game.Instance.playGame(testUserData, AppRoot.Instance.Settings, AppRoot.Instance.TranslationData); + + const settings = this.getTimeModifiedSettings(AppRoot.Instance.Settings); + Game.Instance.playGame(testUserData, settings, AppRoot.Instance.TranslationData, { startTime: this.startTime, startXP: this.startXP }); + } + + private getTimeModifiedSettings(settings: GameSettings): GameSettings { + const spawners: ISpawner[] = [ + ...settings.enemyManager.circularEnemySpawners, + ...settings.enemyManager.individualEnemySpawners, + ...settings.enemyManager.waveEnemySpawners + ]; + + for (const spawner of spawners) { + spawner.common.startDelay -= this.startTime; + spawner.common.stopDelay -= this.startTime; + } + + return settings; } } + +export class TestValues { + public startTime = 0; + public startXP = 0; +} diff --git a/assets/Scripts/Game/Unit/Player/PlayerUI/PlayerUI.ts b/assets/Scripts/Game/Unit/Player/PlayerUI/PlayerUI.ts index fc86ecd..69d676b 100644 --- a/assets/Scripts/Game/Unit/Player/PlayerUI/PlayerUI.ts +++ b/assets/Scripts/Game/Unit/Player/PlayerUI/PlayerUI.ts @@ -1,5 +1,5 @@ import { Component, _decorator } from "cc"; -import { UnitHealth } from "../UnitHealth"; +import { UnitHealth } from "../../UnitHealth"; import { PlayerHealthUI } from "./PlayerHealthUI"; const { ccclass, property } = _decorator; diff --git a/assets/Scripts/Game/Unit/UnitLevel.ts b/assets/Scripts/Game/Unit/UnitLevel.ts index 5bb8831..35df066 100644 --- a/assets/Scripts/Game/Unit/UnitLevel.ts +++ b/assets/Scripts/Game/Unit/UnitLevel.ts @@ -40,5 +40,7 @@ export class UnitLevel { this.currentLevel++; this.levelUpEvent.trigger(this.currentLevel); + + this.tryLevelUp(); } }