internal async void DeconstrucetBase(Dice_Control childDice, int remainingValue) { //Debug.Log($"destroying {childDice.gameObject.GetInstanceID()}"); GameObject parentObject = childDice.gameObject.transform.parent.gameObject; Dice_Control parentDice = parentObject.GetComponent <Dice_Control>(); parentDice.tileControl.SetDiceOnTile(parentDice); Destroy(childDice.gameObject); parentDice.isBase = false; parentDice.child = null; //Debug.Log($"setting {parentDice.gameObject.GetInstanceID()} to {remainingValue}"); await parentDice.AnimateDiceValueChange(remainingValue); }
internal async void BaseReenforceAdjacent(Dice_Control targetDice) { if (targetDice.currentValue < 6) { await targetDice.AnimateDiceValueChange(targetDice.currentValue + 1); gameControl.audioManager.PlaySound("reenforce"); gameControl.playerControl.TakenMove(); } else { //Debug.Log($"Invlaid Move {targetDice.value} at maximum"); InvalidMove(targetDice.tileControl); } }
internal async Task CalculateAttackEnemy(Dice_Control attackingDice, Dice_Control targetEnemyDice, List <TileControl> path) { if (attackingDice.currentValue % 2 == 0) { int remainder = targetEnemyDice.currentValue - attackingDice.currentValue; if (remainder < 0) { Debug.Log($"Attacker won {-remainder} remaining"); await HopTo(path, attackingDice, true); DestroySingleDice(targetEnemyDice); await attackingDice.AnimateDiceValueChange(-remainder); await MoveToEmptyTile(new List <TileControl> { path.Last() }, attackingDice); } else if (remainder == 0) { Debug.Log($"Tie, both destroyed"); await HopTo(path, attackingDice, true); gameControl.audioManager.PlaySound("hitEnemy"); DestroySingleDice(attackingDice, true, false); DestroySingleDice(targetEnemyDice, true, false); } else { Debug.Log($"Defender now at {remainder}"); await HopTo(path, attackingDice, true); await targetEnemyDice.AnimateDiceValueChange(remainder); gameControl.audioManager.PlaySound("hitEnemy"); DestroySingleDice(attackingDice, true, false); } gameControl.playerControl.TakenMove(path.Count); gameControl.AllowInput(); } else { Debug.Log($"Invlaid Move {attackingDice.currentValue} not attacker"); InvalidMove(targetEnemyDice.tileControl); } }
internal async void CalculateBasesAttackEnemy(Dice_Control OwenDice, Dice_Control targetDice) { if (targetDice.isBase) { //Debug.Log($"Invlaid Move bases can't attack bases"); InvalidMove(targetDice.tileControl); } else { if (targetDice.currentValue > 1) { await targetDice.AnimateDiceValueChange(targetDice.currentValue - 1);//defending base attack value } else { targetDice.tileControl.RemoveDiceOnTile(); DestroySingleDice(targetDice); } gameControl.audioManager.PlaySound("outpostAttack"); gameControl.playerControl.TakenMove(1); gameControl.AllowInput(); } }
internal async void CalculateAttackEnemyBase(Dice_Control attackingDice, Dice_Control targetEnemyBaseChild, List <TileControl> path) { if (attackingDice.currentValue % 2 == 0) { await HopTo(path, attackingDice, true); int remainder = targetEnemyBaseChild.currentValue - attackingDice.currentValue; if (remainder < 0) { Debug.Log($"base destoryed and left {6 - -remainder}"); DestroySingleDice(attackingDice); DeconstrucetBase(targetEnemyBaseChild, 6 - -remainder); } else if (remainder == 0) { Debug.Log($"base destoryed"); DestroySingleDice(attackingDice); DeconstrucetBase(targetEnemyBaseChild, 6); } else { Debug.Log($"base now at {remainder}"); await targetEnemyBaseChild.AnimateDiceValueChange(remainder); DestroySingleDice(attackingDice); } gameControl.playerControl.TakenMove(path.Count); gameControl.AllowInput(); } else { Debug.Log($"Invlaid Move {attackingDice.currentValue} not attacker"); InvalidMove(targetEnemyBaseChild.tileControl); } //each case either has destroy base, that allows input, or is invalid, and set allow input }
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(); }