Skip to content

Commit

Permalink
Merge pull request #3063 from masakitenchi/reloadOneAtATimeTurretSupport
Browse files Browse the repository at this point in the history
Add support for turret with reloadOneAtATime AmmoUser comp
  • Loading branch information
N7Huntsman authored Apr 29, 2024
2 parents 2208e92 + 91f20e4 commit fb157b1
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using CombatExtended.CombatExtended.LoggerUtils;
using RimWorld;
using UnityEngine;
Expand Down Expand Up @@ -213,8 +214,32 @@ public override IEnumerable<Toil> MakeNewToils()
compReloader.LoadAmmo(ammo);
turret.SetReloading(false);
};

Func<bool> jumpCondition =
() => compReloader.Props.reloadOneAtATime &&
compReloader.CurMagCount < compReloader.MagSize &&
(!compReloader.UseAmmo || TryFindAmmo(pawn, compReloader, ammo));
Toil jumpToil = Toils_Jump.JumpIf(waitToil, jumpCondition);
//if (compReloader.useAmmo) reloadToil.EndOnDespawnedOrNull(TargetIndex.B);
yield return reloadToil;
yield return jumpToil;
}

bool TryFindAmmo(Pawn byPawn, CompAmmoUser comp, Thing ammoThing)
{
//Find both inventory & carried thing, prefer inventory
Thing thing = byPawn.carryTracker.CarriedThing?.def == ammoThing.def ? byPawn.carryTracker.CarriedThing : null;
if (byPawn.TryGetComp<CompInventory>() is CompInventory inv && inv.ammoList.Find(x => x.def == ammoThing.def) is Thing ans)
{
var Tempthing = ans;
inv.ammoList.Remove(ans);
byPawn.TryGetComp<CompInventory>().UpdateInventory();
byPawn.carryTracker.TryStartCarry(ans);
thing = ans;
}
if (thing == null) { return false; }
ammoThing = thing;
return true;
}
#endregion Methods
}
Expand Down

0 comments on commit fb157b1

Please sign in to comment.