| using System; |
| using System; |
| using System.Collections.Generic; |
| using System.Collections.Generic; |
| using UnityEngine; |
| using UnityEngine; |
| |
| |
| public class Piece : StaticTarget |
| public class Piece : StaticTarget |
| { |
| { |
| private void Awake() |
| private void Awake() |
| { |
| { |
| this.m_nview = base.GetComponent<ZNetView>(); |
| this.m_nview = base.GetComponent<ZNetView>(); |
| Piece.s_allPieces.Add(this); |
| Piece.s_allPieces.Add(this); |
| this.m_myListIndex = Piece.s_allPieces.Count - 1; |
| this.m_myListIndex = Piece.s_allPieces.Count - 1; |
| if (this.m_comfort > 0) |
| if (this.m_comfort > 0) |
| { |
| { |
| Piece.s_allComfortPieces.Add(this); |
| Piece.s_allComfortPieces.Add(this); |
| } |
| } |
| if (this.m_nview && this.m_nview.IsValid()) |
| if (this.m_nview && this.m_nview.IsValid()) |
| { |
| { |
| this.m_creator = this.m_nview.GetZDO().GetLong(ZDOVars.s_creator, 0L); |
| this.m_creator = this.m_nview.GetZDO().GetLong(ZDOVars.s_creator, 0L); |
| } |
| } |
| if (Piece.s_ghostLayer == 0) |
| if (Piece.s_ghostLayer == 0) |
| { |
| { |
| Piece.s_ghostLayer = LayerMask.NameToLayer("ghost"); |
| Piece.s_ghostLayer = LayerMask.NameToLayer("ghost"); |
| } |
| } |
| if (Piece.s_pieceRayMask == 0) |
| if (Piece.s_pieceRayMask == 0) |
| { |
| { |
| Piece.s_pieceRayMask = LayerMask.GetMask(new string[] { "piece", "piece_nonsolid" }); |
| Piece.s_pieceRayMask = LayerMask.GetMask(new string[] { "piece", "piece_nonsolid" }); |
| } |
| } |
| } |
| } |
| |
| |
| private void OnDestroy() |
| private void OnDestroy() |
| { |
| { |
| if (this.m_myListIndex >= 0) |
| if (this.m_myListIndex >= 0) |
| { |
| { |
| Piece.s_allPieces[this.m_myListIndex] = Piece.s_allPieces[Piece.s_allPieces.Count - 1]; |
| Piece.s_allPieces[this.m_myListIndex] = Piece.s_allPieces[Piece.s_allPieces.Count - 1]; |
| Piece.s_allPieces[this.m_myListIndex].m_myListIndex = this.m_myListIndex; |
| Piece.s_allPieces[this.m_myListIndex].m_myListIndex = this.m_myListIndex; |
| Piece.s_allPieces.RemoveAt(Piece.s_allPieces.Count - 1); |
| Piece.s_allPieces.RemoveAt(Piece.s_allPieces.Count - 1); |
| this.m_myListIndex = -1; |
| this.m_myListIndex = -1; |
| } |
| } |
| if (this.m_comfort > 0) |
| if (this.m_comfort > 0) |
| { |
| { |
| Piece.s_allComfortPieces.Remove(this); |
| Piece.s_allComfortPieces.Remove(this); |
| } |
| } |
| } |
| } |
| |
| |
| public bool CanBeRemoved() |
| public bool CanBeRemoved() |
| { |
| { |
| Container componentInChildren = base.GetComponentInChildren<Container>(); |
| Container componentInChildren = base.GetComponentInChildren<Container>(); |
| if (componentInChildren != null) |
| if (componentInChildren != null) |
| { |
| { |
| return componentInChildren.CanBeRemoved(); |
| return componentInChildren.CanBeRemoved(); |
| } |
| } |
| Ship componentInChildren2 = base.GetComponentInChildren<Ship>(); |
| Ship componentInChildren2 = base.GetComponentInChildren<Ship>(); |
| return !(componentInChildren2 != null) || componentInChildren2.CanBeRemoved(); |
| return !(componentInChildren2 != null) || componentInChildren2.CanBeRemoved(); |
| } |
| } |
| |
| |
| . | public void DropResources() |
| public void DropResources(HitData hitData = null) |
| { |
| { |
| if (ZoneSystem.instance.GetGlobalKey(GlobalKeys.NoBuildCost)) |
| if (ZoneSystem.instance.GetGlobalKey(GlobalKeys.NoBuildCost)) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| Container container = null; |
| Container container = null; |
| foreach (Piece.Requirement requirement in this.m_resources) |
| foreach (Piece.Requirement requirement in this.m_resources) |
| { |
| { |
| if (!(requirement.m_resItem == null) && requirement.m_recover) |
| if (!(requirement.m_resItem == null) && requirement.m_recover) |
| { |
| { |
| GameObject gameObject = requirement.m_resItem.gameObject; |
| GameObject gameObject = requirement.m_resItem.gameObject; |
| int j = requirement.m_amount; |
| int j = requirement.m_amount; |
| . | |
| gameObject = Game.instance.CheckDropConversion(hitData, requirement.m_resItem, gameObject, ref j); |
| if (!this.IsPlacedByPlayer()) |
| if (!this.IsPlacedByPlayer()) |
| { |
| { |
| j = Mathf.Max(1, j / 3); |
| j = Mathf.Max(1, j / 3); |
| } |
| } |
| if (this.m_destroyedLootPrefab) |
| if (this.m_destroyedLootPrefab) |
| { |
| { |
| while (j > 0) |
| while (j > 0) |
| { |
| { |
| ItemDrop.ItemData itemData = gameObject.GetComponent<ItemDrop>().m_itemData.Clone(); |
| ItemDrop.ItemData itemData = gameObject.GetComponent<ItemDrop>().m_itemData.Clone(); |
| itemData.m_dropPrefab = gameObject; |
| itemData.m_dropPrefab = gameObject; |
| itemData.m_stack = Mathf.Min(j, itemData.m_shared.m_maxStackSize); |
| itemData.m_stack = Mathf.Min(j, itemData.m_shared.m_maxStackSize); |
| j -= itemData.m_stack; |
| j -= itemData.m_stack; |
| if (container == null || !container.GetInventory().HaveEmptySlot()) |
| if (container == null || !container.GetInventory().HaveEmptySlot()) |
| { |
| { |
| container = UnityEngine.Object.Instantiate<GameObject>(this.m_destroyedLootPrefab, base.transform.position + Vector3.up, Quaternion.identity).GetComponent<Container>(); |
| container = UnityEngine.Object.Instantiate<GameObject>(this.m_destroyedLootPrefab, base.transform.position + Vector3.up, Quaternion.identity).GetComponent<Container>(); |
| } |
| } |
| container.GetInventory().AddItem(itemData); |
| container.GetInventory().AddItem(itemData); |
| } |
| } |
| } |
| } |
| else |
| else |
| { |
| { |
| while (j > 0) |
| while (j > 0) |
| { |
| { |
| ItemDrop component = UnityEngine.Object.Instantiate<GameObject>(gameObject, base.transform.position + Vector3.up, Quaternion.identity).GetComponent<ItemDrop>(); |
| ItemDrop component = UnityEngine.Object.Instantiate<GameObject>(gameObject, base.transform.position + Vector3.up, Quaternion.identity).GetComponent<ItemDrop>(); |
| component.SetStack(Mathf.Min(j, component.m_itemData.m_shared.m_maxStackSize)); |
| component.SetStack(Mathf.Min(j, component.m_itemData.m_shared.m_maxStackSize)); |
| ItemDrop.OnCreateNew(component); |
| ItemDrop.OnCreateNew(component); |
| j -= component.m_itemData.m_stack; |
| j -= component.m_itemData.m_stack; |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| public override bool IsPriorityTarget() |
| public override bool IsPriorityTarget() |
| { |
| { |
| return base.IsPriorityTarget() && (this.m_targetNonPlayerBuilt || this.IsPlacedByPlayer()); |
| return base.IsPriorityTarget() && (this.m_targetNonPlayerBuilt || this.IsPlacedByPlayer()); |
| } |
| } |
| |
| |
| public override bool IsRandomTarget() |
| public override bool IsRandomTarget() |
| { |
| { |
| return base.IsRandomTarget() && (this.m_targetNonPlayerBuilt || this.IsPlacedByPlayer()); |
| return base.IsRandomTarget() && (this.m_targetNonPlayerBuilt || this.IsPlacedByPlayer()); |
| } |
| } |
| |
| |
| public void SetCreator(long uid) |
| public void SetCreator(long uid) |
| { |
| { |
| if (this.m_nview == null) |
| if (this.m_nview == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (this.m_nview.IsOwner()) |
| if (this.m_nview.IsOwner()) |
| { |
| { |
| if (this.GetCreator() != 0L) |
| if (this.GetCreator() != 0L) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.m_creator = uid; |
| this.m_creator = uid; |
| this.m_nview.GetZDO().Set(ZDOVars.s_creator, uid); |
| this.m_nview.GetZDO().Set(ZDOVars.s_creator, uid); |
| } |
| } |
| } |
| } |
| |
| |
| public long GetCreator() |
| public long GetCreator() |
| { |
| { |
| return this.m_creator; |
| return this.m_creator; |
| } |
| } |
| |
| |
| public bool IsCreator() |
| public bool IsCreator() |
| { |
| { |
| long creator = this.GetCreator(); |
| long creator = this.GetCreator(); |
| long playerID = Game.instance.GetPlayerProfile().GetPlayerID(); |
| long playerID = Game.instance.GetPlayerProfile().GetPlayerID(); |
| return creator == playerID; |
| return creator == playerID; |
| } |
| } |
| |
| |
| public bool IsPlacedByPlayer() |
| public bool IsPlacedByPlayer() |
| { |
| { |
| return this.GetCreator() != 0L; |
| return this.GetCreator() != 0L; |
| } |
| } |
| |
| |
| public void SetInvalidPlacementHeightlight(bool enabled) |
| public void SetInvalidPlacementHeightlight(bool enabled) |
| { |
| { |
| if ((enabled && this.m_invalidPlacementMaterials != null) || (!enabled && this.m_invalidPlacementMaterials == null)) |
| if ((enabled && this.m_invalidPlacementMaterials != null) || (!enabled && this.m_invalidPlacementMaterials == null)) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| Renderer[] componentsInChildren = base.GetComponentsInChildren<Renderer>(); |
| Renderer[] componentsInChildren = base.GetComponentsInChildren<Renderer>(); |
| if (enabled) |
| if (enabled) |
| { |
| { |
| this.m_invalidPlacementMaterials = new List<KeyValuePair<Renderer, Material[]>>(); |
| this.m_invalidPlacementMaterials = new List<KeyValuePair<Renderer, Material[]>>(); |
| foreach (Renderer renderer in componentsInChildren) |
| foreach (Renderer renderer in componentsInChildren) |
| { |
| { |
| Material[] sharedMaterials = renderer.sharedMaterials; |
| Material[] sharedMaterials = renderer.sharedMaterials; |
| this.m_invalidPlacementMaterials.Add(new KeyValuePair<Renderer, Material[]>(renderer, sharedMaterials)); |
| this.m_invalidPlacementMaterials.Add(new KeyValuePair<Renderer, Material[]>(renderer, sharedMaterials)); |
| } |
| } |
| Renderer[] array = componentsInChildren; |
| Renderer[] array = componentsInChildren; |
| for (int i = 0; i < array.Length; i++) |
| for (int i = 0; i < array.Length; i++) |
| { |
| { |
| foreach (Material material in array[i].materials) |
| foreach (Material material in array[i].materials) |
| { |
| { |
| if (material.HasProperty("_EmissionColor")) |
| if (material.HasProperty("_EmissionColor")) |
| { |
| { |
| material.SetColor("_EmissionColor", Color.red * 0.7f); |
| material.SetColor("_EmissionColor", Color.red * 0.7f); |
| } |
| } |
| material.color = Color.red; |
| material.color = Color.red; |
| } |
| } |
| } |
| } |
| return; |
| return; |
| } |
| } |
| foreach (KeyValuePair<Renderer, Material[]> keyValuePair in this.m_invalidPlacementMaterials) |
| foreach (KeyValuePair<Renderer, Material[]> keyValuePair in this.m_invalidPlacementMaterials) |
| { |
| { |
| if (keyValuePair.Key) |
| if (keyValuePair.Key) |
| { |
| { |
| keyValuePair.Key.materials = keyValuePair.Value; |
| keyValuePair.Key.materials = keyValuePair.Value; |
| } |
| } |
| } |
| } |
| this.m_invalidPlacementMaterials = null; |
| this.m_invalidPlacementMaterials = null; |
| } |
| } |
| |
| |
| public static void GetSnapPoints(Vector3 point, float radius, List<Transform> points, List<Piece> pieces) |
| public static void GetSnapPoints(Vector3 point, float radius, List<Transform> points, List<Piece> pieces) |
| { |
| { |
| int num = Physics.OverlapSphereNonAlloc(point, radius, Piece.s_pieceColliders, Piece.s_pieceRayMask); |
| int num = Physics.OverlapSphereNonAlloc(point, radius, Piece.s_pieceColliders, Piece.s_pieceRayMask); |
| for (int i = 0; i < num; i++) |
| for (int i = 0; i < num; i++) |
| { |
| { |
| Piece componentInParent = Piece.s_pieceColliders[i].GetComponentInParent<Piece>(); |
| Piece componentInParent = Piece.s_pieceColliders[i].GetComponentInParent<Piece>(); |
| if (componentInParent != null) |
| if (componentInParent != null) |
| { |
| { |
| componentInParent.GetSnapPoints(points); |
| componentInParent.GetSnapPoints(points); |
| pieces.Add(componentInParent); |
| pieces.Add(componentInParent); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| public static void GetAllPiecesInRadius(Vector3 p, float radius, List<Piece> pieces) |
| public static void GetAllPiecesInRadius(Vector3 p, float radius, List<Piece> pieces) |
| { |
| { |
| foreach (Piece piece in Piece.s_allPieces) |
| foreach (Piece piece in Piece.s_allPieces) |
| { |
| { |
| if (piece.gameObject.layer != Piece.s_ghostLayer && Vector3.Distance(p, piece.transform.position) < radius) |
| if (piece.gameObject.layer != Piece.s_ghostLayer && Vector3.Distance(p, piece.transform.position) < radius) |
| { |
| { |
| pieces.Add(piece); |
| pieces.Add(piece); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| public static void GetAllComfortPiecesInRadius(Vector3 p, float radius, List<Piece> pieces) |
| public static void GetAllComfortPiecesInRadius(Vector3 p, float radius, List<Piece> pieces) |
| { |
| { |
| foreach (Piece piece in Piece.s_allComfortPieces) |
| foreach (Piece piece in Piece.s_allComfortPieces) |
| { |
| { |
| if (piece.gameObject.layer != Piece.s_ghostLayer && Vector3.Distance(p, piece.transform.position) < radius) |
| if (piece.gameObject.layer != Piece.s_ghostLayer && Vector3.Distance(p, piece.transform.position) < radius) |
| { |
| { |
| pieces.Add(piece); |
| pieces.Add(piece); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| public void GetSnapPoints(List<Transform> points) |
| public void GetSnapPoints(List<Transform> points) |
| { |
| { |
| for (int i = 0; i < base.transform.childCount; i++) |
| for (int i = 0; i < base.transform.childCount; i++) |
| { |
| { |
| Transform child = base.transform.GetChild(i); |
| Transform child = base.transform.GetChild(i); |
| if (child.CompareTag("snappoint")) |
| if (child.CompareTag("snappoint")) |
| { |
| { |
| points.Add(child); |
| points.Add(child); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| public int GetComfort() |
| public int GetComfort() |
| { |
| { |
| if (this.m_comfortObject != null && !this.m_comfortObject.activeInHierarchy) |
| if (this.m_comfortObject != null && !this.m_comfortObject.activeInHierarchy) |
| { |
| { |
| return 0; |
| return 0; |
| } |
| } |
| return this.m_comfort; |
| return this.m_comfort; |
| } |
| } |
| |
| |
| public bool m_targetNonPlayerBuilt = true; |
| public bool m_targetNonPlayerBuilt = true; |
| |
| |
| [Header("Basic stuffs")] |
| [Header("Basic stuffs")] |
| public Sprite m_icon; |
| public Sprite m_icon; |
| |
| |
| public string m_name = ""; |
| public string m_name = ""; |
| |
| |
| public string m_description = ""; |
| public string m_description = ""; |
| |
| |
| public bool m_enabled = true; |
| public bool m_enabled = true; |
| |
| |
| public Piece.PieceCategory m_category; |
| public Piece.PieceCategory m_category; |
| |
| |
| public bool m_isUpgrade; |
| public bool m_isUpgrade; |
| |
| |
| [Header("Comfort")] |
| [Header("Comfort")] |
| public int m_comfort; |
| public int m_comfort; |
| |
| |
| public Piece.ComfortGroup m_comfortGroup; |
| public Piece.ComfortGroup m_comfortGroup; |
| |
| |
| public GameObject m_comfortObject; |
| public GameObject m_comfortObject; |
| |
| |
| [Header("Placement rules")] |
| [Header("Placement rules")] |
| public bool m_groundPiece; |
| public bool m_groundPiece; |
| |
| |
| public bool m_allowAltGroundPlacement; |
| public bool m_allowAltGroundPlacement; |
| |
| |
| public bool m_groundOnly; |
| public bool m_groundOnly; |
| |
| |
| public bool m_cultivatedGroundOnly; |
| public bool m_cultivatedGroundOnly; |
| |
| |
| public bool m_waterPiece; |
| public bool m_waterPiece; |
| |
| |
| public bool m_clipGround; |
| public bool m_clipGround; |
| |
| |
| public bool m_clipEverything; |
| public bool m_clipEverything; |
| |
| |
| public bool m_noInWater; |
| public bool m_noInWater; |
| |
| |
| public bool m_notOnWood; |
| public bool m_notOnWood; |
| |
| |
| public bool m_notOnTiltingSurface; |
| public bool m_notOnTiltingSurface; |
| |
| |
| public bool m_inCeilingOnly; |
| public bool m_inCeilingOnly; |
| |
| |
| public bool m_notOnFloor; |
| public bool m_notOnFloor; |
| |
| |
| public bool m_noClipping; |
| public bool m_noClipping; |
| |
| |
| public bool m_onlyInTeleportArea; |
| public bool m_onlyInTeleportArea; |
| |
| |
| public bool m_allowedInDungeons; |
| public bool m_allowedInDungeons; |
| |
| |
| public float m_spaceRequirement; |
| public float m_spaceRequirement; |
| |
| |
| public bool m_repairPiece; |
| public bool m_repairPiece; |
| |
| |
| public bool m_canRotate = true; |
| public bool m_canRotate = true; |
| |
| |
| public bool m_randomInitBuildRotation; |
| public bool m_randomInitBuildRotation; |
| |
| |
| public bool m_canBeRemoved = true; |
| public bool m_canBeRemoved = true; |
| |
| |
| public bool m_allowRotatedOverlap; |
| public bool m_allowRotatedOverlap; |
| |
| |
| public bool m_vegetationGroundOnly; |
| public bool m_vegetationGroundOnly; |
| |
| |
| public List<Piece> m_blockingPieces = new List<Piece>(); |
| public List<Piece> m_blockingPieces = new List<Piece>(); |
| |
| |
| public float m_blockRadius; |
| public float m_blockRadius; |
| |
| |
| public ZNetView m_mustConnectTo; |
| public ZNetView m_mustConnectTo; |
| |
| |
| public float m_connectRadius; |
| public float m_connectRadius; |
| |
| |
| public bool m_mustBeAboveConnected; |
| public bool m_mustBeAboveConnected; |
| |
| |
| . | |
| public bool m_noVines; |
| |
| |
| |
| public int m_extraPlacementDistance; |
| |
| |
| [BitMask(typeof(Heightmap.Biome))] |
| [BitMask(typeof(Heightmap.Biome))] |
| public Heightmap.Biome m_onlyInBiome; |
| public Heightmap.Biome m_onlyInBiome; |
| |
| |
| [Header("Effects")] |
| [Header("Effects")] |
| public EffectList m_placeEffect = new EffectList(); |
| public EffectList m_placeEffect = new EffectList(); |
| |
| |
| [Header("Requirements")] |
| [Header("Requirements")] |
| public string m_dlc = ""; |
| public string m_dlc = ""; |
| |
| |
| public CraftingStation m_craftingStation; |
| public CraftingStation m_craftingStation; |
| |
| |
| public Piece.Requirement[] m_resources = Array.Empty<Piece.Requirement>(); |
| public Piece.Requirement[] m_resources = Array.Empty<Piece.Requirement>(); |
| |
| |
| public GameObject m_destroyedLootPrefab; |
| public GameObject m_destroyedLootPrefab; |
| |
| |
| private ZNetView m_nview; |
| private ZNetView m_nview; |
| |
| |
| private List<KeyValuePair<Renderer, Material[]>> m_invalidPlacementMaterials; |
| private List<KeyValuePair<Renderer, Material[]>> m_invalidPlacementMaterials; |
| |
| |
| private long m_creator; |
| private long m_creator; |
| |
| |
| private int m_myListIndex = -1; |
| private int m_myListIndex = -1; |
| |
| |
| private static int s_ghostLayer = 0; |
| private static int s_ghostLayer = 0; |
| |
| |
| private static int s_pieceRayMask = 0; |
| private static int s_pieceRayMask = 0; |
| |
| |
| private static readonly Collider[] s_pieceColliders = new Collider[2000]; |
| private static readonly Collider[] s_pieceColliders = new Collider[2000]; |
| |
| |
| private static readonly List<Piece> s_allPieces = new List<Piece>(); |
| private static readonly List<Piece> s_allPieces = new List<Piece>(); |
| |
| |
| private static readonly HashSet<Piece> s_allComfortPieces = new HashSet<Piece>(); |
| private static readonly HashSet<Piece> s_allComfortPieces = new HashSet<Piece>(); |
| |
| |
| public enum PieceCategory |
| public enum PieceCategory |
| { |
| { |
| Misc, |
| Misc, |
| Crafting, |
| Crafting, |
| . | Building, |
| BuildingWorkbench, |
| |
| BuildingStonecutter, |
| Furniture, |
| Furniture, |
| Max, |
| Max, |
| All = 100 |
| All = 100 |
| } |
| } |
| |
| |
| public enum ComfortGroup |
| public enum ComfortGroup |
| { |
| { |
| None, |
| None, |
| Fire, |
| Fire, |
| Bed, |
| Bed, |
| Banner, |
| Banner, |
| Chair, |
| Chair, |
| Table, |
| Table, |
| Carpet |
| Carpet |
| } |
| } |
| |
| |
| [Serializable] |
| [Serializable] |
| public class Requirement |
| public class Requirement |
| { |
| { |
| public int GetAmount(int qualityLevel) |
| public int GetAmount(int qualityLevel) |
| { |
| { |
| if (qualityLevel <= 1) |
| if (qualityLevel <= 1) |
| { |
| { |
| return this.m_amount; |
| return this.m_amount; |
| } |
| } |
| return (qualityLevel - 1) * this.m_amountPerLevel; |
| return (qualityLevel - 1) * this.m_amountPerLevel; |
| } |
| } |
| |
| |
| [Header("Resource")] |
| [Header("Resource")] |
| public ItemDrop m_resItem; |
| public ItemDrop m_resItem; |
| |
| |
| public int m_amount = 1; |
| public int m_amount = 1; |
| |
| |
| public int m_extraAmountOnlyOneIngredient; |
| public int m_extraAmountOnlyOneIngredient; |
| |
| |
| [Header("Item")] |
| [Header("Item")] |
| public int m_amountPerLevel = 1; |
| public int m_amountPerLevel = 1; |
| |
| |
| [Header("Piece")] |
| [Header("Piece")] |
| public bool m_recover = true; |
| public bool m_recover = true; |
| } |
| } |
| } |
| } |
| |
| |