Documentation
¶
Overview ¶
Package skill is where the rest of the engine meets: a skill names an element, a shape, a power, a scaling stat, the statuses it inflicts and the condition that makes it hit harder. Everything it names is validated against the book that declares it, so a typo in a data file fails at load rather than at the moment it would have mattered.
Nothing here computes damage. A skill is a declaration; turning one into a combat.Hit is the battle layer's job, because only the battle knows the caster's current stats, the target's, and the state of the board.
Index ¶
- Constants
- func CanCarry(affinity element.Affinity, carried Skill) bool
- func Demands(kit []Skill) []element.Element
- func WhySummonsCannotRecurse(book *Book, declared Skill) error
- type Application
- type Book
- type CarryRefusal
- type Cleanse
- type Condition
- func (c *Condition) AppliesOnHold() bool
- func (c *Condition) Arcs() bool
- func (c *Condition) CapsStacks() bool
- func (c *Condition) ChainsOn() bool
- func (c *Condition) GatesCast() bool
- func (c *Condition) Holds(against Target) bool
- func (c *Condition) ReadsHealth() bool
- func (c *Condition) ReadsStatus() bool
- func (c *Condition) Satisfying() Target
- func (c *Condition) Scales() bool
- func (c *Condition) ScalesRestore() bool
- func (c *Condition) Takes(held int) int
- type Deps
- type Gradient
- type Restriction
- func (r *Restriction) AllowsArchetype(id string) bool
- func (r *Restriction) AllowsCharacter(id string) bool
- func (r *Restriction) AllowsElement(affinity element.Affinity) bool
- func (r *Restriction) AllowsOrigin(id string) bool
- func (r *Restriction) AllowsSpecies(kinds []string) bool
- func (r *Restriction) ElementNames() []string
- func (r *Restriction) NamesCharacters() bool
- func (r *Restriction) NamesOrigins() bool
- func (r *Restriction) NamesSpecies() bool
- func (r *Restriction) OriginNames() []string
- func (r *Restriction) SpeciesNames() []string
- type Scaling
- type Side
- type Skill
- func (s Skill) Amplified(against Target) bool
- func (s Skill) ExpectedStrikes() int
- func (s Skill) Guaranteed() bool
- func (s Skill) MarshalJSON() ([]byte, error)
- func (s Skill) PowerAgainst(against Target) int
- func (s Skill) Repeats() bool
- func (s Skill) SelfAmplified(caster Target) bool
- func (s Skill) SelfBonus(caster Target) int
- func (s Skill) SelfCeiling() int
- func (s Skill) SelfRestore(caster Target) int
- func (s Skill) SelfRestoreCeiling() int
- func (s Skill) SelfScale(health, maximum int64) int
- func (s Skill) StrikeCount() int
- func (s Skill) TotalPower() int
- type Summon
- type Target
Constants ¶
const MaxSpendPower = 4 * scale.Base
MaxSpendPower is the most one spend of a counter may add to a skill's own power, in parts per thousand of the caster's scaling stat.
It exists because Condition.StackPower is the only authored power in this package that is multiplied before it is used, and the multiplier is a stack count capped at nine hundred and ninety nine. Every other ceiling here bounds a term an author can read at a glance; this one bounds a product the author never writes down.
Applied by Condition.Takes rather than by clamping the bonus, so what a spend removes and what it buys stay one figure — read that comment before moving it.
Four times the scaling stat, which is a little over twice the heaviest single skill in the shipped book. A spend is meant to be the biggest thing a turn can do and not a different game: at this ceiling emptying a full reserve is worth about two ordinary casts, so hoarding stays a real decision and never becomes the only one.
const MaxSpendRestore = 2 * scale.Base
MaxSpendRestore is the most one spend of a counter may restore to its caster, in parts per thousand of the caster's scaling stat.
MaxSpendPower's twin, and it exists for the same reason: Condition.StackRestore is multiplied by a stack count before it is used, so it bounds a product the author never writes down. Applied by Condition.Takes on the STACKS, exactly as its twin is — read that comment before moving this one.
Twice the scaling stat, derived from the shipped book rather than picked: the heaviest restore anybody carries is `synthesis` at 900, so this is a little over twice the biggest heal in the game. At the golden's reference 800 attack it caps one spend at 1600 health, which sits just under the 1611 damage `tide_break` deals for a spend of the same size — so emptying a reserve into health and emptying it into a blow are worth about the same turn, which is what makes the choice between them a decision rather than an answer.
const MaxSummonCount = 5
MaxSummonCount bounds what one cast may put down.
It is the formation's own size rather than a number of its own: a side cannot hold more than a full team however many a skill asks for, so a larger figure could only ever be an author asking for something the board will refuse silently. Refusing it here says so while the file is still in front of them.
const SideCount = int(All) + 1
SideCount is the number of targeting sides.
Variables ¶
This section is empty.
Functions ¶
func CanCarry ¶
CanCarry reports whether a unit of the given affinity may use this skill. It is WhyCannotCarry for a caller that only needs the yes or no.
func Demands ¶
Demands returns the distinct non-neutral elements a kit requires, in the order the skills were listed.
It is what a kit says about the affinity that may hold it: a unit must have every element in this set, so a kit demanding more than two can never be carried at all, and a kit demanding two can only be carried by exactly that pair. Deriving it from the skills is the point — an authored hint would be free to drift from the kit it described.
func WhySummonsCannotRecurse ¶
WhySummonsCannotRecurse is the rule a book can only check once every skill in it is parsed: a summoned unit may not know a skill that summons.
Without it a single cast is an unbounded one. The board would stop it in practice — a side holds five and no more — but "it runs out of room" is not a rule anybody can read off the file, and a summon whose skills are refused at the moment the room appears is worse than one refused while it is written.
Types ¶
type Application ¶
Application is a status a skill inflicts, with its own chance to take hold.
The chance is fixed. It is not raised by accuracy, not lowered by dodge, and no stat touches it, so it stays a property of the skill rather than of whoever happens to be holding it. Landing the hit and inflicting the status are two separate questions: a skill that connects nine times in ten and poisons half the time poisons on 45 percent of casts, and both halves of that stay legible.
type Book ¶
type Book struct {
// contains filtered or unexported fields
}
Book is the declared skills.
func ParseBook ¶
ParseBook reads a skill declaration and checks every name it uses. It never touches the filesystem.
⚠️ **A field this book does not know is refused, not ignored**, the same rule the status book states for itself and for the same reason: a silent drop of a field an author deliberately wrote is the worst answer available, because the file looks like it worked. Leaving it open here after closing it there would have been a new asymmetry in place of the one that was closed — a misspelt field on a status refused while the same typo on a skill went nowhere.
Measured before it was turned on: the shipped book decodes strictly as it stands, so this refuses nothing that exists today.
func (*Book) Append ¶
Append returns a new book holding the declared skills plus the extra ones, validated exactly as a parse would validate them.
It works by marshalling and re-parsing rather than by re-implementing the checks, which is what guarantees the bytes an authoring tool is about to write are bytes that load.
func (*Book) Marshal ¶
Marshal writes the book as a data file: two-space indented JSON, in the order the skills were declared.
Declaration order rather than sorted by id, which is where this differs from cast.Book.Marshal, and the difference is the point. A cast is a set looked up by id, so sorting it is free and makes an addition a one-block diff. A skill book's order is authored information — the shipped file reads basic attacks, then the elemental ones, then the utility skills, and skills.golden's table is that order — so sorting would shuffle a design record to buy the same one-block diff that appending already gives.
func (*Book) Replace ¶
Replace returns a new book with one skill's declaration changed, in the place that skill already had.
Keeping the position is the whole of it, and it is the same reason Marshal keeps declaration order rather than sorting: the shipped skills.json is committed in the form Marshal writes, and its order is authored information — basic attacks, then the elemental ones, then utility, which is the order skills.golden's table reads in. Moving an edited skill to the end would rewrite every line of the file and every row of that table to change one number, which is exactly what committing the file in Marshal form was meant to avoid.
It validates the way Append does, by marshalling and re-parsing rather than by re-implementing a check, so the bytes an authoring tool is about to write are bytes that load. A skill the book does not already hold is refused: this changes a declaration and never adds one, so an id that is not there is a caller's mistake rather than a new skill.
The id itself cannot be changed through this, because the id is what the position is found by. Renaming a skill has to walk every kit and every restriction that names the old one, which is a different operation.
type CarryRefusal ¶
type CarryRefusal uint8
CarryRefusal is why an affinity may not carry a skill, or that it may.
It is a classification rather than a sentence for the same reason internal/forge returns values: three callers refuse a kit and each words it for its own reader — the engine for a log, the parser for a data file, the authoring tool in the author's language — and a sentence cannot be reworded after it is built without being taken apart again.
const ( // CarryAllowed is a skill the affinity may use. CarryAllowed CarryRefusal = iota // CarryWrongElement is a skill of an element the unit does not have. CarryWrongElement // CarryElementRestricted is a skill whose element allowlist excludes the // unit. It is a separate answer from CarryWrongElement because the two need // different advice: one is fixed by changing the affinity to the skill's // element, and the other cannot be, because the skill's own element is // already shared. CarryElementRestricted )
func WhyCannotCarry ¶
func WhyCannotCarry(affinity element.Affinity, carried Skill) CarryRefusal
WhyCannotCarry is the whole of which skills an affinity may carry.
Two conditions, in the order they are worth reporting. A unit may only use a skill of an element it shares — a neutral skill is universal, which is what makes a second element worth carrying — and it must also satisfy whatever element allowlist the skill declares, which is the narrower rule a restriction adds. Nothing else here is enforceable: an archetype, a character identity and a species do not reach the engine, so those three halves of a restriction are checked where a character is authored. See Restriction.
This is the single declaration. battle.enlist refuses a roster entry that breaks it, cast.ParseBook refuses an authored character that breaks it and forge.CheckCarry brings the same answer forward to the moment an answer is typed — all three by calling this, because two callers wording one rule in their own words is how the two come to disagree, and the disagreement here would be a character that writes cleanly and then cannot enter a battle.
type Condition ¶
type Condition struct {
// Status and MinStacks are what the target must already be carrying. A
// condition may leave them out when it reads health instead.
Status string
MinStacks int
// BelowHealth is the share of its maximum health the unit must be at or
// under, in parts per thousand, and nought is "does not ask". Half is 500.
//
// *Which* unit is the field's business and not this type's: Skill.Requires
// reads the target and Skill.SelfRequires reads the caster, exactly as
// Applies and SelfApplies say who receives a status. That is why the pair is
// two fields rather than one field with a "whose" flag -- the reader already
// knows what the self_ prefix means here, and a flag would be a third thing
// to get wrong.
//
// passive.Condition still reads its holder through a type of its own. The two
// share their arithmetic through scale.AtOrBelowShare and deliberately not
// their type, because passive imports this package and the language refuses
// the shortcut anyway.
BelowHealth int
// BelowStacks is how many stacks of Status the unit must be holding FEWER
// than, and nought is "does not ask" — the same spelling BelowHealth uses,
// and for the same reason: a bound written as "below n" has no meaningful
// zero, so the zero value can mean unasked without a pointer or a second
// flag.
//
// # Why a cap exists at all, when MinStacks is a floor
//
// The two are not opposites of one another; they answer different questions.
// MinStacks is *have you saved enough to pay for this*, which is what every
// reserve in the book asks. BelowStacks is *how many times may you do this at
// all*, which nothing could ask before: a cooldown counts a caster's turns and
// so bounds the rate, never the total, and a permanent status cannot be spent
// (status.Set.Remove refuses one on purpose, so a cleanse can never dispel a
// trait) so a budget cannot be granted and drawn down either.
//
// The shape a lifetime cap takes with it: the skill self-applies a counter and
// gates on holding fewer than the cap. Two casts, spelled `below_stacks: 2` —
// the first sees nought, the second sees one, the third sees two and is not
// offered.
//
// ⚠️ **It composes with MinStacks rather than replacing it**, and both clauses
// read the same status. "At least one and fewer than three" is a legal and
// useful window; a condition naming only BelowStacks is a pure cap.
BelowStacks int
// Gates makes this a condition on **casting** rather than on the payoff.
//
// Every other condition in this engine is an amplifier: it is read while the
// skill resolves, and a caster that fails it simply casts for its own figure.
// A gating condition is read *before* the skill is offered, so a caster short
// of what it names does not have the option at all -- which is the only shape
// a cooldownless spender can take. Without it the spender is cast every turn
// for the unamplified blow, and the design is a suggestion.
//
// ⚠️ **Opt-in, and it has to be.** Nine shipped skills carry min_stacks
// across four characters -- flare, deluge, pyre, thorn_volley, cauterise,
// bloom_burst, verdant_mend, tide_break and wellspring -- and every one was
// authored as an amplifier that pays more when it holds. Reading min_stacks as
// a gate globally would rebalance four characters at once, inside a change
// whose subject is a tenth skill.
//
// ⚠️ **The caster's own condition only, it must read a status, and it must
// spend one.** resolveCondition refuses the other three shapes and says why at
// each: what they have in common is that the reading would have to be taken
// per aim, and battle.aims is required to stay blind to a gate.
Gates bool
// BonusPower is added to the skill's power when the condition holds.
BonusPower int
// Consume removes the status, which is what a detonate does: the burst is
// paid for by the ticks it throws away.
Consume bool
// ConsumeStacks is how many stacks a consume takes, and nought means all of
// them, which is what every consume did before the field existed.
//
// The distinction is the difference between a detonate and a discharge. A
// detonate spends a whole pile at once because the pile *is* the payment —
// the burst is worth the ticks thrown away, so leaving some behind would be
// leaving the payment behind. A counter spent one at a time is a magazine
// instead, and taking the whole magazine for one shot is what would make
// accumulating it pointless.
ConsumeStacks int
// Chains makes the consume travel: from the unit at the aim to every
// hex-adjacent unit carrying the same status, and on from those, for as far
// as an unbroken run of carriers reaches.
//
// It replaced a fixed pattern, and the difference is the whole idea. A
// pattern is geometry — it covers the same three cells whoever is standing
// in them — so a charged unit one cell outside it was never reached and an
// uncharged unit inside it was hit anyway. A chain is the opposite: it goes
// exactly where the charge is, and **it needs a charged body to step on**. A
// gap of one uncharged cell stops it dead, which is what makes laying the
// charge down a decision about *where* rather than only about how much.
//
// ⚠️ **The aim gates the whole thing.** A chain from an uncharged unit is
// empty however much charge is standing beside it — nothing is consumed,
// nothing arcs, and the skill is simply its own blow.
Chains bool
// ArcPower is what one consumed stack deals, as a share of the caster's
// scaling stat, exactly as a skill's own power is.
//
// ⚠️ **It is added to the skill's own blow and never traded against it.** An
// earlier design damped the blow to pay for the discharge, on the reasoning
// that a skill hitting for its full figure *and* firing the charge would be
// strictly better whenever the charge was there. That reasoning was wrong
// about where the payment comes from: a stack does not appear on a target by
// itself, and the turn that put it there is the price. A conduit is paid for
// in **tempo** — the charging turns and the cooldown it sits on — so its own
// figure is a constant, and a reader comparing two skills is comparing the
// numbers on them rather than the numbers minus a condition.
//
// ⚠️ **It is not the skill's damage and does not behave like it.** It is the
// charge going off, so it is not aimed, not rolled against accuracy or dodge,
// and **not stopped by a shield**: a guard that swallows the blow does not
// stop what was already sitting on the target. That is the one thing a
// conduit has over an ordinary attack, and it is the reason the counter is
// worth laying down in front of a wall.
ArcPower int
// StackPower is what one consumed stack adds to the skill's own power, and it
// is the caster's side of the board answering ArcPower.
//
// ⚠️ **It is the only payment that scales with the size of the spend**, which
// is the whole reason it exists. BonusPower is flat, so a skill that empties a
// reserve of nine hundred for it pays exactly what a skill that spends twenty
// pays — "spend all of it" written with a flat payment is a sentence with no
// arithmetic in it. This one multiplies, so how much is left is a decision
// every turn rather than a threshold crossed once.
//
// ⚠️ **It is not ArcPower and does not behave like it.** An arc is the charge
// going off on the target: unaimed, unrolled, and not stopped by a guard. This
// is the caster hitting harder, so it goes into the skill's power and is
// therefore aimed, rolled against accuracy and dodge, divided by defence and
// eaten by a shield exactly as the rest of the blow is. That is why it can be
// caster-side while an arc may not be: it reads nothing about the board.
//
// ⚠️ **Caster-side only, and refused on `requires`.** The target's condition
// already has a per-stack currency, and taking both would be the ceiling
// charged twice with nothing downstream able to tell which half a figure came
// from — the same refusal BonusPower and ArcPower already share.
StackPower int
// StackRestore is the health twin of StackPower: what one consumed stack
// restores to the caster, in parts per thousand of the scaling stat, which is
// the same unit Skill.Restores is written in.
//
// ⚠️ **It is what makes a reserve buy something other than a blow.** A skill
// declaring `restores` alone pays out in full to a caster holding no fuel at
// all — the condition is an amplifier, so failing it charges nothing and stops
// nothing — and a heal that is free when the tank is empty is not paid for by
// the tank. Written per stack instead, with the flat `restores` left at
// nought, "no fuel, no heal" is arithmetic rather than a gate somebody has to
// remember to write.
//
// ⚠️ **A condition may not carry both currencies.** Takes clamps the stacks a
// spend removes against the ceiling the payment can buy, and there is one
// Takes: a condition holding both a power rate and a health rate would have
// two ceilings answering one question, and whichever was applied would be
// wrong for the other half.
StackRestore int
// Applies are riders the condition pays out only when it holds, on the same
// target it read. They are the condition's third currency: a bonus buys
// damage, a restore buys health, and these buy a status the skill does not
// otherwise inflict.
//
// ⚠️ **A target's condition only.** The caster's own reads the caster, so a
// rider here would land on whoever cast it, which is what `self_applies`
// already says plainly and without a condition in the way.
//
// They go out through the same inflict, the same roll and the same shield
// filter as the skill's own `applies`, because a rider that survived a block
// on a different rule from its neighbour would be a difference no reader
// could find on either.
Applies []Application
}
Condition is the amplifier that pays a skill off for arriving after a status.
func (*Condition) AppliesOnHold ¶
AppliesOnHold reports whether the condition carries riders of its own.
func (*Condition) Arcs ¶
Arcs reports whether the condition discharges the status it consumes into damage of its own.
func (*Condition) CapsStacks ¶ added in v0.2.0
CapsStacks reports whether the condition names an upper bound on stacks, which is the same shape ReadsHealth has and answers the same question about the zero value: nought stacks is not a bound anybody could mean.
func (*Condition) GatesCast ¶
GatesCast reports whether the condition decides that the skill may be cast at all, rather than what the cast pays out.
func (*Condition) Holds ¶
Holds reports whether a target satisfies the condition.
Every clause must hold, not any of them: a condition naming both a status and a threshold is "already burning *and* nearly dead", which is the only reading that lets a second clause narrow a skill rather than widen it.
func (*Condition) ReadsHealth ¶
ReadsHealth reports whether the condition asks how hurt the target is.
func (*Condition) ReadsStatus ¶
ReadsStatus reports whether the condition asks what the target is carrying. A condition that reads only health leaves Status empty.
func (*Condition) Satisfying ¶
Satisfying is the cheapest target the condition holds against: exactly the stacks it asks for, and health as low as it wants.
It is what a preview and a report want — both are answering "what is this skill worth when it goes off", and neither has a real unit to ask. Health of nought out of one is not a unit anybody could meet, and that is the point: it is the *threshold satisfied*, written so it cannot be mistaken for a measurement of somebody.
func (*Condition) Scales ¶
Scales reports whether the condition pays its caster per stack it spends.
func (*Condition) ScalesRestore ¶
ScalesRestore reports whether the condition pays its caster health per stack it spends.
A second predicate rather than a widened Scales, because the two are read to decide which sentence to write and which figure to quote: a heal-only spender answering true to Scales would have the description promise that every stack adds to the blow, off a StackPower of nought.
func (*Condition) Takes ¶
Takes is how many stacks a consume removes from a target carrying the given number, and nought when this condition consumes nothing.
The "all of them" default lives here rather than at the call site because two callers ask — the battle that spends the stacks and the pricing that values them — and a default written twice is a default that will disagree with itself.
⚠️ **It is asked once per STRIKE, not once per cast.** One blow spends one charge, so a skill that lands three times spends three — which is what makes a repeating strike and a pile of counters the same bet twice over, and what keeps a multi-strike conduit from being a single-strike one with better numbers.
type Deps ¶
Deps are the books a skill's declarations are checked against. Validating here rather than at use is the whole point: a skill naming a shape or a status that does not exist is a data error, and a data error should stop the load.
type Gradient ¶
type Gradient struct {
// AtEmpty is the share added to the skill's power as the caster approaches
// no health, in parts per thousand. A thousand is double power at the bottom.
AtEmpty int
}
Gradient is how much harder a skill hits as its caster falls, declared by the one number an author has to choose: what it is worth at the very bottom.
One field rather than a pair, because the top of the curve is not a choice — a caster at full health has nothing to be desperate about, so the gradient is worth nothing there by definition. An author picking a floor as well as a ceiling would be picking a threshold, and the threshold already exists.
func (*Gradient) Share ¶
Share returns what the gradient adds at a given health, in parts per thousand, and nought for a skill that declares none.
Nil-safe like Condition.Holds, and for the same reason: the caller is asking what a skill does, and "it does not have one" is an answer rather than a state worth branching on at every call site.
type Restriction ¶
type Restriction struct {
// Elements is the affinities allowed to carry the skill: a unit qualifies
// by holding any one of them.
//
// Any rather than all, because a unit holds at most two elements and an
// all-of rule of more than two could never be met. The list is what makes a
// *neutral* skill restrictable at all — CanCarry lets every affinity carry
// a neutral skill, so a neutral skill that should belong to two elements has
// nowhere else to say so.
Elements []element.Element
// Archetypes is the role presets allowed to carry it, by id in the
// archetype book.
Archetypes []string
// Characters is the characters allowed to carry it, by id in the cast book.
// A list of one is a unique skill.
Characters []string
// Species is the kinds of creature allowed to carry it, by id in the
// species book: a unit qualifies by being any one of them.
//
// Any rather than all, because a unit may be several things at once and a
// skill about being a dragon has no opinion about what else the holder is.
// This is the axis a body-bound skill wants: a lineage outlives the
// character that first had it, so `dragon_rage` restricted to one character
// said "only this one may carry it" when it meant "only a dragon may".
Species []string
// Origins is the works allowed to carry it, by id in the origin book: a
// character qualifies by having been borrowed from any one of them.
//
// The broadest gate here, and the one that says a skill belongs to a
// fiction rather than to a body or a fighting style. A work outlives every
// character in it, which is the same argument Species makes about a
// lineage: `rasengan` restricted to naruto.naruto would say "only this one
// may carry it" when it means "only somebody from Naruto may", and would
// have to be edited every time that work lends another character.
//
// It is a list rather than one id because a crossover is a thing that
// happens, and because every other axis here is a list.
Origins []string
}
Restriction is who a skill declares itself available to.
Every list is an allowlist and every one is optional: a list that is absent restricts nothing, and a skill with no restriction at all is carried by whoever CanCarry allows. A list that is present and empty is a data error rather than "unrestricted" — an allowlist nobody satisfies is a mistake every time, and reading it as "no restriction" would turn that mistake into a skill silently available to everyone.
Why four of the five are plain strings ¶
Elements are parsed here because this package already knows what an element is. Archetypes, characters, species and origins are not: internal/core/cast declares all four, and cast imports this package, so a skill that named a cast type would be an import cycle. So they travel as the ids they were written with and are checked one layer up, by cast.ParseBook and cast.ParseArchetypes — exactly the way a skill's pattern and status names are checked by whoever holds those books rather than by whoever declares the skill.
The layering has a consequence worth stating rather than working around: battle.Roster carries stats, skills, an affinity and a slot, and no archetype, no character identity and no species, because all three are resolved before a battle starts. So Elements is enforceable at battle load and the other four are not. They are authoring-time rules, and pushing any of them into the engine to "complete" the feature would put a fact into the replayable core that no replay needs. See CLAUDE.md, "What a restriction can enforce".
func (*Restriction) AllowsArchetype ¶
func (r *Restriction) AllowsArchetype(id string) bool
AllowsArchetype reports whether the preset allowlist admits an id.
func (*Restriction) AllowsCharacter ¶
func (r *Restriction) AllowsCharacter(id string) bool
AllowsCharacter reports whether the character allowlist admits an id.
func (*Restriction) AllowsElement ¶
func (r *Restriction) AllowsElement(affinity element.Affinity) bool
AllowsElement reports whether the element allowlist admits an affinity.
The nil receiver is the unrestricted case and answers yes, so a caller never has to ask whether there is a restriction before asking what it says.
func (*Restriction) AllowsOrigin ¶
func (r *Restriction) AllowsOrigin(id string) bool
AllowsOrigin reports whether the origin allowlist admits the work a character was borrowed from.
A character with no origin fails a restricted list, for AllowsSpecies's reason: the allowlist names where a holder must be from, and nowhere is not one of those places.
func (*Restriction) AllowsSpecies ¶
func (r *Restriction) AllowsSpecies(kinds []string) bool
AllowsSpecies reports whether the species allowlist admits a unit that is any of the given kinds.
A unit with no species satisfies an unrestricted skill and fails a restricted one, which is the same answer an empty character id would get: the allowlist names what a holder must be, and being nothing is not one of them.
func (*Restriction) ElementNames ¶
func (r *Restriction) ElementNames() []string
ElementNames is the element allowlist written out, which is what a refusal and a listing want.
func (*Restriction) NamesCharacters ¶
func (r *Restriction) NamesCharacters() bool
NamesCharacters reports whether the skill belongs to named characters, which is what makes it unusable in a preset shared by every character built from it.
func (*Restriction) NamesOrigins ¶
func (r *Restriction) NamesOrigins() bool
NamesOrigins reports whether the skill belongs to named works, which keeps it out of a preset for the third time and the same reason: a preset says how a character fights, so every character built from one that was borrowed from another work would be refused, and the refusal would land on whoever wrote the character.
func (*Restriction) NamesSpecies ¶
func (r *Restriction) NamesSpecies() bool
NamesSpecies reports whether the skill belongs to named kinds of creature, which makes it unusable in a preset for exactly the same reason: a preset says how a character fights and nothing about what it is, so every character built from one that is not of those kinds would be refused — and the refusal would land on whoever wrote the character rather than on whoever wrote the preset.
func (*Restriction) OriginNames ¶
func (r *Restriction) OriginNames() []string
OriginNames is the origin allowlist written out, and reaches through the pointer safely for SpeciesNames's reason.
func (*Restriction) SpeciesNames ¶
func (r *Restriction) SpeciesNames() []string
SpeciesNames is the species allowlist written out.
It exists so that a caller can walk the list without reaching through the pointer: r.Species on a nil restriction is a nil dereference, while every method here answers for the unrestricted case. That trap cost a panic once.
type Scaling ¶
type Scaling struct {
Stat progression.Kind
Source combat.ScalingSource
}
Scaling names which stat a skill's damage comes from and which version of it to read.
func DefaultScaling ¶
func DefaultScaling() Scaling
DefaultScaling is what a skill scales off when it says nothing: the caster's attack as it stands, which is what almost every skill wants.
It is named once because three places need it — resolve, which fills it in, file, which leaves it out again, and an authoring tool building a skill from answers — and a second copy of the pair would let a written file disagree with the one it was read from.
It is exported because the zero Scaling is *not* this: progression.HP is the zero stat, and a skill scaling off health is refused, so a Skill built in Go without setting this field is refused the moment it is written. That refusal is loud on purpose. Silently substituting the default here would make the field's zero value mean two different things depending on where the skill came from.
func ParseScaling ¶
ParseScaling resolves a scaling declaration as written in a data file.
Exported because a trait's reply is authored the same way and must be read the same way: "off which stat, and the base one or the modified one" is one question, and two parsers answering it would answer it differently the first time either was edited. An empty source is the current value, which is what a skill that says nothing has always meant.
type Side ¶
type Side uint8
Side is who a skill is aimed at.
const ( // Enemy aims across the battlefield. Enemy Side = iota // Ally aims at the caster's own half, the caster included. Ally // Self aims only at the caster. Self // All aims at either half, and a shape aimed this way spreads across the // midline instead of stopping at it. // // It is what a skill that does not care whose side a unit is on needs: a // battlefield-wide cleanse, a haste on everybody, and — since nothing here // distinguishes a friendly target from a hostile one once a cell is chosen — // a damaging skill that hurts the caster's own squad as well. That last one // is the point of having the value rather than a flaw in it; resolveAgainst // has never asked which side a target is on, so an ally-aimed damaging skill // already did the same thing. // // Declared last on purpose. The value is serialised by name like every // other enum here, so appending cannot reinterpret a skill book or a saved // log — but the numbering is what SideCount and TargetNames are built from, // and putting a new value in the middle would reorder the chooser a // front-end offers. All )
func (Side) CrossesSides ¶
CrossesSides reports whether a shape aimed by this skill may spread onto the other half of the board.
pattern.Targets drops a splash cell that lands on the far side of the midline, which is right for every skill that aims at one side: an area attack on the enemy front rank must not catch the caster's own. A skill aimed at both sides is the one case where that drop is wrong, and this is what says so — once, for the two places that walk a shape.
func (Side) Reaches ¶
Reaches reports whether a skill aimed by a unit on one side of the board may be pointed at a cell on another.
The rule is relational rather than absolute — "the other side" depends on whose turn it is — and it lives here because it is one rule with two callers: the legal aims a unit is offered and the aim an action is checked against. Before, battle worked out an absolute side and then flipped it for an enemy caster, which is the same fact written as a special case.
Self is not asked here and answers no. It reaches exactly the caster's own cell, which is a unit rather than a side, so nothing can decide it from two sides alone; battle answers that one before it asks this.
type Skill ¶
type Skill struct {
ID string
// Name is the skill's authored display name, and this package knows nothing
// about it beyond that it is text: not what language it is in, not how wide
// it is on a screen, not whether anything shows it. Nothing in
// internal/core reads it — no rule branches on it and no event carries it —
// which is what lets it be here at all.
//
// # Why the name is on the declaration
//
// A skill's Vietnamese name used to be a compiled table in internal/i18n,
// which meant a name could not be authored by the tool that authors the
// skill. Putting it here rather than in a translations file beside the book
// is the same judgement `Applies` and `Restrict` are here for: a skill and
// its name are authored in one sitting, and a second file is a second thing
// to keep in step — one that would go stale exactly when a skill was
// renamed or removed.
//
// It is absent by default and absent is a real answer: a skill with no name
// renders as its bare id, which is the rule a data id has always followed
// when nothing has a name for it. internal/i18n prefers this over its own
// table, so the compiled names remain the fallback for the skills that
// shipped before this field existed. Being absent by default is also why no
// golden moved when it arrived — see skillFile.
Name string
// Flavour is one clause saying what the skill *does*, in words rather than in
// figures: "vung dây leo quật kẻ địch từ xa". It opens the sentence a
// description is built into, and the numbers are appended to it.
//
// # Why it is authored where nothing else about a description is
//
// Everything else in a description is derived, on purpose, because an
// authored figure drifts the moment the figure it describes moves. Nothing
// derives "dây leo" from `vine_whip`: the name is the one fact about a skill
// that only a person holds, and a generator reading ids would be guessing.
//
// ⚠️ **It may not contain a digit**, and ParseBook refuses one that does.
// That is the whole of what keeps the guarantee: a clause with no number in
// it cannot be made wrong by changing a number, so this is authored prose
// that still cannot go stale. A skill that wants to say "twice over" says it
// by having a bonus, and the sentence built around this clause reports it.
//
// It is absent by default, and absent is a real answer: a skill with no
// flavour opens with the derived clause instead, which is what every skill
// read like before this existed.
Flavour string
Element element.Element
// Range is the hex distance the skill reaches, measured on the shared board.
Range int
// Pattern is the shape it covers, by name in the pattern book.
Pattern string
// Power is the skill's strength per strike, in parts per thousand.
Power int
// Strikes is how many times it lands, at least. A multi-strike skill is
// expected to divide its power rather than repeat it at full strength.
Strikes int
// Repeat is the chance a strike is followed by another, in parts per
// thousand, rolled again after each; MaxStrikes is where it stops. Together
// they turn the count from a number into a distribution — mostly the floor,
// occasionally a great deal more — and ExpectedStrikes is the mean every
// caller outside the roll reads. Zero for every skill that shipped before
// they existed, which is why adding them moved no golden.
Repeat int
MaxStrikes int
// Accuracy is its own chance to connect, before the caster's accuracy stat
// and the target's dodge. A full thousand cannot miss and cannot be dodged.
Accuracy int
// Pierce is the share of the target's defence the skill ignores, in parts
// per thousand. It is the answer to armour, which every other defence in
// the game already has one of, and it is a ratio rather than a switch for
// the reason combat.Pierced records.
//
// It reaches the skill's own strikes and nothing else. A status this skill
// applies ticks against full defence, because a tick's damage is computed
// once when the stack is applied and frozen for the stack's whole life — so
// a pierced tick is worth several pierced hits, which is a larger effect
// than an author setting a per-strike ratio is asking for.
Pierce int
// Unblockable says nothing stops this skill's strikes: neither a block
// charge, which would otherwise cancel one whole, nor an absorbing pool,
// which would otherwise eat the damage before health did.
//
// A switch rather than a share, and it is the only switch of its kind here on
// purpose. Pierce is a ratio because defence is continuous and a ratio walks
// an armoured unit's edge instead of jumping to the end of it; a guard is
// **discrete** — a charge is spent or it is not, a pool is there or it is not
// — so there is no middle for a ratio to express. "Half a block charge" is
// not a quantity this engine has.
//
// ⚠️ It says nothing about defence. A skill that wants to ignore armour as
// well says so with Pierce, and a skill that wants to ignore everything says
// both — which is a great deal for one skill to be given, and the reason to
// price it with a cooldown rather than to hand it out.
Unblockable bool
// Crit is the chance each of its strikes lands critically, in parts per
// thousand. What a critical strike is worth is one game-wide constant on
// combat.Rules, so this is the whole of what makes one skill crit more than
// another — and it belongs to the skill rather than to whoever casts it,
// because progression.Values has no seventh kind to hold it.
//
// Every shipped skill declares nought.
Crit int
Scaling Scaling
// Applies are the statuses inflicted on each target it hits.
Applies []Application
// SelfApplies are the statuses the caster gains, which is how a shield or a
// self buff is written.
SelfApplies []Application
// Requires is the amplifier read against the target, if the skill has one.
Requires *Condition
// SelfRequires is the amplifier read against the caster.
//
// It is what a skill that spends something of its own needs, and until it
// existed such a skill was unwritable: Requires reads the target, so "hits
// harder while I am furied" and "hits harder while I am cornered" had no
// spelling at all. The two are the same shape asked of two different units,
// which is why they are the same type.
//
// Read once per use rather than once per target -- see Battle.spend. A
// condition that consumed per target would pay for a splash three times over
// and a single-target skill once, for a difference written on neither.
SelfRequires *Condition
// SelfGradient is how much harder the skill hits the further its caster has
// fallen, and it is the smooth twin of SelfRequires rather than a second
// copy of it.
//
// A condition answers yes or no, so it can only ever say "at or below this
// line, take this much". There is no line here and no yes or no: every point
// of health lost is worth the same as the last. That is why it is a share
// multiplied into the power rather than a bonus added to it, why the
// arithmetic lives in combat.Gradient, and why it is a type of its own
// instead of a fourth field on Condition that the other three would have to
// leave empty.
//
// Read once per use, exactly like SelfRequires and for the same reason.
SelfGradient *Gradient
// Strips is the cleanse or dispel the skill performs, if any.
Strips *Cleanse
// Restrict is who may carry the skill, or nil when anybody may.
Restrict *Restriction
// Summons is the unit the skill puts on the board, or nil for a skill that
// only acts on units already standing there.
Summons *Summon
// Restores is how much health the skill gives its targets, in parts per
// thousand of the caster's scaling stat. It does not pass through defence:
// see combat.Rules.Restore for why.
Restores int
// Drains is the share of the damage actually dealt that comes back to the
// caster, in parts per thousand. It reads damage *dealt* rather than damage
// rolled, so a strike that missed or was blocked drains nothing.
Drains int
// Cost is the health the caster pays to use the skill, in parts per thousand
// of its MAXIMUM health.
//
// # Paid up front, and paid whether or not anything lands
//
// That is what makes it a cost rather than a recoil. A share taken out of the
// damage dealt would be free on a turn the skill missed, and a skill that is
// free when it fails is a skill with no decision in it — the whole of what
// this field is for is that using it is worse than not using it unless the
// blow is worth the health.
//
// # A share of maximum rather than current, and never lethal
//
// Of maximum, so the price is the same on the first turn and the last: a
// share of *current* health gets cheaper exactly as it gets more dangerous,
// which prices a desperate cast lowest. And the caster is left standing on at
// least one point — see Battle.spendHealth. A skill that could kill its own
// user is a different design question, and one nothing in the rating is built
// to answer: Suggest prices what a turn is worth, not whether there is a
// next one.
//
// ⚠️ It is refused on a skill that throws no strike, the way Pierce is. A
// price with nothing bought is a skill an author wrote by accident.
Cost int
// Cooldown is how many of the caster's own turns must pass before it can be
// used again. Counting the caster's turns rather than cycles means a fast
// unit really does get its skill back sooner, in step with everything else
// that is timed.
Cooldown int
Target Side
}
Skill is one declared action.
func (Skill) ExpectedStrikes ¶
ExpectedStrikes is how many times the skill lands on average, in parts per thousand, and it is the figure every caller outside the roll should read.
⚠️ **Neither end of the range is usable and that is the point of the field.** The floor prices a repeating skill as though the tail never happened, and a rating reading it would never pick one; the ceiling prices every cast as the best cast anybody ever had, and a rating reading that would pick nothing else. A repeating strike is a *distribution*, so what it is worth is its mean.
The arithmetic is combat.Hit.ExpectedStrikes and this is the same sum written where a skill can be asked without building a hit — a description has no caster and no target, and it still has to quote a figure.
func (Skill) Guaranteed ¶
Guaranteed reports whether the skill cannot miss.
func (Skill) MarshalJSON ¶
MarshalJSON writes a skill as the declaration a parse would read back.
func (Skill) PowerAgainst ¶
PowerAgainst returns the power the skill lands with, given how many stacks of its required status the target carries.
func (Skill) Repeats ¶
Repeats reports whether the skill's strike count is rolled rather than fixed.
func (Skill) SelfAmplified ¶
SelfAmplified reports whether the caster's own condition holds.
func (Skill) SelfBonus ¶
SelfBonus is what the caster's own condition adds to the skill's power, and nought when it does not hold or is not declared.
A separate function from PowerAgainst rather than folded into it, because the two are read at different moments: the target's condition is read per target, and this one is read once for the whole use. Folding them would make the second follow the first around the shape. ⚠️ **A per-stack payment is read here and nowhere else.** It is what the spend buys, so it belongs to the same reading as the flat bonus rather than to the consume — and it is multiplied by what the consume will actually take, which is Condition.Takes of what the caster is holding right now. That is the same figure Battle.spend removes, from the same function, so the power the blow lands with and the stacks that paid for it cannot disagree.
func (Skill) SelfCeiling ¶
SelfCeiling is the most the caster's own condition can add to this skill's power, and it is the figure any bound on the swing must be read against.
⚠️ **Not SelfBonus at Satisfying, and the difference is new.** Satisfying is the CHEAPEST target a condition holds against, and for a flat bonus the cheapest case and the dearest one are the same number — so one reading served both until stack_power existed. A per-stack payment is worth more the deeper the reserve, so a bound taken at the threshold would be a bound on the smallest case the skill can produce.
The ceiling comes from Takes rather than from the status book, because Takes is where the ceiling actually bites: a scaling spend refuses stacks past what MaxSpendPower will pay for, whatever the book allows anybody to hold.
func (Skill) SelfRestore ¶
SelfRestore is the health the caster's own condition buys with the stacks it spends, in parts per thousand of the scaling stat, and nought when the condition does not hold or is not declared.
The health twin of SelfBonus, and read at the same moment for the same reason: once per use, off the same Takes the spend removes, so the heal that lands and the stacks that paid for it cannot disagree.
⚠️ **Nought when the condition does not hold, and that is the whole feature.** A skill's flat `restores` pays out whatever the caster is carrying, because a condition is an amplifier and a caster who fails it is charged nothing and stopped by nothing. Written here instead, an empty tank buys an empty heal without a single gate anywhere.
func (Skill) SelfRestoreCeiling ¶
SelfRestoreCeiling is the most the caster's own condition can restore in one cast, and it is SelfCeiling's twin: read through Takes, because Takes is where the ceiling bites, whatever depth the status book allows anybody to bank to.
func (Skill) SelfScale ¶
SelfScale is the share the caster's own wounds add to the skill's power, in parts per thousand, and nought for a skill with no gradient.
It takes the two numbers rather than a Target because a Target carries a stack count as well, and a gradient has nothing to do with what anybody is carrying. Handing it one would say it might.
func (Skill) StrikeCount ¶
StrikeCount treats an unset count as one.
func (Skill) TotalPower ¶
TotalPower is the skill's power across every strike, which is the figure to compare two skills of different strike counts by.
type Summon ¶
type Summon struct {
// Count is how many units the skill puts down. Fewer arrive when the side
// has no room, which is a fact about the board rather than about the skill.
Count int
// Name is what the summoned units are called on screen. They are numbered
// from it, so a name is worth having: three units all reading "clone" are
// three rows a player cannot tell apart.
Name string
// Share and ShareOfBase are parts per thousand of the caster's stats, and
// exactly one of the three stat spellings is set.
// Stats is a fixed line, for a summon that is its own creature.
Stats *progression.Values
// Affinity is the summoned unit's element by name, or empty to take the
// caster's. A clone shares its caster's element; a toad need not.
Affinity string
// Skills is what the summoned unit knows. It may not include a skill that
// summons: see WhySummonCannotCarry.
Skills []string
// Lasts is how many of the summoned unit's **own** turns it stays for, or
// nought for one that stays until something kills it.
//
// Its own turns rather than the battle's, for the reason a cooldown counts
// the caster's: a slow summon and a fast one given "three turns" should each
// get three, and counting the battle's would hand the fast one more of them.
Lasts int
// Bound says the summoned unit leaves when whoever summoned it dies.
//
// A per-skill flag rather than a rule, because the two things this mechanism
// carries answer it differently: a clone is an extension of its caster and
// goes when the caster goes, while a creature that was called up is its own
// and stays to finish the fight.
Bound bool
// Splits is the share of the caster's MAXIMUM health that is moved into each
// summoned unit, in parts per thousand, and nought is a summon that costs the
// caster nothing.
//
// # It is not a cost, and the difference is the whole of the mechanic
//
// skill.Cost takes health out of a caster and leaves its maximum alone, so a
// heal puts it back and the price is temporary. This moves the maximum: the
// caster is a smaller creature afterwards, permanently, and what came off it
// is standing next to it. Two bodies out of one is a different bargain from a
// blow that hurt to throw, and reading it as a cost would let a mender undo
// it.
//
// # It sizes the health only, and the other stats keep their spelling
//
// So it composes with Share, ShareOfBase or Stats rather than replacing one:
// the spelling says what the copy is made of and this says how much of the
// original went into it. A copy at nine tenths of its maker's attack holding
// three tenths of its health is a legal and deliberate shape, and neither
// half could say that alone.
//
// ⚠️ **The health is taken per copy.** A skill putting down two at three
// tenths each takes six tenths off its caster, which is what "count" means
// everywhere else and is why the refusal below is written against the product
// rather than the field.
Splits int
}
Summon is a unit a skill puts on the board.
It is the first thing a skill does that is neither damage, healing nor a status: everything else a skill can do happens *to* somebody already standing there, and this adds somebody. The engine half of that is in battle.summon; what is here is the declaration and every rule that can be checked without a battle in front of it.
Why the stat line has three spellings and not one ¶
A clone and a summoned creature are different things wearing the same mechanism. A clone is a copy, so it is written as a share of whoever made it and moves when that unit is retuned. A creature is its own animal — a toad does not get bigger because the ninja levelled — so it is written as a stat line of its own. Forcing one spelling would mean either a creature that scales off somebody it has nothing to do with, or a clone that has to be re-authored every time its caster's curve moves.
The two shares differ in *when* they read. Share is the caster's stats as they stand, so a caster that buffed itself first makes a better copy — which is the same freeze every damage-over-time in this engine takes, and reads as the clone being a copy of what was there. ShareOfBase ignores every timed effect, which is what an author reaches for when a copy that can be pre-buffed is an exploit rather than a play.
type Target ¶
Target is what a condition is allowed to know about the unit a skill is aimed at: the stacks it carries of the named status, and where its health sits.
It is a struct rather than three parameters because two of the three are int64 health values that mean nothing apart, and a caller that swapped them would compile. The battle fills it in from the unit; a report fills it in from the numbers it is measuring against.