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
146
147
148
149
|
using Sonigon;
using UnityEngine;
public class OutOfBoundsHandler : MonoBehaviour
{
private bool outOfBounds;
private bool almostOutOfBounds;
private Camera mainCam;
private CharacterData data;
public ParticleSystem wall;
public ParticleSystem burst;
public ParticleSystem burstBig;
public ParticleSystem warning;
public ParticleSystem shieldWall;
public ParticleSystem shieldBurst;
public ParticleSystem shieldBurstBig;
private ChildRPC rpc;
private float counter;
private float warningPercentage = 0.1f;
private void Start()
{
base.transform.position = Vector3.up * 200f;
data = base.transform.root.GetComponent<CharacterData>();
rpc = data.GetComponent<ChildRPC>();
rpc.childRPCs.Add("OutOfBounds", RPCA_DisplayOutOfBounds);
rpc.childRPCs.Add("ShieldOutOfBounds", RPCA_DisplayOutOfBoundsShield);
mainCam = MainCam.instance.transform.GetComponent<Camera>();
base.transform.SetParent(null);
}
private void LateUpdate()
{
if (!data)
{
Object.Destroy(base.gameObject);
}
else
{
if (!data.playerVel.simulated || !data.isPlaying)
{
return;
}
float x = Mathf.InverseLerp(-35.56f, 35.56f, data.transform.position.x);
float y = Mathf.InverseLerp(-20f, 20f, data.transform.position.y);
Vector3 vector = new Vector3(x, y, 0f);
vector = new Vector3(Mathf.Clamp(vector.x, 0f, 1f), Mathf.Clamp(vector.y, 0f, 1f), vector.z);
almostOutOfBounds = false;
outOfBounds = false;
if (vector.x <= 0f || vector.x >= 1f || vector.y >= 1f || vector.y <= 0f)
{
outOfBounds = true;
}
else if (vector.x < warningPercentage || vector.x > 1f - warningPercentage || vector.y > 1f - warningPercentage || vector.y < warningPercentage)
{
almostOutOfBounds = true;
if (vector.x < warningPercentage)
{
vector.x = 0f;
}
if (vector.x > 1f - warningPercentage)
{
vector.x = 1f;
}
if (vector.y < warningPercentage)
{
vector.y = 0f;
}
if (vector.y > 1f - warningPercentage)
{
vector.y = 1f;
}
}
counter += TimeHandler.deltaTime;
if (almostOutOfBounds && !data.dead)
{
base.transform.position = GetPoint(vector);
base.transform.rotation = Quaternion.LookRotation(Vector3.forward, -(data.transform.position - base.transform.position));
if (counter > 0.1f)
{
counter = 0f;
warning.Play();
}
}
if (!outOfBounds || data.dead)
{
return;
}
data.sinceGrounded = 0f;
base.transform.position = GetPoint(vector);
base.transform.rotation = Quaternion.LookRotation(Vector3.forward, -(data.transform.position - base.transform.position));
if (counter > 0.1f && data.view.IsMine)
{
counter = 0f;
if (data.block.IsBlocking())
{
rpc.CallFunction("ShieldOutOfBounds");
data.playerVel.velocity *= 0f;
data.healthHandler.CallTakeForce(base.transform.up * 400f * data.playerVel.mass, ForceMode2D.Impulse, forceIgnoreMass: false, ignoreBlock: true);
data.transform.position = base.transform.position;
}
else
{
rpc.CallFunction("OutOfBounds");
data.healthHandler.CallTakeForce(base.transform.up * 200f * data.playerVel.mass, ForceMode2D.Impulse, forceIgnoreMass: false, ignoreBlock: true);
data.healthHandler.CallTakeDamage(51f * base.transform.up, data.transform.position);
}
}
}
}
private Vector3 GetPoint(Vector3 p)
{
float x = Mathf.Lerp(-35.56f, 35.56f, p.x);
float y = Mathf.Lerp(-20f, 20f, p.y);
return new Vector3(x, y, 0f);
}
private void RPCA_DisplayOutOfBounds()
{
SoundManager.Instance.Play(data.playerSounds.soundCharacterDamageScreenEdge, data.transform);
burst.Play();
wall.Play();
burstBig.Play();
data.sinceGrounded = 0f;
}
private void RPCA_DisplayOutOfBoundsShield()
{
SoundManager.Instance.Play(data.playerSounds.soundCharacterDamageScreenEdge, data.transform);
shieldBurst.Play();
shieldWall.Play();
shieldBurstBig.Play();
data.sinceGrounded = 0f;
}
}
|