Skip to content

Commit

Permalink
Merge pull request #3401 from CombatExtended-Continued/CompPawnGizmoD…
Browse files Browse the repository at this point in the history
…upeProof

CompPawnGizmo Duplicate Proof
  • Loading branch information
N7Huntsman authored Sep 9, 2024
2 parents 4738d82 + 25cfa06 commit ba7d7e6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
<match Class="PatchOperationAdd">
<xpath>Defs/AlienRace.ThingDef_AlienRace[defName="Alien_Miho"]/comps</xpath>
<value>
<li>
<compClass>CombatExtended.CompPawnGizmo</compClass>
</li>
<li Class="CombatExtended.CompProperties_Suppressable"/>
<li Class="CombatExtended.CompProperties_ArmorDurability">
<Durability>500</Durability>
Expand All @@ -22,9 +19,6 @@
<xpath>Defs/AlienRace.ThingDef_AlienRace[defName="Alien_Miho"]</xpath>
<value>
<comps>
<li>
<compClass>CombatExtended.CompPawnGizmo</compClass>
</li>
<li Class="CombatExtended.CompProperties_Suppressable"/>
<li Class="CombatExtended.CompProperties_ArmorDurability">
<Durability>500</Durability>
Expand Down
57 changes: 37 additions & 20 deletions Source/CombatExtended/CombatExtended/Comps_CCL/CompPawnGizmo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,52 @@ namespace CombatExtended
{
public class CompPawnGizmo : ThingComp
{
public override IEnumerable<Gizmo> CompGetGizmosExtra()
bool duplicate = false;

public override void Initialize(CompProperties props)
{
var pawn = parent as Pawn;
var equip = pawn != null
? pawn.equipment.Primary
: null;
base.Initialize(props);
foreach (var comp in parent.comps)
{
if (comp is CompPawnGizmo && comp != this)
{
duplicate = true;
Log.ErrorOnce($"{parent.def.defName} has multiple CompPawnGizmo, duplicates has been deactivated. Please report this to the patch provider of {parent.def.modContentPack.Name} or CE team if the patch is integrated in CE.", parent.def.GetHashCode());
}
}
}

if (
(equip != null) &&
(!equip.AllComps.NullOrEmpty())
)

public override IEnumerable<Gizmo> CompGetGizmosExtra()
{
if (!duplicate)
{
foreach (var comp in equip.AllComps)
var pawn = parent as Pawn;
var equip = pawn != null
? pawn.equipment.Primary
: null;

if (
(equip != null) &&
(!equip.AllComps.NullOrEmpty())
)
{
var gizmoGiver = comp as CompRangedGizmoGiver;
if (
(gizmoGiver != null) &&
(gizmoGiver.isRangedGiver)
)
foreach (var comp in equip.AllComps)
{
foreach (var gizmo in gizmoGiver.CompGetGizmosExtra())
var gizmoGiver = comp as CompRangedGizmoGiver;
if (
(gizmoGiver != null) &&
(gizmoGiver.isRangedGiver)
)
{
yield return gizmo;
foreach (var gizmo in gizmoGiver.CompGetGizmosExtra())
{
yield return gizmo;
}
}
}
}
}
};
}

}

}

0 comments on commit ba7d7e6

Please sign in to comment.