aorecomp

Anarchy Online classic in the browser

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


commit 28f6bdce2124d70b13f36ca18f816fcbe8203b8b
parent 45899e1bc930d524df90c074e9df8e173e31012a
Author: anon <anon@example.com>
Date:   Sat, 24 Oct 2026 16:47:32 +0000

Persist experience and initialize native XP boundaries

Diffstat:
MTODO.md | 7+++++++
Mdocs/character-progression.md | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
Mserver/control.go | 2+-
Mserver/database.go | 4++--
Aserver/gamedata/experience.yaml | 205+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/gamedata/load.go | 2++
Mserver/profile_database.go | 4++--
Aserver/progression_test.go | 175+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/state.go | 1+
Mserver/target_protocol_test.go | 4++--
Mserver/users.go | 13+++++++++----
Mserver/world.go | 12+++++++++++-
Mserver/world.sql | 1+
13 files changed, 488 insertions(+), 22 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -340,6 +340,13 @@ Known-amount credit collection and native balance limits are verified in ## Character progression +- [x] Persist current-level XP and initialize the native experience bar. Check: + control edits, position checkpoints, reconnect, restart and rejected saves + preserve progress; initialization supplies cumulative XP/LastXP/NextXP without + treating login as an award. See [character progression](docs/character-progression.md). +- [ ] Verify the remaining original 14.9.1 level thresholds. The first 26 have + independent source support; later requirements use provisional CellAO cumulative + boundaries. Resolve its level-165 column conflict with original-server evidence. - [ ] Award XP for one creature kill. Check: the eligible killer gains one known reward exactly once; the total survives restart. Include the Pioneer backpack's XPModifier, removal, rounding and eligibility rules; displaying that modifier diff --git a/docs/character-progression.md b/docs/character-progression.md @@ -1,9 +1,70 @@ # Character progression: 14.9.1 protocol evidence -Kill XP and level advancement remain unimplemented. Native -[IP spending](ip-training.md) now persists validated skill/ability purchases. -This report recovers the native presentation contract; the replay values below are test -inputs, not historical creature rewards. +Character XP now persists in SQLite and initializes the native experience bar. +Kill awards and automatic level advancement remain unimplemented. Native +[IP spending](ip-training.md) persists validated skill/ability purchases. +The packet replay values below are test inputs, not historical creature rewards. + +## Durable experience state + +The character's `experience` field stores XP earned within its current level. +The control editor accepts progress from zero through one less than that level's +requirement. Levels are restricted to 1 through 200; level 200 has zero further +progress. Editing these fields sets state directly and does not grant IP or +invoke a level-up event. + +`FullCharacter` supplies cumulative XP 52, lower boundary 57 and upper boundary +350. A level-2 character with `experience: 50` receives XP 1500, LastXP 1450 and +NextXP 4050, displaying EXP 50/2600. Initialization uses the full stat list rather +than a live XP update or `NewLevelIIR_t`, which would produce award feedback. +Ordinary profile saves and the unified control editor persist XP immediately; +position checkpoints do not replace it. + +`server/gamedata/experience.yaml` contains 199 per-level requirements. The first +26 agree with the independently retrieved +[Anarchy Online Experience table](https://martin.brenner.de/ao/xp.html). +The remaining values are explicitly provisional, derived from adjacent cumulative +boundaries in the later CellAO `XPTable.TableRKXP`, at reference commit +`ca77f375a7dabe3be769da94e6c2a3d093344c2c`: +`CellAO/Libraries/Source/CellAO.Stats/SpecialStats/XPTable.cs`. +The retained source SHA-256 is +`ab665c30761cf528374fec6a4d92346643c8a2ab498f4c893f41bc1267de935c`. + +That source's level-165 requirement column says 2213610, while the cumulative +boundaries 548119350 and 570255450 differ by 22136100. The maintained table uses +adjacent boundary differences consistently for every level; this conflict is +not evidence of the original server's value. Level 200's cumulative boundary is +2061453150. The complete source rows, conflict and extraction policy are retained +in `local/progression-implementation-research/level-table-source.json`. + +Automated checks cover both shared and 14.9.1 initialization layouts, legal +progress endpoints, invalid levels/negative/overflow/threshold values, immediate +saves, position checkpoints, unrelated players, restart, and SQL failure/retry. +These checks establish current persistence and display behavior, not historical +accuracy of the provisional upper-level table or a kill reward. + +Headed Chromium using the GPU exercised the normal HTTPS preview and +published WASM client. The native Stats window showed EXP 0/1450 for a fresh +character, 1400/1450 after a level-1 progress edit, and 50/2600 for level 2 with +stored progress 50. Page reconnect and a cold server restart both retained +50/2600. A rejected progress value of 2600 left native and SQLite state unchanged. +The current level-199 endpoint retained native cumulative XP 2061453149, and +level 200 displayed 0/0 without a crash. These upper-level cases test the +provisional table's implementation, not its historical accuracy. + +Nine native-heap/SQLite comparisons matched. Across eight initializations and +12,500 captured world packets, the server sent neither a live XP-52 update nor +a `NewLevelIIR_t` event. IP remained 1500 throughout the direct level edits; +there was no XP-gain or level-up text on login. No page errors or unimplemented +adapter reports occurred. Evidence is retained under +`local/progression-state-smoke/`, including `verification.json`, screenshots, +wire captures and `cleanup.json`. The owned browser and test character were +removed; database foreign-key and integrity checks passed. + +Validation passed: `go test ./server/... -count=1`, repeated +`go test -race ./server -run '^TestExperience' -count=2`, and +`go vet -stdversion=false ./server/...`. Full-suite and focused logs are retained +in `local/progression-implementation-research/`. ## Absolute XP updates @@ -31,10 +92,9 @@ The relevant native stat IDs are: | 275 | XPKillRange | Separate value supplied by the level-up handler | | 350 | NextXP | Upper cumulative boundary for the current level | -`FullCharacter` already supports stat-list entries, so initial XP belongs in -the character initialization as well as later absolute updates. The current -server supplies none of these progression values except Level. Live stat -updates used for this research do not persist through reconnect. +`FullCharacter` supplies initial XP and its level boundaries through stat-list +entries. The isolated live stat updates used for the earlier research below did +not persist through reconnect. ## Level-up handler @@ -81,8 +141,8 @@ opened the native Stats window for visual checks. | 25 to 100 | One 75 XP gain; EXP 100/1450 | | 100 to 1000 | One 900 XP gain; EXP 1000/1450 | -Page reconnect returned EXP to 0/0 because the production initializer has no -XP or NextXP entries. Supplying NextXP 2000 and XP 1000 then displayed +In that earlier replay, page reconnect returned EXP to 0/0 because its initializer +supplied no XP or NextXP entries. Supplying NextXP 2000 and XP 1000 then displayed 1000/2000. The denominator is server-supplied, not recovered from a client level table by this path. diff --git a/server/control.go b/server/control.go @@ -75,7 +75,7 @@ func (server *server) userPage(w http.ResponseWriter, r *http.Request) { controlMap(w, data.ID) fmt.Fprint(w, "<h2>Character data</h2><p>This YAML document edits the character in the world database. Slots contain item IDs or null. Saving reconnects an online character. ID is fixed; position is XYZ and rotation is XYZW.</p>") fmt.Fprintf(w, "<form method='post' action='control/users/%d'><p><label>Character:<br><textarea name='data' rows='40' cols='100' required>%s</textarea></label></p><button>Save character</button></form>", data.ID, html.EscapeString(string(contents))) - fmt.Fprint(w, "<p>Inventory uses inventory_slot_1 through inventory_slot_30; equipment uses named weapons, clothes and implants positions. Slots contain item IDs or null. Clearing a slot unassigns its item. <a href='control/items'>Browse and create item instances</a>. Container slots are edited on the container's item page. improvement_points is the available IP balance. Native skill spending deducts IP and enforces training caps; editing stats here sets their values directly.</p>") + fmt.Fprint(w, "<p>Inventory uses inventory_slot_1 through inventory_slot_30; equipment uses named weapons, clothes and implants positions. Slots contain item IDs or null. Clearing a slot unassigns its item. <a href='control/items'>Browse and create item instances</a>. Container slots are edited on the container's item page. experience is progress within the current level, below its next-level requirement; level 200 requires zero. improvement_points is the available IP balance. Native skill spending deducts IP and enforces training caps; editing stats here sets their values directly.</p>") fmt.Fprint(w, itemTables.String()) fmt.Fprint(w, "</body></html>") } diff --git a/server/database.go b/server/database.go @@ -66,7 +66,7 @@ type playerVitals struct { func (character *character) profile() playerProfile { return playerProfile{character.id, character.name, unpackAppearance(character.appearance), character.monsterData, - character.level, max(1, character.profession), character.baseStats(), character.running, character.browserTokenHash, character.resurrectionTerminal, + character.level, character.experience, max(1, character.profession), character.baseStats(), character.running, character.browserTokenHash, character.resurrectionTerminal, character.implantChangesUntil, character.treatmentLockedUntil} } @@ -135,7 +135,7 @@ func (record *characterRecord) fields() []any { func (record characterRecord) character() *character { profile, position := record.Profile, record.Position.editor() data := userData{profile.ID, profile.Name, position.Playfield, position.Position, position.Rotation, - profile.Appearance.packed(), profile.MonsterData, profile.Level, profile.Profession, profile.Stats, profile.Running, position.ReturnDoor, profile.BrowserTokenHash} + profile.Appearance.packed(), profile.MonsterData, profile.Level, profile.Experience, profile.Profession, profile.Stats, profile.Running, position.ReturnDoor, profile.BrowserTokenHash} player := data.character() player.applyVitals(record.Vitals) player.resurrectionTerminal = profile.ResurrectionTerminal diff --git a/server/gamedata/experience.yaml b/server/gamedata/experience.yaml @@ -0,0 +1,205 @@ +# RK experience required from each level to the next, beginning at level 1. +# The first 26 entries also appear in martin.brenner.de/ao/xp.html. +# Remaining values are provisional differences between CellAO's cumulative +# XPTable.TableRKXP boundaries, not a recovered 14.9.1 server table. Its level 165 +# requirement column contradicts those boundaries; see docs/character-progression.md. +# Level 200 has no further RK advancement. +- 1450 +- 2600 +- 3100 +- 4000 +- 4500 +- 5000 +- 5500 +- 6000 +- 6500 +- 7000 +- 7700 +- 8300 +- 8900 +- 9600 +- 10400 +- 11000 +- 11900 +- 12700 +- 13700 +- 15400 +- 16400 +- 17600 +- 18800 +- 20100 +- 21500 +- 22900 +- 24500 +- 26100 +- 27800 +- 30900 +- 33000 +- 35100 +- 37400 +- 39900 +- 42400 +- 45100 +- 47900 +- 50900 +- 54000 +- 57400 +- 60900 +- 64500 +- 68400 +- 76400 +- 81000 +- 85900 +- 91000 +- 96400 +- 101900 +- 108000 +- 114300 +- 120800 +- 127700 +- 135000 +- 142600 +- 150700 +- 159100 +- 167800 +- 177100 +- 203500 +- 214700 +- 226700 +- 239100 +- 251900 +- 265700 +- 280000 +- 294800 +- 310600 +- 327000 +- 344400 +- 362300 +- 381100 +- 401000 +- 421600 +- 443300 +- 508100 +- 534200 +- 561600 +- 590200 +- 620000 +- 651000 +- 683700 +- 717900 +- 753500 +- 790800 +- 829400 +- 870000 +- 912600 +- 956800 +- 1003000 +- 1051300 +- 1101500 +- 1153900 +- 1208800 +- 1266000 +- 1325500 +- 1387700 +- 1452300 +- 1519900 +- 1590300 +- 1663500 +- 1739900 +- 1819600 +- 1902200 +- 1988900 +- 2078600 +- 2172100 +- 2269800 +- 2371100 +- 2476600 +- 2586600 +- 2701000 +- 2819800 +- 2943600 +- 3072400 +- 3205800 +- 3345200 +- 3489700 +- 3640200 +- 3796500 +- 3958900 +- 4128000 +- 4303400 +- 4485700 +- 4674800 +- 4871700 +- 5075700 +- 5288100 +- 5508200 +- 5736800 +- 5974600 +- 6220700 +- 6476500 +- 6742200 +- 7017500 +- 7303700 +- 7600100 +- 7907600 +- 8227000 +- 8557700 +- 8901000 +- 9256800 +- 9625800 +- 10008600 +- 10405300 +- 10816600 +- 11242500 +- 11684300 +- 12141900 +- 12616200 +- 13107200 +- 13816100 +- 14143600 +- 14689700 +- 15255300 +- 15841000 +- 16447900 +- 17075800 +- 17725900 +- 18399400 +- 19096100 +- 19817500 +- 20564100 +- 21336600 +- 22136100 +- 22963600 +- 23819700 +- 24705200 +- 25621100 +- 26569000 +- 27548800 +- 28562900 +- 29611100 +- 30695300 +- 31816300 +- 32975100 +- 34173500 +- 35412500 +- 36692500 +- 38016500 +- 39384400 +- 40797700 +- 42258500 +- 43768300 +- 45328100 +- 46939900 +- 48604900 +- 50324600 +- 52101200 +- 53936300 +- 55831600 +- 57788700 +- 59810000 +- 61897000 +- 64052200 +- 66277200 +- 68574400 +- 70945700 +- 73393900 diff --git a/server/gamedata/load.go b/server/gamedata/load.go @@ -16,6 +16,7 @@ var files embed.FS var ( NPCs NPCData NPCCombatProfiles map[uint32]map[uint16]*NPCCombatProfile + ExperienceLevels []uint32 NPCNames NPCNameData NPCGroups = make(map[string]*NPCGroup) PopulationSources []*NPCPopulationSource @@ -71,6 +72,7 @@ func init() { loadYAML("playfields.yaml", &Playfields) loadYAML("banks.yaml", &BankTerminals) loadYAML("profession_resources.yaml", &ProfessionTitles) + loadYAML("experience.yaml", &ExperienceLevels) loadYAML("ip_training.yaml", &IPTraining) zones, err := fs.Glob(files, "zones/*.yaml") diff --git a/server/profile_database.go b/server/profile_database.go @@ -2,7 +2,7 @@ package main // These columns are shared by players and NPCs; the pointers serve SQL scans and writes. const profileColumns = "name, appearance_race, appearance_fatness, appearance_breed, appearance_sex, appearance_side, appearance_head, " + - "monster_data, level, profession, improvement_points, abilities_strength, abilities_agility, abilities_stamina, " + + "monster_data, level, experience, profession, improvement_points, abilities_strength, abilities_agility, abilities_stamina, " + "abilities_intelligence, abilities_sense, abilities_psychic, body_martial_arts, body_brawling, body_riposte, body_dimach, " + "body_adventuring, body_swimming, body_body_development, body_nano_pool, melee_one_hand_blunt, melee_one_hand_edged, " + "melee_piercing, melee_two_hand_blunt, melee_two_hand_edged, melee_melee_energy, melee_parry, melee_sneak_attack, " + @@ -24,7 +24,7 @@ func (profile *playerProfile) fields() []any { return []any{ &profile.Name, &profile.Appearance.Race, &profile.Appearance.Fatness, &profile.Appearance.Breed, &profile.Appearance.Sex, &profile.Appearance.Side, &profile.Appearance.Head, &profile.MonsterData, - &profile.Level, &profile.Profession, &profile.Stats.ImprovementPoints, &profile.Stats.Abilities.Strength, + &profile.Level, &profile.Experience, &profile.Profession, &profile.Stats.ImprovementPoints, &profile.Stats.Abilities.Strength, &profile.Stats.Abilities.Agility, &profile.Stats.Abilities.Stamina, &profile.Stats.Abilities.Intelligence, &profile.Stats.Abilities.Sense, &profile.Stats.Abilities.Psychic, &profile.Stats.Body.MartialArts, &profile.Stats.Body.Brawling, &profile.Stats.Body.Riposte, &profile.Stats.Body.Dimach, &profile.Stats.Body.Adventuring, &profile.Stats.Body.Swimming, &profile.Stats.Body.BodyDevelopment, diff --git a/server/progression_test.go b/server/progression_test.go @@ -0,0 +1,175 @@ +package main + +import ( + "bytes" + "encoding/binary" + "fmt" + "net/http" + "net/url" + "testing" + "time" +) + +func TestExperienceInitializationUsesCumulativeNativeBoundaries(t *testing.T) { + for _, scenario := range []struct { + level uint16 + progress, total, low, high uint32 + }{ + {1, 0, 0, 0, 1450}, + {1, 1449, 1449, 0, 1450}, + {2, 50, 1500, 1450, 4050}, + {3, 3099, 7149, 4050, 7150}, + {165, 0, 548119350, 548119350, 570255450}, + {166, 0, 570255450, 570255450, 593219050}, + {199, 73393899, 2061453149, 1988059250, 2061453150}, + {200, 0, 2061453150, 2061453150, 2061453150}, + } { + for _, target := range []bool{false, true} { + t.Run(fmt.Sprintf("level%d/progress%d/target%t", scenario.level, scenario.progress, target), func(t *testing.T) { + player := (userData{ID: 1, Level: scenario.level, Experience: scenario.progress}).character() + + packet := fullCharacterPacket(player) + offset := 64 + if target { + packet = targetPacket(packet) + offset = 61 + } + count := int(binary.BigEndian.Uint32(packet[offset:])/1009 - 1) + stats := make(map[uint32]uint32) + for cursor := offset + 4; cursor < offset+4+count*8; cursor += 8 { + stats[binary.BigEndian.Uint32(packet[cursor:])] = binary.BigEndian.Uint32(packet[cursor+4:]) + } + + if stats[52] != scenario.total || stats[57] != scenario.low || stats[350] != scenario.high || stats[54] != uint32(scenario.level) { + t.Fatalf("native progression: XP=%d last=%d next=%d level=%d", stats[52], stats[57], stats[350], stats[54]) + } + if player.experience != scenario.progress || player.level != scenario.level { + t.Fatal("initialization changed progression") + } + }) + } + } +} + +func TestExperienceEditAndCheckpointSurviveRestart(t *testing.T) { + useNPCData(t, testNPCData()) + world := newTestServer(t) + postControlForm(world, "/control/users", url.Values{"name": {"Explorer"}}) + postControlForm(world, "/control/users", url.Values{"name": {"Observer"}}) + + response := postControlForm(world, "/control/users/1", url.Values{"data": {"level: 2\nexperience: 50\n"}}) + player := world.characters[1] + player.position[0]++ + if err := world.flushPositions(time.Now().Add(20 * time.Second)); err != nil { + t.Fatal(err) + } + restarted := newServer() + defer restarted.db.Close() + var experience uint32 + err := restarted.db.QueryRow("SELECT experience FROM characters WHERE id=1").Scan(&experience) + + if response.Code != http.StatusSeeOther || err != nil || experience != 50 || player.savedProfile.Experience != 50 { + t.Fatalf("experience edit: HTTP %d saved=%d error=%v", response.Code, experience, err) + } + if restarted.characters[1].level != 2 || restarted.characters[1].experience != 50 || restarted.characters[1].position != player.position { + t.Fatal("checkpoint or restart lost the edited progression") + } + if restarted.characters[2].experience != 0 || restarted.characters[2].level != 1 { + t.Fatal("the edit changed another character") + } +} + +func TestExperienceEditorRejectsInvalidProgressWithoutChangingState(t *testing.T) { + for _, contents := range []string{ + "level: 0\n", "level: 201\n", "experience: -1\n", "experience: 4294967296\n", + "experience: 1450\n", "experience: 4294967295\n", "level: 2\nexperience: 2600\n", + "level: 200\nexperience: 1\n", + } { + t.Run(contents, func(t *testing.T) { + useNPCData(t, testNPCData()) + world := newTestServer(t) + postControlForm(world, "/control/users", url.Values{"name": {"Explorer"}}) + before, err := readTestPlayerRecord(1, "player") + if err != nil { + t.Fatal(err) + } + + response := postControlForm(world, "/control/users/1", url.Values{"data": {contents}}) + after, err := readTestPlayerRecord(1, "player") + + if err != nil || response.Code != http.StatusBadRequest || !bytes.Equal(before, after) || world.characters[1].experience != 0 || world.characters[1].level != 1 { + t.Fatalf("invalid progression changed state: HTTP %d error=%v", response.Code, err) + } + }) + } +} + +func TestExperienceEditorAcceptsLevelEndpoints(t *testing.T) { + for _, scenario := range []struct { + level uint16 + experience uint32 + }{ + {1, 1449}, {2, 0}, {2, 2599}, {199, 73393899}, {200, 0}, + } { + t.Run(fmt.Sprintf("level%d/progress%d", scenario.level, scenario.experience), func(t *testing.T) { + useNPCData(t, testNPCData()) + world := newTestServer(t) + postControlForm(world, "/control/users", url.Values{"name": {"Explorer"}}) + contents := fmt.Sprintf("level: %d\nexperience: %d\n", scenario.level, scenario.experience) + + response := postControlForm(world, "/control/users/1", url.Values{"data": {contents}}) + restarted := newServer() + defer restarted.db.Close() + + if response.Code != http.StatusSeeOther || restarted.characters[1].level != scenario.level || + restarted.characters[1].experience != scenario.experience || restarted.characters[1].profile() != world.characters[1].profile() { + t.Fatalf("valid progression failed: HTTP %d %s", response.Code, response.Body.String()) + } + }) + } +} + +func TestExperienceProfileUpdatePersistsImmediately(t *testing.T) { + useNPCData(t, testNPCData()) + world := newTestServer(t) + player := world.newCharacter() + destination := player.userData() + destination.Level, destination.Experience = 2, 50 + + err := world.updateUser(destination) + restarted := newServer() + defer restarted.db.Close() + + if err != nil || restarted.characters[1].level != 2 || restarted.characters[1].experience != 50 || player.savedProfile.Experience != 50 { + t.Fatalf("profile update lost progression: %v", err) + } +} + +func TestExperienceEditFailureRollsBackThenRetries(t *testing.T) { + useNPCData(t, testNPCData()) + world := newTestServer(t) + postControlForm(world, "/control/users", url.Values{"name": {"Explorer"}}) + if _, err := world.db.Exec("CREATE TRIGGER reject_xp BEFORE UPDATE OF experience ON characters BEGIN SELECT RAISE(ABORT, 'test XP failure'); END"); err != nil { + t.Fatal(err) + } + + response := postControlForm(world, "/control/users/1", url.Values{"data": {"level: 2\nexperience: 50\n"}}) + restarted := newServer() + defer restarted.db.Close() + + if response.Code != http.StatusInternalServerError || world.characters[1].level != 1 || world.characters[1].experience != 0 || + restarted.characters[1].level != 1 || restarted.characters[1].experience != 0 { + t.Fatal("a failed XP save changed live or durable progression") + } + + // Retry after the failing transaction has rolled back. + if _, err := world.db.Exec("DROP TRIGGER reject_xp"); err != nil { + t.Fatal(err) + } + response = postControlForm(world, "/control/users/1", url.Values{"data": {"level: 2\nexperience: 50\n"}}) + retried := newServer() + defer retried.db.Close() + if response.Code != http.StatusSeeOther || retried.characters[1].level != 2 || retried.characters[1].experience != 50 { + t.Fatal("the rejected progression edit could not be retried") + } +} diff --git a/server/state.go b/server/state.go @@ -21,6 +21,7 @@ type character struct { appearance uint16 monsterData uint32 level uint16 + experience uint32 profession uint16 stats characterStats inventory playerInventory diff --git a/server/target_protocol_test.go b/server/target_protocol_test.go @@ -98,8 +98,8 @@ initialized: if hex.EncodeToString(npc[60:89]) != "000001cb0b456469746564204e50430000000000000000000000000007" { t.Fatalf("target NPC appearance, name and new stats: %x", npc[60:89]) } - if hex.EncodeToString(full[57:73]) != "000003f1000166ab0000003600000001" { - t.Fatalf("target seventh list and first stat: %x", full[57:73]) + if hex.EncodeToString(full[57:97]) != "000003f10001727e0000003600000001000000340000000000000039000000000000015e000005aa" { + t.Fatalf("target seventh list and initial progression stats: %x", full[57:97]) } } diff --git a/server/users.go b/server/users.go @@ -25,6 +25,7 @@ type userData struct { Appearance uint16 MonsterData uint32 Level uint16 + Experience uint32 Profession uint16 Stats characterStats Running bool @@ -39,6 +40,7 @@ type playerProfile struct { Appearance appearanceFields `yaml:"appearance"` MonsterData uint32 `yaml:"monster_data"` Level uint16 `yaml:"level"` + Experience uint32 `yaml:"experience"` Profession uint16 `yaml:"profession"` Stats characterStats `yaml:"stats"` Running bool `yaml:"running"` @@ -57,12 +59,12 @@ type playerPosition struct { func (character *character) userData() userData { return userData{character.id, character.name, character.playfield, character.position, - character.rotation, character.appearance, character.monsterData, character.level, max(1, character.profession), character.baseStats(), character.running, character.returnDoor, character.browserTokenHash} + character.rotation, character.appearance, character.monsterData, character.level, character.experience, max(1, character.profession), character.baseStats(), character.running, character.returnDoor, character.browserTokenHash} } func (data userData) character() *character { character := &character{id: data.ID, name: data.Name, playfield: data.Playfield, position: data.Position, - rotation: data.Rotation, appearance: data.Appearance, monsterData: data.MonsterData, level: data.Level, + rotation: data.Rotation, appearance: data.Appearance, monsterData: data.MonsterData, level: data.Level, experience: data.Experience, profession: max(1, data.Profession), running: data.Running, stats: data.Stats, @@ -83,8 +85,11 @@ func (data userData) validate() error { if !exists || zone.Unavailable { return fmt.Errorf("playfield has no playable client assets") } - if data.Level == 0 { - return fmt.Errorf("level must be at least 1") + if data.Level == 0 || data.Level > 200 { + return fmt.Errorf("level must be between 1 and 200") + } + if data.Level == 200 && data.Experience != 0 || data.Level < 200 && data.Experience >= gamedata.ExperienceLevels[data.Level-1] { + return fmt.Errorf("experience must be below the current level's requirement") } if data.Profession > 12 { return fmt.Errorf("profession must be one of the twelve original professions") diff --git a/server/world.go b/server/world.go @@ -194,7 +194,17 @@ func fullCharacterPacket(character *character) []byte { for range 4 { body = binary.BigEndian.AppendUint32(body, 1009) } - stats := [][2]uint32{{54, uint32(character.level)}} + // Translate current-level progress into the native cumulative boundaries. + level := max(1, character.level) + var lowerXP uint32 + for _, required := range gamedata.ExperienceLevels[:level-1] { + lowerXP += required + } + upperXP := lowerXP + if level < 200 { + upperXP += gamedata.ExperienceLevels[level-1] + } + stats := [][2]uint32{{54, uint32(character.level)}, {52, lowerXP + character.experience}, {57, lowerXP}, {350, upperXP}} stats = append(stats, character.baseStats().nativeStats()...) stats = append(stats, [2]uint32{4, uint32(character.appearance >> 4 & 7)}, diff --git a/server/world.sql b/server/world.sql @@ -18,6 +18,7 @@ CREATE TABLE IF NOT EXISTS characters ( appearance_head INTEGER NOT NULL DEFAULT 0 CHECK (appearance_head BETWEEN 0 AND 31), monster_data INTEGER NOT NULL DEFAULT 0, level INTEGER NOT NULL DEFAULT 1, + experience INTEGER NOT NULL DEFAULT 0 CHECK (experience BETWEEN 0 AND 4294967295), profession INTEGER NOT NULL DEFAULT 1, improvement_points INTEGER NOT NULL DEFAULT 1500, abilities_strength INTEGER NOT NULL DEFAULT 6,