Exemple #1
0
        //this is used in a lot of places
        //eg in player inventory squares for crafting to check if the thing you've put in the square meets requirements
        public static bool AreRequirementsMet(IWIBase item, GenericWorldItem template, BlueprintStrictness strictness, int numItemsInStack, out int maxItemsToCraft)
        {
            maxItemsToCraft = 1;

            if (item != null && item.IsQuestItem)
            {
                return(false);
            }

            bool prefabReqsMet = true;
            bool stackReqsMet  = true;
            bool stateReqsMet  = true;
            bool subCatReqsMet = true;

            //first we need to get the thing we're crafting from
            //if it's a liquid container we need to get the state data
            if (item.Is <LiquidContainer> ())
            {
                LiquidContainerState stateData = null;
                bool foundState = false;
                if (item.IsWorldItem)
                {
                    stateData  = item.worlditem.Get <LiquidContainer> ().State;
                    foundState = true;
                }
                else
                {
                    if (item.GetStackItem(WIMode.None).GetStateData <LiquidContainerState> (out stateData))
                    {
                        foundState = true;
                    }
                }

                if (foundState)
                {
                    //see if the liquid container contains what's needed
                    mCheckRequirements.CopyFrom(stateData.Contents);
                    mCheckRequirements.InstanceWeight = stateData.Contents.InstanceWeight;
                }
            }
            else
            {
                //if it's not a liquid container just get it from the item
                mCheckRequirements.CopyFrom(item);
                mCheckRequirements.InstanceWeight = numItemsInStack;
            }

            if (Flags.Check((uint)strictness, (uint)BlueprintStrictness.PrefabName, Flags.CheckType.MatchAny))
            {
                prefabReqsMet = string.Equals(mCheckRequirements.PrefabName, template.PrefabName, StringComparison.InvariantCultureIgnoreCase);
            }
            if (Flags.Check((uint)strictness, (uint)BlueprintStrictness.StackName, Flags.CheckType.MatchAny))
            {
                stackReqsMet = string.Equals(mCheckRequirements.StackName, template.StackName, StringComparison.InvariantCultureIgnoreCase);
                if (!stackReqsMet)
                {
                    try {
                        //check for the rare case where a non-numbered item is compared against a numbered item
                        //'x #' vs 'x'
                        //'x' vs 'x #'
                        bool isReqDigit  = char.IsDigit(mCheckRequirements.StackName, mCheckRequirements.StackName.Length - 1);
                        bool isItemDigit = char.IsDigit(template.StackName, template.StackName.Length - 1);
                        if (isReqDigit != isItemDigit)
                        {
                            string nonNumbered = isItemDigit ? mCheckRequirements.StackName : template.StackName;
                            string numbered    = isReqDigit ? mCheckRequirements.StackName.Substring(0, mCheckRequirements.StackName.Length - 2) : template.StackName.Substring(0, template.StackName.Length - 2);
                            stackReqsMet = nonNumbered.Equals(numbered);
                                                        #if UNITY_EDITOR
                            Debug.Log("Checking numbered against non-numbered in crafting: " + mCheckRequirements.StackName + " vs " + template.StackName + " - check " + nonNumbered + ", " + numbered + " - " + stackReqsMet.ToString());
                                                        #endif
                        }
                    } catch (Exception e) {
                        Debug.LogError("Error when checking for item digits in crafting skill: " + e.ToString());
                    }
                }
            }
            if (Flags.Check((uint)strictness, (uint)BlueprintStrictness.StateName, Flags.CheckType.MatchAny))
            {
                if ((string.IsNullOrEmpty(mCheckRequirements.State) || string.IsNullOrEmpty(template.State)) || (mCheckRequirements.State.Equals("Default") || template.State.Equals("Default")))
                {
                    stateReqsMet = true;
                }
                else
                {
                    stateReqsMet = string.Equals(mCheckRequirements.State, template.State, StringComparison.InvariantCultureIgnoreCase);
                }
            }
            if (Flags.Check((uint)strictness, (uint)BlueprintStrictness.Subcategory, Flags.CheckType.MatchAny))
            {
                if (string.IsNullOrEmpty(mCheckRequirements.Subcategory) || string.IsNullOrEmpty(template.Subcategory))
                {
                    subCatReqsMet = true;
                }
                else
                {
                    subCatReqsMet = string.Equals(mCheckRequirements.Subcategory, template.Subcategory, StringComparison.InvariantCultureIgnoreCase);
                }
            }
                        #if UNITY_EDITOR
            Debug.Log(template.PrefabName + " prefab reqs met: " + prefabReqsMet.ToString() + "\nstackReqsMet: " + stackReqsMet.ToString() + "\nstateReqsMet: " + stateReqsMet.ToString() + "\nsubCatReqsMet: " + subCatReqsMet.ToString());
                        #endif
            //max items to craft is the instance weight divided by instance weight of the template
            //instance weight of template tells us how many we need in that stack to craft
            maxItemsToCraft = mCheckRequirements.InstanceWeight / template.InstanceWeight;
            //if we have enough items to craft, we can proceed
            return(prefabReqsMet && stackReqsMet && stateReqsMet && subCatReqsMet && maxItemsToCraft >= template.InstanceWeight);
        }
 public void EnableForBlueprint(GenericWorldItem requiredItemTemplate, BlueprintStrictness strictness)
 {
     mEnabledForBlueprint = true;
     Strictness           = strictness;
     RequiredItemTemplate.CopyFrom(requiredItemTemplate);
 }
Exemple #3
0
 protected void LoadBlueprintRow(List <InventorySquareCrafting> row, List <GenericWorldItem> requirements, BlueprintStrictness strictness)
 {
     for (int i = 0; i < row.Count; i++)
     {
         //always true in this case
         row [i].HasBlueprint = true;
         if (requirements [i] == null || requirements [i].IsEmpty)
         {
             row [i].DisableForBlueprint();
         }
         else
         {
             row [i].EnableForBlueprint(requirements [i], strictness);
             Blueprints.Get.IsCraftable(requirements [i], out row [i].RequirementBlueprint, false);                     //TODO change this to true eventually to cover revealed
         }
         row [i].RefreshRequest();
     }
 }