From ad1be40f2ba4978866da9990fb73ea4f12fe893b Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 13 Dec 2022 15:56:13 +0100 Subject: [PATCH] Meta updates --- assets/Data/GameSettings.json | 210 +----------------- assets/Scripts/Game/Data/GameSettings.ts | 1 + assets/Scripts/Game/Game.ts | 26 ++- assets/Scripts/Game/Unit/Player/Player.ts | 33 +-- .../Scripts/Game/Unit/Player/Weapon/Weapon.ts | 6 +- assets/Scripts/Game/Unit/UnitLevel.ts | 8 +- 6 files changed, 44 insertions(+), 240 deletions(-) diff --git a/assets/Data/GameSettings.json b/assets/Data/GameSettings.json index 1d96f58..0e7fbcc 100644 --- a/assets/Data/GameSettings.json +++ b/assets/Data/GameSettings.json @@ -1,209 +1 @@ -{ - "player": { - "defaultHP": 50, - "requiredXP": [ - 10, - 20, - 30, - 40, - 50, - 60, - 70, - 80, - 90, - 100 - ], - "regenerationDelay": 5, - "collisionDelay": 0.5, - "weapon": { - "strikeDelay": 2.5, - "damage": 5 - }, - "haloLauncher": { - "projectilesToSpawn": 24, - "cooldownDivisorPerUpgrade": 1, - "launcher": { - "projectileLifetime": 2, - "projectileSpeed": 150, - "wavesToShoot": 1, - "wavesDelayMs": 0, - "cooldown": 10 - } - }, - "horizontalLauncher": { - "wavesToShootPerUpgrade": 1, - "launcher": { - "projectileLifetime": 3, - "projectileSpeed": 300, - "wavesToShoot": 1, - "wavesDelayMs": 100, - "cooldown": 4 - } - }, - "diagonalLauncher": { - "wavesToShootPerUpgrade": 1, - "launcher": { - "projectileLifetime": 20, - "projectileSpeed": 300, - "wavesToShoot": 1, - "wavesDelayMs": 100, - "cooldown": 4 - } - } - }, - "upgrades": { - "maxWeaponLengthUpgrades": 5, - "maxWeaponDamageUpgrades": 10, - "maxHorizontalProjectileUpgrades": 0, - "maxDiagonalProjectileUpgrades": 0, - "maxHaloProjectileUpgrades": 5, - "maxRegenerationUpgrades": 5 - }, - "metaUpgrades": { - "healthPointsPerLevel": 0, - "bonusDamagePerLevel": 0, - "projectilePiercingPerLevel": 0, - "movementSpeedPerLevel": 0, - "xpBonusPerLevel": 0, - "goldBonusPerLevel": 0 - }, - "enemyManager": { - "enemies": [ - { - "id": "BasicEnemy", - "moveType": "Follow", - "health": 3, - "damage": 1, - "speed": 60 - }, - { - "id": "CircleEnemy", - "moveType": "Follow", - "health": 10, - "damage": 1, - "speed": 25 - }, - { - "id": "WaveEnemy", - "moveType": "Launch", - "health": 1, - "damage": 2, - "speed": 390 - }, - { - "id": "WaveEnemyArmor", - "moveType": "Launch", - "health": 7, - "damage": 3, - "speed": 70 - }, - { - "id": "BasicBoss", - "moveType": "Follow", - "health": 12, - "damage": 2, - "speed": 65 - }, - { - "id": "BasicCheetah", - "moveType": "PeriodicFollow", - "health": 5, - "damage": 2, - "speed": 140 - } - ], - "individualEnemySpawners": [ - { - "common": { - "enemyId": "BasicEnemy", - "startDelay": 0, - "stopDelay": 29, - "cooldown": 1 - } - }, - { - "common": { - "enemyId": "BasicEnemy", - "startDelay": 30, - "stopDelay": 59, - "cooldown": 0.9 - } - }, - { - "common": { - "enemyId": "BasicBoss", - "startDelay": 60, - "stopDelay": 61, - "cooldown": 0.9 - } - }, - { - "common": { - "enemyId": "BasicEnemy", - "startDelay": 62, - "stopDelay": 120, - "cooldown": 0.7 - } - }, - { - "common": { - "enemyId": "BasicEnemy", - "startDelay": 121, - "stopDelay": 240, - "cooldown": 0.5 - } - } - ], - "circularEnemySpawners": [ - { - "common": { - "enemyId": "CircleEnemy", - "startDelay": 1, - "stopDelay": 240, - "cooldown": 35 - }, - "enemiesToSpawn": 40 - }, - { - "common": { - "enemyId": "BasicEnemy", - "startDelay": 59, - "stopDelay": 63, - "cooldown": 3 - }, - "enemiesToSpawn": 10 - }, - { - "common": { - "enemyId": "BasicCheetah", - "startDelay": 119, - "stopDelay": 123, - "cooldown": 2 - }, - "enemiesToSpawn": 10 - } - ], - "waveEnemySpawners": [ - { - "common": { - "enemyId": "WaveEnemy", - "startDelay": 1, - "stopDelay": -1, - "cooldown": 20 - }, - "enemiesToSpawn": 15, - "waveLifetime": 50 - }, - { - "common": { - "enemyId": "WaveEnemyArmor", - "startDelay": 1, - "stopDelay": -1, - "cooldown": 50 - }, - "enemiesToSpawn": 12, - "waveLifetime": 20 - } - ] - } -} \ No newline at end of file +{"player":{"defaultHP":50,"requiredXP":[10,20,30,40,50,60,70,80,90,100],"speed":0,"regenerationDelay":5,"collisionDelay":0.5,"weapon":{"strikeDelay":2.5,"damage":5},"haloLauncher":{"projectilesToSpawn":24,"cooldownDivisorPerUpgrade":1,"launcher":{"projectileLifetime":2,"projectileSpeed":150,"wavesToShoot":1,"wavesDelayMs":0,"cooldown":10}},"horizontalLauncher":{"wavesToShootPerUpgrade":1,"launcher":{"projectileLifetime":3,"projectileSpeed":300,"wavesToShoot":1,"wavesDelayMs":100,"cooldown":4}},"diagonalLauncher":{"wavesToShootPerUpgrade":1,"launcher":{"projectileLifetime":20,"projectileSpeed":300,"wavesToShoot":1,"wavesDelayMs":100,"cooldown":4}}},"upgrades":{"maxWeaponLengthUpgrades":5,"maxWeaponDamageUpgrades":10,"maxHorizontalProjectileUpgrades":0,"maxDiagonalProjectileUpgrades":0,"maxHaloProjectileUpgrades":5,"maxRegenerationUpgrades":5},"metaUpgrades":{"healthPointsPerLevel":0,"bonusDamagePerLevel":0,"projectilePiercingPerLevel":0,"movementSpeedPerLevel":0,"xpBonusPerLevel":0,"goldBonusPerLevel":0},"enemyManager":{"enemies":[{"id":"BasicEnemy","moveType":"Follow","health":3,"damage":1,"speed":60},{"id":"CircleEnemy","moveType":"Follow","health":10,"damage":1,"speed":25},{"id":"WaveEnemy","moveType":"Launch","health":1,"damage":2,"speed":390},{"id":"WaveEnemyArmor","moveType":"Launch","health":7,"damage":3,"speed":70},{"id":"BasicBoss","moveType":"Follow","health":12,"damage":2,"speed":65},{"id":"BasicCheetah","moveType":"PeriodicFollow","health":5,"damage":2,"speed":140}],"individualEnemySpawners":[{"common":{"enemyId":"BasicEnemy","startDelay":0,"stopDelay":29,"cooldown":1}},{"common":{"enemyId":"BasicEnemy","startDelay":30,"stopDelay":59,"cooldown":0.9}},{"common":{"enemyId":"BasicBoss","startDelay":60,"stopDelay":61,"cooldown":0.9}},{"common":{"enemyId":"BasicEnemy","startDelay":62,"stopDelay":120,"cooldown":0.7}},{"common":{"enemyId":"BasicEnemy","startDelay":121,"stopDelay":240,"cooldown":0.5}}],"circularEnemySpawners":[{"common":{"enemyId":"CircleEnemy","startDelay":1,"stopDelay":240,"cooldown":35},"enemiesToSpawn":40},{"common":{"enemyId":"BasicEnemy","startDelay":59,"stopDelay":63,"cooldown":3},"enemiesToSpawn":10},{"common":{"enemyId":"BasicCheetah","startDelay":119,"stopDelay":123,"cooldown":2},"enemiesToSpawn":10}],"waveEnemySpawners":[{"common":{"enemyId":"WaveEnemy","startDelay":1,"stopDelay":-1,"cooldown":20},"enemiesToSpawn":15,"waveLifetime":50},{"common":{"enemyId":"WaveEnemyArmor","startDelay":1,"stopDelay":-1,"cooldown":50},"enemiesToSpawn":12,"waveLifetime":20}]}} \ No newline at end of file diff --git a/assets/Scripts/Game/Data/GameSettings.ts b/assets/Scripts/Game/Data/GameSettings.ts index 690a7fb..7d9b6f7 100644 --- a/assets/Scripts/Game/Data/GameSettings.ts +++ b/assets/Scripts/Game/Data/GameSettings.ts @@ -8,6 +8,7 @@ export class GameSettings { export class PlayerSettings { public defaultHP = 0; public requiredXP: number[] = []; + public speed = 0; public regenerationDelay = 0; public collisionDelay = 0; public weapon: WeaponSettings = new WeaponSettings(); diff --git a/assets/Scripts/Game/Game.ts b/assets/Scripts/Game/Game.ts index 33e5388..3c6c391 100644 --- a/assets/Scripts/Game/Game.ts +++ b/assets/Scripts/Game/Game.ts @@ -5,7 +5,7 @@ import { Background } from "./Background/Background"; import { PlayerCollisionSystem } from "./Collision/PlayerCollisionSystem"; import { PlayerProjectileCollisionSystem } from "./Collision/PlayerProjectileCollisionSystem"; import { WeaponCollisionSystem } from "./Collision/WeaponCollisionSystem"; -import { GameSettings } from "./Data/GameSettings"; +import { GameSettings, PlayerSettings } from "./Data/GameSettings"; import { UserData } from "./Data/UserData"; import { KeyboardInput } from "./Input/KeyboardInput"; import { MultiInput } from "./Input/MultiInput"; @@ -66,13 +66,7 @@ export class Game extends Component { const arrowKeys = new KeyboardInput(KeyCode.ARROW_UP, KeyCode.ARROW_DOWN, KeyCode.ARROW_LEFT, KeyCode.ARROW_RIGHT); const multiInput: MultiInput = new MultiInput([this.virtualJoystic, wasd, arrowKeys]); - const playerData: PlayerData = Object.assign(new PlayerData(), settings.player); - playerData.bonusHp = metaUpgrades.getUpgradeValue(MetaUpgradeType.MaxHp); - playerData.bonusDamage = metaUpgrades.getUpgradeValue(MetaUpgradeType.OverallDamage); - playerData.bonusSpeed = metaUpgrades.getUpgradeValue(MetaUpgradeType.MovementSpeed); - playerData.bonusXP = metaUpgrades.getUpgradeValue(MetaUpgradeType.XPGatherer); - playerData.bonusGold = metaUpgrades.getUpgradeValue(MetaUpgradeType.GoldGatherer); - this.player.init(multiInput, playerData); + this.player.init(multiInput, this.createPlayerData(settings.player, metaUpgrades)); this.playerCollisionSystem = new PlayerCollisionSystem(this.player, settings.player.collisionDelay); new WeaponCollisionSystem(this.player.Weapon); @@ -141,4 +135,20 @@ export class Game extends Component { this.camera.node.worldPosition = this.player.node.worldPosition; } + + private createPlayerData(settings: PlayerSettings, metaUpgrades: MetaUpgrades): PlayerData { + const playerData: PlayerData = Object.assign(new PlayerData(), settings); + + playerData.maxHp = metaUpgrades.getUpgradeValue(MetaUpgradeType.MaxHp) + settings.defaultHP; + playerData.requiredXP = settings.requiredXP; + playerData.speed = metaUpgrades.getUpgradeValue(MetaUpgradeType.MovementSpeed) + settings.speed; + playerData.regenerationDelay = settings.regenerationDelay; + playerData.xpMultiplier = metaUpgrades.getUpgradeValue(MetaUpgradeType.XPGatherer) + 1; + playerData.goldMultiplier = metaUpgrades.getUpgradeValue(MetaUpgradeType.GoldGatherer) + 1; + + playerData.damage = metaUpgrades.getUpgradeValue(MetaUpgradeType.OverallDamage) + settings.weapon.damage; + playerData.strikeDelay = settings.weapon.strikeDelay; + + return playerData; + } } diff --git a/assets/Scripts/Game/Unit/Player/Player.ts b/assets/Scripts/Game/Unit/Player/Player.ts index 0c5ac85..a8a9185 100644 --- a/assets/Scripts/Game/Unit/Player/Player.ts +++ b/assets/Scripts/Game/Unit/Player/Player.ts @@ -1,5 +1,4 @@ import { BoxCollider2D, Collider2D, Component, Vec2, Vec3, _decorator } from "cc"; -import { PlayerSettings } from "../../Data/GameSettings"; import { IInput } from "../../Input/IInput"; import { UnitHealth } from "../UnitHealth"; import { UnitLevel } from "../UnitLevel"; @@ -11,7 +10,6 @@ const { ccclass, property } = _decorator; @ccclass("Player") export class Player extends Component { - @property private speed = 0; @property(BoxCollider2D) private collider: BoxCollider2D; @property(PlayerUI) private playerUI: PlayerUI; @property(Weapon) private weapon: Weapon; @@ -20,18 +18,18 @@ export class Player extends Component { private health: UnitHealth; private level: UnitLevel; private regeneration: PlayerRegeneration; + private speed: number; - public init(input: IInput, settings: PlayerData): void { + public init(input: IInput, data: PlayerData): void { this.input = input; - this.health = new UnitHealth(settings.defaultHP); - this.level = new UnitLevel(settings.requiredXP); - this.regeneration = new PlayerRegeneration(this.health, settings.regenerationDelay); + this.health = new UnitHealth(data.maxHp); + this.level = new UnitLevel(data.requiredXP, data.xpMultiplier); + this.regeneration = new PlayerRegeneration(this.health, data.regenerationDelay); + this.speed = data.speed; - this.weapon.init(settings.weapon); + this.weapon.init(data.strikeDelay, data.damage); this.playerUI.init(this.health); - - console.log("Bonus damage " + settings.bonusDamage); } public get Health(): UnitHealth { @@ -70,10 +68,15 @@ export class Player extends Component { } } -export class PlayerData extends PlayerSettings { - public bonusDamage = 0; - public bonusHp = 0; - public bonusSpeed = 0; - public bonusXP = 0; - public bonusGold = 0; +export class PlayerData { + public requiredXP: number[] = []; + public speed = 0; + public maxHp = 0; + public regenerationDelay = 0; + public xpMultiplier = 0; + public goldMultiplier = 0; + + // Weapon + public strikeDelay = 0; + public damage = 0; } diff --git a/assets/Scripts/Game/Unit/Player/Weapon/Weapon.ts b/assets/Scripts/Game/Unit/Player/Weapon/Weapon.ts index 7f02f26..5dd1f99 100644 --- a/assets/Scripts/Game/Unit/Player/Weapon/Weapon.ts +++ b/assets/Scripts/Game/Unit/Player/Weapon/Weapon.ts @@ -14,9 +14,9 @@ export class Weapon extends Component { private strikeState: AnimationState; private damage: number; - public init(settings: WeaponSettings): void { - this.strikeTimer = new GameTimer(settings.strikeDelay); - this.damage = settings.damage; + public init(strikeDelay: number, damage: number): void { + this.strikeTimer = new GameTimer(strikeDelay); + this.damage = damage; this.node.active = false; this.weaponAnimation.on(Animation.EventType.FINISHED, this.endStrike, this); diff --git a/assets/Scripts/Game/Unit/UnitLevel.ts b/assets/Scripts/Game/Unit/UnitLevel.ts index c90e8b5..5bb8831 100644 --- a/assets/Scripts/Game/Unit/UnitLevel.ts +++ b/assets/Scripts/Game/Unit/UnitLevel.ts @@ -3,17 +3,15 @@ import { Signal } from "../../Services/EventSystem/Signal"; export class UnitLevel { private xp = 0; - private requiredXPs: number[]; + private currentLevel = 0; private levelUpEvent: Signal = new Signal(); private xpAddedEvent: Signal = new Signal(); - public constructor(requiredXPs: number[]) { - this.requiredXPs = requiredXPs; - } + public constructor(private requiredXPs: number[], private xpMultiplier: number) {} public addXp(points: number): void { - this.xp += points; + this.xp += points * this.xpMultiplier; this.xpAddedEvent.trigger(this.xp); this.tryLevelUp(); }