summaryrefslogtreecommitdiff
path: root/GameCode/Obelisk.cs
blob: 549f3b465aa83108d54244d2a94720d63870107a (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
using UnityEngine;

public class Obelisk : Tower
{
	[SerializeField]
	private GameObject beam;

	[SerializeField]
	private AudioSource audioS;

	private bool soundPlaying;

	private IDamageable lastThingIHit;

	private float timeOnTarget;

	protected override void Update()
	{
		if (currentTarget != null)
		{
			if (turret != null)
			{
				AimTurret();
			}
			GainXP();
		}
		else
		{
			beam.SetActive(value: false);
			PlaySound(onOff: false);
		}
		timeSinceLastShot += Time.deltaTime;
		if (currentTarget != null && timeSinceLastShot > rps)
		{
			Fire();
			timeSinceLastShot = 0f;
		}
	}

	protected override void Fire()
	{
		if (consumesMana)
		{
			int manaCost = (int)((float)base.damage * manaConsumptionRate);
			if (!ResourceManager.instance.CheckMana(manaCost))
			{
				beam.SetActive(value: false);
				PlaySound(onOff: false);
				return;
			}
			ResourceManager.instance.SpendMana(manaCost);
		}
		DealDamage();
	}

	protected override void AimTurret()
	{
		Vector3 forward = currentTarget.transform.position - turret.transform.position + Vector3.up * 0.5f;
		Quaternion rotation = Quaternion.LookRotation(forward, Vector3.up);
		turret.transform.rotation = rotation;
		beam.transform.localScale = new Vector3(1f, 1f, forward.magnitude);
	}

	private void DealDamage()
	{
		IDamageable component = currentTarget.GetComponent<IDamageable>();
		if (component != null)
		{
			if (component == lastThingIHit)
			{
				timeOnTarget += rps;
			}
			else
			{
				timeOnTarget = 0f;
				lastThingIHit = component;
			}
			int num = Mathf.Clamp(Mathf.FloorToInt(timeOnTarget * TowerManager.instance.obeliskTimeOnTargetMultiplier), 0, base.damage);
			component.TakeDamage(towerType, base.damage + num, base.healthDamage, base.armorDamage, base.shieldDamage, base.slowPercent, base.bleedPercent, base.burnPercent, base.poisonPercent, base.critChance, base.stunChance);
			beam.SetActive(value: true);
			PlaySound(onOff: true);
		}
	}

	private void PlaySound(bool onOff)
	{
		if (onOff && !soundPlaying)
		{
			audioS.volume = OptionsMenu.instance.masterVolume * OptionsMenu.instance.sfxVolume;
			audioS.Play();
			soundPlaying = true;
		}
		else if (!onOff && soundPlaying)
		{
			audioS.Stop();
			soundPlaying = false;
		}
	}
}