| using System; |
| using System; |
| using System.Collections.Generic; |
| using System.Collections.Generic; |
| using UnityEngine; |
| using UnityEngine; |
| |
| |
| public class Vagon : MonoBehaviour, Hoverable, Interactable |
| public class Vagon : MonoBehaviour, Hoverable, Interactable |
| { |
| { |
| private void Awake() |
| private void Awake() |
| { |
| { |
| this.m_nview = base.GetComponent<ZNetView>(); |
| this.m_nview = base.GetComponent<ZNetView>(); |
| if (this.m_nview.GetZDO() == null) |
| if (this.m_nview.GetZDO() == null) |
| { |
| { |
| base.enabled = false; |
| base.enabled = false; |
| return; |
| return; |
| } |
| } |
| Vagon.m_instances.Add(this); |
| Vagon.m_instances.Add(this); |
| Heightmap.ForceGenerateAll(); |
| Heightmap.ForceGenerateAll(); |
| this.m_body = base.GetComponent<Rigidbody>(); |
| this.m_body = base.GetComponent<Rigidbody>(); |
| this.m_bodies = base.GetComponentsInChildren<Rigidbody>(); |
| this.m_bodies = base.GetComponentsInChildren<Rigidbody>(); |
| this.m_lineRenderer = base.GetComponent<LineRenderer>(); |
| this.m_lineRenderer = base.GetComponent<LineRenderer>(); |
| Rigidbody[] bodies = this.m_bodies; |
| Rigidbody[] bodies = this.m_bodies; |
| for (int i = 0; i < bodies.Length; i++) |
| for (int i = 0; i < bodies.Length; i++) |
| { |
| { |
| bodies[i].maxDepenetrationVelocity = 2f; |
| bodies[i].maxDepenetrationVelocity = 2f; |
| } |
| } |
| . | this.m_nview.Register("RequestOwn", new Action<long>(this.RPC_RequestOwn)); |
| this.m_nview.Register("RPC_RequestOwn", new Action<long>(this.RPC_RequestOwn)); |
| this.m_nview.Register("RequestDenied", new Action<long>(this.RPC_RequestDenied)); |
| this.m_nview.Register("RPC_RequestDenied", new Action<long>(this.RPC_RequestDenied)); |
| base.InvokeRepeating("UpdateMass", 0f, 5f); |
| base.InvokeRepeating("UpdateMass", 0f, 5f); |
| base.InvokeRepeating("UpdateLoadVisualization", 0f, 3f); |
| base.InvokeRepeating("UpdateLoadVisualization", 0f, 3f); |
| } |
| } |
| |
| |
| private void OnDestroy() |
| private void OnDestroy() |
| { |
| { |
| Vagon.m_instances.Remove(this); |
| Vagon.m_instances.Remove(this); |
| } |
| } |
| |
| |
| public string GetHoverName() |
| public string GetHoverName() |
| { |
| { |
| return this.m_name; |
| return this.m_name; |
| } |
| } |
| |
| |
| public string GetHoverText() |
| public string GetHoverText() |
| { |
| { |
| return Localization.instance.Localize(this.m_name + "\n[<color=yellow><b>$KEY_Use</b></color>] $piece_use"); |
| return Localization.instance.Localize(this.m_name + "\n[<color=yellow><b>$KEY_Use</b></color>] $piece_use"); |
| } |
| } |
| |
| |
| public bool Interact(Humanoid character, bool hold, bool alt) |
| public bool Interact(Humanoid character, bool hold, bool alt) |
| { |
| { |
| if (hold) |
| if (hold) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| this.m_useRequester = character; |
| this.m_useRequester = character; |
| if (!this.m_nview.IsOwner()) |
| if (!this.m_nview.IsOwner()) |
| { |
| { |
| . | this.m_nview.InvokeRPC("RequestOwn", Array.Empty<object>()); |
| this.m_nview.InvokeRPC("RPC_RequestOwn", Array.Empty<object>()); |
| } |
| } |
| return false; |
| return false; |
| } |
| } |
| |
| |
| public void RPC_RequestOwn(long sender) |
| public void RPC_RequestOwn(long sender) |
| { |
| { |
| if (!this.m_nview.IsOwner()) |
| if (!this.m_nview.IsOwner()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (this.InUse()) |
| if (this.InUse()) |
| { |
| { |
| ZLog.Log("Requested use, but is already in use"); |
| ZLog.Log("Requested use, but is already in use"); |
| . | this.m_nview.InvokeRPC(sender, "RequestDenied", Array.Empty<object>()); |
| this.m_nview.InvokeRPC(sender, "RPC_RequestDenied", Array.Empty<object>()); |
| return; |
| return; |
| } |
| } |
| this.m_nview.GetZDO().SetOwner(sender); |
| this.m_nview.GetZDO().SetOwner(sender); |
| } |
| } |
| |
| |
| private void RPC_RequestDenied(long sender) |
| private void RPC_RequestDenied(long sender) |
| { |
| { |
| ZLog.Log("Got request denied"); |
| ZLog.Log("Got request denied"); |
| if (this.m_useRequester) |
| if (this.m_useRequester) |
| { |
| { |
| this.m_useRequester.Message(MessageHud.MessageType.Center, this.m_name + " is in use by someone else", 0, null); |
| this.m_useRequester.Message(MessageHud.MessageType.Center, this.m_name + " is in use by someone else", 0, null); |
| this.m_useRequester = null; |
| this.m_useRequester = null; |
| } |
| } |
| } |
| } |
| |
| |
| private void FixedUpdate() |
| private void FixedUpdate() |
| { |
| { |
| if (!this.m_nview.IsValid()) |
| if (!this.m_nview.IsValid()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.UpdateAudio(Time.fixedDeltaTime); |
| this.UpdateAudio(Time.fixedDeltaTime); |
| if (this.m_nview.IsOwner()) |
| if (this.m_nview.IsOwner()) |
| { |
| { |
| if (this.m_useRequester) |
| if (this.m_useRequester) |
| { |
| { |
| if (this.IsAttached()) |
| if (this.IsAttached()) |
| { |
| { |
| this.Detach(); |
| this.Detach(); |
| } |
| } |
| else if (this.CanAttach(this.m_useRequester.gameObject)) |
| else if (this.CanAttach(this.m_useRequester.gameObject)) |
| { |
| { |
| this.AttachTo(this.m_useRequester.gameObject); |
| this.AttachTo(this.m_useRequester.gameObject); |
| } |
| } |
| else |
| else |
| { |
| { |
| this.m_useRequester.Message(MessageHud.MessageType.Center, "$msg_cart_incorrectposition", 0, null); |
| this.m_useRequester.Message(MessageHud.MessageType.Center, "$msg_cart_incorrectposition", 0, null); |
| } |
| } |
| this.m_useRequester = null; |
| this.m_useRequester = null; |
| } |
| } |
| . | if (this.IsAttached() && !this.CanAttach(this.m_attachJoin.connectedBody.gameObject)) |
| if (this.IsAttached() && (!this.m_attachJoin || !this.CanAttach(this.m_attachJoin.connectedBody.gameObject))) |
| { |
| { |
| this.Detach(); |
| this.Detach(); |
| return; |
| return; |
| } |
| } |
| } |
| } |
| else if (this.IsAttached()) |
| else if (this.IsAttached()) |
| { |
| { |
| this.Detach(); |
| this.Detach(); |
| } |
| } |
| } |
| } |
| |
| |
| private void LateUpdate() |
| private void LateUpdate() |
| { |
| { |
| . | if (this.IsAttached()) |
| if (this.IsAttached() && this.m_attachJoin != null) |
| { |
| { |
| this.m_lineRenderer.enabled = true; |
| this.m_lineRenderer.enabled = true; |
| this.m_lineRenderer.SetPosition(0, this.m_lineAttachPoints0.position); |
| this.m_lineRenderer.SetPosition(0, this.m_lineAttachPoints0.position); |
| this.m_lineRenderer.SetPosition(1, this.m_attachJoin.connectedBody.transform.position + this.m_lineAttachOffset); |
| this.m_lineRenderer.SetPosition(1, this.m_attachJoin.connectedBody.transform.position + this.m_lineAttachOffset); |
| this.m_lineRenderer.SetPosition(2, this.m_lineAttachPoints1.position); |
| this.m_lineRenderer.SetPosition(2, this.m_lineAttachPoints1.position); |
| return; |
| return; |
| } |
| } |
| this.m_lineRenderer.enabled = false; |
| this.m_lineRenderer.enabled = false; |
| } |
| } |
| |
| |
| public bool IsAttached(Character character) |
| public bool IsAttached(Character character) |
| { |
| { |
| return this.m_attachJoin && this.m_attachJoin.connectedBody.gameObject == character.gameObject; |
| return this.m_attachJoin && this.m_attachJoin.connectedBody.gameObject == character.gameObject; |
| } |
| } |
| |
| |
| public bool InUse() |
| public bool InUse() |
| { |
| { |
| return (this.m_container && this.m_container.IsInUse()) || this.IsAttached(); |
| return (this.m_container && this.m_container.IsInUse()) || this.IsAttached(); |
| } |
| } |
| |
| |
| . | private bool IsAttached() |
| public bool IsAttached() |
| { |
| { |
| . | return this.m_attachJoin != null; |
| return this.m_attachJoin != null || (this.m_nview.IsValid() && this.m_nview.GetZDO().GetBool(ZDOVars.s_attachJointHash, false)); |
| } |
| } |
| |
| |
| private bool CanAttach(GameObject go) |
| private bool CanAttach(GameObject go) |
| { |
| { |
| if (base.transform.up.y < 0.1f) |
| if (base.transform.up.y < 0.1f) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| Humanoid component = go.GetComponent<Humanoid>(); |
| Humanoid component = go.GetComponent<Humanoid>(); |
| return (!component || (!component.InDodge() && !component.IsTeleporting())) && Vector3.Distance(go.transform.position + this.m_attachOffset, this.m_attachPoint.position) < this.m_detachDistance; |
| return (!component || (!component.InDodge() && !component.IsTeleporting())) && Vector3.Distance(go.transform.position + this.m_attachOffset, this.m_attachPoint.position) < this.m_detachDistance; |
| } |
| } |
| |
| |
| private void AttachTo(GameObject go) |
| private void AttachTo(GameObject go) |
| { |
| { |
| Vagon.DetachAll(); |
| Vagon.DetachAll(); |
| this.m_attachJoin = base.gameObject.AddComponent<ConfigurableJoint>(); |
| this.m_attachJoin = base.gameObject.AddComponent<ConfigurableJoint>(); |
| this.m_attachJoin.autoConfigureConnectedAnchor = false; |
| this.m_attachJoin.autoConfigureConnectedAnchor = false; |
| this.m_attachJoin.anchor = this.m_attachPoint.localPosition; |
| this.m_attachJoin.anchor = this.m_attachPoint.localPosition; |
| this.m_attachJoin.connectedAnchor = this.m_attachOffset; |
| this.m_attachJoin.connectedAnchor = this.m_attachOffset; |
| this.m_attachJoin.breakForce = this.m_breakForce; |
| this.m_attachJoin.breakForce = this.m_breakForce; |
| this.m_attachJoin.xMotion = ConfigurableJointMotion.Limited; |
| this.m_attachJoin.xMotion = ConfigurableJointMotion.Limited; |
| this.m_attachJoin.yMotion = ConfigurableJointMotion.Limited; |
| this.m_attachJoin.yMotion = ConfigurableJointMotion.Limited; |
| this.m_attachJoin.zMotion = ConfigurableJointMotion.Limited; |
| this.m_attachJoin.zMotion = ConfigurableJointMotion.Limited; |
| SoftJointLimit softJointLimit = default(SoftJointLimit); |
| SoftJointLimit softJointLimit = default(SoftJointLimit); |
| softJointLimit.limit = 0.001f; |
| softJointLimit.limit = 0.001f; |
| this.m_attachJoin.linearLimit = softJointLimit; |
| this.m_attachJoin.linearLimit = softJointLimit; |
| SoftJointLimitSpring softJointLimitSpring = default(SoftJointLimitSpring); |
| SoftJointLimitSpring softJointLimitSpring = default(SoftJointLimitSpring); |
| softJointLimitSpring.spring = this.m_spring; |
| softJointLimitSpring.spring = this.m_spring; |
| softJointLimitSpring.damper = this.m_springDamping; |
| softJointLimitSpring.damper = this.m_springDamping; |
| this.m_attachJoin.linearLimitSpring = softJointLimitSpring; |
| this.m_attachJoin.linearLimitSpring = softJointLimitSpring; |
| this.m_attachJoin.zMotion = ConfigurableJointMotion.Locked; |
| this.m_attachJoin.zMotion = ConfigurableJointMotion.Locked; |
| this.m_attachJoin.connectedBody = go.GetComponent<Rigidbody>(); |
| this.m_attachJoin.connectedBody = go.GetComponent<Rigidbody>(); |
| . | |
| this.m_attachedObject = go; |
| |
| if (this.m_nview.IsValid()) |
| |
| { |
| |
| this.m_nview.GetZDO().Set(ZDOVars.s_attachJointHash, true); |
| |
| } |
| |
| if (this.m_playerExtraPullMass != 0f) |
| |
| { |
| |
| Character component = this.m_attachedObject.GetComponent<Character>(); |
| |
| if (component != null) |
| |
| { |
| |
| component.SetExtraMass(this.m_playerExtraPullMass); |
| |
| } |
| |
| } |
| } |
| } |
| |
| |
| private static void DetachAll() |
| private static void DetachAll() |
| { |
| { |
| foreach (Vagon vagon in Vagon.m_instances) |
| foreach (Vagon vagon in Vagon.m_instances) |
| { |
| { |
| vagon.Detach(); |
| vagon.Detach(); |
| } |
| } |
| } |
| } |
| |
| |
| private void Detach() |
| private void Detach() |
| { |
| { |
| if (this.m_attachJoin) |
| if (this.m_attachJoin) |
| { |
| { |
| UnityEngine.Object.Destroy(this.m_attachJoin); |
| UnityEngine.Object.Destroy(this.m_attachJoin); |
| . | this.m_attachJoin = null; |
| |
| this.m_body.WakeUp(); |
| |
| this.m_body.AddForce(0f, 1f, 0f); |
| |
| } |
| } |
| . | |
| this.m_attachJoin = null; |
| |
| if (this.m_nview.IsValid() && this.m_nview.IsOwner()) |
| |
| { |
| |
| this.m_nview.GetZDO().Set(ZDOVars.s_attachJointHash, false); |
| |
| } |
| |
| this.m_body.WakeUp(); |
| |
| this.m_body.AddForce(0f, 1f, 0f); |
| |
| if (this.m_playerExtraPullMass != 0f && this.m_attachedObject) |
| |
| { |
| |
| Character component = this.m_attachedObject.GetComponent<Character>(); |
| |
| if (component != null) |
| |
| { |
| |
| component.SetExtraMass(0f); |
| |
| } |
| |
| } |
| |
| this.m_attachedObject = null; |
| } |
| } |
| |
| |
| public bool UseItem(Humanoid user, ItemDrop.ItemData item) |
| public bool UseItem(Humanoid user, ItemDrop.ItemData item) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| |
| |
| private void UpdateMass() |
| private void UpdateMass() |
| { |
| { |
| if (!this.m_nview.IsOwner()) |
| if (!this.m_nview.IsOwner()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (this.m_container == null) |
| if (this.m_container == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| float totalWeight = this.m_container.GetInventory().GetTotalWeight(); |
| float totalWeight = this.m_container.GetInventory().GetTotalWeight(); |
| float num = this.m_baseMass + totalWeight * this.m_itemWeightMassFactor; |
| float num = this.m_baseMass + totalWeight * this.m_itemWeightMassFactor; |
| this.SetMass(num); |
| this.SetMass(num); |
| } |
| } |
| |
| |
| private void SetMass(float mass) |
| private void SetMass(float mass) |
| { |
| { |
| float num = mass / (float)this.m_bodies.Length; |
| float num = mass / (float)this.m_bodies.Length; |
| Rigidbody[] bodies = this.m_bodies; |
| Rigidbody[] bodies = this.m_bodies; |
| for (int i = 0; i < bodies.Length; i++) |
| for (int i = 0; i < bodies.Length; i++) |
| { |
| { |
| bodies[i].mass = num; |
| bodies[i].mass = num; |
| } |
| } |
| } |
| } |
| |
| |
| private void UpdateLoadVisualization() |
| private void UpdateLoadVisualization() |
| { |
| { |
| if (this.m_container == null) |
| if (this.m_container == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| float num = this.m_container.GetInventory().SlotsUsedPercentage(); |
| float num = this.m_container.GetInventory().SlotsUsedPercentage(); |
| foreach (Vagon.LoadData loadData in this.m_loadVis) |
| foreach (Vagon.LoadData loadData in this.m_loadVis) |
| { |
| { |
| loadData.m_gameobject.SetActive(num >= loadData.m_minPercentage); |
| loadData.m_gameobject.SetActive(num >= loadData.m_minPercentage); |
| } |
| } |
| } |
| } |
| |
| |
| private void UpdateAudio(float dt) |
| private void UpdateAudio(float dt) |
| { |
| { |
| float num = 0f; |
| float num = 0f; |
| foreach (Rigidbody rigidbody in this.m_wheels) |
| foreach (Rigidbody rigidbody in this.m_wheels) |
| { |
| { |
| num += rigidbody.angularVelocity.magnitude; |
| num += rigidbody.angularVelocity.magnitude; |
| } |
| } |
| num /= (float)this.m_wheels.Length; |
| num /= (float)this.m_wheels.Length; |
| float num2 = Mathf.Lerp(this.m_minPitch, this.m_maxPitch, Mathf.Clamp01(num / this.m_maxPitchVel)); |
| float num2 = Mathf.Lerp(this.m_minPitch, this.m_maxPitch, Mathf.Clamp01(num / this.m_maxPitchVel)); |
| float num3 = this.m_maxVol * Mathf.Clamp01(num / this.m_maxVolVel); |
| float num3 = this.m_maxVol * Mathf.Clamp01(num / this.m_maxVolVel); |
| . | foreach (AudioSource audioSource in this.m_wheelLoops) |
| foreach (ZSFX zsfx in this.m_wheelLoops) |
| { |
| { |
| . | audioSource.volume = Mathf.MoveTowards(audioSource.volume, num3, this.m_audioChangeSpeed * dt); |
| zsfx.SetVolumeModifier(Mathf.MoveTowards(zsfx.GetVolumeModifier(), num3, this.m_audioChangeSpeed * dt)); |
| audioSource.pitch = Mathf.MoveTowards(audioSource.pitch, num2, this.m_audioChangeSpeed * dt); |
| zsfx.SetPitchModifier(Mathf.MoveTowards(zsfx.GetPitchModifier(), num2, this.m_audioChangeSpeed * dt)); |
| } |
| } |
| } |
| } |
| |
| |
| private static List<Vagon> m_instances = new List<Vagon>(); |
| private static List<Vagon> m_instances = new List<Vagon>(); |
| |
| |
| public Transform m_attachPoint; |
| public Transform m_attachPoint; |
| |
| |
| public string m_name = "Wagon"; |
| public string m_name = "Wagon"; |
| |
| |
| public float m_detachDistance = 2f; |
| public float m_detachDistance = 2f; |
| |
| |
| public Vector3 m_attachOffset = new Vector3(0f, 0.8f, 0f); |
| public Vector3 m_attachOffset = new Vector3(0f, 0.8f, 0f); |
| |
| |
| public Container m_container; |
| public Container m_container; |
| |
| |
| public Transform m_lineAttachPoints0; |
| public Transform m_lineAttachPoints0; |
| |
| |
| public Transform m_lineAttachPoints1; |
| public Transform m_lineAttachPoints1; |
| |
| |
| public Vector3 m_lineAttachOffset = new Vector3(0f, 1f, 0f); |
| public Vector3 m_lineAttachOffset = new Vector3(0f, 1f, 0f); |
| |
| |
| public float m_breakForce = 10000f; |
| public float m_breakForce = 10000f; |
| |
| |
| public float m_spring = 5000f; |
| public float m_spring = 5000f; |
| |
| |
| public float m_springDamping = 1000f; |
| public float m_springDamping = 1000f; |
| |
| |
| public float m_baseMass = 20f; |
| public float m_baseMass = 20f; |
| |
| |
| public float m_itemWeightMassFactor = 1f; |
| public float m_itemWeightMassFactor = 1f; |
| |
| |
| . | public AudioSource[] m_wheelLoops; |
| public float m_playerExtraPullMass; |
| |
| |
| |
| public ZSFX[] m_wheelLoops; |
| |
| |
| public float m_minPitch = 1f; |
| public float m_minPitch = 1f; |
| |
| |
| public float m_maxPitch = 1.5f; |
| public float m_maxPitch = 1.5f; |
| |
| |
| public float m_maxPitchVel = 10f; |
| public float m_maxPitchVel = 10f; |
| |
| |
| public float m_maxVol = 1f; |
| public float m_maxVol = 1f; |
| |
| |
| public float m_maxVolVel = 10f; |
| public float m_maxVolVel = 10f; |
| |
| |
| public float m_audioChangeSpeed = 2f; |
| public float m_audioChangeSpeed = 2f; |
| |
| |
| public Rigidbody[] m_wheels = new Rigidbody[0]; |
| public Rigidbody[] m_wheels = new Rigidbody[0]; |
| |
| |
| public List<Vagon.LoadData> m_loadVis = new List<Vagon.LoadData>(); |
| public List<Vagon.LoadData> m_loadVis = new List<Vagon.LoadData>(); |
| |
| |
| private ZNetView m_nview; |
| private ZNetView m_nview; |
| |
| |
| private ConfigurableJoint m_attachJoin; |
| private ConfigurableJoint m_attachJoin; |
| . | |
| |
| |
| private GameObject m_attachedObject; |
| |
| |
| private Rigidbody m_body; |
| private Rigidbody m_body; |
| |
| |
| private LineRenderer m_lineRenderer; |
| private LineRenderer m_lineRenderer; |
| |
| |
| private Rigidbody[] m_bodies; |
| private Rigidbody[] m_bodies; |
| |
| |
| private Humanoid m_useRequester; |
| private Humanoid m_useRequester; |
| |
| |
| [Serializable] |
| [Serializable] |
| public class LoadData |
| public class LoadData |
| { |
| { |
| public GameObject m_gameobject; |
| public GameObject m_gameobject; |
| |
| |
| public float m_minPercentage; |
| public float m_minPercentage; |
| } |
| } |
| } |
| } |
| |
| |