private void OnEntityDeath(ModularCar car) { if (IsBombTruck(car) && car.OwnerID != 0) { var playerConfig = GetPlayerData(car.OwnerID.ToString()); var netID = car.net.ID; var truckName = playerConfig.FindTruck(netID)?.Name; if (truckName == null) { PrintWarning("Unable to determine truck name on death."); return; } var truckConfig = GetTruckConfig(truckName); if (truckConfig == null) { PrintError("Unable to detonate '{0}' truck because its configuration is missing.", truckName); return; } playerConfig.RemoveTruck(netID); // Clean up the engine parts foreach (var module in car.AttachedModuleEntities) { var engineStorage = (module as VehicleModuleEngine)?.GetContainer() as EngineStorage; engineStorage?.inventory?.Kill(); } var carPosition = car.CenterPoint(); car.Kill(); DetonateExplosion(truckConfig.ExplosionSpec, carPosition); } }
private void OnEntitySpawned(ModularCar car) { if (Rust.Application.isLoadingSave) { return; } if (!PluginConfig.IncludeChassis && !car.spawnSettings.useSpawnSettings) { return; } timer.Once(0.5f, () => { if (car == null) { return; } if (!PluginConfig.IncludeOwnedCars && car.OwnerID != 0) { return; } if (BootstrapWasBlocked(car)) { return; } BootstrapAfterModules(car); }); }
private void RefreshCarEngineLoadouts(ModularCar car) { var enginePreset = DetermineEnginePresetForOwner(car.OwnerID); if (enginePreset == null) { return; } foreach (var module in car.AttachedModuleEntities) { var engineModule = module as VehicleModuleEngine; if (engineModule == null) { continue; } var engineStorage = engineModule.GetContainer() as EngineStorage; if (engineStorage == null) { continue; } TryRefreshEngineLoadout(engineStorage, enginePreset); } }
private void MaybeAddFuel(ModularCar car) { var maxFuelAmount = PluginConfig.MaxFuelAmount; var minFuelAmount = PluginConfig.FuelAmount; if (maxFuelAmount == 0) { return; } var fuelContainer = car.fuelSystem.GetFuelContainer(); if (maxFuelAmount < 0) { maxFuelAmount = fuelContainer.allowedItem.stackable; } if (minFuelAmount < 0) { minFuelAmount = 0; } var fuelItem = fuelContainer.inventory.FindItemByItemID(fuelContainer.allowedItem.itemid); var totalFuel = UnityEngine.Random.Range(minFuelAmount, maxFuelAmount + 1); if (fuelItem == null && totalFuel > 0) { fuelContainer.inventory.AddItem(fuelContainer.allowedItem, totalFuel); } }
private void MaybeRepairModules(ModularCar car) { var healthPercentage = PluginConfig.HealthPercentage; if (healthPercentage < 0 || healthPercentage > 100) { return; } healthPercentage /= 100; if (car.Health() < car.MaxHealth() * healthPercentage) { car.SetHealth(car.MaxHealth() * healthPercentage); car.SendNetworkUpdate(); } foreach (var module in car.AttachedModuleEntities) { if (module.Health() < module.MaxHealth() * healthPercentage) { module.SetHealth(module.MaxHealth() * healthPercentage); module.SendNetworkUpdate(); } } }
private RFReceiver AttachRFReceiver(ModularCar car, int frequency = -1) { VehicleModuleSeating module = FindFirstDriverModule(car); if (module == null) { return(null); } var receiver = GameManager.server.CreateEntity(PrefabRfReceiver, module.transform.TransformPoint(RfReceiverPosition), module.transform.rotation * RfReceiverRotation) as RFReceiver; if (receiver == null) { return(null); } if (frequency == -1) { frequency = GenerateRandomFrequency(); } receiver.frequency = frequency; SetupReceiver(receiver); receiver.Spawn(); receiver.SetParent(module, worldPositionStays: true); return(receiver); }
private void OnEntityDeath(ModularCar car) { if (IsBombTruck(car) && car.OwnerID != 0) { DetonateBombTruck(car); } }
private void OnEntityKill(ModularCar car) { // This handles the case when the entity was killed without dying first. if (IsBombTruck(car) && car.OwnerID != 0) { GetPlayerData(car.OwnerID.ToString()).RemoveTruck(car.net.ID); } }
public void GrabOccupant(ModularCar occupant) { if (!(occupant == null)) { lockedOccupant = occupant; lockedOccupant.DisablePhysics(); } }
private bool VerifyCarCanHaveALock(IPlayer player, ModularCar car) { if (CanCarHaveCodeLock(car)) { return(true); } ReplyToPlayer(player, "Error.NoCockpit"); return(false); }
private bool VerifyCarHasNoLock(IPlayer player, ModularCar car) { if (GetCarCodeLock(car) == null) { return(true); } ReplyToPlayer(player, "Error.HasLock"); return(false); }
private bool VerifyCarIsNotDead(IPlayer player, ModularCar car) { if (!car.IsDead()) { return(true); } ReplyToPlayer(player, "Error.CarDead"); return(false); }
public ModularCarLock(ModularCar owner, bool isServer) { this.owner = owner; this.isServer = isServer; if (isServer) { EnableCentralLockingIfNoDriver(); } }
// This hook is exposed by Claim Vehicle Ownership (ClaimVehicle). private object OnVehicleUnclaim(BasePlayer player, ModularCar car) { if (car == null || !IsBombTruck(car)) { return(null); } ChatMessage(player, "Unclaim.Error"); return(false); }
public void ReleaseOccupant() { carOccupant.inEditableLocation = false; carOccupant.immuneToDecay = false; if (lockedOccupant != null) { lockedOccupant.EnablePhysics(); lockedOccupant = null; } }
private static RFReceiver GetBombTruckReceiver(ModularCar car) { var driverModule = FindFirstDriverModule(car); if (driverModule == null) { return(null); } return(GetChildOfType <RFReceiver>(driverModule)); }
private CodeLock DeployCodeLockForPlayer(ModularCar car, BasePlayer player, bool isFree = true) { var driverModule = FindFirstDriverModule(car); if (driverModule == null) { return(null); } var codeLockItem = player.inventory.FindItemID(CodeLockItemId); if (codeLockItem == null && !isFree) { var itemCost = PluginConfig.CodeLockCost; if (itemCost.Amount > 0) { player.inventory.Take(null, itemCost.GetItemID(), itemCost.Amount); } } var codeLock = DeployCodeLock(car, driverModule, player.userID); if (codeLock == null) { return(null); } // Allow other plugins to detect the lock being deployed (e.g., auto lock) if (codeLockItem != null) { Interface.CallHook("OnItemDeployed", codeLockItem.GetHeldEntity(), car); if (!isFree) { player.inventory.Take(null, CodeLockItemId, 1); } } else { // Temporarily increase the player inventory capacity to ensure there is enough space player.inventory.containerMain.capacity++; var temporaryLockItem = ItemManager.CreateByItemID(CodeLockItemId); if (player.inventory.GiveItem(temporaryLockItem)) { Interface.CallHook("OnItemDeployed", temporaryLockItem.GetHeldEntity(), car); temporaryLockItem.RemoveFromContainer(); } temporaryLockItem.Remove(); player.inventory.containerMain.capacity--; } return(codeLock); }
// This hook is exposed by plugin: Claim Vehicle Ownership (ClaimVehicle). private void OnVehicleOwnershipChanged(ModularCar car) { var enginePartsTier = GetOwnerEnginePartsTier(car.OwnerID); foreach (var module in car.AttachedModuleEntities) { var engineStorage = GetEngineStorage(module); if (engineStorage != null) { MaybeUpdateEngineStorage(engineStorage, enginePartsTier, dropExistingParts: true); } } }
private static void DisableEnginePartDamage(ModularCar car) { foreach (var module in car.AttachedModuleEntities) { var engineStorage = GetEngineStorage(module); if (engineStorage == null) { continue; } engineStorage.internalDamageMultiplier = 0; } }
private bool IsCarOnLift(ModularCar car) { RaycastHit hitInfo; // This isn't perfect as it can hit other deployables such as rugs if (!Physics.SphereCast(car.transform.position + Vector3.up, 1f, Vector3.down, out hitInfo, 1f)) { return(false); } var lift = RaycastHitEx.GetEntity(hitInfo) as ModularCarGarage; return(lift != null && lift.carOccupant == car); }
private object CanLockVehicle(ModularCar car, BasePlayer player) { if (!IsBombTruck(car)) { return(null); } if (player != null) { player.ChatMessage(GetMessage(player.IPlayer, "Lock.Deploy.Error")); } return(false); }
// Workaround for car chassis that won't die private void OnEntityDeath(ModularCar car, HitInfo hitinfo) { OutputRcon("Car died! Checking for associated parts..."); List <BaseEntity> ents = new List <BaseEntity>(); Vis.Entities(car.transform.position, 1f, ents); foreach (var ent in ents) { if (ent.name.Contains("module_car_spawned") && !ent.IsDestroyed) { OutputRcon($"Killing {ent.ShortPrefabName}"); ent.Kill(BaseNetworkable.DestroyMode.Gib); } } }
private static VehicleModuleSeating FindFirstDriverModule(ModularCar car) { for (int socketIndex = 0; socketIndex < car.TotalSockets; socketIndex++) { BaseVehicleModule module; if (car.TryGetModuleAt(socketIndex, out module)) { var seatingModule = module as VehicleModuleSeating; if (seatingModule != null && seatingModule.HasADriverSeat()) { return(seatingModule); } } } return(null); }
private bool VerifyCarFound(IPlayer player, out ModularCar car) { var basePlayer = player.Object as BasePlayer; var entity = GetLookEntity(basePlayer); if (PluginConfig.AllowDeployOffLift) { car = entity as ModularCar; if (car != null) { return(true); } // Check for a lift as well since sometimes it blocks the ray car = (entity as ModularCarGarage)?.carOccupant; if (car != null) { return(true); } ReplyToPlayer(player, "Error.NoCarFound"); return(false); } car = (entity as ModularCarGarage)?.carOccupant; if (car != null) { return(true); } var carEnt = entity as ModularCar; if (carEnt == null) { ReplyToPlayer(player, "Error.NoCarFound"); return(false); } if (!IsCarOnLift(carEnt)) { ReplyToPlayer(player, "Error.NotOnLift"); return(false); } car = carEnt; return(true); }
public override bool CanSwapToThis(BasePlayer player) { object obj = Interface.CallHook("CanSwapToSeat", player, this); if (obj is bool) { return((bool)obj); } if (associatedSeatingModule.DoorsAreLockable) { ModularCar modularCar = associatedSeatingModule.Vehicle as ModularCar; if (modularCar != null) { return(modularCar.PlayerCanUseThis(player, ModularCarLock.LockType.Door)); } } return(true); }
private void SpawnBombTruck(BasePlayer player, TruckConfig truckConfig) { var position = GetIdealCarPosition(player); if (position == null) { return; } ModularCar car = (ModularCar)GameManager.server.CreateEntity(PrefabSockets3, position, GetIdealCarRotation(player)); car.spawnSettings = BombTruckSpawnSettings; car.Spawn(); if (permission.UserHasPermission(player.UserIDString, PermissionDriveUnderwater)) { EnableCarUnderwater(car); } car.OwnerID = player.userID; UpdatePlayerCooldown(player.UserIDString, truckConfig.Name); GetPlayerData(player.UserIDString).BombTrucks.Add(new PlayerTruckData { Name = truckConfig.Name, ID = car.net.ID }); SaveData(); NextTick(() => { car.AdminFixUp(truckConfig.EnginePartsTier); car.fuelSystem.GetFuelContainer().SetFlag(BaseEntity.Flags.Locked, true); foreach (var module in car.AttachedModuleEntities) { var storageContainer = (module as VehicleModuleStorage)?.GetContainer(); if (storageContainer != null) { storageContainer.inventory.SetLocked(true); } } }); }
public void UpdateOccupantMode() { //IL_001f: Incompatible stack heights: 4 vs 3 if (HasOccupant) { ModularCar carOccupant2 = carOccupant; bool liftIsUp; if (HasEditableOccupant) { liftIsUp = LiftIsUp; } else { int num = 0; } ((BaseModularVehicle)(object)this).inEditableLocation = liftIsUp; carOccupant.immuneToDecay = IsOn(); } }
public void UpdateCarUI(ModularCar car) { var looters = PluginInstance.LiftTracker.GetPlayersLootingCar(car); if (!PluginInstance.CanCarHaveCodeLock(car)) { foreach (var player in looters) { DestroyPlayerUI(player); } return; } var uiState = PluginInstance.GetCarCodeLock(car) == null ? UIState.AddLock : UIState.RemoveLock; foreach (var player in looters) { UpdatePlayerCarUI(player, uiState); } }
private CodeLock API_DeployCodeLock(ModularCar car, BasePlayer player) { if (car == null || car.IsDead() || DeployWasBlocked(car, player) || GetCarCodeLock(car) != null) { return(null); } if (player != null) { return(DeployCodeLockForPlayer(car, player, isFree: true)); } var driverModule = FindFirstDriverModule(car); if (driverModule == null) { return(null); } return(DeployCodeLock(car, driverModule)); }
private void DetonateBombTruck(ModularCar car) { var playerConfig = GetPlayerData(car.OwnerID.ToString()); var netID = car.net.ID; var truckName = playerConfig.FindTruck(netID)?.Name; if (truckName == null) { LogError("Unable to determine truck name."); return; } var truckConfig = GetTruckConfig(truckName); if (truckConfig == null) { LogError("Unable to detonate '{0}' truck because its configuration is missing.", truckName); return; } playerConfig.RemoveTruck(netID); // Remove the engine parts. foreach (var module in car.AttachedModuleEntities) { var engineStorage = GetEngineStorage(module); if (engineStorage != null) { engineStorage.inventory.Kill(); } } var carPosition = car.CenterPoint(); car.Kill(); DetonateExplosion(truckConfig.ExplosionSpec, carPosition); }