Beispiel #1
0
        private static string RandomArtworkDescription(TaleReference tr)
        {
            RulePackDef extraInclude = null;

            switch (Rand.RangeInclusive(0, 4))
            {
            case 0:
                extraInclude = RulePackDefOf.ArtDescription_Sculpture;
                break;

            case 1:
                extraInclude = RulePackDefOf.ArtDescription_WeaponMelee;
                break;

            case 2:
                extraInclude = RulePackDefOf.ArtDescription_WeaponGun;
                break;

            case 3:
                extraInclude = RulePackDefOf.ArtDescription_Furniture;
                break;

            case 4:
                extraInclude = RulePackDefOf.ArtDescription_SarcophagusPlate;
                break;
            }
            return(tr.GenerateText(TextGenerationPurpose.ArtDescription, extraInclude));
        }
Beispiel #2
0
        public static void NamesFromRulepack()
        {
            IEnumerable <RulePackDef> first = DefDatabase <FactionDef> .AllDefsListForReading.Select((FactionDef f) => f.factionNameMaker);

            IEnumerable <RulePackDef> second = DefDatabase <FactionDef> .AllDefsListForReading.Select((FactionDef f) => f.settlementNameMaker);

            IEnumerable <RulePackDef> second2 = DefDatabase <FactionDef> .AllDefsListForReading.Select((FactionDef f) => f.playerInitialSettlementNameMaker);

            IEnumerable <RulePackDef> second3 = DefDatabase <FactionDef> .AllDefsListForReading.Select((FactionDef f) => f.pawnNameMaker);

            IOrderedEnumerable <RulePackDef> orderedEnumerable = from d in (from d in Enumerable.Concat(second: DefDatabase <RulePackDef> .AllDefsListForReading.Where((RulePackDef d) => d.defName.Contains("Namer")), first: first.Concat(second).Concat(second2).Concat(second3))
                                                                            where d != null
                                                                            select d).Distinct()
                                                                 orderby d.defName
                                                                 select d;
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            foreach (RulePackDef item2 in orderedEnumerable)
            {
                RulePackDef     localNamer = item2;
                FloatMenuOption item       = new FloatMenuOption(localNamer.defName, delegate
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine("Testing RulePack " + localNamer.defName + " as a name generator:");
                    for (int i = 0; i < 200; i++)
                    {
                        string testPawnNameSymbol = (i % 2 == 0) ? "Smithee" : null;
                        stringBuilder.AppendLine(NameGenerator.GenerateName(localNamer, null, appendNumberIfNameUsed: false, localNamer.FirstRuleKeyword, testPawnNameSymbol));
                    }
                    Log.Message(stringBuilder.ToString());
                });
                list.Add(item);
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }
Beispiel #3
0
        public static void NamesFromRulepack()
        {
            IEnumerable <RulePackDef> first = from f in DefDatabase <FactionDef> .AllDefsListForReading
                                              select f.factionNameMaker;
            IEnumerable <RulePackDef> second = from f in DefDatabase <FactionDef> .AllDefsListForReading
                                               select f.settlementNameMaker;
            IEnumerable <RulePackDef> second2 = from f in DefDatabase <FactionDef> .AllDefsListForReading
                                                select f.playerInitialSettlementNameMaker;
            IEnumerable <RulePackDef> second3 = from f in DefDatabase <FactionDef> .AllDefsListForReading
                                                select f.pawnNameMaker;
            IEnumerable <RulePackDef> second4 = from d in DefDatabase <RulePackDef> .AllDefsListForReading
                                                where d.defName.Contains("Namer")
                                                select d;
            IOrderedEnumerable <RulePackDef> orderedEnumerable = from d in (from d in first.Concat(second).Concat(second2).Concat(second3)
                                                                            .Concat(second4)
                                                                            where d != null
                                                                            select d).Distinct()
                                                                 orderby d.defName
                                                                 select d;
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            foreach (RulePackDef item2 in orderedEnumerable)
            {
                RulePackDef     localNamer = item2;
                FloatMenuOption item       = new FloatMenuOption(localNamer.defName, delegate
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine("Testing RulePack " + localNamer.defName + " as  a name generator:");
                    for (int i = 0; i < 200; i++)
                    {
                        string text = (i % 2 != 0) ? null : "Smithee";
                        StringBuilder stringBuilder2 = stringBuilder;
                        RulePackDef rootPack         = localNamer;
                        string testPawnNameSymbol    = text;
                        stringBuilder2.AppendLine(NameGenerator.GenerateName(rootPack, null, appendNumberIfNameUsed: false, null, testPawnNameSymbol));
                    }
                    Log.Message(stringBuilder.ToString());
                });
                list.Add(item);
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }
 public BattleLogEntry_Event(Thing subject, RulePackDef eventDef, Thing initiator) : base(null)
 {
     if (subject is Pawn)
     {
         this.subjectPawn = (subject as Pawn);
     }
     else if (subject != null)
     {
         this.subjectThing = subject.def;
     }
     if (initiator is Pawn)
     {
         this.initiatorPawn = (initiator as Pawn);
     }
     else if (initiator != null)
     {
         this.initiatorThing = initiator.def;
     }
     this.eventDef = eventDef;
 }
 public BattleLogEntry_MeleeCombat(RulePackDef ruleDef, bool alwaysShowInCompact, Pawn initiator, Thing recipient, ImplementOwnerTypeDef implementType, string toolLabel, ThingDef ownerEquipmentDef = null, HediffDef ownerHediffDef = null, LogEntryDef def = null) : base(def)
 {
     this.ruleDef             = ruleDef;
     this.alwaysShowInCompact = alwaysShowInCompact;
     this.initiator           = initiator;
     this.implementType       = implementType;
     this.ownerEquipmentDef   = ownerEquipmentDef;
     this.ownerHediffDef      = ownerHediffDef;
     this.toolLabel           = toolLabel;
     if (recipient is Pawn)
     {
         this.recipientPawn = (recipient as Pawn);
     }
     else if (recipient != null)
     {
         this.recipientThing = recipient.def;
     }
     if (ownerEquipmentDef != null && ownerHediffDef != null)
     {
         Log.ErrorOnce(string.Format("Combat log owned by both equipment {0} and hediff {1}, may produce unexpected results", ownerEquipmentDef.label, ownerHediffDef.label), 96474669, false);
     }
 }
Beispiel #6
0
 public BattleLogEntry_StateTransition(Thing subject, RulePackDef transitionDef, Pawn initiator, Hediff culpritHediff, BodyPartRecord culpritTargetDef)
 {
     if (subject is Pawn)
     {
         subjectPawn = subject as Pawn;
     }
     else if (subject != null)
     {
         subjectThing = subject.def;
     }
     this.transitionDef = transitionDef;
     this.initiator     = initiator;
     if (culpritHediff != null)
     {
         culpritHediffDef = culpritHediff.def;
         if (culpritHediff.Part != null)
         {
             culpritHediffTargetPart = culpritHediff.Part;
         }
     }
     culpritTargetPart = culpritTargetDef;
 }
 public BattleLogEntry_MeleeCombat(RulePackDef outcomeRuleDef, RulePackDef maneuverRuleDef, Pawn initiator, Thing recipient, ImplementOwnerTypeDef implementType, string toolLabel, ThingDef ownerEquipmentDef = null, HediffDef ownerHediffDef = null)
 {
     this.outcomeRuleDef    = outcomeRuleDef;
     this.maneuverRuleDef   = maneuverRuleDef;
     this.initiator         = initiator;
     this.implementType     = implementType;
     this.ownerEquipmentDef = ownerEquipmentDef;
     this.ownerHediffDef    = ownerHediffDef;
     this.toolLabel         = toolLabel;
     if (recipient is Pawn)
     {
         this.recipientPawn = (recipient as Pawn);
     }
     else if (recipient != null)
     {
         this.recipientThing = recipient.def;
     }
     if (ownerEquipmentDef != null && ownerHediffDef != null)
     {
         Log.ErrorOnce(string.Format("Combat log owned by both equipment {0} and hediff {1}, may produce unexpected results", ownerEquipmentDef.label, ownerHediffDef.label), 96474669);
     }
 }
Beispiel #8
0
        public static void FlavorfulCombatTest()
        {
            List <DebugMenuOption>    list      = new List <DebugMenuOption>();
            IEnumerable <ManeuverDef> maneuvers = DefDatabase <ManeuverDef> .AllDefsListForReading;

            Func <ManeuverDef, RulePackDef>[] results = new Func <ManeuverDef, RulePackDef>[5]
            {
                (ManeuverDef m) => new RulePackDef[4]
                {
                    m.combatLogRulesHit,
                    m.combatLogRulesDeflect,
                    m.combatLogRulesMiss,
                    m.combatLogRulesDodge
                }.RandomElement(),
                (ManeuverDef m) => m.combatLogRulesHit,
                (ManeuverDef m) => m.combatLogRulesDeflect,
                (ManeuverDef m) => m.combatLogRulesMiss,
                (ManeuverDef m) => m.combatLogRulesDodge
            };
            string[] array = new string[5]
            {
                "(random)",
                "Hit",
                "Deflect",
                "Miss",
                "Dodge"
            };
            foreach (Pair <ManeuverDef, int> maneuverresult in maneuvers.Concat(null).Cross(Enumerable.Range(0, array.Length)))
            {
                DebugMenuOption item = new DebugMenuOption(string.Format("{0}/{1}", (maneuverresult.First == null) ? "(random)" : maneuverresult.First.defName, array[maneuverresult.Second]), DebugMenuOptionMode.Action, delegate
                {
                    CreateDamagedDestroyedMenu(delegate(Action <List <BodyPartRecord>, List <bool> > bodyPartCreator)
                    {
                        StringBuilder stringBuilder7 = new StringBuilder();
                        ManeuverDef maneuver         = default(ManeuverDef);
                        for (int num2 = 0; num2 < 100; num2++)
                        {
                            maneuver = maneuverresult.First;
                            if (maneuver == null)
                            {
                                maneuver = maneuvers.RandomElement();
                            }
                            RulePackDef rulePackDef     = results[maneuverresult.Second](maneuver);
                            List <BodyPartRecord> list8 = null;
                            List <bool> list9           = null;
                            if (rulePackDef == maneuver.combatLogRulesHit)
                            {
                                list8 = new List <BodyPartRecord>();
                                list9 = new List <bool>();
                                bodyPartCreator(list8, list9);
                            }
                            ImplementOwnerTypeDef implementOwnerTypeDef;
                            string toolLabel;
                            if (!(from ttp in DefDatabase <ThingDef> .AllDefsListForReading.Where((ThingDef td) => td.IsMeleeWeapon && !td.tools.NullOrEmpty()).SelectMany((ThingDef td) => td.tools.Select((Tool tool) => new Pair <ThingDef, Tool>(td, tool)))
                                  where ttp.Second.capacities.Contains(maneuver.requiredCapacity)
                                  select ttp).TryRandomElement(out var result))
                            {
                                Log.Warning(string.Concat("Melee weapon with tool with capacity ", maneuver.requiredCapacity, " not found."));
                                implementOwnerTypeDef = ImplementOwnerTypeDefOf.Bodypart;
                                toolLabel             = "(" + implementOwnerTypeDef.defName + ")";
                            }
                            else
                            {
                                implementOwnerTypeDef = ((result.Second == null) ? ImplementOwnerTypeDefOf.Bodypart : ImplementOwnerTypeDefOf.Weapon);
                                toolLabel             = ((result.Second != null) ? result.Second.label : ("(" + implementOwnerTypeDef.defName + ")"));
                            }
                            BattleLogEntry_MeleeCombat battleLogEntry_MeleeCombat = new BattleLogEntry_MeleeCombat(rulePackDef, alwaysShowInCompact: false, RandomPawnForCombat(), RandomPawnForCombat(), implementOwnerTypeDef, toolLabel, result.First);
                            battleLogEntry_MeleeCombat.FillTargets(list8, list9, battleLogEntry_MeleeCombat.RuleDef.defName.Contains("Deflect"));
                            battleLogEntry_MeleeCombat.Debug_OverrideTicks(Rand.Int);
                            stringBuilder7.AppendLine(battleLogEntry_MeleeCombat.ToGameStringFromPOV(null));
                        }
                        Log.Message(stringBuilder7.ToString());
                    });
                });
 public BattleLogEntry_DamageTaken(Pawn recipient, RulePackDef ruleDef, Pawn initiator = null)
 {
     initiatorPawn = initiator;
     recipientPawn = recipient;
     this.ruleDef  = ruleDef;
 }
Beispiel #10
0
        public static void FlavorfulCombatTest()
        {
            List <DebugMenuOption>    list      = new List <DebugMenuOption>();
            IEnumerable <ManeuverDef> maneuvers = DefDatabase <ManeuverDef> .AllDefsListForReading;

            Func <ManeuverDef, RulePackDef>[] results = new Func <ManeuverDef, RulePackDef>[5]
            {
                (ManeuverDef m) => new RulePackDef[4]
                {
                    m.combatLogRulesHit,
                    m.combatLogRulesDeflect,
                    m.combatLogRulesMiss,
                    m.combatLogRulesDodge
                }.RandomElement(),
                (ManeuverDef m) => m.combatLogRulesHit,
                (ManeuverDef m) => m.combatLogRulesDeflect,
                (ManeuverDef m) => m.combatLogRulesMiss,
                (ManeuverDef m) => m.combatLogRulesDodge
            };
            string[] array = new string[5]
            {
                "(random)",
                "Hit",
                "Deflect",
                "Miss",
                "Dodge"
            };
            foreach (Pair <ManeuverDef, int> item2 in maneuvers.Concat(null).Cross(Enumerable.Range(0, array.Length)))
            {
                DebugMenuOption item = new DebugMenuOption(string.Format("{0}/{1}", (item2.First != null) ? item2.First.defName : "(random)", array[item2.Second]), DebugMenuOptionMode.Action, delegate
                {
                    CreateDamagedDestroyedMenu(delegate(Action <List <BodyPartRecord>, List <bool> > bodyPartCreator)
                    {
                        StringBuilder stringBuilder7 = new StringBuilder();
                        for (int num2 = 0; num2 < 100; num2++)
                        {
                            ManeuverDef maneuver = item2.First;
                            if (maneuver == null)
                            {
                                maneuver = maneuvers.RandomElement();
                            }
                            RulePackDef rulePackDef     = results[item2.Second](maneuver);
                            List <BodyPartRecord> list8 = null;
                            List <bool> list9           = null;
                            if (rulePackDef == maneuver.combatLogRulesHit)
                            {
                                list8 = new List <BodyPartRecord>();
                                list9 = new List <bool>();
                                bodyPartCreator(list8, list9);
                            }
                            Pair <ThingDef, Tool> pair = (from ttp in (from td in DefDatabase <ThingDef> .AllDefsListForReading
                                                                       where td.IsMeleeWeapon && !td.tools.NullOrEmpty()
                                                                       select td).SelectMany((ThingDef td) => from tool in td.tools
                                                                                             select new Pair <ThingDef, Tool>(td, tool))
                                                          where ttp.Second.capacities.Contains(maneuver.requiredCapacity)
                                                          select ttp).RandomElement();
                            BattleLogEntry_MeleeCombat battleLogEntry_MeleeCombat = new BattleLogEntry_MeleeCombat(rulePackDef, alwaysShowInCompact: false, CombatLogTester.GenerateRandom(), CombatLogTester.GenerateRandom(), (pair.Second == null) ? ImplementOwnerTypeDefOf.Bodypart : ImplementOwnerTypeDefOf.Weapon, (pair.Second == null) ? "body part" : pair.Second.label, pair.First);
                            battleLogEntry_MeleeCombat.FillTargets(list8, list9, battleLogEntry_MeleeCombat.RuleDef.defName.Contains("Deflect"));
                            battleLogEntry_MeleeCombat.Debug_OverrideTicks(Rand.Int);
                            stringBuilder7.AppendLine(battleLogEntry_MeleeCombat.ToGameStringFromPOV(null));
                        }
                        Log.Message(stringBuilder7.ToString());
                    });
                });
                list.Add(item);
            }
            int rf;

            for (rf = 0; rf < 2; rf++)
            {
                list.Add(new DebugMenuOption((rf != 0) ? "Ranged fire burst" : "Ranged fire singleshot", DebugMenuOptionMode.Action, delegate
                {
                    StringBuilder stringBuilder6 = new StringBuilder();
                    for (int num = 0; num < 100; num++)
                    {
                        ThingDef thingDef = (from td in DefDatabase <ThingDef> .AllDefsListForReading
                                             where td.IsRangedWeapon
                                             select td).RandomElement();
                        bool flag  = Rand.Value < 0.2f;
                        bool flag2 = !flag && Rand.Value < 0.95f;
                        BattleLogEntry_RangedFire battleLogEntry_RangedFire = new BattleLogEntry_RangedFire(CombatLogTester.GenerateRandom(), (!flag) ? CombatLogTester.GenerateRandom() : null, (!flag2) ? thingDef : null, null, rf != 0);
                        battleLogEntry_RangedFire.Debug_OverrideTicks(Rand.Int);
                        stringBuilder6.AppendLine(battleLogEntry_RangedFire.ToGameStringFromPOV(null));
                    }
                    Log.Message(stringBuilder6.ToString());
                }));
            }
            list.Add(new DebugMenuOption("Ranged impact hit", DebugMenuOptionMode.Action, delegate
            {
                CreateDamagedDestroyedMenu(delegate(Action <List <BodyPartRecord>, List <bool> > bodyPartCreator)
                {
                    StringBuilder stringBuilder5 = new StringBuilder();
                    for (int n = 0; n < 100; n++)
                    {
                        ThingDef weaponDef3 = (from td in DefDatabase <ThingDef> .AllDefsListForReading
                                               where td.IsRangedWeapon
                                               select td).RandomElement();
                        List <BodyPartRecord> list6 = new List <BodyPartRecord>();
                        List <bool> list7           = new List <bool>();
                        bodyPartCreator(list6, list7);
                        Pawn pawn2 = CombatLogTester.GenerateRandom();
                        BattleLogEntry_RangedImpact battleLogEntry_RangedImpact3 = new BattleLogEntry_RangedImpact(CombatLogTester.GenerateRandom(), pawn2, pawn2, weaponDef3, null, ThingDefOf.Wall);
                        battleLogEntry_RangedImpact3.FillTargets(list6, list7, Rand.Chance(0.5f));
                        battleLogEntry_RangedImpact3.Debug_OverrideTicks(Rand.Int);
                        stringBuilder5.AppendLine(battleLogEntry_RangedImpact3.ToGameStringFromPOV(null));
                    }
                    Log.Message(stringBuilder5.ToString());
                });
            }));
            list.Add(new DebugMenuOption("Ranged impact miss", DebugMenuOptionMode.Action, delegate
            {
                StringBuilder stringBuilder4 = new StringBuilder();
                for (int l = 0; l < 100; l++)
                {
                    ThingDef weaponDef2 = (from td in DefDatabase <ThingDef> .AllDefsListForReading
                                           where td.IsRangedWeapon
                                           select td).RandomElement();
                    BattleLogEntry_RangedImpact battleLogEntry_RangedImpact2 = new BattleLogEntry_RangedImpact(CombatLogTester.GenerateRandom(), null, CombatLogTester.GenerateRandom(), weaponDef2, null, ThingDefOf.Wall);
                    battleLogEntry_RangedImpact2.Debug_OverrideTicks(Rand.Int);
                    stringBuilder4.AppendLine(battleLogEntry_RangedImpact2.ToGameStringFromPOV(null));
                }
                Log.Message(stringBuilder4.ToString());
            }));
            list.Add(new DebugMenuOption("Ranged impact hit incorrect", DebugMenuOptionMode.Action, delegate
            {
                CreateDamagedDestroyedMenu(delegate(Action <List <BodyPartRecord>, List <bool> > bodyPartCreator)
                {
                    StringBuilder stringBuilder3 = new StringBuilder();
                    for (int k = 0; k < 100; k++)
                    {
                        ThingDef weaponDef = (from td in DefDatabase <ThingDef> .AllDefsListForReading
                                              where td.IsRangedWeapon
                                              select td).RandomElement();
                        List <BodyPartRecord> list4 = new List <BodyPartRecord>();
                        List <bool> list5           = new List <bool>();
                        bodyPartCreator(list4, list5);
                        BattleLogEntry_RangedImpact battleLogEntry_RangedImpact = new BattleLogEntry_RangedImpact(CombatLogTester.GenerateRandom(), CombatLogTester.GenerateRandom(), CombatLogTester.GenerateRandom(), weaponDef, null, ThingDefOf.Wall);
                        battleLogEntry_RangedImpact.FillTargets(list4, list5, Rand.Chance(0.5f));
                        battleLogEntry_RangedImpact.Debug_OverrideTicks(Rand.Int);
                        stringBuilder3.AppendLine(battleLogEntry_RangedImpact.ToGameStringFromPOV(null));
                    }
                    Log.Message(stringBuilder3.ToString());
                });
            }));
            foreach (RulePackDef item3 in from def in DefDatabase <RulePackDef> .AllDefsListForReading
                     where def.defName.Contains("Transition") && !def.defName.Contains("Include")
                     select def)
            {
                list.Add(new DebugMenuOption(item3.defName, DebugMenuOptionMode.Action, delegate
                {
                    StringBuilder stringBuilder2 = new StringBuilder();
                    for (int j = 0; j < 100; j++)
                    {
                        Pawn pawn                 = CombatLogTester.GenerateRandom();
                        Pawn initiator            = CombatLogTester.GenerateRandom();
                        BodyPartRecord partRecord = pawn.health.hediffSet.GetNotMissingParts().RandomElement();
                        BattleLogEntry_StateTransition battleLogEntry_StateTransition = new BattleLogEntry_StateTransition(pawn, item3, initiator, HediffMaker.MakeHediff(DefDatabase <HediffDef> .AllDefsListForReading.RandomElement(), pawn, partRecord), pawn.RaceProps.body.AllParts.RandomElement());
                        battleLogEntry_StateTransition.Debug_OverrideTicks(Rand.Int);
                        stringBuilder2.AppendLine(battleLogEntry_StateTransition.ToGameStringFromPOV(null));
                    }
                    Log.Message(stringBuilder2.ToString());
                }));
            }
            foreach (RulePackDef item4 in from def in DefDatabase <RulePackDef> .AllDefsListForReading
                     where def.defName.Contains("DamageEvent") && !def.defName.Contains("Include")
                     select def)
            {
                list.Add(new DebugMenuOption(item4.defName, DebugMenuOptionMode.Action, delegate
                {
                    CreateDamagedDestroyedMenu(delegate(Action <List <BodyPartRecord>, List <bool> > bodyPartCreator)
                    {
                        StringBuilder stringBuilder = new StringBuilder();
                        for (int i = 0; i < 100; i++)
                        {
                            List <BodyPartRecord> list2 = new List <BodyPartRecord>();
                            List <bool> list3           = new List <bool>();
                            bodyPartCreator(list2, list3);
                            Pawn recipient = CombatLogTester.GenerateRandom();
                            BattleLogEntry_DamageTaken battleLogEntry_DamageTaken = new BattleLogEntry_DamageTaken(recipient, item4);
                            battleLogEntry_DamageTaken.FillTargets(list2, list3, deflected: false);
                            battleLogEntry_DamageTaken.Debug_OverrideTicks(Rand.Int);
                            stringBuilder.AppendLine(battleLogEntry_DamageTaken.ToGameStringFromPOV(null));
                        }
                        Log.Message(stringBuilder.ToString());
                    });
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
 public override void PostExposeData(object obj)
 {
     if (Scribe.mode == LoadSaveMode.LoadingVars)
     {
         Game game = obj as Game;
         if (game != null && game.battleLog == null)
         {
             game.battleLog = new BattleLog();
         }
         BattleLogEntry_MeleeCombat battleLogEntry_MeleeCombat = obj as BattleLogEntry_MeleeCombat;
         if (battleLogEntry_MeleeCombat != null)
         {
             if (battleLogEntry_MeleeCombat.RuleDef == null)
             {
                 RulePackDef value  = null;
                 RulePackDef value2 = null;
                 Scribe_Defs.Look(ref value, "outcomeRuleDef");
                 Scribe_Defs.Look(ref value2, "maneuverRuleDef");
                 if (value != null && value2 != null)
                 {
                     foreach (RulePackDef item in DefDatabase <RulePackDef> .AllDefsListForReading)
                     {
                         if (!item.include.NullOrEmpty() && item.include.Count == 2 && ((item.include[0] == value && item.include[1] == value2) || (item.include[1] == value && item.include[0] == value2)))
                         {
                             battleLogEntry_MeleeCombat.RuleDef = item;
                             break;
                         }
                     }
                 }
             }
             if (battleLogEntry_MeleeCombat.def == null)
             {
                 battleLogEntry_MeleeCombat.def = LogEntryDefOf.MeleeAttack;
             }
         }
     }
     if (Scribe.mode == LoadSaveMode.PostLoadInit)
     {
         Map map = obj as Map;
         if (map != null && map.pawnDestinationReservationManager == null)
         {
             map.pawnDestinationReservationManager = new PawnDestinationReservationManager();
         }
         Pawn pawn = obj as Pawn;
         if (pawn != null && pawn.Spawned && pawn.rotationTracker == null)
         {
             pawn.rotationTracker = new Pawn_RotationTracker(pawn);
         }
         Pawn_MindState pawn_MindState = obj as Pawn_MindState;
         if (pawn_MindState != null && pawn_MindState.inspirationHandler == null)
         {
             pawn_MindState.inspirationHandler = new InspirationHandler(pawn_MindState.pawn);
         }
         ImportantPawnComp importantPawnComp = obj as ImportantPawnComp;
         if (importantPawnComp != null && importantPawnComp.pawn == null)
         {
             importantPawnComp.pawn = new ThingOwner <Pawn>(importantPawnComp, oneStackOnly: true);
         }
         Pawn_RecordsTracker pawn_RecordsTracker = obj as Pawn_RecordsTracker;
         if (pawn_RecordsTracker != null && Find.TaleManager.AnyTaleConcerns(pawn_RecordsTracker.pawn))
         {
             pawn_RecordsTracker.AccumulateStoryEvent(StoryEventDefOf.TaleCreated);
         }
         WorldPawns worldPawns = obj as WorldPawns;
         if (worldPawns != null && worldPawns.gc == null)
         {
             worldPawns.gc = new WorldPawnGC();
         }
         GameCondition gameCondition = obj as GameCondition;
         if (gameCondition != null && !gameCondition.Permanent && gameCondition.Duration > 1000000000)
         {
             gameCondition.Permanent = true;
         }
         Building_TurretGun building_TurretGun = obj as Building_TurretGun;
         if (building_TurretGun != null && building_TurretGun.gun == null)
         {
             building_TurretGun.MakeGun();
         }
     }
 }
Beispiel #12
0
 public BattleLogEntry_ItemUsed(Pawn caster, Thing target, ThingDef itemUsed, RulePackDef eventDef)
     : base(target, eventDef, caster)
 {
     this.itemUsed = itemUsed;
 }
 public BattleLogEntry_AbilityUsed(Pawn caster, Thing target, AbilityDef ability, RulePackDef eventDef)
     : base(target, eventDef, caster)
 {
     abilityUsed = ability;
 }
Beispiel #14
0
        public static void FlavorfulCombatTest()
        {
            List <DebugMenuOption>    list      = new List <DebugMenuOption>();
            IEnumerable <ManeuverDef> maneuvers = DefDatabase <ManeuverDef> .AllDefsListForReading;

            Func <ManeuverDef, RulePackDef>[] results = new Func <ManeuverDef, RulePackDef>[5]
            {
                (ManeuverDef m) => new RulePackDef[4]
                {
                    m.combatLogRulesHit,
                    m.combatLogRulesDeflect,
                    m.combatLogRulesMiss,
                    m.combatLogRulesDodge
                }.RandomElement(),
                (ManeuverDef m) => m.combatLogRulesHit,
                (ManeuverDef m) => m.combatLogRulesDeflect,
                (ManeuverDef m) => m.combatLogRulesMiss,
                (ManeuverDef m) => m.combatLogRulesDodge
            };
            string[] array = new string[5]
            {
                "(random)",
                "Hit",
                "Deflect",
                "Miss",
                "Dodge"
            };
            foreach (Pair <ManeuverDef, int> maneuverresult in maneuvers.Concat(null).Cross(Enumerable.Range(0, array.Length)))
            {
                DebugMenuOption item = new DebugMenuOption(string.Format("{0}/{1}", (maneuverresult.First == null) ? "(random)" : maneuverresult.First.defName, array[maneuverresult.Second]), DebugMenuOptionMode.Action, delegate
                {
                    CreateDamagedDestroyedMenu(delegate(Action <List <BodyPartRecord>, List <bool> > bodyPartCreator)
                    {
                        StringBuilder stringBuilder7 = new StringBuilder();
                        ManeuverDef maneuver         = default(ManeuverDef);
                        for (int num3 = 0; num3 < 100; num3++)
                        {
                            maneuver = maneuverresult.First;
                            if (maneuver == null)
                            {
                                maneuver = maneuvers.RandomElement();
                            }
                            RulePackDef rulePackDef     = results[maneuverresult.Second](maneuver);
                            List <BodyPartRecord> list8 = null;
                            List <bool> list9           = null;
                            if (rulePackDef == maneuver.combatLogRulesHit)
                            {
                                list8 = new List <BodyPartRecord>();
                                list9 = new List <bool>();
                                bodyPartCreator(list8, list9);
                            }
                            ImplementOwnerTypeDef implementOwnerTypeDef;
                            string toolLabel;
                            if (!(from ttp in DefDatabase <ThingDef> .AllDefsListForReading.Where((ThingDef td) => td.IsMeleeWeapon && !td.tools.NullOrEmpty()).SelectMany((ThingDef td) => td.tools.Select((Tool tool) => new Pair <ThingDef, Tool>(td, tool)))
                                  where ttp.Second.capacities.Contains(maneuver.requiredCapacity)
                                  select ttp).TryRandomElement(out Pair <ThingDef, Tool> result))
                            {
                                Log.Warning("Melee weapon with tool with capacity " + maneuver.requiredCapacity + " not found.");
                                implementOwnerTypeDef = ImplementOwnerTypeDefOf.Bodypart;
                                toolLabel             = "(" + implementOwnerTypeDef.defName + ")";
                            }
                            else
                            {
                                implementOwnerTypeDef = ((result.Second == null) ? ImplementOwnerTypeDefOf.Bodypart : ImplementOwnerTypeDefOf.Weapon);
                                toolLabel             = ((result.Second != null) ? result.Second.label : ("(" + implementOwnerTypeDef.defName + ")"));
                            }
                            BattleLogEntry_MeleeCombat battleLogEntry_MeleeCombat = new BattleLogEntry_MeleeCombat(rulePackDef, alwaysShowInCompact: false, RandomPawnForCombat(), RandomPawnForCombat(), implementOwnerTypeDef, toolLabel, result.First);
                            battleLogEntry_MeleeCombat.FillTargets(list8, list9, battleLogEntry_MeleeCombat.RuleDef.defName.Contains("Deflect"));
                            battleLogEntry_MeleeCombat.Debug_OverrideTicks(Rand.Int);
                            stringBuilder7.AppendLine(battleLogEntry_MeleeCombat.ToGameStringFromPOV(null));
                        }
                        Log.Message(stringBuilder7.ToString());
                    });
                });
                list.Add(item);
            }
            int rf = 0;

            while (rf < 2)
            {
                list.Add(new DebugMenuOption((rf == 0) ? "Ranged fire singleshot" : "Ranged fire burst", DebugMenuOptionMode.Action, delegate
                {
                    StringBuilder stringBuilder6 = new StringBuilder();
                    for (int num2 = 0; num2 < 100; num2++)
                    {
                        ThingDef thingDef = DefDatabase <ThingDef> .AllDefsListForReading.Where((ThingDef td) => td.IsRangedWeapon && td.IsWeaponUsingProjectiles && !td.menuHidden).RandomElement();
                        bool flag         = Rand.Value < 0.2f;
                        bool flag2        = !flag && Rand.Value < 0.95f;
                        BattleLogEntry_RangedFire battleLogEntry_RangedFire = new BattleLogEntry_RangedFire(RandomPawnForCombat(), flag ? null : RandomPawnForCombat(), flag2 ? null : thingDef, null, rf != 0);
                        battleLogEntry_RangedFire.Debug_OverrideTicks(Rand.Int);
                        stringBuilder6.AppendLine(battleLogEntry_RangedFire.ToGameStringFromPOV(null));
                    }
                    Log.Message(stringBuilder6.ToString());
                }));
                int num = ++rf;
            }
            list.Add(new DebugMenuOption("Ranged impact hit", DebugMenuOptionMode.Action, delegate
            {
                CreateDamagedDestroyedMenu(delegate(Action <List <BodyPartRecord>, List <bool> > bodyPartCreator)
                {
                    StringBuilder stringBuilder5 = new StringBuilder();
                    for (int n = 0; n < 100; n++)
                    {
                        ThingDef weaponDef3         = DefDatabase <ThingDef> .AllDefsListForReading.Where((ThingDef td) => td.IsRangedWeapon && td.IsWeaponUsingProjectiles && !td.menuHidden).RandomElement();
                        List <BodyPartRecord> list6 = new List <BodyPartRecord>();
                        List <bool> list7           = new List <bool>();
                        bodyPartCreator(list6, list7);
                        Pawn pawn2 = RandomPawnForCombat();
                        BattleLogEntry_RangedImpact battleLogEntry_RangedImpact3 = new BattleLogEntry_RangedImpact(RandomPawnForCombat(), pawn2, pawn2, weaponDef3, null, ThingDefOf.Wall);
                        battleLogEntry_RangedImpact3.FillTargets(list6, list7, Rand.Chance(0.5f));
                        battleLogEntry_RangedImpact3.Debug_OverrideTicks(Rand.Int);
                        stringBuilder5.AppendLine(battleLogEntry_RangedImpact3.ToGameStringFromPOV(null));
                    }
                    Log.Message(stringBuilder5.ToString());
                });
            }));
            list.Add(new DebugMenuOption("Ranged impact miss", DebugMenuOptionMode.Action, delegate
            {
                StringBuilder stringBuilder4 = new StringBuilder();
                for (int l = 0; l < 100; l++)
                {
                    ThingDef weaponDef2 = DefDatabase <ThingDef> .AllDefsListForReading.Where((ThingDef td) => td.IsRangedWeapon && td.IsWeaponUsingProjectiles && !td.menuHidden).RandomElement();
                    BattleLogEntry_RangedImpact battleLogEntry_RangedImpact2 = new BattleLogEntry_RangedImpact(RandomPawnForCombat(), null, RandomPawnForCombat(), weaponDef2, null, ThingDefOf.Wall);
                    battleLogEntry_RangedImpact2.Debug_OverrideTicks(Rand.Int);
                    stringBuilder4.AppendLine(battleLogEntry_RangedImpact2.ToGameStringFromPOV(null));
                }
                Log.Message(stringBuilder4.ToString());
            }));
            list.Add(new DebugMenuOption("Ranged impact hit incorrect", DebugMenuOptionMode.Action, delegate
            {
                CreateDamagedDestroyedMenu(delegate(Action <List <BodyPartRecord>, List <bool> > bodyPartCreator)
                {
                    StringBuilder stringBuilder3 = new StringBuilder();
                    for (int k = 0; k < 100; k++)
                    {
                        ThingDef weaponDef          = DefDatabase <ThingDef> .AllDefsListForReading.Where((ThingDef td) => td.IsRangedWeapon && td.IsWeaponUsingProjectiles && !td.menuHidden).RandomElement();
                        List <BodyPartRecord> list4 = new List <BodyPartRecord>();
                        List <bool> list5           = new List <bool>();
                        bodyPartCreator(list4, list5);
                        BattleLogEntry_RangedImpact battleLogEntry_RangedImpact = new BattleLogEntry_RangedImpact(RandomPawnForCombat(), RandomPawnForCombat(), RandomPawnForCombat(), weaponDef, null, ThingDefOf.Wall);
                        battleLogEntry_RangedImpact.FillTargets(list4, list5, Rand.Chance(0.5f));
                        battleLogEntry_RangedImpact.Debug_OverrideTicks(Rand.Int);
                        stringBuilder3.AppendLine(battleLogEntry_RangedImpact.ToGameStringFromPOV(null));
                    }
                    Log.Message(stringBuilder3.ToString());
                });
            }));
            foreach (RulePackDef transition in DefDatabase <RulePackDef> .AllDefsListForReading.Where((RulePackDef def) => def.defName.Contains("Transition") && !def.defName.Contains("Include")))
            {
                list.Add(new DebugMenuOption(transition.defName, DebugMenuOptionMode.Action, delegate
                {
                    StringBuilder stringBuilder2 = new StringBuilder();
                    for (int j = 0; j < 100; j++)
                    {
                        Pawn pawn                 = RandomPawnForCombat();
                        Pawn initiator            = RandomPawnForCombat();
                        BodyPartRecord partRecord = pawn.health.hediffSet.GetNotMissingParts().RandomElement();
                        BattleLogEntry_StateTransition battleLogEntry_StateTransition = new BattleLogEntry_StateTransition(pawn, transition, initiator, HediffMaker.MakeHediff(DefDatabase <HediffDef> .AllDefsListForReading.RandomElement(), pawn, partRecord), pawn.RaceProps.body.AllParts.RandomElement());
                        battleLogEntry_StateTransition.Debug_OverrideTicks(Rand.Int);
                        stringBuilder2.AppendLine(battleLogEntry_StateTransition.ToGameStringFromPOV(null));
                    }
                    Log.Message(stringBuilder2.ToString());
                }));
            }
            foreach (RulePackDef damageEvent in DefDatabase <RulePackDef> .AllDefsListForReading.Where((RulePackDef def) => def.defName.Contains("DamageEvent") && !def.defName.Contains("Include")))
            {
                list.Add(new DebugMenuOption(damageEvent.defName, DebugMenuOptionMode.Action, delegate
                {
                    CreateDamagedDestroyedMenu(delegate(Action <List <BodyPartRecord>, List <bool> > bodyPartCreator)
                    {
                        StringBuilder stringBuilder = new StringBuilder();
                        for (int i = 0; i < 100; i++)
                        {
                            List <BodyPartRecord> list2 = new List <BodyPartRecord>();
                            List <bool> list3           = new List <bool>();
                            bodyPartCreator(list2, list3);
                            BattleLogEntry_DamageTaken battleLogEntry_DamageTaken = new BattleLogEntry_DamageTaken(RandomPawnForCombat(), damageEvent);
                            battleLogEntry_DamageTaken.FillTargets(list2, list3, deflected: false);
                            battleLogEntry_DamageTaken.Debug_OverrideTicks(Rand.Int);
                            stringBuilder.AppendLine(battleLogEntry_DamageTaken.ToGameStringFromPOV(null));
                        }
                        Log.Message(stringBuilder.ToString());
                    });
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }