Exemple #1
0
        public void AddBrowserObjects()
        {
            for (int i = 0; i < mEditObject.Objects.Count; i++)
            {
                CircleBrowserObjectTemplate objectTemplate = mEditObject.Objects[i];
                GameObject newBrowserObjectGameObject      = NGUITools.AddChild(RotationPivot, BrowserObjectPrefab.gameObject);
                GUICircularBrowserObject newBrowserObject  = newBrowserObjectGameObject.GetComponent <GUICircularBrowserObject>();
                newBrowserObject.ParentBrowser          = this;
                newBrowserObject.StackNumberLabel.text  = objectTemplate.CenterLabelText;
                newBrowserObject.InventoryItemName.text = objectTemplate.BottomLabelText;
                newBrowserObject.WeightLabel.text       = objectTemplate.TopLabelText;

                if (!GenericWorldItem.IsNullOrEmpty(objectTemplate.DopplegangerProps))
                {
                    newBrowserObject.Doppleganger = WorldItems.GetDoppleganger(
                        objectTemplate.DopplegangerProps,
                        newBrowserObject.transform,
                        newBrowserObject.Doppleganger,
                        WIMode.Stacked,
                        1.0f);
                }

                if (!string.IsNullOrEmpty(objectTemplate.BackgroundSpriteName))
                {
                    newBrowserObject.Background.spriteName = objectTemplate.BackgroundSpriteName;
                }

                BrowserObjects.Add(newBrowserObject);
            }

            RefreshBrowserObjects();
        }
 public void SetRequiredItem(GenericWorldItem newRequirement)
 {
     if (newRequirement != RequiredItemTemplate)
     {
         RequiredItemTemplate = newRequirement;
         RefreshRequest();
     }
 }
Exemple #3
0
 public override void Initialize()
 {
     base.Initialize();
     mCheckRequirements = new GenericWorldItem();
     if (Extensions == null)
     {
         Extensions = new CraftSkillExtensions();
     }
 }
Exemple #4
0
        public bool DateShard()
        {
            if (Player.Local.Tool.IsEquipped)
            {
                ArtifactShard shard = null;
                if (Player.Local.Tool.worlditem.Is <ArtifactShard>(out shard))
                {
                    if (shard.DateShard())
                    {
                        //once the shard is dated
                        //swap it out with a new shard
                        //use the generic world item as a base
                        //set the state so the shard shape is the same
                        GenericWorldItem newShard = null;
                        switch (shard.State.Age)
                        {
                        case ArtifactAge.Modern:
                        default:
                            newShard = ModernShard;
                            break;

                        case ArtifactAge.Old:
                            newShard = OldShard;
                            break;

                        case ArtifactAge.Antiquated:
                            newShard = AntiquatedShard;
                            break;

                        case ArtifactAge.Ancient:
                            newShard = AncientShard;
                            break;

                        case ArtifactAge.Prehistoric:
                            newShard = PrehistoricShard;
                            break;
                        }

                        //now turn it into a stack item
                        //this will allow us to prevent it from randomizing itself
                        StackItem          newShardStackItem = newShard.ToStackItem();
                        ArtifactShardState shardState        = null;
                        newShardStackItem.State     = shard.worlditem.State;
                        newShardStackItem.StackName = shard.worlditem.StackName;
                        if (newShardStackItem.GetStateData <ArtifactShardState>(out shardState))
                        {
                            shardState.HasChosenFragment = true;
                        }

                        WorldItems.ReplaceWorldItem(shard.worlditem, newShardStackItem);
                        FXManager.Get.SpawnFX(transform.position, FXOnDate);
                    }
                }
            }
            return(false);
        }
Exemple #5
0
 public override void Initialize()
 {
     base.Initialize();
     mAllCategory           = new List <string>();
     mLoadedBlueprints      = new Dictionary <string, WIBlueprint>();
     mPatternLookup         = new Dictionary <int, List <WIBlueprint> >();
     mBlueprintAssociations = new Dictionary <GenericWorldItem, WIBlueprint>();
     mEditorBlueprints      = new List <WIBlueprint>();
     mAssociationWorldItem  = new GenericWorldItem();
 }
Exemple #6
0
        public override void PushSelectedObjectToViewer()
        {
            //turn this into a string builder
            Color         plantColor = Colors.ColorFromString(mSelectedObject.CommonName, 100);
            List <string> detailText = new List <string>();

            mExamineInfo.Clear();

            Skill            examineSkill      = null;
            GenericWorldItem dopplegangerProps = null;

            if (Skills.Get.SkillByName("Gathering", out examineSkill))
            {
                bool showDetails = false;
                Plants.Examine(mSelectedObject, mExamineInfo);
                detailText.Add("Viewing season " + WorldClock.TimeOfYearToString(SelectedSeasonality));
                if (Flags.Check((uint)mSelectedObject.EncounteredTimesOfYear, (uint)SelectedSeasonality, Flags.CheckType.MatchAny) ||
                    examineSkill.State.NormalizedUsageLevel > Plants.MinimumGatheringSkillToRevealBasicProps)
                {
                    showDetails                   = true;
                    dopplegangerProps             = mPlantDoppleganger;
                    dopplegangerProps.Subcategory = mSelectedObject.Name;
                }
                else
                {
                    detailText.Add("(You don't know what this plant looks like during this time of year.)");
                }
                detailText.Add("_");
                for (int i = 0; i < mExamineInfo.Count; i++)
                {
                    if (examineSkill.State.NormalizedUsageLevel > mExamineInfo[i].RequiredSkillUsageLevel)
                    {
                        detailText.Add(mExamineInfo[i].StaticExamineMessage);
                    }
                    else
                    {
                        detailText.Add(mExamineInfo[i].ExamineMessageOnFail);
                    }
                }
                string finalDetailText = detailText.JoinToString("\n");
                GUIDetailsPage.Get.DisplayDetail(
                    this,
                    mSelectedObject.CommonName,
                    finalDetailText,
                    "PlantIcon",
                    Mats.Get.IconsAtlas,
                    plantColor,
                    Color.white,
                    dopplegangerProps);
                if (showDetails)
                {
                    GUIDetailsPage.Get.DisplayDopplegangerButton("Next Season", "OnClickNextSeason", gameObject);
                }
            }
        }
Exemple #7
0
 public void DrawBlueprintRowItem(GenericWorldItem item, int itemIndex, int rowIndex)
 {
     if (selectedItemIndex == itemIndex && rowIndex == selectedRowIndex && openWindow)
     {
         UnityEngine.GUI.color = Color.yellow;
         DrawGenericWorldItemSelector(item, ref openWindow, true);
     }
     else
     {
         UnityEngine.GUI.color = Color.white;
         if (item == null || item.IsEmpty)
         {
             UnityEngine.GUI.color = Color.Lerp(Color.grey, Color.black, 0.5f);
             if (GUILayout.Button("\n\n\n =(Empty)= \n\n\n", UnityEditor.EditorStyles.miniButton))
             {
                 selectedRowIndex  = rowIndex;
                 selectedItemIndex = itemIndex;
                 openWindow        = true;
             }
         }
         else
         {
             UnityEngine.GUI.color = Color.Lerp(Color.green, Colors.ColorFromString(item.PrefabName, 150), 0.85f);
             string buttonName = item.PrefabName;
             int    numReturns = 4;
             if (!string.IsNullOrEmpty(item.StackName))
             {
                 buttonName += "\n(" + item.StackName + ")";
                 numReturns--;
             }
             if (!string.IsNullOrEmpty(item.State) && item.State != "Default")
             {
                 buttonName += "\n(" + item.State + ")";
                 numReturns--;
             }
             if (!string.IsNullOrEmpty(item.Subcategory))
             {
                 buttonName += "\n(" + item.Subcategory + ")";
                 numReturns--;
             }
             string returns = string.Empty;
             for (int i = 0; i < numReturns; i++)
             {
                 returns += "\n";
             }
             if (GUILayout.Button(returns + buttonName + returns, UnityEditor.EditorStyles.miniButton))
             {
                 selectedRowIndex  = rowIndex;
                 selectedItemIndex = itemIndex;
                 openWindow        = true;
             }
         }
     }
 }
Exemple #8
0
        public void OnDepleted()
        {
            GenericWorldItem swap     = null;
            WICategory       category = null;

            if (WorldItems.Get.Category(State.CategoryName, out category) && category.GetItem(worlditem.GetHashCode(), out swap))
            {
                WorldItems.ReplaceWorldItem(worlditem, swap);
                Finish();
            }
        }
Exemple #9
0
        public bool FillLiquidContainer(IWIBase liquidContainer, IWIBase foodStuff, WIStack foodStuffStack)
        {
            if (!foodStuff.Is <FoodStuff>())
            {
                //nope! can't do it
                return(false);
            }

            System.Object fssObject = null;
            //check the foodstuff first since it has to be liquid
            if (foodStuff.GetStateOf <FoodStuff>(out fssObject))
            {
                FoodStuffState fss = (FoodStuffState)fssObject;
                if (fss.IsLiquid(foodStuff.State))
                {
                    //okay we've confirmed it's a liquid
                    //now see if the liquid container can hold it
                    if (!liquidContainer.Is <LiquidContainer>())
                    {
                        //we're returning true because it'll make the correct noise and the item will disappear
                        GUIManager.PostWarning("The liquid cannot be held by this container. It seeps away.");
                        foodStuff.RemoveFromGame();
                        return(true);
                    }

                    System.Object lcObject = null;
                    if (liquidContainer.GetStateOf <LiquidContainer>(out lcObject))
                    {
                        LiquidContainerState lcs         = (LiquidContainerState)lcObject;
                        string           liquidFillError = string.Empty;
                        int              numFilled       = 0;
                        GenericWorldItem genericLiquid   = new GenericWorldItem(foodStuff);
                        if (lcs.TryToFillWith(genericLiquid, foodStuffStack.NumItems, out numFilled, out liquidFillError))
                        {
                            //hooray, it worked
                            //how we have to pop items off the top of the food stuff stack
                            for (int i = 0; i < numFilled; i++)
                            {
                                Stacks.Pop.AndToss(foodStuffStack);
                            }
                            GUIManager.PostInfo("Filled " + numFilled.ToString());
                            return(true);
                        }
                        else
                        {
                            GUIManager.PostWarning(liquidFillError);
                        }
                    }
                }
            }
            return(false);
        }
Exemple #10
0
 public bool IsCraftable(GenericWorldItem craftableItem, out string blueprintName, bool requireRevealed)
 {
     blueprintName = string.Empty;
     foreach (KeyValuePair <GenericWorldItem, WIBlueprint> association in mBlueprintAssociations)
     {
         if (craftableItem.Equals(association.Key) && (!requireRevealed || association.Value.Revealed))
         {
             blueprintName = association.Value.Name;
             return(true);
         }
     }
     return(false);
 }
Exemple #11
0
        public override void WakeUp()
        {
            base.WakeUp();

            Get           = this;
            mPotionLookup = new Dictionary <string, Potion>();
            mPotionLookup.Clear();
            PotionList.Clear();

            if (!Application.isPlaying)
            {
                if (!Manager.IsAwake <Mods>())
                {
                    Manager.WakeUp <Mods>("__MODS");
                }
                Mods.Get.Editor.InitializeEditor(true);

                List <string> potionNames = Mods.Get.Available("Potion");

                for (int i = 0; i < potionNames.Count; i++)
                {
                    Potion potion = null;
                    if (Application.isPlaying)
                    {
                        if (Mods.Get.Runtime.LoadMod <Potion>(ref potion, "Potion", potionNames[i]))
                        {
                            mPotionLookup.Add(potion.Name.ToLower().Trim().Replace(" ", ""), potion);
                            PotionList.Add(potion);
                        }
                    }
                    else
                    {
                        if (Mods.Get.Editor.LoadMod <Potion>(ref potion, "Potion", potionNames[i]))
                        {
                            mPotionLookup.Add(potion.Name.ToLower().Trim().Replace(" ", ""), potion);
                            PotionList.Add(potion);
                        }
                    }
                }
            }

            gPotionGenericWorldItem            = new GenericWorldItem();
            gPotionGenericWorldItem.PackName   = "MedicalSupplies";
            gPotionGenericWorldItem.PrefabName = "Potion Bottle 1";
            //gPotionGenericWorldItem.State = "Default";
            gPotionGenericWorldItem.DisplayName = "Potion";
            gPotionGenericWorldItem.Subcategory = "HealingPotion";
        }
Exemple #12
0
        public bool TryToFillWith(GenericWorldItem item, int numItems, out int numFilled, out string errorMessage)
        {
            int availableCapacity = 0;

            numFilled = 0;
            if (CanFillWith(item, out availableCapacity, out errorMessage))
            {
                Contents.CopyFrom(item);
                numFilled = availableCapacity;
                if (numFilled > numItems)
                {
                    numFilled = numItems;
                }
                Contents.InstanceWeight = numFilled;
                return(true);
            }
            return(false);
        }
Exemple #13
0
        public void OnPlayerUseWorldItemSecondary(object secondaryResult)
        {
            WIListResult dialogResult = secondaryResult as WIListResult;

            switch (dialogResult.SecondaryResult)
            {
            case "Milk":
                LiquidContainer container = null;
                if (Player.Local.Tool.worlditem.Is <LiquidContainer>(out container))
                {
                    if (container.State.IsEmpty)
                    {
                        WICategory    category = null;
                        System.Random random   = new System.Random(Profile.Get.CurrentGame.Seed);
                        if (WorldItems.Get.Category(MilkCategory, out category))
                        {
                            GenericWorldItem milkItem = null;
                            if (category.GenericWorldItems.Count > 0)
                            {
                                milkItem = category.GenericWorldItems[random.Next(0, category.GenericWorldItems.Count)];
                            }
                            else
                            {
                                milkItem = category.GenericWorldItems[0];
                            }
                            container.State.Contents.CopyFrom(milkItem);
                            container.State.Contents.InstanceWeight = container.State.Capacity;
                            //make the cow make a noise
                            worlditem.Get <Creature>().OnTakeDamage();
                        }
                    }
                }
                break;

            case "Tip":
                worlditem.Get <Creature>().OnTakeDamage();                                                                //make a noise and flip out
                worlditem.Get <Creature>().TryToStun(10f);
                break;

            default:
                break;
            }
        }
Exemple #14
0
 public void SelectWorldItem()
 {
     UnityEngine.GUI.color = Color.cyan;
     GUILayout.Label("SELECT WORLD ITEM:");
     if (GUILayout.Button("CLOSE"))
     {
         openWindow = false;
     }
     foreach (WorldItemPack pack in WorldItems.Get.WorldItemPacks)
     {
         if (pack.Name == selectedPack)
         {
             UnityEngine.GUI.color = Color.yellow;
             foreach (GameObject prefab in pack.Prefabs)
             {
                 if (GUILayout.Button(prefab.name))
                 {
                     WorldItem worlditem = prefab.GetComponent <WorldItem>();
                     if (rowSelection == null && rowIndex == 100)
                     {
                         selectedBlueprint.GenericResult = new GenericWorldItem(worlditem);
                         rowIndex   = 0;
                         openWindow = false;
                     }
                     else
                     {
                         rowSelection[rowIndex] = new GenericWorldItem(worlditem);
                         openWindow             = false;
                     }
                 }
             }
         }
         else if (GUILayout.Button(pack.Name))
         {
             UnityEngine.GUI.color = Color.cyan;
             selectedPack          = pack.Name;
         }
         else
         {
             UnityEngine.GUI.color = Color.cyan;
         }
     }
 }
Exemple #15
0
        public void OnDie()
        {
            switch (worlditem.State)
            {
            case "Mined":
                Debug.Log("DIED in luminite node with state mined");
                worlditem.Get <Damageable> ().ResetDamage();
                State.TimeMined = WorldClock.AdjustedRealTime;
                break;

            default:
                Debug.Log("DIED in luminite node with state " + worlditem.State);
                worlditem.Get <Damageable> ().ResetDamage();
                //set luminite type to mined raw, then get a stack item for the player
                //add that to player inventory
                WorldItem        rawLuminite     = null;
                GenericWorldItem rawLuminiteItem = RawLuminiteLight;
                if (worlditem.State == "Dark")
                {
                    rawLuminiteItem = RawLuminiteDark;
                }
                if (WorldItems.CloneWorldItem(
                        rawLuminiteItem,
                        new STransform(worlditem.tr),
                        false,
                        worlditem.Group,
                        out rawLuminite))
                {
                    //this will drop to the players' feet
                    rawLuminite.Props.Local.FreezeOnStartup = false;
                    rawLuminite.Initialize();
                    rawLuminite.SetMode(WIMode.World);
                    rawLuminite.GetComponent <Rigidbody>().AddForce(worlditem.tr.up * 0.25f);
                }
                State.TimeMined       = WorldClock.AdjustedRealTime;
                State.AbsorbedDarkRot = 0f;
                worlditem.State       = "Mined";
                break;
            }

            Debug.Log("State is now " + worlditem.State);
        }
Exemple #16
0
        public static bool ConsumeRequirement(WIStack itemStack, IWIBase item, GenericWorldItem template, bool requirementsMet)
        {
            if (!requirementsMet)
            {
                return(false);
            }

            bool result = false;

            if (item.Is <LiquidContainer> ())
            {
                //see if the thing inside the liquid container has what we need
                bool foundState                  = false;
                LiquidContainerState state       = null;
                System.Object        stateObject = null;
                if (item.GetStateOf <LiquidContainer> (out stateObject))
                {
                    state      = (LiquidContainerState)stateObject;
                    foundState = state != null;
                }

                if (foundState)
                {
                    //hooray it is a liquid
                    if (!state.IsEmpty)
                    {
                        //and it's not empty so steal one
                        state.Contents.InstanceWeight--;
                        result = true;
                        item.SetStateOf <LiquidContainer> (state);
                    }
                }
            }
            else
            {
                Stacks.Pop.AndToss(itemStack);
                result = true;
            }
            return(result);
        }
Exemple #17
0
 protected void CreateIngredients(GameObject ingredientsParent, List <GenericWorldItem> ingredients, List <Renderer> renderers)
 {
     for (int i = 0; i < ingredients.Count; i++)
     {
         if (ingredients[i] != null && !ingredients[i].IsEmpty)
         {
             //if it's not an empty spot
             //get an avatar for the item
             GenericWorldItem ingredient       = ingredients[i];
             Transform        ingredientParent = ingredientsParent.CreateChild("Ingredient_" + i.ToString());
             if (ingredientParent != null)
             {
                 ingredientParent.localPosition = IngredientOffsets[i];
                 GameObject ingredientDoppleganger = WorldItems.GetDoppleganger(
                     ingredient,
                     ingredientParent,
                     null,
                     WIMode.World);
             }
         }
     }
 }
Exemple #18
0
        public bool CanFillWith(GenericWorldItem item, out int availableCapacity, out string errorMessage)
        {
            availableCapacity = 0;
            errorMessage      = string.Empty;
            if (IsFilled)
            {
                errorMessage = "Already full";
                return(false);
            }

            if (!IsEmpty)                                       //if we have some filled, see if the items are compatible
            {
                availableCapacity = Capacity - Contents.InstanceWeight;
                return(Stacks.Can.Stack(item, Contents.StackName));
            }

            if (CanContain.Count > 0)                                           //if we have restrictions, check them
            {
                bool canContain = false;
                foreach (string canContainType in CanContain)
                {
                    if (Stacks.Can.Stack(item, canContainType))                                                              //if any item is compatible, yay we can fill
                    {
                        canContain = true;
                        break;
                    }
                }
                if (!canContain)
                {
                    errorMessage = "This container can't hold " + item.DisplayName;
                    return(false);
                }
            }
            availableCapacity = Capacity;
            return(true);
        }
Exemple #19
0
        public void DrawGenericWorldItemSelector(GenericWorldItem item, ref bool open, bool useStrictness)
        {
            if (WorldItems.Get == null)
            {
                Manager.WakeUp <WorldItems>("Frontiers_WorldItems");
                WorldItems.Get.Initialize();
            }

            bool drawEditor = true;

            UnityEditor.EditorStyles.miniButton.stretchWidth = true;
            UnityEditor.EditorStyles.textField.stretchWidth  = true;
            UnityEditor.EditorStyles.popup.stretchWidth      = true;

            GUILayout.BeginVertical();

            if (string.IsNullOrEmpty(item.PackName))
            {
                drawEditor            = false;
                UnityEngine.GUI.color = Color.green;
                if (GUILayout.Button("(Add)", UnityEditor.EditorStyles.miniButton))
                {
                    item.PackName   = "AncientArtifacts";
                    item.PrefabName = string.Empty;
                    drawEditor      = true;
                }
                UnityEngine.GUI.color = Color.yellow;
                if (GUILayout.Button("(Done)", UnityEditor.EditorStyles.miniButton))
                {
                    drawEditor        = false;
                    selectedItemIndex = -1;
                    selectedRowIndex  = -1;
                }
            }
            else
            {
                UnityEngine.GUI.color = Color.red;
                if (GUILayout.Button("(Clear)", UnityEditor.EditorStyles.miniButton))
                {
                    item.Clear();
                    drawEditor = false;
                }
            }

            if (drawEditor)
            {
                UnityEngine.GUI.color = Color.yellow;
                int           packIndex = 0;
                List <string> packNames = new List <string>();
                WorldItemPack pack      = null;
                WorldItem     worlditem = null;
                for (int i = 0; i < WorldItems.Get.WorldItemPacks.Count; i++)
                {
                    string packName = WorldItems.Get.WorldItemPacks[i].Name;
                    packNames.Add(packName);
                    if (item.PackName == packName)
                    {
                        packIndex = i;
                        pack      = WorldItems.Get.WorldItemPacks[i];
                    }
                }
                if (pack == null)
                {
                    pack = WorldItems.Get.WorldItemPacks[0];
                }

                packIndex = UnityEditor.EditorGUILayout.Popup("Pack:", packIndex, packNames.ToArray(), UnityEditor.EditorStyles.popup);
                List <string> prefabNames = new List <string>();
                int           prefabIndex = 0;
                for (int i = 0; i < pack.Prefabs.Count; i++)
                {
                    prefabNames.Add(pack.Prefabs[i].name);
                    if (item.PrefabName == pack.Prefabs[i].name)
                    {
                        prefabIndex = i;
                        worlditem   = pack.Prefabs[i].GetComponent <WorldItem>();
                    }
                }
                prefabIndex = UnityEditor.EditorGUILayout.Popup("Prefab:", prefabIndex, prefabNames.ToArray(), UnityEditor.EditorStyles.popup);

                item.PackName   = packNames[packIndex];
                item.PrefabName = prefabNames[prefabIndex];

                if (worlditem != null)
                {
                    UnityEngine.GUI.color = Color.yellow;
                    item.DisplayName      = worlditem.DisplayName;
                    if (!useStrictness || Flags.Check((uint)Blueprint.Strictness, (uint)BlueprintStrictness.StackName, Flags.CheckType.MatchAny))
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label("StackName: ");
                        if (string.IsNullOrEmpty(item.StackName) || !worlditem.StackName.Contains(item.StackName))
                        {
                            item.StackName = worlditem.StackName;
                        }
                        item.StackName = GUILayout.TextField(item.StackName);
                        GUILayout.EndHorizontal();
                    }
                    if (!useStrictness || Flags.Check((uint)Blueprint.Strictness, (uint)BlueprintStrictness.StateName, Flags.CheckType.MatchAny))
                    {
                        GUILayout.BeginHorizontal();
                        int           stateIndex = 0;
                        List <string> stateNames = new List <string>();
                        stateNames.Add("Default");
                        WIStates states = worlditem.GetComponent <WIStates>();
                        if (states != null)
                        {
                            for (int i = 0; i < states.States.Count; i++)
                            {
                                stateNames.Add(states.States[i].Name);
                                if (item.State == states.States[i].Name)
                                {
                                    stateIndex = i + 1;                                                                                                            //since the first one is Default
                                }
                            }
                        }
                        stateIndex = UnityEditor.EditorGUILayout.Popup("State:", stateIndex, stateNames.ToArray(), UnityEditor.EditorStyles.popup);
                        GUILayout.EndHorizontal();
                        item.State = stateNames[stateIndex];
                    }
                }
                UnityEngine.GUI.color = Color.white;
                if (!useStrictness || Flags.Check((uint)Blueprint.Strictness, (uint)BlueprintStrictness.Subcategory, Flags.CheckType.MatchAny))
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Subcategory: ");
                    item.Subcategory = GUILayout.TextField(item.Subcategory);
                    GUILayout.EndHorizontal();
                }
                UnityEngine.GUI.color = Color.yellow;
                if (GUILayout.Button("(Done)", UnityEditor.EditorStyles.miniButton))
                {
                    open = false;
                }
            }

            GUILayout.EndVertical();

            UnityEditor.EditorStyles.miniButton.stretchWidth = true;
            UnityEditor.EditorStyles.textField.stretchWidth  = true;
            UnityEditor.EditorStyles.popup.stretchWidth      = true;
        }
Exemple #20
0
        protected bool CreateButton(WIListOption option, int flavorIndex, float buttonPosition, string functionName)
        {
            if (!option.IsValid)
            {
                                #if DEBUG_SKILLS
                Debug.Log("Invalid option " + option.OptionText + " - not creating button");
                                #endif
                return(false);
            }

            UIButton randomPrototype = ButtonPrototypes [UnityEngine.Random.Range(0, ButtonPrototypes.Count)];
            UIButton newButton       = NGUITools.AddChild(ScreenEdgeOffset.gameObject, randomPrototype.gameObject).GetComponent <UIButton> ();

            UISprite newButtonBackground = newButton.transform.FindChild("Background").GetComponent <UISprite> ();
            UISprite newButtonSelection  = newButton.transform.FindChild("Selection").GetComponent <UISprite> ();
            UILabel  newButtonLabel      = newButton.transform.FindChild("Label").GetComponent <UILabel> ();
            UISprite overlaySprite       = newButton.transform.FindChild("Overlay").GetComponent <UISprite> ();

            newButton.hover            = Colors.Get.GeneralHighlightColor;
            newButton.defaultColor     = Colors.Darken(Colors.Get.GeneralHighlightColor, 0f);
            newButtonSelection.color   = Colors.Darken(Colors.Get.GeneralHighlightColor, 0f);
            newButtonLabel.effectColor = Colors.Get.MenuButtonTextOutlineColor;
            newButtonLabel.effectStyle = UILabel.Effect.Shadow;            //UILabel.Effect.Outline;

            newButtonLabel.text  = option.OptionText;
            newButton.name       = option.Result;
            newButtonLabel.color = option.TextColor;
            if (option.ObexFont)
            {
                newButtonLabel.useDefaultLabelFont  = false;
                newButtonLabel.multiLine            = false;
                newButtonLabel.transform.localScale = Vector3.one * 15f;
                newButtonLabel.font = Mats.Get.ObexFont;
            }

            if (flavorIndex >= 0)
            {
                if (flavorIndex < option.Flavors.Count)
                {
                    if (string.IsNullOrEmpty(option.Flavors [flavorIndex]))
                    {
                        return(false);
                    }
                    else
                    {
                        newButtonLabel.text = option.Flavors [flavorIndex];
                        newButton.name     += "_" + flavorIndex.ToString();
                    }
                }
                else
                {
                    newButton.name = option.Result + "_" + flavorIndex.ToString();
                }
            }

            Transform currencyTransform = newButton.transform.FindChild("Currency");
            if (option.RequiresCurrency)
            {
                Transform        currencyLabelTransform     = currencyTransform.Find("CurrencyLabel");
                Transform        currencyDopplegangerParent = currencyTransform.Find("CurrencyDopplegangerParent");
                UILabel          currencyLabel             = currencyLabelTransform.gameObject.GetComponent <UILabel> ();
                string           inventoryItemName         = string.Empty;
                GenericWorldItem currencyDopplegangerProps = null;
                switch (option.RequiredCurrencyType)
                {
                case WICurrencyType.A_Bronze:
                default:
                    currencyDopplegangerProps = Currency.BronzeGenericWorldItem;
                    inventoryItemName         = Currency.BronzeCurrencyNamePlural;
                    break;

                case WICurrencyType.B_Silver:
                    currencyDopplegangerProps = Currency.SilverGenericWorldItem;
                    inventoryItemName         = Currency.SilverCurrencyNamePlural;
                    break;

                case WICurrencyType.C_Gold:
                    currencyDopplegangerProps = Currency.GoldIGenericWorldItem;
                    inventoryItemName         = Currency.GoldCurrencyNamePlural;
                    break;

                case WICurrencyType.D_Luminite:
                    currencyDopplegangerProps = Currency.LumenGenericWorldItem;
                    inventoryItemName         = Currency.LumenCurrencyNamePlural;
                    break;

                case WICurrencyType.E_Warlock:
                    currencyDopplegangerProps = Currency.WarlockGenericWorldItem;
                    inventoryItemName         = Currency.WarlockCurrencyNamePlural;
                    break;
                }
                currencyLabel.text = option.CurrencyValue.ToString() + " " + inventoryItemName;
                GameObject currencyDoppleganger = WorldItems.GetDoppleganger(currencyDopplegangerProps, currencyDopplegangerParent, null, WIMode.Stacked, 1f);
            }
            else
            {
                currencyTransform.gameObject.SetActive(false);
            }

            if (option.Disabled)
            {
                newButton.SendMessage("SetDisabled");
                newButton.enabled         = false;
                newButtonBackground.color = Colors.Disabled(option.BackgroundColor);
                newButtonLabel.color      = Colors.Disabled(option.TextColor);
                newButton.hover           = Colors.Disabled(newButton.hover);
                overlaySprite.color       = option.OverlayColor;

                UIButtonScale newButtonScale = newButton.GetComponent <UIButtonScale> ();
                newButtonScale.enabled = false;
            }
            else
            {
                newButton.SendMessage("SetEnabled");
                newButtonBackground.color = option.BackgroundColor;
                newButtonLabel.color      = option.TextColor;
                overlaySprite.color       = option.OverlayColor;

                UIButtonMessage newButtonMessage = newButton.GetComponent <UIButtonMessage> ();
                newButtonMessage.target       = this.gameObject;
                newButtonMessage.functionName = functionName;
            }

            newButton.transform.localPosition = new Vector3(0.0f, buttonPosition, 0.0f);

            Transform credentialsTransform = newButton.transform.FindChild("Credentials");
            if (string.IsNullOrEmpty(option.CredentialsIconName))
            {
                credentialsTransform.gameObject.SetActive(false);
            }
            else
            {
                Transform spriteTransform           = credentialsTransform.FindChild("CredentialsSprite");
                Transform spriteBackgroundTransform = credentialsTransform.transform.FindChild("CredentialsBackground");
                UISprite  sprite           = spriteTransform.gameObject.GetComponent <UISprite> ();
                UISprite  backgroundSprite = spriteBackgroundTransform.gameObject.GetComponent <UISprite> ();
                sprite.spriteName        = option.CredentialsIconName;
                sprite.color             = newButtonBackground.color;
                backgroundSprite.enabled = true;
                backgroundSprite.color   = option.IconColor;
            }


            Transform iconTransform = newButton.transform.FindChild("Icon");
            if (string.IsNullOrEmpty(option.IconName))
            {
                iconTransform.gameObject.SetActive(false);
            }
            else
            {
                Transform spriteTransform           = iconTransform.FindChild("IconSprite");
                Transform spriteBackgroundTransform = iconTransform.transform.FindChild("IconBackground");
                Transform negateIconTransform       = iconTransform.transform.FindChild("NegateIcon");
                UISprite  negateIconSprite          = negateIconTransform.gameObject.GetComponent <UISprite> ();
                UISprite  sprite           = spriteTransform.gameObject.GetComponent <UISprite> ();
                UISprite  backgroundSprite = spriteBackgroundTransform.gameObject.GetComponent <UISprite> ();
                sprite.spriteName        = option.IconName;
                sprite.color             = option.IconColor;
                backgroundSprite.enabled = true;
                backgroundSprite.color   = option.BackgroundColor;
                if (option.Disabled)
                {
                    sprite.color = Colors.Blacken(sprite.color);
                }
                if (option.NegateIcon)
                {
                    negateIconSprite.enabled = true;
                }
                else
                {
                    negateIconSprite.enabled = false;
                }
                backgroundSprite.color = option.BackgroundColor;
            }

            return(true);
        }
Exemple #21
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);
        }
Exemple #22
0
 public void DisplayDetail(FrontiersInterface user, string name, string detailText, string iconName, UIAtlas iconAtlas, Color iconColor, Color iconBackgroundColor, GenericWorldItem dopplegangerProps)
 {
     ScrollBar.scrollValue = 0f;
     Show();
     NameLabel.text        = name;
     DetailTextLabel.color = Colors.Get.MenuButtonTextColorDefault;
     DetailTextLabel.text  = detailText;
     if (string.IsNullOrEmpty(iconName) || iconAtlas == null)
     {
         Icon.enabled           = false;
         IconBackground.enabled = false;
     }
     else
     {
         Icon.enabled           = true;
         IconBackground.enabled = true;
         Icon.atlas             = iconAtlas;
         Icon.spriteName        = iconName;
         Icon.color             = iconColor;
         IconBackground.color   = iconBackgroundColor;
     }
     if (dopplegangerProps != null)
     {
         ShowDoppleganger = true;
         DopplegangerProps.CopyFrom(dopplegangerProps);
     }
     else
     {
         ShowDoppleganger = false;
     }
     RefreshDoppleganger();
     LastUser = user;
 }
 public void EnableForBlueprint(GenericWorldItem requiredItemTemplate, BlueprintStrictness strictness)
 {
     mEnabledForBlueprint = true;
     Strictness           = strictness;
     RequiredItemTemplate.CopyFrom(requiredItemTemplate);
 }
Exemple #24
0
        IEnumerator FillContainerOverTime(bool immediately)
        {
            if (!immediately)
            {
                yield return(null);               //wait for a tick to let recepticles etc. update properties
            }

            State.LastFillTime = WorldClock.AdjustedRealTime;
            //fill container
            WIStackError     error                   = WIStackError.None;
            WIStackContainer container               = worlditem.StackContainer;
            int              numDesired              = State.NumberOfItems;
            int              numAdded                = 0;
            int              lastItemIndex           = 0;
            int              maxDuplicates           = 3;
            bool             continueFilling         = true;
            int              hashCode                = Mathf.Abs((worlditem.Group.Props.UniqueID + worlditem.FileName).GetHashCode());
            int              numDuplicates           = 0;
            bool             belowDuplicateThreshold = true;
            GenericWorldItem genericItem             = null;
            WICategory       category                = null;

            IBank bank = null;

            if (State.FillBank)
            {
                Character character = null;
                if (worlditem.Is <Character> (out character) && character.HasBank)
                {
                    bank = character.InventoryBank;
                    Bank.FillWithRandomCurrency(bank, character.State.Flags.Wealth);
                }
            }

            switch (State.NumberOfItemsRandomness)
            {
            case ContainerFillRandomness.Slight:
            default:
                numDesired = Mathf.Max(1, numDesired + UnityEngine.Random.Range(-1, 1));
                break;

            case ContainerFillRandomness.Moderate:
                numDesired = Mathf.Max(1, numDesired + UnityEngine.Random.Range(-5, 5));
                break;

            case ContainerFillRandomness.Extreme:
                numDesired = Mathf.Max(1, numDesired + UnityEngine.Random.Range(-10, 10));
                break;
            }

            yield return(null);

            switch (State.FillMethod)
            {
            case ContainerFillMethod.AllRandomItemsFromCategory:
            default:
                if (WorldItems.Get.Category(State.WICategoryName, out category))
                {
                    Dictionary <string, int> itemsSoFar = new Dictionary <string, int> ();
                    if (category.HasMinInstanceItems)
                    {
                        gMinInstanceItems.Clear();
                        category.GetMinInstanceItems(gMinInstanceItems);
                        for (int i = 0; i < gMinInstanceItems.Count; i++)
                        {
                            if (itemsSoFar.TryGetValue(gMinInstanceItems [i].PrefabName, out numDuplicates))
                            {
                                numDuplicates++;
                                itemsSoFar [gMinInstanceItems [i].PrefabName] = numDuplicates;
                            }
                            else
                            {
                                itemsSoFar.Add(gMinInstanceItems [i].PrefabName, 1);
                            }

                            StackItem item = gMinInstanceItems [i].ToStackItem();

                            if (item != null)
                            {
                                if (State.AddCurrencyToBank && bank != null && item.Is("Currency"))
                                {
                                    bank.Add(Mathf.FloorToInt(item.BaseCurrencyValue), item.CurrencyType);
                                    item.Clear();
                                }
                                else
                                {
                                    //add the generic item to the container as a stack item
                                    if (!Stacks.Add.Items(item, container, ref error))
                                    {
                                        continueFilling = false;
                                    }
                                    else
                                    {
                                        numAdded++;
                                    }
                                }
                            }
                        }
                        gMinInstanceItems.Clear();
                    }

                    yield return(null);

                    while (continueFilling && category.GetItem(State.Flags, hashCode, ref lastItemIndex, out genericItem))
                    {
                        //make sure we don't have a duplicate
                        if (itemsSoFar.TryGetValue(genericItem.PrefabName, out numDuplicates))
                        {
                            numDuplicates++;
                            if (numDuplicates < maxDuplicates)
                            {
                                itemsSoFar [genericItem.PrefabName] = numDuplicates;
                            }
                            else
                            {
                                belowDuplicateThreshold = false;
                            }
                        }
                        else
                        {
                            itemsSoFar.Add(genericItem.PrefabName, 1);
                        }

                        yield return(null);

                        if (belowDuplicateThreshold)
                        {
                            //this might be a currency item - if it is, add it to the bank
                            StackItem item = genericItem.ToStackItem();

                            if (State.AddCurrencyToBank && bank != null && item.Is("Currency"))
                            {
                                bank.Add(Mathf.FloorToInt(item.BaseCurrencyValue), item.CurrencyType);
                                item.Clear();
                            }
                            else
                            {
                                //add the generic item to the container as a stack item
                                if (!Stacks.Add.Items(item, container, ref error))
                                {
                                    continueFilling = false;
                                }
                                else
                                {
                                    numAdded++;
                                }
                            }
                        }

                        //are we done yet?
                        if (numAdded >= numDesired || container.IsFull || !belowDuplicateThreshold)
                        {
                            continueFilling = false;
                        }
                        //wait a tick unless we need to finish this immediately
                        //if (!immediately) {
                        yield return(null);
                        //}
                    }
                }
                break;

            case ContainerFillMethod.OneRandomItemFromCategory:
                if (WorldItems.Get.Category(State.WICategoryName, out category))
                {
                    if (category.GetItem(State.Flags, hashCode, ref lastItemIndex, out genericItem))
                    {
                        for (int i = 0; i < numDesired; i++)
                        {
                            if (!Stacks.Add.Items(genericItem.ToStackItem(), container, ref error))
                            {
                                break;
                            }
                            else
                            {
                                numAdded++;
                            }

                            if (container.IsFull)
                            {
                                break;
                            }
                        }
                    }
                }
                break;

            case ContainerFillMethod.SpecificItems:
                if (WorldItems.Get.Category(State.WICategoryName, out category))
                {
                    for (int i = 0; i < State.SpecificItems.Count; i++)
                    {
                        GenericWorldItem specificItem = State.SpecificItems [i];
                        Stacks.Add.Items(specificItem.ToStackItem(), container, ref error);
                    }
                }
                break;
            }

            State.NumTimesFilled++;
            mIsFilling = false;

            yield return(null);

            if (worlditem.Is <Stolen> ())
            {
                //the goods in a stolen container are also marked as stolen
                Stacks.Add.ScriptToItems(container, "Stolen");
            }

            yield break;
        }