Crates: Part 1
This commit is contained in:
76
OpenRa.Game/Traits/CrateSpawnPower.cs
Normal file
76
OpenRa.Game/Traits/CrateSpawnPower.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRa.Orders;
|
||||
|
||||
namespace OpenRa.Traits
|
||||
{
|
||||
class CrateSpawnPowerInfo : SupportPowerInfo
|
||||
{
|
||||
public readonly float Duration = 0f;
|
||||
public override object Create(Actor self) { return new CrateSpawnPower(self, this); }
|
||||
}
|
||||
|
||||
class CrateSpawnPower : SupportPower, IResolveOrder
|
||||
{
|
||||
public CrateSpawnPower(Actor self, CrateSpawnPowerInfo info) : base(self, info) { }
|
||||
|
||||
protected override void OnBeginCharging() {}
|
||||
protected override void OnFinishCharging() {}
|
||||
protected override void OnActivate()
|
||||
{
|
||||
Game.controller.orderGenerator = new SelectTarget();
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "SpawnCrate")
|
||||
{
|
||||
self.World.AddFrameEndTask(
|
||||
w => w.CreateActor("crate", order.TargetLocation, self.Owner));
|
||||
|
||||
Game.controller.CancelInputMode();
|
||||
FinishActivate();
|
||||
}
|
||||
}
|
||||
|
||||
class SelectTarget : IOrderGenerator
|
||||
{
|
||||
public SelectTarget() { }
|
||||
|
||||
public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
|
||||
{
|
||||
if (mi.Button == MouseButton.Right)
|
||||
Game.controller.CancelInputMode();
|
||||
|
||||
return OrderInner(world, xy, mi);
|
||||
}
|
||||
|
||||
IEnumerable<Order> OrderInner(World world, int2 xy, MouseInput mi)
|
||||
{
|
||||
if (mi.Button == MouseButton.Left)
|
||||
{
|
||||
var loc = mi.Location + Game.viewport.Location;
|
||||
var underCursor = world.FindUnits(loc, loc).FirstOrDefault();
|
||||
|
||||
if (underCursor == null)
|
||||
yield return new Order("SpawnCrate", world.LocalPlayer.PlayerActor, xy);
|
||||
}
|
||||
|
||||
yield break;
|
||||
}
|
||||
|
||||
public void Tick(World world) { }
|
||||
|
||||
public void Render(World world) { }
|
||||
|
||||
public Cursor GetCursor(World world, int2 xy, MouseInput mi)
|
||||
{
|
||||
mi.Button = MouseButton.Left;
|
||||
return OrderInner(world, xy, mi).Any()
|
||||
? Cursor.Ability : Cursor.MoveBlocked;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user