Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using RimWorld;
- using Verse;
- using UnityEngine;
- using System.Collections.Generic;
- namespace AnaestheticThoughtCode // change to whatever you want
- {
- // This class "ThoughtWorkerAnaesthetic" is derived from ThoughtWorker_Hediff, hence the " : "
- // This means it inherits all of its functions unless otherwise overridden.
- // A class is like an "object" which can contain logic and variables
- public class ThoughtWorker_Anaesthetic : ThoughtWorker_Hediff
- {
- // Notice the "override" keyword below. We are overriding the CurrentStateInternal method from ThoughtWorker_Hediff
- // which is what decides whether or not the thought should be active or inactive based on what we ask for.
- // Also notice "ThoughtState". This is what kind of data the method will return upon execution, if any. If no
- // data is given by the method's execution, it is considered a "void" method, which only executes a function but
- // does not return any information.
- protected override ThoughtState CurrentStateInternal (Pawn pawn) // 'Pawn' is the class of the variable passed to the method, and 'pawn' is our variable name
- {
- // Does the pawn have the required hediff?
- Hediff firstHediffOfDef = pawn.health.hediffSet.GetFirstHediffOfDef (def.hediff);
- if (firstHediffOfDef == null || firstHediffOfDef.def.stages == null) {
- // I guess not
- // "return" ends the method's execution right where it is stated. Nothing below this will be executed if the logic gets here
- return ThoughtState.Inactive;
- }
- int stageIndex = 0; // This will decide what stage of the thought will be used
- Trait drug_desire = pawn.story.traits.GetTrait (TraitDefOf.DrugDesire); // Finds the trait we need to get info from
- if (drug_desire.Degree == -1) { // degree of -1 for DrugDesire is TeeTotaller
- stageIndex = 0;// so let's set our stage index of our thought
- }
- else if (drug_desire.Degree == 1) { // degree of 1 is chemical interest
- stageIndex = 1;
- }
- else if (drug_desire.Degree == 2) { // degree of 2 is chemical fascination as I'm sure you've guessed at this point
- stageIndex = 2;
- }
- return ThoughtState.ActiveAtStage ( stageIndex ); // gives the
- // This is a lot of if / else statements though, we could do this a lot cleaner by just using a dictionary to "translate" the degree
- // of the trait "DrugDesire" directly to the stage of the Thought
- // Dictionaries are lists of key/value pairs. With a dictionary, when you ask it for a specific "key", it will return
- // the corresponding "value". So in the dictionary below, if we ask it for '-1', it will give us '0', etc.
- Dictionary<int,int> degree_to_stage = new Dictionary<int, int> () { {-1,0}, {1,1}, {2,2} };
- // To get a value from a dictionary using a key, the syntax is as follows:
- // my_dict[key]
- // So below, we ask the dictionary 'degree_to_stage' we've made above for the current Degree of the pawn's drugdesire trait
- return ThoughtState.ActiveAtStage ( degree_to_stage[drug_desire.Degree] ); // Give the ThoughtWorker what stage it ought to be at!
- // This is a lot of if / else statements though, we could do this a lot cleaner by just using a dictionary to "translate" the degree
- // of the trait "DrugDesire" directly to the stage of the Thought.
- }
- protected override ThoughtState CurrentStateInternal (Pawn pawn) // 'Pawn' is the class of the variable passed to the method, and 'pawn' is our variable name
- {
- Hediff firstHediffOfDef = pawn.health.hediffSet.GetFirstHediffOfDef (def.hediff);
- if (firstHediffOfDef == null || firstHediffOfDef.def.stages == null) {
- return ThoughtState.Inactive;
- }
- Trait drug_desire = pawn.story.traits.GetTrait (TraitDefOf.DrugDesire);
- // Dictionaries are lists of key/value pairs. With a dictionary, when you ask it for a specific "key", it will return
- // the corresponding "value". So in the dictionary below, if we ask it for '-1', it will give us '0', etc.
- // The <int,int> part defines what KIND of data the key/value pairs are. For our uses we are simply using integers,
- // but you could make a dictionary that uses any kinds of data types. eg: <Vector3, string> to translate a 3D position to a sentence (for whatever reason)
- Dictionary<int,int> degree_to_stage = new Dictionary<int, int> () { {-1,0}, {1,1}, {2,2} };
- // To get a value from a dictionary using a key, the syntax is as follows:
- // my_dict[key]
- // So below, we ask the dictionary 'degree_to_stage' we've made above for the current Degree of the pawn's drugdesire trait
- return ThoughtState.ActiveAtStage ( degree_to_stage[drug_desire.Degree] ); // Give the ThoughtWorker what stage it ought to be at!
- }
- // In the end our method will look simple as this
- // Note that only this last method should be in the actual code used, you don't want to have all three in reality...
- // Only for example :p
- protected override ThoughtState CurrentStateInternal (Pawn pawn) // 'Pawn' is the class of the variable passed to the method, and 'pawn' is our variable name
- {
- Hediff firstHediffOfDef = pawn.health.hediffSet.GetFirstHediffOfDef (def.hediff);
- if (firstHediffOfDef == null || firstHediffOfDef.def.stages == null) {
- return ThoughtState.Inactive;
- }
- Trait drug_desire = pawn.story.traits.GetTrait (TraitDefOf.DrugDesire);
- Dictionary<int,int> degree_to_stage = new Dictionary<int, int> () { {-1,0}, {1,1}, {2,2} };
- return ThoughtState.ActiveAtStage ( degree_to_stage[drug_desire.Degree] );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement