MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / addItems

Method addItems

source/game/StarPlayerInventory.cpp:199–229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

197}
198
199ItemPtr 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
231ItemPtr PlayerInventory::addToBags(ItemPtr items) {
232 if (!items || items->empty())

Callers

nothing calls this directly

Calls 5

currencyTypeMethod · 0.80
totalValueMethod · 0.80
emptyMethod · 0.45
takeMethod · 0.45
stackWithMethod · 0.45

Tested by

no test coverage detected