Some enchanting fixes

This commit is contained in:
Glorf 2013-03-28 23:39:20 +01:00
parent 6643fe789c
commit eb88463b94
11 changed files with 36 additions and 32 deletions

View file

@ -274,18 +274,19 @@ namespace MWClass
return ref->mBase->mEnchant; return ref->mBase->mEnchant;
} }
MWWorld::Ptr Armor::applyEnchantment(const MWWorld::Ptr &ptr, std::string enchId, int enchCharge, std::string newName) const MWWorld::Ptr Armor::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
{ {
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); MWWorld::LiveCellRef<ESM::Armor> *ref =
ESM::Armor oldItem = *store.get<ESM::Armor>().find(ptr.getCellRef().mRefID); ptr.get<ESM::Armor>();
ESM::Armor newItem = oldItem;
ESM::Armor newItem = *ref->mBase;
newItem.mId=""; newItem.mId="";
newItem.mName=newName; newItem.mName=newName;
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);
MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), record->mId); MWWorld::ManualRef mref (MWBase::Environment::get().getWorld()->getStore(), record->mId);
return ref.getPtr(); return mref.getPtr();
} }
boost::shared_ptr<MWWorld::Action> Armor::use (const MWWorld::Ptr& ptr) const boost::shared_ptr<MWWorld::Action> Armor::use (const MWWorld::Ptr& ptr) const

View file

@ -65,7 +65,7 @@ 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 MWWorld::Ptr applyEnchantment(const MWWorld::Ptr &ptr, std::string enchId, int enchCharge, std::string newName) const; virtual MWWorld::Ptr applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
virtual boost::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr) virtual boost::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr)
const; const;

View file

@ -148,19 +148,20 @@ namespace MWClass
return ref->mBase->mEnchant; return ref->mBase->mEnchant;
} }
MWWorld::Ptr Book::applyEnchantment(const MWWorld::Ptr &ptr, std::string enchId, int enchCharge, std::string newName) const MWWorld::Ptr Book::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
{ {
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); MWWorld::LiveCellRef<ESM::Book> *ref =
ESM::Book oldItem = *store.get<ESM::Book>().find(ptr.getCellRef().mRefID); ptr.get<ESM::Book>();
ESM::Book newItem = oldItem;
ESM::Book newItem = *ref->mBase;
newItem.mId=""; newItem.mId="";
newItem.mName=newName; newItem.mName=newName;
newItem.mData.mIsScroll = 1; newItem.mData.mIsScroll = 1;
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);
MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), record->mId); MWWorld::ManualRef mref (MWBase::Environment::get().getWorld()->getStore(), record->mId);
return ref.getPtr(); return mref.getPtr();
} }
boost::shared_ptr<MWWorld::Action> Book::use (const MWWorld::Ptr& ptr) const boost::shared_ptr<MWWorld::Action> Book::use (const MWWorld::Ptr& ptr) const

View file

@ -51,7 +51,7 @@ 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 MWWorld::Ptr applyEnchantment(const MWWorld::Ptr &ptr, std::string enchId, int enchCharge, std::string newName) const; virtual MWWorld::Ptr applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
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

View file

@ -222,18 +222,19 @@ namespace MWClass
return ref->mBase->mEnchant; return ref->mBase->mEnchant;
} }
MWWorld::Ptr Clothing::applyEnchantment(const MWWorld::Ptr &ptr, std::string enchId, int enchCharge, std::string newName) const MWWorld::Ptr Clothing::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
{ {
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); MWWorld::LiveCellRef<ESM::Clothing> *ref =
ESM::Clothing oldItem = *store.get<ESM::Clothing>().find(ptr.getCellRef().mRefID); ptr.get<ESM::Clothing>();
ESM::Clothing newItem = oldItem;
ESM::Clothing newItem = *ref->mBase;
newItem.mId=""; newItem.mId="";
newItem.mName=newName; newItem.mName=newName;
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);
MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), record->mId); MWWorld::ManualRef mref (MWBase::Environment::get().getWorld()->getStore(), record->mId);
return ref.getPtr(); return mref.getPtr();
} }
boost::shared_ptr<MWWorld::Action> Clothing::use (const MWWorld::Ptr& ptr) const boost::shared_ptr<MWWorld::Action> Clothing::use (const MWWorld::Ptr& ptr) const

View file

@ -59,7 +59,7 @@ 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 MWWorld::Ptr applyEnchantment(const MWWorld::Ptr &ptr, std::string enchId, int enchCharge, std::string newName) const; virtual MWWorld::Ptr applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
virtual boost::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr) virtual boost::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr)
const; const;

View file

@ -362,18 +362,19 @@ namespace MWClass
return ref->mBase->mEnchant; return ref->mBase->mEnchant;
} }
MWWorld::Ptr Weapon::applyEnchantment(const MWWorld::Ptr &ptr, std::string enchId, int enchCharge, std::string newName) const MWWorld::Ptr Weapon::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
{ {
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); MWWorld::LiveCellRef<ESM::Weapon> *ref =
ESM::Weapon oldItem = *store.get<ESM::Weapon>().find(ptr.getCellRef().mRefID); ptr.get<ESM::Weapon>();
ESM::Weapon newItem = oldItem;
ESM::Weapon newItem = *ref->mBase;
newItem.mId=""; newItem.mId="";
newItem.mName=newName; newItem.mName=newName;
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);
MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), record->mId); MWWorld::ManualRef mref (MWBase::Environment::get().getWorld()->getStore(), record->mId);
return ref.getPtr(); return mref.getPtr();
} }
boost::shared_ptr<MWWorld::Action> Weapon::use (const MWWorld::Ptr& ptr) const boost::shared_ptr<MWWorld::Action> Weapon::use (const MWWorld::Ptr& ptr) const

View file

@ -65,7 +65,7 @@ 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 MWWorld::Ptr applyEnchantment(const MWWorld::Ptr &ptr, std::string enchId, int enchCharge, std::string newName) const; virtual MWWorld::Ptr applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
virtual boost::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr) virtual boost::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr)
const; const;

View file

@ -62,8 +62,8 @@ namespace MWMechanics
MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), newobj.getCellRef().mRefID); MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), newobj.getCellRef().mRefID);
MWWorld::Class::get (mEnchanter).getContainerStore (mEnchanter).add (ref.getPtr()); MWWorld::Class::get (mEnchanter).getContainerStore (mEnchanter).add (ref.getPtr());
mOldItemPtr.getRefData().setCount(0); mOldItemPtr.getRefData().setCount(mOldItemPtr.getRefData().getCount()-1);
mSoulGemPtr.getRefData().setCount(0); mSoulGemPtr.getRefData().setCount(mSoulGemPtr.getRefData().getCount()-1);
} }
void Enchanting::nextEnchantType() void Enchanting::nextEnchantType()

View file

@ -241,7 +241,7 @@ namespace MWWorld
return ""; return "";
} }
MWWorld::Ptr Class::applyEnchantment(const MWWorld::Ptr &ptr, std::string enchId, int enchCharge, std::string newName) const MWWorld::Ptr 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");
} }

View file

@ -231,7 +231,7 @@ namespace MWWorld
virtual std::string getModel(const MWWorld::Ptr &ptr) const; virtual std::string getModel(const MWWorld::Ptr &ptr) const;
virtual MWWorld::Ptr applyEnchantment(const MWWorld::Ptr &ptr, std::string enchId, int enchCharge, std::string newName) const; virtual MWWorld::Ptr applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
virtual Ptr virtual Ptr
copyToCell(const Ptr &ptr, CellStore &cell) const; copyToCell(const Ptr &ptr, CellStore &cell) const;