当前位置: 首页>>代码示例>>C++>>正文


C++ Npc::addShopPlayer方法代码示例

本文整理汇总了C++中Npc::addShopPlayer方法的典型用法代码示例。如果您正苦于以下问题:C++ Npc::addShopPlayer方法的具体用法?C++ Npc::addShopPlayer怎么用?C++ Npc::addShopPlayer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Npc的用法示例。


在下文中一共展示了Npc::addShopPlayer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: luaNpcOpenShopWindow

int NpcScriptInterface::luaNpcOpenShopWindow(lua_State* L)
{
    // npc:openShopWindow(cid, items, buyCallback, sellCallback)
    if (!isTable(L, 3)) {
        reportErrorFunc("item list is not a table.");
        pushBoolean(L, false);
        return 1;
    }

    Player* player = getPlayer(L, 2);
    if (!player) {
        reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
        pushBoolean(L, false);
        return 1;
    }

    Npc* npc = getUserdata<Npc>(L, 1);
    if (!npc) {
        reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
        pushBoolean(L, false);
        return 1;
    }

    int32_t sellCallback = -1;
    if (LuaScriptInterface::isFunction(L, 5)) {
        sellCallback = luaL_ref(L, LUA_REGISTRYINDEX);
    }

    int32_t buyCallback = -1;
    if (LuaScriptInterface::isFunction(L, 4)) {
        buyCallback = luaL_ref(L, LUA_REGISTRYINDEX);
    }

    std::list<ShopInfo> items;

    lua_pushnil(L);
    while (lua_next(L, 3) != 0) {
        const auto tableIndex = lua_gettop(L);
        ShopInfo item;

        item.itemId = getField<uint32_t>(L, tableIndex, "id");
        item.subType = getField<int32_t>(L, tableIndex, "subType");
        if (item.subType == 0) {
            item.subType = getField<int32_t>(L, tableIndex, "subtype");
            lua_pop(L, 1);
        }

        item.buyPrice = getField<uint32_t>(L, tableIndex, "buy");
        item.sellPrice = getField<uint32_t>(L, tableIndex, "sell");
        item.realName = getFieldString(L, tableIndex, "name");

        items.push_back(item);
        lua_pop(L, 6);
    }
    lua_pop(L, 1);

    player->closeShopWindow(false);
    npc->addShopPlayer(player);

    player->setShopOwner(npc, buyCallback, sellCallback);
    player->openShopWindow(npc, items);

    pushBoolean(L, true);
    return 1;
}
开发者ID:marksamman,项目名称:forgottenserver,代码行数:65,代码来源:npc.cpp

示例2: luaOpenShopWindow

int NpcScriptInterface::luaOpenShopWindow(lua_State* L)
{
    //openShopWindow(cid, items, onBuy callback, onSell callback)
    int32_t sellCallback;
    if (lua_isfunction(L, -1) == 0) {
        sellCallback = -1;
        lua_pop(L, 1); // skip it - use default value
    } else {
        sellCallback = popCallback(L);
    }

    int32_t buyCallback;
    if (lua_isfunction(L, -1) == 0) {
        buyCallback = -1;
        lua_pop(L, 1); // skip it - use default value
    } else {
        buyCallback = popCallback(L);
    }

    if (lua_istable(L, -1) == 0) {
        reportError(__FUNCTION__, "item list is not a table.");
        pushBoolean(L, false);
        return 1;
    }

    std::list<ShopInfo> items;
    lua_pushnil(L);
    while (lua_next(L, -2) != 0) {
        const auto tableIndex = lua_gettop(L);
        ShopInfo item;

        item.itemId = getField<uint32_t>(L, tableIndex, "id");
        item.subType = getField<int32_t>(L, tableIndex, "subType");
        if (item.subType == 0) {
            item.subType = getField<int32_t>(L, tableIndex, "subtype");
            lua_pop(L, 1);
        }

        item.buyPrice = getField<uint32_t>(L, tableIndex, "buy");
        item.sellPrice = getField<uint32_t>(L, tableIndex, "sell");
        item.realName = getFieldString(L, tableIndex, "name");

        items.push_back(item);
        lua_pop(L, 6);
    }
    lua_pop(L, 1);

    Player* player = getPlayer(L, -1);
    if (!player) {
        reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
        pushBoolean(L, false);
        return 1;
    }

    //Close any eventual other shop window currently open.
    player->closeShopWindow(false);

    Npc* npc = getScriptEnv()->getNpc();
    if (!npc) {
        reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
        pushBoolean(L, false);
        return 1;
    }

    npc->addShopPlayer(player);
    player->setShopOwner(npc, buyCallback, sellCallback);
    player->openShopWindow(npc, items);

    pushBoolean(L, true);
    return 1;
}
开发者ID:marksamman,项目名称:forgottenserver,代码行数:71,代码来源:npc.cpp


注:本文中的Npc::addShopPlayer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。