| 197 | } |
| 198 | |
| 199 | ItemPtr PlayerInventory::addItems(ItemPtr items) { |
| 200 | if (!items || items->empty()) |
| 201 | return {}; |
| 202 | |
| 203 | // First, add coins as monetary value. |
| 204 | if (auto currencyItem = as<CurrencyItem>(items)) { |
| 205 | addCurrency(currencyItem->currencyType(), currencyItem->totalValue()); |
| 206 | return {}; |
| 207 | } |
| 208 | |
| 209 | // Then, try adding equipment to the equipment slots. |
| 210 | if (is<HeadArmor>(items) && !headArmor()) |
| 211 | m_equipment[EquipmentSlot::Head] = items->take(1); |
| 212 | if (is<ChestArmor>(items) && !chestArmor()) |
| 213 | m_equipment[EquipmentSlot::Chest] = items->take(1); |
| 214 | if (is<LegsArmor>(items) && !legsArmor()) |
| 215 | m_equipment[EquipmentSlot::Legs] = items->take(1); |
| 216 | if (is<BackArmor>(items) && !backArmor()) |
| 217 | m_equipment[EquipmentSlot::Back] = items->take(1); |
| 218 | |
| 219 | if (is<MaterialItem>(items)) { |
| 220 | if (auto primary = primaryHeldItem()) { |
| 221 | primary->stackWith(items); |
| 222 | if (items->empty()) |
| 223 | return {}; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | // Then, finally the bags |
| 228 | return addToBags(std::move(items)); |
| 229 | } |
| 230 | |
| 231 | ItemPtr PlayerInventory::addToBags(ItemPtr items) { |
| 232 | if (!items || items->empty()) |
nothing calls this directly
no test coverage detected