Skip to content

Commit

Permalink
Backstory fix, bodyRelatedTraits
Browse files Browse the repository at this point in the history
  • Loading branch information
REDIZIT committed Nov 6, 2024
1 parent 35aee3d commit 42f1931
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 18 deletions.
Binary file modified Assemblies/AstraTech.dll
Binary file not shown.
26 changes: 26 additions & 0 deletions Defs/BackstoryDefs/backstories.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<Defs>

<BackstoryDef>
<defName>astra_blank</defName>
<identifier>astra_blank</identifier>
<slot>Childhood</slot>
<title>blank</title>
<titleShort>blank</titleShort>
<description>Desc</description>
<requiredWorkTags>None</requiredWorkTags>
<shuffleable>False</shuffleable>
</BackstoryDef>

<BackstoryDef>
<defName>astra_blank_adult</defName>
<identifier>astra_blank_adult</identifier>
<slot>Adulthood</slot>
<title>blank</title>
<titleShort>blank</titleShort>
<description>Desc</description>
<requiredWorkTags>None</requiredWorkTags>
<shuffleable>False</shuffleable>
</BackstoryDef>

</Defs>
26 changes: 22 additions & 4 deletions Source/AstraTech/Scripts/AstraBrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class AstraBrain : IExposable, IPawnContainer
{
public Pawn innerPawn;

private static HashSet<NeedDef> brainRelatedNeeds = new HashSet<NeedDef>()
public static HashSet<NeedDef> brainRelatedNeeds = new HashSet<NeedDef>()
{
AstraDefOf.Mood,
//AstraDefOf.Rest,
Expand All @@ -23,6 +23,15 @@ public class AstraBrain : IExposable, IPawnContainer
AstraDefOf.RoomSize,
};

public static HashSet<TraitDef> bodyRelatedTraits = new HashSet<TraitDef>()
{
TraitDefOf.AnnoyingVoice,
TraitDefOf.CreepyBreathing,
DefDatabase<TraitDef>.GetNamed("Beauty"),
DefDatabase<TraitDef>.GetNamed("Immunity"),
DefDatabase<TraitDef>.GetNamed("Tough"),
};

//private static FieldInfo cachedThoughtsField = typeof(SituationalThoughtHandler).GetField("cachedThoughts", BindingFlags.Instance | BindingFlags.NonPublic);

public AstraBrain()
Expand All @@ -44,9 +53,17 @@ public static void ClearPawn(Pawn p)
pawnSkill.passion = Passion.None;
}

p.story.traits.allTraits.Clear();

// Remove only brain related traits
p.story.traits.allTraits.RemoveAll(t => bodyRelatedTraits.Contains(t.def) == false);


// Clear story
p.story.AllBackstories.Clear();
p.story.Childhood = AstraDefOf.astra_blank;
p.story.Adulthood = AstraDefOf.astra_blank_adult;

// Clear relationships
p.relations.ClearAllRelations();


Expand Down Expand Up @@ -100,7 +117,6 @@ public void CopyInnerPawnToBlank(Pawn p)
p.Name = innerPawn.Name;
p.ageTracker.AgeChronologicalTicks = innerPawn.ageTracker.AgeChronologicalTicks;


// Copy story
Pawn_StoryTracker newStory = new Pawn_StoryTracker(p);
Pawn_StoryTracker oldStory = p.story;
Expand All @@ -111,11 +127,13 @@ public void CopyInnerPawnToBlank(Pawn p)
newStory.hairDef = oldStory.hairDef;
newStory.SkinColorBase = oldStory.SkinColorBase;

// Add only brain related traits
newStory.traits.allTraits.Clear();
newStory.traits.allTraits.AddRange(brainStory.traits.allTraits);

newStory.AllBackstories.Clear();
newStory.AllBackstories.AddRange(brainStory.AllBackstories);
newStory.Childhood = brainStory.Childhood;
newStory.Adulthood = brainStory.Adulthood;

p.story = newStory;

Expand Down
2 changes: 2 additions & 0 deletions Source/AstraTech/Scripts/AstraDefOf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public static class AstraDefOf
public static ThingDef astra_brain, astra_cards_bank, astra_schematics_skill, astra_schematics_trait;
public static HediffDef astra_brain_socket;

public static BackstoryDef astra_blank, astra_blank_adult;


// Vanilla Rimworld needs (somewhy there is almost nothing inside NeedDefOf)
public static NeedDef Mood, Food, Rest, Joy, Beauty, Comfort, Outdoors, Indoors, DrugDesire, RoomSize;
Expand Down
12 changes: 9 additions & 3 deletions Source/AstraTech/Scripts/Buildings/Building_AstraPawnMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,6 @@ public override void Tick()
}
else
{
Log.Message("Task completed: " + task);

if (task == Task.CreateBlank)
{
Pawn p = CreateBlankWithSocket();
Expand Down Expand Up @@ -439,7 +437,7 @@ private IEnumerable<FloatMenuOption> EnumerateTraitsForExtraction(Pawn selPawn,
{
foreach (Trait trait in pawn.story.traits.allTraits)
{
yield return new FloatMenuOption(trait.LabelCap, () =>
FloatMenuOption option = new FloatMenuOption(trait.LabelCap, () =>
{
traitToExtract = trait.def;

Expand All @@ -455,6 +453,14 @@ private IEnumerable<FloatMenuOption> EnumerateTraitsForExtraction(Pawn selPawn,
}
});
});

if (AstraBrain.bodyRelatedTraits.Contains(trait.def))
{
option.Disabled = true;
option.Label = "Not extractable: " + option.Label;
}

yield return option;
}
}

Expand Down
45 changes: 34 additions & 11 deletions Source/AstraTech/Scripts/ITabs/ITab_Brain_Skill_Installation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ public class ITab_Brain_Skill_Installation : ITab

private Vector2 scrollPos;
private AstraSchematics activeSkillCard => Building.schematicsInsideBank;
private AstraSchematics[] skillCards;
private AstraSchematics[] availableSchematics;

private Texture2D PassionMinorIcon, PassionMajorIcon, rightArrow;
private float tipY;

public ITab_Brain_Skill_Installation()
{
Expand Down Expand Up @@ -51,19 +52,22 @@ protected override void FillTab()
Widgets.Label(labelRect, "Available skill cards");

Rect scrollView = new Rect(body.x, labelRect.yMax, body.width, body.height - labelRect.yMax);
DrawCards(scrollView, skillCards.OrderByDescending(c => c == activeSkillCard));
DrawCards(scrollView, availableSchematics.OrderByDescending(c => c == activeSkillCard));
}

private void OnSchematicsContentChanged()
{
skillCards = Building.GetComp<CompAffectedByFacilities>().LinkedFacilitiesListForReading.SelectMany(t => ((Building_AstraSchematicsBank)t).GetDirectlyHeldThings()).Where(t => t is AstraSchematics_Skill || t is AstraSchematics_Trait).Cast<AstraSchematics>().ToArray();
availableSchematics = Building.GetComp<CompAffectedByFacilities>().LinkedFacilitiesListForReading
.SelectMany(t => ((Building_AstraSchematicsBank)t).GetDirectlyHeldThings())
.Where(t => t is AstraSchematics_Skill || t is AstraSchematics_Trait)
.Cast<AstraSchematics>().ToArray();
}

private void DrawCards(Rect body, IEnumerable<Thing> items)
{
Rect scrollView = new Rect(body.x, body.y, body.width, body.height);

Widgets.BeginScrollView(scrollView, ref scrollPos, new Rect(0, 0, scrollView.width, skillCards.Length * (25 + 1)));
Widgets.BeginScrollView(scrollView, ref scrollPos, new Rect(0, 0, scrollView.width, availableSchematics.Length * (25 + 1)));

float offset = 0;
foreach (Thing item in items)
Expand Down Expand Up @@ -138,7 +142,7 @@ private void DrawCards(Rect body, IEnumerable<Thing> items)
}
}
}
else
else if (brainSkill.levelInt < card.level)
{
if (Widgets.ButtonText(actionRect, "Start training"))
{
Expand Down Expand Up @@ -178,12 +182,13 @@ private void DrawCards(Rect body, IEnumerable<Thing> items)
Widgets.DrawHighlightIfMouseover(lotRect);
}

Rect labelRect = new Rect(12, y, 120, lotRect.height);
float actionXOffset = 67;
Rect labelRect = new Rect(12, y, 120 + actionXOffset, lotRect.height);
Text.Anchor = TextAnchor.MiddleLeft;
Widgets.Label(labelRect, trait.TraitLabel);
Text.Anchor = 0;

Text.Anchor = TextAnchor.MiddleLeft;
float x = 140;
float x = 140 + actionXOffset;


Rect actionRect = new Rect(x + 6, y + 1, lotRect.width - x - 6 * 2, lotRect.height - 2);
Expand All @@ -197,11 +202,29 @@ private void DrawCards(Rect body, IEnumerable<Thing> items)
}
}
}
else if (hasSameTrait == false)
else
{
if (Widgets.ButtonText(actionRect, "Start training"))
if (AstraBrain.bodyRelatedTraits.Contains(trait.traitDef))
{
Building.StartTask_TraitTraining(trait);
Text.Anchor = TextAnchor.MiddleLeft;
Widgets.Label(actionRect, ref tipY, "Not applicable", "This is not character trait, but a feature of the body.");
Text.Anchor = 0;
}
else
{
if (hasSameTrait == false)
{
if (Widgets.ButtonText(actionRect, "Start training"))
{
Building.StartTask_TraitTraining(trait);
}
}
else
{
Text.Anchor = TextAnchor.MiddleCenter;
Widgets.Label(actionRect, "Already has");
Text.Anchor = 0;
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions Source/AstraTech/Scripts/Items/ThingWithComps_AstraBrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public override void SpawnSetup(Map map, bool respawningAfterLoad)
brain = new AstraBrain(Building_AstraPawnMachine.CreateBlank());
brain.GetPawn().Name = new NameSingle("Unnamed");
}

if (brain.innerPawn.story.Childhood == null)
{
brain.innerPawn.story.Childhood = AstraDefOf.astra_blank;
brain.innerPawn.story.Adulthood = AstraDefOf.astra_blank_adult;
}
}

public override IEnumerable<FloatMenuOption> GetFloatMenuOptions(Pawn selPawn)
Expand Down

0 comments on commit 42f1931

Please sign in to comment.