Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ammoConsumedPerShot to ammosetdefs #2941

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Source/CombatExtended/CombatExtended/Defs/AmmoSetDef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class AmmoSetDef : Def

public AmmoSetDef similarTo;

public int ammoConsumedPerShot = 1;

public override IEnumerable<StatDrawEntry> SpecialDisplayStats(StatRequest req)
{
foreach (StatDrawEntry entry in base.SpecialDisplayStats(req)) { yield return entry; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ private Thing Gun(StatRequest req)

public override bool ShouldShowFor(StatRequest req)
{
return base.ShouldShowFor(req) && (GunDef(req)?.Verbs?
.Any(x => ((x as VerbPropertiesCE)?.ammoConsumedPerShotCount ?? 1) > 1) ?? false);
return base.ShouldShowFor(req) &&
(((GunDef(req)?.GetCompProperties<CompProperties_AmmoUser>() as CompProperties_AmmoUser)?.ammoSet.ammoConsumedPerShot != 1) ||
(GunDef(req)?.Verbs?.Any(x => ((x as VerbPropertiesCE)?.ammoConsumedPerShotCount ?? 1) > 1) ?? false));
}

public override float GetValueUnfinalized(StatRequest req, bool applyPostProcess = true)
{
return ((VerbPropertiesCE)GunDef(req)?.Verbs?.FirstOrDefault(x => ((VerbPropertiesCE)x).ammoConsumedPerShotCount > 1))?.ammoConsumedPerShotCount ?? 1;
return ((GunDef(req)?.GetCompProperties<CompProperties_AmmoUser>() as CompProperties_AmmoUser)?.ammoSet?.ammoConsumedPerShot ?? 1 *
((VerbPropertiesCE)GunDef(req)?.Verbs?.FirstOrDefault(x => ((VerbPropertiesCE)x).ammoConsumedPerShotCount > 1))?.ammoConsumedPerShotCount ?? 1);
}

public override string GetExplanationUnfinalized(StatRequest req, ToStringNumberSense numberSense)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public override bool TryCastShot()
//Reduce ammunition
if (CompAmmo != null)
{
if (!CompAmmo.TryReduceAmmoCount(VerbPropsCE.ammoConsumedPerShotCount))
if (!CompAmmo.TryReduceAmmoCount(CompAmmo.Props.ammoSet.ammoConsumedPerShot * VerbPropsCE.ammoConsumedPerShotCount))
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public override bool TryCastShot()
}
if (CompAmmo != null)
{
if (!CompAmmo.TryReduceAmmoCount(VerbPropsCE.ammoConsumedPerShotCount))
if (!CompAmmo.TryReduceAmmoCount(CompAmmo.Props.ammoSet.ammoConsumedPerShot * VerbPropsCE.ammoConsumedPerShotCount))
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static IEnumerable<ThingDef> _GetUsedAmmo()
cetddme._ammoSet = asd;
var ammunition = vtd.ammunition = new ThingFilter();
vtd.genericAmmo = false;
vtd.chargePerAmmoCount = 1f;
vtd.chargePerAmmoCount = 1f / asd.ammoConsumedPerShot;
HashSet<ThingDef> allowedAmmo = (HashSet<ThingDef>)ammunition.AllowedThingDefs;

foreach (var al in asd.ammoTypes)
Expand Down
Loading