public override void ShowToggleAdditionIcon() { WallChunkArchitect.Additions additions = this.SegmentNextAddition(this._addition); if (additions != WallChunkArchitect.Additions.Wall) { if (additions == WallChunkArchitect.Additions.Door1) { if (Scene.HudGui.ToggleDefensiveWallIcon.activeSelf) { Scene.HudGui.ToggleDefensiveWallIcon.SetActive(false); } if (!Scene.HudGui.ToggleGate1Icon.activeSelf) { Scene.HudGui.ToggleGate1Icon.SetActive(true); } } } else { if (!Scene.HudGui.ToggleDefensiveWallIcon.activeSelf) { Scene.HudGui.ToggleDefensiveWallIcon.SetActive(true); } if (Scene.HudGui.ToggleGate1Icon.activeSelf) { Scene.HudGui.ToggleGate1Icon.SetActive(false); } } }
private bool CheckCombineGate() { foreach (WallDefensiveGateAddition wallDefensiveGateAddition in UnityEngine.Object.FindObjectsOfType <WallDefensiveGateAddition>()) { if (wallDefensiveGateAddition != this && !wallDefensiveGateAddition.GetComponent <WallDefensiveGateArchitect>().Is2Sided&& Mathf.Abs(Vector3.Dot(base.transform.forward, wallDefensiveGateAddition.transform.forward)) > 0.95f) { WallDefensiveChunkArchitect component = wallDefensiveGateAddition.GetComponent <WallDefensiveChunkArchitect>(); WallDefensiveChunkArchitect component2 = base.GetComponent <WallDefensiveChunkArchitect>(); WallChunkArchitect.Additions addition = component.Addition; if (Vector3.Distance(component.P2, component2.P1) < 0.2f && Vector3.Distance(component.P1, component2.P2) < 22f) { this.SpawnGate(component.P1, component2.P2, addition, component.Height); base.GetComponentInChildren <Craft_Structure>().CancelBlueprintSafe(); wallDefensiveGateAddition.GetComponentInChildren <Craft_Structure>().CancelBlueprintSafe(); return(true); } if (Vector3.Distance(component.P1, component2.P2) < 0.2f && Vector3.Distance(component.P2, component2.P1) < 22f) { this.SpawnGate(component2.P1, component.P2, addition, component.Height); base.GetComponentInChildren <Craft_Structure>().CancelBlueprintSafe(); wallDefensiveGateAddition.GetComponentInChildren <Craft_Structure>().CancelBlueprintSafe(); return(true); } } } return(false); }
public override void UpdateAddition(WallChunkArchitect.Additions addition) { this._addition = addition; if (!this._wasBuilt) { if (!base.IsDoor(this._addition) && !BoltNetwork.isClient) { base.gameObject.GetComponent <WallDefensiveGateAddition>().Start(); } else { UnityEngine.Object.Destroy(this._wallRoot.gameObject); this._wallRoot = this.SpawnStructure(); this._wallRoot.parent = base.transform; Craft_Structure.BuildIngredients buildIngredients = this._craftStructure._requiredIngredients.FirstOrDefault((Craft_Structure.BuildIngredients i) => i._itemID == this._logItemId); if (buildIngredients == null) { buildIngredients = new Craft_Structure.BuildIngredients(); buildIngredients._itemID = this._logItemId; buildIngredients._amount = 0; buildIngredients._renderers = new GameObject[0]; this._craftStructure._requiredIngredients.Insert(0, buildIngredients); } else { buildIngredients._subIngredients.Clear(); } buildIngredients._amount = this.GetLogCost(); List <GameObject> builtRenderers = this.GetBuiltRenderers(this._wallRoot); buildIngredients.AddRuntimeObjects(builtRenderers, this.BuiltLogPrefab.GetComponentInChildren <Renderer>().sharedMaterial); } } }
private void SpawnGate(Vector3 p1, Vector3 p2, WallChunkArchitect.Additions addition, float height) { if (BoltNetwork.isRunning) { PlaceWallChunk placeWallChunk = PlaceWallChunk.Create(GlobalTargets.OnlyServer); CoopWallChunkToken coopWallChunkToken = new CoopWallChunkToken(); coopWallChunkToken.P1 = p1; coopWallChunkToken.P2 = p2; coopWallChunkToken.PointsPositions = null; coopWallChunkToken.Additions = addition; coopWallChunkToken.Height = height; placeWallChunk.parent = ((!base.transform.parent) ? base.transform.GetComponentInParent <BoltEntity>() : base.transform.parent.GetComponentInParent <BoltEntity>()); placeWallChunk.token = coopWallChunkToken; placeWallChunk.prefab = Prefabs.Instance.WallDefensiveGateGhostPrefab.GetComponent <BoltEntity>().prefabId; placeWallChunk.support = null; placeWallChunk.Send(); } else { WallDefensiveGateArchitect wallDefensiveGateArchitect = UnityEngine.Object.Instantiate <WallDefensiveGateArchitect>(Prefabs.Instance.WallDefensiveGateGhostPrefab, p1, Quaternion.LookRotation(p2 - p1)); wallDefensiveGateArchitect.P1 = p1; wallDefensiveGateArchitect.P2 = p2; wallDefensiveGateArchitect.Addition = addition; wallDefensiveGateArchitect.transform.parent = base.transform.parent; } }
public virtual void UpdateAddition(WallChunkArchitect.Additions addition) { this._addition = addition; UnityEngine.Object.Destroy(this._wallRoot.gameObject); this._wallRoot = this.SpawnStructure(); this._wallRoot.parent = base.transform; Craft_Structure.BuildIngredients buildIngredients = this._craftStructure._requiredIngredients.FirstOrDefault((Craft_Structure.BuildIngredients i) => i._itemID == this._logItemId); if (buildIngredients == null) { buildIngredients = new Craft_Structure.BuildIngredients(); buildIngredients._itemID = this._logItemId; buildIngredients._amount = 0; this._craftStructure._requiredIngredients.Insert(0, buildIngredients); } buildIngredients._subIngredients.Clear(); buildIngredients._renderers = null; buildIngredients._amount = this.GetLogCost(); List <GameObject> builtRenderers = this.GetBuiltRenderers(this._wallRoot); buildIngredients.AddRuntimeObjects(builtRenderers, this.BuiltLogPrefab.GetComponentInChildren <Renderer>().sharedMaterial); this._craftStructure.UpdateNeededRenderers(); 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 = UnityEngine.Object.Instantiate <Transform>(Prefabs.Instance.DoorGhostPrefab, position, this._wallRoot.rotation); transform.LookAt(worldPosition); transform.parent = this._wallRoot; } }
protected override WallChunkArchitect.Additions SegmentNextAddition(WallChunkArchitect.Additions addition) { if (addition == WallChunkArchitect.Additions.Wall && this.CanTurnIntoGate()) { return(WallChunkArchitect.Additions.Door1); } return(WallChunkArchitect.Additions.Wall); }
protected override WallChunkArchitect.Additions SegmentNextAddition(WallChunkArchitect.Additions addition) { if (addition == WallChunkArchitect.Additions.Door1) { return(WallChunkArchitect.Additions.Door2); } return(WallChunkArchitect.Additions.Wall); }
public override void ShowToggleAdditionIcon() { WallChunkArchitect.Additions additions = this.SegmentNextAddition(this._addition); switch (additions + 1) { case WallChunkArchitect.Additions.Window: Scene.HudGui.ToggleWallIcon.SetActive(true); break; case WallChunkArchitect.Additions.Door2: Scene.HudGui.ToggleGate1Icon.SetActive(true); break; } }
public override void UpdateAddition(WallChunkArchitect.Additions addition) { this._addition = addition; if (!this._wasBuilt) { if (!base.IsDoor(this._addition) && !BoltNetwork.isClient) { base.gameObject.GetComponent <WallDefensiveGateAddition>().Start(); } else { UnityEngine.Object.Destroy(this._wallRoot.gameObject); this._wallRoot = this.SpawnEdge(); this._wallRoot.parent = base.transform; } } }
void IProtocolToken.Read(UdpPacket packet) { this.Parent = packet.ReadBoltEntity(); this.P1 = packet.ReadVector3(); this.P2 = packet.ReadVector3(); this.Support = packet.ReadBoltEntity(); this.Additions = (WallChunkArchitect.Additions)packet.ReadInt(); int num = packet.ReadInt(); if (num > 0) { this.PointsPositions = new Vector3[num]; for (int i = 0; i < num; i++) { this.PointsPositions[i] = packet.ReadVector3(); } } }
protected virtual WallChunkArchitect.Additions SegmentNextAddition(WallChunkArchitect.Additions addition) { int num = (int)this._height; 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 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(); } } }
public virtual Transform SpawnStructure() { Transform transform = new GameObject("WallChunk").transform; transform.transform.position = this._p1; Vector3 vector = this._p2 - this._p1; int num = Mathf.RoundToInt(this._height); if (this.UseHorizontalLogs) { Vector3 b = new Vector3(0f, this._logWidth * 0.95f, 0f); Quaternion rotation = Quaternion.LookRotation(vector); Vector3 vector2 = this._p1; transform.position = this._p1; transform.LookAt(this._p2); Vector3 localScale = new Vector3(1f, 1f, vector.magnitude / this._logLength); Vector3 localScale2 = new Vector3(1f, 1f, 0.31f + (localScale.z - 1f) / 2f); float d = 1f - localScale2.z / localScale.z; for (int i = 0; i < num; i++) { Transform transform2 = this.NewLog(vector2, rotation); transform2.parent = transform; WallChunkArchitect.Additions addition = this._addition; switch (addition + 1) { case WallChunkArchitect.Additions.Window: transform2.localScale = localScale; break; case WallChunkArchitect.Additions.Door1: if (i == 2 || i == 3) { transform2.localScale = localScale2; Transform transform3 = this.NewLog(vector2 + vector * d, rotation); transform3.parent = transform2; transform3.localScale = Vector3.one; } else { transform2.localScale = localScale; } break; case WallChunkArchitect.Additions.Door2: case WallChunkArchitect.Additions.LockedDoor1: case WallChunkArchitect.Additions.LockedDoor2: case (WallChunkArchitect.Additions) 5: if (i < 4) { transform2.localScale = localScale2; Transform transform4 = this.NewLog(vector2 + vector * d, rotation); transform4.parent = transform2; transform4.localScale = Vector3.one; } else { transform2.localScale = localScale; } break; } vector2 += b; } } else { Vector3 normalized = Vector3.Scale(vector, new Vector3(1f, 0f, 1f)).normalized; float y = Mathf.Tan(Vector3.Angle(vector, normalized) * 0.0174532924f) * this._logWidth; Quaternion rotation2 = Quaternion.LookRotation(Vector3.up); Vector3 localScale3 = new Vector3(1f, 1f, (float)num * 0.95f * this._logWidth / this._logLength); float num2 = this._logWidth / 2f * 0.98f; float num3 = Vector3.Distance(this._p1, this._p2); int num4 = Mathf.Max(Mathf.RoundToInt((num3 - this._logWidth * 0.96f / 2f) / this._logWidth), 1); Vector3 vector3 = normalized * this._logWidth; vector3.y = y; if (vector.y < 0f) { vector3.y *= -1f; } Vector3 vector4 = this._p1; vector4.y -= num2; vector4 += vector3 / 2f; transform.position = this._p1; transform.LookAt(this._p2); transform.eulerAngles = Vector3.Scale(transform.localEulerAngles, Vector3.up); for (int j = 0; j < num4; j++) { Transform transform5 = this.NewLog(vector4, rotation2); transform5.parent = transform; vector4 += vector3; transform5.localScale = localScale3; } } return(transform); }
protected bool IsDoor(WallChunkArchitect.Additions addition) { return(addition >= WallChunkArchitect.Additions.Door1); }
public override void UpdateAddition(WallChunkArchitect.Additions addition) { }
public virtual void PerformToggleAddition() { if (BoltNetwork.isRunning) { this.entity.GetState<IWallChunkConstructionState>().Addition = (int)(this._addition = this.SegmentNextAddition(this._addition)); } else { this.UpdateAddition(this.SegmentNextAddition(this._addition)); } }
protected virtual void CreateStructure(bool isRepair = false) { if (isRepair) { this.Clear(); base.StartCoroutine(this.DelayedAwake(true)); } int num = LayerMask.NameToLayer("Prop"); this._wallRoot = this.SpawnStructure(); this._wallRoot.parent = base.transform; if (this._wasBuilt) { this._gridToken = InsideCheck.AddWallChunk(this._p1, this._p2, 4.75f * this._logWidth + 1f); if (this._lods) { UnityEngine.Object.Destroy(this._lods.gameObject); } this._lods = new GameObject("lods").AddComponent <WallChunkLods>(); this._lods.transform.parent = base.transform; this._lods.DefineChunk(this._p1, this._p2, 4.44f * this._logWidth, this._wallRoot, this.Addition); if (!this._wallCollision) { GameObject gameObject = new GameObject("collision"); gameObject.transform.parent = this._wallRoot.parent; gameObject.transform.position = this._wallRoot.position; gameObject.transform.rotation = this._wallRoot.rotation; gameObject.tag = "structure"; this._wallCollision = gameObject.transform; GameObject gameObject2 = this._wallRoot.gameObject; int layer = num; gameObject.layer = layer; gameObject2.layer = layer; float num3; float num4; Vector3 size; Vector3 vector; if (this.UseHorizontalLogs) { float num2 = Vector3.Distance(this._p1, this._p2) / this._logLength; num3 = 7.4f * num2; num4 = 6.75f * (0.31f + (num2 - 1f) / 2f); size = new Vector3(1.75f, 0.9f * this._height * this._logWidth, num3 * 1f); vector = Vector3.Lerp(this._p1, this._p2, 0.5f); vector = this._wallRoot.InverseTransformPoint(vector); vector.y = size.y / 2f - this._logWidth / 2f; } else { num3 = this._logWidth * (float)(this._wallRoot.childCount - 1) + 1.5f; num4 = 0f; vector = Vector3.zero; IEnumerator enumerator = this._wallRoot.GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; Transform transform = (Transform)obj; vector += transform.position; } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } size = new Vector3(1.75f, 0.92f * this._height * this._logWidth, num3); vector /= (float)this._wallRoot.childCount; vector = this._wallRoot.InverseTransformPoint(vector); vector.y = size.y / 2f - this._logWidth / 2f; } getStructureStrength getStructureStrength = gameObject.AddComponent <getStructureStrength>(); getStructureStrength._strength = getStructureStrength.strength.strong; BoxCollider boxCollider = gameObject.AddComponent <BoxCollider>(); boxCollider.center = vector; boxCollider.size = size; boxCollider.isTrigger = true; BuildingHealth component = base.GetComponent <BuildingHealth>(); if (component) { component._renderersRoot = this._wallRoot.gameObject; } WallChunkArchitect.Additions addition = this._addition; if (addition != WallChunkArchitect.Additions.Wall) { BoxCollider boxCollider2 = null; if (this._height > 4f) { vector.y += this._logWidth * 2f; size.y = 1f * this._logWidth; boxCollider2 = gameObject.AddComponent <BoxCollider>(); boxCollider2.center = vector; boxCollider2.size = size; } FMOD_StudioEventEmitter.CreateAmbientEmitter(gameObject.transform, gameObject.transform.TransformPoint(vector), "event:/ambient/wind/wind_moan_structures"); size.y = Mathf.Clamp(this._height, 0f, 4f) * this._logWidth; size.z = num4; vector.y = size.y / 2f - this._logWidth / 2f; vector.z = num3 - num4 / 2f; BoxCollider boxCollider3 = gameObject.AddComponent <BoxCollider>(); boxCollider3.center = vector; boxCollider3.size = size; vector.z = num4 / 2f; BoxCollider boxCollider4 = gameObject.AddComponent <BoxCollider>(); boxCollider4.center = vector; boxCollider4.size = size; if (this._addition == WallChunkArchitect.Additions.Window) { size.y = this._logWidth * 1.9f; size.z = num3 - num4 * 2f; vector.z += num4 / 2f + size.z / 2f; vector.y = size.y / 2f - this._logWidth / 2f; BoxCollider boxCollider5 = gameObject.AddComponent <BoxCollider>(); boxCollider5.center = vector; boxCollider5.size = size; GameObject gameObject3 = new GameObject("PerchTarget"); SphereCollider sphereCollider = gameObject3.AddComponent <SphereCollider>(); sphereCollider.isTrigger = true; sphereCollider.radius = 0.145f; gameObject3.transform.parent = this._wallRoot; vector.y += size.y / 2f; gameObject3.transform.localPosition = vector; if (BoltNetwork.isRunning) { if (boxCollider2) { component.SetMpRandomDistortColliders(new Collider[] { boxCollider2, boxCollider4, boxCollider3, boxCollider5 }); } else { component.SetMpRandomDistortColliders(new Collider[] { boxCollider4, boxCollider3, boxCollider5 }); } } } else if (BoltNetwork.isRunning) { component.SetMpRandomDistortColliders(new Collider[] { boxCollider2, boxCollider4, boxCollider3 }); } } else { BoxCollider boxCollider6 = gameObject.AddComponent <BoxCollider>(); boxCollider6.center = vector; boxCollider6.size = size; if (BoltNetwork.isRunning) { component.SetMpRandomDistortColliders(new Collider[] { boxCollider6 }); } } gridObjectBlocker gridObjectBlocker = gameObject.AddComponent <gridObjectBlocker>(); gridObjectBlocker.ignoreOnDisable = true; addToBuilt addToBuilt = gameObject.AddComponent <addToBuilt>(); addToBuilt.addToStructures = true; BuildingHealthHitRelay buildingHealthHitRelay = gameObject.AddComponent <BuildingHealthHitRelay>(); } if (this.Addition >= WallChunkArchitect.Additions.Door1 && this._addition <= WallChunkArchitect.Additions.LockedDoor2 && !isRepair) { Vector3 position = Vector3.Lerp(this._p1, this._p2, 0.5f); position.y -= this._logWidth / 2f; Vector3 worldPosition = (this._addition != WallChunkArchitect.Additions.Door1 && this._addition != WallChunkArchitect.Additions.LockedDoor1) ? this._p1 : this._p2; worldPosition.y = position.y; Transform transform2 = UnityEngine.Object.Instantiate <Transform>(Prefabs.Instance.DoorPrefab, position, this._wallRoot.rotation); transform2.LookAt(worldPosition); transform2.parent = base.transform; } } }
public virtual void ShowToggleAdditionIcon() { WallChunkArchitect.Additions additions = this.SegmentNextAddition(this._addition); switch (additions + 1) { case WallChunkArchitect.Additions.Window: if (!Scene.HudGui.ToggleWallIcon.activeSelf) { Scene.HudGui.ToggleWallIcon.SetActive(true); } if (Scene.HudGui.ToggleDoor1Icon.activeSelf) { Scene.HudGui.ToggleDoor1Icon.SetActive(false); } if (Scene.HudGui.ToggleDoor2Icon.activeSelf) { Scene.HudGui.ToggleDoor2Icon.SetActive(false); } if (Scene.HudGui.ToggleWindowIcon.activeSelf) { Scene.HudGui.ToggleWindowIcon.SetActive(false); } break; case WallChunkArchitect.Additions.Door1: if (Scene.HudGui.ToggleWallIcon.activeSelf) { Scene.HudGui.ToggleWallIcon.SetActive(false); } if (Scene.HudGui.ToggleDoor1Icon.activeSelf) { Scene.HudGui.ToggleDoor1Icon.SetActive(false); } if (Scene.HudGui.ToggleDoor2Icon.activeSelf) { Scene.HudGui.ToggleDoor2Icon.SetActive(false); } if (!Scene.HudGui.ToggleWindowIcon.activeSelf) { Scene.HudGui.ToggleWindowIcon.SetActive(true); } break; case WallChunkArchitect.Additions.Door2: if (Scene.HudGui.ToggleWallIcon.activeSelf) { Scene.HudGui.ToggleWallIcon.SetActive(false); } if (!Scene.HudGui.ToggleDoor1Icon.activeSelf) { Scene.HudGui.ToggleDoor1Icon.SetActive(true); } if (Scene.HudGui.ToggleDoor2Icon.activeSelf) { Scene.HudGui.ToggleDoor2Icon.SetActive(false); } if (Scene.HudGui.ToggleWindowIcon.activeSelf) { Scene.HudGui.ToggleWindowIcon.SetActive(false); } break; case WallChunkArchitect.Additions.LockedDoor1: if (Scene.HudGui.ToggleWallIcon.activeSelf) { Scene.HudGui.ToggleWallIcon.SetActive(false); } if (Scene.HudGui.ToggleDoor1Icon.activeSelf) { Scene.HudGui.ToggleDoor1Icon.SetActive(false); } if (!Scene.HudGui.ToggleDoor2Icon.activeSelf) { Scene.HudGui.ToggleDoor2Icon.SetActive(true); } if (Scene.HudGui.ToggleWindowIcon.activeSelf) { Scene.HudGui.ToggleWindowIcon.SetActive(false); } break; } }
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; } }
public void DefineChunk(Vector3 p1, Vector3 p2, float height, Transform wallRoot, WallChunkArchitect.Additions wallAddition) { if (this._wsToken < 0) { this.SpawnQuad(p1, p2, height); this._wallRootLOD1GO = this.SpawnLOD(Prefabs.Instance.LogWallExBuiltPrefabLOD1, wallRoot); this._wallRootLOD2GO = this.SpawnLOD(Prefabs.Instance.LogWallExBuiltPrefabLOD2, wallRoot); this._wallRootGO = wallRoot.gameObject; this._wsToken = WorkScheduler.Register(new WsTask(this.RefreshVisibility), base.transform.position, false); base.gameObject.SetActive(false); } }