コード例 #1
0
        private void ValSpecial(int x, int y)
        {
            Tile curTile = Tiles[x, y];

            //validate chest entry exists
            if (Tile.IsChest(curTile.Type))
            {
                if (IsAnchor(x, y) && GetChestAtTile(x, y, true) == null)
                {
                    Chests.Add(new Chest(x, y));
                }
            }
            //validate sign entry exists
            else if (Tile.IsSign(curTile.Type))
            {
                if (IsAnchor(x, y) && GetSignAtTile(x, y, true) == null)
                {
                    Signs.Add(new Sign(x, y, string.Empty));
                }
            }
            //validate TileEntity
            else if (Tile.IsTileEntity(curTile.Type))
            {
                if (IsAnchor(x, y) && GetTileEntityAtTile(x, y, true) == null)
                {
                    var TE = TileEntity.CreateForTile(curTile, x, y, TileEntities.Count);
                    TileEntities.Add(TE);
                }
            }
        }
コード例 #2
0
ファイル: Chunk.cs プロジェクト: suicvne/TrueCraft
 /// <summary>
 /// Gets the tile entity for the given coordinates. May return null.
 /// </summary>
 public NbtCompound GetTileEntity(Coordinates3D coordinates)
 {
     if (TileEntities.ContainsKey(coordinates))
     {
         return(TileEntities[coordinates]);
     }
     return(null);
 }
コード例 #3
0
ファイル: Chunk.cs プロジェクト: andy7731/TrueCraft
 /// <summary>
 /// Gets the tile entity for the given coordinates. May return null.
 /// </summary>
 public NbtCompound GetTileEntity(Coordinates3D coordinates)
 {
     LastAccessed = DateTime.Now;
     if (TileEntities.ContainsKey(coordinates))
     {
         return(TileEntities[coordinates]);
     }
     return(null);
 }
コード例 #4
0
ファイル: CraftingGrid.cs プロジェクト: vinterdo/SteamAge
        public void AddToInventory(TileEntities.TileEntityGUI TEGUI)
        {
            foreach (ItemSlot IS in this.RecipeSlots)
            {
                TEGUI.AddSlot(IS);
            }

            TEGUI.AddSlot(OutputSlot);
        }
コード例 #5
0
        protected override void Execute(List <GridEntity> entities)
        {
            foreach (var gridEntity in entities)
            {
                if (gridEntity.isNewGrid)
                {
                    //Generate new grid
                    var gridColumns = gridEntity.gridSize.columns;
                    var gridRows    = gridEntity.gridSize.rows;

                    var tileWidth  = gridEntity.gridTileSize.tileWidth;
                    var tileHeight = gridEntity.gridTileSize.tileHeight;


                    var tiles       = gridEntity.gridTiles.tiles;
                    var tileColumns = tiles.GetLength(0);
                    var tileRows    = tiles.GetLength(1);


                    if (gridColumns != tileColumns || gridRows != tileRows)
                    {
                        tiles = new TileEntities[gridColumns, gridRows];

                        for (var x = 0; x < gridColumns; x++)
                        {
                            for (var y = 0; y < gridRows; y++)
                            {
                                //TODO : Change this to AddTileActionRequest to check that grid tile is vacant
                                var tile = _contexts.game.CreateEntity();
                                _contexts.meta.viewService.instance.LoadAsset(_contexts, tile, "Tile");
                                tile.AddSprite(AssetPaths.TILE_DIRT);
                                tile.AddPosition(x * tileWidth, y * tileHeight);
                                tile.AddGridLayer((int)GlobalVariables.Layer.Background);

                                var typeString =
                                    GlobalVariables.ObjectType.JoinTypes(new[] { ObjectType.OBJECT_CATEGORY_TILE });

                                tile.AddGridTileType(typeString);

                                tiles[x, y] = new TileEntities();
                                tiles[x, y].Entities.Add(tile.id.value);
                            }
                        }
                    }

                    gridEntity.isGridInitialized = true;
                }
                else
                {
                    //TODO : Load grid + grid tiles
                }
            }
        }
コード例 #6
0
ファイル: Chunk.cs プロジェクト: suicvne/TrueCraft
 /// <summary>
 /// Sets the tile entity at the given coordinates to the given value.
 /// </summary>
 public void SetTileEntity(Coordinates3D coordinates, NbtCompound value)
 {
     if (value == null && TileEntities.ContainsKey(coordinates))
     {
         TileEntities.Remove(coordinates);
     }
     else
     {
         TileEntities[coordinates] = value;
     }
     IsModified = true;
 }
コード例 #7
0
ファイル: World.cs プロジェクト: wusyong/Terraria-Map-Editor
        public void ValSpecial(int x, int y)
        {
            Tile curTile = Tiles[x, y];

            //validate chest entry exists
            if (Tile.IsChest(curTile.Type))
            {
                if (GetChestAtTile(x, y) == null)
                {
                    Chests.Add(new Chest(x, y));
                }
            }
            //validate sign entry exists
            else if (Tile.IsSign(curTile.Type))
            {
                if (GetSignAtTile(x, y) == null)
                {
                    Signs.Add(new Sign(x, y, string.Empty));
                }
            }
            //validate TileEntity
            else if (Tile.IsTileEntity(curTile.Type))
            {
                if (GetTileEntityAtTile(x, y) == null)
                {
                    TileEntity TE = new TileEntity();
                    TE.PosX = (short)x;
                    TE.PosY = (short)y;
                    TE.Id   = TileEntities.Count;
                    if (curTile.Type == (int)TileType.Dummy)
                    {
                        TE.Type = 0;
                        TE.Npc  = -1;
                    }
                    else if (curTile.Type == (int)TileType.ItemFrame)
                    {
                        TE.Type      = 1;
                        TE.NetId     = 0;
                        TE.Prefix    = 0;
                        TE.StackSize = 0;
                    }
                    else
                    {
                        TE.Type       = 2;
                        TE.On         = false;
                        TE.LogicCheck = (byte)(curTile.V / 18 + 1);
                    }
                    TileEntities.Add(TE);
                }
            }
        }
コード例 #8
0
 public void SetTileEntity(Coordinates3D coordinates, TileEntity value)
 {
     LastAccessed = DateTime.Now;
     IsModified   = true;
     for (int i = 0; i < TileEntities.Count; i++)
     {
         if (TileEntities[i].Coordinates == coordinates)
         {
             TileEntities[i] = value;
             return;
         }
     }
     TileEntities.Add(value);
 }
コード例 #9
0
 /// <summary>
 /// Sets the tile entity at the given coordinates to the given value.
 /// </summary>
 public void SetTileEntity(Coordinates3D coordinates, NbtCompound value)
 {
     if (value == null && TileEntities.ContainsKey(coordinates))
     {
         TileEntities.Remove(coordinates);
     }
     else
     {
         TileEntities[coordinates] = value;
     }
     IsModified = true;
     if (ParentRegion != null)
     {
         ParentRegion.DamageChunk(Coordinates);
     }
 }
コード例 #10
0
        public void Validate()
        {
            var t = TaskFactoryHelper.UiTaskFactory.StartNew(() =>
            {
                for (int x = 0; x < TilesWide; x++)
                {
                    OnProgressChanged(this,
                                      new ProgressChangedEventArgs((int)(x / (float)TilesWide * 100.0), "Validating World..."));

                    for (int y = 0; y < TilesHigh; y++)
                    {
                        Tile curTile = Tiles[x, y];

                        if (curTile.Type == (int)TileType.IceByRod)
                        {
                            curTile.IsActive = false;
                        }

                        ValSpecial(x, y);
                    }
                }
            });

            foreach (Chest chest in Chests.ToArray())
            {
                bool removed = false;
                for (int x = chest.X; x < chest.X + 1; x++)
                {
                    for (int y = chest.Y; y < chest.Y + 1; y++)
                    {
                        if (!Tiles[x, y].IsActive || !Tile.IsChest(Tiles[x, y].Type))
                        {
                            Chests.Remove(chest);
                            removed = true;
                            break;
                        }
                    }
                    if (removed)
                    {
                        break;
                    }
                }
            }

            foreach (Sign sign in Signs.ToArray())
            {
                if (sign.Text == null)
                {
                    Signs.Remove(sign);
                    continue;
                }

                bool removed = false;
                for (int x = sign.X; x < sign.X + 1; x++)
                {
                    for (int y = sign.Y; y < sign.Y + 1; y++)
                    {
                        if (!Tiles[x, y].IsActive || !Tile.IsSign(Tiles[x, y].Type))
                        {
                            Signs.Remove(sign);
                            removed = true;
                            break;
                        }
                    }
                    if (removed)
                    {
                        break;
                    }
                }
            }


            foreach (TileEntity tileEntity in TileEntities.ToArray())
            {
                int x      = tileEntity.PosX;
                int y      = tileEntity.PosY;
                var anchor = GetAnchor(x, y);
                if (!Tiles[anchor.X, anchor.Y].IsActive || !Tile.IsTileEntity(Tiles[anchor.X, anchor.Y].Type))
                {
                    TaskFactoryHelper.ExecuteUiTask(() => TileEntities.Remove(tileEntity));
                }
            }

            OnProgressChanged(this,
                              new ProgressChangedEventArgs(0, "Validating Complete..."));

            if (Chests.Count > World.MaxChests)
            {
                throw new ArgumentOutOfRangeException($"Chest Count is {Chests.Count} which is greater than {World.MaxChests}.");
            }
            if (Signs.Count > World.MaxSigns)
            {
                throw new ArgumentOutOfRangeException($"Sign Count is {Signs.Count} which is greater than {World.MaxSigns}.");
            }
        }
コード例 #11
0
        public TileEntity GetTileEntityAtTile(int x, int y, bool findOrigin = false)
        {
            Vector2Int32 anchor = findOrigin ? GetAnchor(x, y) : new Vector2Int32(x, y);

            return(TileEntities.FirstOrDefault(c => (c.PosX == anchor.X) && (c.PosY == anchor.Y)));
        }
コード例 #12
0
        public TileEntity GetTileEntityAtTile(int x, int y)
        {
            Vector2Int32 anchor = GetAnchor(x, y);

            return(TileEntities.FirstOrDefault(c => (c.PosX == anchor.X) && (c.PosY == anchor.Y)));
        }
コード例 #13
0
        public void Validate()
        {
            for (int x = 0; x < TilesWide; x++)
            {
                OnProgressChanged(this,
                                  new ProgressChangedEventArgs((int)(x / (float)TilesWide * 100.0), "Validating World..."));

                for (int y = 0; y < TilesHigh; y++)
                {
                    Tile curTile = Tiles[x, y];

                    if (curTile.Type == (int)TileType.IceByRod)
                    {
                        curTile.IsActive = false;
                    }

                    // TODO: Let Validate handle these
                    //validate chest entry exists
                    if (Tile.IsChest(curTile.Type))
                    {
                        if (GetChestAtTile(x, y) == null)
                        {
                            Chests.Add(new Chest(x, y));
                        }
                    }
                    //validate sign entry exists
                    else if (Tile.IsSign(curTile.Type))
                    {
                        if (GetSignAtTile(x, y) == null)
                        {
                            Signs.Add(new Sign(x, y, string.Empty));
                        }
                    }
                    //validate logic sensors
                    else if (curTile.Type == 423)
                    {
                        if (GetTileEntityAtTile(x, y) == null)
                        {
                            TileEntity TE = new TileEntity();
                            TE.Type       = 2;
                            TE.PosX       = (short)x;
                            TE.PosY       = (short)y;
                            TE.On         = false;
                            TE.LogicCheck = (byte)(curTile.V / 18 + 1);
                            TE.Id         = TileEntities.Count;
                            TileEntities.Add(TE);
                        }
                    }
                }
            }

            foreach (Chest chest in Chests.ToArray())
            {
                bool removed = false;
                for (int x = chest.X; x < chest.X + 1; x++)
                {
                    for (int y = chest.Y; y < chest.Y + 1; y++)
                    {
                        if (!Tiles[x, y].IsActive || !Tile.IsChest(Tiles[x, y].Type))
                        {
                            Chests.Remove(chest);
                            removed = true;
                            break;
                        }
                    }
                    if (removed)
                    {
                        break;
                    }
                }
            }

            foreach (Sign sign in Signs.ToArray())
            {
                if (sign.Text == null)
                {
                    Signs.Remove(sign);
                    continue;
                }

                bool removed = false;
                for (int x = sign.X; x < sign.X + 1; x++)
                {
                    for (int y = sign.Y; y < sign.Y + 1; y++)
                    {
                        if (!Tiles[x, y].IsActive || !Tile.IsSign(Tiles[x, y].Type))
                        {
                            Signs.Remove(sign);
                            removed = true;
                            break;
                        }
                    }
                    if (removed)
                    {
                        break;
                    }
                }
            }
            OnProgressChanged(this,
                              new ProgressChangedEventArgs(0, "Validating Complete..."));
            if (Chests.Count > 1000)
            {
                throw new ArgumentOutOfRangeException(string.Format("Chest Count is {0} which is greater than 1000", Chests.Count));
            }
            if (Signs.Count > 1000)
            {
                throw new ArgumentOutOfRangeException(string.Format("Sign Count is {0} which is greater than 1000", Signs.Count));
            }
        }
コード例 #14
0
 public TileEntity GetTileEntityAtTile(int x, int y)
 {
     return(TileEntities.FirstOrDefault(c => (c.PosX == x || c.PosX == x - 1) && (c.PosY == y || c.PosY == y - 1)));
 }
コード例 #15
0
        public void Validate()
        {
            for (int x = 0; x < TilesWide; x++)
            {
                OnProgressChanged(this,
                                  new ProgressChangedEventArgs((int)(x / (float)TilesWide * 100.0), "验证世界文件..."));

                for (int y = 0; y < TilesHigh; y++)
                {
                    Tile curTile = Tiles[x, y];

                    if (curTile.Type == (int)TileType.IceByRod)
                    {
                        curTile.IsActive = false;
                    }

                    ValSpecial(x, y);
                }
            }

            foreach (Chest chest in Chests.ToArray())
            {
                bool removed = false;
                for (int x = chest.X; x < chest.X + 1; x++)
                {
                    for (int y = chest.Y; y < chest.Y + 1; y++)
                    {
                        if (!Tiles[x, y].IsActive || !Tile.IsChest(Tiles[x, y].Type))
                        {
                            Chests.Remove(chest);
                            removed = true;
                            break;
                        }
                    }
                    if (removed)
                    {
                        break;
                    }
                }
            }

            foreach (Sign sign in Signs.ToArray())
            {
                if (sign.Text == null)
                {
                    Signs.Remove(sign);
                    continue;
                }

                bool removed = false;
                for (int x = sign.X; x < sign.X + 1; x++)
                {
                    for (int y = sign.Y; y < sign.Y + 1; y++)
                    {
                        if (!Tiles[x, y].IsActive || !Tile.IsSign(Tiles[x, y].Type))
                        {
                            Signs.Remove(sign);
                            removed = true;
                            break;
                        }
                    }
                    if (removed)
                    {
                        break;
                    }
                }
            }

            foreach (TileEntity tileEntity in TileEntities.ToArray())
            {
                int x = tileEntity.PosX;
                int y = tileEntity.PosY;
                if (!Tiles[x, y].IsActive || !Tile.IsTileEntity(Tiles[x, y].Type))
                {
                    TileEntities.Remove(tileEntity);
                }
            }

            OnProgressChanged(this,
                              new ProgressChangedEventArgs(0, "验证完整性..."));
            if (Chests.Count > 1000)
            {
                throw new ArgumentOutOfRangeException(string.Format("宝箱数量为 {0} 且大于1000.", Chests.Count));
            }
            if (Signs.Count > 1000)
            {
                throw new ArgumentOutOfRangeException(string.Format("标牌数量为 {0} 且大于1000.", Signs.Count));
            }
        }