void ChartBase:: free_chart_items(Items& itms) { Item *temp; while( !itms.empty() ) { temp = itms.front(); //temp->check(); itms.pop_front(); //if(!temp->term()->terminal_p()) delete temp; } }
QString ShopTemplateManager::FetchFromItemsKey(const QString &key, const Items &items, QHash<QString, QString> *options) { QString replacement; if (items.size() > 0){ Items result; bool includeNoBuyouts = options->contains("include.ignored"); ShopTemplateContainType containType = CONTAIN_TYPE_NONE; if (key == "everything") { result = items; } else if (key.startsWith("stash:")) { int index = key.indexOf(":"); QString name = (index + 1 >= key.length()) ? "" : key.mid(index + 1); if (!name.isEmpty()) { for (const std::shared_ptr<Item> &item : items) { if (QString::fromStdString(item->location().GetLabel()).compare(name, Qt::CaseInsensitive) == 0) { result.push_back(item); } } } includeNoBuyouts = true; } else { Items pool = items; QStringList keyParts = key.split("+", QString::SkipEmptyParts); for (QString part : keyParts) { if (templateMatchers.contains(part)) { result = FindMatchingItems(pool, part); } else { // todo(novynn): phase these out? Prefer {Normal+Helmet} over {NormalHelmet} bool matchedRarity = false; const QStringList rarities = {"normal", "magic", "rare", "unique"}; for (QString rarity : rarities) { if (part.startsWith(rarity)) { QString type = part.mid(rarity.length()); result = FindMatchingItems(pool, rarity); result = FindMatchingItems(result, type); matchedRarity = true; } } if (matchedRarity) continue; if (part.endsWith("gems")) { if (part == "gems" || part == "allgems") { result = FindMatchingItems(pool, "gems"); } else { const QStringList gemTypes = {"AoE", "Attack", "Aura", "Bow", "Cast", "Chaining", "Chaos", "Cold", "Curse", "Duration", "Fire", "Lightning", "Melee", "Mine", "Minion", "Movement", "Projectile", "Spell", "Totem", "Trap", "Support"}; for (QString gemType : gemTypes) { if (!part.startsWith(gemType, Qt::CaseInsensitive)) continue; // This will never just be first key (?) QString firstKey = gemType.toLower() + "gems"; result = FindMatchingItems(pool, firstKey); if (part != firstKey) { // supportlightninggems QString secondKey = part.mid(gemType.length()); result = FindMatchingItems(result, secondKey); } } } } } pool = result; } } // If no items were returned, bail out now! if (result.size() == 0) return replacement; // Only select items from your stash unless specified if (!options->contains("include.character")) { result = from(result) .where([](const std::shared_ptr<Item> item) { return item->location().type() == ItemLocationType::STASH; }) .toVector(); } // Recheck if (result.size() == 0) return replacement; if (containType == CONTAIN_TYPE_NONE && options->contains("wrap")) containType = CONTAIN_TYPE_WRAP; if (containType == CONTAIN_TYPE_NONE && options->contains("group")) containType = CONTAIN_TYPE_GROUP; switch (containType) { case (CONTAIN_TYPE_WRAP): { QString header = "Items"; Buyout buyout = {}; if (options->contains("header")) { header = options->value("header"); } const std::shared_ptr<Item> first = result.front(); if (parent_->buyout_manager().Exists(*first)) buyout = parent_->buyout_manager().Get(*first); bool sameBuyout = from(result).all([this, buyout](const std::shared_ptr<Item> item) { Buyout thisBuyout = {}; if (parent_->buyout_manager().Exists(*item)) thisBuyout = parent_->buyout_manager().Get(*item); return BuyoutManager::Equal(thisBuyout, buyout); }); if (sameBuyout) { header += BuyoutManager::Generate(buyout); } QString temp; WriteItems(result, &temp, !sameBuyout, includeNoBuyouts); if (temp.isEmpty()) return replacement; replacement += QString("[spoiler=\"%1\"]").arg(header); replacement += temp; replacement += "[/spoiler]"; break; } case CONTAIN_TYPE_GROUP: { QMultiMap<Buyout, std::shared_ptr<Item>> itemsMap; for (auto &item : result) { Buyout b = {}; if (parent_->buyout_manager().Exists(*item)) b = parent_->buyout_manager().Get(*item); itemsMap.insert(b, item); } for (Buyout b : itemsMap.uniqueKeys()) { Items itemList = itemsMap.values(b).toVector().toStdVector(); if (itemList.size() == 0) continue; QString header = BuyoutManager::Generate(b); if (header.isEmpty()) header = "Offers Accepted"; QString temp; WriteItems(itemList, &temp, false, includeNoBuyouts); if (temp.isEmpty()) continue; replacement += QString("[spoiler=\"%1\"]").arg(header); replacement += temp; replacement += "[/spoiler]"; } break; } default: { WriteItems(result, &replacement, true, includeNoBuyouts); break; } } } return replacement; }