Skip to content

Commit dea4551

Browse files
committed
Make attack automation work with npcs, and adjust npc stats accordingly.
1 parent 0711f4c commit dea4551

File tree

12 files changed

+108
-94
lines changed

12 files changed

+108
-94
lines changed

css/deathinspace.css

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,45 @@
154154
.deathinspace.sheet .editor {
155155
padding: 0 8px;
156156
}
157+
.roll-card {
158+
border: 1px solid var(--highlight-background-color);
159+
font-family: var(--text-font);
160+
padding: 5px;
161+
}
162+
.roll-card .card-title {
163+
font-weight: bold;
164+
margin-bottom: 10px;
165+
text-transform: uppercase;
166+
}
167+
.roll-card .roll-title {
168+
text-align: center;
169+
text-transform: uppercase;
170+
}
171+
.roll-card .roll-result {
172+
border: 1px solid gray;
173+
margin-bottom: 10px;
174+
margin-left: 10px;
175+
margin-right: 10px;
176+
text-align: center;
177+
}
178+
.roll-card .roll-result span {
179+
font-size: 20px;
180+
}
181+
.roll-card .outcome-text {
182+
font-size: 28px;
183+
font-weight: bold;
184+
margin-bottom: 10px;
185+
text-align: center;
186+
text-transform: uppercase;
187+
}
188+
189+
.attack-roll-card {
190+
border: 2px solid var(--character-background-color);
191+
}
192+
.attack-roll-card .risky-outcome {
193+
font-size: 12px;
194+
text-transform: none;
195+
}
157196
/* ====================== */
158197
/* Actor sheet */
159198
/* ====================== */
@@ -1372,45 +1411,6 @@
13721411
.deathinspace.sheet.npc .data-wrapper .form-spacer {
13731412
height: 20px;
13741413
}
1375-
.roll-card {
1376-
border: 1px solid var(--highlight-background-color);
1377-
font-family: var(--text-font);
1378-
padding: 5px;
1379-
}
1380-
.roll-card .card-title {
1381-
font-weight: bold;
1382-
margin-bottom: 10px;
1383-
text-transform: uppercase;
1384-
}
1385-
.roll-card .roll-title {
1386-
text-align: center;
1387-
text-transform: uppercase;
1388-
}
1389-
.roll-card .roll-result {
1390-
border: 1px solid gray;
1391-
margin-bottom: 10px;
1392-
margin-left: 10px;
1393-
margin-right: 10px;
1394-
text-align: center;
1395-
}
1396-
.roll-card .roll-result span {
1397-
font-size: 20px;
1398-
}
1399-
.roll-card .outcome-text {
1400-
font-size: 28px;
1401-
font-weight: bold;
1402-
margin-bottom: 10px;
1403-
text-align: center;
1404-
text-transform: uppercase;
1405-
}
1406-
1407-
.attack-roll-card {
1408-
border: 2px solid var(--character-background-color);
1409-
}
1410-
.attack-roll-card .risky-outcome {
1411-
font-size: 12px;
1412-
text-transform: none;
1413-
}
14141414
.deathinspace.sheet.item {
14151415
/* Notes tab */
14161416
/* Data tab */

lang/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"DIS.AttackCriticalHit": "Critical Hit",
1111
"DIS.AttackHit": "Hit",
1212
"DIS.AttackMiss": "Miss",
13+
"DIS.AttackWith": "Attack with",
1314
"DIS.Background": "Background",
1415
"DIS.Cancel": "Cancel",
1516
"DIS.CharacterSheetTitle": "Personal Data Sheet",
@@ -25,6 +26,7 @@
2526
"DIS.DefenseRating": "Defense Rating",
2627
"DIS.DefenseRatingHelp": "12+DEX Unarmored",
2728
"DIS.Drive": "Drive",
29+
"DIS.DR": "DR",
2830
"DIS.DRBonus": "DR Bonus",
2931
"DIS.Equipment": "Equipment",
3032
"DIS.Frame": "Frame",
@@ -85,6 +87,7 @@
8587
"DIS.TabCargo": "Cargo",
8688
"DIS.TabSituation": "Situation",
8789
"DIS.TabWeaponry": "Weaponry",
90+
"DIS.ToHit": "To hit",
8891
"DIS.Total": "Total",
8992
"DIS.Traits": "Traits",
9093
"DIS.Weapon": "Weapon",
@@ -95,5 +98,6 @@
9598
"DIS.VoidPointsCanBeUsedTo": "Void points can be used to",
9699
"DIS.VoidPointsUse1": "Get advantage on an ability check or attack roll",
97100
"DIS.VoidPointsUse2": "Activate a cosmic mutation",
101+
"DIS.Vs": "vs.",
98102
"DIS.XP": "XP"
99103
}

module/actor/actor.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -130,42 +130,42 @@ export class DISActor extends Actor {
130130
});
131131
}
132132

133-
async showAttackDialog(itemId) {
133+
async showAttackDialogWithItem(itemId) {
134134
const item = this.items.get(itemId);
135135
if (!item) {
136136
return;
137137
}
138+
let attackAbility;
139+
if (item.data.data.weaponType === "melee") {
140+
attackAbility = "body";
141+
} else {
142+
attackAbility = "tech";
143+
}
144+
await this.showAttackDialog(
145+
item.name, attackAbility, item.data.data.damage);
146+
}
147+
148+
async showAttackDialog(attackName, attackAbility, attackDamage) {
138149
const attackDialog = new AttackDialog();
139150
attackDialog.actor = this;
140-
attackDialog.itemId = itemId;
151+
attackDialog.attackName = attackName;
152+
attackDialog.attackAbility = attackAbility;
153+
attackDialog.attackDamage = attackDamage;
141154
attackDialog.render(true);
142155
}
143156

144-
async attack(itemId, defenderDR, rollType, risky) {
145-
const item = this.items.get(itemId);
146-
if (!item) {
147-
return;
148-
}
149-
157+
async rollAttack(attackName, attackAbility, attackDamage, defenderDR, rollType, risky) {
150158
let d20Formula = "1d20";
151159
if (rollType === "advantage") {
152160
d20Formula = "2d20kh";
153161
} else if (rollType === "disadvantage") {
154162
d20Formula = "2d20kl";
155163
}
156-
let ability;
157-
if (item.data.data.weaponType === "melee") {
158-
ability = "body";
159-
} else {
160-
ability = "tech";
161-
}
162-
const weaponTypeKey = `DIS.WeaponType${item.data.data.weaponType[0].toUpperCase() + item.data.data.weaponType.substring(1)}`;
163-
const attackTitle = `${game.i18n.localize(weaponTypeKey)} ${game.i18n.localize("DIS.Attack")}`;
164-
// TODO: localize
165-
const attackText = `To hit: ${d20Formula}+${ability.toUpperCase()} vs. DR${defenderDR}`;
164+
const attackTitle = `${game.i18n.localize("DIS.AttackWith")} ${attackName}`;
165+
const attackText = `${game.i18n.localize("DIS.ToHit")}: ${d20Formula}+${attackAbility.toUpperCase()} ${game.i18n.localize("DIS.Vs")} ${game.i18n.localize("DIS.DR")}${defenderDR}`;
166166
const rollData = this.getRollData();
167167
const attackRoll = new Roll(
168-
`${d20Formula} + @abilities.${ability}.value`,
168+
`${d20Formula} + @abilities.${attackAbility}.value`,
169169
rollData
170170
);
171171
attackRoll.evaluate({ async: false });
@@ -180,7 +180,7 @@ export class DISActor extends Actor {
180180
if (isCrit || attackRoll.total >= defenderDR) {
181181
// hit
182182
attackOutcome = game.i18n.localize(isCrit ? "DIS.AttackCriticalHit" : "DIS.AttackHit");
183-
const baseDamage = item.data.data.damage;
183+
const baseDamage = attackDamage;
184184
let damageFormula = baseDamage;
185185
if (isCrit) {
186186
damageFormula += ` + ${baseDamage}`;
@@ -202,6 +202,7 @@ export class DISActor extends Actor {
202202
}
203203

204204
const chatData = {
205+
attackName,
205206
attackOutcome,
206207
attackRoll,
207208
attackText,

module/actor/sheet/attack-dialog.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export default class AttackDialog extends Application {
2727
.val();
2828
const risky = $(form).find("input[name=risky]").is(":checked");
2929
this.close();
30-
// TODO: await this?
31-
this.actor.attack(this.itemId, defenderDR, rollType, risky);
30+
this.actor.rollAttack(this.attackName, this.attackAbility, this.attackDamage, defenderDR, rollType, risky);
3231
}
3332
}

module/actor/sheet/character-sheet.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ export class DISCharacterSheet extends DISActorSheet {
130130
event.preventDefault();
131131
const row = $(event.currentTarget).parents(".item");
132132
const itemId = row.data("itemId");
133-
//this.actor.rollItemAttack(itemId);
134-
this.actor.showAttackDialog(itemId);
133+
this.actor.showAttackDialogWithItem(itemId);
135134
}
136135

137136
_onDamageRoll(event) {

module/actor/sheet/npc-sheet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class DISNpcSheet extends DISActorSheet {
3838

3939
_onAttackRoll(event) {
4040
event.preventDefault();
41-
this.actor.rollNpcAttack();
41+
this.actor.showAttackDialog(this.actor.data.data.attackName, this.actor.data.data.attackAbility, this.actor.data.data.attackDamage);
4242
}
4343

4444
_onDamageRoll(event) {

0 commit comments

Comments
 (0)