public void RemoveTerrainFurniture(int value) { if (Terrain.ExtractContents(value) == 227) { int designIndex = FurnitureBlock.GetDesignIndex(Terrain.ExtractData(value)); if (designIndex < m_furnitureDesigns.Length) { m_furnitureDesigns[designIndex].m_terrainUseCount = MathUtils.Max(m_furnitureDesigns[designIndex].m_terrainUseCount - 1, 0); } } }
public void AddTerrainFurniture(int value) { if (Terrain.ExtractContents(value) == 227) { int designIndex = FurnitureBlock.GetDesignIndex(Terrain.ExtractData(value)); if (designIndex < m_furnitureDesigns.Length) { m_furnitureDesigns[designIndex].m_terrainUseCount++; } } }
public FurnitureDesign GetFurnitureDesign(object dragData) { InventoryDragData inventoryDragData = dragData as InventoryDragData; if (inventoryDragData != null) { int slotValue = inventoryDragData.Inventory.GetSlotValue(inventoryDragData.SlotIndex); if (Terrain.ExtractContents(slotValue) == 227) { int designIndex = FurnitureBlock.GetDesignIndex(Terrain.ExtractData(slotValue)); return(m_furnitureInventoryPanel.SubsystemFurnitureBlockBehavior.GetDesign(designIndex)); } } return(null); }
public override bool OnInteract(TerrainRaycastResult raycastResult, ComponentMiner componentMiner) { int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(raycastResult.CellFace.X, raycastResult.CellFace.Y, raycastResult.CellFace.Z); if (Terrain.ExtractContents(cellValue) == 227) { int designIndex = FurnitureBlock.GetDesignIndex(Terrain.ExtractData(cellValue)); FurnitureDesign design = GetDesign(designIndex); if (design != null && (design.InteractionMode == FurnitureInteractionMode.Multistate || design.InteractionMode == FurnitureInteractionMode.ConnectedMultistate)) { SwitchToNextState(raycastResult.CellFace.X, raycastResult.CellFace.Y, raycastResult.CellFace.Z, playSound: true); return(true); } } return(false); }
public void SwitchToNextState(int x, int y, int z, bool playSound) { HashSet <Point3> hashSet = new HashSet <Point3>(); List <Point3> list = new List <Point3>(); list.Add(new Point3(x, y, z)); int num = 0; while (num < list.Count && num < 4096) { Point3 item = list[num++]; if (!hashSet.Add(item)) { continue; } int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(item.X, item.Y, item.Z); if (Terrain.ExtractContents(cellValue) != 227) { continue; } int data = Terrain.ExtractData(cellValue); int designIndex = FurnitureBlock.GetDesignIndex(data); FurnitureDesign design = GetDesign(designIndex); if (design != null && design.LinkedDesign != null && design.LinkedDesign.Index >= 0 && (list.Count == 1 || design.InteractionMode == FurnitureInteractionMode.ConnectedMultistate)) { int data2 = FurnitureBlock.SetDesignIndex(data, design.LinkedDesign.Index, design.LinkedDesign.ShadowStrengthFactor, design.LinkedDesign.IsLightEmitter); int value = Terrain.ReplaceData(cellValue, data2); base.SubsystemTerrain.ChangeCell(item.X, item.Y, item.Z, value); if (design.InteractionMode == FurnitureInteractionMode.ConnectedMultistate) { list.Add(new Point3(item.X - 1, item.Y, item.Z)); list.Add(new Point3(item.X + 1, item.Y, item.Z)); list.Add(new Point3(item.X, item.Y - 1, item.Z)); list.Add(new Point3(item.X, item.Y + 1, item.Z)); list.Add(new Point3(item.X, item.Y, item.Z - 1)); list.Add(new Point3(item.X, item.Y, item.Z + 1)); } } } if (playSound) { m_subsystemAudio.PlaySound("Audio/BlockPlaced", 1f, 0f, new Vector3(x, y, z), 2f, autoDelay: true); } }
public int CountFurnitureDesigns() { int num = 0; for (int i = 0; i < m_furnitureInventoryPanel.ComponentFurnitureInventory.SlotsCount; i++) { int slotValue = m_furnitureInventoryPanel.ComponentFurnitureInventory.GetSlotValue(i); if (Terrain.ExtractContents(slotValue) == 227) { int designIndex = FurnitureBlock.GetDesignIndex(Terrain.ExtractData(slotValue)); FurnitureDesign design = m_furnitureInventoryPanel.SubsystemFurnitureBlockBehavior.GetDesign(designIndex); if (design != null && design.FurnitureSet == m_furnitureSet) { num++; } } } return(num); }
public void GarbageCollectDesigns(ReadOnlyList <ScannedItemData> allExistingItems) { for (int i = 0; i < m_furnitureDesigns.Length; i++) { if (m_furnitureDesigns[i] != null) { m_furnitureDesigns[i].m_gcUsed = (m_furnitureDesigns[i].m_terrainUseCount > 0); } } foreach (ScannedItemData item in allExistingItems) { if (Terrain.ExtractContents(item.Value) == 227) { int designIndex = FurnitureBlock.GetDesignIndex(Terrain.ExtractData(item.Value)); FurnitureDesign design = GetDesign(designIndex); if (design != null) { design.m_gcUsed = true; } } } for (int j = 0; j < m_furnitureDesigns.Length; j++) { if (m_furnitureDesigns[j] != null && m_furnitureDesigns[j].m_gcUsed) { FurnitureDesign linkedDesign = m_furnitureDesigns[j].LinkedDesign; while (linkedDesign != null && !linkedDesign.m_gcUsed) { linkedDesign.m_gcUsed = true; linkedDesign = linkedDesign.LinkedDesign; } } } for (int k = 0; k < m_furnitureDesigns.Length; k++) { if (m_furnitureDesigns[k] != null && !m_furnitureDesigns[k].m_gcUsed && m_furnitureDesigns[k].FurnitureSet == null) { m_furnitureDesigns[k].Index = -1; m_furnitureDesigns[k] = null; } } }
public void AssignInventorySlots() { List <int> list = new List <int>(); for (int i = 0; i < ComponentFurnitureInventory.SlotsCount; i++) { int slotValue = ComponentFurnitureInventory.GetSlotValue(i); int slotCount = ComponentFurnitureInventory.GetSlotCount(i); if (slotValue != 0 && slotCount > 0 && Terrain.ExtractContents(slotValue) == 227) { int designIndex = FurnitureBlock.GetDesignIndex(Terrain.ExtractData(slotValue)); FurnitureDesign design = SubsystemFurnitureBlockBehavior.GetDesign(designIndex); if (design != null && design.FurnitureSet == ComponentFurnitureInventory.FurnitureSet) { list.Add(i); } } } List <InventorySlotWidget> list2 = new List <InventorySlotWidget>((from w in m_inventoryGrid.Children select w as InventorySlotWidget into w where w != null select w).Cast <InventorySlotWidget>()); int num = ComponentFurnitureInventory.PageIndex * list2.Count; for (int j = 0; j < list2.Count; j++) { if (num < list.Count) { list2[j].AssignInventorySlot(ComponentFurnitureInventory, list[num]); } else { list2[j].AssignInventorySlot(null, 0); } num++; } m_pagesCount = (list.Count + list2.Count - 1) / list2.Count; m_assignedPage = ComponentFurnitureInventory.PageIndex; }
public void AddParticleSystems(int value, int x, int y, int z) { if (Terrain.ExtractContents(value) != 227) { return; } int data = Terrain.ExtractData(value); int rotation = FurnitureBlock.GetRotation(data); int designIndex = FurnitureBlock.GetDesignIndex(data); FurnitureDesign design = GetDesign(designIndex); if (design == null) { return; } List <FireParticleSystem> list = new List <FireParticleSystem>(); BoundingBox[] torchPoints = design.GetTorchPoints(rotation); if (torchPoints.Length != 0) { BoundingBox[] array = torchPoints; for (int i = 0; i < array.Length; i++) { BoundingBox boundingBox = array[i]; float num = (boundingBox.Size().X + boundingBox.Size().Y + boundingBox.Size().Z) / 3f; float size = MathUtils.Clamp(1.5f * num, 0.1f, 1f); FireParticleSystem fireParticleSystem = new FireParticleSystem(new Vector3(x, y, z) + boundingBox.Center(), size, 24f); m_subsystemParticles.AddParticleSystem(fireParticleSystem); list.Add(fireParticleSystem); } } if (list.Count > 0) { m_particleSystemsByCell[new Point3(x, y, z)] = list; } }
public static IEnumerable <CellFace> GetMountingCellFaces(SubsystemElectricity subsystemElectricity, Point3 point) { int data = Terrain.ExtractData(subsystemElectricity.SubsystemTerrain.Terrain.GetCellValue(point.X, point.Y, point.Z)); int rotation = FurnitureBlock.GetRotation(data); int designIndex = FurnitureBlock.GetDesignIndex(data); FurnitureDesign design = subsystemElectricity.SubsystemTerrain.SubsystemFurnitureBlockBehavior.GetDesign(designIndex); if (design == null) { yield break; } int face = 0; while (face < 6) { int num = (face < 4) ? ((face - rotation + 4) % 4) : face; if ((design.MountingFacesMask & (1 << num)) != 0) { yield return(new CellFace(point.X, point.Y, point.Z, CellFace.OppositeFace(face))); } int num2 = face + 1; face = num2; } }
public void ScanDesign(CellFace start, Vector3 direction, ComponentMiner componentMiner) { FurnitureDesign design = null; FurnitureDesign furnitureDesign = null; Dictionary <Point3, int> valuesDictionary = new Dictionary <Point3, int>(); Point3 point = start.Point; Point3 point2 = start.Point; int startValue = base.SubsystemTerrain.Terrain.GetCellValue(start.Point.X, start.Point.Y, start.Point.Z); int num = Terrain.ExtractContents(startValue); if (BlocksManager.Blocks[num] is FurnitureBlock) { int designIndex = FurnitureBlock.GetDesignIndex(Terrain.ExtractData(startValue)); furnitureDesign = GetDesign(designIndex); if (furnitureDesign == null) { componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Unsuitable block found", Color.White, blinking: true, playNotificationSound: false); return; } design = furnitureDesign.Clone(); design.LinkedDesign = null; design.InteractionMode = FurnitureInteractionMode.None; valuesDictionary.Add(start.Point, startValue); } else { Stack <Point3> val = new Stack <Point3>(); val.Push(start.Point); while (val.Count > 0) { Point3 key = val.Pop(); if (valuesDictionary.ContainsKey(key)) { continue; } int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(key.X, key.Y, key.Z); if (IsValueDisallowed(cellValue)) { componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Unsuitable block found", Color.White, blinking: true, playNotificationSound: false); return; } if (IsValueAllowed(cellValue)) { if (key.X < point.X) { point.X = key.X; } if (key.Y < point.Y) { point.Y = key.Y; } if (key.Z < point.Z) { point.Z = key.Z; } if (key.X > point2.X) { point2.X = key.X; } if (key.Y > point2.Y) { point2.Y = key.Y; } if (key.Z > point2.Z) { point2.Z = key.Z; } if (MathUtils.Abs(point.X - point2.X) >= 16 || MathUtils.Abs(point.Y - point2.Y) >= 16 || MathUtils.Abs(point.Z - point2.Z) >= 16) { componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Furniture design is too large", Color.White, blinking: true, playNotificationSound: false); return; } valuesDictionary[key] = cellValue; val.Push(new Point3(key.X - 1, key.Y, key.Z)); val.Push(new Point3(key.X + 1, key.Y, key.Z)); val.Push(new Point3(key.X, key.Y - 1, key.Z)); val.Push(new Point3(key.X, key.Y + 1, key.Z)); val.Push(new Point3(key.X, key.Y, key.Z - 1)); val.Push(new Point3(key.X, key.Y, key.Z + 1)); } } if (valuesDictionary.Count == 0) { componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("No suitable blocks found", Color.White, blinking: true, playNotificationSound: false); return; } design = new FurnitureDesign(base.SubsystemTerrain); Point3 point3 = point2 - point; int num2 = MathUtils.Max(MathUtils.Max(point3.X, point3.Y, point3.Z) + 1, 2); int[] array = new int[num2 * num2 * num2]; foreach (KeyValuePair <Point3, int> item in valuesDictionary) { Point3 point4 = item.Key - point; array[point4.X + point4.Y * num2 + point4.Z * num2 * num2] = item.Value; } design.SetValues(num2, array); int steps = (start.Face > 3) ? CellFace.Vector3ToFace(direction, 3) : CellFace.OppositeFace(start.Face); design.Rotate(1, steps); Point3 location = design.Box.Location; Point3 point5 = new Point3(design.Resolution) - (design.Box.Location + design.Box.Size); Point3 delta = new Point3((point5.X - location.X) / 2, -location.Y, (point5.Z - location.Z) / 2); design.Shift(delta); } BuildFurnitureDialog dialog = new BuildFurnitureDialog(design, furnitureDesign, delegate(bool result) { if (result) { design = TryAddDesign(design); if (design == null) { componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Too many different furniture designs", Color.White, blinking: true, playNotificationSound: false); } else { if (m_subsystemGameInfo.WorldSettings.GameMode != 0) { foreach (KeyValuePair <Point3, int> item2 in valuesDictionary) { base.SubsystemTerrain.DestroyCell(0, item2.Key.X, item2.Key.Y, item2.Key.Z, 0, noDrop: true, noParticleSystem: true); } } int value = Terrain.MakeBlockValue(227, 0, FurnitureBlock.SetDesignIndex(0, design.Index, design.ShadowStrengthFactor, design.IsLightEmitter)); int num3 = MathUtils.Clamp(design.Resolution, 4, 8); Matrix matrix = componentMiner.ComponentCreature.ComponentBody.Matrix; Vector3 position = matrix.Translation + 1f * matrix.Forward + 1f * Vector3.UnitY; m_subsystemPickables.AddPickable(value, num3, position, null, null); componentMiner.DamageActiveTool(1); componentMiner.Poke(forceRestart: false); for (int i = 0; i < 3; i++) { Time.QueueTimeDelayedExecution(Time.FrameStartTime + (double)((float)i * 0.25f), delegate { m_subsystemSoundMaterials.PlayImpactSound(startValue, new Vector3(start.Point), 1f); }); } if (componentMiner.ComponentCreature.PlayerStats != null) { componentMiner.ComponentCreature.PlayerStats.FurnitureItemsMade += num3; } } } }); if (componentMiner.ComponentPlayer != null) { DialogsManager.ShowDialog(componentMiner.ComponentPlayer.GuiWidget, dialog); } }