Esempio n. 1
0
	int ActorInventory::unequip(ItemType::Type item_type) {
		int ret = -1;

		if(item_type == ItemType::weapon) {
			if(!m_weapon.isDummy()) {
				ret = add(m_weapon, 1);
				m_weapon = m_dummy_weapon;
			}

			unequip(ItemType::ammo);
		}
		else if(item_type == ItemType::armour) {
			if(!m_armour.isDummy()) {
				ret = add(m_armour, 1);
				m_armour = Item::dummyArmour();
			}
		}
		else if(item_type == ItemType::ammo) {
			if(!m_ammo.item.isDummy()) {
				ret = add(m_ammo.item, m_ammo.count);
				m_ammo.item = Item::dummyAmmo();
				m_ammo.count = 0;
			}
		}

		return ret;
	}
Esempio n. 2
0
void BTPc::equip(BTDisplay &d, int index)
{
 BTFactory<BTItem> &itemList = BTGame::getGame()->getItemList();
 BTParty &party = BTGame::getGame()->getParty();
 int pc = party.find(this);
 int type = itemList[item[index].id].getType();
 for (int i = 0; i < BT_ITEMS; ++i)
 {
  if (BTITEM_NONE == item[i].id)
   break;
  if ((item[i].equipped == BTITEM_EQUIPPED) && (type == itemList[item[i].id].getType()))
  {
   unequip(d, i);
  }
 }
 ac += itemList[item[index].id].getArmorPlus();
 toHit += itemList[item[index].id].getHitPlus();
 item[index].equipped = BTITEM_EQUIPPED;
 if (BTTIMESUSABLE_CONTINUOUS == item[index].charges)
 {
  BTGame *game = BTGame::getGame();
  BTFactory<BTSpell, BTSpell1> &spellList = BTGame::getGame()->getSpellList();
  int spellCast = itemList[item[index].id].getSpellCast();
  int effectID = item[index].effectID;
  if ((effectID != BTEFFECTID_NONE) && (!game->hasEffectID(effectID)))
   effectID = BTEFFECTID_NONE;
  if (effectID == BTEFFECTID_NONE)
  {
   item[index].effectID = effectID = game->nextEffectID();
   spellList[spellCast].silentActivate(d, pc, effectID, level);
  }
 }
}
Esempio n. 3
0
bool Inventory::removeEntityInventoryItem(Entity * entity, Grpg* gamePtr)
{
	// Iterate to element to remove it
	for (map<int,Entity*>::iterator it = slotList.begin(); it != slotList.end(); ++it){
		if (it->second == entity){
			//add pickup behavior
			if (gamePtr != nullptr)
			{
				entity->setPickupBehavior(new PickupBehavior(gamePtr, gamePtr->getDrawManager(), entity, gamePtr->getPlayer()));//change behaviors
				entity->setDropBehavior(nullptr);
				entity->setupVectorActiveBehaviors();
				entity->setX(gamePtr->getPlayer()->getX());//set the entity to the player's position (it was previously in the inventory position)
				entity->setY(gamePtr->getPlayer()->getY());
				entity->setAnchored(false);//and make it affected by viewport
				gamePtr->setMouseOverEntity(nullptr);
			}
			//SAFE_DELETE(it->second);
			unequip(it->first);
			slotList.erase(it->first);
			return true;
		}
	}

	return false; 
}
Esempio n. 4
0
thing_data* Obj_Data :: From( int i )
{
  char_data*         ch;
  obj_data*         obj;
  content_array*  where  = array;
  
  if( number > i ) {
    remove_weight( this, i );
    number        -= i;
    obj            = duplicate( this );   
    obj->number    = i;
    obj->selected  = i;
    return obj;
    }

  Thing_Data :: From( );

  if( ( ch = character( where->where ) ) != NULL
    && where == &ch->wearing )
    unequip( ch, this );

  for( int i = 0; i < *where; i++ ) 
    if( ( ch = character( where->list[i] ) ) != NULL 
      && ch->cast != NULL
      && ch->cast->target == this )
      disrupt_spell( ch ); 

  stop_events( this, execute_decay );

  return this;
}
Esempio n. 5
0
					atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRDY;
					atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_IO|ATAPI_INTREASON_COMMAND;
				}
				else
				{
					// indicate data ready: set DRQ and DMA ready, and IO in INTREASON
					if (atapi_regs[ATAPI_REG_FEATURES] & 0x01)	// DMA feature
					{
						atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_BSY | ATAPI_STAT_DRDY | ATAPI_STAT_SERVDSC;
					}
					else
					{
						atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ | ATAPI_STAT_SERVDSC | ATAPI_STAT_DRQ;
					}
					atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_IO;
				}

				switch( phase )
				{
				case SCSI_PHASE_DATAOUT:
					atapi_cdata_wait = atapi_xferlen;
					break;
				}

				// perform special ATAPI processing of certain commands
				switch (atapi_data[0]&0xff)
				{
					case 0x00: // BUS RESET / TEST UNIT READY
					case 0xbb: // SET CDROM SPEED
						atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
						break;
Esempio n. 6
0
	bool ActorInventory::equip(int id, int count) {
		DASSERT(isValidId(id) && count > 0);

		Item item = m_entries[id].item;
		ItemType::Type type = item.type();
		if((type != ItemType::weapon && type != ItemType::armour && type != ItemType::ammo) || !count)
			return false;
		if(type == ItemType::ammo && m_weapon.proto().ammo_class_id != Ammo(item).classId())
			return false;

		Entry old_ammo = m_ammo;
		unequip(type);

		if(type == ItemType::ammo) {
			if(old_ammo.item == item)
				count += old_ammo.count;
			count = min(count, m_weapon.maxAmmo());
		}
		else
			count = min(count, 1);
		count = min(count, m_entries[id].count);

		remove(id, count);

		if(type == ItemType::weapon)
			m_weapon = item;
		else if(type == ItemType::armour)
			m_armour = item;
		else if(type == ItemType::ammo) {
			m_ammo.item = item;
			m_ammo.count = count;
		}

		return true;
	}
Esempio n. 7
0
void BTPc::takeItemCharge(BTDisplay &d, int index, int amount /*= 1*/)
{
 if (item[index].id == BTITEM_NONE)
  return;
 if ((item[index].charges == 0) || (item[index].charges == BTTIMESUSABLE_UNLIMITED))
  return;
 item[index].charges -= amount;
 if (item[index].charges <= 0)
 {
  BTFactory<BTItem> &itemList = BTGame::getGame()->getItemList();
  if (itemList[item[index].id].isConsumed())
  {
   if (item[index].equipped == BTITEM_EQUIPPED)
    unequip(d, index);
   for (int i = index + 1; i < BT_ITEMS; ++i)
   {
    item[i - 1].id = item[i].id;
    item[i - 1].equipped = item[i].equipped;
    item[i - 1].known = item[i].known;
    item[i - 1].charges = item[i].charges;
   }
   item[BT_ITEMS - 1].id = BTITEM_NONE;
  }
  else
  {
   item[index].charges = 0;
  }
 }
}
Esempio n. 8
0
void Hero::handleStateEquip(bool pressed, int key)
{
    showInventory();

    if (pressed)
    {
        switch (key)
        {
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        {
            int i = m_inventoryPage * INVENTORY_PAGE_SIZE + key - '1';
            if (i < (int)m_items.size())
            {
                ItemSharedPtr item = m_items[i];
                if (isEquipped(item))
                {
                    unequip(item);
                }
                else
                {
                    equip(item);
                }
            }
        }
        break;

        case 'n':
        case 'N':
        {
            m_inventoryPage++;
            if (m_inventoryPage * INVENTORY_PAGE_SIZE > (int)m_items.size())
            {
                m_inventoryPage = 0;
            }
        }
        break;

        case ' ':
            m_state = State::InGame;
            break;

        case 's':
        case 'S':
            m_state = State::Status;
            break;

        case 'd':
        case 'D':
            m_state = State::Drop;
            break;
        }
    }
}
Esempio n. 9
0
ActorPtr Wearer::unequip(ActorPtr actor)
{
  for (const auto& p : _itemSlots)
  {
    if ( p.second.first == actor )
    {
      return unequip(p.first);
    }
  }
  return actor;
}
Esempio n. 10
0
bool Inventory::removeEntityInventoryItem(int i)
{
	if (hasEntityInventoryItem(i))
	{
		unequip(i);
		slotList[i] = nullptr;
		slotList.erase(i);
		return true;
	}
	return false;
}
Esempio n. 11
0
bool Inventory::destroyEntityInventoryItem(int i)
{
	if (hasEntityInventoryItem(i))
	{
		unequip(i);
		SAFE_DELETE(slotList[i]);
		slotList[i] = nullptr;
		slotList.erase(i);
		return true;
	}
	return false;
}
Esempio n. 12
0
bool BTPc::takeItemFromIndex(BTDisplay &d, int index)
{
 if (item[index].id == BTITEM_NONE)
  return false;
 if (item[index].equipped == BTITEM_EQUIPPED)
  unequip(d, index);
 for (int i = index + 1; i < BT_ITEMS; ++i)
 {
  item[i - 1].id = item[i].id;
  item[i - 1].equipped = item[i].equipped;
  item[i - 1].known = item[i].known;
  item[i - 1].charges = item[i].charges;
 }
 item[BT_ITEMS - 1].id = BTITEM_NONE;
 return true;
}
Esempio n. 13
0
bool BTPc::equip(BTDisplay &d, int index)
{
 BTItemSlotList &itemSlotList = BTGame::getGame()->getItemSlotList();
 BTItemTypeList &itemTypeList = BTGame::getGame()->getItemTypeList();
 BTFactory<BTItem> &itemList = BTGame::getGame()->getItemList();
 BTParty &party = BTGame::getGame()->getParty();
 int pc = party.find(this);
 int type = itemList[item[index].id].getType();
 int itemSlot = itemTypeList[type]->itemSlot;
 int numberSlots = itemSlotList[itemSlot]->number;
 int usedSlots = 0;
 for (int i = 0; i < BT_ITEMS; ++i)
 {
  if (BTITEM_NONE == item[i].id)
   break;
  if ((item[i].equipped == BTITEM_EQUIPPED) && (itemSlot == itemTypeList[itemList[item[i].id].getType()]->itemSlot))
  {
   if (numberSlots == 1)
    unequip(d, i);
   else
    usedSlots++;
  }
 }
 if (usedSlots >= numberSlots)
  return false;
 ac += itemList[item[index].id].getArmorPlus();
 if (itemTypeList[itemList[item[index].id].getType()]->toHitBonus == BTTOHITBONUS_ALWAYS)
  toHit += itemList[item[index].id].getHitPlus();
 item[index].equipped = BTITEM_EQUIPPED;
 if (BTTIMESUSABLE_CONTINUOUS == item[index].charges)
 {
  BTGame *game = BTGame::getGame();
  BTFactory<BTSpell, BTSpell1> &spellList = BTGame::getGame()->getSpellList();
  int spellCast = itemList[item[index].id].getSpellCast();
  int effectID = item[index].effectID;
  if ((effectID != BTEFFECTID_NONE) && (!game->hasEffectID(effectID)))
   effectID = BTEFFECTID_NONE;
  if (effectID == BTEFFECTID_NONE)
  {
   item[index].effectID = effectID = game->nextEffectID();
   spellList[spellCast].silentActivate(d, pc, effectID, level);
  }
 }
 return true;
}
Esempio n. 14
0
bool Inventory::unequipItem(unsigned itemId)
{
    std::set<unsigned> itemInstances;
    for (EquipData::iterator it = mPoss->equipSlots.begin(),
        it_end = mPoss->equipSlots.end(); it != it_end; ++it)
    {
        if (it->second.itemId == itemId)
            itemInstances.insert(it->second.itemInstance);
    }

    // Nothing to do but it's a success
    if (itemInstances.empty())
        return true;

    for (std::set<unsigned>::const_iterator it = itemInstances.begin(),
        it_end = itemInstances.end(); it != it_end; ++it)
    {
        if (!unequip(*it))
            return false;
    }
    return true;
}
Esempio n. 15
0
unsigned int Inventory::remove(unsigned int itemId, unsigned int amount, bool force)
{
    prepare();
    bool inv = false,
         eq = !itemManager->getItem(itemId)->getItemEquipData().empty();
    for (InventoryData::iterator it = mPoss->inventory.begin(),
                                 it_end = mPoss->inventory.end();
         it != it_end; ++it)
        if (it->second.itemId == itemId)
        {
            if (amount)
            {
                if (eq)
                {
                    // If the item is equippable, we have additional checks to make.
                    bool ch = false;
                    for (EquipData::iterator it2 = mPoss->equipSlots.begin(),
                                         it2_end = mPoss->equipSlots.end();
                         it2 != it2_end;
                         ++it2)
                        if (it2->second == it->first)
                        {
                            if (force)
                                unequip(it2);
                            else
                                ch = inv = true;
                            break;
                        }
                    if (ch && !force)
                        continue;
                }
                unsigned int sub = std::min(amount, it->second.amount);
                amount -= sub;
                it->second.amount -= sub;
                mInvMsg.writeInt16(it->first);
                if (it->second.amount)
                {
                    mInvMsg.writeInt16(it->second.itemId);
                    mInvMsg.writeInt16(it->second.amount);
                    // Some still exist, and we have none left to remove, so
                    // no need to run leave invy triggers.
                    if (!amount)
                        return 0;
                }
                else
                {
                    mInvMsg.writeInt16(0);
                    mPoss->inventory.erase(it);
                }
            }
            else
                // We found an instance of them existing and have none left to
                // remove, so no need to run leave invy triggers.
                return 0;
        }
    if (force)
        itemManager->getItem(itemId)->useTrigger(mClient, ITT_LEAVE_INVY);
    // Rather inefficient, but still usable for now assuming small invy size.
    // FIXME
    return inv && !force ? remove(itemId, amount, true) : amount;
}
Esempio n. 16
0
PItem Equipment::removeItem(WItem item, WCreature c) {
  if (isEquipped(item))
    unequip(item, c);
  return Inventory::removeItem(item);
}
Esempio n. 17
0
bool Inventory::equip(int inventorySlot)
{
    // Test inventory slot existence
    InventoryData::iterator it;
    if ((it = mPoss->inventory.find(inventorySlot)) == mPoss->inventory.end())
    {
        LOG_DEBUG("No existing item in inventory at slot: " << inventorySlot);
        return false;
    }

    // Test the equipment scripted requirements
    if (!testEquipScriptRequirements(it->second.itemId))
        return false;

    // Test the equip requirements. If none, it's not an equipable item.
    const ItemEquipRequirement &equipReq =
        itemManager->getItem(it->second.itemId)->getItemEquipRequirement();
    if (!equipReq.equipSlotId)
    {
        LOG_DEBUG("No equip requirements for item id: " << it->second.itemId
            << " at slot: " << inventorySlot);
        return false;
    }

    // List of potential unique itemInstances to unequip first.
    std::set<unsigned> equipInstancesToUnequipFirst;

    // We first check the equipment slots for:
    // - 1. whether enough total equip slot space is available.
    // - 2. whether some other equipment is to be unequipped first.

    // If not enough total space in the equipment slot is available,
    // we cannot equip.
    if (itemManager->getEquipSlotCapacity(equipReq.equipSlotId)
            < equipReq.capacityRequired)
    {
        LOG_DEBUG("Not enough equip capacity at slot: " << equipReq.equipSlotId
                  << ", total available: "
                  << itemManager->getEquipSlotCapacity(equipReq.equipSlotId)
                  << ", required: " << equipReq.capacityRequired);
        return false;
    }

    // Test whether some item(s) is(are) to be unequipped first.
    if (!checkEquipmentCapacity(equipReq.equipSlotId,
                                equipReq.capacityRequired))
    {
        // And test whether the unequip action would succeed first.
        if (testUnequipScriptRequirements(equipReq.equipSlotId)
            && hasInventoryEnoughSpace(equipReq.equipSlotId))
        {
            // Then, we unequip each iteminstance of the equip slot
            for (EquipData::iterator iter =
                mPoss->equipSlots.begin();
                iter != mPoss->equipSlots.end(); ++iter)
            {
                if (iter->first == equipReq.equipSlotId
                    && iter->second.itemInstance)
                    equipInstancesToUnequipFirst.insert(
                                                     iter->second.itemInstance);
            }
        }
        else
        {
            // Some non-unequippable equipment is to be unequipped first.
            // Can be the case of cursed items,
            // or when the inventory is full, for instance.
            return false;
        }
    }

    // Potential Pre-unequipment process
    for (std::set<unsigned>::const_iterator it3 =
            equipInstancesToUnequipFirst.begin();
            it3 != equipInstancesToUnequipFirst.end(); ++it3)
    {
        if (!unequip(*it3))
        {
            // Something went wrong even when we tested the unequipment process.
            LOG_WARN("Unable to unequip even when unequip was tested. "
                     "Character : "
                    << mCharacter->getComponent<BeingComponent>()->getName()
                     << ", unequip slot: " << *it3);
            return false;
        }
    }

    // Actually equip the item now that the requirements has met.
    //W equip slot type count, W item id, { W equip slot, W capacity used}*
    MessageOut equipMsg(GPMSG_EQUIP);
    equipMsg.writeInt16(it->second.itemId); // Item Id
    equipMsg.writeInt16(1); // Number of equip slot changed.

    // Compute an unique equip item Instance id (unicity is per character only.)
    int itemInstance = getNewEquipItemInstance();

    unsigned capacityLeft = equipReq.capacityRequired;
    unsigned capacityUsed = 0;
    // Apply equipment changes
    for (EquipData::iterator it4 = mPoss->equipSlots.begin(),
         it4_end = mPoss->equipSlots.end(); it4 != it4_end; ++it4)
    {
        if (!capacityLeft)
            break;

        // We've found an existing equip slot
        if (it4->first == equipReq.equipSlotId)
        {
            // We've found an empty slot
            if (it4->second.itemInstance == 0)
            {
                it4->second.itemId = it->second.itemId;
                it4->second.itemInstance = itemInstance;
                --capacityLeft;
            }
            else // The slot is already in use.
            {
                ++capacityUsed;
            }
        }
    }

    // When there is still something to apply even when out of that loop,
    // It means that the equip multimapis missing empty slots.
    // Hence, we add them back
    if(capacityLeft)
    {
        unsigned maxCapacity =
            itemManager->getEquipSlotCapacity(equipReq.equipSlotId);

        // A should never happen case
        assert(maxCapacity >= capacityUsed + capacityLeft);

        while (capacityLeft)
        {
            EquipmentItem equipItem(it->second.itemId, itemInstance);
            mPoss->equipSlots.insert(
                    std::make_pair(equipReq.equipSlotId, equipItem));
            --capacityLeft;
        }
    }

    // Equip slot
    equipMsg.writeInt16(equipReq.equipSlotId);
    // Capacity used
    equipMsg.writeInt16(equipReq.capacityRequired);
    // Item instance
    equipMsg.writeInt16(itemInstance);

    // New item trigger
    updateEquipmentTrigger(0, it->second.itemId);

    // Remove item from inventory
    removeFromSlot(inventorySlot, 1);

    gameHandler->sendTo(mCharacter, equipMsg);

    // Update look when necessary
    checkLookchanges(equipReq.equipSlotId);

    return true;
}
Esempio n. 18
0
PItem Equipment::removeItem(Item* item) {
  if (isEquiped(item))
    unequip(item);
  return Inventory::removeItem(item);
}