mirror of
https://github.com/polserver/polserver
synced 2026-08-13 08:23:08 -04:00
* 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
139 lines
3.3 KiB
C++
139 lines
3.3 KiB
C++
|
|
#include "wornitems.h"
|
|
|
|
#include "../../bscript/bobject.h"
|
|
#include "../../clib/passert.h"
|
|
#include "../containr.h"
|
|
#include "../extobj.h"
|
|
#include "../globals/settings.h"
|
|
#include "../item/item.h"
|
|
#include "../item/itemdesc.h"
|
|
#include "../layers.h"
|
|
#include "../objtype.h"
|
|
#include "charactr.h"
|
|
|
|
|
|
namespace Pol
|
|
{
|
|
namespace Core
|
|
{
|
|
WornItemsContainer::WornItemsContainer()
|
|
: UContainer( Items::find_container_desc( settingsManager.extobj.wornitems_container ) ),
|
|
chr_owner( nullptr )
|
|
{
|
|
contents_.resize( HIGHEST_LAYER + 1, nullptr );
|
|
}
|
|
|
|
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_ )
|
|
{
|
|
if ( item != nullptr )
|
|
{
|
|
if ( item->isa( UOBJ_CLASS::CLASS_CONTAINER ) )
|
|
{
|
|
UContainer* cont = static_cast<UContainer*>( item );
|
|
cont->for_each_item( f, arg );
|
|
}
|
|
( *f )( item, arg );
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
item->setposition( Core::Pos4d( item->pos().xyz(), realm() ) ); // TODO POS nullptr
|
|
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();
|
|
item->container = nullptr;
|
|
contents_[item->tile_layer] = nullptr;
|
|
// 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;
|
|
}
|
|
for ( unsigned clayer = 0; clayer < contents_.size(); ++clayer )
|
|
{
|
|
const Items::Item* item = contents_[clayer];
|
|
if ( item )
|
|
{
|
|
if ( !item->itemdesc().save_on_exit || !item->saveonexit() )
|
|
continue;
|
|
|
|
if ( ( clayer == LAYER_HAIR ) || ( clayer == LAYER_BEARD ) || ( clayer == LAYER_FACE ) ||
|
|
( clayer == LAYER_ROBE_DRESS && item->objtype_ == UOBJ_DEATH_SHROUD ) )
|
|
{
|
|
item->printOn( sw_pc );
|
|
item->clear_dirty();
|
|
}
|
|
else if ( clayer == LAYER_BACKPACK )
|
|
{
|
|
// 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
|
|
{
|
|
item->printOn( sw_equip );
|
|
item->clear_dirty();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Bscript::BObjectImp* WornItemsContainer::make_ref()
|
|
{
|
|
passert_always( chr_owner != nullptr );
|
|
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;
|
|
}
|
|
} // namespace Core
|
|
} // namespace Pol
|