Пример #1
0
        public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
        {
            m_subsystemGameInfo           = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true);
            m_subsystemParticles          = base.Project.FindSubsystem <SubsystemParticles>(throwOnError: true);
            m_subsystemAudio              = base.Project.FindSubsystem <SubsystemAudio>(throwOnError: true);
            m_subsystemTime               = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
            m_subsystemTerrain            = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true);
            m_subsystemPickables          = base.Project.FindSubsystem <SubsystemPickables>(throwOnError: true);
            m_componentGui                = base.Entity.FindComponent <ComponentGui>(throwOnError: true);
            m_componentHumanModel         = base.Entity.FindComponent <ComponentHumanModel>(throwOnError: true);
            m_componentBody               = base.Entity.FindComponent <ComponentBody>(throwOnError: true);
            m_componentOuterClothingModel = base.Entity.FindComponent <ComponentOuterClothingModel>(throwOnError: true);
            m_componentVitalStats         = base.Entity.FindComponent <ComponentVitalStats>(throwOnError: true);
            m_componentLocomotion         = base.Entity.FindComponent <ComponentLocomotion>(throwOnError: true);
            m_componentPlayer             = base.Entity.FindComponent <ComponentPlayer>(throwOnError: true);
            SteedMovementSpeedFactor      = 1f;
            Insulation                    = 0f;
            LeastInsulatedSlot            = ClothingSlot.Feet;
            m_clothes[ClothingSlot.Head]  = new List <int>();
            m_clothes[ClothingSlot.Torso] = new List <int>();
            m_clothes[ClothingSlot.Legs]  = new List <int>();
            m_clothes[ClothingSlot.Feet]  = new List <int>();
            ValuesDictionary value = valuesDictionary.GetValue <ValuesDictionary>("Clothes");

            SetClothes(ClothingSlot.Head, HumanReadableConverter.ValuesListFromString <int>(';', value.GetValue <string>("Head")));
            SetClothes(ClothingSlot.Torso, HumanReadableConverter.ValuesListFromString <int>(';', value.GetValue <string>("Torso")));
            SetClothes(ClothingSlot.Legs, HumanReadableConverter.ValuesListFromString <int>(';', value.GetValue <string>("Legs")));
            SetClothes(ClothingSlot.Feet, HumanReadableConverter.ValuesListFromString <int>(';', value.GetValue <string>("Feet")));
            Display.DeviceReset += Display_DeviceReset;
        }
Пример #2
0
 public override void OnCollide(CellFace cellFace, float velocity, ComponentBody componentBody)
 {
     if (Terrain.ExtractContents(base.SubsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z)) == 226)
     {
         componentBody.Entity.FindComponent <ComponentCreature>()?.ComponentHealth.Injure(0.01f * MathUtils.Abs(velocity), null, ignoreInvulnerability: false, "Spiked by a sea creature");
     }
 }
Пример #3
0
 public override bool OnHitAsProjectile(CellFace?cellFace, ComponentBody componentBody, WorldItem worldItem)
 {
     if (Terrain.ExtractContents(worldItem.Value) != Bullet2Block.Index)
     {
         return(false);
     }
     if (cellFace.HasValue)
     {
         var value     = cellFace.Value;
         int cellValue = SubsystemTerrain.Terrain.GetCellValue(value.X, value.Y, value.Z);
         if (worldItem.Velocity.Length() > 30f)
         {
             Utils.SubsystemExplosions.TryExplodeBlock(value.X, value.Y, value.Z, cellValue);
         }
         if (BlocksManager.Blocks[Terrain.ExtractContents(cellValue)].Density >= 1.5f && worldItem.Velocity.Length() > 30f)
         {
             const float num         = 1f;
             const float minDistance = 8f;
             if (Utils.Random.UniformFloat(0f, 1f) < num)
             {
                 Utils.SubsystemAudio.PlayRandomSound("Audio/Ricochets", 1f, Utils.Random.UniformFloat(-0.2f, 0.2f), new Vector3(value.X, value.Y, value.Z), minDistance, true);
                 return(false);
             }
         }
     }
     return(true);
 }
 public override bool OnHitAsProjectile(CellFace?cellFace, ComponentBody componentBody, WorldItem worldItem)
 {
     ArrowBlock.ArrowType arrowType = ArrowBlock.GetArrowType(Terrain.ExtractData(worldItem.Value));
     if (worldItem.Velocity.Length() > 10f)
     {
         float num = 0.1f;
         if (arrowType == ArrowBlock.ArrowType.FireArrow)
         {
             num = 0.5f;
         }
         if (arrowType == ArrowBlock.ArrowType.WoodenArrow)
         {
             num = 0.2f;
         }
         if (arrowType == ArrowBlock.ArrowType.DiamondArrow)
         {
             num = 0f;
         }
         if (arrowType == ArrowBlock.ArrowType.IronBolt)
         {
             num = 0.05f;
         }
         if (arrowType == ArrowBlock.ArrowType.DiamondBolt)
         {
             num = 0f;
         }
         if (m_random.Float(0f, 1f) < num)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #5
0
        public void CollidedWithBody(ComponentBody body)
        {
            if (body.Density - 4.76f <= float.Epsilon)
            {
                return;
            }
            Vector2 v      = m_componentBody.Velocity.XZ - body.Velocity.XZ;
            float   amount = v.LengthSquared() * .3f;

            if (amount < .02f)
            {
                return;
            }
            var health = body.Entity.FindComponent <ComponentHealth>();

            if (health != null)
            {
                health.Injure(amount / health.AttackResilience, null, false, "Train");
            }
            else
            {
                body.Entity.FindComponent <ComponentDamage>()?.Damage(amount);
            }
            body.ApplyImpulse(MathUtils.Clamp(1.25f * 6f * MathUtils.Pow(m_componentBody.Mass / body.Mass, 0.33f), 0f, 6f) * Vector3.Normalize(body.Position - m_componentBody.Position));
        }
Пример #6
0
        public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
        {
            m_subsystemGameInfo       = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true);
            m_subsystemSky            = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true);
            m_subsystemParticles      = base.Project.FindSubsystem <SubsystemParticles>(throwOnError: true);
            m_subsystemAudio          = base.Project.FindSubsystem <SubsystemAudio>(throwOnError: true);
            m_componentSpawn          = base.Entity.FindComponent <ComponentSpawn>(throwOnError: true);
            m_componentBody           = base.Entity.FindComponent <ComponentBody>(throwOnError: true);
            m_componentHealth         = base.Entity.FindComponent <ComponentHealth>(throwOnError: true);
            m_dayEntityTemplateName   = valuesDictionary.GetValue <string>("DayEntityTemplateName");
            m_nightEntityTemplateName = valuesDictionary.GetValue <string>("NightEntityTemplateName");
            float value = valuesDictionary.GetValue <float>("Probability");

            if (!string.IsNullOrEmpty(m_dayEntityTemplateName))
            {
                DatabaseManager.FindEntityValuesDictionary(m_dayEntityTemplateName, throwIfNotFound: true);
            }
            if (!string.IsNullOrEmpty(m_nightEntityTemplateName))
            {
                DatabaseManager.FindEntityValuesDictionary(m_nightEntityTemplateName, throwIfNotFound: true);
            }
            m_timeToSwitch              = s_random.Float(3f, 15f);
            IsEnabled                   = (s_random.Float(0f, 1f) < value);
            m_componentSpawn.Despawned += ComponentSpawn_Despawned;
        }
 public void Update(float dt)
 {
     m_autoChaseSuppressionTime -= dt;
     if (IsActive && m_target != null)
     {
         m_chaseTime -= dt;
         m_componentCreature.ComponentCreatureModel.LookAtOrder = m_target.ComponentCreatureModel.EyePosition;
         if (IsTargetInAttackRange(m_target.ComponentBody))
         {
             m_componentCreatureModel.AttackOrder = true;
         }
         if (m_componentCreatureModel.IsAttackHitMoment)
         {
             Vector3       hitPoint;
             ComponentBody hitBody = GetHitBody(m_target.ComponentBody, out hitPoint);
             if (hitBody != null)
             {
                 float x = m_isPersistent ? m_random.Float(8f, 10f) : 2f;
                 m_chaseTime = MathUtils.Max(m_chaseTime, x);
                 m_componentMiner.Hit(hitBody, hitPoint, m_componentCreature.ComponentBody.Matrix.Forward);
                 m_componentCreature.ComponentCreatureSounds.PlayAttackSound();
             }
         }
     }
     if (m_subsystemTime.GameTime >= m_nextUpdateTime)
     {
         m_dt             = m_random.Float(0.25f, 0.35f) + MathUtils.Min((float)(m_subsystemTime.GameTime - m_nextUpdateTime), 0.1f);
         m_nextUpdateTime = m_subsystemTime.GameTime + (double)m_dt;
         m_stateMachine.Update();
     }
 }
        public override bool OnUse(Ray3 ray, ComponentMiner componentMiner)
        {
            BodyRaycastResult?bodyRaycastResult = componentMiner.Raycast <BodyRaycastResult>(ray, RaycastMode.Interaction);

            if (bodyRaycastResult.HasValue)
            {
                ComponentHealth componentHealth = bodyRaycastResult.Value.ComponentBody.Entity.FindComponent <ComponentHealth>();
                if (componentHealth == null || componentHealth.Health > 0f)
                {
                    string entityTemplateName = bodyRaycastResult.Value.ComponentBody.Entity.ValuesDictionary.DatabaseObject.Name + "_Saddled";
                    Entity entity             = DatabaseManager.CreateEntity(base.Project, entityTemplateName, throwIfNotFound: false);
                    if (entity != null)
                    {
                        ComponentBody componentBody = entity.FindComponent <ComponentBody>(throwOnError: true);
                        componentBody.Position = bodyRaycastResult.Value.ComponentBody.Position;
                        componentBody.Rotation = bodyRaycastResult.Value.ComponentBody.Rotation;
                        componentBody.Velocity = bodyRaycastResult.Value.ComponentBody.Velocity;
                        entity.FindComponent <ComponentSpawn>(throwOnError: true).SpawnDuration = 0f;
                        base.Project.RemoveEntity(bodyRaycastResult.Value.ComponentBody.Entity, disposeEntity: true);
                        base.Project.AddEntity(entity);
                        m_subsystemAudio.PlaySound("Audio/BlockPlaced", 1f, m_random.Float(-0.1f, 0.1f), ray.Position, 1f, autoDelay: true);
                        componentMiner.RemoveActiveTool(1);
                    }
                }
                return(true);
            }
            return(false);
        }
Пример #9
0
        public override void OnCollide(CellFace cellFace, float velocity, ComponentBody componentBody)
        {
            int data = Terrain.ExtractData(base.SubsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z));

            if (!SpikedPlankBlock.GetSpikesState(data))
            {
                return;
            }
            int mountingFace = SpikedPlankBlock.GetMountingFace(data);

            if (cellFace.Face != mountingFace)
            {
                return;
            }
            ComponentCreature componentCreature = componentBody.Entity.FindComponent <ComponentCreature>();

            if (componentCreature != null)
            {
                m_lastInjuryTimes.TryGetValue(componentCreature, out double value);
                if (m_subsystemTime.GameTime - value > 1.0)
                {
                    m_lastInjuryTimes[componentCreature] = m_subsystemTime.GameTime;
                    componentCreature.ComponentHealth.Injure(0.1f, null, ignoreInvulnerability: false, "Spiked by a trap");
                }
            }
        }
        public float ScoreSafePlace(Vector3 currentPosition, Vector3 safePosition, Vector3?lookDirection)
        {
            float   num      = 16f;
            Vector3 position = m_componentCreature.ComponentBody.Position;

            m_componentBodies.Clear();
            m_subsystemBodies.FindBodiesAroundPoint(new Vector2(position.X, position.Z), 16f, m_componentBodies);
            for (int i = 0; i < m_componentBodies.Count; i++)
            {
                ComponentBody componentBody = m_componentBodies.Array[i];
                if (!IsPredator(componentBody.Entity))
                {
                    continue;
                }
                Vector3 position2 = componentBody.Position;
                Vector3 v         = safePosition - position2;
                if (!lookDirection.HasValue || 0f - Vector3.Dot(lookDirection.Value, v) > 0f)
                {
                    if (v.Y >= 4f)
                    {
                        v *= 2f;
                    }
                    num = MathUtils.Min(num, v.Length());
                }
            }
            float num2 = Vector3.Distance(currentPosition, safePosition);

            if (num2 < 8f)
            {
                return(num * 0.5f);
            }
            return(num * MathUtils.Lerp(1f, 0.75f, MathUtils.Saturate(num2 / 20f)));
        }
Пример #11
0
        public ComponentBody FindNearestBodyInFront(Vector3 position, Vector2 direction)
        {
            if (m_subsystemTime.GameTime >= m_nextBodiesUpdateTime)
            {
                m_nextBodiesUpdateTime = m_subsystemTime.GameTime + 0.5;
                m_nearbyBodies.Clear();
                m_subsystemBodies.FindBodiesAroundPoint(m_componentCreature.ComponentBody.Position.XZ, 4f, m_nearbyBodies);
            }
            ComponentBody result = null;
            float         num    = float.MaxValue;

            foreach (ComponentBody nearbyBody in m_nearbyBodies)
            {
                if (nearbyBody != m_componentCreature.ComponentBody && !(MathUtils.Abs(nearbyBody.Position.Y - m_componentCreature.ComponentBody.Position.Y) > 1.1f) && Vector2.Dot(nearbyBody.Position.XZ - position.XZ, direction) > 0f)
                {
                    float num2 = Vector2.DistanceSquared(nearbyBody.Position.XZ, position.XZ);
                    if (num2 < num)
                    {
                        num    = num2;
                        result = nearbyBody;
                    }
                }
            }
            return(result);
        }
Пример #12
0
        public void SetDestination(Vector3?destination, float speed, float range, bool ignoreHeightDifference, bool raycastDestination, bool takeRisks, ComponentBody doNotAvoidBody)
        {
            bool flag = true;

            if (Destination.HasValue && destination.HasValue)
            {
                Vector3 v = Vector3.Normalize(Destination.Value - m_componentCreature.ComponentBody.Position);
                if (Vector3.Dot(Vector3.Normalize(destination.Value - m_componentCreature.ComponentBody.Position), v) > 0.5f)
                {
                    flag = false;
                }
            }
            if (flag)
            {
                IsStuck = false;
                m_lastStuckCheckPosition = null;
                m_aboveBelowTime         = null;
            }
            Destination            = destination;
            Speed                  = speed;
            Range                  = range;
            IgnoreHeightDifference = ignoreHeightDifference;
            RaycastDestination     = raycastDestination;
            TakeRisks              = takeRisks;
            DoNotAvoidBody         = doNotAvoidBody;
        }
 public void HearNoise(ComponentBody sourceBody, Vector3 sourcePosition, float loudness)
 {
     if (loudness >= 0.25f && m_stateMachine.CurrentState != "RunningAway")
     {
         m_stateMachine.TransitionTo("DangerDetected");
     }
 }
        public float CalculateMotionVoltage()
        {
            float num = 0f;

            m_bodies.Clear();
            m_subsystemBodies.FindBodiesInArea(m_corner1, m_corner2, m_bodies);
            for (int i = 0; i < m_bodies.Count; i++)
            {
                ComponentBody componentBody = m_bodies.Array[i];
                if (componentBody.Velocity.LengthSquared() > 0.0625f)
                {
                    Vector3 vector = componentBody.Position + new Vector3(0f, 0.5f * componentBody.BoxSize.Y, 0f);
                    float   num2   = Vector3.DistanceSquared(vector, m_center);
                    if (num2 < 64f && Vector3.Dot(Vector3.Normalize(vector - (m_center - 0.75f * m_direction)), m_direction) > 0.5f && !base.SubsystemElectricity.SubsystemTerrain.Raycast(m_center, vector, useInteractionBoxes: false, skipAirBlocks: true, delegate(int value, float d)
                    {
                        Block block = BlocksManager.Blocks[Terrain.ExtractContents(value)];
                        return(block.IsCollidable && block.BlockIndex != 15 && block.BlockIndex != 60 && block.BlockIndex != 44 && block.BlockIndex != 18);
                    }).HasValue)
                    {
                        num = MathUtils.Max(num, MathUtils.Saturate(1f - MathUtils.Sqrt(num2) / 8f));
                    }
                }
            }
            if (!(num > 0f))
            {
                return(0f);
            }
            return(MathUtils.Lerp(0.51f, 1f, MathUtils.Saturate(num * 1.1f)));
        }
        public override bool OnHitAsProjectile(CellFace?cellFace, ComponentBody componentBody, WorldItem worldItem)
        {
            BulletBlock.BulletType bulletType = BulletBlock.GetBulletType(Terrain.ExtractData(worldItem.Value));
            bool result = true;

            if (cellFace.HasValue)
            {
                int   cellValue = m_subsystemTerrain.Terrain.GetCellValue(cellFace.Value.X, cellFace.Value.Y, cellFace.Value.Z);
                int   num       = Terrain.ExtractContents(cellValue);
                Block obj       = BlocksManager.Blocks[num];
                if (worldItem.Velocity.Length() > 30f)
                {
                    m_subsystemExplosions.TryExplodeBlock(cellFace.Value.X, cellFace.Value.Y, cellFace.Value.Z, cellValue);
                }
                if (obj.Density >= 1.5f && worldItem.Velocity.Length() > 30f)
                {
                    float num2        = 1f;
                    float minDistance = 8f;
                    if (bulletType == BulletBlock.BulletType.BuckshotBall)
                    {
                        num2        = 0.25f;
                        minDistance = 4f;
                    }
                    if (m_random.Float(0f, 1f) < num2)
                    {
                        m_subsystemAudio.PlayRandomSound("Audio/Ricochets", 1f, m_random.Float(-0.2f, 0.2f), new Vector3(cellFace.Value.X, cellFace.Value.Y, cellFace.Value.Z), minDistance, autoDelay: true);
                        result = false;
                    }
                }
            }
            return(result);
        }
Пример #16
0
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemTime   = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
     m_subsystemAudio  = base.Project.FindSubsystem <SubsystemAudio>(throwOnError: true);
     m_componentMount  = base.Entity.FindComponent <ComponentMount>(throwOnError: true);
     m_componentBody   = base.Entity.FindComponent <ComponentBody>(throwOnError: true);
     m_componentDamage = base.Entity.FindComponent <ComponentDamage>(throwOnError: true);
 }
Пример #17
0
        public void RemoveBody(ComponentBody componentBody)
        {
            Point2 key = m_areaByComponentBody[componentBody];

            m_areaByComponentBody.Remove(componentBody);
            m_componentBodiesByArea[key].Remove(componentBody);
            componentBody.PositionChanged -= ComponentBody_PositionChanged;
        }
Пример #18
0
 public void HearNoise(ComponentBody sourceBody, Vector3 sourcePosition, float loudness)
 {
     if (loudness >= 1f)
     {
         m_heardNoise = true;
         m_lastNoiseSourcePosition = sourcePosition;
     }
 }
Пример #19
0
        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 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");
 }
Пример #21
0
        public void MakeLightningStrike(Vector3 targetPosition)
        {
            if (m_lightningStrikePosition.HasValue || !(m_subsystemTime.GameTime - m_lastLightningStrikeTime > 1.0))
            {
                return;
            }
            m_lastLightningStrikeTime   = m_subsystemTime.GameTime;
            m_lightningStrikePosition   = targetPosition;
            m_lightningStrikeBrightness = 1f;
            float num = float.MaxValue;

            foreach (Vector3 listenerPosition in m_subsystemAudio.ListenerPositions)
            {
                float num2 = Vector2.Distance(new Vector2(listenerPosition.X, listenerPosition.Z), new Vector2(targetPosition.X, targetPosition.Z));
                if (num2 < num)
                {
                    num = num2;
                }
            }
            float delay = m_subsystemAudio.CalculateDelay(num);

            if (num < 40f)
            {
                m_subsystemAudio.PlayRandomSound("Audio/ThunderNear", 1f, m_random.Float(-0.2f, 0.2f), 0f, delay);
            }
            else if (num < 200f)
            {
                m_subsystemAudio.PlayRandomSound("Audio/ThunderFar", 0.8f, m_random.Float(-0.2f, 0.2f), 0f, delay);
            }
            if (m_subsystemGameInfo.WorldSettings.EnvironmentBehaviorMode != 0)
            {
                return;
            }
            DynamicArray <ComponentBody> dynamicArray = new DynamicArray <ComponentBody>();

            m_subsystemBodies.FindBodiesAroundPoint(new Vector2(targetPosition.X, targetPosition.Z), 4f, dynamicArray);
            for (int i = 0; i < dynamicArray.Count; i++)
            {
                ComponentBody componentBody = dynamicArray.Array[i];
                if (componentBody.Position.Y > targetPosition.Y - 1.5f && Vector2.Distance(new Vector2(componentBody.Position.X, componentBody.Position.Z), new Vector2(targetPosition.X, targetPosition.Z)) < 4f)
                {
                    componentBody.Entity.FindComponent <ComponentOnFire>()?.SetOnFire(null, m_random.Float(12f, 15f));
                }
                ComponentCreature componentCreature = componentBody.Entity.FindComponent <ComponentCreature>();
                if (componentCreature != null && componentCreature.PlayerStats != null)
                {
                    componentCreature.PlayerStats.StruckByLightning++;
                }
            }
            int   x        = Terrain.ToCell(targetPosition.X);
            int   num3     = Terrain.ToCell(targetPosition.Y);
            int   z        = Terrain.ToCell(targetPosition.Z);
            float pressure = (m_random.Float(0f, 1f) < 0.2f) ? 39 : 19;

            base.Project.FindSubsystem <SubsystemExplosions>(throwOnError: true).AddExplosion(x, num3 + 1, z, pressure, isIncendiary: false, noExplosionSound: true);
        }
Пример #22
0
 public override void OnCollide(CellFace cellFace, float velocity, ComponentBody componentBody)
 {
     if (componentBody.Mass > 20f && !componentBody.IsSneaking)
     {
         Vector3 velocity2 = componentBody.Velocity;
         if (velocity2.Y < -3f || (velocity2.Y < 0f && m_random.Float(0f, 1f) < 1.5f * m_subsystemTime.GameTimeDelta && velocity2.LengthSquared() > 1f))
         {
             m_toDegrade[cellFace.Point] = true;
         }
     }
 }
Пример #23
0
 public bool IsChildOfBody(ComponentBody componentBody)
 {
     if (ParentBody != componentBody)
     {
         if (ParentBody != null)
         {
             return(ParentBody.IsChildOfBody(componentBody));
         }
         return(false);
     }
     return(true);
 }
Пример #24
0
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     base.Load(valuesDictionary, idToEntityMap);
     ExplosionPressure = valuesDictionary.GetValue("ExplosionPressure", 60f);
     MineType          = valuesDictionary.GetValue <MineType>("Type", 0);
     Delay             = valuesDictionary.GetValue("Delay", .0);
     (ComponentBody = Entity.FindComponent <ComponentBody>(true)).CollidedWithBody += CollidedWithBody;
     if ((MineType & MineType.Torpedo) != 0)
     {
         ComponentBody.Density = .8f;
     }
 }
Пример #25
0
 public void HearNoise(ComponentBody sourceBody, Vector3 sourcePosition, float loudness)
 {
     if (loudness >= 0.5f)
     {
         Vector3 v = m_componentCreature.ComponentBody.Position - sourcePosition;
         m_driveVector += Vector3.Normalize(v) * MathUtils.Max(8f - 0.25f * v.Length(), 1f);
         float num = 12f + m_random.Float(0f, 3f);
         if (m_driveVector.Length() > num)
         {
             m_driveVector = num * Vector3.Normalize(m_driveVector);
         }
     }
 }
Пример #26
0
 public void CollidedWithBody(ComponentBody body)
 {
     if ((MineType & MineType.Sensitive) == 0 && body.Density - 2f < .1f)
     {
         return;
     }
     if ((MineType & MineType.FL) != 0)
     {
         body.PositionChanged += PositionChanged;
         return;
     }
     Fire();
 }
 public override void OnCollide(CellFace cellFace, float velocity, ComponentBody componentBody)
 {
     if (cellFace.Face == 4 && componentBody.Mass > 20f)
     {
         Point3 key = new Point3(cellFace.X, cellFace.Y, cellFace.Z);
         if (!m_trapValues.TryGetValue(key, out TrapValue value))
         {
             value = new TrapValue();
             m_trapValues.Add(key, value);
         }
         value.Damage += 0f - velocity;
     }
 }
Пример #28
0
 public void SetDestination(Vector3?destination, float speed, float range, int maxPathfindingPositions, bool useRandomMovements, bool ignoreHeightDifference, bool raycastDestination, ComponentBody doNotAvoidBody)
 {
     Destination             = destination;
     Speed                   = speed;
     Range                   = range;
     MaxPathfindingPositions = maxPathfindingPositions;
     UseRandomMovements      = useRandomMovements;
     IgnoreHeightDifference  = ignoreHeightDifference;
     RaycastDestination      = raycastDestination;
     DoNotAvoidBody          = doNotAvoidBody;
     m_destinationChanged    = true;
     m_nextUpdateTime        = 0.0;
 }
Пример #29
0
        public void Update(float dt)
        {
            if (m_isAnimating)
            {
                float         f             = 8f * dt;
                ComponentBody componentBody = ComponentCreature.ComponentBody;
                componentBody.ParentBodyPositionOffset = Vector3.Lerp(componentBody.ParentBodyPositionOffset, m_targetPositionOffset, f);
                componentBody.ParentBodyRotationOffset = Quaternion.Slerp(componentBody.ParentBodyRotationOffset, m_targetRotationOffset, f);
                m_animationTime += dt;
                if (Vector3.DistanceSquared(componentBody.ParentBodyPositionOffset, m_targetPositionOffset) < 0.0100000007f || m_animationTime > 0.75f)
                {
                    m_isAnimating = false;
                    if (m_isDismounting)
                    {
                        if (componentBody.ParentBody != null)
                        {
                            componentBody.Velocity   = componentBody.ParentBody.Velocity;
                            componentBody.ParentBody = null;
                        }
                    }
                    else
                    {
                        componentBody.ParentBodyPositionOffset = m_targetPositionOffset;
                        componentBody.ParentBodyRotationOffset = m_targetRotationOffset;
                        m_outOfMountTime = 0f;
                    }
                }
            }
            ComponentMount mount = Mount;

            if (mount != null && !m_isAnimating)
            {
                ComponentBody componentBody2 = ComponentCreature.ComponentBody;
                ComponentBody parentBody     = ComponentCreature.ComponentBody.ParentBody;
                if (Vector3.DistanceSquared(parentBody.Position + Vector3.Transform(componentBody2.ParentBodyPositionOffset, parentBody.Rotation), componentBody2.Position) > 0.160000011f)
                {
                    m_outOfMountTime += dt;
                }
                else
                {
                    m_outOfMountTime = 0f;
                }
                ComponentHealth componentHealth = mount.Entity.FindComponent <ComponentHealth>();
                if (m_outOfMountTime > 0.1f || (componentHealth != null && componentHealth.Health <= 0f) || ComponentCreature.ComponentHealth.Health <= 0f)
                {
                    StartDismounting();
                }
                ComponentCreature.ComponentBody.ParentBodyPositionOffset = mount.MountOffset + m_riderOffset;
                ComponentCreature.ComponentBody.ParentBodyRotationOffset = Quaternion.Identity;
            }
        }
Пример #30
0
        public void AddBody(ComponentBody componentBody)
        {
            Vector3 position = componentBody.Position;
            Point2  point    = new Point2((int)MathUtils.Floor(position.X / 8f), (int)MathUtils.Floor(position.Z / 8f));

            m_areaByComponentBody.Add(componentBody, point);
            if (!m_componentBodiesByArea.TryGetValue(point, out DynamicArray <ComponentBody> value))
            {
                value = new DynamicArray <ComponentBody>();
                m_componentBodiesByArea.Add(point, value);
            }
            value.Add(componentBody);
            componentBody.PositionChanged += ComponentBody_PositionChanged;
        }