| using System; |
| using System; |
| using System.Collections; |
| using System.Collections; |
| using System.Collections.Generic; |
| using System.Collections.Generic; |
| using UnityEngine; |
| using UnityEngine; |
| |
| |
| public class TreeBase : MonoBehaviour, IDestructible |
| public class TreeBase : MonoBehaviour, IDestructible |
| { |
| { |
| private void Awake() |
| private void Awake() |
| { |
| { |
| this.m_nview = base.GetComponent<ZNetView>(); |
| this.m_nview = base.GetComponent<ZNetView>(); |
| . | this.m_nview.Register<HitData>("Damage", new Action<long, HitData>(this.RPC_Damage)); |
| this.m_nview.Register<HitData>("RPC_Damage", new Action<long, HitData>(this.RPC_Damage)); |
| this.m_nview.Register("Grow", new Action<long>(this.RPC_Grow)); |
| this.m_nview.Register("RPC_Grow", new Action<long>(this.RPC_Grow)); |
| this.m_nview.Register("Shake", new Action<long>(this.RPC_Shake)); |
| this.m_nview.Register("RPC_Shake", new Action<long>(this.RPC_Shake)); |
| if (this.m_nview.IsOwner() && this.m_nview.GetZDO().GetFloat(ZDOVars.s_health, this.m_health + (float)Game.m_worldLevel * this.m_health * Game.instance.m_worldLevelMineHPMultiplier) <= 0f) |
| if (this.m_nview.IsOwner() && this.m_nview.GetZDO().GetFloat(ZDOVars.s_health, this.m_health + (float)Game.m_worldLevel * this.m_health * Game.instance.m_worldLevelMineHPMultiplier) <= 0f) |
| { |
| { |
| this.m_nview.Destroy(); |
| this.m_nview.Destroy(); |
| } |
| } |
| } |
| } |
| |
| |
| public DestructibleType GetDestructibleType() |
| public DestructibleType GetDestructibleType() |
| { |
| { |
| return DestructibleType.Tree; |
| return DestructibleType.Tree; |
| } |
| } |
| |
| |
| public void Damage(HitData hit) |
| public void Damage(HitData hit) |
| { |
| { |
| . | this.m_nview.InvokeRPC("Damage", new object[] { hit }); |
| this.m_nview.InvokeRPC("RPC_Damage", new object[] { hit }); |
| } |
| } |
| |
| |
| public void Grow() |
| public void Grow() |
| { |
| { |
| . | this.m_nview.InvokeRPC(ZNetView.Everybody, "Grow", Array.Empty<object>()); |
| this.m_nview.InvokeRPC(ZNetView.Everybody, "RPC_Grow", Array.Empty<object>()); |
| } |
| } |
| |
| |
| private void RPC_Grow(long uid) |
| private void RPC_Grow(long uid) |
| { |
| { |
| base.StartCoroutine("GrowAnimation"); |
| base.StartCoroutine("GrowAnimation"); |
| } |
| } |
| |
| |
| private IEnumerator GrowAnimation() |
| private IEnumerator GrowAnimation() |
| { |
| { |
| GameObject animatedTrunk = UnityEngine.Object.Instantiate<GameObject>(this.m_trunk, this.m_trunk.transform.position, this.m_trunk.transform.rotation, base.transform); |
| GameObject animatedTrunk = UnityEngine.Object.Instantiate<GameObject>(this.m_trunk, this.m_trunk.transform.position, this.m_trunk.transform.rotation, base.transform); |
| animatedTrunk.isStatic = false; |
| animatedTrunk.isStatic = false; |
| LODGroup component = base.transform.GetComponent<LODGroup>(); |
| LODGroup component = base.transform.GetComponent<LODGroup>(); |
| if (component) |
| if (component) |
| { |
| { |
| component.fadeMode = LODFadeMode.None; |
| component.fadeMode = LODFadeMode.None; |
| } |
| } |
| this.m_trunk.SetActive(false); |
| this.m_trunk.SetActive(false); |
| for (float t = 0f; t < 0.3f; t += Time.deltaTime) |
| for (float t = 0f; t < 0.3f; t += Time.deltaTime) |
| { |
| { |
| float num = Mathf.Clamp01(t / 0.3f); |
| float num = Mathf.Clamp01(t / 0.3f); |
| animatedTrunk.transform.localScale = this.m_trunk.transform.localScale * num; |
| animatedTrunk.transform.localScale = this.m_trunk.transform.localScale * num; |
| yield return null; |
| yield return null; |
| } |
| } |
| UnityEngine.Object.Destroy(animatedTrunk); |
| UnityEngine.Object.Destroy(animatedTrunk); |
| this.m_trunk.SetActive(true); |
| this.m_trunk.SetActive(true); |
| if (this.m_nview.IsOwner()) |
| if (this.m_nview.IsOwner()) |
| { |
| { |
| this.m_respawnEffect.Create(base.transform.position, base.transform.rotation, base.transform, 1f, -1); |
| this.m_respawnEffect.Create(base.transform.position, base.transform.rotation, base.transform, 1f, -1); |
| } |
| } |
| yield break; |
| yield break; |
| } |
| } |
| |
| |
| private void RPC_Damage(long sender, HitData hit) |
| private void RPC_Damage(long sender, HitData hit) |
| { |
| { |
| if (!this.m_nview.IsOwner()) |
| if (!this.m_nview.IsOwner()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| float num = this.m_nview.GetZDO().GetFloat(ZDOVars.s_health, this.m_health); |
| float num = this.m_nview.GetZDO().GetFloat(ZDOVars.s_health, this.m_health); |
| if (num <= 0f) |
| if (num <= 0f) |
| { |
| { |
| this.m_nview.Destroy(); |
| this.m_nview.Destroy(); |
| return; |
| return; |
| } |
| } |
| . | |
| bool flag = hit.m_damage.GetMajorityDamageType() == HitData.DamageType.Fire; |
| |
| bool flag2 = hit.m_hitType == HitData.HitType.CinderFire; |
| 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 || (this.m_minToolTier > 0 && (int)hit.m_itemWorldLevel < Game.m_worldLevel && ZoneSystem.instance.GetGlobalKey(GlobalKeys.WorldLevelLockedTools))) |
| if (!hit.CheckToolTier(this.m_minToolTier, true)) |
| { |
| { |
| 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(ZDOVars.s_health, num); |
| this.m_nview.GetZDO().Set(ZDOVars.s_health, num); |
| . | this.Shake(); |
| if (!flag && !flag2) |
| this.m_hitEffect.Create(hit.m_point, Quaternion.identity, base.transform, 1f, -1); |
| |
| Player closestPlayer = Player.GetClosestPlayer(base.transform.position, 10f); |
| |
| if (closestPlayer) |
| |
| { |
| { |
| . | closestPlayer.AddNoise(100f); |
| this.Shake(); |
| |
| } |
| |
| if (!flag2) |
| |
| { |
| |
| this.m_hitEffect.Create(hit.m_point, Quaternion.identity, base.transform, 1f, -1); |
| |
| Player closestPlayer = Player.GetClosestPlayer(base.transform.position, 10f); |
| |
| if (closestPlayer) |
| |
| { |
| |
| closestPlayer.AddNoise(100f); |
| |
| } |
| } |
| } |
| if (hit.GetAttacker() == Player.m_localPlayer) |
| if (hit.GetAttacker() == Player.m_localPlayer) |
| { |
| { |
| Game.instance.IncrementPlayerStat(PlayerStatType.TreeChops, 1f); |
| Game.instance.IncrementPlayerStat(PlayerStatType.TreeChops, 1f); |
| } |
| } |
| if (num <= 0f) |
| if (num <= 0f) |
| { |
| { |
| this.m_destroyedEffect.Create(base.transform.position, base.transform.rotation, base.transform, 1f, -1); |
| this.m_destroyedEffect.Create(base.transform.position, base.transform.rotation, base.transform, 1f, -1); |
| this.SpawnLog(hit.m_dir); |
| this.SpawnLog(hit.m_dir); |
| List<GameObject> dropList = this.m_dropWhenDestroyed.GetDropList(); |
| List<GameObject> dropList = this.m_dropWhenDestroyed.GetDropList(); |
| for (int i = 0; i < dropList.Count; i++) |
| for (int i = 0; i < dropList.Count; i++) |
| { |
| { |
| Vector2 vector = UnityEngine.Random.insideUnitCircle * 0.5f; |
| Vector2 vector = UnityEngine.Random.insideUnitCircle * 0.5f; |
| Vector3 vector2 = base.transform.position + Vector3.up * this.m_spawnYOffset + new Vector3(vector.x, this.m_spawnYStep * (float)i, vector.y); |
| Vector3 vector2 = base.transform.position + Vector3.up * this.m_spawnYOffset + new Vector3(vector.x, this.m_spawnYStep * (float)i, vector.y); |
| Quaternion quaternion = Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f); |
| Quaternion quaternion = Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f); |
| UnityEngine.Object.Instantiate<GameObject>(dropList[i], vector2, quaternion); |
| UnityEngine.Object.Instantiate<GameObject>(dropList[i], vector2, quaternion); |
| } |
| } |
| base.gameObject.SetActive(false); |
| base.gameObject.SetActive(false); |
| this.m_nview.Destroy(); |
| this.m_nview.Destroy(); |
| if (hit.GetAttacker() == Player.m_localPlayer) |
| if (hit.GetAttacker() == Player.m_localPlayer) |
| { |
| { |
| Game.instance.IncrementPlayerStat(PlayerStatType.Tree, 1f); |
| Game.instance.IncrementPlayerStat(PlayerStatType.Tree, 1f); |
| switch (this.m_minToolTier) |
| switch (this.m_minToolTier) |
| { |
| { |
| case 0: |
| case 0: |
| Game.instance.IncrementPlayerStat(PlayerStatType.TreeTier0, 1f); |
| Game.instance.IncrementPlayerStat(PlayerStatType.TreeTier0, 1f); |
| return; |
| return; |
| case 1: |
| case 1: |
| Game.instance.IncrementPlayerStat(PlayerStatType.TreeTier1, 1f); |
| Game.instance.IncrementPlayerStat(PlayerStatType.TreeTier1, 1f); |
| return; |
| return; |
| case 2: |
| case 2: |
| Game.instance.IncrementPlayerStat(PlayerStatType.TreeTier2, 1f); |
| Game.instance.IncrementPlayerStat(PlayerStatType.TreeTier2, 1f); |
| return; |
| return; |
| case 3: |
| case 3: |
| Game.instance.IncrementPlayerStat(PlayerStatType.TreeTier3, 1f); |
| Game.instance.IncrementPlayerStat(PlayerStatType.TreeTier3, 1f); |
| return; |
| return; |
| case 4: |
| case 4: |
| Game.instance.IncrementPlayerStat(PlayerStatType.TreeTier4, 1f); |
| Game.instance.IncrementPlayerStat(PlayerStatType.TreeTier4, 1f); |
| return; |
| return; |
| case 5: |
| case 5: |
| Game.instance.IncrementPlayerStat(PlayerStatType.TreeTier5, 1f); |
| Game.instance.IncrementPlayerStat(PlayerStatType.TreeTier5, 1f); |
| return; |
| return; |
| default: |
| default: |
| ZLog.LogWarning("No stat for tree tier: " + this.m_minToolTier.ToString()); |
| ZLog.LogWarning("No stat for tree tier: " + this.m_minToolTier.ToString()); |
| break; |
| break; |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private void Shake() |
| private void Shake() |
| { |
| { |
| . | this.m_nview.InvokeRPC(ZNetView.Everybody, "Shake", Array.Empty<object>()); |
| this.m_nview.InvokeRPC(ZNetView.Everybody, "RPC_Shake", Array.Empty<object>()); |
| } |
| } |
| |
| |
| private void RPC_Shake(long uid) |
| private void RPC_Shake(long uid) |
| { |
| { |
| base.StopCoroutine("ShakeAnimation"); |
| base.StopCoroutine("ShakeAnimation"); |
| base.StartCoroutine("ShakeAnimation"); |
| base.StartCoroutine("ShakeAnimation"); |
| } |
| } |
| |
| |
| private IEnumerator ShakeAnimation() |
| private IEnumerator ShakeAnimation() |
| { |
| { |
| this.m_trunk.gameObject.isStatic = false; |
| this.m_trunk.gameObject.isStatic = false; |
| float t = Time.time; |
| float t = Time.time; |
| while (Time.time - t < 1f) |
| while (Time.time - t < 1f) |
| { |
| { |
| float time = Time.time; |
| float time = Time.time; |
| float num = 1f - Mathf.Clamp01((time - t) / 1f); |
| float num = 1f - Mathf.Clamp01((time - t) / 1f); |
| float num2 = num * num * num * 1.5f; |
| float num2 = num * num * num * 1.5f; |
| Quaternion quaternion = Quaternion.Euler(Mathf.Sin(time * 40f) * num2, 0f, Mathf.Cos(time * 0.9f * 40f) * num2); |
| Quaternion quaternion = Quaternion.Euler(Mathf.Sin(time * 40f) * num2, 0f, Mathf.Cos(time * 0.9f * 40f) * num2); |
| this.m_trunk.transform.localRotation = quaternion; |
| this.m_trunk.transform.localRotation = quaternion; |
| yield return null; |
| yield return null; |
| } |
| } |
| this.m_trunk.transform.localRotation = Quaternion.identity; |
| this.m_trunk.transform.localRotation = Quaternion.identity; |
| this.m_trunk.gameObject.isStatic = true; |
| this.m_trunk.gameObject.isStatic = true; |
| yield break; |
| yield break; |
| } |
| } |
| |
| |
| private void SpawnLog(Vector3 hitDir) |
| private void SpawnLog(Vector3 hitDir) |
| { |
| { |
| GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.m_logPrefab, this.m_logSpawnPoint.position, this.m_logSpawnPoint.rotation); |
| GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.m_logPrefab, this.m_logSpawnPoint.position, this.m_logSpawnPoint.rotation); |
| gameObject.GetComponent<ZNetView>().SetLocalScale(base.transform.localScale); |
| gameObject.GetComponent<ZNetView>().SetLocalScale(base.transform.localScale); |
| Rigidbody component = gameObject.GetComponent<Rigidbody>(); |
| Rigidbody component = gameObject.GetComponent<Rigidbody>(); |
| component.mass *= base.transform.localScale.x; |
| component.mass *= base.transform.localScale.x; |
| component.ResetInertiaTensor(); |
| component.ResetInertiaTensor(); |
| component.AddForceAtPosition(hitDir * 0.2f, gameObject.transform.position + Vector3.up * 4f * base.transform.localScale.y, ForceMode.VelocityChange); |
| component.AddForceAtPosition(hitDir * 0.2f, gameObject.transform.position + Vector3.up * 4f * base.transform.localScale.y, ForceMode.VelocityChange); |
| if (this.m_stubPrefab) |
| if (this.m_stubPrefab) |
| { |
| { |
| UnityEngine.Object.Instantiate<GameObject>(this.m_stubPrefab, base.transform.position, base.transform.rotation).GetComponent<ZNetView>().SetLocalScale(base.transform.localScale); |
| UnityEngine.Object.Instantiate<GameObject>(this.m_stubPrefab, base.transform.position, base.transform.rotation).GetComponent<ZNetView>().SetLocalScale(base.transform.localScale); |
| } |
| } |
| } |
| } |
| |
| |
| private ZNetView m_nview; |
| private ZNetView m_nview; |
| |
| |
| public float m_health = 1f; |
| public float m_health = 1f; |
| |
| |
| public HitData.DamageModifiers m_damageModifiers; |
| public HitData.DamageModifiers m_damageModifiers; |
| |
| |
| public int m_minToolTier; |
| public int m_minToolTier; |
| |
| |
| 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 EffectList m_respawnEffect = new EffectList(); |
| public EffectList m_respawnEffect = new EffectList(); |
| |
| |
| public GameObject m_trunk; |
| public GameObject m_trunk; |
| |
| |
| public GameObject m_stubPrefab; |
| public GameObject m_stubPrefab; |
| |
| |
| public GameObject m_logPrefab; |
| public GameObject m_logPrefab; |
| |
| |
| public Transform m_logSpawnPoint; |
| public Transform m_logSpawnPoint; |
| |
| |
| [Header("Drops")] |
| [Header("Drops")] |
| public DropTable m_dropWhenDestroyed = new DropTable(); |
| public DropTable m_dropWhenDestroyed = new DropTable(); |
| |
| |
| public float m_spawnYOffset = 0.5f; |
| public float m_spawnYOffset = 0.5f; |
| |
| |
| public float m_spawnYStep = 0.3f; |
| public float m_spawnYStep = 0.3f; |
| } |
| } |
| |
| |