/
CustomMission.cs
380 lines (342 loc) · 14.9 KB
/
CustomMission.cs
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using GTA;
using GTA.Math;
using GTA.Native;
using NativeUI;
namespace NOOSE
{
public enum Gamemodes
{
TargetElimination,
BombDefusal,
}
public class CustomMission
{
public List<Enemy> BadGuys { get; set; }
public List<Entity> CleanupBag { get; set; }
public bool EntryComplete { get; set; }
public string MissionName { get; private set; }
public string MissionDescription { get; private set; }
private readonly List<Tuple<Vector3, float>> _positions;
public Vector3[] EntryPoints { get; private set; }
public string[] EntryNames { get; private set; }
public Vector3 CameraPosition { get; private set; }
public Gamemodes Gamemode { get; set; }
public int BombTime;
public Tuple<Vector3, float> CurrentBomb;
public List<Gamemodes> AvailableGamemodes = new List<Gamemodes>();
public Polygon GameArea;
//
private readonly Dictionary<string, bool> _requiredIpLs;
private readonly List<DecorativeVehicle> _decorativeVehicles;
private readonly List<EntryPoint> _entryData;
private readonly List<Tuple<Vector3, float>> _bombLocations;
private int _maxEnemies;
public CustomMission(string name, Vector3 cameraPos, List<EntryPoint> entries, List<Tuple<Vector3, float>> enemyPositions, int maxEnemies, List<DecorativeVehicle> decorativeVehicles, List<Tuple<Vector3, float>> bombLocations, int bombTime, string description = "", Dictionary<string, bool> requiredIpl = null, Polygon gamearea = null)
{
BadGuys = new List<Enemy>();
CleanupBag = new List<Entity>();
_bombLocations = new List<Tuple<Vector3, float>>(bombLocations);
MissionName = name;
MissionDescription = description;
CameraPosition = cameraPos;
_maxEnemies = maxEnemies;
BombTime = bombTime;
GameArea = gamearea;
EntryPoints = new Vector3[entries.Count];
EntryNames = new string[entries.Count];
for (int i = 0; i < entries.Count; i++)
{
if(entries[i].Type == EntryTypes.Rappel)
EntryPoints[i] = new Vector3(entries[i].Position.X, entries[i].Position.Y, 5f);
else
EntryPoints[i] = entries[i].Position;
EntryNames[i] = entries[i].Name;
}
_entryData = new List<EntryPoint>(entries);
_positions = new List<Tuple<Vector3, float>>(enemyPositions);
_requiredIpLs = requiredIpl != null
? new Dictionary<string, bool>(requiredIpl)
: new Dictionary<string, bool>();
_decorativeVehicles = new List<DecorativeVehicle>(decorativeVehicles);
AvailableGamemodes.Add(Gamemodes.TargetElimination);
if(bombLocations.Count > 0)
AvailableGamemodes.Add(Gamemodes.BombDefusal);
EntryComplete = false;
}
public void OnStartMission(Gamemodes gamemode)
{
Gamemode = gamemode;
LoadIPL();
foreach (var veh in _decorativeVehicles.Where(x => x.EntryPoint == -1))
{
var tmpMod = new Model(veh.Model);
int counter = 0;
do
{
tmpMod.Request();
counter++;
Script.Yield();
} while (!tmpMod.IsLoaded && counter < 10000);
if(counter >= 10000) continue;
Vehicle tmpVeh = new Vehicle(Function.Call<int>(Hash.CREATE_VEHICLE, tmpMod.Hash, veh.Position.X, veh.Position.Y,veh.Position.Z, veh.Heading, false, false));
tmpVeh.SirenActive = veh.SirenActive;
foreach (VehicleDoor door in veh.OpenDoors)
{
tmpVeh.OpenDoor(door, false, false);
}
CleanupBag.Add(tmpVeh);
}
var tmpposs = new List<Tuple<Vector3, float>>(_positions);
var tmpMax = _maxEnemies;
if (_maxEnemies == -1) tmpMax = Enemy.Dice.Next(_positions.Count/2, _positions.Count);
MaxEnemies = tmpMax;
for(int i = 0; i < tmpMax; i++)
{
Enemy tmp;
int ourPick = Enemy.Dice.Next(tmpposs.Count);
Tuple<Vector3, float> ourTuple = tmpposs[ourPick];
tmp = new Enemy(ourTuple.Item1, ourTuple.Item2);
tmpposs.RemoveAt(ourPick);
tmp.Character.Task.GuardCurrentPosition();
BadGuys.Add(tmp);
CleanupBag.Add(tmp.Character);
}
if (Gamemode == Gamemodes.BombDefusal)
{
BombDefused = false;
_defusePercentage = 0;
_defuseStart = null;
IsDefusingBomb = false;
var ourPick = _bombLocations[Enemy.Dice.Next(_bombLocations.Count)];
CurrentBomb = new Tuple<Vector3, float>(ourPick.Item1, ourPick.Item2);
int counter = 0;
var barrelM = new Model(1298403575);
do
{
barrelM.Request();
counter++;
Script.Yield();
} while (!barrelM.IsLoaded && counter < 2000);
var barrel = World.CreateProp(barrelM, CurrentBomb.Item1 - new Vector3(0f, 0f, 1f), new Vector3(0f, 0f, CurrentBomb.Item2), false, false);
barrel.FreezePosition = true;
counter = 0;
var bombM = new Model(929047740);
do
{
bombM.Request();
counter++;
Script.Yield();
} while (!bombM.IsLoaded && counter < 2000);
var bomb = World.CreateProp(bombM, CurrentBomb.Item1 - new Vector3(0f, 0f, 0.2f), new Vector3(-90f, 0f, CurrentBomb.Item2), false, false);
bomb.FreezePosition = true;
CleanupBag.Add(barrel);
CleanupBag.Add(bomb);
}
}
public int MaxEnemies { get; private set; }
public void OnEndMission()
{
foreach (var badGuy in CleanupBag)
{
(badGuy as Ped)?.CurrentBlip?.Remove();
badGuy?.Delete();
}
CleanupBag.Clear();
foreach (var entry in _rappelUpdates)
{
entry?.Clean();
}
foreach (var rappelEntry in _rappelStarted)
{
rappelEntry?.Clean();
}
_planeEntry?.Clean();
UnloadIPL();
}
public void MissionTick()
{
_planeEntry?.Tick();
for (int i = _rappelUpdates.Count - 1; i >= 0; i--)
{
if (!_rappelUpdates[i].EntryInProgress && !_rappelStarted.Contains(_rappelUpdates[i]))
{
_rappelUpdates[i].Start();
_rappelStarted.Add(_rappelUpdates[i]);
}
if (_rappelUpdates[i].EntryInProgress)
{
_rappelUpdates[i].Tick();
break;
}
if (!_rappelUpdates[i].EntryInProgress && _rappelStarted.Contains(_rappelUpdates[i]))
{
_rappelUpdates.RemoveAt(i);
}
}
if (_rappelStarted.Count == 2 && _rappelStarted.All(f => !f.EntryInProgress) && !EntryComplete)
EntryComplete = true;
if (Gamemode == Gamemodes.BombDefusal && !BombDefused)
{
//SC_START
if (Game.Player.Character.IsInRangeOf(CurrentBomb.Item1, 1.2f))
{
if (!IsDefusingBomb)
{
Function.Call(Hash.REQUEST_ADDITIONAL_TEXT, "global", 0);
Function.Call(Hash.DISPLAY_HELP_TEXT_THIS_FRAME, "SC_START");
}
if (!IsDefusingBomb && Game.IsControlJustPressed(0, Control.Context))
{
Game.Player.Character.FreezePosition = true;
IsDefusingBomb = true;
var angle = Math.Atan2(CurrentBomb.Item1.Y - Game.Player.Character.Position.Y,
CurrentBomb.Item1.X - Game.Player.Character.Position.X);
angle = angle*(180/Math.PI);
angle -= 90;
if (angle < 0)
angle = 360 - (-angle);
Game.Player.Character.Heading = (float)angle;
Game.Player.Character.Weapons.Select(Game.Player.Character.Weapons[(WeaponHash) 0xA2719263]);
Game.Player.Character.Task.PlayAnimation("missah_2_ext_altleadinout", "hack_loop", 8f, -1, true, 8f);
_defuseStart = Noose.SecondCount;
_defusePercentage = 0;
}
if (IsDefusingBomb &&
(Game.IsControlJustPressed(0, Control.PhoneCancel) ||
Game.IsControlJustPressed(0, Control.FrontendPauseAlternate)) && !Noose.IsSquadmenuOpen)
{
Game.Player.Character.FreezePosition = false;
IsDefusingBomb = false;
Game.Player.Character.Task.ClearAll();
_defuseStart = null;
_defusePercentage = 0;
}
if (IsDefusingBomb && _defuseStart.HasValue)
{
const int bombDefusedConst = 15;
_defusePercentage = Noose.SecondCount - _defuseStart.Value;
if (_defusePercentage > bombDefusedConst)
{
IsDefusingBomb = false;
BombDefused = true;
Game.Player.Character.FreezePosition = false;
Game.Player.Character.Task.ClearAll();
return;
}
int width = Convert.ToInt32((_defusePercentage/(float)bombDefusedConst) * 590);
SizeF res = UIMenu.GetScreenResolutionMantainRatio();
int center = Convert.ToInt32(res.Width/2);
new Sprite("timerbars", "damagebar_128",
new Point(center - 300, Convert.ToInt32(res.Height - 200)), new Size(600, 50), 0f,
Color.FromArgb(200, 200, 200, 0)).Draw();
new Sprite("timerbars", "damagebarfill_128",
new Point(center - 290, Convert.ToInt32(res.Height - 200)), new Size(width, 50), 0f,
Color.FromArgb(200, 200, 200, 0)).Draw();
}
}
}
}
public bool IsDefusingBomb = false;
private int? _defuseStart = null;
private int _defusePercentage = 0;
public bool BombDefused = false;
private readonly List<RappelEntry> _rappelUpdates = new List<RappelEntry>();
private readonly List<RappelEntry> _rappelStarted = new List<RappelEntry>();
private PlaneEntry _planeEntry;
public void StartEntry(int entryPoint, Ped[] team)
{
var entry = _entryData[entryPoint];
switch (entry.Type)
{
case EntryTypes.Teleport:
foreach (var ped in team)
{
ped.Position = entry.Position;
ped.Heading = entry.Heading;
}
break;
case EntryTypes.Rappel:
if (team.Length == 1)
{
var rappel = new RappelEntry(entry.Helipads[0], entry.Position);
rappel.AddPassenger(team[0]);
_rappelUpdates.Add(rappel);
}
else
{
var rappel = new RappelEntry(entry.Helipads[0], entry.Position);
foreach (Ped ped in team)
{
rappel.AddPassenger(ped);
}
_rappelUpdates.Add(rappel);
}
break;
case EntryTypes.Plane:
_planeEntry = new PlaneEntry(entry.PlaneSpawn, entry.PlaneSpawnHeading, entry.Approach, entry.RunwayStart, entry.RunwayEnd);
foreach (Ped ped in team)
{
_planeEntry.AddPassenger(ped);
}
_planeEntry.Start();
break;
}
foreach (var source in _decorativeVehicles.Where(x => x.EntryPoint == entryPoint))
{
var tmpMod = new Model(source.Model);
int counter = 0;
do
{
tmpMod.Request();
Script.Yield();
counter++;
} while (!tmpMod.IsLoaded && counter < 10000);
var tmpVeh = Function.Call<Vehicle>(Hash.CREATE_VEHICLE, tmpMod.Hash, source.Position.X, source.Position.Y, source.Position.Z,source.Heading, false, false);
tmpVeh.SirenActive = source.SirenActive;
foreach (VehicleDoor door in source.OpenDoors)
{
tmpVeh.OpenDoor(door, false, false);
}
CleanupBag.Add(tmpVeh);
}
}
public void DrawBriefingMap()
{
LoadIPL();
if (!String.IsNullOrWhiteSpace(MissionDescription))
UI.ShowSubtitle(MissionDescription + "\nChoose an entry point.", 10);
}
public void LoadIPL()
{
foreach (var l in _requiredIpLs)
{
if (l.Value)
{
if (Function.Call<bool>(Hash.IS_IPL_ACTIVE, l.Key))
Function.Call(Hash.REMOVE_IPL, l.Key);
}
else
Function.Call(Hash.REQUEST_IPL, l.Key);
}
}
public void UnloadIPL()
{
foreach (var l in _requiredIpLs)
{
if (!l.Value)
{
if (Function.Call<bool>(Hash.IS_IPL_ACTIVE, l.Key))
Function.Call(Hash.REMOVE_IPL, l.Key);
}
else
Function.Call(Hash.REQUEST_IPL, l.Key);
}
//Function.Call((Hash)0xD7C10C4A637992C9);
}
}
}