| using System; |
| using System; |
| using System.Collections.Generic; |
| using System.Collections.Generic; |
| using UnityEngine; |
| using UnityEngine; |
| |
| |
| public class TreeLog : MonoBehaviour, IDestructible |
| public class TreeLog : MonoBehaviour, IDestructible |
| { |
| { |
| private void Awake() |
| private void Awake() |
| { |
| { |
| this.m_body = base.GetComponent<Rigidbody>(); |
| this.m_body = base.GetComponent<Rigidbody>(); |
| this.m_body.maxDepenetrationVelocity = 1f; |
| this.m_body.maxDepenetrationVelocity = 1f; |
| 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)); |
| if (this.m_nview.IsOwner()) |
| if (this.m_nview.IsOwner()) |
| { |
| { |
| float @float = this.m_nview.GetZDO().GetFloat(ZDOVars.s_health, -1f); |
| float @float = this.m_nview.GetZDO().GetFloat(ZDOVars.s_health, -1f); |
| if (@float == -1f) |
| if (@float == -1f) |
| { |
| { |
| this.m_nview.GetZDO().Set(ZDOVars.s_health, this.m_health + (float)Game.m_worldLevel * this.m_health * Game.instance.m_worldLevelMineHPMultiplier); |
| this.m_nview.GetZDO().Set(ZDOVars.s_health, this.m_health + (float)Game.m_worldLevel * this.m_health * Game.instance.m_worldLevelMineHPMultiplier); |
| } |
| } |
| else if (@float <= 0f) |
| else if (@float <= 0f) |
| { |
| { |
| this.m_nview.Destroy(); |
| this.m_nview.Destroy(); |
| } |
| } |
| } |
| } |
| base.Invoke("EnableDamage", 0.2f); |
| base.Invoke("EnableDamage", 0.2f); |
| } |
| } |
| |
| |
| private void EnableDamage() |
| private void EnableDamage() |
| { |
| { |
| this.m_firstFrame = false; |
| this.m_firstFrame = false; |
| } |
| } |
| |
| |
| public DestructibleType GetDestructibleType() |
| public DestructibleType GetDestructibleType() |
| { |
| { |
| return DestructibleType.Tree; |
| return DestructibleType.Tree; |
| } |
| } |
| |
| |
| public void Damage(HitData hit) |
| public void Damage(HitData hit) |
| { |
| { |
| if (this.m_firstFrame) |
| if (this.m_firstFrame) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (!this.m_nview.IsValid()) |
| if (!this.m_nview.IsValid()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| . | this.m_nview.InvokeRPC("Damage", new object[] { hit }); |
| this.m_nview.InvokeRPC("RPC_Damage", new object[] { hit }); |
| } |
| } |
| |
| |
| 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, 0f); |
| float num = this.m_nview.GetZDO().GetFloat(ZDOVars.s_health, 0f); |
| if (num <= 0f) |
| if (num <= 0f) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| . | |
| HitData hitData = hit.Clone(); |
| HitData.DamageModifier damageModifier; |
| HitData.DamageModifier damageModifier; |
| hit.ApplyResistance(this.m_damages, out damageModifier); |
| hit.ApplyResistance(this.m_damages, 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; |
| } |
| } |
| if (this.m_body) |
| if (this.m_body) |
| { |
| { |
| this.m_body.AddForceAtPosition(hit.m_dir * hit.m_pushForce * 2f, hit.m_point, ForceMode.Impulse); |
| this.m_body.AddForceAtPosition(hit.m_dir * hit.m_pushForce * 2f, hit.m_point, ForceMode.Impulse); |
| } |
| } |
| 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; |
| if (num < 0f) |
| if (num < 0f) |
| { |
| { |
| num = 0f; |
| num = 0f; |
| } |
| } |
| this.m_nview.GetZDO().Set(ZDOVars.s_health, num); |
| this.m_nview.GetZDO().Set(ZDOVars.s_health, num); |
| . | this.m_hitEffect.Create(hit.m_point, Quaternion.identity, base.transform, 1f, -1); |
| if (hit.m_hitType != HitData.HitType.CinderFire) |
| if (this.m_hitNoise > 0f) |
| |
| { |
| { |
| . | Player closestPlayer = Player.GetClosestPlayer(base.transform.position, 10f); |
| this.m_hitEffect.Create(hit.m_point, Quaternion.identity, base.transform, 1f, -1); |
| if (closestPlayer) |
| if (this.m_hitNoise > 0f) |
| { |
| { |
| . | closestPlayer.AddNoise(this.m_hitNoise); |
| Player closestPlayer = Player.GetClosestPlayer(base.transform.position, 10f); |
| |
| if (closestPlayer) |
| |
| { |
| |
| closestPlayer.AddNoise(this.m_hitNoise); |
| |
| } |
| } |
| } |
| } |
| } |
| if (hit.GetAttacker() == Player.m_localPlayer) |
| if (hit.GetAttacker() == Player.m_localPlayer) |
| { |
| { |
| Game.instance.IncrementPlayerStat(PlayerStatType.LogChops, 1f); |
| Game.instance.IncrementPlayerStat(PlayerStatType.LogChops, 1f); |
| } |
| } |
| if (num <= 0f) |
| if (num <= 0f) |
| { |
| { |
| . | this.Destroy(); |
| this.Destroy(hitData); |
| if (hit.GetAttacker() == Player.m_localPlayer) |
| if (hit.GetAttacker() == Player.m_localPlayer) |
| { |
| { |
| Game.instance.IncrementPlayerStat(PlayerStatType.Logs, 1f); |
| Game.instance.IncrementPlayerStat(PlayerStatType.Logs, 1f); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| . | private void Destroy() |
| private void Destroy(HitData hitData = null) |
| { |
| { |
| ZNetScene.instance.Destroy(base.gameObject); |
| ZNetScene.instance.Destroy(base.gameObject); |
| 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); |
| 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++) |
| { |
| { |
| Vector3 vector = base.transform.position + base.transform.up * UnityEngine.Random.Range(-this.m_spawnDistance, this.m_spawnDistance) + Vector3.up * 0.3f * (float)i; |
| Vector3 vector = base.transform.position + base.transform.up * UnityEngine.Random.Range(-this.m_spawnDistance, this.m_spawnDistance) + Vector3.up * 0.3f * (float)i; |
| Quaternion quaternion = Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f); |
| Quaternion quaternion = Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f); |
| . | ItemDrop.OnCreateNew(UnityEngine.Object.Instantiate<GameObject>(dropList[i], vector, quaternion)); |
| GameObject gameObject = dropList[i]; |
| |
| ItemDrop component = gameObject.GetComponent<ItemDrop>(); |
| |
| int num = 1; |
| |
| if (component) |
| |
| { |
| |
| gameObject = Game.instance.CheckDropConversion(hitData, component, gameObject, ref num); |
| |
| } |
| |
| for (int j = 0; j < num; j++) |
| |
| { |
| |
| ItemDrop.OnCreateNew(UnityEngine.Object.Instantiate<GameObject>(gameObject, vector, quaternion)); |
| |
| } |
| } |
| } |
| if (this.m_subLogPrefab != null) |
| if (this.m_subLogPrefab != null) |
| { |
| { |
| foreach (Transform transform in this.m_subLogPoints) |
| foreach (Transform transform in this.m_subLogPoints) |
| { |
| { |
| Quaternion quaternion2 = (this.m_useSubLogPointRotation ? transform.rotation : base.transform.rotation); |
| Quaternion quaternion2 = (this.m_useSubLogPointRotation ? transform.rotation : base.transform.rotation); |
| UnityEngine.Object.Instantiate<GameObject>(this.m_subLogPrefab, transform.position, quaternion2).GetComponent<ZNetView>().SetLocalScale(base.transform.localScale); |
| UnityEngine.Object.Instantiate<GameObject>(this.m_subLogPrefab, transform.position, quaternion2).GetComponent<ZNetView>().SetLocalScale(base.transform.localScale); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| public float m_health = 60f; |
| public float m_health = 60f; |
| |
| |
| public HitData.DamageModifiers m_damages; |
| public HitData.DamageModifiers m_damages; |
| |
| |
| 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 DropTable m_dropWhenDestroyed = new DropTable(); |
| public DropTable m_dropWhenDestroyed = new DropTable(); |
| |
| |
| public GameObject m_subLogPrefab; |
| public GameObject m_subLogPrefab; |
| |
| |
| public Transform[] m_subLogPoints = Array.Empty<Transform>(); |
| public Transform[] m_subLogPoints = Array.Empty<Transform>(); |
| |
| |
| public bool m_useSubLogPointRotation; |
| public bool m_useSubLogPointRotation; |
| |
| |
| public float m_spawnDistance = 2f; |
| public float m_spawnDistance = 2f; |
| |
| |
| public float m_hitNoise = 100f; |
| public float m_hitNoise = 100f; |
| |
| |
| private Rigidbody m_body; |
| private Rigidbody m_body; |
| |
| |
| private ZNetView m_nview; |
| private ZNetView m_nview; |
| |
| |
| private bool m_firstFrame = true; |
| private bool m_firstFrame = true; |
| } |
| } |
| |
| |