forked from Neceros/AndroidsExpanded
-
Notifications
You must be signed in to change notification settings - Fork 1
/
message.txt
202 lines (176 loc) · 7.6 KB
/
message.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
public static Pawn MakeDroidTemplate(PawnKindDef pawnKindDef, Faction faction, int tile, List<SkillRequirement> skills = null, int defaultSkillLevel = 6)
{
Log.Message("MakeDroidTemplate: Generating new Droid.");
Map map = null;
if(tile > -1)
{
map = Current.Game?.FindMap(tile);
}
//Log.Message("Map: " + map);
//Manually craft a Droid Pawn.
Log.Message($"MakeDroidTemplate: Vanilla: Generates new pawn: {pawnKindDef.defName}");
Pawn pawnBeingCrafted = (Pawn)ThingMaker.MakeThing(pawnKindDef.race);
if (pawnBeingCrafted == null)
return null;
//Kind, Faction and initial Components.
Log.Message("MakeDroidTemplate: Tries setting faction for droid.");
pawnBeingCrafted.kindDef = pawnKindDef;
if(faction != null)
{
pawnBeingCrafted.SetFactionDirect(faction);
}
PawnComponentsUtility.CreateInitialComponents(pawnBeingCrafted);
//Gender
Log.Message("MakeDroidTemplate: Set defaults for droid.");
pawnBeingCrafted.gender = Gender.Male;
//Set Needs at initial levels.
pawnBeingCrafted.needs.SetInitialLevels();
//Set age
pawnBeingCrafted.ageTracker.AgeBiologicalTicks = 0;
pawnBeingCrafted.ageTracker.AgeChronologicalTicks = 0;
//Set Story
Log.Message("MakeDroidTemplate: Set default backstories for droid.");
if (pawnBeingCrafted.RaceProps.Humanlike)
{
DroidSpawnProperties spawnProperties = pawnKindDef.race.GetModExtension<DroidSpawnProperties>();
Log.Message("MakeDroidTemplate: Set gender and hostility response mode.");
if (spawnProperties != null)
{
pawnBeingCrafted.gender = spawnProperties.gender;
pawnBeingCrafted.playerSettings.hostilityResponse = spawnProperties.hostileResponse;
}
Log.Message("MakeDroidTemplate: Set droid appearance.");
//Appearance
pawnBeingCrafted.story.melanin = 1f;
pawnBeingCrafted.story.crownType = CrownType.Average;
Log.Message("MakeDroidTemplate: Set droid hair (if any).");
if (spawnProperties != null && spawnProperties.generateHair)
{
IEnumerable<HairDef> source = from hair in DefDatabase<HairDef>.AllDefs
where hair.hairTags.SharesElementWith(spawnProperties.hairTags)
select hair;
HairDef resultHair = source.RandomElementByWeightWithFallback((hair) => HairChoiceLikelihoodFor(hair, pawnBeingCrafted), DefDatabase<HairDef>.GetNamed("Shaved"));
pawnBeingCrafted.story.hairDef = resultHair;
if(pawnBeingCrafted.def is ThingDef_AlienRace alienRaceDef)
{
pawnBeingCrafted.story.hairColor = alienRaceDef.alienRace?.generalSettings?.alienPartGenerator?.colorChannels.FirstOrDefault(channel => channel.name == "hair").first?.NewRandomizedColor() ?? new UnityEngine.Color(1f, 1f, 1f, 1f);
}
}
else
{
pawnBeingCrafted.story.hairColor = new UnityEngine.Color(1f, 1f, 1f, 1f);
pawnBeingCrafted.story.hairDef = DefDatabase<HairDef>.GetNamed("Shaved");
}
Log.Message("MakeDroidTemplate: Set droid body type.");
if (spawnProperties != null && spawnProperties.bodyType != null)
{
pawnBeingCrafted.story.bodyType = spawnProperties.bodyType;
}
else
{
pawnBeingCrafted.story.bodyType = BodyTypeDefOf.Thin;
}
PortraitsCache.SetDirty(pawnBeingCrafted);
//Backstory
Log.Message("MakeDroidTemplate: Finalising droid backstories.");
Backstory backstory = null;
if (spawnProperties != null && spawnProperties.backstory != null)
{
BackstoryDatabase.TryGetWithIdentifier(spawnProperties.backstory.defName, out backstory);
}
else
{
BackstoryDatabase.TryGetWithIdentifier("ChJAndroid_Droid", out backstory);
}
pawnBeingCrafted.story.childhood = backstory;
//Skills
Log.Message("MakeDroidTemplate: Set droid skills.");
if (skills == null || skills.Count <= 0)
{
if(spawnProperties != null)
{
//Set all skills to default first.
foreach(SkillDef skillDef in DefDatabase<SkillDef>.AllDefsListForReading)
{
SkillRecord skill = pawnBeingCrafted.skills.GetSkill(skillDef);
skill.Level = spawnProperties.defaultSkillLevel;
}
//Set skills and passions.
foreach (DroidSkill droidSkill in spawnProperties.skills)
{
SkillRecord skill = pawnBeingCrafted.skills.GetSkill(droidSkill.def);
if(skill != null)
{
skill.Level = droidSkill.level;
skill.passion = droidSkill.passion;
}
}
}
else
{
List<SkillDef> allDefsListForReading = DefDatabase<SkillDef>.AllDefsListForReading;
for (int i = 0; i < allDefsListForReading.Count; i++)
{
SkillDef skillDef = allDefsListForReading[i];
SkillRecord skill = pawnBeingCrafted.skills.GetSkill(skillDef);
if (skillDef == SkillDefOf.Shooting || skillDef == SkillDefOf.Melee || skillDef == SkillDefOf.Mining || skillDef == SkillDefOf.Plants)
skill.Level = 8;
else
if (skillDef == SkillDefOf.Medicine || skillDef == SkillDefOf.Crafting || skillDef == SkillDefOf.Cooking)
skill.Level = 4;
else
skill.Level = 6;
skill.passion = Passion.None;
}
}
}
else
{
List<SkillDef> allDefsListForReading = DefDatabase<SkillDef>.AllDefsListForReading;
for (int i = 0; i < allDefsListForReading.Count; i++)
{
SkillDef skillDef = allDefsListForReading[i];
SkillRecord skill = pawnBeingCrafted.skills.GetSkill(skillDef);
SkillRequirement skillRequirement = skills.First(sr => sr.skill == skillDef);
if (skillRequirement != null)
{
skill.Level = skillRequirement.minLevel;
}
else
{
skill.Level = defaultSkillLevel;
}
skill.passion = Passion.None;
}
}
}
//Work settings
Log.Message("MakeDroidTemplate: Set droid work settings.");
if (pawnBeingCrafted.workSettings != null)
{
pawnBeingCrafted.workSettings.EnableAndInitialize();
}
//Name
Log.Message("MakeDroidTemplate: Set droid name.");
if (map != null && faction.IsPlayer)
{
var names = from pawn in map.mapPawns.FreeColonists
select pawn.Name;
if (names != null)
{
int droidNameCount = names.Count(name => name.ToStringShort.ToLower().StartsWith(pawnKindDef.race.label.ToLower()));
string finalShortName = pawnKindDef.race.LabelCap + " " + droidNameCount;
pawnBeingCrafted.Name = MakeDroidName(finalShortName);
}
else
{
pawnBeingCrafted.Name = MakeDroidName(null);
}
}
else
{
pawnBeingCrafted.Name = MakeDroidName(null);
}
Log.Message("MakeDroidTemplate: Returning finished droid.");
return pawnBeingCrafted;
}