Esempio n. 1
0
        public virtual bool AddToReceptacle(WorldItem potentialOccupant)
        {
            if (State.Locked)
            {
                return(false);
            }

            if (mCooldownStartTime + mCooldownInterval > WorldClock.RealTime)
            {
                return(false);
            }

            bool            result     = false;
            ReceptaclePivot emptyPivot = null;

            if (HasRoom(potentialOccupant, out emptyPivot) && IsObjectPermitted(potentialOccupant, emptyPivot.Settings))
            {
                //first we have to move the potential occupant into our group
                WIStack      pivotStack = worlditem.StackContainer.StackList [emptyPivot.State.Index];
                WIStackError error      = WIStackError.None;
                result = Stacks.Push.Item(pivotStack, potentialOccupant, ref error);
            }

            if (result)
            {
                potentialOccupant.OnRemoveFromStack        += Refresh;
                potentialOccupant.OnUnloaded               += Refresh;
                potentialOccupant.OnAddedToPlayerInventory += Refresh;
                OnItemPlacedInReceptacle.SafeInvoke();
                emptyPivot.Refresh();
            }

            return(result);
        }
Esempio n. 2
0
        public bool HasRoom(WorldItem potentialOccupant, Vector3 point, out ReceptaclePivot emptyPivot)
        {
            emptyPivot = null;

            if (State.Locked)
            {
                return(false);
            }

            float closestSoFar = Mathf.Infinity;

            for (int i = 0; i < Pivots.Count; i++)
            {
                ReceptaclePivot pivot = Pivots [i];
                if (!pivot.IsOccupied)
                {
                    float distance = Vector3.Distance(point, pivot.PivotBounds.center);
                    if (distance < closestSoFar)
                    {
                        emptyPivot   = pivot;
                        closestSoFar = distance;
                    }
                }
            }
            return(emptyPivot != null);
        }
Esempio n. 3
0
        public bool CheckKeyItemRequirements()
        {
            bool requirementsMet = false;

            for (int i = 0; i < KeyReceptacle.Pivots.Count; i++)
            {
                ReceptaclePivot pivot = KeyReceptacle.Pivots [i];
                if (pivot.IsOccupied)
                {
                    if (pivot.Occupant.PackName == State.KeyItemRequirements.PackName &&
                        pivot.Occupant.PrefabName == State.KeyItemRequirements.PrefabName &&
                        (string.IsNullOrEmpty(State.KeyItemRequirements.State) || pivot.Occupant.State == State.KeyItemRequirements.State) &&
                        (string.IsNullOrEmpty(State.QuestNameRequirement) || pivot.Occupant.QuestName == State.QuestNameRequirement))
                    {
                        requirementsMet = true;
                        break;
                    }
                    else
                    {
                        Debug.Log("Occupant " + pivot.Occupant.DisplayName + " doesn't meet requirements " + State.KeyItemRequirements.ToString());
                    }
                }
            }
            return(requirementsMet);
        }
Esempio n. 4
0
        public ReceptaclePivot AddPivot(Transform pivotTransform)
        {
            Transform       newPivotTransform = pivotTransform;
            ReceptaclePivot newPivot          = newPivotTransform.gameObject.AddComponent <ReceptaclePivot> ();

            newPivot.ParentReceptacle            = this;
            newPivot.State                       = new ReceptaclePivotState();
            newPivot.State.InheritParentSettings = true;
            newPivot.State.Index                 = State.PivotStates.Count;
            Pivots.Add(newPivot);
            State.PivotStates.Add(newPivot.State);
            newPivot.OnInitialized();
            worlditem.StackContainer.SetNumStacks(Pivots.Count);
            return(newPivot);
        }
Esempio n. 5
0
        protected virtual bool AddToReceptaclePivot(WorldItem potentialOccupant, ReceptaclePivot pivotInFocus)
        {
            if (State.Locked || mAddingToReceptaclePivot)
            {
                return(false);
            }

            if (pivotInFocus.IsOccupied || !IsObjectPermitted(potentialOccupant, pivotInFocus.Settings))
            {
                return(false);
            }

            mAddingToReceptaclePivot = true;
            StartCoroutine(AddToReceptaclePivotOverTime(potentialOccupant, pivotInFocus));
            return(true);
        }
Esempio n. 6
0
        public override void PopulateOptionsList(List <WIListOption> options, List <string> message)
        {
            if (State.Locked || mAddingToReceptaclePivot)
            {
                return;
            }

            if (Player.Local.Tool.IsEquipped)
            {
                //see if there's a spot for this thing
                ReceptaclePivot emptyPivot = null;
                if (HasRoom(Player.Local.Tool.worlditem, out emptyPivot) && IsObjectPermitted(Player.Local.Tool.worlditem, emptyPivot.Settings))
                {
                    options.Add(new WIListOption("Place " + Player.Local.Tool.worlditem.DisplayName, "Place"));
                }
            }
        }
Esempio n. 7
0
        public ReceptaclePivot GetClosestPivot(Vector3 point)
        {
            ReceptaclePivot closestPivot = null;
            float           closestSoFar = Mathf.Infinity;

            for (int i = 0; i < Pivots.Count; i++)
            {
                ReceptaclePivot pivot    = Pivots [i];
                float           distance = Vector3.Distance(point, pivot.PivotBounds.center);
                if (distance < closestSoFar)
                {
                    closestPivot = pivot;
                    closestSoFar = distance;
                }
            }
            mLastPointChecked = point;
            return(closestPivot);
        }
Esempio n. 8
0
        public override void OnInitialized()
        {
            worlditem.OnGainPlayerFocus += OnGainPlayerFocus;
            worlditem.OnPlayerUse       += OnPlayerUse;
            worlditem.OnVisible         += OnVisible;
            worlditem.OnActive          += OnActive;
            //if we're a container, make sure the container uses the right settings
            Container container = worlditem.GetOrAdd <Container> ();

            worlditem.StackContainer.Mode = WIStackMode.Receptacle;
            container.CanUseToOpen        = false;
            container.CanOpen             = false;

            if (State.PivotStates.Count > 0)
            {
                //load the pivots from the states
                for (int i = 0; i < State.PivotStates.Count; i++)
                {
                    ReceptaclePivot pivot = Pivots [i];
                    pivot.ParentReceptacle = this;
                    pivot.State            = State.PivotStates [i];
                    pivot.State.Index      = i;
                    pivot.OnInitialized();
                }
            }
            else
            {
                //this is our first time loading, load the pivot states
                //from the actual pivot objects
                int pivotIndex = 0;
                for (int i = 0; i < Pivots.Count; i++)
                {
                    ReceptaclePivot pivot = Pivots [i];                    // child.GetComponent <ReceptaclePivot> ();
                    pivot.ParentReceptacle = this;
                    pivot.State.Offset     = new STransform(pivot.transform, true);
                    pivot.State.Index      = pivotIndex;
                    pivot.OnInitialized();
                    State.PivotStates.Add(pivot.State);
                    pivotIndex++;
                }
            }
            worlditem.StackContainer.SetNumStacks(Pivots.Count);
        }
Esempio n. 9
0
        public static void ShowPivotVisualizers(ReceptaclePivot pivotInFocus, List <ReceptaclePivot> pivots, ReceptacleVisualStyle visualStyle)
        {
            switch (visualStyle)
            {
            case ReceptacleVisualStyle.Projector:
            default:
                while (pivots.Count > gReceptacleProjectors.Count)
                {
                    GameObject newProjectorGameObject = new GameObject("ReceptacleProjector");
                    Projector  newProjector           = newProjectorGameObject.AddComponent <Projector> ();
                    newProjectorGameObject.layer  = Globals.LayerNumScenery;
                    newProjector.enabled          = false;
                    newProjector.orthographic     = true;
                    newProjector.orthographicSize = 0.15f;
                    newProjector.nearClipPlane    = 0.1f;
                    newProjector.farClipPlane     = 0.6f;
                    newProjector.material         = Mats.Get.ReceptacleProjectorMaterial;
                    newProjector.ignoreLayers     = ~Globals.LayerWorldItemActive;
                    gReceptacleProjectors.Add(newProjector);
                }

                for (int i = 0; i < pivots.Count; i++)
                {
                    if (pivots [i].IsOccupied)
                    {
                        gReceptacleProjectors [i].enabled = false;
                    }
                    else
                    {
                        gReceptacleProjectors [i].transform.position = pivots [i].tr.position + pivots [i].tr.up * 0.5f;
                        gReceptacleProjectors [i].transform.LookAt(pivots [i].tr.position);
                        gReceptacleProjectors [i].enabled = true;
                    }
                }
                break;

            case ReceptacleVisualStyle.GeneralDoppleganger:
                break;

            case ReceptacleVisualStyle.SpecificDoppleganger:
                break;
            }
        }
Esempio n. 10
0
        public bool HasRoom(WorldItem potentialOccupant, out ReceptaclePivot emptyPivot)
        {
            emptyPivot = null;

            if (State.Locked)
            {
                return(false);
            }

            for (int i = 0; i < Pivots.Count; i++)
            {
                ReceptaclePivot pivot = Pivots [i];
                if (!pivot.IsOccupied)
                {
                    emptyPivot = pivot;
                    break;
                }
            }
            return(emptyPivot != null);
        }
Esempio n. 11
0
        public static bool CanOccupantFit(WorldItem potentialOccupant, ReceptaclePivot pivotInFocus, List <ReceptaclePivot> pivots)
        {
                        #if UNITY_EDITOR
            /*
             *                      if (gVisualizationIntersect == null) {
             *                              gVisualizationIntersect = GameObject.CreatePrimitive (PrimitiveType.Cube);
             *                              gVisualizationIntersect.renderer.material = Mats.Get.ItemPlacementMaterial;
             *                              gVisualizationIntersect.renderer.material.color = Color.red;
             *                              gVisualizationIntersect.collider.enabled = false;
             *                              gVisualizationIntersect.layer = Globals.LayerNumScenery;
             *
             *                              gVisualizationItem = GameObject.CreatePrimitive (PrimitiveType.Cube);
             *                              gVisualizationItem.renderer.material = Mats.Get.ItemPlacementMaterial;
             *                              gVisualizationItem.renderer.material.color = Color.yellow;
             *                              gVisualizationItem.collider.enabled = false;
             *                              gVisualizationItem.layer = Globals.LayerNumScenery;
             *                      }
             */
                        #endif
            //check the size collider against all the other colliders in the recepticle
            //start by figuring out how big the occupant is
            gReceptacleBounds.center = pivotInFocus.tr.position;
            gReceptacleBounds.size   = potentialOccupant.BaseObjectBounds.size;

                        #if UNITY_EDITOR
            /*
             *                      gVisualizationItem.transform.localScale = gReceptacleBounds.size;
             *                      gVisualizationItem.transform.position = gReceptacleBounds.center + potentialOccupant.BasePivotOffset;
             *                      gVisualizationItem.renderer.enabled = true;
             *                      gVisualizationIntersect.renderer.enabled = false;
             */
                        #endif

            for (int i = 0; i < pivots.Count; i++)
            {
                if (pivots [i] == pivotInFocus)
                {
                    continue;
                }

                if (pivots [i].IsOccupied)
                {
                    gColliderBounds        = pivots [i].Occupant.BaseObjectBounds;
                    gColliderBounds.center = pivots [i].tr.position + pivots [i].Occupant.BasePivotOffset;

                    if (gReceptacleBounds.Intersects(gColliderBounds))
                    {
                                                #if UNITY_EDITOR
                        /*
                         *                                              gVisualizationIntersect.transform.localScale = gColliderBounds.size;
                         *                                              gVisualizationIntersect.transform.position = gColliderBounds.center + pivots [i].Occupant.BasePivotOffset;
                         *                                              gVisualizationIntersect.renderer.enabled = true;
                         */
                                                #endif
                        return(false);
                    }
                }
            }

            return(true);
        }
Esempio n. 12
0
        protected IEnumerator AddToReceptaclePivotOverTime(WorldItem potentialOccupant, ReceptaclePivot pivotInFocus)
        {
            //remove it from any situation that could cause a c**k-up
            worlditem.Group.AddChildItem(potentialOccupant);
            potentialOccupant.SetMode(WIMode.World);
            //this will put it into the world and un-equip it etc
            //wait for that to happen
            yield return(null);

            WIStack      pivotStack = worlditem.StackContainer.StackList [pivotInFocus.State.Index];
            WIStackError error      = WIStackError.None;

            //do not auto convert to stack item
            if (!Stacks.Push.Item(pivotStack, potentialOccupant, StackPushMode.Manual, ref error))
            {
                Debug.Log("Couldn't push item into group because " + error.ToString());
                yield break;
            }
            //wait again for the worlditem to get situated
            yield return(null);

            potentialOccupant.OnRemoveFromStack += Refresh;
            potentialOccupant.OnModeChange      += Refresh;
            potentialOccupant.tr.parent          = pivotInFocus.tr;
            //this will move it into the recepticle position
            pivotInFocus.Refresh();
            yield return(null);

            OnItemPlacedInReceptacle.SafeInvoke();
            mAddingToReceptaclePivot = false;
        }
Esempio n. 13
0
        public void FixedUpdate()
        {
            if (State.Locked)
            {
                return;
            }

            if (!worlditem.HasPlayerFocus)
            {
                mShowingHUD = false;
                HidePivotVisualizers();
                WorldItems.ReturnDoppleganger(FocusDoppleganger);
                if (PivotInFocus != null)
                {
                    PivotInFocus.FocusOnOccupant(false);
                }
                ItemToPlace  = null;
                PivotInFocus = null;
                enabled      = false;
                return;
            }
            else if (!Player.Local.ItemPlacement.PlacementModeEnabled)
            {
                //don't let item placement force us to disable
                mShowingHUD = false;
                HidePivotVisualizers();
                WorldItems.ReturnDoppleganger(FocusDoppleganger);
                if (PivotInFocus != null)
                {
                    PivotInFocus.FocusOnOccupant(false);
                }
                ItemToPlace  = null;
                PivotInFocus = null;
                return;
            }

            bool useDoppleganger = false;

            ItemToPlace = null;
            ReceptaclePivot newPivotInFocus = GetClosestPivot(Player.Local.Surroundings.WorldItemFocusHitInfo.point);

            if (PivotInFocus != null && PivotInFocus != newPivotInFocus)
            {
                PivotInFocus.FocusOnOccupant(false);
            }
            PivotInFocus            = newPivotInFocus;
            FocusPlacementPermitted = false;

            if (PivotInFocus.IsOccupied)
            {
                //we want to highlight the item so we can pick it up
                PivotInFocus.FocusOnOccupant(true);
            }
            else
            {
                //if the player is holding something, highlight it for placement
                if (Player.Local.Tool.IsEquipped)
                {
                    ItemToPlace = Player.Local.Tool.worlditem;
                }
                else if (Player.Local.ItemPlacement.IsCarryingSomething)
                {
                    ItemToPlace = Player.Local.ItemPlacement.CarryObject;
                }
                if (ItemToPlace != null)
                {
                    //get where our player is focusing
                    string errorMessage = string.Empty;
                    if (IsObjectPermitted(ItemToPlace, PivotInFocus.Settings) && ItemToPlace.CanBePlacedOn(this.worlditem, PivotInFocus.tr.position, PivotInFocus.tr.up, ref errorMessage))
                    {
                        //create a doppleganger showing what the player could place here if he wanted
                        FocusDoppleganger = WorldItems.GetDoppleganger(ItemToPlace, PivotInFocus.tr, FocusDoppleganger, WIMode.Placing, 1f / PivotInFocus.tr.lossyScale.x);
                        //check to see if the potential occupant will actually fix
                        FocusDoppleganger.transform.parent        = PivotInFocus.tr;
                        FocusDoppleganger.transform.localPosition = Vector3.zero + ItemToPlace.BasePivotOffset;
                        FocusDoppleganger.transform.localRotation = Quaternion.identity;

                        Mats.Get.ItemPlacementOutlineMaterial.SetColor("_OutlineColor", Colors.Get.MessageSuccessColor);
                        Mats.Get.ItemPlacementMaterial.SetColor("_TintColor", Colors.Get.MessageSuccessColor);
                        if (CanOccupantFit(ItemToPlace, PivotInFocus, Pivots))
                        {
                            FocusPlacementPermitted = true;
                        }
                        else
                        {
                            Mats.Get.ItemPlacementOutlineMaterial.SetColor("_OutlineColor", Colors.Get.MessageDangerColor);
                            Mats.Get.ItemPlacementMaterial.SetColor("_TintColor", Colors.Get.MessageDangerColor);
                        }
                        //this will show the place / pick up commands
                        worlditem.RefreshHud();
                        useDoppleganger = true;
                    }
                    else
                    {
                        FocusPlacementPermitted = false;
                    }
                }
            }

            if (ItemToPlace != null)
            {
                ShowPivotVisualizers(PivotInFocus, Pivots, VisualStyle);
            }

            if (!useDoppleganger && FocusDoppleganger != null)
            {
                GameObject.Destroy(FocusDoppleganger);
            }
        }