| using System; |
| using System; |
| using UnityEngine; |
| using UnityEngine; |
| |
| |
| public class Leviathan : MonoBehaviour |
| public class Leviathan : MonoBehaviour |
| { |
| { |
| private void Awake() |
| private void Awake() |
| { |
| { |
| this.m_body = base.GetComponent<Rigidbody>(); |
| this.m_body = base.GetComponent<Rigidbody>(); |
| this.m_nview = base.GetComponent<ZNetView>(); |
| this.m_nview = base.GetComponent<ZNetView>(); |
| this.m_zanimator = base.GetComponent<ZSyncAnimation>(); |
| this.m_zanimator = base.GetComponent<ZSyncAnimation>(); |
| this.m_animator = base.GetComponentInChildren<Animator>(); |
| this.m_animator = base.GetComponentInChildren<Animator>(); |
| if (base.GetComponent<MineRock>()) |
| if (base.GetComponent<MineRock>()) |
| { |
| { |
| MineRock mineRock = this.m_mineRock; |
| MineRock mineRock = this.m_mineRock; |
| mineRock.m_onHit = (Action)Delegate.Combine(mineRock.m_onHit, new Action(this.OnHit)); |
| mineRock.m_onHit = (Action)Delegate.Combine(mineRock.m_onHit, new Action(this.OnHit)); |
| } |
| } |
| . | |
| if (this.m_nview.IsValid() && this.m_nview.IsOwner() && this.m_nview.GetZDO().GetBool(ZDOVars.s_dead, false)) |
| |
| { |
| |
| this.m_nview.Destroy(); |
| |
| } |
| } |
| } |
| |
| |
| private void FixedUpdate() |
| private void FixedUpdate() |
| { |
| { |
| if (!this.m_nview.IsValid() || !this.m_nview.IsOwner()) |
| if (!this.m_nview.IsValid() || !this.m_nview.IsOwner()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| float liquidLevel = Floating.GetLiquidLevel(base.transform.position, this.m_waveScale, LiquidType.All); |
| float liquidLevel = Floating.GetLiquidLevel(base.transform.position, this.m_waveScale, LiquidType.All); |
| . | if (liquidLevel > -100f) |
| if (this.m_alignToWaterLevel) |
| { |
| { |
| . | Vector3 position = this.m_body.position; |
| if (liquidLevel > -100f) |
| float num = Mathf.Clamp((liquidLevel - (position.y + this.m_floatOffset)) * this.m_movementSpeed * Time.fixedDeltaTime, -this.m_maxSpeed, this.m_maxSpeed); |
| { |
| position.y += num; |
| Vector3 position = this.m_body.position; |
| this.m_body.MovePosition(position); |
| float num = Mathf.Clamp((liquidLevel - (position.y + this.m_floatOffset)) * this.m_movementSpeed * Time.fixedDeltaTime, -this.m_maxSpeed, this.m_maxSpeed); |
| } |
| position.y += num; |
| else |
| this.m_body.MovePosition(position); |
| { |
| } |
| Vector3 position2 = this.m_body.position; |
| else |
| position2.y = 0f; |
| { |
| this.m_body.MovePosition(Vector3.MoveTowards(this.m_body.position, position2, Time.deltaTime)); |
| Vector3 position2 = this.m_body.position; |
| |
| position2.y = 0f; |
| |
| this.m_body.MovePosition(Vector3.MoveTowards(this.m_body.position, position2, Time.deltaTime)); |
| |
| } |
| } |
| } |
| if (this.m_animator.GetCurrentAnimatorStateInfo(0).IsTag("submerged")) |
| if (this.m_animator.GetCurrentAnimatorStateInfo(0).IsTag("submerged")) |
| { |
| { |
| this.m_nview.Destroy(); |
| this.m_nview.Destroy(); |
| } |
| } |
| } |
| } |
| |
| |
| private void OnHit() |
| private void OnHit() |
| { |
| { |
| if (UnityEngine.Random.value <= this.m_hitReactionChance) |
| if (UnityEngine.Random.value <= this.m_hitReactionChance) |
| { |
| { |
| if (this.m_left) |
| if (this.m_left) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.m_reactionEffects.Create(base.transform.position, base.transform.rotation, null, 1f, -1); |
| this.m_reactionEffects.Create(base.transform.position, base.transform.rotation, null, 1f, -1); |
| this.m_zanimator.SetTrigger("shake"); |
| this.m_zanimator.SetTrigger("shake"); |
| base.Invoke("Leave", (float)this.m_leaveDelay); |
| base.Invoke("Leave", (float)this.m_leaveDelay); |
| } |
| } |
| } |
| } |
| |
| |
| private void Leave() |
| private void Leave() |
| { |
| { |
| if (!this.m_nview.IsValid() || !this.m_nview.IsOwner()) |
| if (!this.m_nview.IsValid() || !this.m_nview.IsOwner()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (this.m_left) |
| if (this.m_left) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.m_left = true; |
| this.m_left = true; |
| this.m_leaveEffects.Create(base.transform.position, base.transform.rotation, null, 1f, -1); |
| this.m_leaveEffects.Create(base.transform.position, base.transform.rotation, null, 1f, -1); |
| this.m_zanimator.SetTrigger("dive"); |
| this.m_zanimator.SetTrigger("dive"); |
| . | |
| this.m_nview.GetZDO().Set(ZDOVars.s_dead, true); |
| |
| } |
| |
| |
| |
| private void OnDestroy() |
| |
| { |
| |
| if (this.m_left && this.m_nview.IsValid() && !this.m_nview.IsOwner() && Player.GetPlayersInRangeXZ(base.transform.position, 40f) == 0) |
| |
| { |
| |
| this.m_nview.Destroy(); |
| |
| } |
| } |
| } |
| |
| |
| public float m_waveScale = 0.5f; |
| public float m_waveScale = 0.5f; |
| |
| |
| public float m_floatOffset; |
| public float m_floatOffset; |
| |
| |
| public float m_movementSpeed = 0.1f; |
| public float m_movementSpeed = 0.1f; |
| |
| |
| public float m_maxSpeed = 1f; |
| public float m_maxSpeed = 1f; |
| |
| |
| public MineRock m_mineRock; |
| public MineRock m_mineRock; |
| |
| |
| public float m_hitReactionChance = 0.25f; |
| public float m_hitReactionChance = 0.25f; |
| |
| |
| public int m_leaveDelay = 5; |
| public int m_leaveDelay = 5; |
| |
| |
| public EffectList m_reactionEffects = new EffectList(); |
| public EffectList m_reactionEffects = new EffectList(); |
| |
| |
| public EffectList m_leaveEffects = new EffectList(); |
| public EffectList m_leaveEffects = new EffectList(); |
| . | |
| |
| |
| public bool m_alignToWaterLevel = true; |
| |
| |
| private Rigidbody m_body; |
| private Rigidbody m_body; |
| |
| |
| private ZNetView m_nview; |
| private ZNetView m_nview; |
| |
| |
| private ZSyncAnimation m_zanimator; |
| private ZSyncAnimation m_zanimator; |
| |
| |
| private Animator m_animator; |
| private Animator m_animator; |
| |
| |
| private bool m_left; |
| private bool m_left; |
| } |
| } |
| |
| |