public PropertyChar AddItem(SerializablePropertys propertys, string slug)
    {
        var v_slug = propertys.PropertyBySlug(slug);

        if (v_slug == null)
        {
            InputFieldHelper.Instance.ShowNoti(string.Format("Item {0} not found (check propertys list)", slug));
            return(null);
        }
        ShouldUpdateGUIContent = true;
        countNewItem++;
        if (v_slug.StackInBag)
        {
            for (int i = 0; i < PropertysChar.Count; i++)
            {
                var p = PropertysChar[i];
                if (p.Slug == slug)
                {
                    p.Count = p.Count + 1;
                    return(p);
                }
            }
        }
        var p_new = PropertyChar.CreateFromSlug(v_slug, slug);

        PropertysChar.Add(p_new);
        return(p_new);
    }
Beispiel #2
0
    private void _importAllFromResource(SerializablePropertys property)
    {
        // Pet
        var petlist = PetsDatabase.Instance.PetList;

        foreach (var pets in petlist)
        {
            var topic = pets.topic;
            var d     = pets.data;
            foreach (var s in d)
            {
                string key = "pet/" + s;
                var    p   = property.PropertyBySlug(key);
                if (p == null)
                {
                    p = property.Add(key);
                }
                p._Type = SerializablePropertys.EType.Pet;
                p.Name  = UtilsAON.NameFormat(s);
                if (string.IsNullOrEmpty(p.Des))
                {
                    p.Des = UtilsAON.DesFormat(s);
                }
                p.RefSlug = topic + "/" + s;
            }
        }
        // Outfit
        // string[] str = AutoTileMap_Editor.Instance.ItemCharData.StrItemList;
        Item[] item = AutoTileMap_Editor.Instance.ItemCharData.ItemList;
        foreach (var i in item)
        {
            string s   = i.SlugGlobal;
            string key = "outfit/" + s;
            var    p   = property.PropertyBySlug(key);
            if (p == null)
            {
                p = property.Add(key);
            }
            p._Type = SerializablePropertys.EType.Outfit;
            p.Name  = UtilsAON.NameFormat(i.Slug);
            if (string.IsNullOrEmpty(p.Des))
            {
                p.Des = UtilsAON.DesFormat(i.Slug);
            }
            p.RefSlug = s;
        }
    }
Beispiel #3
0
    private void SetSelectItem(int ixdex)
    {
        m_indextItemSeleted = ixdex;
        _controlShop.ResetSelectItem();
        if (ixdex == -1)
        {
            _controlShop.SetItemName("No item selected");
            return;
        }
        Debug.Log("SetSelectItem " + ixdex);
        var slug     = m_package.data[ixdex].property;
        var payBy    = m_package.data[ixdex].payBy;
        var property = m_dataRaw.PropertyBySlug(slug);

        if (property == null)
        {
            InputFieldHelper.Instance.ShowNoti("Item not found in database");
            return;
        }
        _controlShop.SetItemName(NameOf(property, slug));
        _controlShop.SetItemDes(property.Des);
        if (property.IsOutfit)
        {
            if (string.IsNullOrEmpty(property.RefSlug))
            {
                InputFieldHelper.Instance.ShowNoti("Item model is null");
                return;
            }
            var tryItem = AutoTileMap_Editor.Instance.ItemCharData.FetchItemByGlobalSlug(property.RefSlug);
            if (tryItem == null)
            {
                InputFieldHelper.Instance.ShowNoti("Item model not found in database");
                return;
            }
            _controlShop.LoadModelItem(tryItem.ItemPrefab);
            var charGame = AutoTileMap_Editor.Instance.Agent.GetComponentInChildren <CharGame>();
            if (tryItem.SlugChar != charGame.SlugChar)
            {
                _controlShop.SetItemDes("Your character can't use this item.");
                return;
            }
            if (PropertysGame.Instance.IsHaveItem(slug))
            {
                _controlShop.SetItemDes("You already own this item.");
                return;
            }
            Item rawItem = charGame.GetCurrentItem(tryItem.ItemType);
            if (rawItem != null && tryItem.SlugGlobal == rawItem.SlugGlobal)
            {
                if (m_itemTryOn != null && rawItem.SlugGlobal == m_itemTryOn.SlugGlobal)
                {
                    _controlShop.SetItemDes("Costumes is trying");
                    _controlShop.AddAction("UnTry", () =>
                    {
                        UnTryCostume(charGame);
                        RefreshDataSelect();
                    });
                }
                else
                {
                    _controlShop.SetItemDes("Costumes are in use");
                }
            }
            else
            {
                _controlShop.AddAction("Try on", () =>
                {
                    _tryOnItem(charGame, rawItem, tryItem, slug, property, payBy);
                });
            }
            _controlShop.AddAction("Buy", () =>
            {
                _onBuy(slug, property, payBy);
            });
        }
        else if (property.IsCertificates)
        {
            if (PropertysGame.Instance.IsHaveItem(slug))
            {
                _controlShop.SetItemDes("You already own this item.");
                return;
            }
            _controlShop.AddAction("Buy", () =>
            {
                Debug.Log("Buy");
                _onBuy(slug, property, payBy);
            });
        }
        else if (property.IsPet)
        {
            if (string.IsNullOrEmpty(property.RefSlug))
            {
                InputFieldHelper.Instance.ShowNoti("Item model is null");
                return;
            }
            if (PropertysGame.Instance.IsHaveItem(slug))
            {
                _controlShop.SetItemDes("You already own this item.");
                return;
            }
            _controlShop.LoadModelItem("pets/" + property.RefSlug);

            _controlShop.AddAction("Buy", () =>
            {
                _onBuy(slug, property, payBy);
            });
        }
        else
        {
            _controlShop.AddAction("Buy", () =>
            {
                _onBuy(slug, property, payBy);
            });
        }
        if (_controlShop.IsLoadModel())
        {
            _controlShop.LoadImageItem(null);
        }
        else
        {
            _controlShop.LoadImageItem(property.RefIcon);
        }
    }
Beispiel #4
0
    public void ShowWithData(SerializablePropertys dataRaw, SerializablePackages.Package package, CallBackClose onCloseShop, CallBackBuy onBuy)
    {
        // ShowWithDataOnGUi(dataRaw, package, onCloseShop);
        // Repair data
        // mOnCloseShop = onCloseShop;
        mOnBuy              = onBuy;
        m_dataRaw           = dataRaw;
        m_package           = package;
        m_indextItemSeleted = 0;
        var propertys = m_package.data;

        string[] m_s_Left  = new string[propertys.Count];
        string[] m_s_Right = new string[propertys.Count];
        for (int i = 0; i < propertys.Count; i++)
        {
            var slug = propertys[i].property;
            if (string.IsNullOrEmpty(slug))
            {
                m_s_Left[i] = "Item is empty";
            }
            else
            {
                var propertyData = m_dataRaw.PropertyBySlug(slug);
                m_s_Left[i] = NameOf(propertyData, slug);
            }
            var payBy = m_package.data[i].payBy;
            if (payBy == null)
            {
                m_s_Right[i] = "NULL";
            }
            else
            {
                m_s_Right[i] = payBy.coin.ToString() + " " + DefineAON.CoinName;
            }
        }
        // UI
        _controlShop_Dispose();
        if (_controlShop == null)
        {
            _controlShop = new ControlShop();
            _controlShop._btClose.onClick.Add(() =>
            {
                // _controlShop.Hide();
                _controlShop_Dispose();
                UnTryCostume(null);
                if (onCloseShop != null)
                {
                    var callback = onCloseShop;
                    onCloseShop  = null;
                    callback();
                }
            });
        }
        else
        {
            _controlShop.ResetListItem();
        }
        _controlShop.SetTitle(m_package.Name);
        for (int i = 0; i < m_s_Left.Length; i++)
        {
            int ii = i;
            var bt = _controlShop.AddItem(m_s_Left[i], m_s_Right[i], () =>
            {
                SetSelectItem(ii);
            });
        }
        m_indextItemSeleted = -1;
        RefreshDataSelect();
        _controlShop.ShowOn(InputFieldHelper.Instance.PopUp);
    }