Merge pull request #9982 from abcdefg30/chronodesc
Unhardcode and document things in Chronoshiftable
This commit is contained in:
@@ -61,9 +61,7 @@ namespace OpenRA.Mods.Common.Lint
|
||||
var actorReference = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
|
||||
var ownerInit = actorReference.InitDict.GetOrDefault<OwnerInit>();
|
||||
if (ownerInit == null)
|
||||
{
|
||||
emitError("Actor {0} is not owned by any player.".F(kv.Key));
|
||||
}
|
||||
else
|
||||
{
|
||||
var ownerName = ownerInit.PlayerName;
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
};
|
||||
|
||||
foreach (var nd in self.TraitsImplementing<INotifyDamage>()
|
||||
.Concat(self.Owner.PlayerActor.TraitsImplementing<INotifyDamage>()))
|
||||
.Concat(self.Owner.PlayerActor.TraitsImplementing<INotifyDamage>()))
|
||||
nd.Damaged(self, ai);
|
||||
|
||||
foreach (var nd in self.TraitsImplementing<INotifyDamageStateChanged>())
|
||||
@@ -99,7 +99,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
if (Info.NotifyAppliedDamage && repairer != null && repairer.IsInWorld && !repairer.IsDead)
|
||||
foreach (var nd in repairer.TraitsImplementing<INotifyAppliedDamage>()
|
||||
.Concat(repairer.Owner.PlayerActor.TraitsImplementing<INotifyAppliedDamage>()))
|
||||
.Concat(repairer.Owner.PlayerActor.TraitsImplementing<INotifyAppliedDamage>()))
|
||||
nd.AppliedDamage(repairer, self, ai);
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
};
|
||||
|
||||
foreach (var nd in self.TraitsImplementing<INotifyDamage>()
|
||||
.Concat(self.Owner.PlayerActor.TraitsImplementing<INotifyDamage>()))
|
||||
.Concat(self.Owner.PlayerActor.TraitsImplementing<INotifyDamage>()))
|
||||
nd.Damaged(self, ai);
|
||||
|
||||
if (DamageState != oldState)
|
||||
@@ -142,7 +142,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
if (Info.NotifyAppliedDamage && attacker != null && attacker.IsInWorld && !attacker.IsDead)
|
||||
foreach (var nd in attacker.TraitsImplementing<INotifyAppliedDamage>()
|
||||
.Concat(attacker.Owner.PlayerActor.TraitsImplementing<INotifyAppliedDamage>()))
|
||||
.Concat(attacker.Owner.PlayerActor.TraitsImplementing<INotifyAppliedDamage>()))
|
||||
nd.AppliedDamage(attacker, self, ai);
|
||||
|
||||
if (hp == 0)
|
||||
|
||||
@@ -19,21 +19,29 @@ namespace OpenRA.Mods.RA.Traits
|
||||
[Desc("Can be teleported via Chronoshift power.")]
|
||||
public class ChronoshiftableInfo : ITraitInfo
|
||||
{
|
||||
[Desc("Should the actor die instead of being teleported?")]
|
||||
public readonly bool ExplodeInstead = false;
|
||||
public readonly string ChronoshiftSound = "chrono2.aud";
|
||||
|
||||
[Desc("Should the actor return to its location after the chronoshift weared out?.")]
|
||||
public readonly bool ReturnToOrigin = true;
|
||||
|
||||
[Desc("The color the bar of the 'return-to-origin' logic has.")]
|
||||
public readonly Color TimeBarColor = Color.White;
|
||||
|
||||
public object Create(ActorInitializer init) { return new Chronoshiftable(init, this); }
|
||||
}
|
||||
|
||||
public class Chronoshiftable : ITick, ISync, ISelectionBar, IDeathActorInitModifier
|
||||
public class Chronoshiftable : ITick, ISync, ISelectionBar, IDeathActorInitModifier, INotifyCreated
|
||||
{
|
||||
readonly ChronoshiftableInfo info;
|
||||
readonly Actor self;
|
||||
Actor chronosphere;
|
||||
bool killCargo;
|
||||
int duration;
|
||||
IPositionable iPositionable;
|
||||
|
||||
// Return-to-sender logic
|
||||
// Return-to-origin logic
|
||||
[Sync] public CPos Origin;
|
||||
[Sync] public int ReturnTicks = 0;
|
||||
|
||||
@@ -54,7 +62,7 @@ namespace OpenRA.Mods.RA.Traits
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (ReturnTicks <= 0)
|
||||
if (!info.ReturnToOrigin || ReturnTicks <= 0)
|
||||
return;
|
||||
|
||||
// Return to original location
|
||||
@@ -65,28 +73,33 @@ namespace OpenRA.Mods.RA.Traits
|
||||
}
|
||||
}
|
||||
|
||||
public void Created(Actor self)
|
||||
{
|
||||
iPositionable = self.TraitOrDefault<IPositionable>();
|
||||
}
|
||||
|
||||
// Can't be used in synced code, except with ignoreVis.
|
||||
public virtual bool CanChronoshiftTo(Actor self, CPos targetLocation)
|
||||
{
|
||||
// TODO: Allow enemy units to be chronoshifted into bad terrain to kill them
|
||||
return self.Info.HasTraitInfo<IPositionableInfo>() && self.Trait<IPositionable>().CanEnterCell(targetLocation);
|
||||
return iPositionable != null && iPositionable.CanEnterCell(targetLocation);
|
||||
}
|
||||
|
||||
public virtual bool Teleport(Actor self, CPos targetLocation, int duration, bool killCargo, Actor chronosphere)
|
||||
{
|
||||
// some things appear chronoshiftable, but instead they just die.
|
||||
// Some things appear chronoshiftable, but instead they just die.
|
||||
if (info.ExplodeInstead)
|
||||
{
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
// damage is inflicted by the chronosphere
|
||||
// Damage is inflicted by the chronosphere
|
||||
if (!self.Disposed)
|
||||
self.InflictDamage(chronosphere, int.MaxValue, null);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
// Set up return-to-sender info
|
||||
// Set up return-to-origin info
|
||||
Origin = self.Location;
|
||||
ReturnTicks = duration;
|
||||
this.duration = duration;
|
||||
@@ -103,19 +116,23 @@ namespace OpenRA.Mods.RA.Traits
|
||||
// Show the remaining time as a bar
|
||||
public float GetValue()
|
||||
{
|
||||
// otherwise an empty bar is rendered all the time
|
||||
if (!info.ReturnToOrigin)
|
||||
return 0f;
|
||||
|
||||
// Otherwise an empty bar is rendered all the time
|
||||
if (ReturnTicks == 0 || !self.Owner.IsAlliedWith(self.World.RenderPlayer))
|
||||
return 0f;
|
||||
|
||||
return (float)ReturnTicks / duration;
|
||||
}
|
||||
|
||||
public Color GetColor() { return Color.White; }
|
||||
public Color GetColor() { return info.TimeBarColor; }
|
||||
|
||||
public void ModifyDeathActorInit(Actor self, TypeDictionary init)
|
||||
{
|
||||
if (ReturnTicks <= 0)
|
||||
if (!info.ReturnToOrigin || ReturnTicks <= 0)
|
||||
return;
|
||||
|
||||
init.Add(new ChronoshiftOriginInit(Origin));
|
||||
init.Add(new ChronoshiftReturnInit(ReturnTicks));
|
||||
if (chronosphere != self)
|
||||
|
||||
Reference in New Issue
Block a user