Fixes dupe exception (#258)

- [X] Cleans up ActivatorUtil
- [X] Fixes dupe exception
- [X] Fixes a bug in BasePotion
- [X] Fixes a few possible memory leaks

Bumps release version
This commit is contained in:
Kamron Batman 2020-09-19 15:46:07 -07:00 • committed by GitHub
parent 4d6e584b6c
commit e9c1e4cbba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 597 additions and 496 deletions

View file

@ -2820,17 +2820,9 @@ namespace Server.Mobiles
m_SpellDefense.Add(type);
}
public Spell GetAttackSpellRandom()
{
var type = m_SpellAttack.RandomElement();
return type == null ? null : ActivatorUtil.CreateInstance(type, this, null) as Spell;
}
public Spell GetAttackSpellRandom() => m_SpellAttack.RandomElement()?.CreateInstance<Spell>(this, null);
public Spell GetDefenseSpellRandom()
{
var type = m_SpellDefense.RandomElement();
return type == null ? null : ActivatorUtil.CreateInstance(type, this, null) as Spell;
}
public Spell GetDefenseSpellRandom() => m_SpellDefense.RandomElement()?.CreateInstance<Spell>(this, null);
public Spell GetSpellSpecific(Type type)
{
@ -2840,7 +2832,7 @@ namespace Server.Mobiles
{
if (m_SpellAttack[i] == type)
{
return ActivatorUtil.CreateInstance(type, this, null) as Spell;
return type.CreateInstance<Spell>(this, null);
}
}
@ -2848,7 +2840,7 @@ namespace Server.Mobiles
{
if (m_SpellDefense[i] == type)
{
return ActivatorUtil.CreateInstance(type, this, null) as Spell;
return type.CreateInstance<Spell>(this, null);
}
}

View file

@ -3838,7 +3838,7 @@ namespace Server.Mobiles
try
{
ammo = ActivatorUtil.CreateInstance(kvp.Key) as Item;
ammo = kvp.Key.CreateInstance<Item>();
}
catch
{

View file

@ -215,7 +215,7 @@ namespace Server.Mobiles
public static void GiveArtifactTo(Mobile m)
{
var item = (Item)ActivatorUtil.CreateInstance(Artifacts.RandomElement());
var item = Artifacts.RandomElement().CreateInstance<Item>();
if (m.AddToBackpack(item))
{

View file

@ -41,6 +41,6 @@ namespace Server.Mobiles
public override bool CanCacheDisplay => false;
public override IEntity GetEntity() => (IEntity)ActivatorUtil.CreateInstance(Type, m_Content);
public override IEntity GetEntity() => Type.CreateInstance<IEntity>(m_Content);
}
}

View file

@ -97,16 +97,7 @@ namespace Server.Mobiles
public int MaxAmount { get; set; }
// get a new instance of an object (we just bought it)
public virtual IEntity GetEntity()
{
if (Args == null || Args.Length == 0)
{
return (IEntity)ActivatorUtil.CreateInstance(Type);
}
return (IEntity)ActivatorUtil.CreateInstance(Type, Args);
// return (Item)ActivatorUtil.CreateInstance( m_Type );
}
public virtual IEntity GetEntity() => Type.CreateInstance<IEntity>(Args);
// Attempt to restock with item, (return true if restock successful)
public bool Restock(Item item, int amount) => false;

View file

@ -265,7 +265,7 @@ namespace Server.Mobiles
}
}
var g = ActivatorUtil.CreateInstance(buyInfo.GumpType, args) as Gump;
var g = buyInfo.GumpType.CreateInstance<Gump>(args);
m_From.SendGump(g);
}