| 112 | } |
| 113 | |
| 114 | ItemPtr ItemBag::putItems(size_t pos, ItemPtr items) { |
| 115 | if (!items || items->empty()) |
| 116 | return {}; |
| 117 | |
| 118 | auto& storedItem = at(pos); |
| 119 | |
| 120 | if (storedItem) { |
| 121 | // Try to stack with an item that is already there |
| 122 | storedItem->stackWith(items); |
| 123 | if (!items->empty()) |
| 124 | return items; |
| 125 | else |
| 126 | return {}; |
| 127 | } else { |
| 128 | // Otherwise just put the items there and return nothing. |
| 129 | storedItem = items; |
| 130 | |
| 131 | return {}; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | ItemPtr ItemBag::takeItems(size_t pos, uint64_t count) { |
| 136 | if (auto& storedItem = at(pos)) { |