summaryrefslogtreecommitdiff
path: root/GameCode/TasteOfBlood.cs
blob: 1a7ed4152806a3c4bda2655b8a9baa0d45c749bc (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;
using UnityEngine;

public class TasteOfBlood : MonoBehaviour
{
	public AnimationCurve attackSpeedCurve;

	public float decaySpeed = 1f;

	private float damageValue;

	private CharacterStatModifiers stats;

	private ParticleSystem part;

	private CharacterData data;

	private bool isOn;

	private void Start()
	{
		part = GetComponentInChildren<ParticleSystem>();
		stats = GetComponentInParent<CharacterStatModifiers>();
		CharacterStatModifiers characterStatModifiers = stats;
		characterStatModifiers.DealtDamageAction = (Action<Vector2, bool>)Delegate.Combine(characterStatModifiers.DealtDamageAction, new Action<Vector2, bool>(DealtDamage));
		data = GetComponentInParent<CharacterData>();
	}

	public void DealtDamage(Vector2 damage, bool selfDamage)
	{
		if (!selfDamage)
		{
			damageValue += damage.magnitude;
		}
		damageValue = Mathf.Clamp(damageValue, 0f, 50f);
	}

	private void Update()
	{
		if (!data.isPlaying)
		{
			damageValue = 0f;
		}
		if (damageValue > 0f)
		{
			damageValue -= TimeHandler.deltaTime * decaySpeed;
			isOn = true;
		}
		else
		{
			isOn = false;
		}
		if (damageValue > 10f)
		{
			if (!part.isPlaying)
			{
				part.Play();
			}
		}
		else if (part.isPlaying)
		{
			part.Stop();
		}
		stats.tasteOfBloodSpeed = attackSpeedCurve.Evaluate(damageValue);
	}
}