#include #include "ItemType.h" #include "ItemSkill.h" #include "ItemStack.h" ItemType::ItemType( int id, ItemSkillLevelUpRule* levelUpRule, const ItemType* zBrokenType ) : ReferenceCounter(), id( id ), levelUpRule( levelUpRule ), zBrokenType( zBrokenType ) { StaticRegistry::INSTANCE.registerT( this, id ); } ItemType::~ItemType() { if( levelUpRule ) levelUpRule->release(); } void ItemType::loadSuperItem( Item* zItem, Framework::StreamReader* zReader ) const { zReader->lese( (char*)&zItem->damage, 4 ); zReader->lese( (char*)&zItem->maxDamage, 4 ); zReader->lese( (char*)&zItem->durability, 4 ); zReader->lese( (char*)&zItem->maxDurability, 4 ); unsigned char flags = 0; zReader->lese( (char*)&flags, 1 ); zItem->eatable = (flags | 1) == flags; zItem->placeable = (flags | 2) == flags; zItem->equippable = (flags | 4) == flags; zItem->solid = (flags | 8) == flags; zItem->usable = (flags | 16) == flags; zReader->lese( (char*)&zItem->maxStackSize, 1 ); unsigned char len = 0; zReader->lese( (char*)&len, 1 ); zItem->name.fillText( ' ', len ); zReader->lese( zItem->name, len ); } void ItemType::saveSuperItem( const Item* zItem, Framework::StreamWriter* zWriter ) const { zWriter->schreibe( (char*)&zItem->damage, 4 ); zWriter->schreibe( (char*)&zItem->maxDamage, 4 ); zWriter->schreibe( (char*)&zItem->durability, 4 ); zWriter->schreibe( (char*)&zItem->maxDurability, 4 ); unsigned char flags = (unsigned char)(((((zItem->usable << 1) | zItem->solid << 1) | zItem->equippable << 1) | zItem->placeable << 1) | zItem->eatable); zWriter->schreibe( (char*)&flags, 1 ); zWriter->schreibe( (char*)&zItem->maxStackSize, 1 ); unsigned char len = (unsigned char)zItem->name.getLength(); zWriter->schreibe( (char*)&len, 1 ); zWriter->schreibe( zItem->name, len ); } void ItemType::loadSuperItemSkill( ItemSkill* zSkill, Framework::StreamReader* zReader ) const { } void ItemType::saveSuperItemSkill( const ItemSkill* zSkill, Framework::StreamWriter* zWriter ) const { } int ItemType::getId() const { return id; } const ItemType* ItemType::zBrokenItemType() const { return zBrokenType; } ItemStack* ItemType::createItemStack( int size ) const { Item* item = createItem(); if( !item ) return 0; return new ItemStack( item, MIN( size, item->getMaxStackSize() ) ); } ItemSkill* ItemType::createDefaultItemSkill() const { return 0; } void ItemType::levelUpItemSkill( ItemSkill* zSkill ) const { if( levelUpRule ) levelUpRule->applyOn( zSkill ); } Item* ItemType::loadItem( Framework::StreamReader* zReader ) const { Item* item = createItem(); loadSuperItem( item, zReader ); return item; } void ItemType::saveItem( const Item* zItem, Framework::StreamWriter* zWriter ) const { saveSuperItem( zItem, zWriter ); } Item* ItemType::cloneItem( Item* zItem ) const { Framework::InMemoryBuffer buffer; saveItem( zItem, &buffer ); return loadItem( &buffer ); } ItemSkill* ItemType::loadItemSkill( Framework::StreamReader* zReader ) const { ItemSkill* skill = createDefaultItemSkill(); loadSuperItemSkill( skill, zReader ); return skill; } void ItemType::saveItemSkill( const ItemSkill* zSkill, Framework::StreamWriter* zWriter ) const { saveSuperItemSkill( zSkill, zWriter ); } Item* ItemType::breakItem( Item* zItem ) const { return 0; }