跳到主要内容

Server Economy API Reference

PGOS provides a series of services to help you build a in-game economy, including virtual currencies, in-game items, stores, and inventory.

API List

APIDescription
GrantItemToPlayerGrant specified items to the player's inventory. The PGOS backend events event_item_granted/event_currency_changed will be triggered.
BatchRevokeInstancesBatch revoke the specified item instances in the player's inventory. The PGOS virtual server event event_item_revoked will be triggered.
GrantCurrencyToPlayerGrant currency to player's balance. The PGOS backend event event_currency_changed will be triggered.
BatchGrantVirtualCurrenciesToPlayerBatch grant virtual currencies to player's balance. NOTE: Premium currency can not be granted by this API.
SubtractPlayerCurrencySubtract currency form player's balance. The PGOS backend event event_currency_changed will be triggered.
BatchSubtractPlayerVirtualCurrenciesBatch subtract virtual currencies from player's balance. NOTE: Premium currency can not be subtracted by this API.
GetPlayerBalanceGet player's balance.
GetPlayerInventoryQuery item instances in the specified player's inventory.
GetPlayerInventoryWithFilterGet all item instances in the player's inventory.
SetInstanceCustomDataUpdate the mutable_custom_data of the specified item instance in the player's inventory. The key must be prefixed with "int", "flt", or "str_", which respectively indicate that the value type is integer, float, or string. Instance mutable_custom_data can have up to 32 keys, with each key limited to 128 bytes and each value limited to 4096 bytes(in a narrow-character string).
BatchSetInstanceCustomDataBatch update the mutable_custom_data of the specified item instance in the player's inventory. The key must be prefixed with "int", "flt", or "str_", which respectively indicate that the value type is integer, float, or string. Instance mutable_custom_data can have up to 32 keys, with each key limited to 128 bytes and each value limited to 4096 bytes(in a narrow-character string).
SetInstanceCustomDataWithVersionUpdate the mutable_custom_data of the specified item instance in the player's inventory. The key must be prefixed with "int", "flt", or "str_", which respectively indicate that the value type is integer, float, or string. The 'version' that needs to be passed in can be obtained from the mutable_custom_data of the ItemInstance. If the 'version' passed in is the latest, the callback will return success along with the latest data after updated. If the 'version' passed in is not the latest, the callback will return failure(err_code=11108, kBackendKVDataVersionMismatched (11108)) along with the current latest data, you may try again with the latest version. Instance mutable_custom_data can have up to 32 keys, with each key limited to 128 bytes and each value limited to 4096 bytes(in a narrow-character string).
IncrInstanceCustomDataPerform atomic increment operation on mutable_custom_data kvdata for the instance. [Only keys with the prefixes "int" and "flt" are supported]
SetInstanceTagsUpdate the tags data of the specified item instance in the player's inventory. Instance tags can have up to 32 keys, with each key limited to 128 bytes and each value limited to 1024 bytes(in a narrow-character string).
BatchSetInstanceTagsBatch update the tags data of the specified item instance in the player's inventory. Instance tags can have up to 32 keys, with each key limited to 128 bytes and each value limited to 1024 bytes(in a narrow-character string).

API Details

GrantItemToPlayer

Grant specified items to the player's inventory. The PGOS backend events event_item_granted/event_currency_changed will be triggered.

/// <summary>
/// Grant specified items to the player's inventory.
/// The PGOS backend events `event_item_granted`/`event_currency_changed` will be triggered.
/// </summary>
/// <param name="pgos_params">Request params.</param>
public void GrantItemToPlayer(GrantItemToPlayerParams pgos_params, EconomyDelegate0 callback);

Parameters:

ParamTypeDescription
pgos_paramsGrantItemToPlayerParamsRequest params.
callbackEconomyDelegate0

Return: void

BatchRevokeInstances

Batch revoke the specified item instances in the player's inventory. The PGOS virtual server event event_item_revoked will be triggered.

/// <summary>
/// Batch revoke the specified item instances in the player's inventory.
/// The PGOS virtual server event `event_item_revoked` will be triggered.
/// </summary>
/// <param name="pgos_params">Request params.</param>
public void BatchRevokeInstances(BatchRevokeInstancesParams pgos_params, EconomyDelegate1 callback);

Parameters:

ParamTypeDescription
pgos_paramsBatchRevokeInstancesParamsRequest params.
callbackEconomyDelegate1

Return: void

GrantCurrencyToPlayer

Grant currency to player's balance. The PGOS backend event event_currency_changed will be triggered.

/// <summary>
/// Grant currency to player's balance.
/// The PGOS backend event `event_currency_changed` will be triggered.
/// </summary>
/// <param name="pgos_params">Request params.</param>
public void GrantCurrencyToPlayer(GrantCurrencyToPlayerParams pgos_params, EconomyDelegate2 callback);

Parameters:

ParamTypeDescription
pgos_paramsGrantCurrencyToPlayerParamsRequest params.
callbackEconomyDelegate2

Return: void

BatchGrantVirtualCurrenciesToPlayer

Batch grant virtual currencies to player's balance. NOTE: Premium currency can not be granted by this API.

/// <summary>
/// Batch grant virtual currencies to player's balance.
/// NOTE: Premium currency can not be granted by this API.
/// </summary>
/// <param name="pgos_params">Result params.</param>
public void BatchGrantVirtualCurrenciesToPlayer(BatchGrantVirtualCurrenciesToPlayerParams pgos_params, EconomyDelegate3 callback);

Parameters:

ParamTypeDescription
pgos_paramsBatchGrantVirtualCurrenciesToPlayerParamsResult params.
callbackEconomyDelegate3

Return: void

SubtractPlayerCurrency

Subtract currency form player's balance. The PGOS backend event event_currency_changed will be triggered.

/// <summary>
/// Subtract currency form player's balance.
/// The PGOS backend event `event_currency_changed` will be triggered.
/// </summary>
/// <param name="pgos_params">Request params.</param>
public void SubtractPlayerCurrency(SubtractPlayerCurrencyParams pgos_params, EconomyDelegate4 callback);

Parameters:

ParamTypeDescription
pgos_paramsSubtractPlayerCurrencyParamsRequest params.
callbackEconomyDelegate4

Return: void

BatchSubtractPlayerVirtualCurrencies

Batch subtract virtual currencies from player's balance. NOTE: Premium currency can not be subtracted by this API.

/// <summary>
/// Batch subtract virtual currencies from player's balance.
/// NOTE: Premium currency can not be subtracted by this API.
/// </summary>
/// <param name="pgos_params">Result params.</param>
public void BatchSubtractPlayerVirtualCurrencies(BatchSubtractPlayerVirtualCurrenciesParams pgos_params, EconomyDelegate5 callback);

Parameters:

ParamTypeDescription
pgos_paramsBatchSubtractPlayerVirtualCurrenciesParamsResult params.
callbackEconomyDelegate5

Return: void

GetPlayerBalance

Get player's balance.

/// <summary>Get player's balance.</summary>
/// <param name="pgos_params">Request params.</param>
public void GetPlayerBalance(GetPlayerBalanceParams pgos_params, EconomyDelegate6 callback);

Parameters:

ParamTypeDescription
pgos_paramsGetPlayerBalanceParamsRequest params.
callbackEconomyDelegate6

Return: void

GetPlayerInventory

Query item instances in the specified player's inventory.

/// <summary>Query item instances in the specified player's inventory.</summary>
/// <param name="player_id">The specified player id.</param>
/// <param name="instance_ids">
/// Item instance ids to query.
/// If the 'instance_ids' is empty, it will return all instances in the player's inventory.
/// </param>
public void GetPlayerInventory(string player_id, List<string> instance_ids, EconomyDelegate7 callback);

Parameters:

ParamTypeDescription
player_idstringThe specified player id.
instance_idsList<string>Item instance ids to query. If the 'instance_ids' is empty, it will return all instances in the player's inventory.
callbackEconomyDelegate7

Return: void

GetPlayerInventoryWithFilter

Get all item instances in the player's inventory.

/// <summary>Get all item instances in the player's inventory.</summary>
/// <param name="pgos_params">Request params.</param>
public void GetPlayerInventoryWithFilter(GetPlayerInventoryWithFilterParams pgos_params, EconomyDelegate8 callback);

Parameters:

ParamTypeDescription
pgos_paramsGetPlayerInventoryWithFilterParamsRequest params.
callbackEconomyDelegate8

Return: void

SetInstanceCustomData

Update the mutable_custom_data of the specified item instance in the player's inventory. The key must be prefixed with "int", "flt", or "str_", which respectively indicate that the value type is integer, float, or string. Instance mutable_custom_data can have up to 32 keys, with each key limited to 128 bytes and each value limited to 4096 bytes(in a narrow-character string).

/// <summary>
/// Update the `mutable_custom_data` of the specified item instance in the player's inventory.
/// The key must be prefixed with "int_", "flt_", or "str_", which respectively indicate that the value type is integer, float, or string.
/// Instance `mutable_custom_data` can have up to 32 keys, with each key limited to 128 bytes and each value limited to 4096 bytes(in a narrow-character string).
/// </summary>
/// <param name="pgos_params">Request params.</param>
public void SetInstanceCustomData(SetInstanceCustomDataParams pgos_params, EconomyDelegate9 callback);

Parameters:

ParamTypeDescription
pgos_paramsSetInstanceCustomDataParamsRequest params.
callbackEconomyDelegate9

Return: void

BatchSetInstanceCustomData

Batch update the mutable_custom_data of the specified item instance in the player's inventory. The key must be prefixed with "int", "flt", or "str_", which respectively indicate that the value type is integer, float, or string. Instance mutable_custom_data can have up to 32 keys, with each key limited to 128 bytes and each value limited to 4096 bytes(in a narrow-character string).

/// <summary>
/// Batch update the `mutable_custom_data` of the specified item instance in the player's inventory.
/// The key must be prefixed with "int_", "flt_", or "str_", which respectively indicate that the value type is integer, float, or string.
/// Instance `mutable_custom_data` can have up to 32 keys, with each key limited to 128 bytes and each value limited to 4096 bytes(in a narrow-character string).
/// </summary>
/// <param name="pgos_params">Request params.</param>
public void BatchSetInstanceCustomData(BatchSetInstanceCustomDataParams pgos_params, EconomyDelegate10 callback);

Parameters:

ParamTypeDescription
pgos_paramsBatchSetInstanceCustomDataParamsRequest params.
callbackEconomyDelegate10

Return: void

SetInstanceCustomDataWithVersion

Update the mutable_custom_data of the specified item instance in the player's inventory. The key must be prefixed with "int", "flt", or "str_", which respectively indicate that the value type is integer, float, or string. The 'version' that needs to be passed in can be obtained from the mutable_custom_data of the ItemInstance. If the 'version' passed in is the latest, the callback will return success along with the latest data after updated. If the 'version' passed in is not the latest, the callback will return failure(err_code=11108, kBackendKVDataVersionMismatched (11108)) along with the current latest data, you may try again with the latest version. Instance mutable_custom_data can have up to 32 keys, with each key limited to 128 bytes and each value limited to 4096 bytes(in a narrow-character string).

/// <summary>
/// Update the `mutable_custom_data` of the specified item instance in the player's inventory.
/// The key must be prefixed with "int_", "flt_", or "str_", which respectively indicate that the value type is integer, float, or string.
/// The 'version' that needs to be passed in can be obtained from the `mutable_custom_data` of the `ItemInstance`.
/// If the 'version' passed in is the latest, the callback will return success along with the latest data after updated.
/// If the 'version' passed in is not the latest, the callback will return failure(err_code=11108, kBackendKVDataVersionMismatched (11108)) along with the current latest data, you may try again with the latest version.
/// Instance `mutable_custom_data` can have up to 32 keys, with each key limited to 128 bytes and each value limited to 4096 bytes(in a narrow-character string).
/// </summary>
/// <param name="pgos_params">Request params.</param>
public void SetInstanceCustomDataWithVersion(SetInstanceCustomDataWithVersionParams pgos_params, EconomyDelegate9 callback);

Parameters:

ParamTypeDescription
pgos_paramsSetInstanceCustomDataWithVersionParamsRequest params.
callbackEconomyDelegate9

Return: void

IncrInstanceCustomData

Perform atomic increment operation on mutable_custom_data kvdata for the instance. [Only keys with the prefixes "int" and "flt" are supported]

/// <summary>Perform atomic increment operation on `mutable_custom_data` kvdata for the instance. [Only keys with the prefixes "int_" and "flt_" are supported]</summary>
/// <param name="pgos_params">Request params.</param>
public void IncrInstanceCustomData(IncrInstanceCustomDataParams pgos_params, EconomyDelegate11 callback);

Parameters:

ParamTypeDescription
pgos_paramsIncrInstanceCustomDataParamsRequest params.
callbackEconomyDelegate11

Return: void

SetInstanceTags

Update the tags data of the specified item instance in the player's inventory. Instance tags can have up to 32 keys, with each key limited to 128 bytes and each value limited to 1024 bytes(in a narrow-character string).

/// <summary>
/// Update the `tags` data of the specified item instance in the player's inventory.
/// Instance `tags` can have up to 32 keys, with each key limited to 128 bytes and each value limited to 1024 bytes(in a narrow-character string).
/// </summary>
/// <param name="pgos_params">Request params.</param>
public void SetInstanceTags(SetInstanceTagsParams pgos_params, EconomyDelegate12 callback);

Parameters:

ParamTypeDescription
pgos_paramsSetInstanceTagsParamsRequest params.
callbackEconomyDelegate12

Return: void

BatchSetInstanceTags

Batch update the tags data of the specified item instance in the player's inventory. Instance tags can have up to 32 keys, with each key limited to 128 bytes and each value limited to 1024 bytes(in a narrow-character string).

/// <summary>
/// Batch update the `tags` data of the specified item instance in the player's inventory.
/// Instance `tags` can have up to 32 keys, with each key limited to 128 bytes and each value limited to 1024 bytes(in a narrow-character string).
/// </summary>
/// <param name="pgos_params">Request params.</param>
public void BatchSetInstanceTags(BatchSetInstanceTagsParams pgos_params, EconomyDelegate13 callback);

Parameters:

ParamTypeDescription
pgos_paramsBatchSetInstanceTagsParamsRequest params.
callbackEconomyDelegate13

Return: void

All Delegates

public delegate void EconomyDelegate0(PgosResult a0, GrantItemResult a1);
public delegate void EconomyDelegate1(PgosResult a0, BatchRevokeInstancesResult a1);
public delegate void EconomyDelegate2(PgosResult a0, GrantCurrencyResult a1);
public delegate void EconomyDelegate3(PgosResult a0, BatchGrantVirtualCurrenciesToPlayerResult a1);
public delegate void EconomyDelegate4(PgosResult a0, SubtractPlayerCurrencyResult a1);
public delegate void EconomyDelegate5(PgosResult a0, BatchSubtractPlayerVirtualCurrenciesResult a1);
public delegate void EconomyDelegate6(PgosResult a0, GetPlayerBalanceResult a1);
public delegate void EconomyDelegate7(PgosResult a0, GetPlayerInventoryResult a1);
public delegate void EconomyDelegate8(PgosResult a0, GetPlayerInventoryWithFilterResult a1);
public delegate void EconomyDelegate9(PgosResult a0, SetInstanceCustomDataResult a1);
public delegate void EconomyDelegate10(PgosResult a0, BatchSetInstanceCustomDataResult a1);
public delegate void EconomyDelegate11(PgosResult a0, IncrInstanceCustomDataResult a1);
public delegate void EconomyDelegate12(PgosResult a0, SetInstanceTagsResult a1);
public delegate void EconomyDelegate13(PgosResult a0, BatchSetInstanceTagsResult a1);

Type Reference: