All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.softwaremagico.tm.character.equipment.armors.Armor Maven / Gradle / Ivy

package com.softwaremagico.tm.character.equipment.armors;

/*-
 * #%L
 * Think Machine 4E (Rules)
 * %%
 * Copyright (C) 2017 - 2024 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.fasterxml.jackson.annotation.JsonProperty;
import com.softwaremagico.tm.character.equipment.DamageTypeFactory;
import com.softwaremagico.tm.character.equipment.Equipment;
import com.softwaremagico.tm.character.equipment.shields.ShieldFactory;
import com.softwaremagico.tm.exceptions.InvalidXmlElementException;

import java.util.HashSet;
import java.util.Set;

public class Armor extends Equipment {
    private int protection;
    @JsonProperty("damageTypes")
    private Set damageTypes;
    @JsonProperty("standardPenalizations")
    private ArmourPenalization standardPenalization;
    @JsonProperty("specialPenalizations")
    private ArmourPenalization specialPenalization;
    @JsonProperty("shields")
    private Set allowedShields;
    @JsonProperty("others")
    private Set specifications;

    /**
     * For creating empty elements.
     */
    public Armor() {
        super();
        this.protection = 0;
        this.damageTypes = new HashSet<>();
        this.standardPenalization = new ArmourPenalization(0, 0, 0, 0);
        this.specialPenalization = new ArmourPenalization(0, 0, 0, 0);
        this.allowedShields = new HashSet<>();
        this.specifications = new HashSet<>();
    }

    public int getProtection() {
        return protection;
    }

    public Set getDamageTypes() {
        return damageTypes;
    }

    public ArmourPenalization getStandardPenalization() {
        return standardPenalization;
    }

    public ArmourPenalization getSpecialPenalization() {
        return specialPenalization;
    }

    public Set getAllowedShields() {
        return allowedShields;
    }

    public boolean isHeavy() {
        return standardPenalization.getDexterityModification() > 0 || standardPenalization.getStrengthModification() > 0
                || standardPenalization.getEnduranceModification() > 0;
    }

    public void setProtection(int protection) {
        this.protection = protection;
    }

    public void setDamageTypes(Set damageTypes) {
        this.damageTypes = damageTypes;
    }

    public void setStandardPenalization(ArmourPenalization standardPenalization) {
        this.standardPenalization = standardPenalization;
    }

    public void setSpecialPenalization(ArmourPenalization specialPenalization) {
        this.specialPenalization = specialPenalization;
    }

    public void setAllowedShields(Set allowedShields) {
        this.allowedShields = allowedShields;
    }

    public void setSpecifications(Set specifications) {
        this.specifications = specifications;
    }

    public Set getSpecifications() {
        return specifications;
    }

    @Override
    public void validate() throws InvalidXmlElementException {
        super.validate();
        if (damageTypes != null) {
            damageTypes.forEach(damageType -> DamageTypeFactory.getInstance().getElement(damageType));
        }
        if (allowedShields != null) {
            allowedShields.forEach(allowedShield -> ShieldFactory.getInstance().getElement(allowedShield));
        }
        if (specifications != null) {
            specifications.forEach(specification -> ArmourSpecificationFactory.getInstance().getElement(specification));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy