diff --git a/Scripts/Items/Food/Cooking.cs b/Scripts/Items/Food/Cooking.cs index 5cd16b466..bb8355b52 100644 --- a/Scripts/Items/Food/Cooking.cs +++ b/Scripts/Items/Food/Cooking.cs @@ -71,45 +71,40 @@ namespace Server.Items { if ( m_Item.Deleted ) return; + Item targetItem = targeted as Item; + if ( targetItem == null || targetItem.Deleted ) return; + + m_Item.Consume(); + if ( targeted is Eggs ) { - m_Item.Delete(); - - ((Eggs)targeted).Consume(); + targetItem.Consume(); from.AddToBackpack( new UnbakedQuiche() ); from.AddToBackpack( new Eggshells() ); } else if ( targeted is CheeseWheel ) { - m_Item.Delete(); - - ((CheeseWheel)targeted).Consume(); + targetItem.Consume(); from.AddToBackpack( new CheesePizza() ); } else if ( targeted is Sausage ) { - m_Item.Delete(); - - ((Sausage)targeted).Consume(); + targetItem.Consume(); from.AddToBackpack( new SausagePizza() ); } else if ( targeted is Apple ) { - m_Item.Delete(); - - ((Apple)targeted).Consume(); + targetItem.Consume(); from.AddToBackpack( new UnbakedApplePie() ); } else if ( targeted is Peach ) { - m_Item.Delete(); - - ((Peach)targeted).Consume(); + targetItem.Consume(); from.AddToBackpack( new UnbakedPeachCobbler() ); } @@ -174,9 +169,10 @@ namespace Server.Items { if ( m_Item.Deleted ) return; + m_Item.Consume(); + if ( targeted is BowlFlour ) { - m_Item.Delete(); ((BowlFlour)targeted).Delete(); from.AddToBackpack( new CakeMix() ); @@ -184,7 +180,6 @@ namespace Server.Items else if ( targeted is Campfire ) { from.PlaySound( 0x225 ); - m_Item.Delete(); InternalTimer t = new InternalTimer( from, (Campfire)targeted ); t.Start(); } @@ -273,9 +268,10 @@ namespace Server.Items { if ( m_Item.Deleted ) return; + m_Item.Consume(); + if ( targeted is Dough ) { - m_Item.Delete(); ((Dough)targeted).Consume(); from.AddToBackpack( new SweetDough() ); @@ -283,7 +279,6 @@ namespace Server.Items if (targeted is BowlFlour) { - m_Item.Consume(); ((BowlFlour)targeted).Delete(); from.AddToBackpack( new CookieMix() ); @@ -420,12 +415,7 @@ namespace Server.Items get{ return m_Quantity; } set { - if ( value < 0 ) - value = 0; - else if ( value > 20 ) - value = 20; - - m_Quantity = value; + m_Quantity = Math.Min(20, Math.Max(0, value)); if ( m_Quantity == 0 ) Delete(); diff --git a/Scripts/Items/Resources/Blacksmithing/Ore.cs b/Scripts/Items/Resources/Blacksmithing/Ore.cs index a06b0fbaa..9de23f477 100644 --- a/Scripts/Items/Resources/Blacksmithing/Ore.cs +++ b/Scripts/Items/Resources/Blacksmithing/Ore.cs @@ -96,6 +96,10 @@ namespace Server.Items public BaseOre( Serial serial ) : base( serial ) { } + public override bool CanStackWith(Item dropped) + { + return dropped.Stackable && Stackable && dropped.GetType() == GetType() && dropped.Hue == Hue && dropped.Name == Name && (dropped.Amount + Amount) <= 60000 && dropped != this; + } public override void AddNameProperty( ObjectPropertyList list ) { @@ -698,4 +702,4 @@ namespace Server.Items return new ValoriteIngot(); } } -} \ No newline at end of file +} diff --git a/Server/Item.cs b/Server/Item.cs index 971c6e551..9f6a5983d 100644 --- a/Server/Item.cs +++ b/Server/Item.cs @@ -1525,6 +1525,11 @@ namespace Server } } + public virtual bool CanStackWith( Item dropped ) + { + return dropped.Stackable && Stackable && dropped.GetType() == GetType() && dropped.ItemID == ItemID && dropped.Hue == Hue && dropped.Name == Name && (dropped.Amount + Amount) <= 60000 && dropped != this; + } + public bool StackWith( Mobile from, Item dropped ) { return StackWith( from, dropped, true ); @@ -1532,7 +1537,7 @@ namespace Server public virtual bool StackWith( Mobile from, Item dropped, bool playSound ) { - if ( dropped.Stackable && Stackable && dropped.GetType() == GetType() && dropped.ItemID == ItemID && dropped.Hue == Hue && dropped.Name == Name && (dropped.Amount + Amount) <= 60000 && dropped != this && !dropped.Nontransferable && !Nontransferable ) + if ( CanStackWith( dropped ) ) { if ( m_LootType != dropped.m_LootType ) m_LootType = LootType.Regular; @@ -1558,10 +1563,19 @@ namespace Server public virtual bool OnDragDrop( Mobile from, Item dropped ) { + bool success = false; if ( Parent is Container ) - return ((Container)Parent).OnStackAttempt( from, this, dropped ); + success = ((Container)Parent).OnStackAttempt( from, this, dropped ); + else + success = StackWith( from, dropped ); - return StackWith( from, dropped ); + if ( success && Spawner != null ) + { + Spawner.Remove( this ); + Spawner = null; + } + + return success; } public Rectangle2D GetGraphicBounds() diff --git a/Server/Items/Container.cs b/Server/Items/Container.cs index df3578e02..aadece33e 100644 --- a/Server/Items/Container.cs +++ b/Server/Items/Container.cs @@ -132,7 +132,9 @@ namespace Server.Items } public virtual Rectangle2D Bounds{ get{ return ContainerData.Bounds; } } + [CommandProperty( AccessLevel.GameMaster )] public virtual int DefaultGumpID{ get{ return ContainerData.GumpID; } } + [CommandProperty( AccessLevel.GameMaster )] public virtual int DefaultDropSound{ get{ return ContainerData.DropSound; } } public virtual int DefaultMaxItems{ get{ return m_GlobalMaxItems; } } @@ -190,7 +192,7 @@ namespace Server.Items public virtual bool CheckHold( Mobile m, Item item, bool message, bool checkItems, int plusItems, int plusWeight ) { - if ( m.AccessLevel < AccessLevel.GameMaster ) + if ( m != null && m.AccessLevel < AccessLevel.GameMaster ) { if ( IsDecoContainer ) { @@ -209,17 +211,13 @@ namespace Server.Items return false; } - else + + if ( MaxWeight != 0 && (this.TotalWeight + plusWeight + item.TotalWeight + item.PileWeight) > MaxWeight ) { - int maxWeight = this.MaxWeight; + if ( message ) + SendFullWeightMessage( m, item ); - if ( maxWeight != 0 && (this.TotalWeight + plusWeight + item.TotalWeight + item.PileWeight) > maxWeight ) - { - if ( message ) - SendFullWeightMessage( m, item ); - - return false; - } + return false; } } @@ -356,7 +354,7 @@ namespace Server.Items if ( callback != null ) callback( item, theirAmount ); - item.Delete(); + item.Consume( theirAmount ); need -= theirAmount; } else @@ -456,7 +454,7 @@ namespace Server.Items if ( callback != null ) callback( item, theirAmount ); - item.Delete(); + item.Consume( theirAmount ); need -= theirAmount; } else @@ -556,7 +554,7 @@ namespace Server.Items if ( callback != null ) callback( item, theirAmount ); - item.Delete(); + item.Consume( theirAmount ); need -= theirAmount; } else @@ -621,7 +619,7 @@ namespace Server.Items if ( callback != null ) callback( item, theirAmount ); - item.Delete(); + item.Consume( theirAmount ); need -= theirAmount; } else @@ -682,7 +680,7 @@ namespace Server.Items if ( callback != null ) callback( item, theirAmount ); - item.Delete(); + item.Consume( theirAmount ); need -= theirAmount; } else @@ -736,7 +734,7 @@ namespace Server.Items if( callback != null ) callback( item, theirAmount ); - item.Delete(); + item.Consume( theirAmount ); need -= theirAmount; } else @@ -1164,7 +1162,7 @@ namespace Server.Items public List FindItemsByType( Predicate predicate ) where T : Item { - return FindItemsByType( true, predicate ); + return FindItemsByType( true, predicate ); } public List FindItemsByType( bool recurse, Predicate predicate ) where T : Item @@ -1466,10 +1464,7 @@ namespace Server.Items public virtual bool OnStackAttempt( Mobile from, Item stack, Item dropped ) { - if ( !CheckHold( from, dropped, true, false ) ) - return false; - - return stack.StackWith( from, dropped ); + return CheckHold( from, dropped, true, false ) && stack.StackWith( from, dropped ); } public override bool OnDragDrop( Mobile from, Item dropped ) @@ -1488,22 +1483,94 @@ namespace Server.Items public virtual bool TryDropItem( Mobile from, Item dropped, bool sendFullMessage ) { - if ( !CheckHold( from, dropped, sendFullMessage, true ) ) - return false; + return TryDropItem( from, dropped, sendFullMessage, false ); + } + public virtual bool TryDropItem( Mobile from, Item dropped, bool sendFullMessage, bool playSound ) + { List list = this.Items; for ( int i = 0; i < list.Count; ++i ) { Item item = list[i]; - if ( !(item is Container) && item.StackWith( from, dropped, false ) ) + if ( !(item is Container) && CheckHold( from, dropped, false, false ) && item.StackWith( from, dropped, playSound ) ) return true; } - DropItem( dropped ); + if ( CheckHold( from, dropped, sendFullMessage, true ) ) + { + DropItem( dropped ); + return true; + } - return true; + return false; + } + + public virtual bool TryDropItems( Mobile from, bool sendFullMessage, params Item[] droppedItems ) + { + List dropItems = new List(); + List stackItems = new List(); + + int extraItems = 0; + int extraWeight = 0; + +// from.SendMessage( String.Format( "There are {0} items in this container.", this.Items.Count ) ); +// from.SendMessage( String.Format( "There are {0} items being dropped into this container.", droppedItems.Length ) ); + + for ( int i = 0; i < droppedItems.Length; i++ ) + { + Item dropped = droppedItems[i]; + + List list = this.Items; + + bool stacked = false; + + for ( int j = 0; j < list.Count; ++j ) + { + Item item = list[j]; + + if ( !(item is Container) && CheckHold( from, dropped, false, false, 0, extraWeight ) && item.CanStackWith( dropped ) ) + { + stackItems.Add( new ItemStackEntry( item, dropped ) ); + extraWeight += (int)Math.Ceiling( item.Weight * (item.Amount + dropped.Amount) ) - item.PileWeight; //extra weight delta, do not need TotalWeight as we do not have hybrid stackable container types + stacked = true; + break; + } + } + + if ( !stacked && CheckHold( from, dropped, false, true, extraItems, extraWeight ) ) + { + dropItems.Add( dropped ); + extraItems++; + extraWeight += dropped.TotalWeight + dropped.PileWeight; + } + } + + if ( dropItems.Count + stackItems.Count == droppedItems.Length ) //All good + { + for ( int i = 0; i < dropItems.Count; i++ ) + DropItem( dropItems[i] ); + + for ( int i = 0; i < stackItems.Count; i++ ) + stackItems[i].m_StackItem.StackWith( from, stackItems[i].m_DropItem, false ); + + return true; + } + + return false; + } + + private struct ItemStackEntry + { + public Item m_StackItem; + public Item m_DropItem; + + public ItemStackEntry( Item stack, Item drop ) + { + m_StackItem = stack; + m_DropItem = drop; + } } public virtual void Destroy() @@ -1582,13 +1649,13 @@ namespace Server.Items public virtual bool CheckContentDisplay( Mobile from ) { - if ( !DisplaysContent ) - return false; + if ( DisplaysContent ) + { + object root = this.RootParent; - object root = this.RootParent; - - if ( root == null || root is Item || root == from || from.AccessLevel > AccessLevel.Player ) - return true; + if ( root == null || root is Item || root == from || from.AccessLevel > AccessLevel.Player ) + return true; + } return false; } @@ -1598,8 +1665,8 @@ namespace Server.Items base.OnSingleClick( from ); if ( CheckContentDisplay( from ) ) - LabelTo(from, "({0} items, {1} stones)", TotalItems, TotalWeight); - //LabelTo(from, 1050044, String.Format("{0}\t{1}", TotalItems, TotalWeight)); // ~1_COUNT~ items, ~2_WEIGHT~ stones + LabelTo( from, "({0} item{2}, {1} stones)", TotalItems, TotalWeight, TotalItems != 1 ? "s" : String.Empty ); + //LabelTo( from, 1050044, String.Format( "{0}\t{1}", TotalItems.ToString(), TotalWeight.ToString() ) ); } private List m_Openers; @@ -1625,25 +1692,22 @@ namespace Server.Items NetState ns = to.NetState; - if ( ns == null ) - return; - - if ( ns.HighSeas ) - to.Send( new ContainerDisplayHS( this ) ); - else - to.Send( new ContainerDisplay( this ) ); - - if ( ns.ContainerGridLines ) - to.Send( new ContainerContent6017( to, this ) ); - else - to.Send( new ContainerContent( to, this ) ); - - if ( ObjectPropertyList.Enabled ) + if ( ns != null ) { - List items = this.Items; + if ( ns.HighSeas ) + to.Send( new ContainerDisplayHS( this ) ); + else + to.Send( new ContainerDisplay( this ) ); - for ( int i = 0; i < items.Count; ++i ) - to.Send( items[i].OPLPacket ); + SendContentTo( ns ); + + if ( ObjectPropertyList.Enabled ) + { + List items = this.Items; + + for ( int i = 0; i < items.Count; ++i ) + to.Send( items[i].OPLPacket ); + } } } @@ -1663,9 +1727,7 @@ namespace Server.Items Mobile mob = m_Openers[i]; if ( mob == opener ) - { contains = true; - } else { int range = GetUpdateRange( mob ); @@ -1679,26 +1741,30 @@ namespace Server.Items if ( !contains ) { if ( m_Openers == null ) - { m_Openers = new List(); - } m_Openers.Add( opener ); } else if ( m_Openers != null && m_Openers.Count == 0 ) - { m_Openers = null; - } } } + public virtual void SendContentTo( NetState state ) + { + if ( state != null && state.ContainerGridLines ) + state.Send( new ContainerContent6017( state.Mobile, this ) ); + else + state.Send( new ContainerContent( state.Mobile, this ) ); + } + public override void GetProperties( ObjectPropertyList list ) { base.GetProperties( list ); - if( DisplaysContent )//CheckContentDisplay( from ) ) + if ( DisplaysContent )//CheckContentDisplay( from ) ) { - if( Core.ML ) + if ( Core.ML ) { if( ParentsContain() ) //Root Parent is the Mobile. Parent could be another containter. list.Add( 1073841, "{0}\t{1}\t{2}", TotalItems, MaxItems, TotalWeight ); // Contents: ~1_COUNT~/~2_MAXCOUNT~ items, ~3_WEIGHT~ stones @@ -1708,9 +1774,7 @@ namespace Server.Items //TODO: Where do the other clilocs come into play? 1073839 & 1073840? } else - { list.Add( 1050044, "{0}\t{1}", TotalItems, TotalWeight ); // ~1_COUNT~ items, ~2_WEIGHT~ stones - } } } @@ -1839,4 +1903,4 @@ namespace Server.Items m_DropSound = dropSound; } } -} \ No newline at end of file +}