Exemple #1
0
        private void ApplyBuyItemCommand(MarketItemModel model)
        {
            var apiCommand = Strategy.GetBuyItemCommand(model);

            apiCommand.CommandFinished += OnCommandFinished;
            SendApiCommand(apiCommand);
        }
        protected override void OnItemClicked(ItemActionType actionType, MarketItemModel itemModel)
        {
            base.OnItemClicked(actionType, itemModel);

            switch (actionType)
            {
            case ItemActionType.Select:
                OnItemSelected(itemModel);
                break;

            case ItemActionType.SendToDmarket:
                ApplyChangeItemInventoryCommand(itemModel, MarketMoveItemType.ToMarket);
                break;

            case ItemActionType.SendToGameInventory:
                ApplyChangeItemInventoryCommand(itemModel, MarketMoveItemType.FromMarket);
                break;

            case ItemActionType.CancelSellOffer:
                ApplyCancelSellOfferCommand(itemModel);
                break;

            case ItemActionType.EditSellOffer:
                OnEditSellOffer(itemModel);
                break;
            }
        }
Exemple #3
0
        public override void Start()
        {
            base.Start();
            var targetGameItems = GetTargetGameItems();

            var startIndex = _loadParameters.Offset;
            var endIndex   = Mathf.Min(_loadParameters.Offset + _loadParameters.Limit, GameModel.Items.Count);

            var items = new List <MarketItemModel>();

            for (int i = startIndex; i < endIndex && i < targetGameItems.Count; i++)
            {
                var itemInfo = targetGameItems[i];

                var itemModel = new MarketItemModel
                {
                    Tittle     = itemInfo.Title,
                    ClassId    = itemInfo.ClassId,
                    AssetId    = itemInfo.AssetId,
                    IconSprite = itemInfo.Sprite
                };

                items.Add(itemModel);
            }

            CommandResult = new LoadMarketItemsCommandResult(items, targetGameItems.Count);
            Terminate();
        }
        private void ApplyCancelSellOfferCommand(MarketItemModel model)
        {
            var cancelOfferCommand = Strategy.GetCancelSellOfferCommand(model);

            cancelOfferCommand.CommandFinished += OnCancelSellOfferFinished;
            SendApiCommand(cancelOfferCommand, false);
        }
 protected override void OnItemClicked(ItemActionType actionType, MarketItemModel model)
 {
     if (actionType == ItemActionType.CreateSellOffer)
     {
         if (WidgetModel.CurrentItemType == ItemModelType.GameInventory)
         {
             MoveToMarketAndSell();
         }
         else
         {
             ApplyCreateSellOfferCommand(model);
         }
     }
     else if (actionType == ItemActionType.EditSellOffer)
     {
         if (WidgetModel.CurrentItemType == ItemModelType.MySellOffers)
         {
             ApplyEditSellOfferCommand(model);
         }
     }
     else
     {
         base.OnItemClicked(actionType, model);
     }
 }
        private void ApplyCreateSellOfferCommand(MarketItemModel model)
        {
            var apiCommand = Strategy.GetCreateSellOfferCommand(model);

            apiCommand.CommandFinished += OnSellItemFinished;
            SendApiCommand(apiCommand);
        }
        protected virtual List <MarketItemModel> CreateItems()
        {
            var result = new List <MarketItemModel>();

            for (int i = 0; i < _loadParameters.Limit; i++)
            {
                var categoryType      = Random.value > 0.5f ? GameItemCategory.Skin : GameItemCategory.Helmet;
                var randomItem        = GameItemTypeExtensions.GetRandomItem(categoryType);
                int randomStatusIndex = Random.Range(0, _offerStatuses.Length);

                var itemModel = new MarketItemModel
                {
                    Tittle      = randomItem.ToString(),
                    ImageUrl    = GetUrlForIcon(randomItem),
                    Created     = DateTime.Now.AddMinutes(Random.Range(0, 55)),
                    Updated     = DateTime.Now.AddMinutes(Random.Range(0, 55)),
                    Fee         = { Amount = Random.Range(10, 3000) },
                    Price       = { Amount = Random.Range(10, 3000) },
                    AssetId     = Random.Range(10000, 100000).ToString(),
                    ClassId     = randomItem.ToString(),
                    SellOfferId = Guid.NewGuid().ToString(),
                    IconSprite  = null,
                    OffersCount = Random.Range(2, 22),
                    Status      = _offerStatuses[randomStatusIndex]
                };
                result.Add(itemModel);
            }
            return(result);
        }
        private void OnSuccessCallback(GetUserSellOffersRequest.Response response, GetUserSellOffersRequest.RequestParams request)
        {
            var answer     = response;
            var modelsList = new List <MarketItemModel>();

            foreach (var itemInfo in answer.Items)
            {
                var itemModel = new MarketItemModel
                {
                    SellOfferId = itemInfo.sellOfferId,
                    Tittle      = itemInfo.title,
                    ImageUrl    = itemInfo.imageUrl,
                    Created     = IntToDateTime(itemInfo.created),
                    Fee         = itemInfo.fee,
                    Price       = itemInfo.price,
                    Status      = SellOfferStatusTypeExtentions.GetSellOfferStatusType(itemInfo.status)
                };
                itemModel.Fee.Currency = itemModel.Price.Currency; // TODO: workaround. wait backend.

                modelsList.Add(itemModel);
            }

            CommandResult = new LoadMarketItemsCommandResult(modelsList, answer.total);
            Terminate(true);
        }
Exemple #9
0
 private void SetSelectItem(MarketItemModel itemModel, bool isSelected)
 {
     if (itemModel != null)
     {
         itemModel.IsSelected = isSelected;
         itemModel.SetChanges();
     }
 }
        private void ApplyChangeItemInventoryCommand(MarketItemModel model, MarketMoveItemType marketMoveType)
        {
            FormModel.AddItemLock(model);
            FormModel.SetChanges();
            var apiCommand = Strategy.GetChangeItemInventoryCommand(model, marketMoveType);

            apiCommand.CommandFinished += OnChangeInventoryItemFinished;
            SendApiCommand(apiCommand, false);
        }
        protected string GetTargetString(ShowType showType, MarketItemModel model)
        {
            var result = string.Empty;

            switch (showType)
            {
            case ShowType.Tittle:
                result = model.Tittle;
                break;

            case ShowType.Description:
                result = model.Description;
                break;

            case ShowType.ClassId:
                result = model.ClassId;
                break;

            case ShowType.AssetId:
                result = model.AssetId;
                break;

            case ShowType.CreationDate:
                result = GetDateString(model.Created);
                break;

            case ShowType.LastUpdate:
                result = GetDateString(model.Updated);
                break;

            case ShowType.Price:
                result = model.Price.GetStringWithCurrencySprite(_text.color);
                break;

            case ShowType.Fee:
                result = model.Fee.GetStringWithCurrencySprite(_text.color);
                break;

            case ShowType.OrderStatus:
                result = model.Status.GetText();
                break;

            case ShowType.OffersCount:
                result = model.OffersCount.ToString();
                break;

            case ShowType.SellOfferId:
                result = model.SellOfferId;
                break;

            default:
                result = "NOT IMPLEMENT";
                DevLogger.Warning("Need implement for " + showType);
                break;
            }
            return(result);
        }
Exemple #12
0
 protected override void OnItemClicked(ItemActionType actionType, MarketItemModel model)
 {
     if (actionType == ItemActionType.Buy)
     {
         ApplyBuyItemCommand(model);
     }
     else
     {
         base.OnItemClicked(actionType, model);
     }
 }
 protected virtual void UpdateItemViewPanel(MarketItemModel item)
 {
     _itemViewPanel.ApplyModel(item);
     if (item != null)
     {
         _itemViewPanel.Show();
     }
     else
     {
         _itemViewPanel.Hide();
     }
 }
Exemple #14
0
 public void RemoveItemLock(MarketItemModel item)
 {
     if (item != null)
     {
         if (_lockedItems.Contains(item.AssetId))
         {
             _lockedItems.Remove(item.AssetId);
         }
         item.IsLockFromServer = false;
         item.SetChanges();
     }
 }
Exemple #15
0
 public void AddItemLock(MarketItemModel item)
 {
     if (item != null)
     {
         if (!_lockedItems.Contains(item.AssetId))
         {
             _lockedItems.Add(item.AssetId);
         }
         item.IsLockFromServer = true;
         item.SetChanges();
     }
 }
        private void ApplyCancelSellOfferCommand(MarketItemModel model)
        {
            Action <bool> approveCallback = isApproveCancel =>
            {
                if (isApproveCancel)
                {
                    var cancelOfferCommand = Strategy.GetCancelSellOfferCommand(model);
                    cancelOfferCommand.CommandFinished += OnCancelSellOfferFinished;
                    SendApiCommand(cancelOfferCommand, false);
                }
            };

            Controller.GetForm <ApproveForm>().ShowChoiceWindow("Are you sure?", approveCallback);
        }
Exemple #17
0
 public ChangeInventoryForItemCommand(MarketItemModel itemModel, MarketMoveItemType marketMoveType) : base(itemModel)
 {
     _request = new MarketMoveItemRequestParams
     {
         AssetIds = new List <string>()
         {
             TargetItemModel.AssetId
         },
         ClassIds = new List <string>()
         {
             TargetItemModel.ClassId
         },
         TransactionType = marketMoveType,
         Callback        = OnGameResponse
     };
 }
Exemple #18
0
        protected virtual void OnItemClicked(ItemActionType actionType, MarketItemModel itemModel)
        {
            switch (actionType)
            {
            case ItemActionType.SellOnDmarket:
                ApplySellItemState(itemModel);
                break;

            case ItemActionType.Buy:
                ApplyCheckoutItemState(itemModel);
                break;

            case ItemActionType.BuyItem:
                ApplyBuyItemState(itemModel);
                break;
            }
        }
        private void OnSuccessCallback(GetUserInventoryRequest.Response response, GetUserInventoryRequest.RequestParams request)
        {
            var items = new List <MarketItemModel>();

            for (int i = 0; i < response.Items.Count; i++)
            {
                var itemInfo  = response.Items[i];
                var itemModel = new MarketItemModel
                {
                    Tittle   = itemInfo.title,
                    ClassId  = itemInfo.classId,
                    AssetId  = itemInfo.assetId,
                    ImageUrl = itemInfo.imageUrl
                };
                items.Add(itemModel);
            }

            CommandResult = new LoadMarketItemsCommandResult(items, response.total);
            Terminate(true);
        }
Exemple #20
0
        public void SetItems(List <MarketItemModel> items)
        {
            var selectedAssetId = SelectedItem != null ? SelectedItem.AssetId : string.Empty;
            var maxCount        = Math.Max(MarketItems.Count, items.Count);

            for (var i = 0; i < maxCount; i++)
            {
                if (i >= items.Count)
                {
                    MarketItems.RemoveAt(MarketItems.Count - 1);
                    continue;
                }
                items[i].IsLockFromServer = _lockedItems.Contains(items[i].AssetId);
                if (i >= MarketItems.Count)
                {
                    MarketItems.Add(items[i]);
                }
                else
                {
                    MarketItems[i] = items[i];
                }
                items[i].SetChanges();
            }

            if (MarketItems.Count > 0)
            {
                var newSelectedItem = MarketItems.Find(item => item.AssetId.Equals(selectedAssetId));
                if (newSelectedItem == null)
                {
                    newSelectedItem = MarketItems[0];
                }

                SelectedItem = newSelectedItem;
            }
            else
            {
                SelectedItem = null;
            }
        }
        private void OnSuccessCallback(GetGameClassSellOffersRequest.Response response, GetGameClassSellOffersRequest.RequestParams request)
        {
            var items = new List <MarketItemModel>();

            foreach (var itemInfo in response.Items)
            {
                var itemModel = new MarketItemModel
                {
                    ClassId     = _loadParameters.ClassId,
                    SellOfferId = itemInfo.sellOfferId,
                    Tittle      = itemInfo.title,
                    ImageUrl    = itemInfo.imageUrl,
                    Created     = IntToDateTime(itemInfo.created),
                    Fee         = itemInfo.fee,
                    Price       = itemInfo.price
                };
                itemModel.Fee.Currency = itemModel.Price.Currency;               // TODO: workaround. wait backend.
                items.Add(itemModel);
            }

            CommandResult = new LoadMarketItemsCommandResult(items, response.total);
            Terminate(true);
        }
Exemple #22
0
        private void OnSuccessLoadItemsCallback(GetGameAggregatedClassesRequest.Response response, GetGameAggregatedClassesRequest.RequestParams request)
        {
            var items = new List <MarketItemModel>();

            foreach (var itemInfo in response.Items)
            {
                var itemModel = new MarketItemModel
                {
                    SellOfferId = itemInfo.cheapestOfferId,
                    Tittle      = itemInfo.title,
                    ImageUrl    = itemInfo.imageUrl,
                    Updated     = IntToDateTime(itemInfo.lastUpdate),
                    Price       = itemInfo.cheapestPrice,
                    OffersCount = itemInfo.offersCount,
                    ClassId     = itemInfo.classId,
                    Description = itemInfo.description
                };

                items.Add(itemModel);
            }

            CommandResult = new LoadMarketItemsCommandResult(items, response.total);
            Terminate(true);
        }
 private void OnItemClicked(ItemActionType actionType, MarketItemModel itemModel)
 {
     CallItemClicked(actionType, itemModel);
 }
Exemple #24
0
 protected void OnItemClicked(ItemActionType actionType, MarketItemModel model)
 {
     ItemClicked.SafeRaise(actionType, model);
 }
 private void OnItemSelected(MarketItemModel model)
 {
     FormModel.SelectedItem = model;
     FormModel.SetChanges();
 }
 private void OnEditSellOffer(MarketItemModel model)
 {
     ApplyState <MarketSellOfferState>(model, ItemActionType.EditSellOffer);
 }
Exemple #27
0
 public BuyItemCommand(MarketItemModel itemModel) : base(itemModel)
 {
 }
Exemple #28
0
 public MockupItemOperationCommand(MarketItemModel targetItemModel) : base(targetItemModel)
 {
 }
 protected override void UpdateItemViewPanel(MarketItemModel item)
 {
 }
Exemple #30
0
 ApiCommandBase IMarketStrategy.GetChangeItemInventoryCommand(MarketItemModel model, MarketMoveItemType marketMoveType)
 {
     return(new ChangeInventoryForItemCommand(model, marketMoveType));
 }