Make CrateAction conditional.
This commit is contained in:
committed by
Paul Chote
parent
93977782a7
commit
f3cbc5f72b
@@ -15,7 +15,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class CrateActionInfo : ITraitInfo
|
||||
public class CrateActionInfo : ConditionalTraitInfo
|
||||
{
|
||||
[Desc("Chance of getting this crate, assuming the collector is compatible.")]
|
||||
public readonly int SelectionShares = 10;
|
||||
@@ -38,29 +38,31 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("Actor types that this crate action will not occur for.")]
|
||||
[ActorReference] public string[] ExcludedActorTypes = { };
|
||||
|
||||
public virtual object Create(ActorInitializer init) { return new CrateAction(init.Self, this); }
|
||||
public override object Create(ActorInitializer init) { return new CrateAction(init.Self, this); }
|
||||
}
|
||||
|
||||
public class CrateAction
|
||||
public class CrateAction : ConditionalTrait<CrateActionInfo>
|
||||
{
|
||||
readonly Actor self;
|
||||
readonly CrateActionInfo info;
|
||||
|
||||
public CrateAction(Actor self, CrateActionInfo info)
|
||||
: base(info)
|
||||
{
|
||||
this.self = self;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public int GetSelectionSharesOuter(Actor collector)
|
||||
{
|
||||
if (self.World.WorldTick < info.TimeDelay)
|
||||
if (IsTraitDisabled)
|
||||
return 0;
|
||||
|
||||
if (info.ExcludedActorTypes.Contains(collector.Info.Name))
|
||||
if (self.World.WorldTick < Info.TimeDelay)
|
||||
return 0;
|
||||
|
||||
if (info.Prerequisites.Any() && !collector.Owner.PlayerActor.Trait<TechTree>().HasPrerequisites(info.Prerequisites))
|
||||
if (Info.ExcludedActorTypes.Contains(collector.Info.Name))
|
||||
return 0;
|
||||
|
||||
if (Info.Prerequisites.Any() && !collector.Owner.PlayerActor.Trait<TechTree>().HasPrerequisites(Info.Prerequisites))
|
||||
return 0;
|
||||
|
||||
return GetSelectionShares(collector);
|
||||
@@ -68,15 +70,15 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public virtual int GetSelectionShares(Actor collector)
|
||||
{
|
||||
return info.SelectionShares;
|
||||
return Info.SelectionShares;
|
||||
}
|
||||
|
||||
public virtual void Activate(Actor collector)
|
||||
{
|
||||
Game.Sound.PlayToPlayer(SoundType.World, collector.Owner, info.Notification);
|
||||
Game.Sound.PlayToPlayer(SoundType.World, collector.Owner, Info.Notification);
|
||||
|
||||
if (info.Effect != null)
|
||||
collector.World.AddFrameEndTask(w => w.Add(new CrateEffect(collector, info.Effect, info.Palette)));
|
||||
if (Info.Effect != null)
|
||||
collector.World.AddFrameEndTask(w => w.Add(new CrateEffect(collector, Info.Effect, Info.Palette)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user