Exemplo n.º 1
0
        private bool SpawnEphemeralPortal(BasePlayer player, BaseEntity entity, float time = 10f)
        {
            if (player == null)
            {
                return(false);
            }
            if (entity == null)
            {
                return(false);
            }
            if (time < 5f)
            {
                return(false);
            }
#if DEBUG
            Puts($"Trying to spin up a temporary portal for {player.displayName} to {entity.ShortPrefabName}");
#endif
            var portal = new PortalInfo();
            portal.ID = $"{player.displayName}:TEMP";

            Vector3 primary = player.transform.position + player.transform.forward * 2f;
            if (!AboveFloor(primary))
            {
                primary.y = TerrainMeta.HeightMap.GetHeight(player.transform.position) + 0.1f;
            }
            portal.Primary.Location.Vector3 = primary;

            Vector3 secondary = entity.transform.position + entity.transform.forward * 2f;
            bool    ok        = false;
            while (!ok)
            {
                ok           = !BadLocation(secondary);
                secondary.x -= 0.5f;
                secondary.z += 0.5f;
#if DEBUG
                Puts($"Seeking new location: {secondary.ToString()}");
#endif
            }
            portal.Secondary.Location.Vector3 = secondary;
            if (!AboveFloor(secondary))
            {
                secondary.y = TerrainMeta.HeightMap.GetHeight(entity.transform.position) + 0.1f;
            }

            portal.OneWay        = true;
            portal.DeploySpinner = configData.deploySpinner;
            portals.Add(portal);
            portal.ReCreate();
//            portal.Primary.GameObject.GetComponent<PortalEntity>().ExitEffects(player);
            timer.Once(time, () => KillEphemeralPortal(portal));
            return(true);
        }
Exemplo n.º 2
0
        private void cmdPortal(BasePlayer player, string cmd, string[] args)
        {
            if (!HasPerm(player.userID, "admin"))
            {
                return;
            }

            if (args.Length == 0)
            {
                SendReply(player, "Syntax: /portal <entrance|exit|remove|list> <ID>");
                return;
            }

            string            ID;
            PortalInfo        portal;
            List <PortalInfo> savedPortals;

            switch (args[0])
            {
            case "copy":
                savedPortals = new List <PortalInfo>();
                foreach (var portalSave in portals)
                {
                    var name = CuiHelper.GetGuid();
                    var p    = new PortalInfo(name);
                    p.Entrance.Location.Vector3 = player.transform.position - portalSave.Entrance.Location.Vector3;
                    p.Exit.Location.Vector3     = player.transform.position - portalSave.Exit.Location.Vector3;
                    savedPortals.Add(p);
                }
                SaveData(savedPortals, "Portals_COPY");
                break;

            case "paste":
                LoadData(out savedPortals, "Portals_COPY");
                foreach (var portalSave in savedPortals)
                {
                    var name = CuiHelper.GetGuid();
                    var p    = new PortalInfo(name);
                    portals.Add(p);
                    p.Entrance.Location.Vector3 = player.transform.position - portalSave.Entrance.Location.Vector3;
                    p.ReCreate();
                    p.Exit.Location.Vector3 = player.transform.position - portalSave.Exit.Location.Vector3;
                    p.ReCreate();
                }
                SaveData(savedPortals, "Portals_COPY");
                break;

            case "cancelpaste":
                LoadData(out savedPortals, "Portals_COPY");
                for (int i = 0; i < savedPortals.Count; i++)
                {
                    var index = portals.Count - 1;
                    portals[index].Remove();
                    portals.RemoveAt(index);
                }
                break;

            case "entrance":

                if (args.Length != 2)
                {
                    SendReply(player, "Syntax: /portal entrance <ID>");
                    return;
                }

                ID = args[1];

                portal = PortalInfo.Find(ID);

                if (portal == null)
                {
                    portal = new PortalInfo(ID);
                    portals.Add(portal);
                }

                portal.Entrance.Location.Vector3 = player.transform.position;
                portal.ReCreate();

                SaveData(portals);

                SendReply(player, GetMsg("Portal Entrance Set").Replace("{ID}", args[1]));

                break;

            case "exit":

                if (args.Length != 2)
                {
                    SendReply(player, "Syntax: /portal exit <ID>");
                    return;
                }

                ID = args[1];

                portal = PortalInfo.Find(ID);

                if (portal == null)
                {
                    portal = new PortalInfo(ID);
                    portals.Add(portal);
                }

                portal.Exit.Location.Vector3 = player.transform.position;
                portal.ReCreate();

                SaveData(portals);

                SendReply(player, GetMsg("Portal Exit Set").Replace("{ID}", args[1]));

                break;

            case "remove":

                if (args.Length != 2)
                {
                    SendReply(player, "Syntax: /portal remove <ID>");
                    return;
                }

                ID = args[1];

                portal = PortalInfo.Find(ID);

                if (portal == null)
                {
                    SendReply(player, GetMsg("Portal Does Not Exist").Replace("{ID}", args[1]));
                    return;
                }

                portal.Remove();
                portals.Remove(portal);

                SaveData(portals);

                SendReply(player, GetMsg("Portal Removed").Replace("{ID}", args[1]));

                break;

            case "list":

                string portalList = portals.Count == 0
                        ? GetMsg("Portal List Empty")
                        : GetMsg("Portal List").Replace("{portals}",
                                                        string.Join("<color=#333> ◆ </color>", portals.Select(p => $"<color=#C4FF00>{p.ID}</color>").ToArray()));

                SendReply(player, portalList);

                break;

            default:

                SendReply(player, "Syntax: /portal <entrance|exit|remove> <ID>");

                break;
            }
        }