Skip to content

Commit 503e48c

Browse files
author
Firebottle
committed
refactor: A bunch of refactoring and flavor text improvements. New settings as well.
1 parent ed6df52 commit 503e48c

File tree

9 files changed

+265
-107
lines changed

9 files changed

+265
-107
lines changed

src/firebot/games/register-game.ts

Lines changed: 78 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,27 @@ const gameSettings: Record<string, SettingCategoryDefinition> = {
283283
description: 'Settings related to combat.',
284284
sortRank: 5,
285285
settings: {
286+
duelTimeout: {
287+
type: 'number',
288+
title: 'Duel Timeout',
289+
description:
290+
'This is the number of minutes that must pass before a duel request times out.',
291+
tip: 'New duels can not be issued to someone until the previous duel times out.',
292+
default: 2,
293+
sortRank: 1,
294+
showBottomHr: false,
295+
validation: {
296+
required: true,
297+
},
298+
},
286299
offHandMissChance: {
287300
type: 'number',
288301
title: 'Off hand fumble chance',
289302
description:
290-
'If a weapon in the off hand is not "light", this is the fumble chance (skipped turn).',
303+
'If a weapon or spell is in the off hand and is not "light", this is the fumble chance (skipped turn).',
291304
tip: 'Setting this lower makes off hand weapons stronger in melee.',
292305
default: 25,
293-
sortRank: 1,
306+
sortRank: 2,
294307
showBottomHr: false,
295308
validation: {
296309
required: true,
@@ -303,7 +316,7 @@ const gameSettings: Record<string, SettingCategoryDefinition> = {
303316
'If a ranged weapon is used in melee, this is the fumble chance (skipped turn).',
304317
tip: 'Setting this lower makes ranged weapons stronger in melee.',
305318
default: 25,
306-
sortRank: 1,
319+
sortRank: 3,
307320
showBottomHr: false,
308321
validation: {
309322
required: true,
@@ -316,7 +329,7 @@ const gameSettings: Record<string, SettingCategoryDefinition> = {
316329
'Divide character stats by this number to determine hit bonus',
317330
tip: 'The lower this number, the higher the hit bonus. This will make characters hit more often.',
318331
default: 10,
319-
sortRank: 2,
332+
sortRank: 4,
320333
showBottomHr: false,
321334
validation: {
322335
required: true,
@@ -329,7 +342,7 @@ const gameSettings: Record<string, SettingCategoryDefinition> = {
329342
'Divide character stats by this number to determine damage bonus',
330343
tip: 'The lower this number, the higher the damage bonus. This will make characters deal more damage.',
331344
default: 10,
332-
sortRank: 2,
345+
sortRank: 5,
333346
showBottomHr: false,
334347
validation: {
335348
required: true,
@@ -342,7 +355,7 @@ const gameSettings: Record<string, SettingCategoryDefinition> = {
342355
'This is how fast a character moves in heavy armor.',
343356
tip: 'The higher this number, the faster heavy armor characters will approach in the ranged phase of combat.',
344357
default: 30,
345-
sortRank: 2,
358+
sortRank: 6,
346359
showBottomHr: false,
347360
validation: {
348361
required: true,
@@ -355,7 +368,7 @@ const gameSettings: Record<string, SettingCategoryDefinition> = {
355368
'This is how fast a character moves in medium armor.',
356369
tip: 'The higher this number, the faster medium armor characters will approach in the ranged phase of combat.',
357370
default: 40,
358-
sortRank: 2,
371+
sortRank: 7,
359372
showBottomHr: false,
360373
validation: {
361374
required: true,
@@ -368,7 +381,7 @@ const gameSettings: Record<string, SettingCategoryDefinition> = {
368381
'This is how fast a character moves in light armor.',
369382
tip: 'The higher this number, the faster light armor characters+ will approach in the ranged phase of combat.',
370383
default: 50,
371-
sortRank: 2,
384+
sortRank: 8,
372385
showBottomHr: false,
373386
validation: {
374387
required: true,
@@ -381,7 +394,7 @@ const gameSettings: Record<string, SettingCategoryDefinition> = {
381394
'This is how fast a character moves with no armor.',
382395
tip: 'The higher this number, the faster unarmored characters will approach in the ranged phase of combat.',
383396
default: 50,
384-
sortRank: 2,
397+
sortRank: 9,
385398
showBottomHr: false,
386399
validation: {
387400
required: true,
@@ -394,7 +407,7 @@ const gameSettings: Record<string, SettingCategoryDefinition> = {
394407
'Percent of dex used when calculating bonus AC for this armor type.',
395408
tip: 'The higher this number, the better this armor type becomes.',
396409
default: 25,
397-
sortRank: 2,
410+
sortRank: 10,
398411
showBottomHr: false,
399412
validation: {
400413
required: true,
@@ -407,7 +420,7 @@ const gameSettings: Record<string, SettingCategoryDefinition> = {
407420
'Percent of dex used when calculating bonus AC for this armor type.',
408421
tip: 'The higher this number, the better this armor type becomes.',
409422
default: 50,
410-
sortRank: 2,
423+
sortRank: 11,
411424
showBottomHr: false,
412425
validation: {
413426
required: true,
@@ -420,7 +433,7 @@ const gameSettings: Record<string, SettingCategoryDefinition> = {
420433
'Percent of dex used when calculating bonus AC for this armor type.',
421434
tip: 'The higher this number, the better this armor type becomes.',
422435
default: 75,
423-
sortRank: 2,
436+
sortRank: 12,
424437
showBottomHr: false,
425438
validation: {
426439
required: true,
@@ -433,7 +446,59 @@ const gameSettings: Record<string, SettingCategoryDefinition> = {
433446
'Percent of dex used when calculating bonus AC for this armor type.',
434447
tip: 'The higher this number, the better this armor type becomes.',
435448
default: 100,
436-
sortRank: 2,
449+
sortRank: 13,
450+
showBottomHr: false,
451+
validation: {
452+
required: true,
453+
},
454+
},
455+
heavyArcaneFailure: {
456+
type: 'number',
457+
title: 'Heavy Arcane Failure',
458+
description:
459+
'Percent chance a spell will fail to cast when wearing this type of armor.',
460+
tip: 'Lower numbers makes this armor better for spell users.',
461+
default: 50,
462+
sortRank: 10,
463+
showBottomHr: false,
464+
validation: {
465+
required: true,
466+
},
467+
},
468+
mediumArcaneFailure: {
469+
type: 'number',
470+
title: 'Medium Arcane Failure',
471+
description:
472+
'Percent chance a spell will fail to cast when wearing this type of armor.',
473+
tip: 'Lower numbers makes this armor better for spell users.',
474+
default: 30,
475+
sortRank: 10,
476+
showBottomHr: false,
477+
validation: {
478+
required: true,
479+
},
480+
},
481+
lightArcaneFailure: {
482+
type: 'number',
483+
title: 'Light Arcane Failure',
484+
description:
485+
'Percent chance a spell will fail to cast when wearing this type of armor.',
486+
tip: 'Lower numbers makes this armor better for spell users.',
487+
default: 0,
488+
sortRank: 10,
489+
showBottomHr: false,
490+
validation: {
491+
required: true,
492+
},
493+
},
494+
nakedArcaneFailure: {
495+
type: 'number',
496+
title: 'Unarmored Arcane Failure',
497+
description:
498+
'Percent chance a spell will fail to cast when wearing this type of armor.',
499+
tip: 'Lower numbers makes this armor better for spell users.',
500+
default: 0,
501+
sortRank: 10,
437502
showBottomHr: false,
438503
validation: {
439504
required: true,

src/systems/characters/characters.ts

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {
22
Armor,
33
CharacterClass,
4+
Enchantments,
5+
EnchantmentTypes,
46
Shield,
57
Spell,
68
Title,
@@ -103,6 +105,42 @@ export async function getCharacterTotalAC(
103105
return Math.floor(defenderAC);
104106
}
105107

108+
/**
109+
* Returns defenders defenses against a specific element.
110+
* @param defender
111+
* @param enchantment
112+
* @returns
113+
*/
114+
export function getCharacterElementalDefense(
115+
defender: Character | GeneratedMonster,
116+
enchantment: EnchantmentTypes
117+
) {
118+
let totalDefenderValue = 0;
119+
let armor = null;
120+
let shield = null;
121+
122+
if (defender.armor != null) {
123+
armor = getItemByID(defender.armor.id, 'armor') as Armor;
124+
}
125+
126+
if (defender.offHand != null && defender.offHand?.itemType === 'shield') {
127+
shield = getItemByID(defender.offHand.id, 'shield') as Shield;
128+
}
129+
130+
if (armor != null) {
131+
totalDefenderValue +=
132+
defender.armor.enchantments[enchantment as keyof Enchantments] +
133+
armor.enchantments[enchantment as keyof Enchantments];
134+
}
135+
136+
if (shield != null) {
137+
totalDefenderValue +=
138+
shield.enchantments[enchantment as keyof Enchantments];
139+
}
140+
141+
return totalDefenderValue;
142+
}
143+
106144
/**
107145
* Gets a characters int bonus used in spellcasting and resisting.
108146
* @param attacker
@@ -195,36 +233,36 @@ export async function getCharacterDamageBonus(
195233
let item;
196234
const str = await getAdjustedCharacterStat(attacker, 'str');
197235
const dex = await getAdjustedCharacterStat(attacker, 'dex');
236+
const int = await getAdjustedCharacterStat(attacker, 'int');
198237

199238
// Get our item first.
200239
if (slot === 'mainHand') {
201-
item = getItemByID(attacker.mainHand.id, 'weapon') as Weapon;
240+
item = getItemByID(attacker.mainHand.id, 'weapon') as Weapon | Spell;
202241
}
203242

204-
if (slot === 'offHand' && attacker.offHand.itemType === 'weapon') {
205-
item = getItemByID(attacker.offHand.id, 'weapon') as Weapon;
243+
if (slot === 'offHand' && attacker.offHand.itemType !== 'shield') {
244+
item = getItemByID(attacker.offHand.id, 'weapon') as Weapon | Spell;
206245
}
207246

208247
if (item == null) {
209248
return 0;
210249
}
211250

251+
// Item is a spell, use int.
252+
if (item.itemType === 'spell') {
253+
return Math.floor(int / damageBonusDivider);
254+
}
255+
212256
// Now, adjust for item properties.
213257
if (item.properties.includes('versatile')) {
214258
return Math.floor(Math.max(str, dex) / damageBonusDivider);
215259
}
216260

217-
if (
218-
item.properties.includes('heavy') ||
219-
item.damage_type === 'bludgeoning'
220-
) {
261+
if (item.properties.includes('heavy')) {
221262
return Math.floor(str / damageBonusDivider);
222263
}
223264

224-
if (
225-
item.properties.includes('finesse') ||
226-
item.damage_type === 'piercing'
227-
) {
265+
if (item.properties.includes('finesse')) {
228266
return Math.floor(dex / damageBonusDivider);
229267
}
230268

src/systems/duels/duels.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { startCombat } from '../combat/combat';
2+
import { getDuelTimeout } from '../settings';
23
import { getUserData } from '../user/user';
34

45
export function isDuelExpired(date: number | null) {
56
if (date == null) {
67
return true;
78
}
89

9-
const timer = 1000 * 60 * 2; // 2 minutes
10+
const duelTimeout = getDuelTimeout() ? getDuelTimeout() : 2;
11+
const timer = 1000 * 60 * duelTimeout;
1012
const checked = Date.now() - timer;
1113

1214
return date > checked;

src/systems/equipment/armor.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
StoredArmor,
77
} from '../../types/equipment';
88
import {
9+
getArmorArcaneFailure,
910
getArmorDexBonusSettings,
1011
getArmorMovementSpeedSettings,
1112
} from '../settings';
@@ -37,7 +38,7 @@ export function getArmorFilteredByRarity(rarity: Rarity[]): Armor {
3738
* @param armorType
3839
* @returns
3940
*/
40-
export function getArmorDexBonus(armorType: ArmorProperties) {
41+
export function getArmorDexBonus(armorType: ArmorProperties): number {
4142
return getArmorDexBonusSettings(armorType) / 100;
4243
}
4344

@@ -102,15 +103,6 @@ export async function generateArmorForUser(
102103
* @param weight
103104
* @returns
104105
*/
105-
export function getArcaneFailureChance(
106-
weight: 'heavy' | 'medium' | 'light'
107-
): number {
108-
switch (weight) {
109-
case 'heavy':
110-
return 50;
111-
case 'medium':
112-
return 30;
113-
default:
114-
return 0;
115-
}
106+
export function getArcaneFailureChance(weight: ArmorProperties): number {
107+
return getArmorArcaneFailure(weight);
116108
}

0 commit comments

Comments
 (0)