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, runtime ...*common.CurrencyWarsRuntimeState) ([]*pb.KFNCAIHIHCM, error) { if branch == nil { return nil, fmt.Errorf("CW Encounter selected branch missing") } if len(runtime) == 1 && cwXaodevGenerated(run, runtime[0]) { // xaodev branchDropPreview advertises the node's base gold, already // paid by settlement. It is not an additional threshold reward. The // server-side source marker survives reconnects and is never a wire tag. data, err := common.LoadCurrencyWarsXaodev(c) if err != nil { return nil, err } _, node := cwStage(run) drops := branch.GetBOAMLLHPNEC().GetNMGIABHIJJB() if data.Policy.RewardPolicy != "preview_base_gold_already_paid_by_settlement" || node == nil || len(drops) != 1 || drops[0] == nil || drops[0].FKKGLFOHGGA != pb.MJJIFGINJAJ_MJJIFGINJAJ_item_value || drops[0].FNLMKJLKLFH != 0 || drops[0].Num != node.PICMDONCKCO { return nil, fmt.Errorf("CW xaodev Encounter base-gold preview differs") } return nil, nil } 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 }