private static void VerbGiverExtended(ref IEnumerable <Gizmo> __result, Pawn_DraftController __instance) { List <Gizmo> gizmos = new List <Gizmo>(__result); // normal gizmos List <Gizmo> toggleGizmos = new List <Gizmo>(); List <Gizmo> rangedVerbGizmos = new List <Gizmo>(); // iterates over verbgivercomps foreach (HediffComp_VerbGiverExtended verbGiverExtended in __instance.pawn.health.hediffSet.GetAllComps().Where(c => c is HediffComp_VerbGiverExtended)) { // create a gizmo Command_Toggle command_HediffToggle = new Command_Toggle { isActive = () => verbGiverExtended.canAutoAttack, toggleAction = () => verbGiverExtended.canAutoAttack = !verbGiverExtended.canAutoAttack, defaultLabel = verbGiverExtended.Props.toggleLabel, defaultDesc = verbGiverExtended.Props.toggleDescription.CapitalizeFirst(), icon = PCF_VanillaExtender.GetIcon(verbGiverExtended.Pawn.GetUniqueLoadID() + "_" + verbGiverExtended.parent.GetUniqueLoadID(), verbGiverExtended.Props.toggleIconPath), iconAngle = verbGiverExtended.Props.toggleIconAngle, iconOffset = verbGiverExtended.Props.toggleIconOffset }; if (__instance.pawn.Faction != Faction.OfPlayer) // disable show on enemies { command_HediffToggle.Disable("CannotOrderNonControlled".Translate()); } if (__instance.pawn.Downed) // disable on downed { command_HediffToggle.Disable("IsIncapped".Translate(__instance.pawn.LabelShort, __instance.pawn)); } toggleGizmos.Add(command_HediffToggle); // add to list of toggles // command to use verb Command_HediffVerbRanged command_HediffVerbRanged = new Command_HediffVerbRanged { rangedComp = verbGiverExtended, defaultLabel = verbGiverExtended.rangedVerbLabel, defaultDesc = verbGiverExtended.rangedVerbDescription.CapitalizeFirst(), icon = PCF_VanillaExtender.GetIcon(verbGiverExtended.Pawn.GetUniqueLoadID() + "_" + verbGiverExtended.rangedVerb.loadID, verbGiverExtended.rangedVerbIconPath), iconAngle = verbGiverExtended.rangedVerbIconAngle, iconOffset = verbGiverExtended.rangedVerbIconOffset }; if (__instance.pawn.Faction != Faction.OfPlayer) { command_HediffVerbRanged.Disable("CannotOrderNonControlled".Translate()); } else if (__instance.pawn.IsColonist) { if (__instance.pawn.story.DisabledWorkTagsBackstoryAndTraits.HasFlag(WorkTags.Violent)) { command_HediffVerbRanged.Disable("IsIncapableOfViolence".Translate(__instance.pawn.LabelShort, __instance.pawn)); } else if (!__instance.pawn.drafter.Drafted) { command_HediffVerbRanged.Disable("IsNotDrafted".Translate(__instance.pawn.LabelShort, __instance.pawn)); } } rangedVerbGizmos.Add(command_HediffVerbRanged); } __result = gizmos.Concat(toggleGizmos).Concat(rangedVerbGizmos); }
private static void VerbGiverExtended(JobDriver __instance) { /* * // Patch inspirated from RunAndGun mod by roolo * // License for patch when i make this mod "10 July 2019" * // That patch is free to use except don't make exact copies or only with minor adjustment of Run And Gun. The author also give permission. * // --- github.com/rheirman/RunAndGun/blob/master/README.md --- */ if (__instance is JobDriver_Goto jobDriver_Goto) { List <Toil> value = Traverse.Create(jobDriver_Goto).Field("toils").GetValue <List <Toil> >(); if (value.Count() > 0) { Toil toil = value.ElementAt(0); toil.AddPreTickAction(delegate { if (jobDriver_Goto.pawn.Downed) { return; } if (jobDriver_Goto.pawn.Faction != null && (jobDriver_Goto.pawn.drafter == null || jobDriver_Goto.pawn.drafter.FireAtWill) && jobDriver_Goto.pawn.IsHashIntervalTick(10)) { PCF_VanillaExtender.CheckForAutoAttack(jobDriver_Goto); } }); } } }
private static void VerbGiverExtended(JobDriver_Wait __instance) { if (__instance.pawn.Downed) { return; } if (__instance.pawn.Faction != null && __instance.job.def == JobDefOf.Wait_Combat && (__instance.pawn.drafter == null || __instance.pawn.drafter.FireAtWill)) { PCF_VanillaExtender.CheckForAutoAttack(__instance); } }
private static void VerbGiverExtended(ref IEnumerable <Gizmo> __result, Pawn_DraftController __instance) { List <Gizmo> gizmos = new List <Gizmo>(__result); List <Gizmo> toggleGizmos = new List <Gizmo>(); List <Gizmo> rangedVerbGizmos = new List <Gizmo>(); List <Hediff> hediffs = __instance.pawn.health.hediffSet.hediffs; for (int i = 0; i < hediffs.Count; i++) { HediffComp_VerbGiverExtended verbGiverExtended = hediffs[i].TryGetComp <HediffComp_VerbGiverExtended>(); if (verbGiverExtended != null) { Command_HediffToggle command_HediffToggle = new Command_HediffToggle { isActive = (() => verbGiverExtended.canAutoAttack), toggleAction = delegate() { verbGiverExtended.canAutoAttack = !verbGiverExtended.canAutoAttack; }, defaultLabel = verbGiverExtended.Props.toggleLabel, defaultDesc = verbGiverExtended.Props.toggleDescription.CapitalizeFirst(), icon = PCF_VanillaExtender.GetIcon(verbGiverExtended.Pawn.GetUniqueLoadID() + "_" + verbGiverExtended.parent.GetUniqueLoadID(), verbGiverExtended.Props.toggleIconPath), iconAngle = verbGiverExtended.Props.toggleIconAngle, iconOffset = verbGiverExtended.Props.toggleIconOffset }; if (__instance.pawn.Faction != Faction.OfPlayer) { command_HediffToggle.Disable("CannotOrderNonControlled".Translate()); } if (__instance.pawn.Downed) { command_HediffToggle.Disable("IsIncapped".Translate(__instance.pawn.LabelShort, __instance.pawn)); } toggleGizmos.Add(command_HediffToggle); Command_HediffVerbRanged command_HediffVerbRanged = new Command_HediffVerbRanged { rangedComp = verbGiverExtended, defaultLabel = verbGiverExtended.rangedVerbLabel, defaultDesc = verbGiverExtended.rangedVerbDescription.CapitalizeFirst(), icon = PCF_VanillaExtender.GetIcon(verbGiverExtended.Pawn.GetUniqueLoadID() + "_" + verbGiverExtended.rangedVerb.loadID, verbGiverExtended.rangedVerbIconPath), iconAngle = verbGiverExtended.rangedVerbIconAngle, iconOffset = verbGiverExtended.rangedVerbIconOffset }; if (__instance.pawn.Faction != Faction.OfPlayer) { command_HediffVerbRanged.Disable("CannotOrderNonControlled".Translate()); } else if (__instance.pawn.IsColonist) { if (__instance.pawn.story.WorkTagIsDisabled(WorkTags.Violent)) { command_HediffVerbRanged.Disable("IsIncapableOfViolence".Translate(__instance.pawn.LabelShort, __instance.pawn)); } else if (!__instance.pawn.drafter.Drafted) { command_HediffVerbRanged.Disable("IsNotDrafted".Translate(__instance.pawn.LabelShort, __instance.pawn)); } } rangedVerbGizmos.Add(command_HediffVerbRanged); } } __result = gizmos.Concat(toggleGizmos).Concat(rangedVerbGizmos); }