/* * Copyright (C) 2012 Joe AmRhein * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.arconus.dicecommander.model.entities.dice; import com.arconus.dicecommander.interactors.diceformatters.FormatDiceFormulaResult; import java.util.ArrayList; import java.util.List; public class DiceFormulaResult { private List<SingleDieResult> dieResults; private int modifier; public DiceFormulaResult(int modifier) { dieResults = new ArrayList<SingleDieResult>(); this.modifier = modifier; } public void addSingleDieResult(SingleDieResult result) { dieResults.add(result); } public int getTotalResult() { int total = 0; for (SingleDieResult i : dieResults) { total += i.getResult(); } total += modifier; return total; } public String getDiceFormulaResultString() { return FormatDiceFormulaResult.getDiceFormulaResultString(dieResults, modifier); } //returns a SUCCESS or FAILURE if dieResults contains only 1 d20. Otherwise, return NONE public CriticalStatus getCriticalStatus() { int d20Count = 0; SingleDieResult d20Result = null; for (SingleDieResult s : dieResults) { if (s.getNumberOfSides() == 20) { d20Count++; d20Result = s; } } if (d20Count == 1) { return d20Result.getCriticalStatus(); } else return CriticalStatus.NONE; } }