package gameserver import ( "fmt" "gac-hkrpg-go/internal/common" goproto "gac-hkrpg-go/protocol/proto" "google.golang.org/protobuf/proto" ) // Apply the resource-defined freeplay lobby state on this entrance only. // Client-managed groups create their own props once their condition is true. func currencyWarsEntranceScene(scene *common.LevelOutputConfig, entrance common.CurrencyWarsEntrance) (*common.LevelOutputConfig, error) { copyScene := *scene copyScene.SavedValues = make(map[string]int32, len(scene.SavedValues)) for name, value := range scene.SavedValues { copyScene.SavedValues[name] = value } for name, value := range entrance.SavedValues { old, exists := copyScene.SavedValues[name] if !exists { return nil, fmt.Errorf("CW room activation value missing: %s", name) } copyScene.SavedValues[name] = value SceneDebugLog("CW_ROOM_ACTIVATION entry=%d name=%s previous=%d selected=%d", entrance.EntryID, name, old, value) } for _, room := range entrance.RoomGroups { value, exists := copyScene.SavedValues[room.Condition.Name] if !exists { return nil, fmt.Errorf("CW room activation value missing: %s", room.Condition.Name) } if room.Condition.Comparison != "GreaterEqual" { return nil, fmt.Errorf("unsupported CW room comparison") } if value < room.Condition.Value { return nil, fmt.Errorf("CW room activation condition is not satisfied") } } return ©Scene, nil } func init() { // Bind to this revision's command table. Save a complete initial preset // before returning success so the immediately following GetData sees it. cwHandle("GridFightStartGamePlay", func(s *Session, req *goproto.GridFightStartGamePlayCsReq, rsp *goproto.GridFightStartGamePlayScRsp) error { mode := "standard" if req.IsOverlock { mode = "overclock" } rsp.Retcode = uint32(goproto.Retcode_RET_GRID_FIGHT_CONF_MISS) catalog, err := common.LoadCurrencyWarsCatalog() if err != nil { PacketLog(fmt.Sprintf("CW_START_GAMEPLAY rejected mode=%s retcode=%d reason=catalog_error error=%v", mode, rsp.Retcode, err)) return nil } division, exists := catalog.Division(req.DivisionId) if !exists || division.SeasonID != catalog.ActiveSeasonID { rsp.Retcode = uint32(goproto.Retcode_RET_GRID_FIGHT_PARAM_NOT_MATCH) PacketLog(fmt.Sprintf("CW_START_GAMEPLAY rejected mode=%s division=%d param_3=%d season=%d retcode=%d reason=division_mismatch", mode, req.DivisionId, req.MPJPLKKJNGE, req.LJNGPCKPJLF, rsp.Retcode)) return nil } data, revision, err := readCurrencyWarsData(catalog) if err != nil { PacketLog(fmt.Sprintf("CW_START_GAMEPLAY rejected mode=%s retcode=%d reason=snapshot_error error=%v", mode, rsp.Retcode, err)) return nil } if data != nil && data.DHFOFLFCLAH != nil { rsp.Retcode = uint32(goproto.Retcode_RET_GRID_FIGHT_ALREADY_IN_GAMEPLAY) PacketLog(fmt.Sprintf("CW_START_GAMEPLAY rejected mode=%s retcode=%d reason=active_run_exists", mode, rsp.Retcode)) return nil } if req.LJNGPCKPJLF != catalog.ActiveSeasonID || revision != s.currencyWarsRevision { rsp.Retcode = uint32(goproto.Retcode_RET_GRID_FIGHT_PARAM_NOT_MATCH) PacketLog(fmt.Sprintf("CW_START_GAMEPLAY rejected mode=%s retcode=%d reason=season_or_session_revision_mismatch", mode, rsp.Retcode)) return nil } if revision >= uint64(^uint32(0)) { PacketLog("CW_START_GAMEPLAY rejected reason=run_identifier_exhausted") return nil } run, err := buildCurrencyWarsInitialRun(catalog, req, uint32(revision+1)) if err != nil { PacketLog(fmt.Sprintf("CW_START_GAMEPLAY rejected mode=%s division=%d retcode=%d error=%v", mode, req.DivisionId, rsp.Retcode, err)) return nil } if data == nil { data, err = newCurrencyWarsData(catalog) if err != nil { return err } } data.DHFOFLFCLAH = run if err := s.saveCurrencyWarsData(data, catalog); err != nil { PacketLog(fmt.Sprintf("CW_START_GAMEPLAY rejected reason=save_error error=%v", err)) return nil } rsp.DHFOFLFCLAH = proto.Clone(run).(*goproto.MPIMAEMCEFH) rsp.Retcode = 0 PacketLog(fmt.Sprintf("CW_START_GAMEPLAY started mode=%s division=%d season=%d run=%d revision=%d source=captured_initial_preset", mode, req.DivisionId, req.LJNGPCKPJLF, run.UniqueId, s.currencyWarsRevision)) return nil }) cwHandle("GridFightResumeGamePlay", func(s *Session, req *goproto.GridFightResumeGamePlayCsReq, rsp *goproto.GridFightResumeGamePlayScRsp) error { rsp.Retcode = uint32(goproto.Retcode_RET_GRID_FIGHT_NOT_IN_GAMEPLAY) catalog, err := common.LoadCurrencyWarsCatalog() if err != nil { return err } data, revision, err := readCurrencyWarsData(catalog) if err != nil { return err } if data == nil || data.DHFOFLFCLAH == nil { return nil } if req.UniqueId != data.DHFOFLFCLAH.UniqueId { rsp.Retcode = uint32(goproto.Retcode_RET_GRID_FIGHT_PARAM_NOT_MATCH) return nil } if revision != s.currencyWarsRevision { rsp.Retcode = uint32(goproto.Retcode_RET_GRID_FIGHT_PARAM_NOT_MATCH) return nil } // Reconcile triplets left by the former buy handler on an explicit // Resume action. Snapshot readers remain read-only. if data.DHFOFLFCLAH.GetFMIGOKIDKJL().GetBAKAKODKECM() != nil { if _, active := CURRENT_BATTLE.Load(s.Token); !active { changed, e := cwAlignEncounterCamp(catalog, data.DHFOFLFCLAH) if e != nil { PacketLog("CW_RESUME Encounter rejected: " + e.Error()) return nil } if changed { if e = s.saveCurrencyWarsData(data, catalog); e != nil { return nil } } } } if data.DHFOFLFCLAH.FMIGOKIDKJL == nil { if _, active := CURRENT_BATTLE.Load(s.Token); !active { groups, e := cwMergeRoles(catalog, data.DHFOFLFCLAH, 0) if e != nil { PacketLog("CW_RESUME merge rejected: " + e.Error()) return nil } addedSpotlights := cwEnsureSpotlights(data.DHFOFLFCLAH) if len(groups) > 0 || addedSpotlights { if e = s.saveCurrencyWarsData(data, catalog); e != nil { return nil } // Resume is followed by GetData. Return the reconciled roster in // that snapshot, after the Client constructs its game session. PacketLog(fmt.Sprintf("CW_RESUME merged=%d revision=%d", len(groups), s.currencyWarsRevision)) } } } rsp.Retcode = 0 return nil }) // Leaving the UI keeps the active run for Resume, matching the reference. cwHandle("GridFightQuitLeaveGamePlay", func(s *Session, _ *goproto.GridFightQuitLeaveGamePlayCsReq, _ *goproto.GridFightQuitLeaveGamePlayScRsp) error { s.currencyWarsOpen = false return nil }) // CW's points panel uses the shared CycleScore reward period. Missing // GetData leaves its MonoRemainTimer at the Unix epoch and closes the page. // This fresh-profile bootstrap uses the explicit operator activity window; // weekly rollover, earned scores and reward claims still need persistence. handle("CycleScoreRewardGetData", func(s *Session, req *goproto.CycleScoreRewardGetDataCsReq, rsp *goproto.CycleScoreRewardGetDataScRsp) error { cfg, err := common.LoadRuntimeConfig() if err != nil { return err } rsp.NFEDANFBIBE = &goproto.GAAMBBFPCHB{EndTime: *cfg.ActivitySchedule.EndTime} PacketLog(fmt.Sprintf("CYCLE_SCORE_REWARD_DATA end_time=%d score=0 bootstrap=true policy=activity_window", *cfg.ActivitySchedule.EndTime)) return nil }) // Bootstrap only. Keep the danger-family guard for every unsupported CW // operation; it must never receive a successful empty gameplay response. cwHandle("GridFightGetData", func(s *Session, req *goproto.GridFightGetDataCsReq, rsp *goproto.GridFightGetDataScRsp) error { catalog, err := common.LoadCurrencyWarsCatalog() if err != nil { return err } saved, revision, err := readCurrencyWarsData(catalog) if err != nil { return err } if saved != nil { proto.Merge(rsp, saved) s.currencyWarsRevision = revision s.currencyWarsOpen = saved.DHFOFLFCLAH != nil PacketLog(fmt.Sprintf("CW_GET_DATA restored=true revision=%d active_run=%t", revision, saved.DHFOFLFCLAH != nil)) return nil } s.currencyWarsRevision = 0 initial, err := newCurrencyWarsData(catalog) if err != nil { return err } proto.Merge(rsp, initial) PacketLog(fmt.Sprintf("CW_GET_DATA season=%d subseason=%d division=%d active_run=false bootstrap=true tutorial_policy=freeplay_unlocked", catalog.ActiveSeasonID, catalog.ActiveSubSeasonID, initial.LFLCDNGALME.HFPEJIDDDJG.DivisionId)) return nil }) }