Ejemplo n.º 1
0
        public void OnDamage(ShPlayer player, DamageIndex damageIndex, float amount, ShPlayer attacker, Collider collider, Vector3 source, Vector3 hitPoint)
        {
            if (player.svPlayer.godMode || player.IsDead || player.IsShielded(damageIndex, collider))
            {
                return;
            }

            if (damageIndex != DamageIndex.Null)
            {
                BodyEffect effect;
                float      random = Random.value;

                if (random < 0.6f)
                {
                    effect = BodyEffect.Null;
                }
                else if (random < 0.8f)
                {
                    effect = BodyEffect.Pain;
                }
                else if (random < 0.925f)
                {
                    effect = BodyEffect.Bloodloss;
                }
                else
                {
                    effect = BodyEffect.Fracture;
                }

                BodyPart part;

                float capsuleHeight = player.capsule.direction == 1 ? player.capsule.height : player.capsule.radius * 2f;

                float hitY = player.GetLocalY(hitPoint);

                if (damageIndex == DamageIndex.Random)
                {
                    part = (BodyPart)Random.Range(0, (int)BodyPart.Count);
                }
                else if (damageIndex == DamageIndex.Melee && player.IsBlocking(damageIndex))
                {
                    part    = BodyPart.Arms;
                    amount *= 0.3f;
                }
                else if (collider == player.headCollider) // Headshot
                {
                    part    = BodyPart.Head;
                    amount *= 2f;
                }
                else if (hitY >= capsuleHeight * 0.75f)
                {
                    part = Random.value < 0.5f ? BodyPart.Arms : BodyPart.Chest;
                }
                else if (hitY >= capsuleHeight * 0.5f)
                {
                    part    = BodyPart.Abdomen;
                    amount *= 0.8f;
                }
                else
                {
                    part    = BodyPart.Legs;
                    amount *= 0.5f;
                }

                if (effect != BodyEffect.Null)
                {
                    player.svPlayer.SvAddInjury(part, effect, (byte)Random.Range(10, 50));
                }
            }

            if (!player.isHuman)
            {
                amount /= player.svPlayer.svManager.settings.difficulty;
            }

            amount -= amount * (player.armorLevel / 200f);

            base.OnDamage(player, damageIndex, amount, attacker, collider, source, hitPoint);

            if (player.IsDead)
            {
                return;
            }

            // Still alive, do knockdown and Assault crimes

            if (player.stance.setable)
            {
                if (player.isHuman && player.health < 15f)
                {
                    player.svPlayer.SvForceStance(StanceIndex.KnockedOut);
                    // If knockout AI, set AI state Null
                }
                else if (Random.value < player.manager.damageTypes[(int)damageIndex].fallChance)
                {
                    player.StartCoroutine(player.svPlayer.KnockedDown());
                }
            }

            if (attacker && attacker != player)
            {
                if (!player.isHuman)
                {
                    player.svPlayer.SetAttackState(attacker);
                }
                else
                {
                    var playerFollower = player.svPlayer.follower;
                    if (playerFollower)
                    {
                        playerFollower.svPlayer.SetAttackState(attacker);
                    }
                }

                var attackerFollower = attacker.svPlayer.follower;

                if (attackerFollower)
                {
                    attackerFollower.svPlayer.SetAttackState(player);
                }
            }
        }