Example #1
0
    public static DamageType GetDamageType(this DamageHandlerBase handler)
    {
        if (handler == null)
        {
            return(DamageType.Unknown);
        }

        if (Enum.TryParse <DamageType>(handler.GetType().Name.Replace("DamageHandler", ""), out var type))
        {
            if (type == DamageType.Universal)
            {
                var id = (handler as UniversalDamageHandler).TranslationId;

                if (id < 0 || id > 23)
                {
                    return(DamageType.Universal);
                }

                return((DamageType)id);
            }

            return(type);
        }

        return(DamageType.Unknown);
    }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DiedEventArgs"/> class.
        /// </summary>
        /// <param name="target"><inheritdoc cref="Target"/></param>
        /// <param name="damageHandler"><inheritdoc cref="DamageHandler"/></param>
        public DiedEventArgs(Player target, DamageHandlerBase damageHandler)
        {
            Killer = damageHandler is AttackerDamageHandler attackerDamageHandler?Player.Get(attackerDamageHandler.Attacker.Hub) : null;

            Target  = target;
            Handler = new DamageHandler(target, damageHandler);
        }
Example #3
0
        private static bool OnDeath(PlayerStats __instance, DamageHandlerBase handler, out bool __state)
        {
            try
            {
                var standardhandler = handler as StandardDamageHandler;
                var type            = handler.GetDamageType();
                var victim          = __instance.GetPlayer();
                var attacker        = handler is AttackerDamageHandler ahandler?ahandler.Attacker.GetPlayer() : null;

                if (type == DamageType.PocketDecay)
                {
                    attacker = Server.Get.Players.FirstOrDefault(x => x.Scp106Controller.PocketPlayers.Contains(victim));
                }

                SynapseController.Server.Events.Player.InvokePlayerDeathEvent(victim, attacker, type, out var allow);

                if (!allow)
                {
                    victim.Health = 1;
                }
                if (allow)
                {
                    victim.DeathPosition = victim.Position;
                }
                __state = allow;
                return(allow);
            }
            catch (Exception e)
            {
                __state = true;
                Logger.Get.Error($"Synapse-Event: PlayerDeath event failed!!\n{e}");
                return(true);
            }
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DyingEventArgs"/> class.
        /// </summary>
        /// <param name="target"><inheritdoc cref="Target"/></param>
        /// <param name="damageHandler"><inheritdoc cref="DamageHandler"/></param>
        public DyingEventArgs(Player target, DamageHandlerBase damageHandler)
        {
            ItemsToDrop = new List <Item>(target.Items.ToList());
            Killer      = damageHandler is AttackerDamageHandler attackerDamageHandler?Player.Get(attackerDamageHandler.Attacker.Hub) : null;

            Target  = target;
            Handler = new DamageHandler(target, damageHandler);
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DamageHandler"/> class.
        /// </summary>
        /// <param name="target">The <see cref="Player"/> target of the handler.</param>
        /// <param name="handlerBase">The <see cref="DamageHandlerBase"/> to initialize from.</param>
        public DamageHandler(Player target, DamageHandlerBase handlerBase)
        {
            Base     = handlerBase;
            Target   = target;
            Attacker = handlerBase is AttackerDamageHandler attacker?Player.Get(attacker.Attacker.Hub) : null;

            Item = handlerBase is FirearmDamageHandler ? Attacker.CurrentItem : null;
        }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SpawningRagdollEventArgs"/> class.
 /// </summary>
 /// <param name="ragdollInfo"><inheritdoc cref="Info"/></param>
 /// <param name="damageHandlerBase"><inheritdoc cref="DamageHandlerBase"/></param>
 /// <param name="isAllowed"><inheritdoc cref="IsAllowed"/></param>
 public SpawningRagdollEventArgs(
     RagdollInfo ragdollInfo,
     DamageHandlerBase damageHandlerBase,
     bool isAllowed = true)
 {
     Info = ragdollInfo;
     DamageHandlerBase = damageHandlerBase;
     Owner             = Player.Get(ragdollInfo.OwnerHub);
     IsAllowed         = isAllowed;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="AnnouncingScpTerminationEventArgs"/> class.
        /// </summary>
        /// <param name="scp"><inheritdoc cref="Player"/></param>
        /// <param name="damageHandlerBase"><inheritdoc cref="DamageHandler"/></param>
        /// <param name="isAllowed"><inheritdoc cref="IsAllowed"/></param>
        public AnnouncingScpTerminationEventArgs(Player scp, DamageHandlerBase damageHandlerBase, bool isAllowed = true)
        {
            Player  = scp;
            Role    = scp.ReferenceHub.characterClassManager.CurRole;
            Handler = new DamageHandler(scp, damageHandlerBase);
            Killer  = damageHandlerBase is AttackerDamageHandler attackerDamageHandler?API.Features.Player.Get(attackerDamageHandler.Attacker.Hub) : null;

            TerminationCause = damageHandlerBase.CassieDeathAnnouncement;
            IsAllowed        = isAllowed;
        }
Example #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Ragdoll"/> class.
        /// </summary>
        /// <param name="player">The ragdoll's <see cref="Player">owner</see>.</param>
        /// <param name="handler">The player's <see cref="DamageHandlerBase"/>.</param>
        /// <param name="canBeSpawned">A value that represents whether the ragdoll can be spawned.</param>
        public Ragdoll(Player player, DamageHandlerBase handler, bool canBeSpawned = false)
        {
            GameObject model_ragdoll = player.ReferenceHub.characterClassManager.CurRole.model_ragdoll;

            if (model_ragdoll is null || !Object.Instantiate(model_ragdoll).TryGetComponent(out RagDoll ragdoll))
            {
                return;
            }
            ragdoll.NetworkInfo = new RagdollInfo(player.ReferenceHub, handler, model_ragdoll.transform.localPosition, model_ragdoll.transform.localRotation);
            this.ragdoll        = ragdoll;
            Map.RagdollsValue.Add(this);
            if (canBeSpawned)
            {
                Spawn();
            }
        }
Example #9
0
 private static bool WriteDamageHandler(NetworkWriter writer, DamageHandlerBase info)
 {
     try
     {
         if (info?.GetType() == typeof(Turret.SynapseTurretDamageHandler))
         {
             writer?.WriteByte(DamageHandlers.IdsByTypeHash[typeof(CustomReasonDamageHandler).FullName.GetStableHashCode()]);
             info?.WriteAdditionalData(writer);
             return(false);
         }
         return(true);
     }
     catch (Exception ex)
     {
         Logger.Get.Error("Synapse-Turret: Failed to write Data of SynapseTurretDamageHandler:\n" + ex);
         return(true);
     }
 }
Example #10
0
        private static bool OnDamage(HitboxIdentity __instance, DamageHandlerBase handler)
        {
            try
            {
                if (handler is AttackerDamageHandler ahandler)
                {
                    var ply      = __instance.TargetHub.GetPlayer();
                    var attacker = ahandler.Attacker.GetPlayer();
                    Logger.Get.Debug($"{ply == null} - {attacker == null}");
                    return(SynapseExtensions.GetHarmPermission(attacker, ply));
                }
            }
            catch (Exception ex)
            {
                Logger.Get.Error($"Synapse-FF: PlayerDamage failed!!\n{ex}");
            }

            return(true);
        }
Example #11
0
        /// <summary>
        /// Announce the termination of a custom SCP name.
        /// </summary>
        /// <param name="scpname">SCP Name.</param>
        /// <param name="info">Hit Information.</param>
        public static void CustomSCPTermination(string scpname, DamageHandlerBase info)
        {
            string result = scpname;

            if (info is MicroHidDamageHandler)
            {
                result += " SUCCESSFULLY TERMINATED BY AUTOMATIC SECURITY SYSTEM";
            }
            else if (info is WarheadDamageHandler)
            {
                result += " SUCCESSFULLY TERMINATED BY ALPHA WARHEAD";
            }
            else if (info is UniversalDamageHandler)
            {
                result += " LOST IN DECONTAMINATION SEQUENCE";
            }
            else if (info is FirearmDamageHandler firearmDamageHandler && Player.Get(firearmDamageHandler.Attacker.Hub) is Player attacker)
            {
                result += " CONTAINEDSUCCESSFULLY " + ConvertTeam(attacker.Team, attacker.UnitName);
            }
Example #12
0
        private static bool DealDamagePatch(PlayerStats __instance, DamageHandlerBase handler)
        {
            try
            {
                if (!__instance._hub.characterClassManager.IsAlive ||
                    __instance._hub.characterClassManager.GodMode)
                {
                    return(false);
                }

                var standardhandler = handler as StandardDamageHandler;
                var type            = handler.GetDamageType();
                var victim          = __instance.GetPlayer();
                var attacker        = handler is AttackerDamageHandler ahandler?ahandler.Attacker.GetPlayer() : null;

                var damage = standardhandler.Damage;

                if (type == DamageType.PocketDecay)
                {
                    attacker = Server.Get.Players.FirstOrDefault(x => x.Scp106Controller.PocketPlayers.Contains(victim));
                    if (attacker != null && !SynapseExtensions.GetHarmPermission(attacker, victim))
                    {
                        return(false);
                    }
                }

                SynapseController.Server.Events.Player.InvokePlayerDamageEvent(victim, attacker, ref damage, type, out var allow);
                standardhandler.Damage = damage;

                return(allow);
            }
            catch (Exception e)
            {
                Logger.Get.Error($"Synapse-Event: PlayerDamage event failed!!\n{e}");
                return(true);
            }
        }
Example #13
0
        private static bool Prefix(ShootingTarget __instance, ref bool __result, float damage, DamageHandlerBase handler, Vector3 exactHit)
        {
            try
            {
                if (handler is not AttackerDamageHandler attackerDamageHandler)
                {
                    __result = false;
                    return(false);
                }

                if (attackerDamageHandler.Attacker.Hub is null)
                {
                    __result = false;
                    return(false);
                }

                DamagingShootingTargetEventArgs ev = new(
                    Player.Get(attackerDamageHandler.Attacker.Hub),
                    damage,
                    Vector3.Distance(attackerDamageHandler.Attacker.Hub.transform.position, __instance._bullsEye.position),
                    exactHit,
                    __instance,
                    handler);
                Handlers.Player.OnDamagingShootingTarget(ev);

                if (!ev.IsAllowed)
                {
                    __result = false;
                    return(false);
                }

                foreach (ReferenceHub referenceHub in ReferenceHub.GetAllHubs().Values)
                {
                    if (__instance._syncMode || referenceHub == attackerDamageHandler.Attacker.Hub)
                    {
                        __instance.TargetRpcReceiveData(referenceHub.characterClassManager.connectionToClient, ev.Amount, ev.Distance, exactHit, handler);
                    }
                }

                __result = true;
                return(false);
            }
            catch (Exception exception)
            {
                Log.Error($"{typeof(DamagingShootingTarget).FullName}.{nameof(Prefix)}:\n{exception}");
                return(false);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DamagingShootingTargetEventArgs"/> class.
 /// </summary>
 /// <param name="player"><inheritdoc cref="Player"/></param>
 /// <param name="damage"><inheritdoc cref="Amount"/></param>
 /// <param name="distance"><inheritdoc cref="Distance"/></param>
 /// <param name="shootingTarget"><inheritdoc cref="ShootingTarget"/></param>
 /// <param name="damageHandler"><inheritdoc cref="Item"/></param>
 /// <param name="hitLocation"><inheritdoc cref="HitLocation"/></param>
 /// <param name="isAllowed"><inheritdoc cref="IsAllowed"/></param>
 public DamagingShootingTargetEventArgs(Player player, float damage, float distance, Vector3 hitLocation, AdminToys.ShootingTarget shootingTarget, DamageHandlerBase damageHandler, bool isAllowed = true)
 {
     Player         = player;
     Amount         = damage;
     Distance       = distance;
     ShootingTarget = ShootingTargetToy.Get(shootingTarget);
     Item           = player.CurrentItem;
     DamageHandler  = (AttackerDamageHandler)damageHandler;
     HitLocation    = hitLocation;
     IsAllowed      = isAllowed;
 }
Example #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OwnerDyingEventArgs"/> class.
 /// </summary>
 /// <param name="item"><inheritdoc cref="Item"/></param>
 /// <param name="target"><inheritdoc cref="DyingEventArgs.Target"/></param>
 /// <param name="damageHandler"><inheritdoc cref="DyingEventArgs.DamageHandler"/></param>
 public OwnerDyingEventArgs(Item item, Player target, DamageHandlerBase damageHandler)
     : base(target, damageHandler)
 {
     Item = item;
 }
Example #16
0
 public bool Hurt(DamageHandlerBase handlerbase) => PlayerStats.DealDamage(handlerbase);
Example #17
0
 /// <summary>
 /// Announce a SCP Termination.
 /// </summary>
 /// <param name="scp">SCP to announce termination of.</param>
 /// <param name="info">HitInformation.</param>
 public static void SCPTermination(Player scp, DamageHandlerBase info)
 => NineTailedFoxAnnouncer.AnnounceScpTermination(scp.ReferenceHub, info);