commit 5aa0792add99399bd8d10525fe8314b28fbba5b9
parent 3eabb0825cad0b281e8df6eaa8fc194eecef4a37
Author: anon <anon@example.com>
Date: Sun, 25 Oct 2026 14:06:46 +0000
Generalize direct damage to complete catalog nano contracts
Read damage endpoints, type, requirements and cast metadata for 33 reviewed single-hit programs and 31 ordinary crystals. Reuse atomic outcomes and the existing execution path instead of Winter's Bite constants; reject secondary, periodic and unverified contracts.
Cover the complete admitted set, requirement and range boundaries, rejection without consumption, and durable lethal/nonlethal outcomes. Verify all eight damage labels in two native WASM clients, exact debits and committed receipts, plus recovery after a server restart. Keep original server policy limits and the known NPC recovery phase gap explicit.
Diffstat:
10 files changed, 617 insertions(+), 23 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -710,6 +710,16 @@ introduction and starting-item gameplay remain open below.
otherwise valid buffs or resetting the fight to hide the discrepancy.
- [x] Cast one direct-damage program on a creature. Check: target validation,
damage and death handling work without starting an unintended weapon attack.
+- [x] Replace Winter's Bite's damage constants and bespoke requirements with
+ complete catalog single-hit contracts. Support 33 ordinary programs and 31
+ ordinary uploaders, all eight damage stats, authored timing/range, learning,
+ requirements, atomic outcomes, lethal/nonlethal results and cold restore.
+ Preserve the existing PvE/reconstruction policy limits. See
+ [catalog direct damage](docs/nano-direct-damage.md).
+- [ ] Complete the NT starter Ice Flechette 28612's secondary cast 144632 and
+ its initiative debuff lifecycle before admitting it. Do not apply its Hit
+ alone. Recover ordinary acquisition for Heat Miser 26310 and Nano Bolt 27114;
+ the scanned original item catalog has no ordinary single-program uploader.
- [x] Apply one temporary stat buff. Check: the native effect appears, the stat
changes once, and expiration removes exactly that contribution.
All six basic ability Boosts, six Augments, Enhanced Senses, Feline Grace
diff --git a/docs/nano-damage.md b/docs/nano-damage.md
@@ -1,5 +1,10 @@
# Winter's Bite in 14.9.1
+The shared path now also supports 32 additional reviewed pure single-hit
+programs and their complete crystal contracts. See
+[catalog direct damage](nano-direct-damage.md) for admission, verification and
+the retained original-server policy limits below.
+
The QL 1 Bureaucrat startup crystal 29625 uploads program 29618, Winter's
Bite. The server supports this exact single-hit program against a visible,
living creature in the same playfield. Casting does not start the caster's
diff --git a/docs/nano-direct-damage.md b/docs/nano-direct-damage.md
@@ -0,0 +1,141 @@
+# Catalog direct-damage programs
+
+The shared casting path supports 33 reviewed ordinary programs whose entire
+OnUse effect is one immediate health Hit. It reads the original signed damage
+endpoints and damage stat, uses the program's own cost, attack delay, recharge,
+range and requirements, and commits the result through the existing atomic
+nano outcome transaction. There is no program-ID switch for damage delivery.
+
+This extends the existing PvE reconstruction policy: visible living creatures,
+an inclusive uniform damage roll, and range checks at admission and completion.
+Original resistance/fumble rolls, AC/modifier ordering, reflect/absorb, PvP,
+line of sight, interruption/refund policy and packet timing remain unresolved.
+Expanding these complete effects does not establish those server policies.
+
+## Original contracts and admission
+
+The audit reparsed the original 14.9.1 resource database. Of 246 programs with
+one selected-target immediate health Hit, 33 have the ordinary reviewed
+`0x80008000` flag contract. They retain the attack/Nano Resist dictionaries,
+zero defaults for those dictionaries, a single unconditional Hit 53002, and
+one action-3 requirement expression. The damage types span stats 90 through 97.
+The reader rejects secondary functions, ticks, other targets/resources, unknown
+sections, metadata variants and unrecognized argument forms.
+
+Thirty-one ordinary crystals upload these programs. Heat Miser 26310 and
+Nano Bolt 27114 have no ordinary single-program uploader in the scanned item
+catalog; test fixtures seed their learned entries without inventing acquisition.
+Multi-upload test items remain unsupported. The native upload and crystal
+consumption transaction is shared with supported stat buffs. Winter's Bite's
+startup crystal now uses its authored requirements through that common reader.
+
+Examples of the original single-hit contracts:
+
+| Program | Health damage | Damage stat | Raw cost | Attack / recharge, cs | Range, m |
+| --- | --- | --- | --- | --- | --- |
+| Winter's Bite 29618 | 10..23 | 95 cold | 10 | 261 / 100 | 25 |
+| Fire Stream 28608 | 26..46 | 97 fire | 15 | 327 / 208 | 25 |
+| Corrosive Spray 28601 | 17..30 | 93 chemical | 12 | 126 / 258 | 25 |
+| Inflict Harm 28667 | 16..29 | 91 melee | 13 | 265 / 102 | 25 |
+| Radioactive Cloud 28632 | 244..442 | 94 radiation | 114 | 314 / 126 | 22 |
+| Izgimmer's Last Word 28618 | 4118..8907 | 94 radiation | 1079 | 2000 / 800 | 35 |
+
+Crystals and programs retain their own postfix requirements. Most use visual
+profession 368; Heat Miser uses actual profession 60. All authored skill gates
+are checked independently. Raw cost is distinct from the existing native
+float-based debit policy: with modifier 100, these positive integer costs debit
+one point less. For example Fire Stream reserves 14 and Corrosive Spray 11.
+
+Ice Flechette 28612 is deliberately excluded. Its Hit is followed by
+CastNano 53051 of 144632, which applies four initiative debuffs for 6000 cs.
+Implementing only its damage would drop an authored effect. Area programs such
+as Radiation Pulse 28631 use an area-cast function and are also excluded.
+The separate flag `0x80000` zeroes native cast/recharge deadlines; it is outside
+this ordinary timing contract.
+
+Complete decoded census, rejected neighbors, uploaders and fixture provenance
+are retained in `local/direct-damage-nano-research/`. The checked-in
+`server/testdata/direct-damage-nanos.json` records all 33 contracts independently
+of the runtime reader.
+
+## Native result contract
+
+Original KKR SHA-256 is
+`a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0`.
+The retained audit contains 25 complete original REA records and 13 checked
+citations in `local/direct-damage-nano-research/native/README.md`; no fresh
+binary analysis session was opened.
+
+Hit 53002 is server-owned: common executor `100bfb40` rejects it before effect
+dispatch, and its otherwise unreachable executor is a stub. NanoAttack
+`0x4727213e`, reader `100b1590` / activation `100b1600`, carries a signed HP delta
+followed by a damage stat. Its envelope identifies the victim. Activation adds
+the signed delta to HP 27; it has no program-ID branch or damage-type whitelist.
+Feedback initialization`10039cf0` maps 90 projectile,91 melee,92 energy,
+93 chemical,94 radiation,95 cold,96 poison and 97 fire.
+
+The existing action 18/107 execution gate and recharge consumer are generic.
+On success, the server sends 107 with the actual completed program ID, then
+NanoAttack with the resolved negative delta and authored damage stat. Lethal
+hits retain the established death/corpse/StopFight and action 153 ordering.
+Cost, recharge, health, contributions and death/reward state commit before
+completion packets. Failed outcomes retain the existing cancellation/refund
+transaction; packet loss cannot repeat the committed damage.
+
+Principal complete evidence:
+`ev_065aec48e84d7bcfd376705ec06f50ef9f1ffd1b50711ff79c65ede2a927eec6`
+(NanoAttack),
+`ev_f28cc89d25d840908ea753e766d4e2d1a718ef5138b04f190e82062755593b1d`
+(effect gate), and
+`ev_a9090944783a773664fa3351a229696dfbf286ba0e7263ad03c2c2b5942ca38a`
+(execution/finish gate). These prove client consumers, not original-server
+damage arithmetic or scheduling.
+
+## Verification
+
+Go regressions check exact admitted sets, all 31 crystal uploads, all 33 cast
+results and cold restores, per-program cost/timing/type, skill equality/pass
+boundaries, profession rejection, nonlethal contribution and lethal corpse
+ownership, no duplicate completion, and 12/35-metre admission/completion edges.
+Mutation cases reject partial effects and unsupported metadata without
+consuming the crystal, reserving nano or damaging a target. Existing Winter's
+Bite outcome/reservation failure tests remain in the shared path.
+
+Three family/outcome race repetitions passed in 178.019 seconds. Three
+additional range repetitions passed in 111.994 seconds. Vet passed.
+The complete Go suite passed 5043 tests and subtests: server 795.418 seconds,
+game data 7.695 seconds.
+
+Two owned GPU WASM clients uploaded eight ordinary crystals and executed
+one program for each damage stat through native mouse controls. Their matching
+NanoAttack deltas were projectile 100, melee 56, energy 100, chemical 19,
+radiation 100, cold 57, poison 88 and fire 33; lethal damage was clamped to the
+target's remaining health. All eight native damage labels appeared correctly.
+The first completion receipts already had the committed NPC health, zero
+reserved nano and recharge in SQLite. Each admission debited its own cost;
+no cast started the player's weapon attack. Page reload retained all eight
+programs and the two correctly rejected crystals.
+
+The fixture initially selected Bureaucrat Drill Missile for the NT. Its
+profession rejection was correct; Vulcan Flechette supplied the NT projectile
+case. Ice Flechette's unsupported compound effect was also rejected without
+consumption. A separate wrong-profession upload retained its crystal.
+
+Sequential snapshots after the melee hit showed committed HP 44, owner 45 and
+observer 46 as ordinary recovery advanced. These are later samples, not a
+simultaneous health comparison. The already-open native/server recovery-phase
+gap remains; this milestone verifies matching result deltas and durable
+outcomes, not synchronization of those prediction clocks. See
+[NPC recovery](npc-regeneration.md).
+
+After a server restart, fresh clients retained the eight learned programs and
+both rejected crystals. Another native Fire Stream cast debited 14, committed
+37 fire damage and zero reservation, and reached both clients with the same
+delta. Normal nano recovery during execution was retained.
+
+The owned players, remaining crystals and disposable Leet fixtures/respawns
+were removed. Unrelated-row hashes and SQLite foreign-key/integrity checks
+passed, retaining existing players 8/24. The single normal preview remains on
+the default ports. No client rebuild was needed and no browser or adapter
+errors were captured. Warm/cold wire, native, SQLite and cleanup checks are
+recorded in `local/direct-damage-nano-smoke/verification.json`.
diff --git a/server/backpacks.go b/server/backpacks.go
@@ -104,7 +104,7 @@ func (server *server) handleOwnedItemUse(client *worldClient, body []byte) error
switch player.inventory.Items[index].Template {
case 205736:
return server.useRemoteBank_locked(client, player.inventory.Items[index], body)
- case 43330, 29625, 28778:
+ case 43330, 28778:
return server.learnNano_locked(client, index, body)
case 43552:
return server.useClinic_locked(client, index, body)
@@ -115,7 +115,7 @@ func (server *server) handleOwnedItemUse(client *worldClient, body []byte) error
if kit, supported := player.inventory.Items[index].resourceKit(); supported {
return server.useResourceKit_locked(client, index, body, kit)
}
- if statBuffCrystalProgram(player.inventory.Items[index].Template) != 0 {
+ if nanoCrystalProgram(player.inventory.Items[index].Template) != 0 {
return server.learnNano_locked(client, index, body)
}
}
diff --git a/server/nano_casting.go b/server/nano_casting.go
@@ -73,12 +73,7 @@ func (player *character) nanoCastDelay(program uint32) time.Duration {
}
func (player *character) nanoRequirementsMet(program uint32) bool {
- if program == 29618 {
- stats := player.baseStats()
- return player.profession == 8 && player.effectiveSkill(129, stats.NanoAiding.PsychologicalModification, [6]uint32{0, 0, 0, 80, 20, 0}) > 8 &&
- player.effectiveSkill(130, stats.NanoAiding.MatterCreation, [6]uint32{0, 0, 20, 80, 0, 0}) > 7
- }
- return statBuffNano(program) && player.templateUseRequirementsMet(gamedata.NanoTemplates[program])
+ return (directDamageNano(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 {
@@ -86,7 +81,7 @@ func (server *server) nanoTarget_locked(player, target *character, client *world
return false
}
second := target.position
- if program == 29618 {
+ if directDamageNano(program) != nil {
if !target.npc || target.appearance>>4&7 != 6 || !client.npcs[target.id] {
return false
}
@@ -224,9 +219,11 @@ func (server *server) advanceNanos(now time.Time) {
victim = caster
}
var damage uint32
+ hit := directDamageNano(program)
removedHealthBonus := false
- if program == 29618 {
- damage = min(10+rand.Uint32N(14), target.health)
+ if hit != nil {
+ minimum, maximum := uint32(-*hit.Arguments[1].Integer), uint32(-*hit.Arguments[2].Integer)
+ damage = min(minimum+rand.Uint32N(maximum-minimum+1), target.health)
victim = prepareDamage(player, target, damage, now)
} else {
// A strain has one contribution; a refresh replaces its deadline and caster.
@@ -251,7 +248,7 @@ func (server *server) advanceNanos(now time.Time) {
previous := *target
*player, *target = caster, victim
client.nanoCast = nil
- if program != 29618 {
+ if hit == nil {
server.queueCombat_locked(updates, player, target, characterActionPacket(player.id, [5]uint32{107, 0, 0, 0, program}))
server.queueCombat_locked(updates, target, target, characterActionPacket(target.id, [5]uint32{177, 53019, program, player.id, nanoStat(program, 8)}))
server.finishResourceChange_locked(updates, target, previous, now)
@@ -262,8 +259,8 @@ func (server *server) advanceNanos(now time.Time) {
continue
}
body := binary.BigEndian.AppendUint32(nil, uint32(-int32(damage)))
- body = binary.BigEndian.AppendUint32(body, 95)
- server.queueCombat_locked(updates, player, target, characterActionPacket(player.id, [5]uint32{107, 0, 0, 0, 29618}))
+ body = binary.BigEndian.AppendUint32(body, uint32(*hit.Arguments[3].Integer))
+ server.queueCombat_locked(updates, player, target, characterActionPacket(player.id, [5]uint32{107, 0, 0, 0, program}))
server.queueCombat_locked(updates, target, target, n3Packet(0x4727213e, 50000, target.id, body))
server.finishDamageEffects_locked(player, target, previous, now, updates)
server.applyExperienceAward_locked(award, now, updates)
diff --git a/server/nano_damage.go b/server/nano_damage.go
@@ -0,0 +1,63 @@
+package main
+
+import (
+ "ao/server/gamedata"
+ "slices"
+)
+
+func directDamageNano(program uint32) *gamedata.ItemFunction {
+ definition := gamedata.NanoTemplates[program]
+ if definition == nil || definition.RecordType != 1040005 || definition.HeaderWords[0] != 51051 || definition.Undecoded != nil ||
+ itemStat(definition, 0) != 0x80008000 || itemStat(definition, 30) != 0 || itemStat(definition, 76) != 0 || len(definition.Sections) != 4 {
+ return nil
+ }
+ for _, stat := range []uint32{210, 287, 294, 407} {
+ if value := nanoStat(program, stat); value == 0 || value >= 0x80000000 {
+ return nil
+ }
+ }
+
+ // Ordinary single-target hits carry attack weights and a Nano Resist weight.
+ weights := definition.Sections[0]
+ if weights.Type != 4 || weights.Subtype != 4 || weights.Entries == nil || len(*weights.Entries) != 2 {
+ return nil
+ }
+ attack, defense := (*weights.Entries)[0], (*weights.Entries)[1]
+ if attack.Type == nil || *attack.Type != 12 || attack.Stats == nil || defense.Type == nil || *defense.Type != 13 || defense.Stats == nil ||
+ len(*defense.Stats) != 1 || (*defense.Stats)[0][0] != 168 || (*defense.Stats)[0][1] == 0 {
+ return nil
+ }
+ var total uint32
+ for _, weight := range *attack.Stats {
+ if weight[0] < 100 || weight[0] > 168 || weight[1] == 0 || weight[1] > 100 {
+ return nil
+ }
+ total += weight[1]
+ }
+ defaults := definition.Sections[1]
+ if total != 100 || defaults.Type != 6 || defaults.Subtype != 27 || defaults.Stats == nil || !slices.Equal(*defaults.Stats, [][2]uint32{{12, 0}, {13, 0}}) {
+ return nil
+ }
+
+ // Admit the whole OnUse contract; secondary casts, areas and ticks stay closed.
+ 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 {
+ return nil
+ }
+ 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 {
+ return nil
+ }
+ for _, argument := range hit.Arguments {
+ if argument.Integer == nil {
+ return nil
+ }
+ }
+ if *hit.Arguments[0].Integer != 27 || *hit.Arguments[1].Integer >= 0 || *hit.Arguments[2].Integer > *hit.Arguments[1].Integer ||
+ *hit.Arguments[3].Integer < 90 || *hit.Arguments[3].Integer > 97 {
+ return nil
+ }
+ return hit
+}
diff --git a/server/nano_damage_test.go b/server/nano_damage_test.go
@@ -0,0 +1,348 @@
+package main
+
+import (
+ "ao/server/gamedata"
+ _ "embed"
+ "encoding/binary"
+ "encoding/json"
+ "fmt"
+ "slices"
+ "testing"
+ "time"
+)
+
+//go:embed testdata/direct-damage-nanos.json
+var directDamageNanoData []byte
+
+type directDamageNanoFixture struct {
+ Program, Crystal, Quality, Profession uint32
+ Minimum, Maximum, Debit, Range uint32
+ DamageType uint32 `json:"damage_type"`
+ NanoCost uint32 `json:"nano_cost"`
+ AttackDelay uint32 `json:"attack_delay"`
+ RechargeDelay uint32 `json:"recharge_delay"`
+ Skills [][2]uint32
+}
+
+func directDamageNanoFixtures(t *testing.T) []directDamageNanoFixture {
+ t.Helper()
+ var fixtures []directDamageNanoFixture
+ if err := json.Unmarshal(directDamageNanoData, &fixtures); err != nil {
+ t.Fatal(err)
+ }
+ return fixtures
+}
+
+func newDirectDamageWorld(t *testing.T, fixture directDamageNanoFixture) (*server, *combatTestConn) {
+ t.Helper()
+ world, conn := newNanoOutcomeWorld(t, 100)
+ player := world.characters[1]
+ world.characters[1000000].position = [3]float32{1, 0, 0}
+ if fixture.Profession != 0 {
+ player.profession = uint16(fixture.Profession)
+ }
+ for _, field := range player.stats.trainingStats() {
+ *field.value = 2000
+ }
+ player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1}
+ player.stats.Speed.NanoInitiative = 5
+ player.stats.Body.NanoPool, player.nano = 30000, 50000
+ player.inventory.LearnedNanos = nil
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ if fixture.Crystal != 0 {
+ if granted, err := world.grantItem_locked(player, fixture.Crystal); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ }
+ conn.packets = nil
+ return world, conn
+}
+
+func TestDirectDamageNanoCatalogMatchesCompleteOriginalContracts(t *testing.T) {
+ var expectedPrograms, expectedCrystals, programs, crystals []uint32
+ for _, fixture := range directDamageNanoFixtures(t) {
+ expectedPrograms = append(expectedPrograms, fixture.Program)
+ if fixture.Crystal != 0 {
+ expectedCrystals = append(expectedCrystals, fixture.Crystal)
+ }
+ }
+
+ for program := range gamedata.NanoTemplates {
+ if directDamageNano(program) != nil {
+ programs = append(programs, program)
+ }
+ }
+ for crystal := range gamedata.ItemTemplates {
+ if directDamageNano(nanoCrystalProgram(crystal)) != nil {
+ crystals = append(crystals, crystal)
+ }
+ }
+ for _, values := range [][]uint32{programs, crystals, expectedPrograms, expectedCrystals} {
+ slices.Sort(values)
+ }
+
+ if len(programs) != 33 || len(crystals) != 31 || !slices.Equal(programs, expectedPrograms) || !slices.Equal(crystals, expectedCrystals) {
+ t.Fatalf("admission differs from the original-record census: programs=%v crystals=%v", programs, crystals)
+ }
+ for _, fixture := range directDamageNanoFixtures(t) {
+ hit := directDamageNano(fixture.Program)
+ if uint32(-*hit.Arguments[1].Integer) != fixture.Minimum || uint32(-*hit.Arguments[2].Integer) != fixture.Maximum || uint32(*hit.Arguments[3].Integer) != fixture.DamageType ||
+ nanoStat(fixture.Program, 407) != fixture.NanoCost || nanoStat(fixture.Program, 294) != fixture.AttackDelay ||
+ nanoStat(fixture.Program, 210) != fixture.RechargeDelay || nanoStat(fixture.Program, 287) != fixture.Range {
+ t.Fatal("authored hit or timing changed", fixture.Program)
+ }
+ }
+}
+
+func TestDirectDamageNanosLearnCastAndRestoreTheirCompleteResult(t *testing.T) {
+ for _, fixture := range directDamageNanoFixtures(t) {
+ t.Run(fmt.Sprint(fixture.Program), func(t *testing.T) {
+ world, conn := newDirectDamageWorld(t, fixture)
+ player, target, client := world.characters[1], world.characters[1000000], world.clients[1]
+ if fixture.Crystal != 0 {
+ if err := world.handleOwnedItemUse(client, backpackUseRequest(1, 64, 1)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if len(conn.packets) != 3 || len(player.inventory.Items) != 0 || !slices.Equal(player.inventory.LearnedNanos, []uint32{fixture.Program}) {
+ t.Fatal("original crystal did not upload and consume once")
+ }
+ } else {
+ // These two original programs have no ordinary crystal in this catalog.
+ player.inventory.LearnedNanos = []uint32{fixture.Program}
+ if err := world.saveInventory_locked(player, player.inventory); err != nil {
+ t.Fatal(err)
+ }
+ }
+ conn.packets = nil
+ request := characterActionPacket(1, [5]uint32{19, 50000, target.id, 53019, fixture.Program})[20:]
+
+ started := time.Now()
+ if err := world.handleNanoCast(client, request); err != nil {
+ t.Fatal(err)
+ }
+ if client.nanoCast == nil {
+ t.Fatal("qualified learned program was rejected")
+ }
+ deadline := client.nanoCast.readyAt
+ delay := time.Duration(fixture.AttackDelay)*10*time.Millisecond - 25*time.Millisecond
+ if deadline.Before(started.Add(delay-time.Millisecond)) || deadline.After(time.Now().Add(delay+time.Millisecond)) || player.nano != 50000-fixture.Debit {
+ t.Fatal("cast did not use its own delay and reservation", deadline.Sub(started), player.nano)
+ }
+ world.advanceNanos(deadline)
+ if target.health != 100 {
+ t.Fatal("damage arrived before the execution deadline")
+ }
+ world.advanceNanos(deadline.Add(time.Nanosecond))
+ damage, packets := 100-target.health, len(conn.packets)
+ world.advanceNanos(deadline.Add(time.Second))
+ restored := newTestInventoryServer(t)
+
+ if damage < min(100, fixture.Minimum) || damage > min(100, fixture.Maximum) || client.nanoCast != nil || player.fighting != 0 || len(conn.packets) != packets ||
+ player.nano != 50000-fixture.Debit || player.nanoReserved != 0 || restored.characters[1].nano != player.nano ||
+ restored.characters[1000000].health != target.health || !slices.Equal(restored.characters[1].inventory.LearnedNanos, []uint32{fixture.Program}) {
+ t.Fatalf("cast did not commit exactly one complete result: damage=%d player=%+v target=%+v", damage, player, target)
+ }
+ recharge := player.nanoRechargeUntil.Sub(deadline)
+ expectedRecharge := time.Duration(fixture.RechargeDelay) * 10 * time.Millisecond
+ if len(player.activeNanos) != 0 || len(target.activeNanos) != 0 ||
+ recharge < expectedRecharge-time.Millisecond || recharge > expectedRecharge+time.Millisecond {
+ t.Fatal("damage contribution, instant lifecycle or recharge changed")
+ }
+ if target.health == 0 {
+ if target.corpse == nil || target.corpse.looter != 1 || len(target.damageContributors) != 0 {
+ t.Fatal("lethal nano did not finalize corpse ownership")
+ }
+ } else if target.damageContributors[damageContributor{player: 1}] != damage {
+ t.Fatal("nonlethal nano lost its damage contribution")
+ }
+ if binary.BigEndian.Uint32(conn.packets[2][29:33]) != 107 || binary.BigEndian.Uint32(conn.packets[2][45:49]) != fixture.Program ||
+ binary.BigEndian.Uint32(conn.packets[3][16:20]) != 0x4727213e || int32(binary.BigEndian.Uint32(conn.packets[3][29:33])) != -int32(damage) ||
+ binary.BigEndian.Uint32(conn.packets[3][33:37]) != fixture.DamageType {
+ t.Fatal("completion or signed damage used another program's contract")
+ }
+ })
+ }
+}
+
+func TestDirectDamageNanoSkillAndProfessionGatesApplyToUploadAndCast(t *testing.T) {
+ for _, fixture := range directDamageNanoFixtures(t) {
+ for _, skill := range fixture.Skills {
+ for _, passed := range []bool{false, true} {
+ t.Run(fmt.Sprintf("%d/%d/pass=%t", fixture.Program, skill[0], passed), func(t *testing.T) {
+ world, _ := newDirectDamageWorld(t, fixture)
+ player, client := world.characters[1], world.clients[1]
+ for _, field := range player.stats.trainingStats() {
+ if field.stat == skill[0] {
+ *field.value = uint16(skill[1])
+ if passed {
+ *field.value++
+ }
+ }
+ }
+
+ if fixture.Crystal != 0 {
+ if err := world.handleOwnedItemUse(client, backpackUseRequest(1, 64, 1)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if (len(player.inventory.LearnedNanos) == 1) != passed {
+ t.Fatal("crystal ignored an authored skill threshold")
+ }
+ }
+ player.inventory.LearnedNanos = []uint32{fixture.Program}
+ if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, 1000000, 53019, fixture.Program})[20:]); err != nil {
+ t.Fatal(err)
+ }
+
+ if (client.nanoCast != nil) != passed || !passed && player.nano != 50000 || !passed && fixture.Crystal != 0 && len(player.inventory.Items) != 1 {
+ t.Fatal("cast threshold or rejected crystal changed resources")
+ }
+ })
+ }
+ }
+ if fixture.Profession == 0 {
+ continue
+ }
+ t.Run(fmt.Sprintf("%d/profession", fixture.Program), func(t *testing.T) {
+ world, _ := newDirectDamageWorld(t, fixture)
+ player, client := world.characters[1], world.clients[1]
+ player.profession = 1
+
+ if fixture.Crystal != 0 {
+ 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) != 1 {
+ t.Fatal("wrong profession consumed the crystal")
+ }
+ }
+ player.inventory.LearnedNanos = []uint32{fixture.Program}
+ if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, 1000000, 53019, fixture.Program})[20:]); err != nil {
+ t.Fatal(err)
+ }
+
+ if client.nanoCast != nil || player.nano != 50000 {
+ t.Fatal("wrong profession started a cast")
+ }
+ })
+ }
+}
+
+func TestDirectDamageNanoRejectsPartialAndUnverifiedContracts(t *testing.T) {
+ for _, scenario := range []string{"extra effect", "periodic", "interval", "self target", "healing", "reversed range", "nano resource", "nano damage", "conditional effect", "opaque argument", "instant flags", "zero range", "unknown section", "other action"} {
+ t.Run(scenario, func(t *testing.T) {
+ world, conn := newDirectDamageWorld(t, directDamageNanoFixture{Crystal: 28811, Profession: 11})
+ player, client := world.characters[1], world.clients[1]
+ original := gamedata.NanoTemplates[28608]
+ program := *original
+ program.Stats = slices.Clone(original.Stats)
+ program.Sections = slices.Clone(original.Sections)
+ functions := slices.Clone(*program.Sections[2].Functions)
+ functions[0].Arguments = slices.Clone(functions[0].Arguments)
+ program.Sections[2].Functions = &functions
+ switch scenario {
+ case "extra effect":
+ functions = append(functions, gamedata.ItemFunction{ID: 53051})
+ case "periodic":
+ functions[0].TickCount = 2
+ case "interval":
+ functions[0].TickInterval = 100
+ case "self target":
+ functions[0].Target = 2
+ case "healing":
+ value := int32(26)
+ functions[0].Arguments[1].Integer = &value
+ case "reversed range":
+ value := int32(-10)
+ functions[0].Arguments[2].Integer = &value
+ case "nano resource":
+ value := int32(214)
+ functions[0].Arguments[0].Integer = &value
+ case "nano damage":
+ value := int32(168)
+ functions[0].Arguments[3].Integer = &value
+ case "conditional effect":
+ functions[0].Requirements = []gamedata.ItemRequirement{{Stat: 54, Value: 20, Operator: 2}}
+ case "opaque argument":
+ functions[0].Arguments[1].Integer = nil
+ case "instant flags", "zero range":
+ for index, stat := range program.Stats {
+ if scenario == "instant flags" && stat[0] == 0 {
+ program.Stats[index][1] = 0x80088000
+ }
+ if scenario == "zero range" && stat[0] == 287 {
+ program.Stats[index][1] = 0
+ }
+ }
+ case "unknown section":
+ program.Sections = append(program.Sections, gamedata.ItemSection{Type: 99})
+ case "other action":
+ actions := slices.Clone(*program.Sections[3].Actions)
+ actions[0].Type = 7
+ program.Sections[3].Actions = &actions
+ }
+ gamedata.NanoTemplates[28608] = &program
+ t.Cleanup(func() { gamedata.NanoTemplates[28608] = original })
+
+ if err := world.handleOwnedItemUse(client, backpackUseRequest(1, 64, 1)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if len(player.inventory.LearnedNanos) != 0 {
+ t.Fatal("partial program was uploaded")
+ }
+ player.inventory.LearnedNanos = []uint32{28608}
+ if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, 1000000, 53019, 28608})[20:]); err != nil {
+ t.Fatal(err)
+ }
+
+ if client.nanoCast != nil || player.nano != 50000 || player.nanoReserved != 0 || len(player.inventory.Items) != 1 || world.characters[1000000].health != 100 ||
+ len(conn.packets) != 2 || binary.BigEndian.Uint32(conn.packets[0][29:33]) != 2 || binary.BigEndian.Uint32(conn.packets[1][29:33]) != 108 {
+ t.Fatal("unsupported contract consumed a crystal, charged nano or applied a partial effect")
+ }
+ })
+ }
+}
+
+func TestDirectDamageNanoRechecksItsOwnRangeWithoutSpendingOnRejection(t *testing.T) {
+ for _, fixture := range []directDamageNanoFixture{
+ {Program: 26310, Profession: 6, Range: 12},
+ {Program: 28618, Profession: 11, Range: 35},
+ } {
+ for _, scenario := range []string{"boundary", "outside admission", "outside completion"} {
+ t.Run(fmt.Sprintf("%d/%s", fixture.Program, scenario), func(t *testing.T) {
+ world, _ := newDirectDamageWorld(t, fixture)
+ player, target, client := world.characters[1], world.characters[1000000], world.clients[1]
+ player.inventory.LearnedNanos = []uint32{fixture.Program}
+ target.position = [3]float32{float32(fixture.Range), 0, 0}
+ if scenario == "outside admission" {
+ target.position[0] += 0.01
+ }
+
+ if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, target.id, 53019, fixture.Program})[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if scenario != "outside admission" {
+ if client.nanoCast == nil {
+ t.Fatal("exact authored range was rejected")
+ }
+ if scenario == "outside completion" {
+ target.position[0] += 0.01
+ }
+ world.advanceNanos(client.nanoCast.readyAt.Add(time.Nanosecond))
+ }
+
+ if client.nanoCast != nil || player.nanoReserved != 0 {
+ t.Fatal("range outcome left a pending reservation")
+ }
+ if scenario == "boundary" {
+ if target.health != 0 || player.nano == 50000 {
+ t.Fatal("qualified boundary hit did not complete")
+ }
+ } else if target.health != 100 || player.nano != 50000 || !player.nanoRechargeUntil.IsZero() || len(target.damageContributors) != 0 {
+ t.Fatal("rejected range spent resources or damaged the target")
+ }
+ })
+ }
+ }
+}
diff --git a/server/nano_learning.go b/server/nano_learning.go
@@ -6,7 +6,7 @@ import (
"slices"
)
-func statBuffCrystalProgram(template uint32) uint32 {
+func nanoCrystalProgram(template uint32) uint32 {
definition := gamedata.ItemTemplates[template]
if definition == nil || definition.RecordType != 1000020 || definition.HeaderWords[0] != 51005 || definition.Undecoded != nil || definition.Quality == nil ||
itemStat(definition, 30) != 0x29 || itemStat(definition, 26) != 1 {
@@ -41,7 +41,7 @@ func statBuffCrystalProgram(template uint32) uint32 {
return 0
}
program = uint32(*function.Arguments[0].Integer)
- if !statBuffNano(program) {
+ if !statBuffNano(program) && directDamageNano(program) == nil {
return 0
}
}
@@ -61,18 +61,13 @@ func (server *server) learnNano_locked(client *worldClient, index int, body []by
accepted = accepted && item.Quality == 1 && player.profession == 10 &&
player.effectiveSkill(128, stats.NanoAiding.BiologicalMetamorphosis, [6]uint32{0, 0, 0, 80, 0, 20}) > 8 &&
player.effectiveSkill(127, stats.NanoAiding.MatterMetamorphosis, [6]uint32{0, 0, 0, 80, 0, 20}) > 6
- case 29625:
- program = 29618
- accepted = accepted && item.Quality == 1 && player.profession == 8 &&
- player.effectiveSkill(130, stats.NanoAiding.MatterCreation, [6]uint32{0, 0, 20, 80, 0, 0}) > 7 &&
- player.effectiveSkill(129, stats.NanoAiding.PsychologicalModification, [6]uint32{0, 0, 0, 80, 20, 0}) > 8
case 43330:
program = 43324
accepted = accepted && item.Quality == 1 && player.profession == 12 &&
player.effectiveSkill(130, stats.NanoAiding.MatterCreation, [6]uint32{0, 0, 20, 80, 0, 0}) > 7 &&
player.effectiveSkill(131, stats.NanoAiding.TimeAndSpace, [6]uint32{0, 20, 0, 80, 0, 0}) > 7
default:
- program = statBuffCrystalProgram(item.Template)
+ program = nanoCrystalProgram(item.Template)
accepted = accepted && program != 0 && item.Quality == *gamedata.ItemTemplates[item.Template].Quality &&
player.templateUseRequirementsMet(gamedata.ItemTemplates[item.Template])
}
diff --git a/server/stat_buff_catalog_test.go b/server/stat_buff_catalog_test.go
@@ -64,7 +64,7 @@ func TestStatBuffCatalogAdmitsOnlyCompleteOrdinaryContracts(t *testing.T) {
}
}
for crystal := range gamedata.ItemTemplates {
- if statBuffCrystalProgram(crystal) != 0 {
+ if statBuffNano(nanoCrystalProgram(crystal)) {
crystals = append(crystals, crystal)
}
}
diff --git a/server/testdata/direct-damage-nanos.json b/server/testdata/direct-damage-nanos.json
@@ -0,0 +1,35 @@
+[
+ {"program": 26310, "crystal": 0, "quality": 0, "profession": 6, "minimum": 116, "maximum": 203, "damage_type": 95, "nano_cost": 241, "debit": 240, "attack_delay": 65, "recharge_delay": 493, "range": 12, "skills": [[130, 266]]},
+ {"program": 27114, "crystal": 0, "quality": 0, "profession": 0, "minimum": 14, "maximum": 22, "damage_type": 92, "nano_cost": 53, "debit": 52, "attack_delay": 52, "recharge_delay": 319, "range": 14, "skills": [[130, 27]]},
+ {"program": 28592, "crystal": 28842, "quality": 113, "profession": 11, "minimum": 417, "maximum": 905, "damage_type": 90, "nano_cost": 170, "debit": 169, "attack_delay": 356, "recharge_delay": 300, "range": 25, "skills": [[130, 525]]},
+ {"program": 28598, "crystal": 28801, "quality": 139, "profession": 11, "minimum": 314, "maximum": 767, "damage_type": 92, "nano_cost": 194, "debit": 193, "attack_delay": 139, "recharge_delay": 354, "range": 25, "skills": [[130, 638]]},
+ {"program": 28601, "crystal": 28804, "quality": 10, "profession": 11, "minimum": 17, "maximum": 30, "damage_type": 93, "nano_cost": 12, "debit": 11, "attack_delay": 126, "recharge_delay": 258, "range": 25, "skills": [[130, 57]]},
+ {"program": 28605, "crystal": 28808, "quality": 53, "profession": 11, "minimum": 209, "maximum": 448, "damage_type": 92, "nano_cost": 100, "debit": 99, "attack_delay": 500, "recharge_delay": 252, "range": 25, "skills": [[130, 257]]},
+ {"program": 28607, "crystal": 28810, "quality": 27, "profession": 11, "minimum": 38, "maximum": 92, "damage_type": 97, "nano_cost": 31, "debit": 30, "attack_delay": 276, "recharge_delay": 107, "range": 25, "skills": [[130, 142]]},
+ {"program": 28608, "crystal": 28811, "quality": 7, "profession": 11, "minimum": 26, "maximum": 46, "damage_type": 97, "nano_cost": 15, "debit": 14, "attack_delay": 327, "recharge_delay": 208, "range": 25, "skills": [[130, 51]]},
+ {"program": 28609, "crystal": 28812, "quality": 96, "profession": 11, "minimum": 186, "maximum": 503, "damage_type": 95, "nano_cost": 135, "debit": 134, "attack_delay": 136, "recharge_delay": 327, "range": 25, "skills": [[130, 451]]},
+ {"program": 28611, "crystal": 28814, "quality": 14, "profession": 11, "minimum": 33, "maximum": 53, "damage_type": 97, "nano_cost": 17, "debit": 16, "attack_delay": 328, "recharge_delay": 211, "range": 25, "skills": [[130, 68]]},
+ {"program": 28614, "crystal": 28817, "quality": 70, "profession": 11, "minimum": 120, "maximum": 283, "damage_type": 96, "nano_cost": 77, "debit": 76, "attack_delay": 297, "recharge_delay": 118, "range": 25, "skills": [[130, 323]]},
+ {"program": 28618, "crystal": 28821, "quality": 212, "profession": 11, "minimum": 4118, "maximum": 8907, "damage_type": 94, "nano_cost": 1079, "debit": 1078, "attack_delay": 2000, "recharge_delay": 800, "range": 35, "skills": [[130, 999]]},
+ {"program": 28619, "crystal": 28822, "quality": 185, "profession": 11, "minimum": 2834, "maximum": 4739, "damage_type": 92, "nano_cost": 635, "debit": 634, "attack_delay": 800, "recharge_delay": 850, "range": 25, "skills": [[130, 861]]},
+ {"program": 28621, "crystal": 28824, "quality": 80, "profession": 11, "minimum": 259, "maximum": 538, "damage_type": 92, "nano_cost": 110, "debit": 109, "attack_delay": 347, "recharge_delay": 270, "range": 25, "skills": [[130, 377]]},
+ {"program": 28623, "crystal": 28826, "quality": 185, "profession": 11, "minimum": 1050, "maximum": 2569, "damage_type": 96, "nano_cost": 306, "debit": 305, "attack_delay": 400, "recharge_delay": 394, "range": 30, "skills": [[130, 855]]},
+ {"program": 28626, "crystal": 28829, "quality": 123, "profession": 11, "minimum": 252, "maximum": 665, "damage_type": 92, "nano_cost": 170, "debit": 169, "attack_delay": 138, "recharge_delay": 344, "range": 25, "skills": [[130, 566]]},
+ {"program": 28627, "crystal": 28830, "quality": 37, "profession": 11, "minimum": 104, "maximum": 189, "damage_type": 97, "nano_cost": 85, "debit": 84, "attack_delay": 335, "recharge_delay": 233, "range": 25, "skills": [[130, 174]]},
+ {"program": 28628, "crystal": 28831, "quality": 50, "profession": 11, "minimum": 85, "maximum": 212, "damage_type": 92, "nano_cost": 66, "debit": 65, "attack_delay": 131, "recharge_delay": 293, "range": 25, "skills": [[130, 240]]},
+ {"program": 28630, "crystal": 28833, "quality": 30, "profession": 11, "minimum": 38, "maximum": 113, "damage_type": 96, "nano_cost": 36, "debit": 35, "attack_delay": 128, "recharge_delay": 275, "range": 25, "skills": [[130, 152]]},
+ {"program": 28632, "crystal": 28835, "quality": 99, "profession": 11, "minimum": 244, "maximum": 442, "damage_type": 94, "nano_cost": 114, "debit": 113, "attack_delay": 314, "recharge_delay": 126, "range": 22, "skills": [[130, 460]]},
+ {"program": 28634, "crystal": 28837, "quality": 66, "profession": 11, "minimum": 111, "maximum": 287, "damage_type": 91, "nano_cost": 85, "debit": 84, "attack_delay": 132, "recharge_delay": 303, "range": 25, "skills": [[130, 310]]},
+ {"program": 28639, "crystal": 28795, "quality": 33, "profession": 11, "minimum": 93, "maximum": 167, "damage_type": 97, "nano_cost": 45, "debit": 44, "attack_delay": 334, "recharge_delay": 230, "range": 25, "skills": [[130, 162]]},
+ {"program": 28667, "crystal": 28780, "quality": 7, "profession": 10, "minimum": 16, "maximum": 29, "damage_type": 91, "nano_cost": 13, "debit": 12, "attack_delay": 265, "recharge_delay": 102, "range": 25, "skills": [[128, 51], [130, 43]]},
+ {"program": 29618, "crystal": 29625, "quality": 1, "profession": 8, "minimum": 10, "maximum": 23, "damage_type": 95, "nano_cost": 10, "debit": 9, "attack_delay": 261, "recharge_delay": 100, "range": 25, "skills": [[129, 8], [130, 7]]},
+ {"program": 30068, "crystal": 30113, "quality": 37, "profession": 8, "minimum": 97, "maximum": 241, "damage_type": 90, "nano_cost": 68, "debit": 67, "attack_delay": 337, "recharge_delay": 237, "range": 25, "skills": [[130, 166], [129, 190]]},
+ {"program": 30082, "crystal": 30127, "quality": 169, "profession": 8, "minimum": 863, "maximum": 2341, "damage_type": 91, "nano_cost": 346, "debit": 345, "attack_delay": 400, "recharge_delay": 377, "range": 25, "skills": [[130, 729], [129, 802]]},
+ {"program": 30083, "crystal": 30128, "quality": 50, "profession": 8, "minimum": 145, "maximum": 409, "damage_type": 91, "nano_cost": 103, "debit": 102, "attack_delay": 400, "recharge_delay": 251, "range": 25, "skills": [[130, 225], [129, 251]]},
+ {"program": 30091, "crystal": 30136, "quality": 109, "profession": 8, "minimum": 264, "maximum": 532, "damage_type": 91, "nano_cost": 132, "debit": 131, "attack_delay": 320, "recharge_delay": 129, "range": 25, "skills": [[129, 525], [130, 478]]},
+ {"program": 42539, "crystal": 42547, "quality": 7, "profession": 11, "minimum": 24, "maximum": 43, "damage_type": 93, "nano_cost": 14, "debit": 13, "attack_delay": 327, "recharge_delay": 206, "range": 25, "skills": [[130, 40]]},
+ {"program": 42540, "crystal": 42546, "quality": 17, "profession": 11, "minimum": 47, "maximum": 75, "damage_type": 90, "nano_cost": 24, "debit": 23, "attack_delay": 330, "recharge_delay": 215, "range": 25, "skills": [[130, 88]]},
+ {"program": 42541, "crystal": 42545, "quality": 17, "profession": 11, "minimum": 44, "maximum": 69, "damage_type": 91, "nano_cost": 22, "debit": 21, "attack_delay": 329, "recharge_delay": 214, "range": 25, "skills": [[130, 83]]},
+ {"program": 42542, "crystal": 42548, "quality": 10, "profession": 11, "minimum": 45, "maximum": 61, "damage_type": 96, "nano_cost": 21, "debit": 20, "attack_delay": 550, "recharge_delay": 209, "range": 25, "skills": [[130, 57]]},
+ {"program": 42543, "crystal": 42544, "quality": 20, "profession": 11, "minimum": 54, "maximum": 95, "damage_type": 95, "nano_cost": 28, "debit": 27, "attack_delay": 331, "recharge_delay": 218, "range": 25, "skills": [[130, 103]]}
+]