| using System; |
| using System; |
| using UnityEngine; |
| using UnityEngine; |
| |
| |
| public class TeleportWorld : MonoBehaviour, Hoverable, Interactable, TextReceiver |
| public class TeleportWorld : MonoBehaviour, Hoverable, Interactable, TextReceiver |
| { |
| { |
| 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; |
| } |
| } |
| this.m_hadTarget = this.HaveTarget(); |
| this.m_hadTarget = this.HaveTarget(); |
| . | this.m_nview.Register<string, string>("SetTag", new Action<long, string, string>(this.RPC_SetTag)); |
| this.m_nview.Register<string, string>("RPC_SetTag", new Action<long, string, string>(this.RPC_SetTag)); |
| |
| this.m_nview.Register<ZDOID>("RPC_SetConnected", new Action<long, ZDOID>(this.RPC_SetConnected)); |
| base.InvokeRepeating("UpdatePortal", 0.5f, 0.5f); |
| base.InvokeRepeating("UpdatePortal", 0.5f, 0.5f); |
| } |
| } |
| |
| |
| public string GetHoverText() |
| public string GetHoverText() |
| { |
| { |
| string text = this.GetText().RemoveRichTextTags(); |
| string text = this.GetText().RemoveRichTextTags(); |
| string text2 = (this.HaveTarget() ? "$piece_portal_connected" : "$piece_portal_unconnected"); |
| string text2 = (this.HaveTarget() ? "$piece_portal_connected" : "$piece_portal_unconnected"); |
| return Localization.instance.Localize(string.Concat(new string[] { "$piece_portal $piece_portal_tag:\"", text, "\" [", text2, "]\n[<color=yellow><b>$KEY_Use</b></color>] $piece_portal_settag" })); |
| return Localization.instance.Localize(string.Concat(new string[] { "$piece_portal $piece_portal_tag:\"", text, "\" [", text2, "]\n[<color=yellow><b>$KEY_Use</b></color>] $piece_portal_settag" })); |
| } |
| } |
| |
| |
| public string GetHoverName() |
| public string GetHoverName() |
| { |
| { |
| return "Teleport"; |
| return "Teleport"; |
| } |
| } |
| |
| |
| public bool Interact(Humanoid human, bool hold, bool alt) |
| public bool Interact(Humanoid human, bool hold, bool alt) |
| { |
| { |
| if (hold) |
| if (hold) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| if (!PrivateArea.CheckAccess(base.transform.position, 0f, true, false)) |
| if (!PrivateArea.CheckAccess(base.transform.position, 0f, true, false)) |
| { |
| { |
| human.Message(MessageHud.MessageType.Center, "$piece_noaccess", 0, null); |
| human.Message(MessageHud.MessageType.Center, "$piece_noaccess", 0, null); |
| return true; |
| return true; |
| } |
| } |
| TextInput.instance.RequestText(this, "$piece_portal_tag", 10); |
| TextInput.instance.RequestText(this, "$piece_portal_tag", 10); |
| return true; |
| return true; |
| } |
| } |
| |
| |
| public bool UseItem(Humanoid user, ItemDrop.ItemData item) |
| public bool UseItem(Humanoid user, ItemDrop.ItemData item) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| |
| |
| private void UpdatePortal() |
| private void UpdatePortal() |
| { |
| { |
| if (!this.m_nview.IsValid() || this.m_proximityRoot == null) |
| if (!this.m_nview.IsValid() || this.m_proximityRoot == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| Player closestPlayer = Player.GetClosestPlayer(this.m_proximityRoot.position, this.m_activationRange); |
| Player closestPlayer = Player.GetClosestPlayer(this.m_proximityRoot.position, this.m_activationRange); |
| bool flag = this.HaveTarget(); |
| bool flag = this.HaveTarget(); |
| if (flag && !this.m_hadTarget) |
| if (flag && !this.m_hadTarget) |
| { |
| { |
| this.m_connected.Create(base.transform.position, base.transform.rotation, null, 1f, -1); |
| this.m_connected.Create(base.transform.position, base.transform.rotation, null, 1f, -1); |
| } |
| } |
| this.m_hadTarget = flag; |
| this.m_hadTarget = flag; |
| . | this.m_target_found.SetActive(closestPlayer && closestPlayer.IsTeleportable() && this.TargetFound()); |
| bool flag2 = false; |
| |
| if (closestPlayer) |
| |
| { |
| |
| flag2 = closestPlayer.IsTeleportable() || this.m_allowAllItems; |
| |
| } |
| |
| this.m_target_found.SetActive(flag2 && this.TargetFound()); |
| } |
| } |
| |
| |
| private void Update() |
| private void Update() |
| { |
| { |
| this.m_colorAlpha = Mathf.MoveTowards(this.m_colorAlpha, this.m_hadTarget ? 1f : 0f, Time.deltaTime); |
| this.m_colorAlpha = Mathf.MoveTowards(this.m_colorAlpha, this.m_hadTarget ? 1f : 0f, Time.deltaTime); |
| this.m_model.material.SetColor("_EmissionColor", Color.Lerp(this.m_colorUnconnected, this.m_colorTargetfound, this.m_colorAlpha)); |
| this.m_model.material.SetColor("_EmissionColor", Color.Lerp(this.m_colorUnconnected, this.m_colorTargetfound, this.m_colorAlpha)); |
| } |
| } |
| |
| |
| public void Teleport(Player player) |
| public void Teleport(Player player) |
| { |
| { |
| if (!this.TargetFound()) |
| if (!this.TargetFound()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (ZoneSystem.instance.GetGlobalKey(GlobalKeys.NoPortals)) |
| if (ZoneSystem.instance.GetGlobalKey(GlobalKeys.NoPortals)) |
| { |
| { |
| player.Message(MessageHud.MessageType.Center, "$msg_blocked", 0, null); |
| player.Message(MessageHud.MessageType.Center, "$msg_blocked", 0, null); |
| return; |
| return; |
| } |
| } |
| float num; |
| float num; |
| if (ZoneSystem.instance.GetGlobalKey(GlobalKeys.NoBossPortals) && (RandEventSystem.instance.GetBossEvent() != null || (ZoneSystem.instance.GetGlobalKey(GlobalKeys.activeBosses, out num) && num > 0f))) |
| if (ZoneSystem.instance.GetGlobalKey(GlobalKeys.NoBossPortals) && (RandEventSystem.instance.GetBossEvent() != null || (ZoneSystem.instance.GetGlobalKey(GlobalKeys.activeBosses, out num) && num > 0f))) |
| { |
| { |
| player.Message(MessageHud.MessageType.Center, "$msg_blockedbyboss", 0, null); |
| player.Message(MessageHud.MessageType.Center, "$msg_blockedbyboss", 0, null); |
| return; |
| return; |
| } |
| } |
| . | if (!player.IsTeleportable()) |
| if (!this.m_allowAllItems && !player.IsTeleportable()) |
| { |
| { |
| player.Message(MessageHud.MessageType.Center, "$msg_noteleport", 0, null); |
| player.Message(MessageHud.MessageType.Center, "$msg_noteleport", 0, null); |
| return; |
| return; |
| } |
| } |
| ZLog.Log("Teleporting " + player.GetPlayerName()); |
| ZLog.Log("Teleporting " + player.GetPlayerName()); |
| ZDO zdo = ZDOMan.instance.GetZDO(this.m_nview.GetZDO().GetConnectionZDOID(ZDOExtraData.ConnectionType.Portal)); |
| ZDO zdo = ZDOMan.instance.GetZDO(this.m_nview.GetZDO().GetConnectionZDOID(ZDOExtraData.ConnectionType.Portal)); |
| if (zdo == null) |
| if (zdo == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| Vector3 position = zdo.GetPosition(); |
| Vector3 position = zdo.GetPosition(); |
| Quaternion rotation = zdo.GetRotation(); |
| Quaternion rotation = zdo.GetRotation(); |
| Vector3 vector = rotation * Vector3.forward; |
| Vector3 vector = rotation * Vector3.forward; |
| Vector3 vector2 = position + vector * this.m_exitDistance + Vector3.up; |
| Vector3 vector2 = position + vector * this.m_exitDistance + Vector3.up; |
| player.TeleportTo(vector2, rotation, true); |
| player.TeleportTo(vector2, rotation, true); |
| Game.instance.IncrementPlayerStat(PlayerStatType.PortalsUsed, 1f); |
| Game.instance.IncrementPlayerStat(PlayerStatType.PortalsUsed, 1f); |
| } |
| } |
| |
| |
| public string GetText() |
| public string GetText() |
| { |
| { |
| ZDO zdo = this.m_nview.GetZDO(); |
| ZDO zdo = this.m_nview.GetZDO(); |
| if (zdo == null) |
| if (zdo == null) |
| { |
| { |
| return ""; |
| return ""; |
| } |
| } |
| return CensorShittyWords.FilterUGC(zdo.GetString(ZDOVars.s_tag, ""), UGCType.Text, zdo.GetString(ZDOVars.s_tagauthor, ""), 0L); |
| return CensorShittyWords.FilterUGC(zdo.GetString(ZDOVars.s_tag, ""), UGCType.Text, zdo.GetString(ZDOVars.s_tagauthor, ""), 0L); |
| } |
| } |
| |
| |
| private void GetTagSignature(out string tagRaw, out string authorId) |
| private void GetTagSignature(out string tagRaw, out string authorId) |
| { |
| { |
| ZDO zdo = this.m_nview.GetZDO(); |
| ZDO zdo = this.m_nview.GetZDO(); |
| tagRaw = zdo.GetString(ZDOVars.s_tag, ""); |
| tagRaw = zdo.GetString(ZDOVars.s_tag, ""); |
| authorId = zdo.GetString(ZDOVars.s_tagauthor, ""); |
| authorId = zdo.GetString(ZDOVars.s_tagauthor, ""); |
| } |
| } |
| |
| |
| public void SetText(string text) |
| public void SetText(string text) |
| { |
| { |
| if (!this.m_nview.IsValid()) |
| if (!this.m_nview.IsValid()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| . | this.m_nview.InvokeRPC("SetTag", new object[] |
| this.m_nview.InvokeRPC("RPC_SetTag", new object[] |
| { |
| { |
| text, |
| text, |
| PrivilegeManager.GetNetworkUserId() |
| PrivilegeManager.GetNetworkUserId() |
| }); |
| }); |
| } |
| } |
| |
| |
| private void RPC_SetTag(long sender, string tag, string authorId) |
| private void RPC_SetTag(long sender, string tag, string authorId) |
| { |
| { |
| if (!this.m_nview.IsValid() || !this.m_nview.IsOwner()) |
| if (!this.m_nview.IsValid() || !this.m_nview.IsOwner()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| string text; |
| string text; |
| string text2; |
| string text2; |
| this.GetTagSignature(out text, out text2); |
| this.GetTagSignature(out text, out text2); |
| if (text == tag && text2 == authorId) |
| if (text == tag && text2 == authorId) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| ZDO zdo = this.m_nview.GetZDO(); |
| ZDO zdo = this.m_nview.GetZDO(); |
| . | ZDOID connectionZDOID = zdo.GetConnectionZDOID(ZDOExtraData.ConnectionType.Portal); |
| |
| zdo.UpdateConnection(ZDOExtraData.ConnectionType.Portal, ZDOID.None); |
| zdo.UpdateConnection(ZDOExtraData.ConnectionType.Portal, ZDOID.None); |
| . | ZDO zdo2 = ZDOMan.instance.GetZDO(connectionZDOID); |
| ZDOID connectionZDOID = zdo.GetConnectionZDOID(ZDOExtraData.ConnectionType.Portal); |
| if (zdo2 != null) |
| this.SetConnectedPortal(connectionZDOID); |
| { |
| |
| zdo2.UpdateConnection(ZDOExtraData.ConnectionType.Portal, ZDOID.None); |
| |
| } |
| |
| zdo.Set(ZDOVars.s_tag, tag); |
| zdo.Set(ZDOVars.s_tag, tag); |
| zdo.Set(ZDOVars.s_tagauthor, authorId); |
| zdo.Set(ZDOVars.s_tagauthor, authorId); |
| } |
| } |
| |
| |
| . | |
| private void SetConnectedPortal(ZDOID targetID) |
| |
| { |
| |
| ZDO zdo = ZDOMan.instance.GetZDO(targetID); |
| |
| if (zdo == null) |
| |
| { |
| |
| return; |
| |
| } |
| |
| long owner = zdo.GetOwner(); |
| |
| if (owner == 0L) |
| |
| { |
| |
| zdo.SetOwner(ZDOMan.GetSessionID()); |
| |
| zdo.SetConnection(ZDOExtraData.ConnectionType.Portal, ZDOID.None); |
| |
| return; |
| |
| } |
| |
| this.m_nview.InvokeRPC(owner, "RPC_SetConnected", new object[] { targetID }); |
| |
| } |
| |
| |
| |
| private void RPC_SetConnected(long sender, ZDOID portalID) |
| |
| { |
| |
| ZDO zdo = ZDOMan.instance.GetZDO(portalID); |
| |
| if (zdo == null || !zdo.IsOwner()) |
| |
| { |
| |
| return; |
| |
| } |
| |
| zdo.UpdateConnection(ZDOExtraData.ConnectionType.Portal, ZDOID.None); |
| |
| } |
| |
| |
| private bool HaveTarget() |
| private bool HaveTarget() |
| { |
| { |
| return !(this.m_nview == null) && this.m_nview.GetZDO() != null && this.m_nview.GetZDO().GetConnectionZDOID(ZDOExtraData.ConnectionType.Portal) != ZDOID.None; |
| return !(this.m_nview == null) && this.m_nview.GetZDO() != null && this.m_nview.GetZDO().GetConnectionZDOID(ZDOExtraData.ConnectionType.Portal) != ZDOID.None; |
| } |
| } |
| |
| |
| private bool TargetFound() |
| private bool TargetFound() |
| { |
| { |
| if (this.m_nview == null || this.m_nview.GetZDO() == null) |
| if (this.m_nview == null || this.m_nview.GetZDO() == null) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| ZDOID connectionZDOID = this.m_nview.GetZDO().GetConnectionZDOID(ZDOExtraData.ConnectionType.Portal); |
| ZDOID connectionZDOID = this.m_nview.GetZDO().GetConnectionZDOID(ZDOExtraData.ConnectionType.Portal); |
| if (connectionZDOID == ZDOID.None) |
| if (connectionZDOID == ZDOID.None) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| if (ZDOMan.instance.GetZDO(connectionZDOID) == null) |
| if (ZDOMan.instance.GetZDO(connectionZDOID) == null) |
| { |
| { |
| ZDOMan.instance.RequestZDO(connectionZDOID); |
| ZDOMan.instance.RequestZDO(connectionZDOID); |
| return false; |
| return false; |
| } |
| } |
| return true; |
| return true; |
| } |
| } |
| |
| |
| public float m_activationRange = 5f; |
| public float m_activationRange = 5f; |
| |
| |
| public float m_exitDistance = 1f; |
| public float m_exitDistance = 1f; |
| |
| |
| public Transform m_proximityRoot; |
| public Transform m_proximityRoot; |
| |
| |
| [ColorUsage(true, true)] |
| [ColorUsage(true, true)] |
| public Color m_colorUnconnected = Color.white; |
| public Color m_colorUnconnected = Color.white; |
| |
| |
| [ColorUsage(true, true)] |
| [ColorUsage(true, true)] |
| public Color m_colorTargetfound = Color.white; |
| public Color m_colorTargetfound = Color.white; |
| |
| |
| public EffectFade m_target_found; |
| public EffectFade m_target_found; |
| |
| |
| public MeshRenderer m_model; |
| public MeshRenderer m_model; |
| |
| |
| public EffectList m_connected; |
| public EffectList m_connected; |
| . | |
| |
| |
| public bool m_allowAllItems; |
| |
| |
| private ZNetView m_nview; |
| private ZNetView m_nview; |
| |
| |
| private bool m_hadTarget; |
| private bool m_hadTarget; |
| |
| |
| private float m_colorAlpha; |
| private float m_colorAlpha; |
| } |
| } |
| |
| |