Fix IDE0032
This commit is contained in:
committed by
Pavel Penev
parent
9809f6ed08
commit
ed90322a0b
@@ -267,10 +267,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
INotifyAddedToWorld, INotifyRemovedFromWorld
|
INotifyAddedToWorld, INotifyRemovedFromWorld
|
||||||
{
|
{
|
||||||
public readonly BuildingInfo Info;
|
public readonly BuildingInfo Info;
|
||||||
|
|
||||||
[Sync]
|
|
||||||
readonly CPos topLeft;
|
|
||||||
|
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
readonly BuildingInfluence influence;
|
readonly BuildingInfluence influence;
|
||||||
|
|
||||||
@@ -278,13 +274,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
readonly (CPos, SubCell)[] targetableCells;
|
readonly (CPos, SubCell)[] targetableCells;
|
||||||
readonly CPos[] transitOnlyCells;
|
readonly CPos[] transitOnlyCells;
|
||||||
|
|
||||||
public CPos TopLeft => topLeft;
|
[Sync]
|
||||||
|
public CPos TopLeft { get; }
|
||||||
public WPos CenterPosition { get; }
|
public WPos CenterPosition { get; }
|
||||||
|
|
||||||
public Building(ActorInitializer init, BuildingInfo info)
|
public Building(ActorInitializer init, BuildingInfo info)
|
||||||
{
|
{
|
||||||
self = init.Self;
|
self = init.Self;
|
||||||
topLeft = init.GetValue<LocationInit, CPos>();
|
TopLeft = init.GetValue<LocationInit, CPos>();
|
||||||
Info = info;
|
Info = info;
|
||||||
influence = self.World.WorldActor.Trait<BuildingInfluence>();
|
influence = self.World.WorldActor.Trait<BuildingInfluence>();
|
||||||
|
|
||||||
@@ -296,7 +293,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
transitOnlyCells = Info.TransitOnlyTiles(TopLeft).ToArray();
|
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; }
|
public (CPos, SubCell)[] OccupiedCells() { return occupiedCells; }
|
||||||
|
|||||||
@@ -60,47 +60,45 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
INotifyKilled[] notifyKilled;
|
INotifyKilled[] notifyKilled;
|
||||||
INotifyKilled[] notifyKilledPlayer;
|
INotifyKilled[] notifyKilledPlayer;
|
||||||
|
|
||||||
[Sync]
|
|
||||||
int hp;
|
|
||||||
|
|
||||||
public int DisplayHP { get; private set; }
|
public int DisplayHP { get; private set; }
|
||||||
|
|
||||||
public Health(ActorInitializer init, HealthInfo info)
|
public Health(ActorInitializer init, HealthInfo info)
|
||||||
{
|
{
|
||||||
Info = 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
|
// Cast to long to avoid overflow when multiplying by the health
|
||||||
var healthInit = init.GetOrDefault<HealthInit>();
|
var healthInit = init.GetOrDefault<HealthInit>();
|
||||||
if (healthInit != null)
|
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 int MaxHP { get; }
|
||||||
|
|
||||||
public bool IsDead => hp <= 0;
|
public bool IsDead => HP <= 0;
|
||||||
public bool RemoveOnDeath = true;
|
public bool RemoveOnDeath = true;
|
||||||
|
|
||||||
public DamageState DamageState
|
public DamageState DamageState
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (hp == MaxHP)
|
if (HP == MaxHP)
|
||||||
return DamageState.Undamaged;
|
return DamageState.Undamaged;
|
||||||
|
|
||||||
if (hp <= 0)
|
if (HP <= 0)
|
||||||
return DamageState.Dead;
|
return DamageState.Dead;
|
||||||
|
|
||||||
if (hp * 100L < MaxHP * 25L)
|
if (HP * 100L < MaxHP * 25L)
|
||||||
return DamageState.Critical;
|
return DamageState.Critical;
|
||||||
|
|
||||||
if (hp * 100L < MaxHP * 50L)
|
if (HP * 100L < MaxHP * 50L)
|
||||||
return DamageState.Heavy;
|
return DamageState.Heavy;
|
||||||
|
|
||||||
if (hp * 100L < MaxHP * 75L)
|
if (HP * 100L < MaxHP * 75L)
|
||||||
return DamageState.Medium;
|
return DamageState.Medium;
|
||||||
|
|
||||||
return DamageState.Light;
|
return DamageState.Light;
|
||||||
@@ -130,7 +128,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (!IsDead)
|
if (!IsDead)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
hp = MaxHP;
|
HP = MaxHP;
|
||||||
|
|
||||||
var ai = new AttackInfo
|
var ai = new AttackInfo
|
||||||
{
|
{
|
||||||
@@ -188,7 +186,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
damage = new Damage((int)appliedDamage, damage.DamageTypes);
|
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
|
var ai = new AttackInfo
|
||||||
{
|
{
|
||||||
@@ -215,7 +213,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
nd.AppliedDamage(attacker, self, ai);
|
nd.AppliedDamage(attacker, self, ai);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hp == 0)
|
if (HP == 0)
|
||||||
{
|
{
|
||||||
foreach (var nd in notifyKilled)
|
foreach (var nd in notifyKilled)
|
||||||
nd.Killed(self, ai);
|
nd.Killed(self, ai);
|
||||||
@@ -234,10 +232,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
void ITick.Tick(Actor self)
|
void ITick.Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (hp >= DisplayHP)
|
if (HP >= DisplayHP)
|
||||||
DisplayHP = hp;
|
DisplayHP = HP;
|
||||||
else
|
else
|
||||||
DisplayHP = (2 * DisplayHP + hp) / 3;
|
DisplayHP = (2 * DisplayHP + HP) / 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,18 +31,12 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
sealed class Immobile : IOccupySpace, ISync, INotifyAddedToWorld, INotifyRemovedFromWorld
|
sealed class Immobile : IOccupySpace, ISync, INotifyAddedToWorld, INotifyRemovedFromWorld
|
||||||
{
|
{
|
||||||
[Sync]
|
|
||||||
readonly CPos location;
|
|
||||||
|
|
||||||
[Sync]
|
|
||||||
readonly WPos position;
|
|
||||||
|
|
||||||
readonly (CPos, SubCell)[] occupied;
|
readonly (CPos, SubCell)[] occupied;
|
||||||
|
|
||||||
public Immobile(ActorInitializer init, ImmobileInfo info)
|
public Immobile(ActorInitializer init, ImmobileInfo info)
|
||||||
{
|
{
|
||||||
location = init.GetValue<LocationInit, CPos>();
|
TopLeft = init.GetValue<LocationInit, CPos>();
|
||||||
position = init.World.Map.CenterOfCell(location);
|
CenterPosition = init.World.Map.CenterOfCell(TopLeft);
|
||||||
|
|
||||||
if (info.OccupiesSpace)
|
if (info.OccupiesSpace)
|
||||||
occupied = new[] { (TopLeft, SubCell.FullCell) };
|
occupied = new[] { (TopLeft, SubCell.FullCell) };
|
||||||
@@ -50,8 +44,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
occupied = Array.Empty<(CPos, SubCell)>();
|
occupied = Array.Empty<(CPos, SubCell)>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CPos TopLeft => location;
|
[Sync]
|
||||||
public WPos CenterPosition => position;
|
public CPos TopLeft { get; }
|
||||||
|
[Sync]
|
||||||
|
public WPos CenterPosition { get; }
|
||||||
public (CPos, SubCell)[] OccupiedCells() { return occupied; }
|
public (CPos, SubCell)[] OccupiedCells() { return occupied; }
|
||||||
|
|
||||||
void INotifyAddedToWorld.AddedToWorld(Actor self)
|
void INotifyAddedToWorld.AddedToWorld(Actor self)
|
||||||
|
|||||||
@@ -42,16 +42,12 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
readonly Dictionary<Actor, int> powerDrain = new();
|
readonly Dictionary<Actor, int> powerDrain = new();
|
||||||
|
|
||||||
[Sync]
|
[Sync]
|
||||||
int totalProvided;
|
public int PowerProvided { get; private set; }
|
||||||
|
|
||||||
public int PowerProvided => totalProvided;
|
|
||||||
|
|
||||||
[Sync]
|
[Sync]
|
||||||
int totalDrained;
|
public int PowerDrained { get; private set; }
|
||||||
|
|
||||||
public int PowerDrained => totalDrained;
|
public int ExcessPower => PowerProvided - PowerDrained;
|
||||||
|
|
||||||
public int ExcessPower => totalProvided - totalDrained;
|
|
||||||
|
|
||||||
public int PowerOutageRemainingTicks { get; private set; }
|
public int PowerOutageRemainingTicks { get; private set; }
|
||||||
public int PowerOutageTotalTicks { get; private set; }
|
public int PowerOutageTotalTicks { get; private set; }
|
||||||
@@ -96,14 +92,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (old > 0)
|
if (old > 0)
|
||||||
totalProvided -= old;
|
PowerProvided -= old;
|
||||||
else if (old < 0)
|
else if (old < 0)
|
||||||
totalDrained += old;
|
PowerDrained += old;
|
||||||
|
|
||||||
if (amount > 0)
|
if (amount > 0)
|
||||||
totalProvided += amount;
|
PowerProvided += amount;
|
||||||
else if (amount < 0)
|
else if (amount < 0)
|
||||||
totalDrained -= amount;
|
PowerDrained -= amount;
|
||||||
|
|
||||||
UpdatePowerState();
|
UpdatePowerState();
|
||||||
}
|
}
|
||||||
@@ -122,9 +118,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (amount > 0)
|
if (amount > 0)
|
||||||
totalProvided -= amount;
|
PowerProvided -= amount;
|
||||||
else if (amount < 0)
|
else if (amount < 0)
|
||||||
totalDrained += amount;
|
PowerDrained += amount;
|
||||||
|
|
||||||
UpdatePowerState();
|
UpdatePowerState();
|
||||||
}
|
}
|
||||||
@@ -147,17 +143,17 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
if (wasHackEnabled != devMode.UnlimitedPower)
|
if (wasHackEnabled != devMode.UnlimitedPower)
|
||||||
{
|
{
|
||||||
totalProvided = 0;
|
PowerProvided = 0;
|
||||||
totalDrained = 0;
|
PowerDrained = 0;
|
||||||
|
|
||||||
if (!devMode.UnlimitedPower)
|
if (!devMode.UnlimitedPower)
|
||||||
{
|
{
|
||||||
foreach (var kv in powerDrain)
|
foreach (var kv in powerDrain)
|
||||||
{
|
{
|
||||||
if (kv.Value > 0)
|
if (kv.Value > 0)
|
||||||
totalProvided += kv.Value;
|
PowerProvided += kv.Value;
|
||||||
else if (kv.Value < 0)
|
else if (kv.Value < 0)
|
||||||
totalDrained -= kv.Value;
|
PowerDrained -= kv.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user