Exemplo n.º 1
0
        public virtual void SetObjectData(Dictionary <string, object> data)
        {
            this.Stack = System.Convert.ToInt32(data["Stack"]);
            if (data.ContainsKey("RarityIndex"))
            {
                int rarityIndex = System.Convert.ToInt32(data["RarityIndex"]);
                if (rarityIndex > -1 && rarityIndex < InventoryManager.Database.raritys.Count)
                {
                    this.m_Rarity = InventoryManager.Database.raritys[rarityIndex];
                }
            }

            if (data.ContainsKey("Properties"))
            {
                List <object> objectProperties = data["Properties"] as List <object>;
                for (int i = 0; i < objectProperties.Count; i++)
                {
                    Dictionary <string, object> propertyData = objectProperties[i] as Dictionary <string, object>;
                    string         propertyName  = (string)propertyData["Name"];
                    object         propertyValue = propertyData["Value"];
                    ObjectProperty property      = FindProperty(propertyName);
                    if (property == null)
                    {
                        property      = new ObjectProperty();
                        property.Name = propertyName;
                        properties.Add(property);
                    }
                    property.SetValue(propertyValue);
                }
            }

            if (data.ContainsKey("Reference"))
            {
                List <object> references = data["Reference"] as List <object>;
                for (int i = 0; i < references.Count; i++)
                {
                    Dictionary <string, object> referenceData = references[i] as Dictionary <string, object>;
                    string        container          = (string)referenceData["Container"];
                    int           slot               = System.Convert.ToInt32(referenceData["Slot"]);
                    ItemContainer referenceContainer = WidgetUtility.Find <ItemContainer>(container);
                    if (referenceContainer != null)
                    {
                        referenceContainer.ReplaceItem(slot, this);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void SetObjectData(Dictionary <string, object> data)
        {
            this.Stack = System.Convert.ToInt32(data["Stack"]);
            if (data.ContainsKey("RarityIndex"))
            {
                int rarityIndex = System.Convert.ToInt32(data["RarityIndex"]);
                if (rarityIndex > -1 && rarityIndex < InventoryManager.Database.raritys.Count)
                {
                    this.m_Rarity = InventoryManager.Database.raritys[rarityIndex];
                }
            }

            foreach (ObjectProperty property in this.properties)
            {
                if (data.ContainsKey(property.Name))
                {
                    object obj = data[property.Name];
                    property.SetValue(obj);
                }
            }
            if (data.ContainsKey("Reference"))
            {
                List <object> references = data["Reference"] as List <object>;
                for (int i = 0; i < references.Count; i++)
                {
                    Dictionary <string, object> referenceData = references[i] as Dictionary <string, object>;
                    string        container          = (string)referenceData["Container"];
                    int           slot               = System.Convert.ToInt32(referenceData["Slot"]);
                    ItemContainer referenceContainer = WidgetUtility.Find <ItemContainer>(container);
                    if (referenceContainer != null)
                    {
                        referenceContainer.ReplaceItem(slot, this);
                    }
                }
            }
        }
Exemplo n.º 3
0
        protected virtual void OnEnable()
        {
            this.m_Script    = serializedObject.FindProperty("m_Script");
            this.m_From      = serializedObject.FindProperty("m_From");
            this.m_Filters   = serializedObject.FindProperty("m_Filters");
            this.m_MinStack  = serializedObject.FindProperty("m_MinStack");
            this.m_MaxStack  = serializedObject.FindProperty("m_MaxStack");
            this.m_MinAmount = serializedObject.FindProperty("m_MinAmount");
            this.m_MaxAmount = serializedObject.FindProperty("m_MaxAmount");
            this.m_Chance    = serializedObject.FindProperty("m_Chance");
            this.m_Modifiers = serializedObject.FindProperty("m_Modifiers");

            CreateModifierList("Modifiers", serializedObject, this.m_Modifiers);

            this.m_FilterList = new ReorderableList(serializedObject, this.m_Filters, true, true, true, true);
            this.m_FilterList.drawHeaderCallback = (Rect rect) => {
                EditorGUI.LabelField(rect, "Filters");
            };


            this.m_FilterList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => {
                SerializedProperty element = this.m_FilterList.serializedProperty.GetArrayElementAtIndex(index);
                rect.y     += 2;
                rect.height = EditorGUIUtility.singleLineHeight;
                EditorGUI.LabelField(rect, (element.objectReferenceValue as INameable).Name + " (" + element.objectReferenceValue.GetType().Name + ")");
            };


            this.m_FilterList.onRemoveCallback = (ReorderableList list) =>
            {
                list.serializedProperty.GetArrayElementAtIndex(list.index).objectReferenceValue = null;
                ReorderableList.defaultBehaviours.DoRemoveButton(list);
            };

            this.m_FilterList.onAddDropdownCallback = (Rect rect, ReorderableList list) => {
                GenericMenu menu  = new GenericMenu();
                string[]    guids = AssetDatabase.FindAssets("t:" + typeof(ItemDatabase).FullName);
                for (int i = 0; i < guids.Length; i++)
                {
                    string       path     = AssetDatabase.GUIDToAssetPath(guids[i]);
                    ItemDatabase database = AssetDatabase.LoadAssetAtPath(path, typeof(ItemDatabase)) as ItemDatabase;
                    for (int j = 0; j < database.categories.Count; j++)
                    {
                        Category category = database.categories[j];
                        menu.AddItem(new GUIContent(database.name + "/Category/" + database.categories[j].Name), false, () => {
                            serializedObject.Update();
                            this.m_Filters.InsertArrayElementAtIndex(this.m_Filters.arraySize);
                            SerializedProperty property   = this.m_Filters.GetArrayElementAtIndex(this.m_Filters.arraySize - 1);
                            property.objectReferenceValue = category;
                            serializedObject.ApplyModifiedProperties();
                        });
                    }
                    for (int j = 0; j < database.raritys.Count; j++)
                    {
                        Rarity rarity = database.raritys[j];
                        menu.AddItem(new GUIContent(database.name + "/Rarity/" + database.raritys[j].Name), false, () => {
                            serializedObject.Update();
                            this.m_Filters.InsertArrayElementAtIndex(this.m_Filters.arraySize);
                            SerializedProperty property   = this.m_Filters.GetArrayElementAtIndex(this.m_Filters.arraySize - 1);
                            property.objectReferenceValue = rarity;
                            serializedObject.ApplyModifiedProperties();
                        });
                    }
                }
                menu.DropDown(rect);
            };
        }
        protected virtual void OnEnable()
        {
            this.m_Script = serializedObject.FindProperty("m_Script");
            this.m_From = serializedObject.FindProperty("m_From");
            this.m_Filters = serializedObject.FindProperty("m_Filters");
            this.m_MinStack = serializedObject.FindProperty("m_MinStack");
            this.m_MaxStack = serializedObject.FindProperty("m_MaxStack");
            this.m_MinAmount = serializedObject.FindProperty("m_MinAmount");
            this.m_MaxAmount = serializedObject.FindProperty("m_MaxAmount");
            this.m_Chance = serializedObject.FindProperty("m_Chance");
            this.m_Modifiers = serializedObject.FindProperty("m_Modifiers");

            CreateModifierList("Modifiers", serializedObject, this.m_Modifiers);

            this.m_FilterList = new ReorderableList(serializedObject, this.m_Filters, true, true, true, true);
            this.m_FilterList.drawHeaderCallback = (Rect rect) => {
                EditorGUI.LabelField(rect, "Filters");
            };


            this.m_FilterList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => {
                SerializedProperty element = this.m_FilterList.serializedProperty.GetArrayElementAtIndex(index);
                rect.y += 2;
                rect.height = EditorGUIUtility.singleLineHeight;
                EditorGUI.LabelField(rect, (element.objectReferenceValue as INameable).Name+" ("+element.objectReferenceValue.GetType().Name+")");
            };

  
            this.m_FilterList.onRemoveCallback = (ReorderableList list) =>
            {
                list.serializedProperty.GetArrayElementAtIndex(list.index).objectReferenceValue = null;
                ReorderableList.defaultBehaviours.DoRemoveButton(list);
            };

            this.m_FilterList.onAddDropdownCallback = (Rect rect, ReorderableList list) => {
                GenericMenu menu = new GenericMenu();
                for (int i = 0; i < InventorySystemEditor.Database.categories.Count; i++) {
                    Category category = InventorySystemEditor.Database.categories[i];
                    menu.AddItem(new GUIContent("Category/"+category.Name),false, delegate {
                        serializedObject.Update();
                        this.m_Filters.InsertArrayElementAtIndex(this.m_Filters.arraySize);
                        SerializedProperty property = this.m_Filters.GetArrayElementAtIndex(this.m_Filters.arraySize-1);
                        property.objectReferenceValue = category;
                        serializedObject.ApplyModifiedProperties();
                    });
                }
                for (int i = 0; i < InventorySystemEditor.Database.raritys.Count; i++)
                {
                    Rarity rarity = InventorySystemEditor.Database.raritys[i];
                    menu.AddItem(new GUIContent("Rarity/" + rarity.Name), false, delegate {
                        serializedObject.Update();
                        this.m_Filters.InsertArrayElementAtIndex(this.m_Filters.arraySize);
                        SerializedProperty property = this.m_Filters.GetArrayElementAtIndex(this.m_Filters.arraySize - 1);
                        property.objectReferenceValue = rarity;
                        serializedObject.ApplyModifiedProperties();
                    });
                }
                menu.DropDown(rect);
            };

        }
        public void BuyItem(Item item, int amount, bool showDialog = true)
        {
            if (showDialog)
            {
                this.m_AmountSpinner.gameObject.SetActive(this.m_DisplaySpinner);

                this.m_AmountSpinner.onChange.RemoveAllListeners();
                this.m_AmountSpinner.current = 1;
                this.m_AmountSpinner.min     = 1;
                ObjectProperty property = item.FindProperty("BuyBack");
                this.m_AmountSpinner.max = (this.m_RemoveItemAfterPurchase || property != null && property.boolValue)?item.Stack:int.MaxValue;
                this.m_AmountSpinner.onChange.AddListener(delegate(float value)
                {
                    Currency price = Instantiate(item.BuyCurrency);
                    price.Stack    = Mathf.RoundToInt(this.m_BuyPriceFactor * item.BuyPrice * value);
                    this.m_PriceInfo.RemoveItems();
                    this.m_PriceInfo.StackOrAdd(price);
                });
                this.m_AmountSpinner.onChange.Invoke(this.m_AmountSpinner.current);

                ExecuteEvent <ITriggerSelectBuyItem>(Execute, item);
                this.m_BuySellDialog.Show(this.m_BuyDialogTitle, this.m_BuyDialogText, item.Icon, delegate(int result)
                {
                    if (result == 0)
                    {
                        BuyItem(item, Mathf.RoundToInt(this.m_AmountSpinner.current), false);
                    }
                }, this.m_BuyDialogButton, "Cancel");
            }
            else
            {
                if (this.m_PurchasedStorageContainer == null || this.m_PaymentContainer == null)
                {
                    return;
                }
                Rarity rarity   = item.Rarity;
                Item   instance = Instantiate(item);

                instance.Rarity = rarity;
                instance.Stack  = amount;
                Currency price = Instantiate(instance.BuyCurrency);
                price.Stack = Mathf.RoundToInt(this.m_BuyPriceFactor * instance.BuyPrice * amount);

                if (this.m_PaymentContainer.RemoveItem(price, price.Stack))
                {
                    if (amount > instance.MaxStack)
                    {
                        int      stack       = instance.Stack;
                        Currency singlePrice = Instantiate(instance.BuyCurrency);
                        singlePrice.Stack = Mathf.RoundToInt(instance.BuyPrice * this.m_BuyPriceFactor);
                        // singlePrice.Stack = Mathf.RoundToInt(this.m_BuyPriceFactor * singlePrice.Stack);
                        int purchasedStack = 0;
                        for (int i = 0; i < stack; i++)
                        {
                            Item singleItem = Instantiate(instance);
                            singleItem.Rarity = instance.Rarity;
                            singleItem.Stack  = 1;
                            if (!this.m_PurchasedStorageContainer.StackOrAdd(singleItem))
                            {
                                this.m_PaymentContainer.StackOrAdd(singlePrice);
                                InventoryManager.Notifications.containerFull.Show(this.m_PurchasedStorageWindow);
                                ExecuteEvent <ITriggerFailedToBuyItem>(Execute, instance, FailureCause.ContainerFull);
                                break;
                            }
                            purchasedStack += 1;
                            ExecuteEvent <ITriggerBoughtItem>(Execute, singleItem);
                        }
                        if (this.m_RemoveItemAfterPurchase)
                        {
                            item.Container.RemoveItem(item, purchasedStack);
                        }
                        InventoryManager.Notifications.boughtItem.Show(purchasedStack.ToString() + "x" + instance.DisplayName, singlePrice.Stack * purchasedStack + " " + price.Name);
                    }
                    else
                    {
                        Item itemInstance = Instantiate(instance);
                        itemInstance.Rarity = instance.Rarity;

                        if (!this.m_PurchasedStorageContainer.StackOrAdd(itemInstance))
                        {
                            this.m_PaymentContainer.StackOrAdd(price);
                            InventoryManager.Notifications.containerFull.Show(this.m_PurchasedStorageWindow);
                            ExecuteEvent <ITriggerFailedToBuyItem>(Execute, instance, FailureCause.ContainerFull);
                        }
                        else
                        {
                            ObjectProperty property = item.FindProperty("BuyBack");

                            if (this.m_RemoveItemAfterPurchase || property != null && property.boolValue)
                            {
                                item.RemoveProperty("BuyBack");
                                item.Container.RemoveItem(item, amount);
                            }
                            InventoryManager.Notifications.boughtItem.Show(itemInstance.Name, price.Stack + " " + price.Name);
                            ExecuteEvent <ITriggerBoughtItem>(Execute, itemInstance);
                        }
                    }
                }
                else
                {
                    InventoryManager.Notifications.noCurrencyToBuy.Show(item.DisplayName, price.Stack + " " + price.Name);
                    ExecuteEvent <ITriggerFailedToBuyItem>(Execute, item, FailureCause.NotEnoughCurrency);
                }
            }
        }