コード例 #1
0
        object CanBeTargeted(BasePlayer player, BaseCombatEntity entity)
        {
            if (permission.UserHasPermission(player.UserIDString, turretsIgnore))
            {
                return(false);
            }

            else if (permission.UserHasPermission(player.UserIDString, turretsNeverIgnore))
            {
                return(null);
            }

            if (entity is NPCAutoTurret && _config.NPCTurretsAffected)
            {
                BuildingPrivlidge priviledge = entity.GetBuildingPrivilege();

                if (priviledge != null && !priviledge.IsAuthed(player) && player.IsBuildingBlocked() && player.IsVisible(new Vector3(entity.transform.position.x, entity.transform.position.y + 0.8f, entity.transform.position.z), new Vector3(player.transform.position.x, player.transform.position.y + 1.5f, player.transform.position.z)))
                {
                    return(null);
                }
                else
                {
                    return(false);
                }
            }

            if ((entity is AutoTurret && !(entity is NPCAutoTurret) && _config.autoturretsAffected))
            {
                AutoTurret turret = entity as AutoTurret;

                BuildingPrivlidge priviledge = turret.GetBuildingPrivilege();

                if (priviledge != null && !priviledge.IsAuthed(player) && player.IsBuildingBlocked() && player.IsVisible(new Vector3(turret.transform.position.x, turret.transform.position.y + 0.8f, turret.transform.position.z), new Vector3(player.transform.position.x, player.transform.position.y + 1.5f, player.transform.position.z)))
                {
                    if (_config.autoturretsShootAuthed && turret.IsAuthed(player))
                    {
                        turret.SetTarget(player);

                        return(null);
                    }
                    else if (!turret.IsAuthed(player))
                    {
                        return(null);
                    }
                }

                return(false);
            }

            if ((entity is FlameTurret && _config.flameTrapsAffected) || (entity is GunTrap && _config.shotgunTrapsAffected) && !player.IsBuildingBlocked() || !player.IsVisible(entity.transform.position, player.transform.position, Mathf.Infinity))
            {
                return(false);
            }

            return(null);
        }
コード例 #2
0
        private void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
            if (info == null)
            {
                return;
            }

            if (!IsRaidEntity(entity))
            {
                return;
            }
            if (info.InitiatorPlayer == null)
            {
                return;
            }

            var buildingPrivilege = entity.GetBuildingPrivilege();

            if (buildingPrivilege == null || buildingPrivilege.authorizedPlayers.IsEmpty())
            {
                return;
            }

            var victims = new List <ulong>(buildingPrivilege.authorizedPlayers.Count);

            foreach (PlayerNameID victim in buildingPrivilege.authorizedPlayers)
            {
                if (victim == null)
                {
                    continue;
                }
                if (config.usePermissions && !permission.UserHasPermission(victim.userid.ToString(), PERMISSION))
                {
                    return;
                }
                if (victim.userid == info.InitiatorPlayer.userID)
                {
                    return;
                }
                if (disabled.Contains(victim.userid))
                {
                    continue;
                }
                victims.Add(victim.userid);
            }

            NotificationList.SendNotificationTo(
                victims, NotificationChannel.SmartAlarm, lang.GetMessage(AlarmLoc.TITLE, this),
                string.Format(lang.GetMessage(AlarmLoc.BODY, this),
                              entity.ShortPrefabName, GetGrid(entity.transform.position)), Util.GetServerPairingData());
        }
コード例 #3
0
        object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo)
        {
            if (!init || entity == null || hitInfo == null)
            {
                return(null);
            }

            var kvp = prefabs.FirstOrDefault(x => x.Key == entity.PrefabName);

            bool underPriv = entity.GetBuildingPrivilege();

            if (!underPriv)
            {
                return(!string.IsNullOrEmpty(kvp.Value) && deployables.ContainsKey(kvp.Value) && deployables[kvp.Value] && !blockOnlyUnderTC ? (object)false : null);
            }
            else
            {
                return(!string.IsNullOrEmpty(kvp.Value) && deployables.ContainsKey(kvp.Value) && deployables[kvp.Value] ? (object)false : null);
            }
        }
コード例 #4
0
        void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
            // Ignore if the entity is destroyed by decaying or not in list.
            if ((info?.damageTypes?.Has(DamageType.Decay) ?? true) ||
                !BuildingBlocks.ContainsKey(entity.ShortPrefabName))
            {
                return;
            }

            if (entity is BuildingBlock)
            {
                var block = entity as BuildingBlock;
                if (block.grade == BuildingGrade.Enum.Twigs)
                {
                    return;
                }
            }

            var tc = entity.GetBuildingPrivilege();

            // If there are no owners, ignore
            if (tc == null || tc.authorizedPlayers.Count == 0)
            {
                return;
            }

            // If the initiator has auth, ignore
            if (info?.InitiatorPlayer != null &&
                tc.authorizedPlayers.FirstOrDefault(
                    ap => ap.userid.ToString() == info.InitiatorPlayer.UserIDString) != null)
            {
                return;
            }


            SendAlert(BuildingBlocks[entity.ShortPrefabName],
                      tc.authorizedPlayers.Select(p => p.userid.ToString()).ToArray());

            tc.authorizedPlayers?.ForEach(player => Puts($"{player.username}({player.userid.ToString()})"));
        }
コード例 #5
0
        object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
        {
            if (info == null || info.damageTypes == null || entity == null || !info.damageTypes.Has(DamageType.Decay))
            {
                return(null);
            }

            BuildingPrivlidge priv = entity.GetBuildingPrivilege();

            if (config.General.usePermission && entity.OwnerID != 0 && !permission.UserHasPermission(priv == null ? entity.OwnerID.ToString() : GetOwnerPlayer(priv, entity.OwnerID), config.General.permission))
            {
                Output(lang.GetMessage("NoPermission", this).Replace("{0}", $"({entity.OwnerID})"));

                return(null);
            }
            else if (config.General.usePermission && !config.General.decayNoOwner && entity.OwnerID == 0)
            {
                return(true);
            }

            if (config.General.CupboardSettings.requireTC && !AnyToolCupboards(entity))
            {
                Output(lang.GetMessage("OutOfRange", this).Replace("{0}", entity.ShortPrefabName).Replace("{1}", $"{entity.transform.position}"));
                return(null);
            }

            if (entity is BuildingBlock)
            {
                info.damageTypes.ScaleAll(config.buildingMultipliers[(int)((BuildingBlock)entity).grade]);

                Output(lang.GetMessage("DecayBlocked", this).Replace("{0}", entity.ShortPrefabName).Replace("{1}", $"{entity.transform.position}"));
                if (!info.hasDamage)
                {
                    return(true);
                }

                return(null);
            }

            string matchingType = null;

            if (config.multipliers.ContainsKey(entity.ShortPrefabName) || IsOfType(entity, out matchingType))
            {
                if (config.General.excludeOthers)
                {
                    return(null);
                }
                else
                {
                    info.damageTypes.ScaleAll(config.multipliers[matchingType != null ? matchingType : entity.ShortPrefabName]);

                    Output(lang.GetMessage("DecayBlocked", this).Replace("{0}", entity.ShortPrefabName).Replace("{1}", $"{entity.transform.position}"));
                    if (!info.hasDamage)
                    {
                        return(true);
                    }
                }
            }

            if (config.General.disableAll)
            {
                return(true);
            }

            return(null);
        }
コード例 #6
0
        private bool?ProcessDecayDamage(BaseCombatEntity entity, HitInfo hitInfo)
        {
            if (entity == null || !hitInfo.damageTypes.Has(Rust.DamageType.Decay))
            {
                return(null);
            }

            float damageMultiplier = 1;

            VehicleConfig    vehicleConfig;
            string           vehicleSpecificNoDecayPerm;
            float            timeSinceLastUsed;
            BaseCombatEntity vehicle;
            ulong            lockOwnerId;

            if (!GetSupportedVehicleInformation(entity, out vehicleConfig, out vehicleSpecificNoDecayPerm, out timeSinceLastUsed, out vehicle))
            {
                return(null);
            }

            if (timeSinceLastUsed != 0 && timeSinceLastUsed < 60 * vehicleConfig.ProtectionMinutesAfterUse)
            {
                if (_pluginConfig.Debug)
                {
                    LogWarning($"{entity.ShortPrefabName}: Nullifying decay damage due to being recently used: {(int)timeSinceLastUsed}s < {60 * vehicleConfig.ProtectionMinutesAfterUse}s.");
                }

                damageMultiplier = 0;
            }
            else if (UserHasPermission(vehicle.OwnerID, vehicleSpecificNoDecayPerm))
            {
                if (_pluginConfig.Debug)
                {
                    LogWarning($"{entity.ShortPrefabName}: Nullifying decay damage due to owner permission. OwnerId: {vehicle.OwnerID}.");
                }

                damageMultiplier = 0;
            }
            else if (LockOwnerHasPermission(vehicle, vehicleSpecificNoDecayPerm, out lockOwnerId))
            {
                if (_pluginConfig.Debug)
                {
                    LogWarning($"{entity.ShortPrefabName}: Nullifying decay damage due to lock owner permission. OwnerId: {lockOwnerId}.");
                }

                damageMultiplier = 0;
            }
            else
            {
                if (vehicleConfig.DecayMultiplierInside != 1.0 && !entity.IsOutside())
                {
                    if (_pluginConfig.Debug)
                    {
                        LogWarning($"{entity.ShortPrefabName}: Multiplying decay damage due to being inside: x{vehicleConfig.DecayMultiplierInside}.");
                    }

                    damageMultiplier = vehicleConfig.DecayMultiplierInside;
                }

                // Skip building privilege check if damage multiplier is already 0.
                if (damageMultiplier != 0 && vehicleConfig.DecayMultiplierNearTC != 1.0 && entity.GetBuildingPrivilege() != null)
                {
                    if (_pluginConfig.Debug)
                    {
                        LogWarning($"{entity.ShortPrefabName}: Multiplying decay damage due to being near TC: x{vehicleConfig.DecayMultiplierNearTC}.");
                    }

                    damageMultiplier *= vehicleConfig.DecayMultiplierNearTC;
                }
            }

            if (damageMultiplier != 1)
            {
                hitInfo.damageTypes.Scale(Rust.DamageType.Decay, damageMultiplier);

                // If no damage, return true to prevent the vehicle being considered attacked (which would have prevented repair).
                if (!hitInfo.hasDamage)
                {
                    return(true);
                }
            }

            return(null);
        }