void Hero::displayInventory()
{
    cout<<"===== INVENTORY ====="<<endl;
    for(int i=0;i<inventory.size();i++) //Displays names of all items in inventory
    {
        cout<<i<<". "<<inventory[i]->name<<endl;
    }
    int choice;
    do
    {
        cout<<"Please Choose Item to Equip or Exit By Entering \"-1\" "<<endl;
        cout<<"Choice: ";
        cin>>choice;
    }
    while((choice>=inventory.size())&&(choice!=(-1))); //Continues to display message until valid choice is made

    if(choice!=-1) //If User Selected Item
    {
        equipItem(inventory[choice]);
    }
    if(inventory.empty())
    {
        cout<<"No Items in Inventory"<<endl;
    }
    cout<<endl;
}
Example #2
0
void Creature::loadEquipment(const Aurora::GFF3Struct &gff) {
	if (!gff.hasField("Equip_ItemList"))
		return;

	for (const auto &i : gff.getList("Equip_ItemList")) {
		InventorySlot slot = InventorySlot(static_cast<int>(std::log2f(i->getID())));
		Common::UString tag = i->getString("EquippedRes");
		equipItem(tag, slot, false);
	}
}
void AManaJourneyCharacter::equipItems(FName SocketName, TArray<AStaticMeshActor*> equipments)
{
	AActor* equipActor;
	FString equipmentName;

	for (int32 e = 0; e < equipments.Num(); e++)
	{
		equipActor = equipments[e];
		if (equipActor)
		{
			equipmentName = equipActor->GetName();

			// move this to seperate function

			if (equipmentName.Contains("NightwingStaff"))
			{
				equipItem(equipActor, "Staff");
				AStaff* staff = Cast<AStaff>(equipActor);
				if (staff)
				{
					staff->setUserStrength(level, *this);
					staff->setWeaponDamage(*this);
					weaponReference = staff;
				}
			}

			// NOTE: The BP the weapon is made of, MUST be based on the corresponding c++ class ( e.g DragonSword c++ class )
			if (equipmentName.Contains("DragonSword"))
			{
				equipItem(equipActor, "Sword_1");
				ADragonSword* dragonSword = Cast<ADragonSword>(equipActor);
				if (dragonSword)
				{
					dragonSword->setUserStrength(level, *this);
					dragonSword->setWeaponDamage(*this);
					weaponReference = dragonSword;
				}
			}

		}
	}

}
Example #4
0
void Inventory::insertItem(Item *item, bool equip) {
    if(item!=NULL) {
        if(_items.size()==(unsigned)this->_spaces) {
            std::cout << ">> Inventory: cannot insert item \"" << item->getName() << "\", inventory is full!\n";
            return;
        }

        _items.push_back(std::make_pair(item, false));
        if(equip) // if equip, equip item
            equipItem(item->getName());
    }
}
Example #5
0
void UCharacterEquipment::initializeStartEquipment()
{
	for (int32 i = 0; i < initEquipment.Num(); i++)
	{
		if (initEquipment[i].item)
		{
			if (isItemEquippable(initEquipment[i].slot,Cast<UItemBase>( initEquipment[i].item->GetDefaultObject())))
			{
				equipItem(initEquipment[i].slot, NewObject<UItemBase>(this,initEquipment[i].item));
			}
		}
	}
}
/**
 * @brief OknoBazaru::zaloz	Odpowiednio zakłada lub zdejmuje aktualnie zaznaczony przedmiot z listy						przedmiotów gracza
 */
void MarketWindow::equip()
{
	const QList <const Item *> backpack = player_->equipment()->backpack();
	const Item *item = backpack.at(playerItemList->currentRow());

	if (equipButton->text() == unequipText) //NOTE do I really want string comparision? Maybe boolean flag?
		unequipItem(item, player_);
	else
		equipItem(item, player_);

	generateDescription(item, player_, itemDescriptionWidget);
	playerWindow_->update();

	if (isEquipped(item, player_))
		equipButton->setText(unequipText);
	else
		equipButton->setText(equipText);
}
Example #7
0
int invCommands (player *playr){
    char inp;

    printf("Equip : e\tDestroy : d\tUnequip : u\tExit : Anything else\n\n");
    inp = getch();
    if (inp == 'd'){
        printf("Which Item Do You Want to Destroy?");
        inp = getch();
        if (inp != 27) destroyItem(inp-'a');
    } else if (inp == 'e'){
        printf("Which Item Do You Want to Equip?");
        inp = getch();
        if (inp != 27) equipItem(playr ,inp-'a');
    } else if (inp == 'u'){
        printf("Which Item Do You Want to UnEquip?");
        inp = getch();
        if (inp != 27) unEquipItem(playr ,inp-'a');
    }
    return 1;
}
Example #8
0
void Creature::equipItem(Common::UString tag, InventorySlot slot, bool updateModel) {
	equipItem(tag, slot, _info, updateModel);
}
Example #9
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;
}