コード例 #1
0
ファイル: DebugOutputsTextGen.cs プロジェクト: potsh/RimWorld
        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));
        }
コード例 #2
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));
        }