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

@@ -65,8 +65,7 @@ namespace OpenRA.Mods.Cnc.Activities
t.Infiltrated(targetActor, self, infiltrates.Info.Types);
var exp = self.Owner.PlayerActor.TraitOrDefault<PlayerExperience>();
if (exp != null)
exp.GiveExperience(infiltrates.Info.PlayerExperience);
exp?.GiveExperience(infiltrates.Info.PlayerExperience);
if (!string.IsNullOrEmpty(infiltrates.Info.Notification))
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech",

View File

@@ -97,8 +97,8 @@ namespace OpenRA.Mods.Cnc.Activities
}
// Consume teleport charges if this wasn't triggered via chronosphere
if (teleporter == self && pc != null)
pc.ResetChargeTime();
if (teleporter == self)
pc?.ResetChargeTime();
// Trigger screen desaturate effect
if (screenFlash)

View File

@@ -194,8 +194,7 @@ namespace OpenRA.Mods.Cnc.Graphics
public void RefreshBuffer()
{
if (vertexBuffer != null)
vertexBuffer.Dispose();
vertexBuffer?.Dispose();
vertexBuffer = Game.Renderer.CreateVertexBuffer(totalVertexCount);
vertexBuffer.SetData(vertices.SelectMany(v => v).ToArray(), totalVertexCount);
cachedVertexCount = totalVertexCount;
@@ -234,8 +233,7 @@ namespace OpenRA.Mods.Cnc.Graphics
public void Dispose()
{
if (vertexBuffer != null)
vertexBuffer.Dispose();
vertexBuffer?.Dispose();
sheetBuilder.Dispose();
}
}

View File

@@ -52,13 +52,8 @@ namespace OpenRA.Mods.Cnc.Traits
if (!IsTraitDisabled && damage != null)
{
var damageSubTicks = (int)(damage.Value * 100L * Info.DamageMultiplier / Info.DamageDivisor);
if (spm.Powers.TryGetValue(Info.OrderName, out var spi))
{
var dspi = spi as GrantPrerequisiteChargeDrainPower.DischargeableSupportPowerInstance;
if (dspi != null)
dspi.Discharge(damageSubTicks);
}
(spi as GrantPrerequisiteChargeDrainPower.DischargeableSupportPowerInstance)?.Discharge(damageSubTicks);
}
return 100;

View File

@@ -240,9 +240,7 @@ namespace OpenRA.Mods.Cnc.Traits
new LocationInit(self.Location),
new OwnerInit(self.Owner)
});
var driverMobile = driver.TraitOrDefault<Mobile>();
if (driverMobile != null)
driverMobile.Nudge(driver);
driver.TraitOrDefault<Mobile>()?.Nudge(driver);
}
}
}

View File

@@ -49,8 +49,7 @@ namespace OpenRA.Mods.Cnc.Traits
var external = toActor.TraitsImplementing<ExternalCondition>()
.FirstOrDefault(t => t.Info.Condition == info.Condition && t.CanGrantCondition(toActor, this));
if (external != null)
external.GrantCondition(toActor, this, duration, remaining);
external?.GrantCondition(toActor, this, duration, remaining);
}
void IConditionTimerWatcher.Update(int duration, int remaining)