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

public class Destructible : Damagable
{
	public float threshold = 25f;

	public float force = 1f;

	public float rangeMulti = 1f;

	public override void CallTakeDamage(Vector2 damage, Vector2 damagePosition, GameObject damagingWeapon = null, Player damagingPlayer = null, bool lethal = true)
	{
		throw new NotImplementedException();
	}

	public override void TakeDamage(Vector2 damage, Vector2 position, GameObject damagingWeapon = null, Player damagingPlayer = null, bool lethal = true, bool ignoreBlock = false)
	{
		if (!(damage.magnitude < threshold))
		{
			damage = damage.normalized * 100f;
			Transform[] array = new Transform[base.transform.childCount];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = base.transform.GetChild(i);
			}
			foreach (Transform transform in array)
			{
				transform.gameObject.SetActive(value: true);
				transform.SetParent(null, worldPositionStays: true);
				float num = damage.magnitude * 0.02f * rangeMulti;
				float num2 = Mathf.Clamp((num - Vector2.Distance(transform.position, position)) / num, 0f, 1f);
				Rigidbody2D component = transform.GetComponent<Rigidbody2D>();
				component.AddForce(damage * num2 * force * 0.1f * component.mass, ForceMode2D.Impulse);
				transform.gameObject.AddComponent<RemoveAfterSeconds>().seconds = UnityEngine.Random.Range(1f, 3f);
			}
			base.gameObject.SetActive(value: false);
		}
	}

	public override void TakeDamage(Vector2 damage, Vector2 damagePosition, Color dmgColor, GameObject damagingWeapon = null, Player damagingPlayer = null, bool lethal = true, bool ignoreBlock = false)
	{
		TakeDamage(damage, damagePosition, dmgColor, damagingWeapon, damagingPlayer, lethal);
	}
}