| 64 | |
| 65 | |
| 66 | bool ResolveItem(const AString & a_ItemName, cItem & a_Item) |
| 67 | { |
| 68 | // Split into parts divided by either ':' or '^' |
| 69 | AStringVector Split = StringSplitAndTrim(a_ItemName, ":^"); |
| 70 | if (Split.empty()) |
| 71 | { |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | ItemMap::iterator itr = m_Map.find(Split[0]); |
| 76 | if (itr != m_Map.end()) |
| 77 | { |
| 78 | // Resolved as a string, assign the type and the default damage / count |
| 79 | a_Item.m_ItemType = itr->second.first; |
| 80 | a_Item.m_ItemDamage = itr->second.second; |
| 81 | if (a_Item.m_ItemDamage == -1) |
| 82 | { |
| 83 | a_Item.m_ItemDamage = 0; |
| 84 | } |
| 85 | } |
| 86 | else |
| 87 | { |
| 88 | // Not a resolvable string, try pure numbers: "45:6", "45^6" etc. |
| 89 | a_Item.m_ItemType = (short)atoi(Split[0].c_str()); |
| 90 | if ((a_Item.m_ItemType == 0) && (Split[0] != "0")) |
| 91 | { |
| 92 | // Parsing the number failed |
| 93 | return false; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | // Parse the damage, if present: |
| 98 | if (Split.size() < 2) |
| 99 | { |
| 100 | // Not present, set the item as valid and return success: |
| 101 | a_Item.m_ItemCount = 1; |
| 102 | return true; |
| 103 | } |
| 104 | |
| 105 | a_Item.m_ItemDamage = atoi(Split[1].c_str()); |
| 106 | if ((a_Item.m_ItemDamage == 0) && (Split[1] != "0")) |
| 107 | { |
| 108 | // Parsing the number failed |
| 109 | return false; |
| 110 | } |
| 111 | a_Item.m_ItemCount = 1; |
| 112 | return true; |
| 113 | } |
| 114 | |
| 115 | |
| 116 | AString Desolve(short a_ItemType, short a_ItemDamage) |
no test coverage detected