Esempio n. 1
0
        public static DoorRange CalculateRange( Door Door )
        {
            DoorRange range = new DoorRange( 0, 0, 0, 0, 0, 0 );

            foreach ( Vector3I block in Door.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;
        }
Esempio n. 2
0
        public static void CreateDoor( Door Door, World source )
        {
            WorldManager.FindWorldExact( Door.World );

            if ( source.Map.Doors == null ) {
                source.Map.Doors = new ArrayList();
            }
            lock ( source.Map.Doors.SyncRoot ) {
                source.Map.Doors.Add( Door );
            }
        }
Esempio n. 3
0
        static void DoorAdd( Player player, Vector3I[] marks, object tag )
        {
            int sx = Math.Min( marks[0].X, marks[1].X );
            int ex = Math.Max( marks[0].X, marks[1].X );
            int sy = Math.Min( marks[0].Y, marks[1].Y );
            int ey = Math.Max( marks[0].Y, marks[1].Y );
            int sh = Math.Min( marks[0].Z, marks[1].Z );
            int eh = Math.Max( marks[0].Z, marks[1].Z );

            int volume = ( ex - sx + 1 ) * ( ey - sy + 1 ) * ( eh - sh + 1 );
            if ( volume > 30 ) {
                player.Message( "Doors are only allowed to be {0} blocks", 30 );
                return;
            }
            if ( !player.Info.Rank.AllowSecurityCircumvention ) {
                SecurityCheckResult buildCheck = player.World.BuildSecurity.CheckDetailed( player.Info );
                switch ( buildCheck ) {
                    case SecurityCheckResult.BlackListed:
                        player.Message( "Cannot add a door to world {0}&S: You are barred from building here.",
                                        player.World.ClassyName );
                        return;
                    case SecurityCheckResult.RankTooLow:
                        player.Message( "Cannot add a door to world {0}&S: You are not allowed to build here.",
                                        player.World.ClassyName );
                        return;
                    //case SecurityCheckResult.RankTooHigh:
                }
            }
            List<Vector3I> blocks = new List<Vector3I>();
            for ( int x = sx; x < ex; x++ ) {
                for ( int y = sy; y < ey; y++ ) {
                    for ( int z = sh; z < eh; z++ ) {
                        if ( player.CanPlace( player.World.Map, new Vector3I( x, y, z ), Block.Wood, BlockChangeContext.Manual ) != CanPlaceResult.Allowed ) {
                            player.Message( "Cannot add a door to world {0}&S: Build permissions in this area replied with 'denied'.",
                                        player.World.ClassyName );
                            return;
                        }
                        blocks.Add( new Vector3I( x, y, z ) );
                    }
                }
            }

            Door door = new Door( player.World.Name,
                blocks.ToArray(),
                fCraft.Doors.Door.GenerateName( player.World ),
                player.ClassyName );
            door.Range = new DoorRange( sx, ex, sy, ey, sh, eh );

            DoorHandler.CreateDoor( door, player.World );
            Logger.Log( LogType.UserActivity, "{0} created door {1} (on world {2})", player.Name, door.Name, player.World.Name );
            player.Message( "Door created on world {0}&S with name {1}", player.World.ClassyName, door.Name );
        }
Esempio n. 4
0
        static void Door( Player player, Command cmd )
        {
            string option = cmd.Next();
            if ( option == null ) {
                Door door = new Door();
                player.SelectionStart( 2, DoorAdd, door, CdDoor.Permissions );
                player.Message( "Door: Place a block or type /mark to use your location." );
                return;
            } else if ( option.ToLower().Equals( "remove" ) || option.ToLower().Equals( "rd" ) ) {
                string doorName = cmd.Next();

                if ( doorName == null ) {
                    player.Message( "No door name specified." );
                } else {
                    if ( player.World.Map.Doors != null && player.World.Map.Doors.Count > 0 ) {
                        bool found = false;
                        Door doorFound = null;

                        lock ( player.World.Map.Doors.SyncRoot ) {
                            foreach ( Door door in player.World.Map.Doors ) {
                                if ( door.Name.ToLower().Equals( doorName.ToLower() ) ) {
                                    doorFound = door;
                                    found = true;
                                    break;
                                }
                            }

                            if ( !found ) {
                                player.Message( "Could not find door by name {0}.", doorName );
                            } else {
                                doorFound.Remove( player );
                                player.Message( "door was removed." );
                            }
                        }
                    } else {
                        player.Message( "Could not find door as this world doesn't contain a door." );
                    }
                }
            } else if ( option.ToLower().Equals( "info" ) ) {
                string doorName = cmd.Next();

                if ( doorName == null ) {
                    player.Message( "No door name specified." );
                } else {
                    if ( player.World.Map.Doors != null && player.World.Map.Doors.Count > 0 ) {
                        bool found = false;

                        lock ( player.World.Map.Doors.SyncRoot ) {
                            foreach ( Door door in player.World.Map.Doors ) {
                                if ( door.Name.ToLower().Equals( doorName.ToLower() ) ) {
                                    World doorWorld = WorldManager.FindWorldExact( door.World );
                                    player.Message( "Door '{0}&S' was created by {1}&S at {2}",
                                        door.Name, door.Creator, door.Created );
                                    found = true;
                                }
                            }
                        }

                        if ( !found ) {
                            player.Message( "Could not find door by name {0}.", doorName );
                        }
                    } else {
                        player.Message( "Could not find door as this world doesn't contain a door." );
                    }
                }
            } else if ( option.ToLower().Equals( "list" ) ) {
                if ( player.World.Map.Doors == null || player.World.Map.Doors.Count == 0 ) {
                    player.Message( "There are no doors in {0}&S.", player.World.ClassyName );
                } else {
                    String[] doorNames = new String[player.World.Map.Doors.Count];
                    System.Text.StringBuilder output = new System.Text.StringBuilder( "There are " + player.World.Map.Doors.Count + " doors in " + player.World.ClassyName + "&S: " );

                    for ( int i = 0; i < player.World.Map.Doors.Count; i++ ) {
                        doorNames[i] = ( ( Door )player.World.Map.Doors[i] ).Name;
                    }
                    output.Append( doorNames.JoinToString( ", " ) );
                    player.Message( output.ToString() );
                }
            } else {
                CdDoor.PrintUsage( player );
            }
        }
Esempio n. 5
0
 public DoorInfo( Door door, Block[] buffer, Map worldMap )
 {
     Door = door;
     Buffer = buffer;
     WorldMap = worldMap;
 }
Esempio n. 6
0
        private static void openDoor( Door door, Player player )
        {
            int sx = door.Range.Xmin;
            int ex = door.Range.Xmax;
            int sy = door.Range.Ymin;
            int ey = door.Range.Ymax;
            int sz = door.Range.Zmin;
            int ez = door.Range.Zmax;

            Block[] buffer = new Block[( ex - sx + 1 ) * ( ey - sy + 1 ) * ( ez - sz + 1 )];

            int counter = 0;
            for ( int x = sx; x <= ex; x++ ) {
                for ( int y = sy; y <= ey; y++ ) {
                    for ( int z = sz; z <= ez; z++ ) {
                        buffer[counter] = player.WorldMap.GetBlock( x, y, z );
                        player.WorldMap.QueueUpdate( new BlockUpdate( null, new Vector3I( x, y, z ), Block.Air ) );
                        counter++;
                    }
                }
            }

            DoorInfo info = new DoorInfo( door, buffer, player.WorldMap );
            //reclose door
            Scheduler.NewTask( doorTimer_Elapsed ).RunOnce( info, DoorCloseTimer );
        }
Esempio n. 7
0
 public Vector3I[] GetAffectedBlocks( Door door )
 {
     Vector3I[] temp = new Vector3I[] { };
     List<Vector3I> temp2 = new List<Vector3I>();
     for ( int x = door.Range.Xmin; x < door.Range.Xmax; x++ )
         for ( int y = door.Range.Ymin; y < door.Range.Ymax; y++ )
             for ( int z = door.Range.Zmin; z < door.Range.Zmax; z++ ) {
                 temp2.Add( new Vector3I( x, y, z ) );
             }
     temp = temp2.ToArray();
     return temp;
 }
Esempio n. 8
0
 public void UpdateDoor( Door Door )
 {
     Door.Name = Name;
     Door.Creator = Creator;
     Door.Created = Created;
     Door.World = World;
     Door.Range = new DoorRange( XMin, XMax, YMin, YMax, ZMin, ZMax );
 }
Esempio n. 9
0
 public SerializedData( Door Door )
 {
     lock ( Door ) {
         Name = Door.Name;
         Creator = Door.Creator;
         Created = Door.Created;
         World = Door.World;
         XMin = Door.Range.Xmin;
         XMax = Door.Range.Xmax;
         YMin = Door.Range.Ymin;
         YMax = Door.Range.Ymax;
         ZMin = Door.Range.Zmin;
         ZMax = Door.Range.Zmax;
     }
 }
Esempio n. 10
0
 public static Door Deserialize( string name, string sdata, Map map )
 {
     byte[] bdata = Convert.FromBase64String( sdata );
     Door Door = new Door();
     DataContractSerializer serializer = new DataContractSerializer( typeof( SerializedData ) );
     System.IO.MemoryStream s = new System.IO.MemoryStream( bdata );
     SerializedData data = ( SerializedData )serializer.ReadObject( s );
     data.UpdateDoor( Door );
     return Door;
 }
Esempio n. 11
0
        private static void Door( Player player, Command cmd )
        {
            string option = cmd.Next();
            if ( string.IsNullOrEmpty(option) ) {
                const int maxNumberOfDoorsPerPlayer = 4;
                if ( DoorHandler.GetPlayerOwnedDoorsCount( player.World, player ) >= maxNumberOfDoorsPerPlayer ) {
                    player.Message( "You cannot place any more doors, a player can have a maximum of {0} doors per world",
                        maxNumberOfDoorsPerPlayer );
                    return;
                }
                Door door = new Door();
                player.SelectionStart( 2, DoorAdd, door, CdDoor.Permissions );
                player.Message( "Door: Place a block or type /Mark to use your location." );
                return;
            } else if ( option.ToLower().Equals( "remove" ) || option.ToLower().Equals( "rd" ) ) {
                string doorName = cmd.Next();
                if ( doorName == null ) {
                    player.Message( "No door name specified." );
                } else {
                    if ( player.World.Map.Doors != null && player.World.Map.Doors.Count > 0 ) {
                        bool found = false;
                        Door doorFound = null;
                        lock ( player.World.Map.Doors.SyncRoot ) {
                            foreach ( Door door in player.World.Map.Doors ) {
                                if ( door.Name.Equals( doorName, StringComparison.OrdinalIgnoreCase ) ) {
                                    doorFound = door;
                                    found = true;
                                    break;
                                }
                            }
                            if ( !found ) {
                                player.Message( "Could not find door by name {0}.", doorName );
                            } else {
                                doorFound.Remove( player );
                                player.Message( "door was removed." );
                            }
                        }
                    } else {
                        player.Message( "Could not find door as this world doesn't contain a door." );
                    }
                }
            } else if ( option.ToLower().Equals( "info" ) ) {
                string doorName = cmd.Next();
                if ( doorName == null ) {
                    player.Message( "No door name specified." );
                } else {
                    if ( player.World.Map.Doors != null && player.World.Map.Doors.Count > 0 ) {
                        bool found = false;
                        lock ( player.World.Map.Doors.SyncRoot ) {
                            foreach ( Door door in player.World.Map.Doors ) {
                                if ( door.Name.Equals( doorName, StringComparison.OrdinalIgnoreCase ) ) {
                                    player.Message( "Door '{0}&S' was created by {1}&S at {2}",
                                        door.Name, door.Creator, door.Created );
                                    found = true;
                                }
                            }
                        }
                        if ( !found ) {
                            player.Message( "Could not find door by name {0}.", doorName );
                        }
                    } else {
                        player.Message( "Could not find door as this world doesn't contain a door." );
                    }
                }
            } else if ( option.ToLower().Equals( "list" ) ) {
                if ( player.World.Map.Doors == null || player.World.Map.Doors.Count == 0 ) {
                    player.Message( "There are no doors in {0}&S.", player.World.ClassyName );
                } else {
                    String[] doorNames = new String[player.World.Map.Doors.Count];
                    System.Text.StringBuilder output = new System.Text.StringBuilder( "There are " + player.World.Map.Doors.Count + " doors in " + player.World.ClassyName + "&S: " );

                    for ( int i = 0; i < player.World.Map.Doors.Count; i++ ) {
                        doorNames[i] = ( ( Door )player.World.Map.Doors[i] ).Name;
                    }
                    output.Append( doorNames.JoinToString( ", " ) );
                    player.Message( output.ToString() );
                }
            } else if ( option.ToLower() == "test" ) {
                player.SelectionStart( 1, DoorTestCallback, null, CdDoor.Permissions );
                player.Message( "DoorTest: Click a block or type /mark to use your location." );
            } else {
                CdDoor.PrintUsage( player );
            }
        }