package gameserver import ( "fmt" "gac-hkrpg-go/internal/common" pb "gac-hkrpg-go/protocol/proto" ) // cwEncounterRewards grants the selected server-side offer, never a list // supplied by the battle upload. In the reference, gfRouteBattleStageInfoProto // projects option reward type/id/count into the branch's drop list; the battle // result applies that option reward on passing the threshold or a perfect clear. // Perfect clears additionally earn monster Orbs, which are not handled here. // run must be a detached snapshot which the caller discards on any error. func cwEncounterRewards(c *common.CurrencyWarsCatalog, run *pb.MPIMAEMCEFH, branch *pb.KKBGIPCAGGH, progress, threshold uint32) ([]*pb.KFNCAIHIHCM, error) { if branch == nil { return nil, fmt.Errorf("CW Encounter selected branch missing") } if progress < threshold { return nil, nil } if branch.BOAMLLHPNEC == nil { return nil, fmt.Errorf("CW Encounter selected rewards missing") } recipes, err := common.LoadCurrencyWarsOrbRecipes() if err != nil { return nil, err } var updates []*pb.KFNCAIHIHCM for _, drop := range branch.BOAMLLHPNEC.NMGIABHIJJB { if drop == nil || drop.Num == 0 { return nil, fmt.Errorf("CW Encounter reward is invalid") } var reward common.CurrencyWarsOrbReward switch drop.FKKGLFOHGGA { case pb.MJJIFGINJAJ_MJJIFGINJAJ_item_value: if drop.FNLMKJLKLFH != 0 { return nil, fmt.Errorf("CW Encounter gold identity is invalid") } reward = common.CurrencyWarsOrbReward{Reward: "Gold", Amount: drop.Num} case pb.MJJIFGINJAJ_MJJIFGINJAJ_exp: if drop.FNLMKJLKLFH != 0 { return nil, fmt.Errorf("CW Encounter EXP identity is invalid") } reward = common.CurrencyWarsOrbReward{Reward: "Exp", Amount: drop.Num} case pb.MJJIFGINJAJ_MJJIFGINJAJ_NLFCABFPJHD: reward = common.CurrencyWarsOrbReward{Reward: "Item", ItemID: drop.FNLMKJLKLFH, Count: drop.Num} default: return nil, fmt.Errorf("CW Encounter reward type %v is not mapped", drop.FKKGLFOHGGA) } grants, _, err := cwApplyOrbReward(c, run, recipes, reward) if err != nil { return nil, err } updates = append(updates, grants...) } return updates, nil }