Skip to content

Commit 66f45c7

Browse files
Remove IServer::RemoveEntity, Update mock module
1 parent 9c04b3b commit 66f45c7

File tree

12 files changed

+40
-74
lines changed

12 files changed

+40
-74
lines changed

api/AltV.Net.Mock/MockAltV.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public IPlayer ConnectPlayer(string playerName, string reason, Action<IPlayer> i
4242
Alt.Module.PlayerPool.Create(ptr, MockEntities.Id, out var player);
4343
player.Name = playerName;
4444
intercept?.Invoke(player);
45-
MockEntities.Insert(player);
4645
Alt.Module.OnPlayerConnect(ptr, player.Id, reason);
4746
return player;
4847
}

api/AltV.Net.Mock/MockBlip.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public MockBlip(IntPtr nativePointer) : base(nativePointer, BaseObjectType.Blip)
2020

2121
public void Remove()
2222
{
23-
throw new NotImplementedException();
23+
Alt.Server.RemoveBlip(this);
2424
}
2525
}
2626
}

api/AltV.Net.Mock/MockCheckpoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ bool ICheckpoint.IsVehicleIn(IVehicle vehicle)
2929

3030
public void Remove()
3131
{
32-
throw new NotImplementedException();
32+
Alt.Server.RemoveCheckpoint(this);
3333
}
3434
}
3535
}

api/AltV.Net.Mock/MockEntities.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,11 @@ public class MockEntities
1010

1111
public static ushort Id = 0;
1212

13-
public static readonly Dictionary<IntPtr, IBaseObject> Entities = new Dictionary<IntPtr, IBaseObject>();
14-
1513
public static IntPtr GetNextPtr()
1614
{
1715
Ptr += 1;
1816
Id++;
1917
return Ptr;
2018
}
21-
22-
public static void Insert(IBaseObject entity)
23-
{
24-
Entities[Ptr] = entity;
25-
}
2619
}
2720
}

api/AltV.Net.Mock/MockEntity.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace AltV.Net.Mock
99
{
10-
public class MockEntity : IEntity
10+
public abstract class MockEntity : IEntity
1111
{
1212
public IntPtr NativePointer { get; }
1313
public bool Exists { get; }
@@ -111,13 +111,15 @@ public bool GetSyncedMetaData<T>(string key, out T result)
111111
return true;
112112
}
113113

114-
public void Remove()
115-
{
116-
Alt.Server.RemoveEntity(this);
117-
}
114+
public abstract void Remove();
118115

119116
public void CheckIfEntityExists()
120117
{
118+
if (Exists)
119+
{
120+
return;
121+
}
122+
throw new EntityRemovedException(this);
121123
}
122124
}
123125
}

api/AltV.Net.Mock/MockPlayer.Events.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ public static void Disconnect(this IPlayer player, string reason)
99
{
1010
player.CancelEvents();
1111
Alt.Module.OnPlayerDisconnect(player.NativePointer, reason);
12-
Alt.Server.RemoveEntity(player);
12+
Alt.Module.OnPlayerRemove(player.NativePointer);
13+
Alt.Module.OnRemovePlayer(player.NativePointer);
1314
}
1415

1516
public static void Damage(this IPlayer player, IEntity attacker, uint weapon, byte damage)

api/AltV.Net.Mock/MockPlayer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,10 @@ public ReadOnlyPlayer Copy()
7878
{
7979
return ReadOnlyPlayer.Empty;
8080
}
81+
82+
public override void Remove()
83+
{
84+
throw new NotImplementedException();
85+
}
8186
}
8287
}

api/AltV.Net.Mock/MockServer.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,21 @@ public IVehicle CreateVehicle(uint model, Position pos, Rotation rotation)
186186
var ptr = MockEntities.GetNextPtr();
187187
vehiclePool.Create(ptr, MockEntities.Id, out var vehicle);
188188
vehicle.Position = pos;
189-
//TODO: apis missing for more properties from create
190-
MockEntities.Insert(vehicle);
189+
if (vehicle is MockVehicle mockVehicle)
190+
{
191+
mockVehicle.Position = pos;
192+
mockVehicle.Rotation = rotation;
193+
mockVehicle.Model = model;
194+
}
195+
Alt.Module.OnCreateVehicle(ptr, MockEntities.Id);
191196
return vehicle;
192197
}
193198

194199
public IntPtr CreateVehicleEntity(out ushort id, uint model, Position pos, Rotation rotation)
195200
{
196201
var ptr = MockEntities.GetNextPtr();
197202
id = MockEntities.Id;
203+
Alt.Module.OnCreateVehicle(ptr, id);
198204
return ptr;
199205
}
200206

@@ -211,8 +217,7 @@ public ICheckpoint CreateCheckpoint(IPlayer player, byte type, Position pos, flo
211217
mockCheckpoint.Height = height;
212218
mockCheckpoint.Color = color;
213219
}
214-
215-
MockEntities.Insert(checkpoint);
220+
Alt.Module.OnCreateCheckpoint(ptr);
216221
return checkpoint;
217222
}
218223

@@ -225,8 +230,7 @@ public IBlip CreateBlip(IPlayer player, byte type, Position pos)
225230
mockBlip.Position = pos;
226231
mockBlip.BlipType = type;
227232
}
228-
229-
MockEntities.Insert(blip);
233+
Alt.Module.OnCreateBlip(ptr);
230234
return blip;
231235
}
232236

@@ -240,8 +244,7 @@ public IBlip CreateBlip(IPlayer player, byte type, IEntity entityAttach)
240244
mockBlip.IsAttached = true;
241245
mockBlip.AttachedTo = entityAttach;
242246
}
243-
244-
MockEntities.Insert(blip);
247+
Alt.Module.OnCreateBlip(ptr);
245248
return blip;
246249
}
247250

@@ -254,8 +257,7 @@ public IVoiceChannel CreateVoiceChannel(bool spatial, float maxDistance)
254257
mockVoiceChannel.IsSpatial = spatial;
255258
mockVoiceChannel.MaxDistance = maxDistance;
256259
}
257-
258-
MockEntities.Insert(voiceChannel);
260+
Alt.Module.OnCreateVoiceChannel(ptr);
259261
return voiceChannel;
260262
}
261263

@@ -272,25 +274,22 @@ public void RemoveEntity(IEntity entity)
272274
public void RemoveBlip(IBlip blip)
273275
{
274276
Alt.Module.OnRemoveBlip(blip.NativePointer);
275-
MockEntities.Entities.Remove(blip.NativePointer);
276277
}
277278

278279
public void RemoveCheckpoint(ICheckpoint checkpoint)
279280
{
280-
Alt.Module.OnRemoveCheckpoint(checkpoint.NativePointer);
281-
MockEntities.Entities.Remove(checkpoint.NativePointer);
281+
Alt.Module.OnRemoveCheckpoint(checkpoint.NativePointer);
282282
}
283283

284284
public void RemoveVehicle(IVehicle vehicle)
285285
{
286+
Alt.Module.OnVehicleRemove(vehicle.NativePointer);
286287
Alt.Module.OnRemoveVehicle(vehicle.NativePointer);
287-
MockEntities.Entities.Remove(vehicle.NativePointer);
288288
}
289289

290290
public void RemoveVoiceChannel(IVoiceChannel channel)
291291
{
292292
Alt.Module.OnRemoveVoiceChannel(channel.NativePointer);
293-
MockEntities.Entities.Remove(channel.NativePointer);
294293
}
295294

296295
public ServerNativeResource GetResource(string name)

api/AltV.Net.Mock/MockVehicle.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class MockVehicle: MockEntity, IVehicle
1010
public MockVehicle(IntPtr nativePointer, ushort id): base(nativePointer, BaseObjectType.Vehicle, id)
1111
{
1212
}
13+
14+
1315

1416
public IPlayer Driver { get; }
1517
public byte ModKit { get; set; }
@@ -229,5 +231,10 @@ public void SetBumperDamageLevel(byte bumperId, byte damageLevel)
229231
}
230232

231233
public string DamageData { get; set; }
234+
235+
public override void Remove()
236+
{
237+
Alt.Server.RemoveVehicle(this);
238+
}
232239
}
233240
}

api/AltV.Net.Mock/MockVoiceChannel.cs

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,10 @@
33

44
namespace AltV.Net.Mock
55
{
6-
public class MockVoiceChannel : IVoiceChannel
6+
public class MockVoiceChannel : MockWorldObject, IVoiceChannel
77
{
8-
public MockVoiceChannel(IntPtr nativePointer)
8+
public MockVoiceChannel(IntPtr nativePointer): base(nativePointer, BaseObjectType.VoiceChannel)
99
{
10-
NativePointer = nativePointer;
11-
}
12-
13-
public IntPtr NativePointer { get; }
14-
public bool Exists { get; }
15-
public BaseObjectType Type { get; }
16-
17-
public void SetMetaData(string key, object value)
18-
{
19-
throw new NotImplementedException();
20-
}
21-
22-
public bool GetMetaData<T>(string key, out T result)
23-
{
24-
throw new NotImplementedException();
25-
}
26-
27-
public void SetData(string key, object value)
28-
{
29-
throw new NotImplementedException();
30-
}
31-
32-
public bool GetData<T>(string key, out T result)
33-
{
34-
throw new NotImplementedException();
3510
}
3611

3712
public void AddPlayer(IPlayer player)
@@ -69,11 +44,7 @@ public bool IsPlayerMuted(IPlayer player)
6944

7045
public void Remove()
7146
{
72-
throw new NotImplementedException();
73-
}
74-
75-
public void CheckIfEntityExists()
76-
{
47+
Alt.Server.RemoveVoiceChannel(this);
7748
}
7849
}
7950
}

0 commit comments

Comments
 (0)