Files
bd2/go/internal/server/gamedata/dispatch_test.go
T
Flechazo d8771caef2 feat(all): add hunting and events, commerce and rewards, binary calendars, GameData caching and login diagnostics
Implement hunting AP and progress, event tasks, exchanges, games, stories and actions; connect battle and reward handling.

Add CashShop plugin and installation, server purchases and entitlements, recharge rules and plugin version metadata.

Distribute binary calendars independently; cache GameData in memory and fix single-connection query deadlocks.

Improve automatic login and recovery diagnostics; document configuration and release flows.
2026-10-05 11:50:31 +08:00

43 lines
1.3 KiB
Go

package gamedata
import (
"fmt"
"testing"
)
func TestDispatchWeightedNestedRewards(t *testing.T) {
leaf := &dispatchGroup{Drop: 1, Entries: []dispatchEntry{{Weight: 100, Reward: BattleReward{Type: 8, ID: 44, Count: 3}}}}
weighted := &dispatchGroup{Drop: 0, Count: 2, Entries: []dispatchEntry{{Reward: BattleReward{Type: 9, Count: 1}, Weight: 90, Child: leaf}, {Reward: BattleReward{Type: 4, Count: 5}, Weight: 10}}}
d := &DispatchDesign{Rewards: []BattleReward{{Type: 9, ID: 7, Count: 1}}, boxes: map[uint64]*dispatchGroup{7: weighted}}
draws := 0
r, err := d.Roll(2, func(n uint64) (uint64, error) {
if n != 100 {
return 0, fmt.Errorf("limit %d", n)
}
draws++
if draws%3 == 0 {
return 95, nil
}
return 0, nil
})
if err != nil {
t.Fatal(err)
}
totals := map[uint64]uint64{}
for _, v := range r {
totals[v.Type] += v.Count
}
if totals[8] != 6 || totals[4] != 10 || draws != 6 {
t.Fatalf("rewards %+v draws %d", r, draws)
}
if _, err = d.Roll(1, func(n uint64) (uint64, error) { return n, nil }); err == nil {
t.Fatal("out of range RNG accepted")
}
}
func TestDispatchRewardOverflow(t *testing.T) {
d := &DispatchDesign{Rewards: []BattleReward{{Type: 4, Count: 2147483647}}}
if _, err := d.Roll(2, nil); err == nil {
t.Fatal("overflow accepted")
}
}