public void Update(float dt) { if (m_subsystemTime.PeriodicGameTimeEvent(2.5, 0.0)) { foreach (Point3 key2 in m_toDegrade.Keys) { if (base.SubsystemTerrain.Terrain.GetCellContents(key2.X, key2.Y, key2.Z) == 168) { int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(key2.X, key2.Y, key2.Z); base.SubsystemTerrain.ChangeCell(key2.X, key2.Y, key2.Z, Terrain.ReplaceContents(cellValue, 2)); } } m_toDegrade.Clear(); } if (m_subsystemTime.PeriodicGameTimeEvent(10.0, 0.0)) { foreach (KeyValuePair <Point3, bool> item in m_toHydrate) { Point3 key = item.Key; bool value = item.Value; int cellValue2 = base.SubsystemTerrain.Terrain.GetCellValue(key.X, key.Y, key.Z); if (Terrain.ExtractContents(cellValue2) == 168) { int data = SoilBlock.SetHydration(Terrain.ExtractData(cellValue2), value); int value2 = Terrain.ReplaceData(cellValue2, data); base.SubsystemTerrain.ChangeCell(key.X, key.Y, key.Z, value2); } } m_toHydrate.Clear(); } }
public void Update(float dt) { m_stateMachine.Update(); if (SpeedOrder != 0 || TurnOrder != 0f || JumpOrder != 0f) { SpeedOrder = 0; TurnOrder = 0f; JumpOrder = 0f; WasOrderIssued = true; } else { WasOrderIssued = false; } if (m_subsystemTime.PeriodicGameTimeEvent(1.0, (float)(GetHashCode() % 100) * 0.01f)) { m_importanceLevel = 0f; if (m_isEnabled) { if (m_componentMount.Rider != null) { m_importanceLevel = 275f; } else if (FindNearbyRider(7f) != null) { m_importanceLevel = 7f; } } } if (!IsActive) { m_stateMachine.TransitionTo("Inactive"); } }
public void Update(float dt) { if (m_subsystemTime.PeriodicGameTimeEvent(60.0, 0.0)) { foreach (KeyValuePair <Point3, int> item in m_toUpdate) { if (Terrain.ExtractContents(item.Value) == 8) { if (base.SubsystemTerrain.Terrain.GetCellContents(item.Key.X, item.Key.Y, item.Key.Z) != 2) { continue; } } else { int cellContents = base.SubsystemTerrain.Terrain.GetCellContents(item.Key.X, item.Key.Y - 1, item.Key.Z); if ((cellContents != 8 && cellContents != 2) || base.SubsystemTerrain.Terrain.GetCellContents(item.Key.X, item.Key.Y, item.Key.Z) != 0) { continue; } } base.SubsystemTerrain.ChangeCell(item.Key.X, item.Key.Y, item.Key.Z, item.Value); } m_toUpdate.Clear(); } }
public void Update(float dt) { if (m_subsystemTime.PeriodicGameTimeEvent(5.0, 0.0)) { m_updateIndex++; foreach (Point3 key in m_particleSystemsByCell.Keys) { PrecipitationShaftInfo precipitationShaftInfo = m_subsystemWeather.GetPrecipitationShaftInfo(key.X, key.Z); if ((precipitationShaftInfo.Intensity > 0f && key.Y >= precipitationShaftInfo.YLimit - 1) || m_updateIndex % 5 == 0) { m_toReduce.Add(key); } } foreach (Point3 item in m_toReduce) { ResizeCampfire(item.X, item.Y, item.Z, -1, playSound: true); } m_toReduce.Clear(); } if (Time.PeriodicEvent(0.5, 0.0)) { float num = float.MaxValue; foreach (Point3 key2 in m_particleSystemsByCell.Keys) { float x = m_subsystemAmbientSounds.SubsystemAudio.CalculateListenerDistanceSquared(new Vector3(key2.X, key2.Y, key2.Z)); num = MathUtils.Min(num, x); } m_fireSoundVolume = m_subsystemAmbientSounds.SubsystemAudio.CalculateVolume(MathUtils.Sqrt(num), 2f); } m_subsystemAmbientSounds.FireSoundVolume = MathUtils.Max(m_subsystemAmbientSounds.FireSoundVolume, m_fireSoundVolume); }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_subsystemGameInfo = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true); m_componentCreature = base.Entity.FindComponent <ComponentCreature>(throwOnError: true); m_componentMount = base.Entity.FindComponent <ComponentMount>(throwOnError: true); m_componentSteedBehavior = base.Entity.FindComponent <ComponentSteedBehavior>(throwOnError: true); m_componentEatPickableBehavior = base.Entity.FindComponent <ComponentEatPickableBehavior>(throwOnError: true); m_stubbornProbability = valuesDictionary.GetValue <float>("StubbornProbability"); m_stubbornEndTime = valuesDictionary.GetValue <double>("StubbornEndTime"); m_periodicEventOffset = m_random.Float(0f, 100f); m_isSaddled = base.Entity.ValuesDictionary.DatabaseObject.Name.EndsWith("_Saddled"); m_stateMachine.AddState("Inactive", null, delegate { if (m_subsystemTime.PeriodicGameTimeEvent(1.0, m_periodicEventOffset) && m_componentMount.Rider != null && m_random.Float(0f, 1f) < m_stubbornProbability && (!m_isSaddled || m_componentEatPickableBehavior.Satiation <= 0f)) { m_stubbornEndTime = m_subsystemGameInfo.TotalElapsedGameTime + (double)m_random.Float(60f, 120f); } if (IsActive) { m_stateMachine.TransitionTo("Stubborn"); } }, null); m_stateMachine.AddState("Stubborn", null, delegate { if (m_componentSteedBehavior.WasOrderIssued) { m_componentCreature.ComponentCreatureModel.HeadShakeOrder = m_random.Float(0.6f, 1f); m_componentCreature.ComponentCreatureSounds.PlayPainSound(); } }, null); m_stateMachine.TransitionTo("Inactive"); }
public void Update(float dt) { if (m_subsystemTime.PeriodicGameTimeEvent(0.125, 0.0)) { ProcessQueuedActions(); } UpdateMovableBlocks(); }
public void Update(float dt) { if (m_subsystemTime.PeriodicGameTimeEvent(60.0, 0.0)) { foreach (KeyValuePair <Point3, int> item in m_toUpdate) { if (base.SubsystemTerrain.Terrain.GetCellContents(item.Key.X, item.Key.Y, item.Key.Z) == 0) { base.SubsystemTerrain.ChangeCell(item.Key.X, item.Key.Y, item.Key.Z, item.Value); } } m_toUpdate.Clear(); } }
public void Update(float dt) { if (m_subsystemTime.PeriodicGameTimeEvent(0.1, 0.0)) { foreach (Projectile key in m_projectiles.Keys) { if (m_subsystemGameInfo.TotalElapsedGameTime - key.CreationTime > 5.0) { m_subsystemExplosions.TryExplodeBlock(Terrain.ToCell(key.Position.X), Terrain.ToCell(key.Position.Y), Terrain.ToCell(key.Position.Z), key.Value); key.ToRemove = true; } } } }
public void Update(float dt) { if (m_subsystemTime.PeriodicGameTimeEvent(30.0, 0.0)) { foreach (KeyValuePair <Point3, Replacement> item in m_toReplace) { Point3 key = item.Key; if (Terrain.ReplaceLight(base.SubsystemTerrain.Terrain.GetCellValue(key.X, key.Y, key.Z), 0) == Terrain.ReplaceLight(item.Value.RequiredValue, 0)) { base.SubsystemTerrain.ChangeCell(key.X, key.Y, key.Z, item.Value.Value); } } m_toReplace.Clear(); } }
public void Update(float dt) { if (m_leavesToCheck.Count <= 0 || !m_subsystemTime.PeriodicGameTimeEvent(20.0, 0.0)) { return; } int num = MathUtils.Min(MathUtils.Max((int)((float)m_leavesToCheck.Count * 0.1f), 10), 200); for (int i = 0; i < num; i++) { if (m_leavesToCheck.Count <= 0) { break; } DecayLeavesIfNeeded(m_leavesToCheck.First()); } }
public void Update(float dt) { if (m_subsystemTime.PeriodicGameTimeEvent(180.0, 179.0)) { AddExperience(1, playSound: false); } StrengthFactor = CalculateStrengthFactor(null); SpeedFactor = CalculateSpeedFactor(null); HungerFactor = CalculateHungerFactor(null); ResilienceFactor = CalculateResilienceFactor(null); if (!m_lastLevelTextValue.HasValue || m_lastLevelTextValue.Value != MathUtils.Floor(m_componentPlayer.PlayerData.Level)) { m_componentPlayer.ComponentGui.LevelLabelWidget.Text = string.Format(LanguageControl.Get(fName, 2), MathUtils.Floor(m_componentPlayer.PlayerData.Level).ToString()); m_lastLevelTextValue = MathUtils.Floor(m_componentPlayer.PlayerData.Level); } m_componentPlayer.PlayerStats.HighestLevel = MathUtils.Max(m_componentPlayer.PlayerStats.HighestLevel, m_componentPlayer.PlayerData.Level); }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_subsystemSky = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true); m_componentCreature = base.Entity.FindComponent <ComponentCreature>(throwOnError: true); m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true); m_subsystemCampfireBlockBehavior = base.Project.FindSubsystem <SubsystemCampfireBlockBehavior>(throwOnError: true); m_dayRange = valuesDictionary.GetValue <float>("DayRange"); m_nightRange = valuesDictionary.GetValue <float>("NightRange"); m_periodicEventOffset = m_random.Float(0f, 10f); m_stateMachine.AddState("Inactive", delegate { m_importanceLevel = 0f; m_target = null; }, delegate { if (IsActive) { m_stateMachine.TransitionTo((m_importanceLevel < 10f) ? "Circle" : "Move"); } else if (m_subsystemTime.PeriodicGameTimeEvent(1.0, m_periodicEventOffset)) { m_target = FindTarget(out float targetScore); if (m_target.HasValue) { if (m_random.Float(0f, 1f) < 0.015f) { m_ignoreFireUntil = m_subsystemTime.GameTime + 20.0; } Vector3.Distance(m_target.Value, m_componentCreature.ComponentBody.Position); if (m_subsystemTime.GameTime < m_ignoreFireUntil) { m_importanceLevel = 0f; } else { m_importanceLevel = ((targetScore > 0.5f) ? 250f : m_random.Float(1f, 5f)); } } else { m_importanceLevel = 0f; } } }, null);
public void Update(float dt) { if (m_thermometersToSimulateIndex < m_thermometersToSimulate.Count) { double period = MathUtils.Max(5.0 / (double)m_thermometersToSimulate.Count, 1.0); if (m_subsystemTime.PeriodicGameTimeEvent(period, 0.0)) { Point3 point = m_thermometersToSimulate.Array[m_thermometersToSimulateIndex]; SimulateThermometer(point.X, point.Y, point.Z, invalidateTerrainOnChange: true); m_thermometersToSimulateIndex++; } } else if (m_thermometersByPoint.Count > 0) { m_thermometersToSimulateIndex = 0; m_thermometersToSimulate.Clear(); m_thermometersToSimulate.AddRange(m_thermometersByPoint.Keys); } }
public void Update(float dt) { m_stateMachine.Update(); if (!IsActive) { m_stateMachine.TransitionTo("Inactive"); } if (m_subsystemTime.PeriodicGameTimeEvent(1.0, m_periodicEventOffset)) { if (m_subsystemGameInfo.TotalElapsedGameTime < m_stubbornEndTime && m_componentEatPickableBehavior.Satiation <= 0f && m_componentMount.Rider != null) { m_importanceLevel = 210f; } else { m_importanceLevel = 0f; } } }
public void Update(float dt) { if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative || !m_subsystemGameInfo.WorldSettings.AreAdventureSurvivalMechanicsEnabled) { m_sicknessDuration = 0f; return; } if (m_sicknessDuration > 0f) { m_sicknessDuration = MathUtils.Max(m_sicknessDuration - dt, 0f); if (m_componentPlayer.ComponentHealth.Health > 0f && !m_componentPlayer.ComponentSleep.IsSleeping && m_subsystemTime.PeriodicGameTimeEvent(3.0, -0.0099999997764825821) && (!m_lastNauseaTime.HasValue || m_subsystemTime.GameTime - m_lastNauseaTime > 15.0)) { NauseaEffect(); } } if (m_pukeParticleSystem != null) { float num = MathUtils.DegToRad(MathUtils.Lerp(-35f, -60f, SimplexNoise.Noise(2f * (float)MathUtils.Remainder(m_subsystemTime.GameTime, 10000.0)))); m_componentPlayer.ComponentLocomotion.LookOrder = new Vector2(m_componentPlayer.ComponentLocomotion.LookOrder.X, MathUtils.Clamp(num - m_componentPlayer.ComponentLocomotion.LookAngles.Y, -2f, 2f)); Vector3 upVector = m_componentPlayer.ComponentCreatureModel.EyeRotation.GetUpVector(); Vector3 forwardVector = m_componentPlayer.ComponentCreatureModel.EyeRotation.GetForwardVector(); m_pukeParticleSystem.Position = m_componentPlayer.ComponentCreatureModel.EyePosition - 0.08f * upVector + 0.3f * forwardVector; m_pukeParticleSystem.Direction = Vector3.Normalize(forwardVector + 0.5f * upVector); if (m_pukeParticleSystem.IsStopped) { m_pukeParticleSystem = null; } } if (m_greenoutDuration > 0f) { m_greenoutDuration = MathUtils.Max(m_greenoutDuration - dt, 0f); m_greenoutFactor = MathUtils.Min(m_greenoutFactor + 0.5f * dt, 0.95f); } else if (m_greenoutFactor > 0f) { m_greenoutFactor = MathUtils.Max(m_greenoutFactor - 0.5f * dt, 0f); } m_componentPlayer.ComponentScreenOverlays.GreenoutFactor = MathUtils.Max(m_greenoutFactor, m_componentPlayer.ComponentScreenOverlays.GreenoutFactor); }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_componentCreature = base.Entity.FindComponent <ComponentCreature>(throwOnError: true); m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true); m_componentMount = base.Entity.FindComponent <ComponentMount>(throwOnError: true); m_isEnabled = !base.Entity.ValuesDictionary.DatabaseObject.Name.EndsWith("_Saddled"); m_stateMachine.AddState("Inactive", delegate { m_importanceLevel = 0f; m_rider = null; }, delegate { if (m_isEnabled && m_random.Float(0f, 1f) < 1f * m_subsystemTime.GameTimeDelta && m_componentMount.Rider != null) { m_importanceLevel = 220f; m_dumpStartTime = m_subsystemTime.GameTime; m_rider = m_componentMount.Rider; } if (IsActive) { m_stateMachine.TransitionTo("WildJumping"); } }, null); m_stateMachine.AddState("WildJumping", delegate { m_componentCreature.ComponentCreatureSounds.PlayPainSound(); m_componentPathfinding.Stop(); }, delegate { if (!IsActive) { m_stateMachine.TransitionTo("Inactive"); } else if (m_componentMount.Rider == null) { m_importanceLevel = 0f; RunAway(); } if (m_random.Float(0f, 1f) < 1f * m_subsystemTime.GameTimeDelta) { m_componentCreature.ComponentCreatureSounds.PlayPainSound(); } if (m_random.Float(0f, 1f) < 3f * m_subsystemTime.GameTimeDelta) { m_walkOrder = new Vector2(m_random.Float(-0.5f, 0.5f), m_random.Float(-0.5f, 1.5f)); } if (m_random.Float(0f, 1f) < 2.5f * m_subsystemTime.GameTimeDelta) { m_turnOrder.X = m_random.Float(-1f, 1f); } if (m_random.Float(0f, 1f) < 2f * m_subsystemTime.GameTimeDelta) { m_componentCreature.ComponentLocomotion.JumpOrder = m_random.Float(0.9f, 1f); if (m_componentMount.Rider != null && m_subsystemTime.GameTime - m_dumpStartTime > 3.0) { if (m_random.Float(0f, 1f) < 0.05f) { m_componentMount.Rider.StartDismounting(); m_componentMount.Rider.ComponentCreature.ComponentHealth.Injure(m_random.Float(0.05f, 0.2f), m_componentCreature, ignoreInvulnerability: false, "Thrown from a mount"); } if (m_random.Float(0f, 1f) < 0.25f) { m_componentMount.Rider.ComponentCreature.ComponentHealth.Injure(0.05f, m_componentCreature, ignoreInvulnerability: false, "Thrown from a mount"); } } } if (m_random.Float(0f, 1f) < 4f * m_subsystemTime.GameTimeDelta) { m_lookOrder = new Vector2(m_random.Float(-3f, 3f), m_lookOrder.Y); } if (m_random.Float(0f, 1f) < 0.25f * m_subsystemTime.GameTimeDelta) { TransitionToRandomDumpingBehavior(); } m_componentCreature.ComponentLocomotion.WalkOrder = m_walkOrder; m_componentCreature.ComponentLocomotion.TurnOrder = m_turnOrder; m_componentCreature.ComponentLocomotion.LookOrder = m_lookOrder; }, null); m_stateMachine.AddState("BlindRacing", delegate { m_componentCreature.ComponentCreatureSounds.PlayPainSound(); m_componentPathfinding.SetDestination(m_componentCreature.ComponentBody.Position + new Vector3(m_random.Float(-15f, 15f), 0f, m_random.Float(-15f, 15f)), 1f, 2f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null); }, delegate { if (!IsActive) { m_stateMachine.TransitionTo("Inactive"); } else if (m_componentMount.Rider == null) { m_importanceLevel = 0f; RunAway(); } else if (!m_componentPathfinding.Destination.HasValue || m_componentPathfinding.IsStuck) { TransitionToRandomDumpingBehavior(); } if (m_random.Float(0f, 1f) < 0.5f * m_subsystemTime.GameTimeDelta) { m_componentCreature.ComponentLocomotion.JumpOrder = 1f; m_componentCreature.ComponentCreatureSounds.PlayPainSound(); } }, null); m_stateMachine.AddState("Stupor", delegate { m_componentCreature.ComponentCreatureSounds.PlayPainSound(); m_componentPathfinding.Stop(); }, delegate { if (!IsActive) { m_stateMachine.TransitionTo("Inactive"); } else if (m_componentMount.Rider == null) { m_importanceLevel = 0f; } if (m_subsystemTime.PeriodicGameTimeEvent(2.0, 0.0)) { TransitionToRandomDumpingBehavior(); } }, null); m_stateMachine.TransitionTo("Inactive"); }
public bool Dig(TerrainRaycastResult raycastResult) { if (Dig1 != null) { return(Dig1(raycastResult)); } bool result = false; m_lastDigFrameIndex = Time.FrameIndex; CellFace cellFace = raycastResult.CellFace; int cellValue = m_subsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z); int num = Terrain.ExtractContents(cellValue); Block block = BlocksManager.Blocks[num]; int activeBlockValue = ActiveBlockValue; int num2 = Terrain.ExtractContents(activeBlockValue); Block block2 = BlocksManager.Blocks[num2]; if (!DigCellFace.HasValue || DigCellFace.Value.X != cellFace.X || DigCellFace.Value.Y != cellFace.Y || DigCellFace.Value.Z != cellFace.Z) { m_digStartTime = m_subsystemTime.GameTime; DigCellFace = cellFace; } float num3 = CalculateDigTime(cellValue, num2); m_digProgress = ((num3 > 0f) ? MathUtils.Saturate((float)(m_subsystemTime.GameTime - m_digStartTime) / num3) : 1f); if (!CanUseTool(activeBlockValue)) { m_digProgress = 0f; if (m_subsystemTime.PeriodicGameTimeEvent(5.0, m_digStartTime + 1.0)) { ComponentPlayer?.ComponentGui.DisplaySmallMessage(string.Format(LanguageControl.Get(fName, 1), block2.PlayerLevelRequired, block2.GetDisplayName(m_subsystemTerrain, activeBlockValue)), Color.White, blinking: true, playNotificationSound: true); } } bool flag = ComponentPlayer != null && !ComponentPlayer.ComponentInput.IsControlledByTouch && m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative; if (flag || (m_lastPokingPhase <= 0.5f && PokingPhase > 0.5f)) { if (m_digProgress >= 1f) { DigCellFace = null; if (flag) { Poke(forceRestart: true); } BlockPlacementData digValue = block.GetDigValue(m_subsystemTerrain, this, cellValue, activeBlockValue, raycastResult); m_subsystemTerrain.DestroyCell(block2.ToolLevel, digValue.CellFace.X, digValue.CellFace.Y, digValue.CellFace.Z, digValue.Value, noDrop: false, noParticleSystem: false); m_subsystemSoundMaterials.PlayImpactSound(cellValue, new Vector3(cellFace.X, cellFace.Y, cellFace.Z), 2f); DamageActiveTool(1); if (ComponentCreature.PlayerStats != null) { ComponentCreature.PlayerStats.BlocksDug++; } result = true; } else { m_subsystemSoundMaterials.PlayImpactSound(cellValue, new Vector3(cellFace.X, cellFace.Y, cellFace.Z), 1f); BlockDebrisParticleSystem particleSystem = block.CreateDebrisParticleSystem(m_subsystemTerrain, raycastResult.HitPoint(0.1f), cellValue, 0.35f); base.Project.FindSubsystem <SubsystemParticles>(throwOnError: true).AddParticleSystem(particleSystem); } } return(result); }
public void Update(float dt) { Vector3 position = m_componentCreature.ComponentBody.Position; if (Health > 0f && Health < 1f) { float num = 0f; if (m_componentPlayer != null) { if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Harmless) { num = 0.0166666675f; } else if (m_componentPlayer.ComponentSleep.SleepFactor == 1f && m_componentPlayer.ComponentVitalStats.Food > 0f) { num = 0.00166666671f; } else if (m_componentPlayer.ComponentVitalStats.Food > 0.5f) { num = 0.00111111114f; } } else { num = 0.00111111114f; } Heal(m_subsystemGameInfo.TotalElapsedGameTimeDelta * num); } if (BreathingMode == BreathingMode.Air) { int cellContents = m_subsystemTerrain.Terrain.GetCellContents(Terrain.ToCell(position.X), Terrain.ToCell(m_componentCreature.ComponentCreatureModel.EyePosition.Y), Terrain.ToCell(position.Z)); if (BlocksManager.Blocks[cellContents] is FluidBlock || position.Y > 259f) { Air = MathUtils.Saturate(Air - dt / AirCapacity); } else { Air = 1f; } } else if (BreathingMode == BreathingMode.Water) { if (m_componentCreature.ComponentBody.ImmersionFactor > 0.25f) { Air = 1f; } else { Air = MathUtils.Saturate(Air - dt / AirCapacity); } } if (m_componentCreature.ComponentBody.ImmersionFactor > 0f && m_componentCreature.ComponentBody.ImmersionFluidBlock is MagmaBlock) { Injure(2f * m_componentCreature.ComponentBody.ImmersionFactor * dt, null, ignoreInvulnerability: false, LanguageControl.Get("ComponentHealth", "1")); float num2 = 1.1f + 0.1f * (float)MathUtils.Sin(12.0 * m_subsystemTime.GameTime); m_redScreenFactor = MathUtils.Max(m_redScreenFactor, num2 * 1.5f * m_componentCreature.ComponentBody.ImmersionFactor); } float num3 = MathUtils.Abs(m_componentCreature.ComponentBody.CollisionVelocityChange.Y); if (!m_wasStanding && num3 > FallResilience) { float num4 = MathUtils.Sqr(MathUtils.Max(num3 - FallResilience, 0f)) / 15f; if (m_componentPlayer != null) { num4 /= m_componentPlayer.ComponentLevel.ResilienceFactor; } Injure(num4, null, ignoreInvulnerability: false, LanguageControl.Get("ComponentHealth", "2")); } m_wasStanding = (m_componentCreature.ComponentBody.StandingOnValue.HasValue || m_componentCreature.ComponentBody.StandingOnBody != null); if ((position.Y < 0f || position.Y > 296f) && m_subsystemTime.PeriodicGameTimeEvent(2.0, 0.0)) { Injure(0.1f, null, ignoreInvulnerability: true, LanguageControl.Get("ComponentHealth", "3")); m_componentPlayer?.ComponentGui.DisplaySmallMessage(LanguageControl.Get("ComponentHealth", "4"), Color.White, blinking: true, playNotificationSound: false); } bool num5 = m_subsystemTime.PeriodicGameTimeEvent(1.0, 0.0); if (num5 && Air == 0f) { float num6 = 0.12f; if (m_componentPlayer != null) { num6 /= m_componentPlayer.ComponentLevel.ResilienceFactor; } Injure(num6, null, ignoreInvulnerability: false, LanguageControl.Get("ComponentHealth", "5")); } if (num5 && (m_componentOnFire.IsOnFire || m_componentOnFire.TouchesFire)) { float num7 = 1f / FireResilience; if (m_componentPlayer != null) { num7 /= m_componentPlayer.ComponentLevel.ResilienceFactor; } Injure(num7, m_componentOnFire.Attacker, ignoreInvulnerability: false, LanguageControl.Get("ComponentHealth", "5")); } if (num5 && CanStrand && m_componentCreature.ComponentBody.ImmersionFactor < 0.25f && (m_componentCreature.ComponentBody.StandingOnValue != 0 || m_componentCreature.ComponentBody.StandingOnBody != null)) { Injure(0.05f, null, ignoreInvulnerability: false, LanguageControl.Get("ComponentHealth", "6")); } HealthChange = Health - m_lastHealth; m_lastHealth = Health; if (m_redScreenFactor > 0.01f) { m_redScreenFactor *= MathUtils.Pow(0.2f, dt); } else { m_redScreenFactor = 0f; } if (HealthChange < 0f) { m_componentCreature.ComponentCreatureSounds.PlayPainSound(); m_redScreenFactor += -4f * HealthChange; m_componentPlayer?.ComponentGui.HealthBarWidget.Flash(MathUtils.Clamp((int)((0f - HealthChange) * 30f), 0, 10)); } if (m_componentPlayer != null) { m_componentPlayer.ComponentScreenOverlays.RedoutFactor = MathUtils.Max(m_componentPlayer.ComponentScreenOverlays.RedoutFactor, m_redScreenFactor); } if (m_componentPlayer != null) { m_componentPlayer.ComponentGui.HealthBarWidget.Value = Health; } if (Health == 0f && HealthChange < 0f) { Vector3 position2 = m_componentCreature.ComponentBody.Position + new Vector3(0f, m_componentCreature.ComponentBody.BoxSize.Y / 2f, 0f); float x = m_componentCreature.ComponentBody.BoxSize.X; m_subsystemParticles.AddParticleSystem(new KillParticleSystem(m_subsystemTerrain, position2, x)); Vector3 position3 = (m_componentCreature.ComponentBody.BoundingBox.Min + m_componentCreature.ComponentBody.BoundingBox.Max) / 2f; foreach (IInventory item in base.Entity.FindComponents <IInventory>()) { item.DropAllItems(position3); } DeathTime = m_subsystemGameInfo.TotalElapsedGameTime; } if (Health <= 0f && CorpseDuration > 0f && m_subsystemGameInfo.TotalElapsedGameTime - DeathTime > (double)CorpseDuration) { m_componentCreature.ComponentSpawn.Despawn(); } }
public void UpdateFood() { float gameTimeDelta = m_subsystemTime.GameTimeDelta; float num = m_componentPlayer.ComponentLocomotion.LastWalkOrder.HasValue ? m_componentPlayer.ComponentLocomotion.LastWalkOrder.Value.Length() : 0f; float lastJumpOrder = m_componentPlayer.ComponentLocomotion.LastJumpOrder; float num2 = m_componentPlayer.ComponentCreatureModel.EyePosition.Y - m_componentPlayer.ComponentBody.Position.Y; bool flag = m_componentPlayer.ComponentBody.ImmersionDepth > num2; bool flag2 = m_componentPlayer.ComponentBody.ImmersionFactor > 0.33f && !m_componentPlayer.ComponentBody.StandingOnValue.HasValue; bool flag3 = m_subsystemTime.PeriodicGameTimeEvent(240.0, 13.0) && !m_componentPlayer.ComponentSickness.IsSick; if (m_subsystemGameInfo.WorldSettings.GameMode != 0 && m_subsystemGameInfo.WorldSettings.AreAdventureSurvivalMechanicsEnabled) { float hungerFactor = m_componentPlayer.ComponentLevel.HungerFactor; Food -= hungerFactor * gameTimeDelta / 2880f; if (flag2 | flag) { Food -= hungerFactor * gameTimeDelta * num / 1440f; } else { Food -= hungerFactor * gameTimeDelta * num / 2880f; } Food -= hungerFactor * lastJumpOrder / 1200f; if (m_componentPlayer.ComponentMiner.DigCellFace.HasValue) { Food -= hungerFactor * gameTimeDelta / 2880f; } if (!m_componentPlayer.ComponentSleep.IsSleeping) { if (Food <= 0f) { if (m_subsystemTime.PeriodicGameTimeEvent(50.0, 0.0)) { m_componentPlayer.ComponentHealth.Injure(0.05f, null, ignoreInvulnerability: false, LanguageControl.Get(fName, 9)); m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 10), Color.White, blinking: true, playNotificationSound: false); m_componentPlayer.ComponentGui.FoodBarWidget.Flash(10); } } else if (Food < 0.1f && ((m_lastFood >= 0.1f) | flag3)) { m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 11), Color.White, blinking: true, playNotificationSound: true); } else if (Food < 0.25f && ((m_lastFood >= 0.25f) | flag3)) { m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 12), Color.White, blinking: true, playNotificationSound: true); } else if (Food < 0.5f && ((m_lastFood >= 0.5f) | flag3)) { m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 13), Color.White, blinking: true, playNotificationSound: false); } } } else { Food = 0.9f; } if (m_subsystemTime.PeriodicGameTimeEvent(1.0, -0.01)) { m_satiationList.Clear(); m_satiationList.AddRange(m_satiation); m_satiation.Clear(); foreach (KeyValuePair <int, float> satiation in m_satiationList) { float num3 = MathUtils.Max(satiation.Value - 0.000416666677f, 0f); if (num3 > 0f) { m_satiation.Add(satiation.Key, num3); } } } m_lastFood = Food; m_componentPlayer.ComponentGui.FoodBarWidget.Value = Food; }
public void Update(float dt) { double totalElapsedGameTime = m_subsystemGameInfo.TotalElapsedGameTime; float num = MathUtils.Pow(0.5f, dt); float num2 = MathUtils.Pow(0.001f, dt); m_tmpPlayers.Clear(); foreach (ComponentPlayer componentPlayer in m_subsystemPlayers.ComponentPlayers) { if (componentPlayer.ComponentHealth.Health > 0f) { m_tmpPlayers.Add(componentPlayer); } } foreach (Pickable pickable in m_pickables) { if (pickable.ToRemove) { m_pickablesToRemove.Add(pickable); } else { Block block = BlocksManager.Blocks[Terrain.ExtractContents(pickable.Value)]; int num3 = m_pickables.Count - m_pickablesToRemove.Count; float num4 = MathUtils.Lerp(300f, 90f, MathUtils.Saturate((float)num3 / 60f)); double num5 = totalElapsedGameTime - pickable.CreationTime; if (num5 > (double)num4) { pickable.ToRemove = true; } else { TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Z)); if (chunkAtCell != null && chunkAtCell.State > TerrainChunkState.InvalidContents4) { Vector3 position = pickable.Position; Vector3 vector = position + pickable.Velocity * dt; if (!pickable.FlyToPosition.HasValue && num5 > 0.5) { foreach (ComponentPlayer tmpPlayer in m_tmpPlayers) { ComponentBody componentBody = tmpPlayer.ComponentBody; Vector3 v = componentBody.Position + new Vector3(0f, 0.75f, 0f); float num6 = (v - pickable.Position).LengthSquared(); if (num6 < 3.0625f) { bool flag = Terrain.ExtractContents(pickable.Value) == 248; IInventory inventory = tmpPlayer.ComponentMiner.Inventory; if (flag || ComponentInventoryBase.FindAcquireSlotForItem(inventory, pickable.Value) >= 0) { if (num6 < 1f) { if (flag) { tmpPlayer.ComponentLevel.AddExperience(pickable.Count, playSound: true); pickable.ToRemove = true; } else { pickable.Count = ComponentInventoryBase.AcquireItems(inventory, pickable.Value, pickable.Count); if (pickable.Count == 0) { pickable.ToRemove = true; m_subsystemAudio.PlaySound("Audio/PickableCollected", 0.7f, -0.4f, pickable.Position, 2f, autoDelay: false); } } } else if (!pickable.StuckMatrix.HasValue) { pickable.FlyToPosition = v + 0.1f * MathUtils.Sqrt(num6) * componentBody.Velocity; } } } } } if (pickable.FlyToPosition.HasValue) { Vector3 v2 = pickable.FlyToPosition.Value - pickable.Position; float num7 = v2.LengthSquared(); if (num7 >= 0.25f) { pickable.Velocity = 6f * v2 / MathUtils.Sqrt(num7); } else { pickable.FlyToPosition = null; } } else { FluidBlock surfaceBlock; float? surfaceHeight; Vector2? vector2 = m_subsystemFluidBlockBehavior.CalculateFlowSpeed(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y + 0.1f), Terrain.ToCell(pickable.Position.Z), out surfaceBlock, out surfaceHeight); if (!pickable.StuckMatrix.HasValue) { TerrainRaycastResult?terrainRaycastResult = m_subsystemTerrain.Raycast(position, vector, useInteractionBoxes: false, skipAirBlocks: true, (int value, float distance) => BlocksManager.Blocks[Terrain.ExtractContents(value)].IsCollidable); if (terrainRaycastResult.HasValue) { int contents = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValue(terrainRaycastResult.Value.CellFace.X, terrainRaycastResult.Value.CellFace.Y, terrainRaycastResult.Value.CellFace.Z)); SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(contents); for (int i = 0; i < blockBehaviors.Length; i++) { blockBehaviors[i].OnHitByProjectile(terrainRaycastResult.Value.CellFace, pickable); } if (m_subsystemTerrain.Raycast(position, position, useInteractionBoxes: false, skipAirBlocks: true, (int value2, float distance) => BlocksManager.Blocks[Terrain.ExtractContents(value2)].IsCollidable).HasValue) { int num8 = Terrain.ToCell(position.X); int num9 = Terrain.ToCell(position.Y); int num10 = Terrain.ToCell(position.Z); int num11 = 0; int num12 = 0; int num13 = 0; int?num14 = null; for (int j = -3; j <= 3; j++) { for (int k = -3; k <= 3; k++) { for (int l = -3; l <= 3; l++) { if (!BlocksManager.Blocks[m_subsystemTerrain.Terrain.GetCellContents(j + num8, k + num9, l + num10)].IsCollidable) { int num15 = j * j + k * k + l * l; if (!num14.HasValue || num15 < num14.Value) { num11 = j + num8; num12 = k + num9; num13 = l + num10; num14 = num15; } } } } } if (num14.HasValue) { pickable.FlyToPosition = new Vector3(num11, num12, num13) + new Vector3(0.5f); } else { pickable.ToRemove = true; } } else { Plane plane = terrainRaycastResult.Value.CellFace.CalculatePlane(); bool flag2 = vector2.HasValue && vector2.Value != Vector2.Zero; if (plane.Normal.X != 0f) { float num16 = (flag2 || MathUtils.Sqrt(MathUtils.Sqr(pickable.Velocity.Y) + MathUtils.Sqr(pickable.Velocity.Z)) > 10f) ? 0.95f : 0.25f; pickable.Velocity *= new Vector3(0f - num16, num16, num16); } if (plane.Normal.Y != 0f) { float num17 = (flag2 || MathUtils.Sqrt(MathUtils.Sqr(pickable.Velocity.X) + MathUtils.Sqr(pickable.Velocity.Z)) > 10f) ? 0.95f : 0.25f; pickable.Velocity *= new Vector3(num17, 0f - num17, num17); if (flag2) { pickable.Velocity.Y += 0.1f * plane.Normal.Y; } } if (plane.Normal.Z != 0f) { float num18 = (flag2 || MathUtils.Sqrt(MathUtils.Sqr(pickable.Velocity.X) + MathUtils.Sqr(pickable.Velocity.Y)) > 10f) ? 0.95f : 0.25f; pickable.Velocity *= new Vector3(num18, num18, 0f - num18); } vector = position; } } } else { Vector3 vector3 = pickable.StuckMatrix.Value.Translation + pickable.StuckMatrix.Value.Up * block.ProjectileTipOffset; if (!m_subsystemTerrain.Raycast(vector3, vector3, useInteractionBoxes: false, skipAirBlocks: true, (int value, float distance) => BlocksManager.Blocks[Terrain.ExtractContents(value)].IsCollidable).HasValue) { pickable.Position = pickable.StuckMatrix.Value.Translation; pickable.Velocity = Vector3.Zero; pickable.StuckMatrix = null; } } if (surfaceBlock is WaterBlock && !pickable.SplashGenerated) { m_subsystemParticles.AddParticleSystem(new WaterSplashParticleSystem(m_subsystemTerrain, pickable.Position, large: false)); m_subsystemAudio.PlayRandomSound("Audio/Splashes", 1f, m_random.Float(-0.2f, 0.2f), pickable.Position, 6f, autoDelay: true); pickable.SplashGenerated = true; } else if (surfaceBlock is MagmaBlock && !pickable.SplashGenerated) { m_subsystemParticles.AddParticleSystem(new MagmaSplashParticleSystem(m_subsystemTerrain, pickable.Position, large: false)); m_subsystemAudio.PlayRandomSound("Audio/Sizzles", 1f, m_random.Float(-0.2f, 0.2f), pickable.Position, 3f, autoDelay: true); pickable.ToRemove = true; pickable.SplashGenerated = true; m_subsystemExplosions.TryExplodeBlock(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y), Terrain.ToCell(pickable.Position.Z), pickable.Value); } else if (surfaceBlock == null) { pickable.SplashGenerated = false; } if (m_subsystemTime.PeriodicGameTimeEvent(1.0, (double)(pickable.GetHashCode() % 100) / 100.0) && (m_subsystemTerrain.Terrain.GetCellContents(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y + 0.1f), Terrain.ToCell(pickable.Position.Z)) == 104 || m_subsystemFireBlockBehavior.IsCellOnFire(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y + 0.1f), Terrain.ToCell(pickable.Position.Z)))) { m_subsystemAudio.PlayRandomSound("Audio/Sizzles", 1f, m_random.Float(-0.2f, 0.2f), pickable.Position, 3f, autoDelay: true); pickable.ToRemove = true; m_subsystemExplosions.TryExplodeBlock(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y), Terrain.ToCell(pickable.Position.Z), pickable.Value); } if (!pickable.StuckMatrix.HasValue) { if (vector2.HasValue && surfaceHeight.HasValue) { float num19 = surfaceHeight.Value - pickable.Position.Y; float num20 = MathUtils.Saturate(3f * num19); pickable.Velocity.X += 4f * dt * (vector2.Value.X - pickable.Velocity.X); pickable.Velocity.Y -= 10f * dt; pickable.Velocity.Y += 10f * (1f / block.Density * num20) * dt; pickable.Velocity.Z += 4f * dt * (vector2.Value.Y - pickable.Velocity.Z); pickable.Velocity.Y *= num2; } else { pickable.Velocity.Y -= 10f * dt; pickable.Velocity *= num; } } } pickable.Position = vector; } } } } foreach (Pickable item in m_pickablesToRemove) { m_pickables.Remove(item); if (this.PickableRemoved != null) { this.PickableRemoved(item); } } m_pickablesToRemove.Clear(); }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_subsystemPickables = base.Project.FindSubsystem <SubsystemPickables>(throwOnError: true); m_componentCreature = base.Entity.FindComponent <ComponentCreature>(throwOnError: true); m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true); m_foodFactors = new float[EnumUtils.GetEnumValues(typeof(FoodType)).Max() + 1]; foreach (KeyValuePair <string, object> item in valuesDictionary.GetValue <ValuesDictionary>("FoodFactors")) { FoodType foodType = (FoodType)Enum.Parse(typeof(FoodType), item.Key, ignoreCase: false); m_foodFactors[(int)foodType] = (float)item.Value; } m_subsystemPickables.PickableAdded += delegate(Pickable pickable) { if (TryAddPickable(pickable) && m_pickable == null) { m_pickable = pickable; } }; m_subsystemPickables.PickableRemoved += delegate(Pickable pickable) { m_pickables.Remove(pickable); if (m_pickable == pickable) { m_pickable = null; } }; m_stateMachine.AddState("Inactive", delegate { m_importanceLevel = 0f; m_pickable = null; }, delegate { if (m_satiation < 1f) { if (m_pickable == null) { if (m_subsystemTime.GameTime > m_nextFindPickableTime) { m_nextFindPickableTime = m_subsystemTime.GameTime + (double)m_random.Float(2f, 4f); m_pickable = FindPickable(m_componentCreature.ComponentBody.Position); } } else { m_importanceLevel = m_random.Float(5f, 10f); } } if (IsActive) { m_stateMachine.TransitionTo("Move"); m_blockedCount = 0; } }, null); m_stateMachine.AddState("Move", delegate { if (m_pickable != null) { float speed = (m_satiation == 0f) ? m_random.Float(0.5f, 0.7f) : 0.5f; int maxPathfindingPositions = (m_satiation == 0f) ? 1000 : 500; float num2 = Vector3.Distance(m_componentCreature.ComponentCreatureModel.EyePosition, m_componentCreature.ComponentBody.Position); m_componentPathfinding.SetDestination(m_pickable.Position, speed, 1f + num2, maxPathfindingPositions, useRandomMovements: true, ignoreHeightDifference: false, raycastDestination: true, null); if (m_random.Float(0f, 1f) < 0.66f) { m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: true); } } }, delegate { if (!IsActive) { m_stateMachine.TransitionTo("Inactive"); } else if (m_pickable == null) { m_importanceLevel = 0f; } else if (m_componentPathfinding.IsStuck) { m_importanceLevel = 0f; m_satiation += 0.75f; } else if (!m_componentPathfinding.Destination.HasValue) { m_stateMachine.TransitionTo("Eat"); } else if (Vector3.DistanceSquared(m_componentPathfinding.Destination.Value, m_pickable.Position) > 0.0625f) { m_stateMachine.TransitionTo("PickableMoved"); } if (m_random.Float(0f, 1f) < 0.1f * m_subsystemTime.GameTimeDelta) { m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: true); } if (m_pickable != null) { m_componentCreature.ComponentCreatureModel.LookAtOrder = m_pickable.Position; } else { m_componentCreature.ComponentCreatureModel.LookRandomOrder = true; } }, null); m_stateMachine.AddState("PickableMoved", null, delegate { if (m_pickable != null) { m_componentCreature.ComponentCreatureModel.LookAtOrder = m_pickable.Position; } if (m_subsystemTime.PeriodicGameTimeEvent(0.25, (double)(GetHashCode() % 100) * 0.01)) { m_stateMachine.TransitionTo("Move"); } }, null); m_stateMachine.AddState("Eat", delegate { m_eatTime = m_random.Float(4f, 5f); m_blockedTime = 0f; }, delegate { if (!IsActive) { m_stateMachine.TransitionTo("Inactive"); } if (m_pickable == null) { m_importanceLevel = 0f; } if (m_pickable != null) { if (Vector3.DistanceSquared(new Vector3(m_componentCreature.ComponentCreatureModel.EyePosition.X, m_componentCreature.ComponentBody.Position.Y, m_componentCreature.ComponentCreatureModel.EyePosition.Z), m_pickable.Position) < 0.640000045f) { m_eatTime -= m_subsystemTime.GameTimeDelta; m_blockedTime = 0f; if (m_eatTime <= 0.0) { m_satiation += 1f; m_pickable.Count = MathUtils.Max(m_pickable.Count - 1, 0); if (m_pickable.Count == 0) { m_pickable.ToRemove = true; m_importanceLevel = 0f; } else if (m_random.Float(0f, 1f) < 0.5f) { m_importanceLevel = 0f; } } } else { float num = Vector3.Distance(m_componentCreature.ComponentCreatureModel.EyePosition, m_componentCreature.ComponentBody.Position); m_componentPathfinding.SetDestination(m_pickable.Position, 0.3f, 0.5f + num, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null); m_blockedTime += m_subsystemTime.GameTimeDelta; } if (m_blockedTime > 3f) { m_blockedCount++; if (m_blockedCount >= 3) { m_importanceLevel = 0f; m_satiation += 0.75f; } else { m_stateMachine.TransitionTo("Move"); } } } m_componentCreature.ComponentCreatureModel.FeedOrder = true; if (m_random.Float(0f, 1f) < 0.1f * m_subsystemTime.GameTimeDelta) { m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: true); } if (m_random.Float(0f, 1f) < 1.5f * m_subsystemTime.GameTimeDelta) { m_componentCreature.ComponentCreatureSounds.PlayFootstepSound(2f); } }, null); m_stateMachine.TransitionTo("Inactive"); }
public void Update(float dt) { if (m_subsystemGameInfo.WorldSettings.GameMode != 0 && m_subsystemGameInfo.WorldSettings.AreAdventureSurvivalMechanicsEnabled && m_subsystemTime.PeriodicGameTimeEvent(0.5, 0.0)) { foreach (int enumValue in EnumUtils.GetEnumValues(typeof(ClothingSlot))) { bool flag = false; m_clothesList.Clear(); m_clothesList.AddRange(GetClothes((ClothingSlot)enumValue)); int num = 0; while (num < m_clothesList.Count) { int value = m_clothesList[num]; ClothingData clothingData = ClothingBlock.GetClothingData(Terrain.ExtractData(value)); if ((float)clothingData.PlayerLevelRequired > m_componentPlayer.PlayerData.Level) { m_componentGui.DisplaySmallMessage(string.Format(LanguageControl.Get(fName, 1), clothingData.PlayerLevelRequired, clothingData.DisplayName), Color.White, blinking: true, playNotificationSound: true); m_subsystemPickables.AddPickable(value, 1, m_componentBody.Position, null, null); m_clothesList.RemoveAt(num); flag = true; } else { num++; } } if (flag) { SetClothes((ClothingSlot)enumValue, m_clothesList); } } } if (m_subsystemGameInfo.WorldSettings.GameMode != 0 && m_subsystemGameInfo.WorldSettings.AreAdventureSurvivalMechanicsEnabled && m_subsystemTime.PeriodicGameTimeEvent(2.0, 0.0) && ((m_componentLocomotion.LastWalkOrder.HasValue && m_componentLocomotion.LastWalkOrder.Value != Vector2.Zero) || (m_componentLocomotion.LastSwimOrder.HasValue && m_componentLocomotion.LastSwimOrder.Value != Vector3.Zero) || m_componentLocomotion.LastJumpOrder != 0f)) { if (m_lastTotalElapsedGameTime.HasValue) { foreach (int enumValue2 in EnumUtils.GetEnumValues(typeof(ClothingSlot))) { bool flag2 = false; m_clothesList.Clear(); m_clothesList.AddRange(GetClothes((ClothingSlot)enumValue2)); for (int i = 0; i < m_clothesList.Count; i++) { int value2 = m_clothesList[i]; ClothingData clothingData2 = ClothingBlock.GetClothingData(Terrain.ExtractData(value2)); float num2 = (m_componentVitalStats.Wetness > 0f) ? (10f * clothingData2.Sturdiness) : (20f * clothingData2.Sturdiness); double num3 = MathUtils.Floor(m_lastTotalElapsedGameTime.Value / (double)num2); if (MathUtils.Floor(m_subsystemGameInfo.TotalElapsedGameTime / (double)num2) > num3 && m_random.Float(0f, 1f) < 0.75f) { m_clothesList[i] = BlocksManager.DamageItem(value2, 1); flag2 = true; } } int num4 = 0; while (num4 < m_clothesList.Count) { if (Terrain.ExtractContents(m_clothesList[num4]) != 203) { m_clothesList.RemoveAt(num4); m_subsystemParticles.AddParticleSystem(new BlockDebrisParticleSystem(m_subsystemTerrain, m_componentBody.Position + m_componentBody.BoxSize / 2f, 1f, 1f, Color.White, 0)); m_componentGui.DisplaySmallMessage(LanguageControl.Get(fName, 2), Color.White, blinking: true, playNotificationSound: true); } else { num4++; } } if (flag2) { SetClothes((ClothingSlot)enumValue2, m_clothesList); } } } m_lastTotalElapsedGameTime = m_subsystemGameInfo.TotalElapsedGameTime; } UpdateRenderTargets(); }
public override bool OnAim(Ray3 aim, ComponentMiner componentMiner, AimState state) { IInventory inventory = componentMiner.Inventory; if (inventory != null) { int activeSlotIndex = inventory.ActiveSlotIndex; if (activeSlotIndex >= 0) { int slotValue = inventory.GetSlotValue(activeSlotIndex); int slotCount = inventory.GetSlotCount(activeSlotIndex); int num = Terrain.ExtractContents(slotValue); int data = Terrain.ExtractData(slotValue); if (num == 191 && slotCount > 0) { if (!m_aimStartTimes.TryGetValue(componentMiner, out double value)) { value = m_subsystemTime.GameTime; m_aimStartTimes[componentMiner] = value; } float num2 = (float)(m_subsystemTime.GameTime - value); float num3 = (float)MathUtils.Remainder(m_subsystemTime.GameTime, 1000.0); Vector3 v = ((componentMiner.ComponentCreature.ComponentBody.IsSneaking ? 0.02f : 0.04f) + 0.25f * MathUtils.Saturate((num2 - 2.1f) / 5f)) * new Vector3 { X = SimplexNoise.OctavedNoise(num3, 2f, 3, 2f, 0.5f), Y = SimplexNoise.OctavedNoise(num3 + 100f, 2f, 3, 2f, 0.5f), Z = SimplexNoise.OctavedNoise(num3 + 200f, 2f, 3, 2f, 0.5f) }; aim.Direction = Vector3.Normalize(aim.Direction + v); switch (state) { case AimState.InProgress: { if (num2 >= 9f) { componentMiner.ComponentCreature.ComponentCreatureSounds.PlayMoanSound(); return(true); } ComponentFirstPersonModel componentFirstPersonModel = componentMiner.Entity.FindComponent <ComponentFirstPersonModel>(); if (componentFirstPersonModel != null) { componentMiner.ComponentPlayer?.ComponentAimingSights.ShowAimingSights(aim.Position, aim.Direction); componentFirstPersonModel.ItemOffsetOrder = new Vector3(-0.1f, 0.15f, 0f); componentFirstPersonModel.ItemRotationOrder = new Vector3(0f, -0.7f, 0f); } componentMiner.ComponentCreature.ComponentCreatureModel.AimHandAngleOrder = 1.2f; componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemOffsetOrder = new Vector3(0f, 0f, 0f); componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemRotationOrder = new Vector3(0f, -0.2f, 0f); if (m_subsystemTime.PeriodicGameTimeEvent(0.10000000149011612, 0.0)) { int draw2 = MathUtils.Min(BowBlock.GetDraw(data) + 1, 15); inventory.RemoveSlotItems(activeSlotIndex, 1); inventory.AddSlotItems(activeSlotIndex, Terrain.MakeBlockValue(num, 0, BowBlock.SetDraw(data, draw2)), 1); } break; } case AimState.Cancelled: inventory.RemoveSlotItems(activeSlotIndex, 1); inventory.AddSlotItems(activeSlotIndex, Terrain.MakeBlockValue(num, 0, BowBlock.SetDraw(data, 0)), 1); m_aimStartTimes.Remove(componentMiner); break; case AimState.Completed: { int draw = BowBlock.GetDraw(data); ArrowBlock.ArrowType?arrowType = BowBlock.GetArrowType(data); if (arrowType.HasValue) { Vector3 vector = componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition + componentMiner.ComponentCreature.ComponentBody.Matrix.Right * 0.3f - componentMiner.ComponentCreature.ComponentBody.Matrix.Up * 0.2f; Vector3 vector2 = Vector3.Normalize(vector + aim.Direction * 10f - vector); float num4 = MathUtils.Lerp(0f, 28f, MathUtils.Pow((float)draw / 15f, 0.75f)); if (componentMiner.ComponentPlayer != null) { num4 *= 0.5f * (componentMiner.ComponentPlayer.ComponentLevel.StrengthFactor - 1f) + 1f; } Vector3 vector3 = Vector3.Zero; if (arrowType == ArrowBlock.ArrowType.WoodenArrow) { vector3 = new Vector3(0.025f, 0.025f, 0.025f); } if (arrowType == ArrowBlock.ArrowType.StoneArrow) { vector3 = new Vector3(0.01f, 0.01f, 0.01f); } int value2 = Terrain.MakeBlockValue(192, 0, ArrowBlock.SetArrowType(0, arrowType.Value)); Vector3 vector4 = Vector3.Normalize(Vector3.Cross(vector2, Vector3.UnitY)); Vector3 v2 = Vector3.Normalize(Vector3.Cross(vector2, vector4)); Vector3 v3 = m_random.Float(0f - vector3.X, vector3.X) * vector4 + m_random.Float(0f - vector3.Y, vector3.Y) * v2 + m_random.Float(0f - vector3.Z, vector3.Z) * vector2; if (m_subsystemProjectiles.FireProjectile(value2, vector, (vector2 + v3) * num4, Vector3.Zero, componentMiner.ComponentCreature) != null) { data = BowBlock.SetArrowType(data, null); m_subsystemAudio.PlaySound("Audio/Bow", 1f, m_random.Float(-0.1f, 0.1f), vector, 3f, autoDelay: true); } } else { componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Load an arrow first", Color.White, blinking: true, playNotificationSound: false); } inventory.RemoveSlotItems(activeSlotIndex, 1); int value3 = Terrain.MakeBlockValue(num, 0, BowBlock.SetDraw(data, 0)); inventory.AddSlotItems(activeSlotIndex, value3, 1); int damageCount = 0; if (draw >= 15) { damageCount = 2; } else if (draw >= 4) { damageCount = 1; } componentMiner.DamageActiveTool(damageCount); m_aimStartTimes.Remove(componentMiner); break; } } } } } return(false); }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_subsystemCreatureSpawn = base.Project.FindSubsystem <SubsystemCreatureSpawn>(throwOnError: true); m_componentCreature = base.Entity.FindComponent <ComponentCreature>(throwOnError: true); m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true); HerdName = valuesDictionary.GetValue <string>("HerdName"); m_herdingRange = valuesDictionary.GetValue <float>("HerdingRange"); m_autoNearbyCreaturesHelp = valuesDictionary.GetValue <bool>("AutoNearbyCreaturesHelp"); m_componentCreature.ComponentHealth.Attacked += delegate(ComponentCreature attacker) { CallNearbyCreaturesHelp(attacker, 20f, 30f, isPersistent: false); }; m_stateMachine.AddState("Inactive", null, delegate { if (m_subsystemTime.PeriodicGameTimeEvent(1.0, 1f * ((float)(GetHashCode() % 256) / 256f))) { Vector3?vector2 = FindHerdCenter(); if (vector2.HasValue) { float num = Vector3.Distance(vector2.Value, m_componentCreature.ComponentBody.Position); if (num > 10f) { m_importanceLevel = 1f; } if (num > 12f) { m_importanceLevel = 3f; } if (num > 16f) { m_importanceLevel = 50f; } if (num > 20f) { m_importanceLevel = 250f; } } } if (IsActive) { m_stateMachine.TransitionTo("Herd"); } }, null); m_stateMachine.AddState("Stuck", delegate { m_stateMachine.TransitionTo("Herd"); if (m_random.Bool(0.5f)) { m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: false); m_importanceLevel = 0f; } }, null, null); m_stateMachine.AddState("Herd", delegate { Vector3?vector = FindHerdCenter(); if (vector.HasValue && Vector3.Distance(m_componentCreature.ComponentBody.Position, vector.Value) > 6f) { float speed = (m_importanceLevel > 10f) ? m_random.Float(0.9f, 1f) : m_random.Float(0.25f, 0.35f); int maxPathfindingPositions = (m_importanceLevel > 200f) ? 100 : 0; m_componentPathfinding.SetDestination(vector.Value, speed, 7f, maxPathfindingPositions, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null); } else { m_importanceLevel = 0f; } }, delegate { m_componentCreature.ComponentLocomotion.LookOrder = m_look - m_componentCreature.ComponentLocomotion.LookAngles; if (m_componentPathfinding.IsStuck) { m_stateMachine.TransitionTo("Stuck"); } if (!m_componentPathfinding.Destination.HasValue) { m_importanceLevel = 0f; } if (m_random.Float(0f, 1f) < 0.05f * m_dt) { m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: false); } if (m_random.Float(0f, 1f) < 1.5f * m_dt) { m_look = new Vector2(MathUtils.DegToRad(45f) * m_random.Float(-1f, 1f), MathUtils.DegToRad(10f) * m_random.Float(-1f, 1f)); } }, null); }
public void Update(float dt) { if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative || !m_subsystemGameInfo.WorldSettings.AreAdventureSurvivalMechanicsEnabled) { m_fluDuration = 0f; m_fluOnset = 0f; return; } if (m_fluDuration > 0f) { m_fluOnset = 0f; float num = 1f; if (m_componentPlayer.ComponentVitalStats.Temperature > 16f) { num = 2f; } else if (m_componentPlayer.ComponentVitalStats.Temperature > 12f) { num = 1.5f; } else if (m_componentPlayer.ComponentVitalStats.Temperature < 8f) { num = 0.5f; } m_fluDuration = MathUtils.Max(m_fluDuration - num * dt, 0f); if (m_componentPlayer.ComponentHealth.Health > 0f && !m_componentPlayer.ComponentSleep.IsSleeping && m_subsystemTime.PeriodicGameTimeEvent(5.0, -0.0099999997764825821) && m_subsystemTime.GameTime - m_lastEffectTime > 13.0) { FluEffect(); } } else if (m_componentPlayer.ComponentVitalStats.Temperature < 6f) { float num2 = 13f; m_fluOnset += dt; if (m_fluOnset > 120f) { num2 = 9f; if (m_subsystemTime.PeriodicGameTimeEvent(1.0, 0.0) && m_random.Bool(0.025f)) { StartFlu(); } if (m_subsystemTime.GameTime - m_lastMessageTime > 60.0) { m_lastMessageTime = m_subsystemTime.GameTime; m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 1), Color.White, blinking: true, playNotificationSound: true); } } if (m_fluOnset > 60f && m_subsystemTime.PeriodicGameTimeEvent(num2, -0.0099999997764825821) && m_random.Bool(0.75f)) { Sneeze(); } } else { m_fluOnset = 0f; } if ((m_coughDuration > 0f || m_sneezeDuration > 0f) && m_componentPlayer.ComponentHealth.Health > 0f && !m_componentPlayer.ComponentSleep.IsSleeping) { m_coughDuration = MathUtils.Max(m_coughDuration - dt, 0f); m_sneezeDuration = MathUtils.Max(m_sneezeDuration - dt, 0f); float num3 = MathUtils.DegToRad(MathUtils.Lerp(-35f, -65f, SimplexNoise.Noise(4f * (float)MathUtils.Remainder(m_subsystemTime.GameTime, 10000.0)))); m_componentPlayer.ComponentLocomotion.LookOrder = new Vector2(m_componentPlayer.ComponentLocomotion.LookOrder.X, MathUtils.Clamp(num3 - m_componentPlayer.ComponentLocomotion.LookAngles.Y, -3f, 3f)); if (m_random.Bool(2f * dt)) { m_componentPlayer.ComponentBody.ApplyImpulse(-1.2f * m_componentPlayer.ComponentCreatureModel.EyeRotation.GetForwardVector()); } } if (m_blackoutDuration > 0f) { m_blackoutDuration = MathUtils.Max(m_blackoutDuration - dt, 0f); m_blackoutFactor = MathUtils.Min(m_blackoutFactor + 0.5f * dt, 0.95f); } else if (m_blackoutFactor > 0f) { m_blackoutFactor = MathUtils.Max(m_blackoutFactor - 0.5f * dt, 0f); } m_componentPlayer.ComponentScreenOverlays.BlackoutFactor = MathUtils.Max(m_blackoutFactor, m_componentPlayer.ComponentScreenOverlays.BlackoutFactor); }
public void Update(float dt) { if (m_firePointsCopy.Count == 0) { m_firePointsCopy.Count += m_fireData.Count; m_fireData.Keys.CopyTo(m_firePointsCopy.Array, 0); m_copyIndex = 0; m_lastScanDuration = (float)(m_subsystemTime.GameTime - m_lastScanTime); m_lastScanTime = m_subsystemTime.GameTime; if (m_firePointsCopy.Count == 0) { m_fireSoundVolume = 0f; } } if (m_firePointsCopy.Count > 0) { float num = MathUtils.Min(1f * dt * (float)m_firePointsCopy.Count + m_remainderToScan, 50f); int num2 = (int)num; m_remainderToScan = num - (float)num2; int num3 = MathUtils.Min(m_copyIndex + num2, m_firePointsCopy.Count); while (m_copyIndex < num3) { if (m_fireData.TryGetValue(m_firePointsCopy.Array[m_copyIndex], out FireData value)) { int x = value.Point.X; int y = value.Point.Y; int z = value.Point.Z; int num4 = Terrain.ExtractData(base.SubsystemTerrain.Terrain.GetCellValue(x, y, z)); m_fireSoundIntensity += 1f / (m_subsystemAudio.CalculateListenerDistanceSquared(new Vector3(x, y, z)) + 0.01f); if ((num4 & 1) != 0) { value.Time0 -= m_lastScanDuration; if (value.Time0 <= 0f) { QueueBurnAway(x, y, z + 1, value.FireExpandability * 0.85f); } foreach (KeyValuePair <Point3, float> expansionProbability in m_expansionProbabilities) { if (m_random.Float(0f, 1f) < expansionProbability.Value * m_lastScanDuration * value.FireExpandability) { m_toExpand[new Point3(x + expansionProbability.Key.X, y + expansionProbability.Key.Y, z + 1 + expansionProbability.Key.Z)] = value.FireExpandability * 0.85f; } } } if ((num4 & 2) != 0) { value.Time1 -= m_lastScanDuration; if (value.Time1 <= 0f) { QueueBurnAway(x + 1, y, z, value.FireExpandability * 0.85f); } foreach (KeyValuePair <Point3, float> expansionProbability2 in m_expansionProbabilities) { if (m_random.Float(0f, 1f) < expansionProbability2.Value * m_lastScanDuration * value.FireExpandability) { m_toExpand[new Point3(x + 1 + expansionProbability2.Key.X, y + expansionProbability2.Key.Y, z + expansionProbability2.Key.Z)] = value.FireExpandability * 0.85f; } } } if ((num4 & 4) != 0) { value.Time2 -= m_lastScanDuration; if (value.Time2 <= 0f) { QueueBurnAway(x, y, z - 1, value.FireExpandability * 0.85f); } foreach (KeyValuePair <Point3, float> expansionProbability3 in m_expansionProbabilities) { if (m_random.Float(0f, 1f) < expansionProbability3.Value * m_lastScanDuration * value.FireExpandability) { m_toExpand[new Point3(x + expansionProbability3.Key.X, y + expansionProbability3.Key.Y, z - 1 + expansionProbability3.Key.Z)] = value.FireExpandability * 0.85f; } } } if ((num4 & 8) != 0) { value.Time3 -= m_lastScanDuration; if (value.Time3 <= 0f) { QueueBurnAway(x - 1, y, z, value.FireExpandability * 0.85f); } foreach (KeyValuePair <Point3, float> expansionProbability4 in m_expansionProbabilities) { if (m_random.Float(0f, 1f) < expansionProbability4.Value * m_lastScanDuration * value.FireExpandability) { m_toExpand[new Point3(x - 1 + expansionProbability4.Key.X, y + expansionProbability4.Key.Y, z + expansionProbability4.Key.Z)] = value.FireExpandability * 0.85f; } } } if (num4 == 0) { value.Time5 -= m_lastScanDuration; if (value.Time5 <= 0f) { QueueBurnAway(x, y - 1, z, value.FireExpandability * 0.85f); } } } m_copyIndex++; } if (m_copyIndex >= m_firePointsCopy.Count) { m_fireSoundVolume = 0.75f * m_fireSoundIntensity; m_firePointsCopy.Clear(); m_fireSoundIntensity = 0f; } } if (m_subsystemTime.PeriodicGameTimeEvent(5.0, 0.0)) { int num5 = 0; int num6 = 0; foreach (KeyValuePair <Point3, float> item in m_toBurnAway) { Point3 key = item.Key; float value2 = item.Value; base.SubsystemTerrain.ChangeCell(key.X, key.Y, key.Z, Terrain.ReplaceContents(0, 0)); if (value2 > 0.25f) { for (int i = 0; i < 5; i++) { Point3 point = CellFace.FaceToPoint3(i); SetCellOnFire(key.X + point.X, key.Y + point.Y, key.Z + point.Z, value2); } } float num7 = m_subsystemViews.CalculateDistanceFromNearestView(new Vector3(key)); if (num5 < 15 && num7 < 24f) { m_subsystemParticles.AddParticleSystem(new BurntDebrisParticleSystem(base.SubsystemTerrain, key.X, key.Y, key.Z)); num5++; } if (num6 < 4 && num7 < 16f) { m_subsystemAudio.PlayRandomSound("Audio/Sizzles", 1f, m_random.Float(-0.25f, 0.25f), new Vector3(key.X, key.Y, key.Z), 3f, autoDelay: true); num6++; } } foreach (KeyValuePair <Point3, float> item2 in m_toExpand) { SetCellOnFire(item2.Key.X, item2.Key.Y, item2.Key.Z, item2.Value); } m_toBurnAway.Clear(); m_toExpand.Clear(); } m_subsystemAmbientSounds.FireSoundVolume = MathUtils.Max(m_subsystemAmbientSounds.FireSoundVolume, m_fireSoundVolume); }
public void Update(float dt) { if (m_subsystemGameInfo.TotalElapsedGameTime > m_precipitationEndTime) { if (m_precipitationEndTime == 0.0) { if (m_subsystemGameInfo.WorldSettings.StartingPositionMode == StartingPositionMode.Hard) { m_precipitationStartTime = m_subsystemGameInfo.TotalElapsedGameTime + (double)(60f * m_random.Float(2f, 3f)); m_lightningIntensity = m_random.Float(0.5f, 1f); } else { m_precipitationStartTime = m_subsystemGameInfo.TotalElapsedGameTime + (double)(60f * m_random.Float(3f, 6f)); m_lightningIntensity = m_random.Float(0.33f, 0.66f); } } else { m_precipitationStartTime = m_subsystemGameInfo.TotalElapsedGameTime + (double)(60f * m_random.Float(5f, 45f)); m_lightningIntensity = ((m_random.Float(0f, 1f) < 0.5f) ? m_random.Float(0.33f, 1f) : 0f); } m_precipitationEndTime = m_precipitationStartTime + (double)(60f * m_random.Float(3f, 6f)); } float num = (float)MathUtils.Max(0.0, MathUtils.Min(m_subsystemGameInfo.TotalElapsedGameTime - m_precipitationStartTime, m_precipitationEndTime - m_subsystemGameInfo.TotalElapsedGameTime)); GlobalPrecipitationIntensity = (m_subsystemGameInfo.WorldSettings.AreWeatherEffectsEnabled ? MathUtils.Saturate(num * 0.04f) : 0f); if (GlobalPrecipitationIntensity == 1f && SubsystemTime.PeriodicGameTimeEvent(1.0, 0.0)) { TerrainChunk[] allocatedChunks = SubsystemTerrain.Terrain.AllocatedChunks; for (int i = 0; i < allocatedChunks.Length; i++) { TerrainChunk terrainChunk = allocatedChunks[m_random.Int(0, allocatedChunks.Length - 1)]; if (terrainChunk.State < TerrainChunkState.InvalidVertices1 || !m_random.Bool(m_lightningIntensity * 0.0002f)) { continue; } int num2 = terrainChunk.Origin.X + m_random.Int(0, 15); int num3 = terrainChunk.Origin.Y + m_random.Int(0, 15); Vector3?vector = null; for (int j = num2 - 8; j < num2 + 8; j++) { for (int k = num3 - 8; k < num3 + 8; k++) { int topHeight = SubsystemTerrain.Terrain.GetTopHeight(j, k); if (!vector.HasValue || (float)topHeight > vector.Value.Y) { vector = new Vector3(j, topHeight, k); } } } if (vector.HasValue) { SubsystemSky.MakeLightningStrike(vector.Value); return; } } } if (Time.PeriodicEvent(0.5, 0.0)) { float num4 = 0f; if (GlobalPrecipitationIntensity > 0f) { float num5 = 0f; foreach (Vector3 listenerPosition in m_subsystemAudio.ListenerPositions) { int num6 = Terrain.ToCell(listenerPosition.X) - 5; int num7 = Terrain.ToCell(listenerPosition.Z) - 5; int num8 = Terrain.ToCell(listenerPosition.X) + 5; int num9 = Terrain.ToCell(listenerPosition.Z) + 5; Vector3 vector2 = default(Vector3); for (int l = num6; l <= num8; l++) { for (int m = num7; m <= num9; m++) { PrecipitationShaftInfo precipitationShaftInfo = GetPrecipitationShaftInfo(l, m); if (precipitationShaftInfo.Type == PrecipitationType.Rain && precipitationShaftInfo.Intensity > 0f) { vector2.X = (float)l + 0.5f; vector2.Y = MathUtils.Max(precipitationShaftInfo.YLimit, listenerPosition.Y); vector2.Z = (float)m + 0.5f; float num10 = vector2.X - listenerPosition.X; float num11 = 8f * (vector2.Y - listenerPosition.Y); float num12 = vector2.Z - listenerPosition.Z; float distance = MathUtils.Sqrt(num10 * num10 + num11 * num11 + num12 * num12); num5 += m_subsystemAudio.CalculateVolume(distance, 1.5f) * precipitationShaftInfo.Intensity; } } } } num4 = MathUtils.Max(num4, num5); } m_targetRainSoundVolume = MathUtils.Saturate(1.5f * num4 / m_rainVolumeFactor); } m_rainSound.Volume = MathUtils.Saturate(MathUtils.Lerp(m_rainSound.Volume, SettingsManager.SoundsVolume * m_targetRainSoundVolume, 5f * dt)); if (m_rainSound.Volume > AudioManager.MinAudibleVolume) { m_rainSound.Play(); } else { m_rainSound.Pause(); } }
public void Update(float dt) { double totalElapsedGameTime = m_subsystemGameInfo.TotalElapsedGameTime; foreach (Projectile projectile in m_projectiles) { if (projectile.ToRemove) { m_projectilesToRemove.Add(projectile); } else { Block block = BlocksManager.Blocks[Terrain.ExtractContents(projectile.Value)]; if (totalElapsedGameTime - projectile.CreationTime > 40.0) { projectile.ToRemove = true; } TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Z)); if (chunkAtCell == null || chunkAtCell.State <= TerrainChunkState.InvalidContents4) { projectile.NoChunk = true; if (projectile.TrailParticleSystem != null) { projectile.TrailParticleSystem.IsStopped = true; } } else { projectile.NoChunk = false; Vector3 position = projectile.Position; Vector3 vector = position + projectile.Velocity * dt; Vector3 v = block.ProjectileTipOffset * Vector3.Normalize(projectile.Velocity); BodyRaycastResult? bodyRaycastResult = m_subsystemBodies.Raycast(position + v, vector + v, 0.2f, (ComponentBody body, float distance) => true); TerrainRaycastResult?terrainRaycastResult = m_subsystemTerrain.Raycast(position + v, vector + v, useInteractionBoxes: false, skipAirBlocks: true, (int value, float distance) => BlocksManager.Blocks[Terrain.ExtractContents(value)].IsCollidable); bool flag = block.DisintegratesOnHit; if (terrainRaycastResult.HasValue || bodyRaycastResult.HasValue) { CellFace? cellFace = terrainRaycastResult.HasValue ? new CellFace?(terrainRaycastResult.Value.CellFace) : null; ComponentBody componentBody = bodyRaycastResult.HasValue ? bodyRaycastResult.Value.ComponentBody : null; SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(Terrain.ExtractContents(projectile.Value)); for (int i = 0; i < blockBehaviors.Length; i++) { flag |= blockBehaviors[i].OnHitAsProjectile(cellFace, componentBody, projectile); } projectile.ToRemove |= flag; } Vector3?vector2 = null; if (bodyRaycastResult.HasValue && (!terrainRaycastResult.HasValue || bodyRaycastResult.Value.Distance < terrainRaycastResult.Value.Distance)) { if (projectile.Velocity.Length() > 10f) { ComponentMiner.AttackBody(bodyRaycastResult.Value.ComponentBody, projectile.Owner, bodyRaycastResult.Value.HitPoint(), Vector3.Normalize(projectile.Velocity), block.GetProjectilePower(projectile.Value), isMeleeAttack: false); if (projectile.Owner != null && projectile.Owner.PlayerStats != null) { projectile.Owner.PlayerStats.RangedHits++; } } if (projectile.IsIncendiary) { bodyRaycastResult.Value.ComponentBody.Entity.FindComponent <ComponentOnFire>()?.SetOnFire(projectile?.Owner, m_random.Float(6f, 8f)); } vector = position; projectile.Velocity *= -0.05f; projectile.Velocity += m_random.Vector3(0.33f * projectile.Velocity.Length()); projectile.AngularVelocity *= -0.05f; } else if (terrainRaycastResult.HasValue) { CellFace cellFace2 = terrainRaycastResult.Value.CellFace; int cellValue = m_subsystemTerrain.Terrain.GetCellValue(cellFace2.X, cellFace2.Y, cellFace2.Z); int num = Terrain.ExtractContents(cellValue); Block block2 = BlocksManager.Blocks[num]; float num2 = projectile.Velocity.Length(); SubsystemBlockBehavior[] blockBehaviors2 = m_subsystemBlockBehaviors.GetBlockBehaviors(num); for (int j = 0; j < blockBehaviors2.Length; j++) { blockBehaviors2[j].OnHitByProjectile(cellFace2, projectile); } if (num2 > 10f && m_random.Float(0f, 1f) > block2.ProjectileResilience) { m_subsystemTerrain.DestroyCell(0, cellFace2.X, cellFace2.Y, cellFace2.Z, 0, noDrop: true, noParticleSystem: false); m_subsystemSoundMaterials.PlayImpactSound(cellValue, position, 1f); } if (projectile.IsIncendiary) { m_subsystemFireBlockBehavior.SetCellOnFire(terrainRaycastResult.Value.CellFace.X, terrainRaycastResult.Value.CellFace.Y, terrainRaycastResult.Value.CellFace.Z, 1f); Vector3 vector3 = projectile.Position - 0.75f * Vector3.Normalize(projectile.Velocity); for (int k = 0; k < 8; k++) { Vector3 v2 = (k == 0) ? Vector3.Normalize(projectile.Velocity) : m_random.Vector3(1.5f); TerrainRaycastResult?terrainRaycastResult2 = m_subsystemTerrain.Raycast(vector3, vector3 + v2, useInteractionBoxes: false, skipAirBlocks: true, (int value, float distance) => true); if (terrainRaycastResult2.HasValue) { m_subsystemFireBlockBehavior.SetCellOnFire(terrainRaycastResult2.Value.CellFace.X, terrainRaycastResult2.Value.CellFace.Y, terrainRaycastResult2.Value.CellFace.Z, 1f); } } } if (num2 > 5f) { m_subsystemSoundMaterials.PlayImpactSound(cellValue, position, 1f); } if (block.IsStickable && num2 > 10f && m_random.Bool(block2.ProjectileStickProbability)) { Vector3 v3 = Vector3.Normalize(projectile.Velocity); float s = MathUtils.Lerp(0.1f, 0.2f, MathUtils.Saturate((num2 - 15f) / 20f)); vector2 = position + terrainRaycastResult.Value.Distance * Vector3.Normalize(projectile.Velocity) + v3 * s; } else { Plane plane = cellFace2.CalculatePlane(); vector = position; if (plane.Normal.X != 0f) { projectile.Velocity *= new Vector3(-0.3f, 0.3f, 0.3f); } if (plane.Normal.Y != 0f) { projectile.Velocity *= new Vector3(0.3f, -0.3f, 0.3f); } if (plane.Normal.Z != 0f) { projectile.Velocity *= new Vector3(0.3f, 0.3f, -0.3f); } float num3 = projectile.Velocity.Length(); projectile.Velocity = num3 * Vector3.Normalize(projectile.Velocity + m_random.Vector3(num3 / 6f, num3 / 3f)); projectile.AngularVelocity *= -0.3f; } MakeProjectileNoise(projectile); } if (terrainRaycastResult.HasValue || bodyRaycastResult.HasValue) { if (flag) { m_subsystemParticles.AddParticleSystem(block.CreateDebrisParticleSystem(m_subsystemTerrain, projectile.Position, projectile.Value, 1f)); } else if (!projectile.ToRemove && (vector2.HasValue || projectile.Velocity.Length() < 1f)) { if (projectile.ProjectileStoppedAction == ProjectileStoppedAction.TurnIntoPickable) { int num4 = BlocksManager.DamageItem(projectile.Value, 1); if (num4 != 0) { if (vector2.HasValue) { CalculateVelocityAlignMatrix(block, vector2.Value, projectile.Velocity, out Matrix matrix); m_subsystemPickables.AddPickable(num4, 1, projectile.Position, Vector3.Zero, matrix); } else { m_subsystemPickables.AddPickable(num4, 1, position, Vector3.Zero, null); } } projectile.ToRemove = true; } else if (projectile.ProjectileStoppedAction == ProjectileStoppedAction.Disappear) { projectile.ToRemove = true; } } } float num5 = projectile.IsInWater ? MathUtils.Pow(0.001f, dt) : MathUtils.Pow(block.ProjectileDamping, dt); projectile.Velocity.Y += -10f * dt; projectile.Velocity *= num5; projectile.AngularVelocity *= num5; projectile.Position = vector; projectile.Rotation += projectile.AngularVelocity * dt; if (projectile.TrailParticleSystem != null) { if (!m_subsystemParticles.ContainsParticleSystem((ParticleSystemBase)projectile.TrailParticleSystem)) { m_subsystemParticles.AddParticleSystem((ParticleSystemBase)projectile.TrailParticleSystem); } Vector3 v4 = (projectile.TrailOffset != Vector3.Zero) ? Vector3.TransformNormal(projectile.TrailOffset, Matrix.CreateFromAxisAngle(Vector3.Normalize(projectile.Rotation), projectile.Rotation.Length())) : Vector3.Zero; projectile.TrailParticleSystem.Position = projectile.Position + v4; if (projectile.IsInWater) { projectile.TrailParticleSystem.IsStopped = true; } } bool flag2 = IsWater(projectile.Position); if (projectile.IsInWater != flag2) { if (flag2) { float num6 = new Vector2(projectile.Velocity.X + projectile.Velocity.Z).Length(); if (num6 > 6f && num6 > 4f * MathUtils.Abs(projectile.Velocity.Y)) { projectile.Velocity *= 0.5f; projectile.Velocity.Y *= -1f; flag2 = false; } else { projectile.Velocity *= 0.2f; } float?surfaceHeight = m_subsystemFluidBlockBehavior.GetSurfaceHeight(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Y), Terrain.ToCell(projectile.Position.Z)); if (surfaceHeight.HasValue) { m_subsystemParticles.AddParticleSystem(new WaterSplashParticleSystem(m_subsystemTerrain, new Vector3(projectile.Position.X, surfaceHeight.Value, projectile.Position.Z), large: false)); m_subsystemAudio.PlayRandomSound("Audio/Splashes", 1f, m_random.Float(-0.2f, 0.2f), projectile.Position, 6f, autoDelay: true); MakeProjectileNoise(projectile); } } projectile.IsInWater = flag2; } if (IsMagma(projectile.Position)) { m_subsystemParticles.AddParticleSystem(new MagmaSplashParticleSystem(m_subsystemTerrain, projectile.Position, large: false)); m_subsystemAudio.PlayRandomSound("Audio/Sizzles", 1f, m_random.Float(-0.2f, 0.2f), projectile.Position, 3f, autoDelay: true); projectile.ToRemove = true; m_subsystemExplosions.TryExplodeBlock(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Y), Terrain.ToCell(projectile.Position.Z), projectile.Value); } if (m_subsystemTime.PeriodicGameTimeEvent(1.0, (double)(projectile.GetHashCode() % 100) / 100.0) && (m_subsystemFireBlockBehavior.IsCellOnFire(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Y + 0.1f), Terrain.ToCell(projectile.Position.Z)) || m_subsystemFireBlockBehavior.IsCellOnFire(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Y + 0.1f) - 1, Terrain.ToCell(projectile.Position.Z)))) { m_subsystemAudio.PlayRandomSound("Audio/Sizzles", 1f, m_random.Float(-0.2f, 0.2f), projectile.Position, 3f, autoDelay: true); projectile.ToRemove = true; m_subsystemExplosions.TryExplodeBlock(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Y), Terrain.ToCell(projectile.Position.Z), projectile.Value); } } } } foreach (Projectile item in m_projectilesToRemove) { if (item.TrailParticleSystem != null) { item.TrailParticleSystem.IsStopped = true; } m_projectiles.Remove(item); if (this.ProjectileRemoved != null) { this.ProjectileRemoved(item); } } m_projectilesToRemove.Clear(); }