| . | |
| using System; |
| |
| using UnityEngine; |
| |
| |
| |
| public class CinderSpawner : MonoBehaviour |
| |
| { |
| |
| private void Awake() |
| |
| { |
| |
| this.m_nview = base.GetComponentInParent<ZNetView>(); |
| |
| if (this.m_cinderInterval > 0f) |
| |
| { |
| |
| base.InvokeRepeating("UpdateSpawnCinder", this.m_cinderInterval, this.m_cinderInterval); |
| |
| } |
| |
| if (this.m_spawnOnAwake) |
| |
| { |
| |
| this.SpawnCinder(); |
| |
| } |
| |
| if (this.m_spawnOnProjectileHit) |
| |
| { |
| |
| Projectile component = base.GetComponent<Projectile>(); |
| |
| if (component != null) |
| |
| { |
| |
| Projectile projectile = component; |
| |
| projectile.m_onHit = (OnProjectileHit)Delegate.Combine(projectile.m_onHit, new OnProjectileHit(delegate(Collider collider, Vector3 point, bool water) |
| |
| { |
| |
| this.SpawnCinder(); |
| |
| })); |
| |
| } |
| |
| } |
| |
| this.m_fireplace = base.GetComponent<Fireplace>(); |
| |
| } |
| |
| |
| |
| private void FixedUpdate() |
| |
| { |
| |
| if (this.m_hasAttachObj && !this.m_attachObj) |
| |
| { |
| |
| this.DestroyNow(); |
| |
| } |
| |
| } |
| |
| |
| |
| public void Setup(int spread, GameObject attachObj) |
| |
| { |
| |
| this.m_nview.GetZDO().Set(ZDOVars.s_spread, spread, false); |
| |
| this.m_hasAttachObj = attachObj != null; |
| |
| this.m_attachObj = attachObj; |
| |
| } |
| |
| |
| |
| private int GetSpread() |
| |
| { |
| |
| return this.m_nview.GetZDO().GetInt(ZDOVars.s_spread, this.m_spread); |
| |
| } |
| |
| |
| |
| private void UpdateSpawnCinder() |
| |
| { |
| |
| if (!this.m_nview.IsValid() || !this.m_nview.IsOwner()) |
| |
| { |
| |
| return; |
| |
| } |
| |
| if (this.m_fireplace && !this.m_fireplace.IsBurning()) |
| |
| { |
| |
| return; |
| |
| } |
| |
| if (!this.CanSpawnCinder()) |
| |
| { |
| |
| return; |
| |
| } |
| |
| if (this.GetSpread() <= 0) |
| |
| { |
| |
| return; |
| |
| } |
| |
| if (UnityEngine.Random.value > this.m_cinderChance) |
| |
| { |
| |
| return; |
| |
| } |
| |
| this.SpawnCinder(); |
| |
| } |
| |
| |
| |
| public void SpawnCinder() |
| |
| { |
| |
| if (!this.m_nview.IsValid() || !this.m_nview.IsOwner()) |
| |
| { |
| |
| return; |
| |
| } |
| |
| if (!this.CanSpawnCinder()) |
| |
| { |
| |
| return; |
| |
| } |
| |
| if (ShieldGenerator.IsInsideShield(base.transform.position)) |
| |
| { |
| |
| return; |
| |
| } |
| |
| for (int i = 0; i < this.m_instancesPerSpawn; i++) |
| |
| { |
| |
| Vector3 insideUnitSphere = UnityEngine.Random.insideUnitSphere; |
| |
| insideUnitSphere.y = Mathf.Abs(insideUnitSphere.y * 2f); |
| |
| insideUnitSphere.Normalize(); |
| |
| UnityEngine.Object.Instantiate<GameObject>(this.m_cinderPrefab, base.transform.position + insideUnitSphere * this.m_spawnOffset, Quaternion.identity).GetComponent<Cinder>().Setup(insideUnitSphere * this.m_cinderVel, this.GetSpread() - 1); |
| |
| } |
| |
| } |
| |
| |
| |
| public bool CanSpawnCinder() |
| |
| { |
| |
| return CinderSpawner.CanSpawnCinder(base.transform, ref this.m_biome); |
| |
| } |
| |
| |
| |
| public static bool CanSpawnCinder(Transform transform, ref Heightmap.Biome biome) |
| |
| { |
| |
| if (biome == Heightmap.Biome.None) |
| |
| { |
| |
| Vector3 position = transform.position; |
| |
| Vector3 vector; |
| |
| Heightmap.Biome biome2; |
| |
| Heightmap.BiomeArea biomeArea; |
| |
| Heightmap heightmap; |
| |
| ZoneSystem.instance.GetGroundData(ref position, out vector, out biome2, out biomeArea, out heightmap); |
| |
| if (heightmap != null) |
| |
| { |
| |
| biome = heightmap.GetBiome(transform.position, 0.02f, false); |
| |
| } |
| |
| } |
| |
| return biome == Heightmap.Biome.AshLands || ZoneSystem.instance.GetGlobalKey(GlobalKeys.Fire); |
| |
| } |
| |
| |
| |
| private void DestroyNow() |
| |
| { |
| |
| if (!this.m_nview.IsValid() || !this.m_nview.IsOwner()) |
| |
| { |
| |
| return; |
| |
| } |
| |
| this.m_nview.Destroy(); |
| |
| } |
| |
| |
| |
| private void OnDrawGizmosSelected() |
| |
| { |
| |
| Gizmos.color = Color.cyan; |
| |
| Gizmos.DrawWireSphere(base.transform.position + this.m_spawnOffsetPoint, 0.05f); |
| |
| } |
| |
| |
| |
| public GameObject m_cinderPrefab; |
| |
| |
| |
| public float m_cinderInterval = 2f; |
| |
| |
| |
| public float m_cinderChance = 0.1f; |
| |
| |
| |
| public float m_cinderVel = 5f; |
| |
| |
| |
| public float m_spawnOffset = 1f; |
| |
| |
| |
| public Vector3 m_spawnOffsetPoint; |
| |
| |
| |
| public int m_spread = 4; |
| |
| |
| |
| public int m_instancesPerSpawn = 1; |
| |
| |
| |
| public bool m_spawnOnAwake; |
| |
| |
| |
| public bool m_spawnOnProjectileHit; |
| |
| |
| |
| private ZNetView m_nview; |
| |
| |
| |
| private Heightmap.Biome m_biome; |
| |
| |
| |
| private GameObject m_attachObj; |
| |
| |
| |
| private bool m_hasAttachObj; |
| |
| |
| |
| private Fireplace m_fireplace; |
| |
| } |
| |
| |