- A character at 0 HP is Dying, Stable or Dead. The tallies live on the character, so the sheet and the encounter card always agree. - Death saves are typed in as the d20 showed: 10 or more succeeds, less fails, a 1 fails twice, a 20 puts the character back up at 1 HP. Three successes make them stable; three failures kill. - Damage taken at 0 HP is a failed save and ends stable. A blow that leaves as much as max HP still to take after reaching 0 kills outright. - Healing from 0 clears the tallies. The dead cannot be healed; the DM revives them at 1 HP. - A player rolls and stabilises for their own character; the DM for anyone, and only the DM sets tallies by hand or revives. - The party overview, campaign list and quick stats show the state. - All packages at version 1.5.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
107 lines
4.4 KiB
TypeScript
107 lines
4.4 KiB
TypeScript
import { Link, useParams } from 'react-router-dom';
|
|
import { useAuth } from '../auth/AuthContext';
|
|
import { useCampaign, useCampaignCharacters } from '../api/queries';
|
|
import { useCampaignSocket } from '../hooks/useCampaignSocket';
|
|
import { Spinner, ErrorBanner } from '../components/Spinner';
|
|
import { usePagination, Pagination } from '../components/Paginated';
|
|
import { InfoTip } from '../components/InfoTip';
|
|
import { CLASS_LABELS, SPECIES_LABELS, formatPurse } from '../lib/format';
|
|
import { HpBar } from '../components/HpBar';
|
|
import { LifeBadge } from '../components/DeathSaves';
|
|
import { speciesIcon } from '../lib/speciesIcons';
|
|
|
|
// A DM's one-screen view of every character's stats at a glance; a player
|
|
// sees the same table, scoped to their own character(s) plus a read-only
|
|
// view of the rest of the party — same visibility split as the character
|
|
// list on the campaign home page.
|
|
export function PartyOverviewPage() {
|
|
const { campaignId = '' } = useParams();
|
|
const { user } = useAuth();
|
|
useCampaignSocket(campaignId);
|
|
|
|
const { data, isLoading: campaignLoading, error: campaignError } = useCampaign(campaignId);
|
|
const { data: characters, isLoading: charsLoading, error: charsError } = useCampaignCharacters(campaignId);
|
|
const { pageItems, page, pageCount, prevPage, nextPage } = usePagination(characters, 12);
|
|
|
|
if (campaignLoading || charsLoading) return <Spinner label="Gathering the party…" />;
|
|
if (campaignError || charsError || !data) return <ErrorBanner message="Could not load the party overview." />;
|
|
|
|
const isDM = data.campaign.role === 'DM';
|
|
|
|
return (
|
|
<div>
|
|
<div className="page-header">
|
|
<div>
|
|
<h1>Party Overview</h1>
|
|
<p className="subtitle">{isDM ? 'Every character in this campaign, at a glance.' : 'Your party.'}</p>
|
|
</div>
|
|
<Link to={`/campaigns/${campaignId}`} className="btn btn-ghost">
|
|
← Back to Campaign
|
|
</Link>
|
|
</div>
|
|
|
|
{characters?.length === 0 && <div className="empty-state">No characters yet.</div>}
|
|
|
|
{characters && characters.length > 0 && (
|
|
<div className="table-wrap">
|
|
<table className="data-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Character</th>
|
|
<th>Species</th>
|
|
<th>Class</th>
|
|
<th>Level</th>
|
|
<th>
|
|
HP <InfoTip term="HP" />
|
|
</th>
|
|
<th>
|
|
AC <InfoTip term="AC" />
|
|
</th>
|
|
<th>Coins</th>
|
|
<th>Location</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{pageItems.map((c) => {
|
|
const inProgress = c.buildStage !== 'COMPLETE';
|
|
const isMine = c.userId === user?.id;
|
|
return (
|
|
<tr key={c.id}>
|
|
<td>
|
|
<Link to={inProgress ? `/characters/${c.id}/build` : `/characters/${c.id}`}>
|
|
<span aria-hidden="true">{speciesIcon(c.species)}</span> {c.name}
|
|
</Link>
|
|
{isMine && <span className="badge" style={{ marginLeft: 6 }}>you</span>}
|
|
</td>
|
|
<td>{c.species ? SPECIES_LABELS[c.species] : '—'}</td>
|
|
<td>{c.characterClass ? CLASS_LABELS[c.characterClass] : inProgress ? 'Building…' : '—'}</td>
|
|
<td>{c.level}</td>
|
|
<td>
|
|
{c.maxHp != null ? (
|
|
<div style={{ minWidth: 90 }}>
|
|
<span className="mono">
|
|
{c.currentHp}/{c.maxHp}
|
|
{c.tempHp > 0 && ` +${c.tempHp}`}
|
|
</span>{' '}
|
|
<LifeBadge deathSaves={c.deathSaves} />
|
|
<HpBar current={c.currentHp} max={c.maxHp} temp={c.tempHp} height={6} />
|
|
</div>
|
|
) : (
|
|
'—'
|
|
)}
|
|
</td>
|
|
<td>{c.armorClass ?? '—'}</td>
|
|
<td className="mono">{c.gold == null ? '—' : formatPurse(c)}</td>
|
|
<td>{c.currentLocationName ? `📍 ${c.currentLocationName}` : '—'}</td>
|
|
</tr>
|
|
);
|
|
})}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
)}
|
|
<Pagination page={page} pageCount={pageCount} onPrev={prevPage} onNext={nextPage} />
|
|
</div>
|
|
);
|
|
}
|