This repository has been archived by the owner on Apr 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1039 from CombatExtendedRWMod/Fix-for-#937
Fix #937 (loaded ammo has weight/bulk update properly)
- Loading branch information
Showing
8 changed files
with
70 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Source/CombatExtended/CombatExtended/StatParts/StatPart_LoadedAmmo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Verse; | ||
using RimWorld; | ||
|
||
namespace CombatExtended | ||
{ | ||
public class StatPart_LoadedAmmo : StatPart | ||
{ | ||
public override void TransformValue(StatRequest req, ref float val) | ||
{ | ||
if (TryGetValue(req, out float num)) | ||
val += num; | ||
} | ||
|
||
public override string ExplanationPart(StatRequest req) | ||
{ | ||
return TryGetValue(req, out float num) | ||
? "CE_StatsReport_LoadedAmmo".Translate() + ": " + parentStat.ValueToString(num) | ||
: null; | ||
} | ||
|
||
public bool TryGetValue(StatRequest req, out float num) | ||
{ | ||
num = 0f; | ||
if (req.HasThing) | ||
{ | ||
var ammoUser = req.Thing.TryGetComp<CompAmmoUser>(); | ||
if (ammoUser != null && ammoUser.CurrentAmmo != null) | ||
{ | ||
num = ammoUser.CurrentAmmo.GetStatValueAbstract(parentStat) * ammoUser.CurMagCount; | ||
|
||
if (parentStat == CE_StatDefOf.Bulk) | ||
num *= ammoUser.Props.loadedAmmoBulkFactor; | ||
} | ||
} | ||
return num != 0f; | ||
} | ||
} | ||
} |