Skip to content

Commit 969269a

Browse files
author
Firebottle
committed
fix: A bunch of sanity checks so we're not getting the id of null items.
1 parent 1f51865 commit 969269a

File tree

5 files changed

+31
-13
lines changed

5 files changed

+31
-13
lines changed

src/firebot/commands/rpg-job.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ export async function rpgJobCommand(userCommand: UserCommand) {
283283
let completePlayer = await getCompleteCharacterData(player);
284284

285285
logger('debug', `JOB STARTED: ${username}`);
286+
logger('debug', `PLAYER: ${JSON.stringify(completePlayer)}`);
286287

287288
// Combat time.
288289
if (selectedJob.encounter != null) {

src/systems/characters/characters.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,15 @@ export async function getCharacterDamageBonus(
261261
const int = await getAdjustedCharacterStat(attacker, 'int');
262262

263263
// Get our item first.
264-
if (slot === 'mainHand') {
264+
if (slot === 'mainHand' && attacker.mainHand != null) {
265265
item = getItemByID(attacker.mainHand.id, 'weapon') as Weapon | Spell;
266266
}
267267

268-
if (slot === 'offHand' && attacker.offHand.itemType !== 'shield') {
268+
if (
269+
slot === 'offHand' &&
270+
attacker.offHand.itemType !== 'shield' &&
271+
attacker.offHand != null
272+
) {
269273
item = getItemByID(attacker.offHand.id, 'weapon') as Weapon | Spell;
270274
}
271275

src/systems/combat/approach.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,18 +219,23 @@ async function getDistanceMoved(
219219
let approacherArmor = null;
220220

221221
if (characterOneMaxRange >= characterTwoMaxRange) {
222+
if (characterTwo.armor != null) {
223+
approacherArmor = (await getItemByID(
224+
characterTwo.armor.id,
225+
'armor'
226+
)) as Armor;
227+
}
228+
229+
return getArmorMovementSpeed(approacherArmor);
230+
}
231+
232+
if (characterOne.armor != null) {
222233
approacherArmor = (await getItemByID(
223-
characterTwo.armor?.id,
234+
characterOne.armor.id,
224235
'armor'
225236
)) as Armor;
226-
return getArmorMovementSpeed(approacherArmor);
227237
}
228238

229-
approacherArmor = (await getItemByID(
230-
characterOne.armor?.id,
231-
'armor'
232-
)) as Armor;
233-
234239
return getArmorMovementSpeed(approacherArmor);
235240
}
236241

src/systems/combat/combat-hit.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,14 @@ export async function didCharacterHitMelee(
151151
const defenderAC = await getCharacterTotalAC(defender, roundCounter);
152152
const hitBonus = await getCharacterHitBonus(attacker, slot);
153153
const roll = rollDice(`1d20 +${hitBonus}`);
154+
let item = null;
154155

155-
const item = getItemByID(
156-
attacker[slot as EquippableSlots].id,
157-
attacker[slot as EquippableSlots].itemType
158-
) as Weapon | Spell;
156+
if (attacker[slot as EquippableSlots] != null) {
157+
item = getItemByID(
158+
attacker[slot as EquippableSlots].id,
159+
attacker[slot as EquippableSlots].itemType
160+
) as Weapon | Spell;
161+
}
159162

160163
if (item == null) {
161164
logger(

src/systems/combat/magic.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import { rollDice } from '../utils';
88
export async function didCharacterCastSuccessfully(
99
attacker: Character
1010
): Promise<boolean> {
11+
// Naked users have no arcane failure.
12+
if (attacker.armor == null) {
13+
return true;
14+
}
15+
1116
const armor = (await getItemByID(attacker.armor.id, 'armor')) as Armor;
1217
const failureChance = getArcaneFailureChance(armor.properties[0]);
1318
const roll = rollDice('1d100');

0 commit comments

Comments
 (0)