fix(server): restore quest chains, rewards and progress across game cards
This commit is contained in:
1 parent
8c5cd3dbdb
commit
59ce3ce74b
15 files changed
+594
-177
No files matched your search
@@ -15,9 +15,9 @@ type FieldPack struct {
|
||||
HasOpenRule bool
|
||||
MapIDs map[int]bool
|
||||
IntroQuest *QuestDesign
|
||||
// LifeQuests is a Life pack's quest chain: QuestTable rows of
|
||||
// EQuestType.Life, ordered by their prior/next links.
|
||||
LifeQuests []QuestDesign
|
||||
Quests map[int]QuestDesign
|
||||
MainQuestIDs []int
|
||||
LifeQuestIDs []int
|
||||
}
|
||||
|
||||
// Define_PackType.PackLife and EQuestType.Life.
|
||||
@@ -149,25 +149,28 @@ func loadFieldPacks(db *sql.DB) (map[int]FieldPack, error) {
|
||||
if len(pack.MapIDs) == 0 {
|
||||
return nil, fmt.Errorf("gamedata: arena pack %d has no map", id)
|
||||
}
|
||||
intro, err := loadFieldIntroduction(db, id)
|
||||
pack.Quests, err = loadOptionalPackQuests(db, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pack.IntroQuest = intro
|
||||
if pack.Type == LifePackType {
|
||||
if pack.LifeQuests, err = loadLifeQuests(db, id); err != nil {
|
||||
pack.IntroQuest = fieldIntroduction(pack.Quests)
|
||||
if pack.IntroQuest == nil {
|
||||
pack.MainQuestIDs, err = orderedQuestIDs(id, pack.Quests, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pack.LifeQuestIDs, err = orderedQuestIDs(id, pack.Quests, LifeQuestType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
result[id] = pack
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Standalone field introductions have one accept movie and no quest chain,
|
||||
// completion movie or rewards. Ordinary field quest chains retain their own
|
||||
// acceptance and settlement rules, even when their first quest has a movie.
|
||||
func loadFieldIntroduction(db *sql.DB, packID int) (*QuestDesign, error) {
|
||||
func loadOptionalPackQuests(db *sql.DB, packID int) (map[int]QuestDesign, error) {
|
||||
var exists bool
|
||||
if err := db.QueryRow("SELECT EXISTS(SELECT 1 FROM sqlite_master WHERE type='table' AND name=?)", fmt.Sprintf("QuestTable%d", packID)).Scan(&exists); err != nil {
|
||||
return nil, err
|
||||
@@ -175,61 +178,24 @@ func loadFieldIntroduction(db *sql.DB, packID int) (*QuestDesign, error) {
|
||||
if !exists {
|
||||
return nil, nil
|
||||
}
|
||||
quests, err := loadQuestDesignDB(db, packID)
|
||||
if err != nil || len(quests) != 1 {
|
||||
return nil, err
|
||||
return loadQuestDesignDB(db, packID)
|
||||
}
|
||||
|
||||
// Standalone introductions are watched locally and never send QuestClear.
|
||||
func fieldIntroduction(quests map[int]QuestDesign) *QuestDesign {
|
||||
if len(quests) != 1 {
|
||||
return nil
|
||||
}
|
||||
for _, quest := range quests {
|
||||
if quest.Type != 0 || quest.PriorQuestID != 0 || quest.NextQuestID != 0 || quest.AcceptCinemaName == "" || quest.CompleteCinemaName != "" || len(quest.GiveQuestItemIDs) != 0 || len(quest.CollectionRewards) != 0 {
|
||||
return nil, nil
|
||||
return nil
|
||||
}
|
||||
for _, rewards := range quest.Rewards {
|
||||
if len(rewards) != 0 {
|
||||
return nil, nil
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return &quest, nil
|
||||
return &quest
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// loadLifeQuests returns the single chain of Life quests, head first. The
|
||||
// client advances it with QuestUpdate and QuestClear like any active quest.
|
||||
func loadLifeQuests(db *sql.DB, packID int) ([]QuestDesign, error) {
|
||||
var exists bool
|
||||
if err := db.QueryRow("SELECT EXISTS(SELECT 1 FROM sqlite_master WHERE type='table' AND name=?)", fmt.Sprintf("QuestTable%d", packID)).Scan(&exists); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !exists {
|
||||
return nil, nil
|
||||
}
|
||||
quests, err := loadQuestDesignDB(db, packID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
head := 0
|
||||
for id, quest := range quests {
|
||||
if quest.Type != LifeQuestType {
|
||||
return nil, fmt.Errorf("gamedata: life pack %d quest %d has type %d", packID, id, quest.Type)
|
||||
}
|
||||
if quest.PriorQuestID == 0 {
|
||||
if head != 0 {
|
||||
return nil, fmt.Errorf("gamedata: life pack %d has two quest chains", packID)
|
||||
}
|
||||
head = id
|
||||
}
|
||||
}
|
||||
var chain []QuestDesign
|
||||
for id, seen := head, map[int]bool{}; id != 0; id = quests[id].NextQuestID {
|
||||
quest, found := quests[id]
|
||||
if !found || seen[id] || (len(chain) > 0 && quest.PriorQuestID != chain[len(chain)-1].ID) {
|
||||
return nil, fmt.Errorf("gamedata: life pack %d quest chain breaks at %d", packID, id)
|
||||
}
|
||||
seen[id] = true
|
||||
chain = append(chain, quest)
|
||||
}
|
||||
if len(chain) != len(quests) {
|
||||
return nil, fmt.Errorf("gamedata: life pack %d chain covers %d of %d quests", packID, len(chain), len(quests))
|
||||
}
|
||||
return chain, nil
|
||||
return nil
|
||||
}
|
||||
@@ -29,11 +29,18 @@ func LoadWorldRules(root, version string, placeholder uint64) (*WorldRules, erro
|
||||
rules.Transitions[id] = PackTransition{PackID: id, NextPackID: pack.NextPackID}
|
||||
packs = append(packs, id)
|
||||
}
|
||||
rules.QuestCostumes, err = LoadQuestCostumes(root, version, rules.Packs, story)
|
||||
rules.FieldPacks, err = LoadFieldPacks(root, version)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rules.FieldPacks, err = LoadFieldPacks(root, version)
|
||||
for id, pack := range rules.FieldPacks {
|
||||
if _, exists := rules.Packs[id]; exists || len(pack.MainQuestIDs) == 0 {
|
||||
continue
|
||||
}
|
||||
rules.Packs[id] = pack.Quests
|
||||
packs = append(packs, id)
|
||||
}
|
||||
rules.QuestCostumes, err = LoadQuestCostumes(root, version, rules.Packs, story)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -60,31 +67,44 @@ func LoadWorldRules(root, version string, placeholder uint64) (*WorldRules, erro
|
||||
// a predecessor merely because their numeric ID lies between two main quests.
|
||||
func orderMainQuests(story *StoryCatalog) error {
|
||||
for id, pack := range story.Packs {
|
||||
start := 0
|
||||
for _, qid := range pack.MainQuestIDs {
|
||||
if pack.Quests[qid].PriorQuestID == 0 {
|
||||
if start != 0 {
|
||||
return fmt.Errorf("world: pack %d has multiple main quest roots", id)
|
||||
}
|
||||
start = qid
|
||||
}
|
||||
ids, err := orderedQuestIDs(id, pack.Quests, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var ordered []int
|
||||
seen := map[int]bool{}
|
||||
for qid := start; qid != 0; {
|
||||
q, exists := pack.Quests[qid]
|
||||
if !exists || q.Type != 0 || seen[qid] {
|
||||
return fmt.Errorf("world: invalid main quest chain pack %d quest %d", id, qid)
|
||||
}
|
||||
seen[qid] = true
|
||||
ordered = append(ordered, qid)
|
||||
qid = q.NextQuestID
|
||||
}
|
||||
if len(ordered) != len(pack.MainQuestIDs) {
|
||||
return fmt.Errorf("world: disconnected main quest chain pack %d", id)
|
||||
}
|
||||
pack.MainQuestIDs = ordered
|
||||
pack.MainQuestIDs = ids
|
||||
story.Packs[id] = pack
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func orderedQuestIDs(packID int, quests map[int]QuestDesign, questType int) ([]int, error) {
|
||||
start, count := 0, 0
|
||||
for id, quest := range quests {
|
||||
if quest.Type != questType {
|
||||
continue
|
||||
}
|
||||
count++
|
||||
if quest.PriorQuestID == 0 {
|
||||
if start != 0 {
|
||||
return nil, fmt.Errorf("world: pack %d has multiple quest roots", packID)
|
||||
}
|
||||
start = id
|
||||
}
|
||||
}
|
||||
var ordered []int
|
||||
seen := map[int]bool{}
|
||||
previous := 0
|
||||
for id := start; id != 0; {
|
||||
quest, exists := quests[id]
|
||||
if !exists || quest.Type != questType || seen[id] || quest.PriorQuestID != previous {
|
||||
return nil, fmt.Errorf("world: invalid quest chain pack %d quest %d", packID, id)
|
||||
}
|
||||
seen[id] = true
|
||||
ordered = append(ordered, id)
|
||||
previous, id = id, quest.NextQuestID
|
||||
}
|
||||
if len(ordered) != count {
|
||||
return nil, fmt.Errorf("world: disconnected quest chain pack %d", packID)
|
||||
}
|
||||
return ordered, nil
|
||||
}
|
||||
@@ -0,0 +1,380 @@
|
||||
//go:build integration
|
||||
|
||||
package world
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"bd2server/internal/common/versionconfig"
|
||||
"bd2server/internal/server/design/gamedata"
|
||||
"bd2server/internal/server/domain/command"
|
||||
"bd2server/internal/server/domain/events"
|
||||
assets "bd2server/internal/server/domain/inventory"
|
||||
"bd2server/internal/server/domain/roster"
|
||||
"bd2server/internal/server/domain/world/progress"
|
||||
"bd2server/internal/server/protocol/wire"
|
||||
"bd2server/internal/server/storage/stateio"
|
||||
)
|
||||
|
||||
// Current GameData gives Mirror War six introductory main quests, including
|
||||
// PvpDeckSave (3) and a practice battle (5); Last Night has three. Both native
|
||||
// lobby gates consult QuestPacket.IsCompleteQuest before opening.
|
||||
func TestFieldMainQuestsAdvanceRestoreAndComplete(t *testing.T) {
|
||||
versions, err := versionconfig.Find()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
root := versions.Resolve("data/resources/GameData")
|
||||
rules, err := gamedata.LoadWorldRules(root, versions.GameDataVersion, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
if err := gamedata.CloseDatabaseCache(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
for _, tc := range []struct {
|
||||
pack, count, mapID int
|
||||
values [][]uint64
|
||||
}{
|
||||
{3001, 6, 30011, [][]uint64{{11}, {21}, {1}, {41}, {1}, {61}}},
|
||||
{3005, 3, 30051, [][]uint64{{11}, {21, 22}, {31}}},
|
||||
} {
|
||||
t.Run(fmt.Sprint(tc.pack), func(t *testing.T) {
|
||||
field := rules.FieldPacks[tc.pack]
|
||||
if len(field.MainQuestIDs) != tc.count || field.IntroQuest != nil {
|
||||
t.Fatalf("field main quests: %v, intro=%v", field.MainQuestIDs, field.IntroQuest)
|
||||
}
|
||||
if _, story := rules.Story.Packs[tc.pack]; story {
|
||||
t.Fatal("arena must retain field-card ownership and access rules")
|
||||
}
|
||||
ctx := command.Context{State: stateio.NewMemory()}
|
||||
store := stateio.RootStore{}
|
||||
state, err := progress.OpenStore(ctx, store)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wallet, err := assets.OpenWallet(ctx, store, assets.Currency{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var tickets []assets.Item
|
||||
if field.TicketID != 0 {
|
||||
tickets = append(tickets, assets.Item{InvenIndex: 1, Type: 19, ID: field.TicketID, Count: 1})
|
||||
}
|
||||
inventory, err := assets.OpenInventory(ctx, store, tickets)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
characters, err := roster.OpenCharacterStore(ctx, store, nil, inventory, root, versions.GameDataVersion)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
collection, err := roster.OpenCollectionStore(ctx, store, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
equipment, err := assets.OpenEquipmentInventory(ctx, store)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
equipmentDesign, err := gamedata.LoadRewardEquipmentCatalog(root, versions.GameDataVersion)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
graph, err := gamedata.LoadRewardGraph(root, versions.GameDataVersion)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
economy, err := events.NewEconomy(ctx, store, inventory, wallet, collection, equipment, rules.QuestCostumes, equipmentDesign, graph, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
service := &Service{seed: Seed{PackID: 1}, activePack: tc.pack, state: state, storyCatalog: rules.Story, fieldPacks: rules.FieldPacks, packs: rules.Packs, wallet: wallet, inventory: inventory, characters: characters, storyRoster: rules.Characters, questDifficulties: rules.Difficulties, squadLevel: func() (uint64, error) { return 999, nil }}
|
||||
source := gamedata.NewSource(root, versions.GameDataVersion)
|
||||
service.attachPackDetailDesign(source)
|
||||
service.presentationSource = source
|
||||
service.AttachFieldPackEconomy(economy)
|
||||
var seq uint64
|
||||
call := func(path string, quest int, values ...uint64) []byte {
|
||||
t.Helper()
|
||||
seq++
|
||||
req := wire.AppendVarint(wire.AppendVarint(wire.AppendVarint(nil, 1, seq), 2, uint64(quest)), 3, uint64(tc.pack))
|
||||
for _, v := range values {
|
||||
req = wire.AppendVarint(req, 4, v)
|
||||
}
|
||||
_, body, handled, err := service.Handle(ctx, path, req)
|
||||
if err != nil || !handled {
|
||||
t.Fatalf("%s quest %d: handled=%t err=%v", path, quest, handled, err)
|
||||
}
|
||||
return body
|
||||
}
|
||||
finish := func() {
|
||||
t.Helper()
|
||||
pending, err := loadStoryCheckpoint(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if pending != nil {
|
||||
_, err = service.StoryCheckpoint(ctx, StoryCheckpointRequest{Operation: "complete", StoryCheckpoint: StoryCheckpoint{ID: pending.ID}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
var gold uint64
|
||||
expectedCurrencies := map[int]uint64{}
|
||||
for id := 1; id <= tc.count; id++ {
|
||||
body, err := service.basePackInfoFor(ctx, tc.pack)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rows, err := nestedMessages(body, 2)
|
||||
if err != nil || len(rows) != 1 {
|
||||
t.Fatalf("pack entry quest rows=%d err=%v", len(rows), err)
|
||||
}
|
||||
if got, _, _ := wire.Varint(rows[0], 1); got != uint64(id) {
|
||||
t.Fatalf("active quest %d, want %d", got, id)
|
||||
}
|
||||
if service.canClear(ctx, tc.pack, id+1) {
|
||||
t.Fatal("later quest may not bypass predecessor")
|
||||
}
|
||||
design := field.Quests[id]
|
||||
if design.AcceptCinemaName != "" {
|
||||
cp := StoryCheckpoint{ID: fmt.Sprintf("accept:%d", id), PackID: tc.pack, QuestID: id, Phase: "accept", MapID: tc.mapID, Timeline: design.AcceptCinemaName}
|
||||
if _, err := service.StoryCheckpoint(ctx, StoryCheckpointRequest{Operation: "begin", StoryCheckpoint: cp}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
finish()
|
||||
}
|
||||
if tc.pack == 3001 && id == 5 {
|
||||
if err := service.ValidateQuestBattle(ctx, tc.pack, []uint64{5}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.ValidateQuestBattle(ctx, tc.pack, []uint64{6}); err == nil {
|
||||
t.Fatal("practice battle must belong to active quest")
|
||||
}
|
||||
deck, err := gamedata.ResolveQuestBattleDeck(root, versions.GameDataVersion, tc.pack, 1, 1, 0)
|
||||
if err != nil || !slices.Contains(deck.QuestIDs, uint64(5)) {
|
||||
t.Fatalf("practice battle design: %+v %v", deck, err)
|
||||
}
|
||||
}
|
||||
values := tc.values[id-1]
|
||||
call("/QuestUpdate", id, values...)
|
||||
service.state, err = progress.OpenStore(ctx, store)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wantValues := make([]int, len(values))
|
||||
for i, v := range values {
|
||||
wantValues[i] = int(v)
|
||||
}
|
||||
if current, ok := service.state.QuestInPack(id, tc.pack, 0); !ok || !slices.Equal(current.Values, wantValues) {
|
||||
t.Fatalf("quest update lost on reconnect: %+v %t", current, ok)
|
||||
}
|
||||
clear := call("/QuestClear", id)
|
||||
next, _, _ := wire.Bytes(clear, 2)
|
||||
wantNext := id + 1
|
||||
if id == tc.count {
|
||||
wantNext = 0
|
||||
}
|
||||
if got, _, _ := wire.Varint(next, 1); got != uint64(wantNext) {
|
||||
t.Fatalf("next quest %d, want %d", got, wantNext)
|
||||
}
|
||||
pending, err := loadStoryCheckpoint(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if design.CompleteCinemaName != "" && (pending == nil || pending.Timeline != design.CompleteCinemaName || pending.QuestID != id || pending.MapID != tc.mapID) {
|
||||
t.Fatalf("missing native completion presentation: %+v", pending)
|
||||
}
|
||||
finish()
|
||||
for _, r := range design.Rewards[0] {
|
||||
if r.Type == 4 {
|
||||
gold += r.Count
|
||||
}
|
||||
}
|
||||
for _, r := range design.Rewards[0] {
|
||||
if field, ok := events.AdditionalCurrencyFields[r.Type]; ok {
|
||||
expectedCurrencies[field] += r.Count
|
||||
}
|
||||
}
|
||||
currencies, err := economy.AdditionalCurrencies(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for field, want := range expectedCurrencies {
|
||||
if currencies[field] != want {
|
||||
t.Fatalf("currency field %d=%d want %d", field, currencies[field], want)
|
||||
}
|
||||
}
|
||||
before := wallet.Snapshot(ctx)
|
||||
call("/QuestClear", id)
|
||||
currenciesAfter, err := economy.AdditionalCurrencies(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for field, want := range expectedCurrencies {
|
||||
if currenciesAfter[field] != want {
|
||||
t.Fatal("repeated clear paid arena currency twice")
|
||||
}
|
||||
}
|
||||
if after := wallet.Snapshot(ctx); after != before {
|
||||
t.Fatal("repeated clear paid rewards twice")
|
||||
}
|
||||
}
|
||||
if got := wallet.Snapshot(ctx).Gold; got != gold {
|
||||
t.Fatalf("gold=%d want %d", got, gold)
|
||||
}
|
||||
service.state, err = progress.OpenStore(ctx, store)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
body, err := service.basePackInfoFor(ctx, tc.pack)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rows, _ := nestedMessages(body, 2)
|
||||
if len(rows) != 0 {
|
||||
t.Fatal("completed intro restarted on reconnect")
|
||||
}
|
||||
cleared, err := intsRequest(body, 3)
|
||||
if err != nil || len(cleared) != tc.count {
|
||||
t.Fatalf("native gate completion list=%v err=%v", cleared, err)
|
||||
}
|
||||
for id := 1; id <= tc.count; id++ {
|
||||
if !slices.Contains(cleared, uint64(id)) {
|
||||
t.Fatalf("missing completion %d", id)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Counts and title ranges are fixed from GameData 20261021182514, including
|
||||
// character-card side quests which are absent from the story-only catalog.
|
||||
func TestFieldQuestCatalogCoversNativeCardKinds(t *testing.T) {
|
||||
versions, err := versionconfig.Find()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
root := versions.Resolve("data/resources/GameData")
|
||||
rules, err := gamedata.LoadWorldRules(root, versions.GameDataVersion, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
if err := gamedata.CloseDatabaseCache(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
source := gamedata.NewSource(root, versions.GameDataVersion)
|
||||
cases := []struct{ pack, main, side, life int }{
|
||||
{1001, 38, 16, 0}, {1002, 36, 12, 0}, {1003, 34, 0, 0}, {1004, 34, 0, 0}, {1005, 29, 0, 0}, {1006, 29, 0, 0}, {1007, 31, 0, 0}, {1008, 33, 0, 0}, {1009, 29, 0, 0}, {1010, 31, 0, 0}, {1011, 30, 0, 0},
|
||||
{2001, 18, 0, 0}, {2002, 19, 0, 0}, {2003, 19, 0, 0}, {2004, 21, 0, 0}, {2005, 24, 0, 0}, {2006, 21, 0, 0}, {2007, 23, 0, 0}, {2008, 34, 0, 0}, {2009, 31, 0, 0}, {2010, 26, 0, 0},
|
||||
{3001, 6, 0, 0}, {3003, 5, 0, 0}, {3004, 3, 0, 0}, {3005, 3, 0, 0}, {3006, 0, 0, 0}, {3007, 0, 0, 0}, {3008, 0, 0, 0}, {3009, 0, 0, 0}, {3010, 0, 0, 0}, {3011, 0, 0, 15}, {3012, 0, 0, 0},
|
||||
}
|
||||
if len(rules.FieldPacks) != len(cases) {
|
||||
t.Fatalf("field pack count=%d want %d", len(rules.FieldPacks), len(cases))
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(fmt.Sprint(tc.pack), func(t *testing.T) {
|
||||
pack, found := rules.FieldPacks[tc.pack]
|
||||
if !found || len(pack.MainQuestIDs) != tc.main || len(pack.LifeQuestIDs) != tc.life {
|
||||
t.Fatalf("pack %d: main=%v life=%v", tc.pack, pack.MainQuestIDs, pack.LifeQuestIDs)
|
||||
}
|
||||
side := 0
|
||||
for _, q := range pack.Quests {
|
||||
if q.Type == 1 {
|
||||
side++
|
||||
}
|
||||
}
|
||||
if side != tc.side {
|
||||
t.Fatalf("side quests=%d want %d", side, tc.side)
|
||||
}
|
||||
ctx := command.Context{State: stateio.NewMemory()}
|
||||
state, err := progress.OpenStore(ctx, stateio.RootStore{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
service := &Service{state: state, storyCatalog: rules.Story, fieldPacks: rules.FieldPacks, packs: rules.Packs, presentationSource: source}
|
||||
if tc.main > 0 {
|
||||
body, err := service.basePackInfoFor(ctx, tc.pack)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rows, err := nestedMessages(body, 2)
|
||||
if err != nil || len(rows) != 1 {
|
||||
t.Fatalf("entry rows=%d err=%v", len(rows), err)
|
||||
}
|
||||
if first, _, _ := wire.Varint(rows[0], 1); first != 1 {
|
||||
t.Fatalf("first active quest=%d want 1", first)
|
||||
}
|
||||
if service.packCompleteFor(tc.pack) {
|
||||
t.Fatal("new pack reported complete")
|
||||
}
|
||||
for id := 1; id <= tc.main; id++ {
|
||||
if err := state.ClearQuest(ctx, id, tc.pack, 0); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
card := service.fieldPackDBInfo(pack)
|
||||
count, _, _ := wire.Varint(card, 2)
|
||||
done, _, _ := wire.Varint(card, 3)
|
||||
if count != uint64(tc.main) || done != 1 || !service.packCompleteFor(tc.pack) {
|
||||
t.Fatalf("card progress count=%d done=%d", count, done)
|
||||
}
|
||||
}
|
||||
if tc.side > 0 {
|
||||
if err := state.AcceptQuest(ctx, 101, tc.pack, 0); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
active := service.activeSideQuestWires(tc.pack)
|
||||
if len(active) != 1 {
|
||||
t.Fatalf("active side rows=%d want 1", len(active))
|
||||
}
|
||||
if id, _, _ := wire.Varint(active[0], 1); id != 101 {
|
||||
t.Fatalf("active side=%d want 101", id)
|
||||
}
|
||||
rows, err := service.questTitleInfo(tc.pack)
|
||||
if err != nil || len(rows) != 2 {
|
||||
t.Fatalf("character card titles=%d err=%v", len(rows), err)
|
||||
}
|
||||
request := wire.AppendVarint(wire.AppendVarint(nil, 1, 1), 2, uint64(tc.pack))
|
||||
_, body, _, err := service.packSubQuestClearInfo(request)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rows, err = nestedMessages(body, 1)
|
||||
if err != nil || len(rows) != 1 {
|
||||
t.Fatalf("side preview=%d %v", len(rows), err)
|
||||
}
|
||||
if count, _, _ := wire.Varint(rows[0], 2); count != 0 {
|
||||
t.Fatalf("uncompleted side chain count=%d", count)
|
||||
}
|
||||
for id := 101; id <= 100+tc.side; id++ {
|
||||
if err := state.ClearQuest(ctx, id, tc.pack, 0); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
_, body, _, err = service.packSubQuestClearInfo(request)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rows, err = nestedMessages(body, 1)
|
||||
if err != nil || len(rows) != 1 {
|
||||
t.Fatalf("completed side preview=%d %v", len(rows), err)
|
||||
}
|
||||
if count, _, _ := wire.Varint(rows[0], 2); count != 1 {
|
||||
t.Fatalf("completed side chapter count=%d want 1", count)
|
||||
}
|
||||
}
|
||||
if pack.IntroQuest != nil && (tc.pack != 3006 || service.firstUnclearedQuestFor(tc.pack) != 0) {
|
||||
t.Fatal("local watched introduction became a claimable quest")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,18 @@ func (s *Service) fieldPackDBInfo(pack gamedata.FieldPack) []byte {
|
||||
row = wire.AppendVarint(row, 8, 1)
|
||||
}
|
||||
}
|
||||
cleared := 0
|
||||
for _, id := range pack.MainQuestIDs {
|
||||
if s.state.QuestCleared(id, int(pack.ID), s.questDifficulty(int(pack.ID))) {
|
||||
cleared++
|
||||
}
|
||||
}
|
||||
if cleared > 0 {
|
||||
row = wire.AppendVarint(row, 2, uint64(cleared))
|
||||
}
|
||||
if len(pack.MainQuestIDs) > 0 && cleared == len(pack.MainQuestIDs) {
|
||||
row = wire.AppendVarint(row, 3, 1)
|
||||
}
|
||||
return row
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
|
||||
"bd2server/internal/server/design/gamedata"
|
||||
"bd2server/internal/server/domain/command"
|
||||
"bd2server/internal/server/protocol/wire"
|
||||
)
|
||||
|
||||
// Life packs carry one quest chain. Its current quest is always active: the
|
||||
@@ -14,50 +13,20 @@ import (
|
||||
// first tutorial focuses that HUD entry, so without an active quest it can
|
||||
// never reach the marker that records its completion.
|
||||
|
||||
func (s *Service) lifeQuestDesigns(packID int) map[int]gamedata.QuestDesign {
|
||||
chain := s.fieldPacks[packID].LifeQuests
|
||||
if len(chain) == 0 {
|
||||
return nil
|
||||
}
|
||||
quests := make(map[int]gamedata.QuestDesign, len(chain))
|
||||
for _, quest := range chain {
|
||||
quests[quest.ID] = quest
|
||||
}
|
||||
return quests
|
||||
}
|
||||
|
||||
// ensureLifeQuest accepts the first quest of the chain that is not cleared.
|
||||
func (s *Service) ensureLifeQuest(ctx command.Context, packID int) error {
|
||||
for _, quest := range s.fieldPacks[packID].LifeQuests {
|
||||
if s.state.QuestCleared(quest.ID, packID, 0) {
|
||||
for _, questID := range s.fieldPacks[packID].LifeQuestIDs {
|
||||
if s.state.QuestCleared(questID, packID, 0) {
|
||||
continue
|
||||
}
|
||||
if _, active := s.state.QuestInPack(quest.ID, packID, 0); active {
|
||||
if _, active := s.state.QuestInPack(questID, packID, 0); active {
|
||||
return nil
|
||||
}
|
||||
return s.state.AcceptQuest(ctx, quest.ID, packID, 0)
|
||||
return s.state.AcceptQuest(ctx, questID, packID, 0)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// lifeQuestWires are QuestDBInfo rows for the active Life quests. Their
|
||||
// progress is QuestDBInfo.value, which LifeQuestController adds to.
|
||||
func (s *Service) lifeQuestWires(packID int) [][]byte {
|
||||
var out [][]byte
|
||||
for _, quest := range s.fieldPacks[packID].LifeQuests {
|
||||
progress, active := s.state.QuestInPack(quest.ID, packID, 0)
|
||||
if !active || s.state.QuestCleared(quest.ID, packID, 0) {
|
||||
continue
|
||||
}
|
||||
row := wire.AppendVarint(nil, 1, uint64(quest.ID))
|
||||
if len(progress.Values) > 0 && progress.Values[0] > 0 {
|
||||
row = wire.AppendVarint(row, 2, uint64(progress.Values[0]))
|
||||
}
|
||||
out = append(out, wire.AppendVarint(row, 6, uint64(packID)))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func lifeReward(reward gamedata.Reward) bool { return reward.Type >= 64 && reward.Type <= 66 }
|
||||
|
||||
// grantLifeQuestRewards pays life coins and life items through the life
|
||||
|
||||
@@ -45,12 +45,12 @@ func TestLifeQuestChainActivatesAdvancesAndPaysLifeRewards(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
farm := packs[3011]
|
||||
if farm.Type != gamedata.LifePackType || len(farm.LifeQuests) != 15 {
|
||||
t.Fatalf("pack 3011 type=%d life quests=%d, want the 15-quest farm chain", farm.Type, len(farm.LifeQuests))
|
||||
if farm.Type != gamedata.LifePackType || len(farm.LifeQuestIDs) != 15 {
|
||||
t.Fatalf("pack 3011 type=%d life quests=%d, want the 15-quest farm chain", farm.Type, len(farm.LifeQuestIDs))
|
||||
}
|
||||
for i, quest := range farm.LifeQuests {
|
||||
if quest.ID != i+1 {
|
||||
t.Fatalf("chain position %d is quest %d", i, quest.ID)
|
||||
for i, questID := range farm.LifeQuestIDs {
|
||||
if questID != i+1 {
|
||||
t.Fatalf("chain position %d is quest %d", i, questID)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ func TestLifeQuestChainActivatesAdvancesAndPaysLifeRewards(t *testing.T) {
|
||||
active := func() []int {
|
||||
t.Helper()
|
||||
var ids []int
|
||||
for _, row := range service.lifeQuestWires(3011) {
|
||||
for _, row := range service.activeLifeQuestWires(3011) {
|
||||
id, _, _ := wire.Varint(row, 1)
|
||||
ids = append(ids, int(id))
|
||||
}
|
||||
@@ -91,7 +91,7 @@ func TestLifeQuestChainActivatesAdvancesAndPaysLifeRewards(t *testing.T) {
|
||||
}
|
||||
value := func(quest int) uint64 {
|
||||
t.Helper()
|
||||
for _, row := range service.lifeQuestWires(3011) {
|
||||
for _, row := range service.activeLifeQuestWires(3011) {
|
||||
if id, _, _ := wire.Varint(row, 1); int(id) == quest {
|
||||
v, _, _ := wire.Varint(row, 2)
|
||||
return v
|
||||
@@ -126,6 +126,17 @@ func TestLifeQuestChainActivatesAdvancesAndPaysLifeRewards(t *testing.T) {
|
||||
if got := value(1); got != 1 {
|
||||
t.Fatalf("quest 1 progress=%d, want 1", got)
|
||||
}
|
||||
_, info, handled, err := service.Handle(ctx, "/QuestInfo", wire.AppendVarint(wire.AppendVarint(nil, 1, 2), 2, 3011))
|
||||
if err != nil || !handled {
|
||||
t.Fatalf("life QuestInfo: handled=%t err=%v", handled, err)
|
||||
}
|
||||
rows, err := nestedMessages(info, 1)
|
||||
if err != nil || len(rows) != 1 {
|
||||
t.Fatalf("life QuestInfo rows=%d err=%v", len(rows), err)
|
||||
}
|
||||
if got, _, _ := wire.Varint(rows[0], 2); got != 1 {
|
||||
t.Fatalf("life QuestInfo.value=%d, want 1", got)
|
||||
}
|
||||
|
||||
body := call("/QuestClear", 1)
|
||||
if len(ledger.rewards) != 1 || ledger.identities[0] != "pack3011:quest1:life" ||
|
||||
|
||||
@@ -67,7 +67,7 @@ func (s *Service) basePackInfoFor(ctx command.Context, packID int) ([]byte, erro
|
||||
for _, quest := range s.activeSideQuestWires(packID) {
|
||||
out = wire.AppendBytes(out, 2, quest)
|
||||
}
|
||||
for _, quest := range s.lifeQuestWires(packID) {
|
||||
for _, quest := range s.activeLifeQuestWires(packID) {
|
||||
out = wire.AppendBytes(out, 2, quest)
|
||||
}
|
||||
cleared := s.completedQuestIDs(packID)
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package world
|
||||
|
||||
import (
|
||||
"bd2server/internal/server/design/gamedata"
|
||||
"bd2server/internal/server/domain/command"
|
||||
"bd2server/internal/server/domain/events"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (s *Service) packQuestDesigns(packID int) map[int]gamedata.QuestDesign {
|
||||
if s.storyCatalog != nil {
|
||||
if pack, found := s.storyCatalog.Packs[packID]; found {
|
||||
return pack.Quests
|
||||
}
|
||||
}
|
||||
if pack := s.fieldPacks[packID]; len(pack.Quests) != 0 {
|
||||
return pack.Quests
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) mainQuestIDs(packID int) []int {
|
||||
if s.storyCatalog != nil {
|
||||
if pack, found := s.storyCatalog.Packs[packID]; found {
|
||||
return pack.MainQuestIDs
|
||||
}
|
||||
}
|
||||
return s.fieldPacks[packID].MainQuestIDs
|
||||
}
|
||||
|
||||
func additionalQuestCurrency(reward gamedata.Reward) bool {
|
||||
_, exists := events.AdditionalCurrencyFields[reward.Type]
|
||||
return exists
|
||||
}
|
||||
|
||||
func (s *Service) grantAdditionalQuestCurrencies(ctx command.Context, packID, quest int, rewards []gamedata.Reward) ([]byte, error) {
|
||||
var currencies []gamedata.Reward
|
||||
for _, reward := range rewards {
|
||||
if additionalQuestCurrency(reward) {
|
||||
currencies = append(currencies, reward)
|
||||
}
|
||||
}
|
||||
if len(currencies) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
if s.fieldPackEconomy == nil {
|
||||
return nil, fmt.Errorf("world: quest currency economy unavailable")
|
||||
}
|
||||
return s.fieldPackEconomy.Apply(ctx, questRewardIdentity(packID, quest, s.questDifficultyFor(packID, quest))+":currencies", nil, currencies)
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package world
|
||||
|
||||
import (
|
||||
"bd2server/internal/server/design/gamedata"
|
||||
"bd2server/internal/server/domain/command"
|
||||
assets "bd2server/internal/server/domain/inventory"
|
||||
"bd2server/internal/server/domain/world/progress"
|
||||
@@ -55,14 +56,21 @@ func (s *Service) appendCurrentBattleDeck(response []byte, field int) []byte {
|
||||
func (s *Service) questInfoWire(packID, questID int) []byte {
|
||||
out := wire.AppendVarint(nil, 1, uint64(questID))
|
||||
selection, _ := s.state.Selection(packID)
|
||||
if s.storyCatalog != nil && s.storyCatalog.Packs[packID].Quests[questID].Type != 0 {
|
||||
if s.packQuestDesigns(packID)[questID].Type != 0 {
|
||||
selection = progress.QuestSelection{}
|
||||
}
|
||||
if current, ok := s.state.QuestInPack(questID, packID, selection.Difficulty); ok {
|
||||
for _, value := range current.Values {
|
||||
out = wire.AppendVarint(out, 3, uint64(value))
|
||||
if s.packQuestDesigns(packID)[questID].Type == gamedata.LifeQuestType {
|
||||
if len(current.Values) > 0 {
|
||||
out = wire.AppendVarint(out, 2, uint64(current.Values[0]))
|
||||
}
|
||||
} else {
|
||||
for _, value := range current.Values {
|
||||
out = wire.AppendVarint(out, 3, uint64(value))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if selection.Difficulty != 0 {
|
||||
out = wire.AppendVarint(out, 4, uint64(selection.Difficulty))
|
||||
}
|
||||
@@ -77,8 +85,8 @@ func (s *Service) questLevelInfoWire(packID, difficulty int) []byte {
|
||||
out = wire.AppendVarint(out, 2, uint64(difficulty))
|
||||
last := 0
|
||||
complete := true
|
||||
pack := s.storyCatalog.Packs[packID]
|
||||
for _, id := range pack.MainQuestIDs {
|
||||
ids := s.mainQuestIDs(packID)
|
||||
for _, id := range ids {
|
||||
if !s.state.QuestCleared(id, packID, difficulty) {
|
||||
complete = false
|
||||
break
|
||||
@@ -90,7 +98,7 @@ func (s *Service) questLevelInfoWire(packID, difficulty int) []byte {
|
||||
if selection.Difficulty == difficulty {
|
||||
out = wire.AppendVarint(out, 4, uint64(selection.Option))
|
||||
}
|
||||
if complete && len(pack.MainQuestIDs) > 0 {
|
||||
if complete && len(ids) > 0 {
|
||||
out = wire.AppendVarint(out, 5, 1)
|
||||
}
|
||||
return out
|
||||
@@ -104,7 +112,7 @@ func (s *Service) completedQuestIDs(pack int) []int {
|
||||
return ids
|
||||
}
|
||||
for _, id := range s.state.ClearedQuests(pack, 0) {
|
||||
if s.storyCatalog.Packs[pack].Quests[id].Type == 1 {
|
||||
if s.packQuestDesigns(pack)[id].Type == 1 {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
}
|
||||
@@ -125,7 +133,7 @@ func (s *Service) handleQuestSelection(ctx command.Context, path string, request
|
||||
if active := s.firstUnclearedQuestFor(pack); active != 0 {
|
||||
out = wire.AppendBytes(out, 1, s.questInfoWire(pack, active))
|
||||
}
|
||||
for _, quest := range s.activeSideQuestWires(pack) {
|
||||
for _, quest := range append(s.activeSideQuestWires(pack), s.activeLifeQuestWires(pack)...) {
|
||||
out = wire.AppendBytes(out, 1, quest)
|
||||
}
|
||||
var todayCleared []int
|
||||
@@ -231,7 +239,7 @@ func (s *Service) handleQuestSelection(ctx command.Context, path string, request
|
||||
return 17, out, true, nil
|
||||
}
|
||||
if level > 0 {
|
||||
ids := s.storyCatalog.Packs[pack].MainQuestIDs
|
||||
ids := s.mainQuestIDs(pack)
|
||||
for _, id := range ids {
|
||||
if !s.state.QuestCleared(id, pack, int(level)-1) {
|
||||
return 0, nil, true, fmt.Errorf("%w: previous difficulty is incomplete", ErrInvalidRequest)
|
||||
@@ -241,7 +249,7 @@ func (s *Service) handleQuestSelection(ctx command.Context, path string, request
|
||||
// Accept only the first unfinished main quest in this difficulty, using
|
||||
// authoritative links rather than permitting an arbitrary reward jump.
|
||||
first := 0
|
||||
for _, id := range s.storyCatalog.Packs[pack].MainQuestIDs {
|
||||
for _, id := range s.mainQuestIDs(pack) {
|
||||
if !s.state.QuestCleared(id, pack, int(level)) {
|
||||
first = id
|
||||
break
|
||||
@@ -280,13 +288,20 @@ func (s *Service) handleQuestSelection(ctx command.Context, path string, request
|
||||
|
||||
func (s *Service) activeSideQuestWires(packID int) [][]byte {
|
||||
var out [][]byte
|
||||
if s.storyCatalog == nil {
|
||||
return nil
|
||||
}
|
||||
for _, quest := range s.state.QuestsInPack(packID, 0) {
|
||||
if s.storyCatalog.Packs[packID].Quests[quest.QuestID].Type == 1 && !s.state.QuestCleared(quest.QuestID, packID) {
|
||||
if s.packQuestDesigns(packID)[quest.QuestID].Type == 1 && !s.state.QuestCleared(quest.QuestID, packID) {
|
||||
out = append(out, s.questInfoWire(packID, quest.QuestID))
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *Service) activeLifeQuestWires(packID int) [][]byte {
|
||||
var out [][]byte
|
||||
for _, id := range s.fieldPacks[packID].LifeQuestIDs {
|
||||
if _, active := s.state.QuestInPack(id, packID, 0); active && !s.state.QuestCleared(id, packID, 0) {
|
||||
out = append(out, s.questInfoWire(packID, id))
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -100,7 +100,7 @@ func (s *Service) clearResponse(ctx command.Context, packID, quest int, rewards
|
||||
for _, item := range nextItems {
|
||||
out = wire.AppendBytes(out, 6, assets.ItemWire(item))
|
||||
}
|
||||
if s.storyCatalog.Packs[packID].Quests[quest].Type == 0 && next == 0 && s.packCompleteFor(packID) {
|
||||
if s.packQuestDesigns(packID)[quest].Type == 0 && next == 0 && s.packCompleteFor(packID) {
|
||||
// The final normal quest unlocks PackTable.NextPackId. Without these
|
||||
// PackDBInfo updates the client cannot find the next story pack and
|
||||
// falls back to presenting the hard-difficulty objective.
|
||||
@@ -540,6 +540,10 @@ func (s *Service) Handle(ctx command.Context, path string, request []byte) (int,
|
||||
if err != nil {
|
||||
return 0, nil, true, err
|
||||
}
|
||||
currencyRewards, err := s.grantAdditionalQuestCurrencies(ctx, pack, quest, design.Rewards[s.questDifficultyFor(pack, quest)])
|
||||
if err != nil {
|
||||
return 0, nil, true, err
|
||||
}
|
||||
if err := s.state.ClearQuest(ctx, quest, pack, s.questDifficultyFor(pack, quest)); err != nil {
|
||||
return 0, nil, true, fmt.Errorf("world: clear quest: %w", err)
|
||||
}
|
||||
@@ -589,6 +593,7 @@ func (s *Service) Handle(ctx command.Context, path string, request []byte) (int,
|
||||
"timeline_map", design.TimelineStartMapID, "position_found", positionFound,
|
||||
"saved_position", saved.Position, "party_changes", len(nextChars), "items", len(items))
|
||||
rewards := append(s.questClearRewards(pack, quest, design.Rewards[s.questDifficultyFor(pack, quest)], items, questEquipment), lifeRewards...)
|
||||
rewards = append(rewards, currencyRewards...)
|
||||
out, err := s.clearResponse(ctx, pack, quest, rewards, nextItems, nextChars)
|
||||
if err != nil {
|
||||
return 0, nil, true, err
|
||||
|
||||
@@ -40,10 +40,7 @@ func (s *Service) questMaxClearInfo(request []byte) (int, []byte, bool, error) {
|
||||
}
|
||||
|
||||
func (s *Service) questTitleInfo(pack int) ([][]byte, error) {
|
||||
if s.storyCatalog == nil {
|
||||
return nil, nil
|
||||
}
|
||||
if _, found := s.storyCatalog.Packs[pack]; !found {
|
||||
if len(s.packQuestDesigns(pack)) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
titles, err := s.presentationSource.QuestTitles(pack)
|
||||
|
||||
@@ -40,12 +40,9 @@ func (s *Service) packSubQuestClearInfo(request []byte) (int, []byte, bool, erro
|
||||
}
|
||||
var response []byte
|
||||
for _, id := range packs {
|
||||
if s.storyCatalog == nil {
|
||||
return 227, nil, true, fmt.Errorf("%w: sub-quest clear info requested without a story catalog", ErrInvalidRequest)
|
||||
}
|
||||
pack, ok := s.storyCatalog.Packs[id]
|
||||
if !ok {
|
||||
return 227, nil, true, fmt.Errorf("%w: pack %d is not a story pack", ErrInvalidRequest, id)
|
||||
quests := s.packQuestDesigns(id)
|
||||
if len(quests) == 0 {
|
||||
return 227, nil, true, fmt.Errorf("%w: pack %d has no quest catalog", ErrInvalidRequest, id)
|
||||
}
|
||||
titles, err := s.presentationSource.QuestTitles(id)
|
||||
if err != nil {
|
||||
@@ -53,7 +50,7 @@ func (s *Service) packSubQuestClearInfo(request []byte) (int, []byte, bool, erro
|
||||
}
|
||||
var count uint64
|
||||
for _, title := range titles {
|
||||
if pack.Quests[title.LastQuest].Type == 1 && s.state.QuestCleared(title.LastQuest, id, 0) {
|
||||
if quests[title.LastQuest].Type == 1 && s.state.QuestCleared(title.LastQuest, id, 0) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func (s *Service) questDifficultyFor(packID, questID int) int {
|
||||
if s.storyCatalog != nil && s.storyCatalog.Packs[packID].Quests[questID].Type != 0 {
|
||||
if s.packQuestDesigns(packID)[questID].Type != 0 {
|
||||
return 0
|
||||
}
|
||||
return s.questDifficulty(packID)
|
||||
@@ -44,7 +44,7 @@ func (s *Service) visibleOwnedCharacters(characters []roster.Character) []roster
|
||||
}
|
||||
|
||||
func (s *Service) ensureQuestItems(ctx command.Context, packID, questID int) ([]assets.Item, error) {
|
||||
ids := s.storyCatalog.Packs[packID].Quests[questID].GiveQuestItemIDs
|
||||
ids := s.packQuestDesigns(packID)[questID].GiveQuestItemIDs
|
||||
if len(ids) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ func (s *Service) validateStoryCheckpoint(ctx command.Context, checkpoint StoryC
|
||||
if field, exists := s.fieldPacks[checkpoint.PackID]; exists && field.IntroQuest != nil {
|
||||
return s.validateFieldIntroCheckpoint(ctx, checkpoint, field)
|
||||
}
|
||||
pack, exists := s.storyCatalog.Packs[checkpoint.PackID]
|
||||
quests, exists := s.questsFor(ctx, checkpoint.PackID)
|
||||
if !exists || !s.packUnlocked(ctx, checkpoint.PackID) || checkpoint.Difficulty != s.questDifficultyFor(checkpoint.PackID, checkpoint.QuestID) {
|
||||
return fmt.Errorf("%w: checkpoint pack or difficulty unavailable", ErrInvalidRequest)
|
||||
}
|
||||
@@ -132,7 +132,7 @@ func (s *Service) validateStoryCheckpoint(ctx command.Context, checkpoint StoryC
|
||||
if !slices.Contains(maps.MapIDs, checkpoint.MapID) {
|
||||
return fmt.Errorf("%w: checkpoint map outside pack", ErrInvalidRequest)
|
||||
}
|
||||
quest, exists := pack.Quests[checkpoint.QuestID]
|
||||
quest, exists := quests[checkpoint.QuestID]
|
||||
if !exists {
|
||||
return fmt.Errorf("%w: pack %d has no quest %d for checkpoint %q", ErrInvalidRequest, checkpoint.PackID, checkpoint.QuestID, checkpoint.ID)
|
||||
}
|
||||
@@ -178,7 +178,7 @@ func (s *Service) validateFieldIntroCheckpoint(ctx command.Context, checkpoint S
|
||||
}
|
||||
|
||||
func (s *Service) beginQuestCompletionPresentation(ctx command.Context, pack, quest, difficulty int) error {
|
||||
design := s.storyCatalog.Packs[pack].Quests[quest]
|
||||
design := s.packQuestDesigns(pack)[quest]
|
||||
if design.CompleteCinemaName == "" {
|
||||
return nil
|
||||
}
|
||||
@@ -186,8 +186,14 @@ func (s *Service) beginQuestCompletionPresentation(ctx command.Context, pack, qu
|
||||
if saved, found := s.state.Position(); found && saved.PackID == pack {
|
||||
mapID = saved.Position.MapID
|
||||
}
|
||||
if mapID == 0 && len(s.storyCatalog.Packs[pack].MapIDs) > 0 {
|
||||
mapID = s.storyCatalog.Packs[pack].MapIDs[0]
|
||||
if mapID == 0 {
|
||||
maps, err := s.packDetailDesign(pack)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(maps.MapIDs) > 0 {
|
||||
mapID = maps.MapIDs[0]
|
||||
}
|
||||
}
|
||||
checkpoint := StoryCheckpoint{ID: fmt.Sprintf("quest-complete:%d:%d:%d", pack, difficulty, quest), PackID: pack, QuestID: quest, Difficulty: difficulty, Phase: "complete", Timeline: design.CompleteCinemaName, MapID: mapID}
|
||||
pending, err := loadStoryCheckpoint(ctx)
|
||||
|
||||
@@ -243,12 +243,7 @@ func (s *Service) questsFor(ctx command.Context, packID int) (map[int]gamedata.Q
|
||||
if pack.kind == eventCard {
|
||||
return nil, true
|
||||
}
|
||||
if s.storyCatalog != nil {
|
||||
if story, found := s.storyCatalog.Packs[packID]; found {
|
||||
return story.Quests, true
|
||||
}
|
||||
}
|
||||
return s.lifeQuestDesigns(packID), true
|
||||
return s.packQuestDesigns(packID), true
|
||||
}
|
||||
|
||||
// packUnlocked uses installed ContentOpen rules and real account tickets.
|
||||
@@ -262,7 +257,7 @@ func (s *Service) canClear(ctx command.Context, packID, quest int) bool {
|
||||
return true
|
||||
}
|
||||
quests, found := s.questsFor(ctx, packID)
|
||||
if !found || s.storyCatalog == nil {
|
||||
if !found {
|
||||
return false
|
||||
}
|
||||
design, found := quests[quest]
|
||||
@@ -313,8 +308,8 @@ func (s *Service) grantQuestRewards(ctx command.Context, packID, quest int, desi
|
||||
return nil, nil, fmt.Errorf("world: missing quest costume %d", reward.ID)
|
||||
}
|
||||
default:
|
||||
if lifeReward(reward) {
|
||||
continue // grantLifeQuestRewards
|
||||
if lifeReward(reward) || additionalQuestCurrency(reward) {
|
||||
continue
|
||||
}
|
||||
if reward.ID == 0 || reward.Count == 0 {
|
||||
return nil, nil, fmt.Errorf("world: invalid item reward type=%d id=%d count=%d", reward.Type, reward.ID, reward.Count)
|
||||
@@ -387,10 +382,7 @@ func (s *Service) grantQuestRewards(ctx command.Context, packID, quest int, desi
|
||||
}
|
||||
|
||||
func (s *Service) firstUnclearedQuestFor(packID int) int {
|
||||
if s.storyCatalog == nil {
|
||||
return 0
|
||||
}
|
||||
for _, id := range s.storyCatalog.Packs[packID].MainQuestIDs {
|
||||
for _, id := range s.mainQuestIDs(packID) {
|
||||
if !s.state.QuestCleared(id, packID, s.questDifficulty(packID)) {
|
||||
return id
|
||||
}
|
||||
@@ -399,10 +391,7 @@ func (s *Service) firstUnclearedQuestFor(packID int) int {
|
||||
}
|
||||
|
||||
func (s *Service) packCompleteFor(packID int) bool {
|
||||
if s.storyCatalog == nil {
|
||||
return false
|
||||
}
|
||||
ids := s.storyCatalog.Packs[packID].MainQuestIDs
|
||||
ids := s.mainQuestIDs(packID)
|
||||
if len(ids) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user