blob: 35be82f19a410e32f2ed53429c6e51be64f6f616 (
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
using System.Collections;
using Sonigon;
using UnityEngine;
public class WeaponHandler : MonoBehaviour
{
[Header("Sounds")]
public SoundEvent soundCharacterCantShoot;
private bool soundFireHold;
[Header("Settings")]
public Gun gun;
private Holding holding;
private GeneralInput input;
private CharacterData data;
private float heatSinceAttack;
private float heat;
public float heatPerBullet = 0.1f;
public float secondsBeforeStartToCool = 0.1f;
public float coolPerSecond = 0.2f;
public float overHeatTime = 1f;
public float resetSpeed = 2f;
public bool isOverHeated;
private bool hasBeenHeated;
public SpriteRenderer heatRenderer;
private Transform overHeatPivot;
public Color overHeatColor;
private Color baseHeatColor;
internal void DoReload()
{
gun.GetComponentInChildren<GunAmmo>().ReloadAmmo();
}
private void Awake()
{
holding = GetComponent<Holding>();
input = GetComponent<GeneralInput>();
data = GetComponent<CharacterData>();
}
private void Start()
{
overHeatPivot = heatRenderer.transform.parent;
baseHeatColor = heatRenderer.color;
}
private void Update()
{
if (!gun.holdable.holder && (bool)data)
{
gun.holdable.holder = data;
}
if (data.playerVel.simulated)
{
gun.attackSpeedMultiplier = data.stats.attackSpeedMultiplier;
heatSinceAttack += TimeHandler.deltaTime;
Attack();
OverHeat();
}
}
private void Attack()
{
if (!gun || !gun.IsReady())
{
return;
}
if (input.shootIsPressed)
{
if (!soundFireHold)
{
soundFireHold = true;
if (gun.isReloading || data.isSilenced)
{
SoundManager.Instance.Play(soundCharacterCantShoot, base.transform);
}
}
}
else
{
soundFireHold = false;
}
if (gun.bursts == 0 && (!soundFireHold || gun.isReloading || data.isSilenced))
{
gun.soundGun.StopAutoPlayTail();
}
if ((!input.shootWasPressed || gun.useCharge) && (!input.shootWasReleased || !gun.useCharge) && (!(gun.attackSpeed / data.stats.attackSpeedMultiplier < 0.3f) || !input.shootIsPressed || gun.useCharge || gun.dontAllowAutoFire))
{
return;
}
if (isOverHeated)
{
heatRenderer.GetComponent<CodeAnimation>().PlayBoop();
gun.sinceAttack = 0f;
return;
}
gun.Attack(0f);
if (heat >= 1f)
{
StartCoroutine(DoOverHeat());
isOverHeated = true;
}
heatSinceAttack = 0f;
}
internal void NewGun()
{
gun.ResetStats();
gun.soundGun.ClearSoundModifiers();
}
private void OverHeat()
{
if (!isOverHeated)
{
if (heatSinceAttack > secondsBeforeStartToCool)
{
heat -= TimeHandler.deltaTime * coolPerSecond;
}
SetOverHeatColor();
}
}
private IEnumerator DoOverHeat()
{
SetOverHeatColor();
yield return new WaitForSeconds(overHeatTime);
while (heat > 0f)
{
heat -= resetSpeed * TimeHandler.deltaTime;
SetOverHeatColor();
yield return null;
}
isOverHeated = false;
}
private void SetOverHeatColor()
{
heat = Mathf.Clamp(heat, 0f, 1f);
heatRenderer.color = Color.Lerp(baseHeatColor, overHeatColor, heat);
if (heat > 0.25f || hasBeenHeated)
{
hasBeenHeated = true;
overHeatPivot.transform.localScale = new Vector3(heat, 1f, 1f);
}
else
{
overHeatPivot.transform.localScale = new Vector3(0f, 1f, 1f);
}
if (heat == 0f)
{
hasBeenHeated = false;
}
}
}
|