AlexTo

Untitled

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