public override void OnHitByProjectile(CellFace cellFace, WorldItem worldItem) { if (worldItem.ToRemove) { return; } ComponentBlockEntity blockEntity = m_subsystemBlockEntities.GetBlockEntity(cellFace.X, cellFace.Y, cellFace.Z); if (blockEntity != null && DispenserBlock.GetAcceptsDrops(Terrain.ExtractData(m_subsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z)))) { ComponentDispenser inventory = blockEntity.Entity.FindComponent <ComponentDispenser>(throwOnError: true); Pickable pickable = worldItem as Pickable; int num = pickable?.Count ?? 1; int num2 = ComponentInventoryBase.AcquireItems(inventory, worldItem.Value, num); if (num2 < num) { m_subsystemAudio.PlaySound("Audio/PickableCollected", 1f, 0f, worldItem.Position, 3f, autoDelay: true); } if (num2 <= 0) { worldItem.ToRemove = true; } else if (pickable != null) { pickable.Count = num2; } } }
public override bool OnInteract(TerrainRaycastResult raycastResult, ComponentMiner componentMiner) { if (m_subsystemGameInfo.WorldSettings.GameMode != GameMode.Adventure) { ComponentBlockEntity blockEntity = m_subsystemBlockEntities.GetBlockEntity(raycastResult.CellFace.X, raycastResult.CellFace.Y, raycastResult.CellFace.Z); if (blockEntity != null && componentMiner.ComponentPlayer != null) { ComponentDispenser componentDispenser = blockEntity.Entity.FindComponent <ComponentDispenser>(throwOnError: true); componentMiner.ComponentPlayer.ComponentGui.ModalPanelWidget = new DispenserWidget(componentMiner.Inventory, componentDispenser); AudioManager.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f); return(true); } } return(false); }
public DispenserWidget(IInventory inventory, ComponentDispenser componentDispenser) { m_componentDispenser = componentDispenser; m_componentBlockEntity = componentDispenser.Entity.FindComponent <ComponentBlockEntity>(throwOnError: true); m_subsystemTerrain = componentDispenser.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true); XElement node = ContentManager.Get <XElement>("Widgets/DispenserWidget"); LoadContents(this, node); m_inventoryGrid = Children.Find <GridPanelWidget>("InventoryGrid"); m_dispenserGrid = Children.Find <GridPanelWidget>("DispenserGrid"); m_dispenseButton = Children.Find <ButtonWidget>("DispenseButton"); m_shootButton = Children.Find <ButtonWidget>("ShootButton"); m_acceptsDropsBox = Children.Find <CheckboxWidget>("AcceptsDropsBox"); int num = 0; for (int i = 0; i < m_dispenserGrid.RowsCount; i++) { for (int j = 0; j < m_dispenserGrid.ColumnsCount; j++) { InventorySlotWidget inventorySlotWidget = new InventorySlotWidget(); inventorySlotWidget.AssignInventorySlot(componentDispenser, num++); m_dispenserGrid.Children.Add(inventorySlotWidget); m_dispenserGrid.SetWidgetCell(inventorySlotWidget, new Point2(j, i)); } } num = 10; for (int k = 0; k < m_inventoryGrid.RowsCount; k++) { for (int l = 0; l < m_inventoryGrid.ColumnsCount; l++) { InventorySlotWidget inventorySlotWidget2 = new InventorySlotWidget(); inventorySlotWidget2.AssignInventorySlot(inventory, num++); m_inventoryGrid.Children.Add(inventorySlotWidget2); m_inventoryGrid.SetWidgetCell(inventorySlotWidget2, new Point2(l, k)); } } }