AlexTo

RimModBeastFormCode

Mar 9th, 2024
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.56 KB | Gaming | 0 0
  1. using System;
  2. using RimWorld;
  3. using TaranMagicFramework;
  4. using UnityEngine;
  5. using Verse;
  6.  
  7. namespace SaiyanMod
  8. {
  9.     public class Main
  10.     {
  11.         static Main()
  12.         {
  13.        
  14.         }
  15.     }
  16.     public class KIAbility_BeastformSaiyan : KIAbility_Toggleable
  17.     {
  18.         public virtual string HairPostfix
  19.         {
  20.             get
  21.             {
  22.                 return "Beast";
  23.             }
  24.         }
  25.         //This striing is the postfix of the hair texture png, that the ability try to grab
  26.         public override void Start(bool consumeEnergy = true)
  27.         {
  28.             base.Start(true);
  29.             //Grab the new hediff you added in the xml
  30.             HediffDef def = SR_DefOfBeast.BeastformSaiyanHediff;
  31.             Hediff hediff = HediffMaker.MakeHediff(def, this.pawn, null);
  32.             this.pawn.health.AddHediff(hediff, null, null, null);
  33.             //This will record old pawn hair for restoring hair after exiting transform form
  34.             this.OldHairDef = this.pawn.story.hairDef;
  35.             HairDef named = DefDatabase<HairDef>.GetNamed("AT_BeastForm", true);
  36.             this.pawn.story.hairDef = named;
  37.             this.oldColor = this.pawn.story.HairColor;
  38.             this.pawn.story.HairColor = Color.white;
  39.             this.pawn.Drawer.renderer.graphics.ResolveAllGraphicsSafely();
  40.             PortraitsCache.SetDirty(this.pawn);
  41.             PortraitsCache.PortraitsCacheUpdate();
  42.             GlobalTextureAtlasManager.TryMarkPawnFrameSetDirty(this.pawn);
  43.             bool flag = ModsConfig.IdeologyActive && this.pawn.Map != null;
  44.             if (flag)
  45.             {
  46.                 GameComponent_SaiyanRace component = Current.Game.GetComponent<GameComponent_SaiyanRace>();
  47.                 foreach (Pawn pawn in this.pawn.Map.mapPawns.SpawnedPawnsInFaction(this.pawn.Faction))
  48.                 {
  49.                     if (pawn == this.pawn || !pawn.RaceProps.Humanlike)
  50.                     {
  51.                         goto IL_1C1;
  52.                     }
  53.                     Pawn_NeedsTracker needs = pawn.needs;
  54.                     bool flag2;
  55.                     if (needs == null)
  56.                     {
  57.                         flag2 = (null != null);
  58.                     }
  59.                     else
  60.                     {
  61.                         Need_Mood mood = needs.mood;
  62.                         if (mood == null)
  63.                         {
  64.                             flag2 = (null != null);
  65.                         }
  66.                         else
  67.                         {
  68.                             ThoughtHandler thoughts = mood.thoughts;
  69.                             flag2 = (((thoughts != null) ? thoughts.memories : null) != null);
  70.                         }
  71.                     }
  72.                     if (!flag2)
  73.                     {
  74.                         goto IL_1C1;
  75.                     }
  76.                     Ideo ideo = pawn.Ideo;
  77.                     bool flag3 = ((ideo != null) ? ideo.GetPrecept(SR_DefOf.SR_SuperSaiyan_Revered) : null) != null;
  78.                 IL_1C2:
  79.                     bool flag4 = flag3;
  80.                     if (flag4)
  81.                     {
  82.                         bool flag5 = !component.transformationWitnesses.Contains(pawn);
  83.                         if (flag5)
  84.                         {
  85.                             component.transformationWitnesses.Add(pawn);
  86.                             pawn.needs.mood.thoughts.memories.TryGainMemory(SR_DefOf.SR_WitnessedSuperSaiyanTransformation, null, null);
  87.                         }
  88.                     }
  89.                     continue;
  90.                 IL_1C1:
  91.                     flag3 = false;
  92.                     goto IL_1C2;
  93.                 }
  94.             }
  95.         }
  96.         public override void End()
  97.         {
  98.             base.End();
  99.             Hediff firstHediffOfDef = this.pawn.health.hediffSet.GetFirstHediffOfDef(SR_DefOfBeast.BeastformSaiyanHediff, false);
  100.             bool flag = firstHediffOfDef != null;
  101.             if (flag)
  102.             {
  103.                 this.pawn.health.RemoveHediff(firstHediffOfDef);
  104.             }
  105.             this.TryRestoreHair();
  106.         }
  107.         public void TryRestoreHair()
  108.         {
  109.             try
  110.             {
  111.                 this.pawn.story.hairDef = this.OldHairDef;
  112.                 this.pawn.story.HairColor = this.oldColor;
  113.                 this.pawn.Drawer.renderer.graphics.ResolveAllGraphicsSafely();
  114.                 PortraitsCache.SetDirty(this.pawn);
  115.                 PortraitsCache.PortraitsCacheUpdate();
  116.                 GlobalTextureAtlasManager.TryMarkPawnFrameSetDirty(this.pawn);
  117.             }
  118.             catch (Exception ex)
  119.             {
  120.             }
  121.         }
  122.         public override void Tick()
  123.         {
  124.             base.Tick();
  125.             bool flag = this.abilityResource.energy <= 0f && this.Active;
  126.             if (flag)
  127.             {
  128.                 this.End();
  129.             }
  130.         }
  131.         public override Func<string> CanBeActivatedValidator()
  132.         {
  133.             return delegate ()
  134.             {
  135.                 TaranMagicFramework.Ability learnedAbility = this.abilityClass.GetLearnedAbility(SR_DefOf.SR_SaiyanFury);
  136.                 bool flag = learnedAbility != null && learnedAbility.Active;
  137.                 string result;
  138.                 if (flag)
  139.                 {
  140.                     result = Translator.Translate("SR.CannotUseStrainRisk");
  141.                 }
  142.                 else
  143.                 {
  144.                     CompSaiyanRace comp = this.pawn.GetComp<CompSaiyanRace>();
  145.                     bool flag2 = comp != null && comp.isMonkeyNow;
  146.                     if (flag2)
  147.                     {
  148.                         result = Translator.Translate("SR.CannotUseOozaru");
  149.                     }
  150.                     else
  151.                     {
  152.                         result = "";
  153.                     }
  154.                 }
  155.                 return result;
  156.             };
  157.         }
  158.         public override void ExposeData()
  159.         {
  160.             base.ExposeData();
  161.             Scribe_Values.Look<Color>(ref this.oldColor, "oldColor", default(Color), false);
  162.         }
  163.  
  164.         public Color oldColor;
  165.  
  166.         public HairDef OldHairDef;
  167.  
  168.     }
  169.     [DefOf]
  170.     public static class SR_DefOfBeast
  171.     {
  172.         //your hediff is here
  173.         public static HediffDef BeastformSaiyanHediff;
  174.     }
  175. }
  176.  
Tags: BeastForm
Advertisement
Add Comment
Please, Sign In to add comment