commit b5e2b554c2b2a81185d783bb83fb52aa63030156
parent 929583fac45c4e5db2a8ba890e3e4ae87d452087
Author: anon <anon@example.com>
Date: Sun, 25 Oct 2026 02:02:05 +0000
Support ordinary maximum health buffs and native resource accounting
Diffstat:
20 files changed, 601 insertions(+), 63 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -585,6 +585,12 @@ introduction and starting-item gameplay remain open below.
Resolve combat health delivery rather than limiting healing to idle use.
- [ ] Cancel an in-progress cast. Check: the applicable cancellation/refund rule
is followed and no delayed heal or duplicate result occurs.
+- [ ] Reconcile native HP during maximum-health buff replacement/refresh under
+ incoming weapon combat. Native modifier removal can clamp to the intermediate
+ maximum; idle casts now correct HP immediately after action 177. The existing quiet
+ HP path deliberately waits for weapon queues to drain. Resolve the shared
+ combat health-delivery contract together with healing, without disabling
+ 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] Apply one temporary stat buff. Check: the native effect appears, the stat
@@ -599,14 +605,18 @@ introduction and starting-item gameplay remain open below.
share authored casting criteria, NCU/strain, cost and duration. Tests cover
cancellation, exact expiry, death, failed persistence and cold restore with
additive equipment. See [temporary nanos](docs/nano-buffs.md).
-- [ ] Complete the seven remaining delta programs from the13-program audit.
- Titan Physique29254 and95693..95697 also modify MaxHealth1 and need the complete
- direct nano maximum-health consumer, clamps and their authored flags/lifecycle.
- Blood Circle27803 has special flags, no strain and zero casting cost/timing;
- research its actual delivery path. The complete original records are retained
- in `local/regeneration-nano-research/catalog/`. Never grant just a supported
- subset of an unfinished program. Keep passive deltas distinct from periodic
- heal-over-time functions.
+- [x] Support the six complete health/delta programs from the13-program audit.
+ Titan Physique29254 and95693..95697 apply both MaxHealth1 and HealDelta343.
+ Improve Health27085 and Soldier startup Body Boost29091 share the same direct
+ health consumer. Cover both skill gates, profession/quality boundaries, final
+ HP clamps, failed writes/COMMIT, expiry/death, cold restore and observer
+ foundations after inspection/team snapshots. See [health buffs](docs/nano-health-buffs.md).
+- [ ] Research Blood Circle27803 and special Iron Circle42052 delivery.
+ Their flags and zero casting cost/timing do not qualify as ordinary casts;
+ Blood Circle also omits strain. Retain complete original contracts in
+ `local/maximum-resource-nano-research/catalog/`. Never grant just a supported
+ subset of an unfinished program; passive deltas remain distinct from
+ periodic heal-over-time functions.
- [x] Enforce NCU capacity. Check: a buff fitting the available NCU succeeds and
one exceeding it is rejected without charging resources incorrectly.
Native checks cover exact fit at 8/8, rejecting a 9-NCU replacement without
@@ -1029,6 +1039,11 @@ and unresolved indoor lifecycle are explicit in [flight](docs/vehicles.md#yalmah
native text explains the rejection, without the action-46 contract error.
Repeated attempts preserve IDs/counts/placements and the bank opening anchor.
Protocol tests preserve pending equipment work when bank requests overlap it.
+- [ ] Complete Unique acquisition checks beyond bank/backpack transfers.
+ Audit corpse loot, shop purchases and future player trading using the same
+ source-backed low-template scope, including Unique crystals inside carried
+ bags, duplicate races, rejection without debit/loss and cold recovery. Keep
+ deliberate GM fixture creation distinct from ordinary acquisition.
- [x] Exercise bank Unique/NoDrop transfers, native Delete cancellation and
confirmation, Ctrl-split, ordinary-inventory merge/redeposit and bank layout
persistence through browser reload. Check IDs, counts and placements against
diff --git a/docs/combat-regeneration.md b/docs/combat-regeneration.md
@@ -115,9 +115,11 @@ cover the negative consumer independently of catalog admission.
The complete implant audit adds 1,596 definitions whose remaining consumers
are these two deltas. Implants with another unsupported effect still reject
-as whole items; see [implants](implants.md). Six complete ordinary delta programs
-support native crystal learning and casting through the same recovery consumers;
-see [temporary nanos](nano-buffs.md#passive-regeneration-programs).
+as whole items; see [implants](implants.md). Twelve complete ordinary delta
+programs support native crystal learning and casting through the same recovery
+consumers; six also modify maximum health. See
+[temporary nanos](nano-buffs.md#passive-regeneration-programs) and
+[health buffs](nano-health-buffs.md).
Recovery stays in memory until a vitals checkpoint; equipping or removing
these implants persists placement immediately without forcing unrelated vitals
updates when the resource caps are unchanged.
diff --git a/docs/nano-buffs.md b/docs/nano-buffs.md
@@ -1,24 +1,28 @@
# Temporary nano research for 14.9.1
Ordinary ability and passive regeneration buffs share one timed-effect path.
-Complete-contract checks admit 21 original programs and their 21 crystals.
+Complete-contract checks admit 29 original programs and their 29 crystals.
Learning and casting remain separate operations; arbitrary nano functions are
not enabled by this family.
## Complete contract admission
Programs require native header51051, ItemType0, Can0 and the audited raw
-Flags0 value `0x80010000`. Duration, NCU, strain, cost, range, attack and recharge
-must be positive finite values. Every effect is unconditional OnUse53045,
+Flags0 values `0x80010000` or `0x10000`. Both carry BuffNano0x10000 and lack the
+hostile/nonoverwrite flags used by the reviewed cast and cancellation paths.
+These are two exact audited values, not a claim that arbitrary other flag bits
+are harmless. Duration, NCU, strain, cost, range, attack and recharge
+must be positive finite values. Each OnUse0 effect is an unconditional Modify53045,
target3, tick1/interval0, with two integer arguments and an implemented consumer.
-Positive ability16..21, HealDelta343 and NanoDelta364 modifiers qualify.
+Positive MaxHealth1, ability16..21, HealDelta343 and NanoDelta364 modifiers qualify.
Signed SkillLockModifier382 also has a verified consumer, but no original
nano uses it; its synthetic lifecycle fixtures remain separate from content.
The checker validates ordinary attack-weight dictionaries4/4 and getter-mode
maps6/27, plus action3 criteria22/36. Unknown metadata, additional effects,
other events, conditions or repetition reject the whole program. An ordinary
-crystal requires header51005, Flags0=`0x80400203`, Can30=`0x29`, Count26=1 and
+crystal requires header51005, one audited Flags0 value (`0x80400203`,
+`0x00400203` or `0x88400203`), Can30=`0x29`, Count26=1 and
exactly one unconditional OnUse LearnNano53019, target2, for an admitted program.
Only its original authored quality is accepted; bulk TESTITEM uploads reject.
@@ -30,10 +34,10 @@ VisualProfession368 criteria are distinct IDs; both currently read the saved
profession because false-profession effects are not implemented. Unsupported
predicates fail closed, including inside OR expressions.
-The complete audit covers all4,366 decoded nanos and re-parses62 selected
+The complete audit covers all4,366 decoded nanos and re-parses66 selected
program/crystal payloads from the original ResourceDatabase. Raw records,
-hashes, exact RPN criteria and the 21-program admission boundary are in
-`local/regeneration-nano-research/catalog/`. Raw flags identify this bounded
+hashes, exact RPN criteria and the 29-program admission boundary are in
+`local/maximum-resource-nano-research/catalog/`. Raw flags identify this bounded
content class; they are not reinterpreted as evidence of historical death or
offline-clock rules.
@@ -56,10 +60,11 @@ replace each other. Refresh retains one contribution and NCU allocation.
Equipment and different strains add their deltas once. Cancellation, expiry
and the current ordinary-buff death policy remove each contribution through65.
-Blood Circle27803 and the special Iron Circle42052 contract do not qualify.
-The other six delta programs combine MaxHealth1 with343; that direct nano
-maximum-health consumer remains unfinished, so the entire program and its
-crystal remain unavailable. No partial delta effect is granted.
+Six further delta programs combine MaxHealth1 with343 and use the same complete
+timed-effect path. Improve Health and the Soldier startup Body Boost also
+qualify; see [health buffs](nano-health-buffs.md) for all eight additions and
+their resource accounting. Blood Circle27803 and the special Iron Circle42052
+contract remain unavailable. No partial effect is granted.
## Additional ability programs
diff --git a/docs/nano-health-buffs.md b/docs/nano-health-buffs.md
@@ -0,0 +1,134 @@
+# Ordinary maximum-health nanos
+
+Eight complete original programs add positive MaxHealth1 through the shared
+timed-buff path. Six also add HealDelta343. Original ResourceDatabase records,
+full postfix requirements, flag variants and payload hashes are retained in
+`local/maximum-resource-nano-research/catalog/`. This extends the ordinary
+family to 29 programs and 29 crystals; no complete candidate needs MaxNano221,
+so that direct nano consumer remains unsupported.
+
+| Program | Crystal/QL | HP | HealDelta | NCU | Duration |
+| --- | --- | ---: | ---: | ---: | --- |
+| Improve Health 27085 | 27216/7 | 10 | 0 | 3 | 20 min |
+| Body Boost 29091 | 29092/1 | 20 | 0 | 1 | 30 min |
+| Titan Physique 29254 | 29366/113 | 416 | 2 | 35 | 50 min |
+| Survivor's Resilience 95693 | 95724/139 | 361 | 3 | 43 | 60 min |
+| Tough as Nails 95694 | 95725/63 | 176 | 2 | 20 | 40 min |
+| Combat Hardening 95695 | 95723/33 | 105 | 1 | 11 | 35 min |
+| Boot Camp Toughness 95696 | 95727/17 | 58 | 1 | 6 | 30 min |
+| Battlefield Endurance 95697 | 95726/152 | 405 | 3 | 47 | 60 min |
+
+Improve Health has strain 80 and no profession restriction. All seven Soldier
+programs have strain 151 and require VisualProfession368 equal to 1. Their
+Biological Metamorphosis128 and Matter Creation130 criteria retain the original
+strict comparisons. Improve Health uses Biological/Matter Metamorphosis.
+Crystal and program requirements are evaluated separately through the shared
+postfix evaluator; a crystal's quality is independent of the program's quality.
+
+The common strain priority uses NCU, not HP size: Survivor's Resilience (43 NCU)
+can replace Titan Physique (35 NCU) despite reducing the HP bonus from 416 to 361.
+Completion clamps current
+HP to the final maximum and commits that clamp with the new effect, caster
+cost and recharge. Statement or COMMIT failure retains the old effect and HP,
+refunds the pending reservation and publishes no replacement. Additions and
+upgrades do not grant current HP. Cancellation and expiry clamp excess HP
+atomically with removal. Death uses the existing ordinary-buff removal policy.
+
+Native replacement removes the old MaxHealth modifier before applying the new
+one. Its removal handler can temporarily clamp HP to the intermediate maximum,
+even on refresh or an upgrade whose authoritative HP stays unchanged. Such
+casts therefore publish a quiet HP correction after action 177 and any resource
+foundation updates. This adds no database write when actual HP is unchanged.
+Health reconciliation during weapon combat retains the broader unresolved
+delivery limitation described in [Doctor healing](nano-healing.md); maximum
+foundation accounting during combat is covered separately.
+
+## Native resource foundations
+
+`kkr.dll!100bd600` applies Modify53045 through 10074730/10074b00. Stat getters
+add this modifier to cached MaxHealth1, independently of the formula derived
+from breed, level, profession/title and effective Body Development.
+FullCharacter, owner replay corrections and SimpleChar therefore exclude
+direct nano bonuses from their foundations; action 177 adds the contribution once.
+
+Inspection and TeamMemberInfo instead publish complete maxima and zero the
+native additive modifier entry. Per-connection accounting records both the
+authored equipment bonus and active direct nano bonus absorbed by that snapshot.
+Subsequent combat corrections, equipment changes and skill training preserve
+that observer's foundation, even after leaving the team. Actor replacement
+resets the accounting. Owner equipment overequipping remains separate: the
+owner applies the effective gear bonus, while observer accounting uses the
+authored OnWear bonus. Ability-buff trickle remains in the derived foundation.
+
+Complete original Modify/add/remove records and exact Evidence IDs are retained
+in `local/maximum-resource-nano-research/native-health-reused-evidence.json`.
+They reuse the original 14.9.1 KKR SHA-256
+`a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0`.
+The separate team/inspection receiver evidence is documented in
+[team resources](team-resources.md) and [inspection](character-info.md).
+
+## Flags and remaining policies
+
+Two exact program Flags0 variants qualify: 0x80010000 and 0x10000. All carry
+BuffNano0x10000, with no hostile0x8000 or nonoverwrite0x800000 bit in the reviewed
+native paths. Bounded original disassembly identifies a high-bit surface
+collision use for entity flags; this does not prove every program-template
+consumer or historical server flag policy. The original cancellation sender
+checks hostile0x8000, and the add path checks BuffNano0x10000.
+
+The Soldier startup crystal uses the existing Unique0x08000000 variant, matching
+the Doctor and Bureaucrat startup crystals. Unique remains distinct from NoDrop.
+Generic admission recognizes only the three actual whole-crystal flag values;
+it does not clear arbitrary bits. Broader Unique acquisition through loot,
+shops and player trading remains separate unfinished work.
+
+Blood Circle27803 and the special Iron Circle42052 remain unavailable: zero
+casting values, special flags and Blood Circle's missing strain require their
+actual delivery contracts. No partial HP/delta effect is enabled. Historical
+offline timing, death-persistent exceptions, final-allocation NCU admission and
+the server's clamp policy retain the limits described in
+[temporary nanos](nano-buffs.md#reconstruction-policies-and-remaining-checks).
+
+## Verification
+
+Go regressions exercise all eight original crystal uploads, exact qualities,
+both skill gates and profession boundaries, casts, costs, NCU and complete
+modifiers. Lifecycle checks cover cancellation, exact authored expiry, death,
+cold recovery, self/other recipient clamps, failed health writes and deferred
+COMMIT failure. Observer checks cover inspection, team departure, combat before
+and after a snapshot, cancellation and subsequent skill training. Refresh tests
+reject any database health update when authoritative HP is unchanged.
+
+The full maintained Go suite passed in 625.767s, with gamedata passing in
+7.772s. Focused race checks passed in 137.454s; build and vet also passed.
+The final unchanged-health write regression passed in 9.068s. Logs are in
+`local/maximum-resource-nano-checks/`.
+
+Two real WASM clients used the GPU OpenGL renderer on the sole HTTPS
+preview. All eight crystals were uploaded and consumed through native UI, and
+all eight programs delivered their complete effects with exact observed nano
+debits. A team recipient with Dust Collector reached 2,023 HP under Improve
+Health and Titan Physique; replacing Titan with Survivor's Resilience clamped
+both native views and SQLite to 1,968. Battlefield Endurance exceeded capacity
+until Improve Health was cancelled, then fit exactly at 47/47 NCU. Restart
+replayed its remaining lifetime and modifier once.
+
+The first upgrade trace reproduced a temporary native HP drop from 1,958 to
+1,597. After the correction, an actual Endurance refresh retained 2,002 current
+and maximum HP in all 220 samples over 12 seconds. Leaving the team and
+cancelling restored 1,597. Native removal of Dust Collector restored 1,507;
+equipping Pioneer then produced 1,510 in owner and former teammate views. Both
+clients retained that maximum after reload.
+
+`local/maximum-resource-nano-smoke/tmp_verify.py` checks all 28 required captures,
+native packet streams, SQLite snapshots, costs, NCU, modifier foundations and
+the two HP traces. The eight crystals were consumed once and the four remaining
+fixture instances retained their IDs, counts and final placements. Both owned
+browser contexts closed without errors or unimplemented adapter calls. Cleanup
+removed only the two owned characters and their four items; hashes of every
+unrelated row were unchanged, and SQLite foreign key and integrity checks passed.
+
+Fixtures used GM-created Soldier characters with high skills and NCU ears,
+qualified original backpacks and one control-editor HP fill to isolate the
+lower-maximum replacement. Original nano durations and recharge deadlines were
+not shortened. These checks do not close the combat HP delivery gap above.
diff --git a/docs/nano-learning.md b/docs/nano-learning.md
@@ -26,12 +26,18 @@ basic ability Boost crystals and QL 4 Augment Strength now share this upload
path. Their exact crystal/program IDs and qualities are tabulated there;
each uses its authored LearnNano function and requirements.
-Complete-contract admission now covers21 ordinary ability/regeneration crystals.
+Complete-contract admission now covers29 ordinary ability, health and regeneration crystals.
Both upload and casting use the shared postfix requirement evaluator, including
the authored BM/MM/PM/MC thresholds and real or visual profession predicates.
The full program, crystal and quality tables are in
[temporary nanos](nano-buffs.md#complete-contract-admission).
+The Soldier startup Body Boost crystal29092/QL1 uploads29091 through this
+generic path. Its Unique flag variant matches the Doctor/Bureaucrat startup
+crystals; it requires BM>8, MC>6 and VisualProfession368==1. All eight complete
+health-buff additions and their original crystal qualities are listed in
+[maximum-health nanos](nano-health-buffs.md).
+
## Requirements and character data
The Meta-Physicist crystal's Use action requires effective Matter Creation 130 greater than 7,
diff --git a/docs/team-resources.md b/docs/team-resources.md
@@ -59,7 +59,7 @@ receive team resource fields. No resource replication writes to the database.
Outside combat, TeamMemberInfo corrects all eight fields. During outgoing or
incoming combat, ordinary stat packets correct the seven non-HP fields and
leave current HP on the native impact timeline. Each connection records the
-direct equipment bonuses absorbed by its last full snapshot. Later stat
+direct equipment and nano health bonuses absorbed by its last full snapshot. Later stat
corrections use that observer's basis, including after departure from the team:
the native actor retains its folded maxima until it is replaced. Equipment
changes between snapshots can otherwise double or lose bonuses. Actor spawn
@@ -78,6 +78,10 @@ of the owning player's private skills, so exact intermediate prediction parity
still needs original producer/capture evidence. Authoritative snapshots correct
the displayed resources; this does not establish every historical timing rule.
+Ordinary [maximum-health nanos](nano-health-buffs.md) use the same observer
+accounting. Their Modify1 contribution stays separate in normal spawn/replay
+foundations, and is included in the absorbed total after a complete snapshot.
+
## Verification
Go regressions cover initial wire order/values, current and equipped maxima,
diff --git a/server/character_info.go b/server/character_info.go
@@ -47,12 +47,12 @@ func (server *server) handleCharacterInfo(client *worldClient, body []byte) erro
}
packet := characterInfoPacket(target)
if target.id != client.id {
- // Remote InfoPacket overwrites raw health maxima, absorbing existing OnWear bonuses.
+ // Remote InfoPacket folds direct equipment and nano health bonuses into its maximum.
if client.absorbedBonuses == nil {
client.absorbedBonuses = make(map[uint32]resourceBonuses)
}
bonuses := client.absorbedBonuses[target.id]
- bonuses.health = target.inventory.equipmentBonus(1)
+ bonuses.health = target.directHealthBonus()
client.absorbedBonuses[target.id] = bonuses
}
server.mutex.Unlock()
diff --git a/server/combat.go b/server/combat.go
@@ -130,7 +130,12 @@ func (character *character) maximumHealth() uint32 {
stats := [8][3]uint32{{2, 2, 2}, {10, 6, 3}, {15, 5, 3}, {10, 5, 2}, {25, 6, 4}, {15, 8, 6}, {2, 2, 2}, {2, 2, 2}}[character.appearance>>4&7]
base := character.baseStats()
bodyDevelopment := character.effectiveSkill(152, base.Body.BodyDevelopment, [6]uint32{0, 0, 100, 0, 0, 0})
- return uint32(int32(stats[0]) + int32(character.level)*int32(stats[1]+gamedata.ProfessionTitles[max(1, character.profession)].Health[character.titleLevel()-1]) + bodyDevelopment*int32(stats[2]) + character.equipmentBonus(1))
+ return uint32(int32(stats[0]) + int32(character.level)*int32(stats[1]+gamedata.ProfessionTitles[max(1, character.profession)].Health[character.titleLevel()-1]) + bodyDevelopment*int32(stats[2]) + character.equipmentBonus(1) + character.nanoBonus(1))
+}
+
+func (character *character) directHealthBonus() int32 {
+ // Native snapshots separate authored OnWear/Modify bonuses from the foundation.
+ return character.inventory.equipmentBonus(1) + character.nanoBonus(1)
}
func (character *character) maximumNano() uint32 {
diff --git a/server/equipment.go b/server/equipment.go
@@ -257,7 +257,7 @@ func (server *server) advanceEquipment(now time.Time) {
position = predictedPosition_locked(character, client, now)
}
health, nano := character.health, character.nano
- baseHealth := character.maximumHealth() - uint32(character.inventory.equipmentBonus(1))
+ baseHealth := character.maximumHealth() - uint32(character.directHealthBonus())
baseNano := character.maximumNano() - uint32(character.inventory.equipmentBonus(221))
attackRating := character.attackRating()
if err := server.saveInventory_locked(character, inventory); err != nil {
@@ -295,7 +295,7 @@ func (server *server) advanceEquipment(now time.Time) {
}
// Ability modifiers change derived foundations that the native client caches.
for _, stat := range [][3]uint32{
- {1, baseHealth, character.maximumHealth() - uint32(character.inventory.equipmentBonus(1))},
+ {1, baseHealth, character.maximumHealth() - uint32(character.directHealthBonus())},
{221, baseNano, character.maximumNano() - uint32(character.inventory.equipmentBonus(221))},
{22, uint32(attackRating), uint32(character.attackRating())},
} {
diff --git a/server/ip_training.go b/server/ip_training.go
@@ -112,7 +112,7 @@ func (server *server) handleSkillTraining(client *worldClient, body []byte) erro
server.mutex.Unlock()
return err
}
- baseHealth := player.maximumHealth() - uint32(player.inventory.equipmentBonus(1))
+ baseHealth := player.maximumHealth() - uint32(player.directHealthBonus())
baseNano := player.maximumNano() - uint32(player.inventory.equipmentBonus(221))
attackRating := player.attackRating()
movementChanged := player.maximumHealth() != updated.maximumHealth() ||
@@ -122,7 +122,7 @@ func (server *server) handleSkillTraining(client *worldClient, body []byte) erro
player.position, client.movementStarted = position, now
}
for _, stat := range [][3]uint32{
- {1, baseHealth, player.maximumHealth() - uint32(player.inventory.equipmentBonus(1))},
+ {1, baseHealth, player.maximumHealth() - uint32(player.directHealthBonus())},
{221, baseNano, player.maximumNano() - uint32(player.inventory.equipmentBonus(221))},
{22, uint32(attackRating), uint32(player.attackRating())},
} {
diff --git a/server/main.go b/server/main.go
@@ -384,7 +384,7 @@ func (server *server) serveWorldClient(client *worldClient) error {
updates = append(updates, activeNanoPackets(character, time.Now())...)
if len(character.activeNanos) != 0 {
// FullCharacter recomputes maxima before the later ability replay.
- for _, stat := range [][2]uint32{{1, character.maximumHealth() - uint32(character.equipmentBonus(1))}, {221, character.maximumNano() - uint32(character.inventory.equipmentBonus(221))}} {
+ for _, stat := range [][2]uint32{{1, character.maximumHealth() - uint32(character.equipmentBonus(1)+character.nanoBonus(1))}, {221, character.maximumNano() - uint32(character.inventory.equipmentBonus(221))}} {
body := binary.BigEndian.AppendUint32(nil, stat[0])
body = binary.BigEndian.AppendUint32(body, stat[1])
updates = append(updates, n3Packet(0x2b333d6e, 50000, character.id, body))
diff --git a/server/maximum_health_nano_test.go b/server/maximum_health_nano_test.go
@@ -0,0 +1,325 @@
+package main
+
+import (
+ "encoding/binary"
+ "fmt"
+ "slices"
+ "testing"
+ "time"
+)
+
+func newMaximumHealthNanoWorld(t *testing.T) (*server, *combatTestConn) {
+ t.Helper()
+ world, conn := newStatBuffWorld(t)
+ player := world.characters[1]
+ player.level, player.profession = 1, 1
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ return world, conn
+}
+
+func TestMaximumHealthNanoCrystalsLearnCastRestoreAndCancel(t *testing.T) {
+ for _, fixture := range []struct {
+ crystal, program, quality uint32
+ health, delta, ncu, debit uint32
+ }{
+ {27216, 27085, 7, 47, 0, 3, 24}, {29092, 29091, 1, 57, 0, 1, 10},
+ {29366, 29254, 113, 453, 2, 35, 415}, {95724, 95693, 139, 398, 3, 43, 519},
+ {95725, 95694, 63, 213, 2, 20, 240}, {95723, 95695, 33, 142, 1, 11, 145},
+ {95727, 95696, 17, 95, 1, 6, 82}, {95726, 95697, 152, 442, 3, 47, 580},
+ } {
+ t.Run(fmt.Sprint(fixture.program), func(t *testing.T) {
+ world, conn := newMaximumHealthNanoWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ if granted, err := world.grantItem_locked(player, fixture.crystal); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+
+ if err := world.handleOwnedItemUse(client, backpackUseRequest(1, 64, 1)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if len(conn.packets) != 3 || binary.BigEndian.Uint32(conn.packets[1][37:41]) != fixture.quality {
+ t.Fatal("original health crystal upload was rejected or changed quality")
+ }
+ castTestBuff(t, world, 1, 1, fixture.program)
+ cold := newTestInventoryServer(t).characters[1]
+ packet := fullCharacterPacket(cold)
+ cursor := 60 + len(cold.inventory.Items)*32 + len(cold.inventory.LearnedNanos)*4
+ cursor += 4 + 8*int(binary.BigEndian.Uint32(packet[cursor:])/1009-1)
+ count := int(binary.BigEndian.Uint32(packet[cursor:])/1009 - 1)
+ stats := make(map[uint32]uint32)
+ for offset := cursor + 4; offset < cursor+4+count*8; offset += 8 {
+ stats[binary.BigEndian.Uint32(packet[offset:])] = binary.BigEndian.Uint32(packet[offset+4:])
+ }
+
+ if player.maximumHealth() != fixture.health || cold.maximumHealth() != fixture.health || player.health != 20 || cold.health != 20 ||
+ player.nanoBonus(343) != int32(fixture.delta) || player.usedNCU() != fixture.ncu || player.nano != 1000-fixture.debit ||
+ cold.nano != player.nano || !slices.Equal(cold.inventory.LearnedNanos, []uint32{fixture.program}) || len(cold.inventory.Items) != 1 || stats[1] != 37 {
+ t.Fatal("complete health buff changed current HP, lost an effect or failed cold recovery", player.maximumHealth(), cold.maximumHealth(), player.health, player.nano)
+ }
+ if err := world.handleNanoRemoval(client, characterActionPacket(1, [5]uint32{65, 0, 0, 53019, fixture.program})[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if player.maximumHealth() != 37 || player.health != 20 || player.nanoBonus(343) != 0 || player.usedNCU() != 0 ||
+ len(newTestInventoryServer(t).characters[1].activeNanos) != 0 {
+ t.Fatal("health buff cancellation retained its maximum or delta")
+ }
+ })
+ }
+}
+
+func TestMaximumHealthNanoReplacementClampsAndCommitsTheFinalMaximum(t *testing.T) {
+ for _, scenario := range []string{"success", "failed health write", "failed commit"} {
+ t.Run(scenario, func(t *testing.T) {
+ world, conn := newMaximumHealthNanoWorld(t)
+ player := world.characters[1]
+ player.inventory.LearnedNanos = []uint32{29254, 95693}
+ castTestBuff(t, world, 1, 1, 29254)
+ player.health = 453
+ if err := world.savePosition_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ if scenario == "failed health write" {
+ if _, err := world.db.Exec("CREATE TRIGGER fail_health_buff BEFORE UPDATE OF health ON characters BEGIN SELECT RAISE(FAIL, 'test health buff'); END"); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if scenario == "failed commit" {
+ if _, err := world.db.Exec(`CREATE TABLE invalid_health_buff (player_id INTEGER REFERENCES players(id) DEFERRABLE INITIALLY DEFERRED);
+ CREATE TRIGGER fail_health_buff AFTER UPDATE OF health ON characters BEGIN INSERT INTO invalid_health_buff VALUES (999999); END`); err != nil {
+ t.Fatal(err)
+ }
+ }
+ player.nanoRechargeUntil = time.Time{}
+ conn.packets = nil
+
+ // Higher NCU priority can replace a larger HP bonus with a smaller one.
+ castTestBuff(t, world, 1, 1, 95693)
+ cold := newTestInventoryServer(t).characters[1]
+
+ if scenario != "success" {
+ if player.health != 453 || cold.health != 453 || player.maximumHealth() != 453 || cold.maximumHealth() != 453 ||
+ player.nano != 585 || cold.nano != 585 || player.activeNanos[0].program != 29254 {
+ t.Fatal("failed replacement changed health, effects or the refunded reservation")
+ }
+ for _, packet := range conn.packets {
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x5e477770 && binary.BigEndian.Uint32(packet[29:33]) == 177 {
+ t.Fatal("failed health write published the replacement")
+ }
+ }
+ return
+ }
+ if player.maximumHealth() != 398 || cold.maximumHealth() != 398 || player.health != 398 || cold.health != 398 ||
+ player.nano != 66 || cold.nano != 66 || player.usedNCU() != 43 || player.nanoBonus(343) != 3 ||
+ len(player.activeNanos) != 1 || player.activeNanos[0].program != 95693 || player.savedVitals.Health != 398 {
+ t.Fatal("replacement did not atomically clamp to its final maximum", player.health, cold.health, player.maximumHealth(), player.nano)
+ }
+ })
+ }
+}
+
+func TestMaximumHealthNanoReplacementPersistsTheOtherRecipientsClamp(t *testing.T) {
+ world, _ := newMaximumHealthNanoWorld(t)
+ player := world.characters[1]
+ caster := *player
+ caster.id, caster.name = 2, "Health Caster"
+ caster.inventory = playerInventory{LearnedNanos: []uint32{29254, 95693}}
+ world.characters[2], world.nextCharacter = &caster, 2
+ world.clients[2] = &worldClient{id: 2, conn: &combatTestConn{}, ready: true, target: true}
+ if err := world.saveUser_locked(&caster); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.saveInventory_locked(&caster, caster.inventory); err != nil {
+ t.Fatal(err)
+ }
+ castTestBuff(t, world, 2, 1, 29254)
+ player.health = 453
+ if err := world.savePosition_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ caster.nanoRechargeUntil = time.Time{}
+
+ castTestBuff(t, world, 2, 1, 95693)
+ cold := newTestInventoryServer(t)
+
+ if player.health != 398 || cold.characters[1].health != 398 || player.maximumHealth() != 398 || player.savedVitals.Health != 398 ||
+ caster.health != 20 || cold.characters[2].health != 20 || caster.nano != 66 || cold.characters[2].nano != 66 ||
+ player.nano != 1000 || cold.characters[1].nano != 1000 || player.activeNanos[0].caster != 2 {
+ t.Fatal("recipient health clamp was lost or charged to its caster")
+ }
+}
+
+func TestMaximumHealthNanoReplacementAndRefreshRestoreUnchangedNativeHP(t *testing.T) {
+ for _, program := range []uint32{29254, 95693} {
+ t.Run(fmt.Sprint(program), func(t *testing.T) {
+ world, conn := newMaximumHealthNanoWorld(t)
+ player := world.characters[1]
+ player.nano = 1100
+ player.inventory.LearnedNanos = []uint32{29091, program}
+ castTestBuff(t, world, 1, 1, 29091)
+ player.health = 57
+ if err := world.savePosition_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := world.db.Exec("CREATE TRIGGER reject_unchanged_health BEFORE UPDATE OF health ON characters BEGIN SELECT RAISE(FAIL, 'unchanged health'); END"); err != nil {
+ t.Fatal(err)
+ }
+ player.nanoRechargeUntil = time.Time{}
+ conn.packets = nil
+
+ castTestBuff(t, world, 1, 1, program)
+
+ var add, correction int
+ for index, packet := range conn.packets {
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x5e477770 && binary.BigEndian.Uint32(packet[29:33]) == 177 {
+ add = index + 1
+ }
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x3710256c {
+ correction = index + 1
+ if binary.BigEndian.Uint32(packet[29:33]) != 57 || binary.BigEndian.Uint32(packet[33:37]) != 0 {
+ t.Fatal("replacement correction changed HP or showed damage feedback")
+ }
+ }
+ }
+ if add == 0 || correction <= add || player.health != 57 || newTestInventoryServer(t).characters[1].health != 57 {
+ t.Fatal("native modifier removal can clamp HP without a following authoritative correction", add, correction)
+ }
+
+ // Refresh must correct the same temporary native removal without adding HP.
+ player.nanoRechargeUntil = time.Time{}
+ conn.packets = nil
+ castTestBuff(t, world, 1, 1, program)
+ corrections := 0
+ for _, packet := range conn.packets {
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x3710256c && binary.BigEndian.Uint32(packet[29:33]) == 57 {
+ corrections++
+ }
+ }
+ if corrections != 1 || player.health != 57 || len(player.activeNanos) != 1 {
+ t.Fatal("refresh omitted native HP reconciliation or duplicated state", corrections, player.health)
+ }
+ })
+ }
+}
+
+func TestMaximumHealthNanoExpiryClampsAtTheAuthoredDeadline(t *testing.T) {
+ for _, fixture := range []struct {
+ program uint32
+ minutes time.Duration
+ }{
+ {27085, 20}, {29091, 30}, {29254, 50}, {95693, 60},
+ {95694, 40}, {95695, 35}, {95696, 30}, {95697, 60},
+ } {
+ t.Run(fmt.Sprint(fixture.program), func(t *testing.T) {
+ world, conn := newMaximumHealthNanoWorld(t)
+ player := world.characters[1]
+ player.inventory.LearnedNanos = []uint32{fixture.program}
+ castTestBuff(t, world, 1, 1, fixture.program)
+ deadline := player.activeNanos[0].expiresAt
+ player.health = player.maximumHealth()
+ if err := world.savePosition_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ conn.packets = nil
+
+ world.advanceNanos(deadline.Add(-time.Nanosecond))
+ if len(player.activeNanos) != 1 || player.activeNanos[0].remaining != fixture.minutes*time.Minute || len(conn.packets) != 0 {
+ t.Fatal("health buff expired early or used a different duration")
+ }
+ world.advanceNanos(deadline)
+ world.advanceNanos(deadline.Add(time.Second))
+ cold := newTestInventoryServer(t).characters[1]
+
+ if player.health != 37 || cold.health != 37 || player.maximumHealth() != 37 || cold.maximumHealth() != 37 ||
+ player.usedNCU() != 0 || len(cold.activeNanos) != 0 || player.nanoBonus(343) != 0 {
+ t.Fatal("expiry retained a maximum, delta, excess HP or NCU")
+ }
+ removals := 0
+ for _, packet := range conn.packets {
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x5e477770 && binary.BigEndian.Uint32(packet[29:33]) == 65 {
+ removals++
+ }
+ }
+ if removals != 1 {
+ t.Fatal("health buff expiry did not publish exactly one removal", removals)
+ }
+ })
+ }
+}
+
+func TestMaximumHealthNanoObserverBasisSurvivesCancellationAndTraining(t *testing.T) {
+ for _, scenario := range []string{"quiet team", "inspection", "departed team", "combat before snapshot", "combat after snapshot"} {
+ t.Run(scenario, func(t *testing.T) {
+ world, connections := newResourceBackpackTeam(t)
+ player := world.characters[1]
+ player.stats.NanoAiding.MatterMetamorphosis, player.stats.NanoAiding.BiologicalMetamorphosis = 47, 39
+ player.stats.Body.NanoPool, player.nano = 400, 1000
+ player.inventory.LearnedNanos = []uint32{27085}
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.saveInventory_locked(player, player.inventory); err != nil {
+ t.Fatal(err)
+ }
+ if scenario == "combat before snapshot" {
+ player.fighting = 3
+ player.rechargeUntil = time.Now().Add(time.Minute)
+ world.fighting[1] = player
+ }
+ castTestBuff(t, world, 1, 1, 27085)
+ if scenario == "inspection" || scenario == "departed team" {
+ if err := world.handleTeamAction(world.clients[1], teamRequest(1, 24, 0, 0)); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if scenario == "inspection" {
+ if err := world.handleCharacterInfo(world.clients[2], teamRequest(2, 105, 1, 0)); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if scenario == "combat after snapshot" {
+ player.fighting = 3
+ world.fighting[1] = player
+ }
+ absorbed := int32(100)
+ if scenario == "combat before snapshot" {
+ absorbed = 90
+ }
+ if player.maximumHealth() != 149 || world.clients[2].absorbedBonuses[1].health != absorbed {
+ t.Fatal("snapshot did not account for both equipment and nano health bonuses", player.maximumHealth(), world.clients[2].absorbedBonuses)
+ }
+
+ if err := world.handleNanoRemoval(world.clients[1], characterActionPacket(1, [5]uint32{65, 0, 0, 53019, 27085})[20:]); err != nil {
+ t.Fatal(err)
+ }
+ for _, connection := range connections {
+ connection.packets = nil
+ }
+ stats := player.baseStats()
+ stats.Body.BodyDevelopment = 6
+ if err := world.handleSkillTraining(world.clients[1], skillTrainingRequest(stats)[20:]); err != nil {
+ t.Fatal(err)
+ }
+
+ if player.maximumHealth() != 142 || newTestInventoryServer(t).characters[1].maximumHealth() != 142 || player.nanoBonus(1) != 0 {
+ t.Fatal("training retained the cancelled health modifier")
+ }
+ peer := uint32(152)
+ if scenario == "quiet team" || scenario == "combat before snapshot" {
+ peer = 142
+ }
+ for index, expected := range []uint32{52, peer, 52} {
+ var maxima []uint32
+ for _, packet := range connections[index].packets {
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x2b333d6e && binary.BigEndian.Uint32(packet[24:28]) == 1 && binary.BigEndian.Uint32(packet[29:33]) == 1 {
+ maxima = append(maxima, binary.BigEndian.Uint32(packet[33:37]))
+ }
+ }
+ if !slices.Equal(maxima, []uint32{expected}) {
+ t.Fatal("maximum correction lost the observer's absorbed modifier basis", index, maxima, expected)
+ }
+ }
+ })
+ }
+}
diff --git a/server/nano_buffs.go b/server/nano_buffs.go
@@ -21,7 +21,10 @@ type activeNano struct {
func statBuffNano(program uint32) bool {
definition := gamedata.NanoTemplates[program]
if definition == nil || definition.RecordType != 1040005 || definition.HeaderWords[0] != 51051 || definition.Undecoded != nil ||
- itemStat(definition, 76) != 0 || itemStat(definition, 30) != 0 || itemStat(definition, 0) != 0x80010000 {
+ itemStat(definition, 76) != 0 || itemStat(definition, 30) != 0 {
+ return false
+ }
+ if flags := itemStat(definition, 0); flags != 0x80010000 && flags != 0x10000 {
return false
}
// Ordinary timed buffs have finite duration, NCU, strain, range and casting costs.
@@ -78,7 +81,7 @@ func statBuffNano(program uint32) bool {
}
stat, value := *function.Arguments[0].Integer, *function.Arguments[1].Integer
switch stat {
- case 16, 17, 18, 19, 20, 21, 343, 364:
+ case 1, 16, 17, 18, 19, 20, 21, 343, 364:
if value <= 0 {
return false
}
@@ -102,23 +105,29 @@ func (effect activeNano) remainingAt(now time.Time) time.Duration {
return max(0, effect.expiresAt.Sub(now))
}
-func (player *character) nanoBonus(stat uint32) int32 {
+func nanoProgramBonus(program, stat uint32) int32 {
var bonus int32
- for _, effect := range player.activeNanos {
- for _, section := range gamedata.NanoTemplates[effect.program].Sections {
- if section.Type != 2 || section.Subtype != 0 {
- continue
- }
- for _, function := range *section.Functions {
- if function.ID == 53045 && uint32(*function.Arguments[0].Integer) == stat {
- bonus += *function.Arguments[1].Integer
- }
+ for _, section := range gamedata.NanoTemplates[program].Sections {
+ if section.Type != 2 || section.Subtype != 0 {
+ continue
+ }
+ for _, function := range *section.Functions {
+ if function.ID == 53045 && uint32(*function.Arguments[0].Integer) == stat {
+ bonus += *function.Arguments[1].Integer
}
}
}
return bonus
}
+func (player *character) nanoBonus(stat uint32) int32 {
+ var bonus int32
+ for _, effect := range player.activeNanos {
+ bonus += nanoProgramBonus(effect.program, stat)
+ }
+ return bonus
+}
+
func (player *character) usedNCU() uint32 {
var used uint32
for _, effect := range player.activeNanos {
@@ -248,7 +257,7 @@ func (server *server) finishResourceChange_locked(updates map[*worldClient][][]b
// Refresh the native resource caches when derived maxima change.
for _, stat := range [][3]uint32{
- {1, previous.maximumHealth() - uint32(previous.inventory.equipmentBonus(1)), player.maximumHealth() - uint32(player.inventory.equipmentBonus(1))},
+ {1, previous.maximumHealth() - uint32(previous.directHealthBonus()), player.maximumHealth() - uint32(player.directHealthBonus())},
{221, previous.maximumNano() - uint32(previous.inventory.equipmentBonus(221)), player.maximumNano() - uint32(player.inventory.equipmentBonus(221))},
} {
if stat[1] != stat[2] {
diff --git a/server/nano_casting.go b/server/nano_casting.go
@@ -214,16 +214,22 @@ func (server *server) advanceNanos(now time.Time) {
victim = caster
}
var damage uint32
+ removedHealthBonus := false
if program == 29618 {
damage = min(10+rand.Uint32N(14), target.health)
victim = prepareDamage(player, target, damage, now)
} else {
// A strain has one contribution; a refresh replaces its deadline and caster.
victim.activeNanos = slices.DeleteFunc(slices.Clone(victim.activeNanos), func(effect activeNano) bool {
- return itemStat(gamedata.NanoTemplates[effect.program], 75) == itemStat(gamedata.NanoTemplates[program], 75)
+ if itemStat(gamedata.NanoTemplates[effect.program], 75) != itemStat(gamedata.NanoTemplates[program], 75) {
+ return false
+ }
+ removedHealthBonus = removedHealthBonus || nanoProgramBonus(effect.program, 1) != 0
+ return true
})
duration := time.Duration(itemStat(gamedata.NanoTemplates[program], 8)) * 10 * time.Millisecond
victim.activeNanos = append(victim.activeNanos, activeNano{program: program, caster: player.id, remaining: duration, expiresAt: now.Add(duration)})
+ victim.health = min(victim.health, victim.maximumHealth())
}
award, err := server.saveNanoOutcome_locked(&caster, &victim, now)
@@ -239,6 +245,10 @@ func (server *server) advanceNanos(now time.Time) {
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, itemStat(gamedata.NanoTemplates[program], 8)}))
server.finishResourceChange_locked(updates, target, previous, now)
+ if removedHealthBonus && target.health == previous.health {
+ // Native removal can clamp HP before adding the replacement or refresh.
+ server.queueQuietHealth_locked(updates, target)
+ }
continue
}
body := binary.BigEndian.AppendUint32(nil, uint32(-int32(damage)))
diff --git a/server/nano_learning.go b/server/nano_learning.go
@@ -9,7 +9,12 @@ import (
func statBuffCrystalProgram(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, 0) != 0x80400203 || itemStat(definition, 30) != 0x29 || itemStat(definition, 26) != 1 {
+ itemStat(definition, 30) != 0x29 || itemStat(definition, 26) != 1 {
+ return 0
+ }
+ switch itemStat(definition, 0) {
+ case 0x80400203, 0x88400203, 0x00400203:
+ default:
return 0
}
diff --git a/server/npc_outcome.go b/server/npc_outcome.go
@@ -163,10 +163,14 @@ func (server *server) saveNanoOutcome_locked(player, target *character, now time
return nil, fmt.Errorf("caster %d nano update affected %d rows", player.id, changed)
}
var state npcState
+ healthChanged := !target.npc && target.health != server.characters[target.id].health
if target.npc {
state, err = writeNPCOutcome_locked(tx, target, now)
} else {
err = writeActiveNanos(tx, target, now)
+ if err == nil && healthChanged {
+ err = updateRecord(tx, "characters", target.id, "health", []any{target.health})
+ }
}
if err != nil {
return nil, err
@@ -186,5 +190,8 @@ func (server *server) saveNanoOutcome_locked(player, target *character, now time
} else if target.id == player.id {
target.savedVitals = player.savedVitals
}
+ if healthChanged {
+ target.savedVitals.Health = target.health
+ }
return award, nil
}
diff --git a/server/regeneration_nano_test.go b/server/regeneration_nano_test.go
@@ -99,6 +99,7 @@ func TestRegenerationNanoDeathRemovesEffectsBeforeFurtherRecovery(t *testing.T)
profession uint16
}{
{27118, 1}, {27144, 1}, {28651, 10}, {28663, 10}, {29200, 8}, {30095, 8},
+ {27085, 1}, {29091, 1}, {29254, 1}, {95693, 1}, {95694, 1}, {95695, 1}, {95696, 1}, {95697, 1},
} {
t.Run(fmt.Sprint(fixture.program), func(t *testing.T) {
world, owner := newStatBuffWorld(t)
diff --git a/server/stat_buff_catalog_test.go b/server/stat_buff_catalog_test.go
@@ -56,12 +56,12 @@ func TestStatBuffCatalogAdmitsOnlyCompleteOrdinaryContracts(t *testing.T) {
slices.Sort(crystals)
// Exact IDs come from the independent complete-original-record catalog audit.
- if !slices.Equal(programs, []uint32{25988, 25989, 26342, 26355, 26356, 26357, 26358, 26359, 26360, 27086,
- 27118, 27134, 27144, 27154, 27168, 27169, 28651, 28663, 29200, 29652, 30095}) {
+ if !slices.Equal(programs, []uint32{25988, 25989, 26342, 26355, 26356, 26357, 26358, 26359, 26360, 27085, 27086,
+ 27118, 27134, 27144, 27154, 27168, 27169, 28651, 28663, 29091, 29200, 29254, 29652, 30095, 95693, 95694, 95695, 95696, 95697}) {
t.Fatal("buff admission differs from the complete effect/metadata audit", programs)
}
- if !slices.Equal(crystals, []uint32{26206, 26207, 26469, 26482, 26483, 26484, 26485, 26486, 26487, 27217,
- 27253, 27270, 27280, 27290, 27304, 27305, 28764, 28776, 29202, 29814, 30140}) {
+ if !slices.Equal(crystals, []uint32{26206, 26207, 26469, 26482, 26483, 26484, 26485, 26486, 26487, 27216, 27217,
+ 27253, 27270, 27280, 27290, 27304, 27305, 28764, 28776, 29092, 29202, 29366, 29814, 30140, 95723, 95724, 95725, 95726, 95727}) {
t.Fatal("crystal admission differs from the complete upload audit", crystals)
}
}
@@ -177,21 +177,29 @@ func TestStatBuffCrystalAndCastEnforceAuthoredSkillAndProfessionCriteria(t *test
base uint16
}{
{26207, 25988, 5, "PM", 131}, {26206, 25989, 5, "PM", 249},
- {27253, 27118, 1, "MM", 55}, {27280, 27144, 1, "BM", 58},
+ {27253, 27118, 0, "MM", 55}, {27280, 27144, 0, "BM", 58},
{28764, 28651, 10, "MC", 617}, {28776, 28663, 10, "MC", 324},
{29202, 29200, 8, "PM", 176}, {30140, 30095, 8, "PM", 423},
{29814, 29652, 9, "MM", 632},
+ {27216, 27085, 0, "BM", 36}, {27216, 27085, 0, "MM", 44},
+ {29092, 29091, 1, "BM", 6}, {29092, 29091, 1, "MC", 4},
+ {29366, 29254, 1, "BM", 530}, {29366, 29254, 1, "MC", 512},
+ {95724, 95693, 1, "BM", 653}, {95724, 95693, 1, "MC", 618},
+ {95725, 95694, 1, "BM", 297}, {95725, 95694, 1, "MC", 271},
+ {95723, 95695, 1, "BM", 172}, {95723, 95695, 1, "MC", 157},
+ {95727, 95696, 1, "BM", 93}, {95727, 95696, 1, "MC", 88},
+ {95726, 95697, 1, "BM", 727}, {95726, 95697, 1, "MC", 648},
} {
for _, scenario := range []string{"skill equality", "skill below", "one above", "profession mismatch"} {
- if scenario == "profession mismatch" && fixture.profession == 1 {
+ if scenario == "profession mismatch" && fixture.profession == 0 {
continue
}
- t.Run(fmt.Sprintf("%d/%s", fixture.program, scenario), func(t *testing.T) {
+ t.Run(fmt.Sprintf("%d/%s/%s", fixture.program, fixture.field, scenario), func(t *testing.T) {
world, conn := newStatBuffWorld(t)
player, client := world.characters[1], world.clients[1]
- player.profession = fixture.profession
+ player.profession = max(1, fixture.profession)
if scenario == "profession mismatch" {
- player.profession = 1
+ player.profession = 2
} else {
base := fixture.base
if scenario == "one above" {
@@ -244,7 +252,7 @@ func TestStatBuffCrystalAndCastEnforceAuthoredSkillAndProfessionCriteria(t *test
}
func TestStatBuffCastRejectsIncompleteOrSpecialContractsWithoutDebit(t *testing.T) {
- for _, scenario := range []string{"extra effect", "unsupported stat", "negative ability", "conditional effect", "repeated effect", "interval",
+ for _, scenario := range []string{"extra effect", "unsupported stat", "negative ability", "negative health", "conditional effect", "repeated effect", "interval",
"wrong target", "unknown section", "wrong mode", "bad weights", "special flags", "zero duration", "missing effect", "wrong arguments"} {
t.Run(scenario, func(t *testing.T) {
original := gamedata.NanoTemplates[27144]
@@ -257,9 +265,11 @@ func TestStatBuffCastRejectsIncompleteOrSpecialContractsWithoutDebit(t *testing.
case "extra effect":
functions = append(functions, gamedata.ItemFunction{ID: 53002})
case "unsupported stat":
- functions[0].Arguments[0].Integer = new(int32(1))
+ functions[0].Arguments[0].Integer = new(int32(221))
case "negative ability":
functions[0].Arguments[0].Integer, functions[0].Arguments[1].Integer = new(int32(16)), new(int32(-3))
+ case "negative health":
+ functions[0].Arguments[0].Integer, functions[0].Arguments[1].Integer = new(int32(1)), new(int32(-3))
case "conditional effect":
functions[0].Requirements = []gamedata.ItemRequirement{{Stat: 54, Operator: 2, Value: 1}}
case "repeated effect":
diff --git a/server/team_resources.go b/server/team_resources.go
@@ -29,7 +29,7 @@ func (server *server) teamResourcePacket_locked(owner uint32, member *character)
client.absorbedBonuses = make(map[uint32]resourceBonuses)
}
client.absorbedBonuses[member.id] = resourceBonuses{
- health: member.inventory.equipmentBonus(1), nano: member.inventory.equipmentBonus(221),
+ health: member.directHealthBonus(), nano: member.inventory.equipmentBonus(221),
}
body := binary.BigEndian.AppendUint32(nil, 50000)
body = binary.BigEndian.AppendUint32(body, member.id)
@@ -56,7 +56,7 @@ func (server *server) queueTeamResources_locked(updates map[*worldClient][][]byt
for _, stat := range teamResourceStats(member) {
if stat[0] != 27 {
if stat[0] == 1 {
- stat[1] += uint32(client.absorbedBonuses[member.id].health - member.inventory.equipmentBonus(1))
+ stat[1] += uint32(client.absorbedBonuses[member.id].health - member.directHealthBonus())
} else if stat[0] == 221 {
stat[1] += uint32(client.absorbedBonuses[member.id].nano - member.inventory.equipmentBonus(221))
}
diff --git a/server/world.go b/server/world.go
@@ -100,7 +100,7 @@ func characterPacket(character *character) []byte {
body = append(body, byte(character.level))
}
// Equipment actions also reach observers, so keep direct health bonuses separate.
- for _, value := range []uint32{character.maximumHealth() - uint32(character.inventory.equipmentBonus(1)), character.health, character.monsterData} {
+ for _, value := range []uint32{character.maximumHealth() - uint32(character.directHealthBonus()), character.health, character.monsterData} {
body = binary.BigEndian.AppendUint32(body, value)
}
body = binary.BigEndian.AppendUint16(body, character.baseScale())
@@ -207,7 +207,7 @@ func fullCharacterPacket(character *character) []byte {
[2]uint32{33, uint32(character.appearance >> 9 & 3)},
[2]uint32{59, uint32(character.appearance >> 7 & 3)},
// OnWear applies the direct modifiers; transmit their derived bases once.
- [2]uint32{27, character.health}, [2]uint32{1, character.maximumHealth() - uint32(character.equipmentBonus(1))},
+ [2]uint32{27, character.health}, [2]uint32{1, character.maximumHealth() - uint32(character.equipmentBonus(1)+character.nanoBonus(1))},
[2]uint32{37, character.titleLevel()}, [2]uint32{368, uint32(max(1, character.profession))},
[2]uint32{51, uint32(character.aggDef)}, [2]uint32{61, character.inventory.Credits},
[2]uint32{47, uint32(character.appearance >> 2 & 3)},