public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemGameInfo = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true); m_subsystemSky = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true); m_subsystemParticles = base.Project.FindSubsystem <SubsystemParticles>(throwOnError: true); m_subsystemAudio = base.Project.FindSubsystem <SubsystemAudio>(throwOnError: true); m_componentSpawn = base.Entity.FindComponent <ComponentSpawn>(throwOnError: true); m_componentBody = base.Entity.FindComponent <ComponentBody>(throwOnError: true); m_componentHealth = base.Entity.FindComponent <ComponentHealth>(throwOnError: true); m_dayEntityTemplateName = valuesDictionary.GetValue <string>("DayEntityTemplateName"); m_nightEntityTemplateName = valuesDictionary.GetValue <string>("NightEntityTemplateName"); float value = valuesDictionary.GetValue <float>("Probability"); if (!string.IsNullOrEmpty(m_dayEntityTemplateName)) { DatabaseManager.FindEntityValuesDictionary(m_dayEntityTemplateName, throwIfNotFound: true); } if (!string.IsNullOrEmpty(m_nightEntityTemplateName)) { DatabaseManager.FindEntityValuesDictionary(m_nightEntityTemplateName, throwIfNotFound: true); } m_timeToSwitch = s_random.Float(3f, 15f); IsEnabled = (s_random.Float(0f, 1f) < value); m_componentSpawn.Despawned += ComponentSpawn_Despawned; }
public override bool OnUse(Ray3 ray, ComponentMiner componentMiner) { BodyRaycastResult?bodyRaycastResult = componentMiner.Raycast <BodyRaycastResult>(ray, RaycastMode.Interaction); if (bodyRaycastResult.HasValue) { ComponentHealth componentHealth = bodyRaycastResult.Value.ComponentBody.Entity.FindComponent <ComponentHealth>(); if (componentHealth == null || componentHealth.Health > 0f) { string entityTemplateName = bodyRaycastResult.Value.ComponentBody.Entity.ValuesDictionary.DatabaseObject.Name + "_Saddled"; Entity entity = DatabaseManager.CreateEntity(base.Project, entityTemplateName, throwIfNotFound: false); if (entity != null) { ComponentBody componentBody = entity.FindComponent <ComponentBody>(throwOnError: true); componentBody.Position = bodyRaycastResult.Value.ComponentBody.Position; componentBody.Rotation = bodyRaycastResult.Value.ComponentBody.Rotation; componentBody.Velocity = bodyRaycastResult.Value.ComponentBody.Velocity; entity.FindComponent <ComponentSpawn>(throwOnError: true).SpawnDuration = 0f; base.Project.RemoveEntity(bodyRaycastResult.Value.ComponentBody.Entity, disposeEntity: true); base.Project.AddEntity(entity); m_subsystemAudio.PlaySound("Audio/BlockPlaced", 1f, m_random.Float(-0.1f, 0.1f), ray.Position, 1f, autoDelay: true); componentMiner.RemoveActiveTool(1); } } return(true); } return(false); }
public void Update(float dt) { if (m_isAnimating) { float f = 8f * dt; ComponentBody componentBody = ComponentCreature.ComponentBody; componentBody.ParentBodyPositionOffset = Vector3.Lerp(componentBody.ParentBodyPositionOffset, m_targetPositionOffset, f); componentBody.ParentBodyRotationOffset = Quaternion.Slerp(componentBody.ParentBodyRotationOffset, m_targetRotationOffset, f); m_animationTime += dt; if (Vector3.DistanceSquared(componentBody.ParentBodyPositionOffset, m_targetPositionOffset) < 0.0100000007f || m_animationTime > 0.75f) { m_isAnimating = false; if (m_isDismounting) { if (componentBody.ParentBody != null) { componentBody.Velocity = componentBody.ParentBody.Velocity; componentBody.ParentBody = null; } } else { componentBody.ParentBodyPositionOffset = m_targetPositionOffset; componentBody.ParentBodyRotationOffset = m_targetRotationOffset; m_outOfMountTime = 0f; } } } ComponentMount mount = Mount; if (mount != null && !m_isAnimating) { ComponentBody componentBody2 = ComponentCreature.ComponentBody; ComponentBody parentBody = ComponentCreature.ComponentBody.ParentBody; if (Vector3.DistanceSquared(parentBody.Position + Vector3.Transform(componentBody2.ParentBodyPositionOffset, parentBody.Rotation), componentBody2.Position) > 0.160000011f) { m_outOfMountTime += dt; } else { m_outOfMountTime = 0f; } ComponentHealth componentHealth = mount.Entity.FindComponent <ComponentHealth>(); if (m_outOfMountTime > 0.1f || (componentHealth != null && componentHealth.Health <= 0f) || ComponentCreature.ComponentHealth.Health <= 0f) { StartDismounting(); } ComponentCreature.ComponentBody.ParentBodyPositionOffset = mount.MountOffset + m_riderOffset; ComponentCreature.ComponentBody.ParentBodyRotationOffset = Quaternion.Identity; } }
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 Update(float dt) { CollisionVelocityChange = Vector3.Zero; Velocity += m_totalImpulse; m_totalImpulse = Vector3.Zero; if (m_parentBody != null || m_velocity.LengthSquared() > 9.99999944E-11f || m_directMove != Vector3.Zero) { m_stoppedTime = 0f; } else { m_stoppedTime += dt; if (m_stoppedTime > 0.5f && !Time.PeriodicEvent(0.25, 0.0)) { return; } } Vector3 position = base.Position; TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(Terrain.ToCell(position.X), Terrain.ToCell(position.Z)); if (chunkAtCell == null || chunkAtCell.State <= TerrainChunkState.InvalidContents4) { Velocity = Vector3.Zero; return; } m_bodiesCollisionBoxes.Clear(); FindBodiesCollisionBoxes(position, m_bodiesCollisionBoxes); m_movingBlocksCollisionBoxes.Clear(); FindMovingBlocksCollisionBoxes(position, m_movingBlocksCollisionBoxes); if (!MoveToFreeSpace()) { ComponentHealth componentHealth = base.Entity.FindComponent <ComponentHealth>(); if (componentHealth != null) { componentHealth.Injure(1f, null, ignoreInvulnerability: true, "Crushed"); } else { base.Project.RemoveEntity(base.Entity, disposeEntity: true); } return; } if (IsGravityEnabled) { m_velocity.Y -= 10f * dt; if (ImmersionFactor > 0f) { float num = ImmersionFactor * (1f + 0.03f * MathUtils.Sin((float)MathUtils.Remainder(2.0 * m_subsystemTime.GameTime, 6.2831854820251465))); m_velocity.Y += 10f * (1f / Density * num) * dt; } } float num2 = MathUtils.Saturate(AirDrag.X * dt); float num3 = MathUtils.Saturate(AirDrag.Y * dt); m_velocity.X *= 1f - num2; m_velocity.Y *= 1f - num3; m_velocity.Z *= 1f - num2; if (IsWaterDragEnabled && ImmersionFactor > 0f && ImmersionFluidBlock != null) { Vector2?vector = m_subsystemFluidBlockBehavior.CalculateFlowSpeed(Terrain.ToCell(position.X), Terrain.ToCell(position.Y), Terrain.ToCell(position.Z)); Vector3 vector2 = vector.HasValue ? new Vector3(vector.Value.X, 0f, vector.Value.Y) : Vector3.Zero; float num4 = 1f; if (ImmersionFluidBlock.FrictionFactor != 1f) { num4 = ((SimplexNoise.Noise((float)MathUtils.Remainder(6.0 * Time.FrameStartTime + (double)(GetHashCode() % 1000), 1000.0)) > 0.5f) ? ImmersionFluidBlock.FrictionFactor : 1f); } float f = MathUtils.Saturate(WaterDrag.X * num4 * ImmersionFactor * dt); float f2 = MathUtils.Saturate(WaterDrag.Y * num4 * dt); m_velocity.X = MathUtils.Lerp(m_velocity.X, vector2.X, f); m_velocity.Y = MathUtils.Lerp(m_velocity.Y, vector2.Y, f2); m_velocity.Z = MathUtils.Lerp(m_velocity.Z, vector2.Z, f); if (m_parentBody == null && vector.HasValue && !StandingOnValue.HasValue) { if (WaterTurnSpeed > 0f) { float s = MathUtils.Saturate(MathUtils.Lerp(1f, 0f, m_velocity.Length())); Vector2 vector3 = Vector2.Normalize(vector.Value) * s; base.Rotation *= Quaternion.CreateFromAxisAngle(Vector3.UnitY, WaterTurnSpeed * (-1f * vector3.X + 0.71f * vector3.Y) * dt); } if (WaterSwayAngle > 0f) { base.Rotation *= Quaternion.CreateFromAxisAngle(Vector3.UnitX, WaterSwayAngle * (float)MathUtils.Sin((double)(200f / Mass) * m_subsystemTime.GameTime)); } } } if (m_parentBody != null) { Vector3 v = Vector3.Transform(ParentBodyPositionOffset, m_parentBody.Rotation) + m_parentBody.Position - position; m_velocity = ((dt > 0f) ? (v / dt) : Vector3.Zero); base.Rotation = ParentBodyRotationOffset * m_parentBody.Rotation; } StandingOnValue = null; StandingOnBody = null; StandingOnVelocity = Vector3.Zero; Vector3 velocity = m_velocity; float num5 = m_velocity.Length(); if (num5 > 0f) { float x = 0.45f * MathUtils.Min(BoxSize.X, BoxSize.Y, BoxSize.Z) / num5; float num6 = dt; while (num6 > 0f) { float num7 = MathUtils.Min(num6, x); MoveWithCollision(num7, m_velocity * num7 + m_directMove); m_directMove = Vector3.Zero; num6 -= num7; } } CollisionVelocityChange = m_velocity - velocity; if (IsGroundDragEnabled && StandingOnValue.HasValue) { m_velocity = Vector3.Lerp(m_velocity, StandingOnVelocity, 6f * dt); } if (!StandingOnValue.HasValue) { IsSneaking = false; } UpdateImmersionData(); if (ImmersionFluidBlock is WaterBlock && ImmersionDepth > 0.3f && !m_fluidEffectsPlayed) { m_fluidEffectsPlayed = true; m_subsystemAudio.PlayRandomSound("Audio/WaterFallIn", m_random.Float(0.75f, 1f), m_random.Float(-0.3f, 0f), position, 4f, autoDelay: true); m_subsystemParticles.AddParticleSystem(new WaterSplashParticleSystem(m_subsystemTerrain, position, (BoundingBox.Max - BoundingBox.Min).Length() > 0.8f)); } else if (ImmersionFluidBlock is MagmaBlock && ImmersionDepth > 0f && !m_fluidEffectsPlayed) { m_fluidEffectsPlayed = true; m_subsystemAudio.PlaySound("Audio/SizzleLong", 1f, 0f, position, 4f, autoDelay: true); m_subsystemParticles.AddParticleSystem(new MagmaSplashParticleSystem(m_subsystemTerrain, position, (BoundingBox.Max - BoundingBox.Min).Length() > 0.8f)); } else if (ImmersionFluidBlock == null) { m_fluidEffectsPlayed = false; } }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemTerrain = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true); m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_subsystemNoise = base.Project.FindSubsystem <SubsystemNoise>(throwOnError: true); m_componentCreature = base.Entity.FindComponent <ComponentCreature>(throwOnError: true); m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true); m_componentHerdBehavior = base.Entity.FindComponent <ComponentHerdBehavior>(); m_componentCreature.ComponentHealth.Attacked += delegate(ComponentCreature attacker) { RunAwayFrom(attacker.ComponentBody); }; m_stateMachine.AddState("Inactive", delegate { m_importanceLevel = 0f; m_lastNoiseSourcePosition = null; }, delegate { if (m_attacker != null) { m_timeToForgetAttacker -= m_subsystemTime.GameTimeDelta; if (m_timeToForgetAttacker <= 0f) { m_attacker = null; } } if (m_componentCreature.ComponentHealth.HealthChange < 0f || (m_attacker != null && Vector3.DistanceSquared(m_attacker.Position, m_componentCreature.ComponentBody.Position) < 36f)) { m_importanceLevel = MathUtils.Max(m_importanceLevel, (m_componentCreature.ComponentHealth.Health < 0.33f) ? 300 : 100); } else if (m_heardNoise) { m_importanceLevel = MathUtils.Max(m_importanceLevel, 5f); } else if (!IsActive) { m_importanceLevel = 0f; } if (IsActive) { m_stateMachine.TransitionTo("RunningAway"); } }, null); m_stateMachine.AddState("RunningAway", delegate { Vector3 value = FindSafePlace(); m_componentPathfinding.SetDestination(value, 1f, 1f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null); m_componentCreature.ComponentCreatureSounds.PlayPainSound(); m_subsystemNoise.MakeNoise(m_componentCreature.ComponentBody, 0.25f, 6f); }, delegate { if (!IsActive) { m_stateMachine.TransitionTo("Inactive"); } else if (!m_componentPathfinding.Destination.HasValue || m_componentPathfinding.IsStuck) { m_importanceLevel = 0f; } else if (m_attacker != null) { if (!m_attacker.IsAddedToProject) { m_importanceLevel = 0f; m_attacker = null; } else { ComponentHealth componentHealth = m_attacker.Entity.FindComponent <ComponentHealth>(); if (componentHealth != null && componentHealth.Health == 0f) { m_importanceLevel = 0f; m_attacker = null; } } } }, null); m_stateMachine.TransitionTo("Inactive"); }