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 override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemTerrain = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true); 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_componentMiner = base.Entity.FindComponent <ComponentMiner>(throwOnError: true); m_componentFishModel = base.Entity.FindComponent <ComponentFishModel>(throwOnError: true); m_componentSwimAwayBehavior = base.Entity.FindComponent <ComponentSwimAwayBehavior>(throwOnError: true); string digInBlockName = valuesDictionary.GetValue <string>("DigInBlockName"); m_digInBlockIndex = ((!string.IsNullOrEmpty(digInBlockName)) ? BlocksManager.Blocks.First((Block b) => b.GetType().Name == digInBlockName).BlockIndex : 0); m_maxDigInDepth = valuesDictionary.GetValue <float>("MaxDigInDepth"); m_componentCreature.ComponentBody.CollidedWithBody += delegate(ComponentBody b) { m_collidedWithBody = b; }; m_stateMachine.AddState("Inactive", delegate { m_importanceLevel = 0f; }, delegate { if (m_random.Float(0f, 1f) < 0.5f * m_subsystemTime.GameTimeDelta && m_subsystemTime.GameTime > m_digOutTime + 15.0 && m_digInBlockIndex != 0) { int x = Terrain.ToCell(m_componentCreature.ComponentBody.Position.X); int y = Terrain.ToCell(m_componentCreature.ComponentBody.Position.Y - 0.9f); int z = Terrain.ToCell(m_componentCreature.ComponentBody.Position.Z); if (m_subsystemTerrain.Terrain.GetCellContents(x, y, z) == m_digInBlockIndex) { m_importanceLevel = m_random.Float(1f, 3f); } } if (IsActive) { m_stateMachine.TransitionTo("Sink"); } }, null); m_stateMachine.AddState("Sink", delegate { m_importanceLevel = 10f; m_sinkTime = m_subsystemTime.GameTime; m_componentPathfinding.Stop(); }, delegate { if (m_random.Float(0f, 1f) < 2f * m_subsystemTime.GameTimeDelta && m_componentCreature.ComponentBody.StandingOnValue == m_digInBlockIndex && m_componentCreature.ComponentBody.Velocity.LengthSquared() < 1f) { m_stateMachine.TransitionTo("DigIn"); } if (!IsActive || m_subsystemTime.GameTime > m_sinkTime + 6.0) { m_stateMachine.TransitionTo("Inactive"); } }, null); m_stateMachine.AddState("DigIn", delegate { m_digInTime = m_subsystemTime.GameTime; m_digOutTime = m_digInTime + (double)m_random.Float(30f, 60f); }, delegate { m_componentFishModel.DigInOrder = m_maxDigInDepth; if (m_collidedWithBody != null) { if (m_subsystemTime.GameTime - m_digInTime > 2.0 && m_collidedWithBody.Density < 0.95f) { m_componentMiner.Hit(m_collidedWithBody, m_collidedWithBody.Position, Vector3.Normalize(m_collidedWithBody.Position - m_componentCreature.ComponentBody.Position)); } m_componentSwimAwayBehavior.SwimAwayFrom(m_collidedWithBody); m_stateMachine.TransitionTo("Inactive"); } if (!IsActive || m_subsystemTime.GameTime >= m_digOutTime || m_componentCreature.ComponentBody.StandingOnValue != m_digInBlockIndex || m_componentCreature.ComponentBody.Velocity.LengthSquared() > 1f) { m_stateMachine.TransitionTo("Inactive"); } }, null); m_stateMachine.TransitionTo("Inactive"); }
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"); }
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"); }
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 override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemGameInfo = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true); m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_subsystemSky = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true); m_subsystemBodies = base.Project.FindSubsystem <SubsystemBodies>(throwOnError: true); m_componentCreature = base.Entity.FindComponent <ComponentCreature>(throwOnError: true); m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true); m_dayRange = valuesDictionary.GetValue <float>("DayRange"); m_nightRange = valuesDictionary.GetValue <float>("NightRange"); m_minRange = valuesDictionary.GetValue <float>("MinRange"); m_stateMachine.AddState("Inactive", delegate { m_importanceLevel = 0f; m_target = null; }, delegate { if (IsActive) { m_stateMachine.TransitionTo("Move"); } if (m_subsystemGameInfo.WorldSettings.GameMode > GameMode.Harmless) { m_target = FindTarget(); if (m_target != null) { ComponentPlayer componentPlayer = m_target.Entity.FindComponent <ComponentPlayer>(); if (componentPlayer != null && componentPlayer.ComponentSleep.IsSleeping) { m_importanceLevel = 5f; } else if (m_random.Float(0f, 1f) < 0.05f * m_dt) { m_importanceLevel = m_random.Float(1f, 4f); } } else { m_importanceLevel = 0f; } } }, null); m_stateMachine.AddState("Move", delegate { if (m_target != null) { m_componentPathfinding.SetDestination(m_target.ComponentBody.Position, m_random.Float(0.5f, 0.7f), m_minRange, 500, useRandomMovements: true, ignoreHeightDifference: true, raycastDestination: false, null); } }, delegate { if (!IsActive) { m_stateMachine.TransitionTo("Inactive"); } else if (m_target == null || m_componentPathfinding.IsStuck || !m_componentPathfinding.Destination.HasValue || ScoreTarget(m_target) <= 0f) { m_importanceLevel = 0f; } if (m_random.Float(0f, 1f) < 0.1f * m_dt) { m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: true); } m_componentCreature.ComponentCreatureModel.LookRandomOrder = true; }, null); m_stateMachine.TransitionTo("Inactive"); }
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 override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_componentCreature = base.Entity.FindComponent <ComponentCreature>(throwOnError: true); m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true); m_componentCreature.ComponentBody.CollidedWithBody += delegate(ComponentBody body) { m_target = body; m_isFast = (MathUtils.Max(body.Velocity.Length(), m_componentCreature.ComponentBody.Velocity.Length()) > 3f); }; m_stateMachine.AddState("Inactive", delegate { m_importanceLevel = 0f; m_target = null; }, delegate { if (IsActive) { m_stateMachine.TransitionTo("Move"); } if (m_target != null) { m_importanceLevel = 6f; } }, null); m_stateMachine.AddState("Move", delegate { if (m_random.Float(0f, 1f) < 0.5f) { m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: true); } if (m_target != null) { Vector3 vector = m_target.Position + 0.5f * m_target.Velocity; Vector2 v = Vector2.Normalize(m_componentCreature.ComponentBody.Position.XZ - vector.XZ); Vector2 vector2 = Vector2.Zero; float num = float.MinValue; for (float num2 = 0f; num2 < (float)Math.PI * 2f; num2 += 0.1f) { Vector2 vector3 = Vector2.CreateFromAngle(num2); if (Vector2.Dot(vector3, v) > 0.2f) { float num3 = Vector2.Dot(m_componentCreature.ComponentBody.Matrix.Forward.XZ, vector3); if (num3 > num) { vector2 = vector3; num = num3; } } } float s = m_random.Float(1.5f, 2f); float speed = m_isFast ? 0.7f : 0.35f; m_componentPathfinding.SetDestination(m_componentCreature.ComponentBody.Position + s * new Vector3(vector2.X, 0f, vector2.Y), speed, 1f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null); } }, delegate { if (!IsActive) { m_stateMachine.TransitionTo("Inactive"); } else if (m_componentPathfinding.IsStuck || !m_componentPathfinding.Destination.HasValue) { m_importanceLevel = 0f; } m_componentCreature.ComponentCreatureModel.LookRandomOrder = true; }, null); m_stateMachine.TransitionTo("Inactive"); }