Example #1
0
void Wearer::setBlocked(ItemSlotType slot, bool blocked)
{
  if ( hasSlot(slot) && !isEquipped(slot) )
  {
    auto& p = _itemSlots[slot];
    p.second = blocked;
  }
}
Example #2
0
/**
  Add a static slot to the component.

  Ownership of the slot remains at the caller.
  A EKeyError exception is thrown if there is already a slot with
  the specified name.
  
  \warning As the ownership is \b not transferred you have to make sure 
           that the slot is \b not deleted before the component is deleted!
           The intention of this method is to enable components to have
           static slots that are defined right within their class which
           means the lifetimes of the slot and the component are automatically
           tied together.

  \param name Slot name
  \param slot Static slot
 */
void Component::addSlot(const string& name, ISlot& slot)
{
  DEBUGINFO2(this, "Component::addSlot(\"%s\", 0x%x)", name.c_str(), (long)&slot);
  if (hasSlot(name))
  {
    throw EKeyError("Slot \""+name+"\" already exists.");
  }
  StaticSlotDescriptor* desc = new StaticSlotDescriptor(slot);
  slots[name] = desc;
}
Example #3
0
/**
  Add a dynamic slot to the component.

  Ownership of the slot is transferred to the component, i.e. when 
  the component is deleted the slot is deleted as well.
  A EKeyError exception is thrown if there is already a slot with
  the specified name.
  
  \param name Slot name
  \param slot Dynamically allocated slot
 */
void Component::addSlot(const string& name, auto_ptr<ISlot> slot)
{
  DEBUGINFO2(this, "Component::addSlot(\"%s\", auto_ptr(0x%x))", name.c_str(), (long)slot.get());
  if (hasSlot(name))
  {
    throw EKeyError("Slot \""+name+"\" already exists.");
  }
  DynamicSlotDescriptor* desc = new DynamicSlotDescriptor(slot);
  slots[name] = desc;
}
Example #4
0
void Wearer::assignItemsToSlots()
{
  for ( ActorPtr a : _equippedItems->toVector() )
  {
    PickablePtr pickable = a ? a->getFeature<Pickable>() : nullptr;
    if ( pickable && hasSlot( pickable->getItemSlot() ))
    {
      _itemSlots[ pickable->getItemSlot() ] = std::make_pair(a, false);
    }
  }
}
Example #5
0
bool Wearer::equip(ActorPtr item)
{
  if ( !item ) return false;

  PickablePtr pickable = item->getFeature<Pickable>();
  if ( !pickable ) return false;

  ItemSlotType slot = pickable->getItemSlot();

  if ( hasSlot(slot) && !isEquipped(slot) )
  {
    _equippedItems->push_back(item);
    _itemSlots[slot] = std::make_pair(item, false);

    return true;
  }

  return false;
}
Example #6
0
bool Wearer::isEqual(ActorFeaturePtr rhs) const
{
  bool equal = false;
  WearerPtr crhs = std::dynamic_pointer_cast<Wearer>(rhs);

  if ( crhs != nullptr )
  {
    equal = true;
    //compare item slots and equipped items
    for (auto slot : ItemSlotType())
    {
      equal &= (hasSlot(slot) == crhs->hasSlot(slot));
      equal &= (isEquipped(slot) == crhs->isEquipped(slot));
      if ( equipped(slot) && crhs->equipped(slot) ) equal &=  ( *(equipped(slot)) == *(crhs->equipped(slot)) );
    }
  }

  return equal;
}
Example #7
0
	Slot* EventHandler::getSlot(String name)
	{
		if(hasSlot(name))
			return &(mSlots.find(name)->second);
		return 0;
	}