public static void GiveGift(List <Pawn> possibleGivers, Faction faction) { if (possibleGivers.NullOrEmpty <Pawn>()) { return; } Pawn pawn = null; for (int i = 0; i < possibleGivers.Count; i++) { if (possibleGivers[i].RaceProps.Humanlike && possibleGivers[i].Faction == faction) { pawn = possibleGivers[i]; break; } } if (pawn == null) { for (int j = 0; j < possibleGivers.Count; j++) { if (possibleGivers[j].Faction == faction) { pawn = possibleGivers[j]; break; } } } if (pawn == null) { pawn = possibleGivers[0]; } List <Thing> list = VisitorGiftForPlayerUtility.GenerateGifts(faction, pawn.Map); TargetInfo target = TargetInfo.Invalid; for (int k = 0; k < list.Count; k++) { if (GenPlace.TryPlaceThing(list[k], pawn.Position, pawn.Map, ThingPlaceMode.Near, null, null)) { target = list[k]; } else { list[k].Destroy(DestroyMode.Vanish); } } if (target.IsValid) { LetterStack arg_1B1_0 = Find.LetterStack; string arg_1B1_1 = "LetterLabelVisitorsGaveGift".Translate(new object[] { pawn.Faction.Name }); string arg_193_0 = "LetterVisitorsGaveGift"; object[] expr_150 = new object[2]; expr_150[0] = pawn.Faction.def.pawnsPlural; expr_150[1] = (from g in list select g.LabelCap).ToLineList(" -"); arg_1B1_0.ReceiveLetter(arg_1B1_1, arg_193_0.Translate(expr_150).AdjustedFor(pawn, "PAWN"), LetterDefOf.PositiveEvent, target, faction, null); } }
public static void CheckGiveGift(List <Pawn> pawns, Faction faction) { if (pawns.Any <Pawn>()) { Pawn pawn = null; for (int i = 0; i < pawns.Count; i++) { if (pawns[i].RaceProps.Humanlike && pawns[i].Faction == faction) { pawn = pawns[i]; break; } } if (pawn == null) { for (int j = 0; j < pawns.Count; j++) { if (pawns[j].Faction == faction) { pawn = pawns[j]; break; } } } if (pawn == null) { pawn = pawns[0]; } List <Thing> list = VisitorGiftForPlayerUtility.GenerateGifts(faction, pawn.Map); TargetInfo target = TargetInfo.Invalid; for (int k = 0; k < list.Count; k++) { if (GenPlace.TryPlaceThing(list[k], pawn.Position, pawn.Map, ThingPlaceMode.Near, null, null)) { target = list[k]; } else { list[k].Destroy(DestroyMode.Vanish); } } if (target.IsValid) { Find.LetterStack.ReceiveLetter("LetterLabelVisitorsGaveGift".Translate(), "LetterVisitorsGaveGift".Translate(), LetterDefOf.PositiveEvent, target, faction, null); } } }