Exemple #1
0
        public static Command TradeCommand(Caravan caravan, Faction faction = null, TraderKindDef trader = null)
        {
            Pawn           bestNegotiator = BestCaravanPawnUtility.FindBestNegotiator(caravan, faction, trader);
            Command_Action command_Action = new Command_Action();

            command_Action.defaultLabel = "CommandTrade".Translate();
            command_Action.defaultDesc  = "CommandTradeDesc".Translate();
            command_Action.icon         = TradeCommandTex;
            command_Action.action       = delegate
            {
                Settlement settlement = SettlementVisitedNow(caravan);
                if (settlement != null && settlement.CanTradeNow)
                {
                    Find.WindowStack.Add(new Dialog_Trade(bestNegotiator, settlement));
                    PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter_Send(settlement.Goods.OfType <Pawn>(), "LetterRelatedPawnsTradingWithSettlement".Translate(Faction.OfPlayer.def.pawnsPlural), LetterDefOf.NeutralEvent);
                }
            };
            if (bestNegotiator == null)
            {
                if (trader != null && trader.permitRequiredForTrading != null && !caravan.PawnsListForReading.Any((Pawn p) => p.royalty != null && p.royalty.HasPermit(trader.permitRequiredForTrading, faction)))
                {
                    command_Action.Disable("CommandTradeFailNeedPermit".Translate(trader.permitRequiredForTrading.LabelCap));
                }
                else
                {
                    command_Action.Disable("CommandTradeFailNoNegotiator".Translate());
                }
            }
            if (bestNegotiator != null && bestNegotiator.skills.GetSkill(SkillDefOf.Social).TotallyDisabled)
            {
                command_Action.Disable("CommandTradeFailSocialDisabled".Translate());
            }
            return(command_Action);
        }
        public static string GenerateCaravanName(Caravan caravan)
        {
            Pawn arg_4D_0;

            if ((arg_4D_0 = BestCaravanPawnUtility.FindBestNegotiator(caravan)) == null)
            {
                arg_4D_0 = (BestCaravanPawnUtility.FindBestDiplomat(caravan) ?? caravan.PawnsListForReading.Find((Pawn x) => caravan.IsOwner(x)));
            }
            Pawn   pawn = arg_4D_0;
            string text = (pawn == null) ? caravan.def.label : "CaravanLeaderCaravanName".Translate(pawn.LabelShort, pawn).CapitalizeFirst();

            for (int i = 1; i <= 1000; i++)
            {
                string text2 = text;
                if (i != 1)
                {
                    text2 = text2 + " " + i;
                }
                if (!CaravanNameGenerator.CaravanNameInUse(text2))
                {
                    return(text2);
                }
            }
            Log.Error("Ran out of caravan names.", false);
            return(caravan.def.label);
        }
Exemple #3
0
        public override void Arrived(Caravan caravan)
        {
            CameraJumper.TryJumpAndSelect(caravan);
            Pawn playerNegotiator = BestCaravanPawnUtility.FindBestNegotiator(caravan);

            Find.WindowStack.Add(new Dialog_Trade(playerNegotiator, settlement, giftsOnly: true));
        }
        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);
        }
Exemple #5
0
        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
            {
                Settlement settlement = CaravanVisitUtility.SettlementVisitedNow(caravan);
                if (settlement != null && settlement.CanTradeNow)
                {
                    Find.WindowStack.Add(new Dialog_Trade(bestNegotiator, settlement));
                    string empty  = string.Empty;
                    string empty2 = string.Empty;
                    PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter(settlement.Goods.OfType <Pawn>(), ref empty, ref empty2, "LetterRelatedPawnsTradingWithSettlement".Translate(), false, true);
                    if (!empty2.NullOrEmpty())
                    {
                        Find.LetterStack.ReceiveLetter(empty, empty2, LetterDefOf.NeutralEvent, settlement, null);
                    }
                }
            };
            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);
        }
Exemple #6
0
        private static bool HasNegotiator(Caravan caravan, Settlement settlement)
        {
            Pawn pawn = BestCaravanPawnUtility.FindBestNegotiator(caravan, settlement.Faction, settlement.TraderKind);

            if (pawn != null)
            {
                return(!pawn.skills.GetSkill(SkillDefOf.Social).TotallyDisabled);
            }
            return(false);
        }
Exemple #7
0
        private static bool HasNegotiator(Caravan caravan)
        {
            Pawn pawn = BestCaravanPawnUtility.FindBestNegotiator(caravan);

            if (pawn != null)
            {
                return(!pawn.skills.GetSkill(SkillDefOf.Social).TotallyDisabled);
            }
            return(false);
        }
Exemple #8
0
        private string GetLetterText(string baseText, Caravan caravan)
        {
            string text = baseText;
            Pawn   pawn = BestCaravanPawnUtility.FindBestDiplomat(caravan);

            if (pawn != null)
            {
                text = text + "\n\n" + "PeaceTalksSocialXPGain".Translate(pawn.LabelShort, 6000f);
            }
            return(text);
        }
        private int TryGainRoyalFavor(Caravan caravan)
        {
            int num = 0;

            if (base.Faction.def.HasRoyalTitles)
            {
                num = DiplomacyTuning.RoyalFavor_PeaceTalksSuccessRange.RandomInRange;
                BestCaravanPawnUtility.FindBestDiplomat(caravan)?.royalty.GainFavor(base.Faction, num);
            }
            return(num);
        }
Exemple #10
0
        private string GetLetterText(string baseText, Caravan caravan, FactionRelationKind previousRelationKind)
        {
            string text = baseText;
            Pawn   pawn = BestCaravanPawnUtility.FindBestDiplomat(caravan);

            if (pawn != null)
            {
                text = text + "\n\n" + "PeaceTalksSocialXPGain".Translate(pawn.LabelShort, 6000f.ToString("F0"), pawn.Named("PAWN"));
            }
            base.Faction.TryAppendRelationKindChangedInfo(ref text, previousRelationKind, base.Faction.PlayerRelationKind);
            return(text);
        }
Exemple #11
0
 public static void Notify_CaravanMemberIngestedFood(Pawn p, float nutritionIngested)
 {
     if (!p.Dead && p.needs.joy != null)
     {
         if (nutritionIngested > 0f)
         {
             Pawn       pawn    = BestCaravanPawnUtility.FindBestEntertainingPawnFor(p.GetCaravan(), p);
             JoyKindDef joyKind = (pawn == null) ? JoyKindDefOf.Meditative : Rand.Element <JoyKindDef>(JoyKindDefOf.Meditative, JoyKindDefOf.Social);
             float      amount  = 0.2f * Mathf.Min(nutritionIngested / p.needs.food.MaxLevel, 1f);
             p.needs.joy.GainJoy(amount, joyKind);
         }
     }
 }
Exemple #12
0
        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);
        }
Exemple #13
0
 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));
         }
     });
 }
        private void DoRows(ref float curY, Rect scrollViewRect, Rect scrollOutRect)
        {
            List <Pawn> pawns = this.Pawns;
            Pawn        pawn  = BestCaravanPawnUtility.FindBestNegotiator(base.SelCaravan);

            GUI.color = new Color(0.8f, 0.8f, 0.8f, 1f);
            Widgets.Label(new Rect(0f, curY, scrollViewRect.width, 24f), string.Format("{0}: {1}", "Negotiator".Translate(), (pawn == null) ? "NoneCapable".Translate() : pawn.LabelShort));
            curY += 24f;
            if (this.specificSocialTabForPawn != null && !pawns.Contains(this.specificSocialTabForPawn))
            {
                this.specificSocialTabForPawn = null;
            }
            bool flag = false;

            for (int i = 0; i < pawns.Count; i++)
            {
                Pawn pawn2 = pawns[i];
                if (pawn2.RaceProps.IsFlesh)
                {
                    if (pawn2.IsColonist)
                    {
                        if (!flag)
                        {
                            Widgets.ListSeparator(ref curY, scrollViewRect.width, "CaravanColonists".Translate());
                            flag = true;
                        }
                        this.DoRow(ref curY, scrollViewRect, scrollOutRect, pawn2);
                    }
                }
            }
            bool flag2 = false;

            for (int j = 0; j < pawns.Count; j++)
            {
                Pawn pawn3 = pawns[j];
                if (pawn3.RaceProps.IsFlesh)
                {
                    if (!pawn3.IsColonist)
                    {
                        if (!flag2)
                        {
                            Widgets.ListSeparator(ref curY, scrollViewRect.width, "CaravanPrisonersAndAnimals".Translate());
                            flag2 = true;
                        }
                        this.DoRow(ref curY, scrollViewRect, scrollOutRect, pawn3);
                    }
                }
            }
        }
Exemple #15
0
        public static string GenerateCaravanName(Caravan caravan)
        {
            Pawn         pawn         = BestCaravanPawnUtility.FindBestNegotiator(caravan) ?? BestCaravanPawnUtility.FindBestDiplomat(caravan) ?? caravan.PawnsListForReading.Find((Pawn x) => caravan.IsOwner(x));
            TaggedString taggedString = (pawn != null) ? "CaravanLeaderCaravanName".Translate(pawn.LabelShort, pawn).CapitalizeFirst() : ((TaggedString)caravan.def.label);

            for (int i = 1; i <= 1000; i++)
            {
                TaggedString taggedString2 = taggedString;
                if (i != 1)
                {
                    taggedString2 += " " + i;
                }
                if (!CaravanNameInUse(taggedString2))
                {
                    return(taggedString2);
                }
            }
            Log.Error("Ran out of caravan names.");
            return(caravan.def.label);
        }
Exemple #16
0
        public static Pawn FindPawnWithBestStat(Caravan caravan, StatDef stat)
        {
            Pawn        pawn = null;
            float       num  = -1f;
            List <Pawn> pawnsListForReading = caravan.PawnsListForReading;

            for (int i = 0; i < pawnsListForReading.Count; i++)
            {
                Pawn pawn2 = pawnsListForReading[i];
                if (BestCaravanPawnUtility.IsConsciousOwner(pawn2, caravan) && !stat.Worker.IsDisabledFor(pawn2))
                {
                    float statValue = pawn2.GetStatValue(stat, true);
                    if (pawn == null || statValue > num)
                    {
                        pawn = pawn2;
                        num  = statValue;
                    }
                }
            }
            return(pawn);
        }
        public void Notify_CaravanArrived(Caravan caravan)
        {
            Pawn pawn = BestCaravanPawnUtility.FindBestDiplomat(caravan);

            if (pawn == null)
            {
                Messages.Message("MessagePeaceTalksNoDiplomat".Translate(), caravan, MessageTypeDefOf.NegativeEvent, false);
                return;
            }
            float badOutcomeWeightFactor = PeaceTalks.GetBadOutcomeWeightFactor(pawn);
            float num = 1f / badOutcomeWeightFactor;

            PeaceTalks.tmpPossibleOutcomes.Clear();
            PeaceTalks.tmpPossibleOutcomes.Add(new Pair <Action, float>(delegate()
            {
                this.Outcome_Disaster(caravan);
            }, 0.05f * badOutcomeWeightFactor));
            PeaceTalks.tmpPossibleOutcomes.Add(new Pair <Action, float>(delegate()
            {
                this.Outcome_Backfire(caravan);
            }, 0.1f * badOutcomeWeightFactor));
            PeaceTalks.tmpPossibleOutcomes.Add(new Pair <Action, float>(delegate()
            {
                this.Outcome_TalksFlounder(caravan);
            }, 0.2f));
            PeaceTalks.tmpPossibleOutcomes.Add(new Pair <Action, float>(delegate()
            {
                this.Outcome_Success(caravan);
            }, 0.55f * num));
            PeaceTalks.tmpPossibleOutcomes.Add(new Pair <Action, float>(delegate()
            {
                this.Outcome_Triumph(caravan);
            }, 0.1f * num));
            Action first = PeaceTalks.tmpPossibleOutcomes.RandomElementByWeight((Pair <Action, float> x) => x.Second).First;

            first();
            pawn.skills.Learn(SkillDefOf.Social, 6000f, true);
            Find.WorldObjects.Remove(this);
        }
        public void Notify_CaravanArrived(Caravan caravan)
        {
            Pawn pawn = BestCaravanPawnUtility.FindBestDiplomat(caravan);

            if (pawn == null)
            {
                Messages.Message("MessagePeaceTalksNoDiplomat".Translate(), caravan, MessageTypeDefOf.NegativeEvent, historical: false);
                return;
            }
            float badOutcomeWeightFactor = GetBadOutcomeWeightFactor(pawn);
            float num = 1f / badOutcomeWeightFactor;

            tmpPossibleOutcomes.Clear();
            tmpPossibleOutcomes.Add(new Pair <Action, float>(delegate
            {
                Outcome_Disaster(caravan);
            }, 0.05f * badOutcomeWeightFactor));
            tmpPossibleOutcomes.Add(new Pair <Action, float>(delegate
            {
                Outcome_Backfire(caravan);
            }, 0.1f * badOutcomeWeightFactor));
            tmpPossibleOutcomes.Add(new Pair <Action, float>(delegate
            {
                Outcome_TalksFlounder(caravan);
            }, 0.2f));
            tmpPossibleOutcomes.Add(new Pair <Action, float>(delegate
            {
                Outcome_Success(caravan);
            }, 0.55f * num));
            tmpPossibleOutcomes.Add(new Pair <Action, float>(delegate
            {
                Outcome_Triumph(caravan);
            }, 0.1f * num));
            tmpPossibleOutcomes.RandomElementByWeight((Pair <Action, float> x) => x.Second).First();
            pawn.skills.Learn(SkillDefOf.Social, 6000f, direct: true);
            QuestUtility.SendQuestTargetSignals(questTags, "Resolved", this.Named("SUBJECT"));
            Destroy();
        }
Exemple #19
0
        public static float GetCurrentJoyGainPerTick(Pawn pawn, Caravan caravan)
        {
            float result;

            if (caravan.pather.MovingNow)
            {
                result = 0f;
            }
            else
            {
                Pawn pawn2 = BestCaravanPawnUtility.FindBestEntertainingPawnFor(caravan, pawn);
                if (pawn2 == null)
                {
                    result = 0f;
                }
                else
                {
                    float statValue = pawn2.GetStatValue(StatDefOf.SocialImpact, true);
                    result = statValue * 0.035f / 2500f;
                }
            }
            return(result);
        }
Exemple #20
0
 public static Pawn FindBestDiplomat(Caravan caravan)
 {
     return(BestCaravanPawnUtility.FindPawnWithBestStat(caravan, StatDefOf.NegotiationAbility));
 }
Exemple #21
0
            internal void <> m__0()
            {
                Pawn playerNegotiator = BestCaravanPawnUtility.FindBestNegotiator(this.caravan);

                Find.WindowStack.Add(new Dialog_Trade(playerNegotiator, this.settlement, true));
            }
Exemple #22
0
 public static Pawn FindBestNegotiator(Caravan caravan)
 {
     return(BestCaravanPawnUtility.FindPawnWithBestStat(caravan, StatDefOf.TradePriceImprovement));
 }
Exemple #23
0
 public static Pawn FindBestDiplomat(Caravan caravan)
 {
     return(BestCaravanPawnUtility.FindPawnWithBestStat(caravan, StatDefOf.DiplomacyPower));
 }