Added enchantment combining into cEnchantments.
This commit is contained in:
parent
bdd8b43b3e
commit
7c6ef26be9
@ -29,6 +29,18 @@ cEnchantments::cEnchantments(const AString & a_StringSpec)
|
||||
|
||||
|
||||
|
||||
void cEnchantments::Add(const cEnchantments & a_Other)
|
||||
{
|
||||
for (cEnchantments::cMap::const_iterator itr = a_Other.m_Enchantments.begin(), end = a_Other.m_Enchantments.end(); itr != end; ++itr)
|
||||
{
|
||||
SetLevel(itr->first, itr->second);
|
||||
} // for itr - a_Other.m_Enchantments[]
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cEnchantments::AddFromString(const AString & a_StringSpec)
|
||||
{
|
||||
// Add enchantments in the stringspec; if a specified enchantment already exists, overwrites it
|
||||
|
@ -40,7 +40,8 @@ Serialization will never put zero-level enchantments into the stringspec and wil
|
||||
class cEnchantments
|
||||
{
|
||||
public:
|
||||
/// Individual enchantment IDs, corresponding to their NBT IDs ( http://www.minecraftwiki.net/wiki/Data_Values#Enchantment_IDs )
|
||||
/** Individual enchantment IDs, corresponding to their NBT IDs ( http://www.minecraftwiki.net/wiki/Data_Values#Enchantment_IDs )
|
||||
*/
|
||||
|
||||
enum
|
||||
{
|
||||
@ -70,34 +71,38 @@ public:
|
||||
enchLure = 62,
|
||||
} ;
|
||||
|
||||
/// Creates an empty enchantments container
|
||||
/** Creates an empty enchantments container */
|
||||
cEnchantments(void);
|
||||
|
||||
/// Creates an enchantments container filled with enchantments parsed from stringspec
|
||||
/** Creates an enchantments container filled with enchantments parsed from stringspec */
|
||||
cEnchantments(const AString & a_StringSpec);
|
||||
|
||||
/// Adds enchantments in the stringspec; if a specified enchantment already exists, overwrites it
|
||||
/** Adds the enchantments contained in a_Other into this object.
|
||||
Existing enchantments are preserved, unless a_Other specifies a different level, in which case the level is changed. */
|
||||
void Add(const cEnchantments & a_Other);
|
||||
|
||||
/** Adds enchantments in the stringspec; if a specified enchantment already exists, overwrites it */
|
||||
void AddFromString(const AString & a_StringSpec);
|
||||
|
||||
/// Serializes all the enchantments into a string
|
||||
/** Serializes all the enchantments into a string */
|
||||
AString ToString(void) const;
|
||||
|
||||
/// Returns the level for the specified enchantment; 0 if not stored
|
||||
/** Returns the level for the specified enchantment; 0 if not stored */
|
||||
int GetLevel(int a_EnchantmentID) const;
|
||||
|
||||
/// Sets the level for the specified enchantment, adding it if not stored before or removing it if level <= 0
|
||||
/** Sets the level for the specified enchantment, adding it if not stored before or removing it if level <= 0 */
|
||||
void SetLevel(int a_EnchantmentID, int a_Level);
|
||||
|
||||
/// Removes all enchantments
|
||||
/** Removes all enchantments */
|
||||
void Clear(void);
|
||||
|
||||
/// Returns true if there are no enchantments
|
||||
/** Returns true if there are no enchantments */
|
||||
bool IsEmpty(void) const;
|
||||
|
||||
/// Converts enchantment name to the numeric representation; returns -1 if enchantment name not found; case insensitive
|
||||
/** Converts enchantment name to the numeric representation; returns -1 if enchantment name not found; case insensitive */
|
||||
static int StringToEnchantmentID(const AString & a_EnchantmentName);
|
||||
|
||||
/// Returns true if a_Other contains exactly the same enchantments and levels
|
||||
/** Returns true if a_Other contains exactly the same enchantments and levels */
|
||||
bool operator ==(const cEnchantments & a_Other) const;
|
||||
|
||||
// tolua_end
|
||||
@ -120,20 +125,20 @@ public:
|
||||
/** Gets random enchantment from Vector and returns it */
|
||||
static cEnchantments GetRandomEnchantmentFromVector(cWeightedEnchantments & a_Enchantments);
|
||||
|
||||
/// Returns true if a_Other doesn't contain exactly the same enchantments and levels
|
||||
/** Returns true if a_Other doesn't contain exactly the same enchantments and levels */
|
||||
bool operator !=(const cEnchantments & a_Other) const;
|
||||
|
||||
/// Writes the enchantments into the specified NBT writer; begins with the LIST tag of the specified name ("ench" or "StoredEnchantments")
|
||||
/** Writes the enchantments into the specified NBT writer; begins with the LIST tag of the specified name ("ench" or "StoredEnchantments") */
|
||||
friend void EnchantmentSerializer::WriteToNBTCompound(cEnchantments const& a_Enchantments, cFastNBTWriter & a_Writer, const AString & a_ListTagName);
|
||||
|
||||
/// Reads the enchantments from the specified NBT list tag (ench or StoredEnchantments)
|
||||
/** Reads the enchantments from the specified NBT list tag (ench or StoredEnchantments) */
|
||||
friend void EnchantmentSerializer::ParseFromNBT(cEnchantments& a_Enchantments, const cParsedNBT & a_NBT, int a_EnchListTagIdx);
|
||||
|
||||
protected:
|
||||
/// Maps enchantment ID -> enchantment level
|
||||
/** Maps enchantment ID -> enchantment level */
|
||||
typedef std::map<int, int> cMap;
|
||||
|
||||
/// Currently stored enchantments
|
||||
/** Currently stored enchantments */
|
||||
cMap m_Enchantments;
|
||||
} ; // tolua_export
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user