public static SerializableVehicle Create(InteractableVehicle vehicle) { var result = new SerializableVehicle(); result.Health = vehicle.health; result.Fuel = vehicle.fuel; result.BatteryCharge = vehicle.batteryCharge; result.VehicleId = vehicle.id; result.TrunkSpace = vehicle.trunkItems?.items?.Select(c => SerializableItem.CreateSerializableItem(vehicle.trunkItems.page, c))?.ToList() ?? new List <SerializableItem>(); result.Tires = vehicle.tires?.Select(c => c.isAlive)?.ToArray() ?? new bool[0]; if (BarricadeManager.tryGetPlant(vehicle.transform, out byte x, out byte y, out ushort plant, out var region)) { foreach (var data in region.barricades) { if (data.barricade.isDead) { continue; } var drop = region.drops.FirstOrDefault(c => c.instanceID == data.instanceID); var barricade = SerializableBarricade.Create(drop, data); result.Barricades.Add(barricade); } } return(result); }
public void VehicleElementDrop(InteractableVehicle vehicle, bool shouldDestroy = true, Transform trainCarTransform = null) { if ((vehicle.asset.engine == EEngine.TRAIN && trainCarTransform == null) || vehicle.isDead) { return; } if (BarricadeManager.tryGetPlant(vehicle.asset.engine == EEngine.TRAIN ? trainCarTransform : vehicle.transform, out byte x, out byte y, out ushort plant, out BarricadeRegion vregion)) { for (int i = vregion.drops.Count - 1; i >= 0; i--) { try { Item item = new Item(vregion.barricades[i].barricade.id, true); ItemManager.dropItem(item, vregion.drops[i].model.position, false, true, true); } catch (Exception ex) { // You can get an error, if there's a mismatch in the barricades and drops lists for the region(should rarely ever happen, mostly ever happens when elements are destroyed by a thread outside of the main thread, eg by plugin.). Logger.LogException(ex, "Error in dropping an element off of the vehicle."); } if (shouldDestroy) { try { BarricadeManager.damage(vregion.drops[i].model, ushort.MaxValue, 1, false); } catch (Exception ex) { Logger.LogException(ex, "Error in destroying vehicle barricade."); } } } } }
public void Execute(ICommandContext context) { UnturnedPlayer player = ((UnturnedUser)context.User).Player; int radius = context.Parameters.Get <int> (0); foreach (var vehicle in VehicleManager.vehicles) { if (Vector3.Distance(player.Entity.Position, vehicle.transform.position.ToSystemVector()) > radius) { continue; } int count = 0; BarricadeManager.tryGetPlant(vehicle.transform, out byte _, out byte _, out ushort _, out BarricadeRegion region); count += region.barricades.Count; foreach (var trainCar in vehicle.trainCars) { BarricadeManager.tryGetPlant(trainCar.root, out _, out _, out _, out BarricadeRegion tRegion); count += tRegion.barricades.Count; } context.User.SendLocalizedMessage( _wreckPlugin.Translations, "wreckingball_list_v", vehicle.asset.vehicleName, vehicle.transform.position.ToString(), count); } }
internal static bool HasFlaggedElement(Transform vehicleTransform, out ulong elementSteamID) { elementSteamID = 0; if (BarricadeManager.tryGetPlant(vehicleTransform, out _, out _, out _, out BarricadeRegion barricadeRegion)) { int transformCount = barricadeRegion.drops.Count; int DataCount = barricadeRegion.barricades.Count; BarricadeData bData; bool match = false; if (transformCount == DataCount) { for (int e = 0; e < DataCount; e++) { bData = barricadeRegion.barricades[e]; if (WreckingBall.ElementData.FilterItem(bData.barricade.id, new List <char> { WreckingBall.Instance.Configuration.Instance.VehicleSignFlag })) { match = true; elementSteamID = bData.owner; break; } } if (match) { return(true); } } } return(false); }
public static bool checkForBarricades(InteractableVehicle v, bool ignoreVehiclesWithBarricades) { byte x; byte y; ushort plant; BarricadeRegion region; if (AutoClear.Instance.Configuration.Instance.IgnoreVehiclesWithBarricades) { if (ignoreVehiclesWithBarricades) { if (BarricadeManager.tryGetPlant(v.transform, out x, out y, out plant, out region)) { if (region.drops.Count > 0) { return(true); } } else { } } } return(false); }
// Token: 0x060021B8 RID: 8632 RVA: 0x000B3904 File Offset: 0x000B1D04 private void Start() { if (Level.isEditor) { this.updateWired(true); } else { ushort maxValue = ushort.MaxValue; if (base.isPlant) { byte b; byte b2; BarricadeRegion barricadeRegion; BarricadeManager.tryGetPlant(base.transform.parent, out b, out b2, out maxValue, out barricadeRegion); } List <InteractableGenerator> list = PowerTool.checkGenerators(base.transform.position, 64f, maxValue); for (int i = 0; i < list.Count; i++) { InteractableGenerator interactableGenerator = list[i]; if (interactableGenerator.isPowered && interactableGenerator.fuel > 0 && (interactableGenerator.transform.position - base.transform.position).sqrMagnitude < interactableGenerator.sqrWirerange) { this.updateWired(true); return; } } } }
private static bool BlacklistCheck(UnturnedPlayer player, InteractableVehicle vehicle, out EResponseType responseType, out ushort blacklistedID) { blacklistedID = 0; responseType = EResponseType.SUCCESS; if (Plugin.Conf.BlacklistedVehicles.Any(blacklist => blacklist.Assets.Any(asset => vehicle.id == asset.ID && !player.CheckPermission(blacklist.BypassPermission)))) { responseType = EResponseType.BLACKLIST_VEHICLE; blacklistedID = vehicle.id; return(false); } if (vehicle.trunkItems != null && (vehicle.trunkItems != null || vehicle.trunkItems.items.Count != 0)) { foreach (var item in Plugin.Conf.BlacklistedTrunkItems.SelectMany(blacklist => blacklist.Assets.SelectMany(asset => vehicle.trunkItems.items.Where(item => item.item.id == asset.ID && !player.CheckPermission(blacklist.BypassPermission))))) { responseType = EResponseType.BLACKLIST_TRUNK_ITEM; blacklistedID = item.item.id; return(false); } } if (BarricadeManager.tryGetPlant(vehicle.transform, out _, out _, out _, out var region) && region.barricades != null && region.barricades.Count != 0) { foreach (var asset in Plugin.Conf.BlacklistedBarricades.SelectMany(blacklist => blacklist.Assets.Where(asset => region.drops.Any(drop => drop.asset.id == asset.ID && !player.CheckPermission(blacklist.BypassPermission))))) { responseType = EResponseType.BLACKLIST_BARRICADE; blacklistedID = asset.ID; return(false); } } return(true); }
public static void ClearItems(InteractableVehicle vehicle) { if (!BarricadeManager.tryGetPlant(vehicle.transform, out _, out _, out _, out var region)) { return; } vehicle.trunkItems?.items?.Clear(); region.barricades?.Clear(); region.drops.Clear(); }
internal bool Sell(decimal curBallance, UnturnedPlayer player, RaycastInfo raycastInfo, out decimal totalCost, out short actualCount) { bool sufficientAmount = false; totalCost = 0; actualCount = 0; InteractableVehicle vehicle = null; if (RestrictBuySell == RestrictBuySell.BuyOnly) { actualCount = -1; return(false); } VehicleInfo vInfo = DShop.Instance.Database.GetVehicleInfo((ulong)player.CSteamID, ItemID); if (vInfo == null) { // The car the player's looking at hasn't been bought before from them, from the shop. actualCount = -2; return(false); } else { vehicle = raycastInfo.vehicle; sufficientAmount = true; actualCount = 1; if (DShop.Instance.Configuration.Instance.VehicleSellDropElements) { BarricadeRegion vregion = null; byte x; byte y; ushort plant; if (BarricadeManager.tryGetPlant(vehicle.transform, out x, out y, out plant, out vregion)) { for (int j = 0; j < vregion.drops.Count; j++) { if (j < vregion.drops.Count && vregion.barricades[j].barricade.id > 0) { Item item = new Item(vregion.barricades[j].barricade.id, true); ItemManager.dropItem(item, vregion.drops[j].model.position, false, true, true); } } } } DShop.Instance.Database.DeleteVehicleInfo(vInfo); vehicle.askDamage(ushort.MaxValue, false); totalCost = decimal.Multiply(BuyCost, SellMultiplier); DShop.Instance._OnShopSell(decimal.Add(curBallance, totalCost), player, 1, this, ItemType.Vehicle, BuyCost, totalCost, actualCount, 0); } return(sufficientAmount); }
private void updateWire() { if (this.engine != null) { this.engine.gameObject.SetActive(this.isPowered && this.fuel > 0); } ushort maxValue = ushort.MaxValue; if (base.isPlant) { byte b; byte b2; BarricadeRegion barricadeRegion; BarricadeManager.tryGetPlant(base.transform.parent, out b, out b2, out maxValue, out barricadeRegion); } List <InteractablePower> list = PowerTool.checkPower(base.transform.position, this.wirerange, maxValue); for (int i = 0; i < list.Count; i++) { InteractablePower interactablePower = list[i]; if (interactablePower.isWired) { if (!this.isPowered || this.fuel == 0) { bool flag = false; List <InteractableGenerator> list2 = PowerTool.checkGenerators(interactablePower.transform.position, 64f, maxValue); for (int j = 0; j < list2.Count; j++) { if (list2[j] != this && list2[j].isPowered && list2[j].fuel > 0 && (list2[j].transform.position - interactablePower.transform.position).sqrMagnitude < list2[j].sqrWirerange) { flag = true; break; } } if (!flag) { interactablePower.updateWired(false); } } } else if (this.isPowered && this.fuel > 0) { interactablePower.updateWired(true); } } }
public void Execute(IRocketPlayer caller, string[] command) { var player = (UnturnedPlayer)caller; var raycastInfo = DamageTool.raycast(new Ray(player.Player.look.aim.position, player.Player.look.aim.forward), 10f, RayMasks.VEHICLE); var baseClusteringPlugin = BaseClusteringPlugin.Instance; if (baseClusteringPlugin == null) { throw new NullReferenceException("BaseClusteringPlugin.Instance is null. Cannot execute command."); } if (raycastInfo.vehicle == null) { UnturnedChat.Say(caller, baseClusteringPlugin.Translate("no_vehicle_found")); return; } if (raycastInfo.vehicle.isDead) { UnturnedChat.Say(caller, baseClusteringPlugin.Translate("vehicle_dead")); return; } if (!BarricadeManager.tryGetPlant(raycastInfo.transform, out var x, out var y, out var plant, out var region)) { UnturnedChat.Say(caller, baseClusteringPlugin.Translate("vehicle_no_plant")); return; } for (var i = region.barricades.Count - 1; i > 0; i--) { BarricadeManager.destroyBarricade(region, x, y, plant, (ushort)i); } UnturnedChat.Say(caller, baseClusteringPlugin.Translate("vehicle_wreck", raycastInfo.vehicle.asset.vehicleName ?? raycastInfo.vehicle.asset.name, raycastInfo.vehicle.id, raycastInfo.vehicle.instanceID, raycastInfo.vehicle.lockedOwner.ToString())); }
public static SerializableVehicle Create(InteractableVehicle vehicle) { var vehicleTurret = new List <byte[]>(); if (vehicle.turrets != null && vehicle.turrets?.Length != 0) { byte index = 0; while (index < vehicle.turrets.Length) { vehicleTurret.Add(vehicle.turrets[index].state); index++; } } var result = new SerializableVehicle { Health = vehicle.health, Fuel = vehicle.fuel, BatteryCharge = vehicle.batteryCharge, ID = vehicle.id, TrunkItems = vehicle.trunkItems?.items?.Select(c => SerializableItem.Create(vehicle.trunkItems.page, c)).ToList() ?? new List <SerializableItem>(), Tires = vehicle.tires?.Select(c => c.isAlive)?.ToArray() ?? new bool[0], Turrets = vehicleTurret }; if (BarricadeManager.tryGetPlant(vehicle.transform, out _, out _, out _, out var region)) { foreach (var barricade in from data in region.barricades where !data.barricade.isDead let drop = region.drops.FirstOrDefault(c => c.instanceID == data.instanceID) select SerializableBarricade.Create(drop, data)) { result.Barricades.Add(barricade); } } return(result); }
public static Transform dropBarricade(Barricade barricade, Transform hit, Vector3 point, float angle_x, float angle_y, float angle_z, ulong owner, ulong group) { // #Nelson doesn't know how to optimize!!! ItemBarricadeAsset itemBarricadeAsset = (ItemBarricadeAsset)Assets.find(EAssetType.ITEM, barricade.id); Transform result = null; if (itemBarricadeAsset == null) { return(result); } Vector3 eulerAngles = BarricadeManager.getRotation(itemBarricadeAsset, angle_x, angle_y, angle_z).eulerAngles; angle_x = (float)(Mathf.RoundToInt(eulerAngles.x / 2f) * 2); angle_y = (float)(Mathf.RoundToInt(eulerAngles.y / 2f) * 2); angle_z = (float)(Mathf.RoundToInt(eulerAngles.z / 2f) * 2); byte b3; byte b4; BarricadeRegion barricadeRegion2; bool cancel = false; if (hit != null && hit.transform.CompareTag("Vehicle")) // Placed on vehicle??? { byte b; byte b2; ushort num; BarricadeRegion barricadeRegion; if (!BarricadeManager.tryGetPlant(hit, out b, out b2, out num, out barricadeRegion)) { return(result); } BarricadeData barricadeData = new BarricadeData(barricade, point, MeasurementTool.angleToByte(angle_x), MeasurementTool.angleToByte(angle_y), MeasurementTool.angleToByte(angle_z), owner, @group, Provider.time); ServerEvents.RunBarricadeCreated(barricadeData, ref cancel); if (cancel) { return(null); } barricadeRegion.barricades.Add(barricadeData); uint num2 = (uint)typeof(BarricadeManager).GetField("", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) + 1u; result = (Transform)typeof(BarricadeManager).GetMethod("spawnBarricade", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(BarricadeManager.instance, new object[] { barricadeRegion, barricade.id, barricade.state, barricadeData.point, barricadeData.angle_x, barricadeData.angle_y, barricadeData.angle_z, 100, barricadeData.owner, barricadeData.@group, num2 }); BarricadeManager.instance.channel.send("tellBarricade", ESteamCall.OTHERS, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] { b, b2, num, barricade.id, barricade.state, barricadeData.point, barricadeData.angle_x, barricadeData.angle_y, barricadeData.angle_z, barricadeData.owner, barricadeData.@group, num2 }); } else if (Regions.tryGetCoordinate(point, out b3, out b4) && BarricadeManager.tryGetRegion(b3, b4, 65535, out barricadeRegion2)) { BarricadeData barricadeData2 = new BarricadeData(barricade, point, MeasurementTool.angleToByte(angle_x), MeasurementTool.angleToByte(angle_y), MeasurementTool.angleToByte(angle_z), owner, @group, Provider.time); ServerEvents.RunBarricadeCreated(barricadeData2, ref cancel); if (cancel) { return(null); } barricadeRegion2.barricades.Add(barricadeData2); uint num3 = (uint)typeof(BarricadeManager).GetField("", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) + 1u; result = (Transform)typeof(BarricadeManager).GetMethod("spawnBarricade", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(BarricadeManager.instance, new object[] { barricadeRegion2, barricade.id, barricade.state, barricadeData2.point, barricadeData2.angle_x, barricadeData2.angle_y, barricadeData2.angle_z, 100, barricadeData2.owner, barricadeData2.@group, num3 }); BarricadeManager.instance.channel.send("tellBarricade", ESteamCall.OTHERS, b3, b4, BarricadeManager.BARRICADE_REGIONS, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] { b3, b4, 65535, barricade.id, barricade.state, barricadeData2.point, barricadeData2.angle_x, barricadeData2.angle_y, barricadeData2.angle_z, barricadeData2.owner, barricadeData2.@group, num3 }); } return(result); }
public void Execute(IRocketPlayer caller, string[] command) { float radius = 0; UnturnedPlayer player = null; if (!(caller is ConsolePlayer)) { if (command.GetFloatParameter(0) == null) { UnturnedChat.Say(caller, WreckingBall.Instance.Translate("wreckingball_lv_help")); return; } player = (UnturnedPlayer)caller; radius = (float)command.GetFloatParameter(0); } foreach (InteractableVehicle vehicle in VehicleManager.vehicles) { int count = 0; bool getPInfo = false; // skip the vehicle in the list if it is destroyed or drowned. if (vehicle.isDead || vehicle.isDrowned) { continue; } if (WreckingBall.Instance.Configuration.Instance.EnablePlayerInfo && WreckingBall.isPlayerInfoLibPresent && WreckingBall.isPlayerInfoLibLoaded) { getPInfo = true; } string lockedBy = getPInfo ? WreckingBall.Instance.PInfoGenerateMessage((ulong)vehicle.lockedOwner) : vehicle.lockedOwner.ToString(); ulong signOwner = 0; string signBy = string.Empty; bool showSignBy = false; if (BarricadeManager.tryGetPlant(vehicle.transform, out byte x, out byte y, out ushort plant, out BarricadeRegion barricadeRegion)) { count = barricadeRegion.drops.Count; } if (caller is ConsolePlayer || Vector3.Distance(vehicle.transform.position, player.Position) <= radius) { showSignBy = DestructionProcessing.HasFlaggedElement(vehicle.transform, out signOwner); if (showSignBy) { signBy = getPInfo ? WreckingBall.Instance.PInfoGenerateMessage(signOwner) : signOwner.ToString(); } ProcessMessages(caller, vehicle.transform, vehicle.asset, vehicle.instanceID, count, lockedBy, vehicle.isLocked, signBy, showSignBy); } // Handle train cars too, if in range. if (vehicle.asset.engine == EEngine.TRAIN && vehicle.trainCars != null && vehicle.trainCars.Length > 1) { for (int i = 1; i < vehicle.trainCars.Length; i++) { if (caller is ConsolePlayer || Vector3.Distance(vehicle.trainCars[i].root.transform.position, player.Position) <= radius) { if (BarricadeManager.tryGetPlant(vehicle.trainCars[i].root, out x, out y, out plant, out barricadeRegion)) { count = barricadeRegion.drops.Count; } showSignBy = DestructionProcessing.HasFlaggedElement(vehicle.trainCars[i].root, out signOwner); if (showSignBy) { signBy = getPInfo ? WreckingBall.Instance.PInfoGenerateMessage(signOwner) : signOwner.ToString(); } ProcessMessages(caller, vehicle.trainCars[i].root, null, vehicle.instanceID, count, lockedBy, false, signBy, showSignBy, true, i); } } } } }
internal static void DestructionLoop(WreckType type) { try { int i = 0; EPlayerKill pKill; uint xp; while (((dIdx < dIdxCount && type == WreckType.Wreck) || (cdIdx < cdIdxCount && type == WreckType.Cleanup)) && i < WreckingBall.Instance.Configuration.Instance.DestructionsPerInterval) { Destructible element = type == WreckType.Wreck ? destroyList[dIdx] : cleanupList[cdIdx]; if (element.Type == ElementType.Structure) { try { if (WreckingBall.Instance.Configuration.Instance.EnableDestroyedElementDrop) { try { Item item = new Item(element.ItemID, true); ItemManager.dropItem(item, element.Transform.position, false, true, true); } catch (Exception ex) { Logger.LogException(ex, "Error in dropping an item for a destroyed structure."); } } StructureManager.damage(element.Transform, element.Transform.position, ushort.MaxValue, 1, false); } catch (Exception ex) { Logger.LogException(ex, "Error in destroying structure."); } } else if (element.Type == ElementType.Barricade || element.Type == ElementType.VehicleBarricade) { try { if ((element.Type == ElementType.VehicleBarricade && WreckingBall.Instance.Configuration.Instance.EnableVehicleElementDrop) || (element.Type == ElementType.Barricade && WreckingBall.Instance.Configuration.Instance.EnableDestroyedElementDrop)) { try { Item item = new Item(element.ItemID, true); ItemManager.dropItem(item, element.Transform.position, false, true, true); } catch (Exception ex) { Logger.LogException(ex, "Error in dropping an item for a destroyed" + (element.Type == ElementType.VehicleBarricade ? " vehicle" : string.Empty) + " barricade."); } } BarricadeManager.damage(element.Transform, ushort.MaxValue, 1, false); } catch (Exception ex) { Logger.LogException(ex, "Error in destroying barricade."); } } else if (element.Type == ElementType.Vehicle) { try { // Output log entry if a vehicle is destroyed by a cleanup. if (type == WreckType.Cleanup) { bool getPInfo = WreckingBall.isPlayerInfoLibLoaded; Logger.Log(string.Format("Cleanup: Vehicle with InstanceID: {0}, and Type: {1}({2}), at position: {3} destroyed, Element count: {4}, Sign By: {5}, Locked By: {6}.", element.Vehicle.instanceID, element.Vehicle.asset.vehicleName, element.Vehicle.asset.id, element.Vehicle.transform.position.ToString(), BarricadeManager.tryGetPlant(element.Vehicle.transform, out byte x, out byte y, out ushort plant, out BarricadeRegion barricadeRegion) ? barricadeRegion.drops.Count : 0, HasFlaggedElement(element.Vehicle.transform, out ulong vFlagOwner) ? (getPInfo ? WreckingBall.Instance.PInfoGenerateMessage(vFlagOwner) : vFlagOwner.ToString()) : "N/A", element.Vehicle.isLocked ? (getPInfo ? WreckingBall.Instance.PInfoGenerateMessage((ulong)element.Vehicle.lockedOwner) : element.Vehicle.lockedOwner.ToString()) : "N/A")); } if (WreckingBall.Instance.Configuration.Instance.EnableVehicleElementDrop) { if (element.Vehicle.asset.engine == EEngine.TRAIN && element.Vehicle.trainCars != null && element.Vehicle.trainCars.Count() > 1) { foreach (TrainCar car in element.Vehicle.trainCars) { WreckingBall.Instance.VehicleElementDrop(element.Vehicle, true, car.root); } } else { WreckingBall.Instance.VehicleElementDrop(element.Vehicle); } } if (!element.Vehicle.isDead) { element.Vehicle.askDamage(ushort.MaxValue, false); } } catch (Exception ex) { Logger.LogException(ex, "Error in destroying vehicle."); } } else if (element.Type == ElementType.Zombie) { try { for (int z = 0; z < 1000 && !element.Zombie.isDead; z++) { element.Zombie.askDamage(ushort.MaxValue, element.Zombie.transform.up, out pKill, out xp); } } catch (Exception ex) { Logger.LogException(ex, "Error in killing zombie."); } } else if (element.Type == ElementType.Animal) { try { for (int a = 0; a < 1000 && !element.Animal.isDead; a++) { element.Animal.askDamage(ushort.MaxValue, element.Animal.transform.up, out pKill, out xp); } } catch (Exception ex) { Logger.LogException(ex, "Error in killing animal."); } } if (type == WreckType.Wreck) { dIdx++; } else { cdIdx++; } i++; } if (destroyList.Count == dIdx && type == WreckType.Wreck) { if (originalCaller != null) { UnturnedChat.Say(originalCaller, WreckingBall.Instance.Translate("wreckingball_complete", dIdx)); } else { Logger.Log(WreckingBall.Instance.Translate("wreckingball_complete", dIdx)); } SaveManager.save(); Abort(WreckType.Wreck); } } catch (Exception ex) { Logger.LogException(ex, "General destruction loop error."); } }
internal static void HandleVehicleCap() { if ((DateTime.Now - lastVehiclesCapCheck).TotalSeconds > WreckingBall.Instance.Configuration.Instance.VCapCheckInterval) { lastVehiclesCapCheck = DateTime.Now; Dictionary <InteractableVehicle, int> vList = new Dictionary <InteractableVehicle, int>(); byte x = 0; byte y = 0; ushort plant = 0; foreach (InteractableVehicle vehicle in VehicleManager.vehicles) { if (vehicle.isDead) { continue; } // Don't process trains with the cap, this can bug things up on a server. if (vehicle.asset.engine == EEngine.TRAIN) { continue; } if (BarricadeManager.tryGetPlant(vehicle.transform, out x, out y, out plant, out BarricadeRegion barricadeRegion)) { vList.Add(vehicle, barricadeRegion.drops.Count); } else { vList.Add(vehicle, 0); } } if (vList.Count > WreckingBall.Instance.Configuration.Instance.MaxVehiclesAllowed) { int numToDestroy = vList.Count - WreckingBall.Instance.Configuration.Instance.MaxVehiclesAllowed; int i = 0; Logger.Log(string.Format("Vehicle Cap Check: Count over max by: {0} vehicles, starting cleanup process.", numToDestroy), ConsoleColor.Yellow); if (WreckingBall.Instance.Configuration.Instance.VCapDestroyByElementCount) { var sort = vList.OrderBy(c => c.Value); vList = sort.ToDictionary(d => d.Key, d => d.Value); } bool useSafeGuards = true; bool getPInfo = false; if (WreckingBall.Instance.Configuration.Instance.EnablePlayerInfo && WreckingBall.isPlayerInfoLibPresent && WreckingBall.isPlayerInfoLibLoaded) { getPInfo = true; } restart: int v = 0; foreach (KeyValuePair <InteractableVehicle, int> vehicle in vList) { v++; if (vehicle.Key.isDead) { continue; } if (!vehicle.Key.isEmpty) { continue; } bool hasSign = HasFlaggedElement(vehicle.Key.transform, out ulong elementOwner); if (useSafeGuards && (WreckingBall.Instance.Configuration.Instance.LowElementCountOnly || WreckingBall.Instance.Configuration.Instance.KeepVehiclesWithSigns)) { if (WreckingBall.Instance.Configuration.Instance.LimitSafeGuards && v > Math.Round(WreckingBall.Instance.Configuration.Instance.MaxVehiclesAllowed * WreckingBall.Instance.Configuration.Instance.LimitSafeGuardsRatio + numToDestroy, 0)) { useSafeGuards = false; goto restart; } if (WreckingBall.Instance.Configuration.Instance.LowElementCountOnly && WreckingBall.Instance.Configuration.Instance.MinElementCount <= vehicle.Value) { continue; } if (WreckingBall.Instance.Configuration.Instance.KeepVehiclesWithSigns && hasSign) { continue; } } // Current vehicle in check is the last vehicle added to the server, newest, skip. if (vehicle.Key.transform == VehicleManager.vehicles.Last().transform) { continue; } if ((vehicle.Key.isLocked && R.Permissions.HasPermission(new RocketPlayer(vehicle.Key.lockedOwner.ToString()), "wb.bypassvehiclecap")) || (hasSign && R.Permissions.HasPermission(new RocketPlayer(elementOwner.ToString()), "wb.bypassvehiclecap"))) { continue; } i++; if (i > numToDestroy) { break; } Logger.Log(string.Format("Vehicle #{0}, with InstanceID: {1}, and Type: {5}({6}), at position: {2} destroyed, Element count: {3}, Sign By {7}, Locked By: {4}.", v, vehicle.Key.instanceID, vehicle.Key.transform.position.ToString(), vehicle.Value, vehicle.Key.isLocked ? (getPInfo ? WreckingBall.Instance.PInfoGenerateMessage((ulong)vehicle.Key.lockedOwner) : vehicle.Key.lockedOwner.ToString()) : "N/A", vehicle.Key.asset.vehicleName, vehicle.Key.asset.id, hasSign ? (getPInfo ? WreckingBall.Instance.PInfoGenerateMessage(elementOwner) : elementOwner.ToString()) : "N/A")); if (WreckingBall.Instance.Configuration.Instance.EnableVehicleElementDrop) { WreckingBall.Instance.VehicleElementDrop(vehicle.Key); } vehicle.Key.askDamage(ushort.MaxValue, false); } Logger.Log("Vehicle cleanup finished.", ConsoleColor.Yellow); } } }
internal static void Wreck(IRocketPlayer caller, string filter, float radius, Vector3 position, WreckType type, FlagType flagtype, ulong steamID, ushort itemID) { bool pInfoLibLoaded = false; syncError = false; if (type == WreckType.Wreck) { if (DestructionProcessing.processing) { UnturnedChat.Say(caller, WreckingBall.Instance.Translate("wreckingball_processing", originalCaller != null ? originalCaller.CharacterName : "???", (dIdxCount - dIdx), CalcProcessTime())); return; } Abort(WreckType.Wreck); } else if (type == WreckType.Scan) { WreckingBall.ElementData.reportLists[BuildableType.Element].Clear(); WreckingBall.ElementData.reportLists[BuildableType.VehicleElement].Clear(); if (WreckingBall.Instance.Configuration.Instance.EnablePlayerInfo && WreckingBall.isPlayerInfoLibPresent && WreckingBall.isPlayerInfoLibLoaded) { pInfoLibLoaded = true; } } UnturnedPlayer Player = null; if (!(caller is ConsolePlayer) && type != WreckType.Cleanup) { Player = (UnturnedPlayer)caller; if (Player.IsInVehicle) { position = Player.CurrentVehicle.transform.position; } else { position = Player.Position; } } List <char> Filter = new List <char>(); Filter.AddRange(filter.ToCharArray()); float distance = 0; float vdistance = 0; StructureRegion structureRegion; BarricadeRegion barricadeRegion; for (int k = 0; k < StructureManager.regions.GetLength(0); k++) { for (int l = 0; l < StructureManager.regions.GetLength(1); l++) { // check to see if the region is out of range, skip if it is. if (!radius.IsNaN() && position.RegionOutOfRange(k, l, radius) && type != WreckType.Cleanup && type != WreckType.Counts) { continue; } structureRegion = StructureManager.regions[k, l]; ProcessElements(caller, itemID, radius, type, flagtype, Filter, pInfoLibLoaded, structureRegion, position, steamID, BuildableType.Element); } } for (int k = 0; k < BarricadeManager.BarricadeRegions.GetLength(0); k++) { for (int l = 0; l < BarricadeManager.BarricadeRegions.GetLength(1); l++) { // check to see if the region is out of range, skip if it is. if (!radius.IsNaN() && position.RegionOutOfRange(k, l, radius) && type != WreckType.Cleanup && type != WreckType.Counts) { continue; } barricadeRegion = BarricadeManager.BarricadeRegions[k, l]; ProcessElements(caller, itemID, radius, type, flagtype, Filter, pInfoLibLoaded, barricadeRegion, position, steamID, BuildableType.Element); } } foreach (InteractableVehicle vehicle in VehicleManager.vehicles) { bool validVehicleElements = BarricadeManager.tryGetPlant(vehicle.transform, out byte x, out byte y, out ushort plant, out barricadeRegion); // Process Vehicles. if ((Filter.Contains('V') || Filter.Contains('*')) && type != WreckType.Cleanup && type != WreckType.Counts && (flagtype == FlagType.Normal || (flagtype == FlagType.SteamID && vehicle.isLocked && vehicle.lockedOwner == (CSteamID)steamID))) { vdistance = Vector3.Distance(vehicle.transform.position, position); if ((!radius.IsNaN() && vdistance <= radius) || (radius.IsNaN() && (vehicle.transform.position.x.IsNaN() || vehicle.transform.position.y.IsNaN() || vehicle.transform.position.z.IsNaN()))) { WreckProcess(caller, 999, vdistance, pInfoLibLoaded, BuildableType.Vehicle, type, vehicle, vehicle.transform, !validVehicleElements ? 0 : barricadeRegion.drops.Count, vehicle.isLocked ? (ulong)vehicle.lockedOwner : 0); } if (vehicle.asset.engine == EEngine.TRAIN && vehicle.trainCars != null && vehicle.trainCars.Length > 1) { for (int i = 1; i < vehicle.trainCars.Length; i++) { if (BarricadeManager.tryGetPlant(vehicle.trainCars[i].root, out x, out y, out plant, out BarricadeRegion barricadeRegion2)) { float tcdistance = Vector3.Distance(vehicle.trainCars[i].root.position, position); if (tcdistance <= radius) { WreckProcess(caller, 999, tcdistance, pInfoLibLoaded, BuildableType.Vehicle, type, vehicle, vehicle.transform, barricadeRegion2 == null ? 0 : barricadeRegion2.drops.Count, 0, i); } } } } } if (type == WreckType.Cleanup && vehicle.asset.engine != EEngine.TRAIN && WreckingBall.Instance.Configuration.Instance.CleanupLockedCars && vehicle.isLocked && vehicle.lockedOwner == (CSteamID)steamID) { cleanupList.Add(new Destructible(vehicle.transform, ElementType.Vehicle, vehicle.asset.id, vehicle)); } // Add Locked vehicles to the top players count, if the cleanup locked vehicles feature is active. if (type == WreckType.Counts && vehicle.asset.engine != EEngine.TRAIN && WreckingBall.Instance.Configuration.Instance.CleanupLockedCars && vehicle.isLocked) { ulong vOwner = (ulong)vehicle.lockedOwner; if (pElementCounts.ContainsKey(vOwner)) { pElementCounts[vOwner]++; } else { pElementCounts.Add(vOwner, 1); } } // Process vehicles elements, remove distance limiting on vehicle placement for element scanning, to handle massively misplaced elements on vehicles. if (validVehicleElements) { ProcessElements(caller, itemID, radius, type, flagtype, Filter, pInfoLibLoaded, barricadeRegion, position, steamID, BuildableType.VehicleElement); } if (vehicle.asset.engine == EEngine.TRAIN && vehicle.trainCars != null && vehicle.trainCars.Length > 1) { for (int i = 1; i < vehicle.trainCars.Length; i++) { if (BarricadeManager.tryGetPlant(vehicle.trainCars[i].root, out x, out y, out plant, out BarricadeRegion barricadeRegion2)) { ProcessElements(caller, itemID, radius, type, flagtype, Filter, pInfoLibLoaded, barricadeRegion2, position, steamID, BuildableType.VehicleElement); } } } } if (Filter.Contains('Z')) { for (int z = 0; z < ZombieManager.regions.Length; z++) { foreach (Zombie zombie in ZombieManager.regions[z].zombies) { distance = Vector3.Distance(zombie.transform.position, position); if (distance < radius) { WreckProcess(caller, 998, distance, pInfoLibLoaded, BuildableType.Element, type, zombie, zombie.transform); } } } } if (Filter.Contains('A')) { foreach (Animal animal in AnimalManager.animals) { distance = Vector3.Distance(animal.transform.position, position); if (distance <= radius) { WreckProcess(caller, 997, distance, pInfoLibLoaded, BuildableType.Element, type, animal, animal.transform); } } } if (type == WreckType.Scan) { uint totalCount = 0; if (WreckingBall.ElementData.reportLists[BuildableType.Element].Count > 0 || WreckingBall.ElementData.reportLists[BuildableType.VehicleElement].Count > 0) { foreach (KeyValuePair <BuildableType, Dictionary <char, uint> > reportDictionary in WreckingBall.ElementData.reportLists) { if (reportDictionary.Value.Count == 0) { continue; } foreach (KeyValuePair <char, uint> reportFilter in reportDictionary.Value) { totalCount += reportFilter.Value; } } } Logger.Log(string.Format("Player: {0}, ran scan at: {1}, with Radius: {7}, with Flag type: {2}, with Flags: {3}, with ItemID: {4}, with SteamID: {5}, number of elements scanned: {6}", caller is ConsolePlayer ? "Console" : Player.CharacterName + " [" + Player.SteamName + "] (" + Player.CSteamID.ToString() + ")", caller is ConsolePlayer ? "N/A" : Player.Position.ToString(), flagtype.ToString(), Filter.Count > 0 ? string.Join("", Filter.Select(i => i.ToString()).ToArray()) : "N/A", itemID, steamID, totalCount, radius.IsNaN() ? "NaN(NaN Check)" : radius.ToString())); return; } if (destroyList.Count >= 1 && type == WreckType.Wreck) { Logger.Log(string.Format("Player {0}, queued wreck at: {1}, with Radius: {7}, with Flag type: {2}, with Flags: {3}, with itemID: {4}, with StermID: {5}, number of elements queued: {6}", caller is ConsolePlayer ? "Console" : Player.CharacterName + " [" + Player.SteamName + "] (" + Player.CSteamID.ToString() + ")", caller is ConsolePlayer ? "N/A" : Player.Position.ToString(), flagtype.ToString(), Filter.Count > 0 ? string.Join("", Filter.Select(i => i.ToString()).ToArray()) : "N/A", itemID, steamID, destroyList.Count, radius.IsNaN() ? "NaN(NaN Check)" : radius.ToString())); dIdxCount = destroyList.Count; WreckingBall.Instance.Instruct(caller); } else if (type == WreckType.Cleanup) { cdIdxCount = cleanupList.Count; } else if (type != WreckType.Counts) { UnturnedChat.Say(caller, WreckingBall.Instance.Translate("wreckingball_not_found", radius)); } }
public void VehicleCapRun() { if ((DateTime.Now - _lastVehicleCapRun).TotalSeconds < _wreckPlugin.ConfigurationInstance.VehicleDestructionInterval) { return; } int runCount = 0; while (VehicleManager.vehicles.Count > _wreckPlugin.ConfigurationInstance.MaxVehiclesAllowed) { InteractableVehicle vehicle = VehicleManager.vehicles.FirstOrDefault(); if (vehicle == null) { _lastVehicleCapRun = DateTime.Now; return; } if (vehicle.isLocked && _permissionProvider.CheckHasAnyPermission(_wreckPlugin.Container.Resolve <IPlayerManager> ().GetPlayer(vehicle.lockedOwner.m_SteamID.ToString()), "wreck.skip.vehicle", "wreck.skip.*", "wreck.*") == PermissionResult.Grant) { _lastVehicleCapRun = DateTime.Now; return; } bool skip = false; int count = 0; BarricadeManager.tryGetPlant(vehicle.transform, out byte _, out byte _, out ushort _, out BarricadeRegion region); count += region.barricades.Count; if (_wreckPlugin.ConfigurationInstance.KeepVehiclesWithSigns && region.drops.Any(c => c.interactable is InteractableSign sign && sign.text.Contains(_wreckPlugin.ConfigurationInstance.VehicleSignFlag))) { continue; } foreach (var tranCar in vehicle.trainCars) { BarricadeManager.tryGetPlant(tranCar.root, out _, out _, out _, out BarricadeRegion tRegion); count += tRegion.barricades.Count; if (_wreckPlugin.ConfigurationInstance.KeepVehiclesWithSigns && tRegion.drops.Any(c => c.interactable is InteractableSign sign && sign.text.Contains(_wreckPlugin.ConfigurationInstance.VehicleSignFlag))) { skip = true; break; } } if (_wreckPlugin.ConfigurationInstance.LowElementCountOnly) { if (count >= _wreckPlugin.ConfigurationInstance.MinElementCount) { skip = true; } } if (!skip) { vehicle.askDamage(ushort.MaxValue, true); } runCount++; if (runCount > 15) { break; } } _lastVehicleCapRun = DateTime.Now; }
public void Execute(IRocketPlayer caller, string[] command) { UnturnedPlayer player = (UnturnedPlayer)caller; if (command.Length < 1) { Plugin.Say(player, "INVALID_SYNTAX_AUCTION_VEHICLE", Color.red); return; } if (player.CurrentVehicle == null || player.CurrentVehicle.passengers.First().player != player.Player.channel.owner) { Plugin.Say(player, "NO_VEHICLE", Color.red); return; } if (!decimal.TryParse(command[0], out var startingBid)) { Plugin.Say(player, "NOT_NUMBER", Color.red, command[0]); return; } if (startingBid < Plugin.Instance.Configuration.Instance.MinimumBid) { Plugin.Say(player, "BID_TOO_SMALL", Color.red, Plugin.Instance.Configuration.Instance.MinimumBid); return; } if (Plugin.Instance.AuctionManager.HasAnyAuction(player.CSteamID.m_SteamID)) { Plugin.Say("ALREADY_QUEUED", Color.red); return; } //NO need for lock since all operations on AuctionQuehe happens on the main thread var auction = new Auction(player.Player, new AuctionItem() { Vehicle = SerializableVehicle.Create(player.CurrentVehicle) }, startingBid, TimeSpan.FromSeconds(Plugin.Instance.Configuration.Instance.AuctionDuration)); var vehicle = player.CurrentVehicle; foreach (var currentPlayer in player.CurrentVehicle.passengers.Where(c => c.player != null)) { vehicle.forceRemovePlayer(out var seat, currentPlayer.player.playerID.steamID, out var point, out var angle); VehicleManager.sendExitVehicle(vehicle, seat, point, angle, true); } if (BarricadeManager.tryGetPlant(vehicle.transform, out byte x, out byte y, out ushort plant, out var region)) { vehicle.trunkItems.items.Clear(); region.barricades.Clear(); region.drops.Clear(); } VehicleManager.instance.channel.send("tellVehicleDestroy", ESteamCall.ALL, ESteamPacket.UPDATE_RELIABLE_BUFFER, vehicle.instanceID); Plugin.Instance.AuctionManager.AuctionQueue.Add(auction); Plugin.Instance.AuctionManager.Tick(); if (Plugin.Instance.AuctionManager.AuctionQueue.Count > 0) //If it didn't automaticly get started { Plugin.Say(player, "AUCTION_QUEUED", Color.green, Plugin.Instance.AuctionManager.AuctionQueue.Count, (int)((Plugin.Instance.AuctionManager.LastCompletedAuction.AddSeconds(Plugin.Instance.Configuration.Instance.IntervalInbetween) - DateTime.UtcNow).TotalSeconds)); } }