public static void AttackBody(ComponentBody target, ComponentCreature attacker, Vector3 hitPoint, Vector3 hitDirection, float attackPower, bool isMeleeAttack) { if (attacker != null && attacker is ComponentPlayer && target.Entity.FindComponent <ComponentPlayer>() != null && !target.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true).WorldSettings.IsFriendlyFireEnabled) { attacker.Entity.FindComponent <ComponentGui>(throwOnError: true).DisplaySmallMessage(LanguageControl.Get(fName, 3), Color.White, blinking: true, playNotificationSound: true); return; } if (attackPower > 0f) { ComponentClothing componentClothing = target.Entity.FindComponent <ComponentClothing>(); if (componentClothing != null) { attackPower = componentClothing.ApplyArmorProtection(attackPower); } ComponentLevel componentLevel = target.Entity.FindComponent <ComponentLevel>(); if (componentLevel != null) { attackPower /= componentLevel.ResilienceFactor; } ComponentHealth componentHealth = target.Entity.FindComponent <ComponentHealth>(); if (componentHealth != null) { float num = attackPower / componentHealth.AttackResilience; string cause; if (attacker != null) { string str = attacker.KillVerbs[s_random.Int(0, attacker.KillVerbs.Count - 1)]; string attackerName = attacker.DisplayName; cause = string.Format(LanguageControl.Get(fName, 4), attackerName, LanguageControl.Get(fName, str)); } else { switch (s_random.Int(0, 5)) { case 0: cause = LanguageControl.Get(fName, 5); break; case 1: cause = LanguageControl.Get(fName, 6); break; case 2: cause = LanguageControl.Get(fName, 7); break; case 3: cause = LanguageControl.Get(fName, 8); break; case 4: cause = LanguageControl.Get(fName, 9); break; default: cause = LanguageControl.Get(fName, 10); break; } } float health = componentHealth.Health; componentHealth.Injure(num, attacker, ignoreInvulnerability: false, cause); if (num > 0f) { target.Project.FindSubsystem <SubsystemAudio>(throwOnError: true).PlayRandomSound("Audio/Impacts/Body", 1f, s_random.Float(-0.3f, 0.3f), target.Position, 4f, autoDelay: false); float num2 = (health - componentHealth.Health) * componentHealth.AttackResilience; if (attacker is ComponentPlayer && num2 > 0f) { string text2 = (0f - num2).ToString("0", CultureInfo.InvariantCulture); HitValueParticleSystem particleSystem = new HitValueParticleSystem(hitPoint + 0.75f * hitDirection, 1f * hitDirection + attacker.ComponentBody.Velocity, Color.White, text2); target.Project.FindSubsystem <SubsystemParticles>(throwOnError: true).AddParticleSystem(particleSystem); } } } ComponentDamage componentDamage = target.Entity.FindComponent <ComponentDamage>(); if (componentDamage != null) { float num3 = attackPower / componentDamage.AttackResilience; componentDamage.Damage(num3); if (num3 > 0f) { target.Project.FindSubsystem <SubsystemAudio>(throwOnError: true).PlayRandomSound(componentDamage.DamageSoundName, 1f, s_random.Float(-0.3f, 0.3f), target.Position, 4f, autoDelay: false); } } } float num4 = 0f; float x = 0f; if (isMeleeAttack && attacker != null) { float num5 = (attackPower >= 2f) ? 1.25f : 1f; float num6 = MathUtils.Pow(attacker.ComponentBody.Mass / target.Mass, 0.5f); float x2 = num5 * num6; num4 = 5.5f * MathUtils.Saturate(x2); x = 0.25f * MathUtils.Saturate(x2); } else if (attackPower > 0f) { num4 = 2f; x = 0.2f; } if (num4 > 0f) { target.ApplyImpulse(num4 * Vector3.Normalize(hitDirection + s_random.Vector3(0.1f) + 0.2f * Vector3.UnitY)); ComponentLocomotion componentLocomotion = target.Entity.FindComponent <ComponentLocomotion>(); if (componentLocomotion != null) { componentLocomotion.StunTime = MathUtils.Max(componentLocomotion.StunTime, x); } } }
public void Hit(ComponentBody componentBody, Vector3 hitPoint, Vector3 hitDirection) { if (Hit1 != null) { Hit1(componentBody, hitPoint, hitDirection); return; } if (!(m_subsystemTime.GameTime - m_lastHitTime > 0.6600000262260437)) { return; } m_lastHitTime = m_subsystemTime.GameTime; Block block = BlocksManager.Blocks[Terrain.ExtractContents(ActiveBlockValue)]; if (!CanUseTool(ActiveBlockValue)) { ComponentPlayer?.ComponentGui.DisplaySmallMessage(string.Format(LanguageControl.Get(fName, 1), block.PlayerLevelRequired, block.GetDisplayName(m_subsystemTerrain, ActiveBlockValue)), Color.White, blinking: true, playNotificationSound: true); Poke(forceRestart: false); return; } float num = 0f; float num2 = 1f; if (ActiveBlockValue != 0) { num = block.GetMeleePower(ActiveBlockValue) * AttackPower * m_random.Float(0.8f, 1.2f); num2 = block.GetMeleeHitProbability(ActiveBlockValue); } else { num = AttackPower * m_random.Float(0.8f, 1.2f); num2 = 0.66f; } bool flag; if (ComponentPlayer != null) { m_subsystemAudio.PlaySound("Audio/Swoosh", 1f, m_random.Float(-0.2f, 0.2f), componentBody.Position, 3f, autoDelay: false); flag = m_random.Bool(num2); num *= ComponentPlayer.ComponentLevel.StrengthFactor; } else { flag = true; } if (flag) { AttackBody(componentBody, ComponentCreature, hitPoint, hitDirection, num, isMeleeAttack: true); DamageActiveTool(1); } else if (ComponentCreature is ComponentPlayer) { HitValueParticleSystem particleSystem = new HitValueParticleSystem(hitPoint + 0.75f * hitDirection, 1f * hitDirection + ComponentCreature.ComponentBody.Velocity, Color.White, LanguageControl.Get(fName, 2)); base.Project.FindSubsystem <SubsystemParticles>(throwOnError: true).AddParticleSystem(particleSystem); } if (ComponentCreature.PlayerStats != null) { ComponentCreature.PlayerStats.MeleeAttacks++; if (flag) { ComponentCreature.PlayerStats.MeleeHits++; } } Poke(forceRestart: false); }