added custom sell value trait. this fixes sell/repair on FACT, and buy/sell exploit on PROC
This commit is contained in:
@@ -118,6 +118,7 @@
|
||||
<Compile Include="Support\PerfHistory.cs" />
|
||||
<Compile Include="Sync.cs" />
|
||||
<Compile Include="Traits\Attack\AttackOmni.cs" />
|
||||
<Compile Include="Traits\CustomSellValue.cs" />
|
||||
<Compile Include="Traits\World\BridgeLoadHook.cs" />
|
||||
<Compile Include="Traits\World\ChoosePaletteOnSelect.cs" />
|
||||
<Compile Include="Traits\World\Country.cs" />
|
||||
|
||||
@@ -15,7 +15,8 @@ namespace OpenRa.Traits.Activities
|
||||
|
||||
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 refund = Rules.General.RefundPercent * self.Health * cost / hp;
|
||||
|
||||
|
||||
@@ -96,8 +96,10 @@ namespace OpenRa.Traits
|
||||
|
||||
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 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 cost = (int)Math.Ceiling(costPerHp * hpToRepair);
|
||||
if (!self.Owner.TakeCash(cost))
|
||||
|
||||
17
OpenRa.Game/Traits/CustomSellValue.cs
Normal file
17
OpenRa.Game/Traits/CustomSellValue.cs
Normal 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 {}
|
||||
}
|
||||
@@ -58,6 +58,9 @@ PROC:
|
||||
StoresOre:
|
||||
Pips: 17
|
||||
Capacity: 1000
|
||||
CustomSellValue:
|
||||
Value: 600
|
||||
|
||||
SILO:
|
||||
Inherits: ^Building
|
||||
Buildable:
|
||||
|
||||
@@ -1355,6 +1355,8 @@ FACT:
|
||||
Produces: Building,Defense
|
||||
ConstructionYard:
|
||||
IronCurtainable:
|
||||
CustomSellValue:
|
||||
Value: 1000
|
||||
|
||||
PROC:
|
||||
Inherits: ^Building
|
||||
@@ -1380,6 +1382,8 @@ PROC:
|
||||
Pips: 17
|
||||
Capacity: 2000
|
||||
IronCurtainable:
|
||||
CustomSellValue:
|
||||
Value: 600
|
||||
|
||||
SILO:
|
||||
Inherits: ^Building
|
||||
|
||||
Reference in New Issue
Block a user