added custom sell value trait. this fixes sell/repair on FACT, and buy/sell exploit on PROC

This commit is contained in:
Chris Forbes
2010-02-11 11:56:07 +13:00
parent f2133458ee
commit eeaf51a859
6 changed files with 31 additions and 3 deletions

View File

@@ -118,6 +118,7 @@
<Compile Include="Support\PerfHistory.cs" /> <Compile Include="Support\PerfHistory.cs" />
<Compile Include="Sync.cs" /> <Compile Include="Sync.cs" />
<Compile Include="Traits\Attack\AttackOmni.cs" /> <Compile Include="Traits\Attack\AttackOmni.cs" />
<Compile Include="Traits\CustomSellValue.cs" />
<Compile Include="Traits\World\BridgeLoadHook.cs" /> <Compile Include="Traits\World\BridgeLoadHook.cs" />
<Compile Include="Traits\World\ChoosePaletteOnSelect.cs" /> <Compile Include="Traits\World\ChoosePaletteOnSelect.cs" />
<Compile Include="Traits\World\Country.cs" /> <Compile Include="Traits\World\Country.cs" />

View File

@@ -15,7 +15,8 @@ namespace OpenRa.Traits.Activities
void DoSell(Actor self) void DoSell(Actor self)
{ {
var cost = self.Info.Traits.Get<BuildableInfo>().Cost; var csv = self.Info.Traits.GetOrDefault<CustomSellValueInfo>();
var cost = csv != null ? csv.Value : self.Info.Traits.Get<BuildableInfo>().Cost;
var hp = self.Info.Traits.Get<OwnedActorInfo>().HP; var hp = self.Info.Traits.Get<OwnedActorInfo>().HP;
var refund = Rules.General.RefundPercent * self.Health * cost / hp; var refund = Rules.General.RefundPercent * self.Health * cost / hp;

View File

@@ -96,8 +96,10 @@ namespace OpenRa.Traits
if (remainingTicks == 0) if (remainingTicks == 0)
{ {
var csv = self.Info.Traits.GetOrDefault<CustomSellValueInfo>();
var buildingValue = csv != null ? csv.Value : self.Info.Traits.Get<BuildableInfo>().Cost;
var maxHP = self.Info.Traits.Get<BuildingInfo>().HP; var maxHP = self.Info.Traits.Get<BuildingInfo>().HP;
var costPerHp = (Rules.General.URepairPercent * self.Info.Traits.Get<BuildableInfo>().Cost) / maxHP; var costPerHp = (Rules.General.URepairPercent * buildingValue) / maxHP;
var hpToRepair = Math.Min(Rules.General.URepairStep, maxHP - self.Health); var hpToRepair = Math.Min(Rules.General.URepairStep, maxHP - self.Health);
var cost = (int)Math.Ceiling(costPerHp * hpToRepair); var cost = (int)Math.Ceiling(costPerHp * hpToRepair);
if (!self.Owner.TakeCash(cost)) if (!self.Owner.TakeCash(cost))

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRa.Traits
{
// allow a nonstandard sell/repair value to avoid
// buy-sell exploits like c&c's PROC.
class CustomSellValueInfo : StatelessTraitInfo<CustomSellValue>
{
public readonly int Value = 0;
}
class CustomSellValue {}
}

View File

@@ -58,6 +58,9 @@ PROC:
StoresOre: StoresOre:
Pips: 17 Pips: 17
Capacity: 1000 Capacity: 1000
CustomSellValue:
Value: 600
SILO: SILO:
Inherits: ^Building Inherits: ^Building
Buildable: Buildable:

View File

@@ -1354,7 +1354,9 @@ FACT:
Production: Production:
Produces: Building,Defense Produces: Building,Defense
ConstructionYard: ConstructionYard:
IronCurtainable: IronCurtainable:
CustomSellValue:
Value: 1000
PROC: PROC:
Inherits: ^Building Inherits: ^Building
@@ -1380,6 +1382,8 @@ PROC:
Pips: 17 Pips: 17
Capacity: 2000 Capacity: 2000
IronCurtainable: IronCurtainable:
CustomSellValue:
Value: 600
SILO: SILO:
Inherits: ^Building Inherits: ^Building