fix(all): preserve equipment health ratios and release updated server and client
release notes / releases (push) Successful in 2s
release notes / releases (push) Successful in 2s
This commit is contained in:
1 parent
34c92a745b
commit
dbfd30d089
11 files changed
+369
-6
No files matched your search
@@ -1,5 +1,59 @@
|
||||
# 更新日志
|
||||
|
||||
## server 2.37.13+server.0.2.3 · 2026-10-25
|
||||
|
||||
> type: update
|
||||
> migration: none
|
||||
|
||||
### en_us: Preserve health when changing equipment
|
||||
|
||||
- Equipping, removing or upgrading gear and switching presets now preserve the character's health percentage. Full health stays full, injured characters retain their health ratio, and defeated characters remain defeated.
|
||||
- Transferring equipped gear updates both characters' health together with the equipment change.
|
||||
|
||||
### zh_cn: 换装与切换预设保留生命比例
|
||||
|
||||
- 穿戴、卸下、强化装备或切换预设时,当前生命按新生命上限同比换算:满血保持满血,受伤保留比例,阵亡角色不会复活。
|
||||
- 转移已穿戴装备时,装备原持有者与接收者的生命会随装备一同保存。
|
||||
|
||||
### zh_tw: 換裝與切換預設保留生命比例
|
||||
|
||||
- 穿戴、卸下、強化裝備或切換預設時,目前生命會依新生命上限同比換算:滿血維持滿血,受傷保留比例,陣亡角色不會復活。
|
||||
- 轉移已穿戴裝備時,裝備原持有者與接收者的生命會隨裝備一同儲存。
|
||||
|
||||
### ja_jp: 装備変更時のHP割合を保持
|
||||
|
||||
- 装備の着脱・強化やプリセットの切り替え時に、変更後の最大HPに合わせて現在HPの割合を維持します。満タンなら満タンを維持し、戦闘不能のキャラクターは復活しません。
|
||||
- 装備を他のキャラクターへ移す際、両者のHPを装備変更と同時に保存します。
|
||||
|
||||
### ko_kr: 장비 변경 시 체력 비율 유지
|
||||
|
||||
- 장비 착용, 해제, 강화 및 프리셋 변경 시 새로운 최대 체력에 맞춰 현재 체력 비율을 유지합니다. 최대 체력은 그대로 유지되고, 부상 비율도 유지되며, 전투 불능 캐릭터는 부활하지 않습니다.
|
||||
- 착용한 장비를 옮기면 기존 착용자와 새 착용자의 체력을 장비 변경과 함께 저장합니다.
|
||||
|
||||
## client 2.37.13+client.0.2.13 · 2026-10-25
|
||||
|
||||
> type: update
|
||||
|
||||
### en_us: Fix health display after switching presets
|
||||
|
||||
- Prevent intermediate equipment changes while applying a preset from reducing a full-health character's HP. After all slots are applied, retain the server's final health value and refresh the display.
|
||||
|
||||
### zh_cn: 修复切换预设后的生命显示
|
||||
|
||||
- 修复应用预设时逐件替换装备导致满血角色变为受伤状态的问题;全部装备应用后保留服务端最终生命值,并刷新界面。
|
||||
|
||||
### zh_tw: 修正切換預設後的生命顯示
|
||||
|
||||
- 修正套用預設時逐件替換裝備,導致滿血角色變為受傷狀態的問題;全部裝備套用後保留伺服器最終生命值,並更新介面。
|
||||
|
||||
### ja_jp: プリセット切り替え後のHP表示を修正
|
||||
|
||||
- プリセット適用中の一時的な装備変更で満タンのHPが減る問題を修正しました。全スロットの適用後にサーバーの最終HPを保持し、表示を更新します。
|
||||
|
||||
### ko_kr: 프리셋 변경 후 체력 표시 수정
|
||||
|
||||
- 프리셋 적용 중 장비가 하나씩 바뀌면서 최대 체력 상태의 캐릭터 체력이 줄어드는 문제를 수정했습니다. 모든 장비 적용 후 서버의 최종 체력을 유지하고 화면을 갱신합니다.
|
||||
|
||||
## server 2.37.13+server.0.2.2 · 2026-10-25
|
||||
|
||||
> type: update
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"key_id": "6ba6c06138973875",
|
||||
"signature": "KuW/B3rJj8d+gr/fY1Bl5eDmZKCozep0y2BkmHkO/n2G2D6Jbfz3MW7p4qpNXXkQB0L1KX2wuV61K7DPRxf3DA=="
|
||||
"signature": "xc2YjF6k//tU0tJZSQT9uL7W75mwy26ysMXcWneNHEXARyUTHRlYDqqZDxsa61CdVuzwsqUdJQWVvMqoAShMBw=="
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
{"fingerprint":{"client_version":"2.37.13+client.0.2.12","game":{"build_origins":["https://cdn.dev.bd2.pmang.cloud","https://dl.dev.bd2.pmang.cloud"],"bundle_version":"20261022174708","catalog_bytes":67513445,"catalog_hash":"ae57bde3e9e5cf6ac57f9b0c0ea39b2f","catalog_sha256":"3e19c645e28b90d3601cd0ed7413dc516399ba2b658e0fa509686527048407b8","data_bytes":194804246,"data_sha256":"f3313a066dd2637678f728136d448adfd413259ae7129a79e109e7332b61a57d","game_bytes":413694732,"game_data_version":"20261021182514","game_path":"/Build/Windows/20261023/StandaloneWindows64.2.37.13.zip","game_sha256":"8f65954eb323fcffb1c29be13205d373d4f8fba3354e2e8d431d263bb2a6ca56","game_version":"2.37.13","platform":"StandaloneWindows64","resource_files":[{"path":"GameData/20261021182514/design.version","sha256":"816a6eaf2766663c792300ae0fc9333e8bf6c2c68b508b4e4f0400adfb194ee8","size":67},{"path":"GameData/20261021182514/release/common-dbdata.bin","sha256":"f3313a066dd2637678f728136d448adfd413259ae7129a79e109e7332b61a57d","size":194804246},{"path":"GameData/20261021182514/release/common-dbdata.info","sha256":"12168a51d330ab2858a765c60853a7feb123681d2d529d321834df97b6e05e4d","size":10},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/catalog_alpha.hash","sha256":"06d64c1f79022d9fc117fc45dc233e14ddbbf23ad1383d38f91006a1e4553ada","size":32},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/catalog_alpha.json","sha256":"3e19c645e28b90d3601cd0ed7413dc516399ba2b658e0fa509686527048407b8","size":67513445},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-avatar-char-group0_assets_charavatar.bundle","sha256":"c723a309b7b61bc2189f539f6911c852b21783b5fcb0a7a167e2f1d073fc2b5f","size":101738625},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-avatar-char-group0_scenes_charavatar.bundle","sha256":"56676c7f48d3d7c90f8956b02bc3f15f3074af7e8ff0ef64e1f9b8289eb08d52","size":31379},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-avatarfishingicon_1_assets_all.bundle","sha256":"3407127468d588ff84e5158d31f2b791fb144582fc914340d307e7b79b96be22","size":44897},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-avatarfishingicon_l_1_assets_all.bundle","sha256":"78ebf960a6b4f3b83fe28de1597e36f9ba7db1142bc1c0acdc9c65cd974cbbb4","size":2932480},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-avataricon_1_assets_all.bundle","sha256":"6bde00a738630d05afb42ee0fe84dd124b16de5b3ba16d62c08f5ea2657452ac","size":2888529},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-avatarlifehousing_1_assets_all.bundle","sha256":"1c844bc153dabe18b153157e466d7f7f0fa12e40c3b3ef6fc00af31abcf354e0","size":42443},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-avatarlifehousing_l_1_assets_all.bundle","sha256":"c12e4bae20aedf8889d7f916cca0b3d55167a4b787bd649e07f10d21db0c49bc","size":2334709},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-avatarlifeicon_1_assets_all.bundle","sha256":"bf6b432dc821a6e864993f649fedc1d03244d1ee2c93310bd0ce55d99ab8b743","size":16286},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-avatarlifeicon_l_1_assets_all.bundle","sha256":"528dec1ed0c867bb6dcd59b985dc3911280f5f560c0d4b000a1e979f46f6e335","size":824161},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-bgmalbum_1_assets_all.bundle","sha256":"16d606338d9b9e53a8d99d063613a8830dc943cb4225047f23b060f11614a7fc","size":614361},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-bundlecommon-effect-animation_assets_all.bundle","sha256":"8fb500400acf16f22516a298afbef6435c42c30969c762d7eee92c1d936cf06c","size":26191},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-bundlecommon-effect-animator_assets_all.bundle","sha256":"098045676a9b7d2c58703745bd608b2f9856027dd461012d3bde66d2f8266a16","size":6987},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-bundlecommon-effect-mesh_assets_all.bundle","sha256":"32a77141ffce92a510deb79f6af3309624b274c6e66493832946169a20612075","size":1617979},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-bundlecommon-effect-meterial_assets_all.bundle","sha256":"d4a379b7ee71e24a6eeecbd9967eeeb5f543b67d2403f736317b40ca281ed416","size":385296},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-bundlecommon-effect-prefab-group10_assets_all_8c26128b1b05c223d044c2f1d7f0e9dd.bundle","sha256":"71724987a41def2769d3bbdf79f1fb02933a0eb557d7f34a87c1e612e355c605","size":524718},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-bundlecommon-effect-prefab-group11_assets_all_7aa567cac538a20349cead4ca6de9a81.bundle","sha256":"31689c4ca268c96fd04e35d45f0bde1261b2810f32e339761889d1bebaaecfb6","size":665927},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-bundlecommon-effect-prefab-group12_assets_all_4913582d39e677c63c907a62c69f82cd.bundle","sha256":"e86c377fd87f65a6092545e559a6bdd483e932741c03fe42538e9b9bc7b5dcc0","size":526015},{"pLine truncated
|
||||
{"fingerprint":{"client_version":"2.37.13+client.0.2.13","game":{"build_origins":["https://cdn.dev.bd2.pmang.cloud","https://dl.dev.bd2.pmang.cloud"],"bundle_version":"20261022174708","catalog_bytes":67513445,"catalog_hash":"ae57bde3e9e5cf6ac57f9b0c0ea39b2f","catalog_sha256":"3e19c645e28b90d3601cd0ed7413dc516399ba2b658e0fa509686527048407b8","data_bytes":194804246,"data_sha256":"f3313a066dd2637678f728136d448adfd413259ae7129a79e109e7332b61a57d","game_bytes":413694732,"game_data_version":"20261021182514","game_path":"/Build/Windows/20261023/StandaloneWindows64.2.37.13.zip","game_sha256":"8f65954eb323fcffb1c29be13205d373d4f8fba3354e2e8d431d263bb2a6ca56","game_version":"2.37.13","platform":"StandaloneWindows64","resource_files":[{"path":"GameData/20261021182514/design.version","sha256":"816a6eaf2766663c792300ae0fc9333e8bf6c2c68b508b4e4f0400adfb194ee8","size":67},{"path":"GameData/20261021182514/release/common-dbdata.bin","sha256":"f3313a066dd2637678f728136d448adfd413259ae7129a79e109e7332b61a57d","size":194804246},{"path":"GameData/20261021182514/release/common-dbdata.info","sha256":"12168a51d330ab2858a765c60853a7feb123681d2d529d321834df97b6e05e4d","size":10},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/catalog_alpha.hash","sha256":"06d64c1f79022d9fc117fc45dc233e14ddbbf23ad1383d38f91006a1e4553ada","size":32},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/catalog_alpha.json","sha256":"3e19c645e28b90d3601cd0ed7413dc516399ba2b658e0fa509686527048407b8","size":67513445},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-avatar-char-group0_assets_charavatar.bundle","sha256":"c723a309b7b61bc2189f539f6911c852b21783b5fcb0a7a167e2f1d073fc2b5f","size":101738625},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-avatar-char-group0_scenes_charavatar.bundle","sha256":"56676c7f48d3d7c90f8956b02bc3f15f3074af7e8ff0ef64e1f9b8289eb08d52","size":31379},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-avatarfishingicon_1_assets_all.bundle","sha256":"3407127468d588ff84e5158d31f2b791fb144582fc914340d307e7b79b96be22","size":44897},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-avatarfishingicon_l_1_assets_all.bundle","sha256":"78ebf960a6b4f3b83fe28de1597e36f9ba7db1142bc1c0acdc9c65cd974cbbb4","size":2932480},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-avataricon_1_assets_all.bundle","sha256":"6bde00a738630d05afb42ee0fe84dd124b16de5b3ba16d62c08f5ea2657452ac","size":2888529},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-avatarlifehousing_1_assets_all.bundle","sha256":"1c844bc153dabe18b153157e466d7f7f0fa12e40c3b3ef6fc00af31abcf354e0","size":42443},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-avatarlifehousing_l_1_assets_all.bundle","sha256":"c12e4bae20aedf8889d7f916cca0b3d55167a4b787bd649e07f10d21db0c49bc","size":2334709},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-avatarlifeicon_1_assets_all.bundle","sha256":"bf6b432dc821a6e864993f649fedc1d03244d1ee2c93310bd0ce55d99ab8b743","size":16286},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-avatarlifeicon_l_1_assets_all.bundle","sha256":"528dec1ed0c867bb6dcd59b985dc3911280f5f560c0d4b000a1e979f46f6e335","size":824161},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-bgmalbum_1_assets_all.bundle","sha256":"16d606338d9b9e53a8d99d063613a8830dc943cb4225047f23b060f11614a7fc","size":614361},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-bundlecommon-effect-animation_assets_all.bundle","sha256":"8fb500400acf16f22516a298afbef6435c42c30969c762d7eee92c1d936cf06c","size":26191},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-bundlecommon-effect-animator_assets_all.bundle","sha256":"098045676a9b7d2c58703745bd608b2f9856027dd461012d3bde66d2f8266a16","size":6987},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-bundlecommon-effect-mesh_assets_all.bundle","sha256":"32a77141ffce92a510deb79f6af3309624b274c6e66493832946169a20612075","size":1617979},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-bundlecommon-effect-meterial_assets_all.bundle","sha256":"d4a379b7ee71e24a6eeecbd9967eeeb5f543b67d2403f736317b40ca281ed416","size":385296},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-bundlecommon-effect-prefab-group10_assets_all_8c26128b1b05c223d044c2f1d7f0e9dd.bundle","sha256":"71724987a41def2769d3bbdf79f1fb02933a0eb557d7f34a87c1e612e355c605","size":524718},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-bundlecommon-effect-prefab-group11_assets_all_7aa567cac538a20349cead4ca6de9a81.bundle","sha256":"31689c4ca268c96fd04e35d45f0bde1261b2810f32e339761889d1bebaaecfb6","size":665927},{"path":"ServerData/StandaloneWindows64/HD/20261022174708/common-bundlecommon-effect-prefab-group12_assets_all_4913582d39e677c63c907a62c69f82cd.bundle","sha256":"e86c377fd87f65a6092545e559a6bdd483e932741c03fe42538e9b9bc7b5dcc0","size":526015},{"pLine truncated
|
||||
@@ -922,6 +922,9 @@ func (s *EquipmentInventory) persistEquipmentState(ctx command.Context, next equ
|
||||
if s.corePresent && next.Version == s.persisted.Version {
|
||||
data = nil
|
||||
}
|
||||
if err := s.preserveEquipmentHealth(ctx, next); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.store.SaveWithEntries(ctx.State, "equipment", data, changes); err != nil {
|
||||
return fmt.Errorf("player: persist equipment %s: %w", operation, err)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package inventory
|
||||
|
||||
import (
|
||||
"bd2server/internal/server/domain/command"
|
||||
"fmt"
|
||||
"math/bits"
|
||||
"reflect"
|
||||
"slices"
|
||||
)
|
||||
|
||||
// The roster owns current HP; equipment only supplies the before/after stat
|
||||
// views. A zero maximum means the stat calculator has not been attached yet.
|
||||
type equipmentHealthSource interface {
|
||||
EquipmentHealth(command.Context, uint64) (uint64, uint64, error)
|
||||
SetCurrentHealth(command.Context, uint64, uint64) error
|
||||
}
|
||||
|
||||
func sameHealthEquipment(a, b Equipment) bool {
|
||||
a.LockFlag, a.KeepFlag, a.SortID, a.UpgradeAttempts, a.Mark = 0, 0, 0, 0, ""
|
||||
b.LockFlag, b.KeepFlag, b.SortID, b.UpgradeAttempts, b.Mark = 0, 0, 0, 0, ""
|
||||
return reflect.DeepEqual(a, b)
|
||||
}
|
||||
|
||||
func equipmentHealthRatio(current, previousMax, nextMax uint64) uint64 {
|
||||
if current == 0 || nextMax == 0 {
|
||||
return 0
|
||||
}
|
||||
if current >= previousMax {
|
||||
return nextMax
|
||||
}
|
||||
hi, lo := bits.Mul64(current, nextMax)
|
||||
hp, _ := bits.Div64(hi, lo, previousMax)
|
||||
// Changing equipment cannot kill a living character through integer rounding.
|
||||
return max(1, hp)
|
||||
}
|
||||
|
||||
func (s *EquipmentInventory) preserveEquipmentHealth(ctx command.Context, next equipmentSnapshot) error {
|
||||
health, ok := s.characters.(equipmentHealthSource)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
before := make(map[uint64]Equipment, len(s.persisted.Equipment))
|
||||
for _, item := range s.persisted.Equipment {
|
||||
before[item.InvenIndex] = item
|
||||
}
|
||||
affected := map[uint64]bool{}
|
||||
for _, item := range next.Equipment {
|
||||
old, exists := before[item.InvenIndex]
|
||||
if !exists || !sameHealthEquipment(old, item) {
|
||||
affected[old.UseChar], affected[item.UseChar] = true, true
|
||||
}
|
||||
delete(before, item.InvenIndex)
|
||||
}
|
||||
for _, item := range before {
|
||||
affected[item.UseChar] = true
|
||||
}
|
||||
delete(affected, 0)
|
||||
if len(affected) == 0 {
|
||||
return nil
|
||||
}
|
||||
indices := make([]uint64, 0, len(affected))
|
||||
for index := range affected {
|
||||
indices = append(indices, index)
|
||||
}
|
||||
slices.Sort(indices)
|
||||
original := s.owned
|
||||
defer func() { s.owned = original }()
|
||||
s.owned = s.persisted
|
||||
type snapshot struct{ current, maximum uint64 }
|
||||
oldHP := make(map[uint64]snapshot, len(indices))
|
||||
for _, index := range indices {
|
||||
current, maximum, err := health.EquipmentHealth(ctx, index)
|
||||
if err != nil {
|
||||
return fmt.Errorf("player: equipment health before change: %w", err)
|
||||
}
|
||||
if maximum != 0 {
|
||||
oldHP[index] = snapshot{current, maximum}
|
||||
}
|
||||
}
|
||||
s.owned = next
|
||||
for _, index := range indices {
|
||||
old, found := oldHP[index]
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
_, maximum, err := health.EquipmentHealth(ctx, index)
|
||||
if err != nil {
|
||||
return fmt.Errorf("player: equipment health after change: %w", err)
|
||||
}
|
||||
if maximum == old.maximum && old.current <= maximum {
|
||||
continue
|
||||
}
|
||||
if maximum == 0 {
|
||||
return fmt.Errorf("player: equipment left character %d without maximum health", index)
|
||||
}
|
||||
if err := health.SetCurrentHealth(ctx, index, equipmentHealthRatio(old.current, old.maximum, maximum)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package inventory_test
|
||||
|
||||
import (
|
||||
"bd2server/internal/server/domain/command"
|
||||
assets "bd2server/internal/server/domain/inventory"
|
||||
"bd2server/internal/server/domain/roster"
|
||||
accountstate "bd2server/internal/server/storage/account"
|
||||
"bd2server/internal/server/storage/instanceid"
|
||||
"bd2server/internal/server/storage/stateio"
|
||||
"context"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPresetEquipmentPreservesHealthRatiosAndPersistsTransfers(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
repo, err := accountstate.Open(filepath.Join(root, "state.db"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = repo.Close() })
|
||||
ids := instanceid.New(filepath.Join(root, "instance-ids.db"))
|
||||
var first, second uint64
|
||||
run := func(commit bool, action func(command.Context, *assets.EquipmentInventory, *roster.CharacterStore)) {
|
||||
t.Helper()
|
||||
tx, err := repo.BeginCommand(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
ctx := command.Context{State: tx, InstanceIDs: ids}
|
||||
scope := stateio.RootStore{}
|
||||
items, err := assets.OpenInventory(ctx, scope, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
characters, err := roster.OpenCharacterStore(ctx, scope, []roster.Character{
|
||||
{InvenIndex: 11, ID: 1, Level: 1, HP: 1000},
|
||||
{InvenIndex: 12, ID: 2, Level: 1, HP: 1000},
|
||||
{InvenIndex: 13, ID: 3, Level: 1, HP: 0},
|
||||
}, items, "", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
equipment, err := assets.OpenEquipmentInventory(ctx, scope)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := equipment.AttachCharacters(ctx, characters); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := equipment.AttachSlots(ctx, map[uint64]uint64{70: 0, 71: 0}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := characters.AttachMaxHealth(ctx, func(_ command.Context, c roster.Character) (uint64, error) {
|
||||
maximum := uint64(1000)
|
||||
for _, item := range equipment.All(ctx) {
|
||||
if item.UseChar == c.InvenIndex {
|
||||
maximum += map[uint64]uint64{70: 1000, 71: 3000}[item.ID]
|
||||
}
|
||||
}
|
||||
return maximum, nil
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := characters.EnsurePersisted(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
action(ctx, equipment, characters)
|
||||
if commit {
|
||||
if err := tx.Commit(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
bind := func(character, weapon uint64) assets.PresetEquipmentBinding {
|
||||
return assets.PresetEquipmentBinding{CharacterIndex: character, Equipment: []uint64{weapon, 0, 0, 0, 0}}
|
||||
}
|
||||
check := func(ctx command.Context, chars *roster.CharacterStore, index, want uint64) {
|
||||
t.Helper()
|
||||
got, err := chars.CurrentHealth(ctx, index)
|
||||
if err != nil || got != want {
|
||||
t.Fatalf("character %d current HP=%d, error=%v, want %d", index, got, err, want)
|
||||
}
|
||||
}
|
||||
run(true, func(ctx command.Context, equipment *assets.EquipmentInventory, chars *roster.CharacterStore) {
|
||||
a, err := equipment.GrantOnce(ctx, "a", 70)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b, err := equipment.GrantOnce(ctx, "b", 71)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
first, second = a.InvenIndex, b.InvenIndex
|
||||
if err := chars.SetCurrentHealth(ctx, 12, 500); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := equipment.ApplyPresetEquipment(ctx, []assets.PresetEquipmentBinding{bind(11, first)}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
check(ctx, chars, 11, 2000)
|
||||
})
|
||||
run(true, func(ctx command.Context, equipment *assets.EquipmentInventory, chars *roster.CharacterStore) {
|
||||
if _, err := equipment.ApplyPresetEquipment(ctx, []assets.PresetEquipmentBinding{bind(11, second), bind(12, first)}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
check(ctx, chars, 11, 4000) // Full HP remains full when the maximum increases.
|
||||
check(ctx, chars, 12, 1000) // Half HP remains half; it is not healed to full.
|
||||
})
|
||||
run(false, func(ctx command.Context, equipment *assets.EquipmentInventory, chars *roster.CharacterStore) {
|
||||
if _, err := equipment.ApplyPresetEquipment(ctx, []assets.PresetEquipmentBinding{bind(12, second)}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
check(ctx, chars, 11, 1000) // The donor loses its gear and remains full.
|
||||
check(ctx, chars, 12, 2000)
|
||||
})
|
||||
run(true, func(ctx command.Context, equipment *assets.EquipmentInventory, chars *roster.CharacterStore) {
|
||||
check(ctx, chars, 11, 4000) // The previous transaction rolled back HP and gear.
|
||||
check(ctx, chars, 12, 1000)
|
||||
if _, err := equipment.ApplyPresetEquipment(ctx, []assets.PresetEquipmentBinding{bind(12, second), bind(13, first)}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
check(ctx, chars, 11, 1000)
|
||||
check(ctx, chars, 12, 2000)
|
||||
check(ctx, chars, 13, 0) // Equipping an exhausted character never revives it.
|
||||
})
|
||||
run(true, func(ctx command.Context, equipment *assets.EquipmentInventory, chars *roster.CharacterStore) {
|
||||
check(ctx, chars, 11, 1000)
|
||||
check(ctx, chars, 12, 2000)
|
||||
check(ctx, chars, 13, 0)
|
||||
})
|
||||
}
|
||||
@@ -67,7 +67,8 @@ func (s *CharacterStore) MaxHealth(ctx command.Context, index uint64) (uint64, e
|
||||
|
||||
// CurrentHealth resolves persisted current HP independently from maximum HP.
|
||||
// A missing current_hp entry retains the owned character record's HP, including
|
||||
// zero. Recomputing equipment or other maximum-health stats must never heal it.
|
||||
// zero. Equipment changes preserve the HP ratio separately; reading stats alone
|
||||
// never changes current health or revives an exhausted character.
|
||||
func (s *CharacterStore) CurrentHealth(ctx command.Context, index uint64) (uint64, error) {
|
||||
var saved Character
|
||||
for _, character := range s.RawAll() {
|
||||
|
||||
@@ -20,6 +20,20 @@ func (s *CharacterStore) EquipmentCharacter(ctx command.Context, index uint64) (
|
||||
c, found := s.Find(ctx, index)
|
||||
return equipmentCharacter(c), found
|
||||
}
|
||||
|
||||
// EquipmentHealth lets an equipment transaction preserve the current HP ratio
|
||||
// using the same maximum-health calculator as battle and recovery.
|
||||
func (s *CharacterStore) EquipmentHealth(ctx command.Context, index uint64) (uint64, uint64, error) {
|
||||
if s.maxHealth == nil {
|
||||
return 0, 0, nil
|
||||
}
|
||||
maximum, err := s.MaxHealth(ctx, index)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
current, err := s.CurrentHealth(ctx, index)
|
||||
return current, maximum, err
|
||||
}
|
||||
func (s *CharacterStore) AddEquipmentTalentExperience(ctx command.Context, index, gain, maximum uint64) (assets.EquipmentCharacter, error) {
|
||||
c, err := s.AddTalentExperience(ctx, index, gain, maximum)
|
||||
return equipmentCharacter(c), err
|
||||
|
||||
@@ -74,6 +74,7 @@ public sealed class Plugin : BaseUnityPlugin
|
||||
TryInstall("battle preparation recovery", () => BattlePreparation.Install(harmony));
|
||||
TryInstall("costume auto-mount indices", () => CostumeAutoMount.Install(harmony, Logger));
|
||||
TryInstall("field party selection indices", () => FieldPartyIndices.Install(harmony, Logger));
|
||||
TryInstall("preset health", () => PresetHealth.Install(harmony, Logger));
|
||||
TryInstall("battle formation diagnostics", () => BattleFormationDiagnostics.Install(harmony, Logger));
|
||||
TryInstall("field transition diagnostics", () => FieldTransitionDiagnostics.Install(harmony, Logger));
|
||||
TryInstall("event hub presentation", () => EventHubPresentation.Install(harmony, Logger));
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BD2.GameNames;
|
||||
using BDNetwork;
|
||||
using BepInEx.Logging;
|
||||
using HarmonyLib;
|
||||
using Proto.Net;
|
||||
|
||||
namespace Bd2LocalIdentity;
|
||||
|
||||
internal static class PresetHealth
|
||||
{
|
||||
internal static void Install(Harmony harmony, ManualLogSource logger)
|
||||
{
|
||||
// CommonPacket has already applied the authoritative CharInfo response
|
||||
// before this method starts replacing individual equipment slots.
|
||||
harmony.Patch(Game.Method(() => EquipmentPacket.RecvPresetUseEquipInfos(null)),
|
||||
prefix: new HarmonyMethod(typeof(PresetHealth), nameof(BeforeEquipment)),
|
||||
postfix: new HarmonyMethod(typeof(PresetHealth), nameof(AfterEquipment)));
|
||||
logger.LogInfo("Preset equipment preserves authoritative health after all slot changes");
|
||||
}
|
||||
|
||||
private static void BeforeEquipment(IList<PresetUseEquipInfo> __0, out Dictionary<long, long> __state)
|
||||
{
|
||||
__state = [];
|
||||
if (__0 == null) return;
|
||||
foreach (PresetUseEquipInfo entry in __0)
|
||||
{
|
||||
Capture(__state, entry.CharInvenIndex);
|
||||
foreach (long index in entry.EquipInvenIndex)
|
||||
{
|
||||
EquipDBInfo item = EquipmentPacket.GetEquipment(index);
|
||||
if (item != null && item.UseChar > 0) Capture(__state, item.UseChar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void Capture(Dictionary<long, long> health, long index)
|
||||
{
|
||||
CharDBInfo character = CommonPacket.GetCharInfo(index);
|
||||
if (character != null) health[index] = character.Hp;
|
||||
}
|
||||
|
||||
private static void AfterEquipment(Dictionary<long, long> __state)
|
||||
{
|
||||
foreach (KeyValuePair<long, long> pair in __state)
|
||||
{
|
||||
CharDBInfo character = CommonPacket.GetCharInfo(pair.Key);
|
||||
if (character == null) continue;
|
||||
long maximum = (long)CharStatInfo.GetCharStat(ECharStatType.CST_HEALTH, pair.Key,
|
||||
out _, EquipmentPacket.EEquipmentGetType.EGT_NORMAL, 0);
|
||||
character.Hp = Math.Min(pair.Value, maximum);
|
||||
UIManager.DefaultUI?.RefreshCharHp(pair.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"game_version": "2.37.13",
|
||||
"client_version": "2.37.13+client.0.2.12",
|
||||
"server_version": "2.37.13+server.0.2.2",
|
||||
"client_version": "2.37.13+client.0.2.13",
|
||||
"server_version": "2.37.13+server.0.2.3",
|
||||
"game_data_version": "20261021182514",
|
||||
"bundle_version": "20261022174708",
|
||||
"seed_directory": "go/seed/v2_37_13",
|
||||
"plugins": {
|
||||
"local_identity": "0.7.7",
|
||||
"local_identity": "0.7.8",
|
||||
"capture_environment": "0.2.0",
|
||||
"login_ui": "0.3.6",
|
||||
"cash_shop": "0.1.2",
|
||||
|
||||
Reference in new issue
Block a user