public void DestroySingleDice(Dice_Control diceToDestroy, bool removeTileDice = true, bool playSound = true) { if (removeTileDice) { diceToDestroy.tileControl.RemoveDiceOnTile(); } diceToDestroy.SetDeselected(); diceToDestroy.StopAllCoroutines(); diceToDestroy.player.diceOwned.Remove(diceToDestroy.gameObject); Destroy(diceToDestroy.gameObject); if (playSound) { gameControl.audioManager.PlaySound("destroyDice"); } //gameControl.AllowInput();//check here for if there is allow input issues }
private async void MouseControl() { ray = mainCamera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 100)) { clickedObject = hit.transform.gameObject; if (currentySelected == null) { if (clickedObject.name == playerControl.activePlayer.name) { Dice_Control clickedDice = clickedObject.GetComponent <Dice_Control>(); if (clickedDice.lowerDice == false && clickedDice.isBase) { clickedDice = clickedObject.transform.parent.GetComponent <Dice_Control>(); } currentySelected = clickedDice; clickedDice.SetSelected(); } AllowInput(); } else { if (currentySelected.isBase) { if (currentySelected.gameObject.GetInstanceID() == clickedObject.GetInstanceID() || currentySelected.child.gameObject.GetInstanceID() == clickedObject.GetInstanceID()) { print("Deselecting currently seleted"); currentySelected.SetDeselected(); currentySelected = null; AllowInput(); return; } float distance = Vector3.Distance(currentySelected.transform.position, clickedObject.transform.position); //print("current distance to clicked object is: " + distance); if (distance <= GlobalVariables.data.BASE_SPAWN_DISTANCE) { if (clickedObject.name == GlobalVariables.data.TILE_NAME || clickedObject.name == currentySelected.player.name) { TileControl clickedTile = clickedObject.GetComponent <TileControl>(); if (clickedTile == null) { clickedTile = clickedObject.GetComponent <Dice_Control>().tileControl; } if (clickedTile.diceOnTile == null) { boardControl.CreateDiceAt(clickedTile, currentySelected.player); playerControl.TakenMove(); } else { Dice_Control diceOneTile = clickedTile.diceOnTile; if (currentySelected.player.name == diceOneTile.player.name) { boardControl.BaseReenforceAdjacent(diceOneTile); } else { boardControl.CalculateBasesAttackEnemy(currentySelected, diceOneTile); } } } else if (clickedObject.GetComponent <Dice_Control>() != null) { boardControl.CalculateBasesAttackEnemy(currentySelected, clickedObject.GetComponent <Dice_Control>()); } else { print("the user clicked a non player, not board object"); AllowInput(); } } else { TileControl clickedTile = clickedObject.GetComponent <TileControl>(); if (clickedTile == null) { Debug.Log($"object too far to consider Creating dice"); Dice_Control dice_Control = clickedObject.GetComponent <Dice_Control>(); if (dice_Control != null) { boardControl.InvalidMove(dice_Control.tileControl); } AllowInput(); } else { boardControl.InvalidMove(clickedTile); } } } else { if (currentySelected.gameObject.GetInstanceID() == clickedObject.GetInstanceID()) { print("Deselected currently seleted"); currentySelected.SetDeselected(); currentySelected = null; AllowInput(); return; } if (clickedObject.name == GlobalVariables.data.TILE_NAME || clickedObject.name == currentySelected.player.name) { //handles if dice was clicked, get the assosicated tile TileControl clickedTile = clickedObject.GetComponent <TileControl>(); if (clickedTile == null) { clickedTile = clickedObject.GetComponent <Dice_Control>().tileControl; } List <TileControl> path = boardControl.Pathfind(currentySelected.tileControl, clickedTile, playerControl.activePlayer.numberOfMoves); if (path == null) { AllowInput(); return; } else { PrintPath(path); if (clickedTile.diceOnTile == null) { await boardControl.MoveToEmptyTile(path, currentySelected); playerControl.TakenMove(); AllowInput(); } else { Dice_Control diceOneTile = clickedTile.diceOnTile; if (currentySelected.player.name == diceOneTile.player.name) { //this gets the child dice when a base is the target if (diceOneTile.isBase && diceOneTile.lowerDice) { boardControl.CombineFriendlyDice(currentySelected, diceOneTile.transform.GetChild(6).GetComponent <Dice_Control>(), path); } else { boardControl.CombineFriendlyDice(currentySelected, diceOneTile, path); } } else { if (diceOneTile.isBase) { boardControl.CalculateAttackEnemyBase(currentySelected, diceOneTile.transform.GetChild(6).GetComponent <Dice_Control>(), path); } else { await boardControl.CalculateAttackEnemy(currentySelected, diceOneTile, path); } } } } } else { Dice_Control clickedDice = clickedObject.GetComponent <Dice_Control>(); if (clickedDice != null) { List <TileControl> path = boardControl.Pathfind(currentySelected.tileControl, clickedDice.tileControl, playerControl.activePlayer.numberOfMoves); if (path == null) { AllowInput(); return; } else { PrintPath(path); if (clickedDice.isBase) { if (clickedDice.lowerDice) { boardControl.CalculateAttackEnemyBase(currentySelected, clickedDice.transform.GetChild(6).GetComponent <Dice_Control>(), path); } else { boardControl.CalculateAttackEnemyBase(currentySelected, clickedDice, path); } } else { await boardControl.CalculateAttackEnemy(currentySelected, clickedDice, path); } } } else { AllowInput(); print("the user clicked a non player, not board object"); } } } } } else { AllowInput(); } }
internal async void CombineFriendlyDice(Dice_Control selectedDice, Dice_Control targetDice, List <TileControl> path) { if (selectedDice.GetInstanceID() == targetDice.GetInstanceID()) { InvalidMove(targetDice.tileControl); return; } int sum = selectedDice.currentValue + targetDice.currentValue; if (targetDice.isBase) { if (targetDice.GetDiceValue() == 6) { InvalidMove(targetDice.tileControl); return; } if (sum > 6) { Debug.Log($"Reenforcing outpost from {targetDice.currentValue} to 6"); await HopTo(path, selectedDice); await targetDice.AnimateDiceValueChange(6); await selectedDice.AnimateDiceValueChange(sum - 6); } else if (sum == 6) { Debug.Log($"Absorbing unit, from {targetDice.currentValue} to 6"); await HopTo(path, selectedDice); await targetDice.AnimateDiceValueChange(6); DestroySingleDice(selectedDice, true, false); UpdateBoardMeta(selectedDice.tileControl, targetDice.tileControl, false); } else { Debug.Log($"Reenforcing outpost from {targetDice.currentValue} to " + sum); await HopTo(path, selectedDice); await targetDice.AnimateDiceValueChange(sum); DestroySingleDice(selectedDice, true, false); UpdateBoardMeta(selectedDice.tileControl, targetDice.tileControl, false); } //targetDice.SetSelected();//crashes here //gameControl.currentySelected = targetDice; gameControl.audioManager.PlaySound("combine"); gameControl.playerControl.TakenMove(path.Count); gameControl.AllowInput(); return; } else if (sum >= 12) { if (targetDice.isBase) { Debug.Log($"Target already base {targetDice.tileControl.tileIndex}"); InvalidMove(targetDice.tileControl); return; } gameControl.currentySelected = null; await HopTo(path, selectedDice); UpdateBoardMeta(selectedDice.tileControl, targetDice.tileControl); Debug.Log($"Making new Base at {targetDice.tileControl.tileIndex}"); CreateBase(selectedDice, targetDice); } else if (sum > 6) { if (targetDice.currentValue == 6) { Debug.Log($"Invlaid Move target at maximum"); InvalidMove(targetDice.tileControl); return; } Debug.Log($"Setting target from {targetDice.currentValue} to 6"); await HopTo(path, selectedDice); await targetDice.AnimateDiceValueChange(6); await selectedDice.AnimateDiceValueChange(sum - 6); } else if (sum <= 6) { await HopTo(path, selectedDice); Debug.Log($"Combining dice, {sum}"); await targetDice.AnimateDiceValueChange(sum); DestroySingleDice(selectedDice, true, false); UpdateBoardMeta(selectedDice.tileControl, targetDice.tileControl, false); } selectedDice.SetDeselected(); targetDice.SetSelected(); gameControl.currentySelected = targetDice; gameControl.audioManager.PlaySound("combine"); gameControl.playerControl.TakenMove(path.Count); gameControl.AllowInput(); }