public void OnDamage(ShPlayer player, DamageIndex damageIndex, float amount, ShPlayer attacker, Collider collider, float hitY) { 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; 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 >= player.capsule.height * 0.75f) { part = Random.value < 0.5f ? BodyPart.Arms : BodyPart.Chest; } else if (hitY >= player.capsule.height * 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 / player.maxStat * 0.5f); base.OnDamage(player, damageIndex, amount, attacker, collider, hitY); 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 { ShPlayer playerFollower = player.svPlayer.follower; if (playerFollower) { playerFollower.svPlayer.SetAttackState(attacker); } } ShPlayer attackerFollower = attacker.svPlayer.follower; if (attackerFollower) { attackerFollower.svPlayer.SetAttackState(player); } } }
public void OnDamage(ShPlayer player, DamageIndex damageIndex, float amount, ShPlayer attacker, Collider collider) { if (player.IsDead || player.IsShielded(damageIndex, collider)) { return; } if (player.IsBlocking(damageIndex)) { amount *= 0.3f; } else if (collider == player.headCollider) // Headshot { amount *= 2f; } if (!player.isHuman) { amount /= player.svPlayer.svManager.settings.difficulty; } amount -= amount * (player.armorLevel / player.maxStat * 0.5f); base.OnDamage(player, damageIndex, amount, attacker, collider); 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 (UnityEngine.Random.value < player.manager.damageTypes[(int)damageIndex].fallChance) { player.StartCoroutine(player.svPlayer.KnockedDown()); } } if (attacker && attacker != player) { if (player.wantedLevel == 0) { if (attacker.curEquipable is ShGun) { attacker.svPlayer.SvAddCrime(CrimeIndex.ArmedAssault, player); } else { attacker.svPlayer.SvAddCrime(CrimeIndex.Assault, player); } } if (!player.isHuman) { player.svPlayer.targetEntity = attacker; player.svPlayer.SetState(StateIndex.Attack); } } }