Add a PlayerExperience trait
This commit is contained in:
committed by
Oliver Brakmann
parent
5157ac917f
commit
c3e862b2ca
@@ -22,6 +22,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("Stance the attacking player needs to receive the experience.")]
|
||||
public readonly Stance ValidStances = Stance.Neutral | Stance.Enemy;
|
||||
|
||||
[Desc("Percentage of the `Experience` value that is being granted to the killing actor.")]
|
||||
public readonly int ActorExperienceModifier = 10000;
|
||||
|
||||
[Desc("Percentage of the `Experience` value that is being granted to the player owning the killing actor.")]
|
||||
public readonly int PlayerExperienceModifier = 0;
|
||||
|
||||
public object Create(ActorInitializer init) { return new GivesExperience(init.Self, this); }
|
||||
}
|
||||
|
||||
@@ -44,14 +50,17 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
var valued = self.Info.TraitInfoOrDefault<ValuedInfo>();
|
||||
|
||||
// Default experience is 100 times our value
|
||||
var exp = info.Experience >= 0
|
||||
? info.Experience
|
||||
: valued != null ? valued.Cost * 100 : 0;
|
||||
: valued != null ? valued.Cost : 0;
|
||||
|
||||
var killer = e.Attacker.TraitOrDefault<GainsExperience>();
|
||||
if (killer != null)
|
||||
killer.GiveExperience(exp);
|
||||
killer.GiveExperience(Util.ApplyPercentageModifiers(exp, new[] { info.ActorExperienceModifier }));
|
||||
|
||||
var attackerExp = e.Attacker.Owner.PlayerActor.TraitOrDefault<PlayerExperience>();
|
||||
if (attackerExp != null)
|
||||
attackerExp.GiveExperience(Util.ApplyPercentageModifiers(exp, new[] { info.PlayerExperienceModifier }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user