//------------------------------------------------------------------------ void CInventory::Destroy() { // //CryLog("%s::CInventory::Destroy()",GetEntity()->GetName()); // if(!GetISystem()->IsSerializingFile()) { IEntitySystem *pEntitySystem = gEnv->pEntitySystem; IItemSystem *pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem(); TInventoryVector deleteList = m_stats.slots; for (TInventoryIt it = deleteList.begin(); it != deleteList.end(); ++it) { EntityId entityId = *it; IItem *pItem = pItemSystem->GetItem(entityId); if (pItem) { RemoveItemFromCategorySlot(pItem->GetEntityId()); pItem->RemoveOwnerAttachedAccessories(); pItem->AttachToHand(false); pItem->AttachToBack(false); pItem->SetOwnerId(0); } pEntitySystem->RemoveEntity(entityId); } } Clear(); }
EntityId CAICorpse::CloneAttachedItem( const CAICorpse::AttachedItem& attachedItem, IAttachment* pAttachment ) { stack_string clonedItemName; clonedItemName.Format("%s_%s", GetEntity()->GetName(), attachedItem.pClass->GetName() ); SEntitySpawnParams params; params.sName = clonedItemName.c_str(); params.pClass = attachedItem.pClass; // Flag as 'No Save' they will be recreated during serialization if needed params.nFlags |= (ENTITY_FLAG_NO_SAVE); IEntity *pClonedItemEntity = gEnv->pEntitySystem->SpawnEntity(params); assert (pClonedItemEntity != NULL); IItem* pClonedItem = g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(pClonedItemEntity->GetId()); assert(pClonedItem != NULL); pClonedItem->Physicalize(false, false); pClonedItem->SetOwnerId( GetEntityId() ); // Set properties table to null, since they'll not be used IScriptTable* pClonedItemEntityScript = pClonedItemEntity->GetScriptTable(); if (pClonedItemEntityScript != NULL) { pClonedItemEntity->GetScriptTable()->SetToNull("Properties"); } // Swap attachments CEntityAttachment* pEntityAttachement = new CEntityAttachment(); pEntityAttachement->SetEntityId( pClonedItemEntity->GetId() ); pAttachment->AddBinding( pEntityAttachement ); return pClonedItemEntity->GetId(); }