| . | |
| using System; |
| |
| using System.Collections.Generic; |
| |
| using UnityEngine; |
| |
| |
| |
| public class Fire : MonoBehaviour |
| |
| { |
| |
| private void Awake() |
| |
| { |
| |
| this.m_nview = base.GetComponent<ZNetView>(); |
| |
| if (Fire.s_dotMask == 0) |
| |
| { |
| |
| Fire.s_dotMask = LayerMask.GetMask(new string[] |
| |
| { |
| |
| "Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "character", "character_net", "character_ghost", "hitbox", "character_noenv", |
| |
| "vehicle" |
| |
| }); |
| |
| Fire.s_solidMask = LayerMask.GetMask(new string[] { "Default", "static_solid", "Default_small", "piece" }); |
| |
| Fire.s_terrainMask = LayerMask.GetMask(new string[] { "terrain" }); |
| |
| Fire.s_smokeRayMask = LayerMask.GetMask(new string[] { "smoke" }); |
| |
| } |
| |
| base.InvokeRepeating("Dot", this.m_dotInterval, this.m_dotInterval); |
| |
| if (this.m_terrainHitSpawn && (this.m_terrainHitBiomes == Heightmap.Biome.All || this.m_terrainHitBiomes.HasFlag(WorldGenerator.instance.GetBiome(base.transform.position)))) |
| |
| { |
| |
| base.Invoke("HitTerrain", this.m_terrainHitDelay); |
| |
| } |
| |
| base.InvokeRepeating("UpdateFire", UnityEngine.Random.Range(this.m_updateRate / 2f, this.m_updateRate), this.m_updateRate); |
| |
| } |
| |
| |
| |
| private void Dot() |
| |
| { |
| |
| if (!this.m_nview.IsValid() || !this.m_nview.IsOwner()) |
| |
| { |
| |
| return; |
| |
| } |
| |
| Fire.m_destructibles.Clear(); |
| |
| int num = Physics.OverlapSphereNonAlloc(base.transform.position, this.m_dotRadius, Fire.m_colliders, Fire.s_dotMask); |
| |
| for (int i = 0; i < num; i++) |
| |
| { |
| |
| GameObject gameObject = Projectile.FindHitObject(Fire.m_colliders[i]); |
| |
| IDestructible component = gameObject.GetComponent<IDestructible>(); |
| |
| if (UnityEngine.Random.Range(0f, 1f) < this.m_fuelBurnChance) |
| |
| { |
| |
| Fireplace component2 = gameObject.GetComponent<Fireplace>(); |
| |
| if (component2 != null) |
| |
| { |
| |
| component2.AddFuel(-this.m_fuelBurnAmount); |
| |
| } |
| |
| } |
| |
| if (gameObject.GetComponent<Character>()) |
| |
| { |
| |
| this.DoDamage(component, Fire.m_colliders[i]); |
| |
| } |
| |
| else |
| |
| { |
| |
| WearNTear component3 = gameObject.GetComponent<WearNTear>(); |
| |
| if ((component3 == null || component3.m_burnable) && component != null) |
| |
| { |
| |
| Fire.m_destructibles.Add(new KeyValuePair<IDestructible, Collider>(component, Fire.m_colliders[i])); |
| |
| } |
| |
| } |
| |
| } |
| |
| if (Fire.m_destructibles.Count > 0) |
| |
| { |
| |
| KeyValuePair<IDestructible, Collider> keyValuePair = Fire.m_destructibles[UnityEngine.Random.Range(0, Fire.m_destructibles.Count)]; |
| |
| this.DoDamage(keyValuePair.Key, keyValuePair.Value); |
| |
| } |
| |
| } |
| |
| |
| |
| private void DoDamage(IDestructible toHit, Collider collider) |
| |
| { |
| |
| HitData hitData = new HitData(); |
| |
| hitData.m_hitCollider = collider; |
| |
| hitData.m_damage.m_fire = this.m_fireDamage; |
| |
| hitData.m_damage.m_chop = this.m_chopDamage; |
| |
| hitData.m_toolTier = this.m_toolTier; |
| |
| hitData.m_point = (base.transform.position + collider.bounds.center) * 0.5f; |
| |
| hitData.m_dodgeable = false; |
| |
| hitData.m_blockable = false; |
| |
| hitData.m_hitType = HitData.HitType.CinderFire; |
| |
| this.m_hitEffect.Create(hitData.m_point, Quaternion.identity, null, 1f, -1); |
| |
| toHit.Damage(hitData); |
| |
| } |
| |
| |
| |
| private void HitTerrain() |
| |
| { |
| |
| RaycastHit raycastHit; |
| |
| if (Physics.Raycast(base.transform.position, Vector3.down, out raycastHit, this.m_terrainMaxDist, Fire.s_terrainMask)) |
| |
| { |
| |
| Heightmap component = raycastHit.collider.GetComponent<Heightmap>(); |
| |
| if (component != null && !component.IsLava(raycastHit.point, 0.6f) && ((this.m_terrainCheckCultivated && !component.IsCultivated(raycastHit.point)) || (this.m_terrainCheckCleared && !component.IsCleared(raycastHit.point)) || (!this.m_terrainCheckCleared && !this.m_terrainCheckCultivated))) |
| |
| { |
| |
| UnityEngine.Object.Instantiate<GameObject>(this.m_terrainHitSpawn, raycastHit.point, Quaternion.identity); |
| |
| } |
| |
| } |
| |
| } |
| |
| |
| |
| private void UpdateFire() |
| |
| { |
| |
| if (!this.m_nview.IsValid() || !this.m_nview.IsOwner()) |
| |
| { |
| |
| return; |
| |
| } |
| |
| if (!this.m_roof) |
| |
| { |
| |
| WearNTear.RoofCheck(base.transform.position, out this.m_roof); |
| |
| } |
| |
| if (!this.m_roof && EnvMan.IsWet()) |
| |
| { |
| |
| ZNetScene.instance.Destroy(base.gameObject); |
| |
| } |
| |
| if (this.m_roof) |
| |
| { |
| |
| this.m_smokeHits = Physics.OverlapSphereNonAlloc(base.transform.position + Vector3.up * this.m_smokeOxygenCheckHeight, this.m_smokeOxygenCheckRadius, Fire.s_hits, Fire.s_smokeRayMask); |
| |
| this.m_smokeHits -= this.m_oxygenSmokeTolerance; |
| |
| if (this.m_smokeHits > 0) |
| |
| { |
| |
| this.m_suffocating += (float)this.m_smokeHits * this.m_smokeSuffocationPerHit; |
| |
| Terminal.Log(string.Format("Fire suffocation in interior with {0} smoke hits", this.m_smokeHits)); |
| |
| } |
| |
| else |
| |
| { |
| |
| this.m_suffocating = Mathf.Max(0f, this.m_suffocating - 1f); |
| |
| } |
| |
| } |
| |
| else |
| |
| { |
| |
| this.m_inSmoke = Physics.CheckSphere(base.transform.position + Vector3.up * this.m_smokeCheckHeight, this.m_smokeCheckRadius, Fire.s_smokeRayMask); |
| |
| if (this.m_inSmoke) |
| |
| { |
| |
| this.m_suffocating += 1f; |
| |
| Terminal.Log("Fire in direct smoke"); |
| |
| } |
| |
| else |
| |
| { |
| |
| this.m_suffocating = Mathf.Max(0f, this.m_suffocating - 1f); |
| |
| } |
| |
| } |
| |
| if (this.m_suffocating >= this.m_maxSmoke && (this.m_smokeDieChance >= 1f || UnityEngine.Random.Range(0f, 1f) < this.m_smokeDieChance)) |
| |
| { |
| |
| Terminal.Log("Fire suffocated"); |
| |
| ZNetScene.instance.Destroy(base.gameObject); |
| |
| } |
| |
| } |
| |
| |
| |
| private static Collider[] m_colliders = new Collider[128]; |
| |
| |
| |
| private static List<KeyValuePair<IDestructible, Collider>> m_destructibles = new List<KeyValuePair<IDestructible, Collider>>(); |
| |
| |
| |
| public float m_dotInterval = 1f; |
| |
| |
| |
| public float m_dotRadius = 1f; |
| |
| |
| |
| public float m_fireDamage = 10f; |
| |
| |
| |
| public float m_chopDamage = 10f; |
| |
| |
| |
| public short m_toolTier = 2; |
| |
| |
| |
| public int m_spread = 4; |
| |
| |
| |
| public float m_updateRate = 2f; |
| |
| |
| |
| [Header("Terrain hit")] |
| |
| public float m_terrainHitDelay; |
| |
| |
| |
| public float m_terrainMaxDist; |
| |
| |
| |
| public bool m_terrainCheckCultivated; |
| |
| |
| |
| public bool m_terrainCheckCleared; |
| |
| |
| |
| public GameObject m_terrainHitSpawn; |
| |
| |
| |
| public Heightmap.Biome m_terrainHitBiomes = Heightmap.Biome.All; |
| |
| |
| |
| [Header("Burn fuel from fireplaces")] |
| |
| public float m_fuelBurnChance = 0.5f; |
| |
| |
| |
| public float m_fuelBurnAmount = 0.1f; |
| |
| |
| |
| [Header("Smoke")] |
| |
| public SmokeSpawner m_smokeSpawner; |
| |
| |
| |
| public float m_smokeCheckHeight = 0.25f; |
| |
| |
| |
| public float m_smokeCheckRadius = 0.5f; |
| |
| |
| |
| public float m_smokeOxygenCheckHeight = 1.25f; |
| |
| |
| |
| public float m_smokeOxygenCheckRadius = 1.5f; |
| |
| |
| |
| public float m_smokeSuffocationPerHit = 0.2f; |
| |
| |
| |
| public int m_oxygenSmokeTolerance = 2; |
| |
| |
| |
| public int m_oxygenInteriorChecks = 5; |
| |
| |
| |
| public float m_smokeDieChance = 0.5f; |
| |
| |
| |
| public float m_maxSmoke = 3f; |
| |
| |
| |
| [Header("Effects")] |
| |
| public EffectList m_hitEffect; |
| |
| |
| |
| private static int s_dotMask = 0; |
| |
| |
| |
| private static int s_solidMask = 0; |
| |
| |
| |
| private static int s_terrainMask = 0; |
| |
| |
| |
| private static int s_smokeRayMask = 0; |
| |
| |
| |
| private static readonly RaycastHit[] s_raycastHits = new RaycastHit[32]; |
| |
| |
| |
| private static readonly Collider[] s_hits = new Collider[32]; |
| |
| |
| |
| private int m_smokeHits; |
| |
| |
| |
| private bool m_inSmoke; |
| |
| |
| |
| private GameObject m_roof; |
| |
| |
| |
| private ZNetView m_nview; |
| |
| |
| |
| private float m_suffocating; |
| |
| } |
| |
| |