summaryrefslogtreecommitdiff
path: root/Thronefall_v1.0/Decompile/ManualAttack.cs
blob: f249343056ffa41f51a0e3a041aea45ca5d80146 (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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
using System.Collections.Generic;
using Rewired;
using UnityEngine;
using UnityEngine.Events;

public class ManualAttack : MonoBehaviour
{
	public float spawnAttackHeight;

	public List<TargetPriority> targetPriorities = new List<TargetPriority>();

	public Weapon weapon;

	public float cooldownTime = 1f;

	public Transform transformForAttackDirection;

	public Transform attackMarkerPosition;

	public Transform preferredTargetMarkerPosition;

	public bool autoAttack = true;

	public ParticleSystem particlesOnAttack;

	public bool playOneShotOnAttack;

	public ThronefallAudioManager.AudioOneShot oneshotOnAttack;

	protected float cooldown;

	protected float inputBuffer = -1f;

	protected bool isAttacking;

	protected Hp hpPlayer;

	private Player input;

	protected TaggedObject myTaggedObj;

	private DayNightCycle dayNightCycle;

	private PlayerUpgradeManager upgradeManager;

	private Vector3 lastTargetPos;

	[HideInInspector]
	public UnityEvent onAttack = new UnityEvent();

	protected AudioSet audioSet;

	private AudioSet.ClipArray caStillOnCooldown;

	private AudioSet.ClipArray caCooldownOver;

	protected ThronefallAudioManager audioManager;

	private bool timedActivationPerfectly;

	protected TaggedObject preferredTarget;

	protected TaggedObject target;

	private float perfectTimingDeniedFor;

	public float AttackDamageMultiplyer => upgradeManager.playerDamageMultiplyer;

	public Vector3 LastTargetPos => lastTargetPos;

	public float CooldownPercentage => Mathf.Clamp01(cooldown / cooldownTime);

	public virtual void Start()
	{
		upgradeManager = PlayerUpgradeManager.instance;
		hpPlayer = GetComponentInParent<Hp>();
		input = ReInput.players.GetPlayer(0);
		myTaggedObj = GetComponentInParent<TaggedObject>();
		dayNightCycle = DayNightCycle.Instance;
		audioSet = ThronefallAudioManager.Instance.audioContent;
		audioManager = ThronefallAudioManager.Instance;
		caStillOnCooldown = audioSet.PlayerCantUseActiveAbility;
		caCooldownOver = audioSet.ActiveAbilityCooldownReadyToUse;
	}

	public virtual void Update()
	{
		if (autoAttack && hpPlayer.HpValue > 0f)
		{
			Tick();
		}
	}

	public void Tick()
	{
		float num = cooldown;
		cooldown -= Time.deltaTime;
		if (upgradeManager.assassinsTraining && timedActivationPerfectly)
		{
			cooldown -= Time.deltaTime * UpgradeAssassinsTraining.instance.additionalCooldownSpeed;
		}
		if (num > 0f && cooldown <= 0f && !autoAttack && DayNightCycle.Instance.CurrentTimestate == DayNightCycle.Timestate.Night)
		{
			audioManager.PlaySoundAsOneShot(caCooldownOver, 1f, 1f, audioSet.mixGroupFX, 5);
		}
		isAttacking = false;
		HandleAttackUpdate();
		inputBuffer -= Time.deltaTime;
		perfectTimingDeniedFor -= Time.deltaTime;
		if ((bool)attackMarkerPosition)
		{
			if (autoAttack || cooldown <= 0f)
			{
				target = FindAttackTarget(_choosePreferredTargetIfPossible: true);
				if (target == null)
				{
					attackMarkerPosition.gameObject.SetActive(value: false);
				}
				else
				{
					if (autoAttack)
					{
						inputBuffer = 0.2f;
						isAttacking = true;
					}
					attackMarkerPosition.gameObject.SetActive(value: true);
					attackMarkerPosition.position = target.transform.position;
				}
			}
			else
			{
				attackMarkerPosition.gameObject.SetActive(value: false);
			}
		}
		if (input.GetButtonDown("Lock Target"))
		{
			TaggedObject taggedObject = FindAttackTarget();
			if (preferredTarget == null)
			{
				preferredTarget = taggedObject;
				if ((bool)taggedObject && upgradeManager.godlyCurse && (bool)preferredTargetMarkerPosition)
				{
					taggedObject.GetComponent<Hp>().ScaleHp(1f / upgradeManager.godlyCurseDamageMultiplyer);
				}
			}
			else
			{
				if (upgradeManager.godlyCurse && (bool)preferredTargetMarkerPosition)
				{
					taggedObject.GetComponent<Hp>().ScaleHp(upgradeManager.godlyCurseDamageMultiplyer);
				}
				preferredTarget = null;
			}
		}
		if ((bool)preferredTargetMarkerPosition)
		{
			if ((bool)preferredTarget)
			{
				preferredTargetMarkerPosition.gameObject.SetActive(value: true);
				preferredTargetMarkerPosition.position = preferredTarget.transform.position;
			}
			else
			{
				preferredTargetMarkerPosition.gameObject.SetActive(value: false);
			}
		}
	}

	public void TryToAttack()
	{
		if (dayNightCycle.CurrentTimestate == DayNightCycle.Timestate.Day && !autoAttack)
		{
			return;
		}
		if (upgradeManager.assassinsTraining && perfectTimingDeniedFor <= 0f)
		{
			timedActivationPerfectly = Mathf.Abs(cooldown) < UpgradeAssassinsTraining.instance.activationWindow;
			if (!timedActivationPerfectly)
			{
				perfectTimingDeniedFor = 2f;
			}
		}
		inputBuffer = 0.2f;
		isAttacking = true;
	}

	public void HandleAttackUpdate()
	{
		if (!(inputBuffer >= 0f))
		{
			return;
		}
		if (cooldown > 0f)
		{
			if (!autoAttack && cooldown > inputBuffer)
			{
				audioManager.PlaySoundAsOneShot(caStillOnCooldown, 1f, Random.Range(1.8f, 2.2f), audioSet.mixGroupFX, 5);
				inputBuffer = -1f;
			}
		}
		else
		{
			inputBuffer = -1f;
			isAttacking = true;
			cooldown = cooldownTime;
			Attack();
		}
	}

	public virtual void Attack()
	{
		if ((bool)particlesOnAttack)
		{
			particlesOnAttack.Play();
		}
		if (playOneShotOnAttack)
		{
			ThronefallAudioManager.Oneshot(oneshotOnAttack);
		}
		TaggedObject taggedObject = FindAttackTarget(_choosePreferredTargetIfPossible: true);
		Hp hp = null;
		if ((bool)taggedObject)
		{
			hp = taggedObject.Hp;
			lastTargetPos = taggedObject.transform.position;
			weapon.Attack(base.transform.position + spawnAttackHeight * Vector3.up, hp, transformForAttackDirection.forward, myTaggedObj, AttackDamageMultiplyer);
			onAttack.Invoke();
		}
	}

	protected TaggedObject FindAttackTarget(bool _choosePreferredTargetIfPossible = false)
	{
		if (_choosePreferredTargetIfPossible && (bool)preferredTarget && TagManager.instance.MeasureDistanceToTaggedObject(preferredTarget, base.transform.position) <= targetPriorities[0].range)
		{
			return preferredTarget;
		}
		for (int i = 0; i < targetPriorities.Count; i++)
		{
			TaggedObject taggedObject = targetPriorities[i].FindClosestTaggedObject(base.transform.position);
			if (taggedObject != null)
			{
				return taggedObject;
			}
		}
		return null;
	}
}