aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit ced54447676c9a2eb2eec628ef149ffe089bb6d6
parent 11ebad11cc5a719214368b2168c5562fa4a27efb
Author: anon <anon@example.com>
Date:   Mon,  2 Nov 2026 22:21:45 +0000

Apply ordinary healing-over-time nanos with durable tick progress

Diffstat:
MTODO.md | 10+++++++---
Mdocs/nano-healing.md | 64+++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
Aserver/browser_hot_test.go | 157+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/main.go | 6+++++-
Mserver/nano_buffs.go | 14+++++++++++++-
Mserver/nano_casting.go | 9+++++++--
Mserver/nano_healing.go | 58++++++++++++++++++++++++++++++++++++++++++++++++++--------
Aserver/nano_hot_catalog_test.go | 165+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aserver/nano_hot_test.go | 356+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/nano_learning.go | 2+-
Mserver/nano_periodic.go | 44+++++++++++++++++++++++++++++++++++++++++++-
Aserver/testdata/periodic-healing-nanos.json | 202+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools/client/test_healing_over_time.mjs | 100+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13 files changed, 1161 insertions(+), 26 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -1993,12 +1993,16 @@ introduction and starting-item gameplay remain open below. periodic HP Hit from passive HealDelta, and identify shared strains. The bounded group contains 40 programs/crystals: 18 Doctor, 11 Fixer short and 11 Fixer long. See [healing contracts](docs/nano-healing.md#periodic-healing-contracts). -- [ ] [P1] Apply one heal-over-time effect. Check: recovery ticks stop at expiration +- [x] Apply one heal-over-time effect. Check: recovery ticks stop at expiration and cancellation, clamp resources correctly and survive the appropriate - logout/restart policy. Resolve the shared incoming-weapon HP delivery - dependency; do not substitute idle-only healing. Cover friendly targets, + logout/restart policy. All 40 audited programs/crystals use shared contract + admission and combat-safe HP delivery. Checks cover friendly targets, shared short-HoT strain12, independent long-HoT strain255, real/visual profession and level criteria, replacement, death and atomic failed ticks. + Logout freezes remaining lifetime and tick phase; cold world login resumes + both. Two native observers verify recovery across a queued weapon impact. + Historical timing/lifecycle policies remain open above. See + [periodic healing](docs/nano-healing.md#periodic-heal-verification). - [x] Execute complete ordinary instant Hit plus TauntNPC programs. Check: independent full-record census admits exactly 27 programs and 27 crystals, including all 20 one-point taunts and seven nukes. Preserve signed amounts, diff --git a/docs/nano-healing.md b/docs/nano-healing.md @@ -1,11 +1,11 @@ -# Doctor startup and direct healing +# Direct and periodic healing Ordinary immediate HP heals now use the shared timed casting path. The complete reviewed group contains 85 programs and 85 individual crystals: 50 Doctor, 26 Adventurer, seven Martial Artist and two without a profession gate. Admission requires the whole unconditional selected-target HP Hit contract, including ordinary friendly flags, the attack dictionary and understood requirements. -Mixed effects, pet/script context, team effects and periodic heals remain separate. +Mixed effects, pet/script context and team effects remain outside this group. The QL 1 Doctor startup crystal 28778 uploads Improved Healing 28665. Upload uses the same atomic learned-program/consumption path as the other supported @@ -138,12 +138,29 @@ HP portion. Ten passive HealDelta programs were retained separately. Their stat343 modifiers are not periodic Hit effects. Bulk TESTITEM uploaders are also separate from the forty individual crystals. -The maintained client reconciliation also applies to HP snapshots during combat. -The current hostile periodic scheduler handles NPC damage and kill outcomes; -friendly healing must use living-player resource transactions and an explicit -timer/logout policy. It must not inherit NPC retaliation, damage credit or -death persistence just because it shares Hit metadata. No HoT casts were -enabled by this audit, including idle-only casts. +All forty ordinary programs and crystals now use the shared upload, casting, +NCU and strain paths. Complete descriptors select periodic healing without +program-ID branches. Doctor and Fixer short effects replace each other in +strain 12 according to their NCU strength; long Fixer strain 255 coexists. +Both original requirement expressions are retained. Real and visual profession +criteria still have the [existing false-profession limitation](nano-buffs.md). + +Friendly recovery uses living-player transactions, separate from hostile NPC +damage, threat and kill outcomes. Each inclusive heal roll clamps to maximum +HP. Due ticks commit HP and progress together before publishing the shared +combat-safe health snapshot; full-health ticks still consume their progress. +Cancellation, replacement and recipient death discard the old sequence. +An unavailable caster does not stop an already applied effect on a living +recipient. + +Timing retains the explicit reconstruction policy used for other periodic nanos: +first tick after one interval, chronological catch-up of overdue ticks, and a +fresh phase on refresh. The last tick runs at the lifetime boundary before +expiration. Recipient logout freezes both remaining duration and the partial +tick interval. Checkpoints retain pending overdue ticks; cold-loaded player +effects stay paused until world login resumes their deadlines. Offline time +does not earn recovery. Original-server tick phase, downtime and caster lifecycle +rules remain an open historical question in TODO.md. Complete records, exact payloads, source hashes, the forty-program fixture and an independent verifier are under `local/nano-hot-research/catalog/`. The @@ -204,4 +221,33 @@ AO_GAME_TEST=1 go test ./server -run '^TestBrowserImprovedHealingQueuedHit$' -co Original-server heal distribution, cross-faction/PvP permissions, interruption rolls and charging/refund timing are not established by this implementation. -Periodic healing retains its separate scheduling and persistence work above. +Periodic healing uses the separate recovery scheduler described above. + +## Periodic-heal verification + +The independent verifier reparses 413 retained original resources and reproduces +the checked-in forty-program fixture exactly. A complete catalog census admits +exactly those forty programs and forty crystals; the existing 85 direct-heal +contracts remain admitted. Mixed/team effects and passive HealDelta are excluded. + +Go checks exercise all forty uploads, original criteria and strict thresholds, +first ticks, full sequences, clamping, expiry and cold persistence. Focused checks +cover friendly recipients, shared short and independent long strains, refresh, +weaker replacement refusal, NCU revalidation/refund, cancellation, recipient death, +an unavailable caster, paused partial intervals and world-login resumption. +Failed/ignored HP or progress writes and failed COMMIT publish no recovery; +retry and concurrent visitors consume each tick once. + +`TestBrowserHealingOverTimeQueuedHit` loads two controlled level 10 Fixers and +uploads original Basic Insurance Hack crystal 85273 through real browser input. +One production Leet swing is scheduled just before the first five-second tick. +Both native clients must show the authoritative recovered HP while that result +is queued and retain it after impact. The test checks one genuine weapon result, +unchanged enemy deadlines, the complete duration 20000 cs installation, cost 84, +39 remaining ticks and a durable paused interval after disconnect. This is a +controlled fixture, not earned progression. Evidence is in `local/nano-hot/`. + +```sh +go test ./server -run '^TestHealingOverTime' -count=1 +AO_GAME_TEST=1 go test ./server -run '^TestBrowserHealingOverTimeQueuedHit$' -count=1 -timeout=5m -v +``` diff --git a/server/browser_hot_test.go b/server/browser_hot_test.go @@ -0,0 +1,157 @@ +package main + +import ( + "context" + "crypto/sha256" + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" + "os" + "os/exec" + "path/filepath" + "runtime" + "testing" + "time" +) + +func TestBrowserHealingOverTimeQueuedHit(t *testing.T) { + if os.Getenv("AO_GAME_TEST") != "1" { + t.Skip("set AO_GAME_TEST=1 for the focused native periodic healing check") + } + _, source, _, _ := runtime.Caller(0) + root := filepath.Dir(filepath.Dir(source)) + output := filepath.Join(root, "local/nano-hot", time.Now().Format("20060102-150405")) + world := newTestServer(t) + world.combatRoll = landedCombatRoll + var enemy *character + for _, actor := range world.characters { + if actor.npc && actor.playfield == 950 && actor.monsterData == 17655 && actor.level == 1 && actor.combatProfile != nil && (enemy == nil || actor.id < enemy.id) { + enemy = actor + } + } + if enemy == nil { + t.Fatal("no controlled level-one Leet") + } + players := []*character{} + for index := 0; index < 2; index++ { + player := world.newCharacter() + player.name, player.level, player.profession = fmt.Sprint("PeriodicHealing", index), 10, 4 + player.stats = testCharacterStats() + player.stats.Body.BodyDevelopment = 55 + player.stats.NanoAiding.BiologicalMetamorphosis, player.stats.NanoAiding.MatterMetamorphosis = 19, 24 + player.stats.NanoAiding.TimeAndSpace = 19 + player.stats.Body.NanoPool = 100 + player.position, player.rotation = enemy.position, [4]float32{0, 0, 0, 1} + player.position[2] -= float32(2 + index*3) + player.health, player.nano = 200, 200 + player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte(fmt.Sprint("hot-", index)))) + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + players = append(players, player) + } + if granted, err := world.grantItem_locked(players[0], 85273); err != nil || !granted { + t.Fatal(granted, err) + } + mux := http.NewServeMux() + mux.Handle("/", world.httpHandler()) + mux.HandleFunc("GET /test-state", func(w http.ResponseWriter, r *http.Request) { + world.mutex.Lock() + defer world.mutex.Unlock() + var cast any + if client := world.clients[players[0].id]; client != nil && client.nanoCast != nil { + cast = map[string]any{"readyAt": client.nanoCast.readyAt} + } + var effects []map[string]any + for _, effect := range players[0].activeNanos { + effects = append(effects, map[string]any{"program": effect.program, "ticks": effect.ticksLeft, "nextTick": effect.nextTick}) + } + json.NewEncoder(w).Encode(map[string]any{"owner": players[0].id, "observer": players[1].id, "enemy": enemy.id, + "health": players[0].health, "nano": players[0].nano, "reserved": players[0].nanoReserved, "cast": cast, + "recharge": players[0].nanoRechargeUntil, "effects": effects, "inventory": players[0].inventory, + "fighting": enemy.fighting, "nextAttack": enemy.nextAttack, "weaponRecharge": enemy.rechargeUntil}) + }) + // One controlled production swing near the first healing tick isolates queued-hit reconciliation. + mux.HandleFunc("POST /test-attack", func(w http.ResponseWriter, r *http.Request) { + world.updateMutex.Lock() + world.mutex.Lock() + updates := make(map[*worldClient][][]byte) + world.startAttack_locked(enemy, players[0], time.Now(), updates) + deadline := enemy.nextAttack + world.mutex.Unlock() + world.sendCombatUpdates(updates) + world.updateMutex.Unlock() + world.advanceCombat(deadline) + w.WriteHeader(http.StatusNoContent) + }) + host := httptest.NewServer(mux) + defer host.Close() + closeTestBrowserStreams(t, world) + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) + defer cancel() + stopped := make(chan struct{}) + go func() { + defer close(stopped) + ticker := time.NewTicker(20 * time.Millisecond) + defer ticker.Stop() + for { + select { + case now := <-ticker.C: + world.advanceNanos(now) + // Isolate one recovery tick while the original weapon feedback settles. + world.mutex.Lock() + ticked := len(players[0].activeNanos) == 1 && players[0].activeNanos[0].ticksLeft == 39 + world.mutex.Unlock() + if ticked { + return + } + case <-ctx.Done(): + return + } + } + }() + defer func() { cancel(); <-stopped }() + + command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_healing_over_time.mjs"), host.URL, output) + command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr + err := command.Run() + cancel() + <-stopped + t.Logf("Browser artifacts: %s", output) + + if err != nil { + t.Fatal(err) + } + // End resumable test streams before checking the world's durable logout state. + world.mutex.Lock() + streams := make([]*browserStream, 0, len(world.browserStreams)) + for _, stream := range world.browserStreams { + streams = append(streams, stream) + } + world.mutex.Unlock() + for _, stream := range streams { + stream.close() + } + deadline := time.Now().Add(5 * time.Second) + for { + world.mutex.Lock() + disconnected := world.clients[players[0].id] == nil + world.mutex.Unlock() + if disconnected { + break + } + if time.Now().After(deadline) { + t.Fatal("HoT owner did not finish disconnecting") + } + time.Sleep(time.Millisecond) + } + cold := newTestInventoryServer(t).characters[players[0].id] + world.mutex.Lock() + defer world.mutex.Unlock() + if cold.health != players[0].health || cold.nano != 116 || cold.nanoReserved != 0 || !cold.nanoRechargeUntil.Equal(players[0].nanoRechargeUntil) || + len(cold.activeNanos) != 1 || cold.activeNanos[0].ticksLeft != 39 || !cold.activeNanos[0].nextTick.IsZero() || + cold.activeNanos[0].tickDelay != players[0].activeNanos[0].tickDelay { + t.Fatal("native HoT lost committed health, cost, progress or its paused interval") + } +} diff --git a/server/main.go b/server/main.go @@ -357,9 +357,13 @@ func (server *server) serveWorldClient(client *worldClient) error { character.movement = playerMovement{} character.body = playerCollisionBody{} server.clients[character.id] = client + now := time.Now() for index := range character.activeNanos { if character.activeNanos[index].expiresAt.IsZero() { - character.activeNanos[index].expiresAt = time.Now().Add(character.activeNanos[index].remaining) + character.activeNanos[index].expiresAt = now.Add(character.activeNanos[index].remaining) + if character.activeNanos[index].ticksLeft != 0 { + character.activeNanos[index].nextTick = now.Add(character.activeNanos[index].tickDelay) + } } } character.sitting = false diff --git a/server/nano_buffs.go b/server/nano_buffs.go @@ -18,6 +18,7 @@ type activeNano struct { expiresAt time.Time ticksLeft uint32 nextTick time.Time + tickDelay time.Duration } func statBuffNano(program uint32) bool { @@ -181,6 +182,9 @@ func (effect activeNano) tickDelayAt(now time.Time) time.Duration { if effect.ticksLeft == 0 { return 0 } + if effect.nextTick.IsZero() { + return effect.tickDelay + } return effect.nextTick.Sub(now) } @@ -315,7 +319,8 @@ func (server *server) loadActiveNanos() error { return err } periodic := damageOverTimeNano(effect.program) - if !statBuffNano(effect.program) && !initiativeDebuffNano(effect.program) && controlNano(effect.program) == nil && periodic == nil || effect.remaining < 0 || server.characters[id] == nil { + healing := healingOverTimeNano(effect.program) + if !statBuffNano(effect.program) && !initiativeDebuffNano(effect.program) && controlNano(effect.program) == nil && periodic == nil && healing == nil || effect.remaining < 0 || server.characters[id] == nil { return fmt.Errorf("character %d has an unsupported active nano %d", id, effect.program) } if periodic != nil { @@ -325,6 +330,11 @@ func (server *server) loadActiveNanos() error { if effect.ticksLeft != 0 { effect.nextTick = now.Add(delay) } + } else if healing != nil { + if server.characters[id].npc || server.characters[effect.caster] == nil || effect.ticksLeft > healing.TickCount { + return fmt.Errorf("character %d has invalid healing nano %d", id, effect.program) + } + effect.tickDelay = delay } else if effect.ticksLeft != 0 || delay != 0 { return fmt.Errorf("character %d has unexpected nano tick state", id) } @@ -425,6 +435,8 @@ func (server *server) pauseActiveNanos_locked(player *character, now time.Time) for index := range player.activeNanos { player.activeNanos[index].remaining = player.activeNanos[index].remainingAt(now) player.activeNanos[index].expiresAt = time.Time{} + player.activeNanos[index].tickDelay = player.activeNanos[index].tickDelayAt(now) + player.activeNanos[index].nextTick = time.Time{} } return server.saveActiveNanos_locked(player, now) } diff --git a/server/nano_casting.go b/server/nano_casting.go @@ -85,7 +85,7 @@ func (player *character) nanoCastDelay(program uint32) time.Duration { } func (player *character) nanoRequirementsMet(program uint32) bool { - return (directDamageNano(program) != nil || directHealingNano(program) != nil || damageOverTimeNano(program) != nil || controlNano(program) != nil || statBuffNano(program)) && player.templateUseRequirementsMet(gamedata.NanoTemplates[program]) + return (directDamageNano(program) != nil || directHealingNano(program) != nil || healingOverTimeNano(program) != nil || damageOverTimeNano(program) != nil || controlNano(program) != nil || statBuffNano(program)) && player.templateUseRequirementsMet(gamedata.NanoTemplates[program]) } func (server *server) nanoTarget_locked(player, target *character, client *worldClient, program uint32, now time.Time) bool { @@ -240,6 +240,7 @@ func (server *server) advanceNanos(now time.Time) { server.mutex.Lock() updates := make(map[*worldClient][][]byte) server.advancePeriodicNanos_locked(now, updates) + server.advanceHealingNanos_locked(now, updates) server.advanceNanoBuffs_locked(now, updates) for id, client := range server.clients { if client.nanoCast == nil || !now.After(client.nanoCast.readyAt) { @@ -301,7 +302,11 @@ func (server *server) advanceNanos(now time.Time) { }) duration := time.Duration(nanoStat(effectProgram, 8)) * 10 * time.Millisecond effect := activeNano{program: effectProgram, caster: player.id, remaining: duration, expiresAt: now.Add(duration)} - if periodic := damageOverTimeNano(effectProgram); periodic != nil { + periodic := damageOverTimeNano(effectProgram) + if periodic == nil { + periodic = healingOverTimeNano(effectProgram) + } + if periodic != nil { effect.ticksLeft = periodic.TickCount effect.nextTick = now.Add(time.Duration(periodic.TickInterval) * 10 * time.Millisecond) } diff --git a/server/nano_healing.go b/server/nano_healing.go @@ -1,12 +1,34 @@ package main -import "ao/server/gamedata" +import ( + "ao/server/gamedata" + "slices" +) func directHealingNano(program uint32) *gamedata.ItemFunction { + return healingHitNano(program, false) +} + +func healingOverTimeNano(program uint32) *gamedata.ItemFunction { + return healingHitNano(program, true) +} + +func healingHitNano(program uint32, periodic bool) *gamedata.ItemFunction { definition := gamedata.NanoTemplates[program] if definition == nil || definition.RecordType != 1040005 || definition.HeaderWords[0] != 51051 || definition.Undecoded != nil || - (itemStat(definition, 0) != 0x80000002 && itemStat(definition, 0) != 2) || itemStat(definition, 30) != 0 || itemStat(definition, 76) != 0 || - itemStat(definition, 405) != 2 || itemStat(definition, 8) != 0 || len(definition.Sections) != 4 { + itemStat(definition, 30) != 0 || itemStat(definition, 76) != 0 || itemStat(definition, 405) != 2 || len(definition.Sections) != 4 { + return nil + } + if periodic { + if flags := itemStat(definition, 0); flags != 0x10002 && flags != 0x80010002 { + return nil + } + for _, stat := range []uint32{8, 54, 75} { + if value := itemStat(definition, stat); value == 0 || value >= 0x80000000 { + return nil + } + } + } else if (itemStat(definition, 0) != 0x80000002 && itemStat(definition, 0) != 2) || itemStat(definition, 8) != 0 { return nil } for _, stat := range []uint32{210, 287, 294, 407} { @@ -15,13 +37,26 @@ func directHealingNano(program uint32) *gamedata.ItemFunction { } } - // Ordinary direct heals have one attack-rating dictionary and no defense roll. + // Ordinary heals have an attack rating and at most an authored zero defense. weights, defaults := definition.Sections[0], definition.Sections[1] - if weights.Type != 4 || weights.Subtype != 4 || weights.Entries == nil || len(*weights.Entries) != 1 || - defaults.Type != 6 || defaults.Subtype != 27 || defaults.Stats == nil || len(*defaults.Stats) != 1 || (*defaults.Stats)[0] != [2]uint32{12, 0} { + if weights.Type != 4 || weights.Subtype != 4 || weights.Entries == nil || len(*weights.Entries) < 1 || len(*weights.Entries) > 2 || + defaults.Type != 6 || defaults.Subtype != 27 || defaults.Stats == nil { return nil } attack := (*weights.Entries)[0] + if len(*weights.Entries) == 2 { + defense := (*weights.Entries)[1] + if attack.Type != nil && *attack.Type == 13 { + attack, defense = defense, attack + } + if !periodic || defense.Type == nil || *defense.Type != 13 || defense.Stats == nil || !slices.Equal(*defense.Stats, [][2]uint32{{168, 0}}) { + return nil + } + } + if !slices.Equal(*defaults.Stats, [][2]uint32{{12, 0}}) && + (!periodic || !slices.Equal(*defaults.Stats, [][2]uint32{{12, 0}, {13, 0}})) { + return nil + } if attack.Type == nil || *attack.Type != 12 || attack.Stats == nil { return nil } @@ -36,7 +71,7 @@ func directHealingNano(program uint32) *gamedata.ItemFunction { return nil } - // Admit the complete immediate selected-target HP contract, not a partial effect. + // Admit the complete selected-target HP contract, not a partial effect. effects, requirements := definition.Sections[2], definition.Sections[3] if effects.Type != 2 || effects.Subtype != 0 || effects.Functions == nil || len(*effects.Functions) != 1 || requirements.Type != 22 || requirements.Subtype != 36 || requirements.Actions == nil || len(*requirements.Actions) != 1 || (*requirements.Actions)[0].Type != 3 { @@ -53,7 +88,14 @@ func directHealingNano(program uint32) *gamedata.ItemFunction { } hit := &(*effects.Functions)[0] if hit.ID != 53002 || hit.HeaderWords != [2]uint32{0, 4} || hit.ArgumentHeader != 9 || hit.Target != 3 || - len(hit.Requirements) != 0 || hit.TickCount != 1 || hit.TickInterval != 0 || len(hit.Arguments) != 4 { + len(hit.Requirements) != 0 || len(hit.Arguments) != 4 { + return nil + } + if periodic { + if hit.TickCount < 2 || hit.TickInterval == 0 || uint64(hit.TickCount)*uint64(hit.TickInterval) != uint64(itemStat(definition, 8)) { + return nil + } + } else if hit.TickCount != 1 || hit.TickInterval != 0 { return nil } for _, argument := range hit.Arguments { diff --git a/server/nano_hot_catalog_test.go b/server/nano_hot_catalog_test.go @@ -0,0 +1,165 @@ +package main + +import ( + "ao/server/gamedata" + _ "embed" + "encoding/json" + "fmt" + "reflect" + "slices" + "testing" + "time" +) + +//go:embed testdata/periodic-healing-nanos.json +var healingOverTimeData []byte + +type healingOverTimeFixture struct { + Program, Crystal, Quality, Minimum, Maximum uint32 + TickCount uint32 `json:"tick_count"` + TickInterval uint32 `json:"tick_interval"` + Duration, NCU, Strain uint32 + NanoCost uint32 `json:"nano_cost"` + AttackDelay uint32 `json:"attack_delay"` + RechargeDelay uint32 `json:"recharge_delay"` + Range uint32 + Requirements []gamedata.ItemRequirement + UploaderRequirements []gamedata.ItemRequirement `json:"uploader_requirements"` + AttackWeights []gamedata.ItemEntry `json:"attack_weights"` + ModeMap [][2]uint32 `json:"mode_map"` +} + +func healingOverTimeFixtures(t *testing.T) []healingOverTimeFixture { + t.Helper() + var fixtures []healingOverTimeFixture + if err := json.Unmarshal(healingOverTimeData, &fixtures); err != nil { + t.Fatal(err) + } + return fixtures +} + +func newHealingOverTimeWorld(t *testing.T, fixture healingOverTimeFixture) (*server, *combatTestConn) { + t.Helper() + world, conn := newNanoCastingWorld(t) + player := world.characters[1] + player.level = 200 + for _, requirement := range fixture.Requirements { + if requirement.Stat == 60 || requirement.Stat == 368 { + player.profession = uint16(requirement.Value) + } + } + for _, field := range player.stats.trainingStats() { + *field.value = 2000 + } + player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1} + player.stats.Speed.NanoInitiative, player.stats.Body.NanoPool = 5, 30000 + player.health, player.nano, player.inventory.LearnedNanos = 1, 50000, nil + // Two original deck memories provide enough NCU for the highest audited HoT. + player.inventory.Items = []ownedItem{ + {ID: 1, Type: 51022, Template: 36782, Quality: 20, Slot: 7, Count: 1}, + {ID: 2, Type: 51022, Template: 36781, Quality: 120, Slot: 9, Count: 1}, + {ID: 3, Type: 51022, Template: 36781, Quality: 120, Slot: 10, Count: 1}, + } + player.inventory.LastID, world.nextItem = 3, 3 + for _, item := range player.inventory.Items { + if !item.fitsEquipmentSlot(item.Slot) { + t.Fatal("invalid HoT fixture equipment", item) + } + } + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if granted, err := world.grantItem_locked(player, fixture.Crystal); err != nil || !granted { + t.Fatal(granted, err) + } + return world, conn +} + +func TestHealingOverTimeCatalogMatchesCompleteOriginalContracts(t *testing.T) { + fixtures := healingOverTimeFixtures(t) + var expected, expectedCrystals, programs, crystals []uint32 + for _, fixture := range fixtures { + expected = append(expected, fixture.Program) + expectedCrystals = append(expectedCrystals, fixture.Crystal) + } + + for program := range gamedata.NanoTemplates { + if healingOverTimeNano(program) != nil { + programs = append(programs, program) + } + } + for crystal := range gamedata.ItemTemplates { + if healingOverTimeNano(nanoCrystalProgram(crystal)) != nil { + crystals = append(crystals, crystal) + } + } + for _, values := range [][]uint32{expected, expectedCrystals, programs, crystals} { + slices.Sort(values) + } + + if len(programs) != 40 || !slices.Equal(programs, expected) || !slices.Equal(crystals, expectedCrystals) { + t.Fatalf("ordinary HoT census differs: programs=%v crystals=%v", programs, crystals) + } + for _, fixture := range fixtures { + definition := gamedata.NanoTemplates[fixture.Program] + hit := healingOverTimeNano(fixture.Program) + if uint32(*hit.Arguments[1].Integer) != fixture.Minimum || uint32(*hit.Arguments[2].Integer) != fixture.Maximum || + hit.TickCount != fixture.TickCount || hit.TickInterval != fixture.TickInterval || + nanoStat(fixture.Program, 8) != fixture.Duration || nanoStat(fixture.Program, 54) != fixture.NCU || nanoStat(fixture.Program, 75) != fixture.Strain || + nanoStat(fixture.Program, 407) != fixture.NanoCost || nanoStat(fixture.Program, 294) != fixture.AttackDelay || + nanoStat(fixture.Program, 210) != fixture.RechargeDelay || nanoStat(fixture.Program, 287) != fixture.Range || + !slices.Equal((*definition.Sections[3].Actions)[0].Requirements, fixture.Requirements) || + !slices.Equal(*definition.Sections[1].Stats, fixture.ModeMap) { + t.Fatal("original HoT contract changed", fixture.Program) + } + if !reflect.DeepEqual(*definition.Sections[0].Entries, fixture.AttackWeights) { + t.Fatal("HoT attack weights changed", fixture.Program) + } + for _, section := range gamedata.ItemTemplates[fixture.Crystal].Sections { + if section.Actions != nil && !slices.Equal((*section.Actions)[0].Requirements, fixture.UploaderRequirements) { + t.Fatal("HoT uploader requirements changed", fixture.Crystal) + } + } + } +} + +func TestHealingOverTimeCrystalsLearnTickClampAndExpire(t *testing.T) { + for _, fixture := range healingOverTimeFixtures(t) { + t.Run(fmt.Sprint(fixture.Program), func(t *testing.T) { + world, _ := newHealingOverTimeWorld(t, fixture) + player, client := world.characters[1], world.clients[1] + if player.inventory.Items[3].Quality != fixture.Quality { + t.Fatal("HoT crystal quality changed") + } + + if err := world.handleOwnedItemUse(client, backpackUseRequest(1, 64, 1)[20:]); err != nil { + t.Fatal(err) + } + if !slices.Equal(player.inventory.LearnedNanos, []uint32{fixture.Program}) || len(player.inventory.Items) != 3 { + t.Fatal("HoT crystal was not consumed and learned once") + } + at := castTestBuff(t, world, 1, 1, fixture.Program) + if player.health != 1 || player.usedNCU() != fixture.NCU || player.nano != 50001-fixture.NanoCost { + t.Fatal("HoT changed HP immediately, lost NCU or charged the wrong cost") + } + world.advanceNanos(at.Add(time.Duration(fixture.TickInterval) * 10 * time.Millisecond)) + cold := newTestInventoryServer(t).characters[1] + if player.health < 1+fixture.Minimum || player.health > 1+fixture.Maximum || cold.health != player.health || + len(cold.activeNanos) != 1 || cold.activeNanos[0].ticksLeft != fixture.TickCount-1 { + t.Fatal("first HoT tick did not commit HP and progress") + } + player.health = player.maximumHealth() - 1 + world.advanceNanos(at.Add(time.Duration(fixture.Duration)*10*time.Millisecond - time.Nanosecond)) + if player.health != player.maximumHealth() || player.activeNanos[0].ticksLeft != 1 { + t.Fatal("overdue HoT ticks failed to clamp or expired before their last tick") + } + world.advanceNanos(at.Add(time.Duration(fixture.Duration) * 10 * time.Millisecond)) + world.advanceNanos(at.Add(24 * time.Hour)) + cold = newTestInventoryServer(t).characters[1] + + if len(player.activeNanos) != 0 || len(cold.activeNanos) != 0 || player.usedNCU() != 0 || cold.health != player.maximumHealth() || cold.nano != player.nano { + t.Fatal("expired HoT retained ticks, NCU or lost clamped HP") + } + }) + } +} diff --git a/server/nano_hot_test.go b/server/nano_hot_test.go @@ -0,0 +1,356 @@ +package main + +import ( + "encoding/binary" + "fmt" + "net" + "slices" + "sync" + "testing" + "time" +) + +func TestHealingOverTimeCrystalSchedulesFirstTick(t *testing.T) { + world, _ := newNanoCastingWorld(t) + player, client := world.characters[1], world.clients[1] + player.profession, player.level = 4, 10 + player.stats.NanoAiding.BiologicalMetamorphosis = 19 + player.stats.NanoAiding.MatterMetamorphosis = 24 + player.stats.NanoAiding.TimeAndSpace = 19 + player.stats.Body.NanoPool = 100 + player.health, player.nano, player.inventory.LearnedNanos = 1, 200, nil + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if granted, err := world.grantItem_locked(player, 85273); err != nil || !granted { + t.Fatal(granted, err) + } + + if err := world.handleOwnedItemUse(client, backpackUseRequest(1, 64, 1)[20:]); err != nil { + t.Fatal(err) + } + if !slices.Equal(player.inventory.LearnedNanos, []uint32{85215}) { + t.Fatal("Basic Insurance Hack crystal was not learned") + } + if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, 1, 53019, 85215})[20:]); err != nil || client.nanoCast == nil { + t.Fatal("Basic Insurance Hack was not admitted", err) + } + completed := client.nanoCast.readyAt.Add(time.Nanosecond) + world.advanceNanos(completed) + if player.health != 1 || len(player.activeNanos) != 1 || player.activeNanos[0].ticksLeft != 40 { + t.Fatal("HoT applied immediate healing or omitted its tick sequence") + } + world.advanceNanos(completed.Add(5*time.Second - time.Nanosecond)) + if player.health != 1 { + t.Fatal("HoT healed before its first interval") + } + world.advanceNanos(completed.Add(5 * time.Second)) + cold := newTestInventoryServer(t).characters[1] + + if player.health < 3 || player.health > 7 || player.nano != 116 || player.usedNCU() != 1 || + player.activeNanos[0].ticksLeft != 39 || cold.health != player.health || len(cold.activeNanos) != 1 || cold.activeNanos[0].ticksLeft != 39 { + t.Fatalf("HoT tick did not commit HP and progress: health=%d nano=%d effects=%+v", player.health, player.nano, player.activeNanos) + } +} + +func TestHealingOverTimeFailedTickRollsBackAndRetries(t *testing.T) { + for _, failure := range []string{"health", "ignored health", "ticks", "ignored ticks", "commit"} { + t.Run(failure, func(t *testing.T) { + world, conn := newHealingOverTimeWorld(t, healingOverTimeFixtures(t)[0]) + player := world.characters[1] + player.profession = 4 + player.inventory.LearnedNanos = []uint32{85215} + player.health = player.maximumHealth() - 1 + if err := world.savePosition_locked(player); err != nil { + t.Fatal(err) + } + at := castTestBuff(t, world, 1, 1, 85215).Add(5 * time.Second) + statement := "CREATE TRIGGER fail_hot BEFORE UPDATE OF health ON characters BEGIN SELECT RAISE(FAIL, 'test HoT'); END" + switch failure { + case "ignored health": + statement = "CREATE TRIGGER fail_hot BEFORE UPDATE OF health ON characters BEGIN SELECT RAISE(IGNORE); END" + case "ticks": + statement = "CREATE TRIGGER fail_hot BEFORE UPDATE ON active_nanos BEGIN SELECT RAISE(FAIL, 'test HoT'); END" + case "ignored ticks": + statement = "CREATE TRIGGER fail_hot BEFORE UPDATE ON active_nanos BEGIN SELECT RAISE(IGNORE); END" + case "commit": + statement = "CREATE TABLE invalid_hot (id INTEGER REFERENCES players(id) DEFERRABLE INITIALLY DEFERRED); CREATE TRIGGER fail_hot AFTER UPDATE OF health ON characters BEGIN INSERT INTO invalid_hot VALUES (999999); END" + } + if _, err := world.db.Exec(statement); err != nil { + t.Fatal(err) + } + conn.packets = nil + + world.advanceNanos(at) + cold := newTestInventoryServer(t).characters[1] + + if player.health != player.maximumHealth()-1 || cold.health != player.health || + player.activeNanos[0].ticksLeft != 40 || cold.activeNanos[0].ticksLeft != 40 || len(conn.packets) != 0 { + t.Fatal("failed HoT tick published HP or consumed progress") + } + if _, err := world.db.Exec("DROP TRIGGER fail_hot"); err != nil { + t.Fatal(err) + } + var visitors sync.WaitGroup + for range 8 { + visitors.Add(1) + go func() { defer visitors.Done(); world.advanceNanos(at) }() + } + visitors.Wait() + cold = newTestInventoryServer(t).characters[1] + if player.health != player.maximumHealth() || cold.health != player.health || player.activeNanos[0].ticksLeft != 39 || cold.activeNanos[0].ticksLeft != 39 || len(conn.packets) != 1 { + t.Fatal("retry or concurrent visitors duplicated a tick or lost its clamped HP") + } + }) + } +} + +func TestHealingOverTimeFriendlyStrainsReplaceCancelAndStopOnDeath(t *testing.T) { + world, _ := newHealingOverTimeWorld(t, healingOverTimeFixtures(t)[0]) + player := world.characters[1] + player.profession = 4 + player.inventory.LearnedNanos = []uint32{85215, 162714, 42401} + patient := *player + patient.id, patient.name, patient.inventory = 2, "HoT Patient", playerInventory{} + patient.health, patient.nano = 1, 100 + world.characters[2], world.nextCharacter = &patient, 2 + world.clients[2] = &worldClient{id: 2, conn: &combatTestConn{}, ready: true, target: true, npcs: map[uint32]bool{1000000: true}} + if err := world.saveUser_locked(&patient); err != nil { + t.Fatal(err) + } + + if err := world.handleNanoCast(world.clients[1], characterActionPacket(1, [5]uint32{19, 50000, 1000000, 53019, 85215})[20:]); err != nil || world.clients[1].nanoCast != nil || player.nano != 50000 { + t.Fatal("friendly HoT targeted an NPC or consumed nano", err) + } + at := castTestBuff(t, world, 1, 2, 85215) + player.nanoRechargeUntil = time.Time{} + if err := world.handleNanoCast(world.clients[1], characterActionPacket(1, [5]uint32{19, 50000, 2, 53019, 162714})[20:]); err != nil || world.clients[1].nanoCast == nil { + t.Fatal("independent long HoT rejected", err) + } + world.clients[1].nanoCast.readyAt = at.Add(time.Second - time.Nanosecond) + world.advanceNanos(at.Add(time.Second)) + if len(patient.activeNanos) != 2 || patient.usedNCU() != 3 || len(player.activeNanos) != 0 { + t.Fatal("short and long HoT strains did not coexist on their recipient") + } + player.nanoRechargeUntil, player.profession = time.Time{}, 10 + if err := world.handleNanoCast(world.clients[1], characterActionPacket(1, [5]uint32{19, 50000, 2, 53019, 42401})[20:]); err != nil || world.clients[1].nanoCast == nil { + t.Fatal("Doctor short HoT rejected", err) + } + world.clients[1].nanoCast.readyAt = at.Add(2*time.Second - time.Nanosecond) + at = at.Add(2 * time.Second) + world.advanceNanos(at) + if len(patient.activeNanos) != 2 || slices.ContainsFunc(patient.activeNanos, func(effect activeNano) bool { return effect.program == 85215 }) { + t.Fatal("Doctor short HoT did not replace the Fixer short strain") + } + player.profession, player.nanoRechargeUntil = 4, time.Time{} + nano := player.nano + if err := world.handleNanoCast(world.clients[1], characterActionPacket(1, [5]uint32{19, 50000, 2, 53019, 85215})[20:]); err != nil || world.clients[1].nanoCast != nil || player.nano != nano { + t.Fatal("weaker short HoT replaced the Doctor effect or consumed nano", err) + } + world.advanceNanos(at.Add(10 * time.Second)) + if patient.health < 36 || patient.health > 61 || patient.nano != 100 || patient.fighting != 0 { + t.Fatal("friendly recovery lost a strain, changed nano or started combat", patient.health) + } + if err := world.handleNanoRemoval(world.clients[2], characterActionPacket(2, [5]uint32{65, 0, 0, 53019, 42401})[20:]); err != nil { + t.Fatal(err) + } + if len(patient.activeNanos) != 1 || patient.activeNanos[0].program != 162714 { + t.Fatal("cancellation removed the independent strain") + } + if err := world.handleNanoRemoval(world.clients[2], characterActionPacket(2, [5]uint32{65, 0, 0, 53019, 162714})[20:]); err != nil { + t.Fatal(err) + } + health := patient.health + world.advanceNanos(at.Add(time.Hour)) + if patient.health != health || len(newTestInventoryServer(t).characters[2].activeNanos) != 0 { + t.Fatal("cancelled HoTs retained a delayed result") + } + player.profession, player.nanoRechargeUntil = 4, time.Time{} + castTestBuff(t, world, 1, 2, 85215) + npc := world.characters[1000000] + npc.stats.Body.MartialArts = 2000 + patient.health = 1 + world.startAttack_locked(npc, &patient, time.Now(), make(map[*worldClient][][]byte)) + world.advanceCombat(npc.nextAttack) + world.advanceNanos(at.Add(2 * time.Hour)) + + if patient.health != 0 || len(patient.activeNanos) != 0 || len(newTestInventoryServer(t).characters[2].activeNanos) != 0 { + t.Fatal("death left recovery ticks or resurrected the recipient") + } +} + +func TestHealingOverTimeCompletionRechecksNCUAndRefunds(t *testing.T) { + world, _ := newHealingOverTimeWorld(t, healingOverTimeFixtures(t)[0]) + player, client := world.characters[1], world.clients[1] + player.profession, player.inventory.LearnedNanos = 4, []uint32{85215} + player.inventory.Items = nil + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, 1, 53019, 85215})[20:]); err != nil || client.nanoCast == nil { + t.Fatal("HoT admission failed", err) + } + at := client.nanoCast.readyAt.Add(time.Nanosecond) + player.activeNanos = []activeNano{ + {program: 26342, caster: 1, expiresAt: at.Add(time.Minute)}, + {program: 27086, caster: 1, expiresAt: at.Add(time.Minute)}, + {program: 26360, caster: 1, expiresAt: at.Add(time.Minute)}, + } + if err := world.saveActiveNanos_locked(player, at); err != nil { + t.Fatal(err) + } + + world.advanceNanos(at) + if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, 1, 53019, 85215})[20:]); err != nil || client.nanoCast != nil { + t.Fatal("full NCU admitted a new HoT", err) + } + cold := newTestInventoryServer(t).characters[1] + + if player.nano != 50000 || cold.nano != 50000 || player.nanoReserved != 0 || client.nanoCast != nil || + !player.nanoRechargeUntil.IsZero() || len(player.activeNanos) != 3 || len(cold.activeNanos) != 3 || player.health != 1 { + t.Fatal("completion bypassed NCU or lost its refund") + } +} + +func TestHealingOverTimeSurvivesUnavailableCaster(t *testing.T) { + world, _ := newHealingOverTimeWorld(t, healingOverTimeFixtures(t)[0]) + player := world.characters[1] + player.profession, player.inventory.LearnedNanos = 4, []uint32{85215} + patient := *player + patient.id, patient.name, patient.inventory = 2, "HoT Recipient", playerInventory{} + world.characters[2], world.nextCharacter = &patient, 2 + world.clients[2] = &worldClient{id: 2, conn: &combatTestConn{}, ready: true, target: true} + if err := world.saveUser_locked(&patient); err != nil { + t.Fatal(err) + } + at := castTestBuff(t, world, 1, 2, 85215) + player.health = 0 + delete(world.clients, 1) + + world.advanceNanos(at.Add(5 * time.Second)) + cold := newTestInventoryServer(t).characters[2] + + if patient.health < 3 || patient.health > 7 || cold.health != patient.health || patient.activeNanos[0].ticksLeft != 39 || cold.activeNanos[0].ticksLeft != 39 { + t.Fatal("unavailable caster stopped the living recipient's recovery") + } +} + +func TestHealingOverTimeRefreshRestartsItsOwnPhase(t *testing.T) { + world, _ := newHealingOverTimeWorld(t, healingOverTimeFixtures(t)[0]) + player, client := world.characters[1], world.clients[1] + player.profession, player.inventory.LearnedNanos = 4, []uint32{85215} + at := castTestBuff(t, world, 1, 1, 85215) + world.advanceNanos(at.Add(5 * time.Second)) + health := player.health + player.nanoRechargeUntil = time.Time{} + if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, 1, 53019, 85215})[20:]); err != nil || client.nanoCast == nil { + t.Fatal("HoT refresh rejected", err) + } + client.nanoCast.readyAt = at.Add(7*time.Second - time.Nanosecond) + + world.advanceNanos(at.Add(7 * time.Second)) + world.advanceNanos(at.Add(10 * time.Second)) + if player.health != health || len(player.activeNanos) != 1 || player.activeNanos[0].ticksLeft != 40 { + t.Fatal("refresh retained the previous tick phase or stacked its strain") + } + world.advanceNanos(at.Add(12 * time.Second)) + + if player.health < health+2 || player.health > health+6 || player.activeNanos[0].ticksLeft != 39 || + player.activeNanos[0].expiresAt != at.Add(207*time.Second) { + t.Fatal("refreshed HoT lost its complete sequence or lifetime") + } +} + +func TestHealingOverTimeColdPauseResumesFrozenPhaseThroughWorldLogin(t *testing.T) { + world, _ := newHealingOverTimeWorld(t, healingOverTimeFixtures(t)[0]) + player := world.characters[1] + player.profession, player.inventory.LearnedNanos = 4, []uint32{85215} + at := castTestBuff(t, world, 1, 1, 85215) + if err := world.pauseActiveNanos_locked(player, at.Add(2*time.Second)); err != nil { + t.Fatal(err) + } + world.advanceNanos(at.Add(24 * time.Hour)) + cold := newTestInventoryServer(t) + patient := cold.characters[1] + if patient.health != 1 || patient.activeNanos[0].remaining != 198*time.Second || patient.activeNanos[0].tickDelay != 3*time.Second || !patient.activeNanos[0].nextTick.IsZero() { + t.Fatal("offline recovery advanced or lost its partial interval") + } + cookie := systemPacket(0x1b, []byte{0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}) + binary.BigEndian.PutUint16(cookie, 0xdfdf) + connection, peer := net.Pipe() + connection.SetDeadline(time.Now().Add(5 * time.Second)) + stopped := make(chan struct{}) + go func() { defer close(stopped); defer peer.Close(); cold.serveWorldConnection(peer) }() + t.Cleanup(func() { connection.Close(); <-stopped }) + + if _, err := connection.Write(cookie); err != nil { + t.Fatal(err) + } + for { + packet, err := readPacket(connection) + if err != nil { + t.Fatal(err) + } + if binary.BigEndian.Uint32(packet[16:20]) == 0x5f52412e { + break + } + } + cold.mutex.Lock() + resumed := patient.activeNanos[0] + cold.mutex.Unlock() + cold.advanceNanos(resumed.nextTick.Add(-time.Nanosecond)) + if patient.health != 1 { + t.Fatal("resumed HoT healed before its saved partial interval") + } + cold.advanceNanos(resumed.nextTick) + connection.Close() + <-stopped + + if resumed.nextTick.IsZero() || resumed.expiresAt.Sub(resumed.nextTick) != 195*time.Second || resumed.ticksLeft != 40 || + patient.health < 3 || patient.health > 7 || patient.activeNanos[0].ticksLeft != 39 || !patient.activeNanos[0].nextTick.IsZero() || patient.activeNanos[0].tickDelay <= 0 { + t.Fatal("login failed to resume the saved phase or disconnect failed to pause it", resumed, patient.activeNanos) + } +} + +func TestHealingOverTimeRequirementBoundariesRejectUploadAndCast(t *testing.T) { + for _, fixture := range healingOverTimeFixtures(t) { + t.Run(fmt.Sprint(fixture.Program), func(t *testing.T) { + world, _ := newHealingOverTimeWorld(t, fixture) + player, client := world.characters[1], world.clients[1] + qualified := *player + for _, requirement := range fixture.Requirements { + if requirement.Operator == 4 { + continue + } + *player = qualified + switch requirement.Stat { + case 60, 368: + player.profession = 1 + case 54: + player.level = uint16(requirement.Value) + default: + for _, field := range player.stats.trainingStats() { + if int32(field.stat) == requirement.Stat { + *field.value = uint16(requirement.Value) + } + } + } + + if err := world.handleOwnedItemUse(client, backpackUseRequest(1, 64, 1)[20:]); err != nil { + t.Fatal(err) + } + if len(player.inventory.LearnedNanos) != 0 || len(player.inventory.Items) != 4 { + t.Fatal("failed original criterion consumed a HoT crystal", requirement) + } + player.inventory.LearnedNanos = []uint32{fixture.Program} + if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, 1, 53019, fixture.Program})[20:]); err != nil { + t.Fatal(err) + } + + if client.nanoCast != nil || player.nano != 50000 || player.nanoReserved != 0 { + t.Fatal("failed original criterion admitted a HoT cast", requirement) + } + } + }) + } +} diff --git a/server/nano_learning.go b/server/nano_learning.go @@ -41,7 +41,7 @@ func nanoCrystalProgram(template uint32) uint32 { return 0 } program = uint32(*function.Arguments[0].Integer) - if !statBuffNano(program) && directDamageNano(program) == nil && directHealingNano(program) == nil && damageOverTimeNano(program) == nil && controlNano(program) == nil { + if !statBuffNano(program) && directDamageNano(program) == nil && directHealingNano(program) == nil && healingOverTimeNano(program) == nil && damageOverTimeNano(program) == nil && controlNano(program) == nil { return 0 } } diff --git a/server/nano_periodic.go b/server/nano_periodic.go @@ -10,7 +10,7 @@ import ( func (server *server) advancePeriodicNanos_locked(now time.Time, updates map[*worldClient][][]byte) { for _, target := range server.characters { - if slices.IndexFunc(target.activeNanos, func(effect activeNano) bool { + if !target.npc || slices.IndexFunc(target.activeNanos, func(effect activeNano) bool { return effect.ticksLeft != 0 && !effect.nextTick.After(now) }) < 0 { continue @@ -67,3 +67,45 @@ func (server *server) advancePeriodicNanos_locked(now time.Time, updates map[*wo } } } + +func (server *server) advanceHealingNanos_locked(now time.Time, updates map[*worldClient][][]byte) { + for _, target := range server.characters { + if target.npc || target.health == 0 || slices.IndexFunc(target.activeNanos, func(effect activeNano) bool { + return effect.ticksLeft != 0 && !effect.nextTick.IsZero() && !effect.nextTick.After(now) + }) < 0 { + continue + } + + // Commit all due recovery and tick progress before publishing an HP snapshot. + candidate := *target + candidate.activeNanos = slices.Clone(target.activeNanos) + for { + index := -1 + for next, effect := range candidate.activeNanos { + if effect.ticksLeft != 0 && !effect.nextTick.IsZero() && !effect.nextTick.After(now) && + (index < 0 || effect.nextTick.Before(candidate.activeNanos[index].nextTick)) { + index = next + } + } + if index < 0 { + break + } + effect := &candidate.activeNanos[index] + hit := healingOverTimeNano(effect.program) + minimum, maximum := uint32(*hit.Arguments[1].Integer), uint32(*hit.Arguments[2].Integer) + candidate.health += min(minimum+rand.Uint32N(maximum-minimum+1), candidate.maximumHealth()-candidate.health) + effect.ticksLeft-- + effect.nextTick = effect.nextTick.Add(time.Duration(hit.TickInterval) * 10 * time.Millisecond) + } + if err := server.saveActiveNanos_locked(&candidate, now); err != nil { + log.Printf("Periodic healing outcome: %v", err) + continue + } + previous := *target + *target = candidate + if target.health != previous.health { + server.queueHealthSnapshot_locked(updates, target) + server.queueTeamResources_locked(updates, target) + } + } +} diff --git a/server/testdata/periodic-healing-nanos.json b/server/testdata/periodic-healing-nanos.json @@ -0,0 +1,202 @@ +[ + {"program": 42396, "crystal": 42411, "quality": 149, "name": "Cycle of Life", "minimum": 181, "maximum": 218, "tick_count": 28, "tick_interval": 500, "duration": 14000, "ncu": 46, "strain": 12, "nano_cost": 807, "attack_delay": 358, "recharge_delay": 171, "range": 20, + "requirements": [{"stat": 128, "value": 716, "operator": 2}, {"stat": 127, "value": 645, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 645, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 716, "operator": 2}, {"stat": 127, "value": 645, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 645, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 32], [131, 32], [128, 36]]}], + "mode_map": [[12, 0]]}, + {"program": 42399, "crystal": 42414, "quality": 60, "name": "Health Pump", "minimum": 57, "maximum": 78, "tick_count": 28, "tick_interval": 500, "duration": 14000, "ncu": 19, "strain": 12, "nano_cost": 454, "attack_delay": 294, "recharge_delay": 129, "range": 20, + "requirements": [{"stat": 128, "value": 303, "operator": 2}, {"stat": 127, "value": 266, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 266, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 303, "operator": 2}, {"stat": 127, "value": 266, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 266, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 32], [131, 32], [128, 36]]}], + "mode_map": [[12, 0]]}, + {"program": 42401, "crystal": 42416, "quality": 14, "name": "Lasting Heal", "minimum": 10, "maximum": 21, "tick_count": 28, "tick_interval": 500, "duration": 14000, "ncu": 5, "strain": 12, "nano_cost": 164, "attack_delay": 260, "recharge_delay": 106, "range": 20, + "requirements": [{"stat": 128, "value": 78, "operator": 2}, {"stat": 127, "value": 65, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 65, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 78, "operator": 2}, {"stat": 127, "value": 65, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 65, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 31], [131, 31], [128, 38]]}], + "mode_map": [[12, 0]]}, + {"program": 43852, "crystal": 43989, "quality": 182, "name": "Deathless Blessing", "minimum": 277, "maximum": 323, "tick_count": 28, "tick_interval": 500, "duration": 14000, "ncu": 56, "strain": 12, "nano_cost": 940, "attack_delay": 403, "recharge_delay": 202, "range": 20, + "requirements": [{"stat": 128, "value": 864, "operator": 2}, {"stat": 127, "value": 778, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 778, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 864, "operator": 2}, {"stat": 127, "value": 778, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 778, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 32], [131, 32], [128, 36]]}], + "mode_map": [[12, 0]]}, + {"program": 43867, "crystal": 43984, "quality": 126, "name": "Continuous Cellular Reconditioning", "minimum": 139, "maximum": 162, "tick_count": 28, "tick_interval": 500, "duration": 14000, "ncu": 39, "strain": 12, "nano_cost": 710, "attack_delay": 335, "recharge_delay": 156, "range": 20, + "requirements": [{"stat": 128, "value": 602, "operator": 2}, {"stat": 127, "value": 542, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 542, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 602, "operator": 2}, {"stat": 127, "value": 542, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 542, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 32], [131, 32], [128, 36]]}], + "mode_map": [[12, 0]]}, + {"program": 43868, "crystal": 43988, "quality": 179, "name": "Cycle of Reconstruction", "minimum": 272, "maximum": 307, "tick_count": 28, "tick_interval": 500, "duration": 14000, "ncu": 55, "strain": 12, "nano_cost": 950, "attack_delay": 394, "recharge_delay": 196, "range": 20, + "requirements": [{"stat": 128, "value": 846, "operator": 2}, {"stat": 127, "value": 765, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 765, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 846, "operator": 2}, {"stat": 127, "value": 765, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 765, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 32], [131, 32], [128, 36]]}], + "mode_map": [[12, 0]]}, + {"program": 43869, "crystal": 43968, "quality": 142, "name": "Greater Periodic Checkup", "minimum": 160, "maximum": 189, "tick_count": 28, "tick_interval": 500, "duration": 14000, "ncu": 44, "strain": 12, "nano_cost": 764, "attack_delay": 346, "recharge_delay": 163, "range": 20, + "requirements": [{"stat": 128, "value": 680, "operator": 2}, {"stat": 127, "value": 609, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 609, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 680, "operator": 2}, {"stat": 127, "value": 609, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 609, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 32], [131, 32], [128, 36]]}], + "mode_map": [[12, 0]]}, + {"program": 43870, "crystal": 43969, "quality": 172, "name": "Greater Policy Payout", "minimum": 258, "maximum": 293, "tick_count": 28, "tick_interval": 500, "duration": 14000, "ncu": 53, "strain": 12, "nano_cost": 936, "attack_delay": 387, "recharge_delay": 191, "range": 20, + "requirements": [{"stat": 128, "value": 823, "operator": 2}, {"stat": 127, "value": 746, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 746, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 823, "operator": 2}, {"stat": 127, "value": 746, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 746, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 32], [131, 32], [128, 36]]}], + "mode_map": [[12, 0]]}, + {"program": 43871, "crystal": 43951, "quality": 156, "name": "Molecular Rejuvenation", "minimum": 200, "maximum": 239, "tick_count": 28, "tick_interval": 500, "duration": 14000, "ncu": 48, "strain": 12, "nano_cost": 840, "attack_delay": 366, "recharge_delay": 177, "range": 20, + "requirements": [{"stat": 128, "value": 741, "operator": 2}, {"stat": 127, "value": 669, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 669, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 741, "operator": 2}, {"stat": 127, "value": 669, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 669, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 32], [131, 32], [128, 36]]}], + "mode_map": [[12, 0]]}, + {"program": 43872, "crystal": 43956, "quality": 169, "name": "Positive Life Reinforcement", "minimum": 243, "maximum": 288, "tick_count": 28, "tick_interval": 500, "duration": 14000, "ncu": 52, "strain": 12, "nano_cost": 920, "attack_delay": 383, "recharge_delay": 189, "range": 20, + "requirements": [{"stat": 128, "value": 806, "operator": 2}, {"stat": 127, "value": 732, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 732, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 806, "operator": 2}, {"stat": 127, "value": 732, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 732, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 32], [131, 32], [128, 36]]}], + "mode_map": [[12, 0]]}, + {"program": 43873, "crystal": 43944, "quality": 162, "name": "Superior Health Pump", "minimum": 229, "maximum": 260, "tick_count": 28, "tick_interval": 500, "duration": 14000, "ncu": 50, "strain": 12, "nano_cost": 884, "attack_delay": 376, "recharge_delay": 184, "range": 20, + "requirements": [{"stat": 128, "value": 774, "operator": 2}, {"stat": 127, "value": 702, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 702, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 774, "operator": 2}, {"stat": 127, "value": 702, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 702, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 32], [131, 32], [128, 36]]}], + "mode_map": [[12, 0]]}, + {"program": 43874, "crystal": 44004, "quality": 33, "name": "Active Remedy", "minimum": 30, "maximum": 42, "tick_count": 28, "tick_interval": 500, "duration": 14000, "ncu": 11, "strain": 12, "nano_cost": 302, "attack_delay": 276, "recharge_delay": 117, "range": 20, + "requirements": [{"stat": 128, "value": 178, "operator": 2}, {"stat": 127, "value": 154, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 154, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 178, "operator": 2}, {"stat": 127, "value": 154, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 154, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 31], [131, 32], [128, 37]]}], + "mode_map": [[12, 0]]}, + {"program": 43875, "crystal": 43986, "quality": 86, "name": "Course of Treatment", "minimum": 82, "maximum": 104, "tick_count": 28, "tick_interval": 500, "duration": 14000, "ncu": 27, "strain": 12, "nano_cost": 537, "attack_delay": 310, "recharge_delay": 140, "range": 20, + "requirements": [{"stat": 128, "value": 417, "operator": 2}, {"stat": 127, "value": 374, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 374, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 417, "operator": 2}, {"stat": 127, "value": 374, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 374, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 32], [131, 32], [128, 36]]}], + "mode_map": [[12, 0]]}, + {"program": 43876, "crystal": 43967, "quality": 93, "name": "Greater Lasting Heal", "minimum": 92, "maximum": 124, "tick_count": 28, "tick_interval": 500, "duration": 14000, "ncu": 29, "strain": 12, "nano_cost": 587, "attack_delay": 317, "recharge_delay": 144, "range": 20, + "requirements": [{"stat": 128, "value": 455, "operator": 2}, {"stat": 127, "value": 417, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 417, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 455, "operator": 2}, {"stat": 127, "value": 417, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 417, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 33], [131, 32], [128, 35]]}], + "mode_map": [[12, 0]]}, + {"program": 43877, "crystal": 43964, "quality": 109, "name": "Lesser Policy Payout", "minimum": 112, "maximum": 143, "tick_count": 28, "tick_interval": 500, "duration": 14000, "ncu": 34, "strain": 12, "nano_cost": 644, "attack_delay": 326, "recharge_delay": 150, "range": 20, + "requirements": [{"stat": 128, "value": 531, "operator": 2}, {"stat": 127, "value": 482, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 482, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 531, "operator": 2}, {"stat": 127, "value": 482, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 482, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 32], [131, 32], [128, 36]]}], + "mode_map": [[12, 0]]}, + {"program": 43879, "crystal": 43948, "quality": 70, "name": "Medical Sequencer", "minimum": 66, "maximum": 86, "tick_count": 28, "tick_interval": 500, "duration": 14000, "ncu": 22, "strain": 12, "nano_cost": 484, "attack_delay": 300, "recharge_delay": 133, "range": 20, + "requirements": [{"stat": 128, "value": 349, "operator": 2}, {"stat": 127, "value": 304, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 304, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 349, "operator": 2}, {"stat": 127, "value": 304, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 304, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 32], [131, 32], [128, 36]]}], + "mode_map": [[12, 0]]}, + {"program": 43880, "crystal": 43954, "quality": 27, "name": "Periodic Checkup", "minimum": 22, "maximum": 35, "tick_count": 28, "tick_interval": 500, "duration": 14000, "ncu": 9, "strain": 12, "nano_cost": 259, "attack_delay": 270, "recharge_delay": 113, "range": 20, + "requirements": [{"stat": 128, "value": 142, "operator": 2}, {"stat": 127, "value": 120, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 120, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 142, "operator": 2}, {"stat": 127, "value": 120, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 120, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 32], [131, 31], [128, 37]]}], + "mode_map": [[12, 0]]}, + {"program": 43882, "crystal": 43938, "quality": 40, "name": "Recurrent Remedy", "minimum": 38, "maximum": 51, "tick_count": 28, "tick_interval": 500, "duration": 14000, "ncu": 13, "strain": 12, "nano_cost": 346, "attack_delay": 281, "recharge_delay": 121, "range": 20, + "requirements": [{"stat": 128, "value": 210, "operator": 2}, {"stat": 127, "value": 187, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 187, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 210, "operator": 2}, {"stat": 127, "value": 187, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 187, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 10, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 32], [131, 32], [128, 36]]}], + "mode_map": [[12, 0]]}, + {"program": 85215, "crystal": 85273, "quality": 4, "name": "Basic Insurance Hack", "minimum": 2, "maximum": 6, "tick_count": 40, "tick_interval": 500, "duration": 20000, "ncu": 1, "strain": 12, "nano_cost": 85, "attack_delay": 253, "recharge_delay": 102, "range": 25, + "requirements": [{"stat": 128, "value": 20, "operator": 2}, {"stat": 131, "value": 20, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 127, "value": 25, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 20, "operator": 2}, {"stat": 131, "value": 20, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 127, "value": 25, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 38], [131, 31], [128, 31]]}], + "mode_map": [[12, 0]]}, + {"program": 85225, "crystal": 85272, "quality": 142, "name": "Advanced Policy Skim", "minimum": 104, "maximum": 244, "tick_count": 40, "tick_interval": 500, "duration": 20000, "ncu": 23, "strain": 12, "nano_cost": 1216, "attack_delay": 377, "recharge_delay": 185, "range": 25, + "requirements": [{"stat": 128, "value": 542, "operator": 2}, {"stat": 131, "value": 542, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 127, "value": 708, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 542, "operator": 2}, {"stat": 131, "value": 542, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 127, "value": 708, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 40], [131, 30], [128, 30]]}], + "mode_map": [[12, 0]]}, + {"program": 85226, "crystal": 85278, "quality": 149, "name": "Omni-Med Incursion", "minimum": 122, "maximum": 276, "tick_count": 40, "tick_interval": 500, "duration": 20000, "ncu": 24, "strain": 12, "nano_cost": 1293, "attack_delay": 391, "recharge_delay": 194, "range": 20, + "requirements": [{"stat": 128, "value": 573, "operator": 2}, {"stat": 127, "value": 758, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 573, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 573, "operator": 2}, {"stat": 131, "value": 573, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 127, "value": 758, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 40], [131, 30], [128, 30]]}], + "mode_map": [[12, 0]]}, + {"program": 85227, "crystal": 85265, "quality": 129, "name": "Flawless Medical Claim", "minimum": 95, "maximum": 200, "tick_count": 40, "tick_interval": 500, "duration": 20000, "ncu": 21, "strain": 12, "nano_cost": 1127, "attack_delay": 363, "recharge_delay": 175, "range": 25, + "requirements": [{"stat": 128, "value": 491, "operator": 2}, {"stat": 131, "value": 491, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 127, "value": 660, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 491, "operator": 2}, {"stat": 131, "value": 491, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 127, "value": 660, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 40], [131, 30], [128, 30]]}], + "mode_map": [[12, 0]]}, + {"program": 85228, "crystal": 85271, "quality": 103, "name": "Advanced Insurance Hack", "minimum": 64, "maximum": 139, "tick_count": 40, "tick_interval": 500, "duration": 20000, "ncu": 17, "strain": 12, "nano_cost": 947, "attack_delay": 333, "recharge_delay": 155, "range": 25, + "requirements": [{"stat": 128, "value": 376, "operator": 2}, {"stat": 131, "value": 376, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 127, "value": 527, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 376, "operator": 2}, {"stat": 131, "value": 376, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 127, "value": 527, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 44], [131, 28], [128, 28]]}], + "mode_map": [[12, 0]]}, + {"program": 85229, "crystal": 85280, "quality": 119, "name": "Policy Skim", "minimum": 83, "maximum": 168, "tick_count": 40, "tick_interval": 500, "duration": 20000, "ncu": 20, "strain": 12, "nano_cost": 1057, "attack_delay": 348, "recharge_delay": 165, "range": 25, + "requirements": [{"stat": 128, "value": 443, "operator": 2}, {"stat": 131, "value": 443, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 127, "value": 617, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 443, "operator": 2}, {"stat": 131, "value": 443, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 127, "value": 617, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 44], [131, 28], [128, 28]]}], + "mode_map": [[12, 0]]}, + {"program": 85230, "crystal": 85269, "quality": 73, "name": "Detailed Medical Claim", "minimum": 43, "maximum": 92, "tick_count": 40, "tick_interval": 500, "duration": 20000, "ncu": 12, "strain": 12, "nano_cost": 752, "attack_delay": 312, "recharge_delay": 141, "range": 25, + "requirements": [{"stat": 128, "value": 275, "operator": 2}, {"stat": 131, "value": 275, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 127, "value": 383, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 275, "operator": 2}, {"stat": 131, "value": 275, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 127, "value": 383, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 44], [131, 28], [128, 28]]}], + "mode_map": [[12, 0]]}, + {"program": 85231, "crystal": 85268, "quality": 66, "name": "Basic Policy Skim", "minimum": 38, "maximum": 82, "tick_count": 40, "tick_interval": 500, "duration": 20000, "ncu": 11, "strain": 12, "nano_cost": 702, "attack_delay": 306, "recharge_delay": 137, "range": 25, + "requirements": [{"stat": 128, "value": 246, "operator": 2}, {"stat": 131, "value": 246, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 127, "value": 344, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 246, "operator": 2}, {"stat": 131, "value": 246, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 127, "value": 344, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 44], [131, 28], [128, 28]]}], + "mode_map": [[12, 0]]}, + {"program": 85232, "crystal": 85267, "quality": 47, "name": "Insurance Hack", "minimum": 26, "maximum": 63, "tick_count": 40, "tick_interval": 500, "duration": 20000, "ncu": 8, "strain": 12, "nano_cost": 599, "attack_delay": 292, "recharge_delay": 128, "range": 25, + "requirements": [{"stat": 128, "value": 181, "operator": 2}, {"stat": 131, "value": 181, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 127, "value": 251, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 181, "operator": 2}, {"stat": 131, "value": 181, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 127, "value": 251, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 40], [131, 30], [128, 30]]}], + "mode_map": [[12, 0]]}, + {"program": 85233, "crystal": 85270, "quality": 30, "name": "Falsify Medical Records", "minimum": 17, "maximum": 39, "tick_count": 40, "tick_interval": 500, "duration": 20000, "ncu": 5, "strain": 12, "nano_cost": 442, "attack_delay": 279, "recharge_delay": 119, "range": 25, + "requirements": [{"stat": 128, "value": 125, "operator": 2}, {"stat": 131, "value": 125, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 127, "value": 170, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 125, "operator": 2}, {"stat": 131, "value": 125, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 127, "value": 170, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 40], [131, 30], [128, 30]]}], + "mode_map": [[12, 0]]}, + {"program": 85234, "crystal": 85282, "quality": 17, "name": "Medical Claim", "minimum": 10, "maximum": 21, "tick_count": 40, "tick_interval": 500, "duration": 20000, "ncu": 3, "strain": 12, "nano_cost": 301, "attack_delay": 266, "recharge_delay": 110, "range": 25, + "requirements": [{"stat": 128, "value": 70, "operator": 2}, {"stat": 131, "value": 70, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 127, "value": 95, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 128, "value": 70, "operator": 2}, {"stat": 131, "value": 70, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 127, "value": 95, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 368, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 40], [131, 30], [128, 30]]}], + "mode_map": [[12, 0]]}, + {"program": 162714, "crystal": 162715, "quality": 7, "name": "Relieving Salve", "minimum": 15, "maximum": 18, "tick_count": 90, "tick_interval": 1000, "duration": 90000, "ncu": 2, "strain": 255, "nano_cost": 114, "attack_delay": 459, "recharge_delay": 306, "range": 15, + "requirements": [{"stat": 127, "value": 56, "operator": 2}, {"stat": 128, "value": 42, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 42, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 60, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 127, "value": 56, "operator": 2}, {"stat": 128, "value": 42, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 42, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 60, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 44], [131, 28], [128, 28]]}, {"type": 13, "stats": [[168, 0]]}], + "mode_map": [[12, 0], [13, 0]]}, + {"program": 162716, "crystal": 162717, "quality": 24, "name": "Rebinding Sutures", "minimum": 35, "maximum": 41, "tick_count": 90, "tick_interval": 1000, "duration": 90000, "ncu": 4, "strain": 255, "nano_cost": 213, "attack_delay": 472, "recharge_delay": 315, "range": 15, + "requirements": [{"stat": 127, "value": 133, "operator": 2}, {"stat": 128, "value": 98, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 98, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 60, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 54, "value": 24, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 127, "value": 133, "operator": 2}, {"stat": 128, "value": 98, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 98, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 60, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 54, "value": 24, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 44], [131, 28], [128, 28]]}, {"type": 13, "stats": [[168, 0]]}], + "mode_map": [[12, 0], [13, 0]]}, + {"program": 162718, "crystal": 162719, "quality": 37, "name": "Hacked Diagnosis", "minimum": 58, "maximum": 64, "tick_count": 90, "tick_interval": 1000, "duration": 90000, "ncu": 6, "strain": 255, "nano_cost": 290, "attack_delay": 484, "recharge_delay": 323, "range": 15, + "requirements": [{"stat": 127, "value": 203, "operator": 2}, {"stat": 128, "value": 148, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 148, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 60, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 54, "value": 24, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 127, "value": 203, "operator": 2}, {"stat": 128, "value": 148, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 148, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 60, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 54, "value": 24, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 44], [131, 28], [128, 28]]}, {"type": 13, "stats": [[168, 0]]}], + "mode_map": [[12, 0], [13, 0]]}, + {"program": 162720, "crystal": 162721, "quality": 53, "name": "Kitchen-sink Surgery", "minimum": 87, "maximum": 92, "tick_count": 90, "tick_interval": 1000, "duration": 90000, "ncu": 9, "strain": 255, "nano_cost": 368, "attack_delay": 498, "recharge_delay": 332, "range": 15, + "requirements": [{"stat": 127, "value": 293, "operator": 2}, {"stat": 128, "value": 211, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 211, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 60, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 54, "value": 49, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 127, "value": 293, "operator": 2}, {"stat": 128, "value": 211, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 211, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 60, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 54, "value": 49, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 44], [131, 28], [128, 28]]}, {"type": 13, "stats": [[168, 0]]}], + "mode_map": [[12, 0], [13, 0]]}, + {"program": 162722, "crystal": 162723, "quality": 70, "name": "Blackmarket Prescription", "minimum": 111, "maximum": 119, "tick_count": 120, "tick_interval": 1000, "duration": 120000, "ncu": 12, "strain": 255, "nano_cost": 418, "attack_delay": 511, "recharge_delay": 341, "range": 15, + "requirements": [{"stat": 127, "value": 378, "operator": 2}, {"stat": 128, "value": 271, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 271, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 60, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 54, "value": 74, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 127, "value": 378, "operator": 2}, {"stat": 128, "value": 271, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 271, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 60, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 54, "value": 74, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 44], [131, 28], [128, 28]]}, {"type": 13, "stats": [[168, 0]]}], + "mode_map": [[12, 0], [13, 0]]}, + {"program": 162724, "crystal": 162725, "quality": 93, "name": "Biosign Rejuvenator", "minimum": 154, "maximum": 162, "tick_count": 120, "tick_interval": 1000, "duration": 120000, "ncu": 15, "strain": 255, "nano_cost": 504, "attack_delay": 527, "recharge_delay": 351, "range": 15, + "requirements": [{"stat": 127, "value": 487, "operator": 2}, {"stat": 128, "value": 346, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 346, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 60, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 54, "value": 99, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 127, "value": 487, "operator": 2}, {"stat": 128, "value": 346, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 346, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 60, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 54, "value": 99, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 44], [131, 28], [128, 28]]}, {"type": 13, "stats": [[168, 0]]}], + "mode_map": [[12, 0], [13, 0]]}, + {"program": 162726, "crystal": 162727, "quality": 109, "name": "Nano Cauterization", "minimum": 194, "maximum": 201, "tick_count": 120, "tick_interval": 1000, "duration": 120000, "ncu": 18, "strain": 255, "nano_cost": 572, "attack_delay": 540, "recharge_delay": 360, "range": 15, + "requirements": [{"stat": 127, "value": 573, "operator": 2}, {"stat": 128, "value": 409, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 409, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 60, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 54, "value": 99, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 127, "value": 573, "operator": 2}, {"stat": 128, "value": 409, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 409, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 60, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 54, "value": 99, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 44], [131, 28], [128, 28]]}, {"type": 13, "stats": [[168, 0]]}], + "mode_map": [[12, 0], [13, 0]]}, + {"program": 162728, "crystal": 162729, "quality": 123, "name": "Systolic Equalizer", "minimum": 235, "maximum": 243, "tick_count": 150, "tick_interval": 1000, "duration": 150000, "ncu": 20, "strain": 255, "nano_cost": 619, "attack_delay": 556, "recharge_delay": 371, "range": 15, + "requirements": [{"stat": 127, "value": 641, "operator": 2}, {"stat": 128, "value": 469, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 469, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 60, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 54, "value": 134, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 127, "value": 641, "operator": 2}, {"stat": 128, "value": 469, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 469, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 60, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 54, "value": 134, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 44], [131, 28], [128, 28]]}, {"type": 13, "stats": [[168, 0]]}], + "mode_map": [[12, 0], [13, 0]]}, + {"program": 162730, "crystal": 162731, "quality": 132, "name": "Backyard Revitalization", "minimum": 276, "maximum": 283, "tick_count": 150, "tick_interval": 1000, "duration": 150000, "ncu": 22, "strain": 255, "nano_cost": 661, "attack_delay": 571, "recharge_delay": 381, "range": 15, + "requirements": [{"stat": 127, "value": 682, "operator": 2}, {"stat": 128, "value": 519, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 519, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 60, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 54, "value": 154, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 127, "value": 682, "operator": 2}, {"stat": 128, "value": 519, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 519, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 60, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 54, "value": 154, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 44], [131, 28], [128, 28]]}, {"type": 13, "stats": [[168, 0]]}], + "mode_map": [[12, 0], [13, 0]]}, + {"program": 162732, "crystal": 162733, "quality": 146, "name": "Cellular Crashcart", "minimum": 326, "maximum": 335, "tick_count": 150, "tick_interval": 1000, "duration": 150000, "ncu": 24, "strain": 255, "nano_cost": 719, "attack_delay": 585, "recharge_delay": 391, "range": 15, + "requirements": [{"stat": 127, "value": 742, "operator": 2}, {"stat": 128, "value": 563, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 563, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 60, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 54, "value": 174, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 127, "value": 742, "operator": 2}, {"stat": 128, "value": 563, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 563, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 60, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 54, "value": 174, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 44], [131, 28], [128, 28]]}, {"type": 13, "stats": [[168, 0]]}], + "mode_map": [[12, 0], [13, 0]]}, + {"program": 162734, "crystal": 162735, "quality": 152, "name": "Dr Hack 'n Quack", "minimum": 362, "maximum": 370, "tick_count": 180, "tick_interval": 1000, "duration": 180000, "ncu": 25, "strain": 255, "nano_cost": 729, "attack_delay": 603, "recharge_delay": 402, "range": 15, + "requirements": [{"stat": 127, "value": 778, "operator": 2}, {"stat": 128, "value": 588, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 588, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 60, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 54, "value": 194, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}], + "uploader_requirements": [{"stat": 127, "value": 778, "operator": 2}, {"stat": 128, "value": 588, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 131, "value": 588, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 60, "value": 4, "operator": 0}, {"stat": 0, "value": 0, "operator": 4}, {"stat": 54, "value": 194, "operator": 2}, {"stat": 0, "value": 0, "operator": 4}], + "attack_weights": [{"type": 12, "stats": [[127, 44], [131, 28], [128, 28]]}, {"type": 13, "stats": [[168, 0]]}], + "mode_map": [[12, 0], [13, 0]]} +] diff --git a/tools/client/test_healing_over_time.mjs b/tools/client/test_healing_over_time.mjs @@ -0,0 +1,100 @@ +import assert from 'node:assert/strict'; +import fs from 'node:fs/promises'; +import {createRequire} from 'node:module'; +import {GameTest} from './game_test.mjs'; + +const {chromium} = createRequire(import.meta.url)('playwright'); +const [url, output] = process.argv.slice(2); +const browser = await chromium.launch({executablePath: '/usr/bin/chromium', headless: false, + args: ['--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage', + '--disable-background-timer-throttling', '--disable-renderer-backgrounding']}); +const games = [], evidence = {}; +const state = async () => (await games[0].page.request.get(url + '/test-state')).json(); +const actor = (game, id) => game.state.actors.find(actor => actor.type === 50000 && actor.id === id); +const pending = (game, id) => actor(game, id)?.weapons.some(weapon => weapon.pending.length); +const waitState = async (label, predicate) => { + const deadline = Date.now() + 10000; + for (;;) { + const current = await state(); + if (predicate(current)) return current; + assert(Date.now() < deadline, 'Timed out waiting for ' + label); + await games[0].snapshot(); + } +}; +try { + // Load the observer first so the caster's regeneration phase stays outside this short check. + for (const index of [1, 0]) { + const context = await browser.newContext({viewport: {width: 1024, height: 768}}); + await context.addCookies([{name: 'ao_client', value: 'hot-' + index, url}]); + const page = await context.newPage(); + const game = await GameTest.attach(page); + games[index] = game; + await page.goto(url); + await game.ready(); + } + const [owner] = games; + const initial = await state(); + evidence.initial = initial; + await Promise.all(games.map(game => game.wait('both patients and the Leet', () => + actor(game, initial.owner) && actor(game, initial.observer) && actor(game, initial.enemy)))); + await owner.key('KeyI'); + await owner.click(681, 45, 'right'); + await owner.wait('Fixer HoT crystal learned', snapshot => owner.local(snapshot).inventory.length === 0); + await owner.page.keyboard.press('Control+8'); + await owner.click(974, 76); + await owner.key('F1'); + await owner.save(output + '/ready'); + + const sequence = owner.sequence; + await owner.click(857, 128, 'right'); + await waitState('HoT installed', state => state.effects?.length === 1); + await waitState('first HoT tick near deadline', state => Date.now() >= Date.parse(state.effects[0].nextTick) - 500); + assert.equal((await owner.page.request.post(url + '/test-attack')).status(), 204); + evidence.pending = {server: await state()}; + assert.equal(evidence.pending.server.cast, null); + assert.equal(evidence.pending.server.effects[0].ticks, 40); + assert(evidence.pending.server.health < 200); + await Promise.all(games.map(game => game.wait('incoming result before the HoT tick', () => pending(game, initial.enemy)))); + evidence.pending.clients = games.map(game => ({health: actor(game, initial.owner).stats[27], enemy: actor(game, initial.enemy)})); + assert(evidence.pending.clients.every(client => client.health === 200)); + await Promise.all(games.map(async game => { + await game.wait('HoT recovery before queued impact', () => actor(game, initial.owner).stats[27] !== 200 && pending(game, initial.enemy)); + return {health: actor(game, initial.owner).stats[27], enemy: actor(game, initial.enemy)}; + })).then(clients => { evidence.beforeImpact = clients; }); + const healed = await state(); + evidence.healed = healed; + assert(healed.health >= evidence.pending.server.health + 2 && healed.health <= evidence.pending.server.health + 6); + assert.equal(healed.nano, 116); + assert.equal(healed.reserved, 0); + assert.equal(healed.cast, null); + assert.equal(healed.effects[0].ticks, 39); + assert.equal(healed.effects[0].program, 85215); + assert(evidence.beforeImpact.every(client => client.health === healed.health)); + assert.equal(healed.nextAttack, evidence.pending.server.nextAttack); + assert.equal(healed.weaponRecharge, evidence.pending.server.weaponRecharge); + await Promise.all(games.map(game => game.wait('healed health remains after impact', () => + actor(game, initial.owner).stats[27] === healed.health && !pending(game, initial.enemy)))); + evidence.afterImpact = games.map(game => ({health: actor(game, initial.owner).stats[27], enemy: actor(game, initial.enemy)})); + await owner.wait('native nano debit', snapshot => owner.local(snapshot).stats[214] === 116); + const results = owner.events.filter(event => event.sequence > sequence && event.direction === 'framereceived' && + ['46002f16', '5c654b28'].includes(event.opcode)); + assert.equal(results.length, 1); + const actions = owner.events.filter(event => event.direction === 'framereceived' && event.opcode === '5e477770') + .map(event => Buffer.from(event.hex, 'hex').readUInt32BE(29)); + assert.equal(actions.filter(action => action === 18).length, 1); + assert.equal(actions.filter(action => action === 108).length, 0); + assert.equal(actions.filter(action => action === 107).length, 1); + const installs = owner.events.filter(event => event.direction === 'framereceived' && event.opcode === '5e477770') + .map(event => Buffer.from(event.hex, 'hex')).filter(packet => packet.readUInt32BE(29) === 177); + assert.equal(installs.length, 1); + assert.deepEqual([29, 33, 37, 41, 45].map(offset => installs[0].readUInt32BE(offset)), + [177, 53019, 85215, initial.owner, 20000]); + assert(games.every(game => game.errors.length === 0)); + console.log('PASS: native Fixer HoT upload, timed recovery during queued weapon damage and both clients retain recovered HP after impact'); +} finally { + try { + await fs.mkdir(output, {recursive: true}); + await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2)); + await Promise.all(games.map((game, index) => game.save(output + '/final-' + index))); + } finally { await browser.close(); } +}