Fix RCS1077

This commit is contained in:
RoosterDragon
2023-03-18 12:47:08 +00:00
committed by Gustas
parent 499efa1d0a
commit 330ca92045
60 changed files with 110 additions and 97 deletions

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Activities;
@@ -162,7 +163,7 @@ namespace OpenRA.Mods.Common.Traits
if (world.Map.Contains(cell))
{
var explored = subject.Actor.Owner.Shroud.IsExplored(cell);
var cannotMove = subjects.FirstOrDefault(a => !a.Trait.Info.MoveIntoShroud).Trait;
var cannotMove = Array.Find(subjects, a => !a.Trait.Info.MoveIntoShroud).Trait;
var blocked = !explored && cannotMove != null;
if (isAssaultMove)

View File

@@ -305,7 +305,7 @@ namespace OpenRA.Mods.Common.Traits
// HACK: Use of this function requires that there is one squad of this type.
Squad GetSquadOfType(SquadType type)
{
return Squads.FirstOrDefault(s => s.Type == type);
return Squads.Find(s => s.Type == type);
}
Squad RegisterNewSquad(IBot bot, SquadType type, (Actor Actor, WVec Offset) target = default)
@@ -446,7 +446,7 @@ namespace OpenRA.Mods.Common.Traits
ownUnits.First())
.ToList();
if (AttackOrFleeFuzzy.Rush.CanAttack(ownUnits, enemies.Select(x => x.Actor).ToList()))
if (AttackOrFleeFuzzy.Rush.CanAttack(ownUnits, enemies.ConvertAll(x => x.Actor)))
{
var target = enemies.Count > 0 ? enemies.Random(World.LocalRandom) : enemyBaseBuilder;
var rush = GetSquadOfType(SquadType.Rush);
@@ -508,7 +508,7 @@ namespace OpenRA.Mods.Common.Traits
return new List<MiniYamlNode>()
{
new("Squads", "", Squads.Select(s => new MiniYamlNode("Squad", s.Serialize())).ToList()),
new("Squads", "", Squads.ConvertAll(s => new MiniYamlNode("Squad", s.Serialize()))),
new("InitialBaseCenter", FieldSaver.FormatValue(initialBaseCenter)),
new("UnitsHangingAroundTheBase", FieldSaver.FormatValue(unitsHangingAroundTheBase
.Where(a => !unitCannotBeOrdered(a))

View File

@@ -57,7 +57,9 @@ namespace OpenRA.Mods.Common.Traits
.ThenBy(e => (actor.World.Map.CenterOfCell(actor.Location + e.Info.ExitCell) - pos).LengthSquared)
.ToList();
#pragma warning disable RCS1077 // Optimize LINQ method call.
return p != null ? all.FirstOrDefault(p) : all.FirstOrDefault();
#pragma warning restore RCS1077 // Optimize LINQ method call.
}
public static IEnumerable<Exit> Exits(this Actor actor, string productionType = null)

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Activities;
@@ -142,7 +143,7 @@ namespace OpenRA.Mods.Common.Traits
return;
var currentTransform = self.CurrentActivity as Transform;
var transform = transforms.FirstOrDefault(t => !t.IsTraitDisabled && !t.IsTraitPaused);
var transform = Array.Find(transforms, t => !t.IsTraitDisabled && !t.IsTraitPaused);
if (transform == null && currentTransform == null)
return;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Activities;
@@ -94,7 +95,7 @@ namespace OpenRA.Mods.Common.Traits
return;
var currentTransform = self.CurrentActivity as Transform;
var transform = transforms.FirstOrDefault(t => !t.IsTraitDisabled && !t.IsTraitPaused);
var transform = Array.Find(transforms, t => !t.IsTraitDisabled && !t.IsTraitPaused);
if (transform == null && currentTransform == null)
return;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Activities;
@@ -120,7 +121,7 @@ namespace OpenRA.Mods.Common.Traits
return;
var currentTransform = self.CurrentActivity as Transform;
var transform = transforms.FirstOrDefault(t => !t.IsTraitDisabled && !t.IsTraitPaused);
var transform = Array.Find(transforms, t => !t.IsTraitDisabled && !t.IsTraitPaused);
if (transform == null && currentTransform == null)
return;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Activities;
@@ -128,7 +129,7 @@ namespace OpenRA.Mods.Common.Traits
return;
var currentTransform = self.CurrentActivity as Transform;
var transform = transforms.FirstOrDefault(t => !t.IsTraitDisabled && !t.IsTraitPaused);
var transform = Array.Find(transforms, t => !t.IsTraitDisabled && !t.IsTraitPaused);
if (transform == null && currentTransform == null)
return;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Activities;
@@ -122,7 +123,7 @@ namespace OpenRA.Mods.Common.Traits
return;
var currentTransform = self.CurrentActivity as Transform;
var transform = transforms.FirstOrDefault(t => !t.IsTraitDisabled && !t.IsTraitPaused);
var transform = Array.Find(transforms, t => !t.IsTraitDisabled && !t.IsTraitPaused);
if (transform == null && currentTransform == null)
return;

View File

@@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Traits
{
if (external == null || !external.CanGrantCondition(self))
{
external = externals.FirstOrDefault(t => t.CanGrantCondition(self));
external = externals.Find(t => t.CanGrantCondition(self));
if (external == null)
break;
}

View File

@@ -310,7 +310,7 @@ namespace OpenRA.Mods.Common.Traits
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world)
{
var minelayer = minelayers.FirstOrDefault(m => m.IsInWorld && !m.IsDead);
var minelayer = minelayers.Find(m => m.IsInWorld && !m.IsDead);
if (minelayer == null)
yield break;

View File

@@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Traits
if (allProductionPaused)
return;
var item = Queue.FirstOrDefault(i => !i.Paused);
var item = Queue.Find(i => !i.Paused);
if (item == null)
return;

View File

@@ -9,8 +9,8 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Traits;
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Traits
// TODO: This won't make sense for MP saves
var localPlayer = worldRenderer.World.LocalPlayer;
if ((localPlayer != null && localPlayer.PlayerActor != self) ||
(localPlayer == null && self.Owner != self.World.Players.FirstOrDefault(p => p.IsBot)))
(localPlayer == null && self.Owner != Array.Find(self.World.Players, p => p.IsBot)))
return null;
var nodes = new List<MiniYamlNode>()

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits
{
CancelUnbuildableItems();
var item = Queue.FirstOrDefault(i => !i.Paused);
var item = Queue.Find(i => !i.Paused);
if (item == null)
return;

View File

@@ -175,7 +175,7 @@ namespace OpenRA.Mods.Common.Traits
.Where(p => p.AcceptsPlug(plugInfo.Type))
.ToList();
var pluggable = pluggables.FirstOrDefault(p => a.Location + p.Info.Offset == targetLocation)
var pluggable = pluggables.Find(p => a.Location + p.Info.Offset == targetLocation)
?? pluggables.FirstOrDefault();
if (pluggable == null)

View File

@@ -515,7 +515,7 @@ namespace OpenRA.Mods.Common.Traits
protected virtual void PauseProduction(string itemName, bool paused)
{
Queue.FirstOrDefault(a => a.Item == itemName)?.Pause(paused);
Queue.Find(a => a.Item == itemName)?.Pause(paused);
}
protected virtual void CancelProduction(string itemName, uint numberToCancel)

View File

@@ -11,7 +11,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Widgets;
using OpenRA.Orders;
@@ -152,7 +151,7 @@ namespace OpenRA.Mods.Common.Traits
Arrow GetArrow(double degree)
{
var arrow = directionArrows.FirstOrDefault(d => d.EndAngle >= degree);
var arrow = Array.Find(directionArrows, d => d.EndAngle >= degree);
return arrow ?? directionArrows[0];
}

View File

@@ -222,7 +222,7 @@ namespace OpenRA.Mods.Common.Traits
if (!Ready)
return;
var power = Instances.FirstOrDefault(i => !i.IsTraitPaused);
var power = Instances.Find(i => !i.IsTraitPaused);
if (power == null)
return;

View File

@@ -332,7 +332,7 @@ namespace OpenRA.Mods.Common.Traits
public EditorActorPreview this[string id]
{
get { return previews.FirstOrDefault(p => p.ID.Equals(id, StringComparison.OrdinalIgnoreCase)); }
get { return previews.Find(p => p.ID.Equals(id, StringComparison.OrdinalIgnoreCase)); }
}
}
}