private bool CanRefuel(Pawn pawn, Thing t, bool mustBeAutoRefuelable) { CompRefuelable compRefuelable = t.TryGetComp <CompRefuelable>(); if (compRefuelable == null || compRefuelable.IsFull) { return(false); } if (mustBeAutoRefuelable && !compRefuelable.ShouldAutoRefuelNow) { return(false); } if (t.IsForbidden(pawn) || !pawn.CanReserveAndReach(t, PathEndMode.Touch, pawn.NormalMaxDanger(), 1)) { return(false); } if (this.FindBestFuel(pawn, t) == null) { ThingFilter fuelFilter = t.TryGetComp <CompRefuelable>().Props.fuelFilter; JobFailReason.Is("NoFuelToRefuel".Translate(new object[] { fuelFilter.Summary })); return(false); } CompMountable compMountable = t.TryGetComp <CompMountable>(); if (compMountable != null && compMountable.IsMounted) { return(false); } return(true); }
public override void TransformValue(StatRequest req, ref float val) { if (req.Thing is Pawn pawn) { val += pawn.BodySize * 150f; float offset = 0; foreach (Hediff h in pawn.health.hediffSet.hediffs) { if (h.def.GetModExtension <DefModextension_Hediff>() is DefModextension_Hediff modExt && modExt.powerRateOffset != 0) { offset += val * modExt.powerRateOffset; } } if (Base.Instance.GetExtendedDataStorage() is ExtendedDataStorage store) { CompMountable turretMount = store.GetExtendedDataFor(pawn).turretMount; if (turretMount != null && turretMount.parent.GetComp <CompPowerTrader>() is CompPowerTrader powerComp && powerComp.PowerOn) { val += powerComp.Props.basePowerConsumption; } } val += offset; val *= Base.powerFallModifier; } }
public override string ExplanationPart(StatRequest req) { StringBuilder sb = new StringBuilder(); if (req.Thing is Pawn pawn) { sb.AppendLine("WTH_Explanation_BodySizeContr".Translate() + ": +" + pawn.BodySize * 150); foreach (Hediff h in pawn.health.hediffSet.hediffs) { if (h.def.GetModExtension <DefModextension_Hediff>() is DefModextension_Hediff modExt && modExt.powerRateOffset != 0) { sb.AppendLine(h.def.label + ": " + modExt.powerRateOffset.ToStringByStyle(ToStringStyle.PercentZero, ToStringNumberSense.Offset)); } } if (Base.Instance.GetExtendedDataStorage() is ExtendedDataStorage store) { CompMountable turretMount = store.GetExtendedDataFor(pawn).turretMount; if (turretMount != null && turretMount.parent.GetComp <CompPowerTrader>() is CompPowerTrader powerComp && powerComp.PowerOn) { sb.AppendLine(turretMount.parent.Label + ":" + powerComp.Props.basePowerConsumption.ToStringByStyle(ToStringStyle.Integer, ToStringNumberSense.Offset)); } } } if (Base.powerFallModifier.Value != 1f) { sb.AppendLine("WTH_Explanation_PowerFallModifier".Translate() + ": " + (1f - Base.powerFallModifier.Value).ToStringByStyle(ToStringStyle.PercentZero, ToStringNumberSense.Offset)); } return(sb.ToString()); }
protected override void PostSuccessfulApply(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill) { pawn.jobs.EndCurrentJob(JobCondition.InterruptForced); Thing oldThing = ingredients.FirstOrDefault((Thing t) => (t.GetInnerIfMinified().TryGetComp <CompMountable>() != null)); CompMountable comp = oldThing.GetInnerIfMinified().TryGetComp <CompMountable>(); comp.MountToPawn(pawn); }
private static void ConfigureTurretModule(Pawn mechanoid) { mechanoid.health.AddHediff(WTH_DefOf.WTH_MountedTurret); ThingDef turretDef = DefDatabase <ThingDef> .AllDefs.Where((ThingDef td) => td.HasComp(typeof(CompMountable))).RandomElement(); Thing thing = ThingMaker.MakeThing(turretDef, ThingDefOf.Steel); CompMountable comp = thing.GetInnerIfMinified().TryGetComp <CompMountable>(); comp.MountToPawn(mechanoid); }
//Make sure mounted turrets are brought along with the caravan. static void Prefix(Dialog_FormCaravan __instance) { List <TransferableOneWay> mountedTurretTows = __instance.transferables.Where((TransferableOneWay tow) => tow.AnyThing is ThingWithComps twc && twc.TryGetComp <CompMountable>() is CompMountable comp && comp.mountedTo != null).ToList(); foreach (TransferableOneWay tow in mountedTurretTows) { CompMountable comp = tow.AnyThing.TryGetComp <CompMountable>(); comp.ToInventory(); Traverse.Create(tow).Property("CountToTransfer").SetValue(1); } }
private static void AddModules(Pawn mechanoid) { List <HediffDef> modules = new List <HediffDef>(); modules.Add(WTH_DefOf.WTH_SpeedModule); modules.Add(WTH_DefOf.WTH_TurretModule); modules.Add(WTH_DefOf.WTH_VanometricModule); modules.Add(WTH_DefOf.WTH_BatteryExpansionModule); modules.Add(WTH_DefOf.WTH_RepairModule); modules.Add(WTH_DefOf.WTH_SelfDestruct); int i = 0; int count = modules.Count; while (i < count) { if (Rand.Chance(0)) {//Chance that the mod is NOT used modules.RemoveAt(i); } i++; } foreach (HediffDef hediff in modules) { if (hediff == WTH_DefOf.WTH_TurretModule) { if (mechanoid.BodySize < 2.0f) { continue; } mechanoid.health.AddHediff(WTH_DefOf.WTH_MountedTurret); ThingDef turretDef = DefDatabase <ThingDef> .AllDefs.Where((ThingDef td) => td.HasComp(typeof(CompMountable))).RandomElement(); Thing thing = ThingMaker.MakeThing(turretDef, ThingDefOf.Steel); CompMountable comp = thing.GetInnerIfMinified().TryGetComp <CompMountable>(); comp.MountToPawn(mechanoid); } mechanoid.health.AddHediff(hediff); if (hediff == WTH_DefOf.WTH_RepairModule) { mechanoid.InitializeComps(); if (mechanoid.TryGetComp <CompRefuelable>() is CompRefuelable comp) { Traverse.Create(comp).Field("fuel").SetValue(comp.Props.fuelCapacity); } } } }
public override bool HasJobOnThing(Pawn pawn, Thing t) { if (t.Faction != pawn.Faction) { return(false); } if (pawn.Faction == Faction.OfPlayer && !Find.AreaHome[t.Position]) { return(false); } if (!t.def.useHitPoints || t.HitPoints == t.MaxHitPoints) { return(false); } CompMountable compMountable = t.TryGetComp <CompMountable>(); if (compMountable != null && compMountable.IsMounted) { return(false); } Building building = t as Building; return(building != null && building.def.building.repairable && pawn.CanReserve(building, 1) && Find.DesignationManager.DesignationOn(building, DesignationDefOf.Deconstruct) == null && !building.IsBurning()); }
protected override void FillTab() { float fieldHeight = 30.0f; PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.PrisonerTab, KnowledgeAmount.FrameDisplayed); Text.Font = GameFont.Small; Rect innerRect1 = new Rect(0.0f, 0.0f, size.x, size.y).ContractedBy(10f); GUI.BeginGroup(innerRect1); Rect mountedRect = new Rect(0.0f, 30.0f, innerRect1.width, fieldHeight); float mountedRectY = mountedRect.y; Widgets.ListSeparator(ref mountedRectY, innerRect1.width, txtDriver.Translate()); mountedRect.y += fieldHeight; Rect thingIconRect = new Rect(mountedRect.x, mountedRect.y, 30f, fieldHeight); Rect thingLabelRect = new Rect(mountedRect.x + 35f, mountedRect.y + 5.0f, innerRect1.width - 35f, fieldHeight); Rect thingButtonRect = new Rect(mountedRect.x, mountedRect.y, innerRect1.width, fieldHeight); CompMountable compMountable = SelThing.TryGetComp <CompMountable>(); if (compMountable.IsMounted) { Pawn driver = compMountable.Driver; Widgets.ThingIcon(thingIconRect, driver); Widgets.Label(thingLabelRect, driver.Label); if (Mouse.IsOver(thingLabelRect)) { GUI.DrawTexture(thingLabelRect, TexUI.HighlightTex); } if (Event.current.button == 1 && Widgets.ButtonInvisible(thingButtonRect)) { List <FloatMenuOption> options = new List <FloatMenuOption>(); FloatMenuOption dismount = new FloatMenuOption("Dismount".Translate(driver.LabelShort), () => { compMountable.Dismount(); }); options.Add(dismount); Find.WindowStack.Add(new FloatMenu(options)); } thingIconRect.y += fieldHeight; thingLabelRect.y += fieldHeight; } Rect storageRect = new Rect(0.0f, thingIconRect.y, innerRect1.width, fieldHeight); float storageRectY = storageRect.y; Widgets.ListSeparator(ref storageRectY, innerRect1.width, txtStorage.Translate()); storageRect.y += fieldHeight; thingIconRect.y = storageRect.y; thingLabelRect.y = storageRect.y; thingButtonRect.y = storageRect.y; #region Cart Vehicle_Cart cart = SelThing as Vehicle_Cart; if (cart != null) { foreach (Thing thing in cart.storage) { if (thing.ThingID.IndexOf("Human_Corpse") > -1) { Widgets.DrawTextureFitted(thingIconRect, ContentFinder <Texture2D> .Get("Things/Pawn/IconHuman_Corpse"), 1.0f); } else if (thing.ThingID.IndexOf("Corpse") > -1) { Widgets.DrawTextureFitted(thingIconRect, ContentFinder <Texture2D> .Get("Things/Pawn/IconAnimal_Corpse"), 1.0f); } else { Widgets.ThingIcon(thingIconRect, thing); } Widgets.Label(thingLabelRect, thing.LabelCap); if (Event.current.button == 1 && Widgets.ButtonInvisible(thingButtonRect)) { List <FloatMenuOption> options = new List <FloatMenuOption>(); options.Add(new FloatMenuOption("ThingInfo".Translate(), () => { Find.WindowStack.Add(new Dialog_InfoCard(thing)); })); options.Add(new FloatMenuOption("DropThing".Translate(), () => { Thing dummy; cart.storage.TryDrop(thing, SelThing.Position, ThingPlaceMode.Near, out dummy); })); Find.WindowStack.Add(new FloatMenu(options, thing.LabelCap)); } if (Mouse.IsOver(thingLabelRect)) { GUI.DrawTexture(thingLabelRect, TexUI.HighlightTex); } TooltipHandler.TipRegion(thingLabelRect, thing.def.LabelStyled()); thingIconRect.y += fieldHeight; thingLabelRect.y += fieldHeight; } if (Widgets.ButtonText(new Rect(180f, 400f, 100f, 30f), "Drop All")) { cart.storage.TryDropAll(SelThing.Position, ThingPlaceMode.Near); } } #endregion GUI.EndGroup(); }