Merge pull request #11561 from Phrohdoh/gives-exp-stances

Replace GivesExperience.FriendlyFire and GivesBounty.Stances with ValidStances
This commit is contained in:
abcdefg30
2016-07-03 16:24:37 +02:00
committed by GitHub
3 changed files with 35 additions and 7 deletions

View File

@@ -10,7 +10,6 @@
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Effects;
using OpenRA.Mods.Common.Warheads;
using OpenRA.Traits;
@@ -27,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly int LevelMod = 125;
[Desc("Stance the attacking player needs to receive the bounty.")]
public readonly Stance[] Stances = { Stance.Neutral, Stance.Enemy };
public readonly Stance ValidStances = Stance.Neutral | Stance.Enemy;
[Desc("Whether to show a floating text announcing the won bounty.")]
public readonly bool ShowBounty = true;
@@ -64,7 +63,7 @@ namespace OpenRA.Mods.Common.Traits
if (e.Attacker == null || e.Attacker.Disposed)
return;
if (!info.Stances.Contains(e.Attacker.Owner.Stances[self.Owner]))
if (!info.ValidStances.HasStance(e.Attacker.Owner.Stances[self.Owner]))
return;
var warhead = e.Warhead as DamageWarhead;

View File

@@ -19,8 +19,8 @@ namespace OpenRA.Mods.Common.Traits
[Desc("If -1, use the value of the unit cost.")]
public readonly int Experience = -1;
[Desc("Grant experience for team-kills.")]
public readonly bool FriendlyFire = false;
[Desc("Stance the attacking player needs to receive the experience.")]
public readonly Stance ValidStances = Stance.Neutral | Stance.Enemy;
public object Create(ActorInitializer init) { return new GivesExperience(init.Self, this); }
}
@@ -36,8 +36,10 @@ namespace OpenRA.Mods.Common.Traits
public void Killed(Actor self, AttackInfo e)
{
// Prevent TK from giving exp
if (e.Attacker == null || e.Attacker.Disposed || (!info.FriendlyFire && e.Attacker.Owner.Stances[self.Owner] == Stance.Ally))
if (e.Attacker == null || e.Attacker.Disposed)
return;
if (!info.ValidStances.HasStance(e.Attacker.Owner.Stances[self.Owner]))
return;
var valued = self.Info.TraitInfoOrDefault<ValuedInfo>();

View File

@@ -185,6 +185,33 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
}
if (engineVersion < 20160702)
{
if (node.Key.StartsWith("GivesExperience"))
{
var ff = "FriendlyFire";
var ffNode = node.Value.Nodes.FirstOrDefault(n => n.Key == ff);
if (ffNode != null)
{
var newStanceStr = "";
if (FieldLoader.GetValue<bool>(ff, ffNode.Value.Value))
newStanceStr = "Neutral, Enemy, Ally";
else
newStanceStr = "Neutral, Enemy";
node.Value.Nodes.Add(new MiniYamlNode("ValidStances", newStanceStr));
}
node.Value.Nodes.Remove(ffNode);
}
else if (node.Key.StartsWith("GivesBounty"))
{
var stancesNode = node.Value.Nodes.FirstOrDefault(n => n.Key == "Stances");
if (stancesNode != null)
stancesNode.Key = "ValidStances";
}
}
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
}