예제 #1
0
    public static bool Prefix(EModelBase __instance, Entity ___entity, Transform ___neckParentTransform, Transform ___headTransform, ref Vector3 ___lookAtPos, float ___lookAtMaxAngle,
                              ref Quaternion ___lookAtRot, Transform ___neckTransform, ref float ___lookAtBlendPer, ref float ___lookAtBlendPerTarget, bool ___lookAtIsPos)
    {
        EntityAliveSDX entityAlive = ___entity as EntityAliveSDX;

        if (!entityAlive)
        {
            return(true);
        }

        EnumEntityStunType currentStun = entityAlive.bodyDamage.CurrentStun;
        float deltaTime = Time.deltaTime;

        if (entityAlive.IsDead() || (currentStun != EnumEntityStunType.None && currentStun != EnumEntityStunType.Getup))
        {
            ___lookAtBlendPerTarget = 0f;
        }

        // If the entity has an attack target, look at them, instead of hte player.
        Entity target = EntityUtilities.GetAttackOrReventTarget(___entity.entityId);

        if (target != null)
        {
            ___lookAtBlendPerTarget -= deltaTime;
            if (target && entityAlive.CanSee(target as EntityAlive))
            {
                ___lookAtPos            = target.getHeadPosition();
                ___lookAtBlendPerTarget = 1f;
            }
        }
        if (___lookAtBlendPer <= 0f && ___lookAtBlendPerTarget <= 0f)
        {
            return(true);
        }
        ___lookAtBlendPer = Mathf.MoveTowards(___lookAtBlendPer, ___lookAtBlendPerTarget, deltaTime * 2f);

        Quaternion rotation3 = ___neckParentTransform.rotation;
        Transform  transform = ___headTransform;
        Vector3    upwards   = rotation3 * Vector3.up;
        Quaternion quaternion;

        quaternion  = Quaternion.LookRotation(___lookAtPos - Origin.position - transform.position);
        quaternion *= Quaternion.Slerp(Quaternion.identity, transform.localRotation, 0.5f);

        Quaternion b = Quaternion.RotateTowards(rotation3, quaternion, ___lookAtMaxAngle);

        ___lookAtRot = Quaternion.Slerp(___lookAtRot, b, 0.16f);
        float num = ___lookAtBlendPer;

        ___neckTransform.rotation = Quaternion.Slerp(___neckTransform.rotation, ___lookAtRot, num * 0.4f);
        Quaternion rotation2 = transform.rotation;

        transform.rotation = Quaternion.Slerp(rotation2, ___lookAtRot, num);
        return(false);
    }
예제 #2
0
    // On dedicated servers, when using an external animation class (MecanimSDX), the server incorrectly assigns a Dummy avatar, rather than our own.
    // We can get around this by disabling ragdolling on external entities, but it also generates warnings in the log file. This should jump in right before we do the
    // switchandmodel.
    static bool Prefix(ref EModelBase __instance, Entity ___entity)
    {
        EntityClass entityClass = EntityClass.list[___entity.entityClass];

        if (entityClass.Properties.Values.ContainsKey(EntityClass.PropAvatarController))
        {
            if (entityClass.Properties.Values[EntityClass.PropAvatarController].Contains("MecanimSDX") && __instance.avatarController is AvatarControllerDummy)
            {
                __instance.avatarController = (__instance.transform.gameObject.AddComponent(Type.GetType(entityClass.Properties.Values[EntityClass.PropAvatarController])) as AvatarController);
                __instance.avatarController.SetVisible(true);
            }
        }
        return(true);
    }
    public float GetTargetXZDistanceSq(int estimatedTicks)
    {
        Vector3 vector = this.entityTarget.position;

        vector += this.entityTargetVel * (float)estimatedTicks;
        if (this.isTargetToEat)
        {
            EModelBase emodel = this.entityTarget.emodel;
            if (emodel && emodel.bipedPelvisTransform)
            {
                vector = emodel.bipedPelvisTransform.position + Origin.position;
            }
        }
        Vector3 vector2 = this.theEntity.position + this.theEntity.motion * (float)estimatedTicks - vector;

        vector2.y = 0f;
        return(vector2.sqrMagnitude);
    }
예제 #4
0
        public static bool Prefix(EModelBase __instance, DamageResponse dr, float stunTime = 999999f)
        {
            float        strength = dr.Strength;
            DamageSource source   = dr.Source;

            var _difficultyModifiers = new Dictionary <int, float>()
            {
                { 0, 0.5f },
                { 1, 0.75f },
                { 3, 1.5f },
                { 4, 2.0f },
                { 5, 2.5f },
            };

            if (strength > 0.0 && source != null)
            {
                float angle = GameManager.Instance.World.GetGameRandom().RandomRange(-20f, 50f);
                float num1  = strength * 0.5f;
                if (source.damageType == EnumDamageTypes.Bashing)
                {
                    num1 *= 2.5f;
                }
                if (dr.Critical)
                {
                    angle += 25f;
                    num1  *= 2f;
                }
                if (dr.HitBodyPart == EnumBodyPartHit.Head)
                {
                    num1 *= 0.45f;
                }
                float   num2      = Utils.FastMin(20f + num1, 500f);
                Vector3 direction = source.getDirection();
                Vector3 axis      = Vector3.Cross(direction, Vector3.up);
                Vector3 forceVec  = Quaternion.AngleAxis(angle, axis) * direction * num2;

                var damageSourceEntity = GameManager.Instance.World.GetEntity(source.getEntityId());

                if (damageSourceEntity != null && dr.Fatal) // only run this logic if the hit was a kill
                {
                    var localPlayer = (damageSourceEntity as EntityPlayerLocal);

                    if (localPlayer != null && localPlayer.inventory != null) // there appears to be a strange timing issue when the inventory is null and throws an exception
                    {
                        var multiplier = 0.0f;

                        var holdingItem = localPlayer.inventory.holdingItem;

                        if (holdingItem.Properties.Contains("DeathForceMultiplier"))
                        {
                            var itemMultiplierString = holdingItem.Properties.GetString("DeathForceMultiplier");
                            if (!string.IsNullOrEmpty(itemMultiplierString))
                            {
                                var split = itemMultiplierString.Split(',');

                                if (split.Length > 1)
                                {
                                    multiplier = UnityEngine.Random.Range(float.Parse(split[0]), float.Parse(split[1]));
                                    Debug.Log(multiplier);
                                }
                                else
                                {
                                    multiplier = float.Parse(split[0]);
                                }
                            }
                        }

                        if (multiplier > 0)
                        {
                            var difficulty = GameStats.GetInt(EnumGameStats.GameDifficulty);

                            forceVec *= multiplier * _difficultyModifiers[difficulty];
                        }
                    }
                }

                __instance.DoRagdoll(stunTime, dr.HitBodyPart, forceVec, source.getHitTransformPosition(), false);
            }
            else
            {
                __instance.DoRagdoll(stunTime, dr.HitBodyPart, Vector3.zero, Vector3.zero, false);
            }

            return(false);
        }