コード例 #1
0
 /// <summary>
 /// Constructs an instance of <see cref="VirtualizingCacheSourceChange{T}"/>.
 /// </summary>
 /// <param name="change">The original change.</param>
 /// <param name="currentIndex">The current index of the change.</param>
 /// <param name="previousIndex">The previous index of the item affected by the change, if any.</param>
 private VirtualizingCacheSourceChange(DeltaState state, T currentItem, int?currentIndex, T previousItem, int?previousIndex)
 {
     State         = state;
     CurrentItem   = currentItem;
     PreviousItem  = previousItem;
     CurrentIndex  = currentIndex;
     PreviousIndex = previousIndex;
 }
コード例 #2
0
 /// <summary>
 /// Constructs an instance of <see cref="LogicalChange{T}"/>.
 /// </summary>
 /// <param name="state"></param>
 /// <param name="currentEntity"></param>
 /// <param name="previousEntity"></param>
 /// <param name="currentIndex"></param>
 /// <param name="previousIndex"></param>
 public LogicalChange(DeltaState state, T currentEntity, T previousEntity, int?currentIndex, int?previousIndex)
 {
     State          = state;
     CurrentEntity  = currentEntity;
     PreviousEntity = previousEntity;
     CurrentIndex   = currentIndex;
     PreviousIndex  = previousIndex;
 }
コード例 #3
0
ファイル: Statics.cs プロジェクト: justdanofficial/khaeros
        public static void Freeze( Mobile from, Map targetMap, Point3D start3d, Point3D end3d )
        {
            Hashtable mapTable = new Hashtable();

            if ( start3d == NullP3D && end3d == NullP3D )
            {
                if ( targetMap == null )
                    CommandLogging.WriteLine( from, "{0} {1} invoking freeze for every item in every map", from.AccessLevel, CommandLogging.Format( from ) );
                else
                    CommandLogging.WriteLine( from, "{0} {1} invoking freeze for every item in {0}", from.AccessLevel, CommandLogging.Format( from ), targetMap );

                foreach ( Item item in World.Items.Values )
                {
                    if ( targetMap != null && item.Map != targetMap )
                        continue;

                    if ( item.Parent != null )
                        continue;

                    if ( item is Static || item is BaseFloor || item is BaseWall )
                    {
                        Map itemMap = item.Map;

                        if ( itemMap == null || itemMap == Map.Internal )
                            continue;

                        Hashtable table = (Hashtable)mapTable[itemMap];

                        if ( table == null )
                            mapTable[itemMap] = table = new Hashtable();

                        Point2D p = new Point2D( item.X >> 3, item.Y >> 3 );

                        DeltaState state = (DeltaState)table[p];

                        if ( state == null )
                            table[p] = state = new DeltaState( p );

                        state.m_List.Add( item );
                    }
                }
            }
            else if ( targetMap != null )
            {
                Point2D start = targetMap.Bound( new Point2D( start3d ) ), end = targetMap.Bound( new Point2D( end3d ) );

                CommandLogging.WriteLine( from, "{0} {1} invoking freeze from {2} to {3} in {4}", from.AccessLevel, CommandLogging.Format( from ), start, end, targetMap );

                IPooledEnumerable eable = targetMap.GetItemsInBounds( new Rectangle2D( start.X, start.Y, end.X - start.X + 1, end.Y - start.Y + 1 ) );

                foreach ( Item item in eable )
                {
                    if ( item is Static || item is BaseFloor || item is BaseWall )
                    {
                        Map itemMap = item.Map;

                        if ( itemMap == null || itemMap == Map.Internal )
                            continue;

                        Hashtable table = (Hashtable)mapTable[itemMap];

                        if ( table == null )
                            mapTable[itemMap] = table = new Hashtable();

                        Point2D p = new Point2D( item.X >> 3, item.Y >> 3 );

                        DeltaState state = (DeltaState)table[p];

                        if ( state == null )
                            table[p] = state = new DeltaState( p );

                        state.m_List.Add( item );
                    }
                }

                eable.Free();
            }

            if ( mapTable.Count == 0 )
            {
                from.SendGump( new NoticeGump( 1060637, 30720, "No freezable items were found.  Only the following item types are frozen:<br> - Static<br> - BaseFloor<br> - BaseWall", 0xFFC000, 320, 240, null, null ) );
                return;
            }

            bool badDataFile = false;

            int totalFrozen = 0;

            foreach ( DictionaryEntry de in mapTable )
            {
                Map map = (Map)de.Key;
                Hashtable table = (Hashtable)de.Value;

                TileMatrix matrix = map.Tiles;

                using ( FileStream idxStream = OpenWrite( matrix.IndexStream ) )
                {
                    using ( FileStream mulStream = OpenWrite( matrix.DataStream ) )
                    {
                        if ( idxStream == null || mulStream == null )
                        {
                            badDataFile = true;
                            continue;
                        }

                        BinaryReader idxReader = new BinaryReader( idxStream );

                        BinaryWriter idxWriter = new BinaryWriter( idxStream );
                        BinaryWriter mulWriter = new BinaryWriter( mulStream );

                        foreach ( DeltaState state in table.Values )
                        {
                            int oldTileCount;
                            StaticTile[] oldTiles = ReadStaticBlock( idxReader, mulStream, state.m_X, state.m_Y, matrix.BlockWidth, matrix.BlockHeight, out oldTileCount );

                            if ( oldTileCount < 0 )
                                continue;

                            int newTileCount = 0;
                            StaticTile[] newTiles = new StaticTile[state.m_List.Count];

                            for ( int i = 0; i < state.m_List.Count; ++i )
                            {
                                Item item = (Item)state.m_List[i];

                                int xOffset = item.X - (state.m_X * 8);
                                int yOffset = item.Y - (state.m_Y * 8);

                                if ( xOffset < 0 || xOffset >= 8 || yOffset < 0 || yOffset >= 8 )
                                    continue;

                                StaticTile newTile = new StaticTile();

                                newTile.m_ID = (short)(item.ItemID & 0x3FFF);
                                newTile.m_X = (byte)xOffset;
                                newTile.m_Y = (byte)yOffset;
                                newTile.m_Z = (sbyte)item.Z;
                                newTile.m_Hue = (short)item.Hue;

                                newTiles[newTileCount++] = newTile;

                                item.Delete();

                                ++totalFrozen;
                            }

                            int mulPos = -1;
                            int length = -1;
                            int extra = 0;

                            if ( (oldTileCount + newTileCount) > 0 )
                            {
                                mulWriter.Seek( 0, SeekOrigin.End );

                                mulPos = (int)mulWriter.BaseStream.Position;
                                length = (oldTileCount + newTileCount) * 7;
                                extra = 1;

                                for ( int i = 0; i < oldTileCount; ++i )
                                {
                                    StaticTile toWrite = oldTiles[i];

                                    mulWriter.Write( (short) toWrite.m_ID );
                                    mulWriter.Write( (byte) toWrite.m_X );
                                    mulWriter.Write( (byte) toWrite.m_Y );
                                    mulWriter.Write( (sbyte) toWrite.m_Z );
                                    mulWriter.Write( (short) toWrite.m_Hue );
                                }

                                for ( int i = 0; i < newTileCount; ++i )
                                {
                                    StaticTile toWrite = newTiles[i];

                                    mulWriter.Write( (short) toWrite.m_ID );
                                    mulWriter.Write( (byte) toWrite.m_X );
                                    mulWriter.Write( (byte) toWrite.m_Y );
                                    mulWriter.Write( (sbyte) toWrite.m_Z );
                                    mulWriter.Write( (short) toWrite.m_Hue );
                                }

                                mulWriter.Flush();
                            }

                            int idxPos = ((state.m_X * matrix.BlockHeight) + state.m_Y) * 12;

                            idxWriter.Seek( idxPos, SeekOrigin.Begin );
                            idxWriter.Write( mulPos );
                            idxWriter.Write( length );
                            idxWriter.Write( extra );

                            idxWriter.Flush();

                            matrix.SetStaticBlock( state.m_X, state.m_Y, null );
                        }
                    }
                }
            }

            if ( totalFrozen == 0 && badDataFile )
                from.SendGump( new NoticeGump( 1060637, 30720, "Output data files could not be opened and the freeze operation has been aborted.<br><br>This probably means your server and client are using the same data files.  Instructions on how to resolve this can be found in the first warning window.", 0xFFC000, 320, 240, null, null ) );
            else
                from.SendGump( new NoticeGump( 1060637, 30720, String.Format( "Freeze operation completed successfully.<br><br>{0} item{1} frozen.<br><br>You must restart your client and update it's data files to see the changes.", totalFrozen, totalFrozen != 1 ? "s were" : " was" ), 0xFFC000, 320, 240, null, null ) );
        }
コード例 #4
0
ファイル: Statics.cs プロジェクト: tflynt91/TrueUO
        public static void Freeze(Mobile from, Map targetMap, Point3D start3d, Point3D end3d)
        {
            Hashtable mapTable = new Hashtable();

            if (start3d == NullP3D && end3d == NullP3D)
            {
                if (targetMap == null)
                {
                    CommandLogging.WriteLine(from, "{0} {1} invoking freeze for every item in every map", from.AccessLevel, CommandLogging.Format(from));
                }
                else
                {
                    CommandLogging.WriteLine(from, "{0} {1} invoking freeze for every item in {0}", from.AccessLevel, CommandLogging.Format(from), targetMap);
                }

                foreach (Item item in World.Items.Values)
                {
                    if (targetMap != null && item.Map != targetMap)
                    {
                        continue;
                    }

                    if (item.Parent != null)
                    {
                        continue;
                    }

                    if (item is Static || item is BaseFloor || item is BaseWall)
                    {
                        Map itemMap = item.Map;

                        if (itemMap == null || itemMap == Map.Internal)
                        {
                            continue;
                        }

                        Hashtable table = (Hashtable)mapTable[itemMap];

                        if (table == null)
                        {
                            mapTable[itemMap] = table = new Hashtable();
                        }

                        Point2D p = new Point2D(item.X >> 3, item.Y >> 3);

                        DeltaState state = (DeltaState)table[p];

                        if (state == null)
                        {
                            table[p] = state = new DeltaState(p);
                        }

                        state.m_List.Add(item);
                    }
                }
            }
            else if (targetMap != null)
            {
                Point2D start = targetMap.Bound(new Point2D(start3d)), end = targetMap.Bound(new Point2D(end3d));

                CommandLogging.WriteLine(from, "{0} {1} invoking freeze from {2} to {3} in {4}", from.AccessLevel, CommandLogging.Format(from), start, end, targetMap);

                IPooledEnumerable eable = targetMap.GetItemsInBounds(new Rectangle2D(start.X, start.Y, end.X - start.X + 1, end.Y - start.Y + 1));

                foreach (Item item in eable)
                {
                    if (item is Static || item is BaseFloor || item is BaseWall)
                    {
                        Map itemMap = item.Map;

                        if (itemMap == null || itemMap == Map.Internal)
                        {
                            continue;
                        }

                        Hashtable table = (Hashtable)mapTable[itemMap];

                        if (table == null)
                        {
                            mapTable[itemMap] = table = new Hashtable();
                        }

                        Point2D p = new Point2D(item.X >> 3, item.Y >> 3);

                        DeltaState state = (DeltaState)table[p];

                        if (state == null)
                        {
                            table[p] = state = new DeltaState(p);
                        }

                        state.m_List.Add(item);
                    }
                }

                eable.Free();
            }

            if (mapTable.Count == 0)
            {
                from.SendGump(new NoticeGump(1060637, 30720, "No freezable items were found.  Only the following item types are frozen:<br> - Static<br> - BaseFloor<br> - BaseWall", 0xFFC000, 320, 240, null, null));
                return;
            }

            bool badDataFile = false;

            int totalFrozen = 0;

            foreach (DictionaryEntry de in mapTable)
            {
                Map       map   = (Map)de.Key;
                Hashtable table = (Hashtable)de.Value;

                TileMatrix matrix = map.Tiles;

                using (FileStream idxStream = OpenWrite(matrix.IndexStream))
                {
                    using (FileStream mulStream = OpenWrite(matrix.DataStream))
                    {
                        if (idxStream == null || mulStream == null)
                        {
                            badDataFile = true;
                            continue;
                        }

                        BinaryReader idxReader = new BinaryReader(idxStream);

                        BinaryWriter idxWriter = new BinaryWriter(idxStream);
                        BinaryWriter mulWriter = new BinaryWriter(mulStream);

                        foreach (DeltaState state in table.Values)
                        {
                            int          oldTileCount;
                            StaticTile[] oldTiles = ReadStaticBlock(idxReader, mulStream, state.m_X, state.m_Y, matrix.BlockWidth, matrix.BlockHeight, out oldTileCount);

                            if (oldTileCount < 0)
                            {
                                continue;
                            }

                            int          newTileCount = 0;
                            StaticTile[] newTiles     = new StaticTile[state.m_List.Count];

                            for (int i = 0; i < state.m_List.Count; ++i)
                            {
                                Item item = state.m_List[i];

                                int xOffset = item.X - (state.m_X * 8);
                                int yOffset = item.Y - (state.m_Y * 8);

                                if (xOffset < 0 || xOffset >= 8 || yOffset < 0 || yOffset >= 8)
                                {
                                    continue;
                                }

                                StaticTile newTile = new StaticTile((ushort)item.ItemID, (byte)xOffset, (byte)yOffset, (sbyte)item.Z, (short)item.Hue);

                                newTiles[newTileCount++] = newTile;

                                item.Delete();

                                ++totalFrozen;
                            }

                            int mulPos = -1;
                            int length = -1;
                            int extra  = 0;

                            if ((oldTileCount + newTileCount) > 0)
                            {
                                mulWriter.Seek(0, SeekOrigin.End);

                                mulPos = (int)mulWriter.BaseStream.Position;
                                length = (oldTileCount + newTileCount) * 7;
                                extra  = 1;

                                for (int i = 0; i < oldTileCount; ++i)
                                {
                                    StaticTile toWrite = oldTiles[i];

                                    mulWriter.Write((ushort)toWrite.ID);
                                    mulWriter.Write((byte)toWrite.X);
                                    mulWriter.Write((byte)toWrite.Y);
                                    mulWriter.Write((sbyte)toWrite.Z);
                                    mulWriter.Write((short)toWrite.Hue);
                                }

                                for (int i = 0; i < newTileCount; ++i)
                                {
                                    StaticTile toWrite = newTiles[i];

                                    mulWriter.Write((ushort)toWrite.ID);
                                    mulWriter.Write((byte)toWrite.X);
                                    mulWriter.Write((byte)toWrite.Y);
                                    mulWriter.Write((sbyte)toWrite.Z);
                                    mulWriter.Write((short)toWrite.Hue);
                                }

                                mulWriter.Flush();
                            }

                            int idxPos = ((state.m_X * matrix.BlockHeight) + state.m_Y) * 12;

                            idxWriter.Seek(idxPos, SeekOrigin.Begin);
                            idxWriter.Write(mulPos);
                            idxWriter.Write(length);
                            idxWriter.Write(extra);

                            idxWriter.Flush();

                            matrix.SetStaticBlock(state.m_X, state.m_Y, null);
                        }
                    }
                }
            }

            if (totalFrozen == 0 && badDataFile)
            {
                from.SendGump(new NoticeGump(1060637, 30720, "Output data files could not be opened and the freeze operation has been aborted.<br><br>This probably means your server and client are using the same data files.  Instructions on how to resolve this can be found in the first warning window.", 0xFFC000, 320, 240, null, null));
            }
            else
            {
                from.SendGump(new NoticeGump(1060637, 30720, string.Format("Freeze operation completed successfully.<br><br>{0} item{1} frozen.<br><br>You must restart your client and update it's data files to see the changes.", totalFrozen, totalFrozen != 1 ? "s were" : " was"), 0xFFC000, 320, 240, null, null));
            }
        }
コード例 #5
0
ファイル: DeltaEntity.cs プロジェクト: hungnd1475/Observatory
 public DeltaEntity(DeltaState state, T entity)
 {
     State  = state;
     Entity = entity;
 }