public void OptionSelected(DefendCommand defendCommand) { combatState = CombatState.ResolvingCombat; defendCommandPanel.SetActive(false); dialogText.text += "\n" + defender.name + " tries to " + defendCommand.Name() + "!"; // do calculations float baseToHit = .75f; float baseToDodge = defendCommand.SuccessRate; Debug.Log(baseToHit - baseToDodge); float toHitAdjusted = Mathf.Clamp(baseToHit - baseToDodge, MinToHitChance, MaxToHitChance); dialogText.text += "\n Total chance to hit is " + toHitAdjusted; float rand = Random.Range(0f, 1); dialogText.text += "\n " + attacker.name + " rolled a " + rand; if (rand <= toHitAdjusted) { dialogText.text += "\n " + attacker.name + " Hit!"; } else { dialogText.text += "\n " + defender.name + " " + defendCommand.Verbed() + " the attack!"; } // resolve counter attacks // calculate damage, if any // resolve final results (forced movements, saving throws, status inflictions, etc) // continue with turn attacker.CombatResolved(); combatState = CombatState.Done; }