예제 #1
0
 static void ForceTrait(Ideo ideo, Pawn ___pawn)
 {
     if (ideo != null)
     {
         foreach (MemeDef meme in ideo.memes)
         {
             ExtendedMemeProperties extendedMemeProps = meme.GetModExtension <ExtendedMemeProperties>();
             if (extendedMemeProps != null)
             {
                 if (extendedMemeProps.forcedTrait != null)
                 {
                     Trait trait = new Trait(extendedMemeProps.forcedTrait, 0, true);
                     ___pawn.story?.traits?.GainTrait(trait);
                 }
                 if (extendedMemeProps.abilitiesGiven != null)
                 {
                     foreach (AbilityDef ability in extendedMemeProps.abilitiesGiven)
                     {
                         ___pawn.abilities?.GainAbility(ability);
                     }
                 }
             }
         }
     }
 }
예제 #2
0
        public override void OnAcceptKeyPressed()
        {
            base.OnAcceptKeyPressed();
            SoundDefOf.ExecuteTrade.PlayOneShotOnCamera();

            if (daysAmount > 0 && hireData.Any(kvp => kvp.Value.First > 0))
            {
                var pawns = new List <Pawn>();

                var remainingCost = Mathf.RoundToInt(CostFinal);

                var silverList = targetMap.listerThings.ThingsOfDef(ThingDefOf.Silver)
                                 .Where(x => !x.Position.Fogged(x.Map) && (targetMap.areaManager.Home[x.Position] || x.IsInAnyStorage())).ToList();
                while (remainingCost > 0)
                {
                    var silver = silverList.First(t => t.stackCount > 0);
                    var num    = Mathf.Min(remainingCost, silver.stackCount);
                    silver.SplitOff(num).Destroy();
                    remainingCost -= num;
                }

                if (!RCellFinder.TryFindRandomPawnEntryCell(out var cell, targetMap, 1f))
                {
                    cell = CellFinder.RandomEdgeCell(targetMap);
                }

                foreach (var kvp in hireData)
                {
                    for (var i = 0; i < kvp.Value.First; i++)
                    {
                        var flag = kvp.Key.ignoreFactionApparelStuffRequirements;
                        kvp.Key.ignoreFactionApparelStuffRequirements = true;
                        var pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(kvp.Key, mustBeCapableOfViolence: true, faction: Faction.OfPlayer,
                                                                                        forbidAnyTitle: true, fixedIdeo: curFaction.referencedFaction is null
                                ? hiredIdeo ?? (hiredIdeo = IdeoGenerator.GenerateIdeo(new IdeoGenerationParms(Faction.OfPlayer.def, classic: true)))
                                : Find.World.factionManager.FirstFactionOfDef(curFaction.referencedFaction).ideos.GetRandomIdeoForNewPawn()));
                        kvp.Key.ignoreFactionApparelStuffRequirements = flag;
                        pawn.playerSettings.hostilityResponse         = HostilityResponseMode.Attack;
                        pawns.Add(pawn);
                        var loc = DropCellFinder.TryFindSafeLandingSpotCloseToColony(targetMap, IntVec2.Two);

                        var activeDropPodInfo = new ActiveDropPodInfo();
                        activeDropPodInfo.innerContainer.TryAdd(pawn, 1);
                        activeDropPodInfo.openDelay = 60;
                        activeDropPodInfo.leaveSlag = false;
                        activeDropPodInfo.despawnPodBeforeSpawningThing = true;
                        activeDropPodInfo.spawnWipeMode = WipeMode.Vanish;
                        DropPodUtility.MakeDropPodAt(loc, targetMap, activeDropPodInfo);
                    }
                }

                Find.World.GetComponent <HiringContractTracker>().SetNewContract(daysAmount, pawns, hireable, curFaction, CostFinal);
            }
        }
예제 #3
0
        static void FixIdeoAfterCopy(Ideo __instance, Ideo ideo)
        {
            if (Multiplayer.ExecutingCmds)
            {
                // Fix ids for precepts generated by the fluid ideo reforming UI
                foreach (var precept in ideo.PreceptsListForReading)
                {
                    if (precept.ID < 0)
                    {
                        precept.ID = Find.UniqueIDsManager.GetNextPreceptID();
                    }
                }

                ideo.development.ideo = ideo;
                ideo.style.ideo       = ideo;
            }
        }
예제 #4
0
        /// <inheritdoc/>
        public bool CanHeal([NotNull] Hediff hediff)
        {
            bool isScarification = hediff.def == HediffDefOf.Scarification;

            Ideo ideo = hediff.pawn.Ideo;

            if (ideo.HasPrecept(PreceptDefOf.Scarification_Minor))
            {
                return(!isScarification);
            }

            if (ideo.HasPrecept(PreceptDefOf.Scarification_Heavy))
            {
                return(!isScarification);
            }

            if (ideo.HasPrecept(PreceptDefOf.Scarification_Extreme))
            {
                return(!isScarification);
            }

            return(true);
        }
예제 #5
0
        public static bool Applies(GoodwillSituationWorker_MemeCompatibility __instance, ref bool __result, Faction a, Faction b)
        {
            Ideo primaryIdeo1 = a.ideos.PrimaryIdeo;

            if (primaryIdeo1 == null)
            {
                return(false);
            }
            GoodwillSituationDef def = __instance.def;

            if (def == null)
            {
                __result = false;
                return(false);
            }
            if (def.versusAll)
            {
                return(primaryIdeo1.memes.Contains(def.meme));
            }
            Ideo primaryIdeo2 = b.ideos.PrimaryIdeo;

            return(primaryIdeo2 != null && primaryIdeo1.memes.Contains(def.meme) && primaryIdeo2.memes.Contains(def.otherMeme));
        }
 public static AcceptanceReport Postfix(AcceptanceReport __result, PreceptWorker_Apparel __instance, ThingDef def, Ideo ideo)
 {
     if (ideo.culture.defName.StartsWith("OG_"))
     {
         if (def.defName.StartsWith("OGI_"))
         {
             return(ideo.culture.defName.Contains("Imperial"));
         }
         if (def.defName.StartsWith("OGAM_"))
         {
             return(ideo.culture.defName.Contains("Mechanicus"));
         }
         if (def.defName.StartsWith("OGO_"))
         {
             return(ideo.culture.defName.Contains("Orkoid") || ideo.culture.defName.Contains("Greenskin"));
         }
         if (def.defName.StartsWith("OGDE_"))
         {
             return(ideo.culture.defName.Contains("DarkEldar") || ideo.culture.defName.Contains("Drukhari"));
         }
         if (def.defName.StartsWith("OGE_"))
         {
             return(ideo.culture.defName.Contains("Eldar") || ideo.culture.defName.Contains("Aeldari"));
         }
         if (def.defName.StartsWith("OGT_"))
         {
             return(ideo.culture.defName.Contains("Tau"));
         }
         if (def.defName.StartsWith("OGK_"))
         {
             return(ideo.culture.defName.Contains("Kroot"));
         }
         if (def.defName.StartsWith("OGC_"))
         {
             return(ideo.culture.defName.Contains("Chaos"));
         }
     }
     return(__result);
 }
예제 #7
0
        public static void GenerateIngredients(Thing meal, Pawn eater)
        {
            CompIngredients compIngredients = meal.TryGetComp <CompIngredients>();

            if (compIngredients != null)
            {
                // Stage 1: Generate random ingredients according to recipe

                // 1.1: Find recipe
                Func <RecipeDef, bool> validator = delegate(RecipeDef r)
                {
                    bool directMatch = r.ProducedThingDef == meal.def;

                    // Add compatibility for VCE Soups and Stews, whose original recipes only makes uncooked versions
                    bool indirectMatch = (r.ProducedThingDef != null) ? (r.ProducedThingDef.ToString().Replace("Uncooked", "Cooked") == meal.def.ToString()) : false;

                    return(directMatch || indirectMatch);
                };

                RecipeDef mealRecipe = DefDatabase <RecipeDef> .AllDefsListForReading.First(validator);

                if (mealRecipe != null)
                {
                    // 1.2: Generate ingredients from recipe
                    List <string> ingredientCategoryOptions = new List <string>();

                    List <ThingDef> ingredientThingDefs = new List <ThingDef>();

                    // 1.3: Find ingredient categories and/or fixed thingDefs
                    foreach (IngredientCount currIngredientCount in mealRecipe.ingredients)
                    {
                        if (currIngredientCount.filter.categories != null)
                        {
                            // Limit to 3 instances of an ingredient category
                            int ingredientCatInstances = Math.Min((int)Math.Ceiling(currIngredientCount.count / 0.5f), 3);

                            for (int i = 0; i < ingredientCatInstances; i++)
                            {
                                // Max limit of one condiment from Vanilla Cooking Expanded
                                if (currIngredientCount.filter.categories.Contains("VCE_Condiments") && ingredientCategoryOptions.Contains("VCE_Condiments"))
                                {
                                    continue;
                                }
                                else
                                {
                                    ingredientCategoryOptions.Add(currIngredientCount.filter.categories.RandomElement());
                                }
                            }
                        }
                        if (currIngredientCount.filter.thingDefs != null)
                        {
                            ingredientThingDefs.AddRange(currIngredientCount.filter.thingDefs);
                        }
                    }

                    // 1.4: Generate random ingredient thingDefs based on categories, and add them to the existing list of fixed thingDefs
                    //
                    // By default, we ignore ingredients that are:
                    // - Permanently disallowed by the Computer
                    // - Disallowed specifically by the pawn's food restriction policy
                    // - Humanlike and insect meats
                    // - Fertilized eggs

                    List <ThingDef> allowedIngredients = ThingCategoryDef.Named("FoodRaw").DescendantThingDefs.Where(x =>
                                                                                                                     !replimatRestrictions.disallowedIngredients.Contains(x) &&
                                                                                                                     eater.foodRestriction.CurrentFoodRestriction.Allows(x) &&
                                                                                                                     FoodUtility.GetMeatSourceCategory(x) != MeatSourceCategory.Humanlike &&
                                                                                                                     FoodUtility.GetMeatSourceCategory(x) != MeatSourceCategory.Insect &&
                                                                                                                     !x.thingCategories.Contains(ThingCategoryDefOf.EggsFertilized)
                                                                                                                     ).ToList();

                    // Also check allowed condiments if Vanilla Cooking Expanded mod is active
                    if (ModCompatibility.VanillaCookingExpandedIsActive)
                    {
                        allowedIngredients.AddRange(ThingCategoryDef.Named("VCE_Condiments").DescendantThingDefs.Where(x =>
                                                                                                                       !replimatRestrictions.disallowedIngredients.Contains(x) &&
                                                                                                                       eater.foodRestriction.CurrentFoodRestriction.Allows(x)
                                                                                                                       ));
                    }

                    foreach (string currentIngredientCatOption in ingredientCategoryOptions)
                    {
                        List <ThingDef> ingredients = ThingCategoryDef.Named(currentIngredientCatOption).DescendantThingDefs.Where((ThingDef d) => allowedIngredients.Contains(d)).ToList();

                        ThingDef ingredient = (ingredients.Count > 0) ? ingredients.RandomElement() : null;

                        // Avoid empty or duplicate ingredients
                        if (ingredient != null && !ingredientThingDefs.Contains(ingredient))
                        {
                            ingredientThingDefs.Add(ingredient);
                        }
                    }

                    // Stage 2: Ideo replacements

                    Ideo ideo = eater.Ideo;

                    // 2.1 Human cannibalism for meals containing meat
                    if (ideo?.HasHumanMeatEatingRequiredPrecept() == true)
                    {
                        List <ThingDef> existingMeats = ingredientThingDefs.FindAll((ThingDef d) => d.thingCategories.Contains(ThingCategoryDefOf.MeatRaw));

                        // Replace existing meats with a single instance of human meat
                        if (existingMeats.Count > 0)
                        {
                            ingredientThingDefs = ingredientThingDefs.Except(existingMeats).ToList();

                            ingredientThingDefs.Add(ThingDefOf.Meat_Human);
                        }
                    }

                    // 2.2 Insect meat loved for meals containing meat
                    if (ideo?.HasPrecept(ReplimatDef.InsectMeatEating_Loved) == true)
                    {
                        List <ThingDef> existingMeats = ingredientThingDefs.FindAll((ThingDef d) => d.thingCategories.Contains(ThingCategoryDefOf.MeatRaw));

                        // Replace existing meats with a single instance of insect meat
                        if (existingMeats.Count > 0)
                        {
                            ingredientThingDefs = ingredientThingDefs.Except(existingMeats).ToList();

                            ingredientThingDefs.Add(ReplimatDef.Meat_Megaspider);
                        }
                    }

                    // 2.3 Fungus preferred for meals containing raw plant food
                    if (ideo?.HasPrecept(ReplimatDef.FungusEating_Preferred) == true)
                    {
                        List <ThingDef> existingPlantFoodRaws = ingredientThingDefs.FindAll((ThingDef d) => d.thingCategories.Contains(ThingCategoryDefOf.PlantFoodRaw) || d.ingestible.foodType == FoodTypeFlags.VegetableOrFruit);
                        // todo - fix

                        // Replace existing raw plant food with a single instance of fungus
                        if (existingPlantFoodRaws.Count > 0)
                        {
                            ingredientThingDefs = ingredientThingDefs.Except(existingPlantFoodRaws).ToList();

                            ingredientThingDefs.Add(ReplimatDef.RawFungus);
                        }
                    }

                    // 2.4 Fungus despised for meals containing raw plant food
                    if (ideo?.HasPrecept(ReplimatDef.FungusEating_Despised) == true)
                    {
                        ingredientThingDefs.Remove(ReplimatDef.RawFungus);
                    }

                    // Stage 3: Assign final ingredients to meal
                    compIngredients.ingredients.AddRange(ingredientThingDefs);
                }
            }
        }
예제 #8
0
        private bool doConquest()
        {
            Settlement AttackerBase = RandomSettlement();

            if (AttackerBase == null)
            {
                return(false);
            }
            Faction AttackerFaction = AttackerBase.Faction;

            if (AttackerFaction == null)
            {
                return(false);
            }

            List <Settlement> settlements       = Find.WorldObjects.Settlements.ToList <Settlement>();
            List <Settlement> prox1             = new List <Settlement>();
            List <Settlement> prox2             = new List <Settlement>();
            List <Settlement> prox3             = new List <Settlement>();
            List <Settlement> prox4             = new List <Settlement>();
            List <Settlement> prox5             = new List <Settlement>();
            List <Settlement> prox6             = new List <Settlement>();
            List <Settlement> prox7             = new List <Settlement>();
            double            attackerBaseCount = 0;
            double            totalBaseCount    = 0;

            List <Settlement> attackerSettlementList = new List <Settlement>();

            for (int i = 0; i < settlements.Count; i++)
            {
                Settlement DefenderBase = settlements[i];

                if (DefenderBase.Faction == AttackerBase.Faction)
                {
                    attackerBaseCount++;
                    attackerSettlementList.Add(DefenderBase);
                }

                if (DefenderBase.Faction != null && !DefenderBase.Faction.IsPlayer && DefenderBase.Faction.def.settlementGenerationWeight > 0f && !DefenderBase.def.defName.Equals("City_Faction") && !DefenderBase.def.defName.Equals("City_Abandoned") && !DefenderBase.def.defName.Equals("City_Ghost") && !DefenderBase.def.defName.Equals("City_Citadel"))
                {
                    totalBaseCount++;
                    if (AttackerBase.Faction.HostileTo(DefenderBase.Faction))
                    {
                        int attackDistance = Find.WorldGrid.TraversalDistanceBetween(AttackerBase.Tile, DefenderBase.Tile, true);
                        if (attackDistance < 30)
                        {
                            prox1.Add(DefenderBase);
                        }
                        else if (attackDistance < 60)
                        {
                            prox2.Add(DefenderBase);
                        }
                        else if (attackDistance < 90)
                        {
                            prox3.Add(DefenderBase);
                        }
                        else if (attackDistance < 120)
                        {
                            prox4.Add(DefenderBase);
                        }
                        else if (attackDistance < 150)
                        {
                            prox5.Add(DefenderBase);
                        }
                        else if (attackDistance < 180)
                        {
                            prox6.Add(DefenderBase);
                        }
                        else if (attackDistance < 210)
                        {
                            prox7.Add(DefenderBase);
                        }
                    }
                }
            }

            // Rebellion code
            if (attackerBaseCount >= 10 && attackerBaseCount >= (totalBaseCount * 0.1))
            {
                int num = Rand.Range(1, 100);
                if (num <= (int)(attackerBaseCount / totalBaseCount * 20) || attackerBaseCount >= (totalBaseCount * 0.8))
                {
                    List <Faction> allFactionList = (from x in Find.FactionManager.AllFactionsVisible
                                                     where x.def.settlementGenerationWeight > 0f && !x.def.hidden && !x.IsPlayer && !x.defeated && x != AttackerFaction && x.leader != null && !x.leader.IsPrisoner && !x.leader.Spawned
                                                     select x).ToList <Faction>();
                    for (int i = 0; i < allFactionList.Count; i++)
                    {
                        if (!IncidentWorker_NPCConquest.HasAnyOtherBase(allFactionList[i]))
                        {
                            for (int j = 0; j < attackerSettlementList.Count; j++)
                            {
                                int  num2             = Rand.Range(1, 100);
                                bool resistancechance = num2 < 41;
                                if (resistancechance)
                                {
                                    Settlement rebelSettlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement);
                                    rebelSettlement.SetFaction(allFactionList[i]);
                                    rebelSettlement.Tile = attackerSettlementList[j].Tile;
                                    rebelSettlement.Name = SettlementNameGenerator.GenerateSettlementName(rebelSettlement, null);
                                    Find.WorldObjects.Remove(attackerSettlementList[j]);
                                    Find.WorldObjects.Add(rebelSettlement);
                                }
                            }

                            FactionRelation factionRelation = allFactionList[i].RelationWith(AttackerBase.Faction, false);
                            factionRelation.kind = FactionRelationKind.Hostile;
                            FactionRelation factionRelation2 = AttackerBase.Faction.RelationWith(allFactionList[i], false);
                            factionRelation2.kind = FactionRelationKind.Hostile;
                            Find.LetterStack.ReceiveLetter("LabelRebellion".Translate(), "DescRebellion".Translate(allFactionList[i], AttackerBase.Faction), LetterDefOf.NeutralEvent, null);
                            return(true);
                        }
                    }

                    if (IncidentWorker_NPCConquest.allowCloneFaction && AttackerFaction != Faction.OfEmpire)
                    {
                        Faction clonefaction = FactionGenerator.NewGeneratedFaction(new FactionGeneratorParms(AttackerFaction.def, default(IdeoGenerationParms), null));
                        clonefaction.color = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
                        Find.FactionManager.Add(clonefaction);

                        for (int i = 0; i < attackerSettlementList.Count; i++)
                        {
                            int  num3             = Rand.Range(1, 100);
                            bool resistancechance = num3 < 41;
                            if (resistancechance)
                            {
                                Settlement rebelSettlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement);
                                rebelSettlement.SetFaction(clonefaction);
                                rebelSettlement.Tile = attackerSettlementList[i].Tile;
                                rebelSettlement.Name = SettlementNameGenerator.GenerateSettlementName(rebelSettlement, null);
                                Find.WorldObjects.Remove(attackerSettlementList[i]);
                                Find.WorldObjects.Add(rebelSettlement);
                            }
                        }

                        FactionRelation factionRelation = clonefaction.RelationWith(AttackerBase.Faction, false);
                        factionRelation.kind = FactionRelationKind.Hostile;
                        FactionRelation factionRelation2 = AttackerBase.Faction.RelationWith(clonefaction, false);
                        factionRelation2.kind = FactionRelationKind.Hostile;

                        Ideo newIdeo = IdeoGenerator.GenerateIdeo(FactionIdeosTracker.IdeoGenerationParmsForFaction_BackCompatibility(clonefaction.def));
                        clonefaction.ideos.SetPrimary(newIdeo);
                        Find.IdeoManager.Add(newIdeo);
                        clonefaction.leader.ideo.SetIdeo(newIdeo);

                        Find.LetterStack.ReceiveLetter("LabelRebellion".Translate(), "DescRebellion".Translate(clonefaction, AttackerBase.Faction), LetterDefOf.NeutralEvent, null);
                        return(true);
                    }
                }
            }

            // Conquest code
            Settlement FinalDefenderBase;

            if (prox1.Count != 0)
            {
                FinalDefenderBase = prox1.RandomElement <Settlement>();
            }
            else if (prox2.Count != 0)
            {
                FinalDefenderBase = prox2.RandomElement <Settlement>();
            }
            else if (prox3.Count != 0)
            {
                FinalDefenderBase = prox3.RandomElement <Settlement>();
            }
            else if (prox4.Count != 0)
            {
                FinalDefenderBase = prox4.RandomElement <Settlement>();
            }
            else if (prox5.Count != 0)
            {
                FinalDefenderBase = prox5.RandomElement <Settlement>();
            }
            else if (prox6.Count != 0)
            {
                FinalDefenderBase = prox6.RandomElement <Settlement>();
            }
            else if (prox7.Count != 0)
            {
                FinalDefenderBase = prox7.RandomElement <Settlement>();
            }
            else
            {
                return(false);
            }

            if (FinalDefenderBase.HasMap)
            {
                Log.Message("attack target has generated map. Event dropped.");
                return(false);
            }

            // Determine whether to raze or take control, distance-based
            int razeroll = Rand.Range(1, 100);

            if (razeroll <= IncidentWorker_NPCConquest.razeChance)
            {
                if (IncidentWorker_NPCConquest.allowRazeClear)
                {
                    List <DestroyedSettlement> clearRuinTarget = Find.WorldObjects.DestroyedSettlements;
                    for (int i = 0; i < clearRuinTarget.Count; i++)
                    {
                        Find.WorldObjects.Remove(clearRuinTarget[i]);
                    }
                }

                DestroyedSettlement destroyedSettlement = (DestroyedSettlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.DestroyedSettlement);
                destroyedSettlement.Tile = FinalDefenderBase.Tile;
                Find.WorldObjects.Remove(FinalDefenderBase);
                Find.WorldObjects.Add(destroyedSettlement);
            }
            else
            {
                Settlement settlementConquest = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement);
                settlementConquest.SetFaction(AttackerBase.Faction);
                settlementConquest.Tile = FinalDefenderBase.Tile;
                settlementConquest.Name = SettlementNameGenerator.GenerateSettlementName(settlementConquest, null);
                Find.WorldObjects.Remove(FinalDefenderBase);
                Find.WorldObjects.Add(settlementConquest);
            }

            // Defeat check for distance conquest
            if (IncidentWorker_NPCConquest.allowCloneFaction && !HasAnyOtherBase(FinalDefenderBase))
            {
                List <Faction> clonefactioncheck = (from x in Find.FactionManager.AllFactionsVisible
                                                    where !x.def.hidden && !x.IsPlayer && !x.defeated && x != FinalDefenderBase.Faction && x.def == FinalDefenderBase.Faction.def
                                                    select x).ToList <Faction>();
                if (clonefactioncheck.Count > 0)
                {
                    FinalDefenderBase.Faction.defeated = true;
                    Find.LetterStack.ReceiveLetter("LetterLabelFactionBaseDefeated".Translate(), "LetterFactionBaseDefeated_FactionDestroyed".Translate(FinalDefenderBase.Faction.Name), LetterDefOf.NeutralEvent, null);
                }
            }

            int defeatroll = Rand.Range(1, 100);

            if (defeatroll <= IncidentWorker_NPCConquest.defeatChance && !HasAnyOtherBase(FinalDefenderBase))
            {
                FinalDefenderBase.Faction.defeated = true;
                Find.LetterStack.ReceiveLetter("LetterLabelFactionBaseDefeated".Translate(), "LetterFactionBaseDefeated_FactionDestroyed".Translate(FinalDefenderBase.Faction.Name), LetterDefOf.NeutralEvent, null);
            }

            // Alliance code
            if (IncidentWorker_NPCConquest.allowAlliance && Find.World.GetComponent <DiplomacyWorldComponent>().allianceCooldown <= 0)
            {
                List <Faction> alliance = (from x in Find.FactionManager.AllFactionsVisible
                                           where x.def.settlementGenerationWeight > 0f && !x.def.hidden && !x.IsPlayer && !x.defeated && x != AttackerFaction && x.leader != null && !x.leader.IsPrisoner && !x.leader.Spawned
                                           select x).ToList <Faction>();
                List <Faction> finalAlliance = new List <Faction>();

                if (alliance.Count >= 2 && attackerBaseCount >= (totalBaseCount * 0.4) && attackerBaseCount <= (totalBaseCount * 0.6) && attackerBaseCount > 9)
                {
                    for (int i = 0; i < alliance.Count; i++)
                    {
                        int  num         = Rand.Range(1, 100);
                        bool havemysword = num < 81;
                        if (havemysword)
                        {
                            FactionRelation factionRelation = AttackerFaction.RelationWith(alliance[i], false);
                            factionRelation.kind = FactionRelationKind.Hostile;
                            FactionRelation factionRelation2 = alliance[i].RelationWith(AttackerFaction, false);
                            factionRelation2.kind = FactionRelationKind.Hostile;
                            finalAlliance.Add(alliance[i]);
                        }
                    }

                    StringBuilder allianceList = new StringBuilder();
                    for (int x = 0; x < finalAlliance.Count; x++)
                    {
                        for (int y = 0; y < finalAlliance.Count; y++)
                        {
                            if (finalAlliance[y] != finalAlliance[x])
                            {
                                FactionRelation factionRelation3 = finalAlliance[y].RelationWith(finalAlliance[x], false);
                                factionRelation3.kind = FactionRelationKind.Neutral;
                                FactionRelation factionRelation4 = finalAlliance[x].RelationWith(finalAlliance[y], false);
                                factionRelation4.kind = FactionRelationKind.Neutral;
                            }
                        }
                        allianceList.Append(finalAlliance[x].ToString()).Append(", ");
                    }
                    string allianceListString = allianceList.ToString();
                    allianceListString = allianceListString.Trim().TrimEnd(',');

                    Find.LetterStack.ReceiveLetter("LabelAlliance".Translate(), "DescAlliance".Translate(allianceListString, AttackerBase.Faction), LetterDefOf.NeutralEvent, null);
                    Find.World.GetComponent <DiplomacyWorldComponent>().allianceCooldown = 11;
                }
            }

            if (Find.World.GetComponent <DiplomacyWorldComponent>().allianceCooldown > 0)
            {
                Find.World.GetComponent <DiplomacyWorldComponent>().allianceCooldown--;
            }

            return(true);
        }
예제 #9
0
        private bool doConvert()
        {
            Faction faction;

            if (!this.TryFindConvertFaction(out faction))
            {
                return(false);
            }

            // adopt similar ideology from ally
            List <MemeDef> initialmemes = faction.ideos.PrimaryIdeo.memes;

            for (int i = 0; i < initialmemes.Count; i++)
            {
                MemeDef eachmeme = initialmemes[i];
                if (eachmeme.impact >= 2)
                {
                    List <Ideo> worldIdeo = Find.IdeoManager.IdeosListForReading;
                    for (int y = 0; y < worldIdeo.Count; y++)
                    {
                        Ideo eachIdeo = worldIdeo[y];
                        if (eachIdeo.HasMeme(eachmeme) && eachIdeo != faction.ideos.PrimaryIdeo)
                        {
                            List <Faction> proselytizer = (from x in Find.FactionManager.AllFactionsVisible
                                                           where !x.def.hidden && (!x.IsPlayer || faction.RelationKindWith(Faction.OfPlayer) == FactionRelationKind.Ally) && !x.defeated && x != faction && !x.HostileTo(faction) && x.ideos.PrimaryIdeo == eachIdeo
                                                           select x).ToList <Faction>();

                            for (int x = 0; x < proselytizer.Count; x++)
                            {
                                Faction temp        = proselytizer[x];
                                int     randomIndex = Random.Range(x, proselytizer.Count);
                                proselytizer[x]           = proselytizer[randomIndex];
                                proselytizer[randomIndex] = temp;
                            }

                            if (proselytizer.Count > 0)
                            {
                                faction.ideos.SetPrimary(eachIdeo);
                                Find.IdeoManager.RemoveUnusedStartingIdeos();
                                faction.leader.ideo.SetIdeo(eachIdeo);
                                Find.LetterStack.ReceiveLetter("LabelDDProselytization".Translate(), "DescDDProselytization".Translate(faction.Name, eachIdeo.name, proselytizer.RandomElement <Faction>().Name, eachmeme.label), LetterDefOf.NeutralEvent);
                                return(true);
                            }
                        }
                    }
                }
            }

            // adopt new ideology with FactionDef limitations
            Ideo           newIdeo          = IdeoGenerator.GenerateIdeo(FactionIdeosTracker.IdeoGenerationParmsForFaction_BackCompatibility(faction.def));
            List <Faction> sameideofactions = (from x in Find.FactionManager.AllFactionsVisible
                                               where !x.def.hidden && !x.defeated && x != faction && x.ideos.PrimaryIdeo == faction.ideos.PrimaryIdeo
                                               select x).ToList <Faction>();

            faction.ideos.SetPrimary(newIdeo);
            Find.IdeoManager.Add(newIdeo);
            faction.leader.ideo.SetIdeo(newIdeo);
            Find.IdeoManager.RemoveUnusedStartingIdeos();
            if (sameideofactions.Count > 0)
            {
                Find.LetterStack.ReceiveLetter("LabelDDFoundation".Translate(), "DescDDFoundation".Translate(faction.Name, newIdeo.name), LetterDefOf.NeutralEvent);
            }

            return(true);
        }
예제 #10
0
        public void DrawIcons(Rect rect, Pawn colonist)
        {
            if (colonist.Dead)
            {
                return;
            }
            tmpIconsToDraw.Clear();
            bool flag = false;

            if (colonist.CurJob != null)
            {
                JobDef def = colonist.CurJob.def;
                if (def == JobDefOf.AttackMelee || def == JobDefOf.AttackStatic)
                {
                    flag = true;
                }
                else if (def == JobDefOf.Wait_Combat)
                {
                    Stance_Busy stance_Busy = colonist.stances.curStance as Stance_Busy;
                    if (stance_Busy != null && stance_Busy.focusTarg.IsValid)
                    {
                        flag = true;
                    }
                }
            }

            if (colonist.IsFormingCaravan())
            {
                tmpIconsToDraw.Add(new IconDrawCall(Icon_FormingCaravan, Strings.ActivityIconFormingCaravan));
            }
            if (colonist.InAggroMentalState)
            {
                tmpIconsToDraw.Add(new IconDrawCall(Icon_MentalStateAggro, colonist.MentalStateDef.LabelCap));
            }
            else if (colonist.InMentalState)
            {
                tmpIconsToDraw.Add(new IconDrawCall(Icon_MentalStateNonAggro, colonist.MentalStateDef.LabelCap));
            }
            else if (colonist.InBed() && colonist.CurrentBed().Medical)
            {
                tmpIconsToDraw.Add(new IconDrawCall(Icon_MedicalRest, Strings.ActivityIconMedicalRest));
            }
            else if (colonist.CurJob != null && colonist.jobs.curDriver.asleep)
            {
                tmpIconsToDraw.Add(new IconDrawCall(Icon_Sleeping, Strings.ActivityIconSleeping));
            }
            else if (colonist.CurJob != null && colonist.CurJob.def == JobDefOf.FleeAndCower)
            {
                tmpIconsToDraw.Add(new IconDrawCall(Icon_Fleeing, Strings.ActivityIconFleeing));
            }
            else if (flag)
            {
                tmpIconsToDraw.Add(new IconDrawCall(Icon_Attacking, Strings.ActivityIconAttacking));
            }
            else if (colonist.mindState.IsIdle && GenDate.DaysPassed >= 1)
            {
                tmpIconsToDraw.Add(new IconDrawCall(Icon_Idle, Strings.ActivityIconIdle));
            }
            if (colonist.IsBurning())
            {
                tmpIconsToDraw.Add(new IconDrawCall(Icon_Burning, Strings.ActivityIconBurning));
            }

            if (colonist.Inspired)
            {
                tmpIconsToDraw.Add(new IconDrawCall(Icon_Inspired, colonist.InspirationDef.LabelCap));
            }

            if (colonist.IsSlaveOfColony)
            {
                tmpIconsToDraw.Add(new IconDrawCall(colonist.guest.GetIcon()));
            }
            else
            {
                bool flag2 = false;
                if (colonist.Ideo != null)
                {
                    Ideo         ideo = colonist.Ideo;
                    Precept_Role role = ideo.GetRole(colonist);
                    if (role != null)
                    {
                        tmpIconsToDraw.Add(new IconDrawCall(role.Icon, null, ideo.Color));
                        flag2 = true;
                    }
                }
                if (!flag2)
                {
                    Faction faction = null;
                    if (colonist.HasExtraMiniFaction())
                    {
                        faction = colonist.GetExtraMiniFaction();
                    }
                    else if (colonist.HasExtraHomeFaction())
                    {
                        faction = colonist.GetExtraHomeFaction();
                    }
                    if (faction != null)
                    {
                        tmpIconsToDraw.Add(new IconDrawCall(faction.def.FactionIcon, null, faction.Color));
                    }
                }
            }

            if (!(ModCompatibility.rimworldOfMagicDrawMethod is null))
            {
                ModCompatibility.rimworldOfMagicDrawMethod.Invoke(this, new object[]
                {
                    null, rect, colonist
                });
            }

            float   num = Mathf.Min(BaseIconAreaWidth / (float)tmpIconsToDraw.Count, BaseIconMaxSize) * TacticUtils.TacticalColonistBar.Scale;
            Vector2 pos = new Vector2(rect.x + 1f, rect.yMax - num - 1f);

            foreach (IconDrawCall item in tmpIconsToDraw)
            {
                GUI.color = item.color ?? Color.white;
                DrawIcon(item.texture, ref pos, num, item.tooltip);
                GUI.color = Color.white;
            }
        }