예제 #1
0
파일: Region.cs 프로젝트: welterde/obsidian
		public Region(Level level,int x1,int y1,int z1,int x2,int y2,int z2) {
			if (level==null) { throw new ArgumentNullException("level"); }
			this.level = level;
			this.x1 = x1; this.y1 = y1; this.z1 = z1;
			this.x2 = x2; this.y2 = y2; this.z2 = z2;
			level.regions.Add(this);
			level.BlockEvent += CheckBlock;
		}
예제 #2
0
 public static Level Flatgrass(short width,short depth,short height,int grasslevel)
 {
     if (!ValidLevelSize(width,depth,height)) { return null; }
     Level level = new Level(width,depth,height);
     grasslevel += depth/2-1;
     if (grasslevel>=depth) { return level; }
     int x,y=grasslevel,z;
     for (x=0;x<width;x++)
         for (z=0;z<height;z++)
             level[x,y,z] = 0x02;
     for (y=0;y<grasslevel && y<depth;y++)
         for (x=0;x<width;x++)
             for (z=0;z<height;z++)
                 level[x,y,z] = 0x03;
     for (y=0;y<grasslevel-4 && y<depth;y++)
         for (x=0;x<width;x++)
             for (z=0;z<height;z++)
                 level[x,y,z] = 0x01;
     return level;
 }
예제 #3
0
파일: Body.cs 프로젝트: welterde/obsidian
		public Body(string name,Level level) {
			if (name==null) { throw new ArgumentNullException("name"); }
			if (level==null) { throw new ArgumentNullException("name"); }
			this.name = name;
			this.level = level;
		}
예제 #4
0
 public void Send(Level level,Player except)
 {
     foreach (Packet packet in packets) packet.Send(level,except);
 }
예제 #5
0
 public void Send(Level level)
 {
     foreach (Packet packet in packets) packet.Send(level);
 }
예제 #6
0
파일: Player.cs 프로젝트: welterde/obsidian
		internal void SendLevel(Level level) {
			if (status!=OnlineStatus.Identified) { return; }
			this.level = level;
			status = OnlineStatus.Loading;
			new Thread(
				delegate() {
					Protocol.MapBeginPacket().Send(this);
					byte[] gzipped = Utility.GZipper.GZip(
						BitConverter.GetBytes(
							IPAddress.HostToNetworkOrder(level.Mapdata.Length)
						),level.Mapdata);
					for (int i=0;i<gzipped.Length;i+=1024) {
						byte progress = (byte)((i/1024+1)/Math.Ceiling(gzipped.Length/1024d)*100);
						Protocol.MapPartPacket(gzipped,i,progress).Send(this);
					} Protocol.MapEndPacket(level.Width,level.Depth,level.Height).Send(this);
					ReadyEvent.Raise(server,this);
					Spawn(level.Spawn);
					foreach (Body b in level.Bodies) { Protocol.SpawnPacket(b).Send(this); }
					Position.Set(level.Spawn);
					Visible = true;
					status = OnlineStatus.Ready;
					level.players.Add(this);
				}).Start();
		}
예제 #7
0
파일: Packet.cs 프로젝트: welterde/obsidian
 public void Send(Level level,Player except)
 {
     Send(new List<Player>(level.Players),except);
 }
예제 #8
0
파일: Packet.cs 프로젝트: welterde/obsidian
 public void Send(Level level)
 {
     Send(new List<Player>(level.Players));
 }
예제 #9
0
파일: Level.cs 프로젝트: welterde/obsidian
		public static Level Load(string name) {
			if (name==null) { throw new ArgumentNullException("name"); }
			if (name=="") { throw new ArgumentException("Name musn't be an empty string.","name"); }
			if (!RegexHelper.IsAlphaNumeric(name)) {
				throw new ArgumentException("Only alphanumerical characters allowed.","name");
			} string filename = "levels/"+name+".lvl";
			try {
				Node node = host.Load(filename,out name);
				if (name!="obsidian-level") { return null; }
				short width = (short)node["width"].Value;
				short depth = (short)node["depth"].Value;
				short height = (short)node["height"].Value;
				Node spawnNode = node["spawn"];
				Position spawn = new Position(
					(short)spawnNode["x"].Value,(short)spawnNode["y"].Value,(short)spawnNode["z"].Value,
					(byte)spawnNode["rotx"].Value,(byte)spawnNode["roty"].Value);
				byte[] mapdata = (byte[])node["mapdata"].Value;
				byte[] blockdata = (byte[])node["blockdata"].Value;
				Level level = new Level(width,depth,height);
				level.spawn.Set(spawn);
				level.mapdata = mapdata;
				level.blockdata = blockdata;
				level.custom = node["custom"]??level.custom;
				return level;
			} catch { return null; }
		}