public void AddSplash(int value, Vector3 position, Vector2 size, Color color, int textureSlot) { for (int i = 0; i < base.Particles.Length; i++) { Particle particle = base.Particles[i]; if (!particle.IsActive) { Block block = BlocksManager.Blocks[Terrain.ExtractContents(value)]; particle.IsActive = true; particle.Position = position; particle.BaseColor = color; particle.BillboardingMode = ParticleBillboardingMode.Horizontal; particle.Size = size; particle.TextureSlot = textureSlot; if (block is WaterBlock) { ((WaterBlock)block).GetLevelHeight(FluidBlock.GetLevel(Terrain.ExtractData(value))); particle.TimeToLive = m_random.Float(0.2f, 0.3f); particle.FadeFactor = 1f; } else if (block.IsCollidable || block is SnowBlock) { particle.TimeToLive = m_random.Float(0.8f, 1.2f); particle.FadeFactor = 1f; } break; } } m_isActive = true; }
public Pickable AddPickable(int value, int count, Vector3 position, Vector3?velocity, Matrix?stuckMatrix) { Pickable pickable = new Pickable(); pickable.Value = value; pickable.Count = count; pickable.Position = position; pickable.StuckMatrix = stuckMatrix; pickable.CreationTime = m_subsystemGameInfo.TotalElapsedGameTime; if (velocity.HasValue) { pickable.Velocity = velocity.Value; } else if (Terrain.ExtractContents(value) == 248) { Vector2 vector = m_random.Vector2(1.5f, 2f); pickable.Velocity = new Vector3(vector.X, 3f, vector.Y); } else { pickable.Velocity = new Vector3(m_random.Float(-0.5f, 0.5f), m_random.Float(1f, 1.2f), m_random.Float(-0.5f, 0.5f)); } m_pickables.Add(pickable); if (this.PickableAdded != null) { this.PickableAdded(pickable); } return(pickable); }
public KillParticleSystem(SubsystemTerrain terrain, Vector3 position, float size) : base(20) { base.Texture = ContentManager.Get <Texture2D>("Textures/KillParticle"); int num = Terrain.ToCell(position.X); int num2 = Terrain.ToCell(position.Y); int num3 = Terrain.ToCell(position.Z); int x = 0; x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num + 1, num2, num3)); x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num - 1, num2, num3)); x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num, num2 + 1, num3)); x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num, num2 - 1, num3)); x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num, num2, num3 + 1)); x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num, num2, num3 - 1)); base.TextureSlotsCount = 2; Color white = Color.White; float num4 = LightingManager.LightIntensityByLightValue[x]; white *= num4; white.A = byte.MaxValue; for (int i = 0; i < base.Particles.Length; i++) { Particle obj = base.Particles[i]; obj.IsActive = true; obj.Position = position + 0.4f * size * new Vector3(m_random.Float(-1f, 1f), m_random.Float(-1f, 1f), m_random.Float(-1f, 1f)); obj.Color = white; obj.Size = new Vector2(0.3f * size); obj.TimeToLive = m_random.Float(0.5f, 3.5f); obj.Velocity = 1.2f * size * new Vector3(m_random.Float(-1f, 1f), m_random.Float(-1f, 1f), m_random.Float(-1f, 1f)); obj.FlipX = m_random.Bool(); obj.FlipY = m_random.Bool(); } }
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); }
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 override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_subsystemNoise = base.Project.FindSubsystem <SubsystemNoise>(throwOnError: true); m_subsystemTerrain = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true); m_subsystemGameInfo = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true); m_componentCreature = base.Entity.FindComponent <ComponentCreature>(throwOnError: true); m_componentPlayer = base.Entity.FindComponent <ComponentPlayer>(); m_componentLevel = base.Entity.FindComponent <ComponentLevel>(); m_componentClothing = base.Entity.FindComponent <ComponentClothing>(); m_componentMount = base.Entity.FindComponent <ComponentMount>(); m_componentRider = base.Entity.FindComponent <ComponentRider>(); IsCreativeFlyEnabled = valuesDictionary.GetValue <bool>("IsCreativeFlyEnabled"); AccelerationFactor = valuesDictionary.GetValue <float>("AccelerationFactor"); WalkSpeed = valuesDictionary.GetValue <float>("WalkSpeed"); LadderSpeed = valuesDictionary.GetValue <float>("LadderSpeed"); JumpSpeed = valuesDictionary.GetValue <float>("JumpSpeed"); CreativeFlySpeed = valuesDictionary.GetValue <float>("CreativeFlySpeed"); FlySpeed = valuesDictionary.GetValue <float>("FlySpeed"); SwimSpeed = valuesDictionary.GetValue <float>("SwimSpeed"); TurnSpeed = valuesDictionary.GetValue <float>("TurnSpeed"); LookSpeed = valuesDictionary.GetValue <float>("LookSpeed"); InAirWalkFactor = valuesDictionary.GetValue <float>("InAirWalkFactor"); m_walkSpeedWhenTurning = valuesDictionary.GetValue <float>("WalkSpeedWhenTurning"); m_minFrictionFactor = valuesDictionary.GetValue <float>("MinFrictionFactor"); m_lookAutoLevelX = valuesDictionary.GetValue <bool>("LookAutoLevelX"); m_lookAutoLevelY = valuesDictionary.GetValue <bool>("LookAutoLevelY"); if (base.Entity.FindComponent <ComponentPlayer>() == null) { WalkSpeed *= m_random.Float(0.85f, 1f); FlySpeed *= m_random.Float(0.85f, 1f); SwimSpeed *= m_random.Float(0.85f, 1f); } }
public void Update(float dt) { m_toGenerate += ParticlesPerSecond * dt; foreach (Particle particle in m_particles) { if (particle.Active) { particle.Position.Y += particle.Speed * dt; particle.AnimationTime += dt; particle.TimeToLive -= dt; particle.TextureSlot = (int)MathUtils.Max(9f * particle.AnimationTime / ParticleAnimationPeriod, 0f); if (particle.TimeToLive <= 0f || particle.TextureSlot > 8 || particle.Position.Y < CutoffPosition) { particle.Active = false; } } else if (m_toGenerate >= 1f) { particle.Active = true; particle.Position = new Vector2(m_random.Float(Origin.X, Origin.X + Width), Origin.Y); particle.Size = new Vector2(ParticleSize); particle.Speed = (0f - m_random.Float(0.75f, 1.25f)) * ParticleSpeed; particle.AnimationTime = m_random.Float(0f, ParticleAnimationOffset); particle.TimeToLive = MathUtils.Lerp(MinTimeToLive, MaxTimeToLive, m_random.Float(0f, 1f)); particle.FlipX = (m_random.Int(0, 1) == 0); particle.FlipY = (m_random.Int(0, 1) == 0); m_toGenerate -= 1f; } } m_toGenerate = MathUtils.Remainder(m_toGenerate, 1f); }
public BurntDebrisParticleSystem(SubsystemTerrain terrain, Vector3 position) : base(15) { m_subsystemTerrain = terrain; base.Texture = ContentManager.Get <Texture2D>("Textures/FireParticle"); int num = Terrain.ToCell(position.X); int num2 = Terrain.ToCell(position.Y); int num3 = Terrain.ToCell(position.Z); int x = 0; x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num + 1, num2, num3)); x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num - 1, num2, num3)); x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num, num2 + 1, num3)); x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num, num2 - 1, num3)); x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num, num2, num3 + 1)); x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num, num2, num3 - 1)); base.TextureSlotsCount = 3; Color white = Color.White; float num4 = LightingManager.LightIntensityByLightValue[x]; white *= num4; white.A = byte.MaxValue; for (int i = 0; i < base.Particles.Length; i++) { Particle obj = base.Particles[i]; obj.IsActive = true; obj.Position = position + 0.5f * new Vector3(m_random.Float(-1f, 1f), m_random.Float(-1f, 1f), m_random.Float(-1f, 1f)); obj.Color = white; obj.Size = new Vector2(0.5f); obj.TimeToLive = m_random.Float(0.75f, 2f); obj.Velocity = new Vector3(3f * m_random.Float(-1f, 1f), 2f * m_random.Float(-1f, 1f), 3f * m_random.Float(-1f, 1f)); obj.TextureSlot = 8; } }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_subsystemGameInfo = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true); m_componentCreature = base.Entity.FindComponent <ComponentCreature>(throwOnError: true); m_componentMount = base.Entity.FindComponent <ComponentMount>(throwOnError: true); m_componentSteedBehavior = base.Entity.FindComponent <ComponentSteedBehavior>(throwOnError: true); m_componentEatPickableBehavior = base.Entity.FindComponent <ComponentEatPickableBehavior>(throwOnError: true); m_stubbornProbability = valuesDictionary.GetValue <float>("StubbornProbability"); m_stubbornEndTime = valuesDictionary.GetValue <double>("StubbornEndTime"); m_periodicEventOffset = m_random.Float(0f, 100f); m_isSaddled = base.Entity.ValuesDictionary.DatabaseObject.Name.EndsWith("_Saddled"); m_stateMachine.AddState("Inactive", null, delegate { if (m_subsystemTime.PeriodicGameTimeEvent(1.0, m_periodicEventOffset) && m_componentMount.Rider != null && m_random.Float(0f, 1f) < m_stubbornProbability && (!m_isSaddled || m_componentEatPickableBehavior.Satiation <= 0f)) { m_stubbornEndTime = m_subsystemGameInfo.TotalElapsedGameTime + (double)m_random.Float(60f, 120f); } if (IsActive) { m_stateMachine.TransitionTo("Stubborn"); } }, null); m_stateMachine.AddState("Stubborn", null, delegate { if (m_componentSteedBehavior.WasOrderIssued) { m_componentCreature.ComponentCreatureModel.HeadShakeOrder = m_random.Float(0.6f, 1f); m_componentCreature.ComponentCreatureSounds.PlayPainSound(); } }, null); m_stateMachine.TransitionTo("Inactive"); }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemParticles = base.Project.FindSubsystem <SubsystemParticles>(throwOnError: true); m_subsystemAudio = base.Project.FindSubsystem <SubsystemAudio>(throwOnError: true); m_subsystemTerrain = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true); m_componentCreature = base.Entity.FindComponent <ComponentCreature>(throwOnError: true); m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true); m_stateMachine.AddState("Inactive", null, delegate { m_importanceLevel = MathUtils.Lerp(0f, 400f, MathUtils.Saturate((0.75f - m_componentCreature.ComponentHealth.Air) / 0.75f)); if (IsActive) { m_stateMachine.TransitionTo("Surface"); } }, null); m_stateMachine.AddState("Surface", delegate { m_componentPathfinding.Stop(); }, delegate { _ = m_componentCreature.ComponentBody.Position; if (!m_componentPathfinding.Destination.HasValue) { Vector3?destination = FindSurfaceDestination(); if (destination.HasValue) { float speed = (m_componentCreature.ComponentHealth.Air < 0.25f) ? 1f : m_random.Float(0.4f, 0.6f); m_componentPathfinding.SetDestination(destination, speed, 1f, 0, useRandomMovements: false, ignoreHeightDifference: false, raycastDestination: false, null); } } else if (m_componentPathfinding.IsStuck) { m_importanceLevel = 0f; } if (m_componentCreature.ComponentHealth.Air > 0.9f) { m_stateMachine.TransitionTo("Breathe"); } }, null); m_stateMachine.AddState("Breathe", delegate { Vector3 forward = m_componentCreature.ComponentBody.Matrix.Forward; Vector3 value = m_componentCreature.ComponentBody.Matrix.Translation + 10f * forward + new Vector3(0f, 2f, 0f); m_componentPathfinding.SetDestination(value, 0.6f, 1f, 0, useRandomMovements: false, ignoreHeightDifference: false, raycastDestination: false, null); m_particleSystem = new WhalePlumeParticleSystem(m_subsystemTerrain, m_random.Float(0.8f, 1.1f), m_random.Float(1f, 1.3f)); m_subsystemParticles.AddParticleSystem(m_particleSystem); m_subsystemAudio.PlayRandomSound("Audio/Creatures/WhaleBlow", 1f, m_random.Float(-0.2f, 0.2f), m_componentCreature.ComponentBody.Position, 10f, autoDelay: true); }, delegate { m_particleSystem.Position = m_componentCreature.ComponentBody.Position + new Vector3(0f, 0.8f * m_componentCreature.ComponentBody.BoxSize.Y, 0f); if (!m_subsystemParticles.ContainsParticleSystem(m_particleSystem)) { m_importanceLevel = 0f; } }, delegate { m_particleSystem.IsStopped = true; m_particleSystem = null; }); }
public override bool Simulate(float dt) { bool flag = false; if (m_visible) { m_toGenerate += 20f * dt; float num = MathUtils.Pow(0.02f, dt); for (int i = 0; i < base.Particles.Length; i++) { Particle particle = base.Particles[i]; if (particle.IsActive) { flag = true; particle.Time += dt; if (particle.Time <= particle.Duration) { particle.Position += particle.Velocity * dt; particle.Velocity *= num; particle.Velocity.Y += 10f * dt; particle.TextureSlot = (int)MathUtils.Min(9f * particle.Time / particle.Duration * 1.2f, 8f); } else { particle.IsActive = false; } } else if (!IsStopped) { if (m_toGenerate >= 1f) { particle.IsActive = true; Vector3 v = new Vector3(m_random.Float(-1f, 1f), m_random.Float(0f, 1f), m_random.Float(-1f, 1f)); particle.Position = Position + 0.75f * Radius * v; particle.Color = Color.White; particle.Velocity = 1.5f * v; particle.Size = new Vector2(0.5f); particle.Time = 0f; particle.Duration = m_random.Float(0.5f, 1.5f); particle.FlipX = m_random.Bool(); particle.FlipY = m_random.Bool(); m_toGenerate -= 1f; } } else { m_toGenerate = 0f; } } m_toGenerate = MathUtils.Remainder(m_toGenerate, 1f); m_visible = false; } if (IsStopped && !flag) { return(true); } return(false); }
public override bool Simulate(float dt) { m_time += dt; if (m_time < m_duration && !IsStopped) { m_toGenerate += 60f * dt; } else { m_toGenerate = 0f; } float num = MathUtils.Pow(0.001f, dt); float num2 = MathUtils.Lerp(4f, 10f, MathUtils.Saturate(2f * m_time / m_duration)); Vector3 v = new Vector3(0f, 1f, 2f); bool flag = false; for (int i = 0; i < base.Particles.Length; i++) { Particle particle = base.Particles[i]; if (particle.IsActive) { flag = true; particle.Time += dt; if (particle.Time <= particle.Duration) { particle.Position += particle.Velocity * dt; particle.Velocity *= num; particle.Velocity += v * dt; particle.TextureSlot = (int)MathUtils.Min(4f * particle.Time / particle.Duration * 1.2f, 3f); particle.Size = new Vector2(m_size) * MathUtils.Lerp(0.1f, 0.2f, particle.Time / particle.Duration); } else { particle.IsActive = false; } } else if (m_toGenerate >= 1f) { particle.IsActive = true; Vector3 v2 = 0.1f * m_size * new Vector3(m_random.Float(-1f, 1f), m_random.Float(0f, 2f), m_random.Float(-1f, 1f)); particle.Position = Position + v2; particle.Color = new Color(200, 220, 210); particle.Velocity = 1f * m_size * new Vector3(m_random.Float(-1f, 1f), num2 * m_random.Float(0.3f, 1f), m_random.Float(-1f, 1f)); particle.Size = Vector2.Zero; particle.Time = 0f; particle.Duration = m_random.Float(1f, 3f); particle.FlipX = m_random.Bool(); particle.FlipY = m_random.Bool(); m_toGenerate -= 1f; } } m_toGenerate = MathUtils.Remainder(m_toGenerate, 1f); if (!flag && (m_time >= m_duration || IsStopped)) { return(true); } return(false); }
public void Update(float dt) { if (m_subsystemTime.GameTime >= m_nextUpdateTime) { m_dt = m_random.Float(1.25f, 1.75f) + MathUtils.Min((float)(m_subsystemTime.GameTime - m_nextUpdateTime), 0.1f); m_nextUpdateTime = m_subsystemTime.GameTime + (double)m_dt; m_stateMachine.Update(); } }
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); }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemSky = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true); m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_subsystemAudio = base.Project.FindSubsystem <SubsystemAudio>(throwOnError: true); m_componentCreature = base.Entity.FindComponent <ComponentCreature>(throwOnError: true); m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true); m_howlSoundName = valuesDictionary.GetValue <string>("HowlSoundName"); m_stateMachine.AddState("Inactive", delegate { m_importanceLevel = 0f; }, delegate { if (IsActive) { m_stateMachine.TransitionTo("Howl"); } if (m_subsystemSky.SkyLightIntensity < 0.1f) { if (m_random.Float(0f, 1f) < 0.015f * m_subsystemTime.GameTimeDelta) { m_importanceLevel = m_random.Float(1f, 3f); } } else { m_importanceLevel = 0f; } }, null); m_stateMachine.AddState("Howl", delegate { m_howlTime = 0f; m_howlDuration = m_random.Float(5f, 6f); m_componentPathfinding.Stop(); m_importanceLevel = 10f; }, delegate { if (!IsActive) { m_stateMachine.TransitionTo("Inactive"); } m_componentCreature.ComponentLocomotion.LookOrder = new Vector2(m_componentCreature.ComponentLocomotion.LookOrder.X, 2f); float num = m_howlTime + m_subsystemTime.GameTimeDelta; if (m_howlTime <= 0.5f && num > 0.5f) { m_subsystemAudio.PlayRandomSound(m_howlSoundName, 1f, m_random.Float(-0.1f, 0.1f), m_componentCreature.ComponentBody.Position, 10f, autoDelay: true); } m_howlTime = num; if (m_howlTime >= m_howlDuration) { m_importanceLevel = 0f; } }, null); m_stateMachine.TransitionTo("Inactive"); }
public SmokeTrailParticleSystem(int particlesCount, float size, float maxDuration, Color color) : base(particlesCount) { m_size = size; m_maxDuration = maxDuration; base.Texture = ContentManager.Get <Texture2D>("Textures/FireParticle"); base.TextureSlotsCount = 3; m_textureSlotMultiplier = m_random.Float(1.1f, 1.9f); m_textureSlotOffset = ((m_random.Float(0f, 1f) < 0.33f) ? 3 : 0); m_color = color; }
public override bool Simulate(float dt) { bool flag = false; m_generationSpeed = MathUtils.Min(m_generationSpeed + 15f * dt, 35f); m_toGenerate += m_generationSpeed * dt; for (int i = 0; i < base.Particles.Length; i++) { Particle particle = base.Particles[i]; if (particle.IsActive) { flag = true; particle.Time += dt; if (particle.Time <= particle.Duration) { particle.Position += particle.Velocity * dt; particle.FlipX = m_random.Bool(); particle.FlipY = m_random.Bool(); particle.TextureSlot = (int)MathUtils.Min(9.900001f * particle.Time / particle.Duration, 8f); } else { particle.IsActive = false; } } else if (!Stopped) { while (m_toGenerate >= 1f) { particle.IsActive = true; particle.Position.X = m_random.Float(BoundingBox.Min.X, BoundingBox.Max.X); particle.Position.Y = m_random.Float(BoundingBox.Min.Y, BoundingBox.Max.Y); particle.Position.Z = m_random.Float(BoundingBox.Min.Z, BoundingBox.Max.Z); particle.Velocity = new Vector3(0f, m_random.Float(0.5f, 1.5f), 0f); particle.Color = Color.White; particle.Size = new Vector2(0.4f); particle.Time = 0f; particle.Duration = m_random.Float(0.75f, 1.5f); m_toGenerate -= 1f; } } else { m_toGenerate = 0f; } } m_toGenerate = MathUtils.Remainder(m_toGenerate, 1f); if (Stopped && !flag) { return(true); } return(false); }
public void Update(float dt) { if (m_componentCreature.ComponentHealth.HealthChange < 0f) { m_stateMachine.TransitionTo("DangerDetected"); } if (m_subsystemTime.GameTime >= m_nextUpdateTime) { m_nextUpdateTime = m_subsystemTime.GameTime + (double)m_random.Float(0.5f, 1f); m_stateMachine.Update(); } }
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); } } }
public static void Update() { if (m_fadeSound != null) { m_fadeSound.Volume = MathUtils.Min(m_fadeSound.Volume - 0.33f * Volume * Time.FrameDuration, Volume); if (m_fadeSound.Volume <= 0f) { m_fadeSound.Dispose(); m_fadeSound = null; } } if (m_sound != null && Time.FrameStartTime >= m_fadeStartTime) { m_sound.Volume = MathUtils.Min(m_sound.Volume + 0.33f * Volume * Time.FrameDuration, Volume); } if (m_currentMix == Mix.None || Volume == 0f) { StopMusic(); } else if (m_currentMix == Mix.Menu && (Time.FrameStartTime >= m_nextSongTime || !IsPlaying)) { float startPercentage = IsPlaying ? m_random.Float(0f, 0.75f) : 0f; switch (m_random.Int(0, 5)) { case 0: PlayMusic("Music/NativeAmericanFluteSpirit", startPercentage); break; case 1: PlayMusic("Music/AloneForever", startPercentage); break; case 2: PlayMusic("Music/NativeAmerican", startPercentage); break; case 3: PlayMusic("Music/NativeAmericanHeart", startPercentage); break; case 4: PlayMusic("Music/NativeAmericanPeaceFlute", startPercentage); break; case 5: PlayMusic("Music/NativeIndianChant", startPercentage); break; } m_nextSongTime = Time.FrameStartTime + (double)m_random.Float(40f, 60f); } }
public override void Update(float dt) { if (m_random.Float(0f, 1f) < 0.1f * dt) { m_frequency = m_random.Float(0.33f, 5f) * 0.5f; } if (m_random.Float(0f, 1f) < m_frequency * dt) { SubsystemPlayers subsystemPlayers = base.GameWidget.SubsystemGameWidgets.Project.FindSubsystem <SubsystemPlayers>(throwOnError: true); if (subsystemPlayers.PlayersData.Count > 0) { Vector3 spawnPosition = subsystemPlayers.PlayersData[0].SpawnPosition; spawnPosition.X += m_random.Float(-150f, 150f); spawnPosition.Y = m_random.Float(70f, 120f); spawnPosition.Z += m_random.Float(-150f, 150f); Vector3 direction = m_random.Vector3(1f); SetupPerspectiveCamera(spawnPosition, direction, Vector3.UnitY); } } if (m_random.Float(0f, 1f) < 0.5f * m_frequency * dt) { base.GameWidget.SubsystemGameWidgets.Project.FindSubsystem <SubsystemTimeOfDay>(throwOnError: true).TimeOfDayOffset = m_random.Float(0f, 1f); } if (m_random.Float(0f, 1f) < 1f * dt * 0.5f) { GameManager.SaveProject(waitForCompletion: false, showErrorDialog: false); } }
public static TerrainBrush CreateTreeBrush(Random random, int woodIndex, int leavesIndex, int height, int branchesCount, Func <int, float> leavesProbabilityByHeight, Func <int, float> branchesLengthByHeight) { TerrainBrush terrainBrush = new TerrainBrush(); terrainBrush.AddRay(0, -1, 0, 0, height, 0, 1, 1, 1, woodIndex); for (int i = 0; i < branchesCount; i++) { int x = 0; int num = random.Int(0, height); int z = 0; float s = branchesLengthByHeight(num); Vector3 vector = Vector3.Normalize(new Vector3(random.Float(-1f, 1f), random.Float(0f, 0.33f), random.Float(-1f, 1f))) * s; int x2 = (int)MathUtils.Round(vector.X); int y = num + (int)MathUtils.Round(vector.Y); int z2 = (int)MathUtils.Round(vector.Z); int cutFace = 0; if (MathUtils.Abs(vector.X) == MathUtils.Max(MathUtils.Abs(vector.X), MathUtils.Abs(vector.Y), MathUtils.Abs(vector.Z))) { cutFace = 1; } else if (MathUtils.Abs(vector.Y) == MathUtils.Max(MathUtils.Abs(vector.X), MathUtils.Abs(vector.Y), MathUtils.Abs(vector.Z))) { cutFace = 4; } terrainBrush.AddRay(x, num, z, x2, y, z2, 1, 1, 1, (Func <int?, int?>)((int?v) => v.HasValue ? null : new int?(Terrain.MakeBlockValue(woodIndex, 0, WoodBlock.SetCutFace(0, cutFace))))); } for (int j = 0; j < 3; j++) { terrainBrush.CalculateBounds(out Point3 min, out Point3 max); for (int k = min.X - 1; k <= max.X + 1; k++) { for (int l = min.Z - 1; l <= max.Z + 1; l++) { for (int m = 1; m <= max.Y + 1; m++) { float num2 = leavesProbabilityByHeight(m); if (random.Float(0f, 1f) < num2 && !terrainBrush.GetValue(k, m, l).HasValue&& (terrainBrush.CountNonDiagonalNeighbors(k, m, l, leavesIndex) != 0 || terrainBrush.CountNonDiagonalNeighbors(k, m, l, (Func <int?, int>)((int?v) => (v.HasValue && Terrain.ExtractContents(v.Value) == woodIndex) ? 1 : 0)) != 0)) { terrainBrush.AddCell(k, m, l, 0); } } } } terrainBrush.Replace(0, leavesIndex); } terrainBrush.AddCell(0, height, 0, leavesIndex); terrainBrush.Compile(); return(terrainBrush); }
public override bool Simulate(float dt) { m_age += dt; bool flag = false; if (m_visible || m_age < 2f) { m_toGenerate += (IsStopped ? 0f : (5f * dt)); for (int i = 0; i < base.Particles.Length; i++) { Particle particle = base.Particles[i]; if (particle.IsActive) { flag = true; particle.Time += dt; particle.TimeToLive -= dt; if (particle.TimeToLive > 0f) { particle.Position.Y += particle.Speed * dt; particle.TextureSlot = (int)MathUtils.Min(9f * particle.Time / 1.25f, 8f); } else { particle.IsActive = false; } } else if (m_toGenerate >= 1f) { particle.IsActive = true; particle.Position = m_position + 0.25f * m_size * new Vector3(m_random.Float(-1f, 1f), 0f, m_random.Float(-1f, 1f)); particle.Color = Color.White; particle.Size = new Vector2(m_size); particle.Speed = m_random.Float(0.45f, 0.55f) * m_size / 0.15f; particle.Time = 0f; particle.TimeToLive = m_random.Float(0.5f, 2f); particle.FlipX = (m_random.Int(0, 1) == 0); particle.FlipY = (m_random.Int(0, 1) == 0); m_toGenerate -= 1f; } } m_toGenerate = MathUtils.Remainder(m_toGenerate, 1f); } m_visible = false; if (IsStopped) { return(!flag); } return(false); }
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 void PlayImpactSound(int value, Vector3 position, float loudnessMultiplier) { int num = Terrain.ExtractContents(value); string soundMaterialName = BlocksManager.Blocks[num].GetSoundMaterialName(m_subsystemTerrain, value); if (!string.IsNullOrEmpty(soundMaterialName)) { string value2 = m_impactsSoundsValuesDictionary.GetValue <string>(soundMaterialName, null); if (!string.IsNullOrEmpty(value2)) { float pitch = m_random.Float(-0.2f, 0.2f); m_subsystemAudio.PlayRandomSound(value2, 0.5f * loudnessMultiplier, pitch, position, 5f * loudnessMultiplier, autoDelay: true); } } }
public override bool Simulate(float dt) { float num = 120f; m_toGenerate += num * dt; if (!m_lastPosition.HasValue) { m_lastPosition = Position; } bool flag = false; for (int i = 0; i < base.Particles.Length; i++) { Particle particle = base.Particles[i]; if (particle.IsActive) { flag = true; particle.Time += dt; if (particle.Time <= particle.Duration) { particle.TextureSlot = (int)MathUtils.Min(9f * particle.Time / particle.Duration, 8f); } else { particle.IsActive = false; } } else if (!IsStopped && m_toGenerate >= 1f) { particle.IsActive = true; particle.Position = Vector3.Lerp(m_lastPosition.Value, Position, m_random.Float(0f, 1f)); particle.Color = Color.White; particle.Time = m_random.Float(0f, 0.75f); particle.Size = new Vector2(m_random.Float(0.12f, 0.16f)); particle.Duration = 1f; particle.FlipX = m_random.Bool(); particle.FlipY = m_random.Bool(); m_toGenerate -= 1f; } } m_toGenerate = MathUtils.Remainder(m_toGenerate, 1f); m_lastPosition = Position; if (IsStopped) { return(!flag); } return(false); }
public bool IgniteFuse(int x, int y, int z) { int cellContents = m_subsystemTerrain.Terrain.GetCellContents(x, y, z); if (BlocksManager.Blocks[cellContents] is GunpowderKegBlock) { AddExplosive(new Point3(x, y, z), m_random.Float(4f, 5f)); return(true); } if (BlocksManager.Blocks[cellContents] is DetonatorBlock) { AddExplosive(new Point3(x, y, z), m_random.Float(0.8f, 1.2f)); return(true); } return(false); }
public void DropAllItems(Vector3 position) { for (int i = 0; i < SlotsCount; i++) { DropSlotItems(this, i, position, m_random.Float(5f, 10f) * Vector3.Normalize(new Vector3(m_random.Float(-1f, 1f), m_random.Float(1f, 2f), m_random.Float(-1f, 1f)))); } }
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); }
public bool AddFuel(int x, int y, int z, int value, int count) { if (Terrain.ExtractData(base.SubsystemTerrain.Terrain.GetCellValue(x, y, z)) > 0) { int num = Terrain.ExtractContents(value); Block block = BlocksManager.Blocks[num]; if (base.Project.FindSubsystem <SubsystemExplosions>(throwOnError: true).TryExplodeBlock(x, y, z, value)) { return(true); } if (block is SnowBlock || block is SnowballBlock || block is IceBlock) { return(ResizeCampfire(x, y, z, -1, playSound: true)); } if (block.FuelHeatLevel > 0f) { float num2 = (float)count * MathUtils.Min(block.FuelFireDuration, 20f) / 5f; int num3 = (int)num2; float num4 = num2 - (float)num3; if (m_random.Float(0f, 1f) < num4) { num3++; } if (num3 > 0) { return(ResizeCampfire(x, y, z, num3, playSound: true)); } return(true); } } return(false); }