public void Update(float dt) { if (IsSleeping && m_componentPlayer.ComponentHealth.Health > 0f) { m_sleepFactor = MathUtils.Min(m_sleepFactor + 0.33f * Time.FrameDuration, 1f); m_minWetness = MathUtils.Min(m_minWetness, m_componentPlayer.ComponentVitalStats.Wetness); m_componentPlayer.PlayerStats.TimeSlept += m_subsystemGameInfo.TotalElapsedGameTimeDelta; if ((m_componentPlayer.ComponentVitalStats.Sleep >= 1f || m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative) && m_subsystemTimeOfDay.TimeOfDay > 0.3f && m_subsystemTimeOfDay.TimeOfDay < 0.599999964f && m_sleepStartTime.HasValue && m_subsystemGameInfo.TotalElapsedGameTime > m_sleepStartTime + 180.0) { WakeUp(); } if (m_componentPlayer.ComponentHealth.HealthChange < 0f && (m_componentPlayer.ComponentHealth.Health < 0.5f || m_componentPlayer.ComponentVitalStats.Sleep > 0.5f)) { WakeUp(); } if (m_componentPlayer.ComponentVitalStats.Wetness > m_minWetness + 0.05f && m_componentPlayer.ComponentVitalStats.Sleep > 0.2f) { WakeUp(); m_subsystemTime.QueueGameTimeDelayedExecution(m_subsystemTime.GameTime + 1.0, delegate { m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 6), Color.White, blinking: true, playNotificationSound: true); }); } if (m_sleepStartTime.HasValue) { float num = (float)(m_subsystemGameInfo.TotalElapsedGameTime - m_sleepStartTime.Value); if (m_allowManualWakeUp && num > 10f) { if (m_componentPlayer.GameWidget.Input.Any && !DialogsManager.HasDialogs(m_componentPlayer.GameWidget)) { m_componentPlayer.GameWidget.Input.Clear(); WakeUp(); m_subsystemTime.QueueGameTimeDelayedExecution(m_subsystemTime.GameTime + 2.0, delegate { m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 7), Color.White, blinking: true, playNotificationSound: false); }); } m_messageFactor = MathUtils.Min(m_messageFactor + 0.5f * Time.FrameDuration, 1f); m_componentPlayer.ComponentScreenOverlays.Message = LanguageControl.Get(fName, 8); m_componentPlayer.ComponentScreenOverlays.MessageFactor = m_messageFactor; } if (!m_allowManualWakeUp && num > 5f) { m_messageFactor = MathUtils.Min(m_messageFactor + 1f * Time.FrameDuration, 1f); m_componentPlayer.ComponentScreenOverlays.Message = LanguageControl.Get(fName, 9); m_componentPlayer.ComponentScreenOverlays.MessageFactor = m_messageFactor; } } } else { m_sleepFactor = MathUtils.Max(m_sleepFactor - 1f * Time.FrameDuration, 0f); } m_componentPlayer.ComponentScreenOverlays.BlackoutFactor = MathUtils.Max(m_componentPlayer.ComponentScreenOverlays.BlackoutFactor, m_sleepFactor); if (m_sleepFactor > 0.01f) { m_componentPlayer.ComponentScreenOverlays.FloatingMessage = LanguageControl.Get(fName, 10); m_componentPlayer.ComponentScreenOverlays.FloatingMessageFactor = MathUtils.Saturate(10f * (m_sleepFactor - 0.9f)); } }
public void ShipView_Enter() { ComponentBody componentBody = m_componentPlayer.Entity.FindComponent <ComponentBody>(throwOnError: true); Vector2 vector = FindOceanDirection(m_subsystemTerrain.TerrainContentsGenerator, componentBody.Position.XZ); Vector2 vector2 = componentBody.Position.XZ + 25f * vector; bool isPlayerMounted = m_componentPlayer.ComponentRider.Mount != null; Vector2 vector3 = vector2; float num = float.MinValue; for (int i = Terrain.ToCell(vector2.Y) - 15; i < Terrain.ToCell(vector2.Y) + 15; i++) { for (int j = Terrain.ToCell(vector2.X) - 15; j < Terrain.ToCell(vector2.X) + 15; j++) { float num2 = ScoreShipPosition(componentBody.Position.XZ, j, i); if (num2 > num) { num = num2; vector3 = new Vector2(j, i); } } } DatabaseObject databaseObject = base.Project.GameDatabase.Database.FindDatabaseObject("IntroShip", base.Project.GameDatabase.EntityTemplateType, throwIfNotFound: true); ValuesDictionary valuesDictionary = new ValuesDictionary(); valuesDictionary.PopulateFromDatabaseObject(databaseObject); Entity entity = base.Project.CreateEntity(valuesDictionary); Vector3 vector4 = new Vector3(vector3.X, (float)m_subsystemTerrain.TerrainContentsGenerator.OceanLevel + 0.5f, vector3.Y); entity.FindComponent <ComponentFrame>(throwOnError: true).Position = vector4; entity.FindComponent <ComponentIntroShip>(throwOnError: true).Heading = Vector2.Angle(vector, -Vector2.UnitY); base.Project.AddEntity(entity); m_subsystemTime.QueueGameTimeDelayedExecution(2.0, delegate { m_componentPlayer.ComponentGui.DisplayLargeMessage(null, LanguageControl.Get(fName, 1), 5f, 0f); }); m_subsystemTime.QueueGameTimeDelayedExecution(7.0, delegate { if (isPlayerMounted) { m_componentPlayer.ComponentGui.DisplayLargeMessage(null, LanguageControl.Get(fName, 2), 5f, 0f); } else { m_componentPlayer.ComponentGui.DisplayLargeMessage(null, LanguageControl.Get(fName, 3), 5f, 0f); } }); m_subsystemTime.QueueGameTimeDelayedExecution(12.0, delegate { m_componentPlayer.ComponentGui.DisplayLargeMessage(null, LanguageControl.Get(fName, 4), 5f, 0f); }); IntroCamera introCamera = m_componentPlayer.GameWidget.FindCamera <IntroCamera>(); m_componentPlayer.GameWidget.ActiveCamera = introCamera; introCamera.CameraPosition = vector4 + new Vector3(12f * vector.X, 8f, 12f * vector.Y) + new Vector3(-5f * vector.Y, 0f, 5f * vector.X); introCamera.TargetPosition = m_componentPlayer.ComponentCreatureModel.EyePosition + 2.5f * new Vector3(vector.X, 0f, vector.Y); introCamera.Speed = 0f; introCamera.TargetCameraPosition = m_componentPlayer.ComponentCreatureModel.EyePosition; }
public void StartFlu() { if (m_fluDuration == 0f) { m_componentPlayer.PlayerStats.TimesHadFlu++; } m_fluDuration = 900f; m_subsystemTime.QueueGameTimeDelayedExecution(m_subsystemTime.GameTime + 10.0, delegate { m_componentPlayer.ComponentVitalStats.MakeSleepy(0.2f); }); }
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_isEnabled = valuesDictionary.GetValue <bool>("IsEnabled"); m_stateMachine.AddState("Inactive", delegate { m_importanceLevel = 0f; SummonTarget = null; m_summonedTime = 0.0; }, delegate { if (m_isEnabled && SummonTarget != null && m_summonedTime == 0.0) { m_subsystemTime.QueueGameTimeDelayedExecution(m_subsystemTime.GameTime + 0.5, delegate { m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: true); m_importanceLevel = 270f; m_summonedTime = m_subsystemTime.GameTime; }); } if (IsActive) { m_stateMachine.TransitionTo("FollowTarget"); } }, null); m_stateMachine.AddState("FollowTarget", delegate { FollowTarget(noDelay: true); }, delegate { if (!IsActive) { m_stateMachine.TransitionTo("Inactive"); } else if (SummonTarget == null || m_componentPathfinding.IsStuck || m_subsystemTime.GameTime - m_summonedTime > 30.0) { m_importanceLevel = 0f; } else if (!m_componentPathfinding.Destination.HasValue) { if (m_stoppedTime < 0.0) { m_stoppedTime = m_subsystemTime.GameTime; } if (m_subsystemTime.GameTime - m_stoppedTime > 6.0) { m_importanceLevel = 0f; } } FollowTarget(noDelay: false); m_componentCreature.ComponentCreatureModel.LookRandomOrder = true; }, null); m_stateMachine.TransitionTo("Inactive"); }
public void NauseaEffect() { m_lastNauseaTime = m_subsystemTime.GameTime; m_componentPlayer.ComponentCreatureSounds.PlayMoanSound(); float injury = MathUtils.Min(0.1f, m_componentPlayer.ComponentHealth.Health - 0.075f); if (injury > 0f) { m_subsystemTime.QueueGameTimeDelayedExecution(m_subsystemTime.GameTime + 0.75, delegate { m_componentPlayer.ComponentHealth.Injure(injury, null, ignoreInvulnerability: false, LanguageControl.Get(fName, 1)); }); } if (m_pukeParticleSystem == null && (!m_lastPukeTime.HasValue || m_subsystemTime.GameTime - m_lastPukeTime > 50.0)) { m_lastPukeTime = m_subsystemTime.GameTime; m_pukeParticleSystem = new PukeParticleSystem(m_subsystemTerrain); m_subsystemParticles.AddParticleSystem(m_pukeParticleSystem); m_componentPlayer.ComponentCreatureSounds.PlayPukeSound(); base.Project.FindSubsystem <SubsystemNoise>(throwOnError: true).MakeNoise(m_componentPlayer.ComponentBody.Position, 0.25f, 10f); m_greenoutDuration = 0.8f; m_componentPlayer.PlayerStats.TimesPuked++; } else { m_greenoutDuration = MathUtils.Lerp(4f, 2f, m_componentPlayer.ComponentHealth.Health); if (!m_lastMessageTime.HasValue || Time.FrameStartTime - m_lastMessageTime > 60.0) { m_lastMessageTime = Time.FrameStartTime; m_subsystemTime.QueueGameTimeDelayedExecution(m_subsystemTime.GameTime + 1.5, delegate { m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 2), Color.White, blinking: true, playNotificationSound: true); }); } } }
public override void OnFiredAsProjectile(Projectile projectile) { int data = Terrain.ExtractData(projectile.Value); float num = (FireworksBlock.GetAltitude(data) == 0) ? 0.8f : 1.3f; m_subsystemProjectiles.AddTrail(projectile, Vector3.Zero, new FireworksTrailParticleSystem()); m_subsystemAudio.PlayRandomSound("Audio/FireworksWhoosh", 1f, m_random.Float(-0.2f, 0.2f), projectile.Position, 8f, autoDelay: true); m_subsystemNoise.MakeNoise(projectile.Position, 1f, 10f); m_subsystemTime.QueueGameTimeDelayedExecution(m_subsystemTime.GameTime + (double)num, delegate { if (!projectile.ToRemove) { projectile.ToRemove = true; ExplodeFireworks(projectile.Position, data); } }); }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemGameInfo = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true); m_subsystemPlayers = base.Project.FindSubsystem <SubsystemPlayers>(throwOnError: true); m_subsystemSky = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true); m_subsystemBodies = base.Project.FindSubsystem <SubsystemBodies>(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_componentMiner = base.Entity.FindComponent <ComponentMiner>(throwOnError: true); m_componentFeedBehavior = base.Entity.FindComponent <ComponentRandomFeedBehavior>(); m_componentCreatureModel = base.Entity.FindComponent <ComponentCreatureModel>(throwOnError: true); m_dayChaseRange = valuesDictionary.GetValue <float>("DayChaseRange"); m_nightChaseRange = valuesDictionary.GetValue <float>("NightChaseRange"); m_dayChaseTime = valuesDictionary.GetValue <float>("DayChaseTime"); m_nightChaseTime = valuesDictionary.GetValue <float>("NightChaseTime"); m_autoChaseMask = valuesDictionary.GetValue <CreatureCategory>("AutoChaseMask"); m_chaseNonPlayerProbability = valuesDictionary.GetValue <float>("ChaseNonPlayerProbability"); m_chaseWhenAttackedProbability = valuesDictionary.GetValue <float>("ChaseWhenAttackedProbability"); m_chaseOnTouchProbability = valuesDictionary.GetValue <float>("ChaseOnTouchProbability"); m_componentCreature.ComponentHealth.Attacked += delegate(ComponentCreature attacker) { if (m_random.Float(0f, 1f) < m_chaseWhenAttackedProbability) { if (m_chaseWhenAttackedProbability >= 1f) { Attack(attacker, 30f, 60f, isPersistent: true); } else { Attack(attacker, 7f, 7f, isPersistent: false); } } }; m_componentCreature.ComponentBody.CollidedWithBody += delegate(ComponentBody body) { if (m_target == null && m_autoChaseSuppressionTime <= 0f && m_random.Float(0f, 1f) < m_chaseOnTouchProbability) { ComponentCreature componentCreature2 = body.Entity.FindComponent <ComponentCreature>(); if (componentCreature2 != null) { bool flag2 = m_subsystemPlayers.IsPlayer(body.Entity); bool flag3 = (componentCreature2.Category & m_autoChaseMask) != 0; if ((flag2 && m_subsystemGameInfo.WorldSettings.GameMode > GameMode.Harmless) || (!flag2 && flag3)) { Attack(componentCreature2, 7f, 7f, isPersistent: false); } } } if (m_target != null && body == m_target.ComponentBody && body.StandingOnBody == m_componentCreature.ComponentBody) { m_componentCreature.ComponentLocomotion.JumpOrder = 1f; } }; m_stateMachine.AddState("LookingForTarget", delegate { m_importanceLevel = 0f; m_target = null; }, delegate { if (IsActive) { m_stateMachine.TransitionTo("Chasing"); } else if (m_autoChaseSuppressionTime <= 0f && (m_target == null || ScoreTarget(m_target) <= 0f) && m_componentCreature.ComponentHealth.Health > 0.4f) { m_range = ((m_subsystemSky.SkyLightIntensity < 0.2f) ? m_nightChaseRange : m_dayChaseRange); ComponentCreature componentCreature = FindTarget(); if (componentCreature != null) { m_targetInRangeTime += m_dt; } else { m_targetInRangeTime = 0f; } if (m_targetInRangeTime > 3f) { bool flag = m_subsystemSky.SkyLightIntensity >= 0.1f; float maxRange = flag ? (m_dayChaseRange + 6f) : (m_nightChaseRange + 6f); float maxChaseTime = flag ? (m_dayChaseTime * m_random.Float(0.75f, 1f)) : (m_nightChaseTime * m_random.Float(0.75f, 1f)); Attack(componentCreature, maxRange, maxChaseTime, (!flag) ? true : false); } } }, null); m_stateMachine.AddState("RandomMoving", delegate { m_componentPathfinding.SetDestination(m_componentCreature.ComponentBody.Position + new Vector3(6f * m_random.Float(-1f, 1f), 0f, 6f * m_random.Float(-1f, 1f)), 1f, 1f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null); }, delegate { if (m_componentPathfinding.IsStuck || !m_componentPathfinding.Destination.HasValue) { m_stateMachine.TransitionTo("Chasing"); } if (!IsActive) { m_stateMachine.TransitionTo("LookingForTarget"); } }, delegate { m_componentPathfinding.Stop(); }); m_stateMachine.AddState("Chasing", delegate { m_subsystemNoise.MakeNoise(m_componentCreature.ComponentBody, 0.25f, 6f); m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: false); m_nextUpdateTime = 0.0; }, delegate { if (!IsActive) { m_stateMachine.TransitionTo("LookingForTarget"); } else if (m_chaseTime <= 0f) { m_autoChaseSuppressionTime = m_random.Float(10f, 60f); m_importanceLevel = 0f; } else if (m_target == null) { m_importanceLevel = 0f; } else if (m_target.ComponentHealth.Health <= 0f) { if (m_componentFeedBehavior != null) { m_subsystemTime.QueueGameTimeDelayedExecution(m_subsystemTime.GameTime + (double)m_random.Float(1f, 3f), delegate { if (m_target != null) { m_componentFeedBehavior.Feed(m_target.ComponentBody.Position); } }); } m_importanceLevel = 0f; } else if (!m_isPersistent && m_componentPathfinding.IsStuck) { m_importanceLevel = 0f; } else if (m_isPersistent && m_componentPathfinding.IsStuck) { m_stateMachine.TransitionTo("RandomMoving"); } else { if (ScoreTarget(m_target) <= 0f) { m_targetUnsuitableTime += m_dt; } else { m_targetUnsuitableTime = 0f; } if (m_targetUnsuitableTime > 3f) { m_importanceLevel = 0f; } else { int maxPathfindingPositions = 0; if (m_isPersistent) { maxPathfindingPositions = (m_subsystemTime.FixedTimeStep.HasValue ? 1500 : 500); } BoundingBox boundingBox = m_componentCreature.ComponentBody.BoundingBox; BoundingBox boundingBox2 = m_target.ComponentBody.BoundingBox; Vector3 v = 0.5f * (boundingBox.Min + boundingBox.Max); Vector3 vector = 0.5f * (boundingBox2.Min + boundingBox2.Max); float num = Vector3.Distance(v, vector); float num2 = (num < 4f) ? 0.2f : 0f; m_componentPathfinding.SetDestination(vector + num2 * num * m_target.ComponentBody.Velocity, 1f, 1.5f, maxPathfindingPositions, useRandomMovements: true, ignoreHeightDifference: false, raycastDestination: true, m_target.ComponentBody); if (m_random.Float(0f, 1f) < 0.33f * m_dt) { m_componentCreature.ComponentCreatureSounds.PlayAttackSound(); } } } }, null); m_stateMachine.TransitionTo("LookingForTarget"); }