mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2024-12-26 11:48:54 +00:00
Meta upgrades
This commit is contained in:
parent
e8fc5a1ec9
commit
714ea8883b
@ -63,9 +63,9 @@
|
|||||||
"metaUpgrades": {
|
"metaUpgrades": {
|
||||||
"health": {
|
"health": {
|
||||||
"costs": [
|
"costs": [
|
||||||
5,
|
0,
|
||||||
10,
|
0,
|
||||||
15
|
0
|
||||||
],
|
],
|
||||||
"bonuses": [
|
"bonuses": [
|
||||||
10,
|
10,
|
||||||
@ -75,9 +75,9 @@
|
|||||||
},
|
},
|
||||||
"overallDamage": {
|
"overallDamage": {
|
||||||
"costs": [
|
"costs": [
|
||||||
6,
|
0,
|
||||||
10,
|
10,
|
||||||
15
|
0
|
||||||
],
|
],
|
||||||
"bonuses": [
|
"bonuses": [
|
||||||
1,
|
1,
|
||||||
@ -87,8 +87,8 @@
|
|||||||
},
|
},
|
||||||
"projectilePiercing": {
|
"projectilePiercing": {
|
||||||
"costs": [
|
"costs": [
|
||||||
7,
|
0,
|
||||||
10,
|
0,
|
||||||
15
|
15
|
||||||
],
|
],
|
||||||
"bonuses": [
|
"bonuses": [
|
||||||
@ -99,9 +99,9 @@
|
|||||||
},
|
},
|
||||||
"movementSpeed": {
|
"movementSpeed": {
|
||||||
"costs": [
|
"costs": [
|
||||||
8,
|
0,
|
||||||
10,
|
0,
|
||||||
15
|
0
|
||||||
],
|
],
|
||||||
"bonuses": [
|
"bonuses": [
|
||||||
10,
|
10,
|
||||||
|
@ -15,12 +15,12 @@
|
|||||||
"META_HEALTH_DESC": "Increases max health by {0}",
|
"META_HEALTH_DESC": "Increases max health by {0}",
|
||||||
"META_OVERALL_DAMAGE_TITLE": "OVERALL DAMAGE",
|
"META_OVERALL_DAMAGE_TITLE": "OVERALL DAMAGE",
|
||||||
"META_OVERALL_DAMAGE_DESC": "Increases overall damage by {0}",
|
"META_OVERALL_DAMAGE_DESC": "Increases overall damage by {0}",
|
||||||
"META_PROJECTILE_PIERCING_TITLE": "",
|
"META_PROJECTILE_PIERCING_TITLE": "PROJECTILE PIERCING",
|
||||||
"META_PROJECTILE_PIERCING_DESC": "",
|
"META_PROJECTILE_PIERCING_DESC": "Projectiles pierce {0} times",
|
||||||
"META_MOVEMENT_SPEED_TITLE": "",
|
"META_MOVEMENT_SPEED_TITLE": "MOVEMENT SPEED",
|
||||||
"META_MOVEMENT_SPEED_DESC": "",
|
"META_MOVEMENT_SPEED_DESC": "Increases movement speed",
|
||||||
"META_XP_GATHERER_TITLE": "",
|
"META_XP_GATHERER_TITLE": "XP GATHERER",
|
||||||
"META_XP_GATHERER_DESC": "",
|
"META_XP_GATHERER_DESC": "Increases the amount of XP obtained by {0}",
|
||||||
"META_GOLD_GATHERER_TITLE": "",
|
"META_GOLD_GATHERER_TITLE": "GOLD GATHERER",
|
||||||
"META_GOLD_GATHERER_DESC": ""
|
"META_GOLD_GATHERER_DESC": "Increases the amount of gold obtained by {0}"
|
||||||
}
|
}
|
@ -29,25 +29,31 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"__id__": 20
|
"__id__": 20
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 26
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"_active": true,
|
"_active": true,
|
||||||
"_components": [
|
"_components": [
|
||||||
{
|
|
||||||
"__id__": 26
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"__id__": 28
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"__id__": 30
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"__id__": 32
|
"__id__": 32
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 34
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 36
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 40
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 38
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"_prefab": {
|
"_prefab": {
|
||||||
"__id__": 34
|
"__id__": 42
|
||||||
},
|
},
|
||||||
"_lpos": {
|
"_lpos": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
@ -138,8 +144,8 @@
|
|||||||
},
|
},
|
||||||
"_contentSize": {
|
"_contentSize": {
|
||||||
"__type__": "cc.Size",
|
"__type__": "cc.Size",
|
||||||
"width": 84.64,
|
"width": 110,
|
||||||
"height": 30
|
"height": 80
|
||||||
},
|
},
|
||||||
"_anchorPoint": {
|
"_anchorPoint": {
|
||||||
"__type__": "cc.Vec2",
|
"__type__": "cc.Vec2",
|
||||||
@ -180,7 +186,7 @@
|
|||||||
"_fontSize": 30,
|
"_fontSize": 30,
|
||||||
"_fontFamily": "Arial",
|
"_fontFamily": "Arial",
|
||||||
"_lineHeight": 30,
|
"_lineHeight": 30,
|
||||||
"_overflow": 0,
|
"_overflow": 1,
|
||||||
"_enableWrapText": true,
|
"_enableWrapText": true,
|
||||||
"_font": {
|
"_font": {
|
||||||
"__uuid__": "c96b42a9-d20d-4c59-8e99-8ed749a715c8",
|
"__uuid__": "c96b42a9-d20d-4c59-8e99-8ed749a715c8",
|
||||||
@ -232,7 +238,7 @@
|
|||||||
"_lpos": {
|
"_lpos": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
"x": 0,
|
"x": 0,
|
||||||
"y": 0,
|
"y": -3,
|
||||||
"z": 0
|
"z": 0
|
||||||
},
|
},
|
||||||
"_lrot": {
|
"_lrot": {
|
||||||
@ -364,7 +370,7 @@
|
|||||||
"_lpos": {
|
"_lpos": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
"x": 0,
|
"x": 0,
|
||||||
"y": -33,
|
"y": -38,
|
||||||
"z": 0
|
"z": 0
|
||||||
},
|
},
|
||||||
"_lrot": {
|
"_lrot": {
|
||||||
@ -475,7 +481,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"__type__": "cc.Node",
|
"__type__": "cc.Node",
|
||||||
"_name": "LevelPoints",
|
"_name": "MaxLevel",
|
||||||
"_objFlags": 0,
|
"_objFlags": 0,
|
||||||
"_parent": {
|
"_parent": {
|
||||||
"__id__": 1
|
"__id__": 1
|
||||||
@ -496,7 +502,7 @@
|
|||||||
"_lpos": {
|
"_lpos": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
"x": 0,
|
"x": 0,
|
||||||
"y": -63.985,
|
"y": -6,
|
||||||
"z": 0
|
"z": 0
|
||||||
},
|
},
|
||||||
"_lrot": {
|
"_lrot": {
|
||||||
@ -532,6 +538,138 @@
|
|||||||
"__prefab": {
|
"__prefab": {
|
||||||
"__id__": 22
|
"__id__": 22
|
||||||
},
|
},
|
||||||
|
"_contentSize": {
|
||||||
|
"__type__": "cc.Size",
|
||||||
|
"width": 96.43,
|
||||||
|
"height": 20
|
||||||
|
},
|
||||||
|
"_anchorPoint": {
|
||||||
|
"__type__": "cc.Vec2",
|
||||||
|
"x": 0.5,
|
||||||
|
"y": 0.5
|
||||||
|
},
|
||||||
|
"_id": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.CompPrefabInfo",
|
||||||
|
"fileId": "276iFXJJBND6xagl8JLo54"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.Label",
|
||||||
|
"_name": "",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"node": {
|
||||||
|
"__id__": 20
|
||||||
|
},
|
||||||
|
"_enabled": true,
|
||||||
|
"__prefab": {
|
||||||
|
"__id__": 24
|
||||||
|
},
|
||||||
|
"_customMaterial": null,
|
||||||
|
"_srcBlendFactor": 2,
|
||||||
|
"_dstBlendFactor": 4,
|
||||||
|
"_color": {
|
||||||
|
"__type__": "cc.Color",
|
||||||
|
"r": 255,
|
||||||
|
"g": 167,
|
||||||
|
"b": 34,
|
||||||
|
"a": 255
|
||||||
|
},
|
||||||
|
"_string": "MAX LEVEL",
|
||||||
|
"_horizontalAlign": 1,
|
||||||
|
"_verticalAlign": 1,
|
||||||
|
"_actualFontSize": 20,
|
||||||
|
"_fontSize": 20,
|
||||||
|
"_fontFamily": "Arial",
|
||||||
|
"_lineHeight": 20,
|
||||||
|
"_overflow": 0,
|
||||||
|
"_enableWrapText": true,
|
||||||
|
"_font": {
|
||||||
|
"__uuid__": "c96b42a9-d20d-4c59-8e99-8ed749a715c8",
|
||||||
|
"__expectedType__": "cc.BitmapFont"
|
||||||
|
},
|
||||||
|
"_isSystemFontUsed": false,
|
||||||
|
"_spacingX": 0,
|
||||||
|
"_isItalic": false,
|
||||||
|
"_isBold": false,
|
||||||
|
"_isUnderline": false,
|
||||||
|
"_underlineHeight": 2,
|
||||||
|
"_cacheMode": 0,
|
||||||
|
"_id": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.CompPrefabInfo",
|
||||||
|
"fileId": "a87NNJ77tKzZ5vkZJk996T"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.PrefabInfo",
|
||||||
|
"root": {
|
||||||
|
"__id__": 1
|
||||||
|
},
|
||||||
|
"asset": {
|
||||||
|
"__id__": 0
|
||||||
|
},
|
||||||
|
"fileId": "0cQMux+vVPoLL0HRl6iqwl"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.Node",
|
||||||
|
"_name": "LevelPoints",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"_parent": {
|
||||||
|
"__id__": 1
|
||||||
|
},
|
||||||
|
"_children": [],
|
||||||
|
"_active": true,
|
||||||
|
"_components": [
|
||||||
|
{
|
||||||
|
"__id__": 27
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 29
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"_prefab": {
|
||||||
|
"__id__": 31
|
||||||
|
},
|
||||||
|
"_lpos": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": 0,
|
||||||
|
"y": -63.985,
|
||||||
|
"z": 0
|
||||||
|
},
|
||||||
|
"_lrot": {
|
||||||
|
"__type__": "cc.Quat",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0,
|
||||||
|
"w": 1
|
||||||
|
},
|
||||||
|
"_lscale": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": 1,
|
||||||
|
"y": 1,
|
||||||
|
"z": 1
|
||||||
|
},
|
||||||
|
"_layer": 33554432,
|
||||||
|
"_euler": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0
|
||||||
|
},
|
||||||
|
"_id": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.UITransform",
|
||||||
|
"_name": "",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"node": {
|
||||||
|
"__id__": 26
|
||||||
|
},
|
||||||
|
"_enabled": true,
|
||||||
|
"__prefab": {
|
||||||
|
"__id__": 28
|
||||||
|
},
|
||||||
"_contentSize": {
|
"_contentSize": {
|
||||||
"__type__": "cc.Size",
|
"__type__": "cc.Size",
|
||||||
"width": 0,
|
"width": 0,
|
||||||
@ -553,11 +691,11 @@
|
|||||||
"_name": "",
|
"_name": "",
|
||||||
"_objFlags": 0,
|
"_objFlags": 0,
|
||||||
"node": {
|
"node": {
|
||||||
"__id__": 20
|
"__id__": 26
|
||||||
},
|
},
|
||||||
"_enabled": true,
|
"_enabled": true,
|
||||||
"__prefab": {
|
"__prefab": {
|
||||||
"__id__": 24
|
"__id__": 30
|
||||||
},
|
},
|
||||||
"_resizeMode": 1,
|
"_resizeMode": 1,
|
||||||
"_layoutType": 1,
|
"_layoutType": 1,
|
||||||
@ -604,7 +742,7 @@
|
|||||||
},
|
},
|
||||||
"_enabled": true,
|
"_enabled": true,
|
||||||
"__prefab": {
|
"__prefab": {
|
||||||
"__id__": 27
|
"__id__": 33
|
||||||
},
|
},
|
||||||
"_contentSize": {
|
"_contentSize": {
|
||||||
"__type__": "cc.Size",
|
"__type__": "cc.Size",
|
||||||
@ -631,7 +769,7 @@
|
|||||||
},
|
},
|
||||||
"_enabled": true,
|
"_enabled": true,
|
||||||
"__prefab": {
|
"__prefab": {
|
||||||
"__id__": 29
|
"__id__": 35
|
||||||
},
|
},
|
||||||
"_customMaterial": null,
|
"_customMaterial": null,
|
||||||
"_srcBlendFactor": 2,
|
"_srcBlendFactor": 2,
|
||||||
@ -675,14 +813,14 @@
|
|||||||
},
|
},
|
||||||
"_enabled": true,
|
"_enabled": true,
|
||||||
"__prefab": {
|
"__prefab": {
|
||||||
"__id__": 31
|
"__id__": 37
|
||||||
},
|
},
|
||||||
"levelPointPrefab": {
|
"levelPointPrefab": {
|
||||||
"__uuid__": "41ca6952-fa32-4e38-8d43-eec2e982533c",
|
"__uuid__": "41ca6952-fa32-4e38-8d43-eec2e982533c",
|
||||||
"__expectedType__": "cc.Prefab"
|
"__expectedType__": "cc.Prefab"
|
||||||
},
|
},
|
||||||
"levelPointsParent": {
|
"levelPointsParent": {
|
||||||
"__id__": 20
|
"__id__": 26
|
||||||
},
|
},
|
||||||
"title": {
|
"title": {
|
||||||
"__id__": 5
|
"__id__": 5
|
||||||
@ -693,12 +831,35 @@
|
|||||||
"cost": {
|
"cost": {
|
||||||
"__id__": 17
|
"__id__": 17
|
||||||
},
|
},
|
||||||
|
"maxLevel": {
|
||||||
|
"__id__": 23
|
||||||
|
},
|
||||||
|
"uiButton": {
|
||||||
|
"__id__": 38
|
||||||
|
},
|
||||||
"_id": ""
|
"_id": ""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"__type__": "cc.CompPrefabInfo",
|
"__type__": "cc.CompPrefabInfo",
|
||||||
"fileId": "c52I+5RPFJDoP/OUf2yPtC"
|
"fileId": "c52I+5RPFJDoP/OUf2yPtC"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"__type__": "55e5f5nQ8dHiL5fPWjgdXbH",
|
||||||
|
"_name": "",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"node": {
|
||||||
|
"__id__": 1
|
||||||
|
},
|
||||||
|
"_enabled": true,
|
||||||
|
"__prefab": {
|
||||||
|
"__id__": 39
|
||||||
|
},
|
||||||
|
"_id": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.CompPrefabInfo",
|
||||||
|
"fileId": "b9Zn/AuoNOdLvE9z2Y6ORa"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"__type__": "cc.Button",
|
"__type__": "cc.Button",
|
||||||
"_name": "",
|
"_name": "",
|
||||||
@ -708,7 +869,7 @@
|
|||||||
},
|
},
|
||||||
"_enabled": true,
|
"_enabled": true,
|
||||||
"__prefab": {
|
"__prefab": {
|
||||||
"__id__": 33
|
"__id__": 41
|
||||||
},
|
},
|
||||||
"clickEvents": [],
|
"clickEvents": [],
|
||||||
"_interactable": true,
|
"_interactable": true,
|
||||||
|
@ -2,7 +2,7 @@ import { sys } from "cc";
|
|||||||
import { UserData } from "../Game/Data/UserData";
|
import { UserData } from "../Game/Data/UserData";
|
||||||
|
|
||||||
export class SaveSystem {
|
export class SaveSystem {
|
||||||
private userDataIdentifier = "user-da";
|
private userDataIdentifier = "user-d";
|
||||||
public save(userData: UserData): void {
|
public save(userData: UserData): void {
|
||||||
sys.localStorage.setItem(this.userDataIdentifier, JSON.stringify(userData));
|
sys.localStorage.setItem(this.userDataIdentifier, JSON.stringify(userData));
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ export class GameData {
|
|||||||
|
|
||||||
export class MetaUpgradesData {
|
export class MetaUpgradesData {
|
||||||
public healthLevel = 0;
|
public healthLevel = 0;
|
||||||
public overallDamageLevel = 2;
|
public overallDamageLevel = 0;
|
||||||
public projectilePiercingLevel = 0;
|
public projectilePiercingLevel = 0;
|
||||||
public movementSpeedLevel = 0;
|
public movementSpeedLevel = 0;
|
||||||
public xpGathererLevel = 0;
|
public xpGathererLevel = 0;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { _decorator, Component } from "cc";
|
import { Component, _decorator } from "cc";
|
||||||
import { ModalWindowManager } from "../Services/ModalWindowSystem/ModalWindowManager";
|
import { ModalWindowManager } from "../Services/ModalWindowSystem/ModalWindowManager";
|
||||||
import { UIButton } from "../Services/UI/Button/UIButton";
|
import { UIButton } from "../Services/UI/Button/UIButton";
|
||||||
import { GameRunner } from "./GameRunner";
|
import { GameRunner } from "./GameRunner";
|
||||||
|
@ -2,6 +2,9 @@ import { Component, instantiate, Label, Node, Prefab, _decorator } from "cc";
|
|||||||
import { MetaUpgradeSettings } from "../../../Game/Data/GameSettings";
|
import { MetaUpgradeSettings } from "../../../Game/Data/GameSettings";
|
||||||
import { TranslationData } from "../../../Game/Data/TranslationData";
|
import { TranslationData } from "../../../Game/Data/TranslationData";
|
||||||
import { MetaUpgradeType } from "../../../Game/Upgrades/UpgradeType";
|
import { MetaUpgradeType } from "../../../Game/Upgrades/UpgradeType";
|
||||||
|
import { ISignal } from "../../../Services/EventSystem/ISignal";
|
||||||
|
import { Signal } from "../../../Services/EventSystem/Signal";
|
||||||
|
import { UIButton } from "../../../Services/UI/Button/UIButton";
|
||||||
import { formatString } from "../../../Services/Utils/StringUtils";
|
import { formatString } from "../../../Services/Utils/StringUtils";
|
||||||
import { UpgradeLevelPointUI } from "./UpgradeLevelPointUI";
|
import { UpgradeLevelPointUI } from "./UpgradeLevelPointUI";
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
@ -13,21 +16,61 @@ export class UpgradeUI extends Component {
|
|||||||
@property(Label) private title: Label;
|
@property(Label) private title: Label;
|
||||||
@property(Label) private description: Label;
|
@property(Label) private description: Label;
|
||||||
@property(Label) private cost: Label;
|
@property(Label) private cost: Label;
|
||||||
|
@property(Label) private maxLevel: Label;
|
||||||
|
|
||||||
|
@property(UIButton) private uiButton: UIButton;
|
||||||
|
|
||||||
|
private interactedEvent = new Signal<MetaUpgradeType>();
|
||||||
|
|
||||||
|
private upgradeType: MetaUpgradeType;
|
||||||
|
private upgradeSettings: MetaUpgradeSettings;
|
||||||
|
private translationData: TranslationData;
|
||||||
|
|
||||||
|
private levelPointUIs: UpgradeLevelPointUI[] = [];
|
||||||
|
|
||||||
public init(upgradeType: MetaUpgradeType, upgradeSettings: MetaUpgradeSettings, level: number, translationData: TranslationData): void {
|
public init(upgradeType: MetaUpgradeType, upgradeSettings: MetaUpgradeSettings, level: number, translationData: TranslationData): void {
|
||||||
for (let i = 0; i < upgradeSettings.bonuses.length; i++) {
|
this.upgradeType = upgradeType;
|
||||||
|
this.upgradeSettings = upgradeSettings;
|
||||||
|
this.translationData = translationData;
|
||||||
|
|
||||||
|
this.title.string = `${translationData[`${upgradeType}_TITLE`]}`;
|
||||||
|
this.uiButton.InteractedEvent.on(() => this.interactedEvent.trigger(upgradeType), this);
|
||||||
|
|
||||||
|
for (let i = 0; i < this.upgradeSettings.bonuses.length; i++) {
|
||||||
const node: Node = instantiate(this.levelPointPrefab);
|
const node: Node = instantiate(this.levelPointPrefab);
|
||||||
node.setParent(this.levelPointsParent);
|
node.setParent(this.levelPointsParent);
|
||||||
|
|
||||||
const levelPointUI = node.getComponent(UpgradeLevelPointUI);
|
const levelPointUI = node.getComponent(UpgradeLevelPointUI);
|
||||||
levelPointUI.init();
|
levelPointUI.init();
|
||||||
if (i < 3) {
|
|
||||||
levelPointUI.upgrade();
|
this.levelPointUIs.push(levelPointUI);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateLevel(level);
|
||||||
|
}
|
||||||
|
|
||||||
|
public updateLevel(level: number): void {
|
||||||
|
for (let i = 0; i < this.levelPointUIs.length; i++) {
|
||||||
|
if (i < level) {
|
||||||
|
this.levelPointUIs[i].upgrade();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.title.string = `${translationData[`${upgradeType}_TITLE`]}`;
|
if (level < this.upgradeSettings.bonuses.length) {
|
||||||
this.description.string = formatString(`${translationData[`${upgradeType}_DESC`]}`, [upgradeSettings.bonuses[level].toString()]);
|
this.maxLevel.node.active = false;
|
||||||
this.cost.string = upgradeSettings.costs[level].toString();
|
this.description.string = formatString(`${this.translationData[`${this.upgradeType}_DESC`]}`, [
|
||||||
|
this.upgradeSettings.bonuses[level].toString()
|
||||||
|
]);
|
||||||
|
this.cost.string = this.upgradeSettings.costs[level].toString();
|
||||||
|
} else {
|
||||||
|
// reached max level
|
||||||
|
this.maxLevel.node.active = true;
|
||||||
|
this.cost.node.active = false;
|
||||||
|
this.description.node.active = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public get InteractedEvent(): ISignal<MetaUpgradeType> {
|
||||||
|
return this.interactedEvent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { instantiate, Label, Node, Prefab, _decorator } from "cc";
|
import { instantiate, Label, Node, Prefab, TiledUserNodeData, _decorator } from "cc";
|
||||||
import { AppRoot } from "../../../AppRoot/AppRoot";
|
import { AppRoot } from "../../../AppRoot/AppRoot";
|
||||||
import { MetaUpgradeSettings } from "../../../Game/Data/GameSettings";
|
import { MetaUpgradeSettings } from "../../../Game/Data/GameSettings";
|
||||||
import { GameData } from "../../../Game/Data/UserData";
|
import { UserData, GameData, MetaUpgradesData } from "../../../Game/Data/UserData";
|
||||||
import { MetaUpgradeType } from "../../../Game/Upgrades/UpgradeType";
|
import { MetaUpgradeType, UpgradeType } from "../../../Game/Upgrades/UpgradeType";
|
||||||
import { ModalWindow } from "../../../Services/ModalWindowSystem/ModalWindow";
|
import { ModalWindow } from "../../../Services/ModalWindowSystem/ModalWindow";
|
||||||
import { UpgradeUI } from "./UpgradeUI";
|
import { UpgradeUI } from "./UpgradeUI";
|
||||||
|
|
||||||
@ -14,28 +14,59 @@ export class UpgradesModalWindow extends ModalWindow<Empty, Empty> {
|
|||||||
@property(Node) private upgradeButtonParent: Node;
|
@property(Node) private upgradeButtonParent: Node;
|
||||||
@property(Label) private goldCoinsLabel: Label;
|
@property(Label) private goldCoinsLabel: Label;
|
||||||
|
|
||||||
private gameData: GameData;
|
private typeToLevel = new Map<MetaUpgradeType, number>();
|
||||||
|
private typeToCosts = new Map<MetaUpgradeType, number[]>();
|
||||||
|
private typeToLevelKey = new Map<MetaUpgradeType, keyof MetaUpgradesData>();
|
||||||
|
private typeToUpgradeUI = new Map<MetaUpgradeType, UpgradeUI>();
|
||||||
|
|
||||||
|
private userData: UserData;
|
||||||
|
|
||||||
public setup(): void {
|
public setup(): void {
|
||||||
this.gameData = AppRoot.Instance.SaveSystem.load().game;
|
this.userData = AppRoot.Instance.SaveSystem.load();
|
||||||
|
|
||||||
const settings = AppRoot.Instance.Settings.metaUpgrades;
|
const settings = AppRoot.Instance.Settings.metaUpgrades;
|
||||||
const data = this.gameData.metaUpgrades;
|
|
||||||
|
|
||||||
this.createUpgradeButton(MetaUpgradeType.Health, settings.health, data.healthLevel);
|
this.createUpgradeButton(MetaUpgradeType.Health, settings.health, "healthLevel");
|
||||||
this.createUpgradeButton(MetaUpgradeType.OverallDamage, settings.overallDamage, data.healthLevel);
|
this.createUpgradeButton(MetaUpgradeType.OverallDamage, settings.overallDamage, "overallDamageLevel");
|
||||||
this.createUpgradeButton(MetaUpgradeType.ProjectilePiercing, settings.projectilePiercing, data.healthLevel);
|
this.createUpgradeButton(MetaUpgradeType.ProjectilePiercing, settings.projectilePiercing, "projectilePiercingLevel");
|
||||||
this.createUpgradeButton(MetaUpgradeType.MovementSpeed, settings.movementSpeed, data.healthLevel);
|
this.createUpgradeButton(MetaUpgradeType.MovementSpeed, settings.movementSpeed, "movementSpeedLevel");
|
||||||
this.createUpgradeButton(MetaUpgradeType.XPGatherer, settings.xpGatherer, data.healthLevel);
|
this.createUpgradeButton(MetaUpgradeType.XPGatherer, settings.xpGatherer, "xpGathererLevel");
|
||||||
this.createUpgradeButton(MetaUpgradeType.GoldGatherer, settings.goldGatherer, data.healthLevel);
|
this.createUpgradeButton(MetaUpgradeType.GoldGatherer, settings.goldGatherer, "goldGathererLevel");
|
||||||
|
|
||||||
this.goldCoinsLabel.string = this.gameData.goldCoins.toString();
|
this.goldCoinsLabel.string = this.userData.game.goldCoins.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private createUpgradeButton(upgradeType: MetaUpgradeType, upgradeSettings: MetaUpgradeSettings, level: number): void {
|
private createUpgradeButton<T extends keyof MetaUpgradesData>(
|
||||||
|
upgradeType: MetaUpgradeType,
|
||||||
|
upgradeSettings: MetaUpgradeSettings,
|
||||||
|
levelKey: T
|
||||||
|
): void {
|
||||||
const upgradeButton: Node = instantiate(this.upgradeButtonPrefab);
|
const upgradeButton: Node = instantiate(this.upgradeButtonPrefab);
|
||||||
upgradeButton.getComponent(UpgradeUI).init(upgradeType, upgradeSettings, level, AppRoot.Instance.TranslationData);
|
const upgradeUI: UpgradeUI = upgradeButton.getComponent(UpgradeUI);
|
||||||
|
|
||||||
|
upgradeUI.init(upgradeType, upgradeSettings, this.userData.game.metaUpgrades[levelKey], AppRoot.Instance.TranslationData);
|
||||||
|
upgradeUI.InteractedEvent.on(this.tryUpgrade, this);
|
||||||
upgradeButton.setParent(this.upgradeButtonParent);
|
upgradeButton.setParent(this.upgradeButtonParent);
|
||||||
|
|
||||||
|
this.typeToLevel.set(upgradeType, this.userData.game.metaUpgrades[levelKey]);
|
||||||
|
this.typeToCosts.set(upgradeType, upgradeSettings.costs);
|
||||||
|
this.typeToLevelKey.set(upgradeType, levelKey);
|
||||||
|
this.typeToUpgradeUI.set(upgradeType, upgradeUI);
|
||||||
|
}
|
||||||
|
|
||||||
|
private tryUpgrade(upgradeType: MetaUpgradeType): void {
|
||||||
|
console.log("Trying to upgrade " + upgradeType);
|
||||||
|
|
||||||
|
const costs: number[] = this.typeToCosts.get(upgradeType);
|
||||||
|
const currentLevel: number = this.typeToLevel.get(upgradeType);
|
||||||
|
|
||||||
|
if (costs.length <= currentLevel) return; // already max level
|
||||||
|
if (this.userData.game.goldCoins < costs[currentLevel]) return; // not enough gold
|
||||||
|
|
||||||
|
this.userData.game.goldCoins -= costs[currentLevel];
|
||||||
|
const level = ++this.userData.game.metaUpgrades[this.typeToLevelKey.get(upgradeType)];
|
||||||
|
this.typeToUpgradeUI.get(upgradeType).updateLevel(level);
|
||||||
|
|
||||||
|
AppRoot.Instance.SaveSystem.save(this.userData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user