public override void OnEnter() { var itemRequest = new ItemPurchaseRequest() { ItemId = itemId.Value, Quantity = (uint)quantity.Value }; var items = new List <ItemPurchaseRequest>(); items.Add(itemRequest); var purchaseRequest = new StartPurchaseRequest() { Items = items }; if (!catalogVersion.IsNone) { purchaseRequest.CatalogVersion = catalogVersion.Value; } if (!storeId.IsNone) { purchaseRequest.StoreId = storeId.Value; } PlayFabClientAPI.StartPurchase(purchaseRequest, OnSucces, OnFailure); }
private bool VerifyTransaction(NetConnection <NetSession> sender, ItemPurchaseRequest request) { if (!DataManager.Instance.ShopItems.ContainsKey(request.shopID)) { return(false); } if (!DataManager.Instance.ShopItems[request.shopID].ContainsKey(request.shopItemID)) { return(false); } ShopItemDefine define = DataManager.Instance.ShopItems[request.shopID][request.shopItemID]; if (define == null) { return(false); } if (!sender.Session.Character.ChangeGold(-define.Price)) { return(false); } return(true); }
public bool BuyItem(NetConnection <NetSession> sender, ItemPurchaseRequest request) { if (VerifyTransaction(sender, request)) { ShopItemDefine define = DataManager.Instance.ShopItems[request.shopID][request.shopItemID]; sender.Session.Character.ItemManager.AddItem(define.ItemID, request.Amount); //additem notify NStatus status = new NStatus(); status.Type = StatusType.Item; status.Action = StatusAction.Add; status.Id = define.ItemID; status.Value = request.Amount; Console.WriteLine("purchase one unit of " + define.ItemID); if (sender.Session.Response.Notifies == null) { sender.Session.Response.Notifies = new StatusNotify(); } sender.Session.Response.Notifies.Status.Add(status); //deduct money notify status = new NStatus(); status.Type = StatusType.Money; status.Action = StatusAction.Remove; status.Id = -1; status.Value = define.Price; sender.Session.Response.Notifies.Status.Add(status); return(true); } return(false); }
public void OnItemPurchase(NetConnection <NetSession> sender, ItemPurchaseRequest request) { sender.Session.Response.itemPurchase = new ItemPurchaseResponse(); if (ShopManager.Instance.BuyItem(sender, request)) { sender.Session.Response.itemPurchase.Result = Result.Success; } else { sender.Session.Response.itemPurchase.Result = Result.Failed; sender.Session.Response.itemPurchase.Errormsg = "You do not have enough gold!"; } sender.SendResponse(); }
//########################################################################################################### // Start Purchase //########################################################################################################### public void onStartPurchase(string itemID, uint quantity, string annotation) { ItemPurchaseRequest itemToPurchase = new ItemPurchaseRequest(); itemToPurchase.ItemId = itemID; itemToPurchase.Quantity = quantity; itemToPurchase.Annotation = annotation; StartPurchaseRequest startRequest = new StartPurchaseRequest(); startRequest.CatalogVersion = CatalogueVersion; startRequest.Items = new List <ItemPurchaseRequest> (); startRequest.Items.Add(itemToPurchase); Debug.Log("onStartPurchase"); PlayFabClientAPI.StartPurchase(startRequest, onStartPurchaseResult, onStartPurchaseError); }
public ItemPurchaseOperation(long clothingCatalogItemId) { PurchaseRequest = default(ItemPurchaseRequest); PurchaseRequest.clothingCatalogItemId = clothingCatalogItemId; }