Пример #1
0
        public void UpdateAll(PlacedTileObject[] neighbourObjects)
        {
            // Because we are on a Furniture layer and walls are on the Turf. Discard furniture neighbours and get the turf neighbours.
            if (!map)
            {
                map = GetComponentInParent <TileMap>();
            }

            neighbourObjects = map.GetNeighbourObjects(TileLayer.Turf, 0, transform.position);
            PlacedTileObject currentObject = GetComponent <PlacedTileObject>();

            bool changed = false;

            for (int i = 0; i < neighbourObjects.Length; i++)
            {
                bool updatedSingle = false;
                updatedSingle = UpdateSingleConnection((Direction)i, neighbourObjects[i]);
                if (updatedSingle && neighbourObjects[i])
                {
                    neighbourObjects[i].UpdateSingleAdjacency(TileHelper.GetOpposite((Direction)i), currentObject);
                }

                changed |= updatedSingle;
            }

            if (changed)
            {
                UpdateWallCaps();
            }
        }
Пример #2
0
        /**
         * Adjusts the connections value based on the given new tile.
         * Returns whether value changed.
         */
        private bool UpdateSingleConnection(Direction direction, PlacedTileObject placedObject)
        {
            SetPerpendicularBlocked(true);
            bool isConnected = (placedObject && placedObject.HasAdjacencyConnector() && placedObject.GetGenericType() == TileObjectGenericType.Wall);

            return(adjacencyMap.SetConnection(direction, new AdjacencyData(TileObjectGenericType.None, TileObjectSpecificType.None, isConnected)));
        }
Пример #3
0
        /**
         * Adjusts the connections value based on the given new tile.
         * Returns whether value changed.
         */
        private bool UpdateSingleConnection(Direction direction, PlacedTileObject placedObject)
        {
            SetPerpendicularBlocked(true);
            bool isConnected = (placedObject && placedObject.HasAdjacencyConnector() && placedObject.GetGenericType() == "wall");

            return(adjacents.UpdateDirection(direction, isConnected, true));
        }
Пример #4
0
 public void UpdateSingle(Direction direction, PlacedTileObject placedObject)
 {
     if (UpdateSingleConnection(direction, placedObject))
     {
         UpdateWallCaps();
     }
 }
Пример #5
0
        public override bool CanInteract(InteractionEvent interactionEvent)
        {
            if (RangeCheck && !InteractionExtensions.RangeCheck(interactionEvent))
            {
                return(false);
            }

            if (interactionEvent.Target is IGameObjectProvider targetBehaviour)
            {
                // Get target tile
                // TargetTile = TileManager.Instance.CanBuild()
                TargetPlacedObject = targetBehaviour.GameObject.GetComponentInParent <PlacedTileObject>();
                if (TargetPlacedObject == null)
                {
                    return(false);
                }

                // Ready if no obstacles
                if (ObstacleMask == 0)
                {
                    return(true);
                }

                // Check for obstacle
                Vector3 center   = TargetPlacedObject.gameObject.transform.position;
                bool    obstacle = Physics.CheckBox(center, BuildDimensions / 2, Quaternion.identity, ObstacleMask, QueryTriggerInteraction.Ignore);
                return(!obstacle);
            }

            return(false);
        }
Пример #6
0
        /// <summary>
        /// Ensures that the object is properly initialized.
        /// </summary>
        private void EnsureInit()
        {
            if (!this)
            {
                return;
            }

            if (adjacencyMap == null)
            {
                adjacencyMap = new AdjacencyMap();
            }

            if (!filter)
            {
                filter = GetComponent <MeshFilter>();
            }

            PlacedTileObject placedTileObject = GetComponent <PlacedTileObject>();

            if (placedTileObject == null)
            {
                genericType  = TileObjectGenericType.None;
                specificType = TileObjectSpecificType.None;
            }
            else
            {
                genericType  = placedTileObject.GetGenericType();
                specificType = placedTileObject.GetSpecificType();
            }
        }
Пример #7
0
        private void OpenConstruction(InteractionEvent interactionEvent, InteractionReference arg2)
        {
            // Set selected tile to build on
            var tile = interactionEvent.Target.GetComponent <Transform>().parent.GetComponent <PlacedTileObject>();

            if (tile == selectedTile)
            {
                return;
            }
            selectedTile = tile;

            string material = GetComponent <Item>().Name;

            ConstructionUiData[] uiData = constructions.Select(x => x.ToUi(material)).ToArray();

            NetworkConnection owner = interactionEvent.Source.GetInstanceFromReference(arg2).Owner;

            if (owner == null)
            {
                // F**k you mirror, just act like you love me (or as if you had a connection)
                UpdateUi(uiData);
            }
            else
            {
                TargetUpdateUi(owner, uiData);
            }
        }
Пример #8
0
        private Direction GetDoorDirection()
        {
            if (placedTileObject == null)
            {
                placedTileObject = GetComponent <PlacedTileObject>();
            }

            return(placedTileObject.GetDirection());
        }
Пример #9
0
        public override string GetName(InteractionEvent interactionEvent)
        {
            PlacedTileObject tileObject = (interactionEvent.Target as IGameObjectProvider)?.GameObject?.GetComponentInParent <PlacedTileObject>();

            if (tileObject != null && tileObject.GetGenericType() == TileObjectGenericType.Wall)
            {
                return("Deconstruct");
            }

            return("Construct");
        }
Пример #10
0
        /// <summary>
        /// Update a single direction. Updates meshes if changed.
        /// </summary>
        /// <param name="dir"></param>
        /// <param name="placedObject"></param>
        public void UpdateSingle(Direction dir, PlacedTileObject placedObject)
        {
            if (!this)
            {
                return;
            }

            if (UpdateSingleConnection(dir, placedObject))
            {
                UpdateMeshAndDirection();
            }
        }
Пример #11
0
        protected override void StartDelayed(InteractionEvent interactionEvent)
        {
            var              targetBehaviour    = (IGameObjectProvider)interactionEvent.Target;
            TileManager      tileManager        = TileManager.Instance;
            PlacedTileObject targetPlacedObject = targetBehaviour.GameObject.GetComponentInParent <PlacedTileObject>();

            // var tile = targetPlacedObject.Tile;

            // Deconstruct
            if (targetPlacedObject != null && targetPlacedObject.GetGenericType() == TileObjectGenericType.Wall)
            {
                tileManager.ClearTileObject(TileLayer.Turf, targetPlacedObject.transform.position);
            }
            else // Construct
            {
                tileManager.SetTileObject(WallToConstruct, targetPlacedObject.transform.position, Direction.South);
            }
        }
Пример #12
0
        /// <summary>
        /// Update a single direction.
        /// </summary>
        /// <param name="dir"></param>
        /// <param name="placedObject"></param>
        /// <returns></returns>
        private bool UpdateSingleConnection(Direction dir, PlacedTileObject placedObject)
        {
            // For some reason called before OnAwake()
            EnsureInit();
            UpdateBlockedFromEditor();

            bool isConnected = false;

            if (placedObject)
            {
                isConnected = (placedObject && placedObject.HasAdjacencyConnector());

                // If cross connect is allowed, we only allow it to connect when the object type matches the connector type
                if (CrossConnectAllowed)
                {
                    isConnected &= (placedObject.GetGenericType() == genericType && genericType != "");
                }
                else
                {
                    isConnected &= (placedObject.GetGenericType() == genericType || genericType == null);
                }

                // Check for specific
                isConnected &= (placedObject.GetSpecificType() == specificType || specificType == "");

                isConnected &= (AdjacencyBitmap.Adjacent(blockedConnections, dir) == 0);
            }
            bool isUpdated = adjacents.UpdateDirection(dir, isConnected, true);

            SyncAdjacentConnections(adjacents.Connections, adjacents.Connections);

            // Cross connect will override adjacents for other layers, so return isConnected instead.
            if (CrossConnectAllowed)
            {
                return(isConnected);
            }
            else
            {
                return(isUpdated);
            }
        }
Пример #13
0
        /// <summary>
        /// Update a single direction.
        /// </summary>
        /// <param name="dir"></param>
        /// <param name="placedObject"></param>
        /// <returns></returns>
        private bool UpdateSingleConnection(Direction dir, PlacedTileObject placedObject)
        {
            // For some reason called before OnAwake()
            EnsureInit();
            UpdateBlockedFromEditor();

            bool isConnected = false;

            if (placedObject)
            {
                isConnected = (placedObject && placedObject.HasAdjacencyConnector());

                // If cross connect is allowed, we only allow it to connect when the object type matches the connector type
                if (CrossConnectAllowed)
                {
                    isConnected &= placedObject.GetGenericType() == genericType && genericType != TileObjectGenericType.None;
                }
                else
                {
                    isConnected &= placedObject.GetGenericType() == genericType || genericType == TileObjectGenericType.None;
                }

                // Check for specific
                isConnected &= placedObject.GetSpecificType() == specificType || specificType == TileObjectSpecificType.None;


                isConnected &= ((blockedConnections >> (int)dir) & 0x1) == 0;
            }
            bool isUpdated   = adjacencyMap.SetConnection(dir, new AdjacencyData(TileObjectGenericType.None, TileObjectSpecificType.None, isConnected));
            byte connections = adjacencyMap.SerializeToByte();

            SyncAdjacentConnections(connections, connections);

            // Cross connect will override adjacents for other layers, so return isConnected instead.
            return(CrossConnectAllowed ? isConnected : isUpdated);
        }