public static bool Prefix([NotNull] EntityZombie __instance) { if (!PersistentData.Instance.PatchCorpseItemDupeExploit) { Log.Debug($"Skipping disabled patch prefix for {nameof(CorpseDupe)}."); return(true); } Log.Debug($"Executing patch prefix for {nameof(CorpseDupe)} ..."); if (__instance.lootContainer != null && __instance.lootContainer.bTouched && !__instance.lootContainer.IsEmpty()) { __instance.lootContainer.SetEmpty(); // EntityAlive.entityThatKilledMe and EntityAlive.GetRevengeTarget() are always null, but this isn't: var sourceEntityId = __instance.GetDamageResponse().Source?.getEntityId() ?? -1; //var sourceEntity = GameManager.Instance.World?.GetEntity(sourceEntityId); var sourceClientInfo = ConnectionManager.Instance?.GetClientInfoForEntityId(sourceEntityId); var pos = __instance.GetPosition().ToVector3i(); Log.Out($"Cleared touched zombie corpse at {pos} killed by '{sourceClientInfo?.playerName ?? "[unknown]"}'."); } return(true); }
bool UpdateActiveZombie(ZombieAgent zombie) { var world = GameManager.Instance.World; int maxPerZone = MaxZombiesPerZone(); bool removeZombie = false; var worldTime = world.GetWorldTime(); var timeAlive = worldTime - zombie.lifeTime; var currentZone = zombie.currentZone as PlayerZone; if (currentZone != null) { currentZone.numZombies--; if (currentZone.numZombies < 0) { currentZone.numZombies = 0; } } zombie.currentZone = null; Vector3 oldPos = new Vector3 { x = zombie.pos.x, y = zombie.pos.y, z = zombie.pos.z }; EntityZombie ent = world.GetEntity(zombie.entityId) as EntityZombie; if (ent == null) { #if DEBUG Log.Out("[WalkerSim] Failed to get zombie with entity id {0}", zombie.entityId); #endif removeZombie = true; RespawnInactiveZombie(zombie); } else { zombie.pos = ent.GetPosition(); zombie.health = ((EntityZombie)ent).Health; zombie.dir = -ent.rotation; if (ent.IsDead()) { removeZombie = true; RespawnInactiveZombie(zombie); } else { List <PlayerZone> zones = _playerZones.FindAllByPos2D(ent.GetPosition()); if (zones.Count == 0 && timeAlive >= MinZombieLifeTime) { #if DEBUG Log.Out("[WalkerSim] Zombie {0} out of range, turning inactive", ent); #endif removeZombie = true; world.RemoveEntity(zombie.entityId, EnumRemoveEntityReason.Despawned); zombie.entityId = -1; zombie.currentZone = null; TurnZombieInactive(zombie); } else { foreach (var zone in zones) { if (zone.numZombies + 1 < maxPerZone) { zone.numZombies++; zombie.currentZone = zone; // If the zombie is inside a player zone make sure we renew the life time. zombie.lifeTime = worldTime; break; } } } } } return(removeZombie); }
private void UpdateActiveZombies() { var world = GameManager.Instance.World; int maxPerZone = MaxZombiesPerZone(); int deactivatedZombies = 0; for (int i = 0; i < _activeZombies.Count; i++) { bool removeZombie = false; var zombie = _activeZombies[i]; var currentZone = zombie.currentZone as PlayerZone; if (currentZone != null) { currentZone.numZombies--; if (currentZone.numZombies < 0) { currentZone.numZombies = 0; } } Vector3 oldPos = new Vector3 { x = zombie.pos.x, y = zombie.pos.y, z = zombie.pos.z }; EntityZombie ent = world.GetEntity(zombie.entityId) as EntityZombie; if (ent == null) { #if DEBUG Log.Out("[WalkerSim] Failed to get zombie with entity id {0}", zombie.entityId); #endif removeZombie = true; RespawnInactiveZombie(zombie); } else { zombie.pos = ent.GetPosition(); zombie.health = ((EntityZombie)ent).Health; zombie.dir = -ent.rotation; if (ent.IsDead()) { deactivatedZombies++; removeZombie = true; RespawnInactiveZombie(zombie); } else { List <PlayerZone> zones = _playerZones.FindAllByPos2D(ent.GetPosition()); if (zones.Count == 0) { #if DEBUG Log.Out("[WalkerSim] Zombie {0} out of range, turning inactive", ent); #endif deactivatedZombies++; removeZombie = true; world.RemoveEntity(zombie.entityId, EnumRemoveEntityReason.Despawned); lock (_lock) { zombie.entityId = -1; zombie.currentZone = null; _inactiveZombies.Add(zombie); } } else { zombie.currentZone = null; foreach (var zone in zones) { if (zone.numZombies + 1 < maxPerZone) { zone.numZombies++; zombie.currentZone = zone; break; } } if (zombie.currentZone == null) { #if DEBUG Log.Out("Unable to assign zone for Zombie {0}, all zones full", ent); #endif } } } } if (removeZombie) { lock (_lock) { _activeZombies.RemoveAt(i); if (_activeZombies.Count == 0) { break; } } i--; } } }