Cast to long to avoid overflow when multiplying by the health

This commit is contained in:
Arular101
2018-01-04 00:23:40 +01:00
committed by reaperrr
parent 32b0170785
commit 30acee38c9
9 changed files with 38 additions and 19 deletions

View File

@@ -34,9 +34,12 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
var cost = self.GetSellValue();
var sellValue = self.GetSellValue();
var refund = (cost * sellableInfo.RefundPercent * (health == null ? 1 : health.HP)) / (100 * (health == null ? 1 : health.MaxHP));
// Cast to long to avoid overflow when multiplying by the health
var hp = health != null ? (long)health.HP : 1L;
var maxHP = health != null ? (long)health.MaxHP : 1L;
var refund = (int)((sellValue * sellableInfo.RefundPercent * hp) / (100 * maxHP));
playerResources.GiveCash(refund);
foreach (var ns in self.TraitsImplementing<INotifySold>())