summaryrefslogtreecommitdiff
path: root/GameCode/UpgradeManager.cs
blob: 685308ed6b5c4ca7f144564669dfd198c64e695d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UpgradeManager : MonoBehaviour
{
	public static UpgradeManager instance;

	public int xp;

	public int prestige;

	[SerializeField]
	private Text xpText;

	[SerializeField]
	private GameObject prestigeDisplay;

	[SerializeField]
	private Text prestigeText;

	public int unlockedCardCount;

	[SerializeField]
	private UpgradeButton[] allButtons;

	[SerializeField]
	private List<UpgradeButton> cardsWhichRequireCardCount = new List<UpgradeButton>();

	private void Awake()
	{
		instance = this;
	}

	private void Start()
	{
		allButtons = Object.FindObjectsOfType<UpgradeButton>();
		UpgradeButton[] array = allButtons;
		foreach (UpgradeButton upgradeButton in array)
		{
			if (upgradeButton.cardCountRequirement > 0)
			{
				cardsWhichRequireCardCount.Add(upgradeButton);
			}
		}
		unlockedCardCount = PlayerPrefs.GetInt("UnlockedCardCount", 0);
		xp = PlayerPrefs.GetInt("XP", 0);
		xpText.text = "XP: " + xp;
		prestige = PlayerPrefs.GetInt("Prestige", 0);
		if (prestige > 0)
		{
			prestigeDisplay.SetActive(value: true);
			prestigeText.text = "Prestige: " + prestige;
		}
	}

	public void AddXP(int change)
	{
		xp += change;
		PlayerPrefs.SetInt("XP", xp);
		xpText.text = "XP: " + xp;
	}

	public void ResetUpgrades()
	{
		int num = 0;
		UpgradeButton[] array = allButtons;
		foreach (UpgradeButton upgradeButton in array)
		{
			if (upgradeButton.enabled)
			{
				if (upgradeButton.unlocked)
				{
					num += upgradeButton.xpCost;
				}
				upgradeButton.ResetUnlock();
			}
		}
		num += xp / 2;
		Debug.Log("Refunded xp: " + num);
		PlayerPrefs.SetInt("Prestige", prestige + num / 1000);
		xp = 0;
		PlayerPrefs.SetInt("XP", 0);
		PlayerPrefs.SetInt("UnlockedCardCount", 0);
		PlayerPrefs.SetInt("Development", 0);
		PlayerPrefs.SetInt("Record1", 0);
		PlayerPrefs.SetInt("Record2", 0);
		PlayerPrefs.SetInt("Record3", 0);
		LevelLoader.instance.LoadLevel("MainMenu");
	}

	public void CountCard(bool countsAsCardUnlock)
	{
		if (countsAsCardUnlock)
		{
			unlockedCardCount++;
			Debug.Log("Number of unlocked cards: " + unlockedCardCount);
			PlayerPrefs.SetInt("UnlockedCardCount", unlockedCardCount);
			CheckCardCount();
		}
	}

	public void CountDevelopment(bool value)
	{
		if (value)
		{
			int @int = PlayerPrefs.GetInt("Development", 0);
			PlayerPrefs.SetInt("Development", @int + 1);
			Debug.Log("Development: " + (@int + 1));
		}
	}

	public void CheckCardCount()
	{
		foreach (UpgradeButton item in cardsWhichRequireCardCount)
		{
			item.CheckEnabled();
		}
	}
}