예제 #1
0
 public World(string name, BoundingBox boundingBox, Vector tileDimensions)
     : base(boundingBox, tileDimensions)
 {
     this.Name = name;
     this.ItemCache = new ItemCache();
     log.InfoFormat("created world {0}", name);
 }
예제 #2
0
 public static OperationRequest CreateWorld(string worldName, BoundingBox boundingBox, Vector tileDimensions)
 {
     var request = new OperationRequest { OperationCode = (byte)OperationCode.CreateWorld, Parameters = new Dictionary<byte, object>() };
     request.Parameters.Add((byte)ParameterCode.WorldName, worldName);
     request.Parameters.Add((byte)ParameterCode.BoundingBox, boundingBox);
     request.Parameters.Add((byte)ParameterCode.TileDimensions, tileDimensions);
     return request;
 }
예제 #3
0
 public static void CreateWorld(Game game, string worldName, BoundingBox boundingBox, Vector tileDimensions)
 {
     var data = new Dictionary<byte, object>
         {
             { (byte)ParameterCode.WorldName, worldName },
             { (byte)ParameterCode.BoundingBox, boundingBox },
             { (byte)ParameterCode.TileDimensions, tileDimensions }
         };
     game.SendOperation(OperationCode.CreateWorld, data, true, Settings.OperationChannel);
 }
예제 #4
0
 public static void CreateWorld(Client client, string worldName, BoundingBox boundingBox, Vector tileDimensions)
 {
     var data = new Dictionary<byte, object>
         {
             { (byte)ParameterCode.WorldName, worldName },
             { (byte)ParameterCode.BoundingBox, boundingBox },
             { (byte)ParameterCode.TileDimensions, tileDimensions }
         };
     client.SendOperation((byte)OperationCode.CreateWorld, data, true);
 }
예제 #5
0
        public GridWorld(BoundingBox area, Vector tileDimensions)
        {
            // 2D grid: extend Z to max possible
            this.Area = area;
            this.TileDimensions = tileDimensions;
            this.TileX = (int)Math.Ceiling(Area.Size.X / (double)tileDimensions.X);
            this.TileY = (int)Math.Ceiling(Area.Size.Y / (double)tileDimensions.Y);

            this.worldRegions = new Region[TileX][];
            for (int x = 0; x < TileX; x++)
            {
                this.worldRegions[x] = new Region[TileY];
                for (int y = 0; y < TileY; y++)
                {
                    this.worldRegions[x][y] = new Region(x, y);
                }
            }
        }
예제 #6
0
 public BoundingBox IntersectWith(BoundingBox other)
 {
     return new BoundingBox { Min = Vector.Max(this.Min, other.Min), Max = Vector.Min(this.Max, other.Max) };
 }
예제 #7
0
 private IEnumerable<Region> GetRegionsEnumerable(BoundingBox area)
 {
     BoundingBox overlap = this.Area.IntersectWith(area);
     var min = overlap.Min - this.Area.Min;
     var max = overlap.Max - this.Area.Min;
     // convert to tile coordinates and check bounds
     int x0 = Math.Max((int)(min.X / this.TileDimensions.X), 0);
     int x1 = Math.Min((int)Math.Ceiling(max.X / this.TileDimensions.X), TileX);
     int y0 = Math.Max((int)(min.Y / this.TileDimensions.Y), 0);
     int y1 = Math.Min((int)Math.Ceiling(max.Y / this.TileDimensions.Y), TileY);
     for (int x = x0; x < x1; x++)
         for (int y = y0; y < y1; y++)
         {
             yield return this.worldRegions[x][y];
         }
     yield break;
 }
예제 #8
0
 public IEnumerable<Region> GetRegions(BoundingBox area)
 {
     return GetRegionsEnumerable(area).ToArray();
 }