private void setItemView(EquipmentIcon iconItem, InventoryIconModel <DCustomEquipment> dataModel)
    {
        bool isPlayerMember = Service.Get <CPDataEntityCollection>().IsLocalPlayerMember() || !model.InventoryData.IsEquipmentMemberOnly(dataModel.Data);

        iconItem.SetupView(dataModel, isPlayerMember);
        itemImageBuilder.RequestImage(dataModel.Data, iconItem.SetIcon);
    }
    private bool onInventoryRetrieved(InventoryServiceEvents.InventoryLoaded evt)
    {
        Service.Get <EventDispatcher>().RemoveListener <InventoryServiceEvents.InventoryLoaded>(onInventoryRetrieved);
        DataEntityHandle localPlayerHandle = Service.Get <CPDataEntityCollection>().LocalPlayerHandle;

        if (!localPlayerHandle.IsNull)
        {
            InventoryData inventoryData = Service.Get <CPDataEntityCollection>().AddComponent <InventoryData>(localPlayerHandle);
            inventoryData.Inventory = new Dictionary <long, InventoryIconModel <DCustomEquipment> >();
            inventoryData.CurrentAvatarEquipment = new List <long>();
            for (int i = 0; i < evt.Inventory.Count; i++)
            {
                try
                {
                    DCustomEquipment data = CustomEquipmentResponseAdaptor.ConvertResponseToCustomEquipment(evt.Inventory[i]);
                    InventoryIconModel <DCustomEquipment> value = new InventoryIconModel <DCustomEquipment>(data.Id, data, isEquipped: false, isMemberItem: true);
                    inventoryData.Inventory.Add(data.Id, value);
                }
                catch (KeyNotFoundException)
                {
                }
            }
        }
        else
        {
            Log.LogError(this, "Unable to find the LocalPlayerHandle.");
        }
        if (callback != null)
        {
            callback();
            callback = null;
        }
        return(false);
    }
        private bool onPurchaseComplete(CatalogServiceEvents.ItemPurchaseCompleteEvent e)
        {
            int coins = Service.Get <CPDataEntityCollection>().GetComponent <CoinsData>(Service.Get <CPDataEntityCollection>().LocalPlayerHandle).Coins;

            if (e.Response.newCoinTotal < coins)
            {
                coins -= (int)e.Response.newCoinTotal;
                Service.Get <CPDataEntityCollection>().GetComponent <CoinsData>(Service.Get <CPDataEntityCollection>().LocalPlayerHandle).RemoveCoins(coins);
            }
            if (selectedItem.clothingCatalogItemId == purchaseItem.clothingCatalogItemId && buyPanel != null)
            {
                buyPanel.SetState(CatalogShopBuyPanelState.Success);
            }
            if (itemForPurchase.HasValue)
            {
                DCustomEquipment data = CustomEquipmentResponseAdaptor.ConvertResponseToCustomEquipment(itemForPurchase.Value);
                data.Id = e.Response.equipmentId;
                data.DateTimeCreated = DateTime.UtcNow.GetTimeInMilliseconds();
                DataEntityHandle localPlayerHandle = Service.Get <CPDataEntityCollection>().LocalPlayerHandle;
                InventoryData    component         = Service.Get <CPDataEntityCollection>().GetComponent <InventoryData>(localPlayerHandle);
                if (component != null)
                {
                    InventoryIconModel <DCustomEquipment> value = new InventoryIconModel <DCustomEquipment>(data.Id, data, isEquipped: false, isMemberItem: true);
                    component.Inventory.Add(data.Id, value);
                    Service.Get <NotificationBreadcrumbController>().AddPersistentBreadcrumb(BreadcrumbType, data.Id.ToString());
                }
                else
                {
                    Log.LogError(this, "Unable to locate InventoryData object.");
                }
            }
            Service.Get <CatalogServiceProxy>().cache.ClearCache();
            return(false);
        }
示例#4
0
 public void SetupView(InventoryIconModel <DCustomEquipment> iconData, bool isPlayerMember)
 {
     IconData = iconData;
     if (!isPlayerMember)
     {
         setMemberViews(canEquip: false);
     }
     else
     {
         setMemberViews(canEquip: true);
     }
 }
 public void SetupView(InventoryIconModel <DCustomEquipment> iconData, bool isPlayerMember)
 {
     IconData    = iconData;
     EquipmentId = IconData.Id;
     activateSelected(iconData.IsEquipped);
     if (!isPlayerMember)
     {
         setMemberViews(canEquip: false);
     }
     else
     {
         setMemberViews(canEquip: true);
     }
     setBreadcrumbId();
 }
 public static bool IsCustomEquipmentOwned(CustomEquipment equipment)
 {
     if (Service.Get <CPDataEntityCollection>().TryGetComponent(Service.Get <CPDataEntityCollection>().LocalPlayerHandle, out InventoryData component) && component.Inventory != null)
     {
         Dictionary <long, InventoryIconModel <DCustomEquipment> > .Enumerator enumerator = component.Inventory.GetEnumerator();
         while (enumerator.MoveNext())
         {
             InventoryIconModel <DCustomEquipment> value = enumerator.Current.Value;
             if (IsEquipmentEqual(value.Data, equipment))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
    private bool onItemReady(EditableItemEvents.ItemReady evt)
    {
        int           index = evt.Index;
        EditableItem  item  = evt.Item;
        EquipmentIcon componentInChildren = item.GetComponentInChildren <EquipmentIcon>();

        switch (index)
        {
        case 0:
            item.ShowActionButton = false;
            componentInChildren.SetupCreateButton();
            break;

        case 1:
            item.ShowActionButton = false;
            componentInChildren.SetupCatalogButton();
            break;

        default:
        {
            componentInChildren.SetupEquipmentButton();
            long key = model.DisplayedInventory[index - 2];
            InventoryIconModel <DCustomEquipment> inventoryIconModel = model.InventoryData.Inventory[key];
            item.ShowActionButton = true;
            item.Action           = EditableItem.ActionType.Delete;
            if (templateDefinitions.TryGetValue(inventoryIconModel.Data.DefinitionId, out TemplateDefinition value) && !value.IsEditable)
            {
                if (inventoryIconModel.IsHidden)
                {
                    item.Action = EditableItem.ActionType.Hide;
                }
                else
                {
                    item.Action = EditableItem.ActionType.Show;
                }
            }
            AccessibilitySettings component = componentInChildren.GetComponent <AccessibilitySettings>();
            if (component != null)
            {
                component.CustomToken = value.Name;
            }
            setItemView(componentInChildren, inventoryIconModel);
            break;
        }
        }
        return(false);
    }
示例#8
0
        public static DCustomEquipment?GetEquipmentFromDreward(DReward reward)
        {
            InventoryData component = Service.Get <CPDataEntityCollection>().GetComponent <InventoryData>(Service.Get <CPDataEntityCollection>().LocalPlayerHandle);

            if (component != null && component.Inventory != null)
            {
                Dictionary <long, InventoryIconModel <DCustomEquipment> > .Enumerator enumerator = component.Inventory.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    InventoryIconModel <DCustomEquipment> value = enumerator.Current.Value;
                    if (InventoryUtils.IsEquipmentEqual(value.Data, reward.EquipmentRequest))
                    {
                        return(value.Data);
                    }
                }
            }
            return(null);
        }
    private bool onInventoryRetrieved(InventoryServiceEvents.InventoryLoaded evt)
    {
        Service.Get <EventDispatcher>().RemoveListener <InventoryServiceEvents.InventoryLoaded>(onInventoryRetrieved);
        DataEntityHandle localPlayerHandle = Service.Get <CPDataEntityCollection>().LocalPlayerHandle;

        if (!localPlayerHandle.IsNull)
        {
            inventoryData           = Service.Get <CPDataEntityCollection>().AddComponent <InventoryData>(localPlayerHandle);
            inventoryData.Inventory = new Dictionary <long, InventoryIconModel <DCustomEquipment> >();
            inventoryData.CurrentAvatarEquipment = new List <long>();
            setTemplateData();
            for (int i = 0; i < evt.Inventory.Count; i++)
            {
                try
                {
                    DCustomEquipment data = CustomEquipmentResponseAdaptor.ConvertResponseToCustomEquipment(evt.Inventory[i]);
                    InventoryIconModel <DCustomEquipment> value = new InventoryIconModel <DCustomEquipment>(data.Id, data, isEquipped: false, isMemberItem: true);
                    inventoryData.Inventory.Add(data.Id, value);
                }
                catch (KeyNotFoundException)
                {
                }
            }
            if (Service.Get <CPDataEntityCollection>().TryGetComponent(localPlayerHandle, out AvatarDetailsData component) && component.Outfit != null)
            {
                DCustomOutfit currentAvatarEquipment = default(DCustomOutfit);
                currentAvatarEquipment.Equipment = component.Outfit;
                setCurrentAvatarEquipment(currentAvatarEquipment);
            }
        }
        else
        {
            Log.LogError(this, "Unable to find the LocalPlayerHandle.");
        }
        setDefaultScreen();
        string key = SceneTransitionService.SceneArgs.ShowCatalogOnEntry.ToString();

        if (Service.Get <SceneTransitionService>().HasSceneArg(key) && (bool)Service.Get <SceneTransitionService>().GetSceneArg(key))
        {
            showCatalog();
        }
        return(false);
    }
        private bool onEquipmentCreated(InventoryServiceEvents.EquipmentCreated evt)
        {
            serviceEventChannel.RemoveListener <InventoryServiceEvents.EquipmentCreated>(onEquipmentCreated);
            serviceEventChannel.RemoveListener <InventoryServiceErrors.EquipmentCreationError>(onEquipmentCreationError);
            long             equipmentId          = evt.EquipmentId;
            DCustomEquipment customEquipmentModel = itemModel.CustomEquipmentModel;

            customEquipmentModel.Id = equipmentId;
            customEquipmentModel.DateTimeCreated = DateTime.UtcNow.GetTimeInMilliseconds();
            InventoryData component = Service.Get <CPDataEntityCollection>().GetComponent <InventoryData>(Service.Get <CPDataEntityCollection>().LocalPlayerHandle);

            if (component != null)
            {
                InventoryIconModel <DCustomEquipment> value = new InventoryIconModel <DCustomEquipment>(equipmentId, customEquipmentModel, isEquipped: false, isMemberItem: true);
                component.Inventory.Add(equipmentId, value);
            }
            else
            {
                Log.LogError(this, "Unable to locate InventoryData object.");
            }
            Service.Get <NotificationBreadcrumbController>().AddPersistentBreadcrumb(BreadcrumbType, equipmentId.ToString());
            CustomizationContext.EventBus.DispatchEvent(default(CustomizerUIEvents.SaveClothingItemSuccess));
            return(false);
        }