com.softwaremagico.tm.character.equipment.EquipmentSelector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of think-machine-random Show documentation
Show all versions of think-machine-random Show documentation
Think Machine - A Fading Suns character generator (random character creation)
package com.softwaremagico.tm.character.equipment;
/*-
* #%L
* Think Machine (Random Generator)
* %%
* Copyright (C) 2017 - 2019 Softwaremagico
* %%
* This software is designed by Jorge Hortelano Otero. Jorge Hortelano Otero
* Valencia (Spain).
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; If not, see .
* #L%
*/
import com.softwaremagico.tm.InvalidXmlElementException;
import com.softwaremagico.tm.character.CharacterPlayer;
import com.softwaremagico.tm.character.exceptions.RestrictedElementException;
import com.softwaremagico.tm.character.exceptions.UnofficialElementNotAllowedException;
import com.softwaremagico.tm.character.characteristics.CharacteristicName;
import com.softwaremagico.tm.random.RandomSelector;
import com.softwaremagico.tm.random.exceptions.InvalidRandomElementSelectedException;
import com.softwaremagico.tm.random.selectors.IRandomPreference;
import java.util.Set;
public abstract class EquipmentSelector> extends RandomSelector {
private Integer currentMoney = null;
protected EquipmentSelector(CharacterPlayer characterPlayer, Set> preferences,
Set mandatoryElements) throws InvalidXmlElementException, RestrictedElementException, UnofficialElementNotAllowedException {
super(characterPlayer, null, preferences, mandatoryElements, null);
}
protected int getCurrentMoney() {
if (currentMoney == null) {
currentMoney = getCharacterPlayer().getMoney();
}
return currentMoney;
}
/**
* Not so expensive weapons.
*
* @param equipment element.
* @return weight
*/
protected abstract int getWeightCostModificator(E equipment) throws InvalidRandomElementSelectedException;
@Override
protected int getWeight(E equipment) throws InvalidRandomElementSelectedException {
// Weapons only if technology is enough.
if (equipment.getTechLevel() > getCharacterPlayer().getCharacteristicValue(CharacteristicName.TECH)) {
throw new InvalidRandomElementSelectedException("Technology requirements not met for '" + equipment + "'.");
}
// I can afford it.
if (equipment.getCost() > getCurrentMoney()) {
throw new InvalidRandomElementSelectedException("Cost not affordable for '" + equipment + "'.");
}
return 1;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy