public void ServerPerformInteraction(PositionalHandApply interaction) { //which matrix are we clicking on var interactableTiles = InteractableTiles.GetAt(interaction.WorldPositionTarget, true); Vector3Int cellPos = interactableTiles.WorldToCell(interaction.WorldPositionTarget); var tileAtPosition = interactableTiles.LayerTileAt(interaction.WorldPositionTarget); //which way are we placing it foreach (var entry in waysToPlace) { //open space if (tileAtPosition == null && entry.placeableOn == LayerType.None && entry.placeableOnlyOnTile == null) { interactableTiles.TileChangeManager.UpdateTile(cellPos, entry.layerTile); break; } // placing on an existing tile else if (tileAtPosition.LayerType == entry.placeableOn && (entry.placeableOnlyOnTile == null || entry.placeableOnlyOnTile == tileAtPosition)) { interactableTiles.TileChangeManager.UpdateTile(cellPos, entry.layerTile); break; } } interactableTiles.TileChangeManager.SubsystemManager.UpdateAt(cellPos); Inventory.ServerConsume(interaction.HandSlot, 1); }
public void ServerPerformInteraction(PositionalHandApply interaction) { //which matrix are we clicking on var interactableTiles = InteractableTiles.GetAt(interaction.WorldPositionTarget, true); Vector3Int cellPos = interactableTiles.WorldToCell(interaction.WorldPositionTarget); var tileAtPosition = interactableTiles.LayerTileAt(interaction.WorldPositionTarget, layerTypeSelection); PlaceableTileEntry placeableTileEntry = null; int itemAmount = 1; var stackable = interaction.HandObject.GetComponent <Stackable>(); if (stackable != null) { itemAmount = stackable.Amount; } // find the first valid way possible to place a tile foreach (var entry in waysToPlace) { //skip what can't be afforded if (entry.itemCost > itemAmount) { continue; } //open space if (tileAtPosition == null && entry.placeableOn == LayerType.None && entry.placeableOnlyOnTile == null) { placeableTileEntry = entry; break; } // placing on an existing tile else if (tileAtPosition.LayerType == entry.placeableOn && (entry.placeableOnlyOnTile == null || entry.placeableOnlyOnTile == tileAtPosition)) { placeableTileEntry = entry; break; } } if (placeableTileEntry != null) { GameObject performer = interaction.Performer; Vector2 targetPosition = interaction.WorldPositionTarget; void ProgressFinishAction() { interactableTiles.TileChangeManager.UpdateTile(cellPos, placeableTileEntry.layerTile); interactableTiles.TileChangeManager.SubsystemManager.UpdateAt(cellPos); Inventory.ServerConsume(interaction.HandSlot, placeableTileEntry.itemCost); SoundManager.PlayNetworkedAtPos(placeSound, targetPosition); } var bar = StandardProgressAction.Create(ProgressConfig, ProgressFinishAction) .ServerStartProgress(targetPosition, placeableTileEntry.timeToPlace, performer); } }
private void ScrewInPlace(HandApply interaction) { var interactableTiles = InteractableTiles.GetAt(interaction.TargetObject.TileWorldPosition(), true); Vector3Int cellPos = interactableTiles.WorldToCell(interaction.TargetObject.TileWorldPosition()); interactableTiles.TileChangeManager.UpdateTile(cellPos, layerTile); interactableTiles.TileChangeManager.SubsystemManager.UpdateAt(cellPos); Despawn.ServerSingle(gameObject); }
private void SpawnTable(HandApply interaction, LayerTile tableToSpawn) { var interactableTiles = InteractableTiles.GetAt(interaction.TargetObject.TileWorldPosition(), true); Vector3Int cellPos = interactableTiles.WorldToCell(interaction.TargetObject.TileWorldPosition()); interaction.HandObject.GetComponent <Stackable>().ServerConsume(2); interactableTiles.TileChangeManager.UpdateTile(cellPos, tableToSpawn); interactableTiles.TileChangeManager.SubsystemManager.UpdateAt(cellPos); _ = Despawn.ServerSingle(gameObject); }
public bool WillInteract(PositionalHandApply interaction, NetworkSide side) { if (!DefaultWillInteract.Default(interaction, side)) { return(false); } if (interaction.HandObject != gameObject) { return(false); } //it's annoying to place something when you're trying to pick up instead to add to your current stack, //so if it's possible to stack what is being targeted with what's in your hand, we will defer to that if (Validations.CanStack(interaction.HandObject, interaction.TargetObject)) { return(false); } //check if we are clicking a spot we can place a tile on var interactableTiles = InteractableTiles.GetAt(interaction.WorldPositionTarget, side); var tileAtPosition = interactableTiles.LayerTileAt(interaction.WorldPositionTarget); foreach (var entry in waysToPlace) { //open space if (tileAtPosition == null && entry.placeableOn == LayerType.None && entry.placeableOnlyOnTile == null) { return(true); } // placing on an existing tile else if (tileAtPosition.LayerType == entry.placeableOn && (entry.placeableOnlyOnTile == null || entry.placeableOnlyOnTile == tileAtPosition)) { return(true); } } return(false); }