summaryrefslogtreecommitdiff
path: root/Thronefall_v1.0/Decompile/LaunchableProjectile.cs
blob: 84f9fbd6d2cc04c14430dc3758b0803969b69e89 (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
using System.Collections.Generic;
using UnityEngine;

public class LaunchableProjectile : MonoBehaviour
{
	public float speed = 20f;

	public float lifetime = 3f;

	public bool groundedTranslation;

	public LayerMask groundLayer;

	public Vector3 groundingOfffset;

	public List<DamageModifyer> dmgModifiers = new List<DamageModifyer>();

	public LayerMask hitLayer;

	public Vector3 damageBoxExtents;

	private bool launched;

	private float timer;

	private List<Hp> touchedEnemies = new List<Hp>();

	public void Launch()
	{
		launched = true;
		if (groundedTranslation && Physics.Raycast(new Ray(base.transform.position, Vector3.down), out var hitInfo, float.PositiveInfinity, groundLayer))
		{
			base.transform.position = hitInfo.point + groundingOfffset;
		}
	}

	private void Update()
	{
		if (!launched)
		{
			return;
		}
		timer += Time.deltaTime;
		base.transform.position += base.transform.forward * speed * Time.deltaTime;
		Collider[] array = Physics.OverlapBox(base.transform.position, damageBoxExtents / 2f, base.transform.rotation, hitLayer);
		for (int i = 0; i < array.Length; i++)
		{
			Hp componentInParent = array[i].GetComponentInParent<Hp>();
			if ((bool)componentInParent && !touchedEnemies.Contains(componentInParent))
			{
				touchedEnemies.Add(componentInParent);
				componentInParent.TakeDamage(DamageModifyer.CalculateDamageOnTarget(componentInParent.TaggedObj, dmgModifiers));
			}
		}
		if (timer >= lifetime)
		{
			Object.Destroy(base.gameObject);
		}
	}

	private void OnDrawGizmos()
	{
		Gizmos.color = Color.magenta;
		Gizmos.DrawWireCube(base.transform.position, damageBoxExtents);
	}
}