public override void Arrived(List <ActiveDropPodInfo> pods, int tile) { for (int i = 0; i < pods.Count; i++) { for (int j = 0; j < pods[i].innerContainer.Count; j++) { Pawn pawn = pods[i].innerContainer[j] as Pawn; if (pawn != null) { if (pawn.RaceProps.Humanlike) { Pawn arg; if (pawn.HomeFaction == this.settlement.Faction) { GenGuest.AddHealthyPrisonerReleasedThoughts(pawn); } else if (PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_FreeColonists.TryRandomElement(out arg)) { Find.HistoryEventsManager.RecordEvent(new HistoryEvent(HistoryEventDefOf.SoldSlave, arg.Named(HistoryEventArgsNames.Doer)), true); } } else if (pawn.RaceProps.Animal && pawn.relations != null) { Pawn firstDirectRelationPawn = pawn.relations.GetFirstDirectRelationPawn(PawnRelationDefOf.Bond, null); if (firstDirectRelationPawn != null && firstDirectRelationPawn.needs.mood != null) { pawn.relations.RemoveDirectRelation(PawnRelationDefOf.Bond, firstDirectRelationPawn); firstDirectRelationPawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOf.SoldMyBondedAnimalMood, null, null); } } } } } FactionGiftUtility.GiveGift(pods, this.settlement); }
public bool TryExecute(out bool actuallyTraded) { bool result; if (TradeSession.giftMode) { this.UpdateCurrencyCount(); this.LimitCurrencyCountToFunds(); int goodwillChange = FactionGiftUtility.GetGoodwillChange(this.tradeables, TradeSession.trader.Faction); FactionGiftUtility.GiveGift(this.tradeables, TradeSession.trader.Faction, TradeSession.playerNegotiator); actuallyTraded = ((float)goodwillChange > 0f); result = true; } else if (this.SilverTradeable == null || this.SilverTradeable.CountPostDealFor(Transactor.Colony) < 0) { Find.WindowStack.WindowOfType <Dialog_Trade>().FlashSilver(); Messages.Message("MessageColonyCannotAfford".Translate(), MessageTypeDefOf.RejectInput, false); actuallyTraded = false; result = false; } else { this.UpdateCurrencyCount(); this.LimitCurrencyCountToFunds(); actuallyTraded = false; float num = 0f; foreach (Tradeable tradeable in this.tradeables) { if (tradeable.ActionToDo != TradeAction.None) { actuallyTraded = true; } if (tradeable.ActionToDo == TradeAction.PlayerSells) { num += tradeable.CurTotalSilverCostForDestination; } tradeable.ResolveTrade(); } this.Reset(); if (TradeSession.trader.Faction != null) { TradeSession.trader.Faction.Notify_PlayerTraded(num, TradeSession.playerNegotiator); } Pawn pawn = TradeSession.trader as Pawn; if (pawn != null) { TaleRecorder.RecordTale(TaleDefOf.TradedWith, new object[] { TradeSession.playerNegotiator, pawn }); } TradeSession.playerNegotiator.mindState.inspirationHandler.EndInspiration(InspirationDefOf.Inspired_Trade); result = true; } return(result); }
public static IEnumerable <FloatMenuOption> GetGIFTFloatMenuOptions(CompLaunchableHelicopter representative, IEnumerable <IThingHolder> pods, SettlementBase settlement, Caravan car) { if (settlement.Faction == Faction.OfPlayer) { return(Enumerable.Empty <FloatMenuOption>()); } return(HelicoptersArrivalActionUtility.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, car)); }
public static bool CheckAndSignalRelevantHandlers(TransportPodsArrivalAction_GiveGift __instance, List <ActiveDropPodInfo> pods) { var settlement = Traverse.Create(__instance).Field("settlement").GetValue <Settlement>(); var unused = DesynchronizedMain.ArrivalActionAndSenderLinker.SafelyGetMapOfGivenAction(__instance); foreach (var activeDropPodInfo in pods) { foreach (var thing in activeDropPodInfo.innerContainer) { if (!(thing is Pawn)) { } } } FactionGiftUtility.GiveGift(pods, settlement); // Original method need not be called. return(false); }
public static bool CheckAndSignalRelevantHandlers(TransportPodsArrivalAction_GiveGift __instance, List <ActiveDropPodInfo> pods) { Settlement settlement = Traverse.Create(__instance).Field("settlement").GetValue <Settlement>(); Map mapOfSender = DesynchronizedMain.ArrivalActionAndSenderLinker.SafelyGetMapOfGivenAction(__instance); for (int i = 0; i < pods.Count; i++) { for (int j = 0; j < pods[i].innerContainer.Count; j++) { Pawn pawn = pods[i].innerContainer[j] as Pawn; if (pawn == null) { continue; } } } FactionGiftUtility.GiveGift(pods, settlement); // Original method need not be called. return(false); }
public override void DoWindowContents(Rect inRect) { if (this.playerIsCaravan) { CaravanUIUtility.DrawCaravanInfo(new CaravanUIUtility.CaravanInfo(this.MassUsage, this.MassCapacity, this.cachedMassCapacityExplanation, this.TilesPerDay, this.cachedTilesPerDayExplanation, this.DaysWorthOfFood, this.ForagedFoodPerDay, this.cachedForagedFoodPerDayExplanation, this.Visibility, this.cachedVisibilityExplanation, -1f, -1f, null), null, this.Tile, null, -9999f, new Rect(12f, 0f, inRect.width - 24f, 40f), true, null, false); inRect.yMin += 52f; } TradeSession.deal.UpdateCurrencyCount(); GUI.BeginGroup(inRect); inRect = inRect.AtZero(); TransferableUIUtility.DoTransferableSorters(this.sorter1, this.sorter2, delegate(TransferableSorterDef x) { this.sorter1 = x; this.CacheTradeables(); }, delegate(TransferableSorterDef x) { this.sorter2 = x; this.CacheTradeables(); }); float num = inRect.width - 590f; Rect position = new Rect(num, 0f, inRect.width - num, 58f); GUI.BeginGroup(position); Text.Font = GameFont.Medium; Rect rect = new Rect(0f, 0f, position.width / 2f, position.height); Text.Anchor = TextAnchor.UpperLeft; Widgets.Label(rect, Faction.OfPlayer.Name.Truncate(rect.width, null)); Rect rect2 = new Rect(position.width / 2f, 0f, position.width / 2f, position.height); Text.Anchor = TextAnchor.UpperRight; string text = TradeSession.trader.TraderName; if (Text.CalcSize(text).x > rect2.width) { Text.Font = GameFont.Small; text = text.Truncate(rect2.width, null); } Widgets.Label(rect2, text); Text.Font = GameFont.Small; Text.Anchor = TextAnchor.UpperLeft; Rect rect3 = new Rect(0f, 27f, position.width / 2f, position.height / 2f); Widgets.Label(rect3, "Negotiator".Translate() + ": " + TradeSession.playerNegotiator.LabelShort); Text.Anchor = TextAnchor.UpperRight; Rect rect4 = new Rect(position.width / 2f, 27f, position.width / 2f, position.height / 2f); Widgets.Label(rect4, TradeSession.trader.TraderKind.LabelCap); Text.Anchor = TextAnchor.UpperLeft; if (!TradeSession.giftMode) { GUI.color = new Color(1f, 1f, 1f, 0.6f); Text.Font = GameFont.Tiny; Rect rect5 = new Rect(position.width / 2f - 100f - 30f, 0f, 200f, position.height); Text.Anchor = TextAnchor.LowerCenter; Widgets.Label(rect5, "PositiveBuysNegativeSells".Translate()); Text.Anchor = TextAnchor.UpperLeft; GUI.color = Color.white; } GUI.EndGroup(); float num2 = 0f; if (this.cachedCurrencyTradeable != null) { float num3 = inRect.width - 16f; Rect rect6 = new Rect(0f, 58f, num3, 30f); TradeUI.DrawTradeableRow(rect6, this.cachedCurrencyTradeable, 1); GUI.color = Color.gray; Widgets.DrawLineHorizontal(0f, 87f, num3); GUI.color = Color.white; num2 = 30f; } Rect mainRect = new Rect(0f, 58f + num2, inRect.width, inRect.height - 58f - 38f - num2 - 20f); this.FillMainRect(mainRect); Rect rect7 = new Rect(inRect.width / 2f - Dialog_Trade.AcceptButtonSize.x / 2f, inRect.height - 55f, Dialog_Trade.AcceptButtonSize.x, Dialog_Trade.AcceptButtonSize.y); if (Widgets.ButtonText(rect7, (!TradeSession.giftMode) ? "AcceptButton".Translate() : ("OfferGifts".Translate() + " (" + FactionGiftUtility.GetGoodwillChange(TradeSession.deal.AllTradeables, TradeSession.trader.Faction).ToStringWithSign() + ")"), true, false, true)) { Action action = delegate { bool flag; if (TradeSession.deal.TryExecute(out flag)) { if (flag) { SoundDefOf.ExecuteTrade.PlayOneShotOnCamera(null); this.Close(false); } else { this.Close(true); } } }; if (TradeSession.deal.DoesTraderHaveEnoughSilver()) { action(); } else { this.FlashSilver(); SoundDefOf.ClickReject.PlayOneShotOnCamera(null); Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmTraderShortFunds".Translate(), action, false, null)); } Event.current.Use(); } Rect rect8 = new Rect(rect7.x - 10f - Dialog_Trade.OtherBottomButtonSize.x, rect7.y, Dialog_Trade.OtherBottomButtonSize.x, Dialog_Trade.OtherBottomButtonSize.y); if (Widgets.ButtonText(rect8, "ResetButton".Translate(), true, false, true)) { SoundDefOf.Tick_Low.PlayOneShotOnCamera(null); TradeSession.deal.Reset(); this.CacheTradeables(); this.CountToTransferChanged(); } Rect rect9 = new Rect(rect7.xMax + 10f, rect7.y, Dialog_Trade.OtherBottomButtonSize.x, Dialog_Trade.OtherBottomButtonSize.y); if (Widgets.ButtonText(rect9, "CancelButton".Translate(), true, false, true)) { this.Close(true); Event.current.Use(); } float y = Dialog_Trade.OtherBottomButtonSize.y; Rect rect10 = new Rect(inRect.width - y, rect7.y, y, y); if (Widgets.ButtonImageWithBG(rect10, Dialog_Trade.ShowSellableItemsIcon, new Vector2?(new Vector2(32f, 32f)))) { Find.WindowStack.Add(new Dialog_SellableItems(TradeSession.trader.TraderKind)); } TooltipHandler.TipRegion(rect10, "CommandShowSellableItemsDesc".Translate()); Faction faction = TradeSession.trader.Faction; if (faction != null && !this.giftsOnly && !faction.def.permanentEnemy) { Rect rect11 = new Rect(rect10.x - y - 4f, rect7.y, y, y); if (TradeSession.giftMode) { if (Widgets.ButtonImageWithBG(rect11, Dialog_Trade.TradeModeIcon, new Vector2?(new Vector2(32f, 32f)))) { TradeSession.giftMode = false; TradeSession.deal.Reset(); this.CacheTradeables(); this.CountToTransferChanged(); SoundDefOf.Tick_High.PlayOneShotOnCamera(null); } TooltipHandler.TipRegion(rect11, "TradeModeTip".Translate()); } else { if (Widgets.ButtonImageWithBG(rect11, Dialog_Trade.GiftModeIcon, new Vector2?(new Vector2(32f, 32f)))) { TradeSession.giftMode = true; TradeSession.deal.Reset(); this.CacheTradeables(); this.CountToTransferChanged(); SoundDefOf.Tick_High.PlayOneShotOnCamera(null); } TooltipHandler.TipRegion(rect11, "GiftModeTip".Translate(faction.Name)); } } GUI.EndGroup(); }
public static IEnumerable <FloatMenuOption> GetFloatMenuOptions(CompLaunchablePawn representative, IEnumerable <IThingHolder> pods, Settlement settlement) { if (settlement.Faction == Faction.OfPlayer) { return(Enumerable.Empty <FloatMenuOption>()); } return(ByakheeArrivalActionUtility.GetFloatMenuOptions <ByakheeArrivalAction_GiveGift>(() => ByakheeArrivalAction_GiveGift.CanGiveGiftTo(pods, settlement), () => new ByakheeArrivalAction_GiveGift(settlement), "GiveGiftViaTransportPods".Translate(settlement.Faction.Name, FactionGiftUtility.GetGoodwillChange(pods, settlement).ToStringWithSign()), representative, settlement.Tile, delegate(Action action) { TradeRequestComp tradeReqComp = settlement.GetComponent <TradeRequestComp>(); if (tradeReqComp.ActiveRequest && pods.Any((IThingHolder p) => p.GetDirectlyHeldThings().Contains(tradeReqComp.requestThingDef))) { Find.WindowStack.Add(new Dialog_MessageBox("GiveGiftViaTransportPodsTradeRequestWarning".Translate(), "Yes".Translate(), delegate() { action(); }, "No".Translate(), null, null, false, null, null, WindowLayer.Dialog)); return; } action(); })); }
public override void DoWindowContents(Rect inRect) { TradeSession.deal.UpdateCurrencyCount(); GUI.BeginGroup(inRect); inRect = inRect.AtZero(); TransferableUIUtility.DoTransferableSorters(sorter1, sorter2, delegate(TransferableSorterDef x) { sorter1 = x; CacheTradeables(); }, delegate(TransferableSorterDef x) { sorter2 = x; CacheTradeables(); }); Text.Font = GameFont.Small; Text.Anchor = TextAnchor.UpperLeft; Widgets.Label(new Rect(0f, SpaceBetweenTraderNameAndTraderKind, inRect.width / 2f, inRect.height / 2f), "NegotiatorTradeDialogInfo".Translate(TradeSession.playerNegotiator.Name.ToStringFull, TradeSession.playerNegotiator.GetStatValue(StatDefOf.TradePriceImprovement, true).ToStringPercent())); float num = inRect.width - 590f; Rect position = new Rect(num, 0f, inRect.width - num, TopAreaHeight); GUI.BeginGroup(position); Text.Font = GameFont.Medium; Rect rect = new Rect(0f, 0f, position.width / 2f, position.height); Text.Anchor = TextAnchor.UpperLeft; Widgets.Label(rect, Faction.OfPlayer.Name.Truncate(rect.width, null)); Rect rect2 = new Rect(position.width / 2f, 0f, position.width / 2f, position.height); Text.Anchor = TextAnchor.UpperRight; string text = TradeSession.trader.TraderName; if (Text.CalcSize(text).x > rect2.width) { Text.Font = GameFont.Small; text = text.Truncate(rect2.width, null); } Widgets.Label(rect2, text); Text.Font = GameFont.Small; Text.Anchor = TextAnchor.UpperRight; Widgets.Label(new Rect(position.width / 2f, SpaceBetweenTraderNameAndTraderKind, position.width / 2f, position.height / 2f), TradeSession.trader.TraderKind.LabelCap); Text.Anchor = TextAnchor.UpperLeft; if (!TradeSession.giftMode) { GUI.color = new Color(1f, 1f, 1f, 0.6f); Text.Font = GameFont.Tiny; Rect rect3 = new Rect(position.width / 2f - 100f - RowInterval, 0f, 200f, position.height); Text.Anchor = TextAnchor.LowerCenter; Widgets.Label(rect3, "PositiveBuysNegativeSells".Translate()); Text.Anchor = TextAnchor.UpperLeft; GUI.color = Color.white; } GUI.EndGroup(); float num2 = 0f; if (cachedCurrencyTradeable != null) { float num3 = inRect.width - 16f; TradeUI.DrawTradeableRow(new Rect(0f, TopAreaHeight, num3, RowInterval), cachedCurrencyTradeable, 1); GUI.color = Color.gray; Widgets.DrawLineHorizontal(0f, 87f, num3); GUI.color = Color.white; num2 = RowInterval; } Rect mainRect = new Rect(0f, TopAreaHeight + num2, inRect.width, inRect.height - TopAreaHeight - 38f - num2 - 20f); FillMainRect(mainRect); Rect rect4 = new Rect(inRect.width / 2f - AcceptButtonSize.x / 2f, inRect.height - 55f, AcceptButtonSize.x, AcceptButtonSize.y); if (Widgets.ButtonText(rect4, TradeSession.giftMode ? ("OfferGifts".Translate() + " (" + FactionGiftUtility.GetGoodwillChange(TradeSession.deal.AllTradeables, TradeSession.trader.Faction).ToStringWithSign() + ")") : "AcceptButton".Translate(), true, true, true)) { void action() { if (TradeSession.deal.TryExecute(out bool flag)) { if (flag) { SoundDefOf.ExecuteTrade.PlayOneShotOnCamera(null); Close(false); return; } Close(true); } } if (TradeSession.deal.DoesTraderHaveEnoughSilver()) { action(); } else { FlashSilver(); SoundDefOf.ClickReject.PlayOneShotOnCamera(null); Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmTraderShortFunds".Translate(), action, false, null)); } Event.current.Use(); } if (Widgets.ButtonText(new Rect(rect4.x - 10f - OtherBottomButtonSize.x, rect4.y, OtherBottomButtonSize.x, OtherBottomButtonSize.y), "ResetButton".Translate(), true, true, true)) { SoundDefOf.Tick_Low.PlayOneShotOnCamera(null); TradeSession.deal.Reset(); CacheTradeables(); CountToTransferChanged(); } if (Widgets.ButtonText(new Rect(rect4.xMax + 10f, rect4.y, OtherBottomButtonSize.x, OtherBottomButtonSize.y), "CancelButton".Translate(), true, true, true)) { this.Close(true); Event.current.Use(); } float y = OtherBottomButtonSize.y; Rect rect5 = new Rect(inRect.width - y, rect4.y, y, y); if (Widgets.ButtonImageWithBG(rect5, ShowSellableItemsIcon, new Vector2?(new Vector2(ShowSellableItemsIconSize, ShowSellableItemsIconSize)))) { Find.WindowStack.Add(new Dialog_SellableItems(TradeSession.trader)); } TooltipHandler.TipRegionByKey(rect5, "CommandShowSellableItemsDesc"); Faction faction = TradeSession.trader.Faction; if (faction != null && !giftsOnly && !faction.def.permanentEnemy) { Rect rect6 = new Rect(rect5.x - y - 4f, rect4.y, y, y); if (TradeSession.giftMode) { if (Widgets.ButtonImageWithBG(rect6, TradeModeIcon, new Vector2?(new Vector2(TradeModeIconSize, TradeModeIconSize)))) { TradeSession.giftMode = false; TradeSession.deal.Reset(); CacheTradeables(); CountToTransferChanged(); SoundDefOf.Tick_High.PlayOneShotOnCamera(null); } TooltipHandler.TipRegionByKey(rect6, "TradeModeTip"); } else { if (Widgets.ButtonImageWithBG(rect6, GiftModeIcon, new Vector2?(new Vector2(GiftModeIconSize, GiftModeIconSize)))) { TradeSession.giftMode = true; TradeSession.deal.Reset(); CacheTradeables(); CountToTransferChanged(); SoundDefOf.Tick_High.PlayOneShotOnCamera(null); } TooltipHandler.TipRegionByKey(rect6, "GiftModeTip", faction.Name); } } GUI.EndGroup(); }