summaryrefslogtreecommitdiff
path: root/GameCode/DamageBox.cs
blob: e86d79ffd5e2871dbe061eaff6b7d24ebf2a5ab5 (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
using Sonigon;
using UnityEngine;

public class DamageBox : MonoBehaviour
{
	[Header("Sound")]
	public bool soundPlaySawDamage;

	public SoundEvent soundSawDamage;

	[Header("Settings")]
	public bool towardsCenterOfMap;

	public bool awayFromMe;

	public float damage = 25f;

	public float force;

	public float setFlyingFor;

	public float shake;

	public float cd = 0.3f;

	public bool ignoreBlock;

	public ParticleSystem dmgPart;

	private float time;

	private SpawnedAttack spawned;

	private void Start()
	{
		spawned = GetComponentInParent<SpawnedAttack>();
	}

	private void OnCollisionEnter2D(Collision2D collision)
	{
		Collide(collision);
	}

	private void OnCollisionStay2D(Collision2D collision)
	{
		Collide(collision);
	}

	private void Collide(Collision2D collision)
	{
		if (Time.time < time + cd)
		{
			return;
		}
		Vector3 vector = base.transform.root.forward;
		if (towardsCenterOfMap)
		{
			vector = -collision.contacts[0].point.normalized;
		}
		if (awayFromMe)
		{
			vector = (collision.transform.position - base.transform.position).normalized;
		}
		Damagable componentInParent = collision.transform.GetComponentInParent<Damagable>();
		if (!componentInParent)
		{
			return;
		}
		time = Time.time;
		HealthHandler component = componentInParent.GetComponent<HealthHandler>();
		CharacterData component2 = component.GetComponent<CharacterData>();
		if (!component2 || component2.view.IsMine)
		{
			if ((bool)component)
			{
				component.CallTakeForce(vector * force, ForceMode2D.Impulse, forceIgnoreMass: false, ignoreBlock, setFlyingFor);
			}
			componentInParent.CallTakeDamage(damage * vector, base.transform.position, null, (spawned != null) ? spawned.spawner : null);
			if (soundPlaySawDamage)
			{
				SoundManager.Instance.PlayAtPosition(soundSawDamage, SoundManager.Instance.GetTransform(), base.transform);
			}
			if ((bool)dmgPart)
			{
				Vector3 forward = vector;
				vector.z = 0f;
				dmgPart.transform.parent.rotation = Quaternion.LookRotation(forward);
				dmgPart.Play();
			}
			if (shake != 0f)
			{
				component2.player.Call_AllGameFeel(shake * (Vector2)vector);
			}
		}
	}
}