/// <summary> /// Handles a selection input based on current board player is viewing. /// This should only be called on the owning clients player controller /// </summary> /// <param name="screenPos">Screen position of selection</param> /// <param name="rightClick">If selection was made using right click</param> private void handleSelection(Vector3 screenPos, bool rightClick) { // Right click is being used to activate abilities while in editor, // in actual games (where we are connected), we want to ignore this if (PhotonNetwork.IsConnected && rightClick) { return; } // Convert from screen space to world space Vector3 worldPos = m_camera.ScreenToWorldPoint(screenPos); BoardManager viewedBoard = getViewedBoardManager(); if (!viewedBoard) { return; } if (viewedBoard == Board && !rightClick) { if (!m_canPlaceTowers) { return; } Vector3Int tileIndex = viewedBoard.positionToIndex(worldPos); if (!viewedBoard.isPlaceableTile(tileIndex)) { return; } TowerBase tower = viewedBoard.getTowerOnTile(tileIndex); if (tower) { // Try destroying the tower if player has bulldozing active if (m_canBulldoze) { // Refund half of a cost of the tower giveGold(tower.m_cost / 2); AnalyticsHelpers.reportTowerBulldozed(tower); TowerBase.destroyTower(tower, true); } } else if (m_canBuildInBulldozeMode || !m_canBulldoze) { // We call this as selectedPos is highly likely not to be // the center of the tile, while this 100% will be Vector3 spawnPos = viewedBoard.indexToPosition(tileIndex); // Spawn tower on the server (replicates back to us if not master client) string prefabName; TowerBase towerPrefab = m_towersList.getSelectedTower(out prefabName); if (towerPrefab && canAfford(towerPrefab.m_cost)) { placeTowerAt(towerPrefab, prefabName, tileIndex, spawnPos); } } } else { // Right click is for using abilities while in editor if (!PhotonNetwork.IsConnected && !rightClick) { return; } AbilityBase ability = m_towersList.getSelectedAbility(); if (!canUseAbility(ability)) { return; } // Make sure we have actually clicked on the board Vector3Int tileIndex = viewedBoard.positionToIndex(worldPos); if (!viewedBoard.isValidTile(tileIndex)) { return; } // Check if this ability would allow us to select this position if (!ability.canUseAbilityHere(this, viewedBoard, worldPos, tileIndex)) { return; } ability.activateAbility(this, viewedBoard, worldPos, tileIndex); } }