private static void UpdateRangedVerbsPostfix(object __instance) { Pawn pawn; if (__instance.GetType() == typeof(HediffSet)) { HediffSet hediffSet = (HediffSet)__instance; pawn = hediffSet.pawn; } else { Pawn_EquipmentTracker equipmentTracker = (Pawn_EquipmentTracker)__instance; pawn = equipmentTracker.pawn; } if (pawn != null && pawn.Spawned && !pawn.Suspended) { VEF_Comp_Pawn_RangedVerbs comp = pawn.TryGetComp <VEF_Comp_Pawn_RangedVerbs>(); if (comp != null) { comp.UpdateRangedVerbs(); comp.TryGetRangedVerb(pawn.mindState.enemyTarget); } } }
private static void PawnAttackGizmoUtility_GetSquadAttackGizmoPostfix(Pawn pawn, ref Gizmo __result) { Command_Target command_Target = (Command_Target)__result; bool flag = false; List <object> selectedObjectsListForReading = Find.Selector.SelectedObjectsListForReading; if (selectedObjectsListForReading.Count > 1) { for (int i = 0; i < selectedObjectsListForReading.Count; i++) { Pawn pawn2 = selectedObjectsListForReading[i] as Pawn; if (pawn2 != null && pawn2.IsColonistPlayerControlled && pawn2.GetComp <VEF_Comp_Pawn_RangedVerbs>().CurRangedVerb != null && pawn2.GetComp <VEF_Comp_Pawn_RangedVerbs>().CurRangedVerb.IsStillUsableBy(pawn2) && (pawn2.GetComp <VEF_Comp_Pawn_RangedVerbs>().CurRangedVerb.EquipmentSource == null || pawn2.GetComp <VEF_Comp_Pawn_RangedVerbs>().CurRangedVerb.EquipmentSource != pawn2.equipment.Primary)) { flag = true; } } } if (flag || (VEF_Comp_Pawn_RangedVerbs.ShouldUseSquadAttackGizmo())) { command_Target.defaultLabel = "CommandSquadEquipmentAttack".Translate(); command_Target.defaultDesc = "CommandSquadEquipmentAttackDesc".Translate(); if (FloatMenuUtility.GetAttackAction(pawn, LocalTargetInfo.Invalid, out string str) == null) { command_Target.Disable(str.CapitalizeFirst() + "."); } command_Target.action = delegate(Thing target) { IEnumerable <Pawn> pawns = Find.Selector.SelectedObjects.Where(delegate(object x) { Pawn pawn3 = x as Pawn; return(pawn3 != null && pawn3.IsColonistPlayerControlled && pawn3.Drafted); }).Cast <Pawn>(); foreach (Pawn pawn2 in pawns) { if (pawn2.equipment != null && pawn2.equipment.Primary != null && !pawn2.equipment.PrimaryEq.PrimaryVerb.IsMeleeAttack && (pawn2.GetComp <VEF_Comp_Pawn_RangedVerbs>().CurRangedVerb.EquipmentSource == null || pawn2.GetComp <VEF_Comp_Pawn_RangedVerbs>().CurRangedVerb.EquipmentSource.def != pawn2.equipment.Primary.def)) { pawn2.GetComp <VEF_Comp_Pawn_RangedVerbs>().SetCurRangedVerb(pawn2.equipment.PrimaryEq.PrimaryVerb, null); } string text; FloatMenuUtility.GetAttackAction(pawn2, target, out text)?.Invoke(); } }; __result = command_Target; } return; }
public override GizmoResult GizmoOnGUI(Vector2 topLeft, float maxWidth) { GizmoResult result = base.GizmoOnGUI(topLeft, maxWidth); if (VEF_ModCompatibilityCheck.enabled_rooloDualWield && verb.EquipmentSource != null && verb.EquipmentSource.def == pawn.equipment.Primary.def && !VEF_Comp_Pawn_RangedVerbs.ShouldUseSquadAttackGizmo()) { try { ((Action)(() => { object[] parameters = new object[] { pawn.equipment, null }; bool hasOffHandEquipment = (bool)VEF_ReflectionData.MB_TryGetOffHandEquipment.Invoke(null, parameters); ThingWithComps offHandThing = (ThingWithComps)parameters[1]; if (offHandThing != null && offHandThing.GetComp <CompEquippable>() != null && !offHandThing.GetComp <CompEquippable>().AllVerbs.NullOrEmpty()) { GUI.color = offHandThing.DrawColor; Material mat = (!this.disabled) ? null : TexUI.GrayscaleGUI; Texture2D texture2D = offHandThing.def.uiIcon; if (texture2D == null) { texture2D = BaseContent.BadTex; } Rect outerRect = new Rect(topLeft.x, topLeft.y + 10f, this.GetWidth(maxWidth), 75f); Widgets.DrawTextureFitted(outerRect, texture2D, this.iconDrawScale * 0.85f, this.iconProportions, this.iconTexCoords, this.iconAngle, mat); GUI.color = Color.white; } }))(); } catch (TypeLoadException ex) { } } return(result); }
private Command_VerbTarget CreateVerbTargetCommand(Verb verb) { VEF_Gizmo_SwitchRangedVerb command_VerbTarget = new VEF_Gizmo_SwitchRangedVerb(Pawn) { tutorTag = "VerbTarget", hotKey = KeyBindingDefOf.Misc5, icon = BaseContent.BadTex, order = +1f, verb = verb }; if (verb != null && verb.IsStillUsableBy(Pawn)) { if (verb.caster.Faction != Faction.OfPlayer) { command_VerbTarget.Disable("CannotOrderNonControlled".Translate()); } else if (verb.CasterIsPawn) { // Disables Conditions if (verb.CasterPawn.story.WorkTagIsDisabled(WorkTags.Violent)) { command_VerbTarget.Disable("IsIncapableOfViolence".Translate(verb.CasterPawn.LabelShort, verb.CasterPawn)); } else if (!verb.CasterPawn.drafter.Drafted) { command_VerbTarget.Disable("IsNotDrafted".Translate(verb.CasterPawn.LabelShort, verb.CasterPawn)); } // Visible Conditions if (verb == null || (rangedVerbs.Count == 1 && verb.EquipmentSource != null && verb.EquipmentSource == verb.CasterPawn.equipment.Primary) || (verb.CasterPawn.story.WorkTagIsDisabled(WorkTags.Violent) && !verb.CasterPawn.Drafted) || VEF_Comp_Pawn_RangedVerbs.ShouldUseSquadAttackGizmo()) { this.visible = false; } else { this.visible = true; } //Description, Icon and Label Conditions Texture2D tempIcon = BaseContent.BadTex; if (CurRangedVerb.EquipmentSource != null) { command_VerbTarget.defaultDesc = (verb.verbProps.label == verb.EquipmentSource.def.label) ? verb.EquipmentSource.LabelCap + ": " + verb.EquipmentSource.def.description.CapitalizeFirst() : verb.verbProps.label + " :: " + verb.EquipmentSource.LabelCap + ": " + verb.EquipmentSource.def.description.CapitalizeFirst(); tempIcon = CurRangedVerb.EquipmentSource.def.uiIcon; if (tempIcon != BaseContent.BadTex || tempIcon != null) { command_VerbTarget.icon = tempIcon; } } else if (verb.verbProps.LaunchesProjectile) { if (verb.HediffCompSource != null) { command_VerbTarget.defaultDesc = (verb.verbProps.label == verb.HediffSource.def.label) ? verb.HediffSource.def.LabelCap + ": " + verb.HediffSource.def.description.CapitalizeFirst() : verb.verbProps.label + " :: " + verb.HediffSource.LabelCap + ": " + verb.HediffSource.def.description.CapitalizeFirst(); } else { command_VerbTarget.defaultDesc = (verb.verbProps.label == verb.CasterPawn.def.label) ? "Biological weapon of " + verb.CasterPawn.def.label + ": " + verb.CasterPawn.def.description.CapitalizeFirst() : CurRangedVerb.verbProps.label.CapitalizeFirst() + " :: Biological weapon of " + verb.CasterPawn.def.label + ": " + verb.CasterPawn.def.description.CapitalizeFirst(); } tempIcon = verb.GetProjectile().uiIcon; if (tempIcon != null) { command_VerbTarget.icon = tempIcon; } } else { if (verb.HediffSource != null) { command_VerbTarget.defaultDesc = (verb.verbProps.label == verb.HediffSource.def.label) ? verb.HediffSource.def.LabelCap + ": " + verb.HediffSource.def.description.CapitalizeFirst() : verb.verbProps.label + " :: " + verb.HediffSource.LabelCap + ": " + verb.HediffSource.def.description.CapitalizeFirst(); if (verb.HediffSource.def.spawnThingOnRemoved.uiIcon != null) { tempIcon = verb.HediffSource.def.spawnThingOnRemoved.uiIcon; } } else { command_VerbTarget.defaultDesc = (verb.verbProps.label == verb.CasterPawn.def.label) ? "Biological weapon of " + verb.CasterPawn.def.label + ": " + verb.CasterPawn.def.description.CapitalizeFirst() : CurRangedVerb.verbProps.label.CapitalizeFirst() + " :: Biological weapon of " + verb.CasterPawn.def.label + ": " + verb.CasterPawn.def.description.CapitalizeFirst(); if (verb.CasterIsPawn && verb.CasterPawn.def.uiIcon != null) { tempIcon = verb.CasterPawn.def.uiIcon; } } if (tempIcon != null) { command_VerbTarget.icon = tempIcon; } } } } else { this.visible = false; command_VerbTarget.Disable(); } return(command_VerbTarget); }