Skip to content

Commit

Permalink
better handling of damage types
Browse files Browse the repository at this point in the history
  • Loading branch information
nornagon committed Jul 26, 2024
1 parent e9556bc commit 134cb36
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion _test/all.meta.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"buildNum":"cdda-experimental-2024-04-30-0753","sha":"c5e504e02ff892dfc470d3a75873781a15019aa060eb2f0bca769921b74a5313"}
{"buildNum":"cdda-experimental-2024-07-26-0605","sha":"e8d131811503113476396350c0c80ada4a4c1b21f8bb68c0fee26ea12e54b5b2"}
12 changes: 1 addition & 11 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,17 +310,7 @@ export type ToolSlot = {
rand_charges?: integer[];
};

export type DamageTypeId =
| "pure"
| "biological"
| "bash"
| "cut"
| "acid"
| "stab"
| "bullet"
| "heat"
| "cold"
| "electric"; // TODO maybe no longer static?
export type DamageTypeId = string;

export type DamageUnit = {
damage_type: DamageTypeId;
Expand Down
11 changes: 7 additions & 4 deletions src/types/Monster.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ function difficulty(mon: Monster): number {
const melee_dmg_total = normalizedMeleeDamage.reduce((acc, { amount = 0, damage_multiplier = 1, constant_damage_multiplier = 1 }) => acc + amount * damage_multiplier * constant_damage_multiplier, 0)
let armor_diff = 3
for (const [damageTypeId, amount] of Object.entries(monsterArmor(mon.armor ?? {}))) {
const damageType = data.byId("damage_type", damageTypeId)
if (damageType.mon_difficulty)
const damageType = data.byIdMaybe("damage_type", damageTypeId)
if (damageType?.mon_difficulty)
armor_diff += amount
}
let difficulty = ( melee_skill + 1 ) * melee_dice * ( melee_dmg_total + melee_sides ) * 0.04 +
Expand Down Expand Up @@ -375,9 +375,12 @@ let upgrades =
<dd>
<dl>
{#each Object.entries(monsterArmor(item.armor)) as [damageTypeId, value]}
{@const damageType = data.byId("damage_type", damageTypeId)}
{@const damageType = data.byIdMaybe(
"damage_type",
damageTypeId
)}
{#if value}
<dt>{singularName(damageType)}</dt>
<dt>{singularName(damageType ?? { id: damageTypeId })}</dt>
<dd>{value.toFixed(1)}</dd>
{/if}
{/each}
Expand Down
12 changes: 8 additions & 4 deletions src/types/item/AmmoInfo.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<script lang="ts">
import { t } from "@transifex/native";
import { i18n } from "../../data";
import { CddaData, i18n, singularName } from "../../data";
import type { AmmoSlot, DamageUnit } from "../../types";
import ThingLink from "../ThingLink.svelte";
import { getContext } from "svelte";
export let item: AmmoSlot;
const _context = "Item Ammo Info";
const data = getContext<CddaData>("data");
// TODO: handle multiple damage type
const damage = Array.isArray(item.damage)
? item.damage[0]
Expand Down Expand Up @@ -36,9 +39,10 @@ function computeLoudness(item: AmmoSlot): number {
<dd><ThingLink type="ammunition_type" id={item.ammo_type} /></dd>
<dt>{t("Damage", { _context })}</dt>
<dd>
{damage.amount ?? 0} ({i18n._p(
"damage_type",
damage.damage_type ?? "bullet"
{damage.amount ?? 0} ({singularName(
data.byIdMaybe("damage_type", damage.damage_type) ?? {
id: damage.damage_type,
}
)})
</dd>
<dt>{t("Armor Penetration", { _context })}</dt>
Expand Down
11 changes: 9 additions & 2 deletions src/types/item/GunInfo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
import { t } from "@transifex/native";
import type { DamageUnit, GunSlot, ItemBasicInfo } from "../../types";
import ThingLink from "../ThingLink.svelte";
import { CddaData, singularName } from "../../data";
import { getContext } from "svelte";
export let item: GunSlot & ItemBasicInfo;
export const _context = "Item Gun Info";
const data = getContext<CddaData>("data");
// TODO: handle multiple ranged_damage type
const ranged_damage = Array.isArray(item.ranged_damage)
? item.ranged_damage[0]
Expand All @@ -33,7 +36,11 @@ const ranged_damage = Array.isArray(item.ranged_damage)
{/if}
<dt>{t("Base Damage", { _context })}</dt>
<dd>
{ranged_damage.amount ?? 0} ({ranged_damage.damage_type ?? "bullet"})
{ranged_damage.amount ?? 0} ({singularName(
data.byIdMaybe("damage_type", ranged_damage.damage_type) ?? {
id: ranged_damage.damage_type,
}
)})
</dd>
<dt>{t("Armor Penetration", { _context })}</dt>
<dd>{ranged_damage.armor_penetration ?? 0}</dd>
Expand Down
6 changes: 5 additions & 1 deletion src/types/item/MeleeInfo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ const piercing =
<h1>{t("Melee", { _context, _comment: "Section heading" })}</h1>
<dl>
{#each Object.entries(item.melee_damage) as [damageType, damage]}
<dt>{singularName(data.byId("damage_type", damageType))}</dt>
<dt>
{singularName(
data.byIdMaybe("damage_type", damageType) ?? { id: damageType }
)}
</dt>
<dd>{damage}</dd>
{/each}
<dt>{t("To Hit", { _context })}</dt>
Expand Down

0 comments on commit 134cb36

Please sign in to comment.