private bool ValidateCollider(Collider other) { if (Grabber.FocusedItem != other) { PrefabIdentifier componentInParent = other.GetComponentInParent <PrefabIdentifier>(); if (componentInParent) { BuildingHealth component = componentInParent.GetComponent <BuildingHealth>(); if (component && component.CanBeRepaired && (component.CalcMissingRepairMaterial() > 0 || component.CalcMissingRepairLogs() > 0) && LocalPlayer.Inventory.Logs.HasLogs == component.CalcMissingRepairLogs() > 0) { return(!other.isTrigger); } FoundationHealth component2 = componentInParent.GetComponent <FoundationHealth>(); if (component2 && component2.CanBeRepaired) { bool flag = component2.CalcMissingRepairMaterial() > 0; bool flag2 = component2.CalcMissingRepairLogs() > 0; if (!LocalPlayer.Inventory.Logs.HasLogs == flag || (LocalPlayer.Inventory.Logs.HasLogs && flag2)) { return(!other.isTrigger); } } } } return(LocalPlayer.Grabber.IsValid(other)); }
private void OnGrabberEnter() { PrefabIdentifier componentInParent = Grabber.FocusedItemGO.GetComponentInParent <PrefabIdentifier>(); if (componentInParent) { BuildingHealth component = componentInParent.GetComponent <BuildingHealth>(); FoundationHealth component2 = componentInParent.GetComponent <FoundationHealth>(); if ((component && component.CanBeRepaired && (component.CalcMissingRepairMaterial() > 0 || component.CalcMissingRepairLogs() > 0) && !LocalPlayer.Inventory.Logs.HasLogs) || (component2 && component2.CanBeRepaired && (!LocalPlayer.Inventory.Logs.HasLogs == component2.CalcMissingRepairMaterial() > 0 || (LocalPlayer.Inventory.Logs.HasLogs && component2.CalcMissingRepairLogs() > 0)))) { this._buildingTarget = component; this._foundationTarget = component2; return; } } this.GrabExit(); this._buildingTarget = null; this._foundationTarget = null; LocalPlayer.Grabber.EnterMessage(); }
public void LocalizedHit(LocalizedHitData data) { PrefabIdentifier componentInParent = base.transform.GetComponentInParent <PrefabIdentifier>(); if (componentInParent) { BuildingHealth component = componentInParent.GetComponent <BuildingHealth>(); if (component) { component.LocalizedHit(data); } } }
private bool TryRemoveTarget(PrefabIdentifier pi, Collider other) { if (pi) { IHoleStructure holeStructure = (IHoleStructure)pi.GetComponent(typeof(IHoleStructure)); if (holeStructure != null) { Collider component = base.GetComponent<Collider>(); if (this._targets.Contains(holeStructure) && (other.bounds.max.y < component.bounds.min.y || other.bounds.min.y > component.bounds.max.y)) { int index = this._targets.IndexOf(holeStructure); UnityEngine.Object.Destroy((this._previews[index] as MonoBehaviour).gameObject); this._targets[index].RemoveHole(this._holes[index]); this._holes[index] = null; this._holes.RemoveAt(index); this._previews.RemoveAt(index); this._targets.RemoveAt(index); this.CheckCanPlace(); return true; } } else { BuildingBlueprint blueprintByPrefabId = Prefabs.Instance.Constructions.GetBlueprintByPrefabId(pi.ClassId); FloorHoleArchitect.DestroyTarget destroyTarget; if (blueprintByPrefabId != null && this._destroyTargets.TryGetValue(pi.gameObject, out destroyTarget)) { if (destroyTarget._colliders.Contains(other)) { destroyTarget._colliders.Remove(other); } if (destroyTarget._colliders.Count == 0) { UnityEngine.Object.Destroy(destroyTarget._ghost); this._destroyTargets.Remove(pi.gameObject); return true; } this.CheckCanPlace(); } } } return false; }
private void OnTriggerExit(Collider other) { PrefabIdentifier componentInParent = other.GetComponentInParent <PrefabIdentifier>(); if (componentInParent) { IHoleStructure holeStructure = (IHoleStructure)componentInParent.GetComponent(typeof(IHoleStructure)); Collider component = base.GetComponent <Collider>(); if (holeStructure != null && this._targets.Contains(holeStructure) && (other.bounds.max.y < component.bounds.min.y || other.bounds.min.y > component.bounds.max.y)) { int index = this._targets.IndexOf(holeStructure); UnityEngine.Object.Destroy((this._previews[index] as MonoBehaviour).gameObject); this._targets[index].RemoveHole(this._holes[index]); this._holes[index] = null; this._holes.RemoveAt(index); this._previews.RemoveAt(index); this._targets.RemoveAt(index); this.CheckCanPlace(); } } }
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); } } }
private void OnTriggerEnter(Collider other) { if (this.IsEnemy(other)) { this.preventHole = true; this.CheckCanPlace(); return; } if (other.CompareTag("effigy") || other.GetComponent <FireWarmth>()) { return; } PrefabIdentifier componentInParent = other.GetComponentInParent <PrefabIdentifier>(); if (componentInParent) { BoltEntity component = componentInParent.GetComponent <BoltEntity>(); if (BoltNetwork.isRunning && component && component.isAttached) { IRaftState raftState; IMultiHolderState multiHolderState; if (component.TryFindState <IRaftState>(out raftState)) { foreach (BoltEntity exists in raftState.GrabbedBy) { if (exists) { return; } } } else if (component.TryFindState <IMultiHolderState>(out multiHolderState) && (multiHolderState.GrabbedBy || multiHolderState.Replaces)) { return; } } this.TryAddTarget(componentInParent, other); } }
private void OnTriggerEnter(Collider other) { PrefabIdentifier componentInParent = other.GetComponentInParent <PrefabIdentifier>(); if (componentInParent) { IHoleStructure holeStructure = (IHoleStructure)componentInParent.GetComponent(typeof(IHoleStructure)); if (holeStructure != null && !this._targets.Contains(holeStructure)) { Hole item; if (holeStructure is FloorArchitect) { FloorArchitect floorArchitect = UnityEngine.Object.Instantiate <FloorArchitect>(this._previewFloor); (holeStructure as FloorArchitect).OnBuilt(floorArchitect.gameObject); floorArchitect._wasBuilt = false; this._previews.Add(floorArchitect); item = floorArchitect.AddSquareHole(base.transform.position, base.transform.rotation.y, this._holeSize); } else { if (!(holeStructure is RoofArchitect)) { Debug.LogError("Trying to cut IHS '" + componentInParent.name + "' which isn't roof or floor. Please report this to guillaume."); return; } RoofArchitect roofArchitect = UnityEngine.Object.Instantiate <RoofArchitect>(this._previewRoof); (holeStructure as RoofArchitect).OnBuilt(roofArchitect.gameObject); roofArchitect._wasBuilt = false; this._previews.Add(roofArchitect); item = roofArchitect.AddSquareHole(base.transform.position, base.transform.rotation.y, this._holeSize); } this._targets.Add(holeStructure); this._holes.Add(item); base.enabled = true; this.CheckCanPlace(); } } }
private bool MatchingExclusionGroup(Collider other, bool enter) { if (LocalPlayer.Create.CurrentBlueprint._exclusionGroup != ExclusionGroups.None) { PrefabIdentifier componentInParent = other.GetComponentInParent <PrefabIdentifier>(); if (componentInParent) { BuildingHealth component = componentInParent.GetComponent <BuildingHealth>(); if (component && component._type != BuildingTypes.None && Prefabs.Instance.Constructions.GetBlueprintExclusionGroup(component._type) == LocalPlayer.Create.CurrentBlueprint._exclusionGroup) { if (enter) { this._inExclusionGroup = true; } else { this._inExclusionGroup = false; } return(true); } } } return(false); }
private bool TryAddTarget(PrefabIdentifier pi, Collider c) { if (pi) { IHoleStructure holeStructure = (IHoleStructure)pi.GetComponent(typeof(IHoleStructure)); if (holeStructure != null) { if (!this._targets.Contains(holeStructure) && holeStructure.HoleCount < 20) { Hole item; if (holeStructure is FloorArchitect) { if (!this._previewFloor || !(holeStructure as FloorArchitect).WasBuilt) { return false; } FloorArchitect floorArchitect = holeStructure as FloorArchitect; FloorArchitect floorArchitect2 = UnityEngine.Object.Instantiate<FloorArchitect>(this._previewFloor, floorArchitect.transform.position, floorArchitect.transform.rotation); floorArchitect.OnBuilt(floorArchitect2.gameObject); floorArchitect2._wasBuilt = false; this._previews.Add(floorArchitect2); item = floorArchitect2.AddSquareHole(base.transform.position, base.transform.rotation.y, this._holeSize); } else if (holeStructure is RoofArchitect) { if (!this._previewRoof || !(holeStructure as RoofArchitect).WasBuilt) { return false; } RoofArchitect roofArchitect = holeStructure as RoofArchitect; RoofArchitect roofArchitect2 = UnityEngine.Object.Instantiate<RoofArchitect>(this._previewRoof, roofArchitect.transform.position, roofArchitect.transform.rotation); roofArchitect.OnBuilt(roofArchitect2.gameObject); roofArchitect2._wasBuilt = false; this._previews.Add(roofArchitect2); item = roofArchitect2.AddSquareHole(base.transform.position, base.transform.rotation.y, this._holeSize); } else { if (holeStructure is CraneArchitect) { return false; } if (!(holeStructure is RaftArchitect) || !(holeStructure as RaftArchitect).WasBuilt) { UnityEngine.Debug.LogError("Trying to cut IHS '" + pi.name + "' which isn't roof, floor or raft. Please report this to guillaume."); return false; } if (!this._previewRaft || !(base.transform.root != pi.transform.root)) { return false; } RaftArchitect raftArchitect = holeStructure as RaftArchitect; RaftArchitect raftArchitect2 = UnityEngine.Object.Instantiate<RaftArchitect>(this._previewRaft, raftArchitect.transform.position, raftArchitect.transform.rotation); raftArchitect.OnBuilt(raftArchitect2.gameObject); this._previews.Add(raftArchitect2); item = raftArchitect2.AddSquareHole(base.transform.position, base.transform.rotation.y, this._holeSize); } this._targets.Add(holeStructure); this._holes.Add(item); this.CheckCanPlace(); return true; } } else { BuildingBlueprint blueprintByPrefabId = Prefabs.Instance.Constructions.GetBlueprintByPrefabId(pi.ClassId); if (blueprintByPrefabId != null && !blueprintByPrefabId._preventHoleCutting) { FloorHoleArchitect.DestroyTarget destroyTarget; if (!this._destroyTargets.TryGetValue(pi.gameObject, out destroyTarget)) { destroyTarget = new FloorHoleArchitect.DestroyTarget(); destroyTarget._go = pi.gameObject; destroyTarget._bh = pi.GetComponent<BuildingHealth>(); ICoopStructure component = pi.GetComponent<ICoopStructure>(); if (component != null) { IProceduralStructure component2 = pi.GetComponent<IProceduralStructure>(); if (component2 == null) { return false; } destroyTarget._ghost = component2.SpawnStructure().gameObject; } else { destroyTarget._ghost = UnityEngine.Object.Instantiate<GameObject>(blueprintByPrefabId._ghostPrefab, pi.transform.position, pi.transform.rotation); } destroyTarget._ghost.transform.parent = pi.transform; int layer = LayerMask.NameToLayer("TransparentFX"); Renderer component3 = destroyTarget._ghost.GetComponent<Renderer>(); if (component3) { destroyTarget._ghost.layer = layer; component3.sharedMaterial = this._overlayMaterial; } else { Craft_Structure componentInChildren = destroyTarget._ghost.GetComponentInChildren<Craft_Structure>(); if (componentInChildren && componentInChildren._requiredIngredients.Count > 0) { for (int i = 0; i < componentInChildren._requiredIngredients.Count; i++) { Craft_Structure.BuildIngredients buildIngredients = componentInChildren._requiredIngredients[i]; buildIngredients.SetGhostMaterial(this._overlayMaterial); } } else { Renderer[] componentsInChildren = destroyTarget._ghost.GetComponentsInChildren<Renderer>(); foreach (Renderer renderer in componentsInChildren) { renderer.gameObject.layer = layer; renderer.sharedMaterial = this._overlayMaterial; } } } Transform transform = destroyTarget._ghost.transform.Find("Trigger"); if (transform) { UnityEngine.Object.Destroy(transform.gameObject); } LastBuiltLocation component4 = destroyTarget._ghost.GetComponent<LastBuiltLocation>(); if (component4) { UnityEngine.Object.Destroy(component4.gameObject); } LastBuiltLocation component5 = destroyTarget._ghost.GetComponent<LastBuiltLocation>(); if (component5) { UnityEngine.Object.Destroy(component5.gameObject); } UnityEngine.Object.Destroy(destroyTarget._ghost.GetComponent<PrefabIdentifier>()); UnityEngine.Object.Destroy(destroyTarget._ghost.GetComponent<SingleAnchorStructure>()); this._destroyTargets.Add(pi.gameObject, destroyTarget); } if (c && !destroyTarget._colliders.Contains(c)) { destroyTarget._colliders.Add(c); } this.CheckCanPlace(); return true; } } } return false; }
public BuildingHealth GetBuildingHealth() { PrefabIdentifier componentInParent = base.transform.GetComponentInParent <PrefabIdentifier>(); return((!componentInParent) ? null : componentInParent.GetComponent <BuildingHealth>()); }
private bool IsDock(Collider c) { PrefabIdentifier componentInParent = c.GetComponentInParent <PrefabIdentifier>(); return(componentInParent && componentInParent.GetComponent <DockArchitect>()); }
private void Update() { if (this._raft.MultiPointsPositions.Count == 0) { RaycastHit raycastHit; if (Physics.SphereCast(((this._origin != RaftOarSwap.RayCastOrigins.Player) ? LocalPlayer.Create.BuildingPlacer.transform.position : LocalPlayer.MainCamTr.position) + Vector3.up * 3f, 2f, Vector3.down, out raycastHit, this._raycastDistance, this._layers.value)) { PrefabIdentifier componentInParent = raycastHit.collider.GetComponentInParent <PrefabIdentifier>(); RaftArchitect raftArchitect = (!componentInParent) ? null : componentInParent.GetComponent <RaftArchitect>(); bool flag = raftArchitect && raftArchitect._wasBuilt; if (flag) { this._oarGo.SetActive(true); this._raftGo.SetActive(false); LocalPlayer.Create.Grabber.ShowPlace(); LocalPlayer.Create.BuildingPlacer.SetClear(); LocalPlayer.Create.BuildingPlacer.SetRenderer(this._oarRenderer); } else if (this._oarGo.activeSelf) { this._oarGo.SetActive(false); this._raftGo.SetActive(true); LocalPlayer.Create.Grabber.ClosePlace(); LocalPlayer.Create.BuildingPlacer.SetRenderer(this._raftRenderer); } } else if (!this._raftGo.activeSelf) { this._oarGo.SetActive(false); this._raftGo.SetActive(true); LocalPlayer.Create.Grabber.ClosePlace(); LocalPlayer.Create.BuildingPlacer.SetRenderer(this._raftRenderer); } } }