revert crafting updates of SVN538. Per Mark: changing baseclasses is a bad idea.
This commit is contained in:
parent
7399519cf7
commit
e86794c4e6
130 changed files with 1007 additions and 4906 deletions
|
|
@ -139,250 +139,7 @@ namespace Server.Items
|
|||
public BaseContainer( Serial serial ) : base( serial )
|
||||
{
|
||||
}
|
||||
|
||||
#region Consume[...]
|
||||
public int ConsumeTotalGroupedCompared( Type[][] types, int[] amounts, bool recurse, OnItemConsumed callback, CheckItemGroup grouper, Item compareTo )
|
||||
{
|
||||
if ( types.Length != amounts.Length )
|
||||
throw new ArgumentException();
|
||||
else if ( grouper == null )
|
||||
throw new ArgumentNullException();
|
||||
|
||||
Item[][][] items = new Item[types.Length][][];
|
||||
int[] totals = new int[types.Length];
|
||||
|
||||
bool hasComparer = false;
|
||||
|
||||
Item originalComparer = compareTo;
|
||||
|
||||
int comparerType = -1;
|
||||
|
||||
for ( int i = 0; i < types.Length; ++i )
|
||||
{
|
||||
Item[] typedItems = FindItemsByType( types[i], recurse );
|
||||
|
||||
List<List<Item>> groups = new List<List<Item>>();
|
||||
|
||||
int idx = 0;
|
||||
|
||||
if ( originalComparer != null )
|
||||
{
|
||||
for ( int j = 0; j < types[i].Length; ++j )
|
||||
{
|
||||
if ( originalComparer.GetType() == types[i][j] )
|
||||
{
|
||||
hasComparer = true;
|
||||
compareTo = originalComparer;
|
||||
comparerType = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while( idx < typedItems.Length )
|
||||
{
|
||||
Item a = typedItems[idx++];
|
||||
List<Item> group = new List<Item>();
|
||||
|
||||
if ( !hasComparer )
|
||||
{
|
||||
compareTo = a;
|
||||
group.Add( a );
|
||||
}
|
||||
else if ( grouper( compareTo, a ) == 0 )
|
||||
group.Add( a );
|
||||
|
||||
while( idx < typedItems.Length )
|
||||
{
|
||||
Item b = typedItems[idx];
|
||||
int v = grouper( compareTo, b );
|
||||
|
||||
if( v == 0 )
|
||||
group.Add( b );
|
||||
else
|
||||
break;
|
||||
|
||||
++idx;
|
||||
}
|
||||
|
||||
groups.Add( group );
|
||||
}
|
||||
|
||||
compareTo = originalComparer;
|
||||
hasComparer = false;
|
||||
|
||||
items[i] = new Item[groups.Count][];
|
||||
|
||||
bool hasEnough = false;
|
||||
|
||||
for ( int j = 0; j < groups.Count; ++j )
|
||||
{
|
||||
items[i][j] = groups[j].ToArray();
|
||||
|
||||
for ( int k = 0; k < items[i][j].Length; ++k )
|
||||
totals[i] += items[i][j][k].Amount;
|
||||
}
|
||||
|
||||
if ( totals[i] >= amounts[i] )
|
||||
hasEnough = true;
|
||||
|
||||
if ( !hasEnough )
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
for ( int i = 0; i < items.Length; ++i )
|
||||
{
|
||||
int need = amounts[i];
|
||||
|
||||
if ( originalComparer != null && comparerType == i )
|
||||
{
|
||||
object parent = originalComparer.RootParent;
|
||||
|
||||
if ( parent is Mobile )
|
||||
{
|
||||
Mobile m = (Mobile)parent;
|
||||
|
||||
if ( this.RootParent is Mobile && m == (Mobile)this.RootParent )
|
||||
ConsumeNeeded( ref need, originalComparer, callback );
|
||||
}
|
||||
}
|
||||
|
||||
for ( int j = 0; j < items[i].Length && need > 0; ++j )
|
||||
{
|
||||
if ( totals[i] >= amounts[i] )
|
||||
{
|
||||
for ( int k = 0; k < items[i][j].Length && need > 0; ++k )
|
||||
{
|
||||
Item item = items[i][j][k];
|
||||
|
||||
if ( !item.Deleted )
|
||||
ConsumeNeeded( ref need, item, callback );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void ConsumeNeeded( ref int need, Item item, OnItemConsumed callback )
|
||||
{
|
||||
int theirAmount = item.Amount;
|
||||
|
||||
if ( theirAmount < need )
|
||||
{
|
||||
if ( callback != null )
|
||||
callback( item, theirAmount );
|
||||
|
||||
item.Delete();
|
||||
need -= theirAmount;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( callback != null )
|
||||
callback( item, need );
|
||||
|
||||
item.Consume( need );
|
||||
need = 0;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Get[Compared]Amount
|
||||
public int GetComparedGroupAmount( Type[] types, bool recurse, CheckItemGroup grouper, Item compareTo )
|
||||
{
|
||||
if( grouper == null )
|
||||
throw new ArgumentNullException();
|
||||
|
||||
Item[] typedItems = FindItemsByType( types, recurse );
|
||||
|
||||
bool hasComparer = false;
|
||||
|
||||
if ( compareTo != null )
|
||||
{
|
||||
for ( int i = 0; i < types.Length; ++i )
|
||||
{
|
||||
if ( compareTo.GetType() == types[i] )
|
||||
{
|
||||
hasComparer = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<List<Item>> groups = new List<List<Item>>();
|
||||
|
||||
int idx = 0;
|
||||
|
||||
while( idx < typedItems.Length )
|
||||
{
|
||||
Item a = typedItems[idx++];
|
||||
List<Item> group = new List<Item>();
|
||||
|
||||
if ( !hasComparer )
|
||||
{
|
||||
compareTo = a;
|
||||
group.Add( a );
|
||||
}
|
||||
else if ( grouper( compareTo, a ) == 0 )
|
||||
group.Add( a );
|
||||
|
||||
while( idx < typedItems.Length )
|
||||
{
|
||||
Item b = typedItems[idx];
|
||||
int v = grouper( compareTo, b );
|
||||
|
||||
if( v == 0 )
|
||||
group.Add( b );
|
||||
else
|
||||
break;
|
||||
|
||||
++idx;
|
||||
}
|
||||
|
||||
groups.Add( group );
|
||||
}
|
||||
|
||||
int total = 0;
|
||||
|
||||
for( int j = 0; j < groups.Count; ++j )
|
||||
{
|
||||
Item[] items = groups[j].ToArray();
|
||||
|
||||
for( int k = 0; k < items.Length; ++k )
|
||||
total += items[k].Amount;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
public int GetAmountCompared( Type[] types, CheckItemGroup grouper, Item compareTo )
|
||||
{
|
||||
return GetAmountCompared( types, grouper, compareTo, true );
|
||||
}
|
||||
|
||||
public int GetAmountCompared( Type[] types, CheckItemGroup grouper, Item compareTo, bool recurse )
|
||||
{
|
||||
Item[] items = FindItemsByType( types, recurse );
|
||||
|
||||
int amount = 0;
|
||||
|
||||
for ( int i = 0; i < items.Length; ++i )
|
||||
{
|
||||
if ( compareTo == null )
|
||||
{
|
||||
compareTo = items[i];
|
||||
amount += items[i].Amount;
|
||||
}
|
||||
else if ( grouper( compareTo, items[i] ) == 0 )
|
||||
amount += items[i].Amount;
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
#endregion
|
||||
|
||||
/* Note: base class insertion; we cannot serialize anything here */
|
||||
public override void Serialize( GenericWriter writer )
|
||||
{
|
||||
|
|
@ -717,7 +474,7 @@ namespace Server.Items
|
|||
}
|
||||
}
|
||||
|
||||
public class Barrel : BaseFurnitureContainer
|
||||
public class Barrel : BaseContainer
|
||||
{
|
||||
[Constructable]
|
||||
public Barrel() : base( 0xE77 )
|
||||
|
|
@ -740,14 +497,14 @@ namespace Server.Items
|
|||
{
|
||||
base.Deserialize( reader );
|
||||
|
||||
int version = ( InheritsBaseCont ? OldVersion : reader.ReadInt() ); //Required for BaseFurnitureContainer insertion
|
||||
int version = reader.ReadInt();
|
||||
|
||||
if ( Weight == 0.0 )
|
||||
Weight = 25.0;
|
||||
}
|
||||
}
|
||||
|
||||
public class Keg : BaseFurnitureContainer
|
||||
public class Keg : BaseContainer
|
||||
{
|
||||
[Constructable]
|
||||
public Keg() : base( 0xE7F )
|
||||
|
|
@ -770,7 +527,7 @@ namespace Server.Items
|
|||
{
|
||||
base.Deserialize( reader );
|
||||
|
||||
int version = ( InheritsBaseCont ? OldVersion : reader.ReadInt() ); //Required for BaseFurnitureContainer insertion
|
||||
int version = reader.ReadInt();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -833,7 +590,7 @@ namespace Server.Items
|
|||
public class WoodenBox : LockableContainer
|
||||
{
|
||||
[Constructable]
|
||||
public WoodenBox() : base( 0xE7D )
|
||||
public WoodenBox() : base( 0x9AA )
|
||||
{
|
||||
Weight = 4.0;
|
||||
}
|
||||
|
|
@ -862,9 +619,9 @@ namespace Server.Items
|
|||
public class SmallCrate : LockableContainer
|
||||
{
|
||||
[Constructable]
|
||||
public SmallCrate() : base( 0xE7E )
|
||||
public SmallCrate() : base( 0x9A9 )
|
||||
{
|
||||
Weight = 1.0;
|
||||
Weight = 2.0;
|
||||
}
|
||||
|
||||
public SmallCrate( Serial serial ) : base( serial )
|
||||
|
|
@ -884,8 +641,8 @@ namespace Server.Items
|
|||
|
||||
int version = reader.ReadInt();
|
||||
|
||||
if ( Weight == 4.0 || Weight == 2.0 )
|
||||
Weight = 1.0;
|
||||
if ( Weight == 4.0 )
|
||||
Weight = 2.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -894,9 +651,9 @@ namespace Server.Items
|
|||
public class MediumCrate : LockableContainer
|
||||
{
|
||||
[Constructable]
|
||||
public MediumCrate() : base( 0xE3E )
|
||||
public MediumCrate() : base( 0xE3F )
|
||||
{
|
||||
Weight = 1.0;
|
||||
Weight = 2.0;
|
||||
}
|
||||
|
||||
public MediumCrate( Serial serial ) : base( serial )
|
||||
|
|
@ -916,8 +673,8 @@ namespace Server.Items
|
|||
|
||||
int version = reader.ReadInt();
|
||||
|
||||
if ( Weight == 6.0 || Weight == 2.0 )
|
||||
Weight = 1.0;
|
||||
if ( Weight == 6.0 )
|
||||
Weight = 2.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -926,7 +683,7 @@ namespace Server.Items
|
|||
public class LargeCrate : LockableContainer
|
||||
{
|
||||
[Constructable]
|
||||
public LargeCrate() : base( 0xE3C )
|
||||
public LargeCrate() : base( 0xE3D )
|
||||
{
|
||||
Weight = 1.0;
|
||||
}
|
||||
|
|
@ -957,8 +714,6 @@ namespace Server.Items
|
|||
[Flipable( 0x9A8, 0xE80 )]
|
||||
public class MetalBox : LockableContainer
|
||||
{
|
||||
public override CraftResource DefaultResource{ get{ return CraftResource.Iron; } }
|
||||
|
||||
[Constructable]
|
||||
public MetalBox() : base( 0x9A8 )
|
||||
{
|
||||
|
|
@ -990,8 +745,6 @@ namespace Server.Items
|
|||
[Flipable( 0x9AB, 0xE7C )]
|
||||
public class MetalChest : LockableContainer
|
||||
{
|
||||
public override CraftResource DefaultResource{ get{ return CraftResource.Iron; } }
|
||||
|
||||
[Constructable]
|
||||
public MetalChest() : base( 0x9AB )
|
||||
{
|
||||
|
|
@ -1023,8 +776,6 @@ namespace Server.Items
|
|||
[Flipable( 0xE41, 0xE40 )]
|
||||
public class MetalGoldenChest : LockableContainer
|
||||
{
|
||||
public override CraftResource DefaultResource{ get{ return CraftResource.Iron; } }
|
||||
|
||||
[Constructable]
|
||||
public MetalGoldenChest() : base( 0xE41 )
|
||||
{
|
||||
|
|
@ -1053,13 +804,13 @@ namespace Server.Items
|
|||
}
|
||||
|
||||
[Furniture]
|
||||
[Flipable( 0xE43, 0xE42 )]
|
||||
[Flipable( 0xe43, 0xe42 )]
|
||||
public class WoodenChest : LockableContainer
|
||||
{
|
||||
[Constructable]
|
||||
public WoodenChest() : base( 0xE42 )
|
||||
public WoodenChest() : base( 0xe43 )
|
||||
{
|
||||
Weight = 1.0;
|
||||
Weight = 2.0;
|
||||
}
|
||||
|
||||
public WoodenChest( Serial serial ) : base( serial )
|
||||
|
|
@ -1079,8 +830,8 @@ namespace Server.Items
|
|||
|
||||
int version = reader.ReadInt();
|
||||
|
||||
if ( Weight == 15.0 || Weight == 2.0 )
|
||||
Weight = 1.0;
|
||||
if ( Weight == 15.0 )
|
||||
Weight = 2.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1089,7 +840,7 @@ namespace Server.Items
|
|||
public class PlainWoodenChest : LockableContainer
|
||||
{
|
||||
[Constructable]
|
||||
public PlainWoodenChest() : base( 0x280C )
|
||||
public PlainWoodenChest() : base( 0x280B )
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -1120,7 +871,7 @@ namespace Server.Items
|
|||
public class OrnateWoodenChest : LockableContainer
|
||||
{
|
||||
[Constructable]
|
||||
public OrnateWoodenChest() : base( 0x280E )
|
||||
public OrnateWoodenChest() : base( 0x280D )
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -1151,7 +902,7 @@ namespace Server.Items
|
|||
public class GildedWoodenChest : LockableContainer
|
||||
{
|
||||
[Constructable]
|
||||
public GildedWoodenChest() : base( 0x2810 )
|
||||
public GildedWoodenChest() : base( 0x280F )
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -1182,7 +933,7 @@ namespace Server.Items
|
|||
public class WoodenFootLocker : LockableContainer
|
||||
{
|
||||
[Constructable]
|
||||
public WoodenFootLocker() : base( 0x2812 )
|
||||
public WoodenFootLocker() : base( 0x2811 )
|
||||
{
|
||||
GumpID = 0x10B;
|
||||
}
|
||||
|
|
@ -1217,7 +968,7 @@ namespace Server.Items
|
|||
public class FinishedWoodenChest : LockableContainer
|
||||
{
|
||||
[Constructable]
|
||||
public FinishedWoodenChest() : base( 0x2814 )
|
||||
public FinishedWoodenChest() : base( 0x2813 )
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue