public void UpdateAllSettings() { DefDatabase <ThingDef> .GetNamed("MineableComponentsIndustrial").building.mineableYield = (int)Math.Floor(MoreCompsModSettings.OriginalCompsAmount * MoreCompsModSettings.multiplyMC); }
private static void ResetDSUToDefaults(string resetDefName) { object tmpObject; string defName = resetDefName; string prop; bool resetAll = (resetDefName == null || resetDefName == ""); while ((resetAll && Settings.defTracker.GetFirstDefaultValue(out defName, out prop, out tmpObject)) || Settings.defTracker.GetFirstDefaultValueFor(defName, out prop, out tmpObject)) { Utils.Mess(Utils.DBF.Settings, "Resetting " + prop + " to default value for " + defName); var def = DefDatabase <ThingDef> .GetNamed(defName, false); if (def == null) { ThingDef tmp = (ThingDef)Settings.defTracker.GetDefaultValue(defName, "def", def); if (tmp != null) { def = tmp; // We are resetting the def, so we need it back in the DefDatabase! ReturnDefToUse(def); Settings.defTracker.Remove(defName, "def"); if (prop == "def") { continue; } } else { //todo: put this error message it translate Log.Warning("LWM.DeepStorage: Tried to change mod setting for " + defName + " but could not find def.\nClear your settings to remove this error."); Settings.defTracker.Remove(defName, prop); continue; } } if (prop == "label") { def.label = (string)(tmpObject); } else if (prop == "maxNumStacks") { def.GetCompProperties <Properties>().maxNumberStacks = (int)(tmpObject); } else if (prop == "maxTotalMass") { def.GetCompProperties <Properties>().maxTotalMass = (float)(tmpObject); } else if (prop == "maxMassStoredItem") { def.GetCompProperties <Properties>().maxMassOfStoredItem = (float)(tmpObject); } else if (prop == "showContents") { def.GetCompProperties <Properties>().showContents = (bool)(tmpObject); } else if (prop == "storagePriority") { def.building.defaultStorageSettings.Priority = (StoragePriority)(tmpObject); } else if (prop == "overlayType") { def.GetCompProperties <Properties>().overlayType = (LWM.DeepStorage.GuiOverlayType)(tmpObject); } else if (prop == "filter") { def.building.fixedStorageSettings.filter = (ThingFilter)(tmpObject); } else if (prop == "def") { // Def was marked for removal but hasn't been removed yet Utils.Mess(Utils.DBF.Settings, "Removing " + defName + " from list of defs to remove."); ReturnDefToUse(def); } else { Log.Error("LWM.DeepStorage: FAILED TO RESET OPTION TO DEFAULT: " + defName + ", " + prop); } Settings.defTracker.Remove(defName, prop); } // end while loop, defSettings.DefTracker didn't have anything else // done resetting! }
// Token: 0x06000024 RID: 36 RVA: 0x00002B1F File Offset: 0x00000D1F // Token: 0x06000025 RID: 37 RVA: 0x00002B27 File Offset: 0x00000D27 public override IEnumerable <Gizmo> GetWornGizmos() { var fuelicon = JPFuelItem.uiIcon; if (fuelicon == null) { ThingDef chkFuelItem = null; if (JPFuelItem == null) { chkFuelItem = DefDatabase <ThingDef> .GetNamed(GetComp <CompJetPack>().Props.JPFuel, false); } if (chkFuelItem != null && chkFuelItem != JPFuelItem) { JPFuelItem = chkFuelItem; var chkFuelMax = GetComp <CompJetPack>().Props.JPFuelMaximum; if (chkFuelMax != JPFuelMax) { JPFuelMax = chkFuelMax; if (JPFuelAmount > JPFuelMax) { JPFuelAmount = JPFuelMax; } } } fuelicon = JPFuelItem.uiIcon; if (fuelicon == null) { JPFuelItem = ThingDefOf.Chemfuel; fuelicon = JPFuelItem.uiIcon; if (fuelicon == null) { fuelicon = def.uiIcon; Log.Message("Error: Jet Pack fuel definition not found."); } } } var chkSkyFallType = GetComp <CompJetPack>().Props.JPSKType; JPSkyFallType = string.IsNullOrEmpty(chkSkyFallType) ? "SFJetPack" : chkSkyFallType; var pilot = Wearer; JPJumpRangeMax = JPUtility.GetJumpRange(pilot, def, JPFuelItem, JPJumpRangeMin); JPFuelRate = JPUtility.GetFuelRate(JPFuelItem); if (Wearer == null || !Wearer.IsColonistPlayerControlled) { yield break; } var wearer = Wearer; if (wearer?.Map == null || Wearer.Downed || !Wearer.Spawned || JPUtility.IsInMeleeWithJP(Wearer)) { yield break; } if (Find.Selector.SingleSelectedThing != Wearer) { yield break; } string text = JPOnCooldown ? "JetPack.CooldownTicks".Translate(JPCooldownTicks.ToString()) : "JetPack.JPJump".Translate(); string desc = "JetPack.JPDesc".Translate(def.label.CapitalizeFirst()); yield return(new Command_JetPack { defaultLabel = text, defaultDesc = desc, icon = def.uiIcon, Pilot = Wearer, JPFuel = JPFuelAmount, JPFRate = JPFuelRate, JPMaxJump = JPJumpRangeMax, JPMinJump = JPJumpRangeMin, JPSKFStr = JPSkyFallType, action = delegate(IntVec3 cell) { SoundDefOf.Click.PlayOneShotOnCamera(); UseJetPack(Wearer, this, cell); } }); if (Settings.AllowSlowBurn) { text = "JetPack.JPSBSet".Translate(); desc = "JetPack.JPSBDesc".Translate(); yield return(new Command_Toggle { icon = ContentFinder <Texture2D> .Get(JPSBTexPath), defaultLabel = text, defaultDesc = desc, isActive = () => JPSlowBurn, toggleAction = delegate { ToggleSlowBurn(JPSlowBurn); } }); } text = "JetPack.JPLabel".Translate(def.label.CapitalizeFirst(), JPFuelAmount.ToString(), JPFuelMax.ToString()); desc = "JetPack.JPDesc".Translate(def.label.CapitalizeFirst()); yield return(new Command_Action { defaultLabel = text, defaultDesc = desc, icon = fuelicon, action = delegate { SoundDefOf.Click.PlayOneShotOnCamera(); RefuelJetPack(Wearer, this); } }); if (Prefs.DevMode) { yield return(new Command_Action { defaultLabel = "Debug Settings", defaultDesc = "Debug Commands", icon = fuelicon, action = delegate { SoundDefOf.Click.PlayOneShotOnCamera(); DoJetPackDebug(Wearer, this); } }); } }
public bool Inject(ModHelperDef def) { if (def.Designators.NullOrEmpty()) { return(true); } foreach (var injectionSet in def.Designators) { if (!string.IsNullOrEmpty(injectionSet.designationCategoryDef)) { // Get the category var designationCategory = DefDatabase <DesignationCategoryDef> .GetNamed(injectionSet.designationCategoryDef, false); // First instatiate and inject the designator into the list of resolved designators if (!injectionSet.DesignatorExists()) { // Create the new designator var designatorObject = (Designator)Activator.CreateInstance(injectionSet.designatorClass); if (designatorObject == null) { CCL_Log.Message(string.Format("Unable to create instance of '{0}'", injectionSet.designatorClass)); return(false); } if (injectionSet.designatorNextTo == null) { // Inject the designator designationCategory._resolvedDesignators().Add(designatorObject); } else { // Prefers to be beside a specific designator var designatorIndex = designationCategory._resolvedDesignators().FindIndex(d => ( (d.GetType() == injectionSet.designatorNextTo) )); if (designatorIndex < 0) { // Other designator doesn't exist (yet?) // Inject the designator at the end designationCategory._resolvedDesignators().Add(designatorObject); } else { // Inject beside desired designator designationCategory._resolvedDesignators().Insert(designatorIndex + 1, designatorObject); } } } // Now inject the designator class into the list of classes as a saftey net for another mod resolving the category if (!designationCategory.specialDesignatorClasses.Exists(s => s == injectionSet.designatorClass)) { if (injectionSet.designatorNextTo == null) { // Inject the designator class at the end of the list designationCategory.specialDesignatorClasses.Add(injectionSet.designatorClass); } else { // Prefers to be beside a specific designator var designatorIndex = designationCategory.specialDesignatorClasses.FindIndex(s => s == injectionSet.designatorNextTo); if (designatorIndex < 0) { // Can't find desired designator class // Inject the designator at the end designationCategory.specialDesignatorClasses.Add(injectionSet.designatorClass); } else { // Inject beside desired designator class designationCategory.specialDesignatorClasses.Insert(designatorIndex + 1, injectionSet.designatorClass); } } } } if (injectionSet.reverseDesignator) { if (ReverseDesignatorDatabase_Extensions.Find(injectionSet.designatorClass) == null) { ReverseDesignatorDatabase.AllDesignators.Add((Designator)Activator.CreateInstance(injectionSet.designatorClass)); } } } return(true); }
public static TraitDef Named(string defName) { return(DefDatabase <TraitDef> .GetNamed(defName, true)); }
public static void Add <D>(D d) where D : Def { DefDatabase <D> .Add(d); }
public static void AddGizmo(Pawn __instance, ref IEnumerable <Gizmo> __result) { //I want access to the pawn object, and want to modify the original method's result var pawn = __instance; var gizmos = __result.ToList(); // First two flags detect if the pawn is mine, and if it is bool flagIsCreatureMine = pawn.Faction != null && pawn.Faction.IsPlayer; bool flagIsCreatureDraftable = (pawn.TryGetComp <CompDraftable>() != null); /* I check these flags only inside flagIsCreatureDraftable true to avoid errors due to pawn.TryGetComp<CompDraftable>() being null in most pawns. The code inside * the conditional only executes if it isn't*/ bool flagIsCreatureRageable = false; bool flagIsCreatureExplodable = false; bool flagIsCreatureChickenRimPox = false; bool flagCanCreatureCarryMore = false; bool flagCanCreatureAdrenalineBurst = false; bool flagCanCanDoInsectClouds = false; bool flagCanStampede = false; bool flagCanDoPoisonousCloud = false; bool flagCanBurrow = false; bool flagCanStamina = false; bool flagCanHorrorize = false; bool flagCanMechaBlast = false; bool flagCanKeenSenses = false; bool flagCanCatReflexes = false; bool flagIsMindControlBuildingPresent = false; if (flagIsCreatureDraftable) { /*Inside here, I check if the Building is present in the map. I only want to do the check for * hybrids, or it will do this iterator for every creature in the map */ foreach (Thing t in pawn.Map.listerThings.ThingsOfDef(ThingDef.Named("GR_AnimalControlHub"))) { Thing mindcontrolhub = t as Thing; if (t != null) { flagIsCreatureRageable = pawn.TryGetComp <CompDraftable>().GetRage; flagIsCreatureExplodable = pawn.TryGetComp <CompDraftable>().GetExplodable; flagIsCreatureChickenRimPox = pawn.TryGetComp <CompDraftable>().GetChickenRimPox; flagCanCreatureCarryMore = pawn.TryGetComp <CompDraftable>().GetCanCarryMore; flagCanCreatureAdrenalineBurst = pawn.TryGetComp <CompDraftable>().GetAdrenalineBurst; flagCanCanDoInsectClouds = pawn.TryGetComp <CompDraftable>().GetCanDoInsectClouds; flagCanStampede = pawn.TryGetComp <CompDraftable>().GetCanStampede; flagCanDoPoisonousCloud = pawn.TryGetComp <CompDraftable>().GetCanDoPoisonousCloud; flagCanBurrow = pawn.TryGetComp <CompDraftable>().GetCanBurrow; flagCanStamina = pawn.TryGetComp <CompDraftable>().HasDinoStamina; flagCanHorrorize = pawn.TryGetComp <CompDraftable>().GetHorror; flagCanMechaBlast = pawn.TryGetComp <CompDraftable>().GetMechablast; flagCanKeenSenses = pawn.TryGetComp <CompDraftable>().GetKeenSenses; flagCanCatReflexes = pawn.TryGetComp <CompDraftable>().GetCatReflexes; flagIsMindControlBuildingPresent = true; } } } /*Is the creature part of the colony, and draftable (the custom comp class)? Then display the drafting gizmo, called * Mind Control. It's action is just calling on toggle the Drafted method in the pawn's drafter, which * we initialized in the first Harmony Postfix */ if ((pawn.drafter != null) && flagIsCreatureMine && flagIsCreatureDraftable && flagIsMindControlBuildingPresent || pawn.def.defName == "GR_ArchotechCentipede") { Command_Action GR_Gizmo_MindControl = new Command_Action(); GR_Gizmo_MindControl.action = delegate { pawn.drafter.Drafted = !pawn.drafter.Drafted; }; GR_Gizmo_MindControl.defaultLabel = "GR_CreatureMindControl".Translate(); GR_Gizmo_MindControl.defaultDesc = "GR_CreatureMindControlDesc".Translate(); GR_Gizmo_MindControl.icon = ContentFinder <Texture2D> .Get("ui/commands/GR_ControlAnimal", true); gizmos.Insert(0, GR_Gizmo_MindControl); } /*If the creature is draftable, drafted at the moment and the rage property (which is passed through XML and the custom comp class) is true, * we add a second gizmo, which copies the code from melee attacks, and thus allows targeting melee attacks */ if ((pawn.drafter != null) && flagIsCreatureRageable && flagIsCreatureMine && pawn.drafter.Drafted && flagIsMindControlBuildingPresent) { Command_Target GR_Gizmo_AttackRage = new Command_Target(); GR_Gizmo_AttackRage.defaultLabel = "GR_CreatureRageAttack".Translate(); GR_Gizmo_AttackRage.defaultDesc = "GR_CreatureRageAttackDesc".Translate(); GR_Gizmo_AttackRage.targetingParams = TargetingParameters.ForAttackAny(); GR_Gizmo_AttackRage.icon = ContentFinder <Texture2D> .Get("Things/Item/AnimalPaws", true); GR_Gizmo_AttackRage.action = delegate(Thing target) { IEnumerable <Pawn> enumerable = Find.Selector.SelectedObjects.Where(delegate(object x) { Pawn pawn2 = x as Pawn; return(pawn2 != null && pawn2.Drafted); }).Cast <Pawn>(); foreach (Pawn current in enumerable) { Job job = new Job(JobDefOf.AttackMelee, target); Pawn pawn2 = target as Pawn; if (pawn2 != null) { job.killIncappedTarget = pawn2.Downed; } pawn.jobs.TryTakeOrderedJob(job, JobTag.Misc); } }; gizmos.Insert(1, GR_Gizmo_AttackRage); } /*This adds a gizmo that makes the creature attack once, and then cause a Hediff disease (GR_ChickenRimPox), then cancels the draft. I used a custom Jobdriver class for that */ if ((pawn.drafter != null) && flagIsCreatureChickenRimPox && flagIsCreatureMine && pawn.drafter.Drafted && flagIsMindControlBuildingPresent || pawn.def.defName == "GR_ArchotechCentipede") { Command_Target GR_Gizmo_AttackPox = new Command_Target(); GR_Gizmo_AttackPox.defaultLabel = "GR_InflictChickenRimPox".Translate(); GR_Gizmo_AttackPox.defaultDesc = "GR_InflictChickenRimPoxDesc".Translate(); GR_Gizmo_AttackPox.targetingParams = TargetingParameters.ForAttackAny(); GR_Gizmo_AttackPox.icon = ContentFinder <Texture2D> .Get("ui/commands/GR_ChickenRimPox", true); GR_Gizmo_AttackPox.action = delegate(Thing target) { IEnumerable <Pawn> enumerable = Find.Selector.SelectedObjects.Where(delegate(object x) { Pawn pawn2 = x as Pawn; return(pawn2 != null && pawn2.Drafted); }).Cast <Pawn>(); foreach (Pawn current in enumerable) { Job job = new Job(DefDatabase <JobDef> .GetNamed("GR_AttackMeleeOnceAndChickenRimPox", true), target); Pawn pawn2 = target as Pawn; if (pawn2 != null) { job.killIncappedTarget = pawn2.Downed; } pawn.jobs.TryTakeOrderedJob(job, JobTag.Misc); } }; gizmos.Insert(1, GR_Gizmo_AttackPox); } /*If the creature is explodable, we add this gizmo, which causes a Heddif called "sudden explosion" (GR_Kamikaze), and increases severity to * 1 to make the creature die. This only works if the creature also has DeathActionWorker. */ if ((pawn.drafter != null) && flagIsCreatureExplodable && flagIsCreatureMine && flagIsMindControlBuildingPresent) { Command_Action GR_Gizmo_Detonate = new Command_Action(); GR_Gizmo_Detonate.action = delegate { pawn.health.AddHediff(HediffDef.Named("GR_Kamikaze")); HealthUtility.AdjustSeverity(pawn, HediffDef.Named("GR_Kamikaze"), 1); }; GR_Gizmo_Detonate.defaultLabel = "GR_DetonateChemfuel".Translate(); GR_Gizmo_Detonate.defaultDesc = "GR_DetonateChemfuelDesc".Translate(); GR_Gizmo_Detonate.icon = ContentFinder <Texture2D> .Get("UI/Commands/Detonate", true); gizmos.Insert(1, GR_Gizmo_Detonate); } /* This is a dummy gizmo. It only displays, but does nothing on click. The processing is done below in another Harmony patch to MassUtility.Capacity */ if ((pawn.drafter != null) && flagCanCreatureCarryMore && flagIsCreatureMine && flagIsMindControlBuildingPresent) { Command_Action GR_Gizmo_Carry = new Command_Action(); GR_Gizmo_Carry.action = delegate { }; GR_Gizmo_Carry.defaultLabel = "GR_CarryMore".Translate(); GR_Gizmo_Carry.defaultDesc = "GR_CarryMoreDesc".Translate(); GR_Gizmo_Carry.icon = ContentFinder <Texture2D> .Get("ui/commands/GR_IncreasedCarry", true); gizmos.Insert(1, GR_Gizmo_Carry); } /*This gizmo applies a Hediff that makes the pawn move faster for a while */ if ((pawn.drafter != null) && flagCanCreatureAdrenalineBurst && flagIsCreatureMine && flagIsMindControlBuildingPresent || pawn.def.defName == "GR_ArchotechCentipede") { Command_Action GR_Gizmo_AdrenalineBurst = new Command_Action(); GR_Gizmo_AdrenalineBurst.defaultLabel = "GR_StartAdrenalineBurst".Translate(); GR_Gizmo_AdrenalineBurst.defaultDesc = "GR_StartAdrenalineBurstDesc".Translate(); GR_Gizmo_AdrenalineBurst.icon = ContentFinder <Texture2D> .Get("ui/commands/GR_AdrenalineBurst", true); GR_Gizmo_AdrenalineBurst.action = delegate { if (!pawn.health.hediffSet.HasHediff(HediffDef.Named("GR_AdrenalineBurst"))) { pawn.health.AddHediff(HediffDef.Named("GR_AdrenalineBurst")); } else { Messages.Message("GR_AbilityRecharging".Translate(), pawn, MessageTypeDefOf.NeutralEvent); } }; gizmos.Insert(1, GR_Gizmo_AdrenalineBurst); } /*This gizmo applies a Hediff that makes the pawn release insect clouds for a while */ if ((pawn.drafter != null) && flagCanCanDoInsectClouds && flagIsCreatureMine && flagIsMindControlBuildingPresent) { Command_Action GR_Gizmo_InsectClouds = new Command_Action(); GR_Gizmo_InsectClouds.defaultLabel = "GR_ReleaseInsectClouds".Translate(); GR_Gizmo_InsectClouds.defaultDesc = "GR_ReleaseInsectCloudsDesc".Translate(); GR_Gizmo_InsectClouds.icon = ContentFinder <Texture2D> .Get("ui/commands/GR_Insectclouds", true); GR_Gizmo_InsectClouds.action = delegate { if (!pawn.health.hediffSet.HasHediff(HediffDef.Named("GR_InsectClouds"))) { pawn.health.AddHediff(HediffDef.Named("GR_InsectClouds")); } else { Messages.Message("GR_AbilityRecharging".Translate(), pawn, MessageTypeDefOf.NeutralEvent); } }; gizmos.Insert(1, GR_Gizmo_InsectClouds); } /*This gizmo applies a Hediff that makes the pawn generate stampede clouds for a while */ if ((pawn.drafter != null) && flagCanStampede && flagIsCreatureMine && flagIsMindControlBuildingPresent || pawn.def.defName == "GR_ArchotechCentipede") { Command_Action GR_Gizmo_Stampede = new Command_Action(); GR_Gizmo_Stampede.defaultLabel = "GR_StartStampede".Translate(); GR_Gizmo_Stampede.defaultDesc = "GR_StartStampedeDesc".Translate(); GR_Gizmo_Stampede.icon = ContentFinder <Texture2D> .Get("ui/commands/GR_StampedeClouds", true); GR_Gizmo_Stampede.action = delegate { if (!pawn.health.hediffSet.HasHediff(HediffDef.Named("GR_Stampeding"))) { pawn.health.AddHediff(HediffDef.Named("GR_Stampeding")); } else { Messages.Message("GR_AbilityRecharging".Translate(), pawn, MessageTypeDefOf.NeutralEvent); } }; gizmos.Insert(1, GR_Gizmo_Stampede); } /*This gizmo adds an attack that spawns a poison cloud at a target's location */ if ((pawn.drafter != null) && flagCanDoPoisonousCloud && flagIsCreatureMine && flagIsMindControlBuildingPresent) { Command_Target GR_Gizmo_PoisonCloud = new Command_Target(); GR_Gizmo_PoisonCloud.defaultLabel = "GR_CreatePoisonousCloud".Translate(); GR_Gizmo_PoisonCloud.defaultDesc = "GR_CreatePoisonousCloudDesc".Translate(); GR_Gizmo_PoisonCloud.targetingParams = TargetingParameters.ForAttackAny(); GR_Gizmo_PoisonCloud.icon = ContentFinder <Texture2D> .Get("ui/commands/GR_PoisonousCloud", true); GR_Gizmo_PoisonCloud.action = delegate(Thing target) { if (!pawn.health.hediffSet.HasHediff(HediffDef.Named("GR_CausedPoisonCloud"))) { Pawn pawn2 = target as Pawn; if (pawn2 != null) { if (pawn.Position.InHorDistOf(pawn2.Position, 10)) { List <IntVec3> list = GenAdj.AdjacentCells8WayRandomized(); for (int i = 0; i < 8; i++) { IntVec3 c2 = pawn2.Position + list[i]; if (c2.InBounds(pawn2.Map)) { Thing thing = ThingMaker.MakeThing(ThingDef.Named("GR_Poison_Cloud"), null); GenSpawn.Spawn(thing, c2, pawn2.Map); } } pawn.health.AddHediff(HediffDef.Named("GR_CausedPoisonCloud")); } else { Messages.Message("GR_PoisonCloudRange".Translate(), pawn, MessageTypeDefOf.NeutralEvent); } } } else { Messages.Message("GR_AbilityRecharging".Translate(), pawn, MessageTypeDefOf.NeutralEvent); } }; gizmos.Insert(1, GR_Gizmo_PoisonCloud); } /*This gizmo puts the creature into burrowing mode */ if ((pawn.drafter != null) && flagCanBurrow && flagIsCreatureMine && flagIsMindControlBuildingPresent || pawn.def.defName == "GR_ArchotechCentipede") { Command_Action GR_Gizmo_Burrowing = new Command_Action(); GR_Gizmo_Burrowing.action = delegate { if (!pawn.health.hediffSet.HasHediff(HediffDef.Named("GR_Burrowing"))) { pawn.health.AddHediff(HediffDef.Named("GR_Burrowing")); } else { Messages.Message("GR_AbilityRecharging".Translate(), pawn, MessageTypeDefOf.NeutralEvent); } }; GR_Gizmo_Burrowing.defaultLabel = "GR_StartBurrowing".Translate(); GR_Gizmo_Burrowing.defaultDesc = "GR_StartBurrowingDesc".Translate(); GR_Gizmo_Burrowing.icon = ContentFinder <Texture2D> .Get("Things/Pawn/Animal/Special/GR_Special_Burrowing", true); gizmos.Insert(1, GR_Gizmo_Burrowing); } /*This gizmo makes the animal more resistant for a while */ if ((pawn.drafter != null) && flagCanStamina && flagIsCreatureMine && flagIsMindControlBuildingPresent) { Command_Action GR_Gizmo_Stamina = new Command_Action(); GR_Gizmo_Stamina.action = delegate { if (!pawn.health.hediffSet.HasHediff(HediffDef.Named("GR_Stamina"))) { pawn.health.AddHediff(HediffDef.Named("GR_Stamina")); } else { Messages.Message("GR_AbilityRecharging".Translate(), pawn, MessageTypeDefOf.NeutralEvent); } }; GR_Gizmo_Stamina.defaultLabel = "GR_StartStamina".Translate(); GR_Gizmo_Stamina.defaultDesc = "GR_StartStaminaDesc".Translate(); GR_Gizmo_Stamina.icon = ContentFinder <Texture2D> .Get("ui/commands/GR_Stamina", true); gizmos.Insert(1, GR_Gizmo_Stamina); } /*This gizmo makes the animal more aware (sight and consciousness) for a while */ if ((pawn.drafter != null) && flagCanKeenSenses && flagIsCreatureMine && flagIsMindControlBuildingPresent) { Command_Action GR_Gizmo_KeenSenses = new Command_Action(); GR_Gizmo_KeenSenses.action = delegate { if (!pawn.health.hediffSet.HasHediff(HediffDef.Named("GR_KeenSenses"))) { pawn.health.AddHediff(HediffDef.Named("GR_KeenSenses")); } else { Messages.Message("GR_AbilityRecharging".Translate(), pawn, MessageTypeDefOf.NeutralEvent); } }; GR_Gizmo_KeenSenses.defaultLabel = "GR_StartKeenSenses".Translate(); GR_Gizmo_KeenSenses.defaultDesc = "GR_StartKeenSensesDesc".Translate(); GR_Gizmo_KeenSenses.icon = ContentFinder <Texture2D> .Get("ui/commands/GR_KeenSenses", true); gizmos.Insert(1, GR_Gizmo_KeenSenses); } /*This gizmo activates cat reflexes, improving melee combat */ if ((pawn.drafter != null) && flagCanCatReflexes && flagIsCreatureMine && flagIsMindControlBuildingPresent || pawn.def.defName == "GR_ArchotechCentipede") { Command_Action GR_Gizmo_CatReflexes = new Command_Action(); GR_Gizmo_CatReflexes.action = delegate { if (!pawn.health.hediffSet.HasHediff(HediffDef.Named("GR_CatReflexes"))) { pawn.health.AddHediff(HediffDef.Named("GR_CatReflexes")); } else { Messages.Message("GR_AbilityRecharging".Translate(), pawn, MessageTypeDefOf.NeutralEvent); } }; GR_Gizmo_CatReflexes.defaultLabel = "GR_StartCatReflexes".Translate(); GR_Gizmo_CatReflexes.defaultDesc = "GR_StartCatReflexesDesc".Translate(); GR_Gizmo_CatReflexes.icon = ContentFinder <Texture2D> .Get("ui/commands/GR_CatReflexes", true); gizmos.Insert(1, GR_Gizmo_CatReflexes); } /*This gizmo makes the animal cast a horror ability */ if ((pawn.drafter != null) && flagCanHorrorize && flagIsCreatureMine && flagIsMindControlBuildingPresent) { Command_Target GR_Gizmo_Horror = new Command_Target(); GR_Gizmo_Horror.defaultLabel = "GR_StartInvokingInsanity".Translate(); GR_Gizmo_Horror.defaultDesc = "GR_StartInvokingInsanityDesc".Translate(); GR_Gizmo_Horror.targetingParams = TargetingParameters.ForAttackAny(); GR_Gizmo_Horror.icon = ContentFinder <Texture2D> .Get("Item/Weapon/MiGoCasterWeapon/MiGoCasterWeaponA", true); GR_Gizmo_Horror.action = delegate(Thing target) { if (!pawn.health.hediffSet.HasHediff(HediffDef.Named("GR_CausedHorror"))) { Pawn pawn2 = target as Pawn; if (pawn2 != null) { if (pawn.Position.InHorDistOf(pawn2.Position, 10)) { List <IntVec3> list = GenAdj.AdjacentCells8WayRandomized(); for (int i = 0; i < 8; i++) { IntVec3 c2 = pawn2.Position + list[i]; if (c2.InBounds(pawn2.Map)) { Thing thing = ThingMaker.MakeThing(ThingDef.Named("GR_Insanity_Cloud"), null); GenSpawn.Spawn(thing, c2, pawn2.Map); } } pawn.health.AddHediff(HediffDef.Named("GR_CausedHorror")); } else { Messages.Message("GR_InvokingInsanityRange".Translate(), pawn, MessageTypeDefOf.NeutralEvent); } } } else { Messages.Message("GR_AbilityRecharging".Translate(), pawn, MessageTypeDefOf.NeutralEvent); } }; gizmos.Insert(1, GR_Gizmo_Horror); } /*This gizmo makes the animal release a burning explosion */ if ((pawn.drafter != null) && flagCanMechaBlast && flagIsCreatureMine && flagIsMindControlBuildingPresent || pawn.def.defName == "GR_ArchotechCentipede") { Command_Action GR_Gizmo_MechaBlast = new Command_Action(); GR_Gizmo_MechaBlast.action = delegate { if (!pawn.health.hediffSet.HasHediff(HediffDef.Named("GR_VentedExhaust"))) { foreach (IntVec3 c in GenAdj.CellsAdjacent8Way(pawn)) { GenExplosion.DoExplosion(c, pawn.Map, (float)0.25, DamageDefOf.Flame, pawn, 25, 5, null, null, null, null, ThingDef.Named("Filth_Ash"), .7f, 1, false, null, 0f, 1); } pawn.health.AddHediff(HediffDef.Named("GR_VentedExhaust")); } else { Messages.Message("GR_AbilityRecharging".Translate(), pawn, MessageTypeDefOf.NeutralEvent); } }; GR_Gizmo_MechaBlast.defaultLabel = "GR_StartMechaBlast".Translate(); GR_Gizmo_MechaBlast.defaultDesc = "GR_StartMechaBlastDesc".Translate(); GR_Gizmo_MechaBlast.icon = ContentFinder <Texture2D> .Get("ui/commands/GR_MechaBlast", true); gizmos.Insert(1, GR_Gizmo_MechaBlast); } /*This gizmo activates the orbital beam */ if ((pawn.drafter != null) && flagIsCreatureMine && pawn.def.defName == "GR_ArchotechCentipede") { Command_Target GR_Gizmo_Orbital = new Command_Target(); GR_Gizmo_Orbital.defaultLabel = "GR_Orbital".Translate(); GR_Gizmo_Orbital.defaultDesc = "GR_OrbitalDesc".Translate(); GR_Gizmo_Orbital.targetingParams = TargetingParameters.ForAttackAny(); GR_Gizmo_Orbital.icon = ContentFinder <Texture2D> .Get("ui/commands/GR_Orbital", true); GR_Gizmo_Orbital.action = delegate(Thing target) { if (!pawn.health.hediffSet.HasHediff(HediffDef.Named("GR_CausedPowerBeam"))) { if (target.Map == pawn.Map) { PowerBeam powerBeam = (PowerBeam)GenSpawn.Spawn(ThingDefOf.PowerBeam, target.Position, pawn.Map, WipeMode.Vanish); powerBeam.duration = 600; powerBeam.instigator = pawn; powerBeam.weaponDef = null; powerBeam.StartStrike(); pawn.health.AddHediff(HediffDef.Named("GR_CausedPowerBeam")); } } else { Messages.Message("GR_AbilityRecharging".Translate(), pawn, MessageTypeDefOf.NeutralEvent); } }; gizmos.Insert(1, GR_Gizmo_Orbital); } __result = gizmos; }
public override void PostMapGenerate(Map map) { IncidentParms incidentParms = StorytellerUtility.DefaultParmsNow(incCat: IncidentCategoryDefOf.Misc, target: map); incidentParms.forced = true; //this part is forced to bypass CanFireNowSub, to solve issue with scenario-added incident. QueuedIncident queuedIncident = new QueuedIncident(firingInc: new FiringIncident(def: DefDatabase <IncidentDef> .GetNamed(defName: "MFI_HerdMigration_Ambush"), source: null, parms: incidentParms), fireTick: Find.TickManager.TicksGame + Rand.RangeInclusive(min: GenDate.TicksPerDay / 2, max: GenDate.TicksPerDay)); Find.Storyteller.incidentQueue.Add(qi: queuedIncident); }
public static DamageDef Named(string defName) { return(DefDatabase <DamageDef> .GetNamed(defName, true)); }
private JoyGiverDef GetJoyGiverDef() { return(DefDatabase <JoyGiverDef> .GetNamed("PracticeShooting")); }
private JobDef GetJobDef() { return(DefDatabase <JobDef> .GetNamed("UseShootingRange_NonJoy")); }
public static ConceptDef Named(string defName) { return(DefDatabase <ConceptDef> .GetNamed(defName, true)); }
static Vaccine() { MethodInfo methodVanilla; MethodInfo methodReplace; try { methodVanilla = typeof(Designator_Build).GetMethod( "CanDesignateCell", BindingFlags.Instance | BindingFlags.Public); methodReplace = typeof(Designator_Build_JT).GetMethod( "CanDesignateCell", BindingFlags.Instance | BindingFlags.Public); giveAutism(methodVanilla, methodReplace); Log.Message( "JTReplaceWalls probably sucessfully replaced Designator_Build.CanDesignateCell(). Code stolen from CCL/RawCode."); } catch (Exception e) { Log.Warning("JTReplaceWalls couldn't replace Designator_Build.CanDesignateCell(). The error is the following: " + e.Message); } try { methodVanilla = typeof(GenConstruct).GetMethod("PlaceBlueprintForBuild", BindingFlags.Static | BindingFlags.Public); methodReplace = typeof(GenConstruct_JT).GetMethod("PlaceBlueprintForBuild", BindingFlags.Static | BindingFlags.Public); giveAutism(methodVanilla, methodReplace); Log.Message("JTReplaceWalls probably sucessfully replaced GenConstruct.PlaceBlueprintForBuild(). Code stolen from CCL/RawCode."); } catch (Exception e) { Log.Warning("JTReplaceWalls couldn't replace GenConstruct.PlaceBlueprintForBuild(). The error is the following: " + e.Message); } try { methodVanilla = typeof(GenConstruct).GetMethod("BlocksConstruction", BindingFlags.Static | BindingFlags.Public); methodReplace = typeof(GenConstruct_JT).GetMethod("BlocksConstruction", BindingFlags.Static | BindingFlags.Public); giveAutism(methodVanilla, methodReplace); Log.Message("JTReplaceWalls probably sucessfully replaced GenConstruct.BlocksConstruction(). Code stolen from CCL/RawCode."); } catch (Exception e) { Log.Warning("JTReplaceWalls couldn't replace GenConstruct.BlocksFramePlacement(). The error is the following: " + e.Message); } try { methodVanilla = typeof(GenSpawn).GetMethod("SpawningWipes", BindingFlags.Static | BindingFlags.Public); methodReplace = typeof(GenSpawn_JT).GetMethod("SpawningWipes", BindingFlags.Static | BindingFlags.Public); giveAutism(methodVanilla, methodReplace); Log.Message("JTReplaceWalls probably sucessfully replaced GenSpawn.SpawningWipes(). Code stolen from CCL/RawCode."); } catch (Exception e) { Log.Warning("JTReplaceWalls couldn't replace GenConstruct.BlocksFramePlacement(). The error is the following: " + e.Message); } //The following is necessary so walls underneath will be removed when new wall is built, not done in XML for some compatibility //ThingDefOf.Wall.building.canPlaceOverWall = true; //Old version DefDatabase <ThingDef> .GetNamed("Wall").building.canPlaceOverWall = true; //Allow other mods to make their walls/doors/conduits replaceable. //To do this, create a new static method that returns IEnumerable<string> with the method name as JTReplaceWalls_walls, JTReplaceWalls_doors or JTReplaceWalls_conduits ///E.G. this method will let the defs NewDoor and NewSuperDoor be replaced by other doors ///namespace mymod { /// class myclass { /// public static IEnumerable<string> JTReplaceWalls_doors() { /// yield return "NewDoor"; /// yield return "NewSuperDoor"; /// } /// } ///} foreach (ModContentPack mod in LoadedModManager.RunningMods) { foreach (Assembly ass in mod.assemblies.loadedAssemblies) { foreach (Type type in ass.GetTypes()) { foreach (MethodInfo method in type.GetMethods()) { switch (method.Name) { case "JTReplaceWalls_walls": addFromMethod(GenConstruct_JT.walls, method); break; case "JTReplaceWalls_doors": addFromMethod(GenConstruct_JT.doors, method); break; case "JTReplaceWalls_conduits": addFromMethod(GenConstruct_JT.conduits, method, false); break; } } } } } }
public override void RunCommand(TwitchIRCMessage message) { Command allCommandsCommand = DefDatabase <Command> .GetNamed("AvailableCommands"); Toolkit.client.SendMessage($"@{message.User} the toolkit is a mod where you earn coins while you watch. Check out the bit.ly/toolkit-guide or use !" + allCommandsCommand.command + " for a short list. " + ToolkitSettings.Channel.CapitalizeFirst() + " has a list of items/events to purchase at " + ToolkitSettings.CustomPricingSheetLink, CommandsHandler.SendToChatroom(message)); }
public static void Listener(ref Pawn __result) { if (__result == null) { return; } if (Faction.OfPlayer.def.basicMemberKind.defName != "AndroidT2ColonistGeneral") { return; } else { Random rnd = new Random(); PawnGenerationRequest request; string pkd = ""; if (!Utils.TXSERIE_LOADED) { switch (rnd.Next(1, 3)) { case 1: pkd = "AndroidT2ColonistGeneral"; break; case 2: pkd = "AndroidT1ColonistGeneral"; break; default: pkd = Faction.OfPlayer.def.basicMemberKind.defName; break; } } else { switch (rnd.Next(1, 5)) { case 1: pkd = "AndroidT2ColonistGeneral"; break; case 2: pkd = "AndroidT1ColonistGeneral"; break; case 3: pkd = "ATPP_Android2ITXKind"; break; case 4: pkd = "ATPP_Android2TXKind"; break; default: pkd = Faction.OfPlayer.def.basicMemberKind.defName; break; } } request = new PawnGenerationRequest(DefDatabase <PawnKindDef> .GetNamed(pkd, false), Faction.OfPlayer, PawnGenerationContext.PlayerStarter, -1, true, false, false, false, true, TutorSystem.TutorialMode, 20f, false, true, true, false, false, false, false); __result = null; try { __result = PawnGenerator.GeneratePawn(request); } catch (Exception e) { Log.Error("[ATPP] StartingPawnUtility.NewGeneratedStartingPawn " + e.Message + " " + e.StackTrace, false); __result = PawnGenerator.GeneratePawn(request); } __result.relations.everSeenByPlayer = true; PawnComponentsUtility.AddComponentsForSpawn(__result); } }
public static void CreateStuff(this ResearchProjectDef tech, ThingFilter filter, UnlockManager unlocked) { string name = "Tech_" + tech.defName; ThingCategoryDef tCat = DefDatabase <ThingCategoryDef> .GetNamed(tech.techLevel.ToString()); string label = "KnowledgeLabel".Translate(tech.label); ThingDef techStuff = new ThingDef { thingClass = typeof(ThingWithComps), defName = name, label = label, description = tech.description, category = ThingCategory.Item, thingCategories = new List <ThingCategoryDef>() { tCat }, techLevel = tech.techLevel, menuHidden = true, stuffProps = new StuffProperties() { categories = new List <StuffCategoryDef>() { TechDefOf.Technic }, color = ResearchTree_Assets.ColorCompleted[tech.techLevel], stuffAdjective = tech.LabelCap, statOffsets = new List <StatModifier>() { new StatModifier { stat = StatDefOf.MarketValue, value = MarketValueOffset } }, statFactors = new List <StatModifier>() { new StatModifier { stat = StatDefOf.WorkToMake, value = StuffCostFactor(tech) }, new StatModifier { stat = StatDefOf.MarketValue, value = StuffMarketValueFactor(tech) } } } }; techStuff.ResolveReferences(); MethodInfo GiveShortHashInfo = AccessTools.Method(typeof(ShortHashGiver), "GiveShortHash"); GiveShortHashInfo.Invoke(tech, new object[] { techStuff, typeof(ThingDef) }); DefDatabase <ThingDef> .Add(techStuff); filter.SetAllow(techStuff, true); unlocked.stuffByTech.Add(tech, techStuff); unlocked.techByStuff.Add(techStuff, tech); }
public static bool isPsyker(this Pawn pawn, out int Level, out float Mult) { bool result = false; Mult = 0f; Level = 0; if (pawn.RaceProps.Humanlike) { if (pawn.health.hediffSet.hediffs.Any(x => x.GetType() == typeof(Hediff_ImplantWithLevel))) { Level = (pawn.health.hediffSet.hediffs.First(x => x.GetType() == typeof(Hediff_ImplantWithLevel)) as Hediff_ImplantWithLevel).level; result = true; } else if (pawn.story.traits.HasTrait(TraitDefOf.PsychicSensitivity)) { result = pawn.story.traits.DegreeOfTrait(TraitDefOf.PsychicSensitivity) > 0; Level = pawn.story.traits.DegreeOfTrait(TraitDefOf.PsychicSensitivity); } else { TraitDef Corruptionpsyker = DefDatabase <TraitDef> .GetNamedSilentFail("Psyker"); if (Corruptionpsyker != null) { result = true; pawn.story.traits.HasTrait(Corruptionpsyker); Level = pawn.story.traits.DegreeOfTrait(Corruptionpsyker); } } Mult = pawn.GetStatValue(StatDefOf.PsychicSensitivity) * (pawn.needs.mood.CurInstantLevelPercentage - pawn.health.hediffSet.PainTotal); } else { ToolUserPskyerDefExtension extension = null; if (pawn.def.HasModExtension <ToolUserPskyerDefExtension>()) { extension = pawn.def.GetModExtension <ToolUserPskyerDefExtension>(); } else if (pawn.kindDef.HasModExtension <ToolUserPskyerDefExtension>()) { extension = pawn.kindDef.GetModExtension <ToolUserPskyerDefExtension>(); } if (extension != null) { result = true; Level = extension.Level; } if (pawn.needs != null && pawn.needs.mood != null) { Mult = pawn.GetStatValue(StatDefOf.PsychicSensitivity) * (pawn.needs.mood.CurInstantLevelPercentage - pawn.health.hediffSet.PainTotal); } else { Mult = pawn.GetStatValue(StatDefOf.PsychicSensitivity) * (1 - pawn.health.hediffSet.PainTotal); } } return(result); }
public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false) { Building dummy = t as Building; return(new Job(DefDatabase <JobDef> .GetNamed("JobDriver_Training_Dummy", true), (LocalTargetInfo)(dummy), (LocalTargetInfo)dummy.InteractionCell)); }
private static bool TryGetFromDB <D>(string s, out object o) where D : Def, new() { o = DefDatabase <D> .GetNamed(s, false); return(o != null); }
public override IEnumerable <Thing> PotentialWorkThingsGlobal(Pawn pawn) { IEnumerable <Thing> L; L = (IEnumerable <Thing>)pawn.Map.listerBuildings.AllBuildingsColonistOfDef(DefDatabase <ThingDef> .GetNamed("ShootingRange", true)).ToArray(); if (L.Any()) { foreach (Thing X in L) { Building_Trainable Y = (Building_Trainable)X; if (Y.MyAllowList.Contains(pawn)) { return(L); } } } L = (IEnumerable <Thing>)pawn.Map.listerBuildings.AllBuildingsColonistOfDef(DefDatabase <ThingDef> .GetNamed("CPRdummy", true)).ToArray(); if (L.Any()) { foreach (Thing X in L) { Building_Trainable Y = (Building_Trainable)X; if (Y.MyAllowList.Contains(pawn)) { return(L); } } } L = (IEnumerable <Thing>)pawn.Map.listerBuildings.AllBuildingsColonistOfDef(DefDatabase <ThingDef> .GetNamed("Holodeck", true)).ToArray(); if (L.Any()) { foreach (Thing X in L) { Building_Trainable Y = (Building_Trainable)X; if (Y.MyAllowList.Contains(pawn)) { return(L); } } } L = (IEnumerable <Thing>)pawn.Map.listerBuildings.AllBuildingsColonistOfDef(DefDatabase <ThingDef> .GetNamed("PunchingBag", true)).ToArray(); if (L.Any()) { foreach (Thing X in L) { Building_Trainable Y = (Building_Trainable)X; if (Y.MyAllowList.Contains(pawn)) { return(L); } } } return(L); }
//UNDONE This doesn't define weapons as yet and the code might not handle that well. Want to get various things stable first RE inventory. // But we can define generics for short range, assault, pistol, melee. /* (ProfoundDarkness) Some issues with weapons is that they have durability, quality, and often made of stuffs. * Also could use a super-generic which fetches x clips for each weapon on the pawn (working on that for something else). * I'm thinking we could add another button (more clutter) to each loadout slot which is only displayed if the item * has key properties. Clicking that button would show a new window which lets the user configure parameters like * a range slider for durability, range slider for quality, and a checklist for stuffs (assuming is made of stuffs). */ /// <summary> /// This constructor gets run on startup of RimWorld and generates the various LoadoutGenericDef instance objects akin to having been loaded from xml. /// </summary> static LoadoutGenericDef() { // Used in a handful of places where all loaded ThingDefs are useful. IEnumerable <ThingDef> everything = DefDatabase <ThingDef> .AllDefs; // need to generate a list as that's how new defs are taken by DefDatabase. List <LoadoutGenericDef> defs = new List <LoadoutGenericDef>(); LoadoutGenericDef generic = new LoadoutGenericDef(); generic.defName = "GenericMeal"; generic.description = "Generic Loadout for perishable meals. Intended for compatibility with pawns automatically picking up a meal for themself."; generic.label = "CE_Generic_Meal".Translate(); generic.defaultCountType = LoadoutCountType.pickupDrop; // Fits with disabling of RimWorld Pawn behavior of fetching meals themselves. generic._lambda = td => td.IsNutritionGivingIngestible && td.ingestible.preferability >= FoodPreferability.MealAwful && td.GetCompProperties <CompProperties_Rottable>()?.daysToRotStart <= 5 && !td.IsDrug; generic.isBasic = true; defs.Add(generic); //Log.Message(string.Concat("CombatExtended :: LoadoutGenericDef :: ", generic.LabelCap, " list: ", string.Join(", ", DefDatabase<ThingDef>.AllDefs.Where(t => generic.lambda(t)).Select(t => t.label).ToArray()))); float targetNutrition = 0.85f; generic = new LoadoutGenericDef(); generic.defName = "GenericRawFood"; generic.description = "Generic Loadout for Raw Food. Intended for compatibility with pawns automatically picking up raw food to train animals."; generic.label = "CE_Generic_RawFood".Translate(); // Exclude drugs and corpses. Also exclude any food worse than RawBad as in testing the pawns would not even pick it up for training. generic._lambda = td => td.IsNutritionGivingIngestible && td.ingestible.preferability <= FoodPreferability.RawTasty && td.ingestible.HumanEdible && td.plant == null && !td.IsDrug && !td.IsCorpse; generic.defaultCount = Convert.ToInt32(Math.Floor(targetNutrition / everything.Where(td => generic.lambda(td)).Average(td => td.ingestible.CachedNutrition))); //generic.defaultCount = 1; generic.isBasic = false; // doesn't need to be in loadouts by default as animal interaction talks to HoldTracker now. //TODO: Test pawns fetching raw food if no meal is available, if so then add a patch to have that talk to HoldTracker too. defs.Add(generic); //Log.Message(string.Concat("CombatExtended :: LoadoutGenericDef :: ", generic.LabelCap, " list: ", string.Join(", ", DefDatabase<ThingDef>.AllDefs.Where(t => generic.lambda(t)).Select(t => t.label + " B(" + t.GetStatValueAbstract(CE_StatDefOf.Bulk) + ") M(" + t.GetStatValueAbstract(StatDefOf.Mass) + ")").ToArray()))); generic = new LoadoutGenericDef(); generic.defName = "GenericDrugs"; generic.defaultCount = 3; generic.description = "Generic Loadout for Drugs. Intended for compatibility with pawns automatically picking up drugs in compliance with drug policies."; generic.label = "CE_Generic_Drugs".Translate(); generic.thingRequestGroup = ThingRequestGroup.Drug; generic.isBasic = true; defs.Add(generic); //Log.Message(string.Concat("CombatExtended :: LoadoutGenericDef :: ", generic.LabelCap, " list: ", string.Join(", ", DefDatabase<ThingDef>.AllDefs.Where(t => generic.lambda(t)).Select(t => t.label).ToArray()))); generic = new LoadoutGenericDef(); generic.defName = "GenericMedicine"; generic.defaultCount = 5; generic.defaultCountType = LoadoutCountType.pickupDrop; generic.description = "Generic Loadout for Medicine. Intended for pawns which will handle triage activities."; generic.label = "CE_Generic_Medicine".Translate(); generic.thingRequestGroup = ThingRequestGroup.Medicine; // now for the guns and ammo... // Get a list of guns that are player acquireable (not menuHidden but could also go with not dropOnDeath) which have expected comps/compProperties/verbs. List <ThingDef> guns = everything.Where(td => !td.menuHidden && td.HasComp(typeof(CompAmmoUser)) && td.GetCompProperties <CompProperties_AmmoUser>() != null && td.Verbs.FirstOrDefault(v => v is VerbPropertiesCE) != null).ToList(); string ammoLabel = "CE_Generic_Ammo".Translate(); const string ammoDescription = "Generic Loadout ammo for {0}. Intended for generic collection of ammo for given gun."; foreach (ThingDef gun in guns) { // make sure the gun has ammo defined... if (gun.GetCompProperties <CompProperties_AmmoUser>().ammoSet.ammoTypes.Count <= 0) { continue; } generic = new LoadoutGenericDef(); generic.defName = "GenericAmmo-" + gun.defName; generic.description = string.Format(ammoDescription, gun.LabelCap); generic.label = string.Format(ammoLabel, gun.LabelCap); generic.defaultCount = gun.GetCompProperties <CompProperties_AmmoUser>().magazineSize; generic.defaultCountType = LoadoutCountType.pickupDrop; // we want ammo to get picked up. //generic._lambda = td => td is AmmoDef && gun.GetCompProperties<CompProperties_AmmoUser>().ammoSet.ammoTypes.Contains(td); generic.thingRequestGroup = ThingRequestGroup.HaulableEver; generic._lambda = td => td is AmmoDef && gun.GetCompProperties <CompProperties_AmmoUser>().ammoSet.ammoTypes.Any(al => al.ammo == td); defs.Add(generic); //Log.Message(string.Concat("CombatExtended :: LoadoutGenericDef :: ", generic.LabelCap, " list: ", string.Join(", ", DefDatabase<ThingDef>.AllDefs.Where(t => generic.lambda(t)).Select(t => t.label).ToArray()))); } // finally we add all the defs generated to the DefDatabase. DefDatabase <LoadoutGenericDef> .Add(defs); }
public static T GetDefById <T>(ushort id) where T : Def => DefDatabase <T> .GetByShortHash(id);
public static WeaponCategoryList Named(string defName) { return(DefDatabase <WeaponCategoryList> .GetNamed(defName)); }
public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target) { if (VoteHandler.voteActive || !Rand.MTBEventOccurs(ToolkitSettings.HodlBotMTBDays, 60000f, 1000f)) { yield break; } if (Rand.Range(0, 1) == 1) { voteType = Vote_VotingIncident.VoteLabelType.Type; } List <VotingIncidentEntry> source = VotingIncidentsByWeight(); List <VotingIncidentEntry> winners = new List <VotingIncidentEntry>(); string str = null; switch (voteType) { case Vote_VotingIncident.VoteLabelType.Category: { EventCategory category = RandomCategory(); source = (from s in source where s.incident.eventCategory == category select s).ToList(); str = "Which " + category.ToString() + " event should happen?"; break; } case Vote_VotingIncident.VoteLabelType.Type: { EventType randType = RandomType(); source = (from s in source where s.incident.eventType == randType select s).ToList(); str = "Which " + randType + " event should happen?"; break; } } int num = 0; while (winners.Count < ToolkitSettings.VoteOptions && num < 12) { VotingIncidentEntry votingIncidentEntry = GenCollection.RandomElementByWeight <VotingIncidentEntry>(from s in source where !winners.Contains(s) select s, (Func <VotingIncidentEntry, float>)((VotingIncidentEntry vi) => vi.weight)); votingIncidentEntry.incident.Helper.target = target; if (votingIncidentEntry.incident.Helper.IsPossible()) { winners.Add(votingIncidentEntry); } num++; } if (winners.Count < 3) { yield break; } Dictionary <int, VotingIncident> dictionary = new Dictionary <int, VotingIncident>(); for (int i = 0; i < winners.Count; i++) { dictionary.Add(i, winners[i].incident); } StorytellerPack named = DefDatabase <StorytellerPack> .GetNamed("HodlBot", true); VoteHandler.QueueVote(new Vote_HodlBot(dictionary, named, str)); }
public static CaravanJobDef Named(string defName) { return(DefDatabase <CaravanJobDef> .GetNamed(defName, true)); }
public static PawnKindDef selectMonster() { return((PawnKindDef)GenCollection.RandomElement <PawnKindDef>((IEnumerable <M0>)DefDatabase <PawnKindDef> .get_AllDefs().Where <PawnKindDef>((Func <PawnKindDef, bool>)(defs => ((string)((Def)defs).defName).Equals("CarrionCrawler") | ((string)((Def)defs).defName).Equals("InfernoBeetle") | ((string)((Def)defs).defName).Equals("LandKraken") | ((string)((Def)defs).defName).Equals("PolarColossus") | ((string)((Def)defs).defName).Equals("SanguineDrake"))))); }
public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false) { return(new Job(DefDatabase <JobDef> .GetNamed("emptySewage"), t)); }
// Token: 0x06000063 RID: 99 RVA: 0x00004318 File Offset: 0x00002518 protected override IEnumerable <Toil> MakeNewToils() { this.FailOnDespawnedOrNull(TargetIndex.A); var toilInv = new Toil(); var toilEquipGoto = new Toil(); var toilEquip = new Toil(); var toilGoto = new Toil(); var toilCast = new Toil(); var toilTouch = new Toil(); var toilBeat = new Toil(); var toilBash = new Toil(); var HasPrimFE = false; var HasPrimFB = false; if (pawn.equipment.Primary != null) { if (pawn.equipment.Primary.def.defName == FEDefName && FWFoamUtility.HasFEFoam(pawn.equipment.Primary)) { HasPrimFE = true; } else if (pawn.equipment.Primary.def.defName == FBDefName) { HasPrimFB = true; } } if (!HasPrimFE) { var fb = HasPrimFB; toilInv.initAction = delegate { var Swap = false; ThingWithComps invGearToEquip2 = null; ThingWithComps primToSwap2 = null; Thing RemoveThing = null; Thing BackupThing2 = null; if (pawn.equipment.Primary != null) { primToSwap2 = pawn.equipment.Primary; } foreach (var invThing2 in pawn.inventory.innerContainer) { if (invThing2.def.defName != FEDefName || !FWFoamUtility.HasFEFoam(invThing2)) { if (invThing2.def.defName == FBDefName) { BackupThing2 = invThing2; } } else { RemoveThing = invThing2; invGearToEquip2 = (ThingWithComps)invThing2; if (primToSwap2 != null) { Swap = true; } break; } } if (invGearToEquip2 == null && !fb && BackupThing2 != null) { RemoveThing = BackupThing2; invGearToEquip2 = (ThingWithComps)BackupThing2; if (primToSwap2 != null) { Swap = true; } } if (invGearToEquip2 == null) { return; } var primDef = ""; if (Swap) { primDef = pawn.equipment.Primary.def.defName; pawn.equipment.Remove(pawn.equipment.Primary); } pawn.inventory.innerContainer.Remove(RemoveThing); pawn.equipment.MakeRoomFor(invGearToEquip2); pawn.equipment.AddEquipment(invGearToEquip2); if (Swap) { pawn.inventory.innerContainer.TryAdd(primToSwap2); } if (!Swap) { return; } var returnType = "SI"; if (pawn.equipment.Primary.def.defName != FEDefName && pawn.equipment.Primary.def.defName != FBDefName) { return; } var primary = pawn.equipment.Primary; ((FireWardenData)primary).FWSwapType = returnType; ((FireWardenData)primary).FWPawnID = pawn.thingIDNumber; ((FireWardenData)primary).FWPrimDef = primDef; if (!DebugFWData) { return; } var Test = pawn.equipment.Primary; var debugTest = pawn.Label + " : "; debugTest = debugTest + Test.Label + " : "; debugTest = debugTest + pawn.equipment.Primary.GetType() + " : "; if (((FireWardenData)Test).FWSwapType != null) { debugTest = debugTest + ((FireWardenData)Test).FWSwapType + " : "; } else { debugTest += "null : "; } debugTest = debugTest + ((FireWardenData)Test).FWPawnID + " : "; if (((FireWardenData)Test).FWPrimDef != null) { debugTest += ((FireWardenData)Test).FWPrimDef; } else { debugTest += "null"; } Messages.Message(debugTest, pawn, MessageTypeDefOf.NeutralEvent, false); }; toilInv.defaultCompleteMode = ToilCompleteMode.FinishedBusy; yield return(toilInv); } var FWEquipping = Controller.Settings.EquippingDone; var FWSearchRange = (float)Controller.Settings.SearchRange; if (FWSearchRange < 25f) { FWSearchRange = 25f; } if (FWSearchRange > 75f) { FWSearchRange = 75f; } HasPrimFE = false; HasPrimFB = false; if (pawn.equipment.Primary != null) { if (pawn.equipment.Primary.def.defName == FEDefName && FWFoamUtility.HasFEFoam(pawn.equipment.Primary)) { HasPrimFE = true; } else if (pawn.equipment.Primary.def.defName == FBDefName) { HasPrimFB = true; } } if (!HasPrimFE && !HasPrimFB && FWEquipping) { ThingWithComps invGearToEquip = null; ThingWithComps primToSwap = null; Thing BackupThing = null; if (pawn.equipment.Primary != null) { primToSwap = pawn.equipment.Primary; } foreach (var invThing in pawn.inventory.innerContainer) { if (invThing.def.defName == FEDefName && FWFoamUtility.HasFEFoam(invThing)) { invGearToEquip = (ThingWithComps)invThing; if (primToSwap != null) { } break; } if (invThing.def.defName == FBDefName) { BackupThing = invThing; } } if (invGearToEquip == null && BackupThing != null) { invGearToEquip = (ThingWithComps)BackupThing; } if (invGearToEquip == null) { Thing ThingToGrab = null; var skip = Controller.Settings.BrawlerNotOK && pawn.story.traits.HasTrait(TraitDefOf.Brawler); var traverseParams = TraverseParms.For(pawn); bool validatorFE(Thing t) { return(!t.IsForbidden(pawn) && pawn.CanReserve(t) && FWFoamUtility.HasFEFoam(t) && !FWFoamUtility.ReplaceFEFoam(t)); } bool validatorFB(Thing t) { return(!t.IsForbidden(pawn) && pawn.CanReserve(t)); } if (!skip) { var FElist = pawn.Map.listerThings.ThingsOfDef(DefDatabase <ThingDef> .GetNamed(FEDefName)); var FEGrab = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, FElist, PathEndMode.OnCell, traverseParams, FWSearchRange, validatorFE); if (FEGrab != null) { ThingToGrab = FEGrab; } else { var FBlist = pawn.Map.listerThings.ThingsOfDef(DefDatabase <ThingDef> .GetNamed(FBDefName)); var FBGrab = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, FBlist, PathEndMode.OnCell, traverseParams, FWSearchRange, validatorFB); if (FBGrab != null) { ThingToGrab = FBGrab; } } } else { var FBlist2 = pawn.Map.listerThings.ThingsOfDef(DefDatabase <ThingDef> .GetNamed(FBDefName)); var FBGrab2 = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, FBlist2, PathEndMode.OnCell, traverseParams, FWSearchRange, validatorFB); if (FBGrab2 != null) { ThingToGrab = FBGrab2; } } if (ThingToGrab != null) { toilEquipGoto.initAction = delegate { if (Map.reservationManager.CanReserve(pawn, ThingToGrab)) { pawn.Reserve(ThingToGrab, job); } pawn.pather.StartPath(ThingToGrab, PathEndMode.OnCell); }; toilEquipGoto.FailOn(ThingToGrab.DestroyedOrNull); toilEquipGoto.AddFailCondition(() => FWHasFE(pawn) && ThingToGrab.def.defName == FEDefName); toilEquipGoto.AddFailCondition(() => FWHasFB(pawn) && ThingToGrab.def.defName == FBDefName); toilEquipGoto.defaultCompleteMode = ToilCompleteMode.PatherArrival; yield return(toilEquipGoto); toilEquip.initAction = delegate { var primDeEquip = pawn.equipment.Primary; var primDef = "N"; if (primDeEquip != null) { primDef = pawn.equipment.Primary.def.defName; pawn.equipment.Remove(pawn.equipment.Primary); pawn.inventory.innerContainer.TryAdd(primDeEquip); } var FWGrabWithComps = (ThingWithComps)ThingToGrab; ThingWithComps FWGrabbed; if (FWGrabWithComps.def.stackLimit > 1 && FWGrabWithComps.stackCount > 1) { FWGrabbed = (ThingWithComps)FWGrabWithComps.SplitOff(1); } else { FWGrabbed = FWGrabWithComps; FWGrabbed.DeSpawn(); } pawn.equipment.MakeRoomFor(FWGrabbed); pawn.equipment.AddEquipment(FWGrabbed); var returnType = "EN"; if (pawn.equipment.Primary.def.defName != FEDefName && pawn.equipment.Primary.def.defName != FBDefName) { return; } var primary = pawn.equipment.Primary; ((FireWardenData)primary).FWSwapType = returnType; ((FireWardenData)primary).FWPawnID = pawn.thingIDNumber; ((FireWardenData)primary).FWPrimDef = primDef; if (!DebugFWData) { return; } var Test = pawn.equipment.Primary; var debugTest = pawn.Label + " : "; debugTest = debugTest + Test.Label + " : "; debugTest = debugTest + pawn.equipment.Primary.GetType() + " : "; if ((Test as FireWardenData)?.FWSwapType != null) { debugTest = debugTest + ((FireWardenData)Test).FWSwapType + " : "; } else { debugTest += "null : "; } debugTest = debugTest + ((FireWardenData)Test).FWPawnID + " : "; if (((FireWardenData)Test).FWPrimDef != null) { debugTest += ((FireWardenData)Test).FWPrimDef; } else { debugTest += "null"; } Messages.Message(debugTest, pawn, MessageTypeDefOf.NeutralEvent, false); }; toilEquip.AddFailCondition(() => FWHasFE(pawn) && ThingToGrab.def.defName == FEDefName); toilEquip.AddFailCondition(() => FWHasFB(pawn) && ThingToGrab.def.defName == FBDefName); toilEquip.defaultCompleteMode = ToilCompleteMode.FinishedBusy; yield return(toilEquip); } } } var HasPrimFEEq = pawn.equipment.Primary != null && pawn.equipment.Primary.def.defName == FEDefName && FWFoamUtility.HasFEFoam(pawn.equipment.Primary); if (HasPrimFEEq) { var FEVerbToUse = pawn.TryGetAttackVerb(TargetFire); var RangeFireExt = 10f; if (FEVerbToUse != null) { pawn.jobs.curJob.verbToUse = FEVerbToUse; RangeFireExt = pawn.jobs.curJob.verbToUse.verbProps.range; RangeFireExt *= (float)(Controller.Settings.HowClose / 100.0); if (RangeFireExt < 3f) { RangeFireExt = 3f; } if (RangeFireExt > pawn.jobs.curJob.verbToUse.verbProps.range) { RangeFireExt = pawn.jobs.curJob.verbToUse.verbProps.range; } } toilGoto.initAction = delegate { if (Map.reservationManager.CanReserve(pawn, TargetFire)) { pawn.Reserve(TargetFire, job); } if (!CastPositionFinder.TryFindCastPosition(new CastPositionRequest { caster = pawn, target = TargetFire, verb = pawn.jobs.curJob.verbToUse, maxRangeFromTarget = RangeFireExt, wantCoverFromTarget = false }, out var dest)) { toilGoto.actor.jobs.EndCurrentJob(JobCondition.Incompletable); return; } toilGoto.actor.pather.StartPath(dest, PathEndMode.OnCell); pawn.Map.pawnDestinationReservationManager.Reserve(pawn, pawn.jobs.curJob, dest); }; toilGoto.tickAction = delegate { if (Controller.Settings.TooBrave) { return; } if (pawn.pather.Moving && pawn.pather.nextCell != TargetFire.Position) { StartTacklingFireIfAnyAt(pawn.pather.nextCell, toilCast); } if (pawn.Position != TargetFire.Position) { StartTacklingFireIfAnyAt(pawn.Position, toilCast); } }; toilGoto.FailOnDespawnedOrNull(TargetIndex.A); toilGoto.defaultCompleteMode = ToilCompleteMode.PatherArrival; toilGoto.atomicWithPrevious = true; yield return(toilGoto); toilCast.initAction = delegate { pawn.jobs.curJob.verbToUse.TryStartCastOn(TargetFire); if (!TargetFire.Destroyed) { return; } pawn.records.Increment(RecordDefOf.FiresExtinguished); pawn.jobs.EndCurrentJob(JobCondition.Succeeded); }; toilCast.FailOnDespawnedOrNull(TargetIndex.A); toilCast.defaultCompleteMode = ToilCompleteMode.FinishedBusy; yield return(toilCast); } else { toilTouch.initAction = delegate { if (Map.reservationManager.CanReserve(pawn, TargetFire)) { pawn.Reserve(TargetFire, job); } pawn.pather.StartPath(TargetFire, PathEndMode.Touch); }; toilTouch.tickAction = delegate { if (Controller.Settings.TooBrave) { return; } if (pawn.pather.Moving && pawn.pather.nextCell != TargetFire.Position) { StartTacklingFireIfAnyAt(pawn.pather.nextCell, toilBeat); } if (pawn.Position != TargetFire.Position) { StartTacklingFireIfAnyAt(pawn.Position, toilBeat); } }; toilTouch.FailOnDespawnedOrNull(TargetIndex.A); toilTouch.defaultCompleteMode = ToilCompleteMode.PatherArrival; toilTouch.atomicWithPrevious = true; yield return(toilTouch); toilBeat.tickAction = delegate { if (!pawn.CanReachImmediate(TargetFire, PathEndMode.Touch)) { JumpToToil(toilTouch); return; } if (pawn.Position != TargetFire.Position && StartTacklingFireIfAnyAt(pawn.Position, toilBeat)) { return; } if (pawn.equipment.Primary != null) { if (pawn.equipment.Primary.def.defName == FBDefName) { JumpToToil(toilBash); } else { pawn.natives.TryBeatFire(TargetFire); } } else { pawn.natives.TryBeatFire(TargetFire); } if (!TargetFire.Destroyed) { return; } pawn.records.Increment(RecordDefOf.FiresExtinguished); pawn.jobs.EndCurrentJob(JobCondition.Succeeded); }; toilBeat.FailOnDespawnedOrNull(TargetIndex.A); toilBeat.defaultCompleteMode = ToilCompleteMode.Never; yield return(toilBeat); if (pawn.equipment.Primary == null || pawn.equipment.Primary.def.defName != FBDefName) { yield break; } toilBash.initAction = delegate { if (TargetFire != null && Map.reservationManager.CanReserve(pawn, TargetFire)) { pawn.Reserve(TargetFire, job); } pawn.pather.StopDead(); }; toilBash.handlingFacing = true; toilBash.tickAction = delegate { pawn.rotationTracker.FaceTarget(pawn.CurJob.GetTarget(TargetIndex.A)); if (TargetFire != null) { pawn.Drawer.Notify_MeleeAttackOn(TargetFire); } }; toilBash.PlaySoundAtStart(SoundDefOf.Interact_BeatFire); toilBash.WithProgressBarToilDelay(TargetIndex.A); toilBash.AddFinishAction(delegate { if (TargetFire != null && !TargetFire.Destroyed) { TargetFire.Destroy(); } }); toilBash.FailOnDespawnedOrNull(TargetIndex.A); toilBash.defaultCompleteMode = ToilCompleteMode.Delay; var ticks = 50; var WorkSpeed = pawn.GetStatValue(StatDefOf.WorkSpeedGlobal); if (WorkSpeed <= 0f) { WorkSpeed = 1f; } ticks = (int)(ticks * (1f / WorkSpeed)); if (ticks < 25) { ticks = 25; } if (ticks > 200) { ticks = 200; } toilBash.defaultDuration = ticks; yield return(toilBash); } }
// Token: 0x0600002A RID: 42 RVA: 0x00002E28 File Offset: 0x00001028 internal bool FlightCellCheck(Pawn pilot, IntVec3 tCell, int fuel, float fRate, float minJump, float maxJump, out string cantReason) { cantReason = ""; if (!tCell.InBounds(pilot.Map)) { cantReason = "JetPack.JumpReasonInvalid".Translate(); return(false); } if (JPOnCooldown) { cantReason = "JetPack.JumpReasonOnCooldown".Translate(); return(false); } if (!pilot.CanReserve(tCell)) { cantReason = "JetPack.JumpReasonReserved".Translate(); return(false); } if (tCell.Roofed(pilot.Map)) { if (!Settings.RoofPunch) { cantReason = "JetPack.JumpReasonRoofed".Translate(); return(false); } var chkSKF = DefDatabase <ThingDef> .GetNamed(JPSkyFallType, false); if (chkSKF == null || !chkSKF.skyfaller.hitRoof) { cantReason = "JetPack.JumpReasonSFNotRPunch".Translate( chkSKF?.label.CapitalizeFirst()); return(false); } } if (!tCell.Walkable(pilot.Map)) { cantReason = "JetPack.JumpReasonNotWalk".Translate(); return(false); } if (tCell.GetDangerFor(pilot, pilot.Map) == Danger.Deadly) { cantReason = "JetPack.JumpReasonDeadly".Translate(); return(false); } var distance = pilot.Position.DistanceTo(tCell); if (distance < minJump) { cantReason = "JetPack.JumpReasonMinRange".Translate(((int)minJump).ToString()); return(false); } if (distance > maxJump) { cantReason = "JetPack.JumpReasonMaxRange".Translate(((int)maxJump).ToString()); return(false); } if (fRate <= 0f) { cantReason = "JetPack.JumpFuelRateInvalid".Translate(fRate.ToString()); return(false); } float distCanJump; if (Settings.UseCarry) { distCanJump = fuel / fRate * JPWeightUtility.JPCarryFactor(pilot, def, JPFuelItem); } else { distCanJump = fuel / fRate; } if (distCanJump > maxJump) { distCanJump = maxJump; } if (!(distCanJump < distance)) { return(true); } cantReason = "JetPack.JumpNotEnoughfuel".Translate(); return(false); }
public static IEnumerable <Filth> SelectAllFilth(Pawn pawn, LocalTargetInfo target, int Limit = int.MaxValue) { Room room = null; if (target.Thing == null) { if (target.Cell == null) { Log.Error("Invalid target: cell or thing it must be"); } else { room = GridsUtility.GetRoom(target.Cell, pawn.Map); } } else { room = target.Thing.GetRoom(); } if (room == null) { return(new List <Filth>()); } PathGrid pathGrid = pawn.Map.pathGrid; if (pathGrid == null) { return(new List <Filth>()); } if (cleanFilth == null) { cleanFilth = DefDatabase <WorkGiverDef> .GetNamed("CleanFilth"); } if (cleanFilth.Worker == null) { return(new List <Filth>()); } IEnumerable <Filth> enumerable = null; if (room.IsHuge || room.CellCount > largeRoomSize) { enumerable = new List <Filth>(); for (int i = 0; i < 200; i++) { IntVec3 intVec = target.Cell + GenRadial.RadialPattern[i]; if (intVec.InBounds(pawn.Map) && intVec.InAllowedArea(pawn) && intVec.GetRoom(pawn.Map) == room) { ((List <Filth>)enumerable).AddRange(intVec.GetThingList(pawn.Map).OfType <Filth>().Where(f => !f.Destroyed && ((WorkGiver_Scanner)cleanFilth.Worker).HasJobOnThing(pawn, f))); } if (enumerable.Count() >= Limit) { break; } } } else { enumerable = room.ContainedAndAdjacentThings.OfType <Filth>().Where(delegate(Filth f) { //Log.Message(f.ToString() + "," + f.Destroyed.ToString()+","+ f.Position.InAllowedArea(pawn).ToString()+","+ ((WorkGiver_Scanner)cleanFilth.Worker).HasJobOnThing(pawn, f).ToString()); if (f == null || f.Destroyed || !f.Position.InAllowedArea(pawn) || !((WorkGiver_Scanner)cleanFilth.Worker).HasJobOnThing(pawn, f)) { return(false); } Room room2 = f.GetRoom(); if (room2 == null || room2 != room && !room2.IsDoorway) { return(false); } return(true); }); } return(enumerable); }