public void MovingBlocksCollidedWithTerrain(IMovingBlockSet movingBlockSet, Point3 p) { if (!(movingBlockSet.Id == "Piston")) { return; } Point3 point = (Point3)movingBlockSet.Tag; int cellValue = m_subsystemTerrain.Terrain.GetCellValue(point.X, point.Y, point.Z); if (Terrain.ExtractContents(cellValue) != 237) { return; } Point3 point2 = CellFace.FaceToPoint3(PistonBlock.GetFace(Terrain.ExtractData(cellValue))); int num = p.X * point2.X + p.Y * point2.Y + p.Z * point2.Z; int num2 = point.X * point2.X + point.Y * point2.Y + point.Z * point2.Z; if (num > num2) { if (IsBlockBlocking(base.SubsystemTerrain.Terrain.GetCellValue(p.X, p.Y, p.Z))) { movingBlockSet.Stop(); } else { base.SubsystemTerrain.DestroyCell(0, p.X, p.Y, p.Z, 0, noDrop: false, noParticleSystem: false); } } }
public void FindMovingBlocksCollisionBoxes(Vector3 position, DynamicArray <CollisionBox> result) { Vector3 boxSize = BoxSize; BoundingBox boundingBox = new BoundingBox(position - new Vector3(boxSize.X / 2f, 0f, boxSize.Z / 2f), position + new Vector3(boxSize.X / 2f, boxSize.Y, boxSize.Z / 2f)); boundingBox.Min -= new Vector3(1f); boundingBox.Max += new Vector3(1f); m_movingBlockSets.Clear(); m_subsystemMovingBlocks.FindMovingBlocks(boundingBox, extendToFillCells: false, m_movingBlockSets); for (int i = 0; i < m_movingBlockSets.Count; i++) { IMovingBlockSet movingBlockSet = m_movingBlockSets.Array[i]; for (int j = 0; j < movingBlockSet.Blocks.Count; j++) { MovingBlock movingBlock = movingBlockSet.Blocks[j]; int num = Terrain.ExtractContents(movingBlock.Value); Block block = BlocksManager.Blocks[num]; if (block.IsCollidable) { BoundingBox[] customCollisionBoxes = block.GetCustomCollisionBoxes(m_subsystemTerrain, movingBlock.Value); Vector3 v = new Vector3(movingBlock.Offset) + movingBlockSet.Position; for (int k = 0; k < customCollisionBoxes.Length; k++) { result.Add(new CollisionBox { Box = new BoundingBox(v + customCollisionBoxes[k].Min, v + customCollisionBoxes[k].Max), BlockValue = movingBlock.Value, BlockVelocity = movingBlockSet.CurrentVelocity }); } } } } }
public void RemoveMovingBlockSet(IMovingBlockSet movingBlockSet) { MovingBlockSet movingBlockSet2 = (MovingBlockSet)movingBlockSet; if (m_movingBlockSets.Remove(movingBlockSet2)) { m_removing.Add(movingBlockSet2); movingBlockSet2.RemainCounter = 4; } }
public void MovingBlocksCollidedWithTerrain(IMovingBlockSet movingBlockSet, Point3 p) { if (movingBlockSet.Id == "CollapsingBlock") { int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(p.X, p.Y, p.Z); if (IsCollapseSupportBlock(cellValue)) { movingBlockSet.Stop(); } else if (IsCollapseDestructibleBlock(cellValue)) { base.SubsystemTerrain.DestroyCell(0, p.X, p.Y, p.Z, 0, noDrop: false, noParticleSystem: false); } } }
public void MovingBlocksStopped(IMovingBlockSet movingBlockSet) { if (movingBlockSet.Id == "CollapsingBlock") { Point3 p = Terrain.ToCell(MathUtils.Round(movingBlockSet.Position.X), MathUtils.Round(movingBlockSet.Position.Y), MathUtils.Round(movingBlockSet.Position.Z)); foreach (MovingBlock block in movingBlockSet.Blocks) { Point3 point = p + block.Offset; base.SubsystemTerrain.DestroyCell(0, point.X, point.Y, point.Z, block.Value, noDrop: false, noParticleSystem: false); } m_subsystemMovingBlocks.RemoveMovingBlockSet(movingBlockSet); if (movingBlockSet.Blocks.Count > 0) { m_subsystemSoundMaterials.PlayImpactSound(movingBlockSet.Blocks[0].Value, movingBlockSet.Position, 1f); } } }
public void MovingBlocksStopped(IMovingBlockSet movingBlockSet) { if (!(movingBlockSet.Id == "Piston") || !(movingBlockSet.Tag is Point3)) { return; } Point3 key = (Point3)movingBlockSet.Tag; if (Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValue(key.X, key.Y, key.Z)) == 237) { if (!m_actions.TryGetValue(key, out QueuedAction value)) { value = new QueuedAction(); m_actions.Add(key, value); } value.Stop = true; } }
public bool TryModifyItem(ScannedItemData itemData, int newValue) { if (itemData.Container is IInventory) { IInventory obj = (IInventory)itemData.Container; obj.RemoveSlotItems(itemData.IndexInContainer, itemData.Count); int slotCapacity = obj.GetSlotCapacity(itemData.IndexInContainer, newValue); obj.AddSlotItems(itemData.IndexInContainer, newValue, MathUtils.Min(itemData.Count, slotCapacity)); return(true); } if (itemData.Container is WorldItem) { ((WorldItem)itemData.Container).Value = newValue; return(true); } if (itemData.Container is IMovingBlockSet) { IMovingBlockSet obj2 = (IMovingBlockSet)itemData.Container; MovingBlock movingBlock = obj2.Blocks.ElementAt(itemData.IndexInContainer); obj2.SetBlock(movingBlock.Offset, newValue); return(true); } return(false); }
public void StopPiston(Point3 position) { IMovingBlockSet movingBlockSet = m_subsystemMovingBlocks.FindMovingBlocks("Piston", position); if (movingBlockSet != null) { int cellValue = m_subsystemTerrain.Terrain.GetCellValue(position.X, position.Y, position.Z); int num = Terrain.ExtractContents(cellValue); int data = Terrain.ExtractData(cellValue); bool flag = num == 237; bool isExtended = false; m_subsystemMovingBlocks.RemoveMovingBlockSet(movingBlockSet); foreach (MovingBlock block in movingBlockSet.Blocks) { int x = Terrain.ToCell(MathUtils.Round(movingBlockSet.Position.X)) + block.Offset.X; int y = Terrain.ToCell(MathUtils.Round(movingBlockSet.Position.Y)) + block.Offset.Y; int z = Terrain.ToCell(MathUtils.Round(movingBlockSet.Position.Z)) + block.Offset.Z; if (!(new Point3(x, y, z) == position)) { int num2 = Terrain.ExtractContents(block.Value); if (flag || num2 != 238) { m_subsystemTerrain.DestroyCell(0, x, y, z, block.Value, noDrop: false, noParticleSystem: false); if (num2 == 238) { isExtended = true; } } } } if (flag) { m_subsystemTerrain.ChangeCell(position.X, position.Y, position.Z, Terrain.MakeBlockValue(237, 0, PistonBlock.SetIsExtended(data, isExtended))); } } }