package gameserver import ( "fmt" 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(run *pb.MPIMAEMCEFH, request *pb.OHAINOHGKCM) (*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 } // 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 return cwNotify(selected, cwFinish(queue), cwUnlock(), &pb.KFNCAIHIHCM{MNLCHEJKDHO: &pb.KFNCAIHIHCM_FMIGOKIDKJL{FMIGOKIDKJL: pending}}), 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 } if err = s.saveCurrencyWarsData(data, catalog); err != nil { return nil } if err = cwSend(s, cwNotify(selected)); err != nil { return err } rsp.Retcode = 0 return nil }) }