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

@ -19,7 +19,7 @@ namespace Server.Factions
{
try
{
return ActivatorUtil.CreateInstance(Definition.Type) as BaseFactionGuard;
return Definition.Type.CreateInstance<BaseFactionGuard>();
}
catch
{

View file

@ -41,7 +41,7 @@ namespace Server.Factions
{
try
{
return ActivatorUtil.CreateInstance(type);
return type.CreateInstance<object>();
}
catch
{

View file

@ -19,7 +19,7 @@ namespace Server.Factions
{
try
{
return ActivatorUtil.CreateInstance(Definition.Type, town, faction) as BaseFactionVendor;
return Definition.Type.CreateInstance<BaseFactionVendor>(town, faction);
}
catch
{

View file

@ -55,7 +55,7 @@ namespace Server
{
if (weight < item.Weight)
{
var obj = item.Construct();
var obj = item.Type.CreateInstance<Item>();
if (obj != null)
{
@ -188,8 +188,6 @@ namespace Server
public int Weight { get; }
public Type Type { get; }
public Item Construct() => ActivatorUtil.CreateInstance(Type) as Item;
}
}
}

View file

@ -51,7 +51,7 @@ namespace Server.Factions
{
try
{
return ActivatorUtil.CreateInstance(TrapType, m_Faction, from) as BaseFactionTrap;
return TrapType.CreateInstance<BaseFactionTrap>(m_Faction, from);
}
catch
{

View file

@ -91,7 +91,7 @@ namespace Server.Factions
if (entry.Chance > Utility.Random(100))
{
releaseTime = DateTime.UtcNow + entry.Hold;
return (Spell)ActivatorUtil.CreateInstance(entry.Spell, mob, null);
return entry.Spell.CreateInstance<Spell>(mob, null);
}
}
@ -406,9 +406,9 @@ namespace Server.Factions
{
if (m_Mobile.Target != null)
m_Mobile.Target.Cancel( m_Mobile, TargetCancelType.Canceled );
new TeleportSpell( m_Mobile, null ).Cast();
m_Mobile.DebugSay( "I am stuck, I'm going to try teleporting away" );
}
else*/
@ -744,7 +744,7 @@ namespace Server.Factions
}
else if (types.Count == 1)
{
spell = ActivatorUtil.CreateInstance(types[0], m_Guard, null) as Spell;
spell = types[0].CreateInstance<Spell>(m_Guard, null);
}
}
else if (types.Count > 0)
@ -796,7 +796,7 @@ namespace Server.Factions
}
else if (types.Count == 1)
{
spell = (Spell)ActivatorUtil.CreateInstance(types[0], m_Guard, null);
spell = types[0].CreateInstance<Spell>(m_Guard, null);
}
}
}
@ -804,24 +804,14 @@ namespace Server.Factions
if (spell != null && m_Guard.HitsMax - m_Guard.Hits + 10 > Utility.Random(100))
{
Type type = null;
if (spell is GreaterHealSpell)
Type type = spell switch
{
type = typeof(BaseHealPotion);
}
else if (spell is CureSpell)
{
type = typeof(BaseCurePotion);
}
else if (spell is StrengthSpell)
{
type = typeof(BaseStrengthPotion);
}
else if (spell is AgilitySpell)
{
type = typeof(BaseAgilityPotion);
}
GreaterHealSpell _ => typeof(BaseHealPotion),
CureSpell _ => typeof(BaseCurePotion),
StrengthSpell _ => typeof(BaseStrengthPotion),
AgilitySpell _ => typeof(BaseAgilityPotion),
_ => null
};
if (type == typeof(BaseHealPotion) && !m_Guard.CanBeginAction(type))
{