MIXED: How To Load Shop Ex and Fix Sort

The source allows you to load the npc shops even via a file called shop_table_ex.txt localed in locale/germany/.

A shop can have max 3 categories as such:

ngTteG7.png

Its content is like this:

Group ShopNPC
{
    #--#    NPC    Group
    1    9003    A01
    2    9003    A02
    3    9003    A03
}

Group A01
{
    Vnum    2
    Name    Potions
    CoinType    Gold
    Group Items
    {
        #--#    Vnum    Count    Price
        1    27003    1    1000
        2    27006    1    1000
        3    51821    1    1000
        4    51822    1    1000
        5    51823    1    1000
        6    51824    1    1000
        7    51825    1    1000
        8    51826    1    1000
        9    40017    1    1000
        10    40018    1    1000
        11    40019    1    1000
        12    40020    1    1000
        13    40024    1    1000
        14    40025    1    1000
    }
}

Group A02
{
    Vnum    3
    Name    Ores
    CoinType    Gold
    Group Items
    {
        #--#    Vnum    Count    Price
        1    29    1    1
    }
}

Group A03
{
    Vnum    4
    Name    Sauce
    CoinType    Gold
    Group Items
    {
        #--#    Vnum    Count    Price
        1    39    1    1
    }
}

ShopNPC contains a list of shops (like player.shop in the db) while A01 A02 A03 (custom names) are the shops containing the currency, and the items (like player.shop_item).

Be careful because the shop vnums should not be present in player.shop otherwise they get in conflict.

The CoinType is the currency you want to use. I suggest to only use Gold, because the SecondaryCoin isn't fully implemented.

The Name is the name of the shop, and it's also the name you see in the shop button.


How To Fix the Item Sort

The shop_table_ex.txt may load the items in a random order sometimes. To solve this issue, open Server/game/src/shop_manager.cpp and replace

    std::string stSort;
    if (!pNode->GetValue("sort", 0, stSort))
    {
        stSort = "None";
    }

    if (boost::iequals(stSort, "Asc"))
    {
        std::sort(shopItems.begin(), shopItems.end(), CompareShopItemName);
    }
    else if(boost::iequals(stSort, "Desc"))
    {
        std::sort(shopItems.rbegin(), shopItems.rend(), CompareShopItemName);
    }

with

    std::sort(shopItems.begin(), shopItems.end(), [](const TShopItemTable& lhs, const TShopItemTable& rhs) {
        return lhs.vnum < rhs.vnum;
    });