Skip to content

Commit 1373983

Browse files
committed
Configure prototype token at character creation
Enable sight : true Link to actor : true Disposition : friendly
1 parent 9665501 commit 1373983

File tree

1 file changed

+43
-38
lines changed

1 file changed

+43
-38
lines changed

module/documents/actor.mjs

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,42 @@
1-
import IntoTheOddChat from "../chat.mjs";
1+
import IntoTheOddChat from "../chat.mjs"
22

33
export default class IntoTheOddActor extends Actor {
4+
async _preCreate(data, options, user) {
5+
await super._preCreate(data, options, user)
6+
7+
// Configure prototype token settings
8+
const prototypeToken = {}
9+
if (this.type === "character") {
10+
Object.assign(prototypeToken, {
11+
sight: { enabled: true },
12+
actorLink: true,
13+
disposition: CONST.TOKEN_DISPOSITIONS.FRIENDLY,
14+
})
15+
this.updateSource({ prototypeToken })
16+
}
17+
}
418

519
/**
6-
* Roll a save for ability
7-
* @param {*} ability
8-
* @returns
9-
*/
20+
* Roll a save for ability
21+
* @param {*} ability
22+
* @returns
23+
*/
1024
async rollSave(ability) {
11-
const roll = await new Roll("1d20").roll();
12-
const total = roll.total;
13-
let success = false;
14-
const abilityValue = this.system.abilities[ability].value;
25+
const roll = await new Roll("1d20").roll()
26+
const total = roll.total
27+
let success = false
28+
const abilityValue = this.system.abilities[ability].value
1529

1630
if (total <= abilityValue) {
17-
success = true;
31+
success = true
1832
}
1933

20-
const abilityName = game.i18n.localize(`INTOTHEODD.Character.FIELDS.${ability}.label`);
21-
let introText;
34+
const abilityName = game.i18n.localize(`INTOTHEODD.Character.FIELDS.${ability}.label`)
35+
let introText
2236
if (success) {
23-
introText = game.i18n.format("INTOTHEODD.Roll.SaveRoll", { ability: abilityName, value: abilityValue });
24-
}
25-
else {
26-
introText = game.i18n.format("INTOTHEODD.Roll.SaveRoll", { ability: abilityName, value: abilityValue });
37+
introText = game.i18n.format("INTOTHEODD.Roll.SaveRoll", { ability: abilityName, value: abilityValue })
38+
} else {
39+
introText = game.i18n.format("INTOTHEODD.Roll.SaveRoll", { ability: abilityName, value: abilityValue })
2740
}
2841

2942
let chatData = {
@@ -35,30 +48,26 @@ export default class IntoTheOddActor extends Actor {
3548
formula: roll.formula,
3649
total: total,
3750
tooltip: await roll.getTooltip(),
38-
success
51+
success,
3952
}
4053

41-
let chat = await new IntoTheOddChat(this)
42-
.withTemplate("systems/intotheodd/templates/roll-result.hbs")
43-
.withData(chatData)
44-
.withRolls([roll])
45-
.create();
54+
let chat = await new IntoTheOddChat(this).withTemplate("systems/intotheodd/templates/roll-result.hbs").withData(chatData).withRolls([roll]).create()
4655

47-
await chat.display();
56+
await chat.display()
4857

49-
return { roll, total, success };
58+
return { roll, total, success }
5059
}
5160

5261
/**
53-
*
54-
* @param {*} itemName
55-
* @param {*} formula
62+
*
63+
* @param {*} itemName
64+
* @param {*} formula
5665
*/
5766
async rollDamage(itemName, formula) {
58-
const roll = await new Roll(formula).roll();
59-
const result = roll.total;
67+
const roll = await new Roll(formula).roll()
68+
const result = roll.total
6069

61-
const label = game.i18n.format("INTOTHEODD.Roll.AttackRollDamage", { itemName });
70+
const label = game.i18n.format("INTOTHEODD.Roll.AttackRollDamage", { itemName })
6271

6372
let chatData = {
6473
rollType: "damage",
@@ -67,17 +76,13 @@ export default class IntoTheOddActor extends Actor {
6776
introText: label,
6877
formula: roll.formula,
6978
total: roll.total,
70-
tooltip: await roll.getTooltip()
79+
tooltip: await roll.getTooltip(),
7180
}
7281

73-
let chat = await new IntoTheOddChat(this)
74-
.withTemplate("systems/intotheodd/templates/roll-result.hbs")
75-
.withData(chatData)
76-
.withRolls([roll])
77-
.create();
82+
let chat = await new IntoTheOddChat(this).withTemplate("systems/intotheodd/templates/roll-result.hbs").withData(chatData).withRolls([roll]).create()
7883

79-
await chat.display();
84+
await chat.display()
8085

81-
return { roll, result };
86+
return { roll, result }
8287
}
8388
}

0 commit comments

Comments
 (0)