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); } }
public void ServerPerformInteraction(PositionalHandApply interaction) { //which matrix are we clicking on var matrix = InteractableTiles.TryGetNonSpaceMatrix(interaction.WorldPositionTarget.RoundToInt(), true); if (matrix.IsSpaceMatrix) { matrix = interaction.Performer.RegisterTile().Matrix; } var interactableTiles = matrix.TileChangeManager.InteractableTiles; 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; } placeableTileEntry = FindValidTile(itemAmount, tileAtPosition); if (placeableTileEntry != null) { GameObject performer = interaction.Performer; Vector2 targetPosition = interaction.WorldPositionTarget; void ProgressFinishAction() { ProgressFinishActionPriv(interaction, placeableTileEntry, interactableTiles, cellPos, targetPosition); } void ProgressInterruptedAction(ActionInterruptionType reason) { ProgressInterruptedActionPriv(interaction, reason, placeableTileEntry); } var bar = StandardProgressAction.Create(ProgressConfig, ProgressFinishAction, ProgressInterruptedAction) .ServerStartProgress(targetPosition, placeableTileEntry.timeToPlace, performer); } }
private void ProgressFinishActionPriv(PositionalHandApply interaction, PlaceableTileEntry placeableTileEntry, InteractableTiles interactableTiles, Vector3Int cellPos, Vector2 targetPosition) { if (Inventory.ServerConsume(interaction.HandSlot, placeableTileEntry.itemCost)) { interactableTiles.TileChangeManager.MetaTileMap.SetTile(cellPos, placeableTileEntry.layerTile); interactableTiles.TileChangeManager.SubsystemManager.UpdateAt(cellPos); SoundManager.PlayNetworkedAtPos(placeSound, targetPosition); } else { Chat.AddExamineMsgFromServer(interaction.PerformerPlayerScript.connectedPlayer, $"You lack the materials to finish placing {placeableTileEntry.layerTile.DisplayName}"); } }
private static void ProgressInterruptedActionPriv(PositionalHandApply interaction, ActionInterruptionType reason, PlaceableTileEntry placeableTileEntry) { switch (reason) { case ActionInterruptionType.ChangeToPerformerActiveSlot: Chat.AddExamineMsgFromServer(interaction.PerformerPlayerScript.connectedPlayer, $"You lack the materials to finish placing {placeableTileEntry.layerTile.DisplayName}"); break; case ActionInterruptionType.PerformerUnconscious: Chat.AddExamineMsgFromServer(interaction.PerformerPlayerScript.connectedPlayer, $"You dream of placing {placeableTileEntry.layerTile.DisplayName}"); break; case ActionInterruptionType.WelderOff: Chat.AddExamineMsgFromServer(interaction.PerformerPlayerScript.connectedPlayer, $"You need the welder to be on to finish this"); break; case ActionInterruptionType.PerformerOrTargetMoved: Chat.AddExamineMsgFromServer(interaction.PerformerPlayerScript.connectedPlayer, $"Cannot place {placeableTileEntry.layerTile.DisplayName}, you or your target moved too much"); break; case ActionInterruptionType.TargetDespawn: Chat.AddExamineMsgFromServer(interaction.PerformerPlayerScript.connectedPlayer, $"Placing {placeableTileEntry.layerTile.DisplayName} has become a tall order, seeing as the conceptual physical placement space has ceased to exist"); break; case ActionInterruptionType.PerformerDirection: Chat.AddExamineMsgFromServer(interaction.PerformerPlayerScript.connectedPlayer, $"You have looked away from placing {placeableTileEntry.layerTile.DisplayName}"); break; } }