Gift and Reward

 

KTplay Gift and Reward feature allow developer to send reward instruction to targeted device (or player) from KTplay developer portal, once a reward event is received in SDK, it will call back to the game client, and the actual reward logic will be executed in the callback function, the Reward Handler.

Reward Handler

The Reward Handler is the callback function for handling Reward event and responsible for handle reward execution.

KTPlay.setOnDispatchRewardsListener(new OnDispatchRewardsListener() {
    @Override
    public void onDispatchRewards(Reward reward) {
            
            Game.reportRewardEvent(reward.messageId,
                                        reward.gameUserId,
                                        reward.ktUserId);
         
        for(KTRewardItem item : reward.items){
             Game.applyReward(item);     
        }
    }
});


 KTDidDispatchRewardsBlock rewardBlock = (KTReward * reward){
     
    [Game reportRewardEvent:reward.messageId 
                     gameUserId:reward.gameUserId 
                        ktUserId:reward.ktUserId];
                        
                    
    for (KTRewardItem *item in reward.items) {
         [Game applyReward:item];   
        }
    }

[KTPlay setDidDispatchRewardsBlock: rewardBlock]

void dispatchRewards (KTRewardC * reward){
    Game::reportRewardEvent(reward->messageId,
                                    reward->gameUserId,
                                    reward->ktUserId);

    for ( int i = 0; i < reward->length; i ++) {
            KTRewardItemC *item = &reward->items[i];
            Game::applyReward(item);
    }
}

KTPlayC::setDidDispatchRewardsCallback( dispatchRewards );

KTPlay.SetDidDispatchRewardsDelegate ((KTReward * reward) => {
   
    Game.reportRewardEvent(reward.messageId,
                                    reward.gameUserId,
                                    reward.ktUserId);
    
    for (int i = 0; i < reward.items.Count; i++) {
        KTPlayRewardsItem item = (KTPlayRewardsItem)reward.item[i];
         Game.applyReward(item);   
    }
});

public function rewardsListener(reward:KTReward):void{
    "userId = " + reward.messageId + "\n" + 
    "headerUrl = " + reward.ktUserId + "\n" + 
    "nickname = " + reward.gameUserId+ "\n" ;
    for (var i:int=0; i<reward.items.length; i++) {
    var rewardItem:KTRewardItem = reward.items[i];
    description+="{name: "+rewardItem.name + "\ntypeId: " + rewardItem.typeId + "\nvalue: " + rewardItem.value +"\n}\n";
    }
    return description;
}
KTPlay.setOnDispatchRewardsListener(rewardsListener);
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.