本文整理汇总了C++中InventoryList::changeItem方法的典型用法代码示例。如果您正苦于以下问题:C++ InventoryList::changeItem方法的具体用法?C++ InventoryList::changeItem怎么用?C++ InventoryList::changeItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InventoryList
的用法示例。
在下文中一共展示了InventoryList::changeItem方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read_inventory_list
void read_inventory_list(lua_State *L, int tableindex,
Inventory *inv, const char *name, Server* srv, int forcesize)
{
if(tableindex < 0)
tableindex = lua_gettop(L) + 1 + tableindex;
// If nil, delete list
if(lua_isnil(L, tableindex)){
inv->deleteList(name);
return;
}
// Otherwise set list
std::vector<ItemStack> items = read_items(L, tableindex,srv);
int listsize = (forcesize != -1) ? forcesize : items.size();
InventoryList *invlist = inv->addList(name, listsize);
int index = 0;
for(std::vector<ItemStack>::const_iterator
i = items.begin(); i != items.end(); i++){
if(forcesize != -1 && index == forcesize)
break;
invlist->changeItem(index, *i);
index++;
}
while(forcesize != -1 && index < forcesize){
invlist->deleteItem(index);
index++;
}
}
示例2: setWieldedItem
bool PlayerSAO::setWieldedItem(const ItemStack &item)
{
Inventory *inv = getInventory();
if (inv) {
InventoryList *mlist = inv->getList(getWieldList());
if (mlist) {
ItemStack olditem = mlist->getItem(getWieldIndex());
if (olditem.name.empty()) {
InventoryList *hlist = inv->getList("hand");
if (hlist) {
hlist->changeItem(0, item);
return true;
}
}
mlist->changeItem(getWieldIndex(), item);
return true;
}
}
return false;
}
示例3: setWieldedItem
bool PlayerSAO::setWieldedItem(const ItemStack &item)
{
Inventory *inv = getInventory();
if (inv) {
InventoryList *mlist = inv->getList(getWieldList());
if (mlist) {
mlist->changeItem(getWieldIndex(), item);
return true;
}
}
return false;
}
示例4: setWieldedItem
bool ServerActiveObject::setWieldedItem(const ItemStack &item)
{
Inventory *inv = getInventory();
if(inv)
{
InventoryList *list = inv->getList(getWieldList());
if (list)
{
list->changeItem(getWieldIndex(), item);
setInventoryModified();
return true;
}
}
return false;
}
示例5: l_set_stack
// set_stack(self, listname, i, stack) -> true/false
int InvRef::l_set_stack(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
InvRef *ref = checkobject(L, 1);
const char *listname = luaL_checkstring(L, 2);
int i = luaL_checknumber(L, 3) - 1;
ItemStack newitem = read_item(L, 4, getServer(L)->idef());
InventoryList *list = getlist(L, ref, listname);
if(list != NULL && i >= 0 && i < (int) list->getSize()){
list->changeItem(i, newitem);
reportInventoryChange(L, ref);
lua_pushboolean(L, true);
} else {
lua_pushboolean(L, false);
}
return 1;
}
示例6: getCraftingResult
// Crafting helper
bool getCraftingResult(Inventory *inv, ItemStack& result,
std::vector<ItemStack> &output_replacements,
bool decrementInput, IGameDef *gamedef)
{
DSTACK(__FUNCTION_NAME);
result.clear();
// Get the InventoryList in which we will operate
InventoryList *clist = inv->getList("craft");
if(!clist)
return false;
// Mangle crafting grid to an another format
CraftInput ci;
ci.method = CRAFT_METHOD_NORMAL;
ci.width = clist->getWidth() ? clist->getWidth() : 3;
for(u16 i=0; i<clist->getSize(); i++)
ci.items.push_back(clist->getItem(i));
// Find out what is crafted and add it to result item slot
CraftOutput co;
bool found = gamedef->getCraftDefManager()->getCraftResult(
ci, co, output_replacements, decrementInput, gamedef);
if(found)
result.deSerialize(co.item, gamedef->getItemDefManager());
if(found && decrementInput)
{
// CraftInput has been changed, apply changes in clist
for(u16 i=0; i<clist->getSize(); i++)
{
clist->changeItem(i, ci.items[i]);
}
}
return found;
}
示例7: loadPlayer
bool PlayerDatabasePostgreSQL::loadPlayer(RemotePlayer *player, PlayerSAO *sao)
{
sanity_check(sao);
verifyDatabase();
const char *values[] = { player->getName() };
PGresult *results = execPrepared("load_player", 1, values, false, false);
// Player not found, return not found
if (!PQntuples(results)) {
PQclear(results);
return false;
}
sao->setPitch(pg_to_float(results, 0, 0));
sao->setYaw(pg_to_float(results, 0, 1));
sao->setBasePosition(v3f(
pg_to_float(results, 0, 2),
pg_to_float(results, 0, 3),
pg_to_float(results, 0, 4))
);
sao->setHPRaw((s16) pg_to_int(results, 0, 5));
sao->setBreath((u16) pg_to_int(results, 0, 6), false);
PQclear(results);
// Load inventory
results = execPrepared("load_player_inventories", 1, values, false, false);
int resultCount = PQntuples(results);
for (int row = 0; row < resultCount; ++row) {
InventoryList* invList = player->inventory.
addList(PQgetvalue(results, row, 2), pg_to_uint(results, row, 3));
invList->setWidth(pg_to_uint(results, row, 1));
u32 invId = pg_to_uint(results, row, 0);
std::string invIdStr = itos(invId);
const char* values2[] = {
player->getName(),
invIdStr.c_str()
};
PGresult *results2 = execPrepared("load_player_inventory_items", 2,
values2, false, false);
int resultCount2 = PQntuples(results2);
for (int row2 = 0; row2 < resultCount2; row2++) {
const std::string itemStr = PQgetvalue(results2, row2, 1);
if (itemStr.length() > 0) {
ItemStack stack;
stack.deSerialize(itemStr);
invList->changeItem(pg_to_uint(results2, row2, 0), stack);
}
}
PQclear(results2);
}
PQclear(results);
results = execPrepared("load_player_metadata", 1, values, false);
int numrows = PQntuples(results);
for (int row = 0; row < numrows; row++) {
sao->getMeta().setString(PQgetvalue(results, row, 0), PQgetvalue(results, row, 1));
}
sao->getMeta().setModified(false);
PQclear(results);
return true;
}
示例8: ProcessData
//.........这里部分代码省略.........
player->hp = hp;
}
else if(command == TOCLIENT_MOVE_PLAYER)
{
std::string datastring((char*)&data[2], datasize-2);
std::istringstream is(datastring, std::ios_base::binary);
Player *player = m_env.getLocalPlayer();
assert(player != NULL);
v3f pos = readV3F1000(is);
f32 pitch = readF1000(is);
f32 yaw = readF1000(is);
player->setPosition(pos);
/*player->setPitch(pitch);
player->setYaw(yaw);*/
infostream<<"Client got TOCLIENT_MOVE_PLAYER"
<<" pos=("<<pos.X<<","<<pos.Y<<","<<pos.Z<<")"
<<" pitch="<<pitch
<<" yaw="<<yaw
<<std::endl;
/*
Add to ClientEvent queue.
This has to be sent to the main program because otherwise
it would just force the pitch and yaw values to whatever
the camera points to.
*/
ClientEvent event;
event.type = CE_PLAYER_FORCE_MOVE;
event.player_force_move.pitch = pitch;
event.player_force_move.yaw = yaw;
m_client_event_queue.push_back(event);
// Ignore damage for a few seconds, so that the player doesn't
// get damage from falling on ground
m_ignore_damage_timer = 3.0;
}
else if(command == TOCLIENT_PLAYERITEM)
{
std::string datastring((char*)&data[2], datasize-2);
std::istringstream is(datastring, std::ios_base::binary);
u16 count = readU16(is);
for (u16 i = 0; i < count; ++i) {
u16 peer_id = readU16(is);
Player *player = m_env.getPlayer(peer_id);
if (player == NULL)
{
infostream<<"Client: ignoring player item "
<< deSerializeString(is)
<< " for non-existing peer id " << peer_id
<< std::endl;
continue;
} else if (player->isLocal()) {
infostream<<"Client: ignoring player item "
<< deSerializeString(is)
<< " for local player" << std::endl;
continue;
} else {
InventoryList *inv = player->inventory.getList("main");
std::string itemstring(deSerializeString(is));
if (itemstring.empty()) {
inv->deleteItem(0);
infostream
<<"Client: empty player item for peer "
<< peer_id << std::endl;
} else {
std::istringstream iss(itemstring);
delete inv->changeItem(0, InventoryItem::deSerialize(iss));
infostream<<"Client: player item for peer " << peer_id << ": ";
player->getWieldItem()->serialize(infostream);
infostream<<std::endl;
}
}
}
}
else if(command == TOCLIENT_DEATHSCREEN)
{
std::string datastring((char*)&data[2], datasize-2);
std::istringstream is(datastring, std::ios_base::binary);
bool set_camera_point_target = readU8(is);
v3f camera_point_target = readV3F1000(is);
ClientEvent event;
event.type = CE_DEATHSCREEN;
event.deathscreen.set_camera_point_target = set_camera_point_target;
event.deathscreen.camera_point_target_x = camera_point_target.X;
event.deathscreen.camera_point_target_y = camera_point_target.Y;
event.deathscreen.camera_point_target_z = camera_point_target.Z;
m_client_event_queue.push_back(event);
}
else
{
infostream<<"Client: Ignoring unknown command "
<<command<<std::endl;
}
}