Skip to content

osrlib.core.npc

NPC adventuring parties: the SRD generation procedure from the character model.

Basic and Expert Adventurers generate through the same character kernel PCs use — composition (the caller rolls the count: the wandering table's printed dice or the compiled composition dice), one alignment for the whole party (RAW offers either; a single alignment drives reaction, parley, and ward interactions coherently), then per member in order: the d8 class-and-level row, the level dice by kind, 3d6-in-order ability scores, hit points by rolling the class hit die per level through level_up (CON applied, minimum 1 per level), XP at the class's threshold for the rolled level, the equipment kit, and rolled spell picks. All of those draw from the NPC_PARTY_STREAM stream; the party's treasure and Expert magic items draw from the treasure stream instead, since they are treasure procedures and belong to its statistics.

osrlib adopts several documented adaptations here (see the adaptations register): NPC adventurers skip class ability-score requirements (RAW's procedure rolls class before scores and names no re-roll); the equipment kits are invented over RAW's "normal adventuring gear"; casters roll each open slot uniformly from the class-legal spells of that level ("choose or roll" — rolling is the deterministic branch), with arcane spell books equal to exactly the memorized picks; Expert magic items roll at 5% per level per suitable sub-table in the master table's printed order, unusable rolls ignored with no re-roll, and rolled wearable or wieldable items are equipped when better than the kit piece (higher effective AC, or any enchantment over a mundane arm).

Part of the core kernel. Call generate_npc_party to run the whole procedure; it builds on osrlib.core.character, whose model and creation functions it reuses for each party member.

NPC_PARTY_STREAM module-attribute

NPC_PARTY_STREAM = 'npc_party'

Stream key for NPC-party generation: composition, class, level, scores, hp, spells.

NpcParty

Bases: BaseModel

A generated NPC adventuring party: the members, their alignment, the loot.

treasure is the group's shared U + V bundle (rolled once), carried as a group bundle that drops with the loot flow — slain or surrendered; a routed party keeps it.

kind instance-attribute

kind: Literal['basic', 'expert']

alignment instance-attribute

alignment: Alignment

members instance-attribute

members: list[Character]

treasure instance-attribute

generate_npc_party

generate_npc_party(
    kind: Literal["basic", "expert"], *, count: int, npc_stream: RngStream, treasure_stream: RngStream, allocator: Any
) -> NpcParty

Generate an NPC adventuring party by the SRD procedure.

Draw order: one d6 alignment roll for the whole party, then per member — the d8 class-and-level row, the level dice by kind, 3d6-in-order scores, the first-level hit die, one level_up roll per level above first, and the spell picks — all on npc_stream; then each member's Expert magic items and finally the shared U + V group treasure on treasure_stream.

Parameters:

Name Type Description Default
kind Literal['basic', 'expert']

"basic" (levels 1d3) or "expert" (per-row level dice).

required
count int

The party size; the caller rolls it (the wandering row's printed dice, or the compiled composition dice).

required
npc_stream RngStream

The npc_party stream.

required
treasure_stream RngStream

The treasure stream — items and the group bundle are treasure procedures and belong to its statistics, not the NPC stream's.

required
allocator Any

The id allocator (npc, magic-item, and valuable prefixes).

required

Returns:

Type Description
NpcParty

The generated party.

npc_defeat_xp

npc_defeat_xp(level: int) -> int

Return the XP award for defeating an NPC adventurer of level.

osrlib adopts the reading that an NPC adventurer's XP award is the OSE SRD's XP awards table value for HD equal to the NPC's level, no plus-category, no ability bonuses — RAW prices monsters, not classed NPCs, and level-as-HD is the straight reading.

Parameters:

Name Type Description Default
level int

The NPC's class level.

required

Returns:

Type Description
int

The base XP award.