summaryrefslogtreecommitdiff
path: root/src/scripting
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2013-03-10 10:27:51 +0100
committerErik Schilling <ablu.erikschilling@googlemail.com>2013-09-08 10:19:40 +0200
commitf712d68495dd8e040c32da3b1c85bcb7845543ec (patch)
treef1a314bc1ef895c31851428b4ceff8b63d209f66 /src/scripting
parent8ddda85d923a528c7497a628d2fe10fc40b80a1f (diff)
downloadmanaserv-f712d68495dd8e040c32da3b1c85bcb7845543ec.tar.gz
manaserv-f712d68495dd8e040c32da3b1c85bcb7845543ec.tar.bz2
manaserv-f712d68495dd8e040c32da3b1c85bcb7845543ec.tar.xz
manaserv-f712d68495dd8e040c32da3b1c85bcb7845543ec.zip
Cleaned up the inventory handling
Things done: - Removed the equips table and added another column which keeps track about whether the item is equipped or not - Added a message to notify the client about failing equips instead of hardcoding to chat notification - Removed the move possibillity. It was a quite long function and our future idea of the inventory does not need any moves - Removed the inInventory and inEquipment parameters from chr_inv_count, but added a equipped key to the table that chr_get_inventory returns This change makes equipped items still being in the inventory. This means in-inventory triggers are still active! However it makes no sense to disable this triggers during equipping since it will appear as still in the inventory to the client.
Diffstat (limited to 'src/scripting')
-rw-r--r--src/scripting/lua.cpp46
1 files changed, 21 insertions, 25 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 0193d888..50bf3f35 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -901,10 +901,8 @@ static int trade(lua_State *s)
}
/** LUA entity:inv_count (inventory)
- * entity:inv_count(bool inInventory, bool inEquipment,
- * int id1, ..., int idN)
- * entity:inv_count(bool inInventory, bool inEquipment,
- * string name1, ..., string nameN)
+ * entity:inv_count(int id1, ..., int idN)
+ * entity:inv_count(string name1, ..., string nameN)
**
* Valid only for character entities.
*
@@ -923,17 +921,14 @@ static int entity_inv_count(lua_State *s)
return 0;
}
- bool inInventory = lua_toboolean(s, 2);
- bool inEquipment = lua_toboolean(s, 3);
-
- int nb_items = lua_gettop(s) - 3;
+ int nb_items = lua_gettop(s) - 1;
Inventory inv(q);
int nb = 0;
for (int i = 4; i < nb_items + 4; ++i)
{
ItemClass *it = checkItemClass(s, i);
- nb = inv.count(it->getDatabaseID(), inInventory, inEquipment);
+ nb = inv.count(it->getDatabaseID());
lua_pushinteger(s, nb);
}
return nb_items;
@@ -1004,7 +999,7 @@ static int entity_inv_change(lua_State *s)
}
/** LUA entity:inventory (inventory)
- * entity:inventory(): table[]{slot, item id, name, amount}
+ * entity:inventory(): table[]{slot, item id, name, amount, equipped}
**
* Valid only for character entities.
*
@@ -1064,6 +1059,10 @@ static int entity_get_inventory(lua_State *s)
lua_pushinteger(s, it->second.amount);
lua_settable(s, subTableStackPosition);
+ lua_pushliteral(s, "equipped");
+ lua_pushboolean(s, it->second.equipmentSlot != 0);
+ lua_settable(s, subTableStackPosition);
+
// Add the sub-table as value of the main one.
lua_rawseti(s, firstTableStackPosition, tableIndex);
++tableIndex;
@@ -1098,39 +1097,36 @@ static int entity_get_equipment(lua_State *s)
Entity *q = checkCharacter(s, 1);
// Create a lua table with the inventory ids.
- const EquipData equipData = q->getComponent<CharacterComponent>()
- ->getPossessions().getEquipment();
+ auto *characterComponent = q->getComponent<CharacterComponent>();
+ const InventoryData inventoryData =
+ characterComponent->getPossessions().getInventory();
+ const EquipData equipData =
+ characterComponent->getPossessions().getEquipment();
lua_newtable(s);
int firstTableStackPosition = lua_gettop(s);
int tableIndex = 1;
- std::set<unsigned> itemInstances;
-
for (EquipData::const_iterator it = equipData.begin(),
it_end = equipData.end(); it != it_end; ++it)
{
- if (!it->second.itemId || !it->second.itemInstance)
- continue;
-
- // Only count multi-slot items once.
- if (!itemInstances.insert(it->second.itemInstance).second)
- continue;
+ InventoryData::const_iterator itemIt = inventoryData.find(*it);
+ const InventoryItem &item = itemIt->second;
// Create the sub-table (value of the main one)
lua_createtable(s, 0, 3);
int subTableStackPosition = lua_gettop(s);
// Stores the item info in it.
lua_pushliteral(s, "slot");
- lua_pushinteger(s, it->first); // The slot id
+ lua_pushinteger(s, item.slot); // The slot id
lua_settable(s, subTableStackPosition);
lua_pushliteral(s, "id");
- lua_pushinteger(s, it->second.itemId);
+ lua_pushinteger(s, item.itemId);
lua_settable(s, subTableStackPosition);
lua_pushliteral(s, "name");
- push(s, itemManager->getItem(it->second.itemId)->getName());
+ push(s, itemManager->getItem(item.itemId)->getName());
lua_settable(s, subTableStackPosition);
// Add the sub-table as value of the main one.
@@ -1202,7 +1198,7 @@ static int entity_unequip_slot(lua_State *s)
Inventory inv(ch);
- lua_pushboolean(s, inv.unequip(inv.getSlotItemInstance(equipmentSlot)));
+ lua_pushboolean(s, inv.unequip(equipmentSlot));
return 1;
}
@@ -1223,7 +1219,7 @@ static int entity_unequip_item(lua_State *s)
ItemClass *it = checkItemClass(s, 2);
Inventory inv(ch);
- lua_pushboolean(s, inv.unequipItem(it->getDatabaseID()));
+ lua_pushboolean(s, inv.unequipAll(it->getDatabaseID()));
return 1;
}