summaryrefslogtreecommitdiff
path: root/GameCode/BeamAttack.cs
blob: a05ee280ef77aed0c690eff2e4ff17df721200f2 (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
using System.Collections;
using UnityEngine;

public class BeamAttack : MonoBehaviour
{
	public float selfHeal;

	public float damage = 8f;

	public float force = 2500f;

	public float scalingForce;

	public float overTimeForce;

	public float overTimeScalingForce;

	public float overTimeDrag;

	public float effectOverTimeTime = 0.1f;

	public float interval = 0.2f;

	public float slow;

	public float maxSlow = 1f;

	public Color dmgColor;

	private Player attacker;

	private Player thisPlayer;

	private LineEffect[] lineEffects;

	private ParticleSystem[] parts;

	private CharacterStatModifiers stats;

	private float scaleMultiplier = 1f;

	private SpawnedAttack spawnedAttack;

	private float counter;

	private void Start()
	{
		lineEffects = GetComponentsInChildren<LineEffect>(includeInactive: true);
		parts = GetComponentsInChildren<ParticleSystem>();
		thisPlayer = GetComponentInParent<Player>();
		stats = thisPlayer.GetComponent<CharacterStatModifiers>();
		attacker = PlayerManager.instance.GetOtherPlayer(thisPlayer);
		scaleMultiplier = base.transform.localScale.x;
		spawnedAttack = GetComponentInParent<SpawnedAttack>();
		if (thisPlayer == spawnedAttack.spawner)
		{
			Object.Destroy(base.gameObject);
		}
	}

	private void Update()
	{
		if (!attacker || !thisPlayer)
		{
			return;
		}
		counter += TimeHandler.deltaTime;
		if (!(counter > interval))
		{
			return;
		}
		CanSeeInfo canSeeInfo = PlayerManager.instance.CanSeePlayer(attacker.transform.position, thisPlayer);
		if (canSeeInfo.canSee)
		{
			Vector2 vector = thisPlayer.transform.position - attacker.transform.position;
			Vector2 normalized = vector.normalized;
			if (force != 0f)
			{
				thisPlayer.data.healthHandler.TakeForce(normalized * scaleMultiplier * force);
			}
			if (scalingForce != 0f)
			{
				thisPlayer.data.healthHandler.TakeForce(vector * scaleMultiplier * scalingForce);
			}
			if (damage != 0f)
			{
				thisPlayer.data.healthHandler.TakeDamage(damage * scaleMultiplier * normalized, base.transform.position, dmgColor, null, attacker);
			}
			if (selfHeal != 0f)
			{
				attacker.data.healthHandler.Heal(selfHeal * scaleMultiplier);
			}
			for (int i = 0; i < lineEffects.Length; i++)
			{
				lineEffects[i].Play(attacker.transform, thisPlayer.transform);
			}
			StartCoroutine(DoOverTimeEffects(attacker));
			if (slow > 0f && (bool)stats)
			{
				stats.AddSlowAddative(slow * scaleMultiplier, maxSlow);
			}
		}
		else
		{
			for (int j = 0; j < lineEffects.Length; j++)
			{
				lineEffects[j].Play(attacker.transform, canSeeInfo.hitPoint);
			}
			for (int k = 0; k < parts.Length; k++)
			{
				parts[k].transform.position = canSeeInfo.hitPoint;
				parts[k].transform.localScale = Vector3.one * scaleMultiplier;
				parts[k].Play();
			}
		}
		counter = 0f;
	}

	private IEnumerator DoOverTimeEffects(Player attacker)
	{
		float c = 0f;
		while (c < effectOverTimeTime)
		{
			c += TimeHandler.deltaTime;
			if ((bool)attacker && (bool)thisPlayer)
			{
				Vector2 vector = thisPlayer.transform.position - attacker.transform.position;
				Vector2 normalized = vector.normalized;
				if (overTimeForce != 0f)
				{
					thisPlayer.data.healthHandler.TakeForce(normalized * scaleMultiplier * TimeHandler.deltaTime * overTimeForce);
				}
				if (overTimeScalingForce != 0f)
				{
					thisPlayer.data.healthHandler.TakeForce(vector * scaleMultiplier * TimeHandler.deltaTime * overTimeScalingForce, ForceMode2D.Force);
				}
				if (overTimeDrag > 0f)
				{
					thisPlayer.data.playerVel.AddForce(-thisPlayer.data.playerVel.velocity * Mathf.Clamp(TimeHandler.deltaTime * scaleMultiplier * overTimeDrag, 0f, 0.95f), ForceMode2D.Force);
				}
			}
			yield return null;
		}
	}
}