public void OnRegisterRelease() { if (!RoundHandler.energyDistributionState) { if (selectedDot != null) { try { if (OnDrag && !SecondSelected) { Debug.Log("past here"); foreach (DotHandler d in FindObjectsOfType <DotHandler>()) { if (d.OnMouse) { selectedDotBefore = selectedDot; selectedDot = d; break; } } } if (selectedDot.Owner == RoundHandler.CurrPlayerMove) { if (selectedDotBefore != null) { if (RoundHandler.CurrPlayerMove.playerDotHandlers.Contains(selectedDot)) { //establish Connection or Move Energy or wants to cancel if (selectedDot == selectedDotBefore) { CancelBuild(2); } else { if (Connection.FindConnectionBetween(selectedDot, selectedDotBefore) != null) { if (energyOnSelect < selectedDotBefore.Strength) { selectedDot.OnDrag = false; Destroy(AbsConnection.gameObject); AbsConnection = null; OnBuildEnd(); EnergyMove(selectedDotBefore, selectedDot, energyOnSelect); Debug.Log("Move Energy // " + energyOnSelect); //move Energy } else { CancelBuild(3); } } if (!AbsConnection.cannotBuild) { selectedDot.OnDrag = false; Debug.Log("Creating Connection // " + selectedDot + " // " + selectedDotBefore + " // " + this); AbsConnection.InitializeAbstractConnection(selectedDotBefore, selectedDot); //CreateConnection(selectedDot, selectedDotBefore); AbsConnection = null; OnBuildEnd(); EnergyMove(selectedDotBefore, selectedDot, energyOnSelect, 1); //Establish connection } else { //Move Energy over multiple nodes CancelBuild(5); } } } } } else { //Dot without owner or Dot owned by other player if (selectedDot.Owner == null) { //Dot without owner Debug.Log((energyOnSelect) + " // " + (selectedDotBefore) + " // " + (selectedDot) + " // " + (selectedDotBefore.Strength != energyOnSelect)); if (energyOnSelect > 1 && selectedDotBefore.Strength > 2 && selectedDotBefore.Strength != energyOnSelect && !AbsConnection.cannotBuild) { selectedDot.OnDrag = false; selectedDot.Owner = selectedDotBefore.Owner; Debug.Log("Creating Connection // " + selectedDot + " // " + selectedDotBefore); AbsConnection.InitializeAbstractConnection(selectedDotBefore, selectedDot); //CreateConnection(selectedDot, selectedDotBefore); AbsConnection = null; Debug.Log("Taken over dot: " + this); EnergyMove(selectedDotBefore, selectedDot, energyOnSelect, 1); RoundHandler.CurrPlayerMove.playerDotHandlers.Add(selectedDot); OnBuildEnd(); //Taking over empty dot } else { CancelBuild(4); } } else { //player wants to attack other dot Debug.Log(RoundHandler.CurrPlayerMove + " attacks " + selectedDot.Owner + " // " + energyOnSelect); Debug.Log(selectedDotBefore + " // " + selectedDot); if (selectedDotBefore != selectedDot) //small bug might be appearant where selectedDot = selectedDotBefore { selectedDotBefore.AttackDot(selectedDot, energyOnSelect); } OnBuildEnd(); } } } catch (System.Exception e) { CancelBuild(0, "", e); } } } }
void AttackOtherDot(DotHandler subject, DotHandler otherDot) { subject.AttackDot(otherDot, subject.Strength - 1); RoundHandler.CurrPlayerMove.playerDotHandlers.Add(otherDot); }