public static bool TryMakePreToilReservations_Prefix(ThingComp __instance, Pawn selPawn, ref IEnumerable <FloatMenuOption> __result) { if (!(selPawn.WorkTypeIsDisabled(WorkTypeDefOf.Research) || selPawn.WorkTagIsDisabled(WorkTags.Intellectual)) && selPawn.CanReach(__instance.parent, PathEndMode.ClosestTouch, Danger.Some, false, TraverseMode.ByPawn) && selPawn.CanReserve(__instance.parent, 1, -1, null, false)) { List <FloatMenuOption> modified = new List <FloatMenuOption>(); Thing thing = GenClosest.ClosestThingReachable(selPawn.Position, selPawn.Map, ThingRequest.ForGroup(ThingRequestGroup.ResearchBench), PathEndMode.InteractionCell, TraverseParms.For(selPawn, Danger.Some, TraverseMode.ByPawn, false), 9999f, (Thing t) => t is Building_WorkTable && selPawn.CanReserve(t, 1, -1, null, false), null, 0, -1, false, RegionType.Set_Passable, false); Job job = null; if (thing != null) { job = JobMaker.MakeJob(JobDefOf.ApplyTechprint); job.targetA = thing; job.targetB = __instance.parent; job.targetC = thing.Position; } modified.Add(new FloatMenuOption("ApplyTechprint".Translate(__instance.parent.Label).CapitalizeFirst(), delegate() { if (job == null) { Messages.Message("MessageNoResearchBenchForTechprint".Translate(), MessageTypeDefOf.RejectInput, true); return; } selPawn.jobs.TryTakeOrderedJob(job, JobTag.Misc); }, MenuOptionPriority.Default, null, null, 0f, null, null)); __result = modified.AsEnumerable(); return(false); } return(true); }
public void PowersSetup() { CompForceUser forcePowers = this.GetComp <CompForceUser>(); if (forcePowers == null) { ThingComp thingComp = (ThingComp)Activator.CreateInstance(typeof(CompForceUser)); thingComp.parent = this; var comps = AccessTools.Field(typeof(ThingWithComps), "comps").GetValue(this); if (comps != null) { ((List <ThingComp>)comps).Add(thingComp); } thingComp.Initialize(null); } forcePowers = this.GetComp <CompForceUser>(); if (forcePowers != null) { forcePowers.AlignmentValue = 0.99f; for (int o = 0; o < 10; o++) { forcePowers.ForceUserLevel += 1; forcePowers.ForceData.Skills.InRandomOrder <ForceSkill>().First((ForceSkill x) => x.level < 4).level++; forcePowers.ForceData.AbilityPoints -= 1; } for (int i = 0; i < 8; i++) { forcePowers.ForceUserLevel += 1; forcePowers.LevelUpPower(forcePowers.ForceData.PowersLight.InRandomOrder <ForcePower>().First((ForcePower x) => x.level < 2)); forcePowers.ForceData.AbilityPoints -= 1; } } }
public void GetObjectData(object obj, SerializationInfo info, StreamingContext context) { ThingComp tc = (ThingComp)obj; info.AddValue("parent", tc.parent); info.AddValue("index", tc.parent.AllComps.FirstIndexOf(t => t == tc)); }
public override bool IsOptionSelected(CustomPawn pawn, PawnLayerOption option) { PawnLayerOptionAlienAddon addonOption = option as PawnLayerOptionAlienAddon; if (addonOption == null) { return(false); } if (pawn.AlienRace != null) { ThingComp alienComp = pawn.Pawn.AllComps.FirstOrDefault((ThingComp comp) => { return(comp.GetType().Name == "AlienComp"); }); if (alienComp == null) { return(false); } FieldInfo variantsField = ReflectionUtil.GetPublicField(alienComp, "addonVariants"); if (variantsField == null) { return(false); } List <int> variants = null; try { variants = (List <int>)variantsField.GetValue(alienComp); } catch (Exception) { return(false); } int selectedIndex = variants[AlienAddon.VariantIndex]; return(selectedIndex == addonOption.Index); } return(false); }
private int?GetSelectedVariant(CustomPawn pawn, int variantIndex) { if (pawn.AlienRace == null) { return(null); } ThingComp alienComp = pawn.Pawn.AllComps.FirstOrDefault((ThingComp comp) => { return(comp.GetType().Name == "AlienComp"); }); if (alienComp == null) { return(null); } FieldInfo variantsField = ReflectionUtil.GetPublicField(alienComp, "addonVariants"); if (variantsField == null) { return(null); } List <int> variants = null; try { variants = (List <int>)variantsField.GetValue(alienComp); } catch (Exception) { return(null); } return(variants[variantIndex]); }
public override void SelectOption(CustomPawn pawn, PawnLayerOption option) { PawnLayerOptionAlienAddon addonOption = option as PawnLayerOptionAlienAddon; if (addonOption == null) { return; } if (pawn.AlienRace != null) { ThingComp alienComp = pawn.Pawn.AllComps.FirstOrDefault((ThingComp comp) => { return(comp.GetType().Name == "AlienComp"); }); if (alienComp == null) { return; } FieldInfo variantsField = ReflectionUtil.GetPublicField(alienComp, "addonVariants"); if (variantsField == null) { return; } List <int> variants = null; try { variants = (List <int>)variantsField.GetValue(alienComp); } catch (Exception) { return; } variants[AlienAddon.VariantIndex] = addonOption.Index; pawn.MarkPortraitAsDirty(); } }
static void DrawCancerRadius(ThingComp __instance) { if (__instance is CompPowerPlantWind) { GenDraw.DrawRadiusRing(__instance.parent.Position, TrumpCancerWindmill.Settings.cancerRadius); } }
public override void PostSpawnSetup(bool respawningAfterLoad) { base.PostSpawnSetup(respawningAfterLoad); if (Props.dependsOnPower) { powerComp = this.parent.GetComp <CompPowerTrader>(); } if (Props.dependsOnFuel) { fuelComp = this.parent.GetComp <CompRefuelable>(); } if (Props.dependsOnGas) { gasComp = GetGasComp(); } if (Props.flickable) { compFlickable = this.parent.GetComp <CompFlickable>(); } if (!Props.dependsOnFuel && !Props.dependsOnPower) { active = true; } tempControlComp = this.parent.GetComp <CompTempControl>(); this.position = this.parent.Position; this.map = this.parent.Map; this.proxyHeatManager = this.map.GetComponent <ProxyHeatManager>(); if (Props.dependsOnPower || Props.dependsOnFuel || Props.dependsOnGas || Props.flickable) { this.proxyHeatManager.compTemperaturesToTick.Add(this); } this.MarkDirty(); }
public override Graphic PostGraphicEffects(Graphic graphic) { if (graphic != null) { ThingComp comp = this.parent.AllComps.FirstOrDefault((ThingComp x) => x is CompSlotLoadable.CompSlotLoadable); if (comp != null) { CompSlotLoadable.CompSlotLoadable compSlotLoadable = comp as CompSlotLoadable.CompSlotLoadable; SlotLoadable colorSlot = compSlotLoadable.Slots.FirstOrDefault((SlotLoadable x) => ((SlotLoadableDef)x.def).doesChangeColor == true); if (colorSlot != null) { if (colorSlot.SlotOccupant != null) { if (graphic.Shader != null) { Graphic result = graphic.GetColoredVersion(graphic.Shader, colorSlot.SlotOccupant.DrawColor, colorSlot.SlotOccupant.DrawColorTwo); if (result != null) { return(result); } } } } } } return(base.PostGraphicEffects(graphic)); }
public static void Postfix(ThingWithComps __instance) { if (__instance.Stuff != null && __instance.Stuff.comps != null) { CompProperties_AddedThing compProperties_AddedThing = __instance.Stuff.comps.Where(x => x is CompProperties_AddedThing).FirstOrDefault() as CompProperties_AddedThing; if (compProperties_AddedThing != null) { if (!compProperties_AddedThing.ForApparel && __instance is Apparel) { return; } if (!compProperties_AddedThing.ForWeapons && __instance.def.equipmentType == EquipmentType.Primary) { return; } FieldInfo compsField = (typeof(ThingWithComps).GetField("comps", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static)); List <ThingComp> comps = compsField.GetValue(__instance) as List <ThingComp>; if (comps == null) { comps = new List <ThingComp>(); } ThingComp thingComp = (ThingComp)Activator.CreateInstance(compProperties_AddedThing.Comp); thingComp.parent = __instance; comps.Add(thingComp); thingComp.Initialize(compProperties_AddedThing); compsField.SetValue(__instance, comps); } } }
private static void SyncFavourValue(ThingComp souldComp, int favourIndex, float value) { var favourTracker = compSoulFavourTrackerField.GetValue(souldComp); var favoursList = (IList)soulFavourTrackerFavoursField.GetValue(favourTracker); favourProgressFavourValueField.SetValue(favoursList[favourIndex], value); }
private static void DeferredInitialization([NotNull] ThingWithComps catalyst) { _pendingInit = false; ThingComp comp = catalyst.AllComps.FirstOrDefault(c => c.GetType().Name.Equals("CompSidearmMemory")); if (comp == null) { return; } try { Assembly assembly = comp.GetType().Assembly; _compSidearmMemory = comp.GetType(); Type weaponPair = assembly.GetType("SimpleSidearms.rimworld.ThingDefStuffDefPair"); _sidearmMemoryWeapons = _compSidearmMemory.GetField("rememberedWeapons"); _thingFromPair = weaponPair.GetField("thing"); _stuffFromPair = weaponPair.GetField("stuff"); Active = true; } catch (Exception e) { TkUtils.Logger.Error("Compatibility class for Simple Sidearms failed!", e); } }
public static void RequireTicker(this ThingComp comp, TickerType type) { if (comp.parent.def.tickerType != type) { Log.Error($"{comp.GetType().Name} requires tickerType:{type} in def {comp.parent.def.defName}"); } }
private static bool InjectedTryLearnPower(ThingComp comp, object selectedPower) { var disciplineDef = compPsykerMainDisciplineField.GetValue(comp); var list = (IList)psykerDisciplineDefAbilitiesField.GetValue(disciplineDef); var index = list.IndexOf(selectedPower); // Main discipline, we have an index to it in the list if (index >= 0) { SyncedTryLearnPower(comp, int.MinValue, index); } // We don't have a discipline index, so it's a minor discipline - find which one and sync it else { var defsList = (IList)compPsykerMinorDisciplinesField.GetValue(comp); for (int i = 0; i < defsList.Count; i++) { list = (IList)psykerDisciplineDefAbilitiesField.GetValue(defsList[i]); index = list.IndexOf(selectedPower); if (index >= 0) { SyncedTryLearnPower(comp, i, index); break; } } } return(true); }
public static void get_Graphic_PostFix(Thing __instance, ref Graphic __result) { Graphic tempGraphic = (Graphic)AccessTools.Field(typeof(Thing), "graphicInt").GetValue(__instance); if (tempGraphic != null) { ThingWithComps thingWithComps = __instance as ThingWithComps; if (thingWithComps != null) { if (thingWithComps.holdingContainer != null) { return; } ThingComp activatableEffect = thingWithComps.AllComps.FirstOrDefault <ThingComp>((ThingComp y) => y.GetType().ToString().Contains("ActivatableEffect")); if (activatableEffect != null) { return; } CompOversizedWeapon compOversizedWeapon = thingWithComps.TryGetComp <CompOversizedWeapon>(); if (compOversizedWeapon != null) { tempGraphic.drawSize = __instance.def.graphicData.drawSize; __result = tempGraphic; } } } }
public static void RequireTicker(this ThingComp comp, TickerType type) { if (comp.parent.def.tickerType != type) { RemoteTechController.Instance.Logger.Error($"{comp.GetType().Name} requires tickerType:{type} in def {comp.parent.def.defName}"); } }
void InitializeThingComps(bool remove) { ThingComp[] comps = GetComps(); if (comps == null) { return; } List <ThingComp> list = pawn.Comps(); foreach (ThingComp comp in comps) { if (remove) { list.RemoveAll(x => x.GetType() == comp.GetType() && x.props == comp.props); continue; } ThingComp existing = list.FirstOrDefault(x => x.GetType() == comp.GetType() && x.props == comp.props); if (existing != null) { continue; } comp.parent = pawn; list.Add(comp); if (pawn.Map != null) { comp.PostSpawnSetup(false); } } }
public static bool TransformPawn(Pawn p) { bool retval = false; if (AbilityUserUtility.abilityUserChildren == null) { AbilityUserUtility.abilityUserChildren = AbilityUserUtility.GetAllChildrenOf(typeof(CompAbilityUser)); } foreach (Type t in AbilityUserUtility.abilityUserChildren) { bool st = true; /* * // this code does a check, but since there is no good way to create triggers when specific events occur to * // add the CompAbilityUser to a Pawn, this just adds them and then checks them on each CompTick. */ if (st) { retval = true; ThingComp thingComp = (ThingComp)Activator.CreateInstance((t)); thingComp.parent = p; object comps = AccessTools.Field(typeof(ThingWithComps), "comps").GetValue(p); if (comps != null) { ((List <ThingComp>)comps).Add(thingComp); } thingComp.Initialize(null); } } return(retval); }
private static void SyncFavourValue(ThingComp souldComp, int favourIndex, float value) { var favourTracker = compSoulFavourTrackerField(souldComp); var favoursList = soulFavourTrackerFavoursField(favourTracker); favourProgressFavourValueField(favoursList[favourIndex]) = value; }
public static void get_Graphic_PostFix(Thing __instance, ref Graphic __result) { Graphic tempGraphic = Traverse.Create(__instance).Field("graphicInt").GetValue<Graphic>(); if (tempGraphic != null) { ThingWithComps thingWithComps = __instance as ThingWithComps; if (thingWithComps != null) { if (thingWithComps.ParentHolder is Pawn) { return; } ThingComp activatableEffect = thingWithComps.AllComps.FirstOrDefault<ThingComp>((ThingComp y) => y.GetType().ToString().Contains("ActivatableEffect")); if (activatableEffect != null) { var getPawn = Traverse.Create(activatableEffect).Property("GetPawn").GetValue<Pawn>(); if (getPawn != null) { //Log.Message("1"); return; } } CompOversizedWeapon compOversizedWeapon = thingWithComps.TryGetComp<CompOversizedWeapon>(); if (compOversizedWeapon != null) { tempGraphic.drawSize = __instance.def.graphicData.drawSize; __result = tempGraphic; } } } }
//Overlay drawer update private static void AddToGraphicUpdateList(ThingComp compAir) { foreach (var current in compAir.parent.OccupiedRect()) { updatees.Add(current); } }
public static T RequireComponent <T>(this ThingComp comp, T component) { if (component == null) { Log.Error($"{comp.GetType().Name} requires {nameof(T)} in def {comp.parent.def.defName}"); } return(component); }
static void RestoreForbidden(bool __state, ThingComp __instance) { if (!qualityBuilder_Forbidden) { return; } __instance.parent.SetForbidden(__state, false); }
public static T RequireComponent <T>(this ThingComp comp, T component) { if (component == null) { RemoteTechController.Instance.Logger.Error($"{comp.GetType().Name} requires {nameof(T)} in def {comp.parent.def.defName}"); } return(component); }
private static void PreSyncBombType(ThingComp __instance) { if (MP.IsInMultiplayer) { MP.WatchBegin(); bombTypeSync.Watch(__instance); } }
public void Offline(ThingComp comp) { onlineComp.Remove(comp); if (comp is Comp.VoidNetEquipmentPort) { (comp as Comp.VoidNetEquipmentPort).voidNetTerminal = null; } }
static void GetForbidden(ref bool __state, ThingComp __instance) { if (!qualityBuilder_Forbidden) { return; } __state = __instance.parent.IsForbidden(Faction.OfPlayer); }
private void DropBomb() { for (int i = 0; i < (bombType == BombingType.precise ? this.precisionBombingNumBombs : 1); ++i) { if (innerContainer.Any(x => ((ActiveDropPod)x)?.Contents.innerContainer.Any(y => SRTSMod.mod.settings.allowedBombs.Contains(y.def.defName)) ?? false)) { ActiveDropPod srts = (ActiveDropPod)innerContainer.First(); Thing thing = srts?.Contents.innerContainer.FirstOrDefault(y => SRTSMod.mod.settings.allowedBombs.Contains(y.def.defName)); if (thing is null) { return; } Thing thing2 = srts?.Contents.innerContainer.Take(thing, 1); IntVec3 bombPos = bombCells[0]; if (bombType == BombingType.carpet) { bombCells.RemoveAt(0); } int timerTickExplode = 20 + Rand.Range(0, 5); //Change later to allow release timer if (SRTSHelper.CEModLoaded) { goto Block_CEPatched; } FallingBomb bombThing = new FallingBomb(thing2, thing2.TryGetComp <CompExplosive>(), this.Map, this.def.skyfaller.shadow); bombThing.HitPoints = int.MaxValue; bombThing.ticksRemaining = timerTickExplode; IntVec3 c = (from x in GenRadial.RadialCellsAround(bombPos, GetCurrentTargetingRadius(), true) where x.InBounds(this.Map) select x).RandomElementByWeight((IntVec3 x) => 1f - Mathf.Min(x.DistanceTo(this.Position) / GetCurrentTargetingRadius(), 1f) + 0.05f); bombThing.angle = this.angle + (SPTrig.LeftRightOfLine(this.DrawPosCell, this.Position, c) * -10); bombThing.speed = (float)SPExtra.Distance(this.DrawPosCell, c) / bombThing.ticksRemaining; Thing t = GenSpawn.Spawn(bombThing, c, this.Map); GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(t, thing2.TryGetComp <CompExplosive>().Props.explosiveDamageType, null); continue; Block_CEPatched :; ThingComp CEComp = (thing2 as ThingWithComps)?.AllComps.Find(x => x.GetType().Name == "CompExplosiveCE"); FallingBombCE CEbombThing = new FallingBombCE(thing2, CEComp.props, CEComp, this.Map, this.def.skyfaller.shadow); CEbombThing.HitPoints = int.MaxValue; CEbombThing.ticksRemaining = timerTickExplode; IntVec3 c2 = (from x in GenRadial.RadialCellsAround(bombPos, GetCurrentTargetingRadius(), true) where x.InBounds(this.Map) select x).RandomElementByWeight((IntVec3 x) => 1f - Mathf.Min(x.DistanceTo(this.Position) / GetCurrentTargetingRadius(), 1f) + 0.05f); CEbombThing.angle = this.angle + (SPTrig.LeftRightOfLine(this.DrawPosCell, this.Position, c2) * -10); CEbombThing.speed = (float)SPExtra.Distance(this.DrawPosCell, c2) / CEbombThing.ticksRemaining; Thing CEt = GenSpawn.Spawn(CEbombThing, c2, this.Map); //GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(CEt, DamageDefOf., null); /*Is GenExplosion CE compatible?*/ } } if (bombType == BombingType.precise && bombCells.Any()) { bombCells.Clear(); } }
private static bool PreCompGetGizmos27(ThingComp __instance, Pawn p) { if (!MP.IsInMultiplayer || MP.IsExecutingSyncCommand) { return(true); } SyncedGetGizmos27(__instance, p.thingIDNumber); return(false); }
// Token: 0x06000072 RID: 114 RVA: 0x00006B74 File Offset: 0x00004D74 public static int GetLastPainReliefTick(Pawn pawn) { ThingComp PComp = (pawn != null) ? ThingCompUtility.TryGetComp <MSPainlessData>(pawn) : null; if (PComp != null) { return((PComp as MSPainlessData).LastPainReliefTick); } return(0); }
//Overlay drawer update private static void AddToGraphicUpdateList( ThingComp compAir ) { foreach (var current in compAir.parent.OccupiedRect()) updatees.Add( current ); }