public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_subsystemTimeOfDay = base.Project.FindSubsystem <SubsystemTimeOfDay>(throwOnError: true); m_subsystemTerrain = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true); m_subsystemParticles = base.Project.FindSubsystem <SubsystemParticles>(throwOnError: true); m_subsystemGameInfo = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true); m_subsystemPickables = base.Project.FindSubsystem <SubsystemPickables>(throwOnError: true); m_componentCreature = base.Entity.FindComponent <ComponentCreature>(throwOnError: true); m_componentPlayer = base.Entity.FindComponent <ComponentPlayer>(); m_componentOnFire = base.Entity.FindComponent <ComponentOnFire>(throwOnError: true); AttackResilience = valuesDictionary.GetValue <float>("AttackResilience"); FallResilience = valuesDictionary.GetValue <float>("FallResilience"); FireResilience = valuesDictionary.GetValue <float>("FireResilience"); CorpseDuration = valuesDictionary.GetValue <float>("CorpseDuration"); BreathingMode = valuesDictionary.GetValue <BreathingMode>("BreathingMode"); CanStrand = valuesDictionary.GetValue <bool>("CanStrand"); Health = valuesDictionary.GetValue <float>("Health"); Air = valuesDictionary.GetValue <float>("Air"); AirCapacity = valuesDictionary.GetValue <float>("AirCapacity"); double value = valuesDictionary.GetValue <double>("DeathTime"); DeathTime = ((value >= 0.0) ? new double?(value) : null); CauseOfDeath = valuesDictionary.GetValue <string>("CauseOfDeath"); if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative && base.Entity.FindComponent <ComponentPlayer>() != null) { IsInvulnerable = true; } }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemTerrain = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true); m_subsystemAudio = base.Project.FindSubsystem <SubsystemAudio>(throwOnError: true); m_subsystemParticles = base.Project.FindSubsystem <SubsystemParticles>(throwOnError: true); m_componentBody = base.Entity.FindComponent <ComponentBody>(throwOnError: true); m_componentOnFire = base.Entity.FindComponent <ComponentOnFire>(); Hitpoints = valuesDictionary.GetValue <float>("Hitpoints"); AttackResilience = valuesDictionary.GetValue <float>("AttackResilience"); m_fallResilience = valuesDictionary.GetValue <float>("FallResilience"); m_fireResilience = valuesDictionary.GetValue <float>("FireResilience"); m_debrisTextureSlot = valuesDictionary.GetValue <int>("DebrisTextureSlot"); m_debrisStrength = valuesDictionary.GetValue <float>("DebrisStrength"); m_debrisScale = valuesDictionary.GetValue <float>("DebrisScale"); DamageSoundName = valuesDictionary.GetValue <string>("DestructionSoundName"); }
public override bool OnUse(Ray3 ray, ComponentMiner componentMiner) { object obj = componentMiner.Raycast(ray, RaycastMode.Digging); if (obj is TerrainRaycastResult) { CellFace cellFace = ((TerrainRaycastResult)obj).CellFace; if (m_subsystemExplosivesBlockBehavior.IgniteFuse(cellFace.X, cellFace.Y, cellFace.Z)) { m_subsystemAudio.PlaySound("Audio/Match", 1f, m_random.Float(-0.1f, 0.1f), ray.Position, 1f, autoDelay: true); componentMiner.RemoveActiveTool(1); return(true); } if (m_subsystemFireBlockBehavior.SetCellOnFire(cellFace.X, cellFace.Y, cellFace.Z, 1f)) { m_subsystemAudio.PlaySound("Audio/Match", 1f, m_random.Float(-0.1f, 0.1f), ray.Position, 1f, autoDelay: true); componentMiner.RemoveActiveTool(1); return(true); } } else if (obj is BodyRaycastResult) { ComponentOnFire componentOnFire = ((BodyRaycastResult)obj).ComponentBody.Entity.FindComponent <ComponentOnFire>(); if (componentOnFire != null) { if (m_subsystemGameInfo.WorldSettings.GameMode < GameMode.Challenging || m_random.Float(0f, 1f) < 0.33f) { componentOnFire.SetOnFire(componentMiner.ComponentCreature, m_random.Float(6f, 8f)); } m_subsystemAudio.PlaySound("Audio/Match", 1f, m_random.Float(-0.1f, 0.1f), ray.Position, 1f, autoDelay: true); componentMiner.RemoveActiveTool(1); return(true); } } return(false); }
public void PostprocessExplosions(bool playExplosionSound) { Point3 point = Point3.Zero; float num = float.MaxValue; float num2 = 0f; foreach (KeyValuePair <Point3, float> item in m_pressureByPoint.ToDictionary()) { num2 += item.Value; float num3 = m_subsystemAudio.CalculateListenerDistance(new Vector3(item.Key)); if (num3 < num) { num = num3; point = item.Key; } float num4 = 0.001f * MathUtils.Pow(num2, 0.5f); float num5 = MathUtils.Saturate(item.Value / 15f - num4) * m_random.Float(0.2f, 1f); if (num5 > 0.1f) { m_explosionParticleSystem.SetExplosionCell(item.Key, num5); } } foreach (KeyValuePair <Point3, SurroundingPressurePoint> item2 in m_surroundingPressureByPoint.ToDictionary()) { int cellValue = m_subsystemTerrain.Terrain.GetCellValue(item2.Key.X, item2.Key.Y, item2.Key.Z); int num6 = Terrain.ExtractContents(cellValue); SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(num6); if (blockBehaviors.Length != 0) { for (int i = 0; i < blockBehaviors.Length; i++) { blockBehaviors[i].OnExplosion(cellValue, item2.Key.X, item2.Key.Y, item2.Key.Z, item2.Value.Pressure); } } float probability = item2.Value.IsIncendiary ? 0.5f : 0.2f; Block block = BlocksManager.Blocks[num6]; if (block.FireDuration > 0f && item2.Value.Pressure / block.ExplosionResilience > 0.2f && m_random.Bool(probability)) { m_subsystemFireBlockBehavior.SetCellOnFire(item2.Key.X, item2.Key.Y, item2.Key.Z, item2.Value.IsIncendiary ? 1f : 0.3f); } } foreach (ComponentBody body in m_subsystemBodies.Bodies) { CalculateImpulseAndDamage(body, null, out Vector3 impulse, out float damage); impulse *= m_random.Float(0.5f, 1.5f); damage *= m_random.Float(0.5f, 1.5f); body.ApplyImpulse(impulse); body.Entity.FindComponent <ComponentHealth>()?.Injure(damage, null, ignoreInvulnerability: false, "Blasted by explosion"); body.Entity.FindComponent <ComponentDamage>()?.Damage(damage); ComponentOnFire componentOnFire = body.Entity.FindComponent <ComponentOnFire>(); if (componentOnFire != null && m_random.Float(0f, 1f) < MathUtils.Min(damage - 0.1f, 0.5f)) { componentOnFire.SetOnFire(null, m_random.Float(6f, 8f)); } } foreach (Pickable pickable in m_subsystemPickables.Pickables) { Block block2 = BlocksManager.Blocks[Terrain.ExtractContents(pickable.Value)]; CalculateImpulseAndDamage(pickable.Position + new Vector3(0f, 0.5f, 0f), 20f, null, out Vector3 impulse2, out float damage2); if (damage2 / block2.ExplosionResilience > 0.1f) { TryExplodeBlock(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y), Terrain.ToCell(pickable.Position.Z), pickable.Value); pickable.ToRemove = true; } else { Vector3 vector = (impulse2 + new Vector3(0f, 0.1f * impulse2.Length(), 0f)) * m_random.Float(0.75f, 1f); if (vector.Length() > 10f) { Projectile projectile = m_subsystemProjectiles.AddProjectile(pickable.Value, pickable.Position, pickable.Velocity + vector, m_random.Vector3(0f, 20f), null); if (m_random.Float(0f, 1f) < 0.33f) { m_subsystemProjectiles.AddTrail(projectile, Vector3.Zero, new SmokeTrailParticleSystem(15, m_random.Float(0.75f, 1.5f), m_random.Float(1f, 6f), Color.White)); } pickable.ToRemove = true; } else { pickable.Velocity += vector; } } } foreach (Projectile projectile2 in m_subsystemProjectiles.Projectiles) { if (!m_generatedProjectiles.ContainsKey(projectile2)) { CalculateImpulseAndDamage(projectile2.Position + new Vector3(0f, 0.5f, 0f), 20f, null, out Vector3 impulse3, out float _); projectile2.Velocity += (impulse3 + new Vector3(0f, 0.1f * impulse3.Length(), 0f)) * m_random.Float(0.75f, 1f); } } Vector3 position = new Vector3(point.X, point.Y, point.Z); float delay = m_subsystemAudio.CalculateDelay(num); if (num2 > 1000000f) { if (playExplosionSound) { m_subsystemAudio.PlaySound("Audio/ExplosionEnormous", 1f, m_random.Float(-0.1f, 0.1f), position, 40f, delay); } m_subsystemNoise.MakeNoise(position, 1f, 100f); } else if (num2 > 100000f) { if (playExplosionSound) { m_subsystemAudio.PlaySound("Audio/ExplosionHuge", 1f, m_random.Float(-0.2f, 0.2f), position, 30f, delay); } m_subsystemNoise.MakeNoise(position, 1f, 70f); } else if (num2 > 20000f) { if (playExplosionSound) { m_subsystemAudio.PlaySound("Audio/ExplosionLarge", 1f, m_random.Float(-0.2f, 0.2f), position, 26f, delay); } m_subsystemNoise.MakeNoise(position, 1f, 50f); } else if (num2 > 4000f) { if (playExplosionSound) { m_subsystemAudio.PlaySound("Audio/ExplosionMedium", 1f, m_random.Float(-0.2f, 0.2f), position, 24f, delay); } m_subsystemNoise.MakeNoise(position, 1f, 40f); } else if (num2 > 100f) { if (playExplosionSound) { m_subsystemAudio.PlaySound("Audio/ExplosionSmall", 1f, m_random.Float(-0.2f, 0.2f), position, 22f, delay); } m_subsystemNoise.MakeNoise(position, 1f, 35f); } else if (num2 > 0f) { if (playExplosionSound) { m_subsystemAudio.PlaySound("Audio/ExplosionTiny", 1f, m_random.Float(-0.2f, 0.2f), position, 20f, delay); } m_subsystemNoise.MakeNoise(position, 1f, 30f); } }