public override void Execute() { if (_map == null || _appointment == null || Viewer == null) { return; } Thing thing = ThingMaker.MakeThing(_appointment.ThingDef); IntVec3 spot = DropCellFinder.TradeDropSpot(_map); if (_appointment.ThingDef.Minifiable) { ThingDef minifiedDef = _appointment.ThingDef.minifiedDef; var minifiedThing = (MinifiedThing)ThingMaker.MakeThing(minifiedDef); minifiedThing.InnerThing = thing; minifiedThing.stackCount = _appointment.Quantity; PurchaseHelper.SpawnItem(spot, _map, minifiedThing); } else { thing.stackCount = _appointment.Quantity; PurchaseHelper.SpawnItem(spot, _map, thing); } _appointment.BookSurgeries(); Viewer.Charge(_appointment.Cost, _appointment.ItemData?.Weight ?? 1f, _appointment.ItemData?.KarmaType ?? storeIncident.karmaType); MessageHelper.SendConfirmation(Viewer.username, "TKUtils.Surgery.Complete".LocalizeKeyed(_appointment.ThingDef.LabelCap)); Find.LetterStack.ReceiveLetter( "TKUtils.SurgeryLetter.Title".Localize(), "TKUtils.SurgeryLetter.Description".LocalizeKeyed(Viewer.username, Find.ActiveLanguageWorker.WithDefiniteArticle(thing.LabelCap)), LetterDefOf.NeutralEvent, new LookTargets(thing) ); }
public override void DoWindowContents(Rect inRect) { //grab before anchor/font GameFont fontBefore = Text.Font; TextAnchor anchorBefore = Text.Anchor; //top label Text.Font = GameFont.Small; Text.Anchor = TextAnchor.MiddleCenter; Text.Anchor = TextAnchor.MiddleLeft; int i = 0; foreach (FCPrisoner prisoner in prisoners) { Rect Box; Rect PawnIcon; Rect PawnName; Rect PawnHealth; Rect PawnUnrest; Rect PawnWorkload; Rect ButtonInfo; Rect ButtonAction; Box = optionBox; PawnIcon = optionPawnIcon; PawnName = optionPawnName; PawnHealth = optionPawnHealth; PawnUnrest = optionPawnUnrest; PawnWorkload = optionPawnWorkload; ButtonInfo = optionButtonInfo; ButtonAction = optionButtonAction; Box.y += scroll + optionHeight * i; PawnIcon.y += scroll + optionHeight * i; PawnName.y += scroll + optionHeight * i; PawnHealth.y += scroll + optionHeight * i; PawnUnrest.y += scroll + optionHeight * i; PawnWorkload.y += scroll + optionHeight * i; ButtonInfo.y += scroll + optionHeight * i; ButtonAction.y += scroll + optionHeight * i; //display stuff now Widgets.DrawMenuSection(Box); //on every other box if (i % 2 == 0) { Widgets.DrawHighlight(Box); } //show pawn; Widgets.ThingIcon(PawnIcon, prisoner.prisoner); //Pawn Name Widgets.Label(PawnName, prisoner.prisoner.Name.ToString()); //Pawn Health Widgets.Label(PawnHealth, "Health".Translate().CapitalizeFirst() + " " + prisoner.health); //Pawn Unrest //Widgets.Label(PawnUnrest, "Unrest".Translate().CapitalizeFirst() + " " + prisoner.unrest); //Pawn Workload string workload; switch (prisoner.workload) { case FCWorkLoad.Heavy: workload = "FCHeavy".Translate().CapitalizeFirst(); break; case FCWorkLoad.Medium: workload = "FCMedium".Translate().CapitalizeFirst(); break; case FCWorkLoad.Light: workload = "FCLight".Translate().CapitalizeFirst(); break; default: workload = "null"; break; } if (Widgets.ButtonText(PawnWorkload, "FCWorkload".Translate().CapitalizeFirst() + ": " + workload)) { List <FloatMenuOption> list = new List <FloatMenuOption>(); list.Add(new FloatMenuOption("FCHeavy".Translate().CapitalizeFirst() + " - " + "FCHeavyExplanation".Translate(), delegate { prisoner.workload = FCWorkLoad.Heavy; })); list.Add(new FloatMenuOption("FCMedium".Translate().CapitalizeFirst() + " - " + "FCMediumExplanation".Translate(), delegate { prisoner.workload = FCWorkLoad.Medium; })); list.Add(new FloatMenuOption("FCLight".Translate().CapitalizeFirst() + " - " + "FCLightExplanation".Translate(), delegate { prisoner.workload = FCWorkLoad.Light; })); FloatMenu menu = new FloatMenu(list); Find.WindowStack.Add(menu); } //Info Button if (Widgets.ButtonTextSubtle(ButtonInfo, "ViewInfo".Translate())) { Pawn pawn = new Pawn(); pawn = prisoner.prisoner; if (prisoner.healthTracker != null) { prisoner.prisoner.health = prisoner.healthTracker; } else { prisoner.prisoner.health = new Pawn_HealthTracker(prisoner.prisoner); prisoner.healthTracker = new Pawn_HealthTracker(prisoner.prisoner); } pawn.health = prisoner.healthTracker; Find.WindowStack.Add(new Dialog_InfoCard(pawn)); } //Action button if (Widgets.ButtonTextSubtle(ButtonAction, "Actions".Translate())) { List <FloatMenuOption> list = new List <FloatMenuOption>(); list.Add(new FloatMenuOption("SellPawn".Translate() + " $" + prisoner.prisoner.MarketValue + " " + "SellPawnInfo".Translate(), delegate { settlement.addSilverIncome(prisoner.prisoner.MarketValue); //reset window prisoners.Remove(prisoner); WindowUpdate(); return; })); list.Add(new FloatMenuOption("ReturnToPlayer".Translate(), delegate { if (prisoner.healthTracker != null) { prisoner.prisoner.health = prisoner.healthTracker; } else { prisoner.prisoner.health = new Pawn_HealthTracker(prisoner.prisoner); prisoner.healthTracker = new Pawn_HealthTracker(prisoner.prisoner); } HealthUtility.DamageUntilDowned(prisoner.prisoner, false); if (prisoner.prisoner.guest == null) { prisoner.prisoner.guest = new Pawn_GuestTracker(); } prisoner.prisoner.guest.isPrisonerInt = true; FieldInfo hostFaction = typeof(Pawn_GuestTracker).GetField("hostFactionInt", BindingFlags.NonPublic | BindingFlags.Instance); hostFaction.SetValue(prisoner.prisoner.guest, Find.FactionManager.OfPlayer); List <Thing> things = new List <Thing>(); things.Add(prisoner.prisoner); DropPodUtility.DropThingsNear(DropCellFinder.TradeDropSpot(Find.CurrentMap), Find.CurrentMap, things); //reset window prisoners.Remove(prisoner); WindowUpdate(); return; })); FloatMenu menu = new FloatMenu(list); Find.WindowStack.Add(menu); } //increment i i++; } Text.Font = fontBefore; Text.Anchor = anchorBefore; if (Event.current.type == EventType.ScrollWheel) { scrollWindow(Event.current.delta.y); } }
public void EndCompetitions() { CompEnd = true; CompStarted = false; if (competitionTableRecords != null) { CompetitionTableRecord winner = competitionTableRecords.FirstOrDefault(); Find.LetterStack.ReceiveLetter("Competitions_WinnerTitle".Translate(), "Competitions_WinnerDesc".Translate(CompetitionSkill.LabelCap, winner.Faction.Name, winner.Pawn.Name.ToStringFull, winner.Score, RewardCount), LetterDefOf.PositiveEvent); if (winner.Faction == Faction.OfPlayer) { Thing reward = ThingMaker.MakeThing(ThingDefOf.Silver); reward.stackCount = RewardCount; Map map = Find.AnyPlayerHomeMap; IntVec3 intVec = DropCellFinder.TradeDropSpot(map); DropPodUtility.DropThingsNear(intVec, map, new List <Thing> { reward }, 110, canInstaDropDuringInit: false, leaveSlag: false, canRoofPunch: false); if (winner.Paid && Rand.Chance(0.15f)) { Find.LetterStack.ReceiveLetter("Competitions_JudgePaidFailTitle".Translate(), "Competitions_JudgePaidFailDesc".Translate(), LetterDefOf.NegativeEvent); competitionTableRecords.ForEach(x => { if (x.Faction != Faction.OfPlayer) { x.Faction.TryAffectGoodwillWith(Faction.OfPlayer, -15, reason: "Competitions_JudgePaidReason".Translate()); } }); } var playerAlliance = QuestsManager.Communications.FactionManager.PlayerAlliance; if (playerAlliance != null) { playerAlliance.GiveTrustToAllFactions(5); } } foreach (var comp in competitionTableRecords) { Find.WorldPawns.RemovePawn(comp.Pawn); } if (PlayerPawn != null) { PlayerPawn.skills.GetSkill(CompetitionSkill).Learn(35000); Find.WorldPawns.PassToWorld(PlayerPawn); PlayerPawn.SetFaction(Faction.OfPlayer); CaravanMaker.MakeCaravan(new List <Pawn> { PlayerPawn }, RimWorld.Faction.OfPlayer, Tile, false); } } else { Find.LetterStack.ReceiveLetter("Competitions_JustEndTitle".Translate(), "Competitions_JustEndDesc".Translate(CompetitionSkill.LabelCap), LetterDefOf.PositiveEvent); } if (Dialog != null) { QuestsManager.Communications.RemoveCommunication(Dialog); } Find.WorldObjects.Remove(this); }
public override bool TryExecute(IncidentParms parms) { Map map = (Map)parms.target; IntVec3 spawnSpot; if (!CellFinder.TryFindRandomEdgeCellWith(c => map.reachability.CanReachColony(c), map, out spawnSpot)) { return(false); } #region CHANGED Func <Pawn, bool> selector = other => other.RaceProps.Humanlike && other.Faction != null && other.Faction.HostileTo(Faction.OfPlayer) && HasGroupMakers(other.Faction); Pawn refugee = GenericUtility.GetAnyRelatedWorldPawn(selector, 100); if (refugee == null) { // Just ANYONE Find.WorldPawns.AllPawnsAlive.Where(selector).TryRandomElement(out refugee); } if (refugee == null) { return(false); } refugee.relations.everSeenByPlayer = true; Faction enemyFac = refugee.Faction; string text = "RefugeeChasedInitial".Translate(new object[] { refugee.Name.ToStringFull, refugee.GetTitle().ToLower(), enemyFac.def.pawnsPlural, enemyFac.Name, refugee.ageTracker.AgeBiologicalYears }); text = text.AdjustedFor(refugee); PawnRelationUtility.TryAppendRelationsWithColonistsInfo(ref text, refugee); DiaNode diaNode = new DiaNode(text); DiaOption diaOption = new DiaOption("RefugeeChasedInitial_Accept".Translate()); diaOption.action = delegate { if (refugee == enemyFac.leader) { enemyFac.GenerateNewLeader(); } Find.WorldPawns.RemovePawn(refugee); var canDrop = enemyFac.def.techLevel >= TechLevel.Spacer; if (canDrop) { spawnSpot = DropCellFinder.TradeDropSpot(map); TradeUtility.SpawnDropPod(spawnSpot, map, refugee); } else { GenSpawn.Spawn(refugee, spawnSpot, map); } refugee.SetFaction(Faction.OfPlayer); Find.CameraDriver.JumpTo(spawnSpot); IncidentParms incidentParms = StorytellerUtility.DefaultParmsNow(Find.Storyteller.def, IncidentCategory.ThreatBig, map); incidentParms.forced = true; incidentParms.faction = enemyFac; incidentParms.raidStrategy = RaidStrategyDefOf.ImmediateAttack; incidentParms.raidArrivalMode = canDrop ? PawnsArriveMode.CenterDrop : PawnsArriveMode.EdgeWalkIn; incidentParms.spawnCenter = spawnSpot; incidentParms.points *= RaidPointsFactor; QueuedIncident qi = new QueuedIncident(new FiringIncident(IncidentDefOf.RaidEnemy, null, incidentParms), Find.TickManager.TicksGame + RaidDelay.RandomInRange); Find.Storyteller.incidentQueue.Add(qi); }; diaOption.resolveTree = true; diaNode.options.Add(diaOption); string text2 = "RefugeeChasedRejected".Translate(new object[] { refugee.NameStringShort }); DiaNode diaNode2 = new DiaNode(text2); DiaOption diaOption2 = new DiaOption("OK".Translate()); diaOption2.resolveTree = true; diaNode2.options.Add(diaOption2); DiaOption diaOption3 = new DiaOption("RefugeeChasedInitial_Reject".Translate()); diaOption3.action = delegate { HealthUtility.GiveInjuriesToKill(refugee); //Log.Message(refugee.Name + " dead? " + refugee.Dead); //Find.WorldPawns.PassToWorld(refugee,PawnDiscardDecideMode.Discard); }; #endregion diaOption3.link = diaNode2; diaNode.options.Add(diaOption3); Find.WindowStack.Add(new Dialog_NodeTree(diaNode, true, true)); return(true); }
protected override bool TryExecuteWorker(IncidentParms parms) { Map target = (Map)parms.target; if (!TryFindFactions(out Faction faction) || !TryFindStravingPawns(out IEnumerable <Pawn> enumerableFood, target) || !TryFindInjuredPawns(out IEnumerable <Pawn> enumerableInjured, target)) { return(false); } List <Thing> thingList = GenerateRewards(faction, enumerableFood.Count(), enumerableInjured.Count(), parms); DropPodUtility.DropThingsNear(DropCellFinder.TradeDropSpot(target), target, thingList, 110, false, true, true); Find.LetterStack.ReceiveLetter("FFE_LetterLabelAid".Translate(), "FFE_Aid".Translate(faction.leader, faction.def.leaderTitle, faction, GenLabel.ThingsLabel(thingList, string.Empty)) , LetterDefOf.PositiveEvent, new TargetInfo(DropCellFinder.TradeDropSpot(target), target, false), faction, null); return(true); }
public static void RequestVassalOptions(Faction faction, DiaNode diaNode1) { DiaNode vassalInfo = new DiaNode("FactionVasalageInfo".Translate(faction)); vassalInfo.options.Add(new DiaOption("Disconnect".Translate()) { resolveTree = true }); DiaNode tributaryInfo = new DiaNode("FactionTributaryInfo".Translate(faction)); tributaryInfo.options.Add(new DiaOption("\"" + "Disconnect".Translate() + "\"") { resolveTree = true }); if (Utilities.FactionsWar().GetByFaction(faction).vassalage == 0) { DiaOption vassalage = new DiaOption("FactionVassalage".Translate()) { link = vassalInfo, action = new Action(() => { Utilities.FactionsWar().GetByFaction(faction).vassalage = 2; faction.TrySetRelationKind(Faction.OfPlayer, FactionRelationKind.Ally); }) }; if (!Prefs.DevMode || faction.def.permanentEnemy || (Utilities.FactionsWar().GetByFaction(faction).resources < 2000 && Utilities.FactionsWar().GetByFaction(faction).resources >= Find.AnyPlayerHomeMap.wealthWatcher.WealthTotal || Utilities.FactionsWar().GetByFaction(faction).resources / Math.Min(Find.AnyPlayerHomeMap.wealthWatcher.WealthTotal, 10000) > 0.25f - Utilities.FactionsWar().GetByFaction(faction).disposition / 100)) { DiaOption vassalagediaOption = new DiaOption("FactionVassalage".Translate()); if (faction.def.permanentEnemy) { vassalagediaOption.Disable("FactionVassalageDisabledEnemy".Translate()); } else { vassalagediaOption.Disable("FactionVassalageDisabled".Translate()); } diaNode1.options.Add(vassalagediaOption); } else { diaNode1.options.Add(vassalage); } DiaOption tribute = new DiaOption("FactionTributary".Translate()) { link = tributaryInfo, action = new Action(() => { Utilities.FactionsWar().GetByFaction(faction).vassalage = 1; faction.TrySetRelationKind(Faction.OfPlayer, FactionRelationKind.Neutral); }) }; if (!Prefs.DevMode || faction.def.permanentEnemy || (Utilities.FactionsWar().GetByFaction(faction).resources < 3000 && Utilities.FactionsWar().GetByFaction(faction).resources >= Find.AnyPlayerHomeMap.wealthWatcher.WealthTotal || Utilities.FactionsWar().GetByFaction(faction).resources / Math.Min(Find.AnyPlayerHomeMap.wealthWatcher.WealthTotal, 10000) > 0.5f - Utilities.FactionsWar().GetByFaction(faction).disposition / 100)) { DiaOption tributarydiaOption = new DiaOption("FactionTributary".Translate()); if (faction.def.permanentEnemy) { tributarydiaOption.Disable("FactionTributaryDisabledEnemy".Translate()); } else { tributarydiaOption.Disable("FactionTributaryDisabled".Translate()); } diaNode1.options.Add(tributarydiaOption); } else { diaNode1.options.Add(tribute); } } else if (Utilities.FactionsWar().GetByFaction(faction).vassalage == 2) { if (Find.TickManager.TicksGame > Utilities.FactionsWar().GetByFaction(faction).vassalageResourseCooldown) { DiaOption vassalage = new DiaOption("FactionVassalDemandResources".Translate()) { resolveTree = true, action = new Action(() => { if (!DefDatabase <ThingDef> .AllDefs.Where(x => x.CountAsResource && x.IsStuff && x.BaseMarketValue >= 5 && x.PlayerAcquirable && !x.CanHaveFaction).TryRandomElement(out ThingDef def)) { Log.Error("No def found"); return; } Thing thing = ThingMaker.MakeThing(def); thing.stackCount = new IntRange(75, 100).RandomInRange; DropPodUtility.DropThingsNear(DropCellFinder.TradeDropSpot(Find.AnyPlayerHomeMap), Find.AnyPlayerHomeMap, new List <Thing>() { thing }, 110, false, false, false); Utilities.FactionsWar().GetByFaction(faction).vassalageResourseCooldown = Find.TickManager.TicksGame + Global.DayInTicks * 3; }) }; diaNode1.options.Add(vassalage); } else { DiaOption vassalage = new DiaOption("FactionVassalDemandResources".Translate()); vassalage.Disable("FactionVassalDemandResourcesDisabled".Translate()); diaNode1.options.Add(vassalage); } if (faction.def.techLevel < TechLevel.Industrial) { return; } RequestInvestmentsNode(faction, diaNode1); } }