package gameserver import ( "fmt" "gac-hkrpg-go/internal/common" pb "gac-hkrpg-go/protocol/proto" ) // Current schema MOADBALHMFD is SelectedEliteBranchId in layer/sync and // EliteBranchId in both requests. The reference SelectEncounter and // BuildEncounterSelectionUpdateSync use a one-based offered-branch index. func cwSetEncounterSelection(run *pb.MPIMAEMCEFH, index uint32) (*pb.KFNCAIHIHCM, error) { stage, _ := cwStage(run) if stage == nil { return nil, fmt.Errorf("CW Encounter stage missing") } layer := stage.GetIMPNAHBCADN().GetMPOBBIPMNNJ() if layer == nil || len(layer.BPDABHGFBFO) < 2 || index == 0 || uint64(index) > uint64(len(layer.BPDABHGFBFO)) || layer.BPDABHGFBFO[index-1] == nil { return nil, fmt.Errorf("CW Encounter branch is not in the active offer") } layer.MOADBALHMFD = index return &pb.KFNCAIHIHCM{MNLCHEJKDHO: &pb.KFNCAIHIHCM_FGODNPLCECH{FGODNPLCECH: &pb.KEPIEGKPFIJ{MOADBALHMFD: index}}}, nil } func cwSelectEncounter(c *common.CurrencyWarsCatalog, run *pb.MPIMAEMCEFH, request *pb.OHAINOHGKCM, runtime *common.CurrencyWarsRuntimeState) (*pb.GridFightSyncUpdateResultScNotify, error) { if run.GetFMIGOKIDKJL().GetBAKAKODKECM() == nil || request == nil { return nil, fmt.Errorf("CW Encounter selection is not active") } queue := run.FMIGOKIDKJL.QueuePosition if queue == ^uint32(0) { return nil, fmt.Errorf("CW pending identifiers exhausted") } selected, err := cwSetEncounterSelection(run, request.MOADBALHMFD) if err != nil { return nil, err } difficulty, err := cwXaodevSelectionDifficulty(c, run, runtime) if err != nil { return nil, err } // Reference phase transition: SelectingEncounter -> AwaitingBattleReturn, // followed by the ordinary ReturnPreparation action; no battle starts here. pending := &pb.CHCHAJIANIM{QueuePosition: queue + 1, FGLIODAJFML: &pb.CHCHAJIANIM_LGNPHHBGKFH{LGNPHHBGKFH: &pb.HJPDALHDJHC{}}} run.FMIGOKIDKJL = pending notify := cwNotify(selected) if difficulty != nil { notify.GCPNIHHBGGD[0].JKPJFKCBIEM = append(notify.GCPNIHHBGGD[0].JKPJFKCBIEM, difficulty) } notify.GCPNIHHBGGD[0].JKPJFKCBIEM = append(notify.GCPNIHHBGGD[0].JKPJFKCBIEM, cwFinish(queue), cwUnlock(), &pb.KFNCAIHIHCM{MNLCHEJKDHO: &pb.KFNCAIHIHCM_FMIGOKIDKJL{FMIGOKIDKJL: pending}}) return notify, nil } func init() { cwHandle("GridFightUpdateEliteBranchSelect", func(s *Session, req *pb.GridFightUpdateEliteBranchSelectCsReq, rsp *pb.GridFightUpdateEliteBranchSelectScRsp) error { rsp.Retcode = uint32(pb.Retcode_RET_GRID_FIGHT_PARAM_NOT_MATCH) catalog, data, err := cwPreparingData(s) if err != nil { return nil } selected, err := cwSetEncounterSelection(data.DHFOFLFCLAH, req.MOADBALHMFD) if err != nil { PacketLog("CW_ENCOUNTER_UPDATE rejected: " + err.Error()) return nil } runtime, err := cwBonfireRuntime(catalog, data.DHFOFLFCLAH) if err != nil { return err } difficulty, err := cwXaodevSelectionDifficulty(catalog, data.DHFOFLFCLAH, runtime) if err != nil { return err } if err = s.saveCurrencyWarsDataWithRuntime(data, catalog, runtime); err != nil { return nil } notify := cwNotify(selected) if difficulty != nil { notify.GCPNIHHBGGD[0].JKPJFKCBIEM = append(notify.GCPNIHHBGGD[0].JKPJFKCBIEM, difficulty) } if err = cwSend(s, notify); err != nil { return err } rsp.Retcode = 0 return nil }) }