Esempio n. 1
0
 static void Postfix(ref bool __result, IncidentParms parms)
 {
     if (__result && parms != null)
     {
         Map map = parms.target as Map;
         if (map != null)
         {
             if (map.ParentFaction != null)
             {
                 FactionInteraction inter = QuestsManager.Communications.FactionManager.GetInteraction(map.ParentFaction);
                 if (inter != null)
                 {
                     Alliance alliance = inter.Alliance;
                     if (alliance != null && alliance.AllianceAgreements != null)
                     {
                         DefenseContractComp defenseContractComp = alliance.AllianceAgreements.FirstOrDefault(x => x is DefenseContractComp) as DefenseContractComp;
                         if (defenseContractComp != null)
                         {
                             if (defenseContractComp.OwnerFaction != null && defenseContractComp.OwnerFaction == inter)
                             {
                                 defenseContractComp.SendHelp(parms);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
0
        public static void AddComponentWithStack(Faction faction, int addCount)
        {
            FactionInteraction interaction = QuestsManager.Communications.FactionManager.GetInteraction(faction);

            if (interaction == null)
            {
                Log.Warning("[CommOption_GetHelp] Faction not found.");
                return;
            }

            if (interaction.Options == null)
            {
                Log.Warning("[CommOption_GetHelp] Interaction is null. Init.");
                interaction.Options = QuestsManager.Communications.FactionManager.StandartOptions(faction);
            }

            foreach (var option in interaction.Options)
            {
                if (option is CommOption_GetHelp optionGetHelp)
                {
                    optionGetHelp.HelpCount += addCount;

                    if (optionGetHelp.HelpCount < 0)
                    {
                        optionGetHelp.HelpCount = 0;
                    }

                    return;
                }
            }

            CommOption_GetHelp getHelp = new CommOption_GetHelp(addCount);

            interaction.Options.Add(getHelp);
        }
Esempio n. 3
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Alliance alliance = parms.target as Alliance;

            if (alliance.Factions.Count == 0)
            {
                return(false);
            }

            FactionInteraction factionInteraction = alliance.Factions.RandomElement();

            if (!Find.WorldObjects.Settlements.Where(x => x.Faction == factionInteraction.Faction &&
                                                     CaravanArrivalTimeEstimator.EstimatedTicksToArrive(Find.AnyPlayerHomeMap.Tile, x.Tile, null).TicksToDays() < 7).TryRandomElement(out Settlement settlement))
            {
                return(false);
            }

            var research     = Find.ResearchManager.currentProj;
            int pointsReward = (int)((research.baseCost - Find.ResearchManager.GetProgress(research)) * 0.3f);
            Alliance_Quest_ResearchSharing quest = new Alliance_Quest_ResearchSharing(factionInteraction.Faction, SkillDef, pointsReward);

            quest.id          = QuestsManager.Communications.UniqueIdManager.GetNextQuestID();
            quest.TicksToPass = 6 * 60000;
            quest.IncidentDef = def;
            QuestSite questSite = quest.CreateSiteFor(settlement.Tile, quest.Faction);

            Find.WorldObjects.Add(questSite);

            QuestsManager.Communications.AddQuest(quest, null);

            SendStandardLetter(parms, questSite, factionInteraction.Faction.Name, pointsReward.ToString());

            return(true);
        }
        public TradeSchedulingAgreementComp(Alliance alliance, FactionInteraction signer, List <Thing> items, Settlement settlement, Map destination, int ticksDelay, int formCaravanDelay)
        {
            AllianceAgreementDef = AllianceAgreementDefOfLocal.TradeSchedulingAgreement;

            PlayerOwner   = true;
            OwnerFaction  = QuestsManager.Communications.FactionManager.GetInteraction(Faction.OfPlayer);
            SignedFaction = signer;
            Items         = items;
            SignTicks     = Find.TickManager.TicksGame;
            EndTicks      = SignTicks + ticksDelay;
            Alliance      = alliance;

            DestinationMap = destination;

            Settlement = settlement;

            int factionTechLevel = (int)SignedFaction.Faction.def.techLevel;

            if (factionTechLevel < 3)
            {
                formCaravanTicks = SignTicks + (int)(formCaravanDelay * 0.97f); //because end so early

                UsedCaravan = true;
            }
            else
            {
                Items.ForEach(x =>
                {
                    if (x is Pawn pawn)
                    {
                        Find.WorldPawns.RemovePawn(pawn);
                    }
                });
            }
        }
Esempio n. 5
0
        public FactionArmy(FactionInteraction factionInteraction, War war, bool useForGenerator)
        {
            Faction         = factionInteraction;
            UseForGenerator = useForGenerator;
            War             = war;

            lastGiveOrderTicks = new Dictionary <ArmyOrderDef, int>();
        }
Esempio n. 6
0
        public static bool Prefix(Faction __instance, Faction other, int goodwillChange)
        {
            FactionInteraction first  = QuestsManager.Communications.FactionManager.GetInteraction(__instance);
            FactionInteraction second = QuestsManager.Communications.FactionManager.GetInteraction(other);

            var war = first.FirstWarWith(second);

            return(war == null);
        }
Esempio n. 7
0
        public DefenseContractComp(Alliance alliance, FactionInteraction signer, FactionInteraction owner, FightersLevel fightersLevel, int daysDuration)
        {
            AllianceAgreementDef = AllianceAgreementDefOfLocal.DefenseContractAgreement;
            Alliance             = alliance;

            SignedFaction      = signer;
            OwnerFaction       = owner;
            SignTicks          = Find.TickManager.TicksGame;
            EndTicks           = Find.TickManager.TicksGame + (daysDuration * 60000);
            this.fightersLevel = fightersLevel;
        }
        public void SelectNewFaction(FactionInteraction faction)
        {
            factionInteraction = faction;

            factionSettlements = Find.WorldObjects.Settlements.Where(x => x.Faction == factionInteraction.Faction)
                                 .ToDictionary(k => k, v => CaravanArrivalTimeEstimator.EstimatedTicksToArrive(Find.AnyPlayerHomeMap.Tile, v.Tile, null).TicksToDays());

            SelectNewSettlement(factionSettlements.First().Key);

            UpdateDeliveryMethod();
        }
Esempio n. 9
0
    private ReadOnlyDictionary <Faction, FactionInteraction> CreateFactionInteractions(IEnumerable <FactionUnityObject> objects)
    {
        Dictionary <Faction, FactionInteraction> ret = new Dictionary <Faction, FactionInteraction>();

        foreach (FactionUnityObject obj in objects)
        {
            FactionInteraction interaction = new FactionInteraction(this, obj.Faction);
            obj.gameObject.GetComponent <Button>().onClick.AddListener(() => OnFactionClick(obj.Faction));
            ret.Add(obj.Faction, interaction);
        }
        return(new ReadOnlyDictionary <Faction, FactionInteraction>(ret));
    }
        public DefenseContractCompWindow(Alliance alliance, DefenseContractCompProperties defenseContractCompProperties, Pawn negotiator)
        {
            this.alliance = alliance;
            this.defenseContractCompProperties = defenseContractCompProperties;
            this.negotiator = negotiator;

            fightersType = FightersLevel.RegularFighers;
            faction      = alliance.Factions.FirstOrDefault();

            doCloseX   = true;
            forcePause = true;

            contractDaysDuration = minContractDays;
        }
Esempio n. 11
0
 public FactionDisplay(FactionInteraction factionInteraction,
                       UnityObjectManager objectManager,
                       FactionsInteractionManager interactionManager,
                       MapInteraction mapInteraction)
 {
     _objectManager          = objectManager;
     _mapInteraction         = mapInteraction;
     _unityObject            = objectManager.GetUnityObject(factionInteraction.Faction);;
     Faction                 = _unityObject.Faction;
     _unityObject.Text.text  = Faction.Name;
     _unityObject.Text.color = Faction.Color;
     _interactionManager     = interactionManager;
     _factionInteraction     = factionInteraction;
     _orderIndicators        = objectManager.GetOrderIndicatorsFor(factionInteraction.Faction).ToList().AsReadOnly();
 }
Esempio n. 12
0
        public override void DoAction(FactionInteraction interaction, Pawn speaker, Pawn defendant)
        {
            if (HelpCount == 0)
            {
                return;
            }

            this.interaction = interaction;
            this.speaker     = speaker;

            Dialog dialog = new Dialog(DialogDefOfLocal.CommOptionGetHelp, speaker);

            dialog.Init();
            dialog.CloseAction = CheckAnswer;
            Find.WindowStack.Add(dialog);
        }
        public static void Postfix(Faction __instance, Faction other)
        {
            if (__instance == Faction.OfPlayer)
            {
                Alliance alliance = QuestsManager.Communications.FactionManager.PlayerAlliance;

                if (alliance != null)
                {
                    alliance.SynchonizeOwnerRelations(__instance.RelationKindWith(other), other);

                    if (other.RelationKindWith(__instance) == FactionRelationKind.Hostile && alliance.Factions.Contains(other))
                    {
                        FactionInteraction factionInteraction = alliance.Factions.FirstOrDefault(x => x.Faction == other);
                        if (factionInteraction != null)
                        {
                            alliance.RemoveFaction(factionInteraction, AllianceRemoveReason.LowTrust);
                        }
                    }
                }
            }
        }
        public override bool CanUse(Pawn p, DialogOption option = null)
        {
            FactionInteraction interaction = QuestsManager.Communications.FactionManager.GetInteraction(p.Faction);

            if (interaction != null)
            {
                Alliance alliance = interaction.Alliance;
                if (alliance != null)
                {
                    if (alliance.FactionOwner == interaction.Faction)
                    {
                        if (alliance.Factions.Count >= MinMembers)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
 static void Postfix(ref bool __result, IncidentParms parms)
 {
     if (parms.faction != null)
     {
         FactionInteraction interaction = QuestsManager.Communications.FactionManager.GetInteraction(parms.faction);
         if (interaction != null)
         {
             var war = interaction.FirstWarWithPlayer();
             if (war != null)
             {
                 __result = true;
             }
             else
             {
                 var option = interaction.GetOption <CommOption_NonAgressionPact>();
                 if (option != null)
                 {
                     __result = !option.Signed;
                 }
             }
         }
     }
 }
Esempio n. 16
0
 public UpgradeIntention(FactionInteraction source)
 {
     _source = source;
 }
        public override void DoWindowContents(Rect inRect)
        {
            float y = inRect.y + 10;

            Text.Anchor = TextAnchor.MiddleCenter;
            Rect selectFactionRect = new Rect(0, y, inRect.width, 25);

            if (GUIUtils.DrawCustomButton(selectFactionRect, "DefenseContractCompWindow_SelectFaction".Translate(faction.Faction.Name), Color.white))
            {
                List <FloatMenuOption> opt = new List <FloatMenuOption>();
                foreach (var f in alliance.Factions)
                {
                    opt.Add(new FloatMenuOption($"{f.Faction.Name} {((int)f.Faction.def.techLevel < (int)defenseContractCompProperties.MinFactionTechLevel ? "DefenseContractCompWindow_LowTechLevel".Translate().ToString() : "")}", () => { if ((int)f.Faction.def.techLevel > (int)defenseContractCompProperties.MinFactionTechLevel)
                                                                                                                                                                                                                                              {
                                                                                                                                                                                                                                                  faction = f;
                                                                                                                                                                                                                                              }
                                                }));
                }
                Find.WindowStack.Add(new FloatMenu(opt));
            }
            y += 30;
            Rect durationLabelRect = new Rect(0, y, inRect.width, 30);

            Widgets.Label(durationLabelRect, "DefenseContractCompWindow_ContractDuration".Translate());
            durationLabelRect.y += 30;
            Widgets.IntEntry(durationLabelRect, ref contractDaysDuration, ref contractDaysDurationBuff);
            if (contractDaysDuration < minContractDays)
            {
                ResetBufferTo(minContractDays, ref contractDaysDuration, ref contractDaysDurationBuff);
            }
            else if (contractDaysDuration > maxContractDays)
            {
                ResetBufferTo(maxContractDays, ref contractDaysDuration, ref contractDaysDurationBuff);
            }

            y = 100;
            Rect costRangeRect = new Rect(0, y, inRect.width, 25);

            Widgets.Label(costRangeRect, "DefenseContractCompWindow_CostRangeSlider".Translate());
            costRangeRect.y += 28;
            if (GUIUtils.DrawCustomButton(costRangeRect, fightersType.ToStringHuman(), Color.white))
            {
                List <FloatMenuOption> opt = new List <FloatMenuOption>();
                foreach (FightersLevel f in Enum.GetValues(typeof(FightersLevel)))
                {
                    opt.Add(new FloatMenuOption(f.ToStringHuman(), () => fightersType = f));
                }
                Find.WindowStack.Add(new FloatMenu(opt));
            }
            y += 60;
            Rect generateButtonRect = new Rect(0, y, inRect.width, 25);

            if (GUIUtils.DrawCustomButton(generateButtonRect, "DefenseContractCompWindow_ShowExamplePawns".Translate(), Color.white))
            {
                GenerateAndSelectPawns();
            }
            y += 30;
            Widgets.DrawLineHorizontal(0, y, inRect.width);
            y += 35;
            Rect  pawnRect   = new Rect(0, y, 100, 140);
            float weaponY    = pawnRect.y + 135;
            Rect  weaponRect = new Rect(0, weaponY, 100, 100);

            foreach (var pawn in generatedPawns)
            {
                Widgets.ThingIcon(pawnRect, pawn);
                if (pawn.equipment != null && pawn.equipment.Primary != null)
                {
                    Widgets.ThingIcon(weaponRect, pawn.equipment.Primary);
                }

                weaponRect.x += 110;
                pawnRect.x   += 110;
            }

            Text.Anchor = TextAnchor.UpperLeft;

            y += 280;

            Rect infoRect = new Rect(0, y, inRect.width, 200);

            Widgets.Label(infoRect, "DefenseContractCompWindow_ResultInfo".Translate(contractDaysDuration, totalDaysCost, fightersType.ToStringHuman(), fightersCost[fightersType], totalCost));

            Text.Anchor = TextAnchor.MiddleCenter;
            y          += 210;
            Rect createAgrRect = new Rect(0, inRect.height - 30, inRect.width, 25);
            bool active        = faction.Trust >= totalCost;

            if (GUIUtils.DrawCustomButton(createAgrRect, "DefenseContractCompWindow_CreateAgreement".Translate(), active ? Color.white : Color.gray))
            {
                if (active)
                {
                    CreateAgreement();

                    Close();
                }
                else
                {
                    Messages.Message("DefenseContractCompWindow_CreateAgreement_NoTrust".Translate(), MessageTypeDefOf.NegativeEvent, false);
                }
            }

            Text.Anchor = TextAnchor.UpperLeft;
        }
        public static void CreateAgreement(Alliance alliance, Settlement settlement, int totalCost, int agreementDelay, List <AgreementGood> items, FactionInteraction signer, int trust, Window windowToClose, int formCaravanDelay)
        {
            if (totalCost == 0)
            {
                return;
            }

            if (agreementDelay == 0)
            {
                return;
            }

            if (items == null)
            {
                return;
            }

            Map targetMap = Find.Maps.Where(x => x.IsPlayerHome).First(x2 => x2.resourceCounter.Silver >= totalCost);

            if (PriceUtils.TakeSilverFromPlayer(totalCost, targetMap))
            {
                List <Thing> toBuy = new List <Thing>();
                foreach (var item in items)
                {
                    if (item.Thing is Pawn pawn)
                    {
                        toBuy.Add(item.Thing);

                        settlement.trader.StockListForReading.Remove(item.Thing);

                        if (Find.WorldPawns.Contains(pawn))
                        {
                            Find.WorldPawns.RemovePawn(pawn);
                        }
                    }
                    else
                    {
                        toBuy.Add(item.Thing.SplitOff(item.CountToTransfer));

                        if (item.Thing.stackCount == 0)
                        {
                            settlement.trader.StockListForReading.Remove(item.Thing);
                        }
                    }
                }

                signer.Trust -= trust;

                TradeSchedulingAgreementComp comp = new TradeSchedulingAgreementComp(alliance, signer, toBuy, settlement, targetMap, agreementDelay * 60000, formCaravanDelay * 60000);
                alliance.AddAgreement(comp);

                Find.LetterStack.ReceiveLetter("TradeSchedulingAgreement_CreateSucessTitle".Translate(), "TradeSchedulingAgreement_CreateSucessDesc".Translate(settlement.Faction.Name, totalCost, settlement.Name, agreementDelay), LetterDefOf.PositiveEvent);

                if (windowToClose != null)
                {
                    windowToClose.Close();
                }
            }
        }