Files

60 lines
2.0 KiB
Go

package gameserver
import (
"fmt"
"gac-hkrpg-go/internal/common"
goproto "gac-hkrpg-go/protocol/proto"
"google.golang.org/protobuf/proto"
)
type currencyWarsNodeCoordinate struct {
Chapter uint32
Section uint32
}
// applyCurrencyWarsRoute fills only the route component. Battle/node status
// belongs to the action that enters a node and is preserved on dst.
// Native GridFightStage.Sync (0xdc05680) copies the three scalar coordinates;
// _SyncRouteInfo (0xdc05740) passes route ID and nodes to SyncRouteNodes. The
// latter stores its first argument in GridFightStageRoute._StageRouteID.
func applyCurrencyWarsRoute(dst *goproto.BEEFLEJAOCN, catalog *common.CurrencyWarsCatalog,
routeID uint32, current currencyWarsNodeCoordinate,
displays map[currencyWarsNodeCoordinate]*goproto.OHMDHKGAEMM) error {
if dst == nil || catalog == nil {
return fmt.Errorf("CW route destination/catalog is missing")
}
rows, err := catalog.RouteNodes(routeID)
if err != nil {
return err
}
nodes := make([]*goproto.BCCIJHPLJOJ, 0, len(rows))
foundCurrent := false
for _, row := range rows {
coordinate := currencyWarsNodeCoordinate{Chapter: row.ChapterID, Section: row.SectionID}
display := displays[coordinate]
if display == nil {
return fmt.Errorf("CW node configuration is missing: route=%d chapter=%d section=%d template=%d",
routeID, row.ChapterID, row.SectionID, row.NodeTemplateID)
}
nodes = append(nodes, &goproto.BCCIJHPLJOJ{
DCAHJELNJNP: row.ChapterID,
SectionId: row.SectionID,
DisplayValue: proto.Clone(display).(*goproto.OHMDHKGAEMM),
})
foundCurrent = foundCurrent || coordinate == current
}
if !foundCurrent {
return fmt.Errorf("CW current node is outside captured route")
}
if len(displays) != len(rows) {
return fmt.Errorf("CW node configuration contains coordinates outside captured route")
}
// Commit after all input has been validated, preserving dst on any error.
dst.DCAHJELNJNP = current.Chapter
dst.SectionId = current.Section
dst.EMOHLJHPOPC = routeID
dst.OOMMIIKPHBC = nodes
return nil
}