本文整理汇总了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;
}
示例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;
}