mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 11:23:51 +00:00
Make applyEnchantment return the record ID instead of modifying Ptr
This commit is contained in:
parent
1d8da95756
commit
a05c8fd3ce
12 changed files with 21 additions and 27 deletions
|
@ -272,7 +272,7 @@ namespace MWClass
|
||||||
return ref->mBase->mEnchant;
|
return ref->mBase->mEnchant;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Armor::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
|
std::string Armor::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
|
||||||
{
|
{
|
||||||
MWWorld::LiveCellRef<ESM::Armor> *ref =
|
MWWorld::LiveCellRef<ESM::Armor> *ref =
|
||||||
ptr.get<ESM::Armor>();
|
ptr.get<ESM::Armor>();
|
||||||
|
@ -283,8 +283,7 @@ namespace MWClass
|
||||||
newItem.mData.mEnchant=enchCharge;
|
newItem.mData.mEnchant=enchCharge;
|
||||||
newItem.mEnchant=enchId;
|
newItem.mEnchant=enchId;
|
||||||
const ESM::Armor *record = MWBase::Environment::get().getWorld()->createRecord (newItem);
|
const ESM::Armor *record = MWBase::Environment::get().getWorld()->createRecord (newItem);
|
||||||
ref->mBase = record;
|
return record->mId;
|
||||||
ref->mRef.mRefID = record->mId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<int, std::string> Armor::canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const
|
std::pair<int, std::string> Armor::canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const
|
||||||
|
|
|
@ -67,7 +67,8 @@ namespace MWClass
|
||||||
virtual std::string getEnchantment (const MWWorld::Ptr& ptr) const;
|
virtual std::string getEnchantment (const MWWorld::Ptr& ptr) const;
|
||||||
///< @return the enchantment ID if the object is enchanted, otherwise an empty string
|
///< @return the enchantment ID if the object is enchanted, otherwise an empty string
|
||||||
|
|
||||||
virtual void applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
|
virtual std::string applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
|
||||||
|
///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it.
|
||||||
|
|
||||||
virtual std::pair<int, std::string> canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const;
|
virtual std::pair<int, std::string> canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const;
|
||||||
///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that. \n
|
///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that. \n
|
||||||
|
|
|
@ -159,7 +159,7 @@ namespace MWClass
|
||||||
return ref->mBase->mEnchant;
|
return ref->mBase->mEnchant;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Book::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
|
std::string Book::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
|
||||||
{
|
{
|
||||||
MWWorld::LiveCellRef<ESM::Book> *ref =
|
MWWorld::LiveCellRef<ESM::Book> *ref =
|
||||||
ptr.get<ESM::Book>();
|
ptr.get<ESM::Book>();
|
||||||
|
@ -171,8 +171,7 @@ namespace MWClass
|
||||||
newItem.mData.mEnchant=enchCharge;
|
newItem.mData.mEnchant=enchCharge;
|
||||||
newItem.mEnchant=enchId;
|
newItem.mEnchant=enchId;
|
||||||
const ESM::Book *record = MWBase::Environment::get().getWorld()->createRecord (newItem);
|
const ESM::Book *record = MWBase::Environment::get().getWorld()->createRecord (newItem);
|
||||||
ref->mBase = record;
|
return record->mId;
|
||||||
ref->mRef.mRefID = record->mId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::shared_ptr<MWWorld::Action> Book::use (const MWWorld::Ptr& ptr) const
|
boost::shared_ptr<MWWorld::Action> Book::use (const MWWorld::Ptr& ptr) const
|
||||||
|
|
|
@ -51,7 +51,8 @@ namespace MWClass
|
||||||
virtual std::string getEnchantment (const MWWorld::Ptr& ptr) const;
|
virtual std::string getEnchantment (const MWWorld::Ptr& ptr) const;
|
||||||
///< @return the enchantment ID if the object is enchanted, otherwise an empty string
|
///< @return the enchantment ID if the object is enchanted, otherwise an empty string
|
||||||
|
|
||||||
virtual void applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
|
virtual std::string applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
|
||||||
|
///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it.
|
||||||
|
|
||||||
virtual boost::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr) const;
|
virtual boost::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr) const;
|
||||||
///< Generate action for using via inventory menu
|
///< Generate action for using via inventory menu
|
||||||
|
|
|
@ -215,7 +215,7 @@ namespace MWClass
|
||||||
return ref->mBase->mEnchant;
|
return ref->mBase->mEnchant;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clothing::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
|
std::string Clothing::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
|
||||||
{
|
{
|
||||||
MWWorld::LiveCellRef<ESM::Clothing> *ref =
|
MWWorld::LiveCellRef<ESM::Clothing> *ref =
|
||||||
ptr.get<ESM::Clothing>();
|
ptr.get<ESM::Clothing>();
|
||||||
|
@ -226,8 +226,7 @@ namespace MWClass
|
||||||
newItem.mData.mEnchant=enchCharge;
|
newItem.mData.mEnchant=enchCharge;
|
||||||
newItem.mEnchant=enchId;
|
newItem.mEnchant=enchId;
|
||||||
const ESM::Clothing *record = MWBase::Environment::get().getWorld()->createRecord (newItem);
|
const ESM::Clothing *record = MWBase::Environment::get().getWorld()->createRecord (newItem);
|
||||||
ref->mBase = record;
|
return record->mId;
|
||||||
ref->mRef.mRefID = record->mId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<int, std::string> Clothing::canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const
|
std::pair<int, std::string> Clothing::canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const
|
||||||
|
|
|
@ -59,7 +59,8 @@ namespace MWClass
|
||||||
virtual std::string getEnchantment (const MWWorld::Ptr& ptr) const;
|
virtual std::string getEnchantment (const MWWorld::Ptr& ptr) const;
|
||||||
///< @return the enchantment ID if the object is enchanted, otherwise an empty string
|
///< @return the enchantment ID if the object is enchanted, otherwise an empty string
|
||||||
|
|
||||||
virtual void applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
|
virtual std::string applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
|
||||||
|
///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it.
|
||||||
|
|
||||||
virtual std::pair<int, std::string> canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const;
|
virtual std::pair<int, std::string> canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const;
|
||||||
///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that.
|
///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that.
|
||||||
|
|
|
@ -372,7 +372,7 @@ namespace MWClass
|
||||||
return ref->mBase->mEnchant;
|
return ref->mBase->mEnchant;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Weapon::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
|
std::string Weapon::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
|
||||||
{
|
{
|
||||||
MWWorld::LiveCellRef<ESM::Weapon> *ref =
|
MWWorld::LiveCellRef<ESM::Weapon> *ref =
|
||||||
ptr.get<ESM::Weapon>();
|
ptr.get<ESM::Weapon>();
|
||||||
|
@ -383,8 +383,7 @@ namespace MWClass
|
||||||
newItem.mData.mEnchant=enchCharge;
|
newItem.mData.mEnchant=enchCharge;
|
||||||
newItem.mEnchant=enchId;
|
newItem.mEnchant=enchId;
|
||||||
const ESM::Weapon *record = MWBase::Environment::get().getWorld()->createRecord (newItem);
|
const ESM::Weapon *record = MWBase::Environment::get().getWorld()->createRecord (newItem);
|
||||||
ref->mBase = record;
|
return record->mId;
|
||||||
ref->mRef.mRefID = record->mId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<int, std::string> Weapon::canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const
|
std::pair<int, std::string> Weapon::canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const
|
||||||
|
|
|
@ -68,7 +68,8 @@ namespace MWClass
|
||||||
virtual std::string getEnchantment (const MWWorld::Ptr& ptr) const;
|
virtual std::string getEnchantment (const MWWorld::Ptr& ptr) const;
|
||||||
///< @return the enchantment ID if the object is enchanted, otherwise an empty string
|
///< @return the enchantment ID if the object is enchanted, otherwise an empty string
|
||||||
|
|
||||||
virtual void applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
|
virtual std::string applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
|
||||||
|
///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it.
|
||||||
|
|
||||||
virtual std::pair<int, std::string> canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const;
|
virtual std::pair<int, std::string> canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const;
|
||||||
///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that.
|
///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that.
|
||||||
|
|
|
@ -20,12 +20,10 @@ namespace MWMechanics
|
||||||
if(!itemEmpty())
|
if(!itemEmpty())
|
||||||
{
|
{
|
||||||
mObjectType = mOldItemPtr.getTypeName();
|
mObjectType = mOldItemPtr.getTypeName();
|
||||||
mOldItemId = mOldItemPtr.getCellRef().mRefID;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mObjectType="";
|
mObjectType="";
|
||||||
mOldItemId="";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,17 +76,13 @@ namespace MWMechanics
|
||||||
enchantment.mData.mCost = getEnchantPoints();
|
enchantment.mData.mCost = getEnchantPoints();
|
||||||
enchantment.mEffects = mEffectList;
|
enchantment.mEffects = mEffectList;
|
||||||
|
|
||||||
// Create a new item
|
|
||||||
MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), mOldItemId, 1);
|
|
||||||
const MWWorld::Ptr& newItemPtr = ref.getPtr();
|
|
||||||
|
|
||||||
// Apply the enchantment
|
// Apply the enchantment
|
||||||
const ESM::Enchantment *enchantmentPtr = MWBase::Environment::get().getWorld()->createRecord (enchantment);
|
const ESM::Enchantment *enchantmentPtr = MWBase::Environment::get().getWorld()->createRecord (enchantment);
|
||||||
newItemPtr.getClass().applyEnchantment(newItemPtr, enchantmentPtr->mId, getGemCharge(), mNewItemName);
|
std::string newItemId = mOldItemPtr.getClass().applyEnchantment(mOldItemPtr, enchantmentPtr->mId, getGemCharge(), mNewItemName);
|
||||||
|
|
||||||
// Add the new item to player inventory and remove the old one
|
// Add the new item to player inventory and remove the old one
|
||||||
store.remove(mOldItemPtr, 1, player);
|
store.remove(mOldItemPtr, 1, player);
|
||||||
store.add(newItemPtr, 1, player);
|
store.add(newItemId, 1, player);
|
||||||
|
|
||||||
if(!mSelfEnchanting)
|
if(!mSelfEnchanting)
|
||||||
payForEnchantment();
|
payForEnchantment();
|
||||||
|
|
|
@ -21,7 +21,6 @@ namespace MWMechanics
|
||||||
|
|
||||||
std::string mNewItemName;
|
std::string mNewItemName;
|
||||||
std::string mObjectType;
|
std::string mObjectType;
|
||||||
std::string mOldItemId;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Enchanting();
|
Enchanting();
|
||||||
|
|
|
@ -304,7 +304,7 @@ namespace MWWorld
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Class::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
|
std::string Class::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
|
||||||
{
|
{
|
||||||
throw std::runtime_error ("class can't be enchanted");
|
throw std::runtime_error ("class can't be enchanted");
|
||||||
}
|
}
|
||||||
|
|
|
@ -278,7 +278,8 @@ namespace MWWorld
|
||||||
|
|
||||||
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
|
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
|
||||||
|
|
||||||
virtual void applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
|
virtual std::string applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
|
||||||
|
///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it.
|
||||||
|
|
||||||
virtual std::pair<int, std::string> canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const;
|
virtual std::pair<int, std::string> canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const;
|
||||||
///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that.
|
///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that.
|
||||||
|
|
Loading…
Reference in a new issue