private void SetFlag( ImplFlag flag, bool value ) { if ( value ) m_Flags |= flag; else m_Flags &= ~flag; }
private bool GetFlag( ImplFlag flag ) { return ( (m_Flags & flag) != 0 ); }
public virtual void Deserialize( GenericReader reader ) { int version = reader.ReadInt(); SetLastMoved(); switch ( version ) { case 14: { m_InstanceID = reader.ReadInt(); SaveFlag flags = (SaveFlag) reader.ReadInt(); int minutes = reader.ReadEncodedInt(); try { LastMoved = DateTime.Now - TimeSpan.FromMinutes( minutes ); } catch { LastMoved = DateTime.Now; } if ( GetSaveFlag( flags, SaveFlag.Direction ) ) m_Direction = (Direction) reader.ReadByte(); if ( GetSaveFlag( flags, SaveFlag.LightType ) ) m_LightType = (LightType) reader.ReadByte(); if ( GetSaveFlag( flags, SaveFlag.Bounce ) ) m_Bounce = BounceInfo.Deserialize( reader ); if ( GetSaveFlag( flags, SaveFlag.LootType ) ) m_LootType = (LootType) reader.ReadByte(); int x = 0, y = 0, z = 0; if ( GetSaveFlag( flags, SaveFlag.LocationFull ) ) { x = reader.ReadEncodedInt(); y = reader.ReadEncodedInt(); z = reader.ReadEncodedInt(); } else { if ( GetSaveFlag( flags, SaveFlag.LocationByteXY ) ) { x = reader.ReadByte(); y = reader.ReadByte(); } else if ( GetSaveFlag( flags, SaveFlag.LocationShortXY ) ) { x = reader.ReadShort(); y = reader.ReadShort(); } if ( GetSaveFlag( flags, SaveFlag.LocationSByteZ ) ) z = reader.ReadSByte(); } m_Location = new Point3D( x, y, z ); if ( GetSaveFlag( flags, SaveFlag.ItemID ) ) m_ItemID = reader.ReadEncodedInt(); if ( GetSaveFlag( flags, SaveFlag.Hue ) ) m_Hue = reader.ReadEncodedInt(); if ( GetSaveFlag( flags, SaveFlag.Amount ) ) m_Amount = reader.ReadEncodedInt(); else m_Amount = 1; if ( GetSaveFlag( flags, SaveFlag.Layer ) ) m_Layer = (Layer) reader.ReadByte(); if ( GetSaveFlag( flags, SaveFlag.Name ) ) m_Name = string.Intern( reader.ReadString() ); if ( GetSaveFlag( flags, SaveFlag.Parent ) ) { Serial parent = reader.ReadInt(); if ( parent.IsMobile ) m_Parent = World.Instance.FindMobile( parent ); else if ( parent.IsItem ) m_Parent = World.Instance.FindItem( parent ); else m_Parent = null; if ( m_Parent == null && ( parent.IsMobile || parent.IsItem ) ) Delete(); } if ( GetSaveFlag( flags, SaveFlag.Items ) ) m_Items = reader.ReadStrongItemList(); if ( GetSaveFlag( flags, SaveFlag.IntWeight ) ) m_Weight = reader.ReadEncodedInt(); else if ( GetSaveFlag( flags, SaveFlag.WeightNot1or0 ) ) m_Weight = reader.ReadDouble(); else if ( GetSaveFlag( flags, SaveFlag.WeightIs0 ) ) m_Weight = 0.0; else m_Weight = 1.0; if ( GetSaveFlag( flags, SaveFlag.Map ) ) m_Map = reader.ReadMap(); else m_Map = Map.Internal; if ( GetSaveFlag( flags, SaveFlag.Visible ) ) SetFlag( ImplFlag.Visible, reader.ReadBool() ); else SetFlag( ImplFlag.Visible, true ); if ( GetSaveFlag( flags, SaveFlag.Movable ) ) SetFlag( ImplFlag.Movable, reader.ReadBool() ); else SetFlag( ImplFlag.Movable, true ); if ( GetSaveFlag( flags, SaveFlag.Stackable ) ) SetFlag( ImplFlag.Stackable, reader.ReadBool() ); if ( GetSaveFlag( flags, SaveFlag.ImplFlags ) ) m_Flags = (ImplFlag) reader.ReadEncodedInt(); if ( GetSaveFlag( flags, SaveFlag.BlessedFor ) ) m_BlessedFor = reader.ReadMobile(); if ( GetSaveFlag( flags, SaveFlag.HeldBy ) ) m_HeldBy = reader.ReadMobile(); if ( GetSaveFlag( flags, SaveFlag.LabelNumber ) ) m_LabelNumber = reader.ReadInt(); #region Labels if ( GetSaveFlag( flags, SaveFlag.Labels ) ) { int length = reader.ReadInt(); m_Labels = new string[length]; for ( int i = 0; i < length; i++ ) m_Labels[i] = reader.ReadString(); } #endregion if ( GetSaveFlag( flags, SaveFlag.SavedFlags ) ) m_SavedFlags = reader.ReadEncodedInt(); if ( m_Map != null && m_Parent == null ) m_Map.OnEnter( this ); break; } } if ( m_HeldBy != null ) Timer.DelayCall( TimeSpan.Zero, new TimerCallback( FixHolding_Sandbox ) ); }
public virtual void Deserialize( GenericReader reader ) { int version = reader.ReadInt(); SetLastMoved(); switch ( version ) { case 7: case 6: { SaveFlag flags = (SaveFlag)reader.ReadInt(); if ( version < 7 ) { LastMoved = reader.ReadDeltaTime(); } else { int minutes = reader.ReadEncodedInt(); try{ LastMoved = Core.Now - TimeSpan.FromMinutes( minutes ); } catch{ LastMoved = Core.Now; } } if ( GetSaveFlag( flags, SaveFlag.Direction ) ) m_Direction = (Direction)reader.ReadByte(); if ( GetSaveFlag( flags, SaveFlag.Bounce ) ) m_Bounce = BounceInfo.Deserialize( reader ); if ( GetSaveFlag( flags, SaveFlag.LootType ) ) m_LootType = (LootType)reader.ReadByte(); int x = 0, y = 0, z = 0; if ( GetSaveFlag( flags, SaveFlag.LocationFull ) ) { x = reader.ReadEncodedInt(); y = reader.ReadEncodedInt(); z = reader.ReadEncodedInt(); } else { if ( GetSaveFlag( flags, SaveFlag.LocationByteXY ) ) { x = reader.ReadByte(); y = reader.ReadByte(); } else if ( GetSaveFlag( flags, SaveFlag.LocationShortXY ) ) { x = reader.ReadShort(); y = reader.ReadShort(); } if ( GetSaveFlag( flags, SaveFlag.LocationSByteZ ) ) z = reader.ReadSByte(); } m_Location = new Point3D( x, y, z ); if ( GetSaveFlag( flags, SaveFlag.ItemID ) ) m_ItemID = reader.ReadEncodedInt(); if ( GetSaveFlag( flags, SaveFlag.Hue ) ) m_Hue = reader.ReadEncodedInt(); if ( GetSaveFlag( flags, SaveFlag.Amount ) ) m_Amount = reader.ReadEncodedInt(); else m_Amount = 1; if ( GetSaveFlag( flags, SaveFlag.Layer ) ) m_Layer = (Layer)reader.ReadByte(); if ( GetSaveFlag( flags, SaveFlag.Name ) ) m_Name = string.Intern(reader.ReadString()); if ( GetSaveFlag( flags, SaveFlag.Parent ) ) { Serial parent = reader.ReadInt(); if ( parent.IsMobile ) m_Parent = World.FindMobile( parent ); else if ( parent.IsItem ) m_Parent = World.FindItem( parent ); else m_Parent = null; if ( m_Parent == null && (parent.IsMobile || parent.IsItem) ) Delete(); } if ( GetSaveFlag( flags, SaveFlag.Items ) ) m_Items = reader.ReadItemList(); //else // m_Items = new ArrayList( 1 ); if ( GetSaveFlag( flags, SaveFlag.IntWeight ) ) m_Weight = reader.ReadEncodedInt(); else if ( GetSaveFlag( flags, SaveFlag.WeightNot1or0 ) ) m_Weight = reader.ReadDouble(); else if ( GetSaveFlag( flags, SaveFlag.WeightIs0 ) ) m_Weight = 0.0; else m_Weight = 1.0; if ( GetSaveFlag( flags, SaveFlag.Map ) ) m_Map = reader.ReadMap(); else m_Map = Map.Internal; if ( GetSaveFlag( flags, SaveFlag.Visible ) ) SetFlag( ImplFlag.Visible, reader.ReadBool() ); else SetFlag( ImplFlag.Visible, true ); if ( GetSaveFlag( flags, SaveFlag.Movable ) ) SetFlag( ImplFlag.Movable, reader.ReadBool() ); else SetFlag( ImplFlag.Movable, true ); if ( GetSaveFlag( flags, SaveFlag.Stackable ) ) SetFlag( ImplFlag.Stackable, reader.ReadBool() ); if ( GetSaveFlag( flags, SaveFlag.ImplFlags ) ) m_Flags = (ImplFlag)reader.ReadEncodedInt(); if ( GetSaveFlag( flags, SaveFlag.InsuredFor ) ) /*m_InsuredFor = */reader.ReadMobile(); if ( GetSaveFlag( flags, SaveFlag.BlessedFor ) ) m_BlessedFor = reader.ReadMobile(); if ( GetSaveFlag( flags, SaveFlag.HeldBy ) ) m_HeldBy = reader.ReadMobile(); if ( GetSaveFlag( flags, SaveFlag.SavedFlags ) ) m_SavedFlags = reader.ReadEncodedInt(); if ( m_Map != null && m_Parent == null ) m_Map.OnEnter( this ); break; } case 5: { SaveFlag flags = (SaveFlag)reader.ReadInt(); LastMoved = reader.ReadDeltaTime(); if ( GetSaveFlag( flags, SaveFlag.Direction ) ) m_Direction = (Direction)reader.ReadByte(); if ( GetSaveFlag( flags, SaveFlag.Bounce ) ) m_Bounce = BounceInfo.Deserialize( reader ); if ( GetSaveFlag( flags, SaveFlag.LootType ) ) m_LootType = (LootType)reader.ReadByte(); if ( GetSaveFlag( flags, SaveFlag.LocationFull ) ) m_Location = reader.ReadPoint3D(); if ( GetSaveFlag( flags, SaveFlag.ItemID ) ) m_ItemID = reader.ReadInt(); if ( GetSaveFlag( flags, SaveFlag.Hue ) ) m_Hue = reader.ReadInt(); if ( GetSaveFlag( flags, SaveFlag.Amount ) ) m_Amount = reader.ReadInt(); else m_Amount = 1; if ( GetSaveFlag( flags, SaveFlag.Layer ) ) m_Layer = (Layer)reader.ReadByte(); if ( GetSaveFlag( flags, SaveFlag.Name ) ) m_Name = string.Intern(reader.ReadString()); if ( GetSaveFlag( flags, SaveFlag.Parent ) ) { Serial parent = reader.ReadInt(); if ( parent.IsMobile ) m_Parent = World.FindMobile( parent ); else if ( parent.IsItem ) m_Parent = World.FindItem( parent ); else m_Parent = null; if ( m_Parent == null && (parent.IsMobile || parent.IsItem) ) Delete(); } if ( GetSaveFlag( flags, SaveFlag.Items ) ) m_Items = reader.ReadItemList(); //else // m_Items = new ArrayList( 1 ); if ( GetSaveFlag( flags, SaveFlag.IntWeight ) ) m_Weight = reader.ReadEncodedInt(); else if ( GetSaveFlag( flags, SaveFlag.WeightNot1or0 ) ) m_Weight = reader.ReadDouble(); else if ( GetSaveFlag( flags, SaveFlag.WeightIs0 ) ) m_Weight = 0.0; else m_Weight = 1.0; if ( GetSaveFlag( flags, SaveFlag.Map ) ) m_Map = reader.ReadMap(); else m_Map = Map.Internal; if ( GetSaveFlag( flags, SaveFlag.Visible ) ) SetFlag( ImplFlag.Visible, reader.ReadBool() ); else SetFlag( ImplFlag.Visible, true ); if ( GetSaveFlag( flags, SaveFlag.Movable ) ) SetFlag( ImplFlag.Movable, reader.ReadBool() ); else SetFlag( ImplFlag.Movable, true ); if ( GetSaveFlag( flags, SaveFlag.Stackable ) ) SetFlag( ImplFlag.Stackable, reader.ReadBool() ); if ( m_Map != null && m_Parent == null ) m_Map.OnEnter( this ); break; } case 4: // Just removed variables case 3: { m_Direction = (Direction)reader.ReadInt(); goto case 2; } case 2: { m_Bounce = BounceInfo.Deserialize( reader ); LastMoved = reader.ReadDeltaTime(); goto case 1; } case 1: { m_LootType = (LootType) reader.ReadByte();//m_Newbied = reader.ReadBool(); goto case 0; } case 0: { m_Location = reader.ReadPoint3D(); m_ItemID = reader.ReadInt(); m_Hue = reader.ReadInt(); m_Amount = reader.ReadInt(); m_Layer = (Layer) reader.ReadByte(); m_Name = reader.ReadString(); if (m_Name != null) m_Name = string.Intern(m_Name); Serial parent = reader.ReadInt(); if ( parent.IsMobile ) m_Parent = World.FindMobile( parent ); else if ( parent.IsItem ) m_Parent = World.FindItem( parent ); else m_Parent = null; if ( m_Parent == null && (parent.IsMobile || parent.IsItem) ) Delete(); int count = reader.ReadInt(); if ( count > 0 ) { m_Items = new ArrayList( count ); for ( int i = 0; i < count; ++i ) { Item item = reader.ReadItem(); if ( item != null ) m_Items.Add( item ); } } m_Weight = reader.ReadDouble(); if ( version <= 3 ) { /*m_TotalItems =*/ reader.ReadInt(); /*m_TotalWeight =*/ reader.ReadInt(); /*m_TotalGold =*/ reader.ReadInt(); } m_Map = reader.ReadMap(); SetFlag( ImplFlag.Visible, reader.ReadBool() ); SetFlag( ImplFlag.Movable, reader.ReadBool() ); if ( version <= 3 ) /*m_Deleted =*/ reader.ReadBool(); Stackable = reader.ReadBool(); if ( m_Map != null && m_Parent == null ) m_Map.OnEnter( this ); break; } } if ( m_HeldBy != null ) Timer.DelayCall( TimeSpan.Zero, new TimerCallback( FixHolding_Sandbox ) ); }
public virtual void Deserialize(GenericReader reader) { int version = reader.ReadInt(); SetLastMoved(); // must always read this first SaveFlag flags = 0; if (version >= 5) flags = (SaveFlag)reader.ReadInt32(); switch (version) { case 10: { // get the per item custom drop rate if (GetSaveFlag(flags, SaveFlag.DropRate)) m_DropRate = reader.ReadDouble(); } goto case 9; case 9: goto case 8; case 8: goto case 7;// change is at bottom of file after ImplFlags are read case 7: goto case 6; case 6: { if (version < 7) { LastMoved = reader.ReadDeltaTime(); } else { int minutes = reader.ReadEncodedInt(); try { LastMoved = DateTime.Now - TimeSpan.FromMinutes(minutes); } catch { LastMoved = DateTime.Now; } } if (GetSaveFlag(flags, SaveFlag.Direction)) m_Direction = (Direction)reader.ReadByte(); if (GetSaveFlag(flags, SaveFlag.Bounce)) m_Bounce = BounceInfo.Deserialize(reader); if (GetSaveFlag(flags, SaveFlag.LootType)) m_LootType = (LootType)reader.ReadByte(); int x = 0, y = 0, z = 0; if (GetSaveFlag(flags, SaveFlag.LocationFull)) { x = reader.ReadEncodedInt(); y = reader.ReadEncodedInt(); z = reader.ReadEncodedInt(); } else { if (GetSaveFlag(flags, SaveFlag.LocationByteXY)) { x = reader.ReadByte(); y = reader.ReadByte(); } else if (GetSaveFlag(flags, SaveFlag.LocationShortXY)) { x = reader.ReadShort(); y = reader.ReadShort(); } if (GetSaveFlag(flags, SaveFlag.LocationSByteZ)) z = reader.ReadSByte(); } m_Location = new Point3D(x, y, z); if (GetSaveFlag(flags, SaveFlag.ItemID)) m_ItemID = reader.ReadEncodedInt(); if (GetSaveFlag(flags, SaveFlag.Hue)) m_Hue = reader.ReadEncodedInt(); if (GetSaveFlag(flags, SaveFlag.Amount)) m_Amount = reader.ReadEncodedInt(); else m_Amount = 1; if (GetSaveFlag(flags, SaveFlag.Layer)) m_Layer = (Layer)reader.ReadByte(); if (GetSaveFlag(flags, SaveFlag.Name)) m_Name = reader.ReadString(); if (GetSaveFlag(flags, SaveFlag.Parent)) { Serial parent = reader.ReadInt32(); if (parent.IsMobile) m_Parent = World.FindMobile(parent); else if (parent.IsItem) m_Parent = World.FindItem(parent); else m_Parent = null; if (m_Parent == null && (parent.IsMobile || parent.IsItem)) Delete(); } if (GetSaveFlag(flags, SaveFlag.Items)) m_Items = reader.ReadItemList(); //else // m_Items = new ArrayList( 1 ); if (GetSaveFlag(flags, SaveFlag.IntWeight)) m_Weight = reader.ReadEncodedInt(); else if (GetSaveFlag(flags, SaveFlag.WeightNot1or0)) m_Weight = reader.ReadDouble(); else if (GetSaveFlag(flags, SaveFlag.WeightIs0)) m_Weight = 0.0; else m_Weight = 1.0; if (GetSaveFlag(flags, SaveFlag.Map)) m_Map = reader.ReadMap(); else m_Map = Map.Internal; if (GetSaveFlag(flags, SaveFlag.Visible)) SetFlag(ImplFlag.Visible, reader.ReadBool()); else SetFlag(ImplFlag.Visible, true); if (GetSaveFlag(flags, SaveFlag.Movable)) SetFlag(ImplFlag.Movable, reader.ReadBool()); else SetFlag(ImplFlag.Movable, true); if (GetSaveFlag(flags, SaveFlag.Stackable)) SetFlag(ImplFlag.Stackable, reader.ReadBool()); if (GetSaveFlag(flags, SaveFlag.ImplFlags)) { m_Flags = (ImplFlag)reader.ReadEncodedInt(); } // don't confuse ImplFlag.FreezeDried with SaveFlag.FreezeDried // we check different flags because of a version quirk - ask Taran if (GetFlag(ImplFlag.FreezeDried)) { TotalWeight = reader.ReadInt32(); TotalItems = reader.ReadInt32(); TotalGold = reader.ReadInt32(); } if (GetSaveFlag(flags, SaveFlag.FreezeDried)) { int count = reader.ReadInt(); m_SerializedContentsIdx = new byte[count]; for (int i = 0; i < count; i++) m_SerializedContentsIdx[i] = reader.ReadByte(); count = reader.ReadInt(); m_SerializedContentsBin = new byte[count]; for (int i = 0; i < count; i++) m_SerializedContentsBin[i] = reader.ReadByte(); } if (GetSaveFlag(flags, SaveFlag.InsuredFor)) /*m_InsuredFor = */ reader.ReadMobile(); if (GetSaveFlag(flags, SaveFlag.BlessedFor)) m_BlessedFor = reader.ReadMobile(); if (GetSaveFlag(flags, SaveFlag.HeldBy)) m_HeldBy = reader.ReadMobile(); if (GetSaveFlag(flags, SaveFlag.SavedFlags)) m_SavedFlags = reader.ReadEncodedInt(); //wea: 13/Mar/2007 Rare Factory if (GetSaveFlag(flags, SaveFlag.RareData)) m_RareData = (UInt32)reader.ReadInt(); if (m_Map != null && m_Parent == null) m_Map.OnEnter(this); break; } case 5: { //SaveFlag flags = (SaveFlag)reader.ReadInt(); LastMoved = reader.ReadDeltaTime(); if (GetSaveFlag(flags, SaveFlag.Direction)) m_Direction = (Direction)reader.ReadByte(); if (GetSaveFlag(flags, SaveFlag.Bounce)) m_Bounce = BounceInfo.Deserialize(reader); if (GetSaveFlag(flags, SaveFlag.LootType)) m_LootType = (LootType)reader.ReadByte(); if (GetSaveFlag(flags, SaveFlag.LocationFull)) m_Location = reader.ReadPoint3D(); if (GetSaveFlag(flags, SaveFlag.ItemID)) m_ItemID = reader.ReadInt(); if (GetSaveFlag(flags, SaveFlag.Hue)) m_Hue = reader.ReadInt(); if (GetSaveFlag(flags, SaveFlag.Amount)) m_Amount = reader.ReadInt(); else m_Amount = 1; if (GetSaveFlag(flags, SaveFlag.Layer)) m_Layer = (Layer)reader.ReadByte(); if (GetSaveFlag(flags, SaveFlag.Name)) m_Name = reader.ReadString(); if (GetSaveFlag(flags, SaveFlag.Parent)) { Serial parent = reader.ReadInt(); if (parent.IsMobile) m_Parent = World.FindMobile(parent); else if (parent.IsItem) m_Parent = World.FindItem(parent); else m_Parent = null; if (m_Parent == null && (parent.IsMobile || parent.IsItem)) Delete(); } if (GetSaveFlag(flags, SaveFlag.Items)) m_Items = reader.ReadItemList(); //else // m_Items = new ArrayList( 1 ); if (GetSaveFlag(flags, SaveFlag.IntWeight)) m_Weight = reader.ReadEncodedInt(); else if (GetSaveFlag(flags, SaveFlag.WeightNot1or0)) m_Weight = reader.ReadDouble(); else if (GetSaveFlag(flags, SaveFlag.WeightIs0)) m_Weight = 0.0; else m_Weight = 1.0; if (GetSaveFlag(flags, SaveFlag.Map)) m_Map = reader.ReadMap(); else m_Map = Map.Internal; if (GetSaveFlag(flags, SaveFlag.Visible)) SetFlag(ImplFlag.Visible, reader.ReadBool()); else SetFlag(ImplFlag.Visible, true); if (GetSaveFlag(flags, SaveFlag.Movable)) SetFlag(ImplFlag.Movable, reader.ReadBool()); else SetFlag(ImplFlag.Movable, true); if (GetSaveFlag(flags, SaveFlag.Stackable)) SetFlag(ImplFlag.Stackable, reader.ReadBool()); if (m_Map != null && m_Parent == null) m_Map.OnEnter(this); break; } case 4: // Just removed variables case 3: { m_Direction = (Direction)reader.ReadInt(); goto case 2; } case 2: { m_Bounce = BounceInfo.Deserialize(reader); LastMoved = reader.ReadDeltaTime(); goto case 1; } case 1: { m_LootType = (LootType)reader.ReadByte();//m_Newbied = reader.ReadBool(); goto case 0; } case 0: { m_Location = reader.ReadPoint3D(); m_ItemID = reader.ReadInt(); m_Hue = reader.ReadInt(); m_Amount = reader.ReadInt(); m_Layer = (Layer)reader.ReadByte(); m_Name = reader.ReadString(); Serial parent = reader.ReadInt(); if (parent.IsMobile) m_Parent = World.FindMobile(parent); else if (parent.IsItem) m_Parent = World.FindItem(parent); else m_Parent = null; if (m_Parent == null && (parent.IsMobile || parent.IsItem)) Delete(); int count = reader.ReadInt(); if (count > 0) { m_Items = new ArrayList(count); for (int i = 0; i < count; ++i) { Item item = reader.ReadItem(); if (item != null) m_Items.Add(item); } } m_Weight = reader.ReadDouble(); if (version <= 3) { /*m_TotalItems =*/ reader.ReadInt(); /*m_TotalWeight =*/ reader.ReadInt(); /*m_TotalGold =*/ reader.ReadInt(); } m_Map = reader.ReadMap(); SetFlag(ImplFlag.Visible, reader.ReadBool()); SetFlag(ImplFlag.Movable, reader.ReadBool()); if (version <= 3) /*m_Deleted =*/ reader.ReadBool(); Stackable = reader.ReadBool(); if (m_Map != null && m_Parent == null) m_Map.OnEnter(this); break; } } if (m_HeldBy != null) Timer.DelayCall(TimeSpan.Zero, new TimerCallback(FixHolding_Sandbox)); }