Exemple #1
0
        /// <summary>
        ///     Create a <see cref="Portal" /> list from a <see cref="ZPackage" />
        /// </summary>
        /// <param name="zpkg"></param>
        /// <returns></returns>
        public static PortalList FromZPackage(ZPackage zpkg)
        {
            Logger.LogDebug("Deserializing portal list from ZPackage");

            var ret = new PortalList();

            var numConnectedPortals = zpkg.ReadInt();

            while (numConnectedPortals > 0)
            {
                var portalPosition = zpkg.ReadVector3();
                var portalName     = zpkg.ReadString();

                Logger.LogDebug($"{portalName}@{portalPosition}");
                ret.Add(new Portal(portalPosition, portalName, true));

                numConnectedPortals--;
            }

            var numUnconnectedPortals = zpkg.ReadInt();

            while (numUnconnectedPortals > 0)
            {
                var portalPosition = zpkg.ReadVector3();
                var portalName     = zpkg.ReadString();

                Logger.LogDebug($"{portalName}@{portalPosition}");
                ret.Add(new Portal(portalPosition, portalName, false));

                numUnconnectedPortals--;
            }

            return(ret);
        }
Exemple #2
0
        /// <summary>
        ///     Get the current list of <see cref="Portal" /> ZDOs
        /// </summary>
        /// <returns></returns>
        public static PortalList GetPortals()
        {
            Logger.LogDebug("Creating portal list from ZDOMan");

            // Collect all portal locations/names
            var connected   = new List <ZDO>();
            var unconnected = new Dictionary <string, ZDO>();

            foreach (var zdoarray in ZDOMan.instance.m_objectsBySector)
            {
                if (zdoarray != null)
                {
                    foreach (var zdo in zdoarray.Where(x => x.m_prefab == -661882940))
                    {
                        var tag = zdo.GetString("tag");

                        if (!unconnected.ContainsKey(tag))
                        {
                            unconnected.Add(tag, zdo);
                        }
                        else
                        {
                            connected.Add(zdo);
                            connected.Add(unconnected[tag]);
                            unconnected.Remove(tag);
                        }
                    }
                }
            }

            // Make a list of all Portals
            var    ret = new PortalList();
            Portal portal;

            Logger.LogDebug("Connected Portals");
            foreach (var entry in connected.OrderBy(x => x.GetString("tag")))
            {
                portal = new Portal(entry.m_position, entry.GetString("tag"), true);
                Logger.LogDebug(portal);
                ret.Add(portal);
            }

            Logger.LogDebug("Unconnected Portals");
            foreach (var entry in unconnected.OrderBy(x => x.Value.GetString("tag")))
            {
                portal = new Portal(entry.Value.m_position, entry.Value.GetString("tag"), false);
                Logger.LogDebug(portal);
                ret.Add(portal);
            }

            return(ret);
        }