Upgrader, LevelUpSkill

This commit is contained in:
Martin
2022-11-23 09:01:01 +01:00
parent 94605e673e
commit b1f8f66499
38 changed files with 5158 additions and 692 deletions

View File

@@ -26,6 +26,8 @@ export class GameBootstrapper extends Component {
private playerCollisionSystem: PlayerCollisionSystem;
private isPaused = false;
public start(): void {
this.virtualJoystic.init();
this.weapon.init(this.strikeDelay);
@@ -45,6 +47,8 @@ export class GameBootstrapper extends Component {
}
public update(deltaTime: number): void {
if (this.isPaused) return;
this.player.gameTick(deltaTime);
this.playerCollisionSystem.gameTick(deltaTime);
this.enemyManager.gameTick(deltaTime);
@@ -53,7 +57,9 @@ export class GameBootstrapper extends Component {
}
private async showModal(): Promise<void> {
this.isPaused = true;
const result: string = await this.modalWindowManager.showModal<string, string>("LevelUpModalWindow", "test params");
this.isPaused = false;
console.log("Result: " + result);
}
}

View File

@@ -17,8 +17,6 @@ export class Player extends Component {
private health: UnitHealth;
private level: UnitLevel;
private xp: number;
public init(input: IInput, weapon: Weapon, maxHp: number, requiredLevelXps: number[]): void {
this.input = input;
this.weapon = weapon;
@@ -39,6 +37,10 @@ export class Player extends Component {
return this.level;
}
public get Weapon(): Weapon {
return this.weapon;
}
public get Collider(): Collider2D {
return this.collider;
}

View File

@@ -0,0 +1,12 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "b10425c2-13b2-4c46-a497-13a269a204de",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -0,0 +1,29 @@
import { CCString, instantiate, Node, Prefab, Vec3, _decorator } from "cc";
import { ModalWindow } from "../../../Services/ModalWindowSystem/ModalWindow";
import { delay } from "../../../Services/Utils/AsyncUtils";
import { LevelUpSkill } from "./LevelUpSkill";
const { ccclass, property } = _decorator;
@ccclass("LevelUpModalWindow")
export class LevelUpModalWindow extends ModalWindow<string, string> {
@property(Prefab) private skillPrefab: Prefab;
@property(Node) private skillParent: Node;
protected async setup(params: string): Promise<void> {
const xPositions: number[] = [-180, 0, 180];
await delay(300);
for (let i = 0; i < 3; i++) {
await delay(500);
const skill: LevelUpSkill = instantiate(this.skillPrefab).getComponent(LevelUpSkill);
skill.node.setParent(this.skillParent);
skill.node.setPosition(new Vec3(xPositions[i]));
skill.init(params);
skill.ChooseSkillEvent.on(this.chooseSkill, this);
}
}
private chooseSkill(skill: LevelUpSkill): void {
this.dismiss("FInishedSuccessfuly");
}
}

View File

@@ -0,0 +1,22 @@
import { Component, Label, NodeEventType, _decorator } from "cc";
import { ISignal } from "../../../Services/EventSystem/ISignal";
import { Signal } from "../../../Services/EventSystem/Signal";
const { ccclass, property } = _decorator;
@ccclass("LevelUpSkill")
export class LevelUpSkill extends Component {
@property(Label) private skillTitle: Label;
private chooseSkillEvent: Signal<LevelUpSkill> = new Signal<LevelUpSkill>();
public init(skillTitle: string): void {
this.skillTitle.string = skillTitle;
this.node.on(NodeEventType.MOUSE_DOWN, this.chooseSkill, this);
}
public get ChooseSkillEvent(): ISignal<LevelUpSkill> {
return this.chooseSkillEvent;
}
private chooseSkill(): void {
this.chooseSkillEvent.trigger(this);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "65e26889-bc4f-487d-8625-602fbced8eb1",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,12 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "c281ddc9-4aa5-4d69-af47-cf25a4ff4c11",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -0,0 +1,9 @@
export enum UpgradeType {
MaxHP,
WeaponLength,
WeaponDamage,
HorizontalProjectile,
VerticalProjectile,
OverallDamage,
Regeneration
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "a481c31c-b6ba-4871-b8d7-f151788a450a",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,39 @@
import { Player } from "../Player/Player";
import { UpgradeType } from "./UpgradeType";
export class Upgrader {
private player: Player;
private typeToAction: Map<UpgradeType, () => void> = new Map<UpgradeType, () => void>();
private typeToLevel: Map<UpgradeType, number> = new Map<UpgradeType, number>();
public constructor(player: Player) {
this.player = player;
this.typeToAction.set(UpgradeType.MaxHP, this.upgradeMaxHp);
this.typeToAction.set(UpgradeType.WeaponLength, this.upgradeWeaponLength);
this.typeToAction.set(UpgradeType.WeaponDamage, this.upgradeWeaponDamage);
this.typeToLevel.set(UpgradeType.MaxHP, 0);
this.typeToLevel.set(UpgradeType.WeaponLength, 0);
}
public upgradeSkill(type: UpgradeType): void {
if (!this.typeToAction.has(type)) throw new Error("Upgrade does not have " + type);
this.typeToAction.get(type)();
}
private upgradeMaxHp(): void {
const healthIncrease = 5;
const currentMax: number = this.player.Health.MaxHealthPoints;
this.player.Health.setMaxHealth(currentMax + healthIncrease);
this.player.Health.heal(healthIncrease);
}
private upgradeWeaponLength(): void {
this.player.Weapon.upgradeWeaponLength();
}
private upgradeWeaponDamage(): void {
this.player.Weapon.upgradeWeaponDamage();
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "51a09dd7-ec63-40dd-a0ce-1a16632f16fa",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -34,6 +34,9 @@ export class Weapon extends Component {
return 5;
}
public upgradeWeaponDamage(): void {}
public upgradeWeaponLength(): void {}
private strike(): void {
this.node.active = true;
this.weaponAnimation.play(this.strikeState.name);

View File

@@ -1,16 +0,0 @@
import { CCString, _decorator } from "cc";
import { delay } from "../Utils/AsyncUtils";
import { ModalWindow } from "./ModalWindow";
const { ccclass, property } = _decorator;
@ccclass("LevelUpModalWindow")
export class LevelUpModalWindow extends ModalWindow<string, string> {
@property(CCString) private testField: string;
protected async setup(params: string): Promise<void> {
console.log("TEST FIELD: " + this.testField + " params: " + params);
await delay(10000);
this.dismiss("FInishedSuccessfuly");
}
}

View File

@@ -1,14 +1,21 @@
import { Component } from "cc";
import { Animation, Component, _decorator } from "cc";
import { delay } from "../Utils/AsyncUtils";
const { property } = _decorator;
export abstract class ModalWindow<TParam, TResult> extends Component {
@property(Animation) private animation: Animation;
private result: TResult;
private isDismissed = false;
public async runAsync(params?: TParam): Promise<TResult> {
this.setup(params);
this.animation?.play("open");
while (!this.isDismissed) await delay(100);
this.animation?.play("close");
await delay(500);
return this.result;
}