Merge branch 'master' into graphics
commit
7ad1e962e0
@ -0,0 +1,37 @@
|
||||
|
||||
#include "skillcheck.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <components/esm/loadskil.hpp>
|
||||
|
||||
#include "../world/universalid.hpp"
|
||||
|
||||
CSMTools::SkillCheckStage::SkillCheckStage (const CSMWorld::IdCollection<ESM::Skill>& skills)
|
||||
: mSkills (skills)
|
||||
{}
|
||||
|
||||
int CSMTools::SkillCheckStage::setup()
|
||||
{
|
||||
return mSkills.getSize();
|
||||
}
|
||||
|
||||
void CSMTools::SkillCheckStage::perform (int stage, std::vector<std::string>& messages)
|
||||
{
|
||||
const ESM::Skill& skill = mSkills.getRecord (stage).get();
|
||||
|
||||
CSMWorld::UniversalId id (CSMWorld::UniversalId::Type_Skill, skill.mId);
|
||||
|
||||
for (int i=0; i<4; ++i)
|
||||
if (skill.mData.mUseValue[i]<0)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
|
||||
stream << id.toString() << "|Use value #" << i << " of " << skill.mId << " is negative";
|
||||
|
||||
messages.push_back (stream.str());
|
||||
}
|
||||
|
||||
if (skill.mDescription.empty())
|
||||
messages.push_back (id.toString() + "|" + skill.mId + " has an empty description");
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
#ifndef CSM_TOOLS_SKILLCHECK_H
|
||||
#define CSM_TOOLS_SKILLCHECK_H
|
||||
|
||||
#include <components/esm/loadskil.hpp>
|
||||
|
||||
#include "../world/idcollection.hpp"
|
||||
|
||||
#include "stage.hpp"
|
||||
|
||||
namespace CSMTools
|
||||
{
|
||||
/// \brief VerifyStage: make sure that skill records are internally consistent
|
||||
class SkillCheckStage : public Stage
|
||||
{
|
||||
const CSMWorld::IdCollection<ESM::Skill>& mSkills;
|
||||
|
||||
public:
|
||||
|
||||
SkillCheckStage (const CSMWorld::IdCollection<ESM::Skill>& skills);
|
||||
|
||||
virtual int setup();
|
||||
///< \return number of steps
|
||||
|
||||
virtual void perform (int stage, std::vector<std::string>& messages);
|
||||
///< Messages resulting from this tage will be appended to \a messages.
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,132 @@
|
||||
#include "merchantrepair.hpp"
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include "../mwbase/world.hpp"
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/mechanicsmanager.hpp"
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
#include "../mwbase/soundmanager.hpp"
|
||||
|
||||
#include "../mwworld/player.hpp"
|
||||
#include "../mwworld/containerstore.hpp"
|
||||
#include "../mwworld/class.hpp"
|
||||
|
||||
#include "list.hpp"
|
||||
#include "inventorywindow.hpp"
|
||||
#include "tradewindow.hpp"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
MerchantRepair::MerchantRepair(MWBase::WindowManager &parWindowManager)
|
||||
: WindowBase("openmw_merchantrepair.layout", parWindowManager)
|
||||
{
|
||||
getWidget(mList, "RepairView");
|
||||
getWidget(mOkButton, "OkButton");
|
||||
getWidget(mGoldLabel, "PlayerGold");
|
||||
|
||||
mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &MerchantRepair::onOkButtonClick);
|
||||
}
|
||||
|
||||
void MerchantRepair::startRepair(const MWWorld::Ptr &actor)
|
||||
{
|
||||
mActor = actor;
|
||||
|
||||
while (mList->getChildCount())
|
||||
MyGUI::Gui::getInstance().destroyWidget(mList->getChildAt(0));
|
||||
|
||||
int currentY = 0;
|
||||
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||
MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player);
|
||||
for (MWWorld::ContainerStoreIterator iter (store.begin());
|
||||
iter!=store.end(); ++iter)
|
||||
{
|
||||
if (MWWorld::Class::get(*iter).hasItemHealth(*iter))
|
||||
{
|
||||
int maxDurability = MWWorld::Class::get(*iter).getItemMaxHealth(*iter);
|
||||
int durability = (iter->getCellRef().mCharge == -1) ? maxDurability : iter->getCellRef().mCharge;
|
||||
if (maxDurability == durability)
|
||||
continue;
|
||||
|
||||
int basePrice = MWWorld::Class::get(*iter).getValue(*iter);
|
||||
float fRepairMult = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()
|
||||
.find("fRepairMult")->getFloat();
|
||||
|
||||
float p = std::max(1, basePrice);
|
||||
float r = std::max(1, static_cast<int>(maxDurability / p));
|
||||
|
||||
int x = ((maxDurability - durability) / r);
|
||||
x = (fRepairMult * x);
|
||||
|
||||
int price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mActor, x, true);
|
||||
|
||||
|
||||
std::string name = MWWorld::Class::get(*iter).getName(*iter)
|
||||
+ " - " + boost::lexical_cast<std::string>(price)
|
||||
+ MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()
|
||||
.find("sgp")->getString();;
|
||||
|
||||
|
||||
MyGUI::Button* button =
|
||||
mList->createWidget<MyGUI::Button>(
|
||||
(price>mWindowManager.getInventoryWindow()->getPlayerGold()) ? "SandTextGreyedOut" : "SandTextButton",
|
||||
0,
|
||||
currentY,
|
||||
0,
|
||||
18,
|
||||
MyGUI::Align::Default
|
||||
);
|
||||
|
||||
currentY += 18;
|
||||
|
||||
button->setEnabled(price<=mWindowManager.getInventoryWindow()->getPlayerGold());
|
||||
button->setUserString("Price", boost::lexical_cast<std::string>(price));
|
||||
button->setUserData(*iter);
|
||||
button->setCaptionWithReplacing(name);
|
||||
button->setSize(button->getTextSize().width,18);
|
||||
button->eventMouseWheel += MyGUI::newDelegate(this, &MerchantRepair::onMouseWheel);
|
||||
button->setUserString("ToolTipType", "ItemPtr");
|
||||
button->eventMouseButtonClick += MyGUI::newDelegate(this, &MerchantRepair::onRepairButtonClick);
|
||||
}
|
||||
}
|
||||
mList->setCanvasSize (MyGUI::IntSize(mList->getWidth(), std::max(mList->getHeight(), currentY)));
|
||||
|
||||
mGoldLabel->setCaptionWithReplacing("#{sGold}: "
|
||||
+ boost::lexical_cast<std::string>(mWindowManager.getInventoryWindow()->getPlayerGold()));
|
||||
}
|
||||
|
||||
void MerchantRepair::onMouseWheel(MyGUI::Widget* _sender, int _rel)
|
||||
{
|
||||
if (mList->getViewOffset().top + _rel*0.3 > 0)
|
||||
mList->setViewOffset(MyGUI::IntPoint(0, 0));
|
||||
else
|
||||
mList->setViewOffset(MyGUI::IntPoint(0, mList->getViewOffset().top + _rel*0.3));
|
||||
}
|
||||
|
||||
void MerchantRepair::open()
|
||||
{
|
||||
center();
|
||||
}
|
||||
|
||||
void MerchantRepair::onRepairButtonClick(MyGUI::Widget *sender)
|
||||
{
|
||||
// repair
|
||||
MWWorld::Ptr item = *sender->getUserData<MWWorld::Ptr>();
|
||||
item.getCellRef().mCharge = MWWorld::Class::get(item).getItemMaxHealth(item);
|
||||
|
||||
MWBase::Environment::get().getSoundManager()->playSound("Repair",1,1);
|
||||
|
||||
int price = boost::lexical_cast<int>(sender->getUserString("Price"));
|
||||
mWindowManager.getTradeWindow()->addOrRemoveGold(-price);
|
||||
|
||||
startRepair(mActor);
|
||||
}
|
||||
|
||||
void MerchantRepair::onOkButtonClick(MyGUI::Widget *sender)
|
||||
{
|
||||
mWindowManager.removeGuiMode(GM_MerchantRepair);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
#ifndef OPENMW_MWGUI_MERCHANTREPAIR_H
|
||||
#define OPENMW_MWGUI_MERCHANTREPAIR_H
|
||||
|
||||
#include "window_base.hpp"
|
||||
#include "../mwworld/ptr.hpp"
|
||||
|
||||
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
class MerchantRepair : public WindowBase
|
||||
{
|
||||
public:
|
||||
MerchantRepair(MWBase::WindowManager &parWindowManager);
|
||||
|
||||
virtual void open();
|
||||
|
||||
void startRepair(const MWWorld::Ptr& actor);
|
||||
|
||||
private:
|
||||
MyGUI::ScrollView* mList;
|
||||
MyGUI::Button* mOkButton;
|
||||
MyGUI::TextBox* mGoldLabel;
|
||||
|
||||
MWWorld::Ptr mActor;
|
||||
|
||||
protected:
|
||||
void onMouseWheel(MyGUI::Widget* _sender, int _rel);
|
||||
void onRepairButtonClick(MyGUI::Widget* sender);
|
||||
void onOkButtonClick(MyGUI::Widget* sender);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,157 @@
|
||||
#include "repair.hpp"
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include "../mwbase/world.hpp"
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
|
||||
#include "../mwworld/player.hpp"
|
||||
#include "../mwworld/containerstore.hpp"
|
||||
#include "../mwworld/class.hpp"
|
||||
|
||||
#include "widgets.hpp"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
Repair::Repair(MWBase::WindowManager &parWindowManager)
|
||||
: WindowBase("openmw_repair.layout", parWindowManager)
|
||||
{
|
||||
getWidget(mRepairBox, "RepairBox");
|
||||
getWidget(mRepairView, "RepairView");
|
||||
getWidget(mToolBox, "ToolBox");
|
||||
getWidget(mToolIcon, "ToolIcon");
|
||||
getWidget(mUsesLabel, "UsesLabel");
|
||||
getWidget(mQualityLabel, "QualityLabel");
|
||||
getWidget(mCancelButton, "CancelButton");
|
||||
|
||||
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &Repair::onCancel);
|
||||
}
|
||||
|
||||
void Repair::open()
|
||||
{
|
||||
center();
|
||||
}
|
||||
|
||||
void Repair::startRepairItem(const MWWorld::Ptr &item)
|
||||
{
|
||||
mRepair.setTool(item);
|
||||
|
||||
std::string path = std::string("icons\\");
|
||||
path += MWWorld::Class::get(item).getInventoryIcon(item);
|
||||
int pos = path.rfind(".");
|
||||
path.erase(pos);
|
||||
path.append(".dds");
|
||||
mToolIcon->setImageTexture (path);
|
||||
mToolIcon->setUserString("ToolTipType", "ItemPtr");
|
||||
mToolIcon->setUserData(item);
|
||||
|
||||
updateRepairView();
|
||||
}
|
||||
|
||||
void Repair::updateRepairView()
|
||||
{
|
||||
MWWorld::LiveCellRef<ESM::Repair> *ref =
|
||||
mRepair.getTool().get<ESM::Repair>();
|
||||
|
||||
int uses = (mRepair.getTool().getCellRef().mCharge != -1) ? mRepair.getTool().getCellRef().mCharge : ref->mBase->mData.mUses;
|
||||
|
||||
float quality = ref->mBase->mData.mQuality;
|
||||
|
||||
std::stringstream qualityStr;
|
||||
qualityStr << std::setprecision(3) << quality;
|
||||
|
||||
mUsesLabel->setCaptionWithReplacing("#{sUses} " + boost::lexical_cast<std::string>(uses));
|
||||
mQualityLabel->setCaptionWithReplacing("#{sQuality} " + qualityStr.str());
|
||||
|
||||
bool toolBoxVisible = (mRepair.getTool().getRefData().getCount() != 0);
|
||||
mToolBox->setVisible(toolBoxVisible);
|
||||
|
||||
bool toolBoxWasVisible = (mRepairBox->getPosition().top != mToolBox->getPosition().top);
|
||||
|
||||
if (toolBoxVisible && !toolBoxWasVisible)
|
||||
{
|
||||
// shrink
|
||||
mRepairBox->setPosition(mRepairBox->getPosition() + MyGUI::IntPoint(0,mToolBox->getSize().height));
|
||||
mRepairBox->setSize(mRepairBox->getSize() - MyGUI::IntSize(0,mToolBox->getSize().height));
|
||||
}
|
||||
else if (!toolBoxVisible && toolBoxWasVisible)
|
||||
{
|
||||
// expand
|
||||
mRepairBox->setPosition(MyGUI::IntPoint (mRepairBox->getPosition().left, mToolBox->getPosition().top));
|
||||
mRepairBox->setSize(mRepairBox->getSize() + MyGUI::IntSize(0,mToolBox->getSize().height));
|
||||
}
|
||||
|
||||
while (mRepairView->getChildCount())
|
||||
MyGUI::Gui::getInstance().destroyWidget(mRepairView->getChildAt(0));
|
||||
|
||||
int currentY = 0;
|
||||
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||
MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player);
|
||||
int categories = MWWorld::ContainerStore::Type_Weapon | MWWorld::ContainerStore::Type_Armor;
|
||||
for (MWWorld::ContainerStoreIterator iter (store.begin(categories));
|
||||
iter!=store.end(); ++iter)
|
||||
{
|
||||
if (MWWorld::Class::get(*iter).hasItemHealth(*iter))
|
||||
{
|
||||
int maxDurability = MWWorld::Class::get(*iter).getItemMaxHealth(*iter);
|
||||
int durability = (iter->getCellRef().mCharge == -1) ? maxDurability : iter->getCellRef().mCharge;
|
||||
if (maxDurability == durability)
|
||||
continue;
|
||||
|
||||
MyGUI::TextBox* text = mRepairView->createWidget<MyGUI::TextBox> (
|
||||
"SandText", MyGUI::IntCoord(8, currentY, mRepairView->getWidth()-8, 18), MyGUI::Align::Default);
|
||||
text->setCaption(MWWorld::Class::get(*iter).getName(*iter));
|
||||
text->setNeedMouseFocus(false);
|
||||
currentY += 19;
|
||||
|
||||
MyGUI::ImageBox* icon = mRepairView->createWidget<MyGUI::ImageBox> (
|
||||
"ImageBox", MyGUI::IntCoord(16, currentY, 32, 32), MyGUI::Align::Default);
|
||||
std::string path = std::string("icons\\");
|
||||
path += MWWorld::Class::get(*iter).getInventoryIcon(*iter);
|
||||
int pos = path.rfind(".");
|
||||
path.erase(pos);
|
||||
path.append(".dds");
|
||||
icon->setImageTexture (path);
|
||||
icon->setUserString("ToolTipType", "ItemPtr");
|
||||
icon->setUserData(*iter);
|
||||
icon->eventMouseButtonClick += MyGUI::newDelegate(this, &Repair::onRepairItem);
|
||||
icon->eventMouseWheel += MyGUI::newDelegate(this, &Repair::onMouseWheel);
|
||||
|
||||
Widgets::MWDynamicStatPtr chargeWidget = mRepairView->createWidget<Widgets::MWDynamicStat>
|
||||
("MW_ChargeBar", MyGUI::IntCoord(72, currentY+2, 199, 20), MyGUI::Align::Default);
|
||||
chargeWidget->setValue(durability, maxDurability);
|
||||
chargeWidget->setNeedMouseFocus(false);
|
||||
|
||||
currentY += 32 + 4;
|
||||
}
|
||||
}
|
||||
mRepairView->setCanvasSize (MyGUI::IntSize(mRepairView->getWidth(), std::max(mRepairView->getHeight(), currentY)));
|
||||
}
|
||||
|
||||
void Repair::onCancel(MyGUI::Widget *sender)
|
||||
{
|
||||
mWindowManager.removeGuiMode(GM_Repair);
|
||||
}
|
||||
|
||||
void Repair::onRepairItem(MyGUI::Widget *sender)
|
||||
{
|
||||
if (!mRepair.getTool().getRefData().getCount())
|
||||
return;
|
||||
|
||||
mRepair.repair(*sender->getUserData<MWWorld::Ptr>());
|
||||
|
||||
updateRepairView();
|
||||
}
|
||||
|
||||
void Repair::onMouseWheel(MyGUI::Widget* _sender, int _rel)
|
||||
{
|
||||
if (mRepairView->getViewOffset().top + _rel*0.3 > 0)
|
||||
mRepairView->setViewOffset(MyGUI::IntPoint(0, 0));
|
||||
else
|
||||
mRepairView->setViewOffset(MyGUI::IntPoint(0, mRepairView->getViewOffset().top + _rel*0.3));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
#ifndef OPENMW_MWGUI_REPAIR_H
|
||||
#define OPENMW_MWGUI_REPAIR_H
|
||||
|
||||
#include "window_base.hpp"
|
||||
|
||||
#include "../mwworld/ptr.hpp"
|
||||
#include "../mwmechanics/repair.hpp"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
class Repair : public WindowBase
|
||||
{
|
||||
public:
|
||||
Repair(MWBase::WindowManager &parWindowManager);
|
||||
|
||||
virtual void open();
|
||||
|
||||
void startRepairItem (const MWWorld::Ptr& item);
|
||||
|
||||
protected:
|
||||
MyGUI::Widget* mRepairBox;
|
||||
MyGUI::ScrollView* mRepairView;
|
||||
|
||||
MyGUI::Widget* mToolBox;
|
||||
|
||||
MyGUI::ImageBox* mToolIcon;
|
||||
|
||||
MyGUI::TextBox* mUsesLabel;
|
||||
MyGUI::TextBox* mQualityLabel;
|
||||
|
||||
MyGUI::Button* mCancelButton;
|
||||
|
||||
MWMechanics::Repair mRepair;
|
||||
|
||||
void updateRepairView();
|
||||
|
||||
void onRepairItem (MyGUI::Widget* sender);
|
||||
void onCancel (MyGUI::Widget* sender);
|
||||
void onMouseWheel(MyGUI::Widget* _sender, int _rel);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,167 @@
|
||||
#include "enchanting.hpp"
|
||||
#include "../mwworld/player.hpp"
|
||||
#include "../mwworld/manualref.hpp"
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/containerstore.hpp"
|
||||
namespace MWMechanics
|
||||
{
|
||||
Enchanting::Enchanting(MWWorld::Ptr enchanter):
|
||||
mEnchanter(enchanter),
|
||||
mEnchantType(0)
|
||||
{}
|
||||
|
||||
void Enchanting::setOldItem(MWWorld::Ptr oldItem)
|
||||
{
|
||||
mOldItemPtr=oldItem;
|
||||
if(!itemEmpty())
|
||||
{
|
||||
mObjectType = mOldItemPtr.getTypeName();
|
||||
mOldItemId = mOldItemPtr.getCellRef().mRefID;
|
||||
}
|
||||
else
|
||||
{
|
||||
mObjectType="";
|
||||
mOldItemId="";
|
||||
}
|
||||
}
|
||||
|
||||
void Enchanting::setNewItemName(std::string s)
|
||||
{
|
||||
mNewItemName=s;
|
||||
}
|
||||
|
||||
void Enchanting::setEffect(ESM::EffectList effectList)
|
||||
{
|
||||
mEffectList=effectList;
|
||||
}
|
||||
|
||||
int Enchanting::getEnchantType()
|
||||
{
|
||||
return mEnchantType;
|
||||
}
|
||||
|
||||
void Enchanting::setSoulGem(MWWorld::Ptr soulGem)
|
||||
{
|
||||
mSoulGemPtr=soulGem;
|
||||
}
|
||||
|
||||
void Enchanting::create()
|
||||
{
|
||||
mOldItemPtr.getRefData().setCount(mOldItemPtr.getRefData().getCount()-1);
|
||||
mSoulGemPtr.getRefData().setCount(mSoulGemPtr.getRefData().getCount()-1);
|
||||
|
||||
mEnchantment.mData.mCharge = getGemCharge();
|
||||
if(mEnchantType==3)
|
||||
{
|
||||
mEnchantment.mData.mCharge=0;
|
||||
}
|
||||
mEnchantment.mData.mType = mEnchantType;
|
||||
mEnchantment.mData.mCost = getEnchantCost();
|
||||
mEnchantment.mEffects = mEffectList;
|
||||
const ESM::Enchantment *enchantment = MWBase::Environment::get().getWorld()->createRecord (mEnchantment);
|
||||
|
||||
std::string newobjId = MWWorld::Class::get(mOldItemPtr).applyEnchantment(mOldItemPtr, enchantment->mId, getGemCharge(), mNewItemName);
|
||||
|
||||
MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), newobjId);
|
||||
MWWorld::Ptr newobjPtr = ref.getPtr();
|
||||
MWWorld::Ptr result = mOldItemPtr;
|
||||
result.mPtr = newobjPtr.mPtr;
|
||||
MWWorld::Class::get (mEnchanter).getContainerStore (mEnchanter).add (result);
|
||||
}
|
||||
|
||||
void Enchanting::nextEnchantType()
|
||||
{
|
||||
mEnchantType++;
|
||||
if (itemEmpty())
|
||||
{
|
||||
mEnchantType = 0;
|
||||
return;
|
||||
}
|
||||
if ((mObjectType == typeid(ESM::Armor).name())||(mObjectType == typeid(ESM::Clothing).name()))
|
||||
{
|
||||
switch(mEnchantType)
|
||||
{
|
||||
case 1:
|
||||
mEnchantType = 2;
|
||||
case 3:
|
||||
if(getGemCharge()<400)
|
||||
mEnchantType=2;
|
||||
case 4:
|
||||
mEnchantType = 2;
|
||||
}
|
||||
}
|
||||
else if(mObjectType == typeid(ESM::Weapon).name())
|
||||
{
|
||||
switch(mEnchantType)
|
||||
{
|
||||
case 3:
|
||||
mEnchantType = 1;
|
||||
}
|
||||
}
|
||||
else if(mObjectType == typeid(ESM::Book).name())
|
||||
{
|
||||
mEnchantType=0;
|
||||
}
|
||||
}
|
||||
|
||||
int Enchanting::getEnchantCost()
|
||||
{
|
||||
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
||||
float cost = 0;
|
||||
std::vector<ESM::ENAMstruct> mEffects = mEffectList.mList;
|
||||
int i=mEffects.size();
|
||||
for (std::vector<ESM::ENAMstruct>::const_iterator it = mEffects.begin(); it != mEffects.end(); ++it)
|
||||
{
|
||||
const ESM::MagicEffect* effect = store.get<ESM::MagicEffect>().find(it->mEffectID);
|
||||
|
||||
float cost1 = ((it->mMagnMin + it->mMagnMax)*it->mDuration*effect->mData.mBaseCost*0.025);
|
||||
|
||||
float cost2 = (std::max(1, it->mArea)*0.125*effect->mData.mBaseCost);
|
||||
|
||||
if(mEnchantType==3)
|
||||
{
|
||||
cost1 *= 100;
|
||||
cost2 *= 2;
|
||||
}
|
||||
if(effect->mData.mFlags & ESM::MagicEffect::CastTarget)
|
||||
cost1 *= 1.5;
|
||||
|
||||
float fullcost = cost1+cost2;
|
||||
fullcost*= i;
|
||||
i--;
|
||||
|
||||
cost+=fullcost;
|
||||
}
|
||||
return cost;
|
||||
}
|
||||
int Enchanting::getGemCharge()
|
||||
{
|
||||
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
||||
if(soulEmpty())
|
||||
return 0;
|
||||
if(mSoulGemPtr.getCellRef().mSoul=="")
|
||||
return 0;
|
||||
const ESM::Creature* soul = store.get<ESM::Creature>().find(mSoulGemPtr.getCellRef().mSoul);
|
||||
return soul->mData.mSoul;
|
||||
}
|
||||
|
||||
int Enchanting::getMaxEnchantValue()
|
||||
{
|
||||
if (itemEmpty())
|
||||
return 0;
|
||||
return MWWorld::Class::get(mOldItemPtr).getEnchantmentPoints(mOldItemPtr);
|
||||
}
|
||||
bool Enchanting::soulEmpty()
|
||||
{
|
||||
if (mSoulGemPtr.isEmpty())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Enchanting::itemEmpty()
|
||||
{
|
||||
if(mOldItemPtr.isEmpty())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
#ifndef GAME_MWMECHANICS_ENCHANTING_H
|
||||
#define GAME_MWMECHANICS_ENCHANTING_H
|
||||
#include <string>
|
||||
#include "../mwworld/ptr.hpp"
|
||||
#include <components/esm/effectlist.hpp>
|
||||
#include "../mwbase/world.hpp"
|
||||
#include "../mwbase/environment.hpp"
|
||||
namespace MWMechanics
|
||||
{
|
||||
class Enchanting
|
||||
{
|
||||
|
||||
MWWorld::Ptr mOldItemPtr;
|
||||
MWWorld::Ptr mSoulGemPtr;
|
||||
MWWorld::Ptr mEnchanter;
|
||||
const MWWorld::Ptr *mNewItemPtr;
|
||||
int mEnchantType;
|
||||
|
||||
ESM::EffectList mEffectList;
|
||||
ESM::Enchantment mEnchantment;
|
||||
|
||||
std::string mNewItemName;
|
||||
std::string mObjectType;
|
||||
std::string mOldItemId;
|
||||
public:
|
||||
Enchanting(MWWorld::Ptr enchanter);
|
||||
void setOldItem(MWWorld::Ptr oldItem);
|
||||
void setNewItemName(std::string s);
|
||||
void setEffect(ESM::EffectList effectList);
|
||||
void setSoulGem(MWWorld::Ptr soulGem);
|
||||
void create();
|
||||
void nextEnchantType();
|
||||
int getEnchantType();
|
||||
int getEnchantCost();
|
||||
int getMaxEnchantValue();
|
||||
int getGemCharge();
|
||||
bool soulEmpty();
|
||||
bool itemEmpty();
|
||||
};
|
||||
}
|
||||
#endif
|
@ -0,0 +1,110 @@
|
||||
#include "repair.hpp"
|
||||
|
||||
#include <boost/format.hpp>
|
||||
|
||||
#include "../mwbase/world.hpp"
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/mechanicsmanager.hpp"
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
#include "../mwbase/soundmanager.hpp"
|
||||
|
||||
#include "../mwworld/player.hpp"
|
||||
#include "../mwworld/containerstore.hpp"
|
||||
#include "../mwworld/class.hpp"
|
||||
|
||||
#include "../mwmechanics/creaturestats.hpp"
|
||||
#include "../mwmechanics/npcstats.hpp"
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
|
||||
void Repair::repair(const MWWorld::Ptr &itemToRepair)
|
||||
{
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||
MWWorld::LiveCellRef<ESM::Repair> *ref =
|
||||
mTool.get<ESM::Repair>();
|
||||
|
||||
// reduce number of uses left
|
||||
int uses = (mTool.getCellRef().mCharge != -1) ? mTool.getCellRef().mCharge : ref->mBase->mData.mUses;
|
||||
mTool.getCellRef().mCharge = uses-1;
|
||||
|
||||
// unstack tool if required
|
||||
if (mTool.getRefData().getCount() > 1 && uses == ref->mBase->mData.mUses)
|
||||
{
|
||||
MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player);
|
||||
MWWorld::ContainerStoreIterator it = store.add(mTool);
|
||||
it->getRefData().setCount(mTool.getRefData().getCount()-1);
|
||||
it->getCellRef().mCharge = -1;
|
||||
|
||||
mTool.getRefData().setCount(1);
|
||||
}
|
||||
|
||||
MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player);
|
||||
MWMechanics::NpcStats& npcStats = MWWorld::Class::get(player).getNpcStats(player);
|
||||
|
||||
float fatigueTerm = stats.getFatigueTerm();
|
||||
int pcStrength = stats.getAttribute(ESM::Attribute::Strength).getModified();
|
||||
int pcLuck = stats.getAttribute(ESM::Attribute::Luck).getModified();
|
||||
int armorerSkill = npcStats.getSkill(ESM::Skill::Armorer).getModified();
|
||||
|
||||
float fRepairAmountMult = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()
|
||||
.find("fRepairAmountMult")->getFloat();
|
||||
|
||||
float toolQuality = ref->mBase->mData.mQuality;
|
||||
|
||||
float x = (0.1 * pcStrength + 0.1 * pcLuck + armorerSkill) * fatigueTerm;
|
||||
|
||||
int roll = static_cast<float> (std::rand()) / RAND_MAX * 100;
|
||||
if (roll <= x)
|
||||
{
|
||||
int y = fRepairAmountMult * toolQuality * roll;
|
||||
y = std::max(1, y);
|
||||
|
||||
// repair by 'y' points
|
||||
itemToRepair.getCellRef().mCharge += y;
|
||||
itemToRepair.getCellRef().mCharge = std::min(itemToRepair.getCellRef().mCharge,
|
||||
MWWorld::Class::get(itemToRepair).getItemMaxHealth(itemToRepair));
|
||||
|
||||
// set the OnPCRepair variable on the item's script
|
||||
std::string script = MWWorld::Class::get(itemToRepair).getScript(itemToRepair);
|
||||
if(script != "")
|
||||
itemToRepair.getRefData().getLocals().setVarByInt(script, "onpcrepair", 1);
|
||||
|
||||
// increase skill
|
||||
MWWorld::Class::get(player).skillUsageSucceeded(player, ESM::Skill::Armorer, 0);
|
||||
|
||||
MWBase::Environment::get().getSoundManager()->playSound("Repair",1,1);
|
||||
MWBase::Environment::get().getWindowManager()->messageBox("#{sRepairSuccess}");
|
||||
}
|
||||
else
|
||||
{
|
||||
MWBase::Environment::get().getSoundManager()->playSound("Repair Fail",1,1);
|
||||
MWBase::Environment::get().getWindowManager()->messageBox("#{sRepairFailed}");
|
||||
}
|
||||
|
||||
// tool used up?
|
||||
if (mTool.getCellRef().mCharge == 0)
|
||||
{
|
||||
mTool.getRefData().setCount(0);
|
||||
|
||||
std::string message = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()
|
||||
.find("sNotifyMessage51")->getString();
|
||||
|
||||
MWBase::Environment::get().getWindowManager()->messageBox((boost::format(message) % MWWorld::Class::get(mTool).getName(mTool)).str());
|
||||
|
||||
// try to find a new tool of the same ID
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||
MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player);
|
||||
for (MWWorld::ContainerStoreIterator iter (store.begin());
|
||||
iter!=store.end(); ++iter)
|
||||
{
|
||||
if (Misc::StringUtils::ciEqual(iter->getCellRef().mRefID, mTool.getCellRef().mRefID))
|
||||
{
|
||||
mTool = *iter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
#ifndef OPENMW_MWMECHANICS_REPAIR_H
|
||||
#define OPENMW_MWMECHANICS_REPAIR_H
|
||||
|
||||
#include "../mwworld/ptr.hpp"
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
|
||||
class Repair
|
||||
{
|
||||
public:
|
||||
void setTool (const MWWorld::Ptr& tool) { mTool = tool; }
|
||||
MWWorld::Ptr getTool() { return mTool; }
|
||||
|
||||
void repair (const MWWorld::Ptr& itemToRepair);
|
||||
|
||||
private:
|
||||
MWWorld::Ptr mTool;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
#include "actionrepair.hpp"
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
ActionRepair::ActionRepair(const Ptr &item)
|
||||
: Action(false, item)
|
||||
{
|
||||
}
|
||||
|
||||
void ActionRepair::executeImp (const Ptr& actor)
|
||||
{
|
||||
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Repair);
|
||||
MWBase::Environment::get().getWindowManager()->startRepairItem(getTarget());
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
#ifndef GAME_MWWORLD_ACTIONREPAIR_H
|
||||
#define GAME_MWWORLD_ACTIONREPAIR_H
|
||||
|
||||
#include "action.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class ActionRepair : public Action
|
||||
{
|
||||
virtual void executeImp (const Ptr& actor);
|
||||
|
||||
public:
|
||||
ActionRepair(const MWWorld::Ptr& item);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,31 @@
|
||||
#include "loadlock.hpp"
|
||||
|
||||
#include "esmreader.hpp"
|
||||
#include "esmwriter.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
|
||||
void Lockpick::load(ESMReader &esm)
|
||||
{
|
||||
mModel = esm.getHNString("MODL");
|
||||
mName = esm.getHNString("FNAM");
|
||||
|
||||
esm.getHNT(mData, "LKDT", 16);
|
||||
|
||||
mScript = esm.getHNOString("SCRI");
|
||||
mIcon = esm.getHNOString("ITEX");
|
||||
}
|
||||
|
||||
void Lockpick::save(ESMWriter &esm)
|
||||
{
|
||||
esm.writeHNCString("MODL", mModel);
|
||||
esm.writeHNCString("FNAM", mName);
|
||||
|
||||
esm.writeHNT("LKDT", mData, 16);
|
||||
esm.writeHNOString("SCRI", mScript);
|
||||
esm.writeHNOCString("ITEX", mIcon);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
#ifndef OPENMW_ESM_LOCK_H
|
||||
#define OPENMW_ESM_LOCK_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
|
||||
class ESMReader;
|
||||
class ESMWriter;
|
||||
|
||||
struct Lockpick
|
||||
{
|
||||
struct Data
|
||||
{
|
||||
float mWeight;
|
||||
int mValue;
|
||||
|
||||
float mQuality;
|
||||
int mUses;
|
||||
}; // Size = 16
|
||||
|
||||
Data mData;
|
||||
std::string mId, mName, mModel, mIcon, mScript;
|
||||
|
||||
void load(ESMReader &esm);
|
||||
void save(ESMWriter &esm);
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
@ -1,65 +0,0 @@
|
||||
#include "loadlocks.hpp"
|
||||
|
||||
#include "esmreader.hpp"
|
||||
#include "esmwriter.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
|
||||
void Tool::load(ESMReader &esm)
|
||||
{
|
||||
mModel = esm.getHNString("MODL");
|
||||
mName = esm.getHNString("FNAM");
|
||||
|
||||
esm.getSubName();
|
||||
NAME n = esm.retSubName();
|
||||
// The data name varies, RIDT for repair items, LKDT for lock
|
||||
// picks, PBDT for probes
|
||||
|
||||
esm.getHT(mData, 16);
|
||||
|
||||
if (n == "RIDT")
|
||||
{
|
||||
mType = Type_Repair;
|
||||
// Swap t.data.quality and t.data.uses for repair items (sigh)
|
||||
float tmp = *((float*) &mData.mUses);
|
||||
mData.mUses = *((int*) &mData.mQuality);
|
||||
mData.mQuality = tmp;
|
||||
}
|
||||
else if (n == "LKDT")
|
||||
mType = Type_Pick;
|
||||
else if (n == "PBDT")
|
||||
mType = Type_Probe;
|
||||
|
||||
mScript = esm.getHNOString("SCRI");
|
||||
mIcon = esm.getHNOString("ITEX");
|
||||
}
|
||||
|
||||
void Tool::save(ESMWriter &esm)
|
||||
{
|
||||
esm.writeHNCString("MODL", mModel);
|
||||
esm.writeHNCString("FNAM", mName);
|
||||
|
||||
std::string typeName;
|
||||
switch(mType)
|
||||
{
|
||||
case Type_Repair: typeName = "RIDT"; break;
|
||||
case Type_Pick: typeName = "LKDT"; break;
|
||||
case Type_Probe: typeName = "PBDT"; break;
|
||||
}
|
||||
|
||||
Data write = mData;
|
||||
if (mType == Type_Repair)
|
||||
{
|
||||
float tmp = *((float*) &write.mUses);
|
||||
write.mUses = *((int*) &write.mQuality);
|
||||
write.mQuality = tmp;
|
||||
}
|
||||
|
||||
esm.writeHNT(typeName, write, 16);
|
||||
esm.writeHNOString("SCRI", mScript);
|
||||
esm.writeHNOCString("ITEX", mIcon);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
#ifndef OPENMW_ESM_LOCKS_H
|
||||
#define OPENMW_ESM_LOCKS_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
|
||||
class ESMReader;
|
||||
class ESMWriter;
|
||||
|
||||
/*
|
||||
* This file covers lockpicks (LOCK), probes (PROB) and armor repair
|
||||
* items (REPA). These have nearly identical data structures.
|
||||
*/
|
||||
|
||||
struct Tool
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
Type_Pick,
|
||||
Type_Probe,
|
||||
Type_Repair
|
||||
};
|
||||
|
||||
struct Data
|
||||
{
|
||||
float mWeight;
|
||||
int mValue;
|
||||
|
||||
float mQuality; // And when I say nearly identical structure, I
|
||||
int mUses; // mean perfectly identical except that these two
|
||||
// variables are swaped for repair items. Don't ask
|
||||
// me why.
|
||||
}; // Size = 16
|
||||
|
||||
Data mData;
|
||||
Type mType;
|
||||
std::string mId, mName, mModel, mIcon, mScript;
|
||||
|
||||
void load(ESMReader &esm);
|
||||
void save(ESMWriter &esm);
|
||||
};
|
||||
|
||||
struct Probe: Tool
|
||||
{
|
||||
Probe() { mType = Type_Probe; }
|
||||
};
|
||||
|
||||
struct Repair: Tool
|
||||
{
|
||||
Repair() { mType = Type_Repair; }
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
@ -0,0 +1,30 @@
|
||||
#include "loadprob.hpp"
|
||||
|
||||
#include "esmreader.hpp"
|
||||
#include "esmwriter.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
|
||||
void Probe::load(ESMReader &esm)
|
||||
{
|
||||
mModel = esm.getHNString("MODL");
|
||||
mName = esm.getHNString("FNAM");
|
||||
|
||||
esm.getHNT(mData, "PBDT", 16);
|
||||
|
||||
mScript = esm.getHNOString("SCRI");
|
||||
mIcon = esm.getHNOString("ITEX");
|
||||
}
|
||||
|
||||
void Probe::save(ESMWriter &esm)
|
||||
{
|
||||
esm.writeHNCString("MODL", mModel);
|
||||
esm.writeHNCString("FNAM", mName);
|
||||
|
||||
esm.writeHNT("PBDT", mData, 16);
|
||||
esm.writeHNOString("SCRI", mScript);
|
||||
esm.writeHNOCString("ITEX", mIcon);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
#ifndef OPENMW_ESM_PROBE_H
|
||||
#define OPENMW_ESM_PROBE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
|
||||
class ESMReader;
|
||||
class ESMWriter;
|
||||
|
||||
struct Probe
|
||||
{
|
||||
struct Data
|
||||
{
|
||||
float mWeight;
|
||||
int mValue;
|
||||
|
||||
float mQuality;
|
||||
int mUses;
|
||||
}; // Size = 16
|
||||
|
||||
Data mData;
|
||||
std::string mId, mName, mModel, mIcon, mScript;
|
||||
|
||||
void load(ESMReader &esm);
|
||||
void save(ESMWriter &esm);
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue