|
| 1 | +#include "character.h" |
| 2 | + |
| 3 | +Character::Character() { |
| 4 | + |
| 5 | +} |
| 6 | + |
| 7 | +void Character::load(QDomDocument& xml) { |
| 8 | + basicConfiguration.load(xml); |
| 9 | + characterInfo.load(xml); |
| 10 | + characteristics.load(xml); |
| 11 | + skills.list.load(xml, "SKILLS"); |
| 12 | + perks.list.load(xml, "PERKS"); |
| 13 | + talents.list.load(xml, "TALENTS"); |
| 14 | + martialArts.list.load(xml, "MARTIALARTS", "MANEUVER"); |
| 15 | + powers.load(xml); |
| 16 | + disadvantages.list.load(xml, "DISADVANTAGES", "DISAD"); |
| 17 | + equipment.load(xml); |
| 18 | + image.load(xml); |
| 19 | +} |
| 20 | + |
| 21 | +void Character::BasicConfiguration::load(QDomDocument& xml) { |
| 22 | + QDomElement chr = xml.firstChildElement("CHARACTER"); |
| 23 | + QDomElement conf = chr.firstChildElement("BASIC_CONFIGURATION"); |
| 24 | + |
| 25 | + basePoints = conf.attribute("BASE_POINTS"); |
| 26 | + experience = conf.attribute("EXPERIENCE"); |
| 27 | + disadPoints = conf.attribute("DISAD_POINTS"); |
| 28 | +} |
| 29 | + |
| 30 | +void Character::CharacterInfo::load(QDomDocument& xml) { |
| 31 | + QDomElement chr = xml.firstChildElement("CHARACTER"); |
| 32 | + QDomElement conf = chr.firstChildElement("CHARACTER_INFO"); |
| 33 | + |
| 34 | + background = conf.firstChildElement("BACKGROUND").text(); |
| 35 | + personality = conf.firstChildElement("PERSONALITY").text(); |
| 36 | + quote = conf.firstChildElement("QUOTE").text(); |
| 37 | + tactics = conf.firstChildElement("TACTICS").text(); |
| 38 | + campaignUse = conf.firstChildElement("CAMPAIGN_USE").text(); |
| 39 | + appearance = conf.firstChildElement("APPEARANCE").text(); |
| 40 | + |
| 41 | + alternateIdentities = conf.attribute("ALTERNATE_IDENTITIES"); |
| 42 | + hairColor = conf.attribute("HAIR_COLOR"); |
| 43 | + playerName = conf.attribute("PLAYER_NAME"); |
| 44 | + height = conf.attribute("HEIGHT"); |
| 45 | + genre = conf.attribute("GENRE"); |
| 46 | + characterName = conf.attribute("CHARACTER_NAME"); |
| 47 | + eyeColor = conf.attribute("EYE_COLOR"); |
| 48 | + gm = conf.attribute("GM"); |
| 49 | + campaignName = conf.attribute("CAMPAIGN_NAME"); |
| 50 | + weight = conf.attribute("WEIGHT"); |
| 51 | +} |
| 52 | + |
| 53 | +void Character::Base::load(QDomElement& e) { |
| 54 | + auto nodes = e.attributes(); |
| 55 | + int count = nodes.count(); |
| 56 | + for (int i = 0; i < count; ++i) { |
| 57 | + QDomAttr node = nodes.item(i).toAttr(); |
| 58 | + if (node.isNull()) continue; |
| 59 | + attributes[node.name()] = node.value(); |
| 60 | + } |
| 61 | + attributes["NOTES"] = e.firstChildElement("NOTES").text(); |
| 62 | +} |
| 63 | + |
| 64 | +int Character::getPrimary(const QString& stat) { |
| 65 | + QMap<QString, int> base { |
| 66 | + { "STR", 10 }, { "DEX", 10 }, { "CON", 10 }, { "INT", 10 }, { "EGO", 10 }, { "PRE", 10 }, { "OCV", 3 }, { "DCV", 3 }, { "OMCV", 3 }, { "DMCV", 3 }, |
| 67 | + { "SPD", 2 }, { "PD", 2 }, { "ED", 2 }, { "REC", 4 }, { "END", 20 }, { "BODY", 10 }, { "STUN", 20 }, { "RUNNING", 12 }, { "SWIMMING", 4 }, { "LEAPING", 4 } |
| 68 | + }; |
| 69 | + int level = base[stat] + characteristics.characteristics[stat].getLevels() + powers.getPrimaries(stat); |
| 70 | + if (stat == "PD" || stat == "ED") { |
| 71 | + level += talents.getPrimaries("COMBAT_LUCK"); |
| 72 | + level += powers.getPrimaries("FORCEFIELD", stat); |
| 73 | + } |
| 74 | + return level; |
| 75 | +} |
| 76 | + |
| 77 | +int Character::getSecondary(const QString& stat) { |
| 78 | + int level = powers.getSecondaries(stat); |
| 79 | + if (stat == "PD" || stat == "ED") { |
| 80 | + level += talents.getSecondaries("COMBAT_LUCK"); |
| 81 | + level += powers.getSecondaries("FORCEFIELD", stat); |
| 82 | + } |
| 83 | + return level; |
| 84 | +} |
| 85 | + |
| 86 | +int Character::getPrimaryResistant(const QString& stat) { |
| 87 | + int level = 0; |
| 88 | + level += talents.getPrimaries("COMBAT_LUCK"); |
| 89 | + level += powers.getPrimaries("FORCEFIELD", stat); |
| 90 | + return level; |
| 91 | +} |
| 92 | + |
| 93 | +int Character::getSecondaryResistant(const QString& stat) { |
| 94 | + int level = 0; |
| 95 | + level += talents.getSecondaries("COMBAT_LUCK"); |
| 96 | + level += powers.getSecondaries("FORCEFIELD", stat); |
| 97 | + return level; |
| 98 | +} |
| 99 | + |
| 100 | +int Character::Talents::getPrimaries(const QString& statName) { |
| 101 | + int primary = 0; |
| 102 | + for (const auto& talent: list) { |
| 103 | + if (talent.attributes["XMLID"] == statName) { |
| 104 | + if (talent.attributes["AFFECTS_TOTAL"] == "Yes" && |
| 105 | + talent.attributes["AFFECTS_PRIMARY"] == "Yes") primary += talent.attributes["LEVELS"].toInt() * 3; |
| 106 | + } |
| 107 | + } |
| 108 | + return primary; |
| 109 | +} |
| 110 | + |
| 111 | +int Character::Talents::getSecondaries(const QString& statName) { |
| 112 | + int secondary = 0; |
| 113 | + for (const auto& talent: list) { |
| 114 | + if (talent.attributes["XMLID"] == statName) { |
| 115 | + if (talent.attributes["AFFECTS_TOTAL"] == "Yes" && |
| 116 | + talent.attributes["AFFECTS_PRIMARY"] == "No") secondary += talent.attributes["LEVELS"].toInt() * 3; |
| 117 | + } |
| 118 | + } |
| 119 | + return secondary; |
| 120 | +} |
| 121 | + |
| 122 | +int Character::Powers::getPrimaries(const QString& statName) { |
| 123 | + int primary = 0; |
| 124 | + for (auto& power: items) { |
| 125 | + Stat* stat = std::get_if<Stat>(&power); |
| 126 | + if (stat == nullptr) continue; |
| 127 | + if (stat->attributes["XMLID"] == statName) { |
| 128 | + if (stat->attributes["AFFECTS_TOTAL"] == "Yes" && |
| 129 | + stat->attributes["AFFECTS_PRIMARY"] == "Yes") primary += stat->attributes["LEVELS"].toInt(); |
| 130 | + } |
| 131 | + } |
| 132 | + return primary; |
| 133 | +} |
| 134 | + |
| 135 | +int Character::Powers::getSecondaries(const QString& statName) { |
| 136 | + int secondary = 0; |
| 137 | + for (auto& power: items) { |
| 138 | + Stat* stat = std::get_if<Stat>(&power); |
| 139 | + if (stat == nullptr) continue; |
| 140 | + if (stat->attributes["XMLID"] == statName) { |
| 141 | + if (stat->attributes["AFFECTS_TOTAL"] == "Yes" && |
| 142 | + stat->attributes["AFFECTS_PRIMARY"] == "No") secondary += stat->attributes["LEVELS"].toInt(); |
| 143 | + } |
| 144 | + } |
| 145 | + return secondary; |
| 146 | +} |
| 147 | + |
| 148 | +int Character::Powers::getPrimaries(const QString& powerName, const QString& where) { |
| 149 | + int primary = 0; |
| 150 | + for (auto& power: items) { |
| 151 | + Power* pwr = std::get_if<Power>(&power); |
| 152 | + if (pwr == nullptr) continue; |
| 153 | + if (pwr->attributes["XMLID"] == powerName) { |
| 154 | + if (pwr->attributes["AFFECTS_TOTAL"] == "Yes" && |
| 155 | + pwr->attributes["AFFECTS_PRIMARY"] == "Yes") primary += pwr->attributes[where + "LEVELS"].toInt(); |
| 156 | + } |
| 157 | + } |
| 158 | + return primary; |
| 159 | +} |
| 160 | + |
| 161 | +int Character::Powers::getSecondaries(const QString& powerName, const QString& where) { |
| 162 | + int secondary = 0; |
| 163 | + for (auto& power: items) { |
| 164 | + Power* pwr = std::get_if<Power>(&power); |
| 165 | + if (pwr == nullptr) continue; |
| 166 | + if (pwr->attributes["XMLID"] == powerName) { |
| 167 | + if (pwr->attributes["AFFECTS_TOTAL"] == "Yes" && |
| 168 | + pwr->attributes["AFFECTS_PRIMARY"] == "No") secondary += pwr->attributes[where + "LEVELS"].toInt(); |
| 169 | + } |
| 170 | + } |
| 171 | + return secondary; |
| 172 | +} |
0 commit comments