New construct methods for Loot
I have added to the construct methods in Loot.cs and I think they would be a great addition to the distro.
[code:1] public static Item Construct( Type type, object[] args ) //One item type with a parameter list
{
try { return Activator.CreateInstance( type, args ) as Item; }
catch { return null; }
}
public static Item Construct( Type[] types, object[] args ) //Set of item types, sharing the same parameter list
{
if ( types.Length > 0 )
{
int item = Utility.Random( types.Length - 1 );
try { return Activator.CreateInstance( types[item], args ) as Item; }
catch { return null; }
}
return null;
}
public static Item Construct( Type[] types, object[][] args ) //Set of item types, with their own parameter list
{
if ( types.Length > 0 )
{
int item = Utility.Random( types.Length - 1 );
try { return Activator.CreateInstance( types[item], new object[]{ args[item] } ) as Item; }
catch{ return null; }
}
return null;
}[/code:1]
For those who want to know how to install this. Open loot.cs and go to where it says [code:1]#region Construction methods [/code:1] and that code under that line.
I have added to the construct methods in Loot.cs and I think they would be a great addition to the distro.
[code:1] public static Item Construct( Type type, object[] args ) //One item type with a parameter list
{
try { return Activator.CreateInstance( type, args ) as Item; }
catch { return null; }
}
public static Item Construct( Type[] types, object[] args ) //Set of item types, sharing the same parameter list
{
if ( types.Length > 0 )
{
int item = Utility.Random( types.Length - 1 );
try { return Activator.CreateInstance( types[item], args ) as Item; }
catch { return null; }
}
return null;
}
public static Item Construct( Type[] types, object[][] args ) //Set of item types, with their own parameter list
{
if ( types.Length > 0 )
{
int item = Utility.Random( types.Length - 1 );
try { return Activator.CreateInstance( types[item], new object[]{ args[item] } ) as Item; }
catch{ return null; }
}
return null;
}[/code:1]
For those who want to know how to install this. Open loot.cs and go to where it says [code:1]#region Construction methods [/code:1] and that code under that line.