Skip to content

Instantly share code, notes, and snippets.

Created June 13, 2012 19:43
Show Gist options
  • Save anonymous/2926030 to your computer and use it in GitHub Desktop.
Save anonymous/2926030 to your computer and use it in GitHub Desktop.
Feature: Can equip items to various slots exposed by objects
In order to equip items (or other objects) to expose emergent functionality
As a game object
I need to expose various equipable slots based on my type
Scenario Outline: Can equip items to objects that support their arrangement
Given that an object has exposed a slot labeled "inventory"
And that no item is filling the exposed slot
When an equip request for an item is received
And the item has an arrangement requiring an "inventory" slot
Then the item is equipped to the object's "inventory" slot
Scenario Outline: Cannot equip items to objects that don't support their arrangement
Given that an object has exposed a slot labeled "inventory"
When an equip request for an item is received
And the item has an arrangement for another non-"inventory" slot
Then the item is not equipped to the object
Scenario Outline: Can equip items with arrangements that require multiple slots
Given that an object has exposed two slots, "earring_l" and "earring_r"
And that no item or items are filling the exposed slots
When an equip request for an item is received
And the item has an arrangement that requires both "earring_l" and "earring_r"
Then the item is equipped to both of the object's corrisponding slots
Scenario Outline: Equipping a new item to a slot with an existing item unequips the first
Given that an object has exposed a slot labeled "gloves"
And an item is already equipped to the "gloves" slot
When an equip request for an item is received
And the item has an arrangement requiring a "gloves" slot
Then the existing item is unequipped from the "gloves" slot
And the new item is equipped
auto player;
auto item;
auto inventory_item;
// example equiping/unequipping items
player->Equip(item);
player->Unequip(item);
// example retrieving the item set in the inventory slot and using it
player->GetEquipment("inventory")->AddContainedObject(inventory_item);
player->GetEquipment("inventory")->RemoveContainedObject(inventory_item);
// example retrieving all equipped items and using an item equipped to the inventory slot
auto equipment = player->GetEquipment();
equipment["inventory"]->AddContainedObject(inventory_item);
// example using the list of equipped items to accumulate attribute data (such as calculating encumbrance)
int health_encumbrance = 0;
health_encumbrance = std::accumulate(
std::begin(equipment),
std::end(equipment),
[] (int accumulated, const std::shared_ptr<Object>& item)
{
return accumulated + item->GetAttribute<int32_t>("health_encumbrance");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment