private void OnDestroy()
 {
     if (base.enabled)
     {
         WallChunkArchitect componentInParent = base.transform.GetComponentInParent <WallChunkArchitect>();
         if (componentInParent)
         {
             componentInParent.HideToggleAdditionIcon();
         }
     }
 }
        public void Show(IStructureSupport ghost, IStructureSupport support, Collider supportCol, float offsetWithSupport)
        {
            Transform transform  = (ghost as MonoBehaviour).transform;
            Transform transform2 = (support as MonoBehaviour).transform;

            if (support is WallChunkArchitect)
            {
                if (this._showHorizontalGrid)
                {
                    WallChunkArchitect wallChunkArchitect = (WallChunkArchitect)support;
                    Vector3            position           = transform2.position;
                    position.y = support.GetLevel() + offsetWithSupport;
                    this._horizontal.position            = position;
                    this._horizontal.rotation            = Quaternion.LookRotation(transform2.forward);
                    this._horizontal.localScale          = new Vector3(1f, 1f, Vector3.Distance(wallChunkArchitect.P1, wallChunkArchitect.P2));
                    this._horizontalMat.mainTextureScale = new Vector2(6.25f, 5f * this._horizontal.localScale.z);
                    this._horizontal.gameObject.SetActive(true);
                }
                if (this._showVerticalGrid)
                {
                    Vector3 position2 = transform.position;
                    position2.y          = support.GetLevel();
                    this._edge1.position = position2;
                    int count = ghost.GetMultiPointsPositions(true).Count;
                    if (count > 0)
                    {
                        Vector3 forward = ghost.GetMultiPointsPositions(true).Last <Vector3>() - position2;
                        forward.y            = 0f;
                        this._edge1.rotation = Quaternion.LookRotation(forward);
                    }
                    else
                    {
                        this._edge1.rotation = this._horizontal.rotation;
                    }
                    this._edge1.gameObject.SetActive(true);
                    if (count > 1)
                    {
                        this._edge2.position = position2;
                        Vector3 forward2 = ghost.GetMultiPointsPositions(true).First <Vector3>() - position2;
                        forward2.y           = 0f;
                        this._edge2.rotation = Quaternion.LookRotation(forward2);
                        this._edge2.gameObject.SetActive(true);
                    }
                    else
                    {
                        this._edge2.gameObject.SetActive(false);
                    }
                }
            }
        }
Exemple #3
0
        private bool CheckForDoubledUpGhost(WallArchitect.HorizontalSegment hs)
        {
            float   maxDistance = 1f;
            Vector3 vector      = Vector3.Cross((hs._p2 - hs._p1).normalized, Vector3.up) * 0.75f;
            Vector3 origin      = Vector3.Lerp(hs._p1, hs._p2, 0.5f) + Vector3.up - vector;

            origin.y += 0.1f;
            int mask = LayerMask.GetMask(new string[]
            {
                "PickUp",
                "Prop"
            });
            int        num = 1 << LayerMask.NameToLayer("PickUp") | 1 << LayerMask.NameToLayer("Prop");
            RaycastHit raycastHit;

            if (Physics.SphereCast(origin, 0.25f, vector, out raycastHit, maxDistance, mask))
            {
                Collider collider = raycastHit.collider;
                if (collider.transform.parent)
                {
                    WallChunkArchitect component = collider.transform.parent.GetComponent <WallChunkArchitect>();
                    if (component)
                    {
                        Vector3 normalized = (component.P1 - component.P2).normalized;
                        float   num2       = Vector3.Dot(normalized, (hs._p1 - hs._p2).normalized);
                        if (Mathf.Abs(num2) > 0.98f)
                        {
                            float num3 = Vector3.Dot(normalized, (hs._p1 - component.P1).normalized);
                            float num4 = Vector3.Dot(-normalized, (hs._p2 - component.P2).normalized);
                            if (num2 > 0f)
                            {
                                if (num3 <= 0f || num4 <= 0f)
                                {
                                    return(false);
                                }
                            }
                            else if (-num3 <= 0f || -num4 <= 0f)
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            return(true);
        }
Exemple #4
0
        protected virtual void OnBuilt(GameObject built)
        {
            this.HideToggleAdditionIcon();
            WallChunkArchitect component = built.GetComponent <WallChunkArchitect>();

            component._multiPointsPositions = this._multiPointsPositions;
            component._p1            = this._p1;
            component._p2            = this._p2;
            component._addition      = this._addition;
            component._height        = this._height;
            component._wasBuilt      = true;
            component.CurrentSupport = this.CurrentSupport;
            if (this.CurrentSupport != null)
            {
                this.CurrentSupport.Enslaved = true;
            }
        }
 public override void UpdateAddition(WallChunkArchitect.Additions addition)
 {
     if (!this._wasBuilt && this.IsDoor(this._addition) && !this.IsDoor(addition))
     {
         UnityEngine.Object.Destroy(base.gameObject.GetComponent<WallDefensiveGateAddition>());
     }
     this._addition = addition;
     if (!this._wasBuilt && this.IsDoor(this._addition) && !BoltNetwork.isClient)
     {
         if (!base.gameObject.GetComponent<WallDefensiveGateAddition>())
         {
             base.gameObject.AddComponent<WallDefensiveGateAddition>();
         }
         else
         {
             base.gameObject.GetComponent<WallDefensiveGateAddition>().Start();
         }
     }
 }
 protected virtual WallChunkArchitect.Additions SegmentNextAddition(WallChunkArchitect.Additions addition)
 {
     if (addition == WallChunkArchitect.Additions.Wall)
     {
         return WallChunkArchitect.Additions.Window;
     }
     if (addition == WallChunkArchitect.Additions.Window && Mathf.Abs(Vector3.Dot((this._p2 - this._p1).normalized, Vector3.up)) < this._doorAdditionMaxSlope)
     {
         return WallChunkArchitect.Additions.Door1;
     }
     if (addition == WallChunkArchitect.Additions.Door1 && Mathf.Abs(Vector3.Dot((this._p2 - this._p1).normalized, Vector3.up)) < this._doorAdditionMaxSlope)
     {
         return WallChunkArchitect.Additions.Door2;
     }
     return WallChunkArchitect.Additions.Wall;
 }
 public virtual void UpdateAddition(WallChunkArchitect.Additions addition)
 {
     this._addition = addition;
     UnityEngine.Object.Destroy(this._wallRoot.gameObject);
     this._wallRoot = this.SpawnEdge();
     this._wallRoot.parent = base.transform;
     if (!this._wasBuilt && this._addition >= WallChunkArchitect.Additions.Door1 && this._addition <= WallChunkArchitect.Additions.LockedDoor2)
     {
         Vector3 position = Vector3.Lerp(this._p1, this._p2, 0.5f);
         position.y -= this._logWidth / 2f;
         Vector3 worldPosition = (this._addition != WallChunkArchitect.Additions.Door1) ? this._p1 : this._p2;
         worldPosition.y = position.y;
         Transform transform = (Transform)UnityEngine.Object.Instantiate(Prefabs.Instance.DoorGhostPrefab, position, this._wallRoot.rotation);
         transform.LookAt(worldPosition);
         transform.parent = this._wallRoot;
     }
 }
Exemple #8
0
        private IEnumerator OnPlaced()
        {
            base.enabled = false;
            yield return(null);

            if (!this._autofillmode && this.CanLock && this._multiPointsPositions.Last <Vector3>() != this._multiPointsPositions.First <Vector3>())
            {
                this.LockCurrentPoint();
            }
            if (Scene.HudGui)
            {
                Scene.HudGui.WallConstructionIcons.Shutdown();
            }
            if (this._tmpEdge != null && this._tmpEdge._root)
            {
                this._tmpEdge._root.parent = null;
                UnityEngine.Object.Destroy(this._tmpEdge._root.gameObject);
            }
            LocalPlayer.Create.Grabber.ClosePlace();
            int   chunkCount  = 0;
            float lengthCount = 0f;

            for (int i = 0; i < this._edges.Count; i++)
            {
                WallArchitect.Edge edge = this._edges[i];
                float height            = (!this._autofillmode) ? edge._height : this._currentHeight;
                lengthCount += edge._hlength;
                for (int j = 0; j < edge._segments.Length; j++)
                {
                    WallArchitect.HorizontalSegment horizontalSegment = edge._segments[j];
                    if (this.CheckForDoubledUpGhost(horizontalSegment))
                    {
                        IStructureSupport segmentSupport = this.GetSegmentSupport(horizontalSegment);
                        if (BoltNetwork.isRunning)
                        {
                            PlaceWallChunk     placeWallChunk     = PlaceWallChunk.Create(GlobalTargets.OnlyServer);
                            CoopWallChunkToken coopWallChunkToken = new CoopWallChunkToken();
                            coopWallChunkToken.P1 = horizontalSegment._p1;
                            coopWallChunkToken.P2 = horizontalSegment._p2;
                            coopWallChunkToken.PointsPositions = this.MultiPointsPositions.ToArray();
                            coopWallChunkToken.Additions       = WallChunkArchitect.Additions.Wall;
                            coopWallChunkToken.Height          = height;
                            placeWallChunk.parent  = ((segmentSupport == null) ? base.transform.GetComponentInParent <BoltEntity>() : (segmentSupport as Component).GetComponentInParent <BoltEntity>());
                            placeWallChunk.token   = coopWallChunkToken;
                            placeWallChunk.prefab  = this.ChunkPrefab.GetComponent <BoltEntity>().prefabId;
                            placeWallChunk.support = null;
                            placeWallChunk.Send();
                        }
                        else
                        {
                            WallChunkArchitect wallChunkArchitect = UnityEngine.Object.Instantiate <WallChunkArchitect>(this.ChunkPrefab);
                            wallChunkArchitect.transform.parent   = ((segmentSupport == null) ? base.transform.parent : (segmentSupport as Component).transform);
                            wallChunkArchitect.transform.position = horizontalSegment._p1;
                            wallChunkArchitect.transform.LookAt(horizontalSegment._p2);
                            wallChunkArchitect.MultipointPositions = this._multiPointsPositions;
                            wallChunkArchitect.P1             = horizontalSegment._p1;
                            wallChunkArchitect.P2             = horizontalSegment._p2;
                            wallChunkArchitect.CurrentSupport = segmentSupport;
                            wallChunkArchitect.Height         = height;
                        }
                        chunkCount++;
                    }
                }
            }
            if (!base.GetType().IsSubclassOf(typeof(WallArchitect)))
            {
                EventRegistry.Achievements.Publish(TfEvent.Achievements.PlacedWall, Mathf.FloorToInt(lengthCount));
            }
            if (!BoltNetwork.isRunning)
            {
                yield return(null);

                yield return(null);

                yield return(null);

                yield return(null);

                UnityEngine.Object.Destroy(base.gameObject);
            }
            else
            {
                CoopDestroyPredictedGhost coopDestroyPredictedGhost = base.gameObject.AddComponent <CoopDestroyPredictedGhost>();
                coopDestroyPredictedGhost.count = (float)chunkCount;
                coopDestroyPredictedGhost.delay = 0.005f;
                base.gameObject.AddComponent <destroyAfter>().destroyTime = 2f;
            }
            yield break;
        }
Exemple #9
0
        private void ToggleBackToWall()
        {
            WallDefensiveGateArchitect component = base.GetComponent <WallDefensiveGateArchitect>();

            if (component.WasBuilt)
            {
                UnityEngine.Object.Destroy(this);
            }
            else
            {
                bool    is2Sided = component.Is2Sided;
                Vector3 vector   = (!is2Sided) ? component.P2 : Vector3.Lerp(component.P1, component.P2, 0.5f);
                if (BoltNetwork.isRunning)
                {
                    PrefabId           prefabId           = Prefabs.Instance.WallDefensiveChunkGhostPrefab.GetComponent <BoltEntity>().prefabId;
                    PlaceWallChunk     placeWallChunk     = PlaceWallChunk.Create(GlobalTargets.OnlyServer);
                    CoopWallChunkToken coopWallChunkToken = new CoopWallChunkToken();
                    coopWallChunkToken.P1 = component.P1;
                    coopWallChunkToken.P2 = vector;
                    coopWallChunkToken.PointsPositions = null;
                    coopWallChunkToken.Additions       = WallChunkArchitect.Additions.Wall;
                    coopWallChunkToken.Height          = component.Height;
                    placeWallChunk.parent  = ((!base.transform.parent) ? null : base.transform.parent.GetComponentInParent <BoltEntity>());
                    placeWallChunk.token   = coopWallChunkToken;
                    placeWallChunk.prefab  = prefabId;
                    placeWallChunk.support = null;
                    placeWallChunk.Send();
                    if (is2Sided)
                    {
                        PlaceWallChunk     placeWallChunk2     = PlaceWallChunk.Create(GlobalTargets.OnlyServer);
                        CoopWallChunkToken coopWallChunkToken2 = new CoopWallChunkToken();
                        coopWallChunkToken2.P1 = vector;
                        coopWallChunkToken2.P2 = component.P2;
                        coopWallChunkToken2.PointsPositions = null;
                        coopWallChunkToken2.Additions       = WallChunkArchitect.Additions.Wall;
                        coopWallChunkToken2.Height          = component.Height;
                        placeWallChunk2.parent  = ((!base.transform.parent) ? null : base.transform.parent.GetComponentInParent <BoltEntity>());
                        placeWallChunk2.token   = coopWallChunkToken2;
                        placeWallChunk2.prefab  = prefabId;
                        placeWallChunk2.support = null;
                        placeWallChunk2.Send();
                    }
                }
                else
                {
                    WallChunkArchitect wallChunkArchitect = UnityEngine.Object.Instantiate <WallDefensiveChunkArchitect>(Prefabs.Instance.WallDefensiveChunkGhostPrefab);
                    if (base.transform.parent)
                    {
                        wallChunkArchitect.transform.parent = base.transform.parent;
                    }
                    wallChunkArchitect.transform.position = component.P1;
                    wallChunkArchitect.transform.LookAt(vector);
                    wallChunkArchitect.MultipointPositions = null;
                    wallChunkArchitect.P1             = component.P1;
                    wallChunkArchitect.P2             = vector;
                    wallChunkArchitect.CurrentSupport = component.CurrentSupport;
                    wallChunkArchitect.Height         = component.Height;
                    if (is2Sided)
                    {
                        WallChunkArchitect wallChunkArchitect2 = UnityEngine.Object.Instantiate <WallDefensiveChunkArchitect>(Prefabs.Instance.WallDefensiveChunkGhostPrefab);
                        if (base.transform.parent)
                        {
                            wallChunkArchitect2.transform.parent = base.transform.parent;
                        }
                        wallChunkArchitect2.transform.position = vector;
                        wallChunkArchitect2.transform.LookAt(component.P2);
                        wallChunkArchitect2.MultipointPositions = null;
                        wallChunkArchitect2.P1             = vector;
                        wallChunkArchitect2.P2             = component.P2;
                        wallChunkArchitect2.CurrentSupport = component.CurrentSupport;
                    }
                }
                base.StartCoroutine(this.DelayedCancelGhost());
            }
        }
 public override void UpdateAddition(WallChunkArchitect.Additions addition)
 {
 }
 protected override WallChunkArchitect.Additions SegmentNextAddition(WallChunkArchitect.Additions addition)
 {
     if (addition == WallChunkArchitect.Additions.Wall && this.CanTurnIntoGate())
     {
         return WallChunkArchitect.Additions.Door1;
     }
     return WallChunkArchitect.Additions.Wall;
 }
 protected bool IsDoor(WallChunkArchitect.Additions addition)
 {
     return addition >= WallChunkArchitect.Additions.Door1;
 }