private void TakeFromCaravan(Caravan caravan, List <ThingCount> demands, Faction enemyFaction) { List <Thing> list = new List <Thing>(); for (int i = 0; i < demands.Count; i++) { ThingCount thingCount = demands[i]; if (thingCount.Thing is Pawn) { Pawn pawn = (Pawn)thingCount.Thing; caravan.RemovePawn(pawn); foreach (Thing thing in ThingOwnerUtility.GetAllThingsRecursively(pawn, false)) { list.Add(thing); thing.holdingOwner.Take(thing); } enemyFaction.kidnapped.KidnapPawn(pawn, null); } else { thingCount.Thing.SplitOff(thingCount.Count).Destroy(DestroyMode.Vanish); } } for (int j = 0; j < list.Count; j++) { if (!list[j].Destroyed) { CaravanInventoryUtility.GiveThing(caravan, list[j]); } } }
public static void Banish(Pawn pawn, int tile = -1) { if (pawn.Faction != Faction.OfPlayer && pawn.HostFaction != Faction.OfPlayer) { Log.Warning("Tried to banish " + pawn + " but he's neither a colonist, tame animal, nor prisoner."); } else { if (tile == -1) { tile = pawn.Tile; } bool flag = PawnBanishUtility.WouldBeLeftToDie(pawn, tile); PawnDiedOrDownedThoughtsUtility.TryGiveThoughts(pawn, null, (PawnDiedOrDownedThoughtsKind)((!flag) ? 1 : 2)); Caravan caravan = pawn.GetCaravan(); if (caravan != null) { CaravanInventoryUtility.MoveAllInventoryToSomeoneElse(pawn, caravan.PawnsListForReading, null); caravan.RemovePawn(pawn); if (flag) { if (Rand.Value < 0.800000011920929) { pawn.Kill(null, null); } else { PawnBanishUtility.HealIfPossible(pawn); } } if (pawn.guest != null) { pawn.guest.SetGuestStatus(null, false); } if (pawn.Faction == Faction.OfPlayer) { Faction newFaction = default(Faction); if (Find.FactionManager.TryGetRandomNonColonyHumanlikeFaction(out newFaction, pawn.Faction != null && (int)pawn.Faction.def.techLevel >= 3, false, TechLevel.Undefined)) { pawn.SetFaction(newFaction, null); } else { pawn.SetFaction(Faction.OfSpacer, null); } } } else { if (pawn.guest != null) { pawn.guest.SetGuestStatus(null, false); } if (pawn.Faction == Faction.OfPlayer) { pawn.SetFaction(Faction.OfSpacer, null); } } } }
public static void KillRandomPawns(Caravan caravan, float attackPower) { List <Pawn> pawns = new List <Pawn>(caravan.PawnsListForReading); List <DamageInfo> damageList = new List <DamageInfo> { new DamageInfo(DamageDefOf.Bullet, attackPower), new DamageInfo(DamageDefOf.Blunt, attackPower), new DamageInfo(DamageDefOf.Crush, attackPower), new DamageInfo(DamageDefOf.Cut, attackPower), new DamageInfo(DamageDefOf.Stab, attackPower) }; foreach (var pawn in pawns) { int shootsCount = Rand.Range(0, 4); for (int i = 0; i < shootsCount; i++) { if (pawn.Dead) { caravan.RemovePawn(pawn); break; } pawn.TakeDamage(damageList.RandomElement()); } } }
public static void KillRandomPawns(Caravan caravan, float attackPower, ref DamageInfo damageInfo) { List <Pawn> pawns = new List <Pawn>(caravan.PawnsListForReading); foreach (var pawn in pawns) { try { int shootsCount = Rand.Range(0, 4); for (int i = 0; i < shootsCount; i++) { if (pawn.Dead) { caravan.RemovePawn(pawn); break; } pawn.TakeDamage(damageInfo); } } catch { } } }
public static void MakePawnLeave(Pawn pawn, Quest quest) { Caravan caravan = pawn.GetCaravan(); if (caravan != null) { CaravanInventoryUtility.MoveAllInventoryToSomeoneElse(pawn, caravan.PawnsListForReading); caravan.RemovePawn(pawn); } if (pawn.Faction == Faction.OfPlayer) { Rand.PushState(quest.id ^ 0x394042B4); Faction result; if (pawn.HasExtraHomeFaction(quest) && pawn.GetExtraHomeFaction(quest) != Faction.OfPlayer) { result = pawn.GetExtraHomeFaction(quest); } else if (pawn.HasExtraMiniFaction(quest) && pawn.GetExtraMiniFaction(quest) != Faction.OfPlayer) { result = pawn.GetExtraMiniFaction(quest); } else if (!(from x in Find.FactionManager.GetFactions_NewTemp(allowHidden: false, allowDefeated: false, allowNonHumanlike: false) where !x.HostileTo(Faction.OfPlayer) select x).TryRandomElement(out result) && !Find.FactionManager.GetFactions_NewTemp(allowHidden: false, allowDefeated: false, allowNonHumanlike: false).TryRandomElement(out result)) { result = null; } Rand.PopState(); if (pawn.Faction != result) { pawn.SetFaction(result); } } foreach (Pawn item in PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_OfPlayerFaction) { if (item.playerSettings.Master == pawn) { item.playerSettings.Master = null; } } if (pawn.guest != null) { if (pawn.InBed() && pawn.CurrentBed().Faction == Faction.OfPlayer && (pawn.Faction == null || !pawn.Faction.HostileTo(Faction.OfPlayer))) { pawn.guest.SetGuestStatus(Faction.OfPlayer); } else { pawn.guest.SetGuestStatus(null); } } pawn.GetLord()?.Notify_PawnLost(pawn, PawnLostCondition.ForcedByQuest); }
public static void Banish(Pawn pawn, int tile = -1) { if (pawn.Faction != Faction.OfPlayer && pawn.HostFaction != Faction.OfPlayer) { Log.Warning(string.Concat("Tried to banish ", pawn, " but he's neither a colonist, tame animal, nor prisoner.")); return; } if (tile == -1) { tile = pawn.Tile; } bool flag = WouldBeLeftToDie(pawn, tile); if (!pawn.IsQuestLodger()) { PawnDiedOrDownedThoughtsUtility.TryGiveThoughts(pawn, null, (!flag) ? PawnDiedOrDownedThoughtsKind.Banished : PawnDiedOrDownedThoughtsKind.BanishedToDie); } Caravan caravan = pawn.GetCaravan(); if (caravan != null) { CaravanInventoryUtility.MoveAllInventoryToSomeoneElse(pawn, caravan.PawnsListForReading); caravan.RemovePawn(pawn); if (flag) { if (Rand.Value < 0.8f) { pawn.Kill(null, null); } else { HealIfPossible(pawn); } } } if (pawn.guest != null) { pawn.guest.SetGuestStatus(null); } if (pawn.Faction == Faction.OfPlayer) { if (!pawn.Spawned && Find.FactionManager.TryGetRandomNonColonyHumanlikeFaction_NewTemp(out var faction, pawn.Faction != null && (int)pawn.Faction.def.techLevel >= 3)) { if (pawn.Faction != faction) { pawn.SetFaction(faction); } } else if (pawn.Faction != null) { pawn.SetFaction(null); } }
public override void Arrived(Caravan caravan) { WorldObject_Competitions.PlayerPawn = caravan.pawns.InnerListForReading.First(x => x.skills.GetSkill(WorldObject_Competitions.CompetitionSkill).Level >= WorldObject_Competitions.CompetitionSkillLevelRequired); caravan.RemovePawn(WorldObject_Competitions.PlayerPawn); if (caravan.pawns.Count == 0) { Find.WorldObjects.Remove(caravan); } WorldObject_Competitions.StartCompetitions(); }
private void TryTransfer(Caravan caravan) { StringBuilder builder = new StringBuilder(); builder.Append("Quest_MissingPeople_End".Translate()); int saved = 0; foreach (var pawn in quest.SavedPawns) { if (caravan.ContainsPawn(pawn)) { caravan.RemovePawn(pawn); saved++; builder.AppendLine($"- {pawn.Name.ToStringFull}"); pawn.Destroy(); } } EndCondition condition = EndCondition.Success; if (saved == quest.SavedPawns.Count) { builder.Append("Quest_MissingPeople_EndFull".Translate(Quest.Faction.Name)); } else { if (saved == 0) { builder.Append("Quest_MissingPeople_Fiasko".Translate(Quest.Faction.Name)); condition = EndCondition.Fail; } else { builder.Append("Quest_MissingPeople_EndPart".Translate()); } } if (caravan.pawns.Count == 0) { Find.WorldObjects.Remove(caravan); } Find.LetterStack.ReceiveLetter("Quest_MissingPeople_EndQuest".Translate(), builder.ToString(), LetterDefOf.NeutralEvent); QuestSite site = (QuestSite)mapParent; site.EndQuest(caravan, condition); }
public override void Arrived(Caravan caravan) { for (int i = 0; i < quest.PawnsRequired; i++) { Pawn pawn = caravan.PawnsListForReading[i]; quest.EnteredPawns.Add(pawn); } foreach (var pawn in quest.EnteredPawns) { caravan.RemovePawn(pawn); } if (caravan.pawns.Count == 0) { Find.WorldObjects.Remove(caravan); } quest.Enter(); Find.LetterStack.ReceiveLetter("HelpStartedTitle".Translate(), "HelpStarted".Translate(quest.TicksToEnd.TicksToDays().ToString("f2")), LetterDefOf.PositiveEvent); }
private void TakeFromCaravan(Caravan caravan, List <ThingCount> demands, Faction enemyFaction) { List <Thing> list = new List <Thing>(); for (int i = 0; i < demands.Count; i++) { ThingCount thingCount = demands[i]; if (thingCount.Thing is Pawn) { Pawn pawn = (Pawn)thingCount.Thing; caravan.RemovePawn(pawn); foreach (Thing item in ThingOwnerUtility.GetAllThingsRecursively(pawn, allowUnreal: false)) { list.Add(item); item.holdingOwner.Take(item); } if (pawn.RaceProps.Humanlike) { enemyFaction.kidnapped.Kidnap(pawn, null); } else if (!Find.WorldPawns.Contains(pawn)) { Find.WorldPawns.PassToWorld(pawn); } } else { thingCount.Thing.SplitOff(thingCount.Count).Destroy(); } } for (int j = 0; j < list.Count; j++) { if (!list[j].Destroyed) { CaravanInventoryUtility.GiveThing(caravan, list[j]); } } }
/// <summary> /// Cleans up all references to the original human pawn after creating the animal pawn. <br /> /// This does not call Pawn.DeSpawn. /// </summary> public static void CleanUpHumanPawnPostTf([NotNull] Pawn originalPawn, [CanBeNull] Hediff cause) { if (originalPawn == null) { throw new ArgumentNullException(nameof(originalPawn)); } HandleApparelAndEquipment(originalPawn); if (cause != null) { originalPawn .health.RemoveHediff(cause); // Remove the hediff that caused the transformation so they don't transform again if reverted. } originalPawn.health.surgeryBills?.Clear(); //if this pawn has any additional surgery bills, get rid of them if (originalPawn.ownership.OwnedBed != null) // If the original pawn owned a bed somewhere... { originalPawn.ownership.UnclaimBed(); // ...unclaim it. } if (originalPawn.CarriedBy != null) // If the original pawn was being carried when they transformed... { Pawn carryingPawn = originalPawn.CarriedBy; Thing outPawn; carryingPawn.carryTracker.TryDropCarriedThing(carryingPawn.Position, ThingPlaceMode.Direct, out outPawn); // ...drop them so they can be removed. } if (originalPawn.IsPrisoner) { HandlePrisoner(originalPawn); } Caravan caravan = originalPawn.GetCaravan(); caravan?.RemovePawn(originalPawn); caravan?.Notify_PawnRemoved(originalPawn); // Make sure any current lords know they can't use this pawn anymore. originalPawn.GetLord()?.Notify_PawnLost(originalPawn, PawnLostCondition.IncappedOrKilled); //remove any jobs the pawn may be doing if (originalPawn.jobs != null && originalPawn.Map != null) { originalPawn.jobs.ClearQueuedJobs(); originalPawn.jobs.EndCurrentJob(JobCondition.InterruptForced); } if (originalPawn.Faction != Faction.OfPlayer) { return; //past here is only relevant for colonists } bool IsMasterOfOriginal(Pawn animalPawn) //function to find all animals our pawn is a master of { if (animalPawn.playerSettings != null) { return(animalPawn.playerSettings.Master == originalPawn); } return(false); } foreach (Pawn animalPawn in PawnsFinder.AllMapsWorldAndTemporary_Alive.Where(IsMasterOfOriginal)) { animalPawn.playerSettings.Master = null; //set to null, these animals don't have a master anymore } }
protected override bool TryCastShot() { bool result = false; CompAbilityUserMagic comp = this.CasterPawn.GetComp <CompAbilityUserMagic>(); Pawn soulPawn = comp.soulBondPawn; if (soulPawn != null && !soulPawn.Dead && !soulPawn.Destroyed) { if (ModCheck.Validate.GiddyUp.Core_IsInitialized()) { ModCheck.GiddyUp.ForceDismount(soulPawn); } bool drafted = soulPawn.Drafted; bool soulPawnSpawned = soulPawn.Spawned; Map map = soulPawn.Map; if (map == null) { Hediff bondHediff = soulPawn.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("TM_SoulBondPhysicalHD"), false); if (bondHediff != null) { HediffComp_SoulBondHost compS = bondHediff.TryGetComp <HediffComp_SoulBondHost>(); if (compS != null && compS.polyHost != null && !compS.polyHost.DestroyedOrNull() && !compS.polyHost.Dead) { soulPawnSpawned = true; soulPawn = compS.polyHost; } } bondHediff = soulPawn.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("TM_SoulBondMentalHD"), false); if (bondHediff != null) { HediffComp_SoulBondHost compS = bondHediff.TryGetComp <HediffComp_SoulBondHost>(); if (compS != null && compS.polyHost != null && !compS.polyHost.DestroyedOrNull() && !compS.polyHost.Dead) { soulPawnSpawned = true; soulPawn = compS.polyHost; } } if (soulPawn.ParentHolder != null && soulPawn.ParentHolder is Caravan) { //Log.Message("caravan detected"); //p.DeSpawn(); Caravan van = soulPawn.ParentHolder as Caravan; van.RemovePawn(soulPawn); GenPlace.TryPlaceThing(soulPawn, this.CasterPawn.Position, this.CasterPawn.Map, ThingPlaceMode.Near); if (van.PawnsListForReading != null && van.PawnsListForReading.Count <= 0) { CaravanEnterMapUtility.Enter(van, this.CasterPawn.Map, CaravanEnterMode.Center, CaravanDropInventoryMode.DropInstantly, false); } //Messages.Message("" + p.LabelShort + " has shadow stepped to a caravan with " + soulPawn.LabelShort, MessageTypeDefOf.NeutralEvent); goto fin; } } IntVec3 casterCell = this.CasterPawn.Position; IntVec3 targetCell = soulPawn.Position; if (soulPawnSpawned) { try { soulPawn.DeSpawn(); GenSpawn.Spawn(soulPawn, casterCell, this.CasterPawn.Map); if (drafted) { soulPawn.drafter.Drafted = true; } } catch { Log.Message("Exception occured when trying to summon soul bound pawn - recovered pawn at original position"); GenSpawn.Spawn(soulPawn, targetCell, map); } } else { Messages.Message("TM_BondedPawnNotSpawned".Translate( soulPawn.LabelShort), MessageTypeDefOf.RejectInput); } //this.Ability.PostAbilityAttempt(); result = true; } else { Log.Warning("No soul bond found to shadow call."); } fin :; this.burstShotsLeft = 0; //this.ability.TicksUntilCasting = (int)base.UseAbilityProps.SecondsToRecharge * 60; return(result); }