public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemGlow          = base.Project.FindSubsystem <SubsystemGlow>(throwOnError: true);
     m_subsystemTerrain       = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true);
     m_componentCreatureModel = base.Entity.FindComponent <ComponentCreatureModel>(throwOnError: true);
     GlowingEyesOffset        = valuesDictionary.GetValue <Vector3>("GlowingEyesOffset");
     GlowingEyesColor         = valuesDictionary.GetValue <Color>("GlowingEyesColor");
 }
예제 #2
0
        public override void Update(float dt)
        {
            if (m_componentCreature.ComponentBody.IsSneaking)
            {
                m_sneakFactor = MathUtils.Min(m_sneakFactor + 2f * dt, 1f);
            }
            else
            {
                m_sneakFactor = MathUtils.Max(m_sneakFactor - 2f * dt, 0f);
            }
            if ((m_componentSleep != null && m_componentSleep.IsSleeping) || m_componentCreature.ComponentHealth.Health <= 0f)
            {
                m_lieDownFactorEye   = MathUtils.Min(m_lieDownFactorEye + 1f * dt, 1f);
                m_lieDownFactorModel = MathUtils.Min(m_lieDownFactorModel + 3f * dt, 1f);
            }
            else
            {
                m_lieDownFactorEye   = MathUtils.Max(m_lieDownFactorEye - 1f * dt, 0f);
                m_lieDownFactorModel = MathUtils.Max(m_lieDownFactorModel - 3f * dt, 0f);
            }
            bool  flag           = true;
            bool  flag2          = true;
            float footstepsPhase = m_footstepsPhase;

            if (m_componentCreature.ComponentLocomotion.LadderValue.HasValue)
            {
                m_footstepsPhase += 1.5f * m_walkAnimationSpeed * m_componentCreature.ComponentBody.Velocity.Length() * dt;
                flag2             = false;
            }
            else if (!m_componentCreature.ComponentLocomotion.IsCreativeFlyEnabled)
            {
                float num = m_componentCreature.ComponentLocomotion.SlipSpeed ?? (m_componentCreature.ComponentBody.Velocity.XZ - m_componentCreature.ComponentBody.StandingOnVelocity.XZ).Length();
                if (num > 0.5f)
                {
                    base.MovementAnimationPhase += num * dt * m_walkAnimationSpeed;
                    m_footstepsPhase            += 1f * m_walkAnimationSpeed * num * dt;
                    flag  = false;
                    flag2 = false;
                }
            }
            if (flag)
            {
                float num2 = 0.5f * MathUtils.Floor(2f * base.MovementAnimationPhase);
                if (base.MovementAnimationPhase != num2)
                {
                    if (base.MovementAnimationPhase - num2 > 0.25f)
                    {
                        base.MovementAnimationPhase = MathUtils.Min(base.MovementAnimationPhase + 2f * dt, num2 + 0.5f);
                    }
                    else
                    {
                        base.MovementAnimationPhase = MathUtils.Max(base.MovementAnimationPhase - 2f * dt, num2);
                    }
                }
            }
            if (flag2)
            {
                m_footstepsPhase = 0f;
            }
            float          num3           = 0f;
            ComponentMount componentMount = (m_componentRider != null) ? m_componentRider.Mount : null;

            if (componentMount != null)
            {
                ComponentCreatureModel componentCreatureModel = componentMount.Entity.FindComponent <ComponentCreatureModel>();
                if (componentCreatureModel != null)
                {
                    base.Bob = componentCreatureModel.Bob;
                    num3     = base.Bob;
                }
                m_headingOffset = 0f;
            }
            else
            {
                float x = MathUtils.Sin((float)Math.PI * 2f * base.MovementAnimationPhase);
                num3 = m_walkBobHeight * MathUtils.Sqr(x);
                float num4 = 0f;
                if (m_componentCreature.ComponentLocomotion.LastWalkOrder.HasValue && m_componentCreature.ComponentLocomotion.LastWalkOrder != Vector2.Zero)
                {
                    num4 = Vector2.Angle(Vector2.UnitY, m_componentCreature.ComponentLocomotion.LastWalkOrder.Value);
                }
                m_headingOffset += MathUtils.NormalizeAngle(num4 - m_headingOffset) * MathUtils.Saturate(8f * m_subsystemTime.GameTimeDelta);
                m_headingOffset  = MathUtils.NormalizeAngle(m_headingOffset);
            }
            float num5 = MathUtils.Min(12f * m_subsystemTime.GameTimeDelta, 1f);

            base.Bob += num5 * (num3 - base.Bob);
            base.IsAttackHitMoment = false;
            if (base.AttackOrder)
            {
                m_punchFactor = MathUtils.Min(m_punchFactor + 4f * dt, 1f);
                float punchPhase = m_punchPhase;
                m_punchPhase = MathUtils.Remainder(m_punchPhase + dt * 2f, 1f);
                if (punchPhase < 0.5f && m_punchPhase >= 0.5f)
                {
                    base.IsAttackHitMoment = true;
                    m_punchCounter++;
                }
            }
            else
            {
                m_punchFactor = MathUtils.Max(m_punchFactor - 4f * dt, 0f);
                if (m_punchPhase != 0f)
                {
                    if (m_punchPhase > 0.5f)
                    {
                        m_punchPhase = MathUtils.Remainder(MathUtils.Min(m_punchPhase + dt * 2f, 1f), 1f);
                    }
                    else if (m_punchPhase > 0f)
                    {
                        m_punchPhase = MathUtils.Max(m_punchPhase - dt * m_punchPhase, 0f);
                    }
                }
            }
            m_rowLeft  = base.RowLeftOrder;
            m_rowRight = base.RowRightOrder;
            if ((m_rowLeft || m_rowRight) && componentMount != null && componentMount.ComponentBody.ImmersionFactor > 0f && MathUtils.Floor(1.1000000238418579 * m_subsystemTime.GameTime) != MathUtils.Floor(1.1000000238418579 * (m_subsystemTime.GameTime - (double)m_subsystemTime.GameTimeDelta)))
            {
                m_subsystemAudio.PlayRandomSound("Audio/Rowing", m_random.Float(0.4f, 0.6f), m_random.Float(-0.3f, 0.2f), m_componentCreature.ComponentBody.Position, 3f, autoDelay: true);
            }
            float num6 = MathUtils.Floor(m_footstepsPhase);

            if (m_footstepsPhase > num6 && footstepsPhase <= num6)
            {
                if (!m_componentCreature.ComponentBody.IsSneaking)
                {
                    m_subsystemNoise.MakeNoise(m_componentCreature.ComponentBody, 0.25f, 8f);
                }
                if (!m_componentCreature.ComponentCreatureSounds.PlayFootstepSound(1f))
                {
                    m_footstepsPhase = 0f;
                }
            }
            m_aimHandAngle               = base.AimHandAngleOrder;
            m_inHandItemOffset           = Vector3.Lerp(m_inHandItemOffset, base.InHandItemOffsetOrder, 10f * dt);
            m_inHandItemRotation         = Vector3.Lerp(m_inHandItemRotation, base.InHandItemRotationOrder, 10f * dt);
            base.AttackOrder             = false;
            base.RowLeftOrder            = false;
            base.RowRightOrder           = false;
            base.AimHandAngleOrder       = 0f;
            base.InHandItemOffsetOrder   = Vector3.Zero;
            base.InHandItemRotationOrder = Vector3.Zero;
            base.Update(dt);
        }
 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");
 }
예제 #4
0
 public void Draw(Camera camera, int drawOrder)
 {
     if (m_componentPlayer.ComponentHealth.Health > 0f && camera.GameWidget.IsEntityFirstPersonTarget(base.Entity) && !m_componentPlayer.ComponentInput.IsControlledByVr)
     {
         Viewport viewport  = Display.Viewport;
         Viewport viewport2 = viewport;
         viewport2.MaxDepth *= 0.1f;
         Display.Viewport    = viewport2;
         try
         {
             Matrix identity = Matrix.Identity;
             if (m_swapAnimationTime > 0f)
             {
                 float num = MathUtils.Pow(MathUtils.Sin(m_swapAnimationTime * (float)Math.PI), 3f);
                 identity *= Matrix.CreateTranslation(0f, -0.8f * num, 0.2f * num);
             }
             if (m_pokeAnimationTime > 0f)
             {
                 float num2 = MathUtils.Sin(MathUtils.Sqrt(m_pokeAnimationTime) * (float)Math.PI);
                 if (m_value != 0)
                 {
                     identity *= Matrix.CreateRotationX((0f - MathUtils.DegToRad(90f)) * num2);
                     identity *= Matrix.CreateTranslation(-0.5f * num2, 0.1f * num2, 0f * num2);
                 }
                 else
                 {
                     identity *= Matrix.CreateRotationX((0f - MathUtils.DegToRad(45f)) * num2);
                     identity *= Matrix.CreateTranslation(-0.1f * num2, 0.2f * num2, -0.05f * num2);
                 }
             }
             if (m_componentRider.Mount != null)
             {
                 ComponentCreatureModel componentCreatureModel = m_componentRider.Mount.Entity.FindComponent <ComponentCreatureModel>();
                 if (componentCreatureModel != null)
                 {
                     float   num3     = componentCreatureModel.MovementAnimationPhase * (float)Math.PI * 2f + 0.5f;
                     Vector3 position = default(Vector3);
                     position.Y = 0.02f * MathUtils.Sin(num3);
                     position.Z = 0.02f * MathUtils.Sin(num3);
                     identity  *= Matrix.CreateRotationX(0.05f * MathUtils.Sin(num3 * 1f)) * Matrix.CreateTranslation(position);
                 }
             }
             else
             {
                 float   num4      = m_componentPlayer.ComponentCreatureModel.MovementAnimationPhase * (float)Math.PI * 2f;
                 Vector3 position2 = default(Vector3);
                 position2.X = 0.03f * MathUtils.Sin(num4 * 1f);
                 position2.Y = 0.02f * MathUtils.Sin(num4 * 2f);
                 position2.Z = 0.02f * MathUtils.Sin(num4 * 1f);
                 identity   *= Matrix.CreateRotationZ(1f * position2.X) * Matrix.CreateTranslation(position2);
             }
             Vector3 eyePosition = m_componentPlayer.ComponentCreatureModel.EyePosition;
             int     x           = Terrain.ToCell(eyePosition.X);
             int     num5        = Terrain.ToCell(eyePosition.Y);
             int     z           = Terrain.ToCell(eyePosition.Z);
             Matrix  m           = Matrix.CreateFromQuaternion(m_componentPlayer.ComponentCreatureModel.EyeRotation);
             m.Translation = m_componentPlayer.ComponentCreatureModel.EyePosition;
             if (m_value != 0)
             {
                 if (num5 >= 0 && num5 <= 255)
                 {
                     TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(x, z);
                     if (chunkAtCell != null && chunkAtCell.State >= TerrainChunkState.InvalidVertices1)
                     {
                         m_itemLight = m_subsystemTerrain.Terrain.GetCellLightFast(x, num5, z);
                     }
                 }
                 int     num6      = Terrain.ExtractContents(m_value);
                 Block   block     = BlocksManager.Blocks[num6];
                 Vector3 vector    = block.FirstPersonRotation * ((float)Math.PI / 180f) + m_itemRotation;
                 Vector3 position3 = block.FirstPersonOffset + m_itemOffset;
                 position3 += m_itemOffset;
                 Matrix matrix = Matrix.CreateFromYawPitchRoll(vector.Y, vector.X, vector.Z) * identity * Matrix.CreateTranslation(position3) * Matrix.CreateFromYawPitchRoll(m_lagAngles.X, m_lagAngles.Y, 0f) * m;
                 m_drawBlockEnvironmentData.SubsystemTerrain = m_subsystemTerrain;
                 m_drawBlockEnvironmentData.InWorldMatrix    = matrix;
                 m_drawBlockEnvironmentData.Light            = m_itemLight;
                 m_drawBlockEnvironmentData.Humidity         = m_subsystemTerrain.Terrain.GetSeasonalHumidity(x, z);
                 m_drawBlockEnvironmentData.Temperature      = m_subsystemTerrain.Terrain.GetSeasonalTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(num5);
                 block.DrawBlock(m_primitivesRenderer, m_value, Color.White, block.FirstPersonScale, ref matrix, m_drawBlockEnvironmentData);
                 m_primitivesRenderer.Flush(camera.ViewProjectionMatrix);
             }
             else
             {
                 if (Time.FrameStartTime >= m_nextHandLightTime)
                 {
                     float?num7 = LightingManager.CalculateSmoothLight(m_subsystemTerrain, eyePosition);
                     if (num7.HasValue)
                     {
                         m_nextHandLightTime = Time.FrameStartTime + 0.1;
                         m_handLight         = num7.Value;
                     }
                 }
                 Vector3 position4 = new Vector3(0.25f, -0.3f, -0.05f);
                 Matrix  matrix2   = Matrix.CreateScale(0.01f) * Matrix.CreateRotationX(0.8f) * Matrix.CreateRotationY(0.4f) * identity * Matrix.CreateTranslation(position4) * Matrix.CreateFromYawPitchRoll(m_lagAngles.X, m_lagAngles.Y, 0f) * m * camera.ViewMatrix;
                 Display.DepthStencilState      = DepthStencilState.Default;
                 Display.RasterizerState        = RasterizerState.CullCounterClockwiseScissor;
                 m_shader.Texture               = m_componentPlayer.ComponentCreatureModel.TextureOverride;
                 m_shader.SamplerState          = SamplerState.PointClamp;
                 m_shader.MaterialColor         = Vector4.One;
                 m_shader.AmbientLightColor     = new Vector3(m_handLight * LightingManager.LightAmbient);
                 m_shader.DiffuseLightColor1    = new Vector3(m_handLight);
                 m_shader.DiffuseLightColor2    = new Vector3(m_handLight);
                 m_shader.LightDirection1       = Vector3.TransformNormal(LightingManager.DirectionToLight1, camera.ViewMatrix);
                 m_shader.LightDirection2       = Vector3.TransformNormal(LightingManager.DirectionToLight2, camera.ViewMatrix);
                 m_shader.Transforms.World[0]   = matrix2;
                 m_shader.Transforms.View       = Matrix.Identity;
                 m_shader.Transforms.Projection = camera.ProjectionMatrix;
                 foreach (ModelMesh mesh in m_handModel.Meshes)
                 {
                     foreach (ModelMeshPart meshPart in mesh.MeshParts)
                     {
                         Display.DrawIndexed(PrimitiveType.TriangleList, m_shader, meshPart.VertexBuffer, meshPart.IndexBuffer, meshPart.StartIndex, meshPart.IndicesCount);
                     }
                 }
             }
         }
         finally
         {
             Display.Viewport = viewport;
         }
     }
 }