Merge pull request #8011 from penev92/bleed_fixTakeCover
Move prone-related logic from DamageWarhead to TakeCover
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Traits;
|
||||
|
||||
@@ -22,11 +24,27 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("Prone movement speed as a percentage of the normal speed.")]
|
||||
public readonly int SpeedModifier = 50;
|
||||
|
||||
[Desc("Damage types that trigger prone state. Defined on the warheads.")]
|
||||
public readonly string[] DamageTriggers = new string[0];
|
||||
|
||||
[FieldLoader.LoadUsing("LoadModifiers")]
|
||||
[Desc("Damage modifiers for each damage type (defined on the warheads) while the unit is prone.")]
|
||||
public readonly Dictionary<string, int> DamageModifiers = new Dictionary<string, int>();
|
||||
|
||||
public readonly WVec ProneOffset = new WVec(85, 0, -171);
|
||||
|
||||
public readonly string ProneSequencePrefix = "prone-";
|
||||
|
||||
public override object Create(ActorInitializer init) { return new TakeCover(init, this); }
|
||||
|
||||
public static object LoadModifiers(MiniYaml yaml)
|
||||
{
|
||||
var md = yaml.ToDictionary();
|
||||
|
||||
return md.ContainsKey("DamageModifiers")
|
||||
? md["DamageModifiers"].ToDictionary(my => FieldLoader.GetValue<int>("(value)", my.Value))
|
||||
: new Dictionary<string, int>();
|
||||
}
|
||||
}
|
||||
|
||||
public class TakeCover : Turreted, INotifyDamage, IDamageModifier, ISpeedModifier, ISync, IRenderInfantrySequenceModifier
|
||||
@@ -46,14 +64,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void Damaged(Actor self, AttackInfo e)
|
||||
{
|
||||
/* Don't go prone when healed */
|
||||
if (e.Damage > 0 && (e.Warhead == null || !e.Warhead.PreventProne))
|
||||
{
|
||||
if (!IsProne)
|
||||
localOffset = info.ProneOffset;
|
||||
if (e.Damage <= 0 || e.Warhead == null || !e.Warhead.DamageTypes.Any(x => info.DamageTriggers.Contains(x)))
|
||||
return;
|
||||
|
||||
remainingProneTime = info.ProneTime;
|
||||
}
|
||||
if (!IsProne)
|
||||
localOffset = info.ProneOffset;
|
||||
|
||||
remainingProneTime = info.ProneTime;
|
||||
}
|
||||
|
||||
public override void Tick(Actor self)
|
||||
@@ -66,7 +83,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public int GetDamageModifier(Actor attacker, DamageWarhead warhead)
|
||||
{
|
||||
return IsProne && warhead != null ? warhead.ProneModifier : 100;
|
||||
if (!IsProne)
|
||||
return 100;
|
||||
|
||||
var modifierPercentages = info.DamageModifiers.Where(x => warhead.DamageTypes.Contains(x.Key)).Select(x => x.Value);
|
||||
return Util.ApplyPercentageModifiers(100, modifierPercentages);
|
||||
}
|
||||
|
||||
public int GetSpeedModifier()
|
||||
|
||||
@@ -855,6 +855,23 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
}
|
||||
}
|
||||
|
||||
if (engineVersion < 20150426)
|
||||
{
|
||||
// Add DamageModifiers to TakeCover with a "Prone50Percent" default
|
||||
// Add ProneTriggers to TakeCover with a "TriggerProne" default
|
||||
if (node.Key == "TakeCover")
|
||||
{
|
||||
var percent = new MiniYamlNode("Prone50Percent", "50");
|
||||
var dictionary = new MiniYamlNode("DamageModifiers", "");
|
||||
dictionary.Value.Nodes.Add(percent);
|
||||
|
||||
if (node.Value.Nodes.All(x => x.Key != "DamageModifiers"))
|
||||
node.Value.Nodes.Add(dictionary);
|
||||
|
||||
node.Value.Nodes.Add(new MiniYamlNode("DamageTriggers", "TriggerProne"));
|
||||
}
|
||||
}
|
||||
|
||||
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||
}
|
||||
}
|
||||
@@ -1240,6 +1257,40 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
}
|
||||
}
|
||||
|
||||
if (engineVersion < 20150421)
|
||||
{
|
||||
if (node.Key.StartsWith("Warhead") && node.Value.Value == "SpreadDamage")
|
||||
{
|
||||
// Add DamageTypes property to DamageWarheads with a default value "Prone50Percent"
|
||||
if (node.Value.Nodes.All(x => x.Key != "DamageTypes"))
|
||||
{
|
||||
var damage = node.Value.Nodes.FirstOrDefault(x => x.Key == "Damage");
|
||||
var damageValue = damage != null ? FieldLoader.GetValue<int>("Damage", damage.Value.Value) : -1;
|
||||
|
||||
var prone = node.Value.Nodes.FirstOrDefault(x => x.Key == "PreventProne");
|
||||
var preventsProne = prone != null && FieldLoader.GetValue<bool>("PreventProne", prone.Value.Value);
|
||||
|
||||
var proneModifier = node.Value.Nodes.FirstOrDefault(x => x.Key == "ProneModifier");
|
||||
var modifierValue = proneModifier == null ? "50" : proneModifier.Value.Value;
|
||||
|
||||
var value = new List<string>();
|
||||
|
||||
if (damageValue > 0)
|
||||
value.Add("Prone{0}Percent".F(modifierValue));
|
||||
|
||||
if (!preventsProne)
|
||||
value.Add("TriggerProne");
|
||||
|
||||
if (value.Any())
|
||||
node.Value.Nodes.Add(new MiniYamlNode("DamageTypes", value.JoinWith(", ")));
|
||||
}
|
||||
|
||||
// Remove obsolete PreventProne and ProneModifier
|
||||
node.Value.Nodes.RemoveAll(x => x.Key == "PreventProne");
|
||||
node.Value.Nodes.RemoveAll(x => x.Key == "ProneModifier");
|
||||
}
|
||||
}
|
||||
|
||||
UpgradeWeaponRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user