commit a4f32cc1d201d2b482d65cecc43de4133374b7cd
parent cc5183789544e1d55e8884cd441658941085197b
Author: anon <anon@example.com>
Date: Wed, 28 Oct 2026 20:11:21 +0000
Scale mission encounters and rewards by difficulty
Diffstat:
9 files changed, 652 insertions(+), 11 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -63,7 +63,10 @@ entry, traversal, reconnect and return. Its bound book can be collected and
survives restart without respawning. Returning that exact book to its issuing
booth now completes the fixed contract and atomically grants authored cash
and a selected-quality equipment reward. The small reward pool is provisional;
-the fixed mission now has five level-1 Leets using shared combat and loot.
+new missions now select the five Leets' level and scalable reward QL from player
+level and difficulty, using explicitly provisional later measurements. Only
+levels 1 and 2 currently have admitted combat profiles; unsupported requests
+return no offer without charging. See [mission levels](docs/mission-levels.md).
Indoor combatants now use shared body/collision probes to plan bounded detours;
native movement timing still needs refinement. An earned level-2 Enforcer can
now select and defeat all five full-health encounters, collect corpse loot and
@@ -630,6 +633,14 @@ for exact records, protocol, tests and remaining reconstruction assumptions.
provisional values at each level. Two native clients verified both fights,
rewards, item pickup and cold reconstruction; automation covers both levels.
See [NPC combat balance](docs/combat-npc-balance.md).
+- [ ] [P0] Expand admitted early mission combat profiles beyond levels 1 and 2.
+ New contracts now select levels before charging and reject an unsupported
+ level-3 encounter without a fee. Add reviewed resources, attacks, defenses,
+ XP and useful loot for the next progression levels, keeping balance explicitly
+ provisional where historical measurements are missing. Prefer shared growth
+ rules supported by evidence over a separate bespoke profile for every level.
+ Verify ordinary earned equipment, healing costs, mission completion and the next
+ level without admin grants. Preserve authored outdoor level ranges.
- [x] Make the next supported enemy level available through ordinary starter
play. Check: a new player can reach and identify supported level-1 and level-2
enemies without admin placement. Resolve the generator's minimum-only choice
@@ -1849,8 +1860,9 @@ client rendering fixes and checks are in [nano damage](docs/nano-damage.md).
- [ ] [P1] Generate one two-room mission layout. Check: a fixed test seed produces
connected rooms with a reachable entrance, objective and exit.
- [ ] [P1] Apply difficulty and all six mission dimensions to generated content.
- Current browsing validates and echoes these settings but returns one fixed
- contract. Recover level/QL, objective, reward and population selection rules;
+ Difficulty now selects a provisional level/QL; the six dimensions are validated
+ and echoed, but the layout, objective and species remain fixed. Recover their
+ selection rules and historical difficulty effects;
preserve authored style selectors instead of treating them as playfield IDs
or faction numbers. Verify distinct settings and original boundary behavior.
- [ ] [P0] Connect mission level to encounters and useful item rewards. Recover
@@ -1861,6 +1873,15 @@ client rendering fixes and checks are in [nano damage](docs/nano-damage.md).
relative to current player level, without specifying a numerical formula.
Check low/high player levels, easier/harder missions, supported item ranges,
usable rewards and durable exactly-once delivery after reconnect/restart.
+ Partial implementation: a documented provisional later measurement table now
+ selects the level before advertising, and generated encounters and scalable
+ rewards retain their selected values through acceptance and cold loading.
+ Unsupported profiles and reward qualities return no offer without charging.
+ Exact 14.9.1 selection, NPC variation, wider combat profiles and reward
+ exceptions remain open. Native ordinary play verified five level-2 kills,
+ QL2 corpse loot, an active-contract cold restart, the selected QL2 reward's
+ wear/remove cycle and another cold restart with all 14 instances accounted for.
+ See [mission levels](docs/mission-levels.md).
## Teams
diff --git a/docs/mission-levels.md b/docs/mission-levels.md
@@ -0,0 +1,110 @@
+# Mission levels and item quality
+
+Mission generation resolves encounter levels and scalable reward quality before
+charging the request fee or advertising a contract. A zero encounter level or
+reward quality selects the mission level; an authored nonzero value remains
+fixed. The generation recipe is copied, so one request cannot change later
+requests. Accepted encounters and the selected reward retain their concrete
+values through reconnect and cold restart, independently of later recipe edits
+or player advancement.
+
+The reward pool is filtered to families supporting the selected quality. There
+is no endpoint clamping. A missing combat profile or an empty eligible reward
+pool produces an empty offer without charging, allocating persistent identities,
+or modifying the recipe. Existing mission persistence already stores the
+concrete values. Outdoor populations still use their authored level ranges.
+
+## Evidence and provisional policy
+
+The shipped `text/help/The Mission Window.txt` describes difficulty relative to
+the character's level, without a numeric selection formula. July 2003 player
+discussions describe the hardest missions as approximately twice player level:
+[July 12](https://forumarchiwum.gry-online.pl/S043archiwum.asp?ID=1512701) and
+[July 28](https://forumarchiwum.gry-online.pl/S043archiwum.asp?ID=1546906).
+These qualitative observations do not establish exact rounding or boundaries.
+
+The maintained table uses the first 200 rows and eleven difficulty columns of
+[Nadybot's later measurements](https://github.com/Nadybot/Nadybot/blob/de9e3b2c8d2f91df87c614a3d9f91bc16c2eacf2/src/Modules/LEVEL_MODULE/levels.csv).
+This is explicitly provisional later evidence, not a recovered 14.9.1 formula.
+The source Git blob is `12572abdb97efb517941bd253a345c3787f06f6b`;
+its raw SHA-256 is
+`0f2d4e31afb875b30c70cdb3f5c62cccc304aafba9825afd26f94c727226eccf`.
+The table includes a quality cap of 250 and a neutral sixth position equal to
+player level.
+
+| Player level | Easiest | Neutral | Hardest |
+| --- | --- | --- | --- |
+| 1 | 1 | 1 | 1 |
+| 2 | 1 | 2 | 3 |
+| 10 | 7 | 10 | 17 |
+| 20 | 14 | 20 | 35 |
+| 112 | 78 | 112 | 200 |
+| 200 | 140 | 200 | 250 |
+
+The first ten columns can be reproduced with single-precision multipliers
+0.7, 0.75, 0.8, 0.85, 0.9, 1, 1.1, 1.2, 1.3 and 1.5. Neither 1.8 nor 1.79
+reproduces the last column. Hundreds of nearby single-precision coefficients
+fit the data, but their origin is unknown. Retaining the factual table avoids
+presenting a fitted constant as a historical rule. Later Helpbot wiki tables
+also disagree with these measurements, including nonmonotonic entries.
+
+The original `kkr.dll` request producer at `0x36021680` encodes the UI percentage
+as `floor((float)percent * 0.10891089 + 1)`, restricted to 1..11. This bounded
+producer does not select a level from the player's level. The examined Quest14
+reader at `0x360c4d80` did not establish another mission-level wire field.
+The original DLL SHA-256 is
+`241b2e665dcd127399b7686cddda8a5b0876d9cde9b3af7a73940dd0b86ecaa7`.
+Local REA evidence is retained under `local/mission-levels/`, including producer
+record `ev_9bf8876532b584f8b6eddb1ad09788085581a8e91e6032ade3c4996a06f3b2ad`
+and reader record
+`ev_37f195acc43817dd65a835816d79671230f8192ae1d0781d3f68fdb2e9cdda04`.
+
+The current five-Leet mission uses the selected level for every encounter and
+the scalable equipment reward. This is a reconstruction policy. Historical NPC
+level variation, reward membership and fixed-quality exceptions such as nano
+crystals still require separate evidence. Only Leet levels 1 and 2 currently
+have admitted combat profiles, so requests requiring level 3 or higher are
+rejected before charging. Expanding these profiles is a priority for further
+progression. Completion XP and tokens remain separate unfinished work.
+
+## Verification
+
+Public request tests cover all eleven difficulties at seven player levels,
+quality endpoints, unsupported profiles and item ranges, fee failure and retry,
+fixed values, recipe immutability, acceptance, objective return and cold loading.
+The focused regression passed 159 root tests and 1,060 total test results; race
+checks passed 19 root tests and 132 results. The complete server suite passed
+1,655 root tests and 16,344 total test results, with no failures. Build and vet
+also passed.
+
+## Native earned-character check
+
+The retained level-2 Atrox Enforcer used the GPU WASM client and ordinary
+inputs throughout. Captured native replies confirmed difficulty 1 advertised
+QL 1, difficulty 6 advertised QL 2, and difficulty 11 returned no offer without
+charging. A difficulty-6 retry succeeded and was accepted. Each supported
+request cost exactly 2 credits; the rejected request allocated no mission.
+
+All five generated Leets appeared at level 2 with full 100 HP and original
+QL 2 Leet Bite endpoints, giving 4..9 base damage. The character started each
+fight at full 91 HP, defeated all five with earned bat 72, and used ten charges
+from the previously bought laboratory 56. The second corpse yielded 3 credits
+and QL 2 Monster Part 75. Kill XP increased native cumulative XP from 2600 to 3100;
+IP remained 5030. These health, kill-XP and loot-profile values remain provisional.
+
+After collecting book 74, a page reconnect and cold server/client restart
+retained the active contract, book/key, selected reward quality and all five
+death records. Returning that saved book consumed book 74 and key 73, paid 20
+credits and delivered the advertised QL 2 Metaplast glove 76. An occupied hands
+slot retained both gloves. Removing bought glove 38 allowed glove 76 to equip;
+native AC 90..97 became `2/12/2/2/1/1/1/1`. Removing it restored shirt-only armor,
+and rewearing 38 restored `3/13/1/1/1/1/1/1`.
+
+Another page reconnect and cold server/client restart retained every original
+instance, the new part and glove, equipped bat 72 and glove 38, 14 laboratory
+charges, 85 credits, XP 3100/IP 5030, 91 HP/24 nano and the completed mission.
+The wallet reconciles as `68 - 3*2 + 3 + 20 = 85`. All 14 owned instances match
+native slots, qualities and counts; database integrity and foreign-key checks
+passed. No admin grants or fixture mutations were used. Owned browsers were
+closed after testing. Evidence and verification scripts remain under
+`local/mission-levels/`.
diff --git a/server/gamedata/load.go b/server/gamedata/load.go
@@ -33,6 +33,7 @@ var (
ShopMachines map[uint32]ShopMachine
MissionBooths map[uint32]MissionBooth
MissionTemplates map[uint32]MissionTemplate
+ MissionLevels map[uint16][11]uint16
ShopStock map[uint32][]ShopItem
ItemCombinations map[uint32]map[uint32]ItemCombination
PlayerAppearances struct {
@@ -86,6 +87,18 @@ func init() {
loadYAML("shops.yaml", &ShopMachines)
loadYAML("mission_booths.yaml", &MissionBooths)
loadYAML("missions.yaml", &MissionTemplates)
+ loadYAML("mission_levels.yaml", &MissionLevels)
+ if len(MissionLevels) != 200 {
+ panic("mission levels must cover classic character levels 1..200")
+ }
+ for level := uint16(1); level <= 200; level++ {
+ levels := MissionLevels[level]
+ for index, selected := range levels {
+ if selected == 0 || selected > 250 || index > 0 && selected < levels[index-1] || levels[5] != level {
+ panic(fmt.Errorf("invalid mission level selection for character level %d", level))
+ }
+ }
+ }
loadYAML("shop_stock.yaml", &ShopStock)
loadYAML("profession_resources.yaml", &ProfessionTitles)
loadYAML("experience.yaml", &ExperienceLevels)
@@ -200,7 +213,8 @@ func init() {
panic(fmt.Errorf("mission %d reward quality has no item pool", booth))
}
for _, template := range mission.RewardItems {
- if !ItemQualitySupported(template, mission.RewardQuality) {
+ item := ItemTemplates[template]
+ if item == nil || item.Quality == nil || *item.Quality == 0 || mission.RewardQuality != 0 && !ItemQualitySupported(template, mission.RewardQuality) {
panic(fmt.Errorf("invalid mission reward %d: template %d quality %d", booth, template, mission.RewardQuality))
}
}
diff --git a/server/gamedata/mission_booths_test.go b/server/gamedata/mission_booths_test.go
@@ -88,7 +88,7 @@ func TestStarterMissionTemplateReferencesOriginalAssets(t *testing.T) {
item := ItemTemplates[definition.ObjectiveItem]
if definition.Playfield != booth.Playfield || definition.Playfield != 3000 || definition.Entrance != 3221228472 ||
- len(definition.RewardItems) != 2 || definition.RewardItems[0] != 85596 || definition.RewardItems[1] != 122691 || definition.RewardQuality != 2 ||
+ len(definition.RewardItems) != 2 || definition.RewardItems[0] != 85596 || definition.RewardItems[1] != 122691 || definition.RewardQuality != 0 ||
!ItemQualitySupported(85596, 2) || !ItemQualitySupported(122691, 2) || definition.PassageDoor != 41565 ||
definition.Position != [3]float32{89.30216217041016, 115.14443969726562, 151.16087341308594} ||
item == nil || item.ID != 40822 || item.Quality == nil || *item.Quality != 1 ||
diff --git a/server/gamedata/mission_levels.yaml b/server/gamedata/mission_levels.yaml
@@ -0,0 +1,204 @@
+# Provisional mission levels from later community measurements, not a recovered 14.9.1 formula.
+# Nadybot LEVEL_MODULE/levels.csv; Git blob 12572abdb97efb517941bd253a345c3787f06f6b.
+# Source and historical limits: docs/mission-levels.md.
+# Player level: eleven difficulty positions, easiest to hardest; position six is neutral.
+1: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
+2: [1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3]
+3: [2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 5]
+4: [2, 3, 3, 3, 3, 4, 4, 4, 5, 6, 7]
+5: [3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 8]
+6: [4, 4, 4, 5, 5, 6, 6, 7, 7, 9, 10]
+7: [4, 5, 5, 5, 6, 7, 7, 8, 9, 10, 12]
+8: [5, 6, 6, 6, 7, 8, 8, 9, 10, 12, 14]
+9: [6, 6, 7, 7, 8, 9, 9, 10, 11, 13, 16]
+10: [7, 7, 8, 8, 9, 10, 11, 12, 13, 15, 17]
+11: [7, 8, 8, 9, 9, 11, 12, 13, 14, 16, 19]
+12: [8, 9, 9, 10, 10, 12, 13, 14, 15, 18, 21]
+13: [9, 9, 10, 11, 11, 13, 14, 15, 16, 19, 23]
+14: [9, 10, 11, 11, 12, 14, 15, 16, 18, 21, 25]
+15: [10, 11, 12, 12, 13, 15, 16, 18, 19, 22, 26]
+16: [11, 12, 12, 13, 14, 16, 17, 19, 20, 24, 28]
+17: [11, 12, 13, 14, 15, 17, 18, 20, 22, 25, 30]
+18: [12, 13, 14, 15, 16, 18, 19, 21, 23, 27, 32]
+19: [13, 14, 15, 16, 17, 19, 20, 22, 24, 28, 34]
+20: [14, 15, 16, 17, 18, 20, 22, 24, 26, 30, 35]
+21: [14, 15, 16, 17, 18, 21, 23, 25, 27, 31, 37]
+22: [15, 16, 17, 18, 19, 22, 24, 26, 28, 33, 39]
+23: [16, 17, 18, 19, 20, 23, 25, 27, 29, 34, 41]
+24: [16, 18, 19, 20, 21, 24, 26, 28, 31, 36, 42]
+25: [17, 18, 20, 21, 22, 25, 27, 30, 32, 37, 44]
+26: [18, 19, 20, 22, 23, 26, 28, 31, 33, 39, 46]
+27: [18, 20, 21, 22, 24, 27, 29, 32, 35, 40, 48]
+28: [19, 21, 22, 23, 25, 28, 30, 33, 36, 42, 50]
+29: [20, 21, 23, 24, 26, 29, 31, 34, 37, 43, 51]
+30: [21, 22, 24, 25, 27, 30, 33, 36, 39, 45, 53]
+31: [21, 23, 24, 26, 27, 31, 34, 37, 40, 46, 55]
+32: [22, 24, 25, 27, 28, 32, 35, 38, 41, 48, 57]
+33: [23, 24, 26, 28, 29, 33, 36, 39, 42, 49, 59]
+34: [23, 25, 27, 28, 30, 34, 37, 40, 44, 51, 60]
+35: [24, 26, 28, 29, 31, 35, 38, 42, 45, 52, 62]
+36: [25, 27, 28, 30, 32, 36, 39, 43, 46, 54, 64]
+37: [25, 27, 29, 31, 33, 37, 40, 44, 48, 55, 66]
+38: [26, 28, 30, 32, 34, 38, 41, 45, 49, 57, 68]
+39: [27, 29, 31, 33, 35, 39, 42, 46, 50, 58, 69]
+40: [28, 30, 32, 34, 36, 40, 44, 48, 52, 60, 71]
+41: [28, 30, 32, 34, 36, 41, 45, 49, 53, 61, 73]
+42: [29, 31, 33, 35, 37, 42, 46, 50, 54, 63, 75]
+43: [30, 32, 34, 36, 38, 43, 47, 51, 55, 64, 77]
+44: [30, 33, 35, 37, 39, 44, 48, 52, 57, 66, 78]
+45: [31, 33, 36, 38, 40, 45, 49, 54, 58, 67, 80]
+46: [32, 34, 36, 39, 41, 46, 50, 55, 59, 69, 82]
+47: [32, 35, 37, 39, 42, 47, 51, 56, 61, 70, 84]
+48: [33, 36, 38, 40, 43, 48, 52, 57, 62, 72, 85]
+49: [34, 36, 39, 41, 44, 49, 53, 58, 63, 73, 87]
+50: [35, 37, 40, 42, 45, 50, 55, 60, 65, 75, 89]
+51: [35, 38, 40, 43, 45, 51, 56, 61, 66, 76, 91]
+52: [36, 39, 41, 44, 46, 52, 57, 62, 67, 78, 93]
+53: [37, 39, 42, 45, 47, 53, 58, 63, 68, 79, 94]
+54: [37, 40, 43, 45, 48, 54, 59, 64, 70, 81, 96]
+55: [38, 41, 44, 46, 49, 55, 60, 66, 71, 82, 98]
+56: [39, 42, 44, 47, 50, 56, 61, 67, 72, 84, 100]
+57: [39, 42, 45, 48, 51, 57, 62, 68, 74, 85, 102]
+58: [40, 43, 46, 49, 52, 58, 63, 69, 75, 87, 103]
+59: [41, 44, 47, 50, 53, 59, 64, 70, 76, 88, 105]
+60: [42, 45, 48, 51, 54, 60, 66, 72, 78, 90, 107]
+61: [42, 45, 48, 51, 54, 61, 67, 73, 79, 91, 109]
+62: [43, 46, 49, 52, 55, 62, 68, 74, 80, 93, 111]
+63: [44, 47, 50, 53, 56, 63, 69, 75, 81, 94, 112]
+64: [44, 48, 51, 54, 57, 64, 70, 76, 83, 96, 114]
+65: [45, 48, 52, 55, 58, 65, 71, 78, 84, 97, 116]
+66: [46, 49, 52, 56, 59, 66, 72, 79, 85, 99, 118]
+67: [46, 50, 53, 56, 60, 67, 73, 80, 87, 100, 120]
+68: [47, 51, 54, 57, 61, 68, 74, 81, 88, 102, 121]
+69: [48, 51, 55, 58, 62, 69, 75, 82, 89, 103, 123]
+70: [49, 52, 56, 59, 63, 70, 77, 84, 91, 105, 125]
+71: [49, 53, 56, 60, 63, 71, 78, 85, 92, 106, 127]
+72: [50, 54, 57, 61, 64, 72, 79, 86, 93, 108, 128]
+73: [51, 54, 58, 62, 65, 73, 80, 87, 94, 109, 130]
+74: [51, 55, 59, 62, 66, 74, 81, 88, 96, 111, 132]
+75: [52, 56, 60, 63, 67, 75, 82, 90, 97, 112, 134]
+76: [53, 57, 60, 64, 68, 76, 83, 91, 98, 114, 136]
+77: [53, 57, 61, 65, 69, 77, 84, 92, 100, 115, 137]
+78: [54, 58, 62, 66, 70, 78, 85, 93, 101, 117, 139]
+79: [55, 59, 63, 67, 71, 79, 86, 94, 102, 118, 141]
+80: [56, 60, 64, 68, 72, 80, 88, 96, 104, 120, 143]
+81: [56, 60, 64, 68, 72, 81, 89, 97, 105, 121, 145]
+82: [57, 61, 65, 69, 73, 82, 90, 98, 106, 123, 146]
+83: [58, 62, 66, 70, 74, 83, 91, 99, 107, 124, 148]
+84: [58, 63, 67, 71, 75, 84, 92, 100, 109, 126, 150]
+85: [59, 63, 68, 72, 76, 85, 93, 102, 110, 127, 152]
+86: [60, 64, 68, 73, 77, 86, 94, 103, 111, 129, 154]
+87: [60, 65, 69, 73, 78, 87, 95, 104, 113, 130, 155]
+88: [61, 66, 70, 74, 79, 88, 96, 105, 114, 132, 157]
+89: [62, 66, 71, 75, 80, 89, 97, 106, 115, 133, 159]
+90: [63, 67, 72, 76, 81, 90, 99, 108, 116, 135, 161]
+91: [63, 68, 72, 77, 81, 91, 100, 109, 118, 136, 163]
+92: [64, 69, 73, 78, 82, 92, 101, 110, 119, 138, 164]
+93: [65, 69, 74, 79, 83, 93, 102, 111, 120, 139, 166]
+94: [65, 70, 75, 79, 84, 94, 103, 112, 122, 141, 168]
+95: [66, 71, 76, 80, 85, 95, 104, 114, 123, 142, 170]
+96: [67, 72, 76, 81, 86, 96, 105, 115, 124, 144, 171]
+97: [67, 72, 77, 82, 87, 97, 106, 116, 126, 145, 173]
+98: [68, 73, 78, 83, 88, 98, 107, 117, 127, 147, 175]
+99: [69, 74, 79, 84, 89, 99, 108, 118, 128, 148, 177]
+100: [70, 75, 80, 85, 90, 100, 110, 120, 130, 150, 179]
+101: [70, 75, 80, 85, 90, 101, 111, 121, 131, 151, 180]
+102: [71, 76, 81, 86, 91, 102, 112, 122, 132, 153, 182]
+103: [72, 77, 82, 87, 92, 103, 113, 123, 133, 154, 184]
+104: [72, 78, 83, 88, 93, 104, 114, 124, 135, 156, 186]
+105: [73, 78, 84, 89, 94, 105, 115, 126, 136, 157, 188]
+106: [74, 79, 84, 90, 95, 106, 116, 127, 137, 159, 189]
+107: [74, 80, 85, 90, 96, 107, 117, 128, 139, 160, 191]
+108: [75, 81, 86, 91, 97, 108, 118, 129, 140, 162, 193]
+109: [76, 81, 87, 92, 98, 109, 119, 130, 141, 163, 195]
+110: [77, 82, 88, 93, 99, 110, 121, 132, 143, 165, 197]
+111: [77, 83, 88, 94, 99, 111, 122, 133, 144, 166, 198]
+112: [78, 84, 89, 95, 100, 112, 123, 134, 145, 168, 200]
+113: [79, 84, 90, 96, 101, 113, 124, 135, 146, 169, 202]
+114: [79, 85, 91, 96, 102, 114, 125, 136, 148, 171, 204]
+115: [80, 86, 92, 97, 103, 115, 126, 138, 149, 172, 205]
+116: [81, 87, 92, 98, 104, 116, 127, 139, 150, 174, 207]
+117: [81, 87, 93, 99, 105, 117, 128, 140, 152, 175, 209]
+118: [82, 88, 94, 100, 106, 118, 129, 141, 153, 177, 211]
+119: [83, 89, 95, 101, 107, 119, 130, 142, 154, 178, 213]
+120: [84, 90, 96, 102, 108, 120, 132, 144, 156, 180, 214]
+121: [84, 90, 96, 102, 108, 121, 133, 145, 157, 181, 216]
+122: [85, 91, 97, 103, 109, 122, 134, 146, 158, 183, 218]
+123: [86, 92, 98, 104, 110, 123, 135, 147, 159, 184, 220]
+124: [86, 93, 99, 105, 111, 124, 136, 148, 161, 186, 222]
+125: [87, 93, 100, 106, 112, 125, 137, 150, 162, 187, 223]
+126: [88, 94, 100, 107, 113, 126, 138, 151, 163, 189, 225]
+127: [88, 95, 101, 107, 114, 127, 139, 152, 165, 190, 227]
+128: [89, 96, 102, 108, 115, 128, 140, 153, 166, 192, 229]
+129: [90, 96, 103, 109, 116, 129, 141, 154, 167, 193, 231]
+130: [91, 97, 104, 110, 117, 130, 143, 156, 169, 195, 232]
+131: [91, 98, 104, 111, 117, 131, 144, 157, 170, 196, 234]
+132: [92, 99, 105, 112, 118, 132, 145, 158, 171, 198, 236]
+133: [93, 99, 106, 113, 119, 133, 146, 159, 172, 199, 238]
+134: [93, 100, 107, 113, 120, 134, 147, 160, 174, 201, 240]
+135: [94, 101, 108, 114, 121, 135, 148, 162, 175, 202, 241]
+136: [95, 102, 108, 115, 122, 136, 149, 163, 176, 204, 243]
+137: [95, 102, 109, 116, 123, 137, 150, 164, 178, 205, 245]
+138: [96, 103, 110, 117, 124, 138, 151, 165, 179, 207, 247]
+139: [97, 104, 111, 118, 125, 139, 152, 166, 180, 208, 248]
+140: [98, 105, 112, 119, 126, 140, 154, 168, 182, 210, 250]
+141: [98, 105, 112, 119, 126, 141, 155, 169, 183, 211, 250]
+142: [99, 106, 113, 120, 127, 142, 156, 170, 184, 213, 250]
+143: [100, 107, 114, 121, 128, 143, 157, 171, 185, 214, 250]
+144: [100, 108, 115, 122, 129, 144, 158, 172, 187, 216, 250]
+145: [101, 108, 116, 123, 130, 145, 159, 174, 188, 217, 250]
+146: [102, 109, 116, 124, 131, 146, 160, 175, 189, 219, 250]
+147: [102, 110, 117, 124, 132, 147, 161, 176, 191, 220, 250]
+148: [103, 111, 118, 125, 133, 148, 162, 177, 192, 222, 250]
+149: [104, 111, 119, 126, 134, 149, 163, 178, 193, 223, 250]
+150: [105, 112, 120, 127, 135, 150, 165, 180, 195, 225, 250]
+151: [105, 113, 120, 128, 135, 151, 166, 181, 196, 226, 250]
+152: [106, 114, 121, 129, 136, 152, 167, 182, 197, 228, 250]
+153: [107, 114, 122, 130, 137, 153, 168, 183, 198, 229, 250]
+154: [107, 115, 123, 130, 138, 154, 169, 184, 200, 231, 250]
+155: [108, 116, 124, 131, 139, 155, 170, 186, 201, 232, 250]
+156: [109, 117, 124, 132, 140, 156, 171, 187, 202, 234, 250]
+157: [109, 117, 125, 133, 141, 157, 172, 188, 204, 235, 250]
+158: [110, 118, 126, 134, 142, 158, 173, 189, 205, 237, 250]
+159: [111, 119, 127, 135, 143, 159, 174, 190, 206, 238, 250]
+160: [112, 120, 128, 136, 144, 160, 176, 192, 208, 240, 250]
+161: [112, 120, 128, 136, 144, 161, 177, 193, 209, 241, 250]
+162: [113, 121, 129, 137, 145, 162, 178, 194, 210, 243, 250]
+163: [114, 122, 130, 138, 146, 163, 179, 195, 211, 244, 250]
+164: [114, 123, 131, 139, 147, 164, 180, 196, 213, 246, 250]
+165: [115, 123, 132, 140, 148, 165, 181, 198, 214, 247, 250]
+166: [116, 124, 132, 141, 149, 166, 182, 199, 215, 249, 250]
+167: [116, 125, 133, 141, 150, 167, 183, 200, 217, 250, 250]
+168: [117, 126, 134, 142, 151, 168, 184, 201, 218, 250, 250]
+169: [118, 126, 135, 143, 152, 169, 185, 202, 219, 250, 250]
+170: [119, 127, 136, 144, 153, 170, 187, 204, 220, 250, 250]
+171: [119, 128, 136, 145, 153, 171, 188, 205, 222, 250, 250]
+172: [120, 129, 137, 146, 154, 172, 189, 206, 223, 250, 250]
+173: [121, 129, 138, 147, 155, 173, 190, 207, 224, 250, 250]
+174: [121, 130, 139, 147, 156, 174, 191, 208, 226, 250, 250]
+175: [122, 131, 140, 148, 157, 175, 192, 210, 227, 250, 250]
+176: [123, 132, 140, 149, 158, 176, 193, 211, 228, 250, 250]
+177: [123, 132, 141, 150, 159, 177, 194, 212, 230, 250, 250]
+178: [124, 133, 142, 151, 160, 178, 195, 213, 231, 250, 250]
+179: [125, 134, 143, 152, 161, 179, 196, 214, 232, 250, 250]
+180: [126, 135, 144, 153, 162, 180, 198, 216, 233, 250, 250]
+181: [126, 135, 144, 153, 162, 181, 199, 217, 235, 250, 250]
+182: [127, 136, 145, 154, 163, 182, 200, 218, 236, 250, 250]
+183: [128, 137, 146, 155, 164, 183, 201, 219, 237, 250, 250]
+184: [128, 138, 147, 156, 165, 184, 202, 220, 239, 250, 250]
+185: [129, 138, 148, 157, 166, 185, 203, 222, 240, 250, 250]
+186: [130, 139, 148, 158, 167, 186, 204, 223, 241, 250, 250]
+187: [130, 140, 149, 158, 168, 187, 205, 224, 243, 250, 250]
+188: [131, 141, 150, 159, 169, 188, 206, 225, 244, 250, 250]
+189: [132, 141, 151, 160, 170, 189, 207, 226, 245, 250, 250]
+190: [133, 142, 152, 161, 171, 190, 209, 228, 246, 250, 250]
+191: [133, 143, 152, 162, 171, 191, 210, 229, 248, 250, 250]
+192: [134, 144, 153, 163, 172, 192, 211, 230, 249, 250, 250]
+193: [135, 144, 154, 164, 173, 193, 212, 231, 250, 250, 250]
+194: [135, 145, 155, 164, 174, 194, 213, 232, 250, 250, 250]
+195: [136, 146, 156, 165, 175, 195, 214, 234, 250, 250, 250]
+196: [137, 147, 156, 166, 176, 196, 215, 235, 250, 250, 250]
+197: [137, 147, 157, 167, 177, 197, 216, 236, 250, 250, 250]
+198: [138, 148, 158, 168, 178, 198, 217, 237, 250, 250, 250]
+199: [139, 149, 159, 169, 179, 199, 218, 238, 250, 250, 250]
+200: [140, 150, 160, 170, 180, 200, 220, 240, 250, 250, 250]
diff --git a/server/gamedata/missions.yaml b/server/gamedata/missions.yaml
@@ -16,18 +16,16 @@
credits: 20
experience: 100
- # Fixed reconstruction pool; original membership and probabilities are unresolved.
+ # Reconstruction pool at mission QL; original membership and probabilities are unresolved.
reward_items: [85596, 122691]
- reward_quality: 2
# Native-tested open passage; historical mission-style selection is unresolved.
passage_door: 41565
- # Fixed encounter selection and positions are reconstruction policy.
+ # Fixed species/positions at mission level are reconstruction policy.
# Species appearance, weapon and loot use the shared admitted NPC profile.
encounters:
- definition: 950/district/2/group/0/authored_point
- level: 1
positions:
- [15, 0, 46]
- [15, 0, 43]
diff --git a/server/gamedata/types.go b/server/gamedata/types.go
@@ -30,14 +30,14 @@ type MissionTemplate struct {
Experience uint32 `yaml:"experience"`
RewardItem uint32 `yaml:"-"` // Concrete choice saved with an advertised contract.
RewardItems []uint32 `yaml:"reward_items"`
- RewardQuality uint32 `yaml:"reward_quality"`
+ RewardQuality uint32 `yaml:"reward_quality"` // Zero selects the mission level.
Encounters []MissionEncounter `yaml:"encounters"`
PassageDoor uint32 `yaml:"passage_door"`
}
type MissionEncounter struct {
Definition string `yaml:"definition"`
- Level uint16 `yaml:"level"`
+ Level uint16 `yaml:"level"` // Zero selects the mission level.
Positions [][3]float32 `yaml:"positions"`
}
diff --git a/server/mission_levels_test.go b/server/mission_levels_test.go
@@ -0,0 +1,264 @@
+package main
+
+import (
+ "ao/server/gamedata"
+ "bytes"
+ "encoding/binary"
+ "fmt"
+ "testing"
+)
+
+func TestMissionScalableRewardsFollowEveryDifficultyAndFamilyBoundary(t *testing.T) {
+ for _, scenario := range []struct {
+ level uint16
+ qualities [11]uint32
+ }{
+ {1, [11]uint32{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}},
+ {2, [11]uint32{1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3}},
+ {10, [11]uint32{7, 7, 8, 8, 9, 10, 11, 12, 13, 15, 17}},
+ {20, [11]uint32{14, 15, 16, 17, 18, 20, 22, 24, 26, 30, 35}},
+ {90, [11]uint32{63, 67, 72, 76, 81, 90, 99, 108, 116, 135, 161}},
+ {112, [11]uint32{78, 84, 89, 95, 100, 112, 123, 134, 145, 168, 200}},
+ {200, [11]uint32{140, 150, 160, 170, 180, 200, 220, 240, 250, 250, 250}},
+ } {
+ for index, quality := range scenario.qualities {
+ t.Run(fmt.Sprintf("level%d/difficulty%d", scenario.level, index+1), func(t *testing.T) {
+ world, output := newMissionOfferWorld(t)
+ t.Cleanup(func() { world.db.Close() })
+ player := world.characters[1]
+ player.level = scenario.level
+ inventory := player.inventory
+ inventory.Credits = 1000
+ if err := world.saveInventory_locked(player, inventory); err != nil {
+ t.Fatal(err)
+ }
+ definition := gamedata.MissionTemplates[3221228472]
+ definition.RewardItems = []uint32{85596, 122691}
+ gamedata.MissionTemplates[3221228472] = definition
+ world.combatRoll = func(bound uint32) uint32 { return bound - 1 }
+ request := missionOffersRequest()
+ request[17] = byte(index + 1)
+ output.packets = nil
+
+ if err := world.handleMissionOffers(world.clients[1], request); err != nil {
+ t.Fatal(err)
+ }
+ cold := newTestInventoryServer(t)
+
+ if quality > 200 {
+ if world.clients[1].missionOffer != nil || player.inventory.Credits != 1000 || cold.characters[1].inventory.Credits != 1000 || len(output.packets) != 1 {
+ t.Fatal("unsupported reward quality charged or advertised an endpoint", quality)
+ }
+ return
+ }
+ offer := world.clients[1].missionOffer
+ low, high := uint32(122691), uint32(122692)
+ if quality > 20 {
+ low, high = 85596, 85595
+ }
+ if offer == nil || offer.definition.RewardItem != low || offer.definition.RewardQuality != quality ||
+ player.inventory.Credits != 1000-uint32(scenario.level) || cold.characters[1].inventory.Credits != player.inventory.Credits ||
+ len(output.packets) != 2 || world.nextItem != 1 || len(player.missions) != 0 ||
+ gamedata.MissionTemplates[3221228472].RewardQuality != 0 || len(gamedata.MissionTemplates[3221228472].RewardItems) != 2 {
+ t.Fatal("offer lost selected quality, eligibility or fee", offer)
+ }
+ if quality == 1 {
+ high = low
+ }
+ if quality == 20 && low == 122691 || quality == 200 {
+ low = high
+ }
+ var advertised []byte
+ for _, word := range []uint32{2018, low, high, quality, 0} {
+ advertised = binary.BigEndian.AppendUint32(advertised, word)
+ }
+ if !bytes.Contains(output.packets[1], advertised) {
+ t.Fatal("native reward endpoints differ from selected QL")
+ }
+ })
+ }
+ }
+}
+
+func TestMissionSelectedEncounterLevelsAndQualitySurviveRecipeAndPlayerChanges(t *testing.T) {
+ world, _ := newMissionOfferWorld(t)
+ t.Cleanup(func() { world.db.Close() })
+ player, client := world.characters[1], world.clients[1]
+ player.level, world.nextNPC = 2, 2000000
+ definition := gamedata.MissionTemplates[3221228472]
+ definition.RewardItems = []uint32{122691}
+ definition.Encounters = []gamedata.MissionEncounter{{Definition: "950/district/2/group/0/authored_point", Positions: [][3]float32{{15, 0, 43}, {15, 0, 46}}}}
+ gamedata.MissionTemplates[3221228472] = definition
+
+ if err := world.handleMissionOffers(client, missionOffersRequest()); err != nil {
+ t.Fatal(err)
+ }
+ if client.missionOffer == nil {
+ t.Fatal("supported level-two offer was rejected")
+ }
+ offer := *client.missionOffer
+ definition.Encounters[0].Level, definition.RewardQuality = 1, 1
+ gamedata.MissionTemplates[3221228472] = definition
+ player.level = 3
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleMissionAcceptance(client, missionAcceptanceRequest(offer)); err != nil {
+ t.Fatal(err)
+ }
+ cold := reloadMissionEntranceWorld(t)
+
+ mission := cold.characters[1].missions[0]
+ if offer.definition.RewardQuality != 2 || offer.definition.Encounters[0].Level != 2 ||
+ mission.offer.definition.RewardQuality != 2 || mission.offer.definition.RewardItem != 122691 ||
+ cold.characters[1].inventory.Credits != 3 || cold.characters[1].level != 3 || cold.nextNPC != 2000002 {
+ t.Fatal("acceptance regenerated an already advertised contract", offer, mission)
+ }
+ for _, id := range []uint32{2000000, 2000001} {
+ npc := cold.characters[id]
+ if npc.level != 2 || npc.combatProfile != gamedata.NPCCombatProfiles[17655][2] || npc.health != 100 {
+ t.Fatal("selected encounter level did not survive cold load", npc)
+ }
+ var level uint16
+ if err := cold.db.QueryRow("SELECT level FROM mission_encounters WHERE npc_id=?", id).Scan(&level); err != nil || level != 2 {
+ t.Fatal("population history lost the selected level", level, err)
+ }
+ }
+}
+
+func TestMissionUnsupportedEncounterLevelDoesNotChargeOrAllocate(t *testing.T) {
+ world, output := newMissionOfferWorld(t)
+ t.Cleanup(func() { world.db.Close() })
+ player := world.characters[1]
+ player.level = 2
+ definition := gamedata.MissionTemplates[3221228472]
+ definition.RewardItems = []uint32{122691}
+ definition.Encounters = []gamedata.MissionEncounter{{Definition: "950/district/2/group/0/authored_point", Positions: [][3]float32{{15, 0, 43}}}}
+ gamedata.MissionTemplates[3221228472] = definition
+ request := missionOffersRequest()
+ request[17] = 11
+ output.packets = nil
+
+ if err := world.handleMissionOffers(world.clients[1], request); err != nil {
+ t.Fatal(err)
+ }
+ cold := newTestInventoryServer(t)
+
+ if world.clients[1].missionOffer != nil || len(output.packets) != 1 || player.inventory.Credits != 5 ||
+ cold.characters[1].inventory.Credits != 5 || world.nextItem != 1 || len(player.missions) != 0 {
+ t.Fatal("unimplemented level-three encounters produced a paid or partial contract")
+ }
+ request[17] = 6
+ if err := world.handleMissionOffers(world.clients[1], request); err != nil {
+ t.Fatal(err)
+ }
+ if world.clients[1].missionOffer == nil || world.clients[1].missionOffer.definition.Encounters[0].Level != 2 || player.inventory.Credits != 3 {
+ t.Fatal("a supported retry did not charge once and advertise level two")
+ }
+}
+
+func TestMissionExplicitQualityAndEncounterLevelRemainIndependentOfDifficulty(t *testing.T) {
+ world, _ := newMissionOfferWorld(t)
+ t.Cleanup(func() { world.db.Close() })
+ world.characters[1].level = 2
+ definition := gamedata.MissionTemplates[3221228472]
+ definition.RewardItems, definition.RewardQuality = []uint32{122691}, 1
+ definition.Encounters = []gamedata.MissionEncounter{{Definition: "950/district/2/group/0/authored_point", Level: 1, Positions: [][3]float32{{15, 0, 43}}}}
+ gamedata.MissionTemplates[3221228472] = definition
+ request := missionOffersRequest()
+ request[17] = 11
+
+ if err := world.handleMissionOffers(world.clients[1], request); err != nil {
+ t.Fatal(err)
+ }
+
+ offer := world.clients[1].missionOffer
+ if offer == nil || offer.definition.RewardQuality != 1 || offer.definition.Encounters[0].Level != 1 || world.characters[1].inventory.Credits != 3 {
+ t.Fatal("level-three selection replaced an explicitly fixed contract value", offer)
+ }
+}
+
+func TestMissionScalableRewardGenerationThroughReturnAndColdOwnership(t *testing.T) {
+ for _, level := range []uint16{1, 2} {
+ t.Run(fmt.Sprint(level), func(t *testing.T) {
+ world, _ := newMissionOfferWorld(t)
+ t.Cleanup(func() { world.db.Close() })
+ player, client := world.characters[1], world.clients[1]
+ player.level = level
+ definition := gamedata.MissionTemplates[3221228472]
+ definition.RewardItems = []uint32{122691}
+ gamedata.MissionTemplates[3221228472] = definition
+
+ if err := world.handleMissionOffers(client, missionOffersRequest()); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleMissionAcceptance(client, missionAcceptanceRequest(*client.missionOffer)); err != nil {
+ t.Fatal(err)
+ }
+ player.geometry = world.geometry
+ player.position, player.rotation = [3]float32{89.30216, 115.75, 152.5}, [4]float32{0, 1, 0, 0}
+ if err := world.handleMovement(client, playerMovementRequest(player, 1)); err != nil {
+ t.Fatal(err)
+ }
+ world.clients[1], client.ready, client.loading = client, true, false
+ player.movement = playerMovement{}
+ player.position = world.worldItems[3].position
+ if err := world.handleInventory(client, worldPickupRequest(1, 3)); err != nil {
+ t.Fatal(err)
+ }
+ destination := player.userData()
+ destination.Playfield, destination.Position = 3000, gamedata.MissionBooths[3221228472].Position
+ if err := world.updateUser_locked(destination); err != nil {
+ t.Fatal(err)
+ }
+ world.clients[1], client.ready, client.loading = client, true, false
+ if err := world.handleMissionReturn(client, missionReturnRequest(1)); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleMissionReturn(client, missionReturnRequest(2)); err != nil {
+ t.Fatal(err)
+ }
+ cold := reloadMissionEntranceWorld(t)
+
+ reward := cold.characters[1].inventory.Items[1]
+ if reward.ID != 4 || reward.Template != 122691 || reward.Quality != uint32(level) || reward.Slot != 65 || reward.Count != 1 ||
+ len(cold.characters[1].inventory.Items) != 2 || cold.characters[1].inventory.Credits != 25-uint32(level) ||
+ cold.nextItem != 4 || len(cold.characters[1].missions) != 0 || !cold.missionExpiry[0].completed {
+ t.Fatal("the generated selected-quality reward was lost, replaced or paid twice", reward)
+ }
+ })
+ }
+}
+
+func TestMissionScalableGenerationFeeFailureRetainsRecipeAndPermitsRetry(t *testing.T) {
+ world, output := newMissionOfferWorld(t)
+ t.Cleanup(func() { world.db.Close() })
+ world.characters[1].level = 2
+ definition := gamedata.MissionTemplates[3221228472]
+ definition.RewardItems = []uint32{122691}
+ definition.Encounters = []gamedata.MissionEncounter{{Definition: "950/district/2/group/0/authored_point", Positions: [][3]float32{{15, 0, 43}}}}
+ gamedata.MissionTemplates[3221228472] = definition
+ if _, err := world.db.Exec("CREATE TRIGGER fail_scaled_offer BEFORE UPDATE OF credits ON players BEGIN SELECT RAISE(FAIL,'offer'); END"); err != nil {
+ t.Fatal(err)
+ }
+ output.packets = nil
+
+ failure := world.handleMissionOffers(world.clients[1], missionOffersRequest())
+ cold := newTestInventoryServer(t)
+
+ if failure == nil || len(output.packets) != 0 || world.clients[1].missionOffer != nil || world.characters[1].inventory.Credits != 5 ||
+ cold.characters[1].inventory.Credits != 5 || gamedata.MissionTemplates[3221228472].Encounters[0].Level != 0 ||
+ gamedata.MissionTemplates[3221228472].RewardQuality != 0 || world.nextItem != 1 {
+ t.Fatal("failed generation changed the recipe, wallet or live identities", failure)
+ }
+ if _, err := world.db.Exec("DROP TRIGGER fail_scaled_offer"); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleMissionOffers(world.clients[1], missionOffersRequest()); err != nil {
+ t.Fatal(err)
+ }
+ offer := world.clients[1].missionOffer
+ if offer == nil || offer.definition.RewardQuality != 2 || offer.definition.Encounters[0].Level != 2 || world.characters[1].inventory.Credits != 3 {
+ t.Fatal("retry did not retain one coherent level-two contract", offer)
+ }
+}
diff --git a/server/mission_offers.go b/server/mission_offers.go
@@ -5,6 +5,7 @@ import (
"encoding/binary"
"math"
"math/rand/v2"
+ "slices"
)
type missionOffer struct {
@@ -117,6 +118,35 @@ func (server *server) handleMissionOffers(client *worldClient, body []byte) erro
if exists {
originator, accepted = server.missionBoothEligibility_locked(client, booth)
}
+ // Resolve the generation recipe once, before charging or advertising a contract.
+ if supported {
+ level := gamedata.MissionLevels[player.level][body[17]-1]
+ supported = level != 0
+ definition.Encounters = slices.Clone(definition.Encounters)
+ for index := range definition.Encounters {
+ encounter := &definition.Encounters[index]
+ if encounter.Level == 0 {
+ encounter.Level = level
+ }
+ group := gamedata.NPCGroups[encounter.Definition]
+ if group == nil || npcCombatProfile(group.ID, group.MonsterData, encounter.Level) == nil {
+ supported = false
+ }
+ }
+ if len(definition.RewardItems) != 0 {
+ if definition.RewardQuality == 0 {
+ definition.RewardQuality = uint32(level)
+ }
+ var rewards []uint32
+ for _, template := range definition.RewardItems {
+ if gamedata.ItemQualitySupported(template, definition.RewardQuality) {
+ rewards = append(rewards, template)
+ }
+ }
+ supported = supported && len(rewards) != 0
+ definition.RewardItems = rewards
+ }
+ }
if !exists || !supported || !accepted || uint32(body[28]) != originator || player.inventory.Credits < uint32(player.level) || len(player.missions) != 0 {
// The complete empty reply resets the native Generating Mission state.
client.missionOffer = nil