mirror of
				https://gitgud.io/amevarashi/rjw-sexperience-ideology.git
				synced 2024-08-15 00:43:19 +00:00 
			
		
		
		
	Refactor ThoughtDefExtension_StageFromOpinion
This commit is contained in:
		
							parent
							
								
									eda7261968
								
							
						
					
					
						commit
						5db34c0c1f
					
				
					 3 changed files with 26 additions and 23 deletions
				
			
		| 
						 | 
				
			
			@ -270,7 +270,7 @@
 | 
			
		|||
 | 
			
		||||
  <ThoughtDef>
 | 
			
		||||
    <defName>Virgin_Precious_Taken</defName>
 | 
			
		||||
    <thoughtClass>RJWSexperience.Thought_Opinionbased</thoughtClass>
 | 
			
		||||
    <thoughtClass>RJWSexperience.Ideology.Thought_Opinionbased</thoughtClass>
 | 
			
		||||
    <durationDays>7</durationDays>
 | 
			
		||||
    <stackLimit>1</stackLimit>
 | 
			
		||||
    <stages>
 | 
			
		||||
| 
						 | 
				
			
			@ -296,7 +296,7 @@
 | 
			
		|||
      </li>
 | 
			
		||||
    </stages>
 | 
			
		||||
    <modExtensions>
 | 
			
		||||
      <li Class="RJWSexperience.ThoughtDefExtension_StageFromOpinion">
 | 
			
		||||
      <li Class="RJWSexperience.Ideology.ThoughtDefExtension_StageFromValue">
 | 
			
		||||
        <minimumValueforStage>
 | 
			
		||||
          <li>-100</li>
 | 
			
		||||
          <li>-50</li>
 | 
			
		||||
| 
						 | 
				
			
			@ -309,7 +309,7 @@
 | 
			
		|||
 | 
			
		||||
  <ThoughtDef>
 | 
			
		||||
    <defName>Virgin_Shameful_Taken</defName>
 | 
			
		||||
    <thoughtClass>RJWSexperience.Thought_Opinionbased</thoughtClass>
 | 
			
		||||
    <thoughtClass>RJWSexperience.Ideology.Thought_Opinionbased</thoughtClass>
 | 
			
		||||
    <durationDays>7</durationDays>
 | 
			
		||||
    <stackLimit>1</stackLimit>
 | 
			
		||||
    <stages>
 | 
			
		||||
| 
						 | 
				
			
			@ -330,7 +330,7 @@
 | 
			
		|||
      </li>
 | 
			
		||||
    </stages>
 | 
			
		||||
    <modExtensions>
 | 
			
		||||
      <li Class="RJWSexperience.ThoughtDefExtension_StageFromOpinion">
 | 
			
		||||
      <li Class="RJWSexperience.Ideology.ThoughtDefExtension_StageFromValue">
 | 
			
		||||
        <minimumValueforStage>
 | 
			
		||||
          <li>-100</li>
 | 
			
		||||
          <li>0</li>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,13 +2,26 @@
 | 
			
		|||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using Verse;
 | 
			
		||||
 | 
			
		||||
namespace RJWSexperience
 | 
			
		||||
namespace RJWSexperience.Ideology
 | 
			
		||||
{
 | 
			
		||||
	public class ThoughtDefExtension_StageFromOpinion : DefModExtension
 | 
			
		||||
	public class ThoughtDefExtension_StageFromValue : DefModExtension
 | 
			
		||||
	{
 | 
			
		||||
		[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
 | 
			
		||||
		public List<float> minimumValueforStage = new List<float>();
 | 
			
		||||
 | 
			
		||||
		public int GetStageIndex(float value)
 | 
			
		||||
		{
 | 
			
		||||
			for (int i = minimumValueforStage.Count - 1; i > 0; i--)
 | 
			
		||||
			{
 | 
			
		||||
				if (minimumValueforStage[i] < value)
 | 
			
		||||
				{
 | 
			
		||||
					return i;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			return 0;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public override IEnumerable<string> ConfigErrors()
 | 
			
		||||
		{
 | 
			
		||||
			foreach (string error in base.ConfigErrors())
 | 
			
		||||
| 
						 | 
				
			
			@ -1,22 +1,21 @@
 | 
			
		|||
using RimWorld;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using Verse;
 | 
			
		||||
 | 
			
		||||
namespace RJWSexperience
 | 
			
		||||
namespace RJWSexperience.Ideology
 | 
			
		||||
{
 | 
			
		||||
	public class Thought_Opinionbased : Thought_Memory
 | 
			
		||||
	{
 | 
			
		||||
		private List<float> minimumValueforStage;
 | 
			
		||||
		private ThoughtDefExtension_StageFromValue stageFromValue;
 | 
			
		||||
 | 
			
		||||
		protected List<float> MinimumValueforStage
 | 
			
		||||
		protected ThoughtDefExtension_StageFromValue StageFromValue
 | 
			
		||||
		{
 | 
			
		||||
			get
 | 
			
		||||
			{
 | 
			
		||||
				if (minimumValueforStage == null)
 | 
			
		||||
				if (stageFromValue == null)
 | 
			
		||||
				{
 | 
			
		||||
					minimumValueforStage = def.GetModExtension<ThoughtDefExtension_StageFromOpinion>().minimumValueforStage;
 | 
			
		||||
					stageFromValue = def.GetModExtension<ThoughtDefExtension_StageFromValue>();
 | 
			
		||||
				}
 | 
			
		||||
				return minimumValueforStage;
 | 
			
		||||
				return stageFromValue;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -47,16 +46,7 @@ namespace RJWSexperience
 | 
			
		|||
			}
 | 
			
		||||
 | 
			
		||||
			float value = pawn.relations?.OpinionOf(otherPawn) ?? 0f;
 | 
			
		||||
 | 
			
		||||
			for (int i = MinimumValueforStage.Count - 1; i > 0; i--)
 | 
			
		||||
			{
 | 
			
		||||
				if (MinimumValueforStage[i] < value)
 | 
			
		||||
				{
 | 
			
		||||
					SetForcedStage(i);
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			SetForcedStage(0);
 | 
			
		||||
			SetForcedStage(StageFromValue.GetStageIndex(value));
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue