示例#1
0
        public static void CreatePortal(Portal portal, World source, bool Custom)
        {
            try
            {
                if (Custom)
                {
                    if (!source.IsLoaded)
                    {
                        source.LoadMap();
                    }
                }
                if (source.Map.Portals == null)
                {
                    source.Map.Portals = new ArrayList();
                }

                lock (source.Map.Portals.SyncRoot)
                {
                    source.Map.Portals.Add(portal);
                }
                if (Custom)
                {
                    if (source.IsLoaded)
                    {
                        source.UnloadMap(true);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Log(LogType.Error, "PortalCreation: " + e);
            }
        }
示例#2
0
        public static PortalRange CalculateRange(Portal portal) {
            PortalRange range = new PortalRange(0, 0, 0, 0, 0, 0);

            foreach (Vector3I block in portal.AffectedBlocks) {
                if (range.Xmin == 0) {
                    range.Xmin = block.X;
                } else {
                    if (block.X < range.Xmin) {
                        range.Xmin = block.X;
                    }
                }

                if (range.Xmax == 0) {
                    range.Xmax = block.X;
                } else {
                    if (block.X > range.Xmax) {
                        range.Xmax = block.X;
                    }
                }

                if (range.Ymin == 0) {
                    range.Ymin = block.Y;
                } else {
                    if (block.Y < range.Ymin) {
                        range.Ymin = block.Y;
                    }
                }

                if (range.Ymax == 0) {
                    range.Ymax = block.Y;
                } else {
                    if (block.Y > range.Ymax) {
                        range.Ymax = block.Y;
                    }
                }

                if (range.Zmin == 0) {
                    range.Zmin = block.Z;
                } else {
                    if (block.Z < range.Zmin) {
                        range.Zmin = block.Z;
                    }
                }

                if (range.Zmax == 0) {
                    range.Zmax = block.Z;
                } else {
                    if (block.Z > range.Zmax) {
                        range.Zmax = block.Z;
                    }
                }
            }

            return range;
        }
示例#3
0
        public static void CreatePortal(Portal portal, World source)
        {
            World world = WorldManager.FindWorldExact(portal.World);

            if (source.Portals == null)
            {
                source.Portals = new ArrayList();
            }

            lock (source.Portals.SyncRoot)
            {
                source.Portals.Add(portal);
            }

            PortalDB.Save();
        }
示例#4
0
        static void PortalCreateCallback(Player player, Vector3I[] marks, object tag)
        {
            try
            {
                World world = WorldManager.FindWorldExact(player.PortalWorld);

                if (world != null)
                {
                    DrawOperation op = (DrawOperation)tag;
                    if (!op.Prepare(marks)) return;
                    if (!player.CanDraw(op.BlocksTotalEstimate))
                    {
                        player.MessageNow("You are only allowed to run draw commands that affect up to {0} blocks. This one would affect {1} blocks.",
                                           player.Info.Rank.DrawLimit,
                                           op.Bounds.Volume);
                        op.Cancel();
                        return;
                    }

                    int Xmin = Math.Min(marks[0].X, marks[1].X);
                    int Xmax = Math.Max(marks[0].X, marks[1].X);
                    int Ymin = Math.Min(marks[0].Y, marks[1].Y);
                    int Ymax = Math.Max(marks[0].Y, marks[1].Y);
                    int Zmin = Math.Min(marks[0].Z, marks[1].Z);
                    int Zmax = Math.Max(marks[0].Z, marks[1].Z);

                    for (int x = Xmin; x <= Xmax; x++)
                    {
                        for (int y = Ymin; y <= Ymax; y++)
                        {
                            for (int z = Zmin; z <= Zmax; z++)
                            {
                                if (PortalHandler.IsInRangeOfSpawnpoint(player.World, new Vector3I(x, y, z)))
                                {
                                    player.Message("You can not build a portal near a spawnpoint.");
                                    return;
                                }

                                if (PortalHandler.GetInstance().GetPortal(player.World, new Vector3I(x, y, z)) != null)
                                {
                                    player.Message("You can not build a portal inside a portal, U MAD BRO?");
                                    return;
                                }
                            }
                        }
                    }

                    if (player.PortalName == null)
                    {
                        player.PortalName = Portal.GenerateName(player.World);
                    }

                    Portal portal = new Portal(player.PortalWorld, marks, player.PortalName, player.Name, player.World.Name);
                    PortalHandler.CreatePortal(portal, player.World);
                    op.AnnounceCompletion = false;
                    op.Context = BlockChangeContext.Portal;
                    op.Begin();

                    player.Message("Successfully created portal with name " + portal.Name + ".");
                }
                else
                {
                    player.MessageInvalidWorldName(player.PortalWorld);
                }
            }
            catch (Exception ex)
            {
                player.Message("Failed to create portal.");
                Logger.Log(LogType.Error, "WorldCommands.PortalCreateCallback: " + ex);
            }
        }
示例#5
0
 public void UpdatePortal( Portal portal )
 {
     portal.Name = Name;
     portal.Creator = Creator;
     portal.Created = Created;
     portal.World = World;
     portal.Range = new PortalRange( XMin, XMax, YMin, YMax, ZMin, ZMax );
     portal.Place = Place;
     portal.DesiredOutputX = DesiredOutputX;
     portal.DesiredOutputY = DesiredOutputY;
     portal.DesiredOutputZ = DesiredOutputZ;
     portal.DesiredOutputR = DesiredOutputR;
     portal.DesiredOutputL = DesiredOutputL;
     portal.HasDesiredOutput = HasDesiredOutput;
 }
示例#6
0
 public SerializedData( Portal portal )
 {
     lock ( portal ) {
         Name = portal.Name;
         Creator = portal.Creator;
         Created = portal.Created;
         World = portal.World;
         XMin = portal.Range.Xmin;
         XMax = portal.Range.Xmax;
         YMin = portal.Range.Ymin;
         YMax = portal.Range.Ymax;
         ZMin = portal.Range.Zmin;
         ZMax = portal.Range.Zmax;
         Place = portal.Place;
         DesiredOutputX = portal.DesiredOutputX;
         DesiredOutputY = portal.DesiredOutputY;
         DesiredOutputZ = portal.DesiredOutputZ;
         DesiredOutputR = portal.DesiredOutputR;
         DesiredOutputL = portal.DesiredOutputL;
         HasDesiredOutput = portal.HasDesiredOutput;
     }
 }
示例#7
0
        public static Portal Deserialize( string name, string sdata, Map map )
        {
            byte[] bdata = Convert.FromBase64String( sdata );
            Portal portal = new Portal();
            DataContractSerializer serializer = new DataContractSerializer( typeof( SerializedData ) );
            System.IO.MemoryStream s = new System.IO.MemoryStream( bdata );
            SerializedData data = ( SerializedData )serializer.ReadObject( s );

            data.UpdatePortal( portal );
            return portal;
        }