protected override void OnRefresh()
        {
            bool enableTakeAll       = false;
            bool enableTakeContainer = false;

            if (ContainerDisplay.HasEnabler && Enabler.HasEnablerContainer)
            {
                ContainerName.text = "Contents of container:";
                WIStackContainer container = Enabler.EnablerContainer;
                IStackOwner      owner     = null;
                if (container.HasOwner(out owner) && owner.IsWorldItem)
                {
                    //the owner will be the world item
                    WorldItem containerWorldItem = container.Owner.worlditem;
                    ContainerDisplay.EnablerDisplay.DopplegangerProps.CopyFrom(containerWorldItem);
                    ContainerDisplay.RefreshRequest();
                    //now check to see if that world item belongs to a non-player group
                    ContainerName.text = "Contents of: " + containerWorldItem.DisplayName;
                    if (containerWorldItem.Group.HasOwner(out owner) && owner == Player.Local)
                    {
                        enableTakeAll = true;
                        if (containerWorldItem.CanEnterInventory)
                        {
                            enableTakeContainer = true;
                        }
                    }
                }
            }
            else
            {
                ContainerName.text = "(No container opened)";
            }
        }
Example #2
0
        public void Start()
        {
            CraftingContainer = Stacks.Create.StackContainer(this, WIGroups.Get.Player);
            CraftingContainer.RefreshAction += RefreshRequest;
            ResultSquare.RefreshAction      += RefreshRequest;

            //temporarily display gather supplies button
            GatherSuppliesButton.gameObject.SetActive(false);

            CraftingSquaresRow0[0].SetStack(CraftingContainer.StackList[0]);
            CraftingSquaresRow0[0].BlueprintPotentiallyChanged += OnBlueprintPotentiallyChanged;
            CraftingSquaresRow0[1].SetStack(CraftingContainer.StackList[1]);
            CraftingSquaresRow0[1].BlueprintPotentiallyChanged += OnBlueprintPotentiallyChanged;
            CraftingSquaresRow0[2].SetStack(CraftingContainer.StackList[2]);
            CraftingSquaresRow0[2].BlueprintPotentiallyChanged += OnBlueprintPotentiallyChanged;

            CraftingSquaresRow1[0].SetStack(CraftingContainer.StackList[3]);
            CraftingSquaresRow1[0].BlueprintPotentiallyChanged += OnBlueprintPotentiallyChanged;
            CraftingSquaresRow1[1].SetStack(CraftingContainer.StackList[4]);
            CraftingSquaresRow1[1].BlueprintPotentiallyChanged += OnBlueprintPotentiallyChanged;
            CraftingSquaresRow1[2].SetStack(CraftingContainer.StackList[5]);
            CraftingSquaresRow1[2].BlueprintPotentiallyChanged += OnBlueprintPotentiallyChanged;

            CraftingSquaresRow2[0].SetStack(CraftingContainer.StackList[6]);
            CraftingSquaresRow2[0].BlueprintPotentiallyChanged += OnBlueprintPotentiallyChanged;
            CraftingSquaresRow2[1].SetStack(CraftingContainer.StackList[7]);
            CraftingSquaresRow2[1].BlueprintPotentiallyChanged += OnBlueprintPotentiallyChanged;
            CraftingSquaresRow2[2].SetStack(CraftingContainer.StackList[8]);
            CraftingSquaresRow2[2].BlueprintPotentiallyChanged += OnBlueprintPotentiallyChanged;

            Rows.Add(CraftingSquaresRow0);
            Rows.Add(CraftingSquaresRow1);
            Rows.Add(CraftingSquaresRow2);

            //make sure to add these in the right order
            //left to right, top to down
            //otherwise the patterns we generate won't match
            //TODO do we really need all these different lists
            mPatternSquares.AddRange(CraftingSquaresRow0);
            mPatternSquares.AddRange(CraftingSquaresRow1);
            mPatternSquares.AddRange(CraftingSquaresRow2);

            Squares.Add(CraftingSquaresRow0[0]);
            Squares.Add(CraftingSquaresRow0[1]);
            Squares.Add(CraftingSquaresRow0[2]);
            Squares.Add(CraftingSquaresRow1[0]);
            Squares.Add(CraftingSquaresRow1[1]);
            Squares.Add(CraftingSquaresRow1[2]);
            Squares.Add(CraftingSquaresRow2[0]);
            Squares.Add(CraftingSquaresRow2[1]);
            Squares.Add(CraftingSquaresRow2[2]);
            Squares.Add(ResultSquare);

            for (int i = 0; i < Squares.Count; i++)
            {
                //to make sure menus show up correctly etc
                Squares[i].NGUICamera = InventoryInterface.NGUICamera;
            }
        }
        public void Initialize()
        {
            if (mInitialized)
            {
                return;
            }

            //Debug.Log("Initializing clothing interface");

            InfoLabel.alpha            = 0f;
            InfoSpriteBackground.alpha = 0f;
            InfoSpriteShadow.alpha     = 0f;

            WIStackContainer upperBodyContainer = Player.Local.Wearables.State.UpperBodyContainer;
            WIStackContainer lowerBodyContainer = Player.Local.Wearables.State.LowerBodyContainer;

            CreateWearableSquare(UpperBodySquaresParent, new Vector3(200f, -50f, -50f), WearableType.Armor, BodyPartType.Head, BodyOrientation.None, upperBodyContainer.StackList[Wearables.UpperBodyHeadIndex]);                                   //head
            CreateWearableSquare(UpperBodySquaresParent, new Vector3(0f, -50f, -50f), WearableType.Clothing | WearableType.Jewelry, BodyPartType.Face, BodyOrientation.None, upperBodyContainer.StackList[Wearables.UpperBodyFaceIndex]);           //face
            CreateWearableSquare(UpperBodySquaresParent, new Vector3(300f, -150f, -50f), WearableType.Armor, BodyPartType.Shoulder, BodyOrientation.Left, upperBodyContainer.StackList[Wearables.UpperBodyLeftShoulderIndex]);                      //left shoulder
            CreateWearableSquare(UpperBodySquaresParent, new Vector3(100f, -150f, -50f), WearableType.Armor, BodyPartType.Shoulder, BodyOrientation.Right, upperBodyContainer.StackList[Wearables.UpperBodyRightShoulderIndex]);                    //right shoulder
            CreateWearableSquare(UpperBodySquaresParent, new Vector3(325f, -250f, -50f), WearableType.Armor, BodyPartType.Arm, BodyOrientation.Left, upperBodyContainer.StackList[Wearables.UpperBodyLeftArmIndex]);                                //left arm
            CreateWearableSquare(UpperBodySquaresParent, new Vector3(75f, -250f, -50f), WearableType.Armor, BodyPartType.Arm, BodyOrientation.Right, upperBodyContainer.StackList[Wearables.UpperBodyRightArmIndex]);                               //right arm
            CreateWearableSquare(UpperBodySquaresParent, new Vector3(400f, -50f, -50f), WearableType.Jewelry, BodyPartType.Neck, BodyOrientation.None, upperBodyContainer.StackList[Wearables.UpperBodyNeckIndex]);                                 //neck
            CreateWearableSquare(UpperBodySquaresParent, new Vector3(200f, -150f, -50f), WearableType.Armor, BodyPartType.Chest, BodyOrientation.None, upperBodyContainer.StackList[Wearables.UpperBodyChestIndex]);                                //chest
            CreateWearableSquare(UpperBodySquaresParent, new Vector3(350f, -350f, -50f), WearableType.Armor | WearableType.Clothing, BodyPartType.Hand, BodyOrientation.Left, upperBodyContainer.StackList[Wearables.UpperBodyLeftHandIndex]);      //left hand
            CreateWearableSquare(UpperBodySquaresParent, new Vector3(50f, -350f, -50f), WearableType.Armor | WearableType.Clothing, BodyPartType.Hand, BodyOrientation.Right, upperBodyContainer.StackList[Wearables.UpperBodyRightHandIndex]);     //right hand

            CreateWearableSquare(LowerBodySquaresParent, new Vector3(200f, -325f, -50f), WearableType.Armor, BodyPartType.Hip, BodyOrientation.None, lowerBodyContainer.StackList[Wearables.LowerBodyHipIndex]);                                    //hips
            //CreateWearableSquare (LowerBodySquaresParent, new Vector3 (250f, -350f, -50f), WearableType.Container, BodyPartType.Hip, BodyOrientation.Right, lowerBodyContainer.StackList [Wearables.LowerBodyRightHipIndex]);//right hip
            CreateWearableSquare(LowerBodySquaresParent, new Vector3(250f, -450f, -50f), WearableType.Armor, BodyPartType.Leg, BodyOrientation.Left, lowerBodyContainer.StackList[Wearables.LowerBodyLeftKneeIndex]);                               //left knee
            CreateWearableSquare(LowerBodySquaresParent, new Vector3(150, -450f, -50f), WearableType.Armor, BodyPartType.Leg, BodyOrientation.Right, lowerBodyContainer.StackList[Wearables.LowerBodyRightKneeIndex]);                              //right knee
            CreateWearableSquare(LowerBodySquaresParent, new Vector3(250f, -650f, -50f), WearableType.Clothing, BodyPartType.Foot, BodyOrientation.Left, lowerBodyContainer.StackList[Wearables.LowerBodyLeftFootIndex]);                           //left foot
            CreateWearableSquare(LowerBodySquaresParent, new Vector3(150f, -650f, -50f), WearableType.Clothing, BodyPartType.Foot, BodyOrientation.Right, lowerBodyContainer.StackList[Wearables.LowerBodyRightFoodIndex]);                         //right foot
            CreateWearableSquare(LowerBodySquaresParent, new Vector3(250f, -550f, -50f), WearableType.Armor, BodyPartType.Shin, BodyOrientation.Left, lowerBodyContainer.StackList[Wearables.LowerBodyLeftShinIndex]);                              //left shin
            CreateWearableSquare(LowerBodySquaresParent, new Vector3(150f, -550f, -50f), WearableType.Armor, BodyPartType.Shin, BodyOrientation.Right, lowerBodyContainer.StackList[Wearables.LowerBodyRightShinIndex]);                            //right shin
            CreateWearableSquare(LowerBodySquaresParent, new Vector3(400f, -475f, -50f), WearableType.Jewelry, BodyPartType.Finger, BodyOrientation.Left, lowerBodyContainer.StackList[Wearables.LowerBodyLeftFingerIndex]);                        //left finger
            CreateWearableSquare(LowerBodySquaresParent, new Vector3(0f, -475f, -50f), WearableType.Jewelry, BodyPartType.Finger, BodyOrientation.Right, lowerBodyContainer.StackList[Wearables.LowerBodyRightFingerIndex]);                        //right finger

            StatButtons.Clear();
            BoxCollider b = null;

            foreach (Transform t in HeatProtection.transform.parent)
            {
                if (t.gameObject.HasComponent <BoxCollider>(out b))
                {
                    StatButtons.Add(b);
                }
            }

            mInitialized = true;

            Refresh();
        }
Example #4
0
        protected IEnumerator TryToFillBookcase()
        {
            if (State.HasBeenFilled)
            {
                yield break;
            }

            State.HasBeenFilled = true;

            while (worlditem.Group == null)
            {
                //wait for on initialized to finish working
                yield return(null);
            }

            WIStackContainer stackContainer   = worlditem.StackContainer;
            List <StackItem> avatarStackItems = new List <StackItem>();

            switch (State.FillMethod)
            {
            case ContainerFillMethod.AllRandomItemsFromCategory:
            default:
                var getStackItemsByBookAndOwner = Books.Get.BookStackItemsByFlagsAndOwner(stackContainer.NumStacks, State.Flags, State.ManualSkillLevel, worlditem, true, avatarStackItems);
                while (getStackItemsByBookAndOwner.MoveNext())
                {
                    yield return(getStackItemsByBookAndOwner.Current);
                }
                break;

            case ContainerFillMethod.SpecificItems:
                Books.Get.BookStackItemsByName(State.SpecificBooks, avatarStackItems);
                break;
            }

            WIStackError error = WIStackError.None;

            for (int i = 0; i < avatarStackItems.Count; i++)
            {
                if (!Stacks.Push.Item(stackContainer, avatarStackItems[i], ref error))
                {
                    break;
                }
                yield return(null);
            }
            yield return(null);

            //wait for one last bit, then refresh our recepticle
            worlditem.Get <Receptacle>().Refresh();
            yield break;
        }
Example #5
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;
        }