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_componentFishModel = base.Entity.FindComponent <ComponentFishModel>(throwOnError: true); m_stateMachine.AddState("Inactive", null, delegate { if (IsOutOfWater()) { m_outOfWaterTime += m_subsystemTime.GameTimeDelta; } else { m_outOfWaterTime = 0f; } if (m_outOfWaterTime > 3f) { m_importanceLevel = 1000f; } if (IsActive) { m_stateMachine.TransitionTo("Jump"); } }, null); m_stateMachine.AddState("Jump", null, delegate { m_componentFishModel.BendOrder = 2f * (2f * MathUtils.Saturate(SimplexNoise.OctavedNoise((float)MathUtils.Remainder(m_subsystemTime.GameTime, 1000.0), 1.2f * m_componentCreature.ComponentLocomotion.TurnSpeed, 1, 1f, 1f)) - 1f); if (!IsActive) { m_stateMachine.TransitionTo("Inactive"); } if (!IsOutOfWater()) { m_importanceLevel = 0f; } if (m_random.Float(0f, 1f) < 2.5f * m_subsystemTime.GameTimeDelta) { m_componentCreature.ComponentLocomotion.JumpOrder = m_random.Float(0.33f, 1f); m_direction = new Vector2(MathUtils.Sign(m_componentFishModel.BendOrder.Value), 0f); } if (!m_componentCreature.ComponentBody.StandingOnValue.HasValue) { m_componentCreature.ComponentLocomotion.TurnOrder = new Vector2(0f - m_componentFishModel.BendOrder.Value, 0f); m_componentCreature.ComponentLocomotion.WalkOrder = m_direction; } }, 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"); }