Metadata-Version: 2.4
Name: kirby-cost
Version: 0.2.0
Summary: Read HERO Designer's own .hdt templates and .hdc characters, and reproduce its point-cost arithmetic exactly.
Author: Peter D Bethke
License: # PolyForm Noncommercial License 1.0.0
        
        <https://polyformproject.org/licenses/noncommercial/1.0.0>
        
        ## Acceptance
        
        In order to get any license under these terms, you must agree
        to them as both strict obligations and conditions to all
        your licenses.
        
        ## Copyright License
        
        The licensor grants you a copyright license for the
        software to do everything you might do with the software
        that would otherwise infringe the licensor's copyright
        in it for any permitted purpose.  However, you may
        only distribute the software according to [Distribution
        License](#distribution-license) and make changes or new works
        based on the software according to [Changes and New Works
        License](#changes-and-new-works-license).
        
        ## Distribution License
        
        The licensor grants you an additional copyright license
        to distribute copies of the software.  Your license
        to distribute covers distributing the software with
        changes and new works permitted by [Changes and New Works
        License](#changes-and-new-works-license).
        
        ## Notices
        
        You must ensure that anyone who gets a copy of any part of
        the software from you also gets a copy of these terms or the
        URL for them above, as well as copies of any plain-text lines
        beginning with `Required Notice:` that the licensor provided
        with the software.  For example:
        
        > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
        
        ## Changes and New Works License
        
        The licensor grants you an additional copyright license to
        make changes and new works based on the software for any
        permitted purpose.
        
        ## Patent License
        
        The licensor grants you a patent license for the software that
        covers patent claims the licensor can license, or becomes able
        to license, that you would infringe by using the software.
        
        ## Noncommercial Purposes
        
        Any noncommercial purpose is a permitted purpose.
        
        ## Personal Uses
        
        Personal use for research, experiment, and testing for
        the benefit of public knowledge, personal study, private
        entertainment, hobby projects, amateur pursuits, or religious
        observance, without any anticipated commercial application,
        is use for a permitted purpose.
        
        ## Noncommercial Organizations
        
        Use by any charitable organization, educational institution,
        public research organization, public safety or health
        organization, environmental protection organization,
        or government institution is use for a permitted purpose
        regardless of the source of funding or obligations resulting
        from the funding.
        
        ## Fair Use
        
        You may have "fair use" rights for the software under the
        law. These terms do not limit them.
        
        ## No Other Rights
        
        These terms do not allow you to sublicense or transfer any of
        your licenses to anyone else, or prevent the licensor from
        granting licenses to anyone else.  These terms do not imply
        any other licenses.
        
        ## Patent Defense
        
        If you make any written claim that the software infringes or
        contributes to infringement of any patent, your patent license
        for the software granted under these terms ends immediately. If
        your company makes such a claim, your patent license ends
        immediately for work on behalf of your company.
        
        ## Violations
        
        The first time you are notified in writing that you have
        violated any of these terms, or done anything with the software
        not covered by your licenses, your licenses can nonetheless
        continue if you come into full compliance with these terms,
        and take practical steps to correct past violations, within
        32 days of receiving notice.  Otherwise, all your licenses
        end immediately.
        
        ## No Liability
        
        ***As far as the law allows, the software comes as is, without
        any warranty or condition, and the licensor will not be liable
        to you for any damages arising out of these terms or the use
        or nature of the software, under any kind of legal claim.***
        
        ## Definitions
        
        The **licensor** is the individual or entity offering these
        terms, and the **software** is the software the licensor makes
        available under these terms.
        
        **You** refers to the individual or entity agreeing to these
        terms.
        
        **Your company** is any legal entity, sole proprietorship,
        or other kind of organization that you work for, plus all
        organizations that have control over, are under the control of,
        or are under common control with that organization.  **Control**
        means ownership of substantially all the assets of an entity,
        or the power to direct its management and policies by vote,
        contract, or otherwise.  Control can be direct or indirect.
        
        **Your licenses** are all the licenses granted to you for the
        software under these terms.
        
        **Use** means anything you do with the software requiring one
        of your licenses.
        
        
        ================================================================================
        NOTES SPECIFIC TO kirby-cost
        ================================================================================
        
        Required Notice: Copyright (c) 2026 Peter D Bethke
        
        (The line above begins with `Required Notice:` deliberately -- see the
        Notices section of the licence. It must travel with any copy of this
        software or any part of it.)
        
        Why this licence
        ----------------
        
        kirby-cost is a Python port of the HERO Designer cost engine. The intent of
        choosing a noncommercial licence is explicit: nobody should be able to build a
        paid product on this work, because doing so would compete with HERO Designer
        and with Hero Games' interests.
        
        The Elastic License 2.0 was considered and rejected for this purpose. ELv2's
        only commercial limitation is against offering the software as a hosted or
        managed service; it permits selling a non-hosted product outright. That does
        not serve the intent above.
        
        Third-party rights this licence does NOT grant
        -----------------------------------------------
        
        This work derives from HERO Designer source licensed from CompNet Design, Inc.
        That licence grants personal use and modification; distribution is separately
        gated on licensing with HERO Games. Nothing in this file grants, or purports to
        grant, any right in HERO Designer's source, in the HERO System rules, or in any
        Hero Games property.
        
        kirby-cost ships NO Hero Games data. It requires the operator to supply their
        own licensed HERO Designer template (for example Main6E.hdt). Running this
        software without such a licence is the operator's responsibility.
        
        HERO System and HERO Designer are the property of their respective owners.
        
Project-URL: Homepage, https://github.com/pdbethke/kirby-cost
Project-URL: Source, https://github.com/pdbethke/kirby-cost
Project-URL: Issues, https://github.com/pdbethke/kirby-cost/issues
Keywords: hero-system,champions,hero-designer,rpg,tabletop
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: Other/Proprietary License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Games/Entertainment :: Role-Playing
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: typing-extensions>=4.8.0
Requires-Dist: lxml>=4.9.0
Provides-Extra: dev
Requires-Dist: pytest>=7.4.0; extra == "dev"
Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
Requires-Dist: mypy>=1.5.0; extra == "dev"
Requires-Dist: black>=23.0.0; extra == "dev"
Requires-Dist: flake8>=6.0.0; extra == "dev"
Dynamic: license-file

# kirby-cost

A Python library for reading HERO Designer's own files — `.hdt` templates and `.hdc`
characters — and reproducing HERO Designer's point-cost arithmetic exactly.

It exists so that **personal Python projects can work with the files HERO Designer
produces**: read a character you built in HD, walk its powers, skills and frameworks as
real objects, and get the same Total / Active / Real costs HD itself would show.

Ported from the **licensed HERO Designer Java source code**, purchased from Hero Games
(see [Provenance](#provenance)).

## What it is for

HERO Designer is where you build a character. This library is for the things you might
want to do afterwards, in Python, for yourself:

- Read an `.hdc` file into typed objects instead of hand-parsing XML.
- Get per-object costs — Total, Active, Real — and character totals, computed the way HD
  computes them rather than re-derived from the rulebook.
- Feed a character you already built into a personal project: a virtual tabletop, a
  campaign tracker, a combat simulator, a spreadsheet, a bit of analysis.
- Verify arithmetic — confirm that what you have matches what HD says it costs.

The point is interoperability with HD's file formats from Python. If you can already do
what you want inside HERO Designer, do it there.

## What it is not

**This is not a replacement for HERO Designer, and not a competitor to it.**

It is a calculator over a build that HERO Designer already authored. It has no character
creation interface — nothing in this library creates or edits a character; it reads one
and does arithmetic on it. And it cannot run without HD: the templates that define what
powers exist and what they cost are HD's, and you supply them from your own licensed
installation.

If you want to create a HERO System character, buy HERO Designer. This library assumes
you already have.

## Requirements — bring your own HERO Designer licence and templates

kirby-cost ships no Hero Games content. To use it you supply, from your own licensed
HERO Designer installation:

- **Your own HERO Designer licence.** This library neither includes nor substitutes for one.
- **Your own template files (`.hdt`)** — `Main6E.hdt` and any others you use. The
  templates encode Hero Games' published catalogue of powers, skills, modifiers and
  their costs. That data is theirs; it is not redistributed here.
- **Your own character files (`.hdc`)**, and any published character packs you cost
  with it.

Point the engine at your template with `KIRBY_COST_HDT`:

```bash
export KIRBY_COST_HDT="$HOME/HERO Designer/template/Main6E.hdt"
```

or pass a path directly:

```python
from kirby_cost.template.hdt_provider import HDTTemplateProvider
loader = HDCLoader(provider=HDTTemplateProvider("/path/to/Main6E.hdt"))
```

There is no bundled fallback — without a template the loader raises and names what to
set. Templates reach the engine through the `TemplateProvider` interface
(`kirby_cost/template/provider.py`), so a consumer that keeps its catalogue elsewhere
implements that protocol against its own storage and passes the provider in.

### How it is verified, and why you cannot reproduce that here

The engine is validated by costing published characters and comparing every number
against HERO Designer's own engine, run headless. As of 2026-08-17 that is 655
characters, 27,019 objects and 82,367 individual cost values, with zero mismatches.

**None of that apparatus is public, and cannot be.** The comparison harness wraps the
licensed HERO Designer source, and the corpus is built from commercial character packs —
names, power names and full costed builds, which together amount to a machine-readable
copy of published stat blocks. Neither is redistributable, so neither is here. The
fixtures directory is gitignored so a locally generated corpus cannot be committed by
accident.

What that means for you: the parity claim above is the maintainer's measurement, not
something this repository lets you re-run. The tests that ship exercise the engine's own
logic and pass without any of it:

```
  375 passed, 159 skipped     # the code alone: no templates, no corpus
  416 passed, 118 skipped     # your templates, no corpus
```

If you own the HERO Designer source package and want to reproduce the full comparison,
contact the maintainer.

## Installation

```bash
pip install kirby-cost
```

or from a clone, for development:

```bash
python3 -m venv venv
source venv/bin/activate
pip install -e ".[dev]"
```

## Usage

```python
from kirby_cost.io import HDCLoader

# reads the .hdt named by KIRBY_COST_HDT
hero = HDCLoader().load_file("MyCharacter.hdc")

print(hero.name, hero.total_points, hero.available_points)

for power in hero.powers:
    print(f"{power.name or power.alias}: {power.real_cost}")
```

`hero` also exposes `characteristics`, `skills`, `perks`, `talents` and `martial_arts`.

`hero.powers` is flat and holds framework containers alongside their slots, the way HD
writes them. A Multipower or VPP appears as an object in its own right, its slots carry
`slot.parent`, and the container also holds them in `container.objects`. Slot costs
follow the framework's rules — a Multipower slot is a fraction of the reserve, and a
power inside a VPP costs nothing at all, because the pool already paid for it. Grouping
containers HD creates for the character sheet appear too, costed at zero.

## Status

- **100% parity with HERO Designer.** Every one of 655 published characters matches the
  Java application's own output on every object and on character totals — 27,019 objects
  and 82,367 individual cost values, with zero mismatches.
- **1,290 tests.** 375 of them need nothing but the code; the rest need your own
  templates, and the parity suite needs a corpus you generate locally.
- Pure code — no database, no web framework, no network access.

Parity is measured against HERO Designer's own engine, run headless over the same
character files. Both halves of that comparison have been wrong before and been
corrected: the figure means "every value the corpus compares", and the corpus is
described above so you can judge what that covers.

## Provenance

**This is a port of licensed source code, purchased from Hero Games.**

The **HERO Designer Source Code** package is an official product Hero Games sells, offered
precisely so people can build software that works with HD. Its product page says so
directly: *"many potential software projects for the HERO System could make use of
portions of the source code which drives HERO Designer. It is for this reason that we are
pleased to offer access to HD's source code."* The purchase receipt and the product page
are retained by the maintainer; they are deliberately not in this repository, which
carries no Hero Games material of any kind. It provides:

- The HERO Designer Java source, updated as the application updates
- The Eclipse project definitions
- Access to the HD Developer Access forum, to ask the developer questions directly

The licensed source is what this port is built on, cited against, and verified against.
The class- and line-level citations throughout this repository (e.g. `Converted from
com.hero.objects.GenericObject.java`) refer to it.

### Licence terms, and how this project sits inside them

Quoted from the product page:

> - You are welcome to change the code or utilize it however you want for your own personal use.
> - If the product you develop is distributed, you will need to pursue licensing with HERO Games -- the terms are exceedingly easy.
> - If the product you develop is intended for sale, there may be a licensing discussion needed with both HERO Games and the developer/owner of the HERO Designer source code. Generally speaking, use of the HERO Designer source code which does not replace or replicate the character generation process does not fall into this category.

**This project follows those guidelines deliberately.**

- The source licence was **purchased**, at full price, from Hero Games' own store.
- Use here is **personal**, which the first condition permits without conditions.
- kirby-cost **does not replace or replicate the character generation process**. It has
  no creation interface; it costs a build HD already produced, and depends on HD's
  templates and licence to run at all.
- It is **noncommercial** — offered under PolyForm Noncommercial 1.0.0, not for sale —
  so the third condition's "intended for sale" case is not engaged.
- **The second condition is acknowledged, not hidden.** This repository is public, which
  the terms treat as distribution. The project is built to sit inside those terms rather
  than at their edge: the source was bought, nothing of Hero Games' is redistributed —
  not the templates, not the character packs, not the test corpus derived from them —
  and the library cannot create a character. Hero Games describe the licensing terms as
  "exceedingly easy", and if they want that arrangement formalised, see below.

If Hero Games, or the owner of the HERO Designer source, sees any of this differently,
we want to hear it — contact the maintainer and it will be acted on.

### Copyright and trademark

HERO Designer is © 2002, 2003, 2006, 2009 by DOJ, Inc. d/b/a Hero Games. **HERO System™**
is DOJ, Inc.'s trademark for its roleplaying system. Game rules content remains the
property of its copyright holders, and no claim is made to ownership of the HERO Designer
application, the game rules, or the game mechanics. This project is an independent work
and is not affiliated with or endorsed by DOJ, Inc. d/b/a Hero Games.

See [`LICENSE`](LICENSE) for the terms this code is offered under
(PolyForm Noncommercial 1.0.0).
