private void DieInstantly(BaseCombatEntity entity)
 {
     if (!entity.IsDestroyed)
     {
         Effect.server.Run(heliExplosion, entity.transform.position, Vector3.up, null, true);
         OnChopperDeath(entity.GetComponent <CSHelicopter>());
         entity.health    = 0f;
         entity.lifestate = BaseCombatEntity.LifeState.Dead;
         entity.Kill(BaseNetworkable.DestroyMode.None);
     }
 }
Beispiel #2
0
        private void OnEntityBuilt(Planner plan, GameObject go)
        {
            if (plan == null || go == null)
            {
                return;
            }

            string name = go.name;

            if (name == null || (name.Length != HighStoneWallName.Length && name.Length != HighWoodWallName.Length))
            {
                return;
            }
            else if (name != HighStoneWallName && name != HighWoodWallName)
            {
                return;
            }

            BasePlayer ownerPlayer = plan.GetOwnerPlayer();

            if (ownerPlayer == null)
            {
                return;
            }
            if (ownerPlayer.IsBuildingAuthed())
            {
                return;
            }

            BaseCombatEntity entity = go.GetComponent <BaseCombatEntity>();

            if (entity == null)
            {
                return;
            }

            float barricadeHealth = entity.MaxHealth() * barricadeHealthPercentage;

            entity.health = barricadeHealth;
            entity.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);

            InvokeHandler.Invoke(entity, delegate
            {
                if (entity.health > barricadeHealth)
                {
                    return;
                }

                entity.Kill();
            }, decayTime);
        }
Beispiel #3
0
        private object CanPickupEntity(BasePlayer player, BaseCombatEntity entity)
        {
            if (entity.name != autoTurretPrefab)
            {
                return(true);
            }
            var item = ItemManager.Create(entity.pickup.itemTarget, entity.pickup.itemCount);

            if (item.hasCondition)
            {
                item.conditionNormalized = entity.Health() / entity.MaxHealth() / 2;
            }
            player.GiveItem(item, BaseEntity.GiveItemReason.PickedUp);
            entity.OnPickedUp(item, player);
            entity.Kill();
            return(false);
        }
Beispiel #4
0
        /// <summary>
        /// Kills JDeployable.
        /// </summary>
        /// <param name="mode"></param>
        /// <param name="remove">Remove JDeployable instance from JDeployableManager so it isn't saved</param>
        public void Kill(BaseNetworkable.DestroyMode mode = BaseNetworkable.DestroyMode.None, bool remove = true)
        {
            if (isBeingDestroyed)
            {
                return;
            }

            if (MainParent != null && !MainParent.IsDestroyed)
            {
                isBeingDestroyed = true;
                MainParent.Kill(mode);
            }

            if (remove)
            {
                JDeployableManager.RemoveJDeployable(this.Id);
            }
        }
Beispiel #5
0
        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.");
                }
            }
        }
Beispiel #6
0
        private object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitinfo)
        {
            if (!enabled)
            {
                return(null);
            }

            if (entity == null || hitinfo == null)
            {
                return(null);
            }

            float  damageAmount = 0f;
            string entity_name  = entity.LookupPrefab().name;
            ulong  owner        = entity.OwnerID;

            switch (hitinfo.damageTypes.GetMajorityDamageType().ToString())
            {
            case "Decay":
                float before = hitinfo.damageTypes.Get(Rust.DamageType.Decay);
                damageAmount = before * configData.Global.DecayMultiplier;

                if (entity is BuildingBlock)
                {
                    if ((bool)JPipes?.Call("IsPipe", entity) && (bool)JPipes?.Call("IsNoDecayEnabled"))
                    {
                        DoLog("Found a JPipe with nodecay enabled");
                        hitinfo.damageTypes.Scale(Rust.DamageType.Decay, 0f);
                        return(null);
                    }

                    damageAmount = before * configData.Global.DecayMultiplier;
                }

                NextTick(() =>
                {
                    DoLog($"Decay ({entity_name}) before: {before} after: {damageAmount}, item health {entity.health.ToString()}");
                    entity.health -= damageAmount;
                    if (entity.health == 0)
                    {
                        DoLog($"Entity {entity_name} completely decayed - destroying!");
                        if (entity == null)
                        {
                            return;
                        }

                        entity.Kill(BaseNetworkable.DestroyMode.Gib);
                    }
                });
                return(true);    // Cancels this hook (for decay only).  Decay handled on NextTick.

            default:
                if (configData.Global.EnablePVE)
                {
                    try
                    {
                        object CanTakeDamage = Interface.CallHook("CanEntityTakeDamage", new object[] { entity, hitinfo });
                        if (CanTakeDamage != null && CanTakeDamage is bool && (bool)CanTakeDamage)
                        {
                            return(null);
                        }
                    }
                    catch { }

                    string source = hitinfo.Initiator?.GetType().Name;
                    string target = entity?.GetType().Name;

                    if (source == "BasePlayer" && target == "BasePlayer")
                    {
                        return(true);    // Block player to player damage
                    }

                    if (source == "BasePlayer" && (target == "BuildingBlock" || target == "Door" || target == "wall.window"))
                    {
                        BasePlayer pl = hitinfo.Initiator as BasePlayer;
                        if (pl != null && owner == pl.userID)
                        {
                            return(null);
                        }
                        // Block damage to non-owned building
                        return(true);
                    }
                }
                break;
            }
            return(null);
        }