summaryrefslogtreecommitdiff
path: root/GameCode/University.cs
blob: 5115f508394088a3d212810257ec4288dd34134d (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using UnityEngine;

public class University : MonoBehaviour, IBuildable
{
	[SerializeField]
	private GameObject UIObject;

	[SerializeField]
	private GameObject mainUIObject;

	public int goldBackOnDemolish;

	[SerializeField]
	private LayerMask layermask;

	private bool active;

	public int healthPercent { get; private set; }

	public int armorPercent { get; private set; }

	public int shieldPercent { get; private set; }

	public int healthGained { get; private set; }

	public int armorGained { get; private set; }

	public int shieldGained { get; private set; }

	private void Start()
	{
		SpawnManager.instance.universities.Add(this);
		DetectShrines();
	}

	public void SetStats()
	{
	}

	public void Research()
	{
		if (active)
		{
			if (Random.Range(0f, 100f) <= (float)(healthPercent + GameManager.instance.universityBonus))
			{
				healthGained++;
				TowerManager.instance.AddBonusHealthDamage(TowerType.Global, 1);
				UniBonusUI.instance.UniBonus(1, 0, 0);
				DamageNumber component = ObjectPool.instance.SpawnObject(ObjectPool.ObjectType.DamageNumber, base.transform.position, Quaternion.identity).GetComponent<DamageNumber>();
				component.SetText("New Discoveries!", "Grey", 1f);
				component.SetHoldTime(2f);
				AchievementManager.instance.NewDiscoveriesAchievement();
			}
			if (Random.Range(0f, 100f) <= (float)(armorPercent + GameManager.instance.universityBonus))
			{
				armorGained++;
				UniBonusUI.instance.UniBonus(0, 1, 0);
				TowerManager.instance.AddBonusArmorDamage(TowerType.Global, 1);
				DamageNumber component2 = ObjectPool.instance.SpawnObject(ObjectPool.ObjectType.DamageNumber, base.transform.position, Quaternion.identity).GetComponent<DamageNumber>();
				component2.SetText("New Discoveries!", "Grey", 1f);
				component2.SetHoldTime(2f);
				AchievementManager.instance.NewDiscoveriesAchievement();
			}
			if (Random.Range(0f, 100f) <= (float)(shieldPercent + GameManager.instance.universityBonus))
			{
				shieldGained++;
				UniBonusUI.instance.UniBonus(0, 0, 1);
				TowerManager.instance.AddBonusShieldDamage(TowerType.Global, 1);
				DamageNumber component3 = ObjectPool.instance.SpawnObject(ObjectPool.ObjectType.DamageNumber, base.transform.position, Quaternion.identity).GetComponent<DamageNumber>();
				component3.SetText("New Discoveries!", "Grey", 1f);
				component3.SetHoldTime(2f);
				AchievementManager.instance.NewDiscoveriesAchievement();
			}
		}
	}

	public void FundHealthStudies()
	{
		int num = (healthPercent + armorPercent + shieldPercent + 1) * 20;
		if (ResourceManager.instance.CheckMoney(num))
		{
			healthPercent++;
			ResourceManager.instance.Spend(num);
			AchievementManager.instance.FundResearchAchievement(num);
		}
	}

	public void FundArmorStudies()
	{
		int num = (healthPercent + armorPercent + shieldPercent + 1) * 20;
		if (ResourceManager.instance.CheckMoney(num))
		{
			armorPercent++;
			ResourceManager.instance.Spend(num);
			AchievementManager.instance.FundResearchAchievement(num);
		}
	}

	public void FundShieldStudies()
	{
		int num = (healthPercent + armorPercent + shieldPercent + 1) * 20;
		if (ResourceManager.instance.CheckMoney(num))
		{
			shieldPercent++;
			ResourceManager.instance.Spend(num);
			AchievementManager.instance.FundResearchAchievement(num);
		}
	}

	public void SpawnUI()
	{
		if (!active)
		{
			Object.Instantiate(UIObject, base.transform.position, Quaternion.identity).GetComponent<SimpleUI>().SetDemolishable(base.gameObject, goldBackOnDemolish);
		}
		else
		{
			Object.Instantiate(mainUIObject, base.transform.position, Quaternion.identity).GetComponent<UniversityUI>().SetStats(this);
		}
	}

	public void Demolish()
	{
		SpawnManager.instance.universities.Remove(this);
	}

	private void DetectShrines()
	{
		if ((!Physics.Raycast(base.transform.position + new Vector3(1f, 1f, 0f), -base.transform.up, out var hitInfo, 1f, layermask, QueryTriggerInteraction.Ignore) || !Rotate(hitInfo)) && (!Physics.Raycast(base.transform.position + new Vector3(-1f, 1f, 0f), -base.transform.up, out hitInfo, 1f, layermask, QueryTriggerInteraction.Ignore) || !Rotate(hitInfo)) && (!Physics.Raycast(base.transform.position + new Vector3(0f, 1f, 1f), -base.transform.up, out hitInfo, 1f, layermask, QueryTriggerInteraction.Ignore) || !Rotate(hitInfo)) && Physics.Raycast(base.transform.position + new Vector3(0f, 1f, -1f), -base.transform.up, out hitInfo, 1f, layermask, QueryTriggerInteraction.Ignore))
		{
			Rotate(hitInfo);
		}
	}

	private bool Rotate(RaycastHit hit)
	{
		if (hit.collider.GetComponent<Shrine>() == null)
		{
			return false;
		}
		if ((double)(hit.collider.transform.position.y - base.transform.position.y) > 0.001)
		{
			return false;
		}
		base.transform.LookAt(hit.collider.transform.position, Vector3.up);
		active = true;
		SetStats();
		return true;
	}
}