Ejemplo n.º 1
0
 private IEnumerable <Pawn> GenerateAmbushPawns()
 {
     if (this.manhunters)
     {
         PawnKindDef animalKind;
         if (!ManhunterPackIncidentUtility.TryFindManhunterAnimalKind(this.points, base.Map.Tile, out animalKind) && !ManhunterPackIncidentUtility.TryFindManhunterAnimalKind(this.points, -1, out animalKind))
         {
             return(Enumerable.Empty <Pawn>());
         }
         return(ManhunterPackIncidentUtility.GenerateAnimals(animalKind, base.Map.Tile, this.points));
     }
     else
     {
         Faction faction;
         if (this.mechanoids)
         {
             faction = Faction.OfMechanoids;
         }
         else
         {
             faction = (base.Map.ParentFaction ?? Find.FactionManager.RandomEnemyFaction(false, false, false, TechLevel.Undefined));
         }
         if (faction == null)
         {
             return(Enumerable.Empty <Pawn>());
         }
         PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms();
         pawnGroupMakerParms.tile    = base.Map.Tile;
         pawnGroupMakerParms.faction = faction;
         pawnGroupMakerParms.points  = this.points;
         return(PawnGroupMakerUtility.GeneratePawns(PawnGroupKindDefOf.Normal, pawnGroupMakerParms, true));
     }
 }
Ejemplo n.º 2
0
 private IEnumerable <Pawn> GenerateAmbushPawns()
 {
     if (this.ambushType == SignalActionAmbushType.Manhunters)
     {
         PawnKindDef animalKind;
         if (!ManhunterPackIncidentUtility.TryFindManhunterAnimalKind(this.points, base.Map.Tile, out animalKind) && !ManhunterPackIncidentUtility.TryFindManhunterAnimalKind(this.points, -1, out animalKind))
         {
             return(Enumerable.Empty <Pawn>());
         }
         return(ManhunterPackIncidentUtility.GenerateAnimals(animalKind, base.Map.Tile, this.points));
     }
     else
     {
         Faction faction;
         if (this.ambushType == SignalActionAmbushType.Mechanoids)
         {
             faction = Faction.OfMechanoids;
         }
         else
         {
             faction = (base.Map.ParentFaction ?? Find.FactionManager.RandomEnemyFaction(false, false, false, TechLevel.Undefined));
         }
         if (faction == null)
         {
             return(Enumerable.Empty <Pawn>());
         }
         return(PawnGroupMakerUtility.GeneratePawns(new PawnGroupMakerParms
         {
             groupKind = PawnGroupKindDefOf.Combat,
             tile = base.Map.Tile,
             faction = faction,
             points = Mathf.Max(this.points, faction.def.MinPointsToGeneratePawnGroup(PawnGroupKindDefOf.Combat))
         }, true));
     }
 }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map = (Map)parms.target;
            List <TargetInfo> list        = new List <TargetInfo>();
            ThingDef          shipPartDef = def.mechClusterBuilding;
            IntVec3           intVec      = FindDropPodLocation(map, (IntVec3 spot) => CanPlaceAt(spot));

            if (intVec == IntVec3.Invalid)
            {
                return(false);
            }
            float       points = Mathf.Max(parms.points * 0.9f, 300f);
            List <Pawn> list2  = PawnGroupMakerUtility.GeneratePawns(new PawnGroupMakerParms
            {
                groupKind = PawnGroupKindDefOf.Combat,
                tile      = map.Tile,
                faction   = Faction.OfMechanoids,
                points    = points
            }).ToList();
            Thing thing = ThingMaker.MakeThing(shipPartDef);

            thing.SetFaction(Faction.OfMechanoids);
            LordMaker.MakeNewLord(Faction.OfMechanoids, new LordJob_SleepThenMechanoidsDefend(new List <Thing>
            {
                thing
            }, Faction.OfMechanoids, 28f, intVec, canAssaultColony: false, isMechCluster: false), map, list2);
            DropPodUtility.DropThingsNear(intVec, map, list2.Cast <Thing>());
            foreach (Pawn item in list2)
            {
                item.TryGetComp <CompCanBeDormant>()?.ToSleep();
            }
            list.AddRange(list2.Select((Pawn p) => new TargetInfo(p)));
            GenSpawn.Spawn(SkyfallerMaker.MakeSkyfaller(ThingDefOf.CrashedShipPartIncoming, thing), intVec, map);
            list.Add(new TargetInfo(intVec, map));
            SendStandardLetter(parms, list);
            return(true);

            bool CanPlaceAt(IntVec3 loc)
            {
                CellRect cellRect = GenAdj.OccupiedRect(loc, Rot4.North, shipPartDef.Size);

                if (loc.Fogged(map) || !cellRect.InBounds(map))
                {
                    return(false);
                }
                if (!DropCellFinder.SkyfallerCanLandAt(loc, map, shipPartDef.Size))
                {
                    return(false);
                }
                foreach (IntVec3 item2 in cellRect)
                {
                    RoofDef roof = item2.GetRoof(map);
                    if (roof != null && roof.isNatural)
                    {
                        return(false);
                    }
                }
                return(GenConstruct.CanBuildOnTerrain(shipPartDef, loc, map, Rot4.North));
            }
        }
        private List <Pawn> GenerateCaravanPawns(Faction faction)
        {
            PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms();

            pawnGroupMakerParms.faction = faction;
            pawnGroupMakerParms.points  = TraderCaravanUtility.GenerateGuardPoints();
            return(PawnGroupMakerUtility.GeneratePawns(PawnGroupKindDefOf.Trader, pawnGroupMakerParms, true).ToList());
        }
Ejemplo n.º 5
0
        private IEnumerable <Pawn> GeneratePawns(Map map)
        {
            PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms();

            pawnGroupMakerParms.tile    = map.Tile;
            pawnGroupMakerParms.faction = Faction.OfMechanoids;
            pawnGroupMakerParms.points  = this.pointsRange.RandomInRange;
            return(PawnGroupMakerUtility.GeneratePawns(PawnGroupKindDefOf.Normal, pawnGroupMakerParms, true));
        }
Ejemplo n.º 6
0
 private List <Pawn> GenerateCaravanPawns(Faction faction)
 {
     return(PawnGroupMakerUtility.GeneratePawns(new PawnGroupMakerParms
     {
         groupKind = PawnGroupKindDefOf.Trader,
         faction = faction,
         points = TraderCaravanUtility.GenerateGuardPoints(),
         dontUseSingleUseRocketLaunchers = true
     }, true).ToList <Pawn>());
 }
Ejemplo n.º 7
0
 private IEnumerable <Pawn> GeneratePawns(Map map)
 {
     return(PawnGroupMakerUtility.GeneratePawns(new PawnGroupMakerParms
     {
         groupKind = PawnGroupKindDefOf.Combat,
         tile = map.Tile,
         faction = Faction.OfMechanoids,
         points = this.pointsRange.RandomInRange
     }, true));
 }
Ejemplo n.º 8
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            parms.points *= IncidentPointsFactorRange.RandomInRange;
            Caravan caravan = (Caravan)parms.target;

            if (!PawnGroupMakerUtility.TryGetRandomFactionForCombatPawnGroup(parms.points, out parms.faction))
            {
                return(false);
            }
            List <ThingCount> demands = GenerateDemands(caravan);

            if (demands.NullOrEmpty())
            {
                return(false);
            }
            PawnGroupMakerParms defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(PawnGroupKindDefOf.Combat, parms);

            defaultPawnGroupMakerParms.generateFightersOnly            = true;
            defaultPawnGroupMakerParms.dontUseSingleUseRocketLaunchers = true;
            List <Pawn> attackers = PawnGroupMakerUtility.GeneratePawns(defaultPawnGroupMakerParms).ToList();

            if (attackers.Count == 0)
            {
                Log.Error("Caravan demand incident couldn't generate any enemies even though min points have been checked. faction=" + defaultPawnGroupMakerParms.faction + "(" + ((defaultPawnGroupMakerParms.faction == null) ? "null" : defaultPawnGroupMakerParms.faction.def.ToString()) + ") parms=" + parms);
                return(false);
            }
            CameraJumper.TryJumpAndSelect(caravan);
            DiaNode   diaNode   = new DiaNode(GenerateMessageText(parms.faction, attackers.Count, demands, caravan));
            DiaOption diaOption = new DiaOption("CaravanDemand_Give".Translate());

            diaOption.action = delegate
            {
                ActionGive(caravan, demands, attackers);
            };
            diaOption.resolveTree = true;
            diaNode.options.Add(diaOption);
            DiaOption diaOption2 = new DiaOption("CaravanDemand_Fight".Translate());

            diaOption2.action = delegate
            {
                ActionFight(caravan, attackers);
            };
            diaOption2.resolveTree = true;
            diaNode.options.Add(diaOption2);
            string      text               = "CaravanDemandTitle".Translate(parms.faction.Name);
            WindowStack windowStack        = Find.WindowStack;
            DiaNode     nodeRoot           = diaNode;
            Faction     faction            = parms.faction;
            bool        delayInteractivity = true;
            string      title              = text;

            windowStack.Add(new Dialog_NodeTreeWithFactionInfo(nodeRoot, faction, delayInteractivity, radioMode: false, title));
            Find.Archive.Add(new ArchivedDialog(diaNode.text, text, parms.faction));
            return(true);
        }
        protected override List <Pawn> GeneratePawns(IncidentParms parms)
        {
            if (!PawnGroupMakerUtility.TryGetRandomFactionForNormalPawnGroup(parms.points, out parms.faction, null, false, false, false, true))
            {
                return(new List <Pawn>());
            }
            PawnGroupMakerParms defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(parms, false);

            defaultPawnGroupMakerParms.generateFightersOnly = true;
            return(PawnGroupMakerUtility.GeneratePawns(PawnGroupKindDefOf.Normal, defaultPawnGroupMakerParms, true).ToList <Pawn>());
        }
        protected List <Pawn> SpawnPawns(IncidentParms parms)
        {
            Map         map  = (Map)parms.target;
            List <Pawn> list = PawnGroupMakerUtility.GeneratePawns(IncidentParmsUtility.GetDefaultPawnGroupMakerParms(PawnGroupKindDef, parms, ensureCanGenerateAtLeastOnePawn: true), warnOnZeroResults: false).ToList();

            foreach (Pawn item in list)
            {
                IntVec3 loc = CellFinder.RandomClosewalkCellNear(parms.spawnCenter, map, 5);
                GenSpawn.Spawn(item, loc, map);
            }
            return(list);
        }
Ejemplo n.º 11
0
        protected List <Pawn> SpawnPawns(IncidentParms parms)
        {
            Map map = (Map)parms.target;
            PawnGroupMakerParms defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(parms, false);
            List <Pawn>         list = PawnGroupMakerUtility.GeneratePawns(this.PawnGroupKindDef, defaultPawnGroupMakerParms, false).ToList <Pawn>();

            foreach (Pawn current in list)
            {
                IntVec3 loc = CellFinder.RandomClosewalkCellNear(parms.spawnCenter, map, 5, null);
                GenSpawn.Spawn(current, loc, map);
            }
            return(list);
        }
Ejemplo n.º 12
0
        protected override List <Pawn> GeneratePawns(IncidentParms parms)
        {
            if (!PawnGroupMakerUtility.TryGetRandomFactionForCombatPawnGroup(parms.points, out parms.faction, null, false, false, false, true))
            {
                Log.Error("Could not find any valid faction for " + this.def + " incident.", false);
                return(new List <Pawn>());
            }
            PawnGroupMakerParms defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(PawnGroupKindDefOf.Combat, parms, false);

            defaultPawnGroupMakerParms.generateFightersOnly            = true;
            defaultPawnGroupMakerParms.dontUseSingleUseRocketLaunchers = true;
            return(PawnGroupMakerUtility.GeneratePawns(defaultPawnGroupMakerParms, true).ToList <Pawn>());
        }
        private IEnumerable <Pawn> GeneratePawns(GenStepParams parms, Map map)
        {
            float points = (parms.siteCoreOrPart == null) ? this.defaultPointsRange.RandomInRange : parms.siteCoreOrPart.parms.threatPoints;
            PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms();

            pawnGroupMakerParms.groupKind = PawnGroupKindDefOf.Combat;
            pawnGroupMakerParms.tile      = map.Tile;
            pawnGroupMakerParms.faction   = Faction.OfMechanoids;
            pawnGroupMakerParms.points    = points;
            if (parms.siteCoreOrPart != null)
            {
                pawnGroupMakerParms.seed = new int?(SleepingMechanoidsSitePartUtility.GetPawnGroupMakerSeed(parms.siteCoreOrPart.parms));
            }
            return(PawnGroupMakerUtility.GeneratePawns(pawnGroupMakerParms, true));
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Caravan caravan = (Caravan)parms.target;

            if (!PawnGroupMakerUtility.TryGetRandomFactionForNormalPawnGroup(parms.points, out parms.faction, null, false, false, false, true))
            {
                return(false);
            }
            PawnGroupMakerParms defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(parms, false);

            defaultPawnGroupMakerParms.generateFightersOnly = true;
            List <Pawn>  attackers = PawnGroupMakerUtility.GeneratePawns(PawnGroupKindDefOf.Normal, defaultPawnGroupMakerParms, true).ToList <Pawn>();
            List <Thing> demands   = this.GenerateDemands(caravan);

            if (demands.Count == 0)
            {
                return(false);
            }
            CameraJumper.TryJumpAndSelect(caravan);
            DiaNode   diaNode   = new DiaNode(this.GenerateMessageText(parms.faction, attackers.Count, demands));
            DiaOption diaOption = new DiaOption("CaravanDemand_Give".Translate());

            diaOption.action = delegate
            {
                this.ActionGive(caravan, demands, attackers);
            };
            diaOption.resolveTree = true;
            diaNode.options.Add(diaOption);
            DiaOption diaOption2 = new DiaOption("CaravanDemand_Fight".Translate());

            diaOption2.action = delegate
            {
                this.ActionFight(caravan, attackers);
            };
            diaOption2.resolveTree = true;
            diaNode.options.Add(diaOption2);
            WindowStack arg_15D_0          = Find.WindowStack;
            DiaNode     nodeRoot           = diaNode;
            bool        delayInteractivity = true;
            string      title = "CaravanDemandTitle".Translate(new object[]
            {
                parms.faction.Name
            });

            arg_15D_0.Add(new Dialog_NodeTree(nodeRoot, delayInteractivity, false, title));
            return(true);
        }
        private IEnumerable <Pawn> GenerateAmbushPawns()
        {
            IEnumerable <Pawn> result;

            if (this.manhunters)
            {
                PawnKindDef animalKind;
                if (!ManhunterPackIncidentUtility.TryFindManhunterAnimalKind(this.points, base.Map.Tile, out animalKind) && !ManhunterPackIncidentUtility.TryFindManhunterAnimalKind(this.points, -1, out animalKind))
                {
                    result = Enumerable.Empty <Pawn>();
                }
                else
                {
                    result = ManhunterPackIncidentUtility.GenerateAnimals(animalKind, base.Map.Tile, this.points);
                }
            }
            else
            {
                Faction faction;
                if (this.mechanoids)
                {
                    faction = Faction.OfMechanoids;
                }
                else
                {
                    faction = (base.Map.ParentFaction ?? Find.FactionManager.RandomEnemyFaction(false, false, false, TechLevel.Undefined));
                }
                if (faction == null)
                {
                    result = Enumerable.Empty <Pawn>();
                }
                else
                {
                    result = PawnGroupMakerUtility.GeneratePawns(new PawnGroupMakerParms
                    {
                        groupKind = PawnGroupKindDefOf.Combat,
                        tile      = base.Map.Tile,
                        faction   = faction,
                        points    = this.points
                    }, true);
                }
            }
            return(result);
        }
Ejemplo n.º 16
0
 public static void LogPawnGroupsMade()
 {
     Dialog_DebugOptionListLister.ShowSimpleDebugMenu(from fac in Find.FactionManager.AllFactions
                                                      where !fac.def.pawnGroupMakers.NullOrEmpty()
                                                      select fac, (Faction fac) => fac.Name + " (" + fac.def.defName + ")", delegate(Faction fac)
     {
         StringBuilder sb = new StringBuilder();
         sb.AppendLine("FACTION: " + fac.Name + " (" + fac.def.defName + ") min=" + fac.def.MinPointsToGenerateNormalPawnGroup());
         Action <float> action = delegate(float points)
         {
             if (!(points < fac.def.MinPointsToGenerateNormalPawnGroup()))
             {
                 PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms();
                 pawnGroupMakerParms.tile    = Find.VisibleMap.Tile;
                 pawnGroupMakerParms.points  = points;
                 pawnGroupMakerParms.faction = fac;
                 sb.AppendLine("Group with " + pawnGroupMakerParms.points + " points (max option cost: " + PawnGroupMakerUtility.MaxAllowedPawnGenOptionCost(fac, points, RaidStrategyDefOf.ImmediateAttack) + ")");
                 float num = 0f;
                 foreach (Pawn item in PawnGroupMakerUtility.GeneratePawns(PawnGroupKindDefOf.Normal, pawnGroupMakerParms, false).OrderBy((Pawn pa) => pa.kindDef.combatPower))
                 {
                     string text     = (item.equipment.Primary == null) ? "no-equipment" : item.equipment.Primary.Label;
                     Apparel apparel = item.apparel.FirstApparelOnBodyPartGroup(BodyPartGroupDefOf.Torso);
                     string text2    = (apparel == null) ? "shirtless" : apparel.LabelCap;
                     sb.AppendLine("  " + item.kindDef.combatPower.ToString("F0").PadRight(6) + item.kindDef.defName + ", " + text + ", " + text2);
                     num += item.kindDef.combatPower;
                 }
                 sb.AppendLine("         totalCost " + num);
                 sb.AppendLine();
             }
         };
         foreach (float item2 in Dialog_DebugActionsMenu.PointsOptions())
         {
             float obj = item2;
             action(obj);
         }
         Log.Message(sb.ToString());
     });
 }
Ejemplo n.º 17
0
        private IEnumerable <Pawn> GenerateAmbushPawns()
        {
            if (ambushType == SignalActionAmbushType.Manhunters)
            {
                if (!ManhunterPackIncidentUtility.TryFindManhunterAnimalKind(points, base.Map.Tile, out PawnKindDef animalKind) && !ManhunterPackIncidentUtility.TryFindManhunterAnimalKind(points, -1, out animalKind))
                {
                    return(Enumerable.Empty <Pawn>());
                }
                return(ManhunterPackIncidentUtility.GenerateAnimals_NewTmp(animalKind, base.Map.Tile, points));
            }
            Faction faction = (ambushType != SignalActionAmbushType.Mechanoids) ? (base.Map.ParentFaction ?? Find.FactionManager.RandomEnemyFaction(allowHidden: false, allowDefeated: false, allowNonHumanlike: false)) : Faction.OfMechanoids;

            if (faction == null)
            {
                return(Enumerable.Empty <Pawn>());
            }
            return(PawnGroupMakerUtility.GeneratePawns(new PawnGroupMakerParms
            {
                groupKind = PawnGroupKindDefOf.Combat,
                tile = base.Map.Tile,
                faction = faction,
                points = Mathf.Max(points, faction.def.MinPointsToGeneratePawnGroup(PawnGroupKindDefOf.Combat))
            }));
        }
Ejemplo n.º 18
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map = (Map)parms.target;

            this.ResolveRaidPoints(parms);
            if (!this.TryResolveRaidFaction(parms))
            {
                return(false);
            }
            this.ResolveRaidStrategy(parms);
            this.ResolveRaidArriveMode(parms);
            if (!this.ResolveRaidSpawnCenter(parms))
            {
                return(false);
            }
            IncidentParmsUtility.AdjustPointsForGroupArrivalParams(parms);
            PawnGroupMakerParms defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(parms, false);
            List <Pawn>         list = PawnGroupMakerUtility.GeneratePawns(PawnGroupKindDefOf.Normal, defaultPawnGroupMakerParms, true).ToList();

            if (list.Count == 0)
            {
                Log.Error("Got no pawns spawning raid from parms " + parms);
                return(false);
            }
            TargetInfo target = TargetInfo.Invalid;

            if (parms.raidArrivalMode == PawnsArriveMode.CenterDrop || parms.raidArrivalMode == PawnsArriveMode.EdgeDrop)
            {
                DropPodUtility.DropThingsNear(parms.spawnCenter, map, list.Cast <Thing>(), parms.raidPodOpenDelay, false, true, true, false);
                target = new TargetInfo(parms.spawnCenter, map, false);
            }
            else
            {
                foreach (Pawn item in list)
                {
                    IntVec3 loc = CellFinder.RandomClosewalkCellNear(parms.spawnCenter, map, 8, null);
                    GenSpawn.Spawn(item, loc, map, parms.spawnRotation, false);
                    target = item;
                }
            }
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("Points = " + parms.points.ToString("F0"));
            foreach (Pawn item2 in list)
            {
                string str = (item2.equipment == null || item2.equipment.Primary == null) ? "unarmed" : item2.equipment.Primary.LabelCap;
                stringBuilder.AppendLine(item2.KindLabel + " - " + str);
            }
            string letterLabel = this.GetLetterLabel(parms);
            string letterText  = this.GetLetterText(parms, list);

            PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter(list, ref letterLabel, ref letterText, this.GetRelatedPawnsInfoLetterText(parms), true, true);
            Find.LetterStack.ReceiveLetter(letterLabel, letterText, this.GetLetterDef(), target, stringBuilder.ToString());
            if (this.GetLetterDef() == LetterDefOf.ThreatBig)
            {
                TaleRecorder.RecordTale(TaleDefOf.RaidArrived);
            }
            Lord lord = LordMaker.MakeNewLord(parms.faction, parms.raidStrategy.Worker.MakeLordJob(parms, map), map, list);

            AvoidGridMaker.RegenerateAvoidGridsFor(parms.faction, map);
            LessonAutoActivator.TeachOpportunity(ConceptDefOf.EquippingWeapons, OpportunityType.Critical);
            if (!PlayerKnowledgeDatabase.IsComplete(ConceptDefOf.ShieldBelts))
            {
                for (int i = 0; i < list.Count; i++)
                {
                    Pawn pawn = list[i];
                    if (pawn.apparel.WornApparel.Any((Apparel ap) => ap is ShieldBelt))
                    {
                        LessonAutoActivator.TeachOpportunity(ConceptDefOf.ShieldBelts, OpportunityType.Critical);
                        break;
                    }
                }
            }
            if (DebugViewSettings.drawStealDebug && parms.faction.HostileTo(Faction.OfPlayer))
            {
                Log.Message("Market value threshold to start stealing: " + StealAIUtility.StartStealingMarketValueThreshold(lord) + " (colony wealth = " + map.wealthWatcher.WealthTotal + ")");
            }
            return(true);
        }
Ejemplo n.º 19
0
 public static void PawnGroupsMade()
 {
     Dialog_DebugOptionListLister.ShowSimpleDebugMenu <Faction>(from fac in Find.FactionManager.AllFactions
                                                                where !fac.def.pawnGroupMakers.NullOrEmpty <PawnGroupMaker>()
                                                                select fac, (Faction fac) => fac.Name + " (" + fac.def.defName + ")", delegate(Faction fac)
     {
         StringBuilder sb = new StringBuilder();
         sb.AppendLine(string.Concat(new object[]
         {
             "FACTION: ",
             fac.Name,
             " (",
             fac.def.defName,
             ") min=",
             fac.def.MinPointsToGeneratePawnGroup(PawnGroupKindDefOf.Combat)
         }));
         Action <float> action = delegate(float points)
         {
             if (points < fac.def.MinPointsToGeneratePawnGroup(PawnGroupKindDefOf.Combat))
             {
                 return;
             }
             PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms();
             pawnGroupMakerParms.groupKind           = PawnGroupKindDefOf.Combat;
             pawnGroupMakerParms.tile    = Find.CurrentMap.Tile;
             pawnGroupMakerParms.points  = points;
             pawnGroupMakerParms.faction = fac;
             sb.AppendLine(string.Concat(new object[]
             {
                 "Group with ",
                 pawnGroupMakerParms.points,
                 " points (max option cost: ",
                 PawnGroupMakerUtility.MaxPawnCost(fac, points, RaidStrategyDefOf.ImmediateAttack, PawnGroupKindDefOf.Combat),
                 ")"
             }));
             float num = 0f;
             foreach (Pawn current in PawnGroupMakerUtility.GeneratePawns(pawnGroupMakerParms, false).OrderBy((Pawn pa) => pa.kindDef.combatPower))
             {
                 string text;
                 if (current.equipment.Primary != null)
                 {
                     text = current.equipment.Primary.Label;
                 }
                 else
                 {
                     text = "no-equipment";
                 }
                 Apparel apparel = current.apparel.FirstApparelOnBodyPartGroup(BodyPartGroupDefOf.Torso);
                 string text2;
                 if (apparel != null)
                 {
                     text2 = apparel.LabelCap;
                 }
                 else
                 {
                     text2 = "shirtless";
                 }
                 sb.AppendLine(string.Concat(new string[]
                 {
                     "  ",
                     current.kindDef.combatPower.ToString("F0").PadRight(6),
                     current.kindDef.defName,
                     ", ",
                     text,
                     ", ",
                     text2
                 }));
                 num += current.kindDef.combatPower;
             }
             sb.AppendLine("         totalCost " + num);
             sb.AppendLine();
         };
         foreach (float obj in Dialog_DebugActionsMenu.PointsOptions(false))
         {
             action(obj);
         }
         Log.Message(sb.ToString(), false);
     });
 }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map = (Map)parms.target;

            this.ResolveRaidPoints(parms);
            if (!this.TryResolveRaidFaction(parms))
            {
                return(false);
            }
            PawnGroupKindDef combat = PawnGroupKindDefOf.Combat;

            this.ResolveRaidStrategy(parms, combat);
            this.ResolveRaidArriveMode(parms);
            if (!parms.raidArrivalMode.Worker.TryResolveRaidSpawnCenter(parms))
            {
                return(false);
            }
            parms.points = IncidentWorker_Raid.AdjustedRaidPoints(parms.points, parms.raidArrivalMode, parms.raidStrategy, parms.faction, combat);
            PawnGroupMakerParms defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(combat, parms, false);
            List <Pawn>         list = PawnGroupMakerUtility.GeneratePawns(defaultPawnGroupMakerParms, true).ToList <Pawn>();

            if (list.Count == 0)
            {
                Log.Error("Got no pawns spawning raid from parms " + parms, false);
                return(false);
            }
            parms.raidArrivalMode.Worker.Arrive(list, parms);
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("Points = " + parms.points.ToString("F0"));
            foreach (Pawn pawn in list)
            {
                string str = (pawn.equipment == null || pawn.equipment.Primary == null) ? "unarmed" : pawn.equipment.Primary.LabelCap;
                stringBuilder.AppendLine(pawn.KindLabel + " - " + str);
            }
            string letterLabel = this.GetLetterLabel(parms);
            string letterText  = this.GetLetterText(parms, list);

            PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter(list, ref letterLabel, ref letterText, this.GetRelatedPawnsInfoLetterText(parms), true, true);
            List <TargetInfo> list2 = new List <TargetInfo>();

            if (parms.pawnGroups != null)
            {
                List <List <Pawn> > list3 = IncidentParmsUtility.SplitIntoGroups(list, parms.pawnGroups);
                List <Pawn>         list4 = list3.MaxBy((List <Pawn> x) => x.Count);
                if (list4.Any <Pawn>())
                {
                    list2.Add(list4[0]);
                }
                for (int i = 0; i < list3.Count; i++)
                {
                    if (list3[i] != list4)
                    {
                        if (list3[i].Any <Pawn>())
                        {
                            list2.Add(list3[i][0]);
                        }
                    }
                }
            }
            else if (list.Any <Pawn>())
            {
                list2.Add(list[0]);
            }
            Find.LetterStack.ReceiveLetter(letterLabel, letterText, this.GetLetterDef(), list2, parms.faction, stringBuilder.ToString());
            parms.raidStrategy.Worker.MakeLords(parms, list);
            AvoidGridMaker.RegenerateAvoidGridsFor(parms.faction, map);
            LessonAutoActivator.TeachOpportunity(ConceptDefOf.EquippingWeapons, OpportunityType.Critical);
            if (!PlayerKnowledgeDatabase.IsComplete(ConceptDefOf.ShieldBelts))
            {
                for (int j = 0; j < list.Count; j++)
                {
                    Pawn pawn2 = list[j];
                    if (pawn2.apparel.WornApparel.Any((Apparel ap) => ap is ShieldBelt))
                    {
                        LessonAutoActivator.TeachOpportunity(ConceptDefOf.ShieldBelts, OpportunityType.Critical);
                        break;
                    }
                }
            }
            return(true);
        }
        private static void <PawnGroupsMade> m__3(Faction fac)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(string.Concat(new object[]
            {
                "FACTION: ",
                fac.Name,
                " (",
                fac.def.defName,
                ") min=",
                fac.def.MinPointsToGeneratePawnGroup(PawnGroupKindDefOf.Combat)
            }));
            Action <float> action = delegate(float points)
            {
                if (points < fac.def.MinPointsToGeneratePawnGroup(PawnGroupKindDefOf.Combat))
                {
                    return;
                }
                PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms();
                pawnGroupMakerParms.groupKind = PawnGroupKindDefOf.Combat;
                pawnGroupMakerParms.tile      = Find.CurrentMap.Tile;
                pawnGroupMakerParms.points    = points;
                pawnGroupMakerParms.faction   = fac;
                sb.AppendLine(string.Concat(new object[]
                {
                    "Group with ",
                    pawnGroupMakerParms.points,
                    " points (max option cost: ",
                    PawnGroupMakerUtility.MaxPawnCost(fac, points, RaidStrategyDefOf.ImmediateAttack, PawnGroupKindDefOf.Combat),
                    ")"
                }));
                float num2 = 0f;
                foreach (Pawn pawn in from pa in PawnGroupMakerUtility.GeneratePawns(pawnGroupMakerParms, false)
                         orderby pa.kindDef.combatPower
                         select pa)
                {
                    string text;
                    if (pawn.equipment.Primary != null)
                    {
                        text = pawn.equipment.Primary.Label;
                    }
                    else
                    {
                        text = "no-equipment";
                    }
                    Apparel apparel = pawn.apparel.FirstApparelOnBodyPartGroup(BodyPartGroupDefOf.Torso);
                    string  text2;
                    if (apparel != null)
                    {
                        text2 = apparel.LabelCap;
                    }
                    else
                    {
                        text2 = "shirtless";
                    }
                    sb.AppendLine(string.Concat(new string[]
                    {
                        "  ",
                        pawn.kindDef.combatPower.ToString("F0").PadRight(6),
                        pawn.kindDef.defName,
                        ", ",
                        text,
                        ", ",
                        text2
                    }));
                    num2 += pawn.kindDef.combatPower;
                }
                sb.AppendLine("         totalCost " + num2);
                sb.AppendLine();
            };

            foreach (float num in Dialog_DebugActionsMenu.PointsOptions(false))
            {
                float obj = num;
                action(obj);
            }
            Log.Message(sb.ToString(), false);
        }
Ejemplo n.º 22
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            ResolveRaidPoints(parms);
            if (!TryResolveRaidFaction(parms))
            {
                return(false);
            }
            PawnGroupKindDef combat = PawnGroupKindDefOf.Combat;

            ResolveRaidStrategy(parms, combat);
            ResolveRaidArriveMode(parms);
            parms.raidStrategy.Worker.TryGenerateThreats(parms);
            if (!parms.raidArrivalMode.Worker.TryResolveRaidSpawnCenter(parms))
            {
                return(false);
            }
            float points = parms.points;

            parms.points = AdjustedRaidPoints(parms.points, parms.raidArrivalMode, parms.raidStrategy, parms.faction, combat);
            List <Pawn> list = parms.raidStrategy.Worker.SpawnThreats(parms);

            if (list == null)
            {
                list = PawnGroupMakerUtility.GeneratePawns(IncidentParmsUtility.GetDefaultPawnGroupMakerParms(combat, parms)).ToList();
                if (list.Count == 0)
                {
                    Log.Error("Got no pawns spawning raid from parms " + parms);
                    return(false);
                }
                parms.raidArrivalMode.Worker.Arrive(list, parms);
            }
            GenerateRaidLoot(parms, points, list);
            TaggedString letterLabel = GetLetterLabel(parms);
            TaggedString letterText  = GetLetterText(parms, list);

            PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter(list, ref letterLabel, ref letterText, GetRelatedPawnsInfoLetterText(parms), informEvenIfSeenBefore: true);
            List <TargetInfo> list2 = new List <TargetInfo>();

            if (parms.pawnGroups != null)
            {
                List <List <Pawn> > list3 = IncidentParmsUtility.SplitIntoGroups(list, parms.pawnGroups);
                List <Pawn>         list4 = list3.MaxBy((List <Pawn> x) => x.Count);
                if (list4.Any())
                {
                    list2.Add(list4[0]);
                }
                for (int i = 0; i < list3.Count; i++)
                {
                    if (list3[i] != list4 && list3[i].Any())
                    {
                        list2.Add(list3[i][0]);
                    }
                }
            }
            else if (list.Any())
            {
                foreach (Pawn item in list)
                {
                    list2.Add(item);
                }
            }
            SendStandardLetter(letterLabel, letterText, GetLetterDef(), parms, list2);
            parms.raidStrategy.Worker.MakeLords(parms, list);
            LessonAutoActivator.TeachOpportunity(ConceptDefOf.EquippingWeapons, OpportunityType.Critical);
            if (!PlayerKnowledgeDatabase.IsComplete(ConceptDefOf.ShieldBelts))
            {
                for (int j = 0; j < list.Count; j++)
                {
                    if (list[j].apparel.WornApparel.Any((Apparel ap) => ap is ShieldBelt))
                    {
                        LessonAutoActivator.TeachOpportunity(ConceptDefOf.ShieldBelts, OpportunityType.Critical);
                        break;
                    }
                }
            }
            return(true);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            parms.points *= 1.5f;
            Caravan caravan = (Caravan)parms.target;
            bool    result;

            if (!PawnGroupMakerUtility.TryGetRandomFactionForCombatPawnGroup(parms.points, out parms.faction, null, false, false, false, true))
            {
                result = false;
            }
            else
            {
                PawnGroupMakerParms defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(PawnGroupKindDefOf.Combat, parms, false);
                defaultPawnGroupMakerParms.generateFightersOnly            = true;
                defaultPawnGroupMakerParms.dontUseSingleUseRocketLaunchers = true;
                List <Pawn> attackers = PawnGroupMakerUtility.GeneratePawns(defaultPawnGroupMakerParms, true).ToList <Pawn>();
                if (attackers.Count == 0)
                {
                    Log.Error(string.Concat(new object[]
                    {
                        "Caravan demand incident couldn't generate any enemies even though min points have been checked. faction=",
                        defaultPawnGroupMakerParms.faction,
                        "(",
                        (defaultPawnGroupMakerParms.faction == null) ? "null" : defaultPawnGroupMakerParms.faction.def.ToString(),
                        ") parms=",
                        parms
                    }), false);
                    result = false;
                }
                else
                {
                    List <Thing> demands = this.GenerateDemands(caravan);
                    if (demands.Count == 0)
                    {
                        result = false;
                    }
                    else
                    {
                        CameraJumper.TryJumpAndSelect(caravan);
                        DiaNode   diaNode   = new DiaNode(this.GenerateMessageText(parms.faction, attackers.Count, demands, caravan));
                        DiaOption diaOption = new DiaOption("CaravanDemand_Give".Translate());
                        diaOption.action = delegate()
                        {
                            this.ActionGive(caravan, demands, attackers);
                        };
                        diaOption.resolveTree = true;
                        diaNode.options.Add(diaOption);
                        DiaOption diaOption2 = new DiaOption("CaravanDemand_Fight".Translate());
                        diaOption2.action = delegate()
                        {
                            this.ActionFight(caravan, attackers);
                        };
                        diaOption2.resolveTree = true;
                        diaNode.options.Add(diaOption2);
                        string text = "CaravanDemandTitle".Translate(new object[]
                        {
                            parms.faction.Name
                        });
                        WindowStack windowStack        = Find.WindowStack;
                        DiaNode     nodeRoot           = diaNode;
                        Faction     faction            = parms.faction;
                        bool        delayInteractivity = true;
                        string      title = text;
                        windowStack.Add(new Dialog_NodeTreeWithFactionInfo(nodeRoot, faction, delayInteractivity, false, title));
                        Find.Archive.Add(new ArchivedDialog(diaNode.text, text, parms.faction));
                        result = true;
                    }
                }
            }
            return(result);
        }