Exemple #1
0
 private void RetryWithRefreshToken(AppChangingItemsMessage message)
 {
     RefreshMarketToken(message.ConnectionId, () => OnItemChangingMsg(message),
                        error =>
     {
         var answer = new AppChangingItemsAnswerMessage(new ItemsChangingResponse(error));
         SendMessageToClient(answer, message.ConnectionId);
     });
 }
 private void OnItemOperationError(AppChangingItemsMessage message, Error error)
 {
     if (error.ErrorCode == ErrorCode.DMarketTokenExpired)
     {
         RetryWithRefreshToken(message);
     }
     else
     {
         SendErrorAnswer(message, error.ErrorCode);
     }
 }
 private void RetryWithRefreshToken(AppChangingItemsMessage message)
 {
     RefreshMarketToken(
         () => OnItemChangingMsg(message),
         error =>
     {
         var answer      = new AppChangingItemsAnswerMessage();
         answer.Response = new ItemsChangingResponse(false, error);
         SendAnswer(answer, message);
     });
 }
        private void OnAfterSuccesDMarketOperation(AppChangingItemsMessage message)
        {
            var playerInfo = GetPlayer(message.ConnectionId);

            Storage.Change(playerInfo);

            var answer = new AppChangingItemsAnswerMessage();

            answer.Response = new ItemsChangingResponse(true);
            SendAnswer(answer, message);
            SendDmarketDataUpdateAnswer(message);
        }
        private void OnItemDevTestAdd(AppChangingItemsMessage message)
        {
            var playerData = GetPlayer(message.ConnectionId);
            var itemType   = message.GetItemType(0);
            var newItem    = new PlayerItemInfo(itemType,
                                                Storage.GetUniqueWorldId());

            playerData.Inventory.Items.Add(newItem);
            Storage.Change(playerData);
            var answer = new AppChangingItemsAnswerMessage(new ItemsChangingResponse());

            SendMessageToClient(answer, message.ConnectionId);
        }
        private void OnItemChangingMsg(AppChangingItemsMessage message)
        {
            switch (message.ActionType)
            {
            case ItemActionType.FromMarket:
                OnItemFromMarketMsg(message);
                break;

            case ItemActionType.ToMarket:
                OnItemToMarketMsg(message);
                break;
            }
        }
Exemple #7
0
        private void OnItemSellMsg(AppChangingItemsMessage message)
        {
            var playerInfo = GetPlayer(message.ConnectionId);
            var itemType   = playerInfo.Inventory.GetItem(message.WorldId).ItemType;
            var price      = GetPrice(itemType);
            var answer     = new AppChangingItemsAnswerMessage();

            playerInfo.Inventory.Coins += price;
            playerInfo.Inventory.RemoveItem(message.WorldId);
            Storage.Change(playerInfo);
            answer.Response = new ItemsChangingResponse(true);
            SendAnswer(answer, message);
        }
        private void OnMarketItemAction(ItemChangingRequest request)
        {
            var message = new AppChangingItemsMessage
            {
                Params =
                {
                    ActionType = request.ActionType,
                    WorldIds   = request.WorldIds
                }
            };

            _waitingItemChangingCallback = request.Callback;
            Client.Send(message);
        }
 private void OnItemOperationError(AppChangingItemsMessage message, Error error)
 {
     if (error.ErrorCode == ErrorCode.DMarketTokenExpired)
     {
         RetryWithRefreshToken(message);
     }
     else
     {
         var answer       = new AppChangingItemsAnswerMessage();
         var errorMessage = GetErrorMessage(error);
         answer.Response = new ItemsChangingResponse(false, errorMessage);
         SendAnswer(answer, message);
     }
 }
Exemple #10
0
 private void Update()
 {
     if (_addButton)
     {
         _addButton = false;
         var appController = FindObjectOfType <AppController>();
         var message       = new AppChangingItemsMessage
         {
             ActionType = ItemActionType.DevTestAdd,
             ItemType   = _itemType
         };
         appController.Client.Send(message);
     }
 }
        private void OnItemChangingMsg(AppChangingItemsMessage message)
        {
            int connectionId = message.ConnectionId;

            if (message.ActionType != ItemActionType.ToMarket && message.ActionType != ItemActionType.FromMarket)
            {
                return;
            }

            if (!IsCanMakeDMarketOperation(message))
            {
                return;
            }

            var assetIds  = new List <string>();
            var itemsInfo = new Dictionary <string, ItemInfo>();

            for (var i = 0; i < message.ItemsCount; i++)
            {
                var assetId = DMarketConverter.GetAssetId(message.GetWorldId(i));
                assetIds.Add(assetId);
                itemsInfo.Add(assetId, new ItemInfo(message.GetWorldId(i), message.GetItemType(i)));
            }

            //TODO think about request generic...  now code is duplicated
            switch (message.ActionType)
            {
            case ItemActionType.ToMarket:
                var items = new AssetToMarketModel[assetIds.Count];
                for (var i = 0; i < items.Length; i++)
                {
                    var classId = DMarketConverter.GetClassId(message.GetItemType(i));
                    items[i] = new AssetToMarketModel {
                        assetId = assetIds[i],
                        classId = classId
                    };
                }
                DMarketApi.AsyncToMarket(Model.GetPlayerMarketAccessToken(connectionId), items,
                                         (response, request) => { AsyncMarketCallback(response.Items, message, itemsInfo); },
                                         error => { OnItemOperationError(message, error); });
                break;

            case ItemActionType.FromMarket:
                DMarketApi.AsyncFromMarket(Model.GetPlayerMarketAccessToken(connectionId), assetIds.ToArray(),
                                           (response, request) => { AsyncMarketCallback(response.Items, message, itemsInfo); },
                                           error => { OnItemOperationError(message, error); });
                break;
            }
        }
        private void OnItemEquipMsg(AppChangingItemsMessage message)
        {
            PlayerInfo playerInfo = GetPlayer(message.ConnectionId);

            for (var i = 0; i < message.ItemsCount; i++)
            {
                var worldId = message.GetWorldId(i);
                var item    = playerInfo.Inventory.GetItem(worldId);
                playerInfo.Inventory.EquipItem(item);
            }
            Storage.Change(playerInfo);
            var answer = new AppChangingItemsAnswerMessage(new ItemsChangingResponse());

            SendMessageToClient(answer, message.ConnectionId);
        }
Exemple #13
0
        private void OnItemEquipMsg(AppChangingItemsMessage message)
        {
            PlayerInfo     playerInfo = GetPlayer(message.ConnectionId);
            PlayerItemInfo item       = playerInfo.Inventory.GetItem(message.WorldId);

            playerInfo.Inventory.EquipItem(item);
            Storage.Change(playerInfo);

            var answer = new AppChangingItemsAnswerMessage
            {
                Response = new ItemsChangingResponse(true)
            };

            SendAnswer(answer, message);
        }
        private void OnItemSellMsg(AppChangingItemsMessage message)
        {
            var playerInfo = GetPlayer(message.ConnectionId);

            for (var i = 0; i < message.ItemsCount; i++)
            {
                var worldId  = message.GetWorldId(i);
                var itemType = playerInfo.Inventory.GetItem(worldId).ItemType;
                var price    = GetPrice(itemType);
                playerInfo.Inventory.Coins += price;
                playerInfo.Inventory.RemoveItem(worldId);
            }
            Storage.Change(playerInfo);
            var answer = new AppChangingItemsAnswerMessage(new ItemsChangingResponse());

            SendMessageToClient(answer, message.ConnectionId);
        }
        private void OnDMarketTransaction(AppDMarketTransactionMessage marketMessage)
        {
            var actionType = CovertMarketAction(marketMessage.TransactionData.TransactionType);
            var appMessage = new AppChangingItemsMessage(actionType)
            {
                ConnectionId = marketMessage.ConnectionId
            };

            for (var i = 0; i < marketMessage.TransactionData.AssetIds.Count; i++)
            {
                var assetId  = marketMessage.TransactionData.AssetIds[i];
                var classId  = marketMessage.TransactionData.ClassIds[i];
                var worldId  = DMarketConverter.GetWorldId(assetId);
                var itemType = DMarketConverter.GetItemType(classId);
                appMessage.AddItem(worldId, itemType);
            }

            OnItemChangingMsg(appMessage);
        }
Exemple #16
0
        private void OnItemChangingMsg(AppChangingItemsMessage message)
        {
            switch (message.ActionType)
            {
            case ItemActionType.Buy:
                OnItemBuyMsg(message);
                break;

            case ItemActionType.Sell:
                OnItemSellMsg(message);
                break;

            case ItemActionType.Equip:
                OnItemEquipMsg(message);
                break;

            case ItemActionType.DevTestAdd:
                OnItemDevTestAdd(message);
                break;
            }
        }
Exemple #17
0
 public MoveAssetTransactionInfo(AppChangingItemsMessage sender)
 {
     Sender      = sender;
     _operations = new Dictionary <string, ItemInfo>();
 }
        private void AsyncMarketCallback(List <AsyncMarketResponse.ItemsAsset> items, AppChangingItemsMessage message, Dictionary <string, ItemInfo> itemsInfo)
        {
            var targetTransaction = new MoveAssetTransactionInfo(message);

            _pendingTransactions.Add(targetTransaction);
            foreach (var item in items)
            {
                targetTransaction.AddOperation(item.OperationId, itemsInfo[item.AssetId]);
            }
        }
        private void SendErrorAnswer(AppChangingItemsMessage message, ErrorCode error)
        {
            var answer = new AppChangingItemsAnswerMessage(new ItemsChangingResponse(error));

            SendMessageToClient(answer, message.ConnectionId);
        }