public static int GetGoodwillChange(IEnumerable <IThingHolder> pods, SettlementBase giveTo) { float num = 0f; foreach (IThingHolder current in pods) { ThingOwner directlyHeldThings = current.GetDirectlyHeldThings(); for (int i = 0; i < directlyHeldThings.Count; i++) { float singlePrice; if (directlyHeldThings[i].def == ThingDefOf.Silver) { singlePrice = directlyHeldThings[i].MarketValue; } else { float priceFactorSell_TraderPriceType = (giveTo.TraderKind == null) ? 1f : giveTo.TraderKind.PriceTypeFor(directlyHeldThings[i].def, TradeAction.PlayerSells).PriceMultiplier(); float tradePriceImprovementOffsetForPlayer = giveTo.TradePriceImprovementOffsetForPlayer; singlePrice = TradeUtility.GetPricePlayerSell(directlyHeldThings[i], priceFactorSell_TraderPriceType, 1f, tradePriceImprovementOffsetForPlayer); } num += FactionGiftUtility.GetBaseGoodwillChange(directlyHeldThings[i], directlyHeldThings[i].stackCount, singlePrice, giveTo.Faction); } } return(FactionGiftUtility.PostProcessedGoodwillChange(num, giveTo.Faction)); }
public static bool IsPlayerAttackingAnySettlementOf(Faction faction) { bool result; if (faction == Faction.OfPlayer) { result = false; } else if (!faction.HostileTo(Faction.OfPlayer)) { result = false; } else { List <Map> maps = Find.Maps; for (int i = 0; i < maps.Count; i++) { SettlementBase settlementBase = maps[i].info.parent as SettlementBase; if (settlementBase != null && settlementBase.Faction == faction) { return(true); } } result = false; } return(result); }
public static Command TradeCommand(Caravan caravan) { Pawn bestNegotiator = BestCaravanPawnUtility.FindBestNegotiator(caravan); Command_Action command_Action = new Command_Action(); command_Action.defaultLabel = "CommandTrade".Translate(); command_Action.defaultDesc = "CommandTradeDesc".Translate(); command_Action.icon = CaravanVisitUtility.TradeCommandTex; command_Action.action = delegate { SettlementBase settlementBase = CaravanVisitUtility.SettlementVisitedNow(caravan); if (settlementBase != null && settlementBase.CanTradeNow) { Find.WindowStack.Add(new Dialog_Trade(bestNegotiator, settlementBase, false)); PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter_Send(settlementBase.Goods.OfType <Pawn>(), "LetterRelatedPawnsTradingWithSettlement".Translate(Faction.OfPlayer.def.pawnsPlural), LetterDefOf.NeutralEvent, false, true); } }; if (bestNegotiator == null) { command_Action.Disable("CommandTradeFailNoNegotiator".Translate()); } if (bestNegotiator != null && bestNegotiator.skills.GetSkill(SkillDefOf.Social).TotallyDisabled) { command_Action.Disable("CommandTradeFailSocialDisabled".Translate()); } return(command_Action); }
public static IEnumerable<FloatMenuOption> GetFloatMenuOptions(Caravan caravan, SettlementBase settlement) { return CaravanArrivalActionUtility.GetFloatMenuOptions<CaravanArrivalAction_AttackSettlement>(() => CaravanArrivalAction_AttackSettlement.CanAttack(caravan, settlement), () => new CaravanArrivalAction_AttackSettlement(settlement), "AttackSettlement".Translate(new object[] { settlement.Label }), caravan, settlement.Tile, settlement); }
public static void GiveGift(List <ActiveDropPodInfo> pods, SettlementBase giveTo) { int goodwillChange = FactionGiftUtility.GetGoodwillChange(pods.Cast <IThingHolder>(), giveTo); for (int i = 0; i < pods.Count; i++) { ThingOwner innerContainer = pods[i].innerContainer; for (int j = innerContainer.Count - 1; j >= 0; j--) { FactionGiftUtility.GiveGiftInternal(innerContainer[j], innerContainer[j].stackCount, giveTo.Faction); if (j < innerContainer.Count) { innerContainer.RemoveAt(j); } } } Faction faction = giveTo.Faction; Faction ofPlayer = Faction.OfPlayer; int goodwillChange2 = goodwillChange; string reason = "GoodwillChangedReason_ReceivedGift".Translate(); GlobalTargetInfo?lookTarget = new GlobalTargetInfo?(giveTo); if (!faction.TryAffectGoodwillWith(ofPlayer, goodwillChange2, true, true, reason, lookTarget)) { FactionGiftUtility.SendGiftNotAppreciatedMessage(giveTo.Faction, giveTo); } }
public static FloatMenuAcceptanceReport CanAttack(Caravan caravan, SettlementBase settlement) { if (settlement == null || !settlement.Spawned || !settlement.Attackable) { return(false); } if (settlement.EnterCooldownBlocksEntering()) { return(FloatMenuAcceptanceReport.WithFailMessage("MessageEnterCooldownBlocksEntering".Translate(settlement.EnterCooldownDaysLeft().ToString("0.#")))); } return(true); }
public static bool IsValidTileForNewSettlement(int tile, StringBuilder reason = null) { Tile tile2 = Find.WorldGrid[tile]; if (!tile2.biome.canBuildBase) { reason?.Append("CannotLandBiome".Translate(tile2.biome.LabelCap)); return(false); } if (!tile2.biome.implemented) { reason?.Append("BiomeNotImplemented".Translate() + ": " + tile2.biome.LabelCap); return(false); } if (tile2.hilliness == Hilliness.Impassable) { reason?.Append("CannotLandImpassableMountains".Translate()); return(false); } SettlementBase settlementBase = Find.WorldObjects.SettlementBaseAt(tile); if (settlementBase != null) { if (reason != null) { if (settlementBase.Faction == null) { reason.Append("TileOccupied".Translate()); } else if (settlementBase.Faction == Faction.OfPlayer) { reason.Append("YourBaseAlreadyThere".Translate()); } else { reason.Append("BaseAlreadyThere".Translate(settlementBase.Faction.Name)); } } return(false); } if (Find.WorldObjects.AnySettlementBaseAtOrAdjacent(tile)) { reason?.Append("FactionBaseAdjacent".Translate()); return(false); } if (Find.WorldObjects.AnyMapParentAt(tile) || Current.Game.FindMap(tile) != null || Find.WorldObjects.AnyWorldObjectOfDefAt(WorldObjectDefOf.AbandonedSettlement, tile)) { reason?.Append("TileOccupied".Translate()); return(false); } return(true); }
internal void <> m__0() { SettlementBase settlementBase = CaravanVisitUtility.SettlementVisitedNow(this.caravan); if (settlementBase != null && settlementBase.CanTradeNow) { Find.WindowStack.Add(new Dialog_Trade(this.bestNegotiator, settlementBase, false)); PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter_Send(settlementBase.Goods.OfType <Pawn>(), "LetterRelatedPawnsTradingWithSettlement".Translate(new object[] { Faction.OfPlayer.def.pawnsPlural }), LetterDefOf.NeutralEvent, false, true); } }
public static Command OfferGiftsCommand(Caravan caravan, SettlementBase settlement) { return(new Command_Action { defaultLabel = "CommandOfferGifts".Translate(), defaultDesc = "CommandOfferGiftsDesc".Translate(), icon = FactionGiftUtility.OfferGiftsCommandTex, action = delegate() { Pawn playerNegotiator = BestCaravanPawnUtility.FindBestNegotiator(caravan); Find.WindowStack.Add(new Dialog_Trade(playerNegotiator, settlement, true)); } }); }
public static Command OfferGiftsCommand(Caravan caravan, SettlementBase settlement) { Command_Action command_Action = new Command_Action(); command_Action.defaultLabel = "CommandOfferGifts".Translate(); command_Action.defaultDesc = "CommandOfferGiftsDesc".Translate(); command_Action.icon = OfferGiftsCommandTex; command_Action.action = delegate { Pawn playerNegotiator = BestCaravanPawnUtility.FindBestNegotiator(caravan); Find.WindowStack.Add(new Dialog_Trade(playerNegotiator, settlement, giftsOnly: true)); }; return(command_Action); }
public static void Attack(Caravan caravan, SettlementBase settlement) { if (!settlement.HasMap) { LongEventHandler.QueueLongEvent(delegate { AttackNow(caravan, settlement); }, "GeneratingMapForNewEncounter", doAsynchronously: false, null); } else { AttackNow(caravan, settlement); } }
public static void Attack(Caravan caravan, SettlementBase settlement) { if (!settlement.HasMap) { LongEventHandler.QueueLongEvent(delegate() { SettlementUtility.AttackNow(caravan, settlement); }, "GeneratingMapForNewEncounter", false, null); } else { SettlementUtility.AttackNow(caravan, settlement); } }
private static void AttackNow(Caravan caravan, SettlementBase settlement) { Pawn t = caravan.PawnsListForReading[0]; bool flag = !settlement.HasMap; Map orGenerateMap = GetOrGenerateMapUtility.GetOrGenerateMap(settlement.Tile, null); string letterLabel = "LetterLabelCaravanEnteredEnemyBase".Translate(); string letterText = "LetterCaravanEnteredEnemyBase".Translate(caravan.Label, settlement.Label).CapitalizeFirst(); AffectRelationsOnAttacked(settlement, ref letterText); if (flag) { Find.TickManager.Notify_GeneratedPotentiallyHostileMap(); PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter(orGenerateMap.mapPawns.AllPawns, ref letterLabel, ref letterText, "LetterRelatedPawnsSettlement".Translate(Faction.OfPlayer.def.pawnsPlural), informEvenIfSeenBefore: true); } Find.LetterStack.ReceiveLetter(letterLabel, letterText, LetterDefOf.NeutralEvent, t, settlement.Faction); CaravanEnterMapUtility.Enter(caravan, orGenerateMap, CaravanEnterMode.Edge, CaravanDropInventoryMode.DoNotDrop, draftColonists: true); }
public static int GetGoodwillChange(IEnumerable <IThingHolder> pods, SettlementBase giveTo) { float num = 0f; foreach (IThingHolder thingHolder in pods) { ThingOwner directlyHeldThings = thingHolder.GetDirectlyHeldThings(); for (int i = 0; i < directlyHeldThings.Count; i++) { float priceFactorSell_TraderPriceType = (giveTo.TraderKind == null) ? 1f : giveTo.TraderKind.PriceTypeFor(directlyHeldThings[i].def, TradeAction.PlayerSells).PriceMultiplier(); float tradePriceImprovementOffsetForPlayer = giveTo.TradePriceImprovementOffsetForPlayer; float pricePlayerSell = TradeUtility.GetPricePlayerSell(directlyHeldThings[i], priceFactorSell_TraderPriceType, 1f, tradePriceImprovementOffsetForPlayer); num += FactionGiftUtility.GetGoodwillChange(directlyHeldThings[i], directlyHeldThings[i].stackCount, pricePlayerSell, giveTo.Faction); } } return((int)num); }
public static SettlementBase SettlementVisitedNow(Caravan caravan) { if (!caravan.Spawned || caravan.pather.Moving) { return null; } List<SettlementBase> settlementBases = Find.WorldObjects.SettlementBases; for (int i = 0; i < settlementBases.Count; i++) { SettlementBase settlementBase = settlementBases[i]; if (settlementBase.Tile == caravan.Tile && settlementBase.Faction != caravan.Faction && settlementBase.Visitable) { return settlementBase; } } return null; }
public static void AffectRelationsOnAttacked(SettlementBase settlement, ref string letterText) { if (settlement.Faction != null && settlement.Faction != Faction.OfPlayer) { FactionRelationKind playerRelationKind = settlement.Faction.PlayerRelationKind; if (!settlement.Faction.HostileTo(Faction.OfPlayer)) { settlement.Faction.TrySetRelationKind(Faction.OfPlayer, FactionRelationKind.Hostile, canSendLetter: false); } else if (settlement.Faction.TryAffectGoodwillWith(Faction.OfPlayer, -50, canSendMessage: false, canSendHostilityLetter: false)) { if (!letterText.NullOrEmpty()) { letterText += "\n\n"; } letterText = letterText + "RelationsWith".Translate(settlement.Faction.Name) + ": " + (-50).ToStringWithSign(); } settlement.Faction.TryAppendRelationKindChangedInfo(ref letterText, playerRelationKind, settlement.Faction.PlayerRelationKind); } }
public static FloatMenuAcceptanceReport CanAttack(Caravan caravan, SettlementBase settlement) { FloatMenuAcceptanceReport result; if (settlement == null || !settlement.Spawned || !settlement.Attackable) { result = false; } else if (settlement.EnterCooldownBlocksEntering()) { result = FloatMenuAcceptanceReport.WithFailMessage("MessageEnterCooldownBlocksEntering".Translate(new object[] { settlement.EnterCooldownDaysLeft().ToString("0.#") })); } else { result = true; } return(result); }
private static void AttackNow(Caravan caravan, SettlementBase settlement) { Pawn t = caravan.PawnsListForReading[0]; bool flag = !settlement.HasMap; Map orGenerateMap = GetOrGenerateMapUtility.GetOrGenerateMap(settlement.Tile, null); string label = "LetterLabelCaravanEnteredEnemyBase".Translate(); string text = "LetterCaravanEnteredEnemyBase".Translate(new object[] { caravan.Label, settlement.Label }).CapitalizeFirst(); SettlementUtility.AffectRelationsOnAttacked(settlement, ref text); if (flag) { Find.TickManager.CurTimeSpeed = TimeSpeed.Paused; PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter(orGenerateMap.mapPawns.AllPawns, ref label, ref text, "LetterRelatedPawnsSettlement".Translate(new object[] { Faction.OfPlayer.def.pawnsPlural }), true, true); } Find.LetterStack.ReceiveLetter(label, text, LetterDefOf.NeutralEvent, t, settlement.Faction, null); CaravanEnterMapUtility.Enter(caravan, orGenerateMap, CaravanEnterMode.Edge, CaravanDropInventoryMode.DoNotDrop, true, null); }
public Settlement_TraderTracker(SettlementBase settlement) : base(settlement) { }
public static IEnumerable <FloatMenuOption> GetFloatMenuOptions(Caravan caravan, SettlementBase settlement) { return(CaravanArrivalActionUtility.GetFloatMenuOptions <CaravanArrivalAction_VisitSettlement>(() => CaravanArrivalAction_VisitSettlement.CanVisit(caravan, settlement), () => new CaravanArrivalAction_VisitSettlement(settlement), "VisitSettlement".Translate(settlement.Label), caravan, settlement.Tile, settlement)); }
public static FloatMenuAcceptanceReport CanVisit(Caravan caravan, SettlementBase settlement) { return(settlement != null && settlement.Spawned && settlement.Visitable); }
public CaravanArrivalAction_VisitSettlement(SettlementBase settlement) { this.settlement = settlement; }
public CaravanArrivalAction_AttackSettlement(SettlementBase settlement) { this.settlement = settlement; }
public static IEnumerable <FloatMenuOption> GetFloatMenuOptions(CompLaunchable representative, IEnumerable <IThingHolder> pods, SettlementBase settlement) { if (settlement.Faction == Faction.OfPlayer) { return(Enumerable.Empty <FloatMenuOption>()); } return(TransportPodsArrivalActionUtility.GetFloatMenuOptions <TransportPodsArrivalAction_GiveGift>(() => TransportPodsArrivalAction_GiveGift.CanGiveGiftTo(pods, settlement), () => new TransportPodsArrivalAction_GiveGift(settlement), "GiveGiftViaTransportPods".Translate(new object[] { settlement.Faction.Name, FactionGiftUtility.GetGoodwillChange(pods, settlement).ToStringWithSign() }), representative, settlement.Tile)); }
public static FloatMenuAcceptanceReport CanGiveGiftTo(IEnumerable <IThingHolder> pods, SettlementBase settlement) { return(settlement != null && settlement.Spawned && settlement.Faction != null && settlement.Faction != Faction.OfPlayer && !settlement.Faction.def.permanentEnemy && !settlement.HasMap); }
public TransportPodsArrivalAction_GiveGift(SettlementBase settlement) { this.settlement = settlement; }
public static IEnumerable <FloatMenuOption> GetFloatMenuOptions(Caravan caravan, SettlementBase settlement) { return(CaravanArrivalActionUtility.GetFloatMenuOptions <CaravanArrivalAction_OfferGifts>(() => CaravanArrivalAction_OfferGifts.CanOfferGiftsTo(caravan, settlement), () => new CaravanArrivalAction_OfferGifts(settlement), "OfferGifts".Translate(), caravan, settlement.Tile, settlement)); }
public static FloatMenuAcceptanceReport CanOfferGiftsTo(Caravan caravan, SettlementBase settlement) { return(settlement != null && settlement.Spawned && !settlement.HasMap && settlement.Faction != null && settlement.Faction != Faction.OfPlayer && !settlement.Faction.def.permanentEnemy && settlement.Faction.HostileTo(Faction.OfPlayer) && settlement.CanTradeNow && CaravanArrivalAction_OfferGifts.HasNegotiator(caravan)); }
public CaravanArrivalAction_OfferGifts(SettlementBase settlement) { this.settlement = settlement; }
public static IEnumerable <FloatMenuOption> GetFloatMenuOptions(CompLaunchable representative, IEnumerable <IThingHolder> pods, SettlementBase settlement) { return(TransportPodsArrivalActionUtility.GetFloatMenuOptions <TransportPodsArrivalAction_VisitSettlement>(() => TransportPodsArrivalAction_VisitSettlement.CanVisit(pods, settlement), () => new TransportPodsArrivalAction_VisitSettlement(settlement), "VisitSettlement".Translate(new object[] { settlement.Label }), representative, settlement.Tile)); }