/*
* 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.interactors;
import com.arconus.dicecommander.Application;
import com.arconus.dicecommander.events.EditPowerEvent;
import com.arconus.dicecommander.events.NewPowerEvent;
import com.arconus.dicecommander.model.entities.character.Defenses;
import com.arconus.dicecommander.model.entities.character.GameCharacter;
import com.arconus.dicecommander.model.entities.character.power.ActionType;
import com.arconus.dicecommander.model.entities.character.power.AttackType;
import com.arconus.dicecommander.model.entities.character.power.CharPower;
import com.arconus.dicecommander.model.entities.character.power.PowerUsage;
import com.arconus.dicecommander.model.entities.dice.DiceFormula;
import com.arconus.dicecommander.model.entities.dice.SingleDie;
public class CharPowerBuilder {
private GameCharacter character;
private String name;
private PowerUsage powerUsage;
private AttackType attackType;
private ActionType actionType;
private Defenses defense;
private DiceFormula attackRoll;
private DiceFormula damageRoll;
public CharPowerBuilder(GameCharacter character) {
this.character = character;
this.name = "";
this.powerUsage = null;
this.attackRoll = null;
this.attackType = null;
this.actionType = null;
this.damageRoll = null;
this.defense = null;
}
public CharPowerBuilder setName(String name) {
this.name = name;
return this;
}
public CharPowerBuilder setPowerUsage(PowerUsage usage) {
this.powerUsage = usage;
return this;
}
public CharPowerBuilder setAttackType(AttackType attack) {
this.attackType = attack;
return this;
}
public CharPowerBuilder setActionType(ActionType action) {
this.actionType = action;
return this;
}
public CharPowerBuilder setDefense(Defenses defense) {
this.defense = defense;
return this;
}
public CharPowerBuilder setAttackRoll(int modifier) {
attackRoll = new DiceFormula(1, new SingleDie(20), modifier);
return this;
}
public CharPowerBuilder setDamageRoll(int dieMod, int dieSize, int formulaMod) {
damageRoll = new DiceFormula(dieMod, new SingleDie(dieSize), formulaMod);
return this;
}
public void publishCharPower() {
addPower();
Application.bus.post(new NewPowerEvent());
}
public void replaceCharPower(int position) {
character.removeCharPower(position);
addPower();
Application.bus.post(new EditPowerEvent());
}
private void addPower() {
CharPower power = new CharPower(name, powerUsage, actionType, attackType, defense, attackRoll, damageRoll);
character.addCharPower(power);
}
}