fix(core): Removes some uses of Linq (#421)

- [X] Removes some uses of linq
- [X] Creates struct based enumerator for Skills
- [X] Creates a struct based enumerator for TypeCache
- [X] Changes HarvestDefinition to an init array instead of List
- [X] Changes HeritageTokenGump Response from List to Array
This commit is contained in:
Kamron Batman 2021-01-18 21:05:11 -08:00 • committed by GitHub
parent 52356866ed
commit b921c38879
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 1006 additions and 507 deletions

View file

@ -1,5 +1,4 @@
using System;
using System.Linq;
using Server.Items;
namespace Server.Spells.Chivalry
@ -55,14 +54,14 @@ namespace Server.Spells.Chivalry
0
);
var targets = Caster.GetMobilesInRange(3)
.Where(
m => Caster != m && SpellHelper.ValidIndirectTarget(Caster, m) && Caster.CanBeHarmful(m, false) &&
(!Core.AOS || Caster.InLOS(m))
);
foreach (var m in targets)
foreach (var m in Caster.GetMobilesInRange(3))
{
if (Caster == m || !SpellHelper.ValidIndirectTarget(Caster, m) || !Caster.CanBeHarmful(m, false) ||
Core.AOS && !Caster.InLOS(m))
{
continue;
}
var damage = Math.Clamp(ComputePowerValue(10) + Utility.RandomMinMax(0, 2), 8, 24);
Caster.DoHarmful(m);

View file

@ -1,5 +1,4 @@
using System;
using System.Linq;
using Server.Engines.CannedEvil;
using Server.Engines.PartySystem;
using Server.Factions;
@ -95,12 +94,13 @@ namespace Server.Spells.Necromancy
if (map != null)
{
var targets = r.ChampionSpawn.GetMobilesInRange(Range).Where(IsValidTarget);
foreach (var m in targets)
// Surprisingly, no sparkle type effects
// Surprisingly, no sparkle type effects
foreach (var m in r.ChampionSpawn.GetMobilesInRange(Range))
{
m.Location = GetNearestShrine(m);
if (IsValidTarget(m))
{
m.Location = GetNearestShrine(m);
}
}
}
}

View file

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Server.Items;
using Server.Mobiles;
using Server.Targeting;
@ -84,13 +83,20 @@ namespace Server.Spells.Necromancy
targets.Add(m);
}
targets.AddRange(
m.GetMobilesInRange(2)
.Where(
targ => !(Caster is BaseCreature && targ is BaseCreature && targ != Caster && m != targ &&
SpellHelper.ValidIndirectTarget(Caster, targ) && Caster.CanBeHarmful(targ, false))
)
);
var eable = m.GetMobilesInRange(2);
foreach (Mobile targ in eable)
{
if (!(Caster is BaseCreature && targ is BaseCreature) &&
targ != Caster && m != targ &&
SpellHelper.ValidIndirectTarget(Caster, targ) &&
Caster.CanBeHarmful(targ, false))
{
targets.Add(targ);
}
}
eable.Free();
for (var i = 0; i < targets.Count; ++i)
{

View file

@ -1,5 +1,4 @@
using System;
using System.Linq;
using Server.Factions;
using Server.Items;
using Server.Misc;
@ -127,10 +126,16 @@ namespace Server.Spells.Seventh
private bool GateExistsAt(Map map, Point3D loc)
{
var eable = map.GetItemsInRange(loc, 0);
var gateFound = eable.Any(item => item is Moongate || item is PublicMoongate);
eable.Free();
return gateFound;
foreach (var item in eable)
{
if (item is Moongate || item is PublicMoongate)
{
return true;
}
}
return false;
}
[DispellableField]

View file

@ -79,9 +79,7 @@ namespace Server.Spells.Seventh
targets = new List<Mobile>();
}
double damage;
damage = Core.AOS
double damage = Core.AOS
? GetNewAosDamage(51, 1, 5, playerVsPlayer)
: Utility.Random(27, 22);

View file

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Server.Items;
using Server.Mobiles;
@ -105,14 +104,17 @@ namespace Server.Spells.Spellweaving
var eable = map.GetItemsInRange(location, 0);
var found = eable.Any(
item =>
item.Z + item.ItemData.CalcHeight == location.Z && IsValidTile(item.ItemID)
);
foreach (var item in eable)
{
if (item.Z + item.ItemData.CalcHeight == location.Z && IsValidTile(item.ItemID))
{
return true;
}
}
eable.Free();
return found;
return false;
}
public static bool IsValidTile(int itemID) =>
@ -126,13 +128,19 @@ namespace Server.Spells.Spellweaving
// OSI Verified: Even enemies/combatants count
// Everyone gets the Arcane Focus, power capped elsewhere
weavers.AddRange(
Caster.GetMobilesInRange(1)
.Where(
m => m != Caster && m is PlayerMobile && Caster.CanBeBeneficial(m, false) &&
Math.Abs(Caster.Skills.Spellweaving.Value - m.Skills.Spellweaving.Value) <= 20
)
);
var eable = Caster.GetMobilesInRange(1);
foreach (var m in eable)
{
if (m != Caster && m is PlayerMobile && Caster.CanBeBeneficial(m, false) &&
Math.Abs(Caster.Skills.Spellweaving.Value - m.Skills.Spellweaving.Value) <= 20)
{
weavers.Add(m);
}
}
eable.Free();
return weavers;
}