Add FriendlyFire property to GivesExperience.
This commit is contained in:
@@ -13,21 +13,32 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
[Desc("This actor gives experience to a GainsExperience actor when they are killed.")]
|
||||
class GivesExperienceInfo : TraitInfo<GivesExperience>
|
||||
class GivesExperienceInfo : ITraitInfo
|
||||
{
|
||||
[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;
|
||||
|
||||
public object Create(ActorInitializer init) { return new GivesExperience(init.self, this); }
|
||||
}
|
||||
|
||||
class GivesExperience : INotifyKilled
|
||||
{
|
||||
readonly GivesExperienceInfo info;
|
||||
|
||||
public GivesExperience(Actor self, GivesExperienceInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void Killed(Actor self, AttackInfo e)
|
||||
{
|
||||
// Prevent TK from giving exp
|
||||
if (e.Attacker == null || e.Attacker.Destroyed || e.Attacker.Owner.Stances[self.Owner] == Stance.Ally)
|
||||
if (e.Attacker == null || e.Attacker.Destroyed || (!info.FriendlyFire && e.Attacker.Owner.Stances[self.Owner] == Stance.Ally))
|
||||
return;
|
||||
|
||||
var info = self.Info.Traits.Get<GivesExperienceInfo>();
|
||||
var valued = self.Info.Traits.GetOrDefault<ValuedInfo>();
|
||||
|
||||
// Default experience is 100 times our value
|
||||
|
||||
Reference in New Issue
Block a user