Skip to main content

Introduction to rotating shop items

Last updated on April 17, 2024
info

Extend is in Open Beta for AGS Premium Clients! This means that the Extend add-on is available for you to try in your development environment. You can submit your feedback via our Extend Open Beta feedback form.

Overview

AccelByte Gaming Services (AGS) has the capability to let you define and customize your own rules for the Rotation Period and Total Items per Rotation for e-commerce platform services.

There are two functions on the contract as shown in the snippet below:

service SectionService {
/**
GetRotationItems: get current rotation items, this method will be called by rotation type is CUSTOM
*/
rpc GetRotationItems(GetRotationItemsRequest) returns (GetRotationItemsResponse);

/**
Backfill method trigger condition:
1. Rotation type is FIXED_PERIOD
2. Bulkfill type is CUSTOM
3. User already owned any one of current rotation items.
*/
rpc Backfill(BackfillRequest) returns (BackfillResponse);
}

GetRotationItems

This method will be called by the AGS platform e-commerce service for a store display section with rotation type CUSTOM. The function is called when users are trying to fetch active display sections. The developer can implement logic that determines what to show for that specified in-game store section for the particular user's request.

In this example, we'll implement the logic for GetRotationItems to return different items that will be rotated every hour.

async def GetRotationItems(self, request : GetRotationItemsRequest, context):
"""*
GetRotationItems: get current rotation items, this method will be called by rotation type is CUSTOM
"""
self.log_payload(f'{self.GetRotationItems.__name__} request: %s', request)
items : List[SectionItemObject] = request.sectionObject.items
input_count : int = len(items)
current_point : float = float(datetime.now().hour)
selected_index : int = int(math.floor((input_count/self.upper_limit)*current_point))
selected_item : SectionItemObject = items[selected_index]
response_items : List[SectionItemObject] = [selected_item]
response : GetRotationItemsResponse = GetRotationItemsResponse(expiredAt=0, items=response_items)
self.log_payload(f'{self.GetRotationItems.__name__} response: %s', response)
return response

Backfill

Backfill is called when the section rotation type is FIXED_PERIOD, the backfill type is CUSTOM, and there's already an owned item in the current item rotation. One of the use cases for this is you can implement the replacement logic for those owned items.

In this example, we'll replace items that are already owned by a new random item ID in its current index.

async def Backfill(self, request : BackfillRequest, context):
"""*
Backfill method trigger condition:
1. Rotation type is FIXED_PERIOD
2. Backfill type is CUSTOM
3. User already owned any one of current rotation items.
"""
self.log_payload(f'{self.Backfill.__name__} request: %s', request)
new_items : List[BackfilledItemObject] = []
item : RotationItemObject
for item in request.items:
if item.owned:
new_item : BackfilledItemObject = BackfilledItemObject(itemId=str(uuid.uuid4()).replace("-",""), index=item.index)
new_items.append(new_item)
response : BackfillResponse = BackfillResponse(backfilledItems=new_items)
self.log_payload(f'{self.Backfill.__name__} response: %s', response)
return response