diff --git a/About/PublishedFileId.txt b/About/PublishedFileId.txt new file mode 100644 index 0000000..2c33680 --- /dev/null +++ b/About/PublishedFileId.txt @@ -0,0 +1 @@ +1454024362 \ No newline at end of file diff --git a/Assemblies/MoreFactionInteraction.dll b/Assemblies/MoreFactionInteraction.dll index 08026c3..0c340f6 100644 Binary files a/Assemblies/MoreFactionInteraction.dll and b/Assemblies/MoreFactionInteraction.dll differ diff --git a/Defs/CustomChoiceLetters.xml b/Defs/CustomChoiceLetters.xml index 45515ea..3f81420 100644 --- a/Defs/CustomChoiceLetters.xml +++ b/Defs/CustomChoiceLetters.xml @@ -16,4 +16,9 @@ MoreFactionInteraction.ChoiceLetter_DiplomaticMarriage + + MysticalShaman + MoreFactionInteraction.ChoiceLetter_MysticalShaman + + diff --git a/Defs/Incidents/Incidents_World_Misc.xml b/Defs/Incidents/Incidents_World_Misc.xml index 2d51f22..bf92a2f 100644 --- a/Defs/Incidents/Incidents_World_Misc.xml +++ b/Defs/Incidents/Incidents_World_Misc.xml @@ -24,6 +24,21 @@ + + MFI_MysticalShaman + + Misc + +
  • World
  • +
    + MoreFactionInteraction.IncidentWorker_MysticalShaman + Mystical shaman + MysticalShaman + 0.8 + 1 + 20 +
    + MFI_HuntersLodge diff --git a/Defs/Incidents/Incidents_World_Quests.xml b/Defs/Incidents/Incidents_World_Quests.xml index ed27984..3c92388 100644 --- a/Defs/Incidents/Incidents_World_Quests.xml +++ b/Defs/Incidents/Incidents_World_Quests.xml @@ -53,7 +53,7 @@ You've received a message from [PAWN_nameDef], {0} of {1}. Their faction recently had diplomatic troubles with another faction and call upon you to negotiate between them and {2}. They've picked a neutral nearby location and invite you to come negotiate.\n\nIt could be a great opportunity to improve relations with their faction, but beware - a poor negotiator can cause more harm than good and even anger them.\n\nThe offer will expire after {3} days, after which [PAWN_nameDef] fears the worst. NeutralEvent 0.51 - 12 + 50 \ No newline at end of file diff --git a/Defs/WorldObjects/WorldObjects.xml b/Defs/WorldObjects/WorldObjects.xml index fc057f3..0e7a4ed 100644 --- a/Defs/WorldObjects/WorldObjects.xml +++ b/Defs/WorldObjects/WorldObjects.xml @@ -15,4 +15,18 @@ + + MFI_MysticalShaman + + The tent where a mystical shaman recides. + MoreFactionInteraction.More_Flavour.MysticalShaman + FactionPeaceTalks + true + Expanding/HealerHand + 70 + +
  • + + + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..17a3183 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Mehni + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/Languages/English/Keyed/Incidents.xml b/Languages/English/Keyed/Incidents.xml index 314463f..bc7e69b 100644 --- a/Languages/English/Keyed/Incidents.xml +++ b/Languages/English/Keyed/Incidents.xml @@ -24,9 +24,15 @@ Bumper crop harvested Your grower {0} has gained {1} growing experience. - Word of {1}'s charm has reached {0} and they've asked you for {1}'s hand in marriage. Accepting this marriage proposal will cement relations and strengthen faction ties, but {1} will leave your faction to join theirs. + Word of {1}'s charm has reached {0} and they've asked you for {1}'s hand in marriage. Accepting this marriage proposal will cement relations and strengthen faction ties, but {1} will leave your faction to join {2}. Diplomatic marriage [PAWN_nameDef] sounds overjoyed. [PAWN_pronoun] is convinced they'll live happily ever after with {0}.\n\nRelations with {1} improved. [PAWN_nameDef] tries [PAWN_possessive] best not to sound rejected.\n\nRelations with {1} have deteriorated somewhat. + Someone who claims to be a representative of {0} contacts us with a tall tale of a mystical shaman who has mastered the "healer's hand" to cure any injury or missing part. They'll tell us the location of this mysterious and normally reclusive person for a small fee of {1} silver. + Mystical Shaman + + The Shaman emerges from his polyester teepee just before your caravan announces their presence. He judges you silently with one crossed eye that penetrates through each of your caravan members deepest vitae and one eye that quivers more and more as he assesses your groups health. He orders you to wait a respectable distance while he retreats back in his teepee. Moments later you hear the rustling of fabric and the sound of a muffalo being spurred on.\n\nIt seems the mystical shaman packed up and left. + The Shaman seems to have been expecting you, and with great practice regales you the tale of his "healer's hands". When he's down he invites {0} in to his teepee. There is a brief shake of the screen before {0} re-emerges, feeling much better. + \ No newline at end of file diff --git a/MoreFactionInteraction/General/MFI_DefOf.cs b/MoreFactionInteraction/General/MFI_DefOf.cs index c012ccb..c720700 100644 --- a/MoreFactionInteraction/General/MFI_DefOf.cs +++ b/MoreFactionInteraction/General/MFI_DefOf.cs @@ -15,7 +15,9 @@ public static class MFI_DefOf public static SiteCoreDef MFI_HuntersLodgeCore; public static SitePartDef MFI_HuntersLodgePart; + public static WorldObjectDef MFI_FactionWarPeaceTalks; + public static WorldObjectDef MFI_MysticalShaman; //public static IncidentDef MFI_WeddingGuestsArrival; } } diff --git a/MoreFactionInteraction/General/Settings.cs b/MoreFactionInteraction/General/Settings.cs index a18d97c..61bb842 100644 --- a/MoreFactionInteraction/General/Settings.cs +++ b/MoreFactionInteraction/General/Settings.cs @@ -10,8 +10,8 @@ namespace MoreFactionInteraction public class MoreFactionInteraction_Settings : ModSettings { public static int ticksToUpgrade = 3 * GenDate.DaysPerQuadrum * GenDate.TicksPerDay; - public static float timeModifierBetweenFactionInteraction = 1f; - public static float traderWealthOffsetFromTimesTraded = 1f; + public static float timeModifierBetweenFactionInteraction = 2f; + public static float traderWealthOffsetFromTimesTraded = 0.7f; public void DoWindowContents(Rect rect) { @@ -30,8 +30,8 @@ public void DoWindowContents(Rect rect) public override void ExposeData() { Scribe_Values.Look(value: ref ticksToUpgrade, label: "ticksToUpgrade", defaultValue: 2700000); - Scribe_Values.Look(value: ref timeModifierBetweenFactionInteraction, label: "timeModifierBetweenFactionInteraction", defaultValue: 1f); - Scribe_Values.Look(value: ref traderWealthOffsetFromTimesTraded, label: "traderWealthOffsetFromTimesTraded", defaultValue: 1f); + Scribe_Values.Look(value: ref timeModifierBetweenFactionInteraction, label: "timeModifierBetweenFactionInteraction", defaultValue: 2f); + Scribe_Values.Look(value: ref traderWealthOffsetFromTimesTraded, label: "traderWealthOffsetFromTimesTraded", defaultValue: 0.8f); } } diff --git a/MoreFactionInteraction/More Flavour/CaravanArrivalAction_VisitMysticalShaman.cs b/MoreFactionInteraction/More Flavour/CaravanArrivalAction_VisitMysticalShaman.cs new file mode 100644 index 0000000..ecc7fab --- /dev/null +++ b/MoreFactionInteraction/More Flavour/CaravanArrivalAction_VisitMysticalShaman.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using RimWorld; +using RimWorld.Planet; +using Verse; + +namespace MoreFactionInteraction.More_Flavour +{ + class CaravanArrivalAction_VisitMysticalShaman : CaravanArrivalAction + { + private MysticalShaman mysticalShaman; + + public override string Label => "VisitPeaceTalks".Translate(mysticalShaman.Label); + public override string ReportString => "CaravanVisiting".Translate(this.mysticalShaman.Label); + + public override void Arrived(Caravan caravan) + { + this.mysticalShaman.Notify_CaravanArrived(caravan: caravan); + } + + public CaravanArrivalAction_VisitMysticalShaman() + { + } + + public CaravanArrivalAction_VisitMysticalShaman(MysticalShaman mysticalShaman) + { + this.mysticalShaman = mysticalShaman; + } + + public static IEnumerable GetFloatMenuOptions(Caravan caravan, MysticalShaman mysticalShaman) + { + return CaravanArrivalActionUtility.GetFloatMenuOptions(acceptanceReportGetter: + () => CanVisit(caravan: caravan, mysticalShaman: mysticalShaman), arrivalActionGetter: + () => new CaravanArrivalAction_VisitMysticalShaman(mysticalShaman: mysticalShaman), + label: "VisitPeaceTalks".Translate(mysticalShaman.Label), + caravan: caravan, pathDestination: mysticalShaman.Tile, + revalidateWorldClickTarget: mysticalShaman); + } + + public static FloatMenuAcceptanceReport CanVisit(Caravan caravan, MysticalShaman mysticalShaman) + { + return mysticalShaman != null && mysticalShaman.Spawned; + } + + public override void ExposeData() + { + base.ExposeData(); + Scribe_References.Look(refee: ref this.mysticalShaman, label: "mysticalShaman"); + } + } +} diff --git a/MoreFactionInteraction/More Flavour/ChoiceLetter_MysticalShaman.cs b/MoreFactionInteraction/More Flavour/ChoiceLetter_MysticalShaman.cs new file mode 100644 index 0000000..2ba7456 --- /dev/null +++ b/MoreFactionInteraction/More Flavour/ChoiceLetter_MysticalShaman.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Verse; +using RimWorld; +using RimWorld.Planet; +using MoreFactionInteraction.More_Flavour; + +namespace MoreFactionInteraction +{ + public class ChoiceLetter_MysticalShaman : ChoiceLetter + { + public int tile; + public Faction faction; + public Map map; + public int fee; + private static readonly IntRange TimeoutDaysRange = new IntRange(min: 5, max: 15); + + public override IEnumerable Choices + { + get + { + if (this.ArchivedOnly) + { + yield return this.Option_Close; + } + else + { + DiaOption accept = new DiaOption(text: "RansomDemand_Accept".Translate()) + { + action = () => + { + MysticalShaman mysticalShaman = (MysticalShaman)WorldObjectMaker.MakeWorldObject(def: MFI_DefOf.MFI_MysticalShaman); + mysticalShaman.Tile = tile; + mysticalShaman.SetFaction(newFaction: faction); + int randomInRange = TimeoutDaysRange.RandomInRange; + mysticalShaman.GetComponent().StartTimeout(ticks: randomInRange * GenDate.TicksPerDay); + Find.WorldObjects.Add(o: mysticalShaman); + + TradeUtility.LaunchSilver(map: this.map, fee: this.fee); + Find.LetterStack.RemoveLetter(let: this); + }, + resolveTree = true + }; + if (!TradeUtility.ColonyHasEnoughSilver(map: this.map, fee: this.fee)) + { + accept.Disable(newDisabledReason: "NeedSilverLaunchable".Translate(this.fee.ToString())); + } + yield return accept; + + DiaOption reject = new DiaOption(text: "RansomDemand_Reject".Translate()) + { + action = () => + { + Find.LetterStack.RemoveLetter(let: this); + }, + resolveTree = true + }; + yield return reject; + yield return this.Option_Postpone; + } + } + } + + public override bool CanShowInLetterStack => base.CanShowInLetterStack && Find.Maps.Contains(item: this.map); + + public override void ExposeData() + { + base.ExposeData(); + Scribe_References.Look(refee: ref this.map, label: "MFI_Shaman_Map"); + Scribe_References.Look(refee: ref this.faction, label: "MFI_Shaman_Faction"); + Scribe_Values.Look(ref this.tile, "MFI_ShamanTile"); + Scribe_Values.Look(value: ref this.fee, label: "MFI_ShamanFee"); + } + } +} diff --git a/MoreFactionInteraction/More Flavour/IncidentWorker_DiplomaticMarriage.cs b/MoreFactionInteraction/More Flavour/IncidentWorker_DiplomaticMarriage.cs index 1404106..f09e276 100644 --- a/MoreFactionInteraction/More Flavour/IncidentWorker_DiplomaticMarriage.cs +++ b/MoreFactionInteraction/More Flavour/IncidentWorker_DiplomaticMarriage.cs @@ -33,20 +33,20 @@ protected override bool TryExecuteWorker(IncidentParms parms) return false; } - ChoiceLetter_DiplomaticMarriage choiceLetter_DiplomaticMarriage = (ChoiceLetter_DiplomaticMarriage)LetterMaker.MakeLetter(label: this.def.letterLabel, text: "MFI_DiplomaticMarriage".Translate(args: new object[] + ChoiceLetter_DiplomaticMarriage choiceLetterDiplomaticMarriage = (ChoiceLetter_DiplomaticMarriage)LetterMaker.MakeLetter(label: this.def.letterLabel, text: "MFI_DiplomaticMarriage".Translate(args: new object[] { - this.marriageSeeker.LabelShort, this.betrothed.LabelShort + this.marriageSeeker.LabelShort, this.betrothed.LabelShort, this.marriageSeeker.Faction.Name }).AdjustedFor(p: this.marriageSeeker), def: this.def.letterDef); - choiceLetter_DiplomaticMarriage.title = "MFI_DiplomaticMarriageLabel".Translate(args: new object[] + choiceLetterDiplomaticMarriage.title = "MFI_DiplomaticMarriageLabel".Translate(args: new object[] { this.betrothed.LabelShort }).CapitalizeFirst(); - choiceLetter_DiplomaticMarriage.radioMode = true; - choiceLetter_DiplomaticMarriage.marriageSeeker = this.marriageSeeker; - choiceLetter_DiplomaticMarriage.betrothed = this.betrothed; - choiceLetter_DiplomaticMarriage.StartTimeout(duration: TimeoutTicks); - Find.LetterStack.ReceiveLetter(@let: choiceLetter_DiplomaticMarriage); + choiceLetterDiplomaticMarriage.radioMode = true; + choiceLetterDiplomaticMarriage.marriageSeeker = this.marriageSeeker; + choiceLetterDiplomaticMarriage.betrothed = this.betrothed; + choiceLetterDiplomaticMarriage.StartTimeout(duration: TimeoutTicks); + Find.LetterStack.ReceiveLetter(@let: choiceLetterDiplomaticMarriage); return true; } diff --git a/MoreFactionInteraction/More Flavour/IncidentWorker_MysticalShaman.cs b/MoreFactionInteraction/More Flavour/IncidentWorker_MysticalShaman.cs new file mode 100644 index 0000000..827174e --- /dev/null +++ b/MoreFactionInteraction/More Flavour/IncidentWorker_MysticalShaman.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using RimWorld; +using Verse; +using RimWorld.Planet; + +namespace MoreFactionInteraction +{ + class IncidentWorker_MysticalShaman : IncidentWorker + { + private static List tmpAvailableMaps = new List(); + + public override float AdjustedChance => base.AdjustedChance; + + private const int MinDistance = 8; + private const int MaxDistance = 22; + private const int TimeoutTicks = GenDate.TicksPerDay; + + protected override bool CanFireNowSub(IncidentParms parms) + { + return base.CanFireNowSub(parms: parms) && Find.AnyPlayerHomeMap != null + && !Find.WorldObjects.AllWorldObjects.Any(predicate: o => o.def == MFI_DefOf.MFI_MysticalShaman) + && Find.FactionManager.AllFactionsVisible.Where(predicate: f => f.def.techLevel <= TechLevel.Neolithic + && !f.HostileTo(other: Faction.OfPlayer)).TryRandomElement(result: out Faction result) + && TryFindTile(tile: out int num) + && TryGetRandomAvailableTargetMap (map: out Map map); + } + + protected override bool TryExecuteWorker(IncidentParms parms) + { + if (!Find.FactionManager.AllFactionsVisible.Where(predicate: f => f.def.techLevel <= TechLevel.Neolithic + && !f.HostileTo(other: Faction.OfPlayer)).TryRandomElement(result: out Faction faction)) + return false; + + if (!TryGetRandomAvailableTargetMap(map: out Map map)) + return false; + + if (faction == null) + return false; + + if (map == null) + return false; + + if (!TryFindTile(tile: out int tile)) + return false; + + int fee = Rand.RangeInclusive(min: 400, max: 1000); + + ChoiceLetter_MysticalShaman choiceLetterMysticalShaman = (ChoiceLetter_MysticalShaman)LetterMaker.MakeLetter(label: this.def.letterLabel, text: "MFI_MysticalShamanLetter".Translate(faction.Name, fee.ToString()), def: this.def.letterDef); + choiceLetterMysticalShaman.title = "MFI_MysticalShamanTitle".Translate().CapitalizeFirst(); + choiceLetterMysticalShaman.faction = faction; + choiceLetterMysticalShaman.tile = tile; + choiceLetterMysticalShaman.map = map; + choiceLetterMysticalShaman.fee = fee; + choiceLetterMysticalShaman.StartTimeout(duration: TimeoutTicks); + Find.LetterStack.ReceiveLetter(let: choiceLetterMysticalShaman); + return true; + } + + private static bool TryFindTile(out int tile) + { + return TileFinder.TryFindNewSiteTile(tile: out tile, minDist: MinDistance, maxDist: MaxDistance, allowCaravans: true, preferCloserTiles: false); + } + + private static bool TryGetRandomAvailableTargetMap(out Map map) + { + tmpAvailableMaps.Clear(); + List maps = Find.Maps; + foreach (Map potentialTargetMap in maps) + { + if (potentialTargetMap.IsPlayerHome && IncidentWorker_QuestTradeRequest.RandomNearbyTradeableSettlement(originTile: potentialTargetMap.Tile) != null) + { + tmpAvailableMaps.Add(item: potentialTargetMap); + } + } + bool result = tmpAvailableMaps.TryRandomElement(result: out map); + tmpAvailableMaps.Clear(); + return result; + } + } +} diff --git a/MoreFactionInteraction/More Flavour/MysticalShaman.cs b/MoreFactionInteraction/More Flavour/MysticalShaman.cs new file mode 100644 index 0000000..943991b --- /dev/null +++ b/MoreFactionInteraction/More Flavour/MysticalShaman.cs @@ -0,0 +1,284 @@ +using System.Collections.Generic; +using System.Linq; +using RimWorld; +using RimWorld.Planet; +using UnityEngine; +using Verse; + +namespace MoreFactionInteraction.More_Flavour +{ + internal class MysticalShaman : WorldObject + { + private Material cachedMat; + + public override Material Material + { + get + { + if (this.cachedMat == null) + { + this.cachedMat = MaterialPool.MatFrom(texPath: this.def.expandingIconTexture, shader: ShaderDatabase.WorldOverlayTransparentLit, color: base.Faction.Color, renderQueue: WorldMaterials.WorldObjectRenderQueue); + } + return this.cachedMat; + } + } + + public override IEnumerable GetCaravanGizmos(Caravan caravan) + { + return base.GetCaravanGizmos(caravan: caravan); + } + + public override IEnumerable GetFloatMenuOptions(Caravan caravan) + { + foreach (FloatMenuOption o in base.GetFloatMenuOptions(caravan: caravan)) yield return o; + foreach (FloatMenuOption f in CaravanArrivalAction_VisitMysticalShaman.GetFloatMenuOptions(caravan: caravan, mysticalShaman: this)) yield return f; + } + + public void Notify_CaravanArrived(Caravan caravan) + { + Pawn pawn = WorstCaravanPawnUtility.FindSickestPawn(caravan: caravan); + if (pawn == null) + { + Find.WindowStack.Add(window: new Dialog_MessageBox(text: "MFI_MysticalShamanFoundNoSickPawn".Translate())); + // Dialog_MessageBox.CreateConfirmation(text: "MFI_MysticalShamanFoundNoSickPawn".Translate(), + // confirmedAct: () => Find.WorldObjects.Remove(o: this))); + } + else + { + CameraJumper.TryJumpAndSelect(target: caravan); + Thing serum = ThingMaker.MakeThing(def: ThingDef.Named(defName: "MechSerumHealer")); //obj ref req, but me lazy. + serum.TryGetComp().DoEffect(usedBy: pawn); + serum = null; + Find.WindowStack.Add(window: new Dialog_MessageBox(text: "MFI_MysticalShamanDoesHisMagic".Translate(pawn.LabelShort))); + } + Find.WorldObjects.Remove(o: this); + } + } + + internal class WorstCaravanPawnUtility + { + private static readonly Dictionary tempPawns = new Dictionary(); + + public static Pawn FindSickestPawn(Caravan caravan) + { + tempPawns.Clear(); + foreach (Pawn pawn in caravan.PawnsListForReading) tempPawns.Add(key: pawn, value: CalcHealthThreatenedScore(usedBy: pawn)); + tempPawns.RemoveAll(predicate: x => x.Value == 0); + return tempPawns.FirstOrDefault(predicate: x => x.Value.Equals(obj: tempPawns.Values.Max())).Key; + } + + private static float HandCoverageAbsWithChildren + { + get + { + return ThingDefOf.Human.race.body.GetPartsWithDef(def: BodyPartDefOf.Hand).First().coverageAbsWithChildren; + } + } + + //Taken from CompUseEffect_FixWorstHealthCondition, with a bit of Resharper cleanup to stop my eyes bleeding. + private static int CalcHealthThreatenedScore(Pawn usedBy) + { + Hediff hediff = FindLifeThreateningHediff(pawn: usedBy); + if (hediff != null) return 8192; + + if (HealthUtility.TicksUntilDeathDueToBloodLoss(pawn: usedBy) < 2500) + { + Hediff hediff2 = FindMostBleedingHediff(pawn: usedBy); + if (hediff2 != null) return 4096; + } + + if (usedBy.health.hediffSet.GetBrain() != null) + { + Hediff_Injury hediffInjury = FindPermanentInjury(pawn: usedBy, allowedBodyParts: Gen.YieldSingle(val: usedBy.health.hediffSet.GetBrain())); + if (hediffInjury != null) return 2048; + } + + BodyPartRecord bodyPartRecord = FindBiggestMissingBodyPart(pawn: usedBy, minCoverage: HandCoverageAbsWithChildren); + if (bodyPartRecord != null) return 1024; + + Hediff_Injury hediffInjury2 = FindPermanentInjury(pawn: usedBy, + allowedBodyParts: usedBy.health.hediffSet.GetNotMissingParts() + .Where(predicate: x => x.def == BodyPartDefOf.Eye)); + if (hediffInjury2 != null) return 512; + + Hediff hediff3 = FindImmunizableHediffWhichCanKill(pawn: usedBy); + if (hediff3 != null) return 255; + + Hediff hediff4 = FindNonInjuryMiscBadHediff(pawn: usedBy, onlyIfCanKill: true); + if (hediff4 != null) return 128; + + Hediff hediff5 = FindNonInjuryMiscBadHediff(pawn: usedBy, onlyIfCanKill: false); + if (hediff5 != null) return 64; + + if (usedBy.health.hediffSet.GetBrain() != null) + { + Hediff_Injury hediffInjury3 = FindInjury(pawn: usedBy, allowedBodyParts: Gen.YieldSingle(val: usedBy.health.hediffSet.GetBrain())); + if (hediffInjury3 != null) return 32; + } + BodyPartRecord bodyPartRecord2 = FindBiggestMissingBodyPart(pawn: usedBy); + if (bodyPartRecord2 != null) return 16; + + Hediff_Addiction hediffAddiction = FindAddiction(pawn: usedBy); + if (hediffAddiction != null) return 8; + + Hediff_Injury hediffInjury4 = FindPermanentInjury(pawn: usedBy); + if (hediffInjury4 != null) return 4; + + Hediff_Injury hediffInjury5 = FindInjury(pawn: usedBy); + if (hediffInjury5 != null) return 2; + + return 0; + } + + private static Hediff FindLifeThreateningHediff(Pawn pawn) + { + Hediff hediff = null; + float num = -1f; + List hediffs = pawn.health.hediffSet.hediffs; + foreach (Hediff current in hediffs) + if (current.Visible && current.def.everCurableByItem) + if (!current.FullyImmune()) + { + bool flag = current.CurStage != null && current.CurStage.lifeThreatening; + bool flag2 = current.def.lethalSeverity >= 0f && current.Severity / current.def.lethalSeverity >= 0.8f; + if (flag || flag2) + { + float num2 = current.Part?.coverageAbsWithChildren ?? 999f; + if (hediff == null || num2 > num) + { + hediff = current; + num = num2; + } + } + } + + return hediff; + } + + private static Hediff FindMostBleedingHediff(Pawn pawn) + { + float num = 0f; + Hediff hediff = null; + List hediffs = pawn.health.hediffSet.hediffs; + foreach (Hediff current in hediffs) + { + if (current.Visible && current.def.everCurableByItem) + { + float bleedRate = current.BleedRate; + if (bleedRate > 0f && (bleedRate > num || hediff == null)) + { + num = bleedRate; + hediff = current; + } + } + } + return hediff; + } + + private static Hediff FindImmunizableHediffWhichCanKill(Pawn pawn) + { + Hediff hediff = null; + float num = -1f; + List hediffs = pawn.health.hediffSet.hediffs; + foreach (Hediff current in hediffs) + { + if (current.Visible && current.def.everCurableByItem) + if (current.TryGetComp() != null) + if (!current.FullyImmune()) + if (CanEverKill(hediff: current)) + { + float severity = current.Severity; + if (hediff == null || severity > num) + { + hediff = current; + num = severity; + } + } + } + return hediff; + } + + private static Hediff FindNonInjuryMiscBadHediff(Pawn pawn, bool onlyIfCanKill) + { + Hediff hediff = null; + float num = -1f; + List hediffs = pawn.health.hediffSet.hediffs; + foreach (Hediff current in hediffs) + { + if (current.Visible && current.def.isBad && current.def.everCurableByItem) + if (!(current is Hediff_Injury) && !(current is Hediff_MissingPart) && !(current is Hediff_Addiction) && !(current is Hediff_AddedPart)) + if (!onlyIfCanKill || CanEverKill(hediff: current)) + { + float num2 = (current.Part == null) ? 999f : current.Part.coverageAbsWithChildren; + if (hediff == null || num2 > num) + { + hediff = current; + num = num2; + } + } + } + return hediff; + } + + private static BodyPartRecord FindBiggestMissingBodyPart(Pawn pawn, float minCoverage = 0f) + { + BodyPartRecord bodyPartRecord = null; + foreach (Hediff_MissingPart current in pawn.health.hediffSet.GetMissingPartsCommonAncestors()) + if (current.Part.coverageAbsWithChildren >= minCoverage) + if (!pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(part: current.Part)) + if (bodyPartRecord == null || current.Part.coverageAbsWithChildren > bodyPartRecord.coverageAbsWithChildren) + bodyPartRecord = current.Part; + + return bodyPartRecord; + } + + private static Hediff_Addiction FindAddiction(Pawn pawn) + { + List hediffs = pawn.health.hediffSet.hediffs; + foreach (Hediff current in hediffs) + { + if (current is Hediff_Addiction hediffAddiction && hediffAddiction.Visible && hediffAddiction.def.everCurableByItem) + { + return hediffAddiction; + } + } + return null; + } + + private static Hediff_Injury FindPermanentInjury(Pawn pawn, IEnumerable allowedBodyParts = null) + { + Hediff_Injury hediffInjury = null; + List hediffs = pawn.health.hediffSet.hediffs; + for (int i = 0; i < hediffs.Count; i++) + { + if (hediffs[index: i] is Hediff_Injury hediffInjury2 && hediffInjury2.Visible && hediffInjury2.IsPermanent() && hediffInjury2.def.everCurableByItem) + if (allowedBodyParts == null || allowedBodyParts.Contains(value: hediffInjury2.Part)) + if (hediffInjury == null || hediffInjury2.Severity > hediffInjury.Severity) + hediffInjury = hediffInjury2; + } + return hediffInjury; + } + + private static Hediff_Injury FindInjury(Pawn pawn, IEnumerable allowedBodyParts = null) + { + Hediff_Injury hediffInjury = null; + List hediffs = pawn.health.hediffSet.hediffs; + foreach (Hediff hediff in hediffs) + if (hediff is Hediff_Injury hediffInjury2 && hediffInjury2.Visible && hediffInjury2.def.everCurableByItem) + if (allowedBodyParts == null || allowedBodyParts.Contains(value: hediffInjury2.Part)) + if (hediffInjury == null || hediffInjury2.Severity > hediffInjury.Severity) + hediffInjury = hediffInjury2; + + return hediffInjury; + } + + private static bool CanEverKill(Hediff hediff) + { + if (hediff.def.stages != null) + if (Enumerable.Any(source: hediff.def.stages, predicate: t => t.lifeThreatening)) + + return true; + return (hediff.def.lethalSeverity >= 0f); + } + } +} \ No newline at end of file diff --git a/MoreFactionInteraction/MoreFactionInteraction.csproj b/MoreFactionInteraction/MoreFactionInteraction.csproj index 49f2d6b..5ab51f0 100644 --- a/MoreFactionInteraction/MoreFactionInteraction.csproj +++ b/MoreFactionInteraction/MoreFactionInteraction.csproj @@ -55,8 +55,12 @@ + + + + diff --git a/MoreFactionInteraction/MoreFactionWar/FactionWarDialogue.cs b/MoreFactionInteraction/MoreFactionWar/FactionWarDialogue.cs index 9e2a9c3..ed885e6 100644 --- a/MoreFactionInteraction/MoreFactionWar/FactionWarDialogue.cs +++ b/MoreFactionInteraction/MoreFactionWar/FactionWarDialogue.cs @@ -119,9 +119,9 @@ public static void DetermineOutcome(Faction favouredFaction, Faction burdenedFac second: BaseWeight_Triumph * goodOutcomeWeightFactor), second: "MFI_FactionWarFavourFactionTriumph".Translate(favouredFaction.Name, burdenedFaction.Name))); - Action first = tmpPossibleOutcomes.RandomElementByWeight(weightSelector: (Pair, string> x) => x.First.Second).First.First; - factionWarNegotiationsOutcome = tmpPossibleOutcomes.RandomElementByWeight(weightSelector: (Pair, string> x) => x.First.Second).Second; - first(); + Pair, string> outcome = tmpPossibleOutcomes.RandomElementByWeight(x => x.First.Second); + outcome.First.First(); + factionWarNegotiationsOutcome = outcome.Second; pawn.skills.Learn(sDef: SkillDefOf.Social, xp: 6000f, direct: true); } @@ -154,9 +154,9 @@ public static void DetermineOutcome(Faction favouredFaction, Faction burdenedFac second: BaseWeight_Triumph * goodOutcomeWeightFactor), second: "MFI_FactionWarSabotageTriumph".Translate(favouredFaction.Name, burdenedFaction.Name))); - Action first = tmpPossibleOutcomes.RandomElementByWeight(weightSelector: (Pair, string> x) => x.First.Second).First.First; - factionWarNegotiationsOutcome = tmpPossibleOutcomes.RandomElementByWeight(weightSelector: (Pair, string> x) => x.First.Second).Second; - first(); + Pair, string> outcome = tmpPossibleOutcomes.RandomElementByWeight(x => x.First.Second); + outcome.First.First(); + factionWarNegotiationsOutcome = outcome.Second; pawn.skills.Learn(sDef: SkillDefOf.Social, xp: 6000f, direct: true); } @@ -189,9 +189,9 @@ public static void DetermineOutcome(Faction favouredFaction, Faction burdenedFac second: BaseWeight_Triumph * goodOutcomeWeightFactor), second: "MFI_FactionWarBrokerPeaceTriumph".Translate(favouredFaction.Name, burdenedFaction.Name))); - Action first = tmpPossibleOutcomes.RandomElementByWeight(weightSelector: (Pair, string> x) => x.First.Second).First.First; - factionWarNegotiationsOutcome = tmpPossibleOutcomes.RandomElementByWeight(weightSelector: (Pair, string> x) => x.First.Second).Second + "\n\n" + "PeaceTalksSocialXPGain".Translate(pawn.LabelShort, 6000f.ToString(format: "F0")); - first(); + Pair, string> outcome = tmpPossibleOutcomes.RandomElementByWeight(x => x.First.Second); + outcome.First.First(); + factionWarNegotiationsOutcome = outcome.Second; pawn.skills.Learn(sDef: SkillDefOf.Social, xp: 6000f, direct: true); } @@ -364,8 +364,7 @@ private static void Outcome_TalksSabotageDisaster(Faction favouredFaction, Facti LordMaker.MakeNewLord(faction: burdenedFactionIncidentParms.faction, lordJob: new LordJob_AssaultColony(assaulterFaction: burdenedFaction), map: map, startingPawns: burdenedFactionWarriors); } - Find.TickManager.CurTimeSpeed = TimeSpeed.Paused; - Find.TickManager.slower.SignalForceNormalSpeedShort(); + Find.TickManager.Notify_GeneratedPotentiallyHostileMap(); }, textKey: "GeneratingMapForNewEncounter", doAsynchronously: false, exceptionHandler: null); } diff --git a/MoreFactionInteraction/Spreading Pirates/IncidentWorker_Extortion.cs b/MoreFactionInteraction/Spreading Pirates/IncidentWorker_Extortion.cs index b725474..c39addd 100644 --- a/MoreFactionInteraction/Spreading Pirates/IncidentWorker_Extortion.cs +++ b/MoreFactionInteraction/Spreading Pirates/IncidentWorker_Extortion.cs @@ -60,8 +60,6 @@ protected override bool TryExecuteWorker(IncidentParms parms) if (RandomNearbyHostileWorldObject(originTile: map.Tile, encampment: out this.worldObject, faction: out this.faction)) { - //technically the math.max is nonsense since this incident uses Misc category, and points don't get calculated for that. Left in for future expansion. - //update: seems they now do? thx Tynan. int extorsionDemand = Math.Max(val1: Rand.Range(min: 150, max: 300), val2: (int)parms.points) * NearbyHostileEncampments(forTile: map.Tile).Count(); ChoiceLetter_ExtortionDemand choiceLetterExtortionDemand = (ChoiceLetter_ExtortionDemand)LetterMaker.MakeLetter(label: this.def.letterLabel, text: "MFI_ExtortionDemand".Translate(args: new object[] diff --git a/MoreFactionInteraction/TODO.txt b/MoreFactionInteraction/TODO.txt deleted file mode 100644 index c0fd78d..0000000 --- a/MoreFactionInteraction/TODO.txt +++ /dev/null @@ -1,56 +0,0 @@ -EVENTS: -- Hunter's Lodge - -- Nearby caravan needs medic -- Military aid - -- Hive like mech-hive -- trigger turrets puzzle ( a la reddit challenge plan ) - -SETTINGS: -- Trade frequency influencer -- Option for cheat settings if god mode on (increase trade quality even further, scale higher) ? - -BUG FIXES AND REFINEMENT: -- Help out harvesting (letters, balance and fluff) -- thrumbo herd on hunters lodge - -TODO: - -- Increase Orbital Traders based on Wealth/TicksGame. -- Balance maxValuePerUnit -- Look into maxTechLevelBuy -- remove from incidentQueue -- Trade requests dynamic based on requester - -Special world maps: -- Ancient cities. Spawned just like faction bases, but preferably in remote/barren locations. No soil, just concrete or stone floor. Destroyed cities, rock rubble, etc. -- Send pawn to faction as inter-marriage for faction goodwill - -IDEAS: -Spawn/split off factions -Faction asks for materials to upgrade itself/roads -(shooting) Competition -ransom demand for prisoner -famed tribal shaman. Bring pawn to them for "free" heal - -FactionWar related: -Guard an outpost -Allegiance shift through trade -Peacetalks to end? - -Bring resources for war effort - -Squatters in destroyed outposts. - - -Cargo pod surprise? -- Scyther -- Cargo pod -- Space refugee -- -- Faction Art with desire to get back -=> lore snippets, like quest system -=> something of great interest to faction -=> faction diaries - diff --git a/MoreFactionInteraction/World Incidents/IncidentWorker_HuntersLodge.cs b/MoreFactionInteraction/World Incidents/IncidentWorker_HuntersLodge.cs index 7bbb0ec..d462143 100644 --- a/MoreFactionInteraction/World Incidents/IncidentWorker_HuntersLodge.cs +++ b/MoreFactionInteraction/World Incidents/IncidentWorker_HuntersLodge.cs @@ -17,18 +17,26 @@ public class IncidentWorker_HuntersLodge : IncidentWorker protected override bool CanFireNowSub(IncidentParms parms) { return base.CanFireNowSub(parms: parms) && Find.AnyPlayerHomeMap != null - && Find.FactionManager.RandomNonHostileFaction(allowHidden: false, allowDefeated: false, allowNonHumanlike: false) != null + && Find.FactionManager.RandomAlliedFaction(allowHidden: false, allowDefeated: false, allowNonHumanlike: false) != null && TryFindTile(tile: out int num); } protected override bool TryExecuteWorker(IncidentParms parms) { - Faction faction = parms.faction ?? Find.FactionManager.RandomNonHostileFaction(allowHidden: false, allowDefeated: false, allowNonHumanlike: false); + Faction faction = parms.faction ?? Find.FactionManager.RandomAlliedFaction(allowHidden: false, allowDefeated: false, allowNonHumanlike: false); + + if (faction == null) + { + faction = Find.FactionManager.RandomNonHostileFaction(false, false, false); + Log.ErrorOnce("MFI: No allied faction found, but event was forced. Using random faction.", 40830425); + } if (!TryFindTile(tile: out int tile)) return false; - Site site = SiteMaker.MakeSite(core: MFI_DefOf.MFI_HuntersLodgeCore, sitePart: MFI_DefOf.MFI_HuntersLodgePart, tile: tile, faction: faction, ifHostileThenMustRemainHostile: false); + Site site = SiteMaker.MakeSite(core: MFI_DefOf.MFI_HuntersLodgeCore, + sitePart: MFI_DefOf.MFI_HuntersLodgePart, + tile: tile, faction: faction, ifHostileThenMustRemainHostile: false); if (site == null) return false; diff --git a/MoreFactionInteraction/World Incidents/WorldObjectComp_SettlementBumperCropComp.cs b/MoreFactionInteraction/World Incidents/WorldObjectComp_SettlementBumperCropComp.cs index ac091a5..4c705e3 100644 --- a/MoreFactionInteraction/World Incidents/WorldObjectComp_SettlementBumperCropComp.cs +++ b/MoreFactionInteraction/World Incidents/WorldObjectComp_SettlementBumperCropComp.cs @@ -79,7 +79,6 @@ private void Outcome_Triumph(Caravan caravan) CaravanInventoryUtility.GiveThing(caravan: caravan, thing: reward); Find.LetterStack.ReceiveLetter(label: "MFI_LetterLabelHarvest_Triumph".Translate(), text: GetLetterText(baseText: "MFI_Harvest_Triumph".Translate( - this.parent.Faction.def.pawnsPlural, this.parent.Faction.Name, Mathf.RoundToInt(f: randomInRange), reward.LabelCap @@ -88,7 +87,7 @@ private void Outcome_Triumph(Caravan caravan) allMembersCapableOfGrowing.ForEach(action: pawn => pawn.skills.Learn(sDef: SkillDefOf.Plants, xp: expGain, direct: true)); } - private static float CalculateYieldForCaravan(List caravanMembersCapableOfGrowing) + private static float CalculateYieldForCaravan(IEnumerable caravanMembersCapableOfGrowing) { return caravanMembersCapableOfGrowing.Select(selector: x => x.GetStatValue(stat: StatDefOf.PlantHarvestYield)).Sum(); } @@ -118,9 +117,9 @@ private static List AllCaravanMembersCapableOfGrowing(Caravan caravan) public override void PostExposeData() { base.PostExposeData(); - Scribe_Values.Look(ref this.expiration, "MFI_BumperCropExpiration"); - Scribe_Values.Look(ref this.workLeft, "MFI_BumperCropWorkLeft"); - Scribe_Values.Look(ref this.workStarted, "MFI_BumperCropWorkStarted"); + Scribe_Values.Look(value: ref this.expiration, label: "MFI_BumperCropExpiration"); + Scribe_Values.Look(value: ref this.workLeft, label: "MFI_BumperCropWorkLeft"); + Scribe_Values.Look(value: ref this.workStarted, label: "MFI_BumperCropWorkStarted"); } } } \ No newline at end of file diff --git a/Textures/Expanding/HealerHand.png b/Textures/Expanding/HealerHand.png new file mode 100644 index 0000000..9ece685 Binary files /dev/null and b/Textures/Expanding/HealerHand.png differ diff --git a/notes on gen.txt b/notes on gen.txt deleted file mode 100644 index a711777..0000000 --- a/notes on gen.txt +++ /dev/null @@ -1,20 +0,0 @@ -The ~10 or so WorldObjects are instantiated by RimWorld.Planet.WorldObjectMaker.MakeWorldObject(WorldObjectDef def), -it takes the worldObjectClass from the def. - -Everything except Sites is pretty straight-forward. - -TryFindSiteParams_SingleSite (SiteCoreDef, sitepartCandidates => out SitePartDef, out Faction <= [factionToUse]) - -- Sites themselves are blank slates. They can be populated by different things: Comps, SiteCoreDefs and SitePartDefs. - -SiteCoreDef doesn't do much, but it's attached to a GenStepDef by the magic of SiteCoreDefName. -This adds the general layout and buildings to a blank slate. - -Comps are comps. Nothing new. Mostly for meta - -SitePartDefs are assigned by string. SiteParts have tags in a string form, and if the faction and tech level match the incident, -that sitepart is a contender to be selected. - -GenStep pushes Symbols based on rules to the stack. idunno what happens when multiple of the same get pushed to the same stack. - -There seems to be a difference between Site/Map owner and SitePart owner, or can potentially be. \ No newline at end of file