-
Notifications
You must be signed in to change notification settings - Fork 4
/
beam.lua
234 lines (175 loc) · 7.5 KB
/
beam.lua
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
function POWERSUIT:GetMuzzlePos()
local muzzle = self.MuzzleOffset;
local owner = self:GetOwner();
local aimVector = owner:GetAimVector();
local aimAngle = aimVector:Angle();
local up = aimAngle:Up();
local right = aimAngle:Right();
local forward = aimAngle:Forward();
local pos = owner:GetShootPos() - (up * muzzle[3]) + (right * muzzle[2]) + (forward * muzzle[1]);
return WGL.ToViewModelProjection(pos, 62, 75, false, owner, true), owner, aimVector;
end
function POWERSUIT:CanAttack()
return !self:UndoVisor(IN_ATTACK) && self.ArmCannon:CanBeamChange() && self.MorphBall:CanMorph();
end
function POWERSUIT:CanQuickCharge(beamData)
return math.Round(self:GetNextPrimaryFire() - self.ArmCannon:GetChargeStartTime(), 2) > beamData.BeamDelay + self.ArmCannon.Constants.Charge.Epsilon;
end
function POWERSUIT:Reload()
local visorData = self:GetVisor();
if (self:CanRequestComponent(false) && self.ArmCannon:CanBeamFidget() && !visorData.ShouldHideBeamMenu) then
self.ArmCannon:SetNextBeamFidgetTime(CurTime());
WGL.SendViewModelAnimation(self, self.FidgetAnimations[math.random(1, #self.FidgetAnimations)]);
end
end
function POWERSUIT:MissileDeny()
self:SetNextSecondaryFire(CurTime() + self.ArmCannon.Constants.Missile.Deny);
if (self.ArmCannon:IsMissileReloading()) then WSL.PlaySound(self.Beams, "depleted"); end
end
function POWERSUIT:MissileReload()
self.ArmCannon:SetNextMissileReloadTime(0);
WGL.SendViewModelAnimation(self, ACT_VM_RELOAD);
WSL.PlaySound(self.Beams, "reload");
end
function POWERSUIT:SetNextFire(primary, secondary)
self:SetNextPrimaryFire(CurTime() + (primary || 0));
self:SetNextSecondaryFire(CurTime() + (secondary || 0));
end
function POWERSUIT:ShootProjectile(projectile, aimAssist, autoTarget, fullCharge)
if (SERVER) then return ents.Create(projectile):Shoot(self:GetAimData(aimAssist, autoTarget), math.random(0, 360), nil, fullCharge); end
end
function POWERSUIT:NormalBeam()
local beamData = self:GetBeam();
self:ShootProjectile(beamData.Projectiles["normal"], beamData.AimAssist);
-- Statemachines.
self:SetNextFire(beamData.BeamDelay, self.ArmCannon.Constants.Charge.Delay);
if (SERVER) then self.ArmCannon:StartBeam(); end
-- Animations.
self:GetOwner():SetAnimation(PLAYER_ATTACK1);
WGL.SendViewModelAnimation(self, ACT_VM_PRIMARYATTACK);
WSL.PlaySound(beamData, "fire_normal");
end
function POWERSUIT:StartChargeBeam(beamData)
-- Statemachines.
self.ArmCannon:StartChargeBeam(self:CanQuickCharge(beamData));
-- Animations.
WGL.SendViewModelAnimation(self, ACT_VM_PULLBACK);
WSL.PlaySound(beamData, "charge");
end
function POWERSUIT:ChargeBeamThink()
-- Statemachines.
if (!self.ArmCannon:IsCharging()) then
if (self.ArmCannon:IsMaxCharge()) then self.ArmCannon:SetMaxCharge(false); end
return;
end
-- Raise event.
hook.Run("MP.ChargeBeamThink", self);
if (self.ArmCannon:GetChargeRatio() < 1 || self.ArmCannon:IsMaxCharge()) then return; end
-- Animations.
self.ArmCannon:SetMaxCharge(true);
WGL.SendViewModelAnimation(self, ACT_VM_PULLBACK_LOW);
end
function POWERSUIT:ChargeBeam(beamData)
local full = self:StopChargeBeam(beamData, true);
self:ShootProjectile(beamData.Projectiles["charge"], beamData.AimAssist, nil, full);
-- Statemachines.
self:SetNextFire(beamData.ChargeDelay, beamData.ChargeDelay);
-- Animations.
self:GetOwner():SetAnimation(PLAYER_ATTACK1);
WGL.SendViewModelAnimation(self, ACT_VM_RECOIL1);
WSL.PlaySound(beamData, "fire_charge");
end
function POWERSUIT:StopChargeBeam(beamData, shoot)
-- Statemachines.
local started, full = self.ArmCannon:StopChargeBeam(shoot, beamData.ChargeViewPunch);
if (started) then WGL.SendViewModelAnimation(self, ACT_VM_IDLE); end
-- Animations.
WSL.StopSound(beamData, "charge");
return full;
end
function POWERSUIT:CloseBeam(beamData, silent, quickCharge)
-- Statemachines.
self:SetNextFire(beamData.MissileCloseDelay, beamData.MissileCloseDelay2);
self.ArmCannon:StopBeam(silent, quickCharge, beamData.MissileCloseSound)
-- Animations.
if (silent) then return; end
WGL.SendViewModelAnimation(self, ACT_VM_DETACH_SILENCER);
WSL.PlaySound(self.Beams, "close_muzzle");
end
function POWERSUIT:Missile()
self:ShootProjectile(self.MissileProjectile);
-- Statemachines.
self:SetNextFire(self.ArmCannon.Constants.Beam.Missile, self.ArmCannon.Constants.Missile.Close);
self.ArmCannon:StartMissile();
-- Animations.
self:GetOwner():SetAnimation(PLAYER_ATTACK1);
WGL.SendViewModelAnimation(self, ACT_VM_SECONDARYATTACK);
WSL.PlaySound(self.Beams, "fire_missile");
end
function POWERSUIT:StartMissileCombo()
local beamData = self:GetBeam();
if (!beamData.ComboUnderWater && self.ArmCannon:Waterlogged()) then return; end
if (!self.ArmCannon:CanMissileCombo(beamData.ComboCost)) then return; end
-- Statemachines.
self.ArmCannon:StartMissileCombo(CurTime());
-- Animations.
WSL.StopSound(beamData, "charge");
WSL.PlaySound(self.Beams, "combo");
end
function POWERSUIT:MissileCombo(beamData)
local autoTarget = beamData.ComboAutoTarget;
local projectile = self:ShootProjectile(beamData.Projectiles["combo"], autoTarget, autoTarget);
self:SetMissileCombo(projectile);
-- Statemachines.
self:StopChargeBeam(beamData);
self.ArmCannon:StartMissileCombo(0, beamData.ComboCost, beamData.ComboReset, beamData.ComboViewPunch);
-- Animations.
self:GetOwner():SetAnimation(PLAYER_ATTACK1);
WGL.SendViewModelAnimation(self, ACT_VM_RECOIL3);
WSL.PlaySound(beamData, "fire_combo");
end
function POWERSUIT:MissileComboLoop(beamData)
if (self.ArmCannon:GetMissileAmmo() <= 0) then return self:CloseMissileCombo(beamData); end
-- Statemachines.
self.ArmCannon:MissileComboDrain();
if (self.ArmCannon:MissileComboLooping() || CurTime() <= self.ArmCannon:GetNextMissileComboResetTime() + beamData.ComboLoopDelay) then return; end
self.ArmCannon:SetMissileComboLooping(true);
-- Animations.
WGL.SendViewModelAnimation(self, ACT_VM_PULLBACK_HIGH);
end
function POWERSUIT:CloseMissileCombo(beamData)
-- Statemachines.
self:SetNextFire(beamData.ComboDelay, beamData.ComboDelay);
self.ArmCannon:StopMissileCombo();
-- Animations.
WGL.SendViewModelAnimation(self, ACT_VM_RECOIL2);
if (beamData.ComboLoopDelay != nil) then
local beamCombo = self:GetMissileCombo();
if (IsValid(beamCombo)) then beamCombo:Destroy(true); end
WSL.StopSound(beamData, "fire_combo");
end
end
function POWERSUIT:BeamThink(beamData)
if (self.ArmCannon:ShouldViewPunchReset()) then self.ArmCannon:SetViewPunch(0); end
if (self.ArmCannon:StartBeamOpen()) then WSL.PlaySound(beamData, "open"); end
if (self.ArmCannon:StartBeamClose()) then WSL.PlaySound(self.Beams, "close_missile"); end
if (self.ArmCannon:StartBeamOpenAnim()) then WGL.SendViewModelAnimation(self, ACT_VM_IDLE_LOWERED); end
end
function POWERSUIT:MuzzleCallback(networkVar, effectKey)
self.MuzzleEffects = self.MuzzleEffects || {};
self:NetworkVarNotify(networkVar, function(ent, name, old, new)
if (!IsValid(ent)) then return; end
local owner = ent:GetOwner();
if (!IsValid(owner) || owner != LocalPlayer()) then return; end
local viewModel = owner:GetViewModel();
if (!IsValid(viewModel)) then return; end
local beamData = ent:GetBeam();
if (beamData && new > 0 && beamData[effectKey] && !IsValid(ent.MuzzleEffects[effectKey])) then
ent.MuzzleEffects[effectKey] = CreateParticleSystem(viewModel, beamData[effectKey], PATTACH_POINT_FOLLOW, 1);
end
if (new <= 0 && IsValid(ent.MuzzleEffects[effectKey])) then
ent.MuzzleEffects[effectKey]:StopEmissionAndDestroyImmediately();
ent.MuzzleEffects[effectKey] = nil;
end
end);
end