From f95101c201116b84f9b106b7c13ce88ed1777ec6 Mon Sep 17 00:00:00 2001 From: mark Date: Fri, 19 Jan 2007 22:10:11 +0000 Subject: [PATCH] lots of little stuff, but mostly bank optimization, due to the weirdness of the calls --- Scripts/Commands/Add.cs | 49 +++--- Scripts/Commands/Handlers.cs | 17 +- Scripts/Commands/SignParser.cs | 10 +- Scripts/Commands/Wipe.cs | 15 +- Scripts/Context Menus/OpenBankEntry.cs | 5 +- Scripts/Engines/Plants/PlantItem.cs | 6 +- Scripts/Engines/Plants/PlantSystem.cs | 6 +- .../Quests/Collector/Mobiles/Impresario.cs | 4 +- .../Quests/The Summoning/TheSummoningQuest.cs | 5 +- Scripts/Engines/Spawner/Spawner.cs | 71 ++++---- Scripts/Gumps/HouseDemolishGump.cs | 2 +- Scripts/Gumps/PlayerVendorGumps.cs | 12 +- Scripts/Gumps/VendorInventoryGump.cs | 2 +- Scripts/Items/Deeds/CommodityDeed.cs | 4 +- Scripts/Items/Misc/BankCheck.cs | 2 +- Scripts/Items/Misc/Corpses/Corpse.cs | 2 +- .../Items/Special/Solen Items/BagOfSending.cs | 2 +- Scripts/Misc/CharacterCreation.cs | 158 +++++++++--------- Scripts/Mobiles/Townfolk/Banker.cs | 21 +-- Scripts/Mobiles/Townfolk/BaseEscortable.cs | 2 +- Scripts/Mobiles/Vendors/BaseVendor.cs | 2 +- Scripts/Mobiles/Vendors/NPC/AnimalTrainer.cs | 2 +- Scripts/Multis/BaseHouse.cs | 2 +- Scripts/Multis/Boats/BaseBoat.cs | 2 +- Server/Effects.cs | 5 +- Server/IEntity.cs | 49 +++--- Server/Item.cs | 12 +- Server/Mobile.cs | 12 +- Server/World.cs | 15 +- 29 files changed, 214 insertions(+), 282 deletions(-) diff --git a/Scripts/Commands/Add.cs b/Scripts/Commands/Add.cs index b98d2e18f..2366b1f0e 100644 --- a/Scripts/Commands/Add.cs +++ b/Scripts/Commands/Add.cs @@ -76,8 +76,7 @@ namespace Server.Commands Type type = ScriptCompiler.FindTypeByName( name ); - if ( type == null ) - { + if ( !IsEntity( type ) ) { from.SendMessage( "No type with that name was found." ); return; } @@ -239,7 +238,7 @@ namespace Server.Commands } } - public static object Build( Mobile from, ConstructorInfo ctor, object[] values, string[,] props, PropertyInfo[] realProps, ref bool sendError ) + public static IEntity Build( Mobile from, ConstructorInfo ctor, object[] values, string[,] props, PropertyInfo[] realProps, ref bool sendError ) { object built = ctor.Invoke( values ); @@ -267,7 +266,7 @@ namespace Server.Commands sendError = false; } - return built; + return (IEntity)built; } public static int Build( Mobile from, Point3D start, Point3D end, ConstructorInfo ctor, object[] values, string[,] props, PropertyInfo[] realProps, List packs ) @@ -290,23 +289,16 @@ namespace Server.Commands { for ( int i = 0; i < packs.Count; ++i ) { - object built = Build( from, ctor, values, props, realProps, ref sendError ); + IEntity built = Build( from, ctor, values, props, realProps, ref sendError ); - if( built is IEntity ) - sb.AppendFormat( "0x{0:X}; ", ((IEntity)built).Serial.Value ); - else - continue; - - if ( built is Item ) - { + sb.AppendFormat( "0x{0:X}; ", built.Serial.Value ); + + if ( built is Item ) { Container pack = packs[i]; - pack.DropItem( (Item)built ); } - else if ( built is Mobile ) - { + else if ( built is Mobile ) { Mobile m = (Mobile)built; - m.MoveToWorld( new Point3D( start.X, start.Y, start.Z ), map ); } } @@ -317,23 +309,16 @@ namespace Server.Commands { for ( int y = start.Y; y <= end.Y; ++y ) { - object built = Build( from, ctor, values, props, realProps, ref sendError ); + IEntity built = Build( from, ctor, values, props, realProps, ref sendError ); - if( built is IEntity ) - sb.AppendFormat( "0x{0:X}; ", ((IEntity)built).Serial.Value ); - else - continue; + sb.AppendFormat( "0x{0:X}; ", built.Serial.Value ); - if ( built is Item ) - { + if ( built is Item ) { Item item = (Item)built; - item.MoveToWorld( new Point3D( x, y, start.Z ), map ); } - else if ( built is Mobile ) - { + else if ( built is Mobile ) { Mobile m = (Mobile)built; - m.MoveToWorld( new Point3D( x, y, start.Z ), map ); } } @@ -419,7 +404,8 @@ namespace Server.Commands else if ( p is Mobile ) p = ((Mobile)p).Location; - Add.Invoke( from, new Point3D( p ), new Point3D( p ), m_Args ); + Point3D point = new Point3D( p ); + Add.Invoke( from, point, point, m_Args ); } } } @@ -529,6 +515,13 @@ namespace Server.Commands } } + private static Type m_EntityType = typeof( IEntity ); + + public static bool IsEntity( Type t ) + { + return m_EntityType.IsAssignableFrom( t ); + } + private static Type m_ConstructableType = typeof( ConstructableAttribute ); public static bool IsConstructable( ConstructorInfo ctor ) diff --git a/Scripts/Commands/Handlers.cs b/Scripts/Commands/Handlers.cs index 88b79f332..88d052f72 100644 --- a/Scripts/Commands/Handlers.cs +++ b/Scripts/Commands/Handlers.cs @@ -205,21 +205,14 @@ namespace Server.Commands { if ( okay ) { - ArrayList list = (ArrayList)state; + List list = (List)state; CommandLogging.WriteLine( from, "{0} {1} deleting {2} objects", from.AccessLevel, CommandLogging.Format( from ), list.Count ); NetState.Pause(); for ( int i = 0; i < list.Count; ++i ) - { - object obj = list[i]; - - if ( obj is Item ) - ((Item)obj).Delete(); - else if ( obj is Mobile ) - ((Mobile)obj).Delete(); - } + list[i].Delete(); NetState.Resume(); @@ -243,19 +236,15 @@ namespace Server.Commands return; } - ArrayList list = new ArrayList(); + List list = new List(); foreach ( Item item in World.Items.Values ) - { if ( item.Map == map && item.Parent == null ) list.Add( item ); - } foreach ( Mobile m in World.Mobiles.Values ) - { if ( m.Map == map && !m.Player ) list.Add( m ); - } if ( list.Count > 0 ) { diff --git a/Scripts/Commands/SignParser.cs b/Scripts/Commands/SignParser.cs index efd8b9c65..673208143 100644 --- a/Scripts/Commands/SignParser.cs +++ b/Scripts/Commands/SignParser.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.IO; using Server; using Server.Items; @@ -42,7 +42,7 @@ namespace Server.Commands if ( File.Exists( cfg ) ) { - ArrayList list = new ArrayList(); + List list = new List(); from.SendMessage( "Generating signs, please wait." ); using ( StreamReader ip = new StreamReader( cfg ) ) @@ -71,7 +71,7 @@ namespace Server.Commands for ( int i = 0; i < list.Count; ++i ) { - SignEntry e = (SignEntry)list[i]; + SignEntry e = list[i]; Map[] maps = null; switch ( e.m_Map ) @@ -96,7 +96,7 @@ namespace Server.Commands } } - private static Queue m_ToDelete = new Queue(); + private static Queue m_ToDelete = new Queue(); public static void Add_Static( int itemID, Point3D location, Map map, string name ) { @@ -111,7 +111,7 @@ namespace Server.Commands eable.Free(); while ( m_ToDelete.Count > 0 ) - ((Item)m_ToDelete.Dequeue()).Delete(); + m_ToDelete.Dequeue().Delete(); Item sign; diff --git a/Scripts/Commands/Wipe.cs b/Scripts/Commands/Wipe.cs index 6d8bfc2a4..c594ee70a 100644 --- a/Scripts/Commands/Wipe.cs +++ b/Scripts/Commands/Wipe.cs @@ -1,9 +1,9 @@ using System; -using System.Collections; +using System.Collections.Generic; using Server; -using Server.Targeting; using Server.Items; using Server.Multis; +using Server.Targeting; namespace Server.Commands { @@ -72,7 +72,7 @@ namespace Server.Commands bool multis = ( (type & WipeType.Multis) != 0 ); bool items = ( (type & WipeType.Items) != 0 ); - ArrayList toDelete = new ArrayList(); + List toDelete = new List(); Rectangle2D rect = new Rectangle2D( start.X, start.Y, end.X - start.X + 1, end.Y - start.Y + 1 ); @@ -87,7 +87,7 @@ namespace Server.Commands else return; - foreach ( object obj in eable ) + foreach ( IEntity obj in eable ) { if ( items && (obj is Item) && !((obj is BaseMulti) || (obj is HouseSign)) ) toDelete.Add( obj ); @@ -100,12 +100,7 @@ namespace Server.Commands eable.Free(); for ( int i = 0; i < toDelete.Count; ++i ) - { - if ( toDelete[i] is Item ) - ((Item)toDelete[i]).Delete(); - else if ( toDelete[i] is Mobile ) - ((Mobile)toDelete[i]).Delete(); - } + toDelete[i].Delete(); } } } \ No newline at end of file diff --git a/Scripts/Context Menus/OpenBankEntry.cs b/Scripts/Context Menus/OpenBankEntry.cs index f2b4eff00..17a8a70ec 100644 --- a/Scripts/Context Menus/OpenBankEntry.cs +++ b/Scripts/Context Menus/OpenBankEntry.cs @@ -23,10 +23,7 @@ namespace Server.ContextMenus } else { - BankBox box = this.Owner.From.BankBox; - - if ( box != null ) - box.Open(); + this.Owner.From.BankBox.Open(); } } } diff --git a/Scripts/Engines/Plants/PlantItem.cs b/Scripts/Engines/Plants/PlantItem.cs index c0a2a6b14..599eba375 100644 --- a/Scripts/Engines/Plants/PlantItem.cs +++ b/Scripts/Engines/Plants/PlantItem.cs @@ -154,7 +154,9 @@ namespace Server.Engines.Plants if ( owner.Backpack != null && IsChildOf( owner.Backpack ) ) return true; - if ( owner.BankBox != null && IsChildOf( owner.BankBox ) ) + + BankBox bank = owner.FindBankNoCreate(); + if ( bank != null && IsChildOf( bank ) ) return true; return false; @@ -317,7 +319,7 @@ namespace Server.Engines.Plants public bool IsUsableBy( Mobile from ) { Item root = RootParent as Item; - return IsChildOf( from.Backpack ) || IsChildOf( from.BankBox ) || IsLockedDown && IsAccessibleTo( from ) || root != null && root.IsSecure && root.IsAccessibleTo( from ); + return IsChildOf( from.Backpack ) || IsChildOf( from.FindBankNoCreate() ) || IsLockedDown && IsAccessibleTo( from ) || root != null && root.IsSecure && root.IsAccessibleTo( from ); } public override void OnDoubleClick( Mobile from ) diff --git a/Scripts/Engines/Plants/PlantSystem.cs b/Scripts/Engines/Plants/PlantSystem.cs index 7761e6190..08b4585fc 100644 --- a/Scripts/Engines/Plants/PlantSystem.cs +++ b/Scripts/Engines/Plants/PlantSystem.cs @@ -400,9 +400,11 @@ namespace Server.Engines.Plants } } - if ( from.BankBox != null ) + BankBox bank = from.FindBankNoCreate(); + + if ( bank != null ) { - Item[] plants = from.BankBox.FindItemsByType( typeof( PlantItem ) ); + Item[] plants = bank.FindItemsByType( typeof( PlantItem ) ); foreach ( PlantItem plant in plants ) { diff --git a/Scripts/Engines/Quests/Collector/Mobiles/Impresario.cs b/Scripts/Engines/Quests/Collector/Mobiles/Impresario.cs index 026808690..adf4e8952 100644 --- a/Scripts/Engines/Quests/Collector/Mobiles/Impresario.cs +++ b/Scripts/Engines/Quests/Collector/Mobiles/Impresario.cs @@ -147,7 +147,9 @@ namespace Server.Engines.Quests.Collector if ( obj != null && !obj.Completed ) { - if ( player.BankBox != null && player.BankBox.ConsumeTotal( typeof( Gold ), 10 ) ) + BankBox bank = player.FindBankNoCreate(); + + if ( bank != null && bank.ConsumeTotal( typeof( Gold ), 10 ) ) { obj.Complete(); } diff --git a/Scripts/Engines/Quests/The Summoning/TheSummoningQuest.cs b/Scripts/Engines/Quests/The Summoning/TheSummoningQuest.cs index d29f610ef..b92b967ff 100644 --- a/Scripts/Engines/Quests/The Summoning/TheSummoningQuest.cs +++ b/Scripts/Engines/Quests/The Summoning/TheSummoningQuest.cs @@ -131,10 +131,7 @@ namespace Server.Engines.Quests.Doom if ( obj != null && obj.CurProgress > 0 ) { - BankBox box = From.BankBox; - - if ( box != null ) - box.DropItem( new DaemonBone( obj.CurProgress ) ); + From.BankBox.DropItem( new DaemonBone( obj.CurProgress ) ); From.SendLocalizedMessage( 1050030 ); // The Daemon bones that you have thus far given to Victoria have been returned to you. } diff --git a/Scripts/Engines/Spawner/Spawner.cs b/Scripts/Engines/Spawner/Spawner.cs index b7e776aef..0b15b9206 100644 --- a/Scripts/Engines/Spawner/Spawner.cs +++ b/Scripts/Engines/Spawner/Spawner.cs @@ -1,9 +1,9 @@ using System; -using System.IO; using System.Collections; +using System.Collections.Generic; +using System.IO; using Server; using Server.Items; -using System.Collections.Generic; namespace Server.Mobiles { @@ -16,7 +16,7 @@ namespace Server.Mobiles private TimeSpan m_MinDelay; private TimeSpan m_MaxDelay; private List m_CreaturesName; - private ArrayList m_Creatures; + private List m_Creatures; private DateTime m_End; private InternalTimer m_Timer; private bool m_Running; @@ -188,7 +188,7 @@ namespace Server.Mobiles m_Team = team; m_HomeRange = homeRange; m_CreaturesName = creaturesName; - m_Creatures = new ArrayList(); + m_Creatures = new List(); DoTimer( TimeSpan.FromSeconds( 1 ) ); } @@ -222,7 +222,7 @@ namespace Server.Mobiles list.Add( 1060661, "speed\t{0} to {1}", m_MinDelay, m_MaxDelay ); // ~1_val~: ~2_val~ for ( int i = 0; i < 2 && i < m_CreaturesName.Count; ++i ) - list.Add( 1060662 + i, "{0}\t{1}", m_CreaturesName[i], CountCreatures( (string)m_CreaturesName[i] ) ); + list.Add( 1060662 + i, "{0}\t{1}", m_CreaturesName[i], CountCreatures( m_CreaturesName[i] ) ); } else { @@ -267,11 +267,11 @@ namespace Server.Mobiles for ( int i = 0; i < m_Creatures.Count; ++i ) { - object o = m_Creatures[i]; + IEntity e = m_Creatures[i]; - if ( o is Item ) + if ( e is Item ) { - Item item = (Item)o; + Item item = (Item)e; if ( item.Deleted || item.Parent != null ) { @@ -280,9 +280,9 @@ namespace Server.Mobiles removed = true; } } - else if ( o is Mobile ) + else if ( e is Mobile ) { - Mobile m = (Mobile)o; + Mobile m = (Mobile)e; if ( m.Deleted ) { @@ -292,7 +292,8 @@ namespace Server.Mobiles } else if ( m is BaseCreature ) { - if ( ((BaseCreature)m).Controlled || ((BaseCreature)m).IsStabled ) + BaseCreature bc = (BaseCreature)m; + if ( bc.Controlled || bc.IsStabled ) { m_Creatures.RemoveAt( i ); --i; @@ -353,7 +354,7 @@ namespace Server.Mobiles { for ( int i = 0; i < m_CreaturesName.Count; i++ ) { - if ( (string)m_CreaturesName[i] == creatureName ) + if ( m_CreaturesName[i] == creatureName ) { Spawn( i ); break; @@ -373,7 +374,7 @@ namespace Server.Mobiles if ( m_Creatures.Count >= m_Count ) return; - Type type = SpawnerType.GetType( (string)m_CreaturesName[index] ); + Type type = SpawnerType.GetType( m_CreaturesName[index] ); if ( type != null ) { @@ -525,19 +526,12 @@ namespace Server.Mobiles { Defrag(); - creatureName = creatureName.ToLower(); - for ( int i = 0; i < m_Creatures.Count; ++i ) { - object o = m_Creatures[i]; + IEntity e = m_Creatures[i]; - if ( Insensitive.Equals( creatureName, o.GetType().Name ) ) - { - if ( o is Item ) - ((Item)o).Delete(); - else if ( o is Mobile ) - ((Mobile)o).Delete(); - } + if ( Insensitive.Equals( creatureName, e.GetType().Name ) ) + e.Delete(); } InvalidateProperties(); @@ -548,14 +542,7 @@ namespace Server.Mobiles Defrag(); for ( int i = 0; i < m_Creatures.Count; ++i ) - { - object o = m_Creatures[i]; - - if ( o is Item ) - ((Item)o).Delete(); - else if ( o is Mobile ) - ((Mobile)o).Delete(); - } + m_Creatures[i].Delete(); InvalidateProperties(); } @@ -566,17 +553,17 @@ namespace Server.Mobiles for ( int i = 0; i < m_Creatures.Count; ++i ) { - object o = m_Creatures[i]; + IEntity e = m_Creatures[i]; - if ( o is Mobile ) + if ( e is Mobile ) { - Mobile m = (Mobile)o; + Mobile m = (Mobile)e; m.MoveToWorld( Location, Map ); } - else if ( o is Item ) + else if ( e is Item ) { - Item item = (Item)o; + Item item = (Item)e; item.MoveToWorld( Location, Map ); } @@ -622,12 +609,12 @@ namespace Server.Mobiles for ( int i = 0; i < m_Creatures.Count; ++i ) { - object o = m_Creatures[i]; + IEntity e = m_Creatures[i]; - if ( o is Item ) - writer.Write( (Item)o ); - else if ( o is Mobile ) - writer.Write( (Mobile)o ); + if ( e is Item ) + writer.Write( (Item)e ); + else if ( e is Mobile ) + writer.Write( (Mobile)e ); else writer.Write( Serial.MinusOne ); } @@ -699,7 +686,7 @@ namespace Server.Mobiles int count = reader.ReadInt(); - m_Creatures = new ArrayList( count ); + m_Creatures = new List( count ); for ( int i = 0; i < count; ++i ) { diff --git a/Scripts/Gumps/HouseDemolishGump.cs b/Scripts/Gumps/HouseDemolishGump.cs index 7d8bde4ac..276da3ba7 100644 --- a/Scripts/Gumps/HouseDemolishGump.cs +++ b/Scripts/Gumps/HouseDemolishGump.cs @@ -109,7 +109,7 @@ namespace Server.Gumps { BankBox box = m_Mobile.BankBox; - if ( box != null && box.TryDropItem( m_Mobile, toGive, false ) ) + if ( box.TryDropItem( m_Mobile, toGive, false ) ) { if ( toGive is BankCheck ) m_Mobile.SendLocalizedMessage( 1060397, ((BankCheck)toGive).Worth.ToString() ); // ~1_AMOUNT~ gold has been deposited into your bank box. diff --git a/Scripts/Gumps/PlayerVendorGumps.cs b/Scripts/Gumps/PlayerVendorGumps.cs index 86b062fc5..d7850782f 100644 --- a/Scripts/Gumps/PlayerVendorGumps.cs +++ b/Scripts/Gumps/PlayerVendorGumps.cs @@ -66,8 +66,10 @@ namespace Server.Gumps if ( from.Backpack != null ) totalGold += from.Backpack.GetAmount( typeof( Gold ) ); - if ( from.BankBox != null ) - totalGold += from.BankBox.GetAmount( typeof( Gold ) ); + BankBox bank = from.FindBankNoCreate(); + + if ( bank != null ) + totalGold += bank.GetAmount( typeof( Gold ) ); if ( totalGold < m_VI.Price ) { @@ -83,9 +85,9 @@ namespace Server.Gumps if ( from.Backpack != null ) leftPrice -= from.Backpack.ConsumeUpTo( typeof( Gold ), leftPrice ); - - if ( leftPrice > 0 && from.BankBox != null ) - from.BankBox.ConsumeUpTo( typeof( Gold ), leftPrice ); + + if ( leftPrice > 0 && bank != null ) + bank.ConsumeUpTo( typeof( Gold ), leftPrice ); m_Vendor.HoldGold += m_VI.Price; diff --git a/Scripts/Gumps/VendorInventoryGump.cs b/Scripts/Gumps/VendorInventoryGump.cs index 5659b0dfb..b683b87c9 100644 --- a/Scripts/Gumps/VendorInventoryGump.cs +++ b/Scripts/Gumps/VendorInventoryGump.cs @@ -90,7 +90,7 @@ namespace Server.Gumps inventory.Items.RemoveAt( i ); givenToBackpack += 1 + item.TotalItems; } - else if ( from.BankBox != null && from.BankBox.TryDropItem( from, item, false ) ) + else if ( from.BankBox.TryDropItem( from, item, false ) ) { inventory.Items.RemoveAt( i ); givenToBankBox += 1 + item.TotalItems; diff --git a/Scripts/Items/Deeds/CommodityDeed.cs b/Scripts/Items/Deeds/CommodityDeed.cs index b2cfcd86f..7d1385591 100644 --- a/Scripts/Items/Deeds/CommodityDeed.cs +++ b/Scripts/Items/Deeds/CommodityDeed.cs @@ -115,7 +115,7 @@ namespace Server.Items { int number; - BankBox box = from.BankBox; + BankBox box = from.FindBankNoCreate(); if ( m_Commodity != null ) { @@ -169,7 +169,7 @@ namespace Server.Items } else if ( targeted is Item ) { - BankBox box = from.BankBox; + BankBox box = from.FindBankNoCreate(); if ( box != null && m_Deed.IsChildOf( box ) && ((Item)targeted).IsChildOf( box ) ) { diff --git a/Scripts/Items/Misc/BankCheck.cs b/Scripts/Items/Misc/BankCheck.cs index 0ab54c4ba..e1f214755 100644 --- a/Scripts/Items/Misc/BankCheck.cs +++ b/Scripts/Items/Misc/BankCheck.cs @@ -78,7 +78,7 @@ namespace Server.Items public override void OnDoubleClick( Mobile from ) { - BankBox box = from.BankBox; + BankBox box = from.FindBankNoCreate(); if ( box != null && IsChildOf( box ) ) { diff --git a/Scripts/Items/Misc/Corpses/Corpse.cs b/Scripts/Items/Misc/Corpses/Corpse.cs index 10a3da35b..fa53a8711 100644 --- a/Scripts/Items/Misc/Corpses/Corpse.cs +++ b/Scripts/Items/Misc/Corpses/Corpse.cs @@ -392,7 +392,7 @@ namespace Server.Items writer.Write( count ); - for ( int i = 0; i < list.Count; ++i ) + for ( int i = 0; i < count; ++i ) { KeyValuePair kvp = list[i]; Item item = kvp.Key; diff --git a/Scripts/Items/Special/Solen Items/BagOfSending.cs b/Scripts/Items/Special/Solen Items/BagOfSending.cs index ea4b51419..6964d0cee 100644 --- a/Scripts/Items/Special/Solen Items/BagOfSending.cs +++ b/Scripts/Items/Special/Solen Items/BagOfSending.cs @@ -215,7 +215,7 @@ namespace Server.Items { from.SendLocalizedMessage( 1062089 ); // You cannot use that here. } - else if ( from.BankBox == null || !from.BankBox.TryDropItem( from, item, false ) ) + else if ( !from.BankBox.TryDropItem( from, item, false ) ) { MessageHelper.SendLocalizedMessageTo( m_Bag, from, 1054110, 0x59 ); // Your bank box is full. } diff --git a/Scripts/Misc/CharacterCreation.cs b/Scripts/Misc/CharacterCreation.cs index 8b68eb7d3..c7f2c0bf5 100644 --- a/Scripts/Misc/CharacterCreation.cs +++ b/Scripts/Misc/CharacterCreation.cs @@ -62,9 +62,6 @@ namespace Server.Misc { BankBox bank = m.BankBox; - if ( bank == null ) - return; - // The new AOS bankboxes don't have powerscrolls, they are automatically 'applied': for ( int i = 0; i < PowerScroll.Skills.Length; ++i ) @@ -431,107 +428,104 @@ namespace Server.Misc BankBox bank = m.BankBox; - if ( bank != null ) - { - bank.DropItem( new BankCheck( 1000000 ) ); + bank.DropItem( new BankCheck( 1000000 ) ); - // Full spellbook - Spellbook book = new Spellbook(); + // Full spellbook + Spellbook book = new Spellbook(); - book.Content = ulong.MaxValue; + book.Content = ulong.MaxValue; - bank.DropItem( book ); + bank.DropItem( book ); - Bag bag = new Bag(); + Bag bag = new Bag(); - for ( int i = 0; i < 5; ++i ) - bag.DropItem( new Moonstone( MoonstoneType.Felucca ) ); + for ( int i = 0; i < 5; ++i ) + bag.DropItem( new Moonstone( MoonstoneType.Felucca ) ); - // Felucca moonstones - bank.DropItem( bag ); + // Felucca moonstones + bank.DropItem( bag ); - bag = new Bag(); + bag = new Bag(); - for ( int i = 0; i < 5; ++i ) - bag.DropItem( new Moonstone( MoonstoneType.Trammel ) ); + for ( int i = 0; i < 5; ++i ) + bag.DropItem( new Moonstone( MoonstoneType.Trammel ) ); - // Trammel moonstones - bank.DropItem( bag ); + // Trammel moonstones + bank.DropItem( bag ); - // Treasure maps - bank.DropItem( new TreasureMap( 1, Map.Trammel ) ); - bank.DropItem( new TreasureMap( 2, Map.Trammel ) ); - bank.DropItem( new TreasureMap( 3, Map.Trammel ) ); - bank.DropItem( new TreasureMap( 4, Map.Trammel ) ); - bank.DropItem( new TreasureMap( 5, Map.Trammel ) ); + // Treasure maps + bank.DropItem( new TreasureMap( 1, Map.Trammel ) ); + bank.DropItem( new TreasureMap( 2, Map.Trammel ) ); + bank.DropItem( new TreasureMap( 3, Map.Trammel ) ); + bank.DropItem( new TreasureMap( 4, Map.Trammel ) ); + bank.DropItem( new TreasureMap( 5, Map.Trammel ) ); - // Bag containing 50 of each reagent - bank.DropItem( new BagOfReagents( 50 ) ); + // Bag containing 50 of each reagent + bank.DropItem( new BagOfReagents( 50 ) ); - // Craft tools - bank.DropItem( MakeNewbie( new Scissors() ) ); - bank.DropItem( MakeNewbie( new SewingKit( 1000 ) ) ); - bank.DropItem( MakeNewbie( new SmithHammer( 1000 ) ) ); - bank.DropItem( MakeNewbie( new FletcherTools( 1000 ) ) ); - bank.DropItem( MakeNewbie( new DovetailSaw( 1000 ) ) ); - bank.DropItem( MakeNewbie( new MortarPestle( 1000 ) ) ); - bank.DropItem( MakeNewbie( new ScribesPen( 1000 ) ) ); - bank.DropItem( MakeNewbie( new TinkerTools( 1000 ) ) ); + // Craft tools + bank.DropItem( MakeNewbie( new Scissors() ) ); + bank.DropItem( MakeNewbie( new SewingKit( 1000 ) ) ); + bank.DropItem( MakeNewbie( new SmithHammer( 1000 ) ) ); + bank.DropItem( MakeNewbie( new FletcherTools( 1000 ) ) ); + bank.DropItem( MakeNewbie( new DovetailSaw( 1000 ) ) ); + bank.DropItem( MakeNewbie( new MortarPestle( 1000 ) ) ); + bank.DropItem( MakeNewbie( new ScribesPen( 1000 ) ) ); + bank.DropItem( MakeNewbie( new TinkerTools( 1000 ) ) ); - // A few dye tubs - bank.DropItem( new Dyes() ); - bank.DropItem( new DyeTub() ); - bank.DropItem( new DyeTub() ); - bank.DropItem( new BlackDyeTub() ); + // A few dye tubs + bank.DropItem( new Dyes() ); + bank.DropItem( new DyeTub() ); + bank.DropItem( new DyeTub() ); + bank.DropItem( new BlackDyeTub() ); - DyeTub darkRedTub = new DyeTub(); + DyeTub darkRedTub = new DyeTub(); - darkRedTub.DyedHue = 0x485; - darkRedTub.Redyable = false; + darkRedTub.DyedHue = 0x485; + darkRedTub.Redyable = false; - bank.DropItem( darkRedTub ); + bank.DropItem( darkRedTub ); - // Some food - bank.DropItem( MakeNewbie( new Apple( 1000 ) ) ); + // Some food + bank.DropItem( MakeNewbie( new Apple( 1000 ) ) ); - // Resources - bank.DropItem( MakeNewbie( new Feather( 1000 ) ) ); - bank.DropItem( MakeNewbie( new BoltOfCloth( 1000 ) ) ); - bank.DropItem( MakeNewbie( new BlankScroll( 1000 ) ) ); - bank.DropItem( MakeNewbie( new Hides( 1000 ) ) ); - bank.DropItem( MakeNewbie( new Bandage( 1000 ) ) ); - bank.DropItem( MakeNewbie( new Bottle( 1000 ) ) ); - bank.DropItem( MakeNewbie( new Log( 1000 ) ) ); + // Resources + bank.DropItem( MakeNewbie( new Feather( 1000 ) ) ); + bank.DropItem( MakeNewbie( new BoltOfCloth( 1000 ) ) ); + bank.DropItem( MakeNewbie( new BlankScroll( 1000 ) ) ); + bank.DropItem( MakeNewbie( new Hides( 1000 ) ) ); + bank.DropItem( MakeNewbie( new Bandage( 1000 ) ) ); + bank.DropItem( MakeNewbie( new Bottle( 1000 ) ) ); + bank.DropItem( MakeNewbie( new Log( 1000 ) ) ); - bank.DropItem( MakeNewbie( new IronIngot( 5000 ) ) ); - bank.DropItem( MakeNewbie( new DullCopperIngot( 5000 ) ) ); - bank.DropItem( MakeNewbie( new ShadowIronIngot( 5000 ) ) ); - bank.DropItem( MakeNewbie( new CopperIngot( 5000 ) ) ); - bank.DropItem( MakeNewbie( new BronzeIngot( 5000 ) ) ); - bank.DropItem( MakeNewbie( new GoldIngot( 5000 ) ) ); - bank.DropItem( MakeNewbie( new AgapiteIngot( 5000 ) ) ); - bank.DropItem( MakeNewbie( new VeriteIngot( 5000 ) ) ); - bank.DropItem( MakeNewbie( new ValoriteIngot( 5000 ) ) ); + bank.DropItem( MakeNewbie( new IronIngot( 5000 ) ) ); + bank.DropItem( MakeNewbie( new DullCopperIngot( 5000 ) ) ); + bank.DropItem( MakeNewbie( new ShadowIronIngot( 5000 ) ) ); + bank.DropItem( MakeNewbie( new CopperIngot( 5000 ) ) ); + bank.DropItem( MakeNewbie( new BronzeIngot( 5000 ) ) ); + bank.DropItem( MakeNewbie( new GoldIngot( 5000 ) ) ); + bank.DropItem( MakeNewbie( new AgapiteIngot( 5000 ) ) ); + bank.DropItem( MakeNewbie( new VeriteIngot( 5000 ) ) ); + bank.DropItem( MakeNewbie( new ValoriteIngot( 5000 ) ) ); - // Reagents - bank.DropItem( MakeNewbie( new BlackPearl( 1000 ) ) ); - bank.DropItem( MakeNewbie( new Bloodmoss( 1000 ) ) ); - bank.DropItem( MakeNewbie( new Garlic( 1000 ) ) ); - bank.DropItem( MakeNewbie( new Ginseng( 1000 ) ) ); - bank.DropItem( MakeNewbie( new MandrakeRoot( 1000 ) ) ); - bank.DropItem( MakeNewbie( new Nightshade( 1000 ) ) ); - bank.DropItem( MakeNewbie( new SulfurousAsh( 1000 ) ) ); - bank.DropItem( MakeNewbie( new SpidersSilk( 1000 ) ) ); + // Reagents + bank.DropItem( MakeNewbie( new BlackPearl( 1000 ) ) ); + bank.DropItem( MakeNewbie( new Bloodmoss( 1000 ) ) ); + bank.DropItem( MakeNewbie( new Garlic( 1000 ) ) ); + bank.DropItem( MakeNewbie( new Ginseng( 1000 ) ) ); + bank.DropItem( MakeNewbie( new MandrakeRoot( 1000 ) ) ); + bank.DropItem( MakeNewbie( new Nightshade( 1000 ) ) ); + bank.DropItem( MakeNewbie( new SulfurousAsh( 1000 ) ) ); + bank.DropItem( MakeNewbie( new SpidersSilk( 1000 ) ) ); - // Some extra starting gold - bank.DropItem( MakeNewbie( new Gold( 9000 ) ) ); + // Some extra starting gold + bank.DropItem( MakeNewbie( new Gold( 9000 ) ) ); - // 5 blank recall runes - for ( int i = 0; i < 5; ++i ) - bank.DropItem( MakeNewbie( new RecallRune() ) ); + // 5 blank recall runes + for ( int i = 0; i < 5; ++i ) + bank.DropItem( MakeNewbie( new RecallRune() ) ); - AddPowerScrolls( bank ); - } + AddPowerScrolls( bank ); } private static void AddPowerScrolls( BankBox bank ) @@ -690,7 +684,7 @@ namespace Server.Misc if( TestCenter.Enabled ) FillBankbox( newChar ); - if ( young && newChar.BankBox != null ) + if ( young ) { NewPlayerTicket ticket = new NewPlayerTicket(); ticket.Owner = newChar; diff --git a/Scripts/Mobiles/Townfolk/Banker.cs b/Scripts/Mobiles/Townfolk/Banker.cs index bb5a0b0cc..b73337f3d 100644 --- a/Scripts/Mobiles/Townfolk/Banker.cs +++ b/Scripts/Mobiles/Townfolk/Banker.cs @@ -36,7 +36,7 @@ namespace Server.Mobiles { int balance = 0; - Container bank = from.BankBox; + Container bank = from.FindBankNoCreate(); if ( bank != null ) { @@ -100,7 +100,7 @@ namespace Server.Mobiles public static bool Deposit( Mobile from, int amount ) { - BankBox box = from.BankBox; + BankBox box = from.FindBankNoCreate(); if ( box == null ) return false; @@ -146,7 +146,7 @@ namespace Server.Mobiles public static int DepositUpTo( Mobile from, int amount ) { - BankBox box = from.BankBox; + BankBox box = from.FindBankNoCreate(); if ( box == null ) return 0; @@ -265,7 +265,7 @@ namespace Server.Mobiles } else if ( amount > 0 ) { - BankBox box = e.Mobile.BankBox; + BankBox box = e.Mobile.FindBankNoCreate(); if ( box == null || !box.ConsumeTotal( typeof( Gold ), amount ) ) { @@ -292,12 +292,12 @@ namespace Server.Mobiles break; } - BankBox box = e.Mobile.BankBox; + BankBox box = e.Mobile.FindBankNoCreate(); if ( box != null ) - { this.Say( 1042759, box.TotalGold.ToString() ); // Thy current bank balance is ~1_AMOUNT~ gold. - } + else + this.Say( 1042759, "0" ); // Thy current bank balance is ~1_AMOUNT~ gold. break; } @@ -311,10 +311,7 @@ namespace Server.Mobiles break; } - BankBox box = e.Mobile.BankBox; - - if ( box != null ) - box.Open(); + e.Mobile.BankBox.Open(); break; } @@ -357,7 +354,7 @@ namespace Server.Mobiles BankBox box = e.Mobile.BankBox; - if ( box == null || !box.TryDropItem( e.Mobile, check, false ) ) + if ( !box.TryDropItem( e.Mobile, check, false ) ) { this.Say( 500386 ); // There's not enough room in your bankbox for the check! check.Delete(); diff --git a/Scripts/Mobiles/Townfolk/BaseEscortable.cs b/Scripts/Mobiles/Townfolk/BaseEscortable.cs index de97cbed0..b0eb52a17 100644 --- a/Scripts/Mobiles/Townfolk/BaseEscortable.cs +++ b/Scripts/Mobiles/Townfolk/BaseEscortable.cs @@ -306,7 +306,7 @@ namespace Server.Mobiles Gold gold = new Gold( 500, 1000 ); - if ( cont == null || !cont.TryDropItem( escorter, gold, false ) ) + if ( !cont.TryDropItem( escorter, gold, false ) ) gold.MoveToWorld( escorter.Location, escorter.Map ); StopFollow(); diff --git a/Scripts/Mobiles/Vendors/BaseVendor.cs b/Scripts/Mobiles/Vendors/BaseVendor.cs index 3078dee2e..1048abca8 100644 --- a/Scripts/Mobiles/Vendors/BaseVendor.cs +++ b/Scripts/Mobiles/Vendors/BaseVendor.cs @@ -974,7 +974,7 @@ namespace Server.Mobiles if ( !bought && totalCost >= 2000 ) { - cont = buyer.BankBox; + cont = buyer.FindBankNoCreate(); if ( cont != null && cont.ConsumeTotal( typeof( Gold ), totalCost ) ) { bought = true; diff --git a/Scripts/Mobiles/Vendors/NPC/AnimalTrainer.cs b/Scripts/Mobiles/Vendors/NPC/AnimalTrainer.cs index fc8ec2e34..fcfb3069f 100644 --- a/Scripts/Mobiles/Vendors/NPC/AnimalTrainer.cs +++ b/Scripts/Mobiles/Vendors/NPC/AnimalTrainer.cs @@ -295,7 +295,7 @@ namespace Server.Mobiles } else { - Container bank = from.BankBox; + Container bank = from.FindBankNoCreate(); if ( bank != null && bank.ConsumeTotal( typeof( Gold ), 30 ) ) { diff --git a/Scripts/Multis/BaseHouse.cs b/Scripts/Multis/BaseHouse.cs index d704c3fc8..5bac5692f 100644 --- a/Scripts/Multis/BaseHouse.cs +++ b/Scripts/Multis/BaseHouse.cs @@ -1322,7 +1322,7 @@ namespace Server.Multis BankBox box = m.BankBox; - if ( box == null || !box.TryDropItem( m, bankKey, false ) ) + if ( !box.TryDropItem( m, bankKey, false ) ) bankKey.Delete(); m.AddToBackpack( packKey ); diff --git a/Scripts/Multis/Boats/BaseBoat.cs b/Scripts/Multis/Boats/BaseBoat.cs index d8619e497..a6f3e19de 100644 --- a/Scripts/Multis/Boats/BaseBoat.cs +++ b/Scripts/Multis/Boats/BaseBoat.cs @@ -327,7 +327,7 @@ namespace Server.Multis BankBox box = m.BankBox; - if ( box == null || !box.TryDropItem( m, bankKey, false ) ) + if ( !box.TryDropItem( m, bankKey, false ) ) bankKey.Delete(); else m.LocalOverheadMessage( MessageType.Regular, 0x3B2, 502484 ); // A ship's key is now in my safety deposit box. diff --git a/Server/Effects.cs b/Server/Effects.cs index 5edef06fd..bf66e3d57 100644 --- a/Server/Effects.cs +++ b/Server/Effects.cs @@ -101,10 +101,7 @@ namespace Server if ( map == null ) return; - if ( e is Item ) - ((Item)e).ProcessDelta(); - else if ( e is Mobile ) - ((Mobile)e).ProcessDelta(); + e.ProcessDelta(); Packet preEffect = null, boltEffect = null, playSound = null; diff --git a/Server/IEntity.cs b/Server/IEntity.cs index 0413bbd15..8f7bfe154 100644 --- a/Server/IEntity.cs +++ b/Server/IEntity.cs @@ -27,9 +27,12 @@ namespace Server Serial Serial{ get; } Point3D Location{ get; } Map Map{ get; } + + void Delete(); + void ProcessDelta(); } - public class Entity : IEntity, IComparable, IComparable, IComparable + public class Entity : IEntity, IComparable { public int CompareTo( IEntity other ) { @@ -63,52 +66,48 @@ namespace Server m_Map = map; } - public Serial Serial - { - get - { + public Serial Serial { + get { return m_Serial; } } - public Point3D Location - { - get - { + public Point3D Location { + get { return m_Location; } } - public int X - { - get - { + public int X { + get { return m_Location.X; } } - public int Y - { - get - { + public int Y { + get { return m_Location.Y; } } - public int Z - { - get - { + public int Z { + get { return m_Location.Z; } } - public Map Map - { - get - { + public Map Map { + get { return m_Map; } } + + public void Delete() + { + } + + public void ProcessDelta() + { + } } } \ No newline at end of file diff --git a/Server/Item.cs b/Server/Item.cs index 67bed38f3..8b92feaec 100644 --- a/Server/Item.cs +++ b/Server/Item.cs @@ -558,7 +558,7 @@ namespace Server Weight = 0x80 } - public class Item : IPoint3D, IEntity, IHued, IComparable, IComparable, IComparable, ISerializable + public class Item : IEntity, IHued, IComparable, ISerializable { //public static readonly EmptyArrayList EmptyItems = new EmptyArrayList(); public static readonly List EmptyItems = new List( 0 ); @@ -1400,14 +1400,6 @@ namespace Server } } - Point3D IEntity.Location - { - get - { - return m_Location; - } - } - /// /// Has the item been deleted? /// @@ -3149,7 +3141,7 @@ namespace Server for ( int i = items.Count - 1; i >= 0; --i ) { if ( i < items.Count ) - ( (Item) items[i] ).OnParentDeleted( this ); + items[i].OnParentDeleted( this ); } } diff --git a/Server/Mobile.cs b/Server/Mobile.cs index ebafc29f6..66dbafbce 100644 --- a/Server/Mobile.cs +++ b/Server/Mobile.cs @@ -496,7 +496,7 @@ namespace Server /// /// Base class representing players, npcs, and creatures. /// - public class Mobile : IEntity, IPoint3D, IHued, IComparable, IComparable, ISerializable + public class Mobile : IEntity, IHued, IComparable, ISerializable { public int CompareTo( IEntity other ) { @@ -8526,14 +8526,6 @@ namespace Server } } - Point3D IEntity.Location - { - get - { - return m_Location; - } - } - [CommandProperty( AccessLevel.Counselor, AccessLevel.GameMaster )] public Point3D Location { @@ -9941,7 +9933,7 @@ namespace Server int index = 0; while( m_DeltaQueue.Count > 0 && index++ < count ) - (m_DeltaQueue.Dequeue()).ProcessDelta(); + m_DeltaQueue.Dequeue().ProcessDelta(); } [CommandProperty( AccessLevel.Counselor, AccessLevel.GameMaster )] diff --git a/Server/World.cs b/Server/World.cs index 9c77761be..f20b68a09 100644 --- a/Server/World.cs +++ b/Server/World.cs @@ -46,7 +46,7 @@ namespace Server { private static bool m_Loading; private static bool m_Loaded; private static bool m_Saving; - private static ArrayList m_DeleteList; + private static List m_DeleteList; public static bool Saving { get { return m_Saving; } } public static bool Loaded { get { return m_Loaded; } } @@ -71,11 +71,11 @@ namespace Server { get { return m_Items; } } - public static bool OnDelete( object o ) { + public static bool OnDelete( IEntity entity ) { if ( !m_Loading ) return true; - m_DeleteList.Add( o ); + m_DeleteList.Add( entity ); return false; } @@ -277,7 +277,7 @@ namespace Server { Stopwatch watch = Stopwatch.StartNew(); m_Loading = true; - m_DeleteList = new ArrayList(); + m_DeleteList = new List(); int mobileCount = 0, itemCount = 0, guildCount = 0; @@ -630,12 +630,7 @@ namespace Server { m_Loading = false; for ( int i = 0; i < m_DeleteList.Count; ++i ) { - object o = m_DeleteList[i]; - - if ( o is Item ) - ( ( Item ) o ).Delete(); - else if ( o is Mobile ) - ( ( Mobile ) o ).Delete(); + m_DeleteList[i].Delete(); } m_DeleteList.Clear();