Refactor DemoTruck/Chronoshiftable inheritance
This commit is contained in:
@@ -24,7 +24,7 @@ namespace OpenRa.Game.Orders
|
|||||||
var loc = mi.Location + Game.viewport.Location;
|
var loc = mi.Location + Game.viewport.Location;
|
||||||
var underCursor = Game.FindUnits(loc, loc)
|
var underCursor = Game.FindUnits(loc, loc)
|
||||||
.Where(a => a.Owner == Game.LocalPlayer
|
.Where(a => a.Owner == Game.LocalPlayer
|
||||||
&& a.traits.WithInterface<IChronoshiftable>().Any()
|
&& a.traits.WithInterface<Chronoshiftable>().Any()
|
||||||
&& a.Info.Selectable).FirstOrDefault();
|
&& a.Info.Selectable).FirstOrDefault();
|
||||||
|
|
||||||
var unit = underCursor != null ? underCursor.Info as UnitInfo : null;
|
var unit = underCursor != null ? underCursor.Info as UnitInfo : null;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using System.Drawing;
|
|||||||
|
|
||||||
namespace OpenRa.Game.Traits
|
namespace OpenRa.Game.Traits
|
||||||
{
|
{
|
||||||
class Chronoshiftable : IOrder, ISpeedModifier, ITick, IChronoshiftable
|
class Chronoshiftable : IOrder, ISpeedModifier, ITick
|
||||||
{
|
{
|
||||||
// Return-to-sender logic
|
// Return-to-sender logic
|
||||||
int2 chronoshiftOrigin;
|
int2 chronoshiftOrigin;
|
||||||
|
|||||||
@@ -6,29 +6,27 @@ using OpenRa.Game.Orders;
|
|||||||
|
|
||||||
namespace OpenRa.Game.Traits
|
namespace OpenRa.Game.Traits
|
||||||
{
|
{
|
||||||
class DemoTruck : IOrder, ISpeedModifier, INotifyDamage, IChronoshiftable
|
class DemoTruck : Chronoshiftable, IOrder, INotifyDamage
|
||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
public DemoTruck(Actor self)
|
public DemoTruck(Actor self)
|
||||||
|
: base(self)
|
||||||
{
|
{
|
||||||
this.self = self;
|
this.self = self;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fire primary on Chronoshift
|
public new void ResolveOrder(Actor self, Order order)
|
||||||
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
|
||||||
{
|
{
|
||||||
return null; // Chronoshift order is issued through Chrome.
|
// Override chronoshifting action to detonate vehicle
|
||||||
}
|
|
||||||
|
|
||||||
public void ResolveOrder(Actor self, Order order)
|
|
||||||
{
|
|
||||||
if (order.OrderString == "ChronosphereSelect")
|
|
||||||
Game.controller.orderGenerator = new ChronoshiftDestinationOrderGenerator(self);
|
|
||||||
|
|
||||||
var movement = self.traits.WithInterface<IMovement>().FirstOrDefault();
|
var movement = self.traits.WithInterface<IMovement>().FirstOrDefault();
|
||||||
var chronosphere = Game.world.Actors.Where(a => a.Owner == order.Subject.Owner && a.traits.Contains<Chronosphere>()).FirstOrDefault();
|
var chronosphere = Game.world.Actors.Where(a => a.Owner == order.Subject.Owner && a.traits.Contains<Chronosphere>()).FirstOrDefault();
|
||||||
if (order.OrderString == "Chronoshift" && movement.CanEnterCell(order.TargetLocation))
|
if (order.OrderString == "Chronoshift" && movement.CanEnterCell(order.TargetLocation))
|
||||||
|
{
|
||||||
self.InflictDamage(chronosphere, self.Health, Rules.WarheadInfo["Super"]);
|
self.InflictDamage(chronosphere, self.Health, Rules.WarheadInfo["Super"]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
base.ResolveOrder(self, order);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fire primary on death
|
// Fire primary on death
|
||||||
@@ -49,11 +47,5 @@ namespace OpenRa.Game.Traits
|
|||||||
w => w.Add(new Bullet(self.Info.Primary, detonatedBy.Owner, detonatedBy,
|
w => w.Add(new Bullet(self.Info.Primary, detonatedBy.Owner, detonatedBy,
|
||||||
detonateLocation, detonateLocation, altitude, altitude)));
|
detonateLocation, detonateLocation, altitude, altitude)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetSpeedModifier()
|
|
||||||
{
|
|
||||||
// ARGH! You must not do this, it will desync!
|
|
||||||
return (Game.controller.orderGenerator is ChronoshiftDestinationOrderGenerator) ? 0f : 1f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ namespace OpenRa.Game.Traits
|
|||||||
bool IsCrushableBy(UnitMovementType umt, Player player);
|
bool IsCrushableBy(UnitMovementType umt, Player player);
|
||||||
bool IsPathableCrush(UnitMovementType umt, Player player);
|
bool IsPathableCrush(UnitMovementType umt, Player player);
|
||||||
}
|
}
|
||||||
interface IChronoshiftable{}
|
|
||||||
struct Renderable
|
struct Renderable
|
||||||
{
|
{
|
||||||
public readonly Sprite Sprite;
|
public readonly Sprite Sprite;
|
||||||
|
|||||||
Reference in New Issue
Block a user