void SelectItemType()
    {
        string val = ItemTypeDropDown.options[ItemTypeDropDown.value].text;

        ItemSystem.ItemTypes type = (ItemSystem.ItemTypes)Enum.Parse(typeof(ItemSystem.ItemTypes), val);

        bool foundType = false;

        foreach (ItemSystem.ItemTypes validType in ValidTypes)
        {
            if (type == validType)
            {
                foundType = true;
            }
        }
        ItemSystem.ItemTypes newType = ValidTypes.Find(x => x == type);
        if (foundType)
        {
            CraftingButtons.SetActive(true);

            CurrentType = newType;
            FilterRecipes();
            DrawRecipes();
        }
    }
示例#2
0
    public void Apply()
    {
        TargetStorage = GetComponent <StorageObject>();

        if (TargetStorage.GetType() == typeof(PlayerInventory))
        {
            VariableName = "PlayerInventory";
        }
        else
        {
            VariableName = "Chest " + TargetStorage.Level + " " + transform.position.x.ToString() + "," + transform.position.y.ToString();
        }

        //        print(VariableName);
        int slotAmount = DialogueLua.GetVariable(VariableName + "SlotAmount").asInt;

        TargetStorage.Init = DialogueLua.GetVariable(VariableName + "Init").asBool;


        for (int i = 0; i < slotAmount; i++)
        {
            int    itemAmount         = DialogueLua.GetVariable(VariableName + "StackAmount" + i).asInt;
            string itemName           = DialogueLua.GetVariable(VariableName + "StackItem" + i).asString;
            string itemType           = DialogueLua.GetVariable(VariableName + "StackItemType" + i).asString;
            ItemSystem.ItemTypes type = (ItemSystem.ItemTypes)System.Enum.Parse(typeof(ItemSystem.ItemTypes), itemType);

            ItemBase item        = ItemSystem.Instance.GetItemClone(itemName);
            int      amountAdded = TargetStorage.Add(item, (uint)itemAmount);
            int      amountLeft  = itemAmount - amountAdded;
            if (amountLeft > 0)
            {
                Debug.LogWarning("Saver could not add all items to storage: " + TargetStorage.Name);
            }
        }
    }
    void OnApplyPersistentData()
    {
        VariableName              = GameManager.Instance.name;
        TargetManager             = GetComponent <GameManager>();
        TargetManager.GameStarted = DialogueLua.GetVariable(VariableName + "GameStarted").asBool;

        if (DialogueLua.DoesVariableExist(VariableName + "NativeTreeID"))
        {
            TargetManager.NativeTree  = TargetManager.PossibleNativeTrees[DialogueLua.GetVariable(VariableName + "NativeTreeID").asInt];
            TargetManager.NativeFruit = TargetManager.NativeTree.ProduceOutputs.Items[0].Item;
        }
        int shippedItemsAmt = DialogueLua.GetVariable(VariableName + "ShippedItemsAmount").AsInt;

        TargetManager.ShippedItems.Clear();
        for (int i = 0; i < shippedItemsAmt; i++)
        {
            string itemID             = DialogueLua.GetVariable(VariableName + "ShippedItemName" + i).AsString;
            string itemType           = DialogueLua.GetVariable(VariableName + "ShippedItemType" + i).AsString;
            ItemSystem.ItemTypes type = (ItemSystem.ItemTypes)System.Enum.Parse(typeof(ItemSystem.ItemTypes), itemType);
            ItemBase             item = ItemSystem.Instance.GetItemClone(itemID);
            print("got item: " + item.Name);
            ShippedItem newShippedItem = new ShippedItem();
            newShippedItem.ContainedItem = item;
            int amount = DialogueLua.GetVariable(VariableName + "ShippedItemAmount" + i).AsInt;
            TargetManager.AddShippedItem(item, amount);
        }
    }
 public void Open(CraftingStation pStation)
 {
     Inventory      = GameManager.Instance.Player.GetComponent <PlayerInventory>();
     CurrentStation = pStation;
     ValidTypes.Clear();
     foreach (RecipeContainer recipe in CurrentStation.StationRecipes)
     {
         if (CanCraft(recipe))
         {
             ItemSystem.ItemTypes type = recipe.Recipe.Outputs[0].ContainedItem.Type;
             if (!ValidTypes.Contains(type))
             {
                 ValidTypes.Add(type);
             }
         }
     }
     DrawItemTypeDropDown();
     GetComponent <WindowToggle>().Open();
 }
示例#5
0
 void FilterTypes()
 {
     ValidTypes.Clear();
     if (CurrentStation == null)
     {
         return;
     }
     foreach (RecipeContainer recipe in CurrentStation.StationRecipes)
     {
         if (CraftingManager.Instance.KnownRecipes.Contains(recipe))
         {
             ItemSystem.ItemTypes type = recipe.Recipe.Outputs[0].ContainedItem.Type;
             if (!ValidTypes.Contains(type))
             {
                 ValidTypes.Add(type);
             }
         }
     }
 }
    void FilterRecipes()
    {
        ValidRecipes.Clear();
        if (CurrentStation == null)
        {
            return;
        }

        foreach (RecipeContainer recipe in CurrentStation.StationRecipes)
        {
            if (CanCraft(recipe))
            {
                ItemSystem.ItemTypes type = recipe.Recipe.Outputs[0].ContainedItem.Type;
                if (CurrentType == type)
                {
                    ValidRecipes.Add(recipe);
                }
            }
        }
    }
        void ApplyGenericProperties(ItemBase pItem, int pID, string pName, string pDescription, Sprite pIcon, float pVal, int pMarkup, float pWeight, bool pSellable, bool pConsumable, bool pToolbar, string pType)
        {
            pItem.ID          = pID;
            pItem.Name        = pName;
            pItem.Description = pDescription;
            if (pIcon != null)
            {
                pItem.Icon = pIcon;
            }

            pItem.Value             = pVal;
            pItem.Markup            = pMarkup;
            pItem.Weight            = pWeight;
            pItem.Sellable          = pSellable;
            pItem.Consumable        = pConsumable;
            pItem.UsableFromToolbar = pToolbar;

            ItemSystem.ItemTypes type = (ItemSystem.ItemTypes)System.Enum.Parse(typeof(ItemSystem.ItemTypes), pType, true);
            if (type.ToString() != string.Empty)
            {
                pItem.Type = type;
            }
        }
    public void OnApplyPersistentData()
    {
        TargetStation = GetComponent <CraftingStation>();
        VariableName  = TargetStation.Name + transform.position.x + transform.position.y;
        if (DialogueLua.DoesVariableExist(VariableName + "CurrentProgress") == false)
        {
            return;
        }

        TargetStation.CurrentProgress = DialogueLua.GetVariable(VariableName + "CurrentProgress").asFloat;
        TargetStation.TargetProgress  = DialogueLua.GetVariable(VariableName + "TargetProgress").asFloat;

        TargetStation.RecipeIndex = DialogueLua.GetVariable(VariableName + "RecipeIndex").AsInt;

        int queueAmt = DialogueLua.GetVariable(VariableName + "QueueAmount").AsInt;

        for (int i = 0; i < queueAmt; i++)
        {
            string recipeName = DialogueLua.GetVariable(VariableName + "Queue" + i).AsString;
            TargetStation.Queue.Add(CraftingManager.Instance.GetRecipeByName(recipeName));
        }

        int chosenAmt = DialogueLua.GetVariable(VariableName + "ChosenItems").AsInt;

        for (int i = 0; i < chosenAmt; i++)
        {
            int    chosenID           = DialogueLua.GetVariable(VariableName + "ChosenID" + i).asInt;
            string typeName           = DialogueLua.GetVariable(VariableName + "ChosenType" + i).AsString;
            ItemSystem.ItemTypes type = (ItemSystem.ItemTypes)System.Enum.Parse(typeof(ItemSystem.ItemTypes), typeName);
            int chosenmAmount         = DialogueLua.GetVariable(VariableName + "ChosenAmount" + i).AsInt;

            StationItem newItem = new StationItem();
            newItem.ContainedItem = ItemSystem.Instance.GetItemClone(chosenID);
            newItem.Amount        = chosenmAmount;

            TargetStation.ChosenItems.Add(newItem);
        }

        string currentRecipe = DialogueLua.GetVariable(VariableName + "CurrentRecipe").AsString;

        if (currentRecipe != "Null")
        {
            TargetStation.CurrentRecipe = CraftingManager.Instance.GetRecipeByName(currentRecipe);
        }
        else
        {
            TargetStation.CurrentRecipe = null;
        }

        TargetStation.CanProgress = DialogueLua.GetVariable(VariableName + "CanProgress").asBool;

        int inputAmount = DialogueLua.GetVariable(VariableName + "RecipesInInput").AsInt;

        for (int i = 0; i < inputAmount; i++)
        {
            string recipeName = DialogueLua.GetVariable(VariableName + "InputName" + i).AsString;
            TargetStation.RecipesInInput.Add(CraftingManager.Instance.GetRecipeByName(recipeName));
        }

        string chosenRecipeName = DialogueLua.GetVariable(VariableName + "ChosenRecipe").AsString;

        if (chosenRecipeName != "Null")
        {
            TargetStation.ChosenRecipe = CraftingManager.Instance.GetRecipeByName(chosenRecipeName);
        }
        else
        {
            TargetStation.ChosenRecipe = null;
        }
        TargetStation.Load();
    }