41 lines
1.8 KiB
C#
41 lines
1.8 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace Harmony.DroneManagerPatches
|
|
{
|
|
[HarmonyPatch(typeof(DroneManager), "RemoveAllDronesFromMap")]
|
|
public class RemoveAllVehiclesFromMapPatch
|
|
{
|
|
public static bool Prefix(DroneManager __instance)
|
|
{
|
|
GameManager instance = GameManager.Instance;
|
|
PersistentPlayerList persistentPlayerList = instance.GetPersistentPlayerList();
|
|
World world = instance.World;
|
|
|
|
foreach (KeyValuePair<PlatformUserIdentifierAbs, PersistentPlayerData> player in persistentPlayerList.Players)
|
|
{
|
|
EntityPlayer entity = world.GetEntity(player.Value.EntityId) as EntityPlayer;
|
|
|
|
if (entity != null)
|
|
{
|
|
OwnedEntityData[] ownedEntities = entity.GetOwnedEntities();
|
|
//Log.Out("DroneManagerPatches-RemoveAllVehiclesFromMap ownedEntities.Length: " + ownedEntities.Length);
|
|
|
|
for (int i = 0; i < ownedEntities.Length; ++i)
|
|
{
|
|
//Log.Out("DroneManagerPatches-RemoveAllVehiclesFromMap ___dronesActive.Count: " + ___dronesActive.Count);
|
|
EntityDrone entityDrone = __instance.dronesActive.Find(v => v.entityId == ownedEntities[i].Id);
|
|
|
|
if (entityDrone != null && entity.HasOwnedEntity(entityDrone.entityId))
|
|
{
|
|
//Log.Out("DroneManagerPatches-RemoveAllVehiclesFromMap entityDrone.entityId: " + entityDrone.entityId);
|
|
GameManager.Instance.World.RemoveEntityFromMap(entityDrone, EnumRemoveEntityReason.Unloaded);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|