Inheritance: GalaSoft.MvvmLight.ObservableObject
        public static void LoadTileEntities(BinaryReader r, World w)
        {
            w.TileEntitiesNumber = r.ReadInt32();

            for (int counter = 0; counter < w.TileEntitiesNumber; counter++ )
            {
                TileEntity entity = new TileEntity();
                entity.Type = r.ReadByte();
                entity.Id = r.ReadInt32();
                entity.PosX = r.ReadInt16();
                entity.PosY = r.ReadInt16();
                switch (entity.Type)
                {
                    case 0: //it is a dummy
                        entity.Npc = r.ReadInt16();
                        break;
                    case 1: //it is a item frame
                        entity.ItemNetId = r.ReadInt16();
                        entity.Prefix = r.ReadByte();
                        entity.Stack = r.ReadInt16();
                        break;
                }
                w.TileEntities.Add(entity);
            }
        }
        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));
        }
 public TileEntity Copy()
 {
     var frame = new TileEntity();
     frame.Type = Type;
     frame.PosX = PosX;
     frame.PosY = PosY;
     switch (Type)
     {
         case 0:
             frame.Npc = Npc;
             break;
         case 1:
             frame.NetId = NetId;
             frame.StackSize = StackSize;
             frame.Prefix = Prefix;
             break;
         case 2:
             frame.LogicCheck = LogicCheck;
             frame.On = On;
             break;
     }
     return frame;
 }
Beispiel #4
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));
            }
        }
Beispiel #5
0
 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);
         }
     }
 }