Skip to content

Commit 8d159a7

Browse files
Mikkel Sørensenkirre-bylund
authored andcommitted
Add granting and deletion of Assets through Game API
1 parent 51356cb commit 8d159a7

File tree

4 files changed

+92
-3
lines changed

4 files changed

+92
-3
lines changed

Runtime/Client/LootLockerEndPoints.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ public class LootLockerEndPoints
135135
public static EndPointClass listingFavouriteAssets = new EndPointClass("v1/asset/favourites", LootLockerHTTPMethod.GET);
136136
public static EndPointClass addingFavouriteAssets = new EndPointClass("v1/asset/{0}/favourite", LootLockerHTTPMethod.POST);
137137
public static EndPointClass removingFavouriteAssets = new EndPointClass("v1/asset/{0}/favourite", LootLockerHTTPMethod.DELETE);
138-
138+
public static EndPointClass grantAssetToPlayerInventory = new EndPointClass("player/inventory/grant", LootLockerHTTPMethod.POST);
139+
139140
// Asset storage
140141
[Header("Asset Instances")]
141142
public static EndPointClass getAllKeyValuePairs = new EndPointClass("v1/asset/instance/storage", LootLockerHTTPMethod.GET);
@@ -147,7 +148,8 @@ public class LootLockerEndPoints
147148
public static EndPointClass deleteKeyValuePair = new EndPointClass("v1/asset/instance/{0}/storage/{1}", LootLockerHTTPMethod.DELETE);
148149
public static EndPointClass inspectALootBox = new EndPointClass("v1/asset/instance/{0}/inspect", LootLockerHTTPMethod.GET);
149150
public static EndPointClass openALootBox = new EndPointClass("v1/asset/instance/{0}/open", LootLockerHTTPMethod.PUT);
150-
151+
public static EndPointClass deleteAssetInstanceFromPlayerInventory = new EndPointClass("player/inventory/{0}", LootLockerHTTPMethod.DELETE);
152+
151153
// Asset instance progressions
152154
[Header("Asset instance progressions")]
153155
public static EndPointClass getAllAssetInstanceProgressions = new EndPointClass("player/assets/instances/{0}/progressions", LootLockerHTTPMethod.GET);

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3304,6 +3304,38 @@ public static void GetAssetsById(string[] assetIdsToRetrieve, Action<LootLockerA
33043304
LootLockerAPIManager.GetAssetsById(data, onComplete);
33053305
}
33063306

3307+
/// <summary>
3308+
/// Grant an Asset Instance to the Player's Inventory.
3309+
/// </summary>
3310+
/// <param name="assetID">The Asset you want to create an Instance of and give to the current player</param>
3311+
public static void GrantAssetToPlayerInventory(int assetID, Action<LootLockerGrantAssetResponse> onComplete)
3312+
{
3313+
GrantAssetToPlayerInventory(assetID, null, null, onComplete);
3314+
}
3315+
3316+
/// <summary>
3317+
/// Grant an Asset Instance to the Player's Inventory.
3318+
/// </summary>
3319+
/// <param name="assetID">The Asset you want to create an Instance of and give to the current player</param>
3320+
/// <param name="assetVariationID">The id of the Asset Variation you want to grant</param>
3321+
/// <param name="assetRentalOptionID">the rental option id you want to give the Asset Instance</param>
3322+
/// <param name="onComplete">onComplete Action for handling the response of type LootLockerGrantAssetResponse</param>
3323+
public static void GrantAssetToPlayerInventory(int assetID, int? assetVariationID, int? assetRentalOptionID, Action<LootLockerGrantAssetResponse> onComplete)
3324+
{
3325+
if (!CheckInitialized())
3326+
{
3327+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerGrantAssetResponse>());
3328+
return;
3329+
}
3330+
3331+
LootLockerGrantAssetRequest data = new LootLockerGrantAssetRequest();
3332+
data.asset_id = assetID;
3333+
data.asset_variation_id = assetVariationID;
3334+
data.asset_rental_option_id = assetRentalOptionID;
3335+
3336+
LootLockerAPIManager.GrantAssetToPlayerInventory(data, onComplete);
3337+
}
3338+
33073339
#endregion
33083340

33093341
#region AssetInstance
@@ -3524,6 +3556,24 @@ public static void OpenALootBoxForAssetInstances(int assetInstanceID, Action<Loo
35243556
data.getRequests.Add(assetInstanceID.ToString());
35253557
LootLockerAPIManager.OpenALootBox(data, onComplete);
35263558
}
3559+
3560+
/// <summary>
3561+
/// Delete an Asset Instance from the current Player's Inventory.
3562+
/// </summary>
3563+
/// <param name="assetInstanceID">The asset instance ID of the you want to delete from the Players Inventory</param>
3564+
/// <param name="onComplete">onComplete Action for handling the response of type LootLockerResponse</param>
3565+
public static void DeleteAssetInstanceFromPlayerInventory(int assetInstanceID, Action<LootLockerResponse> onComplete)
3566+
{
3567+
if (!CheckInitialized())
3568+
{
3569+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerResponse>());
3570+
return;
3571+
}
3572+
3573+
LootLockerGetRequest data = new LootLockerGetRequest();
3574+
data.getRequests.Add(assetInstanceID.ToString());
3575+
LootLockerAPIManager.DeleteAssetInstanceFromPlayerInventory(data, onComplete);
3576+
}
35273577
#endregion
35283578

35293579
#region AssetInstance progressions
@@ -4761,7 +4811,6 @@ public static void PickDropsFromDropTable(int[] picks, int tableInstanceId, Acti
47614811
LootLockerAPIManager.PickDropsFromDropTable(data, tableInstanceId, onComplete);
47624812
}
47634813

4764-
47654814
#region Reports
47664815

47674816
/// <summary>

Runtime/Game/Requests/AssetInstanceRequest.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,5 +181,15 @@ public static void OpenALootBox(LootLockerGetRequest data, Action<LootLockerOpen
181181

182182
LootLockerServerRequest.CallAPI(getVariable, endPoint.httpMethod, null, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
183183
}
184+
185+
public static void DeleteAssetInstanceFromPlayerInventory(LootLockerGetRequest data, Action<LootLockerResponse> onComplete)
186+
{
187+
EndPointClass endPoint = LootLockerEndPoints.deleteAssetInstanceFromPlayerInventory;
188+
189+
string getVariable = string.Format(endPoint.endPoint, data.getRequests[0]);
190+
191+
LootLockerServerRequest.CallAPI(getVariable, endPoint.httpMethod, null, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
192+
}
193+
184194
}
185195
}

Runtime/Game/Requests/AssetRequest.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ public static void ResetAssetCalls()
6868
}
6969
}
7070

71+
public class LootLockerGrantAssetRequest
72+
{
73+
public int asset_id { get; set; }
74+
public int? asset_variation_id { get; set; }
75+
public int? asset_rental_option_id { get; set; }
76+
}
77+
7178
public class LootLockerAssetResponse : LootLockerResponse
7279
{
7380
public LootLockerCommonAsset[] assets { get; set; }
@@ -187,6 +194,17 @@ public class LootLockerActivateRentalAssetResponse : LootLockerResponse
187194
{
188195
public int time_left { get; set; }
189196
}
197+
198+
public class LootLockerGrantAssetResponse : LootLockerResponse
199+
{
200+
public int id { get; set; }
201+
public int asset_id { get; set; }
202+
public int asset_variation_id { get; set; }
203+
public int asset_rental_option_id { get; set; }
204+
public string asset_ulid { get; set; }
205+
public string acquisition_source { get; set; }
206+
public string acquisition_date { get; set; }
207+
}
190208
}
191209

192210
namespace LootLocker
@@ -368,5 +386,15 @@ public static void RemoveFavouriteAsset(LootLockerGetRequest data, Action<LootLo
368386

369387
LootLockerServerRequest.CallAPI(getVariable, endPoint.httpMethod, "", onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
370388
}
389+
390+
public static void GrantAssetToPlayerInventory(LootLockerGrantAssetRequest data, Action<LootLockerGrantAssetResponse> onComplete)
391+
{
392+
EndPointClass endPoint = LootLockerEndPoints.grantAssetToPlayerInventory;
393+
394+
string json = LootLockerJson.SerializeObject(data);
395+
396+
LootLockerServerRequest.CallAPI(endPoint.endPoint, endPoint.httpMethod, json, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
397+
}
398+
371399
}
372400
}

0 commit comments

Comments
 (0)