private void AssignInstancedLoot()
{
if ( m_Aggressors.Count == 0 || this.Items.Count == 0 )
return;
if ( m_InstancedItems == null )
m_InstancedItems = new Dictionary<Item, InstancedItemInfo>();
List<Item> m_Stackables = new List<Item>();
List<Item> m_Unstackables = new List<Item>();
for ( int i = 0; i < this.Items.Count; i++ )
{
Item item = this.Items[i];
if ( item.LootType != LootType.Cursed ) //Don't have curesd items take up someone's item spot.. (?)
{
if ( item.Stackable )
m_Stackables.Add( item );
else
m_Unstackables.Add( item );
}
}
List<Mobile> attackers = new List<Mobile>( m_Aggressors );
for ( int i = 1; i < attackers.Count -1; i++ ) //randomize
{
int rand = Utility.Random( i + 1 );
Mobile temp = attackers[rand];
attackers[rand] = attackers[i];
attackers[i] = temp;
}
//stackables first, for the remaining stackables, have those be randomly added after
for ( int i = 0; i < m_Stackables.Count; i++ )
{
Item item = m_Stackables[i];
if ( item.Amount >= attackers.Count )
{
int amountPerAttacker = (item.Amount / attackers.Count);
int remainder = (item.Amount % attackers.Count);
for ( int j = 0; j < ((remainder == 0) ? attackers.Count -1 : attackers.Count); j++ )
{
Item splitItem = Mobile.LiftItemDupe( item, item.Amount - amountPerAttacker ); //LiftItemDupe automagically adds it as a child item to the corpse
m_InstancedItems.Add( splitItem, new InstancedItemInfo( splitItem, attackers[j] ) );
//What happens to the remaining portion? TEMP FOR NOW UNTIL OSI VERIFICATION: Treat as Single Item.
}
if ( remainder == 0 )
{
m_InstancedItems.Add( item, new InstancedItemInfo( item, attackers[attackers.Count - 1] ) );
//Add in the original item (which has an equal amount as the others) to the instance for the last attacker, cause it wasn't added above.
}
else
{
m_Unstackables.Add( item );
}
}
else
{
//What happens in this case? TEMP FOR NOW UNTIL OSI VERIFICATION: Treat as Single Item.
m_Unstackables.Add( item );
}
}
for ( int i = 0; i < m_Unstackables.Count; i++ )
{
Mobile m = attackers[i % attackers.Count];
Item item = m_Unstackables[i];
m_InstancedItems.Add( item, new InstancedItemInfo( item, m ) );
}
}