| using System; |
| using System; |
| using UnityEngine; |
| using UnityEngine; |
| |
| |
| public class MineRock : MonoBehaviour, IDestructible, Hoverable |
| public class MineRock : MonoBehaviour, IDestructible, Hoverable |
| { |
| { |
| private void Start() |
| private void Start() |
| { |
| { |
| this.m_hitAreas = ((this.m_areaRoot != null) ? this.m_areaRoot.GetComponentsInChildren<Collider>() : base.gameObject.GetComponentsInChildren<Collider>()); |
| this.m_hitAreas = ((this.m_areaRoot != null) ? this.m_areaRoot.GetComponentsInChildren<Collider>() : base.gameObject.GetComponentsInChildren<Collider>()); |
| if (this.m_baseModel) |
| if (this.m_baseModel) |
| { |
| { |
| this.m_areaMeshes = new MeshRenderer[this.m_hitAreas.Length][]; |
| this.m_areaMeshes = new MeshRenderer[this.m_hitAreas.Length][]; |
| for (int i = 0; i < this.m_hitAreas.Length; i++) |
| for (int i = 0; i < this.m_hitAreas.Length; i++) |
| { |
| { |
| this.m_areaMeshes[i] = this.m_hitAreas[i].GetComponents<MeshRenderer>(); |
| this.m_areaMeshes[i] = this.m_hitAreas[i].GetComponents<MeshRenderer>(); |
| } |
| } |
| } |
| } |
| this.m_nview = base.GetComponent<ZNetView>(); |
| this.m_nview = base.GetComponent<ZNetView>(); |
| if (this.m_nview && this.m_nview.GetZDO() != null) |
| if (this.m_nview && this.m_nview.GetZDO() != null) |
| { |
| { |
| this.m_nview.Register<HitData, int>("Hit", new Action<long, HitData, int>(this.RPC_Hit)); |
| this.m_nview.Register<HitData, int>("Hit", new Action<long, HitData, int>(this.RPC_Hit)); |
| this.m_nview.Register<int>("Hide", new Action<long, int>(this.RPC_Hide)); |
| this.m_nview.Register<int>("Hide", new Action<long, int>(this.RPC_Hide)); |
| } |
| } |
| base.InvokeRepeating("UpdateVisability", UnityEngine.Random.Range(1f, 2f), 10f); |
| base.InvokeRepeating("UpdateVisability", UnityEngine.Random.Range(1f, 2f), 10f); |
| } |
| } |
| |
| |
| public string GetHoverText() |
| public string GetHoverText() |
| { |
| { |
| return Localization.instance.Localize(this.m_name); |
| return Localization.instance.Localize(this.m_name); |
| } |
| } |
| |
| |
| public string GetHoverName() |
| public string GetHoverName() |
| { |
| { |
| return this.m_name; |
| return this.m_name; |
| } |
| } |
| |
| |
| private void UpdateVisability() |
| private void UpdateVisability() |
| { |
| { |
| bool flag = false; |
| bool flag = false; |
| for (int i = 0; i < this.m_hitAreas.Length; i++) |
| for (int i = 0; i < this.m_hitAreas.Length; i++) |
| { |
| { |
| Collider collider = this.m_hitAreas[i]; |
| Collider collider = this.m_hitAreas[i]; |
| if (collider) |
| if (collider) |
| { |
| { |
| string text = "Health" + i.ToString(); |
| string text = "Health" + i.ToString(); |
| bool flag2 = this.m_nview.GetZDO().GetFloat(text, this.GetHealth()) > 0f; |
| bool flag2 = this.m_nview.GetZDO().GetFloat(text, this.GetHealth()) > 0f; |
| collider.gameObject.SetActive(flag2); |
| collider.gameObject.SetActive(flag2); |
| if (!flag2) |
| if (!flag2) |
| { |
| { |
| flag = true; |
| flag = true; |
| } |
| } |
| } |
| } |
| } |
| } |
| if (this.m_baseModel) |
| if (this.m_baseModel) |
| { |
| { |
| this.m_baseModel.SetActive(!flag); |
| this.m_baseModel.SetActive(!flag); |
| foreach (MeshRenderer[] array in this.m_areaMeshes) |
| foreach (MeshRenderer[] array in this.m_areaMeshes) |
| { |
| { |
| for (int k = 0; k < array.Length; k++) |
| for (int k = 0; k < array.Length; k++) |
| { |
| { |
| array[k].enabled = flag; |
| array[k].enabled = flag; |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| public DestructibleType GetDestructibleType() |
| public DestructibleType GetDestructibleType() |
| { |
| { |
| return DestructibleType.Default; |
| return DestructibleType.Default; |
| } |
| } |
| |
| |
| public void Damage(HitData hit) |
| public void Damage(HitData hit) |
| { |
| { |
| if (hit.m_hitCollider == null) |
| if (hit.m_hitCollider == null) |
| { |
| { |
| ZLog.Log("Minerock hit has no collider"); |
| ZLog.Log("Minerock hit has no collider"); |
| return; |
| return; |
| } |
| } |
| int areaIndex = this.GetAreaIndex(hit.m_hitCollider); |
| int areaIndex = this.GetAreaIndex(hit.m_hitCollider); |
| if (areaIndex == -1) |
| if (areaIndex == -1) |
| { |
| { |
| ZLog.Log("Invalid hit area on " + base.gameObject.name); |
| ZLog.Log("Invalid hit area on " + base.gameObject.name); |
| return; |
| return; |
| } |
| } |
| ZLog.Log("Hit mine rock area " + areaIndex.ToString()); |
| ZLog.Log("Hit mine rock area " + areaIndex.ToString()); |
| this.m_nview.InvokeRPC("Hit", new object[] { hit, areaIndex }); |
| this.m_nview.InvokeRPC("Hit", new object[] { hit, areaIndex }); |
| } |
| } |
| |
| |
| private void RPC_Hit(long sender, HitData hit, int hitAreaIndex) |
| private void RPC_Hit(long sender, HitData hit, int hitAreaIndex) |
| { |
| { |
| if (!this.m_nview.IsOwner()) |
| if (!this.m_nview.IsOwner()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| Collider hitArea = this.GetHitArea(hitAreaIndex); |
| Collider hitArea = this.GetHitArea(hitAreaIndex); |
| if (hitArea == null) |
| if (hitArea == null) |
| { |
| { |
| ZLog.Log("Missing hit area " + hitAreaIndex.ToString()); |
| ZLog.Log("Missing hit area " + hitAreaIndex.ToString()); |
| return; |
| return; |
| } |
| } |
| string text = "Health" + hitAreaIndex.ToString(); |
| string text = "Health" + hitAreaIndex.ToString(); |
| float num = this.m_nview.GetZDO().GetFloat(text, this.GetHealth()); |
| float num = this.m_nview.GetZDO().GetFloat(text, this.GetHealth()); |
| if (num <= 0f) |
| if (num <= 0f) |
| { |
| { |
| ZLog.Log("Already destroyed"); |
| ZLog.Log("Already destroyed"); |
| return; |
| return; |
| } |
| } |
| HitData.DamageModifier damageModifier; |
| HitData.DamageModifier damageModifier; |
| hit.ApplyResistance(this.m_damageModifiers, out damageModifier); |
| hit.ApplyResistance(this.m_damageModifiers, out damageModifier); |
| float totalDamage = hit.GetTotalDamage(); |
| float totalDamage = hit.GetTotalDamage(); |
| . | if ((int)hit.m_toolTier < this.m_minToolTier || ((int)hit.m_itemWorldLevel < Game.m_worldLevel && ZoneSystem.instance.GetGlobalKey(GlobalKeys.WorldLevelLockedTools))) |
| if (!hit.CheckToolTier(this.m_minToolTier, false)) |
| { |
| { |
| DamageText.instance.ShowText(DamageText.TextType.TooHard, hit.m_point, 0f, false); |
| DamageText.instance.ShowText(DamageText.TextType.TooHard, hit.m_point, 0f, false); |
| return; |
| return; |
| } |
| } |
| DamageText.instance.ShowText(damageModifier, hit.m_point, totalDamage, false); |
| DamageText.instance.ShowText(damageModifier, hit.m_point, totalDamage, false); |
| if (totalDamage <= 0f) |
| if (totalDamage <= 0f) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| num -= totalDamage; |
| num -= totalDamage; |
| this.m_nview.GetZDO().Set(text, num); |
| this.m_nview.GetZDO().Set(text, num); |
| this.m_hitEffect.Create(hit.m_point, Quaternion.identity, null, 1f, -1); |
| this.m_hitEffect.Create(hit.m_point, Quaternion.identity, null, 1f, -1); |
| . | Player closestPlayer = Player.GetClosestPlayer(hit.m_point, 10f); |
| if (hit.m_hitType != HitData.HitType.CinderFire) |
| if (closestPlayer) |
| |
| { |
| { |
| . | closestPlayer.AddNoise(100f); |
| Player closestPlayer = Player.GetClosestPlayer(hit.m_point, 10f); |
| |
| if (closestPlayer) |
| |
| { |
| |
| closestPlayer.AddNoise(100f); |
| |
| } |
| } |
| } |
| if (this.m_onHit != null) |
| if (this.m_onHit != null) |
| { |
| { |
| this.m_onHit(); |
| this.m_onHit(); |
| } |
| } |
| if (hit.GetAttacker() == Player.m_localPlayer) |
| if (hit.GetAttacker() == Player.m_localPlayer) |
| { |
| { |
| Game.instance.IncrementPlayerStat(PlayerStatType.MineHits, 1f); |
| Game.instance.IncrementPlayerStat(PlayerStatType.MineHits, 1f); |
| } |
| } |
| if (num <= 0f) |
| if (num <= 0f) |
| { |
| { |
| this.m_destroyedEffect.Create(hitArea.bounds.center, Quaternion.identity, null, 1f, -1); |
| this.m_destroyedEffect.Create(hitArea.bounds.center, Quaternion.identity, null, 1f, -1); |
| this.m_nview.InvokeRPC(ZNetView.Everybody, "Hide", new object[] { hitAreaIndex }); |
| this.m_nview.InvokeRPC(ZNetView.Everybody, "Hide", new object[] { hitAreaIndex }); |
| foreach (GameObject gameObject in this.m_dropItems.GetDropList()) |
| foreach (GameObject gameObject in this.m_dropItems.GetDropList()) |
| { |
| { |
| Vector3 vector = hit.m_point - hit.m_dir * 0.2f + UnityEngine.Random.insideUnitSphere * 0.3f; |
| Vector3 vector = hit.m_point - hit.m_dir * 0.2f + UnityEngine.Random.insideUnitSphere * 0.3f; |
| UnityEngine.Object.Instantiate<GameObject>(gameObject, vector, Quaternion.identity); |
| UnityEngine.Object.Instantiate<GameObject>(gameObject, vector, Quaternion.identity); |
| ItemDrop.OnCreateNew(gameObject); |
| ItemDrop.OnCreateNew(gameObject); |
| } |
| } |
| if (this.m_removeWhenDestroyed && this.AllDestroyed()) |
| if (this.m_removeWhenDestroyed && this.AllDestroyed()) |
| { |
| { |
| this.m_nview.Destroy(); |
| this.m_nview.Destroy(); |
| } |
| } |
| if (hit.GetAttacker() == Player.m_localPlayer) |
| if (hit.GetAttacker() == Player.m_localPlayer) |
| { |
| { |
| Game.instance.IncrementPlayerStat(PlayerStatType.Mines, 1f); |
| Game.instance.IncrementPlayerStat(PlayerStatType.Mines, 1f); |
| switch (this.m_minToolTier) |
| switch (this.m_minToolTier) |
| { |
| { |
| case 0: |
| case 0: |
| Game.instance.IncrementPlayerStat(PlayerStatType.MineTier0, 1f); |
| Game.instance.IncrementPlayerStat(PlayerStatType.MineTier0, 1f); |
| return; |
| return; |
| case 1: |
| case 1: |
| Game.instance.IncrementPlayerStat(PlayerStatType.MineTier1, 1f); |
| Game.instance.IncrementPlayerStat(PlayerStatType.MineTier1, 1f); |
| return; |
| return; |
| case 2: |
| case 2: |
| Game.instance.IncrementPlayerStat(PlayerStatType.MineTier2, 1f); |
| Game.instance.IncrementPlayerStat(PlayerStatType.MineTier2, 1f); |
| return; |
| return; |
| case 3: |
| case 3: |
| Game.instance.IncrementPlayerStat(PlayerStatType.MineTier3, 1f); |
| Game.instance.IncrementPlayerStat(PlayerStatType.MineTier3, 1f); |
| return; |
| return; |
| case 4: |
| case 4: |
| Game.instance.IncrementPlayerStat(PlayerStatType.MineTier4, 1f); |
| Game.instance.IncrementPlayerStat(PlayerStatType.MineTier4, 1f); |
| return; |
| return; |
| case 5: |
| case 5: |
| Game.instance.IncrementPlayerStat(PlayerStatType.MineTier5, 1f); |
| Game.instance.IncrementPlayerStat(PlayerStatType.MineTier5, 1f); |
| return; |
| return; |
| default: |
| default: |
| ZLog.LogWarning("No stat for mine tier: " + this.m_minToolTier.ToString()); |
| ZLog.LogWarning("No stat for mine tier: " + this.m_minToolTier.ToString()); |
| break; |
| break; |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private bool AllDestroyed() |
| private bool AllDestroyed() |
| { |
| { |
| for (int i = 0; i < this.m_hitAreas.Length; i++) |
| for (int i = 0; i < this.m_hitAreas.Length; i++) |
| { |
| { |
| string text = "Health" + i.ToString(); |
| string text = "Health" + i.ToString(); |
| if (this.m_nview.GetZDO().GetFloat(text, this.GetHealth()) > 0f) |
| if (this.m_nview.GetZDO().GetFloat(text, this.GetHealth()) > 0f) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| } |
| } |
| return true; |
| return true; |
| } |
| } |
| |
| |
| private void RPC_Hide(long sender, int index) |
| private void RPC_Hide(long sender, int index) |
| { |
| { |
| Collider hitArea = this.GetHitArea(index); |
| Collider hitArea = this.GetHitArea(index); |
| if (hitArea) |
| if (hitArea) |
| { |
| { |
| hitArea.gameObject.SetActive(false); |
| hitArea.gameObject.SetActive(false); |
| } |
| } |
| if (this.m_baseModel && this.m_baseModel.activeSelf) |
| if (this.m_baseModel && this.m_baseModel.activeSelf) |
| { |
| { |
| this.m_baseModel.SetActive(false); |
| this.m_baseModel.SetActive(false); |
| foreach (MeshRenderer[] array in this.m_areaMeshes) |
| foreach (MeshRenderer[] array in this.m_areaMeshes) |
| { |
| { |
| for (int j = 0; j < array.Length; j++) |
| for (int j = 0; j < array.Length; j++) |
| { |
| { |
| array[j].enabled = true; |
| array[j].enabled = true; |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private int GetAreaIndex(Collider area) |
| private int GetAreaIndex(Collider area) |
| { |
| { |
| for (int i = 0; i < this.m_hitAreas.Length; i++) |
| for (int i = 0; i < this.m_hitAreas.Length; i++) |
| { |
| { |
| if (this.m_hitAreas[i] == area) |
| if (this.m_hitAreas[i] == area) |
| { |
| { |
| return i; |
| return i; |
| } |
| } |
| } |
| } |
| return -1; |
| return -1; |
| } |
| } |
| |
| |
| private Collider GetHitArea(int index) |
| private Collider GetHitArea(int index) |
| { |
| { |
| if (index < 0 || index >= this.m_hitAreas.Length) |
| if (index < 0 || index >= this.m_hitAreas.Length) |
| { |
| { |
| return null; |
| return null; |
| } |
| } |
| return this.m_hitAreas[index]; |
| return this.m_hitAreas[index]; |
| } |
| } |
| |
| |
| public float GetHealth() |
| public float GetHealth() |
| { |
| { |
| return this.m_health + (float)Game.m_worldLevel * this.m_health * Game.instance.m_worldLevelMineHPMultiplier; |
| return this.m_health + (float)Game.m_worldLevel * this.m_health * Game.instance.m_worldLevelMineHPMultiplier; |
| } |
| } |
| |
| |
| public string m_name = ""; |
| public string m_name = ""; |
| |
| |
| public float m_health = 2f; |
| public float m_health = 2f; |
| |
| |
| public bool m_removeWhenDestroyed = true; |
| public bool m_removeWhenDestroyed = true; |
| |
| |
| public HitData.DamageModifiers m_damageModifiers; |
| public HitData.DamageModifiers m_damageModifiers; |
| |
| |
| public int m_minToolTier; |
| public int m_minToolTier; |
| |
| |
| public GameObject m_areaRoot; |
| public GameObject m_areaRoot; |
| |
| |
| public GameObject m_baseModel; |
| public GameObject m_baseModel; |
| |
| |
| public EffectList m_destroyedEffect = new EffectList(); |
| public EffectList m_destroyedEffect = new EffectList(); |
| |
| |
| public EffectList m_hitEffect = new EffectList(); |
| public EffectList m_hitEffect = new EffectList(); |
| |
| |
| public DropTable m_dropItems; |
| public DropTable m_dropItems; |
| |
| |
| public Action m_onHit; |
| public Action m_onHit; |
| |
| |
| private Collider[] m_hitAreas; |
| private Collider[] m_hitAreas; |
| |
| |
| private MeshRenderer[][] m_areaMeshes; |
| private MeshRenderer[][] m_areaMeshes; |
| |
| |
| private ZNetView m_nview; |
| private ZNetView m_nview; |
| } |
| } |
| |
| |