categorize traits better
This commit is contained in:
43
OpenRa.Game/Traits/Player/PlaceBuilding.cs
Normal file
43
OpenRa.Game/Traits/Player/PlaceBuilding.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRa.GameRules;
|
||||
|
||||
namespace OpenRa.Traits
|
||||
{
|
||||
class PlaceBuildingInfo : StatelessTraitInfo<PlaceBuilding> { }
|
||||
|
||||
class PlaceBuilding : IResolveOrder
|
||||
{
|
||||
public void ResolveOrder( Actor self, Order order )
|
||||
{
|
||||
if( order.OrderString == "PlaceBuilding" )
|
||||
{
|
||||
self.World.AddFrameEndTask( _ =>
|
||||
{
|
||||
var queue = self.traits.Get<ProductionQueue>();
|
||||
var unit = Rules.Info[ order.TargetString ];
|
||||
var producing = queue.CurrentItem(unit.Category);
|
||||
if( producing == null || producing.Item != order.TargetString || producing.RemainingTime != 0 )
|
||||
return;
|
||||
|
||||
self.World.CreateActor( order.TargetString, order.TargetLocation, order.Player );
|
||||
Sound.PlayToPlayer(order.Player, "placbldg.aud");
|
||||
Sound.PlayToPlayer(order.Player, "build5.aud");
|
||||
|
||||
var facts = self.World.Queries.OwnedBy[self.Owner]
|
||||
.WithTrait<ConstructionYard>().Select(x => x.Actor);
|
||||
|
||||
var primaryFact = facts.Where(y => y.traits.Get<Production>().IsPrimary);
|
||||
var fact = (primaryFact.Count() > 0) ? primaryFact.FirstOrDefault() : facts.FirstOrDefault();
|
||||
|
||||
if (fact != null)
|
||||
fact.traits.Get<RenderBuilding>().PlayCustomAnim(fact, "build");
|
||||
|
||||
queue.FinishProduction(unit.Category);
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user