split out Sellable into its own trait; yaml requires update

This commit is contained in:
Chris Forbes
2011-03-16 11:15:05 +13:00
committed by Chris Forbes
parent ff44e34d89
commit 4eaa7d5cf2
5 changed files with 53 additions and 11 deletions

View File

@@ -25,8 +25,6 @@ namespace OpenRA.Mods.RA.Buildings
public readonly bool Capturable = false;
public readonly string Footprint = "x";
public readonly int2 Dimensions = new int2(1, 1);
public readonly bool Unsellable = false;
public readonly int RefundPercent = 50;
public readonly string[] BuildSounds = {"placbldg.aud", "build5.aud"};
public readonly string[] SellSounds = {"cashturn.aud"};

View File

@@ -24,17 +24,18 @@ namespace OpenRA.Mods.RA.Buildings
void DoSell(Actor self)
{
var h = self.TraitOrDefault<Health>();
var bi = self.Info.Traits.Get<BuildingInfo>();
var si = self.Info.Traits.Get<SellableInfo>();
var pr = self.Owner.PlayerActor.Trait<PlayerResources>();
var csv = self.Info.Traits.GetOrDefault<CustomSellValueInfo>();
var cost = csv != null ? csv.Value : self.Info.Traits.Get<ValuedInfo>().Cost;
var refund = (cost * bi.RefundPercent * (h == null ? 1 : h.HP)) / (100 * (h == null ? 1 : h.MaxHP));
var refund = (cost * si.RefundPercent * (h == null ? 1 : h.HP)) / (100 * (h == null ? 1 : h.MaxHP));
pr.GiveCash(refund);
foreach (var ns in self.TraitsImplementing<INotifySold>())
ns.Sold(self);
self.Destroy();
}

View File

@@ -0,0 +1,45 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Orders;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Buildings
{
class SellableInfo : TraitInfo<Sellable>
{
public readonly int RefundPercent = 50;
}
class Sellable : IIssueOrder, IResolveOrder
{
public IEnumerable<IOrderTargeter> Orders
{
get { yield return new PaletteOnlyOrderTargeter("Sell"); }
}
public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued )
{
/* todo: make this work */
throw new NotImplementedException();
}
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString == "Sell")
{
self.CancelActivity();
self.QueueActivity(new Sell());
}
}
}
}

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -330,6 +330,7 @@
<Compile Include="Widgets\SidebarButtonWidget.cs" />
<Compile Include="Widgets\RadarWidget.cs" />
<Compile Include="ActorExts.cs" />
<Compile Include="Buildings\Sellable.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -32,12 +32,9 @@ namespace OpenRA.Mods.RA.Orders
{
var underCursor = world.FindUnitsAtMouse(mi.Location)
.Where(a => a.Owner == world.LocalPlayer
&& a.HasTrait<Building>()
&& a.HasTrait<Selectable>()).FirstOrDefault();
&& a.HasTrait<Sellable>()).FirstOrDefault();
var building = underCursor != null ? underCursor.Info.Traits.Get<BuildingInfo>() : null;
if (building != null && !building.Unsellable)
if (underCursor != null)
yield return new Order("Sell", underCursor, false);
}
}