Skip to content

Commit

Permalink
Merge pull request #3155 from CombatExtended-Continued/Underbarrel_Im…
Browse files Browse the repository at this point in the history
…provments

Underbarrel improvments
  • Loading branch information
N7Huntsman authored Jun 9, 2024
2 parents 720888e + 15a2af7 commit 566a404
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Source/CombatExtended/CombatExtended/AmmoInjector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static bool InjectAmmos()
ammoDefs.UnionWith(props.ammoSet.ammoTypes.Select<AmmoLink, ThingDef>(x => x.ammo));
}
CompProperties_UnderBarrel propsGL = weaponDef.GetCompProperties<CompProperties_UnderBarrel>();
if (propsGL != null && propsGL.propsUnderBarrel.ammoSet != null && !propsGL.propsUnderBarrel.ammoSet.ammoTypes.NullOrEmpty())
if (propsGL?.propsUnderBarrel != null && propsGL.propsUnderBarrel.ammoSet != null && !propsGL.propsUnderBarrel.ammoSet.ammoTypes.NullOrEmpty())
{
ammoDefs.UnionWith(propsGL.propsUnderBarrel.ammoSet.ammoTypes.Select<AmmoLink, ThingDef>(x => x.ammo));
}
Expand Down
49 changes: 32 additions & 17 deletions Source/CombatExtended/CombatExtended/Comps/CompAmmosetSwitcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public CompProperties_AmmoUser CompPropsAmmo
}
}

public bool OneAmmoHolder => Props.oneAmmoHolder;

public AmmoDef mainGunLoadedAmmo;

public int mainGunMagCount;
Expand All @@ -118,18 +120,18 @@ public CompProperties_AmmoUser CompPropsAmmo
[Compatibility.Multiplayer.SyncMethod]
public void SwitchToUB()
{
if (!Props.oneAmmoHolder)
if (!OneAmmoHolder)
{
mainGunLoadedAmmo = CompAmmo.CurrentAmmo;
mainGunMagCount = CompAmmo.CurMagCount;
CompAmmo.CurMagCount = UnderBarrelMagCount;
CompAmmo.CurrentAmmo = UnderBarrelLoadedAmmo;
CompAmmo.SelectedAmmo = CompAmmo.CurrentAmmo;
}

CompAmmo.props = this.Props.propsUnderBarrel;

CompEq.PrimaryVerb.verbProps = Props.verbPropsUnderBarrel;
CompFireModes.props = this.Props.propsFireModesUnderBarrel;
CompAmmo.CurMagCount = UnderBarrelMagCount;
CompAmmo.CurrentAmmo = UnderBarrelLoadedAmmo;
CompAmmo.SelectedAmmo = CompAmmo.CurrentAmmo;
if (CompAmmo.Wielder != null)
{
CompAmmo.Wielder.TryGetComp<CompInventory>().UpdateInventory();
Expand All @@ -141,23 +143,24 @@ public void SwitchToUB()
}
CompEq.PrimaryVerb.verbProps.burstShotCount = this.Props.propsFireModesUnderBarrel.aimedBurstShotCount;
usingUnderBarrel = true;
CompFireModes.InitAvailableFireModes();
}

[Compatibility.Multiplayer.SyncMethod]
public void SwithToB()
{
if (!Props.oneAmmoHolder)
if (!OneAmmoHolder)
{
UnderBarrelLoadedAmmo = CompAmmo.CurrentAmmo;
UnderBarrelMagCount = CompAmmo.CurMagCount;
CompAmmo.CurMagCount = mainGunMagCount;
CompAmmo.CurrentAmmo = mainGunLoadedAmmo;
CompAmmo.SelectedAmmo = CompAmmo.CurrentAmmo;
}

CompAmmo.props = CompPropsAmmo;

CompEq.PrimaryVerb.verbProps = DefVerbProps.MemberwiseClone();
CompFireModes.props = CompPropsFireModes;
CompAmmo.CurMagCount = mainGunMagCount;
CompAmmo.CurrentAmmo = mainGunLoadedAmmo;
CompAmmo.SelectedAmmo = CompAmmo.CurrentAmmo;
if (CompAmmo.Wielder != null)
{
CompAmmo.Wielder.TryGetComp<CompInventory>().UpdateInventory();
Expand All @@ -169,24 +172,28 @@ public void SwithToB()
}
CompEq.PrimaryVerb.verbProps.burstShotCount = DefVerbProps.burstShotCount;
usingUnderBarrel = false;
CompFireModes.InitAvailableFireModes();
}

public override IEnumerable<Gizmo> CompGetGizmosExtra()
{
if (CompEq.Holder?.Faction == Faction.OfPlayer || DebugSettings.godMode)
{
if (CompAmmo.Props.ammoSet == CompPropsAmmo.ammoSet)
if (!usingUnderBarrel)
{
yield return new Command_Action
{

defaultLabel = "CE_SwitchAmmmoSetToUnderBarrel".Translate(),
icon = ContentFinder<Texture2D>.Get("UI/Buttons/Reload"),
defaultLabel = string.IsNullOrEmpty(Props.underBarrelLabel) ? "CE_SwitchAmmmoSetToUnderBarrel".Translate().ToString() : Props.underBarrelLabel,
icon = ContentFinder<Texture2D>.Get(string.IsNullOrEmpty(Props.underBarrelIconTexPath) ? "UI/Buttons/Reload" : Props.underBarrelIconTexPath),
defaultDesc = "CE_UBGLStats".Translate() +
"\n " + "WarmupTime".Translate() + ": " + Props.verbPropsUnderBarrel.warmupTime
+ "\n " + "Range".Translate() + ": " + Props.verbPropsUnderBarrel.range
+ "\n " + "CE_AmmoSet".Translate() + ": " + Props.propsUnderBarrel.ammoSet.label
+
(Props.oneAmmoHolder || Props.propsUnderBarrel?.ammoSet?.label != null ? "" :
"\n " + "CE_AmmoSet".Translate() + ": " + Props.propsUnderBarrel.ammoSet.label
+ "\n " + "CE_MagazineSize".Translate() + ": " + Props.propsUnderBarrel.magazineSize
)
,
action = delegate
{
Expand All @@ -199,8 +206,8 @@ public override IEnumerable<Gizmo> CompGetGizmosExtra()
yield return new Command_Action
{

defaultLabel = "CE_SwitchAmmmoSetToNormalRifle".Translate(),
icon = ContentFinder<Texture2D>.Get("UI/Buttons/Reload"),
defaultLabel = string.IsNullOrEmpty(Props.standardLabel) ? "CE_SwitchAmmmoSetToNormalRifle".Translate().ToString() : Props.standardLabel,
icon = ContentFinder<Texture2D>.Get(string.IsNullOrEmpty(Props.standardIconTexPath) ? "UI/Buttons/Reload" : Props.standardIconTexPath),
action = delegate
{
SwithToB();
Expand Down Expand Up @@ -243,7 +250,7 @@ public override void PostExposeData()
{
if (usingUnderBarrel)
{
if (!Props.oneAmmoHolder)
if (!OneAmmoHolder)
{
CompAmmo.CurMagCount = UnderBarrelMagCount;
CompAmmo.CurrentAmmo = UnderBarrelLoadedAmmo;
Expand Down Expand Up @@ -279,6 +286,14 @@ public class CompProperties_UnderBarrel : CompProperties

public bool oneAmmoHolder = false;

public string underBarrelLabel;

public string standardLabel;

public string underBarrelIconTexPath;

public string standardIconTexPath;

public CompProperties_UnderBarrel()
{
this.compClass = typeof(CompUnderBarrel);
Expand Down
2 changes: 1 addition & 1 deletion Source/CombatExtended/CombatExtended/Verbs/Verb_ShootCE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public virtual int ShotsPerBurstFor(FireMode mode)
}
}
float burstShotCount = VerbPropsCE.burstShotCount;
if (EquipmentSource != null)
if (EquipmentSource != null && (!EquipmentSource.TryGetComp<CompUnderBarrel>()?.usingUnderBarrel ?? false))
{
float modified = EquipmentSource.GetStatValue(CE_StatDefOf.BurstShotCount);
if (modified > 0)
Expand Down

0 comments on commit 566a404

Please sign in to comment.