Jump to content

Get SkillsReadable property from Experience Effects at Runtime


Recommended Posts

All,

Once again thank you to all that have paved the way on KSP.  Now that I have spent hours (days... weeks...) banging my head against the desk, I have so much respect for our modders!

I am trying to pull the "SkillsReadable" attribute from the Experience Effects classes that have that attribute (currently only Experience.Effects.AutopilotSkillExperience.Effects.FailureRepairSkill, and Experience.Effects.RepairSkill).  I get these Effects from the Experience.ExperienceEffect List.  Of course each skill class is inherited from Experience.ExperienceEffect.  I can access all the common properties from the parent class just fine.  But trying to see if each item in the list has the "SkillsReadable" property has become quite problematic.  I have tried all sorts of reflection and such, but I am missing something (it's been 17 years since I last touched C#).  

This does work, so I know the property is accessible directly...

string[] skr = (Experience.Effects.AutopilotSkill.SkillsReadable);
foreach(string s in skr)
{
    Debug.Log(s);
}

But here, when I try to go down the trail of getting all the Kerbal Traits and then getting all the Effects assigned to each of the traits, I hit a wall when I get to the reflection part of getting "SkillsReadable".

List<Experience.ExperienceTraitConfig> experienceTraitConfig = GameDatabase.Instance.ExperienceConfigs.Categories;
foreach (Experience.ExperienceTraitConfig trait in experienceTraitConfig)
{
	string traitName = trait.Name;
	Type type = KerbalRoster.GetExperienceTraitType(traitName) ?? typeof(Experience.ExperienceTrait);
	Experience.ExperienceTrait experienceTrait = Experience.ExperienceTrait.Create(type, trait, new ProtoCrewMember(ProtoCrewMember.KerbalType.Crew));

	List<Experience.ExperienceEffect> experienceEffectList = experienceTrait.Effects;

	foreach (var effect in experienceEffectList)
	{
		//everything so far works fine... it's the part below that is the issue...
		if(effect.GetType().GetProperty("SkillsReadable") != null)
		{
			Debug.Log(effect.GetType().GetProperty("SkillsReadable").GetValue(effect, null));
		}
	}
}

I have been all over StackOverflow and MSDN trying to figure out how to do this and have tried many many methods... the above code is just my most recent one.

Thank you in advance for any help you can give.  I'd hate to be thinking about C# while trying to enjoy Thanksgiving turkey this week... 

Matt

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...