split out Sellable into its own trait; yaml requires update
This commit is contained in:
committed by
Chris Forbes
parent
ff44e34d89
commit
4eaa7d5cf2
@@ -25,8 +25,6 @@ namespace OpenRA.Mods.RA.Buildings
|
|||||||
public readonly bool Capturable = false;
|
public readonly bool Capturable = false;
|
||||||
public readonly string Footprint = "x";
|
public readonly string Footprint = "x";
|
||||||
public readonly int2 Dimensions = new int2(1, 1);
|
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[] BuildSounds = {"placbldg.aud", "build5.aud"};
|
||||||
public readonly string[] SellSounds = {"cashturn.aud"};
|
public readonly string[] SellSounds = {"cashturn.aud"};
|
||||||
|
|||||||
@@ -24,17 +24,18 @@ namespace OpenRA.Mods.RA.Buildings
|
|||||||
void DoSell(Actor self)
|
void DoSell(Actor self)
|
||||||
{
|
{
|
||||||
var h = self.TraitOrDefault<Health>();
|
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 pr = self.Owner.PlayerActor.Trait<PlayerResources>();
|
||||||
var csv = self.Info.Traits.GetOrDefault<CustomSellValueInfo>();
|
var csv = self.Info.Traits.GetOrDefault<CustomSellValueInfo>();
|
||||||
|
|
||||||
var cost = csv != null ? csv.Value : self.Info.Traits.Get<ValuedInfo>().Cost;
|
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);
|
pr.GiveCash(refund);
|
||||||
|
|
||||||
foreach (var ns in self.TraitsImplementing<INotifySold>())
|
foreach (var ns in self.TraitsImplementing<INotifySold>())
|
||||||
ns.Sold(self);
|
ns.Sold(self);
|
||||||
|
|
||||||
self.Destroy();
|
self.Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
45
OpenRA.Mods.RA/Buildings/Sellable.cs
Normal file
45
OpenRA.Mods.RA/Buildings/Sellable.cs
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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">
|
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
@@ -330,6 +330,7 @@
|
|||||||
<Compile Include="Widgets\SidebarButtonWidget.cs" />
|
<Compile Include="Widgets\SidebarButtonWidget.cs" />
|
||||||
<Compile Include="Widgets\RadarWidget.cs" />
|
<Compile Include="Widgets\RadarWidget.cs" />
|
||||||
<Compile Include="ActorExts.cs" />
|
<Compile Include="ActorExts.cs" />
|
||||||
|
<Compile Include="Buildings\Sellable.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
@@ -32,12 +32,9 @@ namespace OpenRA.Mods.RA.Orders
|
|||||||
{
|
{
|
||||||
var underCursor = world.FindUnitsAtMouse(mi.Location)
|
var underCursor = world.FindUnitsAtMouse(mi.Location)
|
||||||
.Where(a => a.Owner == world.LocalPlayer
|
.Where(a => a.Owner == world.LocalPlayer
|
||||||
&& a.HasTrait<Building>()
|
&& a.HasTrait<Sellable>()).FirstOrDefault();
|
||||||
&& a.HasTrait<Selectable>()).FirstOrDefault();
|
|
||||||
|
if (underCursor != null)
|
||||||
var building = underCursor != null ? underCursor.Info.Traits.Get<BuildingInfo>() : null;
|
|
||||||
|
|
||||||
if (building != null && !building.Unsellable)
|
|
||||||
yield return new Order("Sell", underCursor, false);
|
yield return new Order("Sell", underCursor, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user