static void Postfix(ref float armorRating, Pawn pawn) { if (IsMountableUtility.IsCurrentlyMounted(pawn) && pawn.def.GetModExtension <CustomStatsPatch>() is CustomStatsPatch modExt) { armorRating *= modExt.armorModifier; } }
static void Postfix(ref float damAmount, Pawn pawn, ref bool metalArmor) { if (IsMountableUtility.IsCurrentlyMounted(pawn) && pawn.def.GetModExtension <CustomStatsPatch>() is CustomStatsPatch modExt) { damAmount /= modExt.armorModifier; metalArmor = modExt.useMetalArmor; } }
static bool Prefix(WorkGiver_Train __instance, Pawn pawn, Thing t, ref Job __result) { if (t is Pawn animal && animal.RaceProps.Animal && IsMountableUtility.IsCurrentlyMounted(animal)) { __result = null; return(false); } return(true); }
static bool Prefix(ThingDef def, ref bool __result) { if (IsMountableUtility.IsMountable(def)) { __result = true; return(false); } return(true); }
static bool Prefix(Pawn pawn, ref bool __result) { if (IsMountableUtility.isMountable(pawn)) { __result = true; return(false); } return(true); }
static void Postfix(Pawn animal, ref bool __result) { if (!__result) { __result = IsMountableUtility.IsCurrentlyMounted(animal); } //if(store != null && store.GetExtendedDataFor(pawn) is ExtendedPawnData pawnData) //{ // __result = pawnData.wasRidingToJob; //} }
public static bool NeedsToBeManagedByRopeModified(Pawn animal) { if (IsMountableUtility.IsCurrentlyMounted(animal)) { return(true); } else { return(AnimalPenUtility.NeedsToBeManagedByRope(animal)); } }
public override void PostDraw() { if (!(parent is Pawn)) { return; } Pawn pawn = parent as Pawn; if (!IsMountableUtility.IsCurrentlyMounted(pawn)) { return; } base.PostDraw(); CompProperties_Overlay.GraphicOverlay overlay = Props.GetOverlay(parent.Rotation); if (overlay == null) { return; } Vector3 drawPos = parent.DrawPos; GraphicData gd; gd = (pawn.gender == Gender.Female) ? overlay.graphicDataFemale : overlay.graphicDataMale; if (gd == null) { gd = overlay.graphicDataDefault; } if (gd == null) { return; } //g.data. drawPos.y += 0.046875f; Vector3 offset = (pawn.gender == Gender.Female) ? overlay.offsetFemale : overlay.offsetMale; if (offset == Vector3.zero) { offset = overlay.offsetDefault; } if (pawn.Rotation == Rot4.West) { offset.x = -offset.x; } drawPos += offset; //Somehow the rotation is flipped, hence the use of GetOpposite. gd.Graphic.Draw(drawPos, parent.Rotation, parent, 0f); }
static void Postfix(Thing a, Thing b, ref bool __result) { if (__result == true && a.def.category == ThingCategory.Pawn && b.def.category == ThingCategory.Pawn) { Pawn pawnA = (Pawn)a; Pawn pawnB = (Pawn)b; if (IsMountableUtility.isMountable(pawnA) || IsMountableUtility.isMountable(pawnB)) { __result = false; } } }
private static void handleAnimal(float num, Rect buttonRect, Pawn animal, List <Pawn> pawns, TransferableOneWay trad) { ExtendedPawnData animalData = GiddyUpCore.Base.Instance.GetExtendedDataStorage().GetExtendedDataFor(animal); Text.Anchor = TextAnchor.MiddleLeft; List <FloatMenuOption> list = new List <FloatMenuOption>(); string buttonText = "GU_Car_Set_Rider".Translate(); bool canMount = true; if (!animalData.selectedForCaravan) { buttonText = "GU_Car_AnimalNotSelected".Translate(); canMount = false; } bool isMountable = IsMountableUtility.isMountable(animal, out IsMountableUtility.Reason reason); if (!isMountable) { if (reason == IsMountableUtility.Reason.NotFullyGrown) { buttonText = "GU_Car_NotFullyGrown".Translate(); canMount = false; } if (reason == IsMountableUtility.Reason.NeedsObedience) { buttonText = "GU_Car_NeedsObedience".Translate(); canMount = false; } if (reason == IsMountableUtility.Reason.NotInModOptions) { buttonText = "GU_Car_NotInModOptions".Translate(); canMount = false; } } if (animalData.caravanRider != null) { ExtendedPawnData riderData = GiddyUpCore.Base.Instance.GetExtendedDataStorage().GetExtendedDataFor(animalData.caravanRider); if (riderData.selectedForCaravan) { buttonText = animalData.caravanRider.Name.ToStringShort; } } if (!canMount) { Widgets.ButtonText(buttonRect, buttonText, false, false, false); } else if (Widgets.ButtonText(buttonRect, buttonText, true, false, true)) { foreach (Pawn pawn in pawns) { if (pawn.IsColonist) { ExtendedPawnData pawnData = GiddyUpCore.Base.Instance.GetExtendedDataStorage().GetExtendedDataFor(pawn); if (!pawnData.selectedForCaravan) { list.Add(new FloatMenuOption(pawn.Name.ToStringShort + " (" + "GU_Car_PawnNotSelected".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null)); continue; } if (pawnData.caravanMount != null) { continue; } list.Add(new FloatMenuOption(pawn.Name.ToStringShort, delegate { { SelectMountRider(animalData, pawnData, animal, pawn); Traverse.Create(trad).Property("CountToTransfer").SetValue(-1); //Setting this to -1 will make sure total weight is calculated again. it's set back to 1 shortly after Log.Message("setting CountToTransfer to -1"); //if (animalData.caravanRider != null) //{ // ExtendedPawnData riderData = GiddyUpCore.Base.Instance.GetExtendedDataStorage().GetExtendedDataFor(animalData.caravanRider); // riderData.caravanMount = null; //} //pawnData.caravanMount = animal; //animalData.caravanRider = pawn; //Traverse.Create(trad).Property("CountToTransfer").SetValue(-1); //Setting this to -1 will make sure total weight is calculated again. it's set back to 1 shortly after //Log.Message("setting CountToTransfer to -1"); //animalData.selectedForCaravan = true; } }, MenuOptionPriority.High, null, null, 0f, null, null)); } } list.Add(new FloatMenuOption("GU_Car_No_Rider".Translate(), delegate { { ClearMountRider(animalData); Traverse.Create(trad).Property("CountToTransfer").SetValue(-1); //Setting this to -1 will make sure total weight is calculated again. it's set back to 1 shortly after Log.Message("setting CountToTransfer to -1"); //if (animalData.caravanRider != null) //{ // ExtendedPawnData riderData = GiddyUpCore.Base.Instance.GetExtendedDataStorage().GetExtendedDataFor(animalData.caravanRider); // riderData.caravanMount = null; //} //animalData.caravanRider = null; //Traverse.Create(trad).Property("CountToTransfer").SetValue(-1); //Setting this to -1 will make sure total weight is calculated again. it's set back to 1 shortly after //Log.Message("setting CountToTransfer to -1"); //animalData.selectedForCaravan = true; } }, MenuOptionPriority.Low, null, null, 0f, null, null)); Find.WindowStack.Add(new FloatMenu(list)); } }
public override bool HasCheckbox(Pawn pawn) { return(IsMountableUtility.isMountable(pawn)); }
//Gets animal that'll get the pawn to the target the quickest. Returns null if no animal is found or if walking is faster. static Pawn GetBestChoiceAnimal(Pawn pawn, LocalTargetInfo target, LocalTargetInfo secondTarget, float pawnTargetDistance, float firstToSecondTargetDistance, ExtendedDataStorage store) { //float minDistance = float.MaxValue; Pawn closestAnimal = null; float timeNeededMin = (pawnTargetDistance + firstToSecondTargetDistance) * pawn.TicksPerMoveDiagonal; ExtendedPawnData pawnData = store.GetExtendedDataFor(pawn); bool firstTargetNoMount = false; bool secondTargetNoMount = false; Area_GU areaNoMount = (Area_GU)pawn.Map.areaManager.GetLabeled(Base.NOMOUNT_LABEL); Area_GU areaDropAnimal = (Area_GU)pawn.Map.areaManager.GetLabeled(Base.DROPANIMAL_LABEL); if (areaNoMount != null && areaNoMount.ActiveCells.Contains(target.Cell)) { firstTargetNoMount = true; if (pawnTargetDistance < Base.minAutoMountDistance) { return(null); } } //If owning an animal, prefer this animal if it still gets you to the goal quicker than walking. //This'll make sure pawns prefer the animals they were already riding previously. if (pawnData.owning != null && pawnData.owning.Spawned && !AnimalNotAvailable(pawnData.owning) && pawn.CanReserve(pawnData.owning)) { if (CalculateTimeNeeded(pawn, ref target, secondTarget, firstToSecondTargetDistance, pawnData.owning, firstTargetNoMount, secondTargetNoMount, areaDropAnimal) < timeNeededMin) { return(pawnData.owning); } } //Otherwise search the animal on the map that gets you to the goal the quickest foreach (Pawn animal in from p in pawn.Map.mapPawns.AllPawnsSpawned where p.RaceProps.Animal && IsMountableUtility.isMountable(p) && p.CurJob != null && p.CurJob.def != GUC_JobDefOf.Mounted select p) { if (AnimalNotAvailable(animal) || !pawn.CanReserve(animal)) { continue; } float distanceFromAnimal = DistanceUtility.QuickDistance(animal.Position, target.Cell); if (!firstTargetNoMount) { distanceFromAnimal += firstToSecondTargetDistance; } if (distanceFromAnimal < Base.minAutoMountDistanceFromAnimal) { continue; } ExtendedPawnData animalData = store.GetExtendedDataFor(animal); if (animalData.ownedBy != null) { continue; } if (!animalData.mountableByMaster && !animalData.mountableByAnyone) { continue; } else if (!animalData.mountableByAnyone && animalData.mountableByMaster) { if (animal.playerSettings != null && animal.playerSettings.master != pawn) { continue; } } float timeNeeded = CalculateTimeNeeded(pawn, ref target, secondTarget, firstToSecondTargetDistance, animal, firstTargetNoMount, secondTargetNoMount, areaDropAnimal); if (timeNeeded < timeNeededMin) { closestAnimal = animal; timeNeededMin = timeNeeded; } } return(closestAnimal); }
public override bool HasCheckbox(Pawn pawn) { return(IsMountableUtility.isMountable(pawn) && pawn.playerSettings != null && pawn.playerSettings.Master != null); }
public override void PostDraw() { if (!(parent is Pawn)) { return; } Pawn pawn = parent as Pawn; if (!IsMountableUtility.IsCurrentlyMounted(pawn)) { return; } base.PostDraw(); CompProperties_Overlay.GraphicOverlay overlay = Props.GetOverlay(parent.Rotation); if (overlay == null) { return; } Vector3 drawPos = parent.DrawPos; GraphicData gd; gd = (pawn.gender == Gender.Female) ? overlay.graphicDataFemale : overlay.graphicDataMale; if (gd == null) { gd = overlay.graphicDataDefault; } if (gd == null) { return; } //support multi texture animals if (overlay.allVariants != null) { string graphicPath = pawn.Drawer.renderer.graphics.nakedGraphic.path; string graphicName = graphicPath.Split('/').Last(); bool foundTex = false; foreach (var variant in overlay.allVariants) { string variantName = variant.texPath.Split('/').Last().Split(overlay.stringDelimiter.ToCharArray()).First(); if (graphicName == variantName) { //set required properties string texPath = variant.texPath; variant.CopyFrom(gd); variant.texPath = texPath; gd = variant; foundTex = true; } } if (!foundTex) { //Don't throw errors when there's no valid texture. return; } } //g.data. drawPos.y += 0.046875f; Vector3 offset = (pawn.gender == Gender.Female) ? overlay.offsetFemale : overlay.offsetMale; if (offset == Vector3.zero) { offset = overlay.offsetDefault; } if (pawn.Rotation == Rot4.West) { offset.x = -offset.x; } drawPos += offset; //Somehow the rotation is flipped, hence the use of GetOpposite. gd.Graphic.Draw(drawPos, parent.Rotation, parent, 0f); }