void Monster::setType(const TYPE_OF_CHARACTER_ID &type) throw(unknownIDException) { deleteAllSkills(); MonsterStruct monsterdef; if (! MonsterDescriptions->find(type, monsterdef)) { throw unknownIDException(); } // set attributes setAttribute(Character::luck, Random::uniform(monsterdef.attributes.luck.first, monsterdef.attributes.luck.second)); setAttribute(Character::strength, Random::uniform(monsterdef.attributes.strength.first, monsterdef.attributes.strength.second)); setAttribute(Character::dexterity, Random::uniform(monsterdef.attributes.dexterity.first, monsterdef.attributes.dexterity.second)); setAttribute(Character::constitution, Random::uniform(monsterdef.attributes.constitution.first, monsterdef.attributes.constitution.second)); setAttribute(Character::agility, Random::uniform(monsterdef.attributes.agility.first, monsterdef.attributes.agility.second)); setAttribute(Character::intelligence, Random::uniform(monsterdef.attributes.intelligence.first, monsterdef.attributes.intelligence.second)); setAttribute(Character::perception, Random::uniform(monsterdef.attributes.perception.first, monsterdef.attributes.perception.second)); setAttribute(Character::willpower, Random::uniform(monsterdef.attributes.willpower.first, monsterdef.attributes.willpower.second)); setAttribute(Character::essence, Random::uniform(monsterdef.attributes.essence.first, monsterdef.attributes.essence.second)); setAttribute(Character::hitpoints, monsterdef.hitpoints); setAttribute(Character::height, Random::uniform(monsterdef.minsize, monsterdef.maxsize)); // set skills for (auto it = monsterdef.skills.begin(); it != monsterdef.skills.end(); ++it) { increaseSkill(it->first, Random::uniform(it->second.first, it->second.second)); } // add items for (auto it = monsterdef.items.begin(); it != monsterdef.items.end(); ++it) { auto inventorySlot = it->first; auto possibleItems = it->second; int numberOfPossibleItems = possibleItems.size(); if (numberOfPossibleItems > 0) { int selectedItemIndex; if (numberOfPossibleItems == 1) { selectedItemIndex = 0; } else { selectedItemIndex = Random::uniform(0, numberOfPossibleItems - 1); } auto &selectedItem = possibleItems[selectedItemIndex]; characterItems[inventorySlot].setId(selectedItem.itemid); characterItems[inventorySlot].setNumber(Random::uniform(selectedItem.amount.first, selectedItem.amount.second)); characterItems[inventorySlot].setWear(selectedItem.AgeingSpeed); } } SetMovement(monsterdef.movement); race = monsterdef.race; _canAttack = monsterdef.canattack; name = monsterdef.nameEn; nameDe = monsterdef.nameDe; }
void Monster::setMonsterType(TYPE_OF_CHARACTER_ID type) { deleteAllSkills(); if (!monsterDescriptions->exists(type)) { throw unknownIDException(); } const auto &monsterdef = (*monsterDescriptions)[type]; // set attributes setAttribute(Character::luck, Random::uniform(monsterdef.attributes.luck.first, monsterdef.attributes.luck.second)); setAttribute(Character::strength, Random::uniform(monsterdef.attributes.strength.first, monsterdef.attributes.strength.second)); setAttribute(Character::dexterity, Random::uniform(monsterdef.attributes.dexterity.first, monsterdef.attributes.dexterity.second)); setAttribute(Character::constitution, Random::uniform(monsterdef.attributes.constitution.first, monsterdef.attributes.constitution.second)); setAttribute(Character::agility, Random::uniform(monsterdef.attributes.agility.first, monsterdef.attributes.agility.second)); setAttribute(Character::intelligence, Random::uniform(monsterdef.attributes.intelligence.first, monsterdef.attributes.intelligence.second)); setAttribute(Character::perception, Random::uniform(monsterdef.attributes.perception.first, monsterdef.attributes.perception.second)); setAttribute(Character::willpower, Random::uniform(monsterdef.attributes.willpower.first, monsterdef.attributes.willpower.second)); setAttribute(Character::essence, Random::uniform(monsterdef.attributes.essence.first, monsterdef.attributes.essence.second)); setAttribute(Character::hitpoints, monsterdef.hitpoints); setAttribute(Character::height, Random::uniform(monsterdef.minsize, monsterdef.maxsize)); // set skills for (const auto &skill: monsterdef.skills) { increaseSkill(skill.first, Random::uniform(skill.second.first, skill.second.second)); } // add items for (const auto &item: monsterdef.items) { auto inventorySlot = item.first; auto possibleItems = item.second; int numberOfPossibleItems = possibleItems.size(); if (numberOfPossibleItems > 0) { int selectedItemIndex; if (numberOfPossibleItems == 1) { selectedItemIndex = 0; } else { selectedItemIndex = Random::uniform(0, numberOfPossibleItems - 1); } auto &selectedItem = possibleItems[selectedItemIndex]; items[inventorySlot].setId(selectedItem.itemid); items[inventorySlot].setNumber(Random::uniform(selectedItem.amount.first, selectedItem.amount.second)); items[inventorySlot].setWear(selectedItem.AgeingSpeed); } } SetMovement(monsterdef.movement); setRace(monsterdef.race); _canAttack = monsterdef.canattack; setName(monsterdef.nameEn); nameDe = monsterdef.nameDe; const auto raceConfiguration = raceTypes->getRandomRaceConfiguration(monsterdef.race); setAttribute(sex, raceConfiguration.subType); setHair(raceConfiguration.hair); setBeard(raceConfiguration.beard); setHairColour(raceConfiguration.hairColour); setSkinColour(raceConfiguration.skinColour); setSkinColour(raceConfiguration.skinColour); }