//for internal IF2 usages only, does server side logic for processing tileapply public void ServerProcessInteraction(int tileInteractionIndex, GameObject performer, Vector2 targetVector, GameObject processorObj, ItemSlot usedSlot, GameObject usedObject, Intent intent, TileApply.ApplyType applyType) { //find the indicated tile interaction var worldPosTarget = (Vector2)performer.transform.position + targetVector; //pass the interaction down to the basic tile LayerTile tile = LayerTileAt(worldPosTarget, true); if (tile is BasicTile basicTile) { if (tileInteractionIndex >= basicTile.TileInteractions.Count) { //this sometimes happens due to lag, so bumping it down to trace Logger.LogTraceFormat("Requested TileInteraction at index {0} does not exist on this tile {1}.", Category.Interaction, tileInteractionIndex, basicTile.name); return; } var tileInteraction = basicTile.TileInteractions[tileInteractionIndex]; var tileApply = new TileApply(performer, usedObject, intent, (Vector2Int)WorldToCell(worldPosTarget), this, basicTile, usedSlot, targetVector, applyType); if (tileInteraction.WillInteract(tileApply, NetworkSide.Server) && Cooldowns.TryStartServer(tileApply, CommonCooldowns.Instance.Interaction)) { //perform tileInteraction.ServerPerformInteraction(tileApply); } else { tileInteraction.ServerRollbackClient(tileApply); } } }
//for internal IF2 usages only, does server side logic for processing tileapply public void ServerProcessInteraction(GameObject performer, Vector2 targetVector, GameObject processorObj, ItemSlot usedSlot, GameObject usedObject, Intent intent, TileApply.ApplyType applyType) { //find the indicated tile interaction var worldPosTarget = (Vector2)performer.transform.position + targetVector; Vector3Int localPosition = WorldToCell(worldPosTarget); //pass the interaction down to the basic tile LayerTile tile = LayerTileAt(worldPosTarget, true); if (tile is BasicTile basicTile) { // check which tile interaction occurs in the correct order Logger.LogTraceFormat( "Server checking which tile interaction to trigger for TileApply on tile {0} at worldPos {1}", Category.Interaction, tile.name, worldPosTarget); if (basicTile.LayerType == LayerType.Underfloor) { foreach (var underFloorTile in matrix.UnderFloorLayer.GetAllTilesByType <BasicTile>(localPosition)) { var underFloorApply = new TileApply( performer, usedObject, intent, (Vector2Int)localPosition, this, underFloorTile, usedSlot, targetVector, applyType); foreach (var tileInteraction in underFloorTile.TileInteractions) { if (tileInteraction == null) { continue; } if (tileInteraction.WillInteract(underFloorApply, NetworkSide.Server)) { PerformTileInteract(underFloorApply); break; } } } } else { var tileApply = new TileApply( performer, usedObject, intent, (Vector2Int)localPosition, this, basicTile, usedSlot, targetVector, applyType); PerformTileInteract(tileApply); } } }
//for internal IF2 usages only, does server side logic for processing tileapply public void ServerProcessInteraction(GameObject performer, Vector2 targetVector, GameObject processorObj, ItemSlot usedSlot, GameObject usedObject, Intent intent, TileApply.ApplyType applyType) { //find the indicated tile interaction var worldPosTarget = (Vector2)performer.transform.position + targetVector; //pass the interaction down to the basic tile LayerTile tile = LayerTileAt(worldPosTarget, true); if (tile is BasicTile basicTile) { // check which tile interaction occurs in the correct order Logger.LogTraceFormat("Server checking which tile interaction to trigger for TileApply on tile {0} at worldPos {1}", Category.Interaction, tile.name, worldPosTarget); var tileApply = new TileApply(performer, usedObject, intent, (Vector2Int)WorldToCell(worldPosTarget), this, basicTile, usedSlot, targetVector, applyType); foreach (var tileInteraction in basicTile.TileInteractions) { if (tileInteraction == null) { continue; } if (tileInteraction.WillInteract(tileApply, NetworkSide.Server)) { //perform if not on cooldown if (Cooldowns.TryStartServer(tileApply, CommonCooldowns.Instance.Interaction)) { tileInteraction.ServerPerformInteraction(tileApply); } else { //hit a cooldown, rollback in case client tried to predict it tileInteraction.ServerRollbackClient(tileApply); } // interaction should've triggered and did or we hit a cooldown, so we're // done processing this request. break; } else { tileInteraction.ServerRollbackClient(tileApply); } } } }