Demon circulation runtime
Paid-energy accounting, shared reserve ownership, activation transitions and owner-only HUD synchronisation.
The Demon circuit is an internal race subsystem. DemonCirculationState owns the accounting; the player component advances it on the server and projects it into status markers and the HUD. Gameplay values are listed in the Demon guide.
What it does
DemonEventFactory subscribes to SpellCastEvents.ON_ENERGY_SPENT. CommonEventFactory emits the amount actually removed from Astral Energy after cost resolution. Only non-Creative server players paying for magic enter circulation; hit callbacks, free deliveries and energy restoration never award reserve.
DemonCirculation connects paid magic, chant timing, outgoing magic damage and incoming absorption. Formula selection, cost computation, delivery count and channel timing remain owned by their existing spell systems.
Runtime model
DemonCirculationModule is hosted under isekaiexpansion:dynamic_player with RespawnCopyStrategy.NEVER_COPY. Live Ancient Blood enables it; death, power loss or a different race identity detaches it and clears its markers. Ordinary save/load restores the module only when the saved identity matches. See dynamic player modules for the host envelope.
The saved state has these fields. Missing numeric fields read as zero; negative and non-finite amounts are rejected. Timers are clamped to their state-machine bounds, credit stays below one energy point, and loading an open circuit clears any simultaneous committed recovery.
| Field | Type | Default | Meaning |
|---|---|---|---|
reserve | double | 0 | Energy still available for absorption or later recovery. |
recovering | double | 0 | Committed recovery, unavailable to the shell. |
credit | double | 0 | Fractional energy waiting for a whole-point payout. |
passiveRate | double | 0 | Passive payout per tick for the current uninterrupted recovery. |
idleTicks | int | 0 | Elapsed ticks since paid magic. |
recoveryTicks | int | 0 | Remaining committed recovery ticks. |
overloadTicks | int | 0 | Remaining Overload ticks. |
capacity is saved as a double with default 0 for restoration and the owner snapshot. The next server update derives it again from current maximum Astral Energy; it is not an independent capacity authority. Reducing capacity clamps stored amounts, and normal energy caps discard overflow.
The dynamic host sends the complete module payload only to its owner every 4 ticks (0.2 seconds) while dirty. Activation and absorption mark the host dirty; they use the same cadence. Module presence supplies HUD visibility, and fractional accounting stays server-authoritative.
Contracts
Opening Overload starts the cooldown once. Reclaim requires the open circuit’s minimum age and transfers reserve into committed recovery exactly once. Automatic expiry uses the same transition. A new cast during committed recovery builds separate reserve and does not stop the pending return.
SkillPowerUtil asks CooldownBypassSkill before invoking the handler. An accepted follow-up preserves the existing cooldown entry, including its original total; the client hint only permits sending the request. The server still checks power ownership, active state and the authoritative transition. DemonEnergyOverloadASkill applies Ability Haste once and enforces its cooldown floor.
SpellCastTiming multiplies non-channelled magic chant duration by the circuit modifier. IsekaiDamageCondition applies the current circuit stage only to MAGIC damage. Neither path modifies a spell definition or synthesises another impact.
PlayerDamageAbsorptionMixin calls personal-barrier absorption before Demon absorption at the post-mitigation player damage boundary. The circuit subtracts vanilla absorption hearts before pricing the remaining health damage. Only a different living attacker qualifies; invulnerability-bypassing sources are excluded.
The effects isekaiexpansion:demon_energy_overload, isekaiexpansion:demon_residual_energy and isekaiexpansion:demon_ancient_blood_recovery are beneficial, milk-unclearable markers in the attack, defence and regeneration categories respectively. Their amplifiers do not own mechanics. Commands that apply a marker cannot open a circuit, create reserve or grant damage.
Ancient Blood also applies +0.5 with multiply_base to isekaiexpansion:energy_regen_speed through its Origins attribute power. It increases base natural regeneration by 50% without changing reserve accounting or adding a second regeneration tick loop.
Reclaim presentation
An accepted second press plays isekaiexpansion:skill_demon_energy_reclaim and the feet-bound one-shot isekaiexpansion:studio/demon-energy-reclaim/demon-energy-reclaim. The 14-tick (0.7-second) animation gathers inward; only its first 2 ticks (0.1 seconds) commit item use and attacks, while movement and jumping remain free. Recovery begins before presentation, so the animation does not delay energy return.
The Studio-authored effect uses Oni’s flame material in six inward currents. Its presentation contract is recorded with the native source in KTM Effek Studio.
| Presentation | Value |
|---|---|
| Raw scale / outer envelope | 1.0 / 6.4 blocks |
| Chest focus | Local Y 1.15 |
| Returning currents | Native frames 0–36 |
| Absorption beat | Native frames 17–24 |
| Last visible glow | Native frame 58 |
| Controller lifetime | 90 native frames |
| Size control | Dynamic input 1 |
Native frames run at 60 frames per second. The effect has no release trigger or recurring emitter. The second press uses isekaiexpansion:cast.buff_1; the opening press retains isekaiexpansion:fx.overload. These visual timings do not change the three-second energy recovery.
RetriggerableSkill reports the handler’s current follow-up phase independently of CooldownBypassSkill. The owner-only isekaiexpansion:skill_phase component derives both flags from live powers, refreshes after accepted activation and on server ticks, and synchronises only changes. It saves no phase data. SkillPhaseAPI exposes the read-only flags; the server handler remains the authority for activation. See origin icon assets for the optional _rt texture convention.
Auxiliary HUD rows
DemonHudSnapshot projects the synchronised state into immutable AuxiliaryHudGauge entries on the client thread. Reserve and committed recovery have separate stable IDs. Only a nonzero committed recovery adds a second row. During Overload, three charge dots show completed stages and fractional progress towards the next stage; this projection does not change the damage calculation.
AuxiliaryHudLayout shares placement with the item-progress bar and its item model. Frames are 44 × 8 GUI units at horizontal centre +69 and bottom −57. Visible item progress reserves the base slot; resource rows stack upwards at a 24-unit pitch. Without item progress, the first resource occupies the base slot. Each row reserves room for 4-unit dots above and a 5.5-unit label below; long labels shrink to the row width. Rows that would cross the top margin are omitted.
AuxiliaryHudAtlas samples assets/isekaiexpansion/textures/gui/extra_hud_bar.png in a logical 176 × 176 atlas, including when a resource pack supplies a higher-resolution image. The frame is (0, 0, 176, 24); the 128 × 8 cyan, violet and lime strips start at y=34, 46 and 58. The dot frame is (163, 33, 13, 13) with a 2-pixel inset. A centre slice of the selected strip fills its 9 × 9 aperture from the bottom, clipped to the fractional charge; the frame is drawn last. Demon rows use cyan.
PlayerHudAuxiliaryBars retains shaped labels and animation values by gauge ID on the UI thread. Rendering only reads immutable snapshots; it neither reads the live player nor reshapes text each frame.
Extending it
Keep transitions and conservation in DemonCirculationState. Add a runtime adapter at the payment or damage boundary when integrating another producer; never award reserve independently for targets, projectiles or formula followers.
The component owns ticking, persistence and projection. Rendering consumes its synchronised view. Keep race identity in Origins powers and spell legality in the spell runtime.
For another resource display, append an AuxiliaryHudGauge in ModuleHudSnapshot. Give each entry a unique stable ID, translated label, palette, normalised fill, dot count from 0 to 8 and fractional charge count. List order determines placement from the base upwards. Gameplay stays in the producer; the shared renderer owns atlas drawing, clipping and item-progress avoidance.
Verifying
Run ./gradlew.bat compileJava assembleLanguageFiles.
In game, check single-target and multi-target casts at equal cost, paid channel deliveries and prepaid formula followers. Verify Reclaim from the skill bar during cooldown, repeated presses, cooldown haste, shell consumption after barriers and absorption hearts, stage indicators, death, race changes and reconnects. Check base regeneration with and without Ancient Blood. At several GUI scales, toggle an item with progress while reserve or recovery is visible, inspect partially filled dots and switch languages. These integration and visual scenarios require a running game.