commit a3b3b4ac2d5ca75f29ac1d9569d8da43fffdf8e9
parent 4c434ca116c897d665acb6cefc7aeff616082f25
Author: anon <anon@example.com>
Date: Thu, 22 Oct 2026 08:02:25 +0000
Use an explicit combat profile for level 1 Leets
Diffstat:
15 files changed, 298 insertions(+), 16 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -84,6 +84,9 @@ recorded in [inventory behavior](docs/inventory.md).
positions and sizes are accepted or rejected at the recovered range boundary.
- [ ] Reject attacks through one solid obstruction. Check: the same stationary
encounter works in the open and fails with a wall between the actors.
+- [ ] Reconcile quiet health without phantom damage feedback. Check: after a
+ long native fight, prediction drift is corrected to server HP without extra
+ nanobot-damage chat or floating damage, including for an observer.
## Additional weapon actions
@@ -104,7 +107,7 @@ recorded in [inventory behavior](docs/inventory.md).
## NPC profiles and behavior
-- [ ] Give one creature at one level an explicit combat profile. Check: its
+- [x] Give one creature at one level an explicit combat profile. Check: its
health, weapon and timing come from that profile rather than universal values;
each value is identified as verified or provisional.
- [ ] Give that species a second level. Check: the two levels have independently
diff --git a/docs/combat-client-reconstruction.md b/docs/combat-client-reconstruction.md
@@ -78,7 +78,7 @@ unknowns for each area:
| QL 1 fist damage endpoints | Shipped item record | Normal uniform 3-5 roll; distribution and always-hit policy are local |
| Player max/current health and nano | Native formula, breed/title resources, browser 37/37 | Derived from editable abilities and base Body Development/Nano Pool; Soldier profession |
| Martial Arts selecting fist QL | Period observation; exact native selector not found | Fixed QL 1, not a recovered MA-to-QL selection rule |
-| NPC health, damage and weapons | Historical per-species profiles unresolved | Local 100 HP, 5 damage, 1s/1s phases |
+| NPC health, damage and weapons | Level-1 Leet weapon data verified; binding and actor stats provisional | Exact-level Leet profile with replicated bite weapon; other NPCs retain prototype values |
| Armor, evade/critical rolls and damage modifiers | Client data/handlers do not alone establish authoritative calculation | Not implemented |
| Range and physical extents | Native formula recovered; instance extent construction needs full reconciliation | Four-meter center-distance approximation |
| Line of sight | Client checks cannot establish original server validation | Not implemented on the server |
diff --git a/docs/combat-npc-balance.md b/docs/combat-npc-balance.md
@@ -2,7 +2,8 @@
The local wiki database provides useful weapon and behavior leads, but it does
not supply a complete set of historical creature health, ratings and armor.
-The server's universal 100 HP and 5 damage remain prototype values.
+The server has an explicit level-1 Leet profile below. Other creatures retain
+prototype 100 HP, 5 damage and one-second attack/recharge phases.
## Local wiki search
@@ -32,11 +33,13 @@ Exact records are retained in `local/reports/leet-bite-1491-records.json`.
| Templates | QL endpoints | Base damage | Critical bonus | Base attack/recharge |
| --- | --- | --- | --- | --- |
-| LeetBite1, 120910 / 120911 | 1 / 400 | 4-8 / 94-406 | 4 / 55 | 175 / 175 centiseconds |
-| LeetBite2, 120913 / 120914 | 1 / 400 | 4-8 / 94-406 | 4 / 55 | 175 / 175 centiseconds |
-| RagingLeetBite, 171193 / 171200 | 1 / 400 | 12-21 / 585-1008 | 12 / 520 | 80 / 80 centiseconds |
+| LeetBite1, 120910 / 120911 | 1 / 400 | 4-8 / 55-406 | 4 / 94 | 175 / 175 centiseconds |
+| LeetBite2, 120913 / 120914 | 1 / 400 | 4-8 / 55-406 | 4 / 94 | 175 / 175 centiseconds |
+| RagingLeetBite, 171193 / 171200 | 1 / 400 | 12-21 / 520-1008 | 12 / 585 | 80 / 80 centiseconds |
-Damage stat IDs are minimum 284, maximum 285 and critical bonus 286. Delay
+Damage stat IDs are minimum 286, maximum 285 and critical bonus 284. The native
+stat-name initializer `kkr.dll` `sub_36031700` binds these IDs at
+0x360339DF, 0x36033A1C and 0x36033A4E. Delay
294 is attack, 210 recharge, 287 range, and 436 damage type. All six endpoint
records use range 2 and damage type 91 (MeleeAC). Section 12 weights Martial
Arts 100 at 100%; section 13 weights Evade Close 155 at 100%. The two ordinary
@@ -51,6 +54,53 @@ receives it, which hand/variant it uses, or whether the historical server had
additional overrides. Applying 4-8 as a universal NPC damage roll would replace
one unsupported rule with another.
+## Active level-1 Leet profile
+
+`server/gamedata/npc_combat.yaml` selects only MonsterData 17655 at level 1.
+The spawner binds that exact profile and initializes health from it; other
+species and levels retain their existing prototype behavior. Catalog loading
+rejects missing species, missing or mismatched exact-QL weapons, zero health,
+and AggDef outside -100..100.
+
+| Value | Selected setting | Evidence status |
+| --- | --- | --- |
+| Maximum health | 100 | Provisional, retained pending a historical measurement |
+| Weapon | LeetBite1_001, 120910, QL 1 | Shipped definition verified; binding and choice of variant provisional |
+| Normal damage endpoints | 4-8 | Verified weapon values; uniform always-hit roll and omission of rating/armor remain local |
+| Initiative | 0 | Provisional actor value |
+| AggDef | 75 | Provisional actor value |
+| Attack/recharge phases | 1.75s / 1.75s | Derived from the shipped 175 cs delays and the selected initiative/AggDef using the recovered timing formula |
+
+The first bite lands after the attack phase; subsequent bites are 3.5 seconds
+apart before world-tick quantization. Range still uses the existing four-metre
+approximation rather than the weapon's two-metre range with physical extents.
+Health, hit distribution, effective ratings, armor and original spawn binding
+remain gaps in canonical balance; the profile does not make those values
+historically verified.
+
+The native `SimpleCharFullUpdate` includes the selected weapon endpoints and
+QL in its initial weapon list. `SpecialAttackWeapon` (`0x1d3c0f1c`) follows the
+spawn, carrying the same list and the five initiative/AggDef values. Native
+`sub_36083F00` reads the list and stats; `sub_36083FB0` applies them to an NPC.
+Its holder keeps an already populated initial list, so sending only the later
+update would retain fists. `sub_3607B9A0` binds the NPC weapon into combat slot
+0 using the actor's level. The four list fields are low template, high template,
+holder slot 100, and QL. Ordinary player fists retain their existing list.
+
+`server/npc_combat_test.go` checks native initialization and restart, initial
+weapon selection, the first and subsequent deadlines, normal damage bounds,
+slot-0 hit packets and identical results for two observers. Separate cases
+retain prototype behavior for another species, level 7 and extended level 300.
+
+Published WASM checks with an attacker and an independent observer confirmed
+template 120910/120910, QL 1 and holder slot 100 in both native heaps. A real
+100-HP fight recorded 26 bites spanning damage 4..8, with 3.5..3.75-second
+intervals under the world tick. Both clients displayed matching damage and the
+fallen Leet, then reconnected after a server restart with the profile still
+selected and fresh NPC health. Evidence is retained in `local/npc-profile-smoke/`.
+The long fight also exposed phantom nanobot-damage text from existing quiet
+health corrections; that synchronization issue is recorded separately in TODO.
+
## Online search and limits
The web search cross-checked the Leets page and searched exact leet health/HP
diff --git a/docs/combat-rules.md b/docs/combat-rules.md
@@ -36,8 +36,10 @@ Its three skill requirements, 1.5-second equip delay, persistent right-hand slot
and native owner/observer replication are described in
[inventory and equipment](inventory.md). Combat swapping is not implemented.
-The server still selects QL 1 regardless of MA skill, omits hit/critical
-rolls and armor, and uses NPC 100 health and 5 damage with 1s/1s timing.
+The server still selects QL 1 regardless of MA skill and omits hit/critical
+rolls and armor. Level-1 Leets use an explicit catalog-weapon profile;
+other NPCs retain 100 health, 5 damage and 1s/1s timing. Profile settings
+and their verified/provisional status are recorded in [NPC balance](combat-npc-balance.md).
The uniform normal-damage roll is a reconstruction choice; the item establishes
the endpoints, not the historical server's random distribution. The four-meter
range approximates physical extents, and there is no server line-of-sight
diff --git a/server/combat.go b/server/combat.go
@@ -86,6 +86,9 @@ func weaponDelays(weapon *gamedata.Item, initiative, aggDef int32) (time.Duratio
func (character *character) attackDelays() (time.Duration, time.Duration) {
if character.npc {
+ if character.combatProfile != nil {
+ return weaponDelays(character.meleeWeapon(), character.combatProfile.Initiative, character.combatProfile.AggDef)
+ }
return time.Second, time.Second
}
stats := character.baseStats()
@@ -110,6 +113,9 @@ func (character *character) titleLevel() uint32 {
func (character *character) maximumHealth() uint32 {
if character.npc {
+ if character.combatProfile != nil {
+ return character.combatProfile.Health
+ }
return 100
}
// kkr.dll FUN_10075910; breed resources 1000203, Soldier titles 1000200/1.
@@ -219,11 +225,11 @@ func (server *server) advanceCombat(now time.Time) {
// Shipped QL 1 fists have 3..5 base damage; NPC profiles remain local.
damage := rand.Uint32N(3) + 3
- if attacker.npc {
- damage = 5
- } else if weapon := attacker.meleeWeapon(); weapon != nil {
+ if weapon := attacker.meleeWeapon(); weapon != nil {
minimum, maximum := itemStat(weapon, 286), itemStat(weapon, 285)
damage = minimum + rand.Uint32N(maximum-minimum+1)
+ } else if attacker.npc {
+ damage = 5
}
damage = min(damage, target.health)
target.health -= damage
@@ -285,7 +291,7 @@ func hitPacket(attacker, target *character, damage uint32) []byte {
// kkr.dll 0x100aec00: damage, ammo, slot, target identity, death reason and result.
body := binary.BigEndian.AppendUint32(nil, damage)
slot := uint32(0)
- if attacker.meleeWeapon() != nil {
+ if !attacker.npc && attacker.meleeWeapon() != nil {
slot = 6
}
for _, value := range []uint32{0xffffffff, slot, 50000, target.id, 0, 4} {
diff --git a/server/equipment.go b/server/equipment.go
@@ -21,6 +21,9 @@ func (item ownedItem) isKineticAxe() bool {
}
func (character *character) meleeWeapon() *gamedata.Item {
+ if character.npc && character.combatProfile != nil {
+ return gamedata.ItemTemplates[character.combatProfile.Weapon]
+ }
for _, item := range character.inventory.Items {
if item.Slot == 6 && item.isKineticAxe() {
return gamedata.ItemTemplates[item.Template]
diff --git a/server/gamedata/load.go b/server/gamedata/load.go
@@ -15,6 +15,7 @@ var files embed.FS
var (
NPCs NPCData
+ NPCCombatProfiles map[uint32]map[uint16]*NPCCombatProfile
NPCNames NPCNameData
NPCGroups = make(map[string]*NPCGroup)
PopulationSources []*NPCPopulationSource
@@ -118,6 +119,19 @@ func init() {
ItemTemplates[Items.Items[index].ID] = &Items.Items[index]
}
}
+
+ // Combat profiles bind only exact levels to existing catalog weapons.
+ loadYAML("npc_combat.yaml", &NPCCombatProfiles)
+ for monster, levels := range NPCCombatProfiles {
+ for level, profile := range levels {
+ weapon := ItemTemplates[profile.Weapon]
+ if MonsterTemplates[monster] == nil || level == 0 || profile.Health == 0 ||
+ weapon == nil || weapon.Quality == nil || *weapon.Quality != uint32(level) ||
+ profile.AggDef < -100 || profile.AggDef > 100 {
+ panic(fmt.Errorf("NPC combat profile %d/%d has invalid health, weapon or AggDef", monster, level))
+ }
+ }
+ }
}
func loadYAML(name string, value any) {
diff --git a/server/gamedata/npc_combat.yaml b/server/gamedata/npc_combat.yaml
@@ -0,0 +1,11 @@
+# Exact MonsterData and level; unlisted creatures retain prototype combat.
+17655:
+ 1:
+ # Provisional health; no historical level-1 Leet HP measurement recovered.
+ health: 100
+ # Shipped QL 1 LeetBite1_001. Choosing this variant for this spawn is provisional.
+ # Base damage 4..8 and attack/recharge 175 cs are verified item data.
+ weapon: 120910
+ # Provisional actor settings. Together they retain the weapon's base delays.
+ initiative: 0
+ agg_def: 75
diff --git a/server/gamedata/types.go b/server/gamedata/types.go
@@ -14,6 +14,13 @@ type NPCData struct {
Playfields []NPCPlayfield `yaml:"playfields"`
}
+type NPCCombatProfile struct {
+ Health uint32 `yaml:"health"`
+ Weapon uint32 `yaml:"weapon"`
+ Initiative int32 `yaml:"initiative"`
+ AggDef int32 `yaml:"agg_def"`
+}
+
type NPCPlayfield struct {
Source *NPCPopulationSource `json:"-" yaml:"source"`
ID uint32 `yaml:"id"`
diff --git a/server/interest.go b/server/interest.go
@@ -43,6 +43,9 @@ func (server *server) updateNPCInterest_locked(client *worldClient, now time.Tim
updates = append(updates, corpsePacket(other))
} else {
updates = append(updates, characterPacket(other))
+ if other.combatProfile != nil {
+ updates = append(updates, npcCombatPacket(other))
+ }
if other.health == 0 {
updates = append(updates, deathPacket(other))
}
diff --git a/server/npc_combat.go b/server/npc_combat.go
@@ -0,0 +1,13 @@
+package main
+
+import "encoding/binary"
+
+func npcCombatPacket(character *character) []byte {
+ // kkr.dll sub_36083F00/sub_36083FB0: weapon list, initiatives and AggDef.
+ var body []byte
+ for _, value := range []uint32{2018, character.combatProfile.Weapon, character.combatProfile.Weapon, 100, uint32(character.level),
+ uint32(character.combatProfile.Initiative), 0, 0, 0, uint32(character.combatProfile.AggDef)} {
+ body = binary.BigEndian.AppendUint32(body, value)
+ }
+ return n3Packet(0x1d3c0f1c, 50000, character.id, body)
+}
diff --git a/server/npc_combat_test.go b/server/npc_combat_test.go
@@ -0,0 +1,155 @@
+package main
+
+import (
+ "bytes"
+ "encoding/binary"
+ "encoding/hex"
+ "net"
+ "testing"
+ "time"
+)
+
+func TestNPCProfileNativeSpawnUsesLeetBiteAfterRestart(t *testing.T) {
+ data := testNPCData()
+ data.Playfields[0].Districts[0].Groups[0].Level = 1
+ useNPCData(t, data)
+ world := newTestServer(t)
+ if err := world.saveUser_locked(world.newCharacter()); err != nil {
+ t.Fatal(err)
+ }
+
+ for range 2 {
+ client, connection := net.Pipe()
+ client.SetDeadline(time.Now().Add(5 * time.Second))
+ done := make(chan error, 1)
+ go func() { defer connection.Close(); done <- world.serveWorldConnection(connection) }()
+ cookie, _ := hex.DecodeString("dfdf00010001002000000001000000020000001b000000010000000000000000")
+ client.Write(cookie)
+ var weapon []byte
+ spawned := false
+ for {
+ packet, err := readPacket(client)
+ if err != nil {
+ client.Close()
+ t.Fatal(err)
+ }
+ key := binary.BigEndian.Uint32(packet[16:20])
+ if key == 0x271b3a6b && binary.BigEndian.Uint32(packet[24:28]) == 1000000 {
+ spawned = true
+ end := int(binary.BigEndian.Uint16(packet[6:8]))
+ if hex.EncodeToString(packet[end-20:end]) != "000007e20001d84e0001d84e0000006400000001" {
+ client.Close()
+ t.Fatalf("initial native Leet Bite weapon: %x", packet[end-20:end])
+ }
+ }
+ if key == 0x1d3c0f1c {
+ if !spawned {
+ client.Close()
+ t.Fatal("weapon arrived before its NPC")
+ }
+ weapon = packet
+ }
+ if key == 0x5f52412e {
+ break
+ }
+ }
+ client.Close()
+ if err := <-done; err != nil {
+ t.Fatal(err)
+ }
+
+ if len(weapon) == 0 || binary.BigEndian.Uint32(weapon[24:28]) != 1000000 ||
+ hex.EncodeToString(weapon[29:69]) != "000007e20001d84e0001d84e0000006400000001000000000000000000000000000000000000004b" {
+ t.Fatalf("native Leet Bite profile: %x", weapon)
+ }
+ if world.characters[1000000].health != 100 {
+ t.Fatal("profile did not initialize the NPC's health")
+ }
+ world = newServer()
+ }
+}
+
+func TestNPCProfileCombatUsesCatalogTimingAndDamageForBothObservers(t *testing.T) {
+ data := testNPCData()
+ data.Playfields[0].Districts[0].Groups[0].Level = 1
+ useNPCData(t, data)
+ world := newTestServer(t)
+ player := world.newCharacter()
+ observer := world.newCharacter()
+ first, second := &combatTestConn{}, &combatTestConn{}
+ world.clients[player.id] = &worldClient{id: player.id, conn: first, target: true, ready: true, npcs: map[uint32]bool{1000000: true}}
+ world.clients[observer.id] = &worldClient{id: observer.id, conn: second, target: true, ready: true, npcs: map[uint32]bool{1000000: true}}
+ npc := world.characters[1000000]
+
+ if err := world.handleCombat(world.clients[player.id], attackPacket(player.id, npc.id)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ start := player.nextAttack
+ world.advanceCombat(start)
+ if npc.nextAttack != start.Add(1750*time.Millisecond) {
+ t.Fatalf("Leet Bite attack deadline: %v", npc.nextAttack.Sub(start))
+ }
+ world.advanceCombat(start.Add(1750*time.Millisecond - time.Nanosecond))
+ if player.health != 37 {
+ t.Fatal("Leet Bite landed before its attack phase ended")
+ }
+ world.advanceCombat(start.Add(1750 * time.Millisecond))
+ if npc.nextAttack != start.Add(5250*time.Millisecond) {
+ t.Fatalf("Leet Bite recharge and next attack: %v", npc.nextAttack.Sub(start))
+ }
+ world.advanceCombat(start.Add(5250 * time.Millisecond))
+
+ var damage []uint32
+ for index, packet := range first.packets {
+ if len(second.packets) <= index || !bytes.Equal(packet[16:], second.packets[index][16:]) {
+ t.Fatal("observers received different combat results")
+ }
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x46002f16 && binary.BigEndian.Uint32(packet[24:28]) == npc.id {
+ damage = append(damage, binary.BigEndian.Uint32(packet[29:33]))
+ if damage[len(damage)-1] < 4 || damage[len(damage)-1] > 8 || binary.BigEndian.Uint32(packet[37:41]) != 0 {
+ t.Fatalf("Leet Bite damage or native slot: %x", packet)
+ }
+ }
+ }
+ if len(damage) != 2 || len(second.packets) != len(first.packets) || player.health != 37-damage[0]-damage[1] {
+ t.Fatalf("Leet Bite results: %v, health %d", damage, player.health)
+ }
+}
+
+func TestNPCProfileDoesNotApplyToOtherLevelsOrSpecies(t *testing.T) {
+ for _, scenario := range []struct {
+ name string
+ monster uint32
+ level uint16
+ }{
+ {"other level", 17655, 7},
+ {"extended level", 17655, 300},
+ {"other species", 17627, 1},
+ } {
+ t.Run(scenario.name, func(t *testing.T) {
+ data := testNPCData()
+ data.Playfields[0].Districts[0].Groups[0].MonsterData = scenario.monster
+ data.Playfields[0].Districts[0].Groups[0].Level = scenario.level
+ useNPCData(t, data)
+ world := newTestServer(t)
+ player := world.newCharacter()
+ conn := &combatTestConn{}
+ world.clients[player.id] = &worldClient{id: player.id, conn: conn, target: true, ready: true, npcs: map[uint32]bool{1000000: true}}
+
+ world.handleCombat(world.clients[player.id], attackPacket(player.id, 1000000)[20:])
+ start := player.nextAttack
+ world.advanceCombat(start)
+ world.advanceCombat(start.Add(time.Second))
+ world.clients[player.id].send(characterPacket(world.characters[1000000]))
+
+ if player.health != 32 || world.characters[1000000].nextAttack != start.Add(3*time.Second) {
+ t.Fatal("a Leet profile changed an unlisted creature's prototype behavior")
+ }
+ packet := conn.packets[len(conn.packets)-1]
+ end := int(binary.BigEndian.Uint16(packet[6:8]))
+ if hex.EncodeToString(packet[end-20:end]) != "000007e20000aac00000aac10000006400000001" {
+ t.Fatal("an unlisted creature received the Leet Bite template")
+ }
+ })
+ }
+}
diff --git a/server/npcs.go b/server/npcs.go
@@ -26,9 +26,11 @@ func readNPCSpawns() ([]character, error) {
spawn := character{
id: 1000000 + uint32(len(spawns)), name: group.Name,
playfield: playfield.ID, position: position, rotation: [4]float32{0, 0, 0, 1},
- appearance: group.Appearance, monsterData: group.MonsterData, level: group.Level, npc: true, health: 100,
+ appearance: group.Appearance, monsterData: group.MonsterData, level: group.Level, npc: true,
+ combatProfile: gamedata.NPCCombatProfiles[group.MonsterData][group.Level],
npcDefinitionID: group.ID,
}
+ spawn.health = spawn.maximumHealth()
// Fixed posts and human placeholders have no inferred roaming behavior.
if group.PlacementStatus != "fixed_point" && group.Appearance>>4&7 == 6 {
spawn.roaming = &npcRoaming{home: position}
diff --git a/server/state.go b/server/state.go
@@ -1,6 +1,7 @@
package main
import (
+ "ao/server/gamedata"
"encoding/binary"
"fmt"
"log"
@@ -22,6 +23,7 @@ type character struct {
stats characterStats
inventory playerInventory
corpse *npcCorpse
+ combatProfile *gamedata.NPCCombatProfile
health uint32
nano uint32
sitting bool
diff --git a/server/target_protocol.go b/server/target_protocol.go
@@ -1,6 +1,7 @@
package main
import (
+ "ao/server/gamedata"
"bytes"
"encoding/binary"
"time"
@@ -59,13 +60,23 @@ func targetPacket(packet []byte) []byte {
tail = append([]byte(nil), packet[len(packet)-4:]...)
packet = append(packet[:len(packet)-4], 0, 0, 0)
packet = append(packet, tail...)
- // Supply the client's unarmed weapon in slot 0 for hit animation and damage.
+ // Supply the initial weapon before the native holder binds slot 0.
+ weaponLow, weaponHigh, weaponQuality := uint32(43712), uint32(43713), uint32(1)
if flags&1 != 0 {
// Tab targeting requires NPC stat 194 (InPlay), supplied by flag bit 1.
flags |= 2
+ level := uint16(packet[nameEnd])
+ monsterOffset := nameEnd + 9
+ if flags&0x1000 != 0 {
+ level = binary.BigEndian.Uint16(packet[nameEnd:])
+ monsterOffset++
+ }
+ if profile := gamedata.NPCCombatProfiles[binary.BigEndian.Uint32(packet[monsterOffset:])][level]; profile != nil {
+ weaponLow, weaponHigh, weaponQuality = profile.Weapon, profile.Weapon, uint32(level)
+ }
}
binary.BigEndian.PutUint32(packet[37:41], flags|0x100)
- for _, value := range []uint32{2018, 43712, 43713, 100, 1} {
+ for _, value := range []uint32{2018, weaponLow, weaponHigh, 100, weaponQuality} {
packet = binary.BigEndian.AppendUint32(packet, value)
}
case 0x29304349: