Commit 89d1862497222ea48fb38995492df7947b00c4d7
- Diff rendering mode:
- inline
- side by side
|   | |||
| 97 | 97 | { | |
| 98 | 98 | LOG_WARN(itemReferenceFile << ": Unknown item type \"" << sItemType | |
| 99 | 99 | << "\" for item #" << id << | |
| 100 | " - treating it as \"generic\""); | ||
| 100 | " - treating it as \"generic\"."); | ||
| 101 | 101 | itemType = ITEM_UNUSABLE; | |
| 102 | 102 | } | |
| 103 | 103 | ||
| … | … | ||
| 133 | 133 | std::string strWeaponType = XML::getProperty(node, "weapon-type", ""); | |
| 134 | 134 | if (strWeaponType == "") | |
| 135 | 135 | { | |
| 136 | LOG_WARN(itemReferenceFile << ": Unknown weapon type \"" | ||
| 136 | LOG_WARN(itemReferenceFile << ": Empty weapon type \"" | ||
| 137 | 137 | << "\" for item #" << id << | |
| 138 | " - treating it as generic item"); | ||
| 139 | } else { | ||
| 140 | weaponType = SkillManager::getIdFromString(strWeaponType); | ||
| 138 | " - treating it as generic item."); | ||
| 141 | 139 | } | |
| 140 | else | ||
| 141 | weaponType = SkillManager::getIdFromString(strWeaponType); | ||
| 142 | |||
| 142 | 143 | modifiers.setValue(MOD_WEAPON_TYPE, weaponType); | |
| 143 | 144 | modifiers.setValue(MOD_WEAPON_RANGE, XML::getProperty(node, "range", 0)); | |
| 144 | 145 | modifiers.setValue(MOD_ELEMENT_TYPE, XML::getProperty(node, "element", 0)); |
src/game-server/skillmanager.cpp
(106 / 14)
|   | |||
| 30 | 30 | typedef std::map< std::string, int > SkillMap; | |
| 31 | 31 | static SkillMap skillMap; | |
| 32 | 32 | static std::string skillReferenceFile; | |
| 33 | static std::string defaultSkillKey = std::string(); | ||
| 33 | 34 | ||
| 34 | 35 | void SkillManager::initialize(const std::string &file) | |
| 35 | 36 | { | |
| … | … | ||
| 50 | 50 | ||
| 51 | 51 | std::string absPathFile = ResourceManager::resolve(skillReferenceFile); | |
| 52 | 52 | ||
| 53 | if (!data) { | ||
| 54 | LOG_ERROR("Item Manager: Could not find " << skillReferenceFile << "!"); | ||
| 53 | if (!data) | ||
| 54 | { | ||
| 55 | LOG_ERROR("Skill Manager: Could not find " << skillReferenceFile << "!"); | ||
| 55 | 56 | free(data); | |
| 56 | 57 | return; | |
| 57 | 58 | } | |
| … | … | ||
| 86 | 86 | { | |
| 87 | 87 | if (xmlStrEqual(skillnode->name, BAD_CAST "skill")) | |
| 88 | 88 | { | |
| 89 | std::string name = XML::getProperty(skillnode, "name", std::string()); | ||
| 89 | std::string name = XML::getProperty(skillnode, "name", | ||
| 90 | std::string()); | ||
| 90 | 91 | name = utils::toupper(name); | |
| 91 | 92 | int id = XML::getProperty(skillnode, "id", 0); | |
| 92 | 93 | if (id && !name.empty()) | |
| 93 | 94 | { | |
| 94 | skillMap[utils::toupper(name)] = id; | ||
| 95 | bool duplicateKey = false; | ||
| 96 | for (SkillMap::iterator i = skillMap.begin(); | ||
| 97 | i != skillMap.end(); i++) | ||
| 98 | { | ||
| 99 | if (id == i->second) | ||
| 100 | { | ||
| 101 | LOG_ERROR("SkillManager: The same id: " << id | ||
| 102 | << " is given for skill names: " << i->first | ||
| 103 | << " and " << name); | ||
| 104 | LOG_ERROR("The skill reference: " << "'" << name | ||
| 105 | << "': " << id << " will be ignored."); | ||
| 106 | |||
| 107 | duplicateKey = true; | ||
| 108 | break; | ||
| 109 | } | ||
| 110 | } | ||
| 111 | |||
| 112 | if (!duplicateKey) | ||
| 113 | { | ||
| 114 | if (XML::getBoolProperty(skillnode, "default", false)) | ||
| 115 | { | ||
| 116 | if (!defaultSkillKey.empty()) | ||
| 117 | { | ||
| 118 | LOG_WARN("SkillManager: " | ||
| 119 | "Default Skill Key already defined as " | ||
| 120 | << defaultSkillKey | ||
| 121 | << ". Redefinit it as: " << name); | ||
| 122 | } | ||
| 123 | else | ||
| 124 | { | ||
| 125 | LOG_INFO("SkillManager: Defining " << name | ||
| 126 | << " as default weapon-type key."); | ||
| 127 | } | ||
| 128 | defaultSkillKey = name; | ||
| 129 | } | ||
| 130 | skillMap[name] = id; | ||
| 131 | } | ||
| 95 | 132 | } | |
| 96 | 133 | } | |
| 97 | 134 | } | |
| 98 | 135 | } | |
| 99 | 136 | ||
| 100 | LOG_DEBUG("skill map:"); | ||
| 101 | for (SkillMap::iterator i = skillMap.begin(); i != skillMap.end(); i++) | ||
| 137 | if (::utils::Logger::mVerbosity >= ::utils::Logger::Debug) | ||
| 102 | 138 | { | |
| 103 | LOG_DEBUG(" " << i->first << " : " << i->second); | ||
| 139 | LOG_DEBUG("Skill map in " << skillReferenceFile << ":" | ||
| 140 | << std::endl << "-----"); | ||
| 141 | for (SkillMap::iterator i = skillMap.begin(); i != skillMap.end(); i++) | ||
| 142 | { | ||
| 143 | if (!defaultSkillKey.compare(i->first)) | ||
| 144 | { | ||
| 145 | LOG_DEBUG("'" << i->first << "': " << i->second | ||
| 146 | << " (Default)"); | ||
| 147 | } | ||
| 148 | else | ||
| 149 | { | ||
| 150 | LOG_DEBUG("'" << i->first << "': " << i->second); | ||
| 151 | } | ||
| 152 | } | ||
| 153 | LOG_DEBUG("-----"); | ||
| 104 | 154 | } | |
| 155 | |||
| 156 | if (defaultSkillKey.empty()) | ||
| 157 | LOG_WARN("SkillManager: No default weapon-type id was given during " | ||
| 158 | "Skill map loading. Defaults will fall back to id 0."); | ||
| 159 | |||
| 160 | LOG_INFO("Loaded " << skillMap.size() << " skill references from " | ||
| 161 | << absPathFile); | ||
| 105 | 162 | } | |
| 106 | 163 | ||
| 107 | 164 | int SkillManager::getIdFromString(const std::string &name) | |
| 108 | 165 | { | |
| 109 | //check if already an integer, if yes just return it | ||
| 110 | int val; | ||
| 111 | val = atoi(name.c_str()); | ||
| 112 | if (val) | ||
| 113 | return val; | ||
| 166 | // Check if the name is an integer value. | ||
| 167 | if (utils::isNumeric(name)) | ||
| 168 | { | ||
| 169 | int val = 0; | ||
| 170 | val = utils::stringToInt(name); | ||
| 171 | if (val) | ||
| 172 | { | ||
| 173 | for (SkillMap::iterator i = skillMap.begin(); i != skillMap.end(); i++) | ||
| 174 | { | ||
| 175 | if (i->second == val) | ||
| 176 | return val; | ||
| 177 | } | ||
| 178 | LOG_WARN("SkillManager::getIdFromString(): Numeric weapon-type id " | ||
| 179 | << val << " not found into " << skillReferenceFile); | ||
| 114 | 180 | ||
| 115 | // convert to upper case for easier finding | ||
| 181 | SkillMap::iterator i = skillMap.find(defaultSkillKey); | ||
| 182 | if (i != skillMap.end()) | ||
| 183 | { | ||
| 184 | LOG_WARN("Id defaulted to " << defaultSkillKey << ": " | ||
| 185 | << i->second); | ||
| 186 | return i->second; | ||
| 187 | } | ||
| 188 | else | ||
| 189 | { | ||
| 190 | LOG_WARN("Id defaulted to 0."); | ||
| 191 | return 0; | ||
| 192 | } | ||
| 193 | } | ||
| 194 | else | ||
| 195 | { | ||
| 196 | LOG_WARN("SkillManager: Invalid skill id " << name); | ||
| 197 | return 0; | ||
| 198 | } | ||
| 199 | } | ||
| 200 | |||
| 201 | // Convert to upper case for easier finding | ||
| 116 | 202 | SkillMap::iterator i = skillMap.find(utils::toupper(name)); | |
| 117 | 203 | if (i == skillMap.end()) | |
| 118 | 204 | { | |
| 205 | LOG_WARN("SkillManager: No weapon-type name corresponding to " | ||
| 206 | << utils::toupper(name) << " into " << skillReferenceFile); | ||
| 119 | 207 | return 0; | |
| 120 | } else { | ||
| 208 | } | ||
| 209 | else | ||
| 210 | { | ||
| 121 | 211 | return i->second; | |
| 122 | 212 | } | |
| 123 | 213 | } |
src/utils/xml.cpp
(29 / 0)
|   | |||
| 96 | 96 | return mDoc ? xmlDocGetRootElement(mDoc) : 0; | |
| 97 | 97 | } | |
| 98 | 98 | ||
| 99 | bool hasProperty(xmlNodePtr node, const char *name) | ||
| 100 | { | ||
| 101 | xmlChar *prop = xmlGetProp(node, BAD_CAST name); | ||
| 102 | if (prop) | ||
| 103 | { | ||
| 104 | xmlFree(prop); | ||
| 105 | return true; | ||
| 106 | } | ||
| 107 | |||
| 108 | return false; | ||
| 109 | } | ||
| 110 | |||
| 111 | bool getBoolProperty(xmlNodePtr node, const char *name, bool def) | ||
| 112 | { | ||
| 113 | bool ret = def; | ||
| 114 | xmlChar *prop = xmlGetProp(node, BAD_CAST name); | ||
| 115 | if (prop) | ||
| 116 | { | ||
| 117 | if (xmlStrEqual(prop, BAD_CAST "true") | ||
| 118 | ||xmlStrEqual(prop, BAD_CAST "yes")) | ||
| 119 | ret = true; | ||
| 120 | if (xmlStrEqual(prop, BAD_CAST "false") | ||
| 121 | ||xmlStrEqual(prop, BAD_CAST "no")) | ||
| 122 | ret = false; | ||
| 123 | xmlFree(prop); | ||
| 124 | } | ||
| 125 | return ret; | ||
| 126 | } | ||
| 127 | |||
| 99 | 128 | int getProperty(xmlNodePtr node, const char *name, int def) | |
| 100 | 129 | { | |
| 101 | 130 | int &ret = def; |
src/utils/xml.hpp
(10 / 0)
|   | |||
| 70 | 70 | }; | |
| 71 | 71 | ||
| 72 | 72 | /** | |
| 73 | * Tells if a property from an xmlNodePtr exists. | ||
| 74 | */ | ||
| 75 | bool hasProperty(xmlNodePtr node, const char *name); | ||
| 76 | |||
| 77 | /** | ||
| 78 | * Gets a boolean property from an xmlNodePtr. | ||
| 79 | */ | ||
| 80 | bool getBoolProperty(xmlNodePtr node, const char *name, bool def); | ||
| 81 | |||
| 82 | /** | ||
| 73 | 83 | * Gets an integer property from an xmlNodePtr. | |
| 74 | 84 | */ | |
| 75 | 85 | int getProperty(xmlNodePtr node, const char *name, int def); |

