From ed90322a0b8d018cd7a63f0924dc088e30bcae7f Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Wed, 13 Nov 2024 18:02:09 +0000 Subject: [PATCH] Fix IDE0032 --- .../Traits/Buildings/Building.cs | 11 +++--- OpenRA.Mods.Common/Traits/Health.cs | 36 +++++++++---------- OpenRA.Mods.Common/Traits/Immobile.cs | 16 ++++----- .../Traits/Power/Player/PowerManager.cs | 30 +++++++--------- 4 files changed, 40 insertions(+), 53 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Buildings/Building.cs b/OpenRA.Mods.Common/Traits/Buildings/Building.cs index bf037e72d6..d209440e01 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Building.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Building.cs @@ -267,10 +267,6 @@ namespace OpenRA.Mods.Common.Traits INotifyAddedToWorld, INotifyRemovedFromWorld { public readonly BuildingInfo Info; - - [Sync] - readonly CPos topLeft; - readonly Actor self; readonly BuildingInfluence influence; @@ -278,13 +274,14 @@ namespace OpenRA.Mods.Common.Traits readonly (CPos, SubCell)[] targetableCells; readonly CPos[] transitOnlyCells; - public CPos TopLeft => topLeft; + [Sync] + public CPos TopLeft { get; } public WPos CenterPosition { get; } public Building(ActorInitializer init, BuildingInfo info) { self = init.Self; - topLeft = init.GetValue(); + TopLeft = init.GetValue(); Info = info; influence = self.World.WorldActor.Trait(); @@ -296,7 +293,7 @@ namespace OpenRA.Mods.Common.Traits transitOnlyCells = Info.TransitOnlyTiles(TopLeft).ToArray(); - CenterPosition = init.World.Map.CenterOfCell(topLeft) + Info.CenterOffset(init.World); + CenterPosition = init.World.Map.CenterOfCell(TopLeft) + Info.CenterOffset(init.World); } public (CPos, SubCell)[] OccupiedCells() { return occupiedCells; } diff --git a/OpenRA.Mods.Common/Traits/Health.cs b/OpenRA.Mods.Common/Traits/Health.cs index fbac84805a..3ba0744438 100644 --- a/OpenRA.Mods.Common/Traits/Health.cs +++ b/OpenRA.Mods.Common/Traits/Health.cs @@ -60,47 +60,45 @@ namespace OpenRA.Mods.Common.Traits INotifyKilled[] notifyKilled; INotifyKilled[] notifyKilledPlayer; - [Sync] - int hp; - public int DisplayHP { get; private set; } public Health(ActorInitializer init, HealthInfo info) { Info = info; - MaxHP = hp = info.HP > 0 ? info.HP : 1; + MaxHP = HP = info.HP > 0 ? info.HP : 1; // Cast to long to avoid overflow when multiplying by the health var healthInit = init.GetOrDefault(); if (healthInit != null) - hp = (int)(healthInit.Value * (long)MaxHP / 100); + HP = (int)(healthInit.Value * (long)MaxHP / 100); - DisplayHP = hp; + DisplayHP = HP; } - public int HP => hp; + [Sync] + public int HP { get; private set; } public int MaxHP { get; } - public bool IsDead => hp <= 0; + public bool IsDead => HP <= 0; public bool RemoveOnDeath = true; public DamageState DamageState { get { - if (hp == MaxHP) + if (HP == MaxHP) return DamageState.Undamaged; - if (hp <= 0) + if (HP <= 0) return DamageState.Dead; - if (hp * 100L < MaxHP * 25L) + if (HP * 100L < MaxHP * 25L) return DamageState.Critical; - if (hp * 100L < MaxHP * 50L) + if (HP * 100L < MaxHP * 50L) return DamageState.Heavy; - if (hp * 100L < MaxHP * 75L) + if (HP * 100L < MaxHP * 75L) return DamageState.Medium; return DamageState.Light; @@ -130,7 +128,7 @@ namespace OpenRA.Mods.Common.Traits if (!IsDead) return; - hp = MaxHP; + HP = MaxHP; var ai = new AttackInfo { @@ -188,7 +186,7 @@ namespace OpenRA.Mods.Common.Traits damage = new Damage((int)appliedDamage, damage.DamageTypes); } - hp = (hp - damage.Value).Clamp(0, MaxHP); + HP = (HP - damage.Value).Clamp(0, MaxHP); var ai = new AttackInfo { @@ -215,7 +213,7 @@ namespace OpenRA.Mods.Common.Traits nd.AppliedDamage(attacker, self, ai); } - if (hp == 0) + if (HP == 0) { foreach (var nd in notifyKilled) nd.Killed(self, ai); @@ -234,10 +232,10 @@ namespace OpenRA.Mods.Common.Traits void ITick.Tick(Actor self) { - if (hp >= DisplayHP) - DisplayHP = hp; + if (HP >= DisplayHP) + DisplayHP = HP; else - DisplayHP = (2 * DisplayHP + hp) / 3; + DisplayHP = (2 * DisplayHP + HP) / 3; } } diff --git a/OpenRA.Mods.Common/Traits/Immobile.cs b/OpenRA.Mods.Common/Traits/Immobile.cs index 28db3d94e4..67a7ff06a0 100644 --- a/OpenRA.Mods.Common/Traits/Immobile.cs +++ b/OpenRA.Mods.Common/Traits/Immobile.cs @@ -31,18 +31,12 @@ namespace OpenRA.Mods.Common.Traits sealed class Immobile : IOccupySpace, ISync, INotifyAddedToWorld, INotifyRemovedFromWorld { - [Sync] - readonly CPos location; - - [Sync] - readonly WPos position; - readonly (CPos, SubCell)[] occupied; public Immobile(ActorInitializer init, ImmobileInfo info) { - location = init.GetValue(); - position = init.World.Map.CenterOfCell(location); + TopLeft = init.GetValue(); + CenterPosition = init.World.Map.CenterOfCell(TopLeft); if (info.OccupiesSpace) occupied = new[] { (TopLeft, SubCell.FullCell) }; @@ -50,8 +44,10 @@ namespace OpenRA.Mods.Common.Traits occupied = Array.Empty<(CPos, SubCell)>(); } - public CPos TopLeft => location; - public WPos CenterPosition => position; + [Sync] + public CPos TopLeft { get; } + [Sync] + public WPos CenterPosition { get; } public (CPos, SubCell)[] OccupiedCells() { return occupied; } void INotifyAddedToWorld.AddedToWorld(Actor self) diff --git a/OpenRA.Mods.Common/Traits/Power/Player/PowerManager.cs b/OpenRA.Mods.Common/Traits/Power/Player/PowerManager.cs index 1cb89f5094..7315f18094 100644 --- a/OpenRA.Mods.Common/Traits/Power/Player/PowerManager.cs +++ b/OpenRA.Mods.Common/Traits/Power/Player/PowerManager.cs @@ -42,16 +42,12 @@ namespace OpenRA.Mods.Common.Traits readonly Dictionary powerDrain = new(); [Sync] - int totalProvided; - - public int PowerProvided => totalProvided; + public int PowerProvided { get; private set; } [Sync] - int totalDrained; + public int PowerDrained { get; private set; } - public int PowerDrained => totalDrained; - - public int ExcessPower => totalProvided - totalDrained; + public int ExcessPower => PowerProvided - PowerDrained; public int PowerOutageRemainingTicks { get; private set; } public int PowerOutageTotalTicks { get; private set; } @@ -96,14 +92,14 @@ namespace OpenRA.Mods.Common.Traits return; if (old > 0) - totalProvided -= old; + PowerProvided -= old; else if (old < 0) - totalDrained += old; + PowerDrained += old; if (amount > 0) - totalProvided += amount; + PowerProvided += amount; else if (amount < 0) - totalDrained -= amount; + PowerDrained -= amount; UpdatePowerState(); } @@ -122,9 +118,9 @@ namespace OpenRA.Mods.Common.Traits return; if (amount > 0) - totalProvided -= amount; + PowerProvided -= amount; else if (amount < 0) - totalDrained += amount; + PowerDrained += amount; UpdatePowerState(); } @@ -147,17 +143,17 @@ namespace OpenRA.Mods.Common.Traits { if (wasHackEnabled != devMode.UnlimitedPower) { - totalProvided = 0; - totalDrained = 0; + PowerProvided = 0; + PowerDrained = 0; if (!devMode.UnlimitedPower) { foreach (var kv in powerDrain) { if (kv.Value > 0) - totalProvided += kv.Value; + PowerProvided += kv.Value; else if (kv.Value < 0) - totalDrained -= kv.Value; + PowerDrained -= kv.Value; } }