/* * 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.character.power; import com.arconus.dicecommander.model.entities.character.Defenses; import com.arconus.dicecommander.model.entities.dice.CriticalStatus; import com.arconus.dicecommander.model.entities.dice.DiceFormula; import com.arconus.dicecommander.model.entities.dice.DiceFormulaResult; import java.util.UUID; public class CharPower implements Comparable<CharPower> { private UUID id; private String name; private PowerUsage powerUsage; private ActionType actionType; private AttackType attackType; private Defenses targetDefense; private DiceFormula attackRoll; private DiceFormula damageRoll; public CharPower() { id = UUID.randomUUID(); name = ""; powerUsage = null; actionType = null; attackType = null; targetDefense = null; attackRoll = null; damageRoll = null; } public CharPower(String name, PowerUsage powerUsage, ActionType actionType, AttackType attackType, Defenses targetDefense, DiceFormula attackRoll, DiceFormula damageRoll) { id = UUID.randomUUID(); this.name = name; this.attackRoll = attackRoll; this.damageRoll = damageRoll; this.powerUsage = powerUsage; this.actionType = actionType; this.attackType = attackType; this.targetDefense = targetDefense; } public void setName(String name) { this.name = name; } public String getName() { return name; } public void setPowerUsage(PowerUsage powerUsage) { this.powerUsage = powerUsage; } public PowerUsage getPowerUsage() { return powerUsage; } public void setActionType(ActionType actionType) { this.actionType = actionType; } public ActionType getActionType() { return actionType; } public void setAttackType(AttackType attackType) { this.attackType = attackType; } public AttackType getAttackType() { return attackType; } public void setTargetDefense(Defenses targetDefense) { this.targetDefense = targetDefense; } public Defenses getTargetDefense() { return targetDefense; } public int getAttackRollMod() { if (hasAttackRoll()) return attackRoll.getFormulaModifier(); else return -99; } public void setAttackRoll(DiceFormula attackRoll) { this.attackRoll = attackRoll; } public void setDamageRoll(DiceFormula damageRoll) { this.damageRoll = damageRoll; } public boolean hasAttackRoll() { return (attackRoll != null); } public boolean hasDamageRoll() { return (damageRoll != null); } public String getDamageRollString() { return damageRoll.getDiceFormulaString(); } public int getDamageRollMod() { if (hasDamageRoll()) return damageRoll.getFormulaModifier(); else return -99; } //TODO: Refactor this so it's not dependent on getDiceFormulaString public int getDamageDieMod() { if (hasDamageRoll()) return damageRoll.getDieModifier(); else return -99; } //TODO: Refactor this so it's not dependent on getDiceFormulaString public String getDamageDie() { if (hasDamageRoll()) return "d" + damageRoll.getDieSize(); else return ""; } public CharPowerRollResult roll() { if (attackRoll == null && damageRoll == null) return null; CharPowerRollResult ret = new CharPowerRollResult(name); if (attackRoll != null) { ret.setHasAttackRoll(true); ret.setAttackRollString(attackRoll.getDiceFormulaString()); DiceFormulaResult attkRes = rollAttack(); ret.setAttackRollResult(attkRes.getTotalResult()); ret.setAttackRollResultString(attkRes.getDiceFormulaResultString()); ret.setTargetDefenseResID(targetDefense.getResourceIDShort()); ret.setCritStatus(attkRes.getCriticalStatus()); } if (damageRoll != null) { ret.setHasDamageRoll(true); ret.setDamageRollString(damageRoll.getDiceFormulaString()); DiceFormulaResult dmgRes = rollDamage(ret.getCritStatus()); ret.setDamageRollResult(dmgRes.getTotalResult()); ret.setDamageRollResultString(dmgRes.getDiceFormulaResultString()); } return ret; } private DiceFormulaResult rollAttack() { return attackRoll.roll(); } private DiceFormulaResult rollDamage(CriticalStatus status) { if (status == CriticalStatus.SUCCESS) return damageRoll.rollCritical(); else return damageRoll.roll(); } @Override public int compareTo(CharPower another) { if (powerUsage == another.getPowerUsage()) { return name.compareTo(another.getName()); } else { switch (powerUsage) { case AT_WILL: return -1; case ENCOUNTER: if (another.getPowerUsage() == PowerUsage.AT_WILL) return 1; else return -1; case DAILY: return 1; } } return 0; } }