Merge pull request #9007 from reaperrr/armor-upgradable

Made Armor upgradable
This commit is contained in:
Pavel Penev
2015-09-02 14:19:30 +03:00
3 changed files with 17 additions and 14 deletions

View File

@@ -13,10 +13,16 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Used to define weapon efficiency modifiers with different percentages per Type.")] [Desc("Used to define weapon efficiency modifiers with different percentages per Type.")]
public class ArmorInfo : TraitInfo<Armor> public class ArmorInfo : UpgradableTraitInfo
{ {
public readonly string Type = null; public readonly string Type = null;
public override object Create(ActorInitializer init) { return new Armor(init.Self, this); }
} }
public class Armor { } public class Armor : UpgradableTrait<ArmorInfo>
{
public Armor(Actor self, ArmorInfo info)
: base(info) { }
}
} }

View File

@@ -9,6 +9,7 @@
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits;
using OpenRA.Traits; using OpenRA.Traits;
@@ -23,7 +24,7 @@ namespace OpenRA.Mods.Common.Warheads
public readonly string[] DamageTypes = new string[0]; public readonly string[] DamageTypes = new string[0];
[FieldLoader.LoadUsing("LoadVersus")] [FieldLoader.LoadUsing("LoadVersus")]
[Desc("Damage percentage versus each armortype. 0% = can't target.")] [Desc("Damage percentage versus each armortype.")]
public readonly Dictionary<string, int> Versus; public readonly Dictionary<string, int> Versus;
public static object LoadVersus(MiniYaml yaml) public static object LoadVersus(MiniYaml yaml)
@@ -34,17 +35,13 @@ namespace OpenRA.Mods.Common.Warheads
: new Dictionary<string, int>(); : new Dictionary<string, int>();
} }
public int DamageVersus(ActorInfo victim) public int DamageVersus(Actor victim)
{ {
var armor = victim.Traits.GetOrDefault<ArmorInfo>(); var armor = victim.TraitsImplementing<Armor>()
if (armor != null && armor.Type != null) .Where(a => !a.IsTraitDisabled && a.Info.Type != null && Versus.ContainsKey(a.Info.Type))
{ .Select(a => Versus[a.Info.Type]);
int versus;
if (Versus.TryGetValue(armor.Type, out versus))
return versus;
}
return 100; return Util.ApplyPercentageModifiers(100, armor);
} }
public override void DoImpact(Target target, Actor firedBy, IEnumerable<int> damageModifiers) public override void DoImpact(Target target, Actor firedBy, IEnumerable<int> damageModifiers)
@@ -60,7 +57,7 @@ namespace OpenRA.Mods.Common.Warheads
public virtual void DoImpact(Actor victim, Actor firedBy, IEnumerable<int> damageModifiers) public virtual void DoImpact(Actor victim, Actor firedBy, IEnumerable<int> damageModifiers)
{ {
var damage = Util.ApplyPercentageModifiers(Damage, damageModifiers.Append(DamageVersus(victim.Info))); var damage = Util.ApplyPercentageModifiers(Damage, damageModifiers.Append(DamageVersus(victim)));
victim.InflictDamage(firedBy, damage, this); victim.InflictDamage(firedBy, damage, this);
} }
} }

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Warheads
return; return;
// Damage is measured as a percentage of the target health // Damage is measured as a percentage of the target health
var damage = Util.ApplyPercentageModifiers(healthInfo.HP, damageModifiers.Append(Damage, DamageVersus(victim.Info))); var damage = Util.ApplyPercentageModifiers(healthInfo.HP, damageModifiers.Append(Damage, DamageVersus(victim)));
victim.InflictDamage(firedBy, damage, this); victim.InflictDamage(firedBy, damage, this);
} }
} }