コード例 #1
0
    public override void Attached()
    {
        CoopConstructionExToken coopConstructionExToken = (CoopConstructionExToken)this.entity.attachToken;

        for (int i = 0; i < coopConstructionExToken.Architects.Length; i++)
        {
            ICoopStructure coopStructure = (ICoopStructure)this.Architects[i];
            coopStructure.CustomToken          = coopConstructionExToken.Architects[i].CustomToken;
            coopStructure.MultiPointsCount     = coopConstructionExToken.Architects[i].PointsCount;
            coopStructure.MultiPointsPositions = coopConstructionExToken.Architects[i].PointsPositions.ToList <Vector3>();
            coopStructure.WasPlaced            = true;
            if (coopStructure is FoundationArchitect && coopConstructionExToken.Architects[i].AboveGround)
            {
                ((FoundationArchitect)coopStructure)._aboveGround = true;
            }
            if (coopConstructionExToken.Architects[i].Support)
            {
                IStructureSupport structureSupport = coopConstructionExToken.Architects[i].Support.GetComponentInChildren(typeof(IStructureSupport)) as IStructureSupport;
                if (structureSupport != null)
                {
                    if (coopStructure is RoofArchitect)
                    {
                        (coopStructure as RoofArchitect).CurrentSupport = structureSupport;
                    }
                    if (coopStructure is FloorArchitect)
                    {
                        (coopStructure as FloorArchitect).CurrentSupport = structureSupport;
                    }
                }
            }
        }
        this.entity.SendMessage("OnDeserialized");
        base.Attached();
    }
コード例 #2
0
        private IEnumerator BuildingWarmthCheckRoutine(FloorArchitect floor, IStructureSupport ceiling)
        {
            this._hasActiveWarmth = true;
            LocalPlayer.GameObject.SendMessage("HomeWarmth");
            yield return(YieldPresets.WaitPointFiveSeconds);

            for (int i = 0; i < 2; i++)
            {
                bool hasLitFire = true;
                while (hasLitFire && floor != null && floor.gameObject && ceiling != null && (MonoBehaviour)ceiling && ((MonoBehaviour)ceiling).gameObject && this.IsPlayerPositionValid(LocalPlayer.Transform.position, floor, ceiling))
                {
                    i = 0;
                    yield return(YieldPresets.WaitOneSecond);

                    hasLitFire = this.FloorHasLitFire(floor.transform);
                }
                if (!floor || !hasLitFire)
                {
                    break;
                }
                ceiling = this.SearchValidCeiling(floor);
            }
            LocalPlayer.GameObject.SendMessage("LeaveHomeWarmth");
            this._hasActiveWarmth = false;
            yield break;
        }
コード例 #3
0
ファイル: BuildingHealth.cs プロジェクト: DevZhav/The-Forest
        private void SpawnRepairTrigger()
        {
            if (this._repairTrigger || !this._canBeRepaired)
            {
                return;
            }
            if (BoltNetwork.isRunning && base.entity && base.entity.isAttached && base.entity.isOwner)
            {
                base.state.repairTrigger = true;
            }
            this._repairTrigger                  = UnityEngine.Object.Instantiate <BuildingRepair>(Prefabs.Instance.BuildingRepairTriggerPrefab);
            this._repairTrigger._target          = this;
            this._repairTrigger.transform.parent = base.transform;
            IStructureSupport structureSupport = (IStructureSupport)base.GetComponent(typeof(IStructureSupport));

            if (structureSupport != null)
            {
                if (structureSupport is WallChunkArchitect)
                {
                    WallChunkArchitect wallChunkArchitect = (WallChunkArchitect)structureSupport;
                    this._repairTrigger.transform.position = Vector3.Lerp(wallChunkArchitect.P1, wallChunkArchitect.P2, 0.5f) + base.transform.right + base.transform.TransformDirection(this._repairTriggerOffset);
                    this._repairTrigger.transform.rotation = Quaternion.LookRotation(base.transform.right);
                }
                else
                {
                    this._repairTrigger.transform.position = MultipointUtils.CenterOf(structureSupport.GetMultiPointsPositions(true)) + base.transform.TransformDirection(this._repairTriggerOffset);
                }
            }
            else
            {
                this._repairTrigger.transform.position = base.transform.position + base.transform.TransformDirection(this._repairTriggerOffset);
            }
        }
コード例 #4
0
        private IStructureSupport SearchValidCeiling(FloorArchitect floor)
        {
            IStructureSupport structureSupport = this.SearchValidCeiling <FloorArchitect>(floor);

            if (structureSupport == null)
            {
                structureSupport = this.SearchValidCeiling <RoofArchitect>(floor);
            }
            return(structureSupport);
        }
コード例 #5
0
 private void ShowSupportAnchor(IStructureSupport support, Collider c)
 {
     ShowSupportingStructureAnchor.SupportInfo supportInfo = (this._pool.Count <= 0) ? new ShowSupportingStructureAnchor.SupportInfo() : this._pool.Dequeue();
     supportInfo._support = support;
     supportInfo._icon    = PoolManager.Pools["misc"].Spawn(this._anchorPrefab, support.SupportCenter + (support as MonoBehaviour).transform.TransformDirection(this._iconOffset), Quaternion.identity);
     if (supportInfo._colliders == null)
     {
         supportInfo._colliders = new List <Collider>();
     }
     supportInfo._colliders.Add(c);
     this._currentSupportsInfo.Add(supportInfo);
 }
コード例 #6
0
        private void OnTriggerExit(Collider other)
        {
            IStructureSupport support = other.GetComponentInParent <IStructureSupport>();

            if (support != null)
            {
                int num = this._currentSupportsInfo.FindIndex((ShowSupportingStructureAnchor.SupportInfo s) => s._support == support);
                if (num >= 0)
                {
                    this.RemoveSupportCollider(this._currentSupportsInfo[num], other);
                }
            }
        }
コード例 #7
0
ファイル: WallArchitect.cs プロジェクト: DevZhav/The-Forest
        private void InitSupport(IStructureSupport support)
        {
            List <Vector3> multiPointsPositions = support.GetMultiPointsPositions(true);

            if (multiPointsPositions != null && multiPointsPositions.Count > 1)
            {
                if (!this._autofillmode && this._canScriptToggleAutofillmode && this._multiPointsPositions.Count == 0)
                {
                    this._autofillmode = true;
                }
                this.CurrentSupport = support;
                this.UpdateAutoFill(false);
            }
        }
コード例 #8
0
        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);
                    }
                }
            }
        }
コード例 #9
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("structure") && !this._hasActiveWarmth)
     {
         FloorArchitect componentInParent = other.GetComponentInParent <FloorArchitect>();
         if (componentInParent)
         {
             IStructureSupport structureSupport = this.SearchValidCeiling(componentInParent);
             if (structureSupport != null && this.FloorHasLitFire(componentInParent.transform))
             {
                 base.StartCoroutine(this.BuildingWarmthCheckRoutine(componentInParent, structureSupport));
                 return;
             }
         }
     }
 }
コード例 #10
0
ファイル: WallArchitect.cs プロジェクト: DevZhav/The-Forest
        private void CheckTargetingSupport(PrefabIdentifier structureRoot)
        {
            IStructureSupport structureSupport = (!structureRoot) ? null : structureRoot.GetComponent <IStructureSupport>();

            if (structureSupport != null)
            {
                this.InitSupport(structureSupport);
            }
            else
            {
                RaycastHit raycastHit;
                if (Physics.Raycast(base.transform.position + Vector3.up, Vector3.down, out raycastHit, 2f, this._floorLayers))
                {
                    if (raycastHit.collider.CompareTag("TerrainMain"))
                    {
                        if (this._autofillmode || this.CurrentSupport != null)
                        {
                            this.CurrentSupport = null;
                            if (this._autofillmode || this._multiPointsPositions.Count == 0)
                            {
                                this._autofillmode = false;
                                this.UpdateAutoFill(true);
                            }
                        }
                        return;
                    }
                    IStructureSupport componentInParent = raycastHit.collider.GetComponentInParent <IStructureSupport>();
                    if (componentInParent != null)
                    {
                        this.InitSupport(componentInParent);
                        return;
                    }
                }
                if (this.CurrentSupport != null)
                {
                    this.CurrentSupport = null;
                    this.UpdateAutoFill(false);
                }
            }
        }
コード例 #11
0
 private bool IsPlayerPositionValid(Vector3 testPos, IStructureSupport floor, IStructureSupport ceiling)
 {
     return(testPos.y > floor.GetLevel() && testPos.y < ceiling.GetLevel() && MathEx.IsPointInPolygon(testPos, floor.GetMultiPointsPositions(true)) && MathEx.IsPointInPolygon(testPos, ceiling.GetMultiPointsPositions(true)));
 }
コード例 #12
0
ファイル: WallArchitect.cs プロジェクト: DevZhav/The-Forest
        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;
        }
コード例 #13
0
 private IEnumerator BuildingWarmthCheckRoutine(FloorArchitect floor, IStructureSupport ceiling)
 {
     BuildingWarmthCheck.< BuildingWarmthCheckRoutine > c__Iterator14C <BuildingWarmthCheckRoutine> c__Iterator14C = new BuildingWarmthCheck.< BuildingWarmthCheckRoutine > c__Iterator14C();
コード例 #14
0
 protected virtual IEnumerator OnDeserialized()
 {
     if (!this._initialized)
     {
         this._initialized = true;
         if (this._forceWasBuilt)
         {
             this._wasBuilt = true;
         }
         if (this._p1 == Vector3.zero)
         {
             this._p1 = base.transform.position;
         }
         if (this._p2 == Vector3.zero)
         {
             PrefabIdentifier pi = base.GetComponent <PrefabIdentifier>();
             if (pi && !pi.Components.Contains(base.GetType().FullName))
             {
                 pi.Components.Add(base.GetType().FullName);
             }
             Transform parentStructure = base.transform.parent;
             while (parentStructure && parentStructure.parent)
             {
                 parentStructure = parentStructure.parent;
                 yield return(null);
             }
             IStructureSupport support = (!base.transform.parent) ? null : base.transform.parent.GetComponent <IStructureSupport>();
             if (support != null)
             {
                 this.CurrentSupport = support;
                 List <Vector3> multiPointsPositions = support.GetMultiPointsPositions(true);
                 if (multiPointsPositions != null && multiPointsPositions.Count > 1)
                 {
                     Vector3 p = this._p1;
                     p.y = multiPointsPositions[0].y;
                     int num = -1;
                     int i;
                     for (i = 1; i < multiPointsPositions.Count; i++)
                     {
                         Vector3 a    = MathEx.ProjectPointOnLineSegment(multiPointsPositions[i], multiPointsPositions[i - 1], p);
                         float   num2 = Vector3.Distance(a, p);
                         if (num2 < 0.025f)
                         {
                             if (Vector3.Dot(multiPointsPositions[i] - multiPointsPositions[i - 1], base.transform.forward) > 0.98f)
                             {
                                 num = i - 1;
                                 break;
                             }
                             if (Vector3.Dot(multiPointsPositions[i] - multiPointsPositions[(i + 1) % multiPointsPositions.Count], base.transform.forward) > 0.98f)
                             {
                                 num = (i - 1) % multiPointsPositions.Count;
                                 break;
                             }
                         }
                     }
                     if (num > -1)
                     {
                         Vector3 a2        = multiPointsPositions[i] - multiPointsPositions[num];
                         float   magnitude = Vector3.Scale(a2, new Vector3(1f, 0f, 1f)).magnitude;
                         int     num3      = Mathf.CeilToInt(magnitude / this._architect.MaxSegmentHorizontalLength);
                         float   d         = magnitude / (float)num3;
                         this._p2 = this._p1 + base.transform.forward * d;
                     }
                 }
             }
             if (this._p2 == Vector3.zero)
             {
                 this._p2 = this._p1 + base.transform.forward * this._architect.MaxSegmentHorizontalLength * 0.95f;
             }
         }
         if (this._height == 0f)
         {
             this._height = 5f;
         }
         if (this._multiPointsPositions == null)
         {
             this._multiPointsPositions = new List <Vector3>
             {
                 this._p1,
                 this._p2
             };
             this._multiPointsPositionsCount = 2;
         }
         else if (this._multiPointsPositionsCount == 0)
         {
             this._multiPointsPositionsCount = this._multiPointsPositions.Skip(1).IndexOf(this._multiPointsPositions[0]);
             if (this._multiPointsPositionsCount < 0)
             {
                 this._multiPointsPositionsCount = this._multiPointsPositions.Count;
             }
             else
             {
                 this._multiPointsPositionsCount += 2;
             }
         }
         if (this._multiPointsPositions.Count > this._multiPointsPositionsCount)
         {
             this._multiPointsPositions.RemoveRange(this._multiPointsPositionsCount, this._multiPointsPositions.Count - this._multiPointsPositionsCount);
         }
         if (this._wasBuilt)
         {
             this.CreateStructure(false);
             this._wallRoot.transform.parent = base.transform;
         }
         else
         {
             this.CreateStructure(false);
             base.StartCoroutine(this.OnPlaced());
         }
     }
     yield break;
 }
コード例 #15
0
 public void Show(IStructureSupport structure, Vector3 offset = default(Vector3))
 {
     this._offset    = offset;
     this._structure = structure;
     base.enabled    = true;
 }
コード例 #16
0
ファイル: WallArchitect.cs プロジェクト: GameDiffs/TheForest
 private void OnTriggerExit(Collider other)
 {
     if (other.CompareTag("structure") || other.CompareTag("jumpObject"))
     {
         IStructureSupport structureSupport = (IStructureSupport)other.GetComponentInParent(typeof(IStructureSupport));
         if (structureSupport == this.CurrentSupport)
         {
             this.CurrentSupport = null;
         }
     }
 }