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

public class RayHitDrill : RayHitEffect
{
	public float metersOfDrilling = 1f;

	private MoveTransform move;

	private ProjectileHit proj;

	public bool mainDrill;

	private ChildRPC rpc;

	private int sinceDrill = 10;

	public float speedModFlat = 0.5f;

	public float speedMod = 0.1f;

	private bool done;

	private void Start()
	{
		move = GetComponentInParent<MoveTransform>();
		proj = GetComponentInParent<ProjectileHit>();
		proj.canPushBox = false;
		RayHitDrill[] componentsInChildren = base.transform.root.GetComponentsInChildren<RayHitDrill>();
		if (componentsInChildren.Length == 1)
		{
			mainDrill = true;
		}
		bool flag = false;
		int num = -1;
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			if (componentsInChildren[i].mainDrill)
			{
				flag = true;
				num = i;
			}
		}
		if (flag)
		{
			if (componentsInChildren[num] != this)
			{
				componentsInChildren[num].metersOfDrilling += metersOfDrilling;
			}
		}
		else
		{
			mainDrill = true;
		}
		if (mainDrill)
		{
			rpc = GetComponentInParent<ChildRPC>();
			rpc.childRPCsVector2.Add("DrillStop", RPCA_Deactivate);
		}
	}

	private void Update()
	{
		if (mainDrill && proj.view.IsMine)
		{
			if (sinceDrill > 2 && !proj.isAllowedToSpawnObjects)
			{
				rpc.CallFunction("DrillStop", base.transform.position);
			}
			sinceDrill++;
		}
	}

	public void RPCA_Deactivate(Vector2 tpPos)
	{
		base.transform.position = tpPos;
		proj.isAllowedToSpawnObjects = true;
		move.simulationSpeed /= speedModFlat;
		move.simulationSpeed *= move.localForce.magnitude * speedMod;
		proj.sendCollisions = true;
		base.transform.GetChild(0).gameObject.SetActive(value: false);
		if (metersOfDrilling < 2f)
		{
			metersOfDrilling = -1f;
		}
	}

	private void OnDestroy()
	{
		if (mainDrill && !proj.isAllowedToSpawnObjects)
		{
			Object.Instantiate(GetComponentInChildren<ParticleSystem>(includeInactive: true).gameObject, base.transform.position, base.transform.rotation).SetActive(value: true);
		}
	}

	public override HasToReturn DoHitEffect(HitInfo hit)
	{
		if (!mainDrill)
		{
			return HasToReturn.canContinue;
		}
		if (proj.isAllowedToSpawnObjects)
		{
			base.transform.root.position = hit.point;
			move.simulationSpeed *= speedModFlat;
			move.simulationSpeed /= move.localForce.magnitude * speedMod;
			base.transform.GetChild(0).gameObject.SetActive(value: true);
			base.transform.GetComponentInChildren<TrailRenderer>().Clear();
		}
		sinceDrill = 0;
		proj.isAllowedToSpawnObjects = false;
		proj.sendCollisions = false;
		metersOfDrilling -= move.velocity.magnitude * TimeHandler.deltaTime * move.simulationSpeed;
		if (metersOfDrilling <= 0f)
		{
			done = true;
			return HasToReturn.canContinue;
		}
		if (!hit.transform || (bool)hit.transform.root.GetComponent<Player>())
		{
			return HasToReturn.canContinue;
		}
		return HasToReturn.hasToReturnNow;
	}
}