Skip to content

Commit c4d545e

Browse files
committed
Finish character generator: names, starting kit items, starting bonus.
1 parent f159335 commit c4d545e

File tree

2 files changed

+91
-32
lines changed

2 files changed

+91
-32
lines changed

module/generator.js

Lines changed: 90 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { DISActor } from "./actor/actor.js";
22

3+
const CREATION_PACK = "deathinspace.character-creation";
4+
35
export const generateCharacter = async () => {
4-
const creationPack = "deathinspace.character-creation";
6+
const firstName = await drawText(CREATION_PACK, "First Names");
7+
const lastName = await drawText(CREATION_PACK, "Last Names");
58

69
// 1. abilities
710
const body = generateAbilityValue();
@@ -12,36 +15,25 @@ export const generateCharacter = async () => {
1215
const defenseRating = 12 + dexterity;
1316

1417
// 2. origin
15-
const origin = await drawDocument(creationPack, "Origins");
18+
const origin = await drawDocument(CREATION_PACK, "Origins");
1619
const originBenefit = await pickOriginBenefit(origin);
1720

1821
// 3. character details
19-
const background = await drawText(creationPack, "Backgrounds");
20-
const trait = await drawText(creationPack, "Traits");
21-
const drive = await drawText(creationPack, "Drives");
22-
const looks = await drawText(creationPack, "Looks");
22+
const background = await drawText(CREATION_PACK, "Backgrounds");
23+
const trait = await drawText(CREATION_PACK, "Traits");
24+
const drive = await drawText(CREATION_PACK, "Drives");
25+
const looks = await drawText(CREATION_PACK, "Looks");
2326

2427
// 4. past allegiance
25-
const pastAllegiance = await drawText(creationPack, "Past Allegiances");
28+
const pastAllegiance = await drawText(CREATION_PACK, "Past Allegiances");
2629

2730
// 5. hit points and defense rating
2831
const hitPoints = rollTotal("1d8");
2932

3033
// 6. starting gear and starting bonus
3134
const holos = rollTotal("3d10");
32-
// TODO: need to handle multiple results/docs drawn
33-
//const startingKit = await drawResult(creationPack, "Starting Kits");
34-
// TODO: extract entities
35-
36-
const sumOfAbilityScores = body + dexterity + savvy + tech;
37-
let startingBonus = null;
38-
if (sumOfAbilityScores < 0) {
39-
// startingBonus = drawResult("deathinspace.character-creation", "Starting Bonuses");
40-
}
41-
const personalTrinket = await drawDocument(creationPack, "Personal Trinkets");
42-
43-
const firstName = await drawText(creationPack, "First Names");
44-
const lastName = await drawText(creationPack, "Last Names");
35+
const startingKitItems = await drawDocuments(CREATION_PACK, "Starting Kits");
36+
const personalTrinket = await drawDocument(CREATION_PACK, "Personal Trinkets");
4537

4638
const actorData = {
4739
name: `${firstName} ${lastName}`,
@@ -67,29 +59,82 @@ export const generateCharacter = async () => {
6759
type: "character",
6860
};
6961
const actor = await DISActor.create(actorData);
62+
const allItems = [origin.data, originBenefit.data, personalTrinket.data].concat(startingKitItems.map(x => x.data));
63+
await actor.createEmbeddedDocuments("Item", allItems);
64+
await maybeGiveStartingBonus(actor);
7065

71-
// TODO: apply starting bonus to character
72-
73-
// TODO: originBenefit
74-
await actor.createEmbeddedDocuments("Item", [origin.data, originBenefit.data, personalTrinket.data])
7566
actor.sheet.render(true);
76-
77-
return actor;
7867
}
7968

69+
const maybeGiveStartingBonus = async (actor) => {
70+
const sumOfAbilityScores = (
71+
actor.data.data.abilities.body.value +
72+
actor.data.data.abilities.dexterity.value +
73+
actor.data.data.abilities.savvy.value +
74+
actor.data.data.abilities.tech.value);
75+
if (sumOfAbilityScores >= 0) {
76+
// no starting bonus
77+
return;
78+
}
79+
const bonusRoll = rollTotal("1d6");
80+
let bonusItem = null;
81+
let bonusHitPoints = 0;
82+
let bonusFollower = null;
83+
switch (bonusRoll) {
84+
case 1:
85+
bonusItem = await drawDocument(CREATION_PACK, "Cosmic Mutations");
86+
break;
87+
case 2:
88+
bonusHitPoints = 3;
89+
break;
90+
case 3:
91+
bonusItem = await documentFromPack("deathinspace.armor", "EVA Suit - Heavy");
92+
break;
93+
case 4:
94+
bonusItem = await documentFromPack("deathinspace.weapons", "Pistol");
95+
break;
96+
case 5:
97+
bonusFollower = await documentFromPack("deathinspace.starting-npcs", "AI guard animal");
98+
break;
99+
case 6:
100+
bonusFollower = await documentFromPack("deathinspace.starting-npcs", "Old Crew Member");
101+
break;
102+
}
103+
104+
if (bonusItem) {
105+
await actor.createEmbeddedDocuments("Item", [bonusItem.data])
106+
}
107+
if (bonusHitPoints) {
108+
const newHP = actor.data.data.hitPoints.max + bonusHitPoints;
109+
await actor.update({
110+
["data.hitPoints.max"]: newHP,
111+
["data.hitPoints.value"]: newHP
112+
});
113+
}
114+
if (bonusFollower) {
115+
// TODO: randomize follower stats
116+
const followerData = duplicate(bonusFollower.data);
117+
const firstName = actor.name.split(" ")[0];
118+
followerData.name = `${firstName}'s ${followerData.name}`;
119+
const follower = await DISActor.create(followerData);
120+
follower.sheet.render(true);
121+
// TODO: set notes on char sheet?
122+
// "You have a starting follower: "
123+
}
124+
};
125+
80126
const rollTotal = (formula) => {
81127
const roll = new Roll(formula).evaluate({
82128
async: false,
83129
});
84-
return roll.result;
130+
return roll.total;
85131
};
86132

87133
const generateAbilityValue = () => {
88134
return rollTotal("1d4") - rollTotal("1d4");
89135
};
90136

91137
const pickOriginBenefit = async (origin) => {
92-
console.log(origin);
93138
if (origin.data.data.benefitNames) {
94139
const names = origin.data.data.benefitNames.split(",");
95140
if (names.length) {
@@ -104,6 +149,15 @@ const pickOriginBenefit = async (origin) => {
104149
}
105150
};
106151

152+
const documentFromPack = async (packName, docName) => {
153+
const pack = game.packs.get(packName);
154+
const docs = await pack.getDocuments();
155+
const doc = docs.find(
156+
(i) => i.name === docName
157+
);
158+
return doc;
159+
};
160+
107161
const drawFromTable = async (packName, tableName) => {
108162
const creationPack = game.packs.get(packName);
109163
const creationDocs = await creationPack.getDocuments();
@@ -133,7 +187,8 @@ const drawDocuments = async (packName, tableName) => {
133187
};
134188

135189
const documentsFromDraw = async (draw) => {
136-
return Promise.all(draw.results.map(r => documentFromResult(r)));
190+
const docResults = draw.results.filter(r => r.data.type === 2);
191+
return Promise.all(docResults.map(r => documentFromResult(r)));
137192
};
138193

139194
const documentFromDraw = async (draw) => {
@@ -142,6 +197,10 @@ const documentFromDraw = async (draw) => {
142197
};
143198

144199
const documentFromResult = async (result) => {
200+
if (!result.data.collection) {
201+
console.log("No data.collection for result; skipping");
202+
return;
203+
}
145204
const collectionName = result.data.type === 2
146205
? "Compendium." + result.data.collection
147206
: result.data.collection;
@@ -151,9 +210,9 @@ const documentFromResult = async (result) => {
151210
};
152211

153212
const generateSpacecraft = async () => {
154-
213+
// TODO
155214
};
156215

157216
const generateStation = async () => {
158-
217+
// TODO
159218
};

packs/origins.db

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{"_id":"3Hz9KvfzZgCOohuv","name":"Velocity Cursed","type":"origin","img":"systems/deathinspace/assets/images/icons/origins/origin.png","data":{"notes":"<p>Ill-fated ones that have started to lose their connection to reality. They shift and flicker in and out of spacetime with glitching faces.</p>","benefitNames":"Future Memory,Pocket World"},"effects":[],"folder":null,"sort":0,"permission":{"default":0,"BSEmAXWYPuoWh3m2":3},"flags":{}}
22
{"_id":"DQBfvOULpdhM9eN5","name":"Carbon","type":"origin","img":"systems/deathinspace/assets/images/icons/origins/origin.png","data":{"notes":"<p>Grown in space-based exo-wombs. Genderless. Live their lives offworld and are comfortable in the darkness of space. More comfortable in an EVA suit than out of one.</p>","benefitNames":"Engineered Lungs, Gearhead"},"effects":[],"folder":null,"sort":0,"permission":{"default":0,"BSEmAXWYPuoWh3m2":3},"flags":{}}
33
{"_id":"QjNsfOSYiwKYxnWZ","name":"Punk","type":"origin","img":"systems/deathinspace/assets/images/icons/origins/origin.png","data":{"notes":"<p>Rebellious and non- conformist with a long history. They have seen civilizations collapse, and others turn against each other.</p>","benefitNames":"Stubborn,Green Thumb"},"effects":[],"folder":null,"sort":0,"permission":{"default":0,"BSEmAXWYPuoWh3m2":3},"flags":{}}
4-
{"_id":"Ytp1oY7Li7kmlVDV","name":"Void","type":"origin","img":"systems/deathinspace/assets/images/icons/origins/origin.png","data":{"notes":"<p>Robed nihility shamans, hidden behind masks, speaking through synthetic voice scramblers. They have seen visions of the edge of the universe.</p>","benefitNames":"Voice of the Void, Masked"},"effects":[],"folder":null,"sort":0,"permission":{"default":0,"BSEmAXWYPuoWh3m2":3},"flags":{}}
4+
{"_id":"Ytp1oY7Li7kmlVDV","name":"Void","type":"origin","img":"systems/deathinspace/assets/images/icons/origins/origin.png","data":{"notes":"<p>Robed nihility shamans, hidden behind masks, speaking through synthetic voice scramblers. They have seen visions of the edge of the universe.</p>","benefitNames":"Voice of the Void,Masked"},"effects":[],"folder":null,"sort":0,"permission":{"default":0,"BSEmAXWYPuoWh3m2":3},"flags":{}}
55
{"_id":"xAUbnUIXbgncWhOV","name":"Chrome","type":"origin","img":"systems/deathinspace/assets/images/icons/origins/origin.png","data":{"notes":"<p>Ancient AI placed in body vessels of organic material. Part machine, but with an organic CPU and a distributed neural system that requires oxygen.</p>","benefitNames":"Native Machine,Body Battery"},"effects":[],"folder":null,"sort":0,"permission":{"default":0,"BSEmAXWYPuoWh3m2":3},"flags":{}}
66
{"_id":"ySqeOZxJbpTXgHAQ","name":"Solpod","type":"origin","img":"systems/deathinspace/assets/images/icons/origins/origin.png","data":{"notes":"<p>Hibernate for decades, only staying awake for short periods. Dedicate their lives to scientific study of slow, cosmic phenomena.</p>","benefitNames":"Long-lived,Old Tech"},"effects":[],"folder":null,"sort":0,"permission":{"default":0,"BSEmAXWYPuoWh3m2":3},"flags":{}}

0 commit comments

Comments
 (0)