Fix CA1854

This commit is contained in:
RoosterDragon
2023-11-15 19:46:36 +00:00
committed by Pavel Penev
parent c2568ebd1f
commit c8efc5fdd7
19 changed files with 44 additions and 48 deletions

View File

@@ -220,10 +220,10 @@ namespace OpenRA.Mods.Common.Traits
if (!actors.Contains(actor.Name))
return false;
if (!baseBuilder.Info.BuildingLimits.ContainsKey(actor.Name))
if (!baseBuilder.Info.BuildingLimits.TryGetValue(actor.Name, out var limit))
return true;
return playerBuildings.Count(a => a.Info.Name == actor.Name) < baseBuilder.Info.BuildingLimits[actor.Name];
return playerBuildings.Count(a => a.Info.Name == actor.Name) < limit;
});
if (orderBy != null)

View File

@@ -308,11 +308,9 @@ namespace OpenRA.Mods.Common.Traits
clientActor, lookup.Keys, clientActor.Location, BlockedByActor.None,
location =>
{
if (!lookup.ContainsKey(location))
if (!lookup.TryGetValue(location, out var dock))
return 0;
var dock = lookup[location];
// Prefer docks with less occupancy (multiplier is to offset distance cost):
// TODO: add custom wieghts. E.g. owner vs allied.
return dock.Trait.ReservationCount * client.OccupancyCostModifier;

View File

@@ -51,10 +51,10 @@ namespace OpenRA.Mods.Common.Traits
var pos = map.CellContaining(self.CenterPosition);
var terrainType = map.GetTerrainInfo(pos).Type;
if (!Info.TerrainModifier.ContainsKey(terrainType))
if (!Info.TerrainModifier.TryGetValue(terrainType, out var modifiedDamage))
return FullDamage;
return Info.TerrainModifier[terrainType];
return modifiedDamage;
}
}
}

View File

@@ -42,13 +42,13 @@ namespace OpenRA.Mods.Common.Traits
public void Register(Actor actor, GrantConditionOnPrerequisite u, string[] prerequisites)
{
var key = MakeKey(prerequisites);
if (!upgradables.ContainsKey(key))
if (!upgradables.TryGetValue(key, out var list))
{
upgradables.Add(key, new List<(Actor, GrantConditionOnPrerequisite)>());
upgradables.Add(key, list = new List<(Actor, GrantConditionOnPrerequisite)>());
techTree.Add(key, prerequisites, 0, this);
}
upgradables[key].Add((actor, u));
list.Add((actor, u));
// Notify the current state
u.PrerequisitesUpdated(actor, techTree.HasPrerequisites(prerequisites));

View File

@@ -59,9 +59,9 @@ namespace OpenRA.Mods.Common.Traits
{
var key = MakeKey(t);
if (!Powers.ContainsKey(key))
if (!Powers.TryGetValue(key, out var spi))
{
Powers.Add(key, t.CreateInstance(key, this));
Powers.Add(key, spi = t.CreateInstance(key, this));
if (t.Info.Prerequisites.Length > 0)
{
@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
Powers[key].Instances.Add(t);
spi.Instances.Add(t);
}
}