public bool Delete(Item item) { try { _ctx.Items.Remove(item); return true; } catch { return false; } }
public bool Insert(Item item) { try { _ctx.Items.Add(item); return true; } catch { return false; } }
public bool Update(Item oldItem, Item newItem) { try { _ctx.Entry(oldItem).CurrentValues.SetValues(newItem); return true; } catch { return false; } }
public virtual void AddProperties(Item item) { if (item == null || item.Deleted) { return; } if (User.IsOnline()) { item.SendInfoTo(User.NetState, true); } AddProperties(item.Serial); }
public override bool OnDragDrop(Mobile from, Item trashed) { if (from == null || trashed == null || trashed.Deleted || !IsAccessibleTo(from)) { return false; } if (this.IsBound() && !this.IsBoundTo(from)) { from.SendMessage(0x22, "That does not belong to you."); return false; } if (!this.IsBoundTo(from)) { this.CheckBinding( from, r => { switch (r) { case ItemBindResult.NoAccess: { from.SendMessage(0x22, "{0} must be bound to you before you can use it.", this.ResolveName(from.GetLanguage())); } break; } }, true, ConfirmBind, !ConfirmBind); from.SendMessage(0x22, "{0} must be bound to you before you can use it.", this.ResolveName(from.GetLanguage())); return false; } return base.OnDragDrop(from, trashed); }
public ItemModel Create(Item item) { return new ItemModel() { Id = item.Id, UserId = item.UserId, User = Create(item.User), Count = item.Count, Level = item.Level, LevelProgress = item.LevelProgress, ItemTemplate = Create(item.ItemTemplate), }; }
public void OnEnter(Item item) { Add(ref m_Items, item); }
public override void Deserialize(GenericReader reader) { base.Deserialize(reader); reader.ReadInt(); Original = reader.ReadItem(); if (Original == null) Delete(); }
public override bool IsItemProhibited(Server.Item Item) { return(false); }
public static void SendLocalizedMessageTo( Item from, Mobile to, int number, int hue ) { SendLocalizedMessageTo( from, to, number, "", hue ); }
public ItemClone(Item original) { Original = original; foreach (var property in (typeof(Item)).GetProperties()) if (property.CanRead && property.CanWrite) property.SetValue(this, property.GetValue(original, null), null); Movable = false; }
public static void SendLocalizedMessageTo( Item from, Mobile to, int number, string args, int hue ) { to.Send( new MessageLocalized( from.Serial, from.ItemID, MessageType.Regular, hue, 3, number, "", args ) ); }
public static void SendMessageTo( Item from, Mobile to, string text, int hue ) { to.Send( new UnicodeMessage( from.Serial, from.ItemID, MessageType.Regular, hue, 3, "ENU", "", text ) ); }
public void OnLeave(Item item) { Remove(ref m_Items, item); }
public BottleInscriberGump(Mobile from, object o) : base(0, 0) { m_Bottle = o as Item; m_From = from; AddPage(0); AddBackground(1, 9, 372, 144, 5054); AddBackground(11, 19, 352, 124, 3500); AddLabel(50, 27, 0, "Quel nom désirez vous lui donner ?"); AddImage(48, 49, 1141); AddTextEntry(57, 50, 91, 18, 0x000, 0, "Écrire ici"); AddButton(62, 85, 4023, 4025, 1, GumpButtonType.Reply, 0); AddButton(222, 85, 4020, 4022, 2, GumpButtonType.Reply, 0); AddLabel(97, 93, 0, "Ok"); AddLabel(258, 93, 0, "Annuler"); }
public static void RemoveItem( Item item ) { m_Items.Remove( item.Serial ); }
public static void Load() { if ( m_Loaded ) return; m_Loaded = true; m_LoadingType = null; Console.Write( "World: Loading..." ); Stopwatch watch = Stopwatch.StartNew(); m_Loading = true; _addQueue = new Queue<IEntity>(); _deleteQueue = new Queue<IEntity>(); int mobileCount = 0, itemCount = 0, guildCount = 0; object[] ctorArgs = new object[1]; Type[] ctorTypes = new Type[1] { typeof( Serial ) }; List<ItemEntry> items = new List<ItemEntry>(); List<MobileEntry> mobiles = new List<MobileEntry>(); List<GuildEntry> guilds = new List<GuildEntry>(); if ( File.Exists( MobileIndexPath ) && File.Exists( MobileTypesPath ) ) { using ( FileStream idx = new FileStream( MobileIndexPath, FileMode.Open, FileAccess.Read, FileShare.Read ) ) { BinaryReader idxReader = new BinaryReader( idx ); using ( FileStream tdb = new FileStream( MobileTypesPath, FileMode.Open, FileAccess.Read, FileShare.Read ) ) { BinaryReader tdbReader = new BinaryReader( tdb ); int count = tdbReader.ReadInt32(); ArrayList types = new ArrayList( count ); for ( int i = 0; i < count; ++i ) { string typeName = tdbReader.ReadString(); Type t = ScriptCompiler.FindTypeByFullName( typeName ); if ( t == null ) { Console.WriteLine( "failed" ); if ( !Core.Service ) { Console.WriteLine( "Error: Type '{0}' was not found. Delete all of those types? (y/n)", typeName ); if ( Console.ReadKey( true ).Key == ConsoleKey.Y ) { types.Add( null ); Console.Write( "World: Loading..." ); continue; } Console.WriteLine( "Types will not be deleted. An exception will be thrown." ); } else { Console.WriteLine( "Error: Type '{0}' was not found.", typeName ); } throw new Exception( String.Format( "Bad type '{0}'", typeName ) ); } ConstructorInfo ctor = t.GetConstructor( ctorTypes ); if ( ctor != null ) { types.Add( new object[] { ctor, null } ); } else { throw new Exception( String.Format( "Type '{0}' does not have a serialization constructor", t ) ); } } mobileCount = idxReader.ReadInt32(); m_Mobiles = new Dictionary<Serial, Mobile>( mobileCount ); for ( int i = 0; i < mobileCount; ++i ) { int typeID = idxReader.ReadInt32(); int serial = idxReader.ReadInt32(); long pos = idxReader.ReadInt64(); int length = idxReader.ReadInt32(); object[] objs = ( object[] ) types[typeID]; if ( objs == null ) continue; Mobile m = null; ConstructorInfo ctor = ( ConstructorInfo ) objs[0]; string typeName = ( string ) objs[1]; try { ctorArgs[0] = ( Serial ) serial; m = ( Mobile ) ( ctor.Invoke( ctorArgs ) ); } catch { } if ( m != null ) { mobiles.Add( new MobileEntry( m, typeID, typeName, pos, length ) ); AddMobile( m ); } } tdbReader.Close(); } idxReader.Close(); } } else { m_Mobiles = new Dictionary<Serial, Mobile>(); } if ( File.Exists( ItemIndexPath ) && File.Exists( ItemTypesPath ) ) { using ( FileStream idx = new FileStream( ItemIndexPath, FileMode.Open, FileAccess.Read, FileShare.Read ) ) { BinaryReader idxReader = new BinaryReader( idx ); using ( FileStream tdb = new FileStream( ItemTypesPath, FileMode.Open, FileAccess.Read, FileShare.Read ) ) { BinaryReader tdbReader = new BinaryReader( tdb ); int count = tdbReader.ReadInt32(); ArrayList types = new ArrayList( count ); for ( int i = 0; i < count; ++i ) { string typeName = tdbReader.ReadString(); Type t = ScriptCompiler.FindTypeByFullName( typeName ); if ( t == null ) { Console.WriteLine( "failed" ); if ( !Core.Service ) { Console.WriteLine( "Error: Type '{0}' was not found. Delete all of those types? (y/n)", typeName ); if ( Console.ReadKey( true ).Key == ConsoleKey.Y ) { types.Add( null ); Console.Write( "World: Loading..." ); continue; } Console.WriteLine( "Types will not be deleted. An exception will be thrown." ); } else { Console.WriteLine( "Error: Type '{0}' was not found.", typeName ); } throw new Exception( String.Format( "Bad type '{0}'", typeName ) ); } ConstructorInfo ctor = t.GetConstructor( ctorTypes ); if ( ctor != null ) { types.Add( new object[] { ctor, typeName } ); } else { throw new Exception( String.Format( "Type '{0}' does not have a serialization constructor", t ) ); } } itemCount = idxReader.ReadInt32(); m_Items = new Dictionary<Serial, Item>( itemCount ); for ( int i = 0; i < itemCount; ++i ) { int typeID = idxReader.ReadInt32(); int serial = idxReader.ReadInt32(); long pos = idxReader.ReadInt64(); int length = idxReader.ReadInt32(); object[] objs = ( object[] ) types[typeID]; if ( objs == null ) continue; Item item = null; ConstructorInfo ctor = ( ConstructorInfo ) objs[0]; string typeName = ( string ) objs[1]; try { ctorArgs[0] = ( Serial ) serial; item = ( Item ) ( ctor.Invoke( ctorArgs ) ); } catch { } if ( item != null ) { items.Add( new ItemEntry( item, typeID, typeName, pos, length ) ); AddItem( item ); } } tdbReader.Close(); } idxReader.Close(); } } else { m_Items = new Dictionary<Serial, Item>(); } if ( File.Exists( GuildIndexPath ) ) { using ( FileStream idx = new FileStream( GuildIndexPath, FileMode.Open, FileAccess.Read, FileShare.Read ) ) { BinaryReader idxReader = new BinaryReader( idx ); guildCount = idxReader.ReadInt32(); CreateGuildEventArgs createEventArgs = new CreateGuildEventArgs( -1 ); for ( int i = 0; i < guildCount; ++i ) { idxReader.ReadInt32();//no typeid for guilds int id = idxReader.ReadInt32(); long pos = idxReader.ReadInt64(); int length = idxReader.ReadInt32(); createEventArgs.Id = id; BaseGuild guild = EventSink.InvokeCreateGuild( createEventArgs ); if ( guild != null ) guilds.Add( new GuildEntry( guild, pos, length ) ); } idxReader.Close(); } } bool failedMobiles = false, failedItems = false, failedGuilds = false; Type failedType = null; Serial failedSerial = Serial.Zero; Exception failed = null; int failedTypeID = 0; if ( File.Exists( MobileDataPath ) ) { using ( FileStream bin = new FileStream( MobileDataPath, FileMode.Open, FileAccess.Read, FileShare.Read ) ) { BinaryFileReader reader = new BinaryFileReader( new BinaryReader( bin ) ); for ( int i = 0; i < mobiles.Count; ++i ) { MobileEntry entry = mobiles[i]; Mobile m = entry.Mobile; if ( m != null ) { reader.Seek( entry.Position, SeekOrigin.Begin ); try { m_LoadingType = entry.TypeName; m.Deserialize( reader ); if ( reader.Position != ( entry.Position + entry.Length ) ) throw new Exception( String.Format( "***** Bad serialize on {0} *****", m.GetType() ) ); } catch ( Exception e ) { mobiles.RemoveAt( i ); failed = e; failedMobiles = true; failedType = m.GetType(); failedTypeID = entry.TypeID; failedSerial = m.Serial; break; } } } reader.Close(); } } if ( !failedMobiles && File.Exists( ItemDataPath ) ) { using ( FileStream bin = new FileStream( ItemDataPath, FileMode.Open, FileAccess.Read, FileShare.Read ) ) { BinaryFileReader reader = new BinaryFileReader( new BinaryReader( bin ) ); for ( int i = 0; i < items.Count; ++i ) { ItemEntry entry = items[i]; Item item = entry.Item; if ( item != null ) { reader.Seek( entry.Position, SeekOrigin.Begin ); try { m_LoadingType = entry.TypeName; item.Deserialize( reader ); if ( reader.Position != ( entry.Position + entry.Length ) ) throw new Exception( String.Format( "***** Bad serialize on {0} *****", item.GetType() ) ); } catch ( Exception e ) { items.RemoveAt( i ); failed = e; failedItems = true; failedType = item.GetType(); failedTypeID = entry.TypeID; failedSerial = item.Serial; break; } } } reader.Close(); } } m_LoadingType = null; if ( !failedMobiles && !failedItems && File.Exists( GuildDataPath ) ) { using ( FileStream bin = new FileStream( GuildDataPath, FileMode.Open, FileAccess.Read, FileShare.Read ) ) { BinaryFileReader reader = new BinaryFileReader( new BinaryReader( bin ) ); for ( int i = 0; i < guilds.Count; ++i ) { GuildEntry entry = guilds[i]; BaseGuild g = entry.Guild; if ( g != null ) { reader.Seek( entry.Position, SeekOrigin.Begin ); try { g.Deserialize( reader ); if ( reader.Position != ( entry.Position + entry.Length ) ) throw new Exception( String.Format( "***** Bad serialize on Guild {0} *****", g.Id ) ); } catch ( Exception e ) { guilds.RemoveAt( i ); failed = e; failedGuilds = true; failedType = typeof( BaseGuild ); failedTypeID = g.Id; failedSerial = g.Id; break; } } } reader.Close(); } } if ( failedItems || failedMobiles || failedGuilds ) { Console.WriteLine( "An error was encountered while loading a saved object" ); Console.WriteLine( " - Type: {0}", failedType ); Console.WriteLine( " - Serial: {0}", failedSerial ); if ( !Core.Service ) { Console.WriteLine( "Delete the object? (y/n)" ); if ( Console.ReadKey( true ).Key == ConsoleKey.Y ) { if ( failedType != typeof( BaseGuild ) ) { Console.WriteLine( "Delete all objects of that type? (y/n)" ); if ( Console.ReadKey( true ).Key == ConsoleKey.Y ) { if ( failedMobiles ) { for ( int i = 0; i < mobiles.Count; ) { if ( mobiles[i].TypeID == failedTypeID ) mobiles.RemoveAt( i ); else ++i; } } else if ( failedItems ) { for ( int i = 0; i < items.Count; ) { if ( items[i].TypeID == failedTypeID ) items.RemoveAt( i ); else ++i; } } } } SaveIndex<MobileEntry>( mobiles, MobileIndexPath ); SaveIndex<ItemEntry>( items, ItemIndexPath ); SaveIndex<GuildEntry>( guilds, GuildIndexPath ); } Console.WriteLine( "After pressing return an exception will be thrown and the server will terminate." ); Console.ReadLine(); } else { Console.WriteLine( "An exception will be thrown and the server will terminate." ); } throw new Exception( String.Format( "Load failed (items={0}, mobiles={1}, guilds={2}, type={3}, serial={4})", failedItems, failedMobiles, failedGuilds, failedType, failedSerial ), failed ); } EventSink.InvokeWorldLoad(); m_Loading = false; ProcessSafetyQueues(); foreach ( Item item in m_Items.Values ) { if ( item.Parent == null ) item.UpdateTotals(); item.ClearProperties(); } foreach ( Mobile m in m_Mobiles.Values ) { m.UpdateRegion(); // Is this really needed? m.UpdateTotals(); m.ClearProperties(); } watch.Stop(); Console.WriteLine( "done ({1} items, {2} mobiles) ({0:F2} seconds)", watch.Elapsed.TotalSeconds, m_Items.Count, m_Mobiles.Count ); }
public virtual void GetContextMenuEntries(Mobile from, List<Server.ContextMenus.ContextMenuEntry> list, Item item) { }