private object CanPickupEntity(BaseCombatEntity entity, BasePlayer player) { // Preventing from picking up items attached to the CarController if (entity.GetComponentInParent <CarController>()) { return(false); } return(null); }
void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo) { if (entity == null || hitInfo == null) { return; } var iscarpet = entity.GetComponentInParent <CarpetEntity>() ?? null; if (iscarpet != null) { hitInfo.damageTypes.ScaleAll(0); } return; }
object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo) { if (!enabled) { return(null); } if (entity == null || hitInfo == null) { return(null); } if (!hitInfo.damageTypes.Has(Rust.DamageType.Decay)) { return(null); } float damageAmount = 0f; DateTime tick = DateTime.Now; string entity_name = entity.LookupPrefab().name; // Puts($"Decay Entity: {entity_name}"); string owner = entity.OwnerID.ToString(); bool mundane = false; bool isBlock = false; if (configData.Global.usePermission) { if (permission.UserHasPermission(owner, "nodecay.use") || owner == "0") { if (owner != "0") { OutputRcon($"{entity_name} owner {owner} has NoDecay permission!"); } } else { OutputRcon($"{entity_name} owner {owner} does NOT have NoDecay permission. Standard decay in effect."); return(null); } } if (configData.Global.protectedDays > 0 && entity.OwnerID > 0) { long lc = 0; lastConnected.TryGetValue(entity.OwnerID.ToString(), out lc); if (lc > 0) { long now = ToEpochTime(DateTime.UtcNow); float days = Math.Abs((now - lc) / 86400); if (days > configData.Global.protectedDays) { OutputRcon($"Allowing decay for owner offline for {configData.Global.protectedDays.ToString()} days"); return(null); } else { OutputRcon($"Owner was last connected {days.ToString()} days ago and is still protected..."); } } } try { float before = hitInfo.damageTypes.Get(Rust.DamageType.Decay); if (entity is BuildingBlock) { if (configData.Global.useJPipes) { if ((bool)JPipes?.Call("IsPipe", entity)) { if ((bool)JPipes?.Call("IsNoDecayEnabled")) { OutputRcon("Found a JPipe with nodecay enabled"); hitInfo.damageTypes.Scale(Rust.DamageType.Decay, 0f); return(null); } } } damageAmount = ProcessBuildingDamage(entity, before); isBlock = true; } else if (entity is ModularCar) { var garage = entity.GetComponentInParent <ModularCarGarage>(); if (garage != null && configData.Global.protectVehicleOnLift) { return(null); } } else { // Main check for non-building entities/deployables foreach (KeyValuePair <string, List <string> > entities in entityinfo) { //private Dictionary<string, List<string>> entityinfo = new Dictionary<string, List<string>>(); if (entities.Value.Contains(entity_name)) { OutputRcon($"Found {entity_name} listed in {entities.Key}"); if (configData.multipliers.ContainsKey(entities.Key)) { damageAmount = before * configData.multipliers[entities.Key]; break; } } } } // Check non-building entities for cupboard in range if (configData.Global.requireCupboard && configData.Global.cupboardCheckEntity && !isBlock) { // Verify that we should check for a cupboard and ensure that one exists. // If so, multiplier will be set to entityCupboardMultiplier. OutputRcon($"NoDecay checking for local cupboard.", mundane); if (CheckCupboardEntity(entity, mundane)) { damageAmount = before * configData.multipliers["entityCupboard"]; } } NextTick(() => { OutputRcon($"Decay ({entity_name}) before: {before} after: {damageAmount}, item health {entity.health.ToString()}", mundane); entity.health -= damageAmount; if (entity.health == 0 && configData.Global.DestroyOnZero) { OutputRcon($"Entity {entity_name} completely decayed - destroying!", mundane); if (entity == null) { return; } entity.Kill(BaseNetworkable.DestroyMode.Gib); } }); return(true); // Cancels this hook for any of the entities above unless unsupported (for decay only). } finally { double ms = (DateTime.Now - tick).TotalMilliseconds; if (ms > configData.Global.warningTime || configData.Debug.outputMundane) { Puts($"NoDecay.OnEntityTakeDamage on {entity_name} took {ms} ms to execute."); } } }