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

public class RidingDamager : MonoBehaviour
{
	public Equippable requiredUpgrade;

	public LayerMask lmRecieveDamage;

	public List<DamageModifyer> damage;

	private BoxCollider myCollider;

	private Collider[] tempColliders = new Collider[50];

	public float cooldownPerObject = 4f;

	private PlayerMovement playerMovement;

	private PlayerUpgradeManager upgradeManager;

	private BlacksmithUpgrades blacksmithUpgrades;

	private List<TaggedObject> recentlyHit = new List<TaggedObject>();

	private List<float> recentlyHitWhen = new List<float>();

	private float time;

	public float DamageMultiplyer => upgradeManager.playerDamageMultiplyer * blacksmithUpgrades.meleeDamage;

	private void Start()
	{
		if (!PerkManager.IsEquipped(requiredUpgrade))
		{
			Object.Destroy(base.gameObject);
			return;
		}
		myCollider = GetComponent<BoxCollider>();
		playerMovement = GetComponentInParent<PlayerMovement>();
		upgradeManager = PlayerUpgradeManager.instance;
		blacksmithUpgrades = BlacksmithUpgrades.instance;
	}

	private void Update()
	{
		Vector3 center = base.transform.localToWorldMatrix.MultiplyPoint(myCollider.center);
		Vector3 halfExtents = base.transform.localToWorldMatrix.MultiplyVector(myCollider.size);
		if (playerMovement.Moving && playerMovement.enabled)
		{
			Physics.OverlapBoxNonAlloc(center, halfExtents, tempColliders, base.transform.rotation, lmRecieveDamage);
			for (int i = 0; i < tempColliders.Length && !(tempColliders[i] == null); i++)
			{
				DealWithColliderHit(tempColliders[i]);
			}
		}
		time += Time.deltaTime;
		while (recentlyHitWhen.Count > 0 && time - recentlyHitWhen[0] > cooldownPerObject)
		{
			recentlyHitWhen.RemoveAt(0);
			recentlyHit.RemoveAt(0);
		}
	}

	private void DealWithColliderHit(Collider other)
	{
		TaggedObject componentInParent = other.GetComponentInParent<TaggedObject>();
		if ((bool)componentInParent && !recentlyHit.Contains(componentInParent) && componentInParent.Tags.Contains(TagManager.ETag.EnemyOwned))
		{
			componentInParent.Hp.TakeDamage(Weapon.CalculateDamageGeneral(componentInParent, damage, DamageMultiplyer));
			recentlyHit.Add(componentInParent);
			recentlyHitWhen.Add(time);
		}
	}
}