Use pointers for the strings in game item, since they're not common

ryzomclassic-develop
kaetemi 4 years ago
parent abd5c38a80
commit 7b1136ff0b

@ -8394,7 +8394,7 @@ NLMISC_COMMAND(eventResetItemCustomText, "set an item custom text, which replace
}
CGameItemPtr item = invent->getItem(slot);
item->setCustomText(ucstring());
item->setCustomText(std::string());
// Following line was commented out by trap, reason unknown
c->incSlotVersion(INVENTORIES::bag, slot);
log.displayNL("item in slot %u has now its default text displayed", slot);

@ -3162,7 +3162,7 @@ sint32 clientEventSetItemCustomText(CCharacter* character, INVENTORIES::TInvento
}
CGameItemPtr item = invent->getItem(slot);
item->setCustomText(text);
item->setCustomText(text.toUtf8());
// Following line was commented out by trap, reason unknown
character->incSlotVersion(inventory, slot);

@ -782,7 +782,6 @@ void CGameItem::ctor()
//void CGameItem::ctor( const CEntityId& id, const CSheetId& sheetId, uint32 recommended, sint16 slotCount, bool destroyable, bool dropable )
void CGameItem::ctor( const CSheetId& sheetId, uint32 recommended, bool destroyable, bool dropable )
{
_CraftParameters = 0;
ctor();
// _ItemId = id;
_SheetId = sheetId;
@ -1174,10 +1173,6 @@ CGameItemPtr CGameItem::getItemCopy()
CGameItemPtrArray old;
old= *item;
*item = *this;
if( this->_CraftParameters != 0 )
{
item->_CraftParameters = new CItemCraftParameters(*this->_CraftParameters);
}
*(CGameItemPtrArray*)item=old;
// generate a new item id
@ -1219,8 +1214,8 @@ uint32 CGameItem::sendNameId(CCharacter * user)
nlassert( _Form != 0 );
if( _Form->Family != ITEMFAMILY::SCROLL_R2 )
{
if ( ! _PhraseId.empty() )
return STRING_MANAGER::sendStringToClient( user->getEntityRowId(), _PhraseId, TVectorParamCheck() );
if (_PhraseId && !_PhraseId->empty())
return STRING_MANAGER::sendStringToClient(user->getEntityRowId(), *_PhraseId, TVectorParamCheck());
}
else
{
@ -1333,12 +1328,7 @@ void CGameItem::clear()
_Enchantment.clear();
contReset( _Enchantment );
if( _CraftParameters )
{
_CraftParameters->clear();
delete _CraftParameters;
_CraftParameters = 0;
}
_CraftParameters = NULL;
_StackSize = 1;
// _IsOnTheGround = false;
@ -1375,8 +1365,8 @@ void CGameItem::clear()
_UnMovable = false;
_TypeSkillMods.clear();
_PhraseId.clear();
_CustomText.clear();
_PhraseId = NULL;
_CustomText = NULL;
}
void CGameItem::setStackSize(uint32 size)
@ -2705,9 +2695,10 @@ void CGameItem::addHp( double hpGain )
//-----------------------------------------------
// changes the custom text of an item
//-----------------------------------------------
void CGameItem::setCustomText(const ucstring &val)
void CGameItem::setCustomText(const std::string &val)
{
_CustomText = val;
if (!_CustomText) _CustomText = new std::string();
*_CustomText = val;
// getInventory()->onItemChanged(getInventorySlot(), INVENTORIES::TItemChangeFlags(INVENTORIES::itc_custom_text));
}
@ -4360,7 +4351,7 @@ bool CGameItem::getStats(const std::string &stats, std::string &final )
else if (part == "Fo")
final += NLMISC::toString("%s|", _Form->Name.c_str());
else if (part == "Ct")
final += NLMISC::toString("%s|", getCustomText().toString().c_str());
final += NLMISC::toString("%s|", getCustomText().c_str());
else if (part == "Bu")
final += NLMISC::toString("%u|", _Form->Bulk);
else if (part == "We")
@ -4607,11 +4598,7 @@ void CGameItem::postApply(INVENTORIES::TInventory refInventoryId, CCharacter * o
break;
// non craftable-> release craft parameters structure
default:
if (_CraftParameters != NULL)
{
delete _CraftParameters;
_CraftParameters = NULL;
}
_CraftParameters = NULL;
}
}

@ -23,6 +23,7 @@
#include "nel/misc/log.h"
#include "nel/misc/variable.h"
#include "nel/misc/enum_bitset.h"
#include "nel/misc/deep_ptr.h"
// game share
#include "game_share/ryzom_entity_id.h"
@ -230,7 +231,7 @@ struct CItemCraftParameters
* \return the current version of the class. Useful for managing old versions of saved players
* WARNING : the version number should be incremented when the serial method is modified
*/
static inline uint32 getCurrentVersion() { return 4; }
static inline uint32 getCurrentVersion() { return 5; }
/// serial validated point for a character
void serial(NLMISC::IStream &f);
@ -304,6 +305,23 @@ public:
// do nothing
}
CGameItemPtrArray &operator=(const CGameItemPtrArray &)
{
// do nothing
}
#ifdef NL_CPP14
CGameItemPtrArray(CGameItemPtrArray &&)
{
// do nothing
}
CGameItemPtrArray &operator=(CGameItemPtrArray &&) noexcept
{
// do nothing
}
#endif
protected:
/// keep pointers pointing this item
std::vector<CGameItemPtr*> _Ptrs;
@ -501,8 +519,8 @@ public :
float getDefensiveAfflictionPowerFactor() const;
/// accessors to the item phrase
const std::string & getPhraseId() const { return _PhraseId;}
void setPhraseId(const std::string & str){ _PhraseId = str;}
const std::string &getPhraseId() const { static const std::string empty; return _PhraseId ? *_PhraseId : empty; }
void setPhraseId(const std::string &str) { if (!_PhraseId) _PhraseId = new std::string(); *_PhraseId = str; }
// return the enchantment value to be displayed in the client
uint16 getClientEnchantValue() const;
@ -703,12 +721,12 @@ public :
inline void setTypeSkillMods(const std::vector<CTypeSkillMod> &mods) { _TypeSkillMods = mods; }
/// get craft parameters
const CItemCraftParameters * getCraftParameters() const { return _CraftParameters; }
const CItemCraftParameters *getCraftParameters() const { return _CraftParameters.ptr(); }
/// get custom string (for scroll-like items)
const ucstring& getCustomText() const { return _CustomText; }
const std::string &getCustomText() const { static const std::string empty; return _CustomText ? *_CustomText : empty; }
/// set custom string (for scroll-like items)
void setCustomText(const ucstring &val);
void setCustomText(const std::string &val);
uint8 getPetIndex() const { return _PetIndex; }
void setPetIndex(uint8 val) { _PetIndex = val; }
@ -816,7 +834,6 @@ public: // I've had to make these public for now 'cos I can't work out how to ma
: _InventorySlot(INVENTORIES::INVALID_INVENTORY_SLOT),
_RefInventorySlot(INVENTORIES::INVALID_INVENTORY_SLOT)
{
_CraftParameters= 0;
}
/**
@ -826,6 +843,13 @@ public: // I've had to make these public for now 'cos I can't work out how to ma
{
}
#ifdef NL_CPP14
CGameItem(const CGameItem &) = default;
CGameItem &operator=(const CGameItem &) = default;
CGameItem(CGameItem &&) = default;
CGameItem &operator=(CGameItem &&) noexcept = default;
#endif
private:
//--------------------------------------------------------------------
// item initialisation and release code called on allocation/ deallocation
@ -922,7 +946,7 @@ private:
/// current sap load
uint32 _SapLoad;
/// all craft parameters
CItemCraftParameters * _CraftParameters;
NLMISC::CDeepPtr<CItemCraftParameters> _CraftParameters;
/// entityId of the character who has created the Item via faber (if applicable, for item not created by playres, Creator = CEntityId::Unknown)
NLMISC::CEntityId _CreatorId;
@ -938,7 +962,7 @@ private:
/// pointer on the associated static form
const CStaticItem* _Form;
/// string associated with this item
std::string _PhraseId;
NLMISC::CDeepPtr<std::string> _PhraseId;
/// tick when the proc will be available again
NLMISC::TGameCycle _LatencyEndDate;
/// image of the item in bag / equipment
@ -959,7 +983,7 @@ private:
/// skill modifiers against given ennemy types
std::vector<CTypeSkillMod> _TypeSkillMods;
ucstring _CustomText;
NLMISC::CDeepPtr<std::string> _CustomText;
bool _LockedByOwner;
bool _UnMovable;
bool _Movable;
@ -1093,7 +1117,6 @@ inline CGameItemPtr::~CGameItemPtr()
inline CGameItem *CGameItemPtr::newItem(bool destroyable,bool dropable)
{
CGameItem *item=CGameItem::newItem();
item->_CraftParameters = 0;
item->ctor();
item->_Destroyable=destroyable;
item->_Dropable = dropable;

@ -1344,7 +1344,7 @@ private:
PROP2(_HP, uint32, _HP, _HP=val)\
PROP2(_Recommended, uint32, _Recommended, _Recommended=val)\
PROP2(_CreatorId, CEntityId, _CreatorId, _CreatorId=val)\
PROP2(_PhraseId, string, _PhraseId, _PhraseId=val)\
PROP2(_PhraseId, string, getPhraseId(), setPhraseId(val))\
LSTRUCT2(_CraftParameters, if (_CraftParameters != NULL), _CraftParameters->store(pdr), _CraftParameters = new CItemCraftParameters; _CraftParameters->apply(pdr))\
LPROP2(_SlotImage, uint16, if (0), 0xffff, slotImage=val)\
LPROP2(_SapLoad, uint32, if (_SapLoad!=0), _SapLoad, _SapLoad=val)\
@ -1362,7 +1362,7 @@ private:
LPROP2(_RequiredCharacLevel, uint16, if (_RequiredCharacLevel!=0),_RequiredCharacLevel, _RequiredCharacLevel=val)\
STRUCT_VECT(_TypeSkillMods)\
LPROP_VECT(CSheetId, _Enchantment, VECT_LOGIC(_Enchantment) if (_Enchantment[i]!=CSheetId::Unknown))\
PROP2(_CustomText, ucstring, _CustomText, _CustomText=val)\
PROP2(_CustomText, ucstring, ucstring::makeFromUtf8(getCustomText()), setCustomText(val.toUtf8())) /* TODO: UTF-8 (file serial) */ \
PD_CUSTOM_NAME_PROP2()\
PROP(bool, _Movable)\
PROP(bool, _UnMovable)\

Loading…
Cancel
Save