2014-10-31 00:02:41 +01:00
|
|
|
|
|
|
|
|
#include "wornitems.h"
|
|
|
|
|
|
2018-01-29 21:55:48 +01:00
|
|
|
#include "../../bscript/bobject.h"
|
|
|
|
|
#include "../../clib/passert.h"
|
|
|
|
|
#include "../containr.h"
|
|
|
|
|
#include "../extobj.h"
|
|
|
|
|
#include "../globals/settings.h"
|
|
|
|
|
#include "../item/item.h"
|
2014-10-31 00:02:41 +01:00
|
|
|
#include "../item/itemdesc.h"
|
2018-01-29 21:55:48 +01:00
|
|
|
#include "../layers.h"
|
2015-01-02 19:11:57 +01:00
|
|
|
#include "../objtype.h"
|
2018-01-29 21:55:48 +01:00
|
|
|
#include "charactr.h"
|
|
|
|
|
|
2014-10-31 00:02:41 +01:00
|
|
|
|
2016-02-19 19:26:35 +01:00
|
|
|
namespace Pol
|
|
|
|
|
{
|
|
|
|
|
namespace Core
|
|
|
|
|
{
|
|
|
|
|
WornItemsContainer::WornItemsContainer()
|
|
|
|
|
: UContainer( Items::find_container_desc( settingsManager.extobj.wornitems_container ) ),
|
2018-07-31 14:30:29 +02:00
|
|
|
chr_owner( nullptr )
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
2023-05-23 17:07:23 +02:00
|
|
|
contents_.resize( HIGHEST_LAYER + 1, nullptr );
|
2016-02-19 19:26:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t WornItemsContainer::estimatedSize() const
|
|
|
|
|
{
|
|
|
|
|
return sizeof( Mobile::Character* ) /*chr_owner*/ + base::estimatedSize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void WornItemsContainer::for_each_item( void ( *f )( Items::Item* item, void* a ), void* arg )
|
|
|
|
|
{
|
|
|
|
|
for ( auto& item : contents_ )
|
|
|
|
|
{
|
2018-07-31 14:30:29 +02:00
|
|
|
if ( item != nullptr )
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
2016-12-12 22:21:59 +01:00
|
|
|
if ( item->isa( UOBJ_CLASS::CLASS_CONTAINER ) )
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
|
|
|
|
UContainer* cont = static_cast<UContainer*>( item );
|
|
|
|
|
cont->for_each_item( f, arg );
|
|
|
|
|
}
|
|
|
|
|
( *f )( item, arg );
|
2014-10-31 00:02:41 +01:00
|
|
|
}
|
2016-02-19 19:26:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WornItemsContainer::PutItemOnLayer( Items::Item* item )
|
|
|
|
|
{
|
|
|
|
|
passert( Items::valid_equip_layer(
|
|
|
|
|
item ) ); // Calling code must make sure that item->tile_layer is valid!
|
|
|
|
|
|
|
|
|
|
item->set_dirty();
|
|
|
|
|
item->container = this;
|
2021-09-10 20:17:25 +02:00
|
|
|
item->setposition( Core::Pos4d( item->pos().xyz(), realm() ) ); // TODO POS nullptr
|
2016-02-19 19:26:35 +01:00
|
|
|
item->layer = item->tile_layer;
|
|
|
|
|
contents_[item->tile_layer] = Contents::value_type( item );
|
|
|
|
|
add_bulk( item );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WornItemsContainer::RemoveItemFromLayer( Items::Item* item )
|
|
|
|
|
{
|
|
|
|
|
passert( Items::valid_equip_layer(
|
|
|
|
|
item ) ); // Calling code must make sure that item->tile_layer is valid!
|
|
|
|
|
|
|
|
|
|
item->set_dirty();
|
2018-07-31 14:30:29 +02:00
|
|
|
item->container = nullptr;
|
2023-05-23 17:07:23 +02:00
|
|
|
contents_[item->tile_layer] = nullptr;
|
2016-02-19 19:26:35 +01:00
|
|
|
// 12-17-2008 MuadDib added to clear item.layer properties.
|
|
|
|
|
item->layer = 0;
|
|
|
|
|
remove_bulk( item );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WornItemsContainer::print( Clib::StreamWriter& sw_pc, Clib::StreamWriter& sw_equip ) const
|
|
|
|
|
{
|
|
|
|
|
if ( !saveonexit() )
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-08-28 15:38:14 +02:00
|
|
|
for ( unsigned clayer = 0; clayer < contents_.size(); ++clayer )
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
2016-08-28 15:38:14 +02:00
|
|
|
const Items::Item* item = contents_[clayer];
|
2016-02-19 19:26:35 +01:00
|
|
|
if ( item )
|
|
|
|
|
{
|
|
|
|
|
if ( !item->itemdesc().save_on_exit || !item->saveonexit() )
|
|
|
|
|
continue;
|
|
|
|
|
|
2016-08-28 15:38:14 +02:00
|
|
|
if ( ( clayer == LAYER_HAIR ) || ( clayer == LAYER_BEARD ) || ( clayer == LAYER_FACE ) ||
|
|
|
|
|
( clayer == LAYER_ROBE_DRESS && item->objtype_ == UOBJ_DEATH_SHROUD ) )
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
Savefile rewrite (#601)
* rewrite of saving, replaced operator way with a generic add method, thus
not everywhere the formating of the savefiles is hardcoded.
since its the last spot which uses the old formating lib, remobed the
lib
* removed cmake of old format lib
* testscripts for load/save of UObject,Item,Armor,Weapon
* fixed: member faster_cast_recovery and faster_cast_recovery_mod getter returned
a wrong value
* wrong/missing docs
* test containers, lockable, map, spellbooks
fixed save bug in map and spellbook
removed ancient savestrategy experiments
* added corpse test
splitted testfiles
* fixed loading (ancient bug) and saving (PR bug) of Reportables
added tests for houses, boats, accounts and chars
* fixed include
* fix shutdown leak
* added npc tests
upload complete coretest folder also on failure
* do not write and load RegisteredHouse for NPCs two times
readded extra newline between accounts
* tests for guild, party, realm
added resource cfgs, but a test is not really possible since nothing of
interest is stored
* added datafile, storage test
* activated resource loading, 25year old bug, but since the stored values
are senseless it makes no real difference.
added a few wtf comments
catch all exceptions during formatting of log lines
* replaced .write with explixit .begin, .end and .comment.
for leftovers.txt the StreamSaver was also used, since the format is
different use directly ofstream
* added corechanges
2024-01-24 18:49:06 +01:00
|
|
|
item->printOn( sw_pc );
|
2016-02-19 19:26:35 +01:00
|
|
|
item->clear_dirty();
|
|
|
|
|
}
|
2016-08-28 15:38:14 +02:00
|
|
|
else if ( clayer == LAYER_BACKPACK )
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
|
|
|
|
// write the backpack to the PC file,
|
|
|
|
|
// and the backpack contents to the PCEQUIP file
|
|
|
|
|
const UContainer* cont = static_cast<const UContainer*>( item );
|
|
|
|
|
cont->printSelfOn( sw_pc );
|
|
|
|
|
cont->clear_dirty();
|
|
|
|
|
cont->printContents( sw_equip );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
Savefile rewrite (#601)
* rewrite of saving, replaced operator way with a generic add method, thus
not everywhere the formating of the savefiles is hardcoded.
since its the last spot which uses the old formating lib, remobed the
lib
* removed cmake of old format lib
* testscripts for load/save of UObject,Item,Armor,Weapon
* fixed: member faster_cast_recovery and faster_cast_recovery_mod getter returned
a wrong value
* wrong/missing docs
* test containers, lockable, map, spellbooks
fixed save bug in map and spellbook
removed ancient savestrategy experiments
* added corpse test
splitted testfiles
* fixed loading (ancient bug) and saving (PR bug) of Reportables
added tests for houses, boats, accounts and chars
* fixed include
* fix shutdown leak
* added npc tests
upload complete coretest folder also on failure
* do not write and load RegisteredHouse for NPCs two times
readded extra newline between accounts
* tests for guild, party, realm
added resource cfgs, but a test is not really possible since nothing of
interest is stored
* added datafile, storage test
* activated resource loading, 25year old bug, but since the stored values
are senseless it makes no real difference.
added a few wtf comments
catch all exceptions during formatting of log lines
* replaced .write with explixit .begin, .end and .comment.
for leftovers.txt the StreamSaver was also used, since the format is
different use directly ofstream
* added corechanges
2024-01-24 18:49:06 +01:00
|
|
|
item->printOn( sw_equip );
|
2016-02-19 19:26:35 +01:00
|
|
|
item->clear_dirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Bscript::BObjectImp* WornItemsContainer::make_ref()
|
|
|
|
|
{
|
2018-07-31 14:30:29 +02:00
|
|
|
passert_always( chr_owner != nullptr );
|
2016-02-19 19:26:35 +01:00
|
|
|
return chr_owner->make_offline_ref();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UObject* WornItemsContainer::owner()
|
|
|
|
|
{
|
|
|
|
|
return chr_owner;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const UObject* WornItemsContainer::owner() const
|
|
|
|
|
{
|
|
|
|
|
return chr_owner;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UObject* WornItemsContainer::self_as_owner()
|
|
|
|
|
{
|
|
|
|
|
return chr_owner;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const UObject* WornItemsContainer::self_as_owner() const
|
|
|
|
|
{
|
|
|
|
|
return chr_owner;
|
|
|
|
|
}
|
2021-09-10 20:17:25 +02:00
|
|
|
} // namespace Core
|
|
|
|
|
} // namespace Pol
|