Add DamageSource to Explodes

This commit is contained in:
Mustafa Alperen Seki
2018-06-28 14:40:07 +03:00
committed by Paul Chote
parent d07bd029db
commit 6073de52ca
2 changed files with 13 additions and 4 deletions

View File

@@ -19,6 +19,8 @@ namespace OpenRA.Mods.Common.Traits
{ {
public enum ExplosionType { Footprint, CenterPosition } public enum ExplosionType { Footprint, CenterPosition }
public enum DamageSource { Self, Killer }
[Desc("This actor explodes when killed.")] [Desc("This actor explodes when killed.")]
public class ExplodesInfo : ConditionalTraitInfo, Requires<HealthInfo> public class ExplodesInfo : ConditionalTraitInfo, Requires<HealthInfo>
{ {
@@ -40,6 +42,10 @@ namespace OpenRA.Mods.Common.Traits
[Desc("DeathType(s) that trigger the explosion. Leave empty to always trigger an explosion.")] [Desc("DeathType(s) that trigger the explosion. Leave empty to always trigger an explosion.")]
public readonly HashSet<string> DeathTypes = new HashSet<string>(); public readonly HashSet<string> DeathTypes = new HashSet<string>();
[Desc("Who is counted as source of damage for explosion.",
"Possible values are Self and Killer.")]
public readonly DamageSource DamageSource = DamageSource.Self;
[Desc("Possible values are CenterPosition (explosion at the actors' center) and ", [Desc("Possible values are CenterPosition (explosion at the actors' center) and ",
"Footprint (explosion on each occupied cell).")] "Footprint (explosion on each occupied cell).")]
public readonly ExplosionType Type = ExplosionType.CenterPosition; public readonly ExplosionType Type = ExplosionType.CenterPosition;
@@ -103,20 +109,21 @@ namespace OpenRA.Mods.Common.Traits
if (weapon == null) if (weapon == null)
return; return;
var source = Info.DamageSource == DamageSource.Self ? self : e.Attacker;
if (weapon.Report != null && weapon.Report.Any()) if (weapon.Report != null && weapon.Report.Any())
Game.Sound.Play(SoundType.World, weapon.Report.Random(e.Attacker.World.SharedRandom), self.CenterPosition); Game.Sound.Play(SoundType.World, weapon.Report.Random(source.World.SharedRandom), self.CenterPosition);
if (Info.Type == ExplosionType.Footprint && buildingInfo != null) if (Info.Type == ExplosionType.Footprint && buildingInfo != null)
{ {
var cells = buildingInfo.UnpathableTiles(self.Location); var cells = buildingInfo.UnpathableTiles(self.Location);
foreach (var c in cells) foreach (var c in cells)
weapon.Impact(Target.FromPos(self.World.Map.CenterOfCell(c)), e.Attacker, Enumerable.Empty<int>()); weapon.Impact(Target.FromPos(self.World.Map.CenterOfCell(c)), source, Enumerable.Empty<int>());
return; return;
} }
// Use .FromPos since this actor is killed. Cannot use Target.FromActor // Use .FromPos since this actor is killed. Cannot use Target.FromActor
weapon.Impact(Target.FromPos(self.CenterPosition), e.Attacker, Enumerable.Empty<int>()); weapon.Impact(Target.FromPos(self.CenterPosition), source, Enumerable.Empty<int>());
} }
WeaponInfo ChooseWeaponForExplosion(Actor self) WeaponInfo ChooseWeaponForExplosion(Actor self)
@@ -135,8 +142,9 @@ namespace OpenRA.Mods.Common.Traits
return; return;
// Cast to long to avoid overflow when multiplying by the health // Cast to long to avoid overflow when multiplying by the health
var source = Info.DamageSource == DamageSource.Self ? self : e.Attacker;
if (health.HP * 100L < Info.DamageThreshold * (long)health.MaxHP) if (health.HP * 100L < Info.DamageThreshold * (long)health.MaxHP)
self.World.AddFrameEndTask(w => self.Kill(e.Attacker)); self.World.AddFrameEndTask(w => self.Kill(source));
} }
} }
} }

View File

@@ -700,6 +700,7 @@ DTRK:
Explodes: Explodes:
Weapon: MiniNuke Weapon: MiniNuke
EmptyWeapon: MiniNuke EmptyWeapon: MiniNuke
DamageSource: Killer
AttackSuicides: AttackSuicides:
-DamageMultiplier@IRONCURTAIN: -DamageMultiplier@IRONCURTAIN:
KillsSelf: KillsSelf: