Exemple #1
0
        public static bool Prefix([NotNull] EntityAlive __instance, DamageResponse _dmResponse)
        {
            Log.Debug($"Executing patch prefix for {nameof(EntityDamaged)} ...");

            ScriptEvent eventType;

            if (__instance is EntityPlayer)
            {
                eventType = ScriptEvent.playerDamaged;
            }
            else if (__instance is EntityAnimal || __instance is EntityZombieDog || __instance is EntityEnemyAnimal || __instance is EntityHornet)
            {
                eventType = ScriptEvent.animalDamaged;
            }
            else if (__instance is EntityZombie)
            {
                eventType = ScriptEvent.zombieDamaged;
            }
            else
            {
                return(true);
            }

            CommandTools.InvokeScriptEvents(eventType, () =>
            {
                var sourceEntity     = GameManager.Instance.World?.GetEntity(_dmResponse.Source?.getEntityId() ?? -1) as EntityAlive;
                var targetClientInfo = ConnectionManager.Instance?.GetClientInfoForEntityId(__instance.entityId);
                var sourceClientInfo = ConnectionManager.Instance?.GetClientInfoForEntityId(sourceEntity?.entityId ?? -1);

                return(new EntityDamagedEventArgs
                {
                    position = __instance.GetBlockPosition(),
                    entityId = __instance.entityId,
                    entityName = __instance.EntityName,
                    entitySteamId = targetClientInfo?.playerId,
                    sourceEntityId = sourceEntity?.entityId,
                    sourceEntityName = sourceEntity?.EntityName,
                    sourceEntitySteamId = sourceClientInfo?.playerId,
                    damageType = _dmResponse.Source?.GetName().ToString(),
                    hitBodyPart = _dmResponse.HitBodyPart.ToString(),
                    hitDirection = _dmResponse.HitDirection.ToString(),
                    damage = _dmResponse.Strength,
                    armorDamage = _dmResponse.ArmorDamage,
                    armorSlot = _dmResponse.ArmorSlot.ToString(),
                    stunType = _dmResponse.Stun.ToString(),
                    stunDuration = _dmResponse.StunDuration,
                    critical = _dmResponse.Critical,
                    fatal = _dmResponse.Fatal,
                    crippleLegs = _dmResponse.CrippleLegs,
                    dismember = _dmResponse.Dismember,
                    turnIntoCrawler = _dmResponse.TurnIntoCrawler,
                    painHit = _dmResponse.PainHit,
                });
            });

            return(true);
        }