protected override GrammarRequest GenerateGrammarRequest()
        {
            GrammarRequest result = base.GenerateGrammarRequest();

            result.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", this.initiator, result.Constants));
            if (this.recipientPawn != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", this.recipientPawn, result.Constants));
            }
            else if (this.recipientThing != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForDef("RECIPIENT", this.recipientThing));
            }
            result.Includes.Add(this.ruleDef);
            if (!this.toolLabel.NullOrEmpty())
            {
                result.Rules.Add(new Rule_String("TOOL_label", this.toolLabel));
            }
            if (this.implementType != null && !this.implementType.implementOwnerRuleName.NullOrEmpty())
            {
                if (this.ownerEquipmentDef != null)
                {
                    result.Rules.AddRange(GrammarUtility.RulesForDef(this.implementType.implementOwnerRuleName, this.ownerEquipmentDef));
                }
                else if (this.ownerHediffDef != null)
                {
                    result.Rules.AddRange(GrammarUtility.RulesForDef(this.implementType.implementOwnerRuleName, this.ownerHediffDef));
                }
            }
            if (this.implementType != null && !this.implementType.implementOwnerTypeValue.NullOrEmpty())
            {
                result.Constants["IMPLEMENTOWNER_type"] = this.implementType.implementOwnerTypeValue;
            }
            return(result);
        }
		protected override string ToGameStringFromPOV_Worker(Thing pov, bool forceLog)
		{
			string result;
			if (this.initiator == null || this.recipient == null)
			{
				Log.ErrorOnce("PlayLogEntry_Interaction has a null pawn reference.", 34422, false);
				result = "[" + this.intDef.label + " error: null pawn reference]";
			}
			else
			{
				Rand.PushState();
				Rand.Seed = this.logID;
				GrammarRequest request = base.GenerateGrammarRequest();
				string text;
				if (pov == this.initiator)
				{
					request.IncludesBare.Add(this.intDef.logRulesInitiator);
					request.Rules.AddRange(GrammarUtility.RulesForPawn("ME", this.initiator, request.Constants));
					request.Rules.AddRange(GrammarUtility.RulesForPawn("OTHER", this.recipient, request.Constants));
					request.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", this.initiator, request.Constants));
					request.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", this.recipient, request.Constants));
					text = GrammarResolver.Resolve("r_logentry", request, "interaction from initiator", forceLog);
				}
				else if (pov == this.recipient)
				{
					if (this.intDef.logRulesRecipient != null)
					{
						request.IncludesBare.Add(this.intDef.logRulesRecipient);
					}
					else
					{
						request.IncludesBare.Add(this.intDef.logRulesInitiator);
					}
					request.Rules.AddRange(GrammarUtility.RulesForPawn("ME", this.recipient, request.Constants));
					request.Rules.AddRange(GrammarUtility.RulesForPawn("OTHER", this.initiator, request.Constants));
					request.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", this.initiator, request.Constants));
					request.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", this.recipient, request.Constants));
					text = GrammarResolver.Resolve("r_logentry", request, "interaction from recipient", forceLog);
				}
				else
				{
					Log.ErrorOnce("Cannot display PlayLogEntry_Interaction from POV who isn't initiator or recipient.", 51251, false);
					text = this.ToString();
				}
				if (this.extraSentencePacks != null)
				{
					for (int i = 0; i < this.extraSentencePacks.Count; i++)
					{
						request.Clear();
						request.Includes.Add(this.extraSentencePacks[i]);
						request.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", this.initiator, request.Constants));
						request.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", this.recipient, request.Constants));
						text = text + " " + GrammarResolver.Resolve(this.extraSentencePacks[i].RulesPlusIncludes[0].keyword, request, "extraSentencePack", forceLog);
					}
				}
				Rand.PopState();
				result = text;
			}
			return result;
		}
예제 #3
0
        public static string RandomSeedString()
        {
            GrammarRequest request = default(GrammarRequest);

            request.Includes.Add(RulePackDefOf.SeedGenerator);
            return(GrammarResolver.Resolve("r_seed", request).ToLower());
        }
        public static string WarEvent(Faction raider = null, Faction victim = null, Settlement town = null, bool fail = false)
        {
            GrammarRequest request = new GrammarRequest();

            if (victim == null && town == null)
            {
                request.Includes.Add(EndGameDefOf.FE_WarEvent_ArtifactCache);
                request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION1", raider));
                return(GrammarResolver.Resolve("FE_ArtifactCache", request, null, false, null));
            }
            if (town == null)
            {
                request.Includes.Add(EndGameDefOf.FE_WarEvent_Raid);
                request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION1", raider));
                request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION2", victim));
                return(GrammarResolver.Resolve("FE_Sabotage", request, null, false, null));
            }
            if (fail)
            {
                request.Includes.Add(EndGameDefOf.FE_WarEvent_Raid);
                request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION1", raider));
                request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION2", victim));
                request.Rules.AddRange(RulesForTown("AffectedTown", town));
                return(GrammarResolver.Resolve("FE_RaidFail", request, null, false, null));
            }
            request.Includes.Add(EndGameDefOf.FE_WarEvent_Raid);
            request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION1", raider));
            request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION2", victim));
            request.Rules.AddRange(RulesForTown("AffectedTown", town));
            return(GrammarResolver.Resolve("FE_RaidSuccess", request, null, false, null));
        }
예제 #5
0
        protected override GrammarRequest GenerateGrammarRequest()
        {
            GrammarRequest result = base.GenerateGrammarRequest();

            if (this.recipientPawn != null || this.recipientThing != null)
            {
                result.Includes.Add((!this.deflected) ? RulePackDefOf.Combat_RangedDamage : RulePackDefOf.Combat_RangedDeflect);
            }
            else
            {
                result.Includes.Add(RulePackDefOf.Combat_RangedMiss);
            }
            if (this.initiatorPawn != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", this.initiatorPawn, result.Constants));
            }
            else if (this.initiatorThing != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForDef("INITIATOR", this.initiatorThing));
            }
            else
            {
                result.Constants["INITIATOR_missing"] = "True";
            }
            if (this.recipientPawn != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", this.recipientPawn, result.Constants));
            }
            else if (this.recipientThing != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForDef("RECIPIENT", this.recipientThing));
            }
            else
            {
                result.Constants["RECIPIENT_missing"] = "True";
            }
            if (this.originalTargetPawn != this.recipientPawn || this.originalTargetThing != this.recipientThing)
            {
                if (this.originalTargetPawn != null)
                {
                    result.Rules.AddRange(GrammarUtility.RulesForPawn("ORIGINALTARGET", this.originalTargetPawn, result.Constants));
                    result.Constants["ORIGINALTARGET_mobile"] = this.originalTargetMobile.ToString();
                }
                else if (this.originalTargetThing != null)
                {
                    result.Rules.AddRange(GrammarUtility.RulesForDef("ORIGINALTARGET", this.originalTargetThing));
                }
                else
                {
                    result.Constants["ORIGINALTARGET_missing"] = "True";
                }
            }
            result.Rules.AddRange(PlayLogEntryUtility.RulesForOptionalWeapon("WEAPON", this.weaponDef, this.projectileDef));
            result.Constants["COVER_missing"] = ((this.coverDef == null) ? "True" : "False");
            if (this.coverDef != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForDef("COVER", this.coverDef));
            }
            return(result);
        }
        public static string History(Faction subject = null, Faction victim = null, Settlement town = null, Pawn pawn = null, string towndestroyed = null)
        {
            GrammarRequest request = new GrammarRequest();

            request.Includes.Add(EndGameDefOf.FE_History);
            if (pawn != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForPawn("Pawn", pawn));
                return(GrammarResolver.Resolve("r_history_pawn", request, null, false, null));
            }
            if (town != null)
            {
                request.Rules.AddRange(RulesForTown("AffectedTown", town));
                return(GrammarResolver.Resolve("r_history_town", request, null, false, null));
            }
            if (subject != null && victim != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION1", subject));
                request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION2", victim));
                return(GrammarResolver.Resolve("r_history_faction", request, null, false, null));
            }
            if (subject != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION1", subject));
                request.Rules.AddRange(RulesForString("FACTION2", NameGenerator.GenerateName(subject.def.factionNameMaker, Find.FactionManager.AllFactionsVisible.Select(fac => fac.Name))));
                return(GrammarResolver.Resolve("r_history_factiondead", request, null, false, null));
            }
            if (towndestroyed != null)
            {
                request.Rules.AddRange(RulesForString("AffectedTown", towndestroyed));
                return(GrammarResolver.Resolve("r_history_townDestroyed", request, null, false, null));
            }
            return(GrammarResolver.Resolve("r_history_generic", request, null, false, null));
        }
예제 #7
0
        protected override GrammarRequest GenerateGrammarRequest()
        {
            GrammarRequest result = base.GenerateGrammarRequest();

            if (subjectPawn != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForPawn("SUBJECT", subjectPawn, result.Constants));
            }
            else if (subjectThing != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForDef("SUBJECT", subjectThing));
            }
            result.Includes.Add(transitionDef);
            if (initiator != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", initiator, result.Constants));
            }
            if (culpritHediffDef != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForHediffDef("CULPRITHEDIFF", culpritHediffDef, culpritHediffTargetPart));
            }
            if (culpritHediffTargetPart != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForBodyPartRecord("CULPRITHEDIFF_target", culpritHediffTargetPart));
            }
            if (culpritTargetPart != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForBodyPartRecord("CULPRITHEDIFF_originaltarget", culpritTargetPart));
            }
            return(result);
        }
예제 #8
0
        protected virtual string ToGameStringFromPOV_Worker(Thing pov, bool forceLog)
        {
            string         rootKeyword = "r_logentry";
            GrammarRequest request     = this.GenerateGrammarRequest();

            return(GrammarResolver.Resolve(rootKeyword, request, null, forceLog));
        }
예제 #9
0
        private static string GenerateName()
        {
            GrammarRequest req = default(GrammarRequest);

            req.Rules.AddRange(QuestGen.QuestNameRulesReadOnly);
            foreach (KeyValuePair <string, string> item in QuestGen.QuestNameConstantsReadOnly)
            {
                req.Constants.Add(item.Key, item.Value);
            }
            QuestGenUtility.AddSlateVars(ref req);
            Predicate <string> predicate = (string x) => !Find.QuestManager.QuestsListForReading.Any((Quest y) => y.name == x);

            if (QuestGen.Root.nameMustBeUnique)
            {
                return(NameGenerator.GenerateName(req, predicate, appendNumberIfNameUsed: false, "questName"));
            }
            string text = null;
            int    i;

            for (i = 0; i < 20; i++)
            {
                text = NameGenerator.GenerateName(req, null, appendNumberIfNameUsed: false, "questName");
                if (predicate(text))
                {
                    break;
                }
            }
            if (i == 20)
            {
                Log.Warning("Generated duplicate quest name. QuestScriptDef: " + QuestGen.Root + ". Quest name: " + text);
            }
            return(text);
        }
예제 #10
0
        protected override GrammarRequest GenerateGrammarRequest()
        {
            GrammarRequest result = base.GenerateGrammarRequest();

            result.Rules.AddRange(GrammarUtility.RulesForDef("ITEM", itemUsed));
            return(result);
        }
예제 #11
0
        public override void Initialize(CompProperties props)
        {
            base.Initialize(props);
            GrammarRequest request = default(GrammarRequest);

            request.Includes.Add(Props.nameMaker);
            name = GenText.CapitalizeAsTitle(GrammarResolver.Resolve("r_weapon_name", request));
        }
예제 #12
0
        protected override GrammarRequest GenerateGrammarRequest()
        {
            GrammarRequest result = base.GenerateGrammarRequest();

            result.Rules.AddRange(PlayLogEntryUtility.RulesForDamagedParts("recipient_part", DamagedBody(), damagedParts, damagedPartsDestroyed, result.Constants));
            result.Constants.Add("deflected", deflected.ToString());
            return(result);
        }
예제 #13
0
        public static string AdjustedFor(this string text, Pawn p, string pawnSymbol = "PAWN")
        {
            GrammarRequest request = default(GrammarRequest);

            request.Includes.Add(RulePackDefOf.DynamicWrapper);
            request.Rules.Add(new Rule_String("RULE", text));
            request.Rules.AddRange(GrammarUtility.RulesForPawn(pawnSymbol, p, null));
            return(GrammarResolver.Resolve("r_root", request, null, false, null));
        }
예제 #14
0
        /// <summary>
        /// Catches when a cutebold name is about to be generated and nulls out the validator, otherwise errors occur. Cutebold names are very simple and will almost always get rejected.
        /// </summary>
        /// <param name="request">The name generator request.</param>
        /// <param name="validator">The validator to use when naming the pawn.</param>
        /// <param name="appendNumberIfNameUsed">Ignored</param>
        /// <param name="rootKeyword">Ignored</param>
        /// <param name="untranslatedRootKeyword">Ignored</param>
        private static void CuteboldGenerateNamePrefix(GrammarRequest request, ref Predicate <string> validator, bool appendNumberIfNameUsed, string rootKeyword, string untranslatedRootKeyword)
        {
            //Log.Message("Generate Name Prefix");

            if (request.Includes.Any(included => included == Cutebold_DefOf.NamerPersonCutebold || included == Cutebold_DefOf.NamerPersonCuteboldSlave))
            {
                validator = null;
            }
        }
예제 #15
0
        public static string GenerateName(RulePackDef rootPack, Predicate <string> validator = null, bool appendNumberIfNameUsed = false, string rootKeyword = null, string testPawnNameSymbol = null)
        {
            GrammarRequest grammarRequest = default(GrammarRequest);

            grammarRequest.Includes.Add(rootPack);
            if (testPawnNameSymbol != null)
            {
                grammarRequest.Rules.Add(new Rule_String("ANYPAWN_nameDef", testPawnNameSymbol));
                grammarRequest.Rules.Add(new Rule_String("ANYPAWN_nameIndef", testPawnNameSymbol));
            }
            string text  = (rootKeyword == null) ? rootPack.FirstRuleKeyword : rootKeyword;
            string text2 = (rootKeyword == null) ? rootPack.FirstUntranslatedRuleKeyword : rootKeyword;

            if (appendNumberIfNameUsed)
            {
                string         text3;
                GrammarRequest request;
                string         text4;
                for (int i = 0; i < 100; i++)
                {
                    for (int j = 0; j < 5; j++)
                    {
                        text3   = text;
                        request = grammarRequest;
                        text4   = text2;
                        string text5 = GenText.ToTitleCaseSmart(GrammarResolver.Resolve(text3, request, null, false, text4));
                        if (i != 0)
                        {
                            text5 = text5 + " " + (i + 1);
                        }
                        if (validator == null || validator(text5))
                        {
                            return(text5);
                        }
                    }
                }
                text4   = text;
                request = grammarRequest;
                text3   = text2;
                return(GenText.ToTitleCaseSmart(GrammarResolver.Resolve(text4, request, null, false, text3)));
            }
            for (int k = 0; k < 150; k++)
            {
                string         text3   = text;
                GrammarRequest request = grammarRequest;
                string         text4   = text2;
                string         text6   = GenText.ToTitleCaseSmart(GrammarResolver.Resolve(text3, request, null, false, text4));
                if (validator == null || validator(text6))
                {
                    return(text6);
                }
            }
            Log.Error("Could not get new name (rule pack: " + rootPack + ")", false);
            return("Errorname");
        }
예제 #16
0
 public static void Prefix(object __instance, string rootKeyword, GrammarRequest request)
 {
     if (rootKeyword == "r_logentry")
     {
         List <Rule> rules = (List <Rule>)rulesInfo.GetValue(request);
         if (!rules.NullOrEmpty())
         {
             rules.AddRange(ExtraGrammarUtility.ExtraRules());
         }
     }
 }
        protected override GrammarRequest GenerateGrammarRequest()
        {
            GrammarRequest result = base.GenerateGrammarRequest();

            result.Rules.AddRange(GrammarUtility.RulesForDef("ABILITY", abilityUsed));
            if (subjectPawn == null && subjectThing == null)
            {
                result.Rules.Add(new Rule_String("SUBJECT_definite", "AreaLower".Translate()));
            }
            return(result);
        }
        protected override GrammarRequest GenerateGrammarRequest()
        {
            GrammarRequest result = base.GenerateGrammarRequest();

            if (recipientPawn == null)
            {
                Log.ErrorOnce("BattleLogEntry_DamageTaken has a null recipient.", 60465709);
            }
            result.Includes.Add(ruleDef);
            result.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", recipientPawn, result.Constants));
            return(result);
        }
예제 #19
0
        protected override string ToGameStringFromPOV_Worker(Thing pov, bool forceLog)
        {
            if (initiator == null || recipient == null)
            {
                Log.ErrorOnce("PlayLogEntry_Interaction has a null pawn reference.", 34422);
                return("[" + intDef.label + " error: null pawn reference]");
            }
            Rand.PushState();
            Rand.Seed = logID;
            GrammarRequest request = base.GenerateGrammarRequest();
            string         text;

            if (pov == initiator)
            {
                request.IncludesBare.Add(intDef.logRulesInitiator);
                request.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", initiator, request.Constants));
                request.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", recipient, request.Constants));
                text = GrammarResolver.Resolve("r_logentry", request, "interaction from initiator", forceLog);
            }
            else if (pov == recipient)
            {
                if (intDef.logRulesRecipient != null)
                {
                    request.IncludesBare.Add(intDef.logRulesRecipient);
                }
                else
                {
                    request.IncludesBare.Add(intDef.logRulesInitiator);
                }
                request.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", initiator, request.Constants));
                request.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", recipient, request.Constants));
                text = GrammarResolver.Resolve("r_logentry", request, "interaction from recipient", forceLog);
            }
            else
            {
                Log.ErrorOnce("Cannot display PlayLogEntry_Interaction from POV who isn't initiator or recipient.", 51251);
                text = ToString();
            }
            if (extraSentencePacks != null)
            {
                for (int i = 0; i < extraSentencePacks.Count; i++)
                {
                    request.Clear();
                    request.Includes.Add(extraSentencePacks[i]);
                    request.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", initiator, request.Constants));
                    request.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", recipient, request.Constants));
                    text = text + " " + GrammarResolver.Resolve(extraSentencePacks[i].FirstRuleKeyword, request, "extraSentencePack", forceLog, extraSentencePacks[i].FirstUntranslatedRuleKeyword);
                }
            }
            Rand.PopState();
            return(text);
        }
        public override string ToGameStringFromPOV(Thing pov)
        {
            if (this.initiator == null || this.recipient == null)
            {
                Log.ErrorOnce("PlayLogEntry_Interaction has a null pawn reference.", 34422);
                return("[" + this.intDef.label + " error: null pawn reference]");
            }
            Rand.PushState();
            Rand.Seed = this.randSeed;
            GrammarRequest request = default(GrammarRequest);
            string         text;

            if (pov == this.initiator)
            {
                request.Rules.AddRange(this.intDef.logRulesInitiator.Rules);
                request.Rules.AddRange(GrammarUtility.RulesForPawn("me", this.initiator, request.Constants));
                request.Rules.AddRange(GrammarUtility.RulesForPawn("other", this.recipient, request.Constants));
                text = GrammarResolver.Resolve("logentry", request, "interaction from initiator", false);
            }
            else if (pov == this.recipient)
            {
                if (this.intDef.logRulesRecipient != null)
                {
                    request.Rules.AddRange(this.intDef.logRulesRecipient.Rules);
                }
                else
                {
                    request.Rules.AddRange(this.intDef.logRulesInitiator.Rules);
                }
                request.Rules.AddRange(GrammarUtility.RulesForPawn("me", this.recipient, request.Constants));
                request.Rules.AddRange(GrammarUtility.RulesForPawn("other", this.initiator, request.Constants));
                text = GrammarResolver.Resolve("logentry", request, "interaction from recipient", false);
            }
            else
            {
                Log.ErrorOnce("Cannot display PlayLogEntry_Interaction from POV who isn't initiator or recipient.", 51251);
                text = this.ToString();
            }
            if (this.extraSentencePacks != null)
            {
                for (int i = 0; i < this.extraSentencePacks.Count; i++)
                {
                    request.Clear();
                    request.Includes.Add(this.extraSentencePacks[i]);
                    request.Rules.AddRange(GrammarUtility.RulesForPawn("initiator", this.initiator, request.Constants));
                    request.Rules.AddRange(GrammarUtility.RulesForPawn("recipient", this.recipient, request.Constants));
                    text = text + " " + GrammarResolver.Resolve(this.extraSentencePacks[i].RulesPlusIncludes[0].keyword, request, "extraSentencePack", false);
                }
            }
            Rand.PopState();
            return(text);
        }
예제 #21
0
        protected override GrammarRequest GenerateGrammarRequest()
        {
            GrammarRequest result = base.GenerateGrammarRequest();

            if (initiatorPawn == null && initiatorThing == null)
            {
                Log.ErrorOnce("BattleLogEntry_RangedFire has a null initiator.", 60465709);
            }
            if (weaponDef != null && weaponDef.Verbs[0].rangedFireRulepack != null)
            {
                result.Includes.Add(weaponDef.Verbs[0].rangedFireRulepack);
            }
            else
            {
                result.Includes.Add(RulePackDefOf.Combat_RangedFire);
            }
            if (initiatorPawn != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", initiatorPawn, result.Constants));
            }
            else if (initiatorThing != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForDef("INITIATOR", initiatorThing));
            }
            else
            {
                result.Constants["INITIATOR_missing"] = "True";
            }
            if (recipientPawn != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", recipientPawn, result.Constants));
            }
            else if (recipientThing != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForDef("RECIPIENT", recipientThing));
            }
            else
            {
                result.Constants["RECIPIENT_missing"] = "True";
            }
            result.Rules.AddRange(PlayLogEntryUtility.RulesForOptionalWeapon("WEAPON", weaponDef, projectileDef));
            if (initiatorPawn != null && initiatorPawn.skills != null)
            {
                result.Constants["INITIATOR_skill"] = initiatorPawn.skills.GetSkill(SkillDefOf.Shooting).Level.ToStringCached();
            }
            if (recipientPawn != null && recipientPawn.skills != null)
            {
                result.Constants["RECIPIENT_skill"] = recipientPawn.skills.GetSkill(SkillDefOf.Shooting).Level.ToStringCached();
            }
            result.Constants["BURST"] = burst.ToString();
            return(result);
        }
 public static void Prefix(object __instance, string rootKeyword, GrammarRequest request)
 {
     if (rootKeyword == "r_logentry")
     {
         var         initiator = PlayLogEntry_Interaction_ToGameStringFromPOV_Worker.lastInitiator;
         var         recipient = PlayLogEntry_Interaction_ToGameStringFromPOV_Worker.lastRecipient;
         List <Rule> rules     = (List <Rule>)rulesInfo.GetValue(request);
         if (initiator.RaceProps.Humanlike)
         {
             rules.AddRange(ExtraGrammarUtility.ExtraRules(initiator, recipient));
         }
     }
 }
예제 #23
0
        private static void AddSlateVar(ref GrammarRequest req, string absoluteName, HashSet <string> added)
        {
            if (absoluteName == null)
            {
                return;
            }
            tmpVarAbsoluteName.Clear();
            tmpVarAbsoluteName.Append(absoluteName);
            string text;
            object var;

            while (true)
            {
                if (tmpVarAbsoluteName.Length <= 0)
                {
                    return;
                }
                text = tmpVarAbsoluteName.ToString();
                if (added.Contains(text))
                {
                    return;
                }
                if (QuestGen.slate.TryGet(text, out var, isAbsoluteName: true))
                {
                    break;
                }
                if (char.IsNumber(tmpVarAbsoluteName[tmpVarAbsoluteName.Length - 1]))
                {
                    while (char.IsNumber(tmpVarAbsoluteName[tmpVarAbsoluteName.Length - 1]))
                    {
                        tmpVarAbsoluteName.Length--;
                    }
                    continue;
                }
                int num = text.LastIndexOf('_');
                if (num >= 0)
                {
                    int num2 = text.LastIndexOf('/');
                    if (num >= num2)
                    {
                        tmpVarAbsoluteName.Length = num;
                        continue;
                    }
                    return;
                }
                return;
            }
            AddSlateVar(ref req, text, var);
            added.Add(text);
        }
예제 #24
0
        public static string GenerateName(RulePackDef rootPack, Predicate <string> validator = null, bool appendNumberIfNameUsed = false, string rootKeyword = null, string testPawnNameSymbol = null)
        {
            GrammarRequest request = default(GrammarRequest);

            request.Includes.Add(rootPack);
            if (testPawnNameSymbol != null)
            {
                request.Rules.Add(new Rule_String("ANYPAWN_nameDef", testPawnNameSymbol));
                request.Rules.Add(new Rule_String("ANYPAWN_nameIndef", testPawnNameSymbol));
            }
            string rootKeyword2            = ((rootKeyword != null) ? rootKeyword : rootPack.FirstRuleKeyword);
            string untranslatedRootKeyword = ((rootKeyword != null) ? rootKeyword : rootPack.FirstUntranslatedRuleKeyword);

            return(GenerateName(request, validator, appendNumberIfNameUsed, rootKeyword2, untranslatedRootKeyword));
        }
예제 #25
0
        public DiaNode AnnualExpoDialogueNode(Pawn pawn, Caravan caravan, EventDef eventDef, Faction host)
        {
            GrammarRequest request = default;

            request.Includes.Add(RulePackDefOf.ArtDescriptionUtility_Global);

            string flavourText = GrammarResolver.Resolve("artextra_clause", request);

            DiaNode dialogueGreeting = new DiaNode(text: "MFI_AnnualExpoDialogueIntroduction".Translate(eventDef.theme, FirstCharacterToLower(flavourText)));

            foreach (DiaOption option in DialogueOptions(pawn: pawn, caravan, eventDef, host))
            {
                dialogueGreeting.options.Add(item: option);
            }
            return(dialogueGreeting);
        }
예제 #26
0
        public static string GenerateName(RulePackDef rootPack, Predicate <string> validator = null, bool appendNumberIfNameUsed = false, string rootKeyword = null, string testPawnNameSymbol = null)
        {
            GrammarRequest request = default(GrammarRequest);

            request.Includes.Add(rootPack);
            if (testPawnNameSymbol != null)
            {
                request.Rules.Add(new Rule_String("ANYPAWN_nameDef", testPawnNameSymbol));
                request.Rules.Add(new Rule_String("ANYPAWN_nameIndef", testPawnNameSymbol));
            }
            rootKeyword = ((rootKeyword == null) ? rootPack.RulesPlusIncludes[0].keyword : rootKeyword);
            string result;

            if (appendNumberIfNameUsed)
            {
                for (int i = 0; i < 100; i++)
                {
                    for (int j = 0; j < 5; j++)
                    {
                        string text = GenText.ToTitleCaseSmart(GrammarResolver.Resolve(rootKeyword, request, null, false));
                        if (i != 0)
                        {
                            text = text + " " + (i + 1);
                        }
                        if (validator == null || validator(text))
                        {
                            return(text);
                        }
                    }
                }
                result = GenText.ToTitleCaseSmart(GrammarResolver.Resolve(rootKeyword, request, null, false));
            }
            else
            {
                for (int k = 0; k < 150; k++)
                {
                    string text2 = GenText.ToTitleCaseSmart(GrammarResolver.Resolve(rootKeyword, request, null, false));
                    if (validator == null || validator(text2))
                    {
                        return(text2);
                    }
                }
                Log.Error("Could not get new name (rule pack: " + rootPack + ")", false);
                result = "Errorname";
            }
            return(result);
        }
        protected override GrammarRequest GenerateGrammarRequest()
        {
            GrammarRequest result = base.GenerateGrammarRequest();

            result.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", initiator, result.Constants));
            if (recipientPawn != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", recipientPawn, result.Constants));
            }
            else if (recipientThing != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForDef("RECIPIENT", recipientThing));
            }
            result.Includes.Add(ruleDef);
            if (!toolLabel.NullOrEmpty())
            {
                result.Rules.Add(new Rule_String("TOOL_label", toolLabel));
                result.Rules.Add(new Rule_String("TOOL_definite", Find.ActiveLanguageWorker.WithDefiniteArticle(toolLabel)));
                result.Rules.Add(new Rule_String("TOOL_indefinite", Find.ActiveLanguageWorker.WithIndefiniteArticle(toolLabel)));
                result.Constants["TOOL_gender"] = LanguageDatabase.activeLanguage.ResolveGender(toolLabel).ToString();
            }
            if (implementType != null && !implementType.implementOwnerRuleName.NullOrEmpty())
            {
                if (ownerEquipmentDef != null)
                {
                    result.Rules.AddRange(GrammarUtility.RulesForDef(implementType.implementOwnerRuleName, ownerEquipmentDef));
                }
                else if (ownerHediffDef != null)
                {
                    result.Rules.AddRange(GrammarUtility.RulesForDef(implementType.implementOwnerRuleName, ownerHediffDef));
                }
            }
            if (initiator != null && initiator.skills != null)
            {
                result.Constants["INITIATOR_skill"] = initiator.skills.GetSkill(SkillDefOf.Melee).Level.ToStringCached();
            }
            if (recipientPawn != null && recipientPawn.skills != null)
            {
                result.Constants["RECIPIENT_skill"] = recipientPawn.skills.GetSkill(SkillDefOf.Melee).Level.ToStringCached();
            }
            if (implementType != null && !implementType.implementOwnerTypeValue.NullOrEmpty())
            {
                result.Constants["IMPLEMENTOWNER_type"] = implementType.implementOwnerTypeValue;
            }
            return(result);
        }
        public override string ToGameStringFromPOV(Thing pov)
        {
            Rand.PushState();
            Rand.Seed = base.randSeed;
            GrammarRequest request = default(GrammarRequest);

            request.Includes.Add(RulePackDefOf.Combat_ExplosionImpact);
            if (this.initiatorPawn != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForPawn("initiator", this.initiatorPawn, request.Constants));
            }
            else if (this.initiatorThing != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForDef("initiator", this.initiatorThing));
            }
            else
            {
                request.Constants["initiator_missing"] = "True";
            }
            if (this.recipientPawn != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForPawn("recipient", this.recipientPawn, request.Constants));
            }
            else if (this.recipientThing != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForDef("recipient", this.recipientThing));
            }
            else
            {
                request.Constants["recipient_missing"] = "True";
            }
            request.Rules.AddRange(PlayLogEntryUtility.RulesForOptionalWeapon("weapon", this.weaponDef, this.projectileDef));
            if (this.projectileDef != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForDef("projectile", this.projectileDef));
            }
            if (this.damageDef != null && this.damageDef.combatLogRules != null)
            {
                request.Includes.Add(this.damageDef.combatLogRules);
            }
            request.Rules.AddRange(PlayLogEntryUtility.RulesForDamagedParts("recipient_part", this.damagedParts, this.damagedPartsDestroyed, request.Constants));
            string result = GrammarResolver.Resolve("logentry", request, "ranged explosion", false);

            Rand.PopState();
            return(result);
        }
예제 #29
0
        public static TaggedString GenerateTextFromTale(TextGenerationPurpose purpose, Tale tale,
                                                        int seed, RulePackDef extraInclude, CompBook compBook)
        {
            Rand.PushState();
            Rand.Seed = seed;
            string         rootKeyword = null;
            GrammarRequest request     = default(GrammarRequest);

            request.Includes.Add(extraInclude);

            switch (purpose)
            {
            case TextGenerationPurpose.ArtDescription:
                rootKeyword = compBook.Props.nameMaker.RulesImmediate
                              .Where(x => x.keyword != null && x.keyword.Length > 0).RandomElement().keyword;
                //Log.Message("rootKeyword for description: " + rootKeyword);
                if (tale != null && !Rand.Chance(0.2f))
                {
                    request.Includes.Add(RulePackDefOf.ArtDescriptionRoot_HasTale);
                    request.IncludesBare.AddRange(tale.GetTextGenerationIncludes());
                    request.Rules.AddRange(tale.GetTextGenerationRules());
                }
                else
                {
                    request.Includes.Add(RulePackDefOf.ArtDescriptionRoot_Taleless);
                    request.Includes.Add(RulePackDefOf.TalelessImages);
                }
                request.Includes.Add(RulePackDefOf.ArtDescriptionUtility_Global);
                break;

            case TextGenerationPurpose.ArtName:
                rootKeyword = compBook.Props.descriptionMaker.RulesImmediate
                              .Where(x => x.keyword != null && x.keyword.Length > 0).RandomElement().keyword;
                //Log.Message("rootKeyword for name: " + rootKeyword);
                if (tale != null)
                {
                    request.IncludesBare.AddRange(tale.GetTextGenerationIncludes());
                    request.Rules.AddRange(tale.GetTextGenerationRules());
                }
                break;
            }
            string str = GrammarResolver.Resolve(rootKeyword, request, (tale != null) ? tale.def.defName : "null_tale");

            Rand.PopState();
            return(str);
        }
예제 #30
0
        public static void AddSlateVars(ref GrammarRequest req)
        {
            tmpAddedSlateVars.Clear();
            List <Rule> rules = req.Rules;

            for (int i = 0; i < rules.Count; i++)
            {
                Rule_String rule_String = rules[i] as Rule_String;
                if (rule_String == null)
                {
                    continue;
                }
                string text = rule_String.Generate();
                if (text != null)
                {
                    bool flag = false;
                    tmpSymbol.Clear();
                    for (int j = 0; j < text.Length; j++)
                    {
                        if (text[j] == '[')
                        {
                            flag = true;
                        }
                        else if (text[j] == ']')
                        {
                            AddSlateVar(ref req, tmpSymbol.ToString(), tmpAddedSlateVars);
                            tmpSymbol.Clear();
                            flag = false;
                        }
                        else if (flag)
                        {
                            tmpSymbol.Append(text[j]);
                        }
                    }
                }
                if (rule_String.constantConstraints != null)
                {
                    for (int k = 0; k < rule_String.constantConstraints.Count; k++)
                    {
                        string key = rule_String.constantConstraints[k].key;
                        AddSlateVar(ref req, key, tmpAddedSlateVars);
                    }
                }
            }
        }