Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using RimWorld;
- using TaranMagicFramework;
- using UnityEngine;
- using Verse;
- namespace SaiyanMod
- {
- public class Main
- {
- static Main()
- {
- }
- }
- public class KIAbility_BeastformSaiyan : KIAbility_Toggleable
- {
- public virtual string HairPostfix
- {
- get
- {
- return "Beast";
- }
- }
- //This striing is the postfix of the hair texture png, that the ability try to grab
- public override void Start(bool consumeEnergy = true)
- {
- base.Start(true);
- //Grab the new hediff you added in the xml
- HediffDef def = SR_DefOfBeast.BeastformSaiyanHediff;
- Hediff hediff = HediffMaker.MakeHediff(def, this.pawn, null);
- this.pawn.health.AddHediff(hediff, null, null, null);
- //This will record old pawn hair for restoring hair after exiting transform form
- this.OldHairDef = this.pawn.story.hairDef;
- HairDef named = DefDatabase<HairDef>.GetNamed("AT_BeastForm", true);
- this.pawn.story.hairDef = named;
- this.oldColor = this.pawn.story.HairColor;
- this.pawn.story.HairColor = Color.white;
- this.pawn.Drawer.renderer.graphics.ResolveAllGraphicsSafely();
- PortraitsCache.SetDirty(this.pawn);
- PortraitsCache.PortraitsCacheUpdate();
- GlobalTextureAtlasManager.TryMarkPawnFrameSetDirty(this.pawn);
- bool flag = ModsConfig.IdeologyActive && this.pawn.Map != null;
- if (flag)
- {
- GameComponent_SaiyanRace component = Current.Game.GetComponent<GameComponent_SaiyanRace>();
- foreach (Pawn pawn in this.pawn.Map.mapPawns.SpawnedPawnsInFaction(this.pawn.Faction))
- {
- if (pawn == this.pawn || !pawn.RaceProps.Humanlike)
- {
- goto IL_1C1;
- }
- Pawn_NeedsTracker needs = pawn.needs;
- bool flag2;
- if (needs == null)
- {
- flag2 = (null != null);
- }
- else
- {
- Need_Mood mood = needs.mood;
- if (mood == null)
- {
- flag2 = (null != null);
- }
- else
- {
- ThoughtHandler thoughts = mood.thoughts;
- flag2 = (((thoughts != null) ? thoughts.memories : null) != null);
- }
- }
- if (!flag2)
- {
- goto IL_1C1;
- }
- Ideo ideo = pawn.Ideo;
- bool flag3 = ((ideo != null) ? ideo.GetPrecept(SR_DefOf.SR_SuperSaiyan_Revered) : null) != null;
- IL_1C2:
- bool flag4 = flag3;
- if (flag4)
- {
- bool flag5 = !component.transformationWitnesses.Contains(pawn);
- if (flag5)
- {
- component.transformationWitnesses.Add(pawn);
- pawn.needs.mood.thoughts.memories.TryGainMemory(SR_DefOf.SR_WitnessedSuperSaiyanTransformation, null, null);
- }
- }
- continue;
- IL_1C1:
- flag3 = false;
- goto IL_1C2;
- }
- }
- }
- public override void End()
- {
- base.End();
- Hediff firstHediffOfDef = this.pawn.health.hediffSet.GetFirstHediffOfDef(SR_DefOfBeast.BeastformSaiyanHediff, false);
- bool flag = firstHediffOfDef != null;
- if (flag)
- {
- this.pawn.health.RemoveHediff(firstHediffOfDef);
- }
- this.TryRestoreHair();
- }
- public void TryRestoreHair()
- {
- try
- {
- this.pawn.story.hairDef = this.OldHairDef;
- this.pawn.story.HairColor = this.oldColor;
- this.pawn.Drawer.renderer.graphics.ResolveAllGraphicsSafely();
- PortraitsCache.SetDirty(this.pawn);
- PortraitsCache.PortraitsCacheUpdate();
- GlobalTextureAtlasManager.TryMarkPawnFrameSetDirty(this.pawn);
- }
- catch (Exception ex)
- {
- }
- }
- public override void Tick()
- {
- base.Tick();
- bool flag = this.abilityResource.energy <= 0f && this.Active;
- if (flag)
- {
- this.End();
- }
- }
- public override Func<string> CanBeActivatedValidator()
- {
- return delegate ()
- {
- TaranMagicFramework.Ability learnedAbility = this.abilityClass.GetLearnedAbility(SR_DefOf.SR_SaiyanFury);
- bool flag = learnedAbility != null && learnedAbility.Active;
- string result;
- if (flag)
- {
- result = Translator.Translate("SR.CannotUseStrainRisk");
- }
- else
- {
- CompSaiyanRace comp = this.pawn.GetComp<CompSaiyanRace>();
- bool flag2 = comp != null && comp.isMonkeyNow;
- if (flag2)
- {
- result = Translator.Translate("SR.CannotUseOozaru");
- }
- else
- {
- result = "";
- }
- }
- return result;
- };
- }
- public override void ExposeData()
- {
- base.ExposeData();
- Scribe_Values.Look<Color>(ref this.oldColor, "oldColor", default(Color), false);
- }
- public Color oldColor;
- public HairDef OldHairDef;
- }
- [DefOf]
- public static class SR_DefOfBeast
- {
- //your hediff is here
- public static HediffDef BeastformSaiyanHediff;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment