Use Null-Propagation Operator

This commit is contained in:
teinarss
2020-08-16 11:38:14 +02:00
committed by Paul Chote
parent 8d27d22100
commit 9c4fd0e3d3
113 changed files with 219 additions and 464 deletions

View File

@@ -26,9 +26,7 @@ namespace OpenRA.Mods.Common.Traits
if (!building.AppearsFriendlyTo(self))
return;
var rb = building.TraitOrDefault<RepairableBuilding>();
if (rb != null)
rb.RepairBuilding(building, self.Owner);
building.TraitOrDefault<RepairableBuilding>()?.RepairBuilding(building, self.Owner);
}
}
}

View File

@@ -80,8 +80,7 @@ namespace OpenRA.Mods.Common.Traits
if (p != self.Owner && p.IsAlliedWith(self.Owner) && p != e.Attacker.Owner)
Game.Sound.PlayNotification(rules, p, "Speech", info.AllyNotification, p.Faction.InternalName);
if (radarPings != null)
radarPings.Add(() => self.Owner.IsAlliedWith(self.World.RenderPlayer), self.CenterPosition, info.RadarPingColor, info.RadarPingDuration);
radarPings?.Add(() => self.Owner.IsAlliedWith(self.World.RenderPlayer), self.CenterPosition, info.RadarPingColor, info.RadarPingDuration);
}
lastAttackTime = self.World.WorldTick;

View File

@@ -244,10 +244,7 @@ namespace OpenRA.Mods.Common.Traits
case "DevPlayerExperience":
{
var playerExperience = self.Owner.PlayerActor.TraitOrDefault<PlayerExperience>();
if (playerExperience != null)
playerExperience.GiveExperience((int)order.ExtraData);
self.Owner.PlayerActor.TraitOrDefault<PlayerExperience>()?.GiveExperience((int)order.ExtraData);
break;
}

View File

@@ -61,8 +61,7 @@ namespace OpenRA.Mods.Common.Traits
{
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.Notification, self.Owner.Faction.InternalName);
if (radarPings != null)
radarPings.Add(() => self.Owner.IsAlliedWith(self.World.RenderPlayer), self.CenterPosition, info.RadarPingColor, info.RadarPingDuration);
radarPings?.Add(() => self.Owner.IsAlliedWith(self.World.RenderPlayer), self.CenterPosition, info.RadarPingColor, info.RadarPingDuration);
}
lastAttackTime = self.World.WorldTick;

View File

@@ -170,8 +170,7 @@ namespace OpenRA.Mods.Common.Traits
foreach (var t in buildingInfo.Tiles(targetLocation))
{
var host = buildingInfluence.GetBuildingAt(t);
if (host != null)
host.World.Remove(host);
host?.World.Remove(host);
}
}
@@ -193,14 +192,10 @@ namespace OpenRA.Mods.Common.Traits
queue.EndProduction(item);
// FindBaseProvider may return null if the build anywhere cheat is active
// BuildingInfo.IsCloseEnoughToBase has already verified that this is a valid build location
if (buildingInfo.RequiresBaseProvider)
{
// May be null if the build anywhere cheat is active
// BuildingInfo.IsCloseEnoughToBase has already verified that this is a valid build location
var provider = buildingInfo.FindBaseProvider(w, self.Owner, targetLocation);
if (provider != null)
provider.BeginCooldown();
}
buildingInfo.FindBaseProvider(w, self.Owner, targetLocation)?.BeginCooldown();
if (GetNumBuildables(self.Owner) > prevItems)
triggerNotification = true;

View File

@@ -61,8 +61,7 @@ namespace OpenRA.Mods.Common.Traits
{
terrainColor[uv] = GetColor(world.Map, uv);
if (CellTerrainColorChanged != null)
CellTerrainColorChanged(uv);
CellTerrainColorChanged?.Invoke(uv);
}
public void WorldLoaded(World w, WorldRenderer wr)

View File

@@ -465,9 +465,7 @@ namespace OpenRA.Mods.Common.Traits
protected void PauseProduction(string itemName, bool paused)
{
var item = Queue.FirstOrDefault(a => a.Item == itemName);
if (item != null)
item.Pause(paused);
Queue.FirstOrDefault(a => a.Item == itemName)?.Pause(paused);
}
protected void CancelProduction(string itemName, uint numberToCancel)
@@ -646,8 +644,7 @@ namespace OpenRA.Mods.Common.Traits
if (Done)
{
if (OnComplete != null)
OnComplete();
OnComplete?.Invoke();
return;
}